| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace app\command;
- use app\common\model\store\order\StoreOrder;
- use app\common\model\user\UserCertification;
- use app\common\repositories\merchant\order\OrderGzcRepository;
- use app\common\repositories\merchant\order\OrderMerchantRepository;
- use app\common\repositories\store\order\StoreOrderRepository;
- use app\common\repositories\store\order\StoreOrderStatusRepository;
- use app\common\repositories\user\UserBillRepository;
- use app\common\repositories\user\UserRepository;
- use Carbon\Carbon;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Db;
- use think\facade\Log;
- class HuafeiOrderIndependentAccount extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->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)->select();
- /** @var StoreOrderRepository $storeOrderRepository */
- $storeOrderRepository = app()->make(StoreOrderRepository::class);
- if($cursor) {
- $cursor = $cursor->toArray();
- }else {
- die;
- }
- foreach ($cursor as $key => $value) {
- // @todo 下单后第{$timeLimit}天后可分账
- $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;
- $order_huafei_hf['hf_pay_id'] = $order_huafei_hf['payment_id'];
- $order_huafei_hf['group_order_sn'] = $order_huafei_hf['order_no'];
- // 分账账号 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['amount_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]);
- }
- }
- }
- }
|