123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- namespace app\common\model;
- use traits\model\SoftDelete;
- /**
- * 产品信息表
- * Class ProductModel
- * @package app\common\model
- */
- class ProductModel extends BaseModel
- {
- use SoftDelete;
- protected $table = 'product';
- protected $deleteTime = 'delete_time';
- /**
- * 获取元单位的金额
- * @param $value
- * @return string
- */
- public function getMemberPrice($value)
- {
- $member_price = $value/100;
- return sprintf("%.2f", $member_price);
- }
- /**
- * 获取数组图片
- * @param $image
- * @return array
- */
- public function getImages($image)
- {
- $arr = json_decode($image,true);
- $images = [];
- foreach ($arr as $item){
- $images[] = config('admin_host').$item;
- }
- return $images;
- }
- /**
- * 获取单张图片
- * @param $image
- * @return mixed
- */
- public function getImage($image)
- {
- $arr = json_decode($image,true);
- return config('admin_host').$arr[0];
- }
- /**
- * 检查商品的库存
- * @param $product_arr
- * @return array|bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function checkProductNumber($product_arr)
- {
- $product_info = $product_arr['product_info'];
- $error='';
- foreach ($product_info as $item){
- if($item['number'] > $item['stock']){
- $error.=$item['product_name'].'剩余'.$item['stock'].';';
- }
- }
- if(!empty($error)){
- return [
- 'title'=>'库存不足',
- 'msg'=>$error
- ];
- }else{
- return false;
- }
- }
- public function getProductPage($page,$pageSize,$condition=[],$is_count = false,$order=''){
- $join=[
- ['product_type type','type.type_id=product.type_id','LEFT'],
- ];
- $this->alias('product')
- ->field('product.*,type.type_name')
- ->join($join);
- if(!empty($condition)){
- $this->where($condition);
- }
- if(!empty($order)){
- $this->order($order);
- }
- if($is_count){
- return $this->count();
- }
- return $this->page($page,$pageSize)->select();
- }
- /**
- * 获取商品和商品促销信息给首页用
- * @param array $condition
- * @param int $doctor_no
- * @return false|\PDOStatement|string|\think\Collection
- */
- public function getProductAndPromoList($condition=[],$doctor_no=0){
- //开始获取产品和促销信息
- $list = $this->alias('product')
- ->field('product.*,product_promo.price as promo_price,product_config.config_id')
- ->join('product_promo product_promo','product.product_no=product_promo.product_no and product_promo.status=1','left')
- ->join('product_config product_config','product.product_no=product_config.product_no and product_config.status=1','left')
- ->join('doctor_guide doctor_guide',"doctor_guide.product_no=product.product_no and doctor_guide.doctor_no=$doctor_no",'left')
- ->where($condition)
- ->select();
- foreach($list as &$product){
- $member_price = !empty($product['promo_price'])?$product['promo_price']:$product['member_price'];
- $intPrice = intval($member_price/100);
- $dotPrice = intval($member_price%100);
- $dotPrice = str_pad($dotPrice,2,0);
- $product['sales_price'] = $intPrice.".".$dotPrice;
- }
- return $list;
- }
- public function getProductAndPromoOne($condition=[],$doctor_no=0){
- //开始获取产品和促销信息
- $product = $this->alias('product')
- ->field('product.*,product_promo.price as promo_price,product_config.config_id')
- ->join('product_promo product_promo','product.product_id=product_promo.product_id and product_promo.status=1','left')
- ->join('product_config product_config','product.product_id=product_config.product_id and product_config.status=1','left')
- ->join('doctor_guide doctor_guide',"doctor_guide.product_no=product.product_no and doctor_guide.doctor_no=$doctor_no",'left')
- ->where($condition)
- ->find();
- $member_price = !empty($product['promo_price'])?$product['promo_price']:$product['member_price'];
- $intPrice = intval($member_price/100);
- $dotPrice = intval($member_price%100);
- $dotPrice = str_pad($dotPrice,2,0);
- $product['sales_price'] = $intPrice.".".$dotPrice;
- return $product;
- }
- }
|