| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\AcceptorModel;
- use App\Models\AccountLogModel;
- use App\Models\BalanceLogModel;
- use App\Models\MerchantModel;
- use App\Services\Api\FinanceService;
- use App\Services\Api\MessageService;
- use App\Services\BaseService;
- use App\Services\WalletService;
- use Illuminate\Support\Facades\DB;
- /**
- * 承兑商管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Common
- */
- class BalanceLogService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new BalanceLogModel();
- }
- /**
- * 获取列表
- * @param $params 参数
- * @param int $pageSize 分页大小:默认 15
- * @return array
- */
- public function getDataList($params, $pageSize = 10, $field = [])
- {
- $where = ['a.mark' => 1];
- $query = $this->model->with(['member'])
- ->from('balance_logs as a')
- ->leftJoin('member as b', 'b.id', 'a.user_id')
- ->where($where)
- ->select($field ? $field : ['a.*']);
- if (isset($params['keyword']) && $params['keyword'] != '') {
- $query->where(function ($query) use ($params) {
- $kw = isset($params['keyword']) ? trim($params['keyword']) : '';
- if ($kw) {
- $query->where('b.nickname', 'like', "%{$params['keyword']}%")->orWhere('b.realname', 'like', "%{$params['keyword']}%")->orWhere('b.username', 'like', "%{$params['keyword']}%");
- }
- });
- }
- if (isset($params['order_no']) && $params['order_no'] != '') {
- $query->where('a.order_no', 'like', "%{$params['order_no']}%");
- }
- if (isset($params['user_type'])) {
- if (is_array($params['user_type'])) {
- $query->whereIn('a.type', $params['user_type']);
- } else {
- if ($params['user_type'] != '') {
- $query->where('a.user_type', $params['user_type']);
- }
- }
- }
- if (isset($params['type'])) {
- if (is_array($params['type'])) {
- $query->whereIn('a.type', $params['type']);
- } else {
- if ($params['type'] != '') {
- $query->where('a.type', $params['type']);
- }
- }
- }
- if (isset($params['pay_type'])) {
- if (is_array($params['pay_type'])) {
- $query->whereIn('a.pay_type', $params['pay_type']);
- } else {
- if ($params['pay_type'] != '') {
- $query->where('a.pay_type', $params['pay_type']);
- }
- }
- }
- if (isset($params['pay_status'])) {
- if (is_array($params['pay_status'])) {
- $query->whereIn('a.pay_status', $params['pay_status']);
- } else {
- if ($params['pay_status'] != '') {
- $query->where('a.pay_status', $params['pay_status']);
- }
- }
- }
- if (isset($params['coin_type'])) {
- if (is_array($params['coin_type'])) {
- $query->whereIn('a.coin_type', $params['coin_type']);
- } else {
- if ($params['coin_type'] != '') {
- $query->where('a.coin_type', $params['coin_type']);
- }
- }
- }
- if (isset($params['status'])) {
- if (is_array($params['status'])) {
- $query->whereIn('a.status', $params['status']);
- } else {
- if ($params['status'] != '') {
- $query->where('a.status', $params['status']);
- }
- }
- }
- $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- if ($list) {
- foreach ($list['data'] as &$item) {
- $item['create_time_text'] = $item['create_time'] ? datetime($item['create_time']) : '';
- }
- }
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- }
- /**
- * 添加会编辑会员
- * @return array
- * @since 2020/11/11
- * @author laravel开发员
- */
- public function edit()
- {
- // 请求参数
- $data = request()->all();
- $balanceLog = BalanceLogModel::where(['id' => $data['id']])->first();
- DB::beginTransaction();
- try {
- // 提现 审核通过
- if ($balanceLog['type'] = 2 && isset($data['status'])) {
- if ($data['status'] == 2) {
- if ($data['user_type'] == 1) {
- // 会员
- $this->withdrawMember($data);
- } else if ($data['user_type'] == 2) {
- // 商家
- $this->withdrawMerchat($data);
- } else if ($data['user_type'] == 3) {
- // 承兑商
- $this->withdrawAcceptor($data);
- }
- } else if ($data['status'] == 3) {
- $money = $data['money'];
- $userId = $data['user_id'];
- $accountLog = AccountLogModel::where(['source_order_no' => $balanceLog['order_no']])->first();
- if ($accountLog) {
- AccountLogModel::where(['source_order_no' => $balanceLog])->update([
- 'status' => 3,
- 'update_time' => time(),
- ]);
- $updateData = ['usdt' => DB::raw("usdt - {$money}"), 'update_time' => time()];
- if (!MerchantModel::where(['user_id' => $userId, 'mark' => 1])->update($updateData)) {
- DB::rollBack();
- return message('审核不通过操作失败');
- }
- }
- }
- }
- } catch (\Exception $e) {
- DB::rollBack();
- return message('操作失败');
- }
- DB::commit();
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- private function withdrawMember(array $data)
- {
- $trcUrl = $data['trc_url'];
- $realUsdt = $data['actual_money'];
- $orderNo = $data['order_no'];
- $userType = $data['user_type'];
- $dateTime = $dateTime = date('Y-m-d H:i:s');
- $money = $data['money'];
- $userId = $data['user_id'];
- $fee = $data['fee'];
- // 打款处理
- $result = WalletService::make()->usdtTrcTransfer($trcUrl, $realUsdt);
- $txID = isset($result['txId']) ? $result['txId'] : '';
- $payAddress = isset($result['address']) ? $result['address'] : '';
- if ($txID && $payAddress) {
- $updateData = ['hash' => $txID, 'wallet_url' => $payAddress, 'audit_remark' => '审核打款', 'status' => 2, 'update_time' => time()];
- if (BalanceLogModel::where(['order_no' => $orderNo, 'user_type' => $userType])->update($updateData)) {
- $title = $userType == 1 ? 'USDT余额提现审核成功' : '商户余额提现审核成功';
- $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额审核成功,请耐心等候打款到账!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT商户余额审核成功,请耐心等候打款到账!!!";
- MessageService::make()->pushMessage($userId, $title, $message);
- AccountLogModel::where(['source_order_no' => $orderNo])->update(['hash' => $txID, 'update_time' => time()]);
- // 平台明细
- $log = [
- 'user_id' => 0,
- 'source_id' => $userId,
- 'source_order_no' => $orderNo,
- 'type' => 5,
- 'coin_type' => 1,
- 'user_type' => 4,
- 'money' => $fee,
- 'actual_money' => $fee,
- 'balance' => 0,
- 'create_time' => time(),
- 'update_time' => time(),
- 'hash' => $txID,
- 'remark' => "USDT余额提现",
- 'status' => 1,
- 'mark' => 1,
- ];
- AccountLogModel::insertGetId($log);
- // 平台流水
- FinanceService::make()->saveLog(0, $fee, 1);
- }
- }
- }
- private function withdrawMerchat(array $data)
- {
- $trcUrl = $data['trc_url'];
- $realUsdt = $data['actual_money'];
- $orderNo = $data['order_no'];
- $userType = $data['user_type'];
- $dateTime = $dateTime = date('Y-m-d H:i:s');
- $money = $data['money'];
- $userId = $data['user_id'];
- $fee = $data['fee'];
- // 打款处理
- $result = WalletService::make()->usdtTrcTransfer($trcUrl, $realUsdt);
- $txID = isset($result['txId']) ? $result['txId'] : '';
- $payAddress = isset($result['address']) ? $result['address'] : '';
- if ($txID && $payAddress) {
- $updateData = ['hash' => $txID, 'wallet_url' => $payAddress, 'audit_remark' => '审核打款', 'status' => 2, 'update_time' => time()];
- if (BalanceLogModel::where(['order_no' => $orderNo, 'user_type' => $userType])->update($updateData)) {
- $title = $userType == 1 ? 'USDT余额提现审核成功' : '商户余额提现审核成功';
- $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额审核成功,请耐心等候打款到账!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT商户余额审核成功,请耐心等候打款到账!!!";
- MessageService::make()->pushMessage($userId, $title, $message);
- AccountLogModel::where(['source_order_no' => $orderNo])->update(['hash' => $txID, 'update_time' => time()]);
- // 平台明细
- $log = [
- 'user_id' => 0,
- 'source_id' => $userId,
- 'source_order_no' => $orderNo,
- 'type' => 5,
- 'coin_type' => 1,
- 'user_type' => 4,
- 'money' => $fee,
- 'actual_money' => $fee,
- 'balance' => 0,
- 'create_time' => time(),
- 'update_time' => time(),
- 'hash' => $txID,
- 'remark' => "USDT余额提现",
- 'status' => 1,
- 'mark' => 1,
- ];
- AccountLogModel::insertGetId($log);
- // 平台流水
- FinanceService::make()->saveLog(0, $fee, 1);
- }
- }
- }
- private function withdrawAcceptor(array $data)
- {
- $trcUrl = $data['trc_url'];
- $realUsdt = $data['actual_money'];
- $orderNo = $data['order_no'];
- $userType = $data['user_type'];
- $dateTime = $dateTime = date('Y-m-d H:i:s');
- $money = $data['money'];
- $userId = $data['user_id'];
- $fee = $data['fee'];
- // 打款处理
- $result = WalletService::make()->usdtTrcTransfer($trcUrl, $realUsdt);
- $txID = isset($result['txId']) ? $result['txId'] : '';
- $payAddress = isset($result['address']) ? $result['address'] : '';
- if ($txID && $payAddress) {
- $updateData = ['hash' => $txID, 'wallet_url' => $payAddress, 'audit_remark' => '审核打款', 'status' => 2, 'update_time' => time()];
- if (BalanceLogModel::where(['order_no' => $orderNo, 'user_type' => $userType])->update($updateData)) {
- $title = $userType == 1 ? 'USDT余额提现审核成功' : '承兑商余额提现审核成功';
- $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额审核成功,请耐心等候打款到账!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT承兑商余额审核成功,请耐心等候打款到账!!!";
- MessageService::make()->pushMessage($userId, $title, $message, 3);
- AccountLogModel::where(['source_order_no' => $orderNo])->update(['hash' => $txID, 'update_time' => time()]);
- // 平台明细
- $log = [
- 'user_id' => 0,
- 'source_id' => $userId,
- 'source_order_no' => $orderNo,
- 'type' => 5,
- 'coin_type' => 1,
- 'user_type' => 4,
- 'money' => $fee,
- 'actual_money' => $fee,
- 'balance' => 0,
- 'create_time' => time(),
- 'update_time' => time(),
- 'hash' => $txID,
- 'remark' => "USDT余额提现",
- 'status' => 1,
- 'mark' => 1,
- ];
- AccountLogModel::insertGetId($log);
- // 平台流水
- FinanceService::make()->saveLog(0, $fee, 1);
- }
- }
- }
- }
|