OrderReplyJob.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace ln\jobs;
  3. use app\common\repositories\store\order\StoreOrderRepository;
  4. use app\common\repositories\store\order\StoreOrderStatusRepository;
  5. use app\common\repositories\store\product\ProductReplyRepository;
  6. use ln\interfaces\JobInterface;
  7. use think\facade\Db;
  8. use think\facade\Log;
  9. use think\facade\Queue;
  10. class OrderReplyJob implements JobInterface
  11. {
  12. public function fire($job, $orderId)
  13. {
  14. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  15. $productReplyRepository = app()->make(ProductReplyRepository::class);
  16. $order = $storeOrderRepository->getWhere(['order_id' => $orderId, 'status' => 2]);
  17. if ($order) {
  18. $data = ['comment' => '系统默认好评', 'product_score' => 5, 'service_score' => 5, 'postage_score' => 5, 'rate' => 5, 'sort' =>0];
  19. $data['uid'] = $order->uid;
  20. $data['nickname'] = $order->user ? $order->user['nickname'] : '****';
  21. $data['avatar'] = $order->user ? $order->user['avatar'] : '';
  22. $data['mer_id'] = $order->mer_id;
  23. $ids = [];
  24. try {
  25. Db::transaction(function () use ($productReplyRepository, $order, &$ids, $data) {
  26. foreach ($order->orderProduct as $orderProduct) {
  27. if ($orderProduct->is_reply) continue;
  28. $data['order_product_id'] = $orderProduct['order_product_id'];
  29. $data['product_type'] = $orderProduct['cart_info']['product']['product_type']??0;
  30. $ids[] = $data['product_id'] = $orderProduct['product_id'];
  31. $data['unique'] = $orderProduct['cart_info']['productAttr']['unique'];
  32. $productReplyRepository->create($data);
  33. $orderProduct->is_reply = 1;
  34. $orderProduct->save();
  35. }
  36. $order->status = 3;
  37. $order->save();
  38. //TODO 交易完成
  39. app()->make(StoreOrderStatusRepository::class)->status($order->order_id, 'auto_over', '交易完成');
  40. });
  41. foreach ($ids as $id) {
  42. Queue::push(UpdateProductReplyJob::class, $id);
  43. }
  44. } catch (\Exception $e) {
  45. Log::error($orderId . '自动评价商品失败' . $e->getMessage());
  46. }
  47. }
  48. $job->delete();
  49. }
  50. public function failed($data)
  51. {
  52. // TODO: Implement failed() method.
  53. }
  54. }