WithdrawController.php 25 KB

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