| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
- <?php
- namespace plugin\admin\app\controller;
- use app\api\repositories\MoneyLogRepositories;
- use app\business\StreamBusiness;
- use Illuminate\Support\Arr;
- use plugin\admin\app\model\ApplyRecord;
- use plugin\admin\app\model\User;
- use plugin\admin\app\model\UserCark;
- use plugin\admin\app\repositories\WithdrawRepositories;
- 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 UserCarkController extends Crud
- {
- /**
- * @var UserCark
- */
- protected $model = null;
- /**
- * 构造函数
- * @return void
- */
- public function __construct()
- {
- $this->model = new UserCark();
- }
- /**
- * 浏览
- * @return Response
- */
- public function index(): Response
- {
- return view('usercark/index');
- }
- /**
- * 更新
- * @param Request $request
- * @return Response
- * @throws BusinessException
- */
- public function update(Request $request): Response
- {
- if ($request->method() === 'POST') {
- return parent::update($request);
- }
- return view('usercark/update');
- }
- /**查询收银余额
- * @param Request $request
- * @return Response
- */
- public function select(Request $request): Response
- {
- $param = $request->all();
- $data = UserCark::query()->where(function ($query) use ($param) {
- 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, 'is_buy')) {
- $query->where('is_buy', $param['is_buy']);
- }
- if (Arr::get($param, 'id')) {
- $query->where('id', $param['id']);
- }
- })->whereExists(function ($query) use ($param) {
- $query->from('wa_users')->whereRaw('wa_users.id=wa_user_social_cark.user_id');
- if (Arr::get($param, 'user_name')) {
- $query->where('name', 'like', '%' . $param['user_name'] . '%');
- }
- if (Arr::get($param, 'user_mobile')) {
- $query->where('mobile', 'like', '%' . $param['user_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->orderBy('updated_at', 'desc');
- }
- $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'],
- 'user_mobile' => $v['user_data']['mobile'],
- 'name' => $v['name'],
- 'number' => $v['number'],
- 'mobile' => $v['mobile'],
- 'card_num' => $v['card_num'],
- 'status' => $v['status'],
- 'created_at' => $v['created_at'],
- 'updated_at' => $v['updated_at'],
- 'address' => $v['address'],
- 'limit' => $v['limit'],
- 'use_limit' => $v['use_limit'],
- 'create_date' => $v['create_date'],
- 'flag' => $v['flag'],
- 'validity' => $v['validity'],
- 'safety_code' => $v['safety_code'],
- 'odd_numbers' => $v['odd_numbers'],
- 'ranking' => $v['ranking'],
- ];
- }
- 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('标识'),
- ]);
- $applyRecordModel = UserCark::query();
- foreach ($param['id'] as $k => $v) {
- Db::beginTransaction();
- try {
- $system = Db::table('wa_system')->first();
- $has = (clone $applyRecordModel)->where('id', $v)->lock(true)->first();
- if (empty($has)) {
- throw new \Exception('数据不存在!');
- }
- if ($has->status != 1) {
- throw new \Exception('数据已经处理!');
- }
- if ($has && $has->status == 1) {
- $result = [
- 'cardToken' => '4981e7b51d80078d95eb75f6a0113f8c',
- 'channel' => '100003',
- 'coupon' => '10035',
- 'amount' => 10,
- 'action' => 'applicationCard',
- 'user_number' => (string)$has->id,
- 'shopno' => '20001032',
- 'key' => 'A7F232D8364468ED10BC872B4E7EF4D3',
- ];
- $info = openssl_encrypt(json_encode($result), 'AES-256-ECB', 'A7F232D8364468ED10BC872B4E7EF4D3', OPENSSL_RAW_DATA);
- $info = base64_encode($info);
- $order_no = date('YmdHis') . mt_rand(1000, 9999);
- $arr = [
- 'shopno' => '20001032',
- 'wholeRequestId' => $order_no,
- 'data' => $info,
- ];
- $url = 'https://www.supplicardes.online/api/virtual_card';
- $data = Http::post($url, $arr)->array();
- Log::channel('kaicard')->info('开通虚拟卡', $data);
- if ($data['code'] == 1000) {
- $has->status = 2;
- $has->updated_at = date('Y-m-d H:i:s');
- $has->save();
- } else {
- throw new \Exception('开卡失败:' . $data['msg']);
- }
- } else {
- throw new \Exception('已处理请不要重复提交!');
- }
- 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 release(Request $request): Response
- {
- try {
- $param = $request->all();
- Validator::input($param, [
- 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
- ]);
- $applyRecordModel = UserCark::query();
- foreach ($param['id'] as $k => $v) {
- Db::beginTransaction();
- try {
- $system = Db::table('wa_system')->first();
- $has = (clone $applyRecordModel)->where('id', $v)->lock(true)->first();
- if (empty($has)) {
- throw new \Exception('数据不存在!');
- }
- if ($has->status == 1) {
- throw new \Exception('请先开卡!');
- }
- if ($has) {
- $order_no = date('YmdHis') . mt_rand(1000, 9999);
- $result = [
- 'shopno' => '20001032',
- 'key' => 'A7F232D8364468ED10BC872B4E7EF4D3',
- 'action' => 'card_list',
- 'user_number' => $has->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('更新虚拟卡', $data);
- if ($data['code'] == 1000) {
- foreach ($data['data'] as $jj => $ll) {
- if ($ll['user_number'] == $v) {
- $has->card_num = $ll['cardno'];
- $has->safety_code = $ll['CVV'];
- $has->validity = $ll['validity'];
- $has->limit = $ll['limit'];
- $has->use_limit = $ll['use_limit'];
- $has->flag = $ll['flag'];
- $has->create_date = $ll['create_date'];
- $has->taskId = $ll['taskId'];
- $has->user_number = $ll['user_number'];
- $has->status = 3;
- $has->updated_at = date('Y-m-d H:i:s');
- $has->save();
- }
- }
- } else {
- throw new \Exception('更新卡失败:' . $data['msg']);
- }
- } else {
- throw new \Exception('已处理请不要重复提交!');
- }
- 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 topup(Request $request): Response
- {
- try {
- $param = $request->all();
- Validator::input($param, [
- 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
- 'operate_money' => Validator::notEmpty()->setName('充值金额'),
- ]);
- $applyRecordModel = UserCark::query();
- foreach ($param['id'] as $k => $v) {
- Db::beginTransaction();
- try {
- $has = (clone $applyRecordModel)->where('id', $v)->lock(true)->first();
- if (empty($has)) {
- throw new \Exception('数据不存在!');
- }
- if ($has->status != 3) {
- throw new \Exception('卡未完成,不能充值!');
- }
- if ($has->status == 4) {
- throw new \Exception('已充值,请更新查看!');
- }
- if ($has) {
- $order_no = date('YmdHis') . mt_rand(1000, 9999);
- $result = [
- 'cardToken' => $has->taskId,
- 'amount' => (int)$param['operate_money'],
- 'cardno' => $has->card_num,
- 'shopno' => '20001032',
- 'key' => 'A7F232D8364468ED10BC872B4E7EF4D3',
- 'action' => 'rech_card',
- 'user_number' => $has->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) {
- (clone $applyRecordModel)->where('id', $v)->update(['status' => 4]);
- $topup = [
- 'login_admin_id' => admin_id(),
- 'user_id' => $has->user_id,
- 'user_social_cark_id' => $has->id,
- 'money' => $param['operate_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('数据错误,不存在卡!');
- }
- 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 again(Request $request): Response
- {
- try {
- $param = $request->all();
- Validator::input($param, [
- 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
- ]);
- $applyRecordModel = UserCark::query();
- foreach ($param['id'] as $k => $v) {
- Db::beginTransaction();
- try {
- $has = (clone $applyRecordModel)->where('id', $v)->lock(true)->first();
- if (empty($has)) {
- throw new \Exception('数据不存在!');
- }
- if ($has) {
- $result = [
- 'cardToken' => '4981e7b51d80078d95eb75f6a0113f8c',
- 'channel' => '100003',
- 'coupon' => '10035',
- 'amount' => 10,
- 'action' => 'applicationCard',
- 'user_number' => (string)$has->id,
- 'shopno' => '20001032',
- 'key' => 'A7F232D8364468ED10BC872B4E7EF4D3',
- ];
- $info = openssl_encrypt(json_encode($result), 'AES-256-ECB', 'A7F232D8364468ED10BC872B4E7EF4D3', OPENSSL_RAW_DATA);
- $info = base64_encode($info);
- $order_no = date('YmdHis') . mt_rand(1000, 9999);
- $arr = [
- 'shopno' => '20001032',
- 'wholeRequestId' => $order_no,
- 'data' => $info,
- ];
- $url = 'https://www.supplicardes.online/api/virtual_card';
- $data = Http::post($url, $arr)->array();
- Log::channel('kaicard')->info('开通虚拟卡', $data);
- if ($data['code'] == 1000) {
- $has->status = 2;
- $has->updated_at = date('Y-m-d H:i:s');
- $has->save();
- } else {
- throw new \Exception('开卡失败:' . $data['msg']);
- }
- } else {
- throw new \Exception('已处理请不要重复提交!');
- }
- 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 record(Request $request): Response
- {
- $param = $request->all();
- if ($request->isAjax()) {
- $param = $request->all();
- $has = UserCark::query()->where('id', $param['user_id'])->first();
- $result = [
- 'shopno' => '20001032',
- 'key' => 'A7F232D8364468ED10BC872B4E7EF4D3',
- 'action' => 'bill_list',
- 'cardno' => $has->card_num,
- 'p' => $param['page']
- ];
- $info = openssl_encrypt(json_encode($result), 'AES-256-ECB', 'A7F232D8364468ED10BC872B4E7EF4D3', OPENSSL_RAW_DATA);
- $info = base64_encode($info);
- $order_no = date('YmdHis') . mt_rand(1000, 9999);
- $arr = [
- 'shopno' => '20001032',
- 'wholeRequestId' => $order_no,
- 'data' => $info,
- ];
- $url = 'https://www.supplicardes.online/api/virtual_card';
- $data = Http::post($url, $arr)->array();
- if ($data['code'] != 1000) {
- throw new \Exception('获取失败:' . $data['msg']);
- }
- return json(['code' => 0, 'data' => $data['data'], 'msg' => 'ok', 'count' => $data['arr']['totalPages']]);
- }
- return view('usercark/record', $param);
- }
- }
|