1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace app\common\command;
- use app\common\model\MobileOrder;
- use app\common\model\SysConfig;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\Db;
- use think\Log;
- class OrderSettleCommand extends Command{
- protected function configure()
- {
- $this->setName('order:settle')->setDescription('订单结算');
- }
- protected function execute(Input $input, Output $output)
- {
- $time=SysConfig::look($name='command:order:settle');
- if(!$time||time()>$time+3600){
- SysConfig::set($name,time());
- }else{
- return;
- }
- $orders= MobileOrder::filterWillOver()->limit(100)->select();
- foreach ($orders as $order){
- try {
- Db::startTrans();
- $order->makeOver();
- user_log('MobileOrderSettle',"结算订单{$order['id']}成功");
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- if($e->getMessage()=='该笔订单已结算成功'){
- user_log('MobileOrderSettle',["订单{$order['id']}结算失败",'当成功处理']);
- MobileOrder::find($order['id'])->makeOver(false);
- }
- user_log('MobileOrderSettle',["订单{$order['id']}结算失败",$e->getMessage(),$e->getFile(),$e->getLine()]);
- }
- }
- SysConfig::del($name);
- }
- }
|