setName('Profit') ->setDescription('Profit start'); } /** * @param Input $input * @param Output $output * @return int|void|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\Exception */ protected function execute(Input $input, Output $output) { \think\Log::custom_log("分润", "-------------- start --------------", "profit"); $orderModel = new Order(); $orderService = new OrderService(); $orders = $orderModel->whereTime("createtime", "<=", strtotime(date("Y-m-d 00:00:00"))) ->where("status", \E_ORDER_STATUS::WaitFeedback) ->order("id", "ASC") ->select(); $rand_str = ["服务态度好,超赞!!!", "手法专业,点赞!!!", "性价比高,点赞!!!", "价格合理服务态度好点赞!!!"]; foreach ($orders as $order) { $orderService->comment($order["id"], [ "star" => 5, "is_anonymity" => 1, "tags" => "价格合理,着装规范,手法专业,性价比高", "content" => array_rand($rand_str), "negative" => 0, ]); } $orders = (new Order()) ->whereTime("createtime", "<=", strtotime(date("Y-m-d 00:00:00"))) ->where("status", \E_ORDER_STATUS::Finish) ->where("is_use_profit", 0) ->order("id", "ASC") ->select(); $logs = []; $profitService = new ProfitService(); $orderLock = new RedLock(); foreach ($orders as $order) { $oLock = $orderLock->lock(Order::OKey($order["id"])); if (!is_array($oLock)) continue; try { $auto_count = \db("cancel_order_log")->where("order_no", $order["no"])->where("createtime", "DESC")->find(); $unusual = $auto_count && $auto_count["order_status_enum"] == \E_ORDER_STATUS::AdminCancel; $res = $profitService->profit($order, db("user")->where("id", $order["user_id"])->find(), $unusual); if ($res->code()) { \db("order")->where("id", $order["id"])->update([ "is_use_profit" => 1 ]); array_push($logs, [ "order_id" => $order["id"], "s_res" => $res->code() ]); } else { array_push($logs, ["order_id" => $order["id"], "s_res" => $res->msg()]); } } catch (Exception $e) { array_push($logs, ["order_id" => $order["id"], "s_res" => $e->getMessage()]); } finally { $orderLock->unlock($oLock); } } \think\Log::custom_log("分润", $logs, "profit"); \think\Log::custom_log("分润", "--------------- over --------------", "profit"); } }