FootprintService.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace addons\TinyShop\services\member;
  3. use common\components\Service;
  4. use common\enums\StatusEnum;
  5. use addons\TinyShop\common\models\member\Footprint;
  6. /**
  7. * Class FootprintService
  8. * @package addons\TinyShop\services\member
  9. * @author jianyan74 <751393839@qq.com>
  10. */
  11. class FootprintService extends Service
  12. {
  13. /**
  14. * @param $product
  15. * @param $member_id
  16. */
  17. public function create($product, $member_id)
  18. {
  19. if (!($model = $this->findByProductId($member_id, $product['id']))) {
  20. $model = new Footprint();
  21. $model = $model->loadDefaultValues();
  22. $model->member_id = $member_id;
  23. $model->merchant_id = $product['merchant_id'];
  24. $model->product_id = $product['id'];
  25. $model->cate_id = $product['cate_id'];
  26. }
  27. $model->num += 1;
  28. $model->save();
  29. }
  30. /**
  31. * 获取推荐的分类
  32. *
  33. * @param $member_id
  34. * @return array
  35. */
  36. public function findCateIdsByMemberId($member_id)
  37. {
  38. return Footprint::find()
  39. ->select(['cate_id'])
  40. ->where(['status' => StatusEnum::ENABLED])
  41. ->andFilterWhere(['member_id' => $member_id])
  42. ->limit(20)
  43. ->column();
  44. }
  45. /**
  46. * @param $product_id
  47. * @param $member_id
  48. * @return array|\yii\db\ActiveRecord|null
  49. */
  50. public function findByProductId($member_id, $product_id)
  51. {
  52. return Footprint::find()
  53. ->where(['member_id' => $member_id, 'product_id' => $product_id])
  54. ->andWhere(['status' => StatusEnum::ENABLED])
  55. ->one();
  56. }
  57. }
粤ICP备19079148号