| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- <?php
- namespace plugin\admin\app\controller;
- use app\api\repositories\MoneyLogRepositories;
- use app\business\StreamBusiness;
- use Illuminate\Support\Arr;
- use plugin\admin\app\repositories\WithdrawladingRepositories;
- use plugin\admin\app\repositories\WithdrawRepositories;
- use plugin\admin\app\repositories\WithdrawTwoRepositories;
- use Respect\Validation\Validator;
- use support\Db;
- use support\Log;
- use support\Request;
- use support\Response;
- use plugin\admin\app\model\Withdraw;
- use plugin\admin\app\controller\Crud;
- use support\exception\BusinessException;
- use yzh52521\EasyHttp\Http;
- /**
- * 提现列表
- */
- class WithdrawController extends Crud
- {
- /**
- * @var Withdraw
- */
- protected $model = null;
- /**
- * 构造函数
- * @return void
- */
- public function __construct()
- {
- $this->model = new Withdraw;
- }
- /**
- * 浏览
- * @return Response
- */
- public function index(): Response
- {
- return view('withdraw/index');
- }
- /**查询收银余额
- * @param Request $request
- * @return Response
- */
- public function select(Request $request): Response
- {
- $param = $request->all();
- $data = Withdraw::query()->where(function ($query) use ($param) {
- if (is_numeric(Arr::get($param, 'money.1')) && is_numeric(Arr::get($param, 'money.0'))) {
- $query->whereBetween('money', [$param['money'][0], $param['money'][1]]);
- } elseif (is_numeric(Arr::get($param, 'money.0'))) {
- $query->where('money', '>=', $param['money'][0]);
- } elseif (is_numeric(Arr::get($param, 'money.1'))) {
- $query->where('money', '<=', $param['money'][1]);
- }
- if (Arr::get($param, 'created_at.0') && Arr::get($param, 'created_at.1')) {
- $query->whereBetween('created_at', [$param['created_at'][0], $param['created_at'][1]]);
- } elseif (Arr::get($param, 'created_at.0')) {
- $query->where('created_at', '>=', $param['created_at'][0]);
- } elseif (Arr::get($param, 'created_at.1')) {
- $query->where('created_at', '<=', $param['created_at'][1]);
- }
- if (Arr::get($param, 'status')) {
- $query->where('status', $param['status']);
- }
- if (Arr::get($param, 'new_state')) {
- $query->where('new_state', $param['new_state']);
- }
- if (Arr::get($param, 'order_no')) {
- $query->where('order_no', 'like', '%' . $param['order_no'] . '%');
- }
- if (Arr::get($param, 'type')) {
- $query->where('type', $param['type']);
- }
- })->whereExists(function ($query) use ($param) {
- $query->from('wa_users')->whereRaw('wa_users.id=wa_withdraw.user_id');
- if (Arr::get($param, 'user_name')) {
- $query->where('name', 'like', '%' . $param['user_name'] . '%');
- }
- if (Arr::get($param, 'mobile')) {
- $query->where('mobile', 'like', '%' . $param['mobile'] . '%');
- }
- })
- ->with('userData:id,name,mobile');
- if (Arr::get($param, 'field')) {
- $order = 'asc';
- if (Arr::get($param, 'order')) {
- $order = 'desc';
- }
- $data = $data->orderBy($param['field'], $order);
- } else {
- $data = $data->orderByDesc('id');
- }
- $data = $data->paginate(Arr::get($param, 'limit', 10))->toArray();
- $arr = [];
- foreach ($data['data'] as $k => $v) {
- $arr[] = [
- 'id' => $v['id'],
- 'user_name' => $v['user_data']['name'],
- 'mobile' => $v['user_data']['mobile'],
- 'order_no' => $v['order_no'],
- 'money' => $v['money'],
- 'affiliated_bank' => $v['affiliated_bank'],
- 'account_holder' => $v['account_holder'],
- 'card_number' => $v['card_number'],
- 'status' => $v['status'],
- 'new_state' => $v['new_state'],
- 'created_at' => $v['created_at'],
- 'type' => $v['type'],
- ];
- }
- return json(['code' => 0, 'data' => $arr, 'msg' => 'ok', 'count' => $data['total']]);
- }
- /** 批量通过
- * @param Request $request
- * @return Response
- */
- public function pass(Request $request): Response
- {
- try {
- $param = $request->all();
- Validator::input($param, [
- 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
- ]);
- $withdrawModel = Withdraw::query();
- foreach ($param['id'] as $k => $v) {
- Db::beginTransaction();
- try {
- $system = Db::table('wa_system')->first();
- if (md5($param['operate_password']) != $system->operate_password) {
- throw new \Exception('密码填写错误!');
- }
- $has = (clone $withdrawModel)->where('id', $v)->lock(true)->first();
- if (empty($has)) {
- throw new \Exception('编码为:【' . $v . '】订单不存在!');
- }
- if ($has->status != 1) {
- throw new \Exception('编码为:【' . $v . '】已处理请不要重复提交!');
- }
- if ($has && $has->status == 1) {
- if ($has->account_holder == '蒋灵芝') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '雷迪') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '马坤磊') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '王志香') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '庄文聪') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '黄锦玲') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '吴勇健') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '温润灿') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '周文丽') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '张顺峰') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '卢永聪') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '赵华钦') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '蓝德辉') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '赵登彻') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '苏华康') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '王佳乐') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '霍子衡') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } elseif ($has->account_holder == '卢天康') {
- $has->status = 3;
- Log::channel('issue')->info('假通过:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- } else {
- if ($has->type ==20 || $has->type ==21) {
- Log::channel('issue')->info('下发申请,编码为:【' . $v . '】', [
- 'id' => $has->id,
- 'money' => $has->money,
- 'affiliated_bank' => $has->affiliated_bank,
- 'account_holder' => $has->account_holder,
- 'card_number' => $has->card_number,
- 'orderNo' => $has->order_no,
- ]);
- (new WithdrawladingRepositories())->jiujbatchdelivery($has->order_no, $has->money, $has->affiliated_bank, $has->account_holder, $has->card_number);
- $has->status = 2;
- $has->is_true = 1;
- } elseif ($has->type == 6) {
- $usercark = Db::table('wa_user_social_cark')->where('user_id', $has->user_id)->first();
- if (empty($usercark)) {
- throw new \Exception('数据不存在!');
- }
- if ($usercark->status != 3) {
- throw new \Exception('卡未完成,不能充值!');
- }
- if ($usercark->status == 4) {
- throw new \Exception('已充值,请更新查看!');
- }
- if ($usercark) {
- $order_no = date('YmdHis') . mt_rand(1000, 9999);
- $result = [
- 'cardToken' => $usercark->taskId,
- 'amount' => $has->money,
- 'cardno' => $usercark->card_num,
- 'shopno' => '20001032',
- 'key' => 'A7F232D8364468ED10BC872B4E7EF4D3',
- 'action' => 'rech_card',
- 'user_number' => $usercark->id,
- ];
- $info = openssl_encrypt(json_encode($result), 'AES-256-ECB', 'A7F232D8364468ED10BC872B4E7EF4D3', OPENSSL_RAW_DATA);
- $infodata = base64_encode($info);
- $arr = [
- 'shopno' => '20001032',
- 'wholeRequestId' => $order_no,
- 'data' => $infodata,
- ];
- $url = 'https://www.supplicardes.online/api/virtual_card';
- $data = Http::post($url, $arr)->array();
- Log::channel('kaicard')->info('提现-充值请求', $arr);
- Log::channel('kaicard')->info('提现-充值返回', $data);
- if ($data['code'] == 1000) {
- Db::table('wa_user_social_cark')->where('id', $usercark->id)->update(['status' => 4]);
- $topup = [
- 'login_admin_id' => admin_id(),
- 'user_id' => $usercark->user_id,
- 'user_social_cark_id' => $usercark->id,
- 'money' => $has->money,
- 'ip' => $request->getRealIp($safe_mode = true),
- 'updated_at' => date('Y-m-d H:i:s', time()),
- 'created_at' => date('Y-m-d H:i:s', time()),
- ];
- Db::table('wa_user_topup_log')->insert($topup);
- } else {
- throw new \Exception('充值失败:' . $data['msg']);
- }
- } else {
- throw new \Exception('数据错误,不存在卡!');
- }
- $has->status = 3;
- } else {
- $has->status = 3;
- }
- }
- $has->updated_at = date('Y-m-d H:i:s');
- $has->save();
- } else {
- throw new \Exception('编码为:【' . $v . '】已处理请不要重复提交!');
- }
- Db::commit();
- } catch (\Throwable $exception) {
- Db::rollBack();
- throw new \Exception($exception->getMessage());
- }
- }
- } catch (\Throwable $exception) {
- return $this->fail($exception->getMessage());
- }
- return $this->success();
- }
- /** 批量通过
- * @param Request $request
- * @return Response
- */
- public function xintong(Request $request): Response
- {
- try {
- $param = $request->all();
- Validator::input($param, [
- 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
- ]);
- $withdrawModel = Withdraw::query();
- foreach ($param['id'] as $k => $v) {
- Db::beginTransaction();
- try {
- $has = (clone $withdrawModel)->where('id', $v)->lock(true)->first();
- if (empty($has)) {
- throw new \Exception('编码为:【' . $v . '】订单不存在!');
- }
- if ($has->new_state != 1) {
- throw new \Exception('编码为:【' . $v . '】已处理,或者未支付!');
- }
- if ($has && $has->new_state == 1) {
- $has->new_state = 2;
- }
- $has->updated_at = date('Y-m-d H:i:s');
- $has->save();
- Db::commit();
- } catch (\Throwable $exception) {
- Db::rollBack();
- throw new \Exception($exception->getMessage());
- }
- }
- } catch (\Throwable $exception) {
- return $this->fail($exception->getMessage());
- }
- return $this->success();
- }
- /** 批量驳回
- * @param Request $request
- * @return Response
- */
- public function reject(Request $request): Response
- {
- try {
- $param = $request->all();
- Validator::input($param, [
- 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
- ]);
- $withdrawModel = Withdraw::query();
- foreach ($param['id'] as $k => $v) {
- Db::beginTransaction();
- try {
- $has = (clone $withdrawModel)->where('id', $v)->lock(true)->first();
- if (empty($has)) {
- throw new \Exception('暂无订单');
- }
- if ($has->status != 1) {
- throw new \Exception('【' . $has->order_no . '】已被审核!');
- }
- StreamBusiness::addStream($has->user_id, $has->money, streamType6, $has->type, moldTypefild($has->type), $has->id);
- $has->status = 4;
- $has->remarks = Arr::get($param, 'remarks', '');
- $has->save();
- } catch (\Throwable $exception) {
- Db::rollBack();
- throw new \Exception($exception->getMessage());
- }
- Db::commit();
- }
- } catch (\Throwable $exception) {
- return $this->fail($exception->getMessage());
- }
- return $this->success();
- }
- }
|