| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\command;
- use app\extra\life\data\Store;
- use app\extra\life\SignUtil;
- use app\model\hx\HxAgent;
- use app\model\hx\HxOrderLife;
- use app\model\system\SystemConfig;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- class OrderCommand extends Command
- {
- protected static string $defaultName = 'order:all';
- protected static string $defaultDescription = '定时获取线索订单';
- protected array $component_event_type_tags = [
- "2" => "表单提交",
- "17" => "智能电话_确认接通",
- "40" => "无效事件",
- "192" => "私信留资",
- "194" => "确认意向",
- "195" => "加为好友",
- "196" => "预付定金",
- "285" => "正价支付",
- "386" => "微信_添加企业微信",
- "527" => "到店",
- "536" => "团购留资",
- "537" => "私信意向",
- ];
- /**
- * @return void
- */
- protected function configure()
- {
- $this->addArgument('agentId', InputArgument::OPTIONAL, 'Name description');
- }
- protected function execute(InputInterface $input, OutputInterface $output): int
- {
- try {
- $output->writeln("获取线索订单====>".getDateFull());
- $agentId = $input->getArgument("agentId");
- if (empty($agentId)) {
- $output->writeln("配置错误1====>".getDateFull());
- return self::SUCCESS;
- }
- $config = (new HxAgent)->where("account",$agentId)->findOrEmpty();
- $config['version'] = "res";
- if ($config->isEmpty()) {
- $output->writeln("配置错误2====>".getDateFull());
- return self::SUCCESS;
- }
- $result = (new Store)->config($config->toArray())->token()->asyncClue($config['account']);
- $mode = new HxOrderLife;
- if (!empty($result['clue_data'])) {
- foreach ($result['clue_data'] as $k => $v) {
- if ($v['order_id'] > 0) {
- $v['telephone'] = (new SignUtil)->init($config['secret'])->decryptAES($v['telephone']);
- $v['agent_id'] = $config['agent_id'];
- $v['create_at'] = $v['create_time_detail']??getDateFull();
- // print_r($v);
- $order = $mode->where("order_id",$v['order_id'])->findOrEmpty();
- if ($order->isEmpty()) {
- echo getDateFull()."==新增订单=={$v['order_id']}==\n";
- $v['pay_at'] = $v['modify_time'];
- $order->strict(false)->insertGetId($v);
- } else {
- echo getDateFull()."==更新订单=={$v['order_id']}==\n";
- $order->product_id = $v['product_id'];
- if ($v['order_status'] == '履约中') {
- $order->telephone = $v['telephone'];
- $order->tel_addr = $v['tel_addr'];
- }
- $order->save();
- }
- } else {
- echo getDateFull()."==跳过订单=={$v['order_id']}==\n";
- }
- }
- } else {
- echo getDateFull()."==该账号下无订单=={$agentId}==\n";
- }
- } catch (\Throwable $throwable) {
- echo getDateFull()."==获取线索订单失败\n";
- echo $throwable->getMessage()."\n";
- echo $throwable->getFile()."【".$throwable->getLine()."】\n";
- }
- return self::SUCCESS;
- }
- }
|