ProductLogJob.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 app\jobs\product;
  12. use app\services\product\product\StoreProductLogServices;
  13. use app\services\product\product\StoreVisitServices;
  14. use crmeb\basic\BaseJobs;
  15. use crmeb\traits\QueueTrait;
  16. use think\facade\Log;
  17. /**
  18. * 商品记录
  19. * Class ProductLogJob
  20. * @package app\jobs
  21. */
  22. class ProductLogJob extends BaseJobs
  23. {
  24. use QueueTrait;
  25. /**
  26. * @return mixed
  27. */
  28. public static function queueName()
  29. {
  30. return 'CRMEB_PRO_LOG';
  31. }
  32. /**
  33. * @param $type 'visit','cart','order','pay','collect','refund'
  34. * @param $data
  35. * @return bool
  36. */
  37. public function doJob($type, $data, $productType = 'product')
  38. {
  39. try {
  40. /** @var StoreProductLogServices $productLogServices */
  41. $productLogServices = app()->make(StoreProductLogServices::class);
  42. $productLogServices->createLog($type, $data);
  43. if ($type == 'visit') {
  44. /** @var StoreVisitServices $storeVisit */
  45. $storeVisit = app()->make(StoreVisitServices::class);
  46. $storeVisit->setView($data['uid'] ?? 0, $data['id'] ?? 0, $productType, $data['product_id'] ?? [], 'view');
  47. }
  48. } catch (\Throwable $e) {
  49. Log::error('写入商品记录发生错误,错误原因:' . $e->getMessage());
  50. }
  51. return true;
  52. }
  53. }