UpdateProductReplyJob.php 1.2 KB

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