| | |
| | | { |
| | | return json_encode($data); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改器:预告开启购买时间 |
| | | */ |
| | | public function setPreviewTimeAttr($value) |
| | | { |
| | | return $value ? strtotime($value) : 0; |
| | | } |
| | | |
| | | /** |
| | | * 优惠券数组转换 |
| | | * @param $value |
| | | * @param $data |
| | | * @return string |
| | | */ |
| | | public function setOpenCouponsAttr($value) |
| | | { |
| | | return $value ? json_encode($value) : ''; |
| | | } |
| | | |
| | | /** |
| | | * 数组转换 |
| | | * @param $value |
| | | * @param $data |
| | | * @return string |
| | | */ |
| | | public function getOpenCouponsAttr($value) |
| | | { |
| | | return $value ? json_decode($value, 1) : []; |
| | | } |
| | | |
| | | /** |
| | | * 关联商品多分类表 |
| | | */ |
| | | public function categorys() |
| | | { |
| | | return $this->hasMany('app\\common\\model\\product\\ProductCategory', 'product_id', 'product_id'); |
| | | } |
| | | |
| | | /** |
| | | * 关联商品多分类表 |
| | | */ |
| | | public function category_ids() |
| | | { |
| | | return $this->hasMany('app\\common\\model\\product\\ProductCategory', 'product_id', 'product_id'); |
| | | } |
| | | |
| | | /** |
| | |
| | | public function supplier() |
| | | { |
| | | return $this->belongsTo('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id') |
| | | ->field(['shop_supplier_id', 'name', 'address', 'logo_id']); |
| | | ->field(['shop_supplier_id', 'name', 'address', 'logo_id','supplier_type','gift_type']); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'video_id'); |
| | | } |
| | | |
| | | /** |
| | | * 关联视频封面 |
| | | */ |
| | |
| | | $model = $this; |
| | | if ($params['category_id'] > 0) { |
| | | $arr = Category::getSubCategoryId($params['category_id']); |
| | | $model = $model->where('product.category_id', 'IN', $arr); |
| | | $productIds = ProductCategory::getProductIds($params['category_id']); |
| | | if ($productIds) { |
| | | $model = $model->whereRaw('product.category_id in (' . implode(',', $arr) . ') OR product_id in (' . implode(',', $productIds) . ')'); |
| | | } else { |
| | | $model = $model->where('product.category_id', 'IN', $arr); |
| | | } |
| | | } |
| | | if (!empty($params['product_name'])) { |
| | | $model = $model->where('product_name', 'like', '%' . trim($params['product_name']) . '%'); |
| | |
| | | |
| | | // 是否有城市ids by yj |
| | | if (!empty($params['city_supplier_ids'])) { |
| | | $city_supplier_ids = explode(",",$params['city_supplier_ids']); |
| | | $city_supplier_ids = explode(",", $params['city_supplier_ids']); |
| | | $model = $model->where('product.shop_supplier_id', 'IN', $city_supplier_ids); |
| | | } |
| | | // 排序规则 |
| | |
| | | if (isset($params['type'])) { |
| | | $model = $this->buildProductType($model, $params['type']); |
| | | } |
| | | if(isset($params['shop_supplier_id'])&&$params['shop_supplier_id']){ |
| | | if (isset($params['shop_supplier_id']) && $params['shop_supplier_id']) { |
| | | $model = $model->where('product.shop_supplier_id', '=', $params['shop_supplier_id']); |
| | | } |
| | | if(isset($params['shop_supplier_ids'])&&$params['shop_supplier_ids']){ |
| | | if (isset($params['shop_supplier_ids']) && $params['shop_supplier_ids']) { |
| | | $model = $model->where('product.shop_supplier_id', 'in', $params['shop_supplier_ids']); |
| | | } |
| | | if(isset($params['product_id'])&&$params['product_id']){ |
| | | $model = $model->whereNotIn('product_id',$params['product_id']); |
| | | if (isset($params['product_id']) && $params['product_id']) { |
| | | $model = $model->whereNotIn('product_id', $params['product_id']); |
| | | } |
| | | // 多规格商品 最高价与最低价 |
| | | $ProductSku = new ProductSku; |
| | |
| | | "$minPriceSql AS product_min_price", |
| | | "$maxPriceSql AS product_max_price" |
| | | ]) |
| | | ->with(['category', 'image.file', 'sku', 'supplier']) |
| | | ->join('supplier supplier', 'product.shop_supplier_id = supplier.shop_supplier_id','left') |
| | | ->with(['category', 'image.file', 'sku', 'supplier', 'spec_rel.spec']) |
| | | ->join('supplier supplier', 'product.shop_supplier_id = supplier.shop_supplier_id', 'left') |
| | | ->where('product.is_delete', '=', 0) |
| | | ->where('supplier.is_delete', '=', 0) |
| | | ->where('supplier.status', '=', 0) |
| | |
| | | // 商品默认规格 |
| | | $product['product_sku'] = self::getShowSku($product); |
| | | // 等级id转换成数组 |
| | | if(!is_array ($product['grade_ids'])){ |
| | | if($product['grade_ids'] != ''){ |
| | | if (!is_array($product['grade_ids'])) { |
| | | if ($product['grade_ids'] != '') { |
| | | $product['grade_ids'] = explode(',', $product['grade_ids']); |
| | | } else { |
| | | $product['grade_ids'] = []; |
| | | } |
| | | } |
| | | // 可核销门店ids by yj |
| | | if(!is_array($product['verify_store_ids'])){ |
| | | if($product['verify_store_ids'] != ''){ |
| | | if (!is_array($product['verify_store_ids'])) { |
| | | if ($product['verify_store_ids'] != '') { |
| | | $product['verify_store_ids'] = explode(',', $product['verify_store_ids']); |
| | | } else { |
| | | $product['verify_store_ids'] = []; |
| | | } |
| | | } |
| | | // 核销有效时间段 |
| | | if($product['verify_type'] == 20){ |
| | | if ($product['verify_type'] == 20) { |
| | | $product['verify_time'] = [date('Y-m-d H:i:s', $product['verify_start_time']), date('Y-m-d H:i:s', $product['verify_end_time'])]; |
| | | } |
| | | // 商品多分类 by lyzflash |
| | | $product['category_ids'] = []; |
| | | if (!$product['categorys']->isEmpty()) { |
| | | $product['category_ids'] = helper::getArrayColumn($product['categorys'], 'category_id'); |
| | | $product['category_names'] = implode('、', helper::getArrayColumn((new Category)->getListByIds($product['category_ids']), 'name')); |
| | | } else { |
| | | // 兼容没有多分类前的数据 by lyzflash |
| | | if ($product['category_id']) { |
| | | $product['category_ids'] = [$product['category_id']]; |
| | | } |
| | | } |
| | | // 回调函数 |
| | | is_callable($callback) && call_user_func($callback, $product); |
| | |
| | | 'supplier.logo', |
| | | 'video', |
| | | 'poster', |
| | | 'categorys.category', |
| | | 'contentImage.file', |
| | | ])->where('product_id', '=', $product_id) |
| | | ->find(); |
| | |
| | | public static function getShowSku($product) |
| | | { |
| | | //如果是单规格 |
| | | if($product['spec_type'] == 10){ |
| | | if ($product['spec_type'] == 10) { |
| | | return $product['sku'][0]; |
| | | }else{ |
| | | } else { |
| | | //多规格返回最低价 |
| | | foreach ($product['sku'] as $sku){ |
| | | if($product['product_price'] == $sku['product_price']){ |
| | | foreach ($product['sku'] as $sku) { |
| | | if ($product['product_price'] == $sku['product_price']) { |
| | | return $sku; |
| | | } |
| | | } |