123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\model\order;
- use app\model\product\branch\StoreBranchProductAttrValue;
- use app\model\product\product\StoreProduct;
- use app\model\product\sku\StoreProductAttrValue;
- use app\model\user\User;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- use think\Model;
- /**
- * 购物车Model
- * Class StoreCart
- * @package app\model\order
- */
- class StoreCart extends BaseModel
- {
- use ModelTrait;
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'store_cart';
- /**
- * 自动添加字段
- * @var string[]
- */
- protected $insert = ['add_time'];
- /**
- * @return \think\model\relation\HasOne
- */
- public function user()
- {
- return $this->hasOne(User::class, 'uid', 'uid')->bind([
- 'nickname' => 'nickname',
- 'avatar' => 'avatar'
- ]);
- }
- /**
- * 添加时间修改器
- * @return int
- */
- protected function setAddTimeAttr()
- {
- return time();
- }
- /**
- * 一对一关联
- * 购物车关联商品商品详情
- * @return \think\model\relation\HasOne
- */
- public function productInfo()
- {
- return $this->hasOne(StoreProduct::class, 'id', 'product_id');
- }
- /**
- * 一对一关联
- * 购物车关联商品商品规格
- * @return \think\model\relation\HasOne
- */
- public function attrInfo()
- {
- return $this->hasOne(StoreProductAttrValue::class, 'unique', 'product_attr_unique');
- }
- /**
- * 门店规格表
- * @return \think\model\relation\HasOne
- */
- public function storeBranchProductAttr()
- {
- return $this->hasOne(StoreBranchProductAttrValue::class, 'unique', 'product_attr_unique');
- }
- /**
- * 类型搜索器
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchTypeAttr($query, $value, $data)
- {
- $query->where('type', $value);
- }
- /**
- * 购物车ID搜索器
- * @param $query
- * @param $value
- */
- public function searchCartIdsAttr($query, $value)
- {
- if ($value) {
- if (is_array($value)) {
- $query->whereIn('id', $value);
- } else {
- $query->where('id', $value);
- }
- }
- }
- /**
- * 是否支付
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchIsPayAttr($query, $value, $data)
- {
- $query->where('is_pay', $value);
- }
- /**
- * 是否删除
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchIsDelAttr($query, $value, $data)
- {
- $query->where('is_del', $value);
- }
- /**
- * 是否立即支付
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchIsNewAttr($query, $value, $data)
- {
- $query->where('is_new', $value);
- }
- /**
- * 查询用户购物车
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchUidAttr($query, $value, $data)
- {
- $query->where('uid', $value);
- }
- /**
- * @param $query
- * @param $value
- */
- public function searchTouristUidAttr($query, $value)
- {
- if ($value) {
- $query->where('tourist_uid', $value);
- }
- }
- /**
- * 商品ID搜索器
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchProductIdAttr($query, $value, $data)
- {
- if (is_array($value)) {
- $query->whereIn('product_id', $value);
- } else {
- $query->where('product_id', $value);
- }
- }
- /**
- * 商品类型搜索器
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchProductTypeAttr($query, $value, $data)
- {
- if (is_array($value)) {
- $query->whereIn('product_type', $value);
- } else {
- $query->where('product_type', $value);
- }
- }
- /**
- * 商品规格唯一值搜索器
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchProductAttrUniqueAttr($query, $value, $data)
- {
- $query->where('product_attr_unique', $value);
- }
- /**
- * store_id搜索器
- * @param $query
- * @param $value
- */
- public function searchStoreIdAttr($query, $value)
- {
- if ($value !== '') $query->where('store_id', $value);
- }
- /**
- * 店员搜索器
- * @param $query
- * @param $value
- */
- public function searchStaffIdAttr($query, $value)
- {
- if ($value !== '') {
- $query->where('staff_id', $value);
- }
- }
- /**
- * 一对多关联
- * 商品关联优惠卷模板id
- * @return \think\model\relation\HasMany
- */
- public function product()
- {
- return $this->hasMany(StoreProduct::class, 'id', 'product_id');
- }
- }
|