| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace app\http\command;
- use app\common\model\GoodsOrder;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;
- class RenderOrder extends BaseCommand
- {
- /**
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/14 15:41
- *
- */
- protected function configure()
- {
- $this->setName('render:order')
- ->setDescription('render:order');
- }
- /**
- * 流程处理
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/20 9:20
- *
- * @param Input $input
- * @param Output $output
- * @return int|void|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function execute(Input $input, Output $output)
- {
- //1.产品订单处理 查询订单
- $orders = (new GoodsOrder)->whereTime('created_at','month')->select()->toArray();
- foreach ($orders as $order){
- // 已结束不处理
- if ($order['status'] == 4 || $order['status'] == 0) continue;
- switch ($order['status']){
- case 1:
- //待支付订单关闭处理
- // 读取配置 超时时间 (order_expired_at)小时 (下单时间戳+小时*时间戳 < 当前时间戳 超时)
- $order_expired_at = $this->config['store']['order_expired_at'];
- // 流程开始
- if (($order['created_at'] + ($order_expired_at * 3600)) <= time()){
- //关闭订单
- model('common/GoodsOrder')->updateBy($order['id'], [
- 'status' => 0
- ]);
- }
- break;
- case 2:
- // 自动发货 等待
- break;
- case 3:
- // 待收获订单确认处理
- // 读取配置 自动确认时间 (order_confirm_at) 天数 (下单时间戳+天*时间戳 < 当前时间戳 超时)
- $order_confirm_at = $this->config['store']['order_confirm_at'];
- // 流程开始
- if (($order['created_at'] + ($order_confirm_at * 86400)) <= time()){
- // 奖励期权条件
- if ($order && $order['is_pin'] !== 1){
- // 用户期权
- // order_property_reward
- $order_property_reward = $this->config['store']['order_property_reward'];
- // 计算 交易金额 * order_property_reward
- $reward = round($order_property_reward * $order['total_price'],3);
- // 更新
- model('common/Users')->changeProperty(
- $order['user_id'],
- $reward,
- '订单完成,奖励资产【' . $reward . "】",
- true
- );
- }
- // 结束订单
- model('common/GoodsOrder')->updateBy($order['id'], [
- 'received_at' => time(),
- 'status' => 4 // 结束订单
- ]);
- }
- break;
- case 5:
- // 未开团结束处理
- // 读取配置 领取超时时间 (pin_expired_at) 小时 (下单时间戳+小时*时间戳 < 当前时间戳 超时)
- $pin_expired_at = $this->config['store']['pin_expired_at'];
- // 流程开始
- if (($order['created_at'] + ($pin_expired_at * 3600)) <= time()){
- // todo 商品退钱
- model('common/Users')->changeBalance(
- $order['user_id'],
- $order['pay_price'],
- "参团失败,退还支付金额【" . $order['pay_price'] . '】',
- true
- );
- // 结束订单
- model('common/GoodsOrder')->updateBy($order['id'], [
- 'status' => 0 // 关闭订单
- ]);
- }
- break;
- case 6:
- // 待领取订单结束处理
- // 读取配置 领取超时时间 (pin_rebate_expired_at) 小时 (下单时间戳+小时*时间戳 < 当前时间戳 超时)
- $pin_rebate_expired_at = $this->config['store']['pin_rebate_expired_at'];
- // 流程开始
- if (($order['created_at'] + ($pin_rebate_expired_at * 3600)) <= time()){
- // 结束订单
- model('common/GoodsOrder')->updateBy($order['id'], [
- 'status' => 4 // 结束订单
- ]);
- }
- break;
- }
- }
- // 其他订单处理
- }
- }
|