OrderReplyJob.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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];
  28. $data['uid'] = $order->uid;
  29. $data['nickname'] = $order->user['nickname'];
  30. $data['avatar'] = $order->user['avatar'];
  31. $data['mer_id'] = $order->mer_id;
  32. $ids = [];
  33. try {
  34. Db::transaction(function () use ($productReplyRepository, $order, &$ids, $data) {
  35. foreach ($order->orderProduct as $orderProduct) {
  36. if ($orderProduct->is_reply) continue;
  37. $data['order_product_id'] = $orderProduct['order_product_id'];
  38. $data['product_type'] = $orderProduct['cart_info']['product']['product_type']??0;
  39. $ids[] = $data['product_id'] = $orderProduct['product_id'];
  40. $data['unique'] = $orderProduct['cart_info']['productAttr']['unique'];
  41. $productReplyRepository->create($data);
  42. $orderProduct->is_reply = 1;
  43. $orderProduct->save();
  44. }
  45. $order->status = 3;
  46. $order->save();
  47. //TODO 交易完成
  48. app()->make(StoreOrderStatusRepository::class)->status($order->order_id, 'auto_over', '交易完成');
  49. });
  50. foreach ($ids as $id) {
  51. Queue::push(UpdateProductReplyJob::class, $id);
  52. }
  53. } catch (\Exception $e) {
  54. Log::error($orderId . '自动评价商品失败' . $e->getMessage());
  55. }
  56. }
  57. $job->delete();
  58. }
  59. public function failed($data)
  60. {
  61. // TODO: Implement failed() method.
  62. }
  63. }