| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace app\command;
- use app\common\model\store\order\StoreOrder;
- use app\common\repositories\store\order\StoreOrderRepository;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Db;
- class GreatLifeOrderIndependentAccount extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('great-life-order-independent-account')
- ->setDescription('精彩生活区订单分账');
- }
- protected function execute(Input $input, Output $output)
- {
- // @todo 精彩生活区订单分账
- $this->doGreatLifeOrderIndependentAccount([439]);
- }
- /**
- * 会员专区、精彩生活区订单分账
- *
- * @param $merId
- * @param $timeLimit
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function doGreatLifeOrderIndependentAccount($merId = [], $timeLimit = 30)
- {
- $dst_mer_id = systemConfig('mer_365');
- // 商户信息
- $merchants = [];
- // 已支付、未结算
- $where = ['paid' => 1, 'is_independentaccount' => 0, 'is_del' => 0, 'is_system_del' => 0, 'is_settlement' => 1];
- // 订单状态(0:待发货;1:待收货;2:待评价;3:已完成;4已申请退款;-1:已退款)5未支付 6已取消'
- $status = [2, 3];
- // 普通订单
- $cursor = Db::table('rrx_store_order')->where($where)->where('pay_type', 'in', '1,2,4')->whereIn('status', $status)
- ->whereIn('mer_id', $merId)->cursor();
- /** @var StoreOrderRepository $storeOrderRepository */
- $storeOrderRepository = app()->make(StoreOrderRepository::class);
- foreach ($cursor as $key => $value) {
- if (!isset($merchants[$value['mer_id']])) {
- $merchants[$value['mer_id']] = Db::name('merchant')->where('mer_id', $value['mer_id'])->find();
- }
- $group_order = Db::name('store_group_order')->alias('sgo')->where('sgo.group_order_id', $value['group_order_id'])->find();
- // 分账账号 496:表示{会员专区}账户,精彩生活区分账到{会员专区}账户
- $independentAccount = $storeOrderRepository->getIndependentAccount($value, $group_order, $dst_mer_id, $merchants[$value['mer_id']]['hf_member_id']);
- // @todo 预分账处理 496:表示{会员专区}账户,精彩生活区分账到{会员专区}账户,故:hf_platform_member_id 为入账账户
- $isSuccessed = $storeOrderRepository->prepareExecuteIndependentAccount(
- $value, $group_order, $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)));// 日志记录
- $order = StoreOrder::getInstance()->where('order_id', $value['order_id'])->find();
- $order->is_independentaccount = 1;
- $order->save();
- }
- }
- }
- }
|