| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\command;
- use app\api\model\order\Order;
- use app\api\model\system\Message;
- use app\api\service\MassagerActionService;
- use app\api\service\OrderService;
- use app\api\service\ProfitService;
- use app\api\service\TencentCloudService;
- use app\api\service\ThirdPayService;
- use app\api\service\WalletService;
- use redis\RedLock;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\Db;
- use think\Exception;
- // 每天早上8点-分润(昨天)
- class Profit extends Command
- {
- // 配置定时器的信息
- protected function configure()
- {
- $this->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
- ]);
- $logs[] = [
- "order_id" => $order["id"],
- "s_res" => $res->code()
- ];
- } else {
- $logs[] = ["order_id" => $order["id"], "s_res" => $res->msg()];
- }
- } catch (Exception $e) {
- $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");
- }
- }
|