OutController.php 6.2 KB

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