123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\wap\model\store;
- use basic\ModelBasic;
- use behavior\wap\StoreProductBehavior;
- use service\HookService;
- use traits\ModelTrait;
- /**商品点赞和收藏表
- * Class StoreProductRelation
- * @package app\wap\model\store
- */
- class StoreProductRelation extends ModelBasic
- {
- use ModelTrait;
- protected $insert = ['add_time'];
- protected function setAddTimeAttr($value)
- {
- return time();
- }
- public static function productRelation($productId, $uid, $relationType, $category = 'product')
- {
- if (!$productId) return self::setErrorInfo('产品不存在!');
- $relationType = strtolower($relationType);
- $category = strtolower($category);
- $data = ['uid' => $uid, 'product_id' => $productId, 'type' => $relationType, 'category' => $category];
- if (self::be($data)) return true;
- $data = self::set($data);
- HookService::afterListen('store_' . $category . '_' . $relationType, $productId, $uid, false, StoreProductBehavior::class);
- return $data;
- }
- public static function unProductRelation($productId, $uid, $relationType, $category = 'product')
- {
- if (!$productId) return self::setErrorInfo('产品不存在!');
- $relationType = strtolower($relationType);
- $category = strtolower($category);
- self::where(['uid' => $uid, 'product_id' => $productId, 'type' => $relationType, 'category' => $category])->delete();
- HookService::afterListen('store_' . $category . '_un_' . $relationType, $productId, $uid, false, StoreProductBehavior::class);
- return true;
- }
- public static function productRelationNum($productId, $relationType, $category = 'product')
- {
- $relationType = strtolower($relationType);
- $category = strtolower($category);
- return self::where('type', $relationType)->where('product_id', $productId)->where('category', $category)->count();
- }
- public static function isProductRelation($product_id, $uid, $relationType, $category = 'product')
- {
- $type = strtolower($relationType);
- $category = strtolower($category);
- return self::be(compact('product_id', 'uid', 'type', 'category'));
- }
- public static function collection_list($uid, $page, $limit)
- {
- $list = self::where(['a.uid' => $uid, 'a.category' => 'integral', 'a.type' => 'collect'])->alias('a')
- ->join('integral_product i', 'a.product_id=i.id', 'left')->field(['i.image', 'i.integral', 'i.integral_name', 'i.id'])
- ->page((int)$page, (int)$limit)->select();
- $page++;
- return compact('list', 'page');
- }
- }
|