AutoCommentJob.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\jobs;
  3. use app\services\order\StoreOrderCartInfoServices;
  4. use app\services\order\StoreOrderServices;
  5. use app\services\user\UserServices;
  6. use app\services\product\product\StoreProductReplyServices;
  7. use crmeb\basic\BaseJobs;
  8. use crmeb\traits\QueueTrait;
  9. class AutoCommentJob extends BaseJobs
  10. {
  11. use QueueTrait;
  12. /**
  13. * 自动评价
  14. * @param $id
  15. * @param $cart_ids
  16. * @return bool
  17. */
  18. public function doJob($id, $cart_ids)
  19. {
  20. /** @var UserServices $userServices */
  21. $userServices = app()->make(UserServices::class);
  22. /** @var StoreOrderCartInfoServices $cartInfoServices */
  23. $cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
  24. /** @var $replyServices */
  25. $replyServices = app()->make(StoreProductReplyServices::class);
  26. /** @var StoreOrderServices $orderServices */
  27. $orderServices = app()->make(StoreOrderServices::class);
  28. $list = $cartInfoServices->getColumn([['cart_id', 'in', $cart_ids]], 'cart_info,uid,oid,unique,product_id');
  29. $uids = array_column($list, 'uid');
  30. $userInfos = $userServices->getColumn([['uid', 'in', $uids]], 'nickname,avatar', 'uid');
  31. $reply = [];
  32. foreach ($list as $item) {
  33. $reply[] = [
  34. 'uid' => $item['uid'],
  35. 'oid' => $item['oid'],
  36. 'unique' => $item['unique'],
  37. 'product_id' => json_decode($item['cart_info'],true)['product_id'],
  38. 'reply_type' => 'product',
  39. 'nickname' => $userInfos[$item['uid']]['nickname'],
  40. 'avatar' => $userInfos[$item['uid']]['avatar'],
  41. 'comment' => sys_config('comment_content',''),
  42. 'product_score' => 5,
  43. 'service_score' => 5,
  44. 'add_time' => time(),
  45. ];
  46. }
  47. if (count($reply)) {
  48. $replyServices->saveAll($reply);
  49. }
  50. $orderServices->checkOrderOver($replyServices, $cartInfoServices->getCartColunm(['oid' => $id], 'unique', ''), $id);
  51. return true;
  52. }
  53. }