LgCashJob.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\jobs;
  8. use app\models\AccountLog;
  9. use app\models\Cash;
  10. use app\models\Lg;
  11. use app\models\LocalDeliveryCash;
  12. use app\models\LocalDeliveryCourier;
  13. use app\models\User;
  14. use app\utils\LgApi;
  15. use yii\base\BaseObject;
  16. use yii\queue\JobInterface;
  17. use app\models\Goods;
  18. use app\models\MdGoods;
  19. use app\models\Md;
  20. /**
  21. * 用于用户灵工提现后查询状态
  22. */
  23. class LgCashJob extends BaseObject implements JobInterface
  24. {
  25. public int $id;
  26. public int $store_id;
  27. public int $type;//0分销,3股东或2+1,8区域分红,7充值,9入驻商,2门店,12骑手,17全域分红
  28. public int $retry;
  29. public function execute($queue)
  30. {
  31. if ($this->retry > 0) {
  32. $cash_success = Cash::find()->where(['id'=>$this->id,'store_id' => $this->store_id,'status'=>1])->one();
  33. if (!$cash_success){
  34. $queue_id = \queue_push(new LgCashJob(['id'=>$this->id,'store_id'=>$this->store_id,'type'=>$this->type,'retry' => $this->retry--]), 60);
  35. }
  36. }
  37. try {
  38. /**
  39. * 查询待提现成功的记录
  40. */
  41. $lgApi = new LgApi($this->store_id);
  42. //如果是骑手
  43. if ($this->type == 12){
  44. $cash_info = LocalDeliveryCash::find()->where(['id'=>$this->id,'store_id' => $this->store_id,'status'=>6
  45. ])->one();
  46. if($cash_info){
  47. $post_data = [];
  48. $post_data['outTradeNo'] = $cash_info['order_no'];//提现单号
  49. $res = $lgApi->FlexiblePayQuery($post_data);
  50. //审核中
  51. if ($res['status'] == 100 || $res['status'] == 200){
  52. $cash_info->updated_at = time();
  53. $cash_info->save();
  54. }
  55. //成功
  56. if ($res['status'] == 300){
  57. $cash_info->status = 2;
  58. $cash_info->updated_at = time();
  59. $cash_info->save();
  60. }
  61. //失败
  62. if ($res['status'] == 999){
  63. $cash_info->status = 3;
  64. $cash_info->updated_at = time();
  65. $cash_info->lg_refuse_desc = $res['msg'];
  66. if ($cash_info->save()){
  67. $courier = LocalDeliveryCourier::findOne(['saas_user_id' => $cash_info['saas_user_id']]);
  68. //把提现的钱返还
  69. $courier->updateCounters(['money' => $cash_info->price]);
  70. }
  71. }
  72. }
  73. }
  74. //如果是cash表
  75. if (in_array($this->type,[0,2,3,7,8,9,17])){
  76. $cash_info = Cash::find()->where(['id'=>$this->id,'store_id' => $this->store_id,'status'=>6
  77. ])->one();
  78. if($cash_info){
  79. $post_data = [];
  80. $post_data['outTradeNo'] = $cash_info['order_no'];//提现单号
  81. $res = $lgApi->FlexiblePayQuery($post_data);
  82. //审核中
  83. if ($res['status'] == 100 || $res['status'] == 200){
  84. $cash_info->updated_at = time();
  85. $cash_info->save();
  86. }
  87. //成功
  88. if ($res['status'] == 300){
  89. $cash_info->status = 2;
  90. $cash_info->updated_at = time();
  91. $cash_info->save();
  92. }
  93. //失败
  94. if ($res['status'] == 999){
  95. $cash_info->status = 3;
  96. $cash_info->updated_at = time();
  97. $cash_info->lg_refuse_desc = $res['msg'];
  98. if ($cash_info->save()){
  99. $user = User::findOne(['id' => $cash_info['user_id']]);
  100. //把提现的钱返还
  101. if (in_array($cash_info->cash_type,[0,3,8])) {//分销,股东,2+1,区域分红
  102. $user->updateCounters(['price' => $cash_info->price]);
  103. }elseif ($cash_info->cash_type == 2) {//门店
  104. $md = Md::findOne($cash_info->md_id);
  105. $md->updateCounters(['cash_profit' => $cash_info->price]);
  106. }elseif ($cash_info->cash_type == 17) {//全域提现
  107. $user->updateCounters(['global_money' => $cash_info->price]);
  108. }elseif ($cash_info->cash_type == Cash::IS_CASH_TYPE_BALANCE) {//充值
  109. $saveLog = AccountLog::saveLog($cash_info->user_id, $cash_info->price, AccountLog::TYPE_BALANCE, AccountLog::LOG_TYPE_INCOME, 0, 0, "余额提现被驳回,单号:{$cash_info->order_no}");
  110. if (!$saveLog) {
  111. debug_log('网络异常,账户保存失败');
  112. }
  113. } elseif ($cash_info->cash_type == Cash::IS_CASH_TYPE_MCH) {//入驻商
  114. $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);
  115. if ($saveLog['code']) {
  116. debug_log($saveLog);
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. } catch(\Exception $e) {
  124. debug_log('--------auto-lg-cash-error---- '.$this->id.' ----auto-lg-cash-error--------' . $e->getMessage() . $e->getFile() . $e->getLine());
  125. }
  126. if (isset($queue_id) && !\Yii::$app->queue->isDone($queue_id)) {
  127. \Yii::$app->queue->remove($queue_id);
  128. }
  129. }
  130. }