StoreGoods.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. // 商品
  5. class StoreGoods extends Model
  6. {
  7. //protected $resultSetType = 'collection';// 设置返回类型
  8. public function itemList()
  9. {
  10. return $this->hasMany('StoreGoodsItem','goods_id','id')->with(['depotItemInfo'])->where(['is_deleted'=>0,'status'=>1]);
  11. }
  12. public function Param()
  13. {
  14. return $this->hasOne('GoodsParam','goods_id','base_id');
  15. }
  16. /**
  17. * 获取商品规格详情
  18. * @param $goods_id 商品id
  19. * @param $spec_id 规格id
  20. * @return array
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. * @throws \think\exception\DbException
  24. */
  25. public static function getGoodsSpec($goods_id,$spec_id){
  26. $goods_info = self::with(['itemList'=>function($query)use($spec_id){
  27. return $query->where('id',$spec_id)->where('is_deleted',0);
  28. }])->where('id',$goods_id)->where('is_deleted',0)->where('status',1)->find();
  29. return $goods_info ? $goods_info->toArray() : [];
  30. }
  31. /**
  32. * 商品分销设置
  33. * @return \think\model\relation\HasOne
  34. */
  35. public function dist()
  36. {
  37. return $this->hasOne('GoodsParam','goods_id');
  38. }
  39. // 获取商品所属
  40. public static function getGoodsBelong($goods_id)
  41. {
  42. $belong = 0;
  43. $is_nu = InformationGoods::where(['goods_id'=>$goods_id])->count();
  44. if($is_nu){
  45. $belong = 1;
  46. }
  47. return $belong;
  48. }
  49. }