UpdateProductReplyJob.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\product\ProductReplyRepository;
  13. use app\common\repositories\store\product\ProductRepository;
  14. use app\common\repositories\system\merchant\MerchantRepository;
  15. use crmeb\interfaces\JobInterface;
  16. class UpdateProductReplyJob implements JobInterface
  17. {
  18. public function fire($job, $productId)
  19. {
  20. $productReplyRepository = app()->make(ProductReplyRepository::class);
  21. $total = $productReplyRepository->productTotalRate($productId);
  22. if (!$total) return $job->delete();
  23. if(!$total['total_rate']) {
  24. $rate = 5;
  25. } else {
  26. $rate = bcdiv($total['total_rate'], $total['total_count'], 1);
  27. }
  28. app()->make(ProductRepository::class)->update($productId, [
  29. 'rate' => $rate,
  30. 'reply_count' => $total['total_count']
  31. ]);
  32. $data = $productReplyRepository->getWhere(['product_id' => $productId], 'mer_id');
  33. $merchantRate = $productReplyRepository->merchantTotalRate($data['mer_id']);
  34. app()->make(MerchantRepository::class)->update($data['mer_id'], $merchantRate);
  35. $job->delete();
  36. }
  37. public function failed($data)
  38. {
  39. // TODO: Implement failed() method.
  40. }
  41. }