setName('order_comment') ->setDescription('订单自动评论'); } protected function execute(Input $input, Output $output) { $overTimeComment = ConfigService::get('order_setting', 'over_time_comment') * 60 * 60 * 60; $now = time(); $lists = Order::alias('O') ->join('order_goods OG','O.id = OG.order_id') ->whereRaw("true_server_finish_time+$overTimeComment < $now") ->where(['order_status'=>OrderEnum::ORDER_STATUS_SERVER_FINISH,'is_comment'=>0]) ->where('true_server_finish_time','>',0) ->field('O.user_id,O.shop_id,O.coach_id,OG.*') ->select() ->toArray(); if (empty($lists)) { return true; } $overTimeCommentContent = ConfigService::get('order_setting', 'over_time_comment_content'); foreach ($lists as $order) { Db::startTrans(); try{ GoodsComment::create([ 'goods_id' => $order['goods_id'], 'user_id' => $order['user_id'], 'order_goods_id' => $order['id'], 'service_comment' => 5, 'comment' => $overTimeCommentContent, 'reply' => '', 'coach_id' => $order['coach_id'], 'shop_id' => $order['shop_id'], ]); \app\common\logic\CoachLogic::updateCoachComment($order['coach_id']); if($order['shop_id']){ \app\common\logic\ShopLogic::updateShopComment($order['shop_id']); } OrderGoods::where(['id'=>$order['id']])->update(['is_comment' => 1]); Db::commit(); } catch(\Exception $e) { Db::rollback(); Log::write('订单评论失败:' . $e->getMessage()); } } } }