OutController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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'] != 1) { //审核不过已打款发送梦想消息
  91. if ($data['status'] == 3) {
  92. $message = '你的提现被拒绝了。客服会在短时间内联系你。';
  93. }elseif($data['status'] == 4){
  94. $message = '亲,你的提现我们已经审批通过,你的梦想基金很快就到账了哦!';
  95. }else{
  96. // 已打款 记录提现日志 并且用户的账号梦想币减少
  97. if ($info['status']!=2) { //避免重复操作
  98. $user = UserInfoModel::find($data['user_id']);
  99. $user->coin -=$data['cash'];
  100. $user->save();
  101. if (!empty($user)) {
  102. $arr = [
  103. 'from_type'=>'梦想币',
  104. 'from_id'=>$data['user_id'],
  105. 'from_name'=>$user->nickname,
  106. 'op'=>'提现',
  107. 'from_amount'=>$data['cash'],
  108. 'to_type'=>'现金',
  109. 'to_id'=>$data['user_id'],
  110. 'to_name'=>$user->nickname,
  111. 'to_amount'=>$data['cash'],
  112. 'channel'=>'平台内',
  113. 'transaction_id'=>$info->number,
  114. 'avatar'=>env('APP_URL').'/base/img/jianhao.png',
  115. ];
  116. AccountLog::create($arr);
  117. }
  118. }
  119. $message = '你提现的¥'.$data['cash'].'已经到账啦,去实现梦想吧!喵~';
  120. }
  121. $arr = [
  122. 'type_id'=>1,
  123. 'attr_id'=>4,
  124. 'to_user_id'=>$data['user_id'],
  125. 'message'=>$message,
  126. ];
  127. SystemInfoModel::firstOrCreate($arr);
  128. }
  129. $ok = $this->repository->update(request('id'),$data);
  130. if($ok) {
  131. $url[] = array('url'=>U( 'User/Cash/Out/index'),'title'=>'返回列表');
  132. return $this->showMessage('操作成功',urldecode(request('_referer')));
  133. }else{
  134. $url[] = array('url'=>U( 'User/Cash/Out/index'),'title'=>'返回列表');
  135. return $this->showWarning('操作失败',$url);
  136. }
  137. }
  138. public function view(Request $reqeust) {
  139. $data = $this->repository->find(request('id'));
  140. return view('admin.user.cash.out.view',compact('data'));
  141. }
  142. /**
  143. *
  144. * 状态改变
  145. *
  146. */
  147. public function status(Request $reqeust) {
  148. $ok = $this->repository->updateStatus(request('id'),request('status'));
  149. if($ok) {
  150. return $this->showMessage('操作成功');
  151. }else{
  152. return $this->showWarning('操作失败');
  153. }
  154. }
  155. /**
  156. * 删除
  157. */
  158. public function destroy(Request $reqeust) {
  159. $bool = $this->repository->destroy($reqeust->get('id'));
  160. if($bool) {
  161. return $this->showMessage('操作成功');
  162. }else{
  163. return $this->showWarning("操作失败");
  164. }
  165. }
  166. }