OutController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * 提现列表
  4. * @author system
  5. * @version 1.0
  6. * @date 2017-06-30 18:18:37
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\User\Cash;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\AccountLog;
  12. use App\Models\SystemInfoModel;
  13. use App\Models\UserInfoModel;
  14. use Illuminate\Http\Request;
  15. use App\Repositories\Base\Criteria\OrderBy;
  16. use App\Repositories\User\Cash\Criteria\MultiWhere;
  17. use App\Repositories\User\Cash\OutRepository;
  18. class OutController extends Controller
  19. {
  20. private $repository;
  21. public function __construct(OutRepository $repository) {
  22. if(!$this->repository) $this->repository = $repository;
  23. }
  24. function index(Request $reqeust) {
  25. $search['keyword'] = $reqeust->input('keyword');
  26. $query = $this->repository->pushCriteria(new MultiWhere($search));
  27. $request = $reqeust->all();
  28. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  29. $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
  30. }
  31. $list = $query->paginate();
  32. return view('admin.user.cash.out.index',compact('list'));
  33. }
  34. function check(Request $reqeust) {
  35. $request = $reqeust->all();
  36. $search['keyword'] = $reqeust->input('keyword');
  37. $orderby = array();
  38. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  39. $orderby[$request['sort_field']] = $request['sort_field_by'];
  40. }
  41. $list = $this->repository->search($search,$orderby);
  42. return view('admin.user.cash.out.check',compact('list'));
  43. }
  44. /**
  45. * 添加
  46. *
  47. */
  48. public function create(Request $reqeust)
  49. {
  50. if($reqeust->method() == 'POST') {
  51. return $this->_createSave();
  52. }
  53. return view('admin.user.cash.out.edit');
  54. }
  55. /**
  56. * 保存修改
  57. */
  58. private function _createSave(){
  59. $data = (array) request('data');
  60. $id = $this->repository->create($data);
  61. if($id) {
  62. $url[] = array('url'=>U( 'User/Cash/Out/index'),'title'=>'返回列表');
  63. $url[] = array('url'=>U( 'User/Cash/Out/create'),'title'=>'继续添加');
  64. $this->showMessage('添加成功',$url);
  65. }else{
  66. $url[] = array('url'=>U( 'User/Cash/Out/index'),'title'=>'返回列表');
  67. return $this->showWarning('添加失败',$url);
  68. }
  69. }
  70. /**
  71. *
  72. * 修改
  73. *
  74. *
  75. */
  76. public function update(Request $reqeust) {
  77. if($reqeust->method() == 'POST') {
  78. return $this->_updateSave();
  79. }
  80. $data = $this->repository->find($reqeust->get('id'));
  81. return view('admin.user.cash.out.edit',compact('data'));
  82. }
  83. /**
  84. * 保存修改
  85. */
  86. private function _updateSave() {
  87. $data = (array) request('data');
  88. if ($data['status'] == 3|| $data['status'] == 2) { //审核不过已打款发送梦想消息
  89. if ($data['status'] == 3) {
  90. $message = '你的提现被拒绝了。客服会在短时间内联系你。';
  91. }else{
  92. // 已打款 记录提现日志 并且用户的账号梦想币减少
  93. $user = UserInfoModel::find($data['user_id']);
  94. $user->coin -=$data['cash'];
  95. $user->save();
  96. if (!empty($user)) {
  97. $arr = [
  98. 'from_type'=>'梦想币',
  99. 'from_id'=>$data['user_id'],
  100. 'from_name'=>$user->nickname,
  101. 'op'=>'提现',
  102. 'from_amount'=>$data['cash'],
  103. 'to_type'=>'现金',
  104. 'to_id'=>$data['user_id'],
  105. 'to_name'=>$user->nickname,
  106. 'to_amount'=>$data['cash'],
  107. 'channel'=>'平台内',
  108. 'transaction_id'=>date('YmdHis') . mt_rand(1000, 9999),
  109. 'avatar'=>$user->avatar,
  110. ];
  111. AccountLog::create($arr);
  112. }
  113. $message = '你提现的¥'.$data['cash'].'已经到账啦,去实现梦想吧!喵~';
  114. }
  115. $arr = [
  116. 'type_id'=>1,
  117. 'attr_id'=>4,
  118. 'to_user_id'=>$data['user_id'],
  119. 'message'=>$message,
  120. ];
  121. SystemInfoModel::firstOrCreate($arr);
  122. }
  123. $ok = $this->repository->update(request('id'),$data);
  124. if($ok) {
  125. $url[] = array('url'=>U( 'User/Cash/Out/index'),'title'=>'返回列表');
  126. return $this->showMessage('操作成功',urldecode(request('_referer')));
  127. }else{
  128. $url[] = array('url'=>U( 'User/Cash/Out/index'),'title'=>'返回列表');
  129. return $this->showWarning('操作失败',$url);
  130. }
  131. }
  132. public function view(Request $reqeust) {
  133. $data = $this->repository->find(request('id'));
  134. return view('admin.user.cash.out.view',compact('data'));
  135. }
  136. /**
  137. *
  138. * 状态改变
  139. *
  140. */
  141. public function status(Request $reqeust) {
  142. $ok = $this->repository->updateStatus(request('id'),request('status'));
  143. if($ok) {
  144. return $this->showMessage('操作成功');
  145. }else{
  146. return $this->showWarning('操作失败');
  147. }
  148. }
  149. /**
  150. * 删除
  151. */
  152. public function destroy(Request $reqeust) {
  153. $bool = $this->repository->destroy($reqeust->get('id'));
  154. if($bool) {
  155. return $this->showMessage('操作成功');
  156. }else{
  157. return $this->showWarning("操作失败");
  158. }
  159. }
  160. }