OutController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. if (!empty($user)) {
  95. $arr = [
  96. 'from_type'=>'梦想币',
  97. 'from_id'=>$data['user_id'],
  98. 'from_name'=>$user->nickname,
  99. 'op'=>'提现',
  100. 'from_amount'=>$data['cash'],
  101. 'to_type'=>'现金',
  102. 'to_id'=>$data['user_id'],
  103. 'to_name'=>$user->nickname,
  104. 'to_amount'=>$data['cash'],
  105. 'channel'=>'平台内',
  106. 'avatar'=>$user->avatar,
  107. ];
  108. AccountLog::create($arr);
  109. }
  110. $message = '你提现的¥'.$data['cash'].'已经到账啦,去实现梦想吧!喵~';
  111. }
  112. $arr = [
  113. 'type_id'=>1,
  114. 'attr_id'=>4,
  115. 'to_user_id'=>$data['user_id'],
  116. 'message'=>$message,
  117. ];
  118. SystemInfoModel::firstOrCreate($arr);
  119. }
  120. $ok = $this->repository->update(request('id'),$data);
  121. if($ok) {
  122. $url[] = array('url'=>U( 'User/Cash/Out/index'),'title'=>'返回列表');
  123. return $this->showMessage('操作成功',urldecode(request('_referer')));
  124. }else{
  125. $url[] = array('url'=>U( 'User/Cash/Out/index'),'title'=>'返回列表');
  126. return $this->showWarning('操作失败',$url);
  127. }
  128. }
  129. public function view(Request $reqeust) {
  130. $data = $this->repository->find(request('id'));
  131. return view('admin.user.cash.out.view',compact('data'));
  132. }
  133. /**
  134. *
  135. * 状态改变
  136. *
  137. */
  138. public function status(Request $reqeust) {
  139. $ok = $this->repository->updateStatus(request('id'),request('status'));
  140. if($ok) {
  141. return $this->showMessage('操作成功');
  142. }else{
  143. return $this->showWarning('操作失败');
  144. }
  145. }
  146. /**
  147. * 删除
  148. */
  149. public function destroy(Request $reqeust) {
  150. $bool = $this->repository->destroy($reqeust->get('id'));
  151. if($bool) {
  152. return $this->showMessage('操作成功');
  153. }else{
  154. return $this->showWarning("操作失败");
  155. }
  156. }
  157. }