OrderReplyJob.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\jobs;
  12. use app\common\repositories\store\order\StoreOrderRepository;
  13. use app\common\repositories\store\order\StoreOrderStatusRepository;
  14. use app\common\repositories\store\product\ProductReplyRepository;
  15. use crmeb\interfaces\JobInterface;
  16. use think\facade\Db;
  17. use think\facade\Log;
  18. use think\facade\Queue;
  19. class OrderReplyJob implements JobInterface
  20. {
  21. public function fire($job, $orderId)
  22. {
  23. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  24. $productReplyRepository = app()->make(ProductReplyRepository::class);
  25. $order = $storeOrderRepository->getWhere(['order_id' => $orderId, 'status' => 2]);
  26. if ($order) {
  27. $data = ['comment' => '系统默认好评', 'product_score' => 5, 'service_score' => 5, 'postage_score' => 5, 'rate' => 5, 'sort' =>0];
  28. $data['uid'] = $order->uid;
  29. $data['nickname'] = $order->user ? $order->user['nickname'] : '****';
  30. $data['avatar'] = $order->user ? $order->user['avatar'] : '';
  31. $data['mer_id'] = $order->mer_id;
  32. $data['pics'] = '';
  33. $ids = [];
  34. //订单记录
  35. $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  36. $orderStatus = [
  37. 'order_id' => $order->order_id,
  38. 'order_sn' => $order->order_sn,
  39. 'type' => $storeOrderStatusRepository::TYPE_ORDER,
  40. 'change_message' => '交易完成',
  41. 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_AUTO_OVER,
  42. ];
  43. try {
  44. Db::transaction(function () use ($productReplyRepository, $order, &$ids, $data,$storeOrderStatusRepository,$orderStatus) {
  45. foreach ($order->orderProduct as $orderProduct) {
  46. if ($orderProduct->is_reply) continue;
  47. $data['order_product_id'] = $orderProduct['order_product_id'];
  48. $data['product_type'] = $orderProduct['cart_info']['product']['product_type']??0;
  49. $ids[] = $data['product_id'] = $orderProduct['product_id'];
  50. $data['unique'] = $orderProduct['cart_info']['productAttr']['unique'];
  51. $productReplyRepository->create($data);
  52. $orderProduct->is_reply = 1;
  53. $orderProduct->save();
  54. }
  55. $order->status = 3;
  56. $order->save();
  57. //TODO 交易完成
  58. $storeOrderStatusRepository->createSysLog($orderStatus);
  59. });
  60. foreach ($ids as $id) {
  61. Queue::push(UpdateProductReplyJob::class, $id);
  62. }
  63. } catch (\Exception $e) {
  64. Log::error($orderId . '自动评价商品失败' . $e->getMessage());
  65. }
  66. }
  67. $job->delete();
  68. }
  69. public function failed($data)
  70. {
  71. // TODO: Implement failed() method.
  72. }
  73. }