AutoCommentJob.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\jobs;
  12. use app\services\order\StoreOrderCartInfoServices;
  13. use app\services\order\StoreOrderServices;
  14. use app\services\user\UserServices;
  15. use app\services\product\product\StoreProductReplyServices;
  16. use crmeb\basic\BaseJobs;
  17. use crmeb\traits\QueueTrait;
  18. class AutoCommentJob extends BaseJobs
  19. {
  20. use QueueTrait;
  21. /**
  22. * 自动评价
  23. * @param $id
  24. * @param $cart_ids
  25. * @return bool
  26. */
  27. public function doJob($id, $cart_ids)
  28. {
  29. /** @var UserServices $userServices */
  30. $userServices = app()->make(UserServices::class);
  31. /** @var StoreOrderCartInfoServices $cartInfoServices */
  32. $cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
  33. /** @var $replyServices */
  34. $replyServices = app()->make(StoreProductReplyServices::class);
  35. /** @var StoreOrderServices $orderServices */
  36. $orderServices = app()->make(StoreOrderServices::class);
  37. $list = $cartInfoServices->getColumn([['cart_id', 'in', $cart_ids]], 'cart_info,uid,oid,unique,product_id');
  38. $uids = array_column($list, 'uid');
  39. $userInfos = $userServices->getColumn([['uid', 'in', $uids]], 'nickname,avatar', 'uid');
  40. $reply = [];
  41. foreach ($list as $item) {
  42. $reply[] = [
  43. 'uid' => $item['uid'],
  44. 'oid' => $item['oid'],
  45. 'unique' => $item['unique'],
  46. 'product_id' => json_decode($item['cart_info'],true)['product_id'],
  47. 'reply_type' => 'product',
  48. 'nickname' => $userInfos[$item['uid']]['nickname'],
  49. 'avatar' => $userInfos[$item['uid']]['avatar'],
  50. 'comment' => sys_config('comment_content',''),
  51. 'product_score' => 5,
  52. 'service_score' => 5,
  53. 'add_time' => time(),
  54. ];
  55. }
  56. if (count($reply)) {
  57. $replyServices->saveAll($reply);
  58. }
  59. $orderServices->checkOrderOver($replyServices, $cartInfoServices->getCartColunm(['oid' => $id], 'unique', ''), $id);
  60. return true;
  61. }
  62. }