| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\jobs;
- use app\models\AccountLog;
- use app\models\Cash;
- use app\models\Lg;
- use app\models\LocalDeliveryCash;
- use app\models\LocalDeliveryCourier;
- use app\models\User;
- use app\utils\LgApi;
- use yii\base\BaseObject;
- use yii\queue\JobInterface;
- use app\models\Goods;
- use app\models\MdGoods;
- use app\models\Md;
- /**
- * 用于用户灵工提现后查询状态
- */
- class LgCashJob extends BaseObject implements JobInterface
- {
- public int $id;
- public int $store_id;
- public int $type;//0分销,3股东或2+1,8区域分红,7充值,9入驻商,2门店,12骑手,17全域分红
- public int $retry;
- public function execute($queue)
- {
- if ($this->retry > 0) {
- $cash_success = Cash::find()->where(['id'=>$this->id,'store_id' => $this->store_id,'status'=>1])->one();
- if (!$cash_success){
- $queue_id = \queue_push(new LgCashJob(['id'=>$this->id,'store_id'=>$this->store_id,'type'=>$this->type,'retry' => $this->retry--]), 60);
- }
- }
- try {
- /**
- * 查询待提现成功的记录
- */
- $lgApi = new LgApi($this->store_id);
- //如果是骑手
- if ($this->type == 12){
- $cash_info = LocalDeliveryCash::find()->where(['id'=>$this->id,'store_id' => $this->store_id,'status'=>6
- ])->one();
- if($cash_info){
- $post_data = [];
- $post_data['outTradeNo'] = $cash_info['order_no'];//提现单号
- $res = $lgApi->FlexiblePayQuery($post_data);
- //审核中
- if ($res['status'] == 100 || $res['status'] == 200){
- $cash_info->updated_at = time();
- $cash_info->save();
- }
- //成功
- if ($res['status'] == 300){
- $cash_info->status = 2;
- $cash_info->updated_at = time();
- $cash_info->save();
- }
- //失败
- if ($res['status'] == 999){
- $cash_info->status = 3;
- $cash_info->updated_at = time();
- $cash_info->lg_refuse_desc = $res['msg'];
- if ($cash_info->save()){
- $courier = LocalDeliveryCourier::findOne(['saas_user_id' => $cash_info['saas_user_id']]);
- //把提现的钱返还
- $courier->updateCounters(['money' => $cash_info->price]);
- }
- }
- }
- }
- //如果是cash表
- if (in_array($this->type,[0,2,3,7,8,9,17])){
- $cash_info = Cash::find()->where(['id'=>$this->id,'store_id' => $this->store_id,'status'=>6
- ])->one();
- if($cash_info){
- $post_data = [];
- $post_data['outTradeNo'] = $cash_info['order_no'];//提现单号
- $res = $lgApi->FlexiblePayQuery($post_data);
- //审核中
- if ($res['status'] == 100 || $res['status'] == 200){
- $cash_info->updated_at = time();
- $cash_info->save();
- }
- //成功
- if ($res['status'] == 300){
- $cash_info->status = 2;
- $cash_info->updated_at = time();
- $cash_info->save();
- }
- //失败
- if ($res['status'] == 999){
- $cash_info->status = 3;
- $cash_info->updated_at = time();
- $cash_info->lg_refuse_desc = $res['msg'];
- if ($cash_info->save()){
- $user = User::findOne(['id' => $cash_info['user_id']]);
- //把提现的钱返还
- if (in_array($cash_info->cash_type,[0,3,8])) {//分销,股东,2+1,区域分红
- $user->updateCounters(['price' => $cash_info->price]);
- }elseif ($cash_info->cash_type == 2) {//门店
- $md = Md::findOne($cash_info->md_id);
- $md->updateCounters(['cash_profit' => $cash_info->price]);
- }elseif ($cash_info->cash_type == 17) {//全域提现
- $user->updateCounters(['global_money' => $cash_info->price]);
- }elseif ($cash_info->cash_type == Cash::IS_CASH_TYPE_BALANCE) {//充值
- $saveLog = AccountLog::saveLog($cash_info->user_id, $cash_info->price, AccountLog::TYPE_BALANCE, AccountLog::LOG_TYPE_INCOME, 0, 0, "余额提现被驳回,单号:{$cash_info->order_no}");
- if (!$saveLog) {
- debug_log('网络异常,账户保存失败');
- }
- } elseif ($cash_info->cash_type == Cash::IS_CASH_TYPE_MCH) {//入驻商
- $saveLog = \app\models\MchAccountLog::saveLog($cash_info->mch_id, $cash_info->user_id, $cash_info->price, AccountLog::LOG_TYPE_INCOME, 0, '', "提现被驳回,单号:{$cash_info->order_no}", 0, 0);
- if ($saveLog['code']) {
- debug_log($saveLog);
- }
- }
- }
- }
- }
- }
- } catch(\Exception $e) {
- debug_log('--------auto-lg-cash-error---- '.$this->id.' ----auto-lg-cash-error--------' . $e->getMessage() . $e->getFile() . $e->getLine());
- }
- if (isset($queue_id) && !\Yii::$app->queue->isDone($queue_id)) {
- \Yii::$app->queue->remove($queue_id);
- }
- }
- }
|