LogisticsController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * rabbitMq 消费者
  4. */
  5. namespace console\controllers;
  6. use common\enums\ExpressEnum;
  7. use common\enums\StatusEnum;
  8. use common\helpers\FormatHelper;
  9. use common\models\common\MallSetting;
  10. use common\models\order\OrderExpressLog;
  11. use Yii;
  12. use yii\console\Controller;
  13. use yii\console\ExitCode;
  14. class LogisticsController extends Controller
  15. {
  16. public function actionUpdateExpress()
  17. {
  18. // 弃用定时任务查询,数量过大会导致curl并发导致定时任务堵塞
  19. echo '操作成功';
  20. return ExitCode::OK;
  21. try {
  22. $mall_list = \common\models\mall\Mall::getEnableMallList();
  23. foreach ($mall_list as $mall) {
  24. $mall_id = $mall['id'];
  25. $express_account = Yii::$app->services->setting->mall->get($mall_id,'logistics');
  26. $part = 1;
  27. $limit = 200;
  28. //测试 -start
  29. // $express_account['kdn_business_iD'] = '1757494';
  30. // $express_account['kdn_app_key'] = '49533209-91e9-4cb7-a55d-232169a6a91d';
  31. // $params = [];
  32. // $part_where = [['=', 'mall_id', $mall_id], ['=', 'table_express_status', ExpressEnum::TABLE_EXPRESS_WAIT]];
  33. // $part_data = self::batchGetExpressLog($params, $part, $limit);
  34. // self::updateLog($part_data, $express_account);
  35. //测试 -end
  36. $select = "id,mall_id,order_id,express_no,customer_name,express_code,express_id";
  37. $part_where = [['=', 'mall_id', $mall_id], ['=', 'status', StatusEnum::ENABLED], ['=', 'table_express_status', ExpressEnum::TABLE_EXPRESS_WAIT]];
  38. $params = ['where' => $part_where, 'select' => $select];
  39. while ($part_data = OrderExpressLog::batchGetExpressLog($params, $part, $limit)) {
  40. if ($part_data) {
  41. OrderExpressLog::updateLog($part_data, $express_account);
  42. }
  43. $part++;
  44. }
  45. }
  46. echo '操作成功';
  47. return ExitCode::OK;
  48. } catch (\Exception $e) {
  49. echo '物流更新任务处理出错:' . $e->getMessage() . PHP_EOL;
  50. return ExitCode::UNSPECIFIED_ERROR;
  51. }
  52. }
  53. }