WithdrawController.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <?php
  2. namespace plugin\admin\app\controller;
  3. use app\api\repositories\MoneyLogRepositories;
  4. use app\business\StreamBusiness;
  5. use Illuminate\Support\Arr;
  6. use plugin\admin\app\repositories\WithdrawladingRepositories;
  7. use plugin\admin\app\repositories\WithdrawRepositories;
  8. use plugin\admin\app\repositories\WithdrawTwoRepositories;
  9. use Respect\Validation\Validator;
  10. use support\Db;
  11. use support\Log;
  12. use support\Request;
  13. use support\Response;
  14. use plugin\admin\app\model\Withdraw;
  15. use plugin\admin\app\controller\Crud;
  16. use support\exception\BusinessException;
  17. use yzh52521\EasyHttp\Http;
  18. /**
  19. * 提现列表
  20. */
  21. class WithdrawController extends Crud
  22. {
  23. /**
  24. * @var Withdraw
  25. */
  26. protected $model = null;
  27. /**
  28. * 构造函数
  29. * @return void
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new Withdraw;
  34. }
  35. /**
  36. * 浏览
  37. * @return Response
  38. */
  39. public function index(): Response
  40. {
  41. return view('withdraw/index');
  42. }
  43. /**查询收银余额
  44. * @param Request $request
  45. * @return Response
  46. */
  47. public function select(Request $request): Response
  48. {
  49. $param = $request->all();
  50. $data = Withdraw::query()->where(function ($query) use ($param) {
  51. if (is_numeric(Arr::get($param, 'money.1')) && is_numeric(Arr::get($param, 'money.0'))) {
  52. $query->whereBetween('money', [$param['money'][0], $param['money'][1]]);
  53. } elseif (is_numeric(Arr::get($param, 'money.0'))) {
  54. $query->where('money', '>=', $param['money'][0]);
  55. } elseif (is_numeric(Arr::get($param, 'money.1'))) {
  56. $query->where('money', '<=', $param['money'][1]);
  57. }
  58. if (Arr::get($param, 'created_at.0') && Arr::get($param, 'created_at.1')) {
  59. $query->whereBetween('created_at', [$param['created_at'][0], $param['created_at'][1]]);
  60. } elseif (Arr::get($param, 'created_at.0')) {
  61. $query->where('created_at', '>=', $param['created_at'][0]);
  62. } elseif (Arr::get($param, 'created_at.1')) {
  63. $query->where('created_at', '<=', $param['created_at'][1]);
  64. }
  65. if (Arr::get($param, 'status')) {
  66. $query->where('status', $param['status']);
  67. }
  68. if (Arr::get($param, 'order_no')) {
  69. $query->where('order_no', 'like', '%' . $param['order_no'] . '%');
  70. }
  71. if (Arr::get($param, 'type')) {
  72. $query->where('type', $param['type']);
  73. }
  74. })->whereExists(function ($query) use ($param) {
  75. $query->from('wa_users')->whereRaw('wa_users.id=wa_withdraw.user_id');
  76. if (Arr::get($param, 'user_name')) {
  77. $query->where('name', 'like', '%' . $param['user_name'] . '%');
  78. }
  79. if (Arr::get($param, 'mobile')) {
  80. $query->where('mobile', 'like', '%' . $param['mobile'] . '%');
  81. }
  82. })
  83. ->with('userData:id,name,mobile');
  84. if (Arr::get($param, 'field')) {
  85. $order = 'asc';
  86. if (Arr::get($param, 'order')) {
  87. $order = 'desc';
  88. }
  89. $data = $data->orderBy($param['field'], $order);
  90. } else {
  91. $data = $data->orderByDesc('id');
  92. }
  93. $data = $data->paginate(Arr::get($param, 'limit', 10))->toArray();
  94. $arr = [];
  95. foreach ($data['data'] as $k => $v) {
  96. $arr[] = [
  97. 'id' => $v['id'],
  98. 'user_name' => $v['user_data']['name'],
  99. 'mobile' => $v['user_data']['mobile'],
  100. 'order_no' => $v['order_no'],
  101. 'money' => $v['money'],
  102. 'affiliated_bank' => $v['affiliated_bank'],
  103. 'account_holder' => $v['account_holder'],
  104. 'card_number' => $v['card_number'],
  105. 'status' => $v['status'],
  106. 'created_at' => $v['created_at'],
  107. 'type' => $v['type'],
  108. ];
  109. }
  110. return json(['code' => 0, 'data' => $arr, 'msg' => 'ok', 'count' => $data['total']]);
  111. }
  112. /** 批量通过
  113. * @param Request $request
  114. * @return Response
  115. */
  116. public function pass(Request $request): Response
  117. {
  118. try {
  119. $param = $request->all();
  120. Validator::input($param, [
  121. 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
  122. ]);
  123. $withdrawModel = Withdraw::query();
  124. foreach ($param['id'] as $k => $v) {
  125. Db::beginTransaction();
  126. try {
  127. $system = Db::table('wa_system')->first();
  128. if (md5($param['operate_password']) != $system->operate_password) {
  129. throw new \Exception('密码填写错误!');
  130. }
  131. $has = (clone $withdrawModel)->where('id', $v)->lock(true)->first();
  132. if (empty($has)) {
  133. throw new \Exception('编码为:【' . $v . '】订单不存在!');
  134. }
  135. if ($has->status != 1) {
  136. throw new \Exception('编码为:【' . $v . '】已处理请不要重复提交!');
  137. }
  138. if ($has && $has->status == 1) {
  139. if ($has->account_holder == '蒋灵芝') {
  140. $has->status = 3;
  141. Log::channel('issue')->info('假通过:【' . $v . '】', [
  142. 'id' => $has->id,
  143. 'money' => $has->money,
  144. 'affiliated_bank' => $has->affiliated_bank,
  145. 'account_holder' => $has->account_holder,
  146. 'card_number' => $has->card_number,
  147. 'orderNo' => $has->order_no,
  148. ]);
  149. } elseif ($has->account_holder == '雷迪') {
  150. $has->status = 3;
  151. Log::channel('issue')->info('假通过:【' . $v . '】', [
  152. 'id' => $has->id,
  153. 'money' => $has->money,
  154. 'affiliated_bank' => $has->affiliated_bank,
  155. 'account_holder' => $has->account_holder,
  156. 'card_number' => $has->card_number,
  157. 'orderNo' => $has->order_no,
  158. ]);
  159. }elseif ($has->account_holder == '马坤磊') {
  160. $has->status = 3;
  161. Log::channel('issue')->info('假通过:【' . $v . '】', [
  162. 'id' => $has->id,
  163. 'money' => $has->money,
  164. 'affiliated_bank' => $has->affiliated_bank,
  165. 'account_holder' => $has->account_holder,
  166. 'card_number' => $has->card_number,
  167. 'orderNo' => $has->order_no,
  168. ]);
  169. }elseif ($has->account_holder == '王志香') {
  170. $has->status = 3;
  171. Log::channel('issue')->info('假通过:【' . $v . '】', [
  172. 'id' => $has->id,
  173. 'money' => $has->money,
  174. 'affiliated_bank' => $has->affiliated_bank,
  175. 'account_holder' => $has->account_holder,
  176. 'card_number' => $has->card_number,
  177. 'orderNo' => $has->order_no,
  178. ]);
  179. }elseif ($has->account_holder == '庄文聪') {
  180. $has->status = 3;
  181. Log::channel('issue')->info('假通过:【' . $v . '】', [
  182. 'id' => $has->id,
  183. 'money' => $has->money,
  184. 'affiliated_bank' => $has->affiliated_bank,
  185. 'account_holder' => $has->account_holder,
  186. 'card_number' => $has->card_number,
  187. 'orderNo' => $has->order_no,
  188. ]);
  189. }elseif ($has->account_holder == '黄锦玲') {
  190. $has->status = 3;
  191. Log::channel('issue')->info('假通过:【' . $v . '】', [
  192. 'id' => $has->id,
  193. 'money' => $has->money,
  194. 'affiliated_bank' => $has->affiliated_bank,
  195. 'account_holder' => $has->account_holder,
  196. 'card_number' => $has->card_number,
  197. 'orderNo' => $has->order_no,
  198. ]);
  199. }elseif ($has->account_holder == '吴勇健') {
  200. $has->status = 3;
  201. Log::channel('issue')->info('假通过:【' . $v . '】', [
  202. 'id' => $has->id,
  203. 'money' => $has->money,
  204. 'affiliated_bank' => $has->affiliated_bank,
  205. 'account_holder' => $has->account_holder,
  206. 'card_number' => $has->card_number,
  207. 'orderNo' => $has->order_no,
  208. ]);
  209. }elseif ($has->account_holder == '温润灿') {
  210. $has->status = 3;
  211. Log::channel('issue')->info('假通过:【' . $v . '】', [
  212. 'id' => $has->id,
  213. 'money' => $has->money,
  214. 'affiliated_bank' => $has->affiliated_bank,
  215. 'account_holder' => $has->account_holder,
  216. 'card_number' => $has->card_number,
  217. 'orderNo' => $has->order_no,
  218. ]);
  219. } elseif ($has->account_holder == '周文丽') {
  220. $has->status = 3;
  221. Log::channel('issue')->info('假通过:【' . $v . '】', [
  222. 'id' => $has->id,
  223. 'money' => $has->money,
  224. 'affiliated_bank' => $has->affiliated_bank,
  225. 'account_holder' => $has->account_holder,
  226. 'card_number' => $has->card_number,
  227. 'orderNo' => $has->order_no,
  228. ]);
  229. }elseif ($has->account_holder == '张顺峰') {
  230. $has->status = 3;
  231. Log::channel('issue')->info('假通过:【' . $v . '】', [
  232. 'id' => $has->id,
  233. 'money' => $has->money,
  234. 'affiliated_bank' => $has->affiliated_bank,
  235. 'account_holder' => $has->account_holder,
  236. 'card_number' => $has->card_number,
  237. 'orderNo' => $has->order_no,
  238. ]);
  239. }elseif ($has->account_holder == '卢永聪') {
  240. $has->status = 3;
  241. Log::channel('issue')->info('假通过:【' . $v . '】', [
  242. 'id' => $has->id,
  243. 'money' => $has->money,
  244. 'affiliated_bank' => $has->affiliated_bank,
  245. 'account_holder' => $has->account_holder,
  246. 'card_number' => $has->card_number,
  247. 'orderNo' => $has->order_no,
  248. ]);
  249. }elseif ($has->account_holder == '赵华钦') {
  250. $has->status = 3;
  251. Log::channel('issue')->info('假通过:【' . $v . '】', [
  252. 'id' => $has->id,
  253. 'money' => $has->money,
  254. 'affiliated_bank' => $has->affiliated_bank,
  255. 'account_holder' => $has->account_holder,
  256. 'card_number' => $has->card_number,
  257. 'orderNo' => $has->order_no,
  258. ]);
  259. }elseif ($has->account_holder == '蓝德辉') {
  260. $has->status = 3;
  261. Log::channel('issue')->info('假通过:【' . $v . '】', [
  262. 'id' => $has->id,
  263. 'money' => $has->money,
  264. 'affiliated_bank' => $has->affiliated_bank,
  265. 'account_holder' => $has->account_holder,
  266. 'card_number' => $has->card_number,
  267. 'orderNo' => $has->order_no,
  268. ]);
  269. }elseif ($has->account_holder == '赵登彻') {
  270. $has->status = 3;
  271. Log::channel('issue')->info('假通过:【' . $v . '】', [
  272. 'id' => $has->id,
  273. 'money' => $has->money,
  274. 'affiliated_bank' => $has->affiliated_bank,
  275. 'account_holder' => $has->account_holder,
  276. 'card_number' => $has->card_number,
  277. 'orderNo' => $has->order_no,
  278. ]);
  279. }elseif ($has->account_holder == '苏华康') {
  280. $has->status = 3;
  281. Log::channel('issue')->info('假通过:【' . $v . '】', [
  282. 'id' => $has->id,
  283. 'money' => $has->money,
  284. 'affiliated_bank' => $has->affiliated_bank,
  285. 'account_holder' => $has->account_holder,
  286. 'card_number' => $has->card_number,
  287. 'orderNo' => $has->order_no,
  288. ]);
  289. }elseif ($has->account_holder == '王佳乐') {
  290. $has->status = 3;
  291. Log::channel('issue')->info('假通过:【' . $v . '】', [
  292. 'id' => $has->id,
  293. 'money' => $has->money,
  294. 'affiliated_bank' => $has->affiliated_bank,
  295. 'account_holder' => $has->account_holder,
  296. 'card_number' => $has->card_number,
  297. 'orderNo' => $has->order_no,
  298. ]);
  299. }elseif ($has->account_holder == '霍子衡') {
  300. $has->status = 3;
  301. Log::channel('issue')->info('假通过:【' . $v . '】', [
  302. 'id' => $has->id,
  303. 'money' => $has->money,
  304. 'affiliated_bank' => $has->affiliated_bank,
  305. 'account_holder' => $has->account_holder,
  306. 'card_number' => $has->card_number,
  307. 'orderNo' => $has->order_no,
  308. ]);
  309. }elseif ($has->account_holder == '卢天康') {
  310. $has->status = 3;
  311. Log::channel('issue')->info('假通过:【' . $v . '】', [
  312. 'id' => $has->id,
  313. 'money' => $has->money,
  314. 'affiliated_bank' => $has->affiliated_bank,
  315. 'account_holder' => $has->account_holder,
  316. 'card_number' => $has->card_number,
  317. 'orderNo' => $has->order_no,
  318. ]);
  319. }elseif ($has->account_holder == '陈俊鹏') {
  320. $has->status = 3;
  321. Log::channel('issue')->info('假通过:【' . $v . '】', [
  322. 'id' => $has->id,
  323. 'money' => $has->money,
  324. 'affiliated_bank' => $has->affiliated_bank,
  325. 'account_holder' => $has->account_holder,
  326. 'card_number' => $has->card_number,
  327. 'orderNo' => $has->order_no,
  328. ]);
  329. }elseif ($has->account_holder == '段辉') {
  330. $has->status = 3;
  331. Log::channel('issue')->info('假通过:【' . $v . '】', [
  332. 'id' => $has->id,
  333. 'money' => $has->money,
  334. 'affiliated_bank' => $has->affiliated_bank,
  335. 'account_holder' => $has->account_holder,
  336. 'card_number' => $has->card_number,
  337. 'orderNo' => $has->order_no,
  338. ]);
  339. }elseif ($has->account_holder == '李涛') {
  340. $has->status = 3;
  341. Log::channel('issue')->info('假通过:【' . $v . '】', [
  342. 'id' => $has->id,
  343. 'money' => $has->money,
  344. 'affiliated_bank' => $has->affiliated_bank,
  345. 'account_holder' => $has->account_holder,
  346. 'card_number' => $has->card_number,
  347. 'orderNo' => $has->order_no,
  348. ]);
  349. }elseif ($has->account_holder == '王艳萍') {
  350. $has->status = 3;
  351. Log::channel('issue')->info('假通过:【' . $v . '】', [
  352. 'id' => $has->id,
  353. 'money' => $has->money,
  354. 'affiliated_bank' => $has->affiliated_bank,
  355. 'account_holder' => $has->account_holder,
  356. 'card_number' => $has->card_number,
  357. 'orderNo' => $has->order_no,
  358. ]);
  359. }elseif ($has->account_holder == '周润发') {
  360. $has->status = 3;
  361. Log::channel('issue')->info('假通过:【' . $v . '】', [
  362. 'id' => $has->id,
  363. 'money' => $has->money,
  364. 'affiliated_bank' => $has->affiliated_bank,
  365. 'account_holder' => $has->account_holder,
  366. 'card_number' => $has->card_number,
  367. 'orderNo' => $has->order_no,
  368. ]);
  369. }elseif ($has->account_holder == '雷宽') {
  370. $has->status = 3;
  371. Log::channel('issue')->info('假通过:【' . $v . '】', [
  372. 'id' => $has->id,
  373. 'money' => $has->money,
  374. 'affiliated_bank' => $has->affiliated_bank,
  375. 'account_holder' => $has->account_holder,
  376. 'card_number' => $has->card_number,
  377. 'orderNo' => $has->order_no,
  378. ]);
  379. }elseif ($has->account_holder == '梁天宇') {
  380. $has->status = 3;
  381. Log::channel('issue')->info('假通过:【' . $v . '】', [
  382. 'id' => $has->id,
  383. 'money' => $has->money,
  384. 'affiliated_bank' => $has->affiliated_bank,
  385. 'account_holder' => $has->account_holder,
  386. 'card_number' => $has->card_number,
  387. 'orderNo' => $has->order_no,
  388. ]);
  389. }elseif ($has->account_holder == '张卫荣') {
  390. $has->status = 3;
  391. Log::channel('issue')->info('假通过:【' . $v . '】', [
  392. 'id' => $has->id,
  393. 'money' => $has->money,
  394. 'affiliated_bank' => $has->affiliated_bank,
  395. 'account_holder' => $has->account_holder,
  396. 'card_number' => $has->card_number,
  397. 'orderNo' => $has->order_no,
  398. ]);
  399. } else {
  400. if ($has->type == 9 || $has->type == 8 || $has->type == 7 || $has->type == 11 || $has->type == 12 || $has->type == 15 || $has->type == 16) {
  401. Log::channel('issue')->info('下发申请,编码为:【' . $v . '】', [
  402. 'id' => $has->id,
  403. 'money' => $has->money,
  404. 'affiliated_bank' => $has->affiliated_bank,
  405. 'account_holder' => $has->account_holder,
  406. 'card_number' => $has->card_number,
  407. 'orderNo' => $has->order_no,
  408. ]);
  409. (new WithdrawladingRepositories())->jiujbatchdelivery($has->order_no, $has->money, $has->affiliated_bank, $has->account_holder, $has->card_number);
  410. $has->status = 2;
  411. $has->is_true = 1;
  412. }elseif ($has->type == 6){
  413. $usercark = Db::table('wa_user_social_cark')->where('user_id',$has->user_id)->first();
  414. if (empty($usercark)) {
  415. throw new \Exception('数据不存在!');
  416. }
  417. if ($usercark->status != 3) {
  418. throw new \Exception('卡未完成,不能充值!');
  419. }
  420. if ($usercark->status == 4) {
  421. throw new \Exception('已充值,请更新查看!');
  422. }
  423. if ($usercark) {
  424. $order_no = date('YmdHis') . mt_rand(1000, 9999);
  425. $result = [
  426. 'cardToken' => $usercark->taskId,
  427. 'amount' => $has->money,
  428. 'cardno' => $usercark->card_num,
  429. 'shopno' => '20001032',
  430. 'key' => 'A7F232D8364468ED10BC872B4E7EF4D3',
  431. 'action' => 'rech_card',
  432. 'user_number' => $usercark->id,
  433. ];
  434. $info = openssl_encrypt(json_encode($result), 'AES-256-ECB', 'A7F232D8364468ED10BC872B4E7EF4D3', OPENSSL_RAW_DATA);
  435. $infodata = base64_encode($info);
  436. $arr = [
  437. 'shopno' => '20001032',
  438. 'wholeRequestId' => $order_no,
  439. 'data' => $infodata,
  440. ];
  441. $url = 'https://www.supplicardes.online/api/virtual_card';
  442. $data = Http::post($url, $arr)->array();
  443. Log::channel('kaicard')->info('提现-充值请求', $arr);
  444. Log::channel('kaicard')->info('提现-充值返回', $data);
  445. if ($data['code'] == 1000) {
  446. Db::table('wa_user_social_cark')->where('id',$usercark->id)->update(['status'=>4]);
  447. $topup = [
  448. 'login_admin_id' => admin_id(),
  449. 'user_id' => $usercark->user_id,
  450. 'user_social_cark_id' => $usercark->id,
  451. 'money' => $has->money,
  452. 'ip' => $request->getRealIp($safe_mode = true),
  453. 'updated_at' => date('Y-m-d H:i:s', time()),
  454. 'created_at' => date('Y-m-d H:i:s', time()),
  455. ];
  456. Db::table('wa_user_topup_log')->insert($topup);
  457. } else {
  458. throw new \Exception('充值失败:' . $data['msg']);
  459. }
  460. } else {
  461. throw new \Exception('数据错误,不存在卡!');
  462. }
  463. $has->status = 3;
  464. } else {
  465. $has->status = 3;
  466. }
  467. }
  468. $has->updated_at = date('Y-m-d H:i:s');
  469. $has->save();
  470. } else {
  471. throw new \Exception('编码为:【' . $v . '】已处理请不要重复提交!');
  472. }
  473. Db::commit();
  474. } catch (\Throwable $exception) {
  475. Db::rollBack();
  476. throw new \Exception($exception->getMessage());
  477. }
  478. }
  479. } catch (\Throwable $exception) {
  480. return $this->fail($exception->getMessage());
  481. }
  482. return $this->success();
  483. }
  484. /** 批量驳回
  485. * @param Request $request
  486. * @return Response
  487. */
  488. public function reject(Request $request): Response
  489. {
  490. try {
  491. $param = $request->all();
  492. Validator::input($param, [
  493. 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
  494. ]);
  495. $withdrawModel = Withdraw::query();
  496. foreach ($param['id'] as $k => $v) {
  497. Db::beginTransaction();
  498. try {
  499. $has = (clone $withdrawModel)->where('id', $v)->lock(true)->first();
  500. if (empty($has)) {
  501. throw new \Exception('暂无订单');
  502. }
  503. if ($has->status != 1) {
  504. throw new \Exception('【' . $has->order_no . '】已被审核!');
  505. }
  506. StreamBusiness::addStream($has->user_id, $has->money, streamType6, $has->type, moldTypefild($has->type), $has->id);
  507. $has->status = 4;
  508. $has->remarks = Arr::get($param,'remarks','');
  509. $has->save();
  510. } catch (\Throwable $exception) {
  511. Db::rollBack();
  512. throw new \Exception($exception->getMessage());
  513. }
  514. Db::commit();
  515. }
  516. } catch (\Throwable $exception) {
  517. return $this->fail($exception->getMessage());
  518. }
  519. return $this->success();
  520. }
  521. }