setName('huafei-order-independent-account') ->setDescription('话费订单分账'); } protected function execute(Input $input, Output $output) { // @todo 精彩生活区订单分账 $this->doHuafeiOrderIndependentAccount(); } /** * 会员专区、精彩生活区订单分账 * * @param $merId * @param $timeLimit * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function doHuafeiOrderIndependentAccount($timeLimit = 1) { $dst_mer_id = systemConfig('mer_365'); // 商户信息 $merchants = []; $time = time(); // 订单状态(0:待发货;1:待收货;2:待评价;3:已完成;4已申请退款;-1:已退款)5未支付 6已取消' $status = [2]; // 普通订单 $cursor = Db::table('rrx_order_huafei')->where('is_independentaccount', 0)->whereIn('status', $status)->cursor(); /** @var StoreOrderRepository $storeOrderRepository */ $storeOrderRepository = app()->make(StoreOrderRepository::class); foreach ($cursor as $key => $value) { $settlement_period_time = strtotime($value['create_time']) + $timeLimit * 24 * 3600; // @todo 下单后第{$timeLimit}天后可分账 if ($settlement_period_time >= $time) { $merchants['496'] = Db::name('merchant')->where('mer_id', 496)->find(); $order_huafei_hf = Db::name('order_huafei_hf')->where('order_no', $value['order_sn'])->find(); if(!$order_huafei_hf) continue; $value['mer_id'] = 496; $order_huafei_hf['mer_id'] = 496; // 分账账号 496:表示{会员专区}账户,分账到{会员专区}账户 $independentAccount = $storeOrderRepository->getIndependentAccountHuafei($order_huafei_hf, $dst_mer_id, $merchants['496']['hf_member_id']); // @todo 预分账处理 分账到{会员专区}账户,故:hf_platform_member_id 为入账账户 $isSuccessed = $storeOrderRepository->prepareExecuteIndependentAccountHuafei( $value, $order_huafei_hf, $independentAccount['api_key'], $independentAccount['hf_platform_member_id'], '', $value['pay_price'], 0 ); if ($isSuccessed) { Db::name("log")->insert(array('data' => '话费-订单分账:' . json_encode($value, JSON_FORCE_OBJECT)));//日志记录 Db::table('rrx_order_huafei')->where('order_sn', $value['order_sn'])->update(['is_independentaccount' => 1]); } } } } }