isLogin() && $auth->getUser()->is_vipprice == 1){ $is_vipprice = 1; } //vip改价格 return $is_vipprice == 1 ? $data['market_price'] : $data['sales_price']; } /** * 处理规格值 * @param $value * @param $data * @return mixed */ public function getSpecTableListAttr($value, $data) { $specs = !empty($data['specTableList']) ? json_decode($data['specTableList'], true) : []; //vip改价格 $auth = \app\common\library\Auth::instance(); $is_vipprice = 0; if($auth->isLogin() && $auth->getUser()->is_vipprice == 1){ $is_vipprice = 1; } foreach ($specs as &$spec) { unset($spec['code']); $spec['image'] = Config::getImagesFullUrl($spec['image']); $spec['value_text'] = ''; if(!empty($spec['value'])){ $spec['value_text'] = implode(',',$spec['value']); } //vip改价格 $spec['sales_price'] = $is_vipprice == 1 ? $spec['market_price'] : $spec['sales_price']; } return $specs; } /** * 处理详情里面的图片 * @param $value * @param $data */ public function getDescAttr($value, $data) { return str_replace('src="/uploads/','src="'.Config::getHttpLocation().'/uploads/',$data['desc']); } /** * 获取创建订单需要的产品信息 * @param string $spec * @param int $number * @return array * @throws Exception */ public function getDataOnCreateOrder(string $spec = '', $number = 1) { $data = (new \addons\unishop\extend\Product)->getBaseData($this->getData(), $spec); if ($data['stock'] < 1) { throw new Exception('产品库存不足'); } $product = $this->getData(); $data['title'] = $product['title']; $data['spec'] = $spec; $data['number'] = $number; $data['id'] = Hashids::encodeHex($product['id']); $data['total_price'] = bcmul($data['sales_price'],$number,2); return $data; } }