| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- <?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 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)
- {
- // 商户信息
- $merchants = [];
- $time = time();
- // 已支付、未结算
- $where = ['paid' => 1, 'gzc' => 0, 'is_del' => 0, 'is_system_del' => 0];
- // 订单状态(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();
- // $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
- // $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- // $OrderGzcRepository = app()->make(OrderGzcRepository::class);
- /** @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) {
- 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, 496, $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['con_pri'], 0
- );
- Db::name("log")->insert(array('data' => '精彩生活区-订单分账:' . json_encode($value, JSON_FORCE_OBJECT)));//日志记录
- // Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
- // //新增入账明细记录
- // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
- // $create = [
- // 'uid' => $online['uid'],
- // 'platform_no' => $orderId,
- // 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
- // 'user_name' => $certification['user_name'],
- // 'mobile' => $certification['mobile'],
- // 'user_card' => $certification['user_card'],
- // 'pension' => $pension,
- // 'order_type' => 2,
- // 'out_trade_no' => $online['order_sn']
- // ];
- // $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
- // $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
- // if ($test_user == 0 && $check <= 0) {
- // $OrderGzcRepository->create($create);
- // }
- $order = StoreOrder::getInstance()->find($value['order_id']);
- $order->gzc = 1;
- $order->save();
- // });
- }
- }
- // 普通订单(红包,积分,京东,佣金,复购金,养老金,贡献值)
- // $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('is_settlement', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
- // $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
- // $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- // $OrderGzcRepository = app()->make(OrderGzcRepository::class);
- // foreach ($cursor as $online) {
- // $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
- // if ($online['mer_id'] == 496) {
- // if (!in_array($online['status'], [0, 1, 2, 3])) {
- // continue;
- // }
- // if (time() < strtotime($online['pay_time']) + 3600 * 24) {
- // Log::info('还没有到收货后' . $timeLimit . '天');
- // continue;
- // }
- // } else {
- // if (!in_array($online['status'], [2, 3])) {
- // continue;
- // }
- // if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
- // Log::info('还没有到收货后' . $timeLimit . '天');
- // continue;
- // }
- // }
- //
- // $StoreOrderRepository = app()->make(StoreOrderRepository::class);
- // Db::transaction(function () use ($online, $StoreOrderRepository) {
- // $order = StoreOrder::getInstance()->find($online['order_id']);
- // $order->is_settlement = 1;
- // $order->settlement_time = date('Y-m-d H:i:s');
- // $order->save();
- //
- // // 结算积分
- // $user_sign_score_list = Db::name('user_sign_score')
- // ->where('status', -1)
- // ->where('order_id', $online['order_id'])
- // ->whereIn('type', [1, 2])
- // ->select()
- // ->toArray();
- // foreach ($user_sign_score_list as $user_sign_score) {
- // // 修改积分
- // Db::name('user')
- // ->where('uid', $user_sign_score['uid'])
- // ->inc('score', (float)$user_sign_score['reward_socre'])
- // ->update();
- // Db::name('user_sign_score')
- // ->where('status', -1)
- // ->where('id', $user_sign_score['id'])
- // ->update([
- // 'status' => 1,
- // 'settlement_time' => date('Y-m-d H:i:s')
- // ]);
- // }
- //
- // // 结算红包
- // $user_sign_hongbao_list = Db::name('user_sign_hongbao')
- // ->where('status', -1)
- // ->where('order_id', $online['order_id'])
- // ->whereIn('type', [1, 2])
- // ->select()
- // ->toArray();
- // foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
- // // 修改红包
- // Db::name('user')
- // ->where('uid', $user_sign_hongbao['uid'])
- // ->inc('hongbao', (float)$user_sign_hongbao['number'])
- // ->update();
- // Db::name('user_sign_hongbao')
- // ->where('status', -1)
- // ->where('id', $user_sign_hongbao['id'])
- // ->update([
- // 'status' => 1,
- // 'settlement_time' => date('Y-m-d H:i:s')
- // ]);
- // }
- //
- //
- // // 结算京豆
- // $user_sign_jingdou_list = Db::name('user_sign_jingdou')
- // ->where('status', -1)
- // ->where('order_id', $online['order_id'])
- // ->whereIn('type', [1, 2])
- // ->select()
- // ->toArray();
- // foreach ($user_sign_jingdou_list as $user_sign_jingdou) {
- // // 修改京豆
- // Db::name('user')
- // ->where('uid', $user_sign_jingdou['uid'])
- // ->inc('jingdou', (float)$user_sign_jingdou['number'])
- // ->update();
- // Db::name('user_sign_jingdou')
- // ->where('status', -1)
- // ->where('id', $user_sign_jingdou['id'])
- // ->update([
- // 'status' => 1,
- // 'settlement_time' => date('Y-m-d H:i:s')
- // ]);
- // }
- //
- //
- //
- // // 结算复购金
- // $user_sign_fugou_list = Db::name('user_sign_fugou')
- // ->where('status', -1)
- // ->where('order_id', $online['order_id'])
- // ->whereIn('type', [1, 2])
- // ->select()
- // ->toArray();
- // foreach ($user_sign_fugou_list as $user_sign_fugou) {
- // // 修改复购金
- // Db::name('user')
- // ->where('uid', $user_sign_fugou['uid'])
- // ->inc('fugou', (float)$user_sign_fugou['number'])
- // ->update();
- // Db::name('user_sign_fugou')
- // ->where('status', -1)
- // ->where('id', $user_sign_fugou['id'])
- // ->update([
- // 'status' => 1,
- // 'settlement_time' => date('Y-m-d H:i:s')
- // ]);
- // }
- //
- //
- // // 结算贡献值
- // $user_sign_gongxian_list = Db::name('user_sign_gongxian')
- // ->where('status', -1)
- // ->where('order_id', $online['order_id'])
- // ->whereIn('type', [1, 2])
- // ->select()
- // ->toArray();
- // foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
- // // 修改贡献值
- // Db::name('user')
- // ->where('uid', $user_sign_gongxian['uid'])
- // ->inc('contribute', (float)$user_sign_gongxian['number'])
- // ->update();
- // Db::name('user_sign_gongxian')
- // ->where('status', -1)
- // ->where('id', $user_sign_gongxian['id'])
- // ->update([
- // 'status' => 1,
- // 'settlement_time' => date('Y-m-d H:i:s')
- // ]);
- // }
- //
- //
- // // 结算佣金
- // $user_bill_list = Db::name('user_bill')
- // ->where('status', 0)
- // ->where('commission_type','<>', 5)
- // ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']])
- // ->select()
- // ->toArray();
- // foreach ($user_bill_list as $user_bill) {
- // if ($user_bill['commission_type'] != 5) {
- // if (in_array($user_bill['commission_type'], [7,12,19])) {
- // Db::name("merchant")
- // ->where("mer_id", $user_bill['mer_id'])
- // ->inc('brokerage_price', (float)$user_bill['number'])
- // ->update();
- // } else {
- // Db::name('user')
- // ->where('uid', $user_bill['uid'])
- // ->inc('brokerage_price', (float)$user_bill['number'])
- // ->update();
- // }
- // }
- // if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
- // } else {
- // // 虚拟支付的养老金不修改不结算
- // Db::name('user_bill')
- // ->where('status', 0)
- // ->where('bill_id', $user_bill['bill_id'])
- // ->update([
- // 'status' => 1,
- // 'take_time' => time()
- // ]);
- // }
- // if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
- // } else {
- // // 虚拟支付的养老金不修改不结算
- // Db::name('user_bill')
- // ->where('status', 0)
- // ->where('bill_id', $user_bill['bill_id'])
- // ->update([
- // 'status' => 1,
- // 'take_time' => time()
- // ]);
- // }
- // }
- // //按角色结算
- // $StoreOrderRepository->close_order($online['order_id']);
- // });
- // }
- }
- }
|