12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace app\common\model;
- use think\Model;
- // 商品
- class StoreGoods extends Model
- {
- //protected $resultSetType = 'collection';// 设置返回类型
- public function itemList()
- {
- return $this->hasMany('StoreGoodsItem','goods_id','id')->with(['depotItemInfo'])->where(['is_deleted'=>0,'status'=>1]);
- }
- public function Param()
- {
- return $this->hasOne('GoodsParam','goods_id','base_id');
- }
- /**
- * 获取商品规格详情
- * @param $goods_id 商品id
- * @param $spec_id 规格id
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getGoodsSpec($goods_id,$spec_id){
- $goods_info = self::with(['itemList'=>function($query)use($spec_id){
- return $query->where('id',$spec_id)->where('is_deleted',0);
- }])->where('id',$goods_id)->where('is_deleted',0)->where('status',1)->find();
- return $goods_info ? $goods_info->toArray() : [];
- }
- /**
- * 商品分销设置
- * @return \think\model\relation\HasOne
- */
- public function dist()
- {
- return $this->hasOne('GoodsParam','goods_id');
- }
- // 获取商品所属
- public static function getGoodsBelong($goods_id)
- {
- $belong = 0;
- $is_nu = InformationGoods::where(['goods_id'=>$goods_id])->count();
- if($is_nu){
- $belong = 1;
- }
- return $belong;
- }
- }
|