| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace app\command;
- use app\common\enum\CommonEnum;
- 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 MemberAreaOrderIndependentAccount extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('member-area-order-independent-account')
- ->setDescription('会员专区订单分账');
- }
- protected function execute(Input $input, Output $output)
- {
- // @todo 会员专区订单分账
- $this->doMemberAreaOrderIndependentAccount([CommonEnum::DESIGN_MERCHANT_ID['MemberZone']['code']]);
- $this->doSharedProsperityOrderIndependentAccount([CommonEnum::DESIGN_MERCHANT_ID['SharedProsperity']['code']]);
- }
- /**
- * 会员专区、会员专区订单分账
- *
- * @param $merId
- * @param $timeLimit
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function doMemberAreaOrderIndependentAccount($merId = [], $timeLimit = 30)
- {
- $dst_mer_id = systemConfig('mer_365');
- // 商户信息
- $merchants = [];
- // 已支付、未结算 注意,会员专区之前可能没有去及时 更新结算状态 'is_settlement' => 1,
- $where = ['paid' => 1, 'is_del' => 0, 'is_system_del' => 0, 'is_independentaccount' => 0];
- // 订单状态(0:待发货;1:待收货;2:待评价;3:已完成;4已申请退款;-1:已退款)5未支付 6已取消'
- // $status = [2, 3]; ->whereIn('status', $status)
- // 普通订单
- $cursor = Db::table('rrx_store_order')->where($where)->where('pay_type', 'in', '1,2,4')
- ->where('fzone_pay_price', '>', 0.00)
- ->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['fzone_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();
- }
- }
- }
- /**
- * 共富区订单分账
- *
- * @param $merId
- * @param $timeLimit
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function doSharedProsperityOrderIndependentAccount($merId = [], $timeLimit = 30)
- {
- $dst_mer_id = CommonEnum::DESIGN_MERCHANT_ID['SharedProsperity']['code'];
- // 商户信息
- $merchants = [];
- // 已支付、未结算 注意,会员专区之前可能没有去及时 更新结算状态 'is_settlement' => 1,
- $where = ['paid' => 1, 'is_del' => 0, 'is_system_del' => 0, 'is_independentaccount' => 0];
- // 订单状态(0:待发货;1:待收货;2:待评价;3:已完成;4已申请退款;-1:已退款)5未支付 6已取消'
- // $status = [2, 3]; ->whereIn('status', $status)
- // 普通订单
- $cursor = Db::table('rrx_store_order')->where($where)->where('pay_type', 'in', '1,2,4')
- ->where('fzone_pay_price', '>', 0.00)
- ->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();
- $independentAccount = $storeOrderRepository->getIndependentAccount($value, $group_order, $dst_mer_id, $merchants[$value['mer_id']]['hf_member_id']);
- $isSuccessed = $storeOrderRepository->prepareExecuteIndependentAccount(
- $value, $group_order, $independentAccount['api_key'], $independentAccount['hf_platform_member_id'], '', $value['fzone_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();
- }
- }
- }
- }
|