LgApplyJob.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\Lg;
  9. use app\utils\LgApi;
  10. use yii\base\BaseObject;
  11. use yii\queue\JobInterface;
  12. use app\models\Goods;
  13. use app\models\MdGoods;
  14. use app\models\Md;
  15. /**
  16. * 用于用户灵工进件后查询状态
  17. */
  18. class LgApplyJob extends BaseObject implements JobInterface
  19. {
  20. public int $id;
  21. public int $store_id;
  22. public int $retry;
  23. public function execute($queue)
  24. {
  25. if ($this->retry > 0) {
  26. $lg_success = Lg::find()->where(['id' => $this->id,'store_id'=>$this->store_id,'is_delete'=>0,'status'=>1])->one();
  27. if (!$lg_success){
  28. $queue_id = \queue_push(new LgApplyJob(['id'=>$this->id,'store_id'=>$this->store_id,'retry' => $this->retry--]), 60);
  29. }
  30. }
  31. try {
  32. /**
  33. * 查询待进件成功的记录
  34. */
  35. $lgApi = new LgApi($this->store_id);
  36. $lg = Lg::find()->where(['id' => $this->id,'store_id'=>$this->store_id,'is_delete'=>0])
  37. ->andWhere(['status'=>0])
  38. ->one();
  39. if ($lg){
  40. $post_data = [];
  41. $post_data['certCard'] = $lg['cert_card'];//身份证号
  42. $res = $lgApi->FlexibleQuery($post_data);
  43. //审核中
  44. if ($res[0]['status'] == 100 || $res[0]['status'] == 200){
  45. $lg->status = 0;
  46. $lg->updated_at = time();
  47. $lg->save();
  48. }
  49. //成功
  50. if ($res[0]['status'] == 300){
  51. $lg->status = 1;
  52. $lg->updated_at = time();
  53. $lg->save();
  54. }
  55. //失败
  56. if ($res[0]['status'] == 999){
  57. $lg->status = 2;
  58. $lg->updated_at = time();
  59. $lg->refuse_desc = $res['msg'];
  60. $lg->save();
  61. }
  62. }
  63. } catch(\Exception $e) {
  64. debug_log('--------auto-lg-apply-error---- '.$this->id.' ----auto-lg-apply-error--------' . $e->getMessage() . $e->getFile() . $e->getLine());
  65. }
  66. if (isset($queue_id) && !\Yii::$app->queue->isDone($queue_id)) {
  67. \Yii::$app->queue->remove($queue_id);
  68. }
  69. }
  70. }