StoreProductRelation.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\wap\model\store;
  12. use basic\ModelBasic;
  13. use behavior\wap\StoreProductBehavior;
  14. use service\HookService;
  15. use traits\ModelTrait;
  16. class StoreProductRelation extends ModelBasic
  17. {
  18. use ModelTrait;
  19. protected $insert = ['add_time'];
  20. protected function setAddTimeAttr($value)
  21. {
  22. return time();
  23. }
  24. public static function productRelation($productId,$uid,$relationType,$category = 'product')
  25. {
  26. if(!$productId) return self::setErrorInfo('产品不存在!');
  27. $relationType = strtolower($relationType);
  28. $category = strtolower($category);
  29. $data = ['uid'=>$uid,'product_id'=>$productId,'type'=>$relationType,'category'=>$category];
  30. if(self::be($data)) return true;
  31. $data=self::set($data);
  32. HookService::afterListen('store_'.$category.'_'.$relationType,$productId,$uid,false,StoreProductBehavior::class);
  33. return $data;
  34. }
  35. public static function unProductRelation($productId,$uid,$relationType,$category = 'product')
  36. {
  37. if(!$productId) return self::setErrorInfo('产品不存在!');
  38. $relationType = strtolower($relationType);
  39. $category = strtolower($category);
  40. self::where(['uid'=>$uid,'product_id'=>$productId,'type'=>$relationType,'category'=>$category])->delete();
  41. HookService::afterListen('store_'.$category.'_un_'.$relationType,$productId,$uid,false,StoreProductBehavior::class);
  42. return true;
  43. }
  44. public static function productRelationNum($productId,$relationType,$category = 'product')
  45. {
  46. $relationType = strtolower($relationType);
  47. $category = strtolower($category);
  48. return self::where('type',$relationType)->where('product_id',$productId)->where('category',$category)->count();
  49. }
  50. public static function isProductRelation($product_id,$uid,$relationType,$category = 'product')
  51. {
  52. $type = strtolower($relationType);
  53. $category = strtolower($category);
  54. return self::be(compact('product_id','uid','type','category'));
  55. }
  56. public static function collection_list($uid,$page,$limit){
  57. $list=self::where(['a.uid'=>$uid,'a.category'=>'integral','a.type'=>'collect'])->alias('a')
  58. ->join('integral_product i','a.product_id=i.id','left')->field(['i.image','i.integral','i.integral_name','i.id'])
  59. ->page((int)$page,(int)$limit)->select();
  60. $page++;
  61. return compact('list','page');
  62. }
  63. }