UpdateProductReplyJob.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/6/11
  7. *
  8. *
  9. */
  10. namespace crmeb\jobs;
  11. use app\common\repositories\store\product\ProductReplyRepository;
  12. use app\common\repositories\store\product\ProductRepository;
  13. use app\common\repositories\system\merchant\MerchantRepository;
  14. use crmeb\interfaces\JobInterface;
  15. class UpdateProductReplyJob implements JobInterface
  16. {
  17. public function fire($job, $productId)
  18. {
  19. $productReplyRepository = app()->make(ProductReplyRepository::class);
  20. $total = $productReplyRepository->productTotalRate($productId);
  21. if (!$total) return $job->delete();
  22. $rate = bcmul($total['total_rate'], $total['total_count'], 1);
  23. app()->make(ProductRepository::class)->baseUpdate($productId, [
  24. 'rate' => $rate,
  25. 'reply_count' => $total['total_count']
  26. ]);
  27. $data = $productReplyRepository->getWhere(['product_id' => $productId],'mer_id');
  28. $merchantRate = $productReplyRepository->merchantTotalRate($data['mer_id']);
  29. app()->make(MerchantRepository::class)->update($data['mer_id'],$merchantRate);
  30. $job->delete();
  31. }
  32. public function failed($data)
  33. {
  34. // TODO: Implement failed() method.
  35. }
  36. }