TakeController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Withdraw_rule;
  5. use Illuminate\Http\Request as Req;
  6. use Illuminate\Support\Facades\DB;
  7. use Request;
  8. /**
  9. *
  10. */
  11. class TakeController extends Controller
  12. {
  13. /**
  14. * @return 提现管理
  15. */
  16. function index(Req $req)
  17. {
  18. $request = array();
  19. $request['grade'] = isset($req->grade) ? trim ($req->grade) : null;
  20. $request['account_name'] = isset($req->account_name) ? trim ($req->account_name) : null;
  21. $request['order_id'] = isset($req->order_id) ? trim ($req->order_id) : null;
  22. $request['bank_user'] = isset($req->bank_user) ? trim ($req->bank_user) : null;
  23. $request['grade'] = isset($req->grade) ? trim ($req->grade) : null;
  24. $request['status'] = isset($req->status) ? trim ($req->status) : 3;
  25. $request['money_small'] = isset($req->money_small) ? trim ($req->money_small) : null;
  26. $request['money_big'] = isset($req->money_big) ? trim ($req->money_big) : null;
  27. $request['apply_startime'] = isset($req->apply_startime) ? trim ($req->apply_startime) : trans ('status.default_time.atime');
  28. $request['apply_endtime'] = isset($req->apply_endtime) ? trim ($req->apply_endtime) : trans ('status.default_time.etime');
  29. $request['haddle_startime'] = isset($req->haddle_startime) ? trim ($req->haddle_startime) : null;
  30. $request['haddle_endtime'] = isset($req->haddle_endtime) ? trim ($req->haddle_endtime) : null;
  31. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  32. $dt = \App\Lib\DataTable\DataTable::init ();
  33. $dt->setDataSource ('/admin/money/withdraw');
  34. $dt->setLang ('money');
  35. $dt->setPriKey ('order_id');
  36. $dt->addColsFields ('id', array('width' => 90));
  37. $dt->addColsFields ('account_name', array('templet' => '#usertake', 'width' => 130));
  38. $dt->addColsFields ('apply_time', array('width' => 230));
  39. $dt->addColsFields ('money', array('templet' => '#money_aftercash', 'width' => 280));
  40. $dt->addColsFields ('bank_info_no', array('sort' => false, 'templet' => '#infoNo', 'width' => 200));
  41. $dt->addColsFields ('bank_user_address', array('sort' => false, 'width' => 180));
  42. $dt->addColsFields ('reason', array('sort' => false));
  43. $dt->addColsFields ('pass_time', array('templet' => '#takes', 'width' => 180));
  44. $dt->addColsFields ('pass', array('sort' => false, 'templet' => '#pass', 'width' => 120));
  45. return view ('admin.Take/index', $dt->render ($request));
  46. }
  47. /**
  48. * 单用户提现列表
  49. * [detail description]
  50. * @return [type] [description]
  51. */
  52. function usertake()
  53. {
  54. $account_name = Request::has ('account_name') ? Request::get ('account_name') : '';
  55. $dt = \App\Lib\DataTable\DataTable::init ();
  56. $dt->setDataSource (htmlspecialchars ('/admin/money/withdraw?account_name=' . $account_name . "&sureblur=精确"));
  57. $dt->setLang ('money');
  58. $dt->setPriKey ('order_id');
  59. $dt->addColsFields ('id', array('width' => 100));
  60. $dt->addColsFields ('account_name', array('templet' => '#usertake', 'width' => 110));
  61. $dt->addColsFields ('apply_time', array('width' => 200));
  62. $dt->addColsFields ('money', array('width' => 100));
  63. $dt->addColsFields ('bank_info_no', array('sort' => false, 'width' => 180));
  64. $dt->addColsFields ('bank_user_address', array('sort' => false, 'width' => 180));
  65. $dt->addColsFields ('pass_time', array('width' => 180));
  66. $dt->addColsFields ('pass', array('sort' => false, 'templet' => '#pass', 'width' => 100));
  67. return view ('admin.Take/usertake', $dt->render ());
  68. }
  69. //查看提现
  70. function Edit(Req $req)
  71. {
  72. $order_id = $req->order_id;
  73. if (empty($order_id)) {
  74. abort (404);
  75. }
  76. $moneydetails = new \App\Models\Money_take();
  77. $userObj = new \App\Models\Account();
  78. $accountDB = new \App\Models\Account_detailed();
  79. $reccharge = new \App\Models\Money_recharge(); //充值
  80. $money_buy_db = new \App\Models\MoneyBuy(); //购买
  81. $data = $moneydetails->getOrderDetails ($order_id, 3);
  82. if ($data < 0) {
  83. return responseToJson ($data);
  84. }
  85. if (!$req->isMethod ('post')) {
  86. $userRemark = $userObj->getinfo ($data['account_identity'], 2);
  87. $data['user_remark'] = $userRemark['remark'];
  88. $account = $accountDB->getInfoBy ($data['account_identity']);
  89. $data['last_money'] = $account['available_cash']; //交易余额
  90. $data['pre_money'] = $data['money'] + $account['available_cash']; //交易余额
  91. $count_take = $moneydetails->getCount ($data['account_identity']);
  92. $data['take_count'] = $count_take;
  93. $data['today_take'] = $moneydetails->gettoDayCount ($data['account_identity']);
  94. $last_rech_info = $reccharge->getLast ($data['account_identity']);
  95. $time = isset($last_rech_info['apply_time']) ? $last_rech_info['apply_time'] : '';
  96. $data['last_recharge_time'] = $time; //最后一笔存款时间
  97. $data['last_recharge_money'] = isset($last_rech_info['money']) ? $last_rech_info['money'] : '0'; //最后一笔存款金额
  98. $data['total_bet_money'] = 0;
  99. $re = Withdraw_rule::check ($data['account_identity']);
  100. $data['needBettingMoney'] = $re ? $re->needBettingMoney : '未设定';
  101. $data['bettingMoney'] = $re ? $re->bettingMoney : '未设定';
  102. $data['total_bet_money'] = $data['bettingMoney'];
  103. $tradetype = \App\Models\Money_details::select('trade_type')->where('trade_id',$data['order_id'])->first();
  104. $data['active'] = ($tradetype && isset($tradetype->trade_type))?$tradetype->trade_type:5;
  105. return view ('admin.Take/edit', ['data' => $data]);
  106. } else {
  107. //验证可操作金额限额
  108. $limitroot = new \App\Models\System_user();
  109. $limitmoney = $limitroot->checkActMoney ($data['money']);
  110. if ($limitmoney < 0) {
  111. return responseToJson ($limitmoney);
  112. }
  113. if (empty($req->status)) {
  114. return responseToJson (-3025210022); //已处理的订单不能再处理
  115. }
  116. $tradetype = $req->active?trim($req->active):5;
  117. //开启事务
  118. DB::beginTransaction ();
  119. $datas = array(
  120. 'status' => $req->status,
  121. 'reason' => $req->reason,
  122. );
  123. $datas['pass_time'] = date ('Y-m-d H:i:s');
  124. $data['pass_time'] = $datas['pass_time'];
  125. $res = \App\Models\Money_count::AddCountinfo ($data, 'take');
  126. if ($res < 0) {
  127. DB::rollback ();//事务回滚
  128. return responseToJson ($res);
  129. }
  130. $res = $moneydetails->checkInfo ($order_id);
  131. if ($res < 0) {
  132. DB::rollback ();//事务回滚
  133. return responseToJson ($res);
  134. }
  135. if ($req->status == 2) {
  136. //如果驳回
  137. $res1 = $accountDB->addMoney ($data['account_identity'], $data['money']);
  138. if ($res1 < 0) {
  139. DB::rollback ();//事务回滚
  140. return responseToJson ($res1);
  141. }
  142. }
  143. $res = $moneydetails->updateInfo ($datas, $order_id);
  144. if ($res < 0) {
  145. DB::rollback ();//事务回滚
  146. return responseToJson ($res);
  147. }
  148. $log = array(
  149. session ('adminInfo.admin_name'),
  150. $data['account_name'],
  151. $data['money'],
  152. $order_id,
  153. );
  154. if ($req->status == 1) {
  155. OperationLog (session ('adminInfo.admin_id'), 'pass_take', $log);
  156. } else {
  157. OperationLog (session ('adminInfo.admin_id'), 'nopass_take', $log);
  158. }
  159. $data['reason'] = $datas['reason'];
  160. $res = $this->addLog ($data, $req->status,$tradetype);
  161. if ($res < 0) {
  162. DB::rollback ();//事务回滚
  163. return responseToJson ($res);
  164. }
  165. $db = new \App\Models\Manager;
  166. if ($req->status == 1) {
  167. $db->updateMessage ('admin', $data['account_name'], '提款提示', '提款成功,提款金额:' . $data['money'], 2);
  168. } else {
  169. $db->updateMessage ('admin', $data['account_name'], '提款提示', '提款失败,提款金额:' . $data['money'], 2);
  170. }
  171. $clear = Withdraw_rule::withDraw ($data['account_identity']);//更新目标流水增量记录
  172. if (!$clear)
  173. DB::rollback ();
  174. DB::commit ();//事务回滚
  175. return responseToJson ($res);
  176. }
  177. }
  178. //详情记录
  179. function addLog($data, $type,$trade_type=5)
  180. {
  181. $ac_log = array(
  182. $data['account_name'],
  183. $data['money'],
  184. $data['order_id'],
  185. );
  186. $str = 'take_money_';
  187. if ($type == 2) {
  188. $str .= 'fail';
  189. $money_type = 1;
  190. } else {
  191. $str .= 'success';
  192. $money_type = 2;
  193. }
  194. $accountDB = new \App\Models\Account_detailed();
  195. $account = $accountDB->getInfoBy ($data['account_identity']);
  196. $log = array(
  197. 'trade_id' => $data['order_id'],
  198. 'account_name' => $data['account_name'],
  199. 'account_identity' => $data['account_identity'],
  200. 'money' => $data['money'],
  201. 'money_time' => date ('Y-m-d H:i:s', time ()),
  202. 'trade_type' => $trade_type,
  203. 'trade_desc' => vsprintf (trans ('trade.' . $str), $ac_log),
  204. 'status' => $type,
  205. 'money_type' => $money_type,
  206. 'money_cash' => $account['cash'],
  207. 'reason' => $data['reason'],
  208. 'sysetem_user' => session ('adminInfo.admin_name'),
  209. );
  210. $moeny_db = new \App\Models\Money_details;//详情表
  211. return $moeny_db->insertData ($log);
  212. }
  213. public function checkMoney(Req $req)
  214. {
  215. $idd = $req->account_identity ?? '';
  216. if (!$idd) return responseToJson (-3020300502);
  217. return $ret = Withdraw_rule::check ($idd)??0;
  218. }
  219. }
  220. ?>