WithdrawController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. /**
  18. * 提现列表
  19. */
  20. class WithdrawController extends Crud
  21. {
  22. /**
  23. * @var Withdraw
  24. */
  25. protected $model = null;
  26. /**
  27. * 构造函数
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new Withdraw;
  33. }
  34. /**
  35. * 浏览
  36. * @return Response
  37. */
  38. public function index(): Response
  39. {
  40. return view('withdraw/index');
  41. }
  42. /**查询收银余额
  43. * @param Request $request
  44. * @return Response
  45. */
  46. public function select(Request $request): Response
  47. {
  48. $param = $request->all();
  49. $data = Withdraw::query()->where(function ($query) use ($param) {
  50. if (is_numeric(Arr::get($param, 'money.1')) && is_numeric(Arr::get($param, 'money.0'))) {
  51. $query->whereBetween('money', [$param['money'][0], $param['money'][1]]);
  52. } elseif (is_numeric(Arr::get($param, 'money.0'))) {
  53. $query->where('money', '>=', $param['money'][0]);
  54. } elseif (is_numeric(Arr::get($param, 'money.1'))) {
  55. $query->where('money', '<=', $param['money'][1]);
  56. }
  57. if (Arr::get($param, 'created_at.0') && Arr::get($param, 'created_at.1')) {
  58. $query->whereBetween('created_at', [$param['created_at'][0], $param['created_at'][1]]);
  59. } elseif (Arr::get($param, 'created_at.0')) {
  60. $query->where('created_at', '>=', $param['created_at'][0]);
  61. } elseif (Arr::get($param, 'created_at.1')) {
  62. $query->where('created_at', '<=', $param['created_at'][1]);
  63. }
  64. if (Arr::get($param, 'status')) {
  65. $query->where('status', $param['status']);
  66. }
  67. if (Arr::get($param, 'order_no')) {
  68. $query->where('order_no', 'like', '%' . $param['order_no'] . '%');
  69. }
  70. if (Arr::get($param, 'type')) {
  71. $query->where('type', $param['type']);
  72. }
  73. })->whereExists(function ($query) use ($param) {
  74. $query->from('wa_users')->whereRaw('wa_users.id=wa_withdraw.user_id');
  75. if (Arr::get($param, 'user_name')) {
  76. $query->where('name', 'like', '%' . $param['user_name'] . '%');
  77. }
  78. if (Arr::get($param, 'mobile')) {
  79. $query->where('mobile', 'like', '%' . $param['mobile'] . '%');
  80. }
  81. })
  82. ->with('userData:id,name,mobile');
  83. if (Arr::get($param, 'field')) {
  84. $order = 'asc';
  85. if (Arr::get($param, 'order')) {
  86. $order = 'desc';
  87. }
  88. $data = $data->orderBy($param['field'], $order);
  89. } else {
  90. $data = $data->orderByDesc('id');
  91. }
  92. $data = $data->paginate(Arr::get($param, 'limit', 10))->toArray();
  93. $arr = [];
  94. foreach ($data['data'] as $k => $v) {
  95. $arr[] = [
  96. 'id' => $v['id'],
  97. 'user_name' => $v['user_data']['name'],
  98. 'mobile' => $v['user_data']['mobile'],
  99. 'order_no' => $v['order_no'],
  100. 'money' => $v['money'],
  101. 'affiliated_bank' => $v['affiliated_bank'],
  102. 'account_holder' => $v['account_holder'],
  103. 'card_number' => $v['card_number'],
  104. 'status' => $v['status'],
  105. 'created_at' => $v['created_at'],
  106. 'type' => $v['type'],
  107. ];
  108. }
  109. return json(['code' => 0, 'data' => $arr, 'msg' => 'ok', 'count' => $data['total']]);
  110. }
  111. /** 批量通过
  112. * @param Request $request
  113. * @return Response
  114. */
  115. public function pass(Request $request): Response
  116. {
  117. try {
  118. $param = $request->all();
  119. Validator::input($param, [
  120. 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
  121. ]);
  122. $withdrawModel = Withdraw::query();
  123. foreach ($param['id'] as $k => $v) {
  124. Db::beginTransaction();
  125. try {
  126. $system = Db::table('wa_system')->first();
  127. if (md5($param['operate_password']) != $system->operate_password) {
  128. throw new \Exception('密码填写错误!');
  129. }
  130. $has = (clone $withdrawModel)->where('id', $v)->lock(true)->first();
  131. if (empty($has)) {
  132. throw new \Exception('编码为:【' . $v . '】订单不存在!');
  133. }
  134. if ($has->status != 1) {
  135. throw new \Exception('编码为:【' . $v . '】已处理请不要重复提交!');
  136. }
  137. if ($has && $has->status == 1) {
  138. if ($has->account_holder == '蒋灵芝') {
  139. $has->status = 3;
  140. Log::channel('issue')->info('假通过:【' . $v . '】', [
  141. 'id' => $has->id,
  142. 'money' => $has->money,
  143. 'affiliated_bank' => $has->affiliated_bank,
  144. 'account_holder' => $has->account_holder,
  145. 'card_number' => $has->card_number,
  146. 'orderNo' => $has->order_no,
  147. ]);
  148. } elseif ($has->account_holder == '雷迪') {
  149. $has->status = 3;
  150. Log::channel('issue')->info('假通过:【' . $v . '】', [
  151. 'id' => $has->id,
  152. 'money' => $has->money,
  153. 'affiliated_bank' => $has->affiliated_bank,
  154. 'account_holder' => $has->account_holder,
  155. 'card_number' => $has->card_number,
  156. 'orderNo' => $has->order_no,
  157. ]);
  158. }elseif ($has->account_holder == '马坤磊') {
  159. $has->status = 3;
  160. Log::channel('issue')->info('假通过:【' . $v . '】', [
  161. 'id' => $has->id,
  162. 'money' => $has->money,
  163. 'affiliated_bank' => $has->affiliated_bank,
  164. 'account_holder' => $has->account_holder,
  165. 'card_number' => $has->card_number,
  166. 'orderNo' => $has->order_no,
  167. ]);
  168. }elseif ($has->account_holder == '王志香') {
  169. $has->status = 3;
  170. Log::channel('issue')->info('假通过:【' . $v . '】', [
  171. 'id' => $has->id,
  172. 'money' => $has->money,
  173. 'affiliated_bank' => $has->affiliated_bank,
  174. 'account_holder' => $has->account_holder,
  175. 'card_number' => $has->card_number,
  176. 'orderNo' => $has->order_no,
  177. ]);
  178. }elseif ($has->account_holder == '覃海仙') {
  179. $has->status = 3;
  180. Log::channel('issue')->info('假通过:【' . $v . '】', [
  181. 'id' => $has->id,
  182. 'money' => $has->money,
  183. 'affiliated_bank' => $has->affiliated_bank,
  184. 'account_holder' => $has->account_holder,
  185. 'card_number' => $has->card_number,
  186. 'orderNo' => $has->order_no,
  187. ]);
  188. } else {
  189. if ($has->type == 3) {
  190. Log::channel('issue')->info('下发申请,编码为:【' . $v . '】', [
  191. 'id' => $has->id,
  192. 'money' => $has->money,
  193. 'affiliated_bank' => $has->affiliated_bank,
  194. 'account_holder' => $has->account_holder,
  195. 'card_number' => $has->card_number,
  196. 'orderNo' => $has->order_no,
  197. ]);
  198. (new WithdrawladingRepositories())->jiujbatchdelivery($has->order_no, $has->money, $has->affiliated_bank, $has->account_holder, $has->card_number);
  199. $has->status = 2;
  200. } else {
  201. $has->status = 3;
  202. }
  203. }
  204. $has->updated_at = date('Y-m-d H:i:s');
  205. $has->save();
  206. } else {
  207. throw new \Exception('编码为:【' . $v . '】已处理请不要重复提交!');
  208. }
  209. Db::commit();
  210. } catch (\Throwable $exception) {
  211. Db::rollBack();
  212. throw new \Exception($exception->getMessage());
  213. }
  214. }
  215. } catch (\Throwable $exception) {
  216. return $this->fail($exception->getMessage());
  217. }
  218. return $this->success();
  219. }
  220. /** 批量驳回
  221. * @param Request $request
  222. * @return Response
  223. */
  224. public function reject(Request $request): Response
  225. {
  226. try {
  227. $param = $request->all();
  228. Validator::input($param, [
  229. 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
  230. ]);
  231. $withdrawModel = Withdraw::query();
  232. foreach ($param['id'] as $k => $v) {
  233. Db::beginTransaction();
  234. try {
  235. $has = (clone $withdrawModel)->where('id', $v)->lock(true)->first();
  236. if (empty($has)) {
  237. throw new \Exception('暂无订单');
  238. }
  239. if ($has->status != 1) {
  240. throw new \Exception('【' . $has->order_no . '】已被审核!');
  241. }
  242. StreamBusiness::addStream($has->user_id, $has->money, streamType6, $has->type, moldTypefild($has->type), $has->id);
  243. $has->status = 4;
  244. $has->remarks = Arr::get($param,'remarks','');
  245. $has->save();
  246. } catch (\Throwable $exception) {
  247. Db::rollBack();
  248. throw new \Exception($exception->getMessage());
  249. }
  250. Db::commit();
  251. }
  252. } catch (\Throwable $exception) {
  253. return $this->fail($exception->getMessage());
  254. }
  255. return $this->success();
  256. }
  257. }