OutController.php 5.8 KB

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