Profit.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\command;
  3. use app\api\model\order\Order;
  4. use app\api\model\system\Message;
  5. use app\api\service\MassagerActionService;
  6. use app\api\service\OrderService;
  7. use app\api\service\ProfitService;
  8. use app\api\service\TencentCloudService;
  9. use app\api\service\ThirdPayService;
  10. use app\api\service\WalletService;
  11. use redis\RedLock;
  12. use think\console\Command;
  13. use think\console\Input;
  14. use think\console\Output;
  15. use think\Db;
  16. use think\Exception;
  17. // 每天早上8点-分润(昨天)
  18. class Profit extends Command
  19. {
  20. // 配置定时器的信息
  21. protected function configure()
  22. {
  23. $this->setName('Profit')
  24. ->setDescription('Profit start');
  25. }
  26. /**
  27. * @param Input $input
  28. * @param Output $output
  29. * @return int|void|null
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @throws \think\exception\DbException
  33. * @throws \think\Exception
  34. */
  35. protected function execute(Input $input, Output $output)
  36. {
  37. \think\Log::custom_log("分润", "-------------- start --------------", "profit");
  38. $orderModel = new Order();
  39. $orderService = new OrderService();
  40. $orders = $orderModel->whereTime("createtime", "<=", strtotime(date("Y-m-d 00:00:00")))
  41. ->where("status", \E_ORDER_STATUS::WaitFeedback)
  42. ->order("id", "ASC")
  43. ->select();
  44. $rand_str = ["服务态度好,超赞!!!", "手法专业,点赞!!!", "性价比高,点赞!!!", "价格合理服务态度好点赞!!!"];
  45. foreach ($orders as $order) {
  46. $orderService->comment($order["id"], [
  47. "star" => 5,
  48. "is_anonymity" => 1,
  49. "tags" => "价格合理,着装规范,手法专业,性价比高",
  50. "content" => array_rand($rand_str),
  51. "negative" => 0,
  52. ]);
  53. }
  54. $orders = (new Order())
  55. ->whereTime("createtime", "<=", strtotime(date("Y-m-d 00:00:00")))
  56. ->where("status", \E_ORDER_STATUS::Finish)
  57. ->where("is_use_profit", 0)
  58. ->order("id", "ASC")
  59. ->select();
  60. $logs = [];
  61. $profitService = new ProfitService();
  62. $orderLock = new RedLock();
  63. foreach ($orders as $order) {
  64. $oLock = $orderLock->lock(Order::OKey($order["id"]));
  65. if (!is_array($oLock))
  66. continue;
  67. try {
  68. $auto_count = \db("cancel_order_log")->where("order_no", $order["no"])->where("createtime", "DESC")->find();
  69. $unusual = $auto_count && $auto_count["order_status_enum"] == \E_ORDER_STATUS::AdminCancel;
  70. $res = $profitService->profit($order, db("user")->where("id", $order["user_id"])->find(), $unusual);
  71. if ($res->code()) {
  72. \db("order")->where("id", $order["id"])->update([
  73. "is_use_profit" => 1
  74. ]);
  75. $logs[] = [
  76. "order_id" => $order["id"],
  77. "s_res" => $res->code()
  78. ];
  79. } else {
  80. $logs[] = ["order_id" => $order["id"], "s_res" => $res->msg()];
  81. }
  82. } catch (Exception $e) {
  83. $logs[] = ["order_id" => $order["id"], "s_res" => $e->getMessage()];
  84. } finally {
  85. $orderLock->unlock($oLock);
  86. }
  87. }
  88. \think\Log::custom_log("分润", $logs, "profit");
  89. \think\Log::custom_log("分润", "--------------- over --------------", "profit");
  90. }
  91. }