OrderCommand.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\command;
  3. use app\extra\life\data\Store;
  4. use app\extra\life\SignUtil;
  5. use app\model\hx\HxAgent;
  6. use app\model\hx\HxOrderLife;
  7. use app\model\system\SystemConfig;
  8. use Symfony\Component\Console\Command\Command;
  9. use Symfony\Component\Console\Input\InputArgument;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. class OrderCommand extends Command
  13. {
  14. protected static string $defaultName = 'order:all';
  15. protected static string $defaultDescription = '定时获取线索订单';
  16. protected array $component_event_type_tags = [
  17. "2" => "表单提交",
  18. "17" => "智能电话_确认接通",
  19. "40" => "无效事件",
  20. "192" => "私信留资",
  21. "194" => "确认意向",
  22. "195" => "加为好友",
  23. "196" => "预付定金",
  24. "285" => "正价支付",
  25. "386" => "微信_添加企业微信",
  26. "527" => "到店",
  27. "536" => "团购留资",
  28. "537" => "私信意向",
  29. ];
  30. /**
  31. * @return void
  32. */
  33. protected function configure()
  34. {
  35. $this->addArgument('agentId', InputArgument::OPTIONAL, 'Name description');
  36. }
  37. protected function execute(InputInterface $input, OutputInterface $output): int
  38. {
  39. try {
  40. $output->writeln("获取线索订单====>".getDateFull());
  41. $agentId = $input->getArgument("agentId");
  42. if (empty($agentId)) {
  43. $output->writeln("配置错误1====>".getDateFull());
  44. return self::SUCCESS;
  45. }
  46. $config = (new HxAgent)->where("account",$agentId)->findOrEmpty();
  47. $config['version'] = "res";
  48. if ($config->isEmpty()) {
  49. $output->writeln("配置错误2====>".getDateFull());
  50. return self::SUCCESS;
  51. }
  52. $result = (new Store)->config($config->toArray())->token()->asyncClue($config['account']);
  53. $mode = new HxOrderLife;
  54. if (!empty($result['clue_data'])) {
  55. foreach ($result['clue_data'] as $k => $v) {
  56. if ($v['order_id'] > 0 && $v['order_status'] == '履约中') {
  57. $v['telephone'] = (new SignUtil)->init($config['secret'])->decryptAES($v['telephone']);
  58. $v['agent_id'] = $config['agent_id'];
  59. $order = $mode->where("order_id",$v['order_id'])->findOrEmpty();
  60. if ($order->isEmpty()) {
  61. echo getDateFull()."==新增订单=={$v['order_id']}==\n";
  62. $order->strict(false)->insertGetId($v);
  63. } else {
  64. echo getDateFull()."==更新订单=={$v['order_id']}==\n";
  65. $order->strict(false)->save($v);
  66. }
  67. } else {
  68. echo getDateFull()."==跳过订单=={$v['order_id']}==\n";
  69. }
  70. }
  71. } else {
  72. echo getDateFull()."==该账号下无订单=={$agentId}==\n";
  73. }
  74. } catch (\Throwable $throwable) {
  75. echo getDateFull()."==获取线索订单失败\n";
  76. echo $throwable->getMessage()."\n";
  77. echo $throwable->getFile()."【".$throwable->getLine()."】\n";
  78. }
  79. return self::SUCCESS;
  80. }
  81. }