123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace app\common\model;
- /**
- * 产品信息表
- * Class ProductModel
- * @package app\common\model
- */
- class ProductModel extends BaseModel
- {
- protected $table = 'product';
- 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,$order='',$action='2'){
- //开始获取产品和促销信息
- $this->alias('product')
- ->field('product.*,doctor_guide.price as doctor_price,product_promo.price as promo_price,product_config.config_id,product_type.type_name')
- ->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');
- if($action==2){
- $this->join('doctor_guide doctor_guide',"doctor_guide.product_no=product.product_no and doctor_guide.doctor_no=$doctor_no",'left');
- }else{
- $this ->join('doctor_guide doctor_guide',"doctor_guide.product_no=product.product_no and doctor_guide.doctor_no=$doctor_no",'right');
- }
- $this ->join('product_type product_type','product.type_id = product_type.type_id and product_type.status=1','left')
- ->where($condition);
- if($order){
- $this->order($order);
- }
- $list = $this->select();
- //echo $this->getLastSql();exit;
- //print_r($list);exit;
- foreach($list as &$product){
- // echo $product['product_name'];echo "<br/>";
- $sales_price = $product['promo_price'] !== null?$product['promo_price']:$product['member_price'];
- $sales_price = $product['doctor_price'] !== null?$product['doctor_price']:$sales_price;
- $intPrice = intval($sales_price/100);
- $dotPrice = intval($sales_price%100);
- $dotPrice = str_pad($dotPrice,2,0,STR_PAD_LEFT);
- $product['sales_price'] = $intPrice.".".$dotPrice;
- $member_price = $product['member_price'];
- $intPrice = intval($member_price/100);
- $dotPrice = intval($member_price%100);
- $dotPrice = str_pad($dotPrice,2,0,STR_PAD_LEFT);
- $product['member_price'] = $intPrice.".".$dotPrice;
- }
- //exit;
- return $list;
- }
- public function getProductAndPromoOne($condition=[],$doctor_no=0){
- //开始获取产品和促销信息
- $product = $this->alias('product')
- ->field('product.*,doctor_guide.price as doctor_price,product_promo.price as promo_price,product_config.config_id,product_type.type_name')
- ->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')
- ->join('product_type product_type','product.type_id = product_type.type_id and product_type.status=1','left')
- ->where($condition)
- ->find();
- // print_r($product);exit;
- $sales_price = $product['promo_price'] !== null?$product['promo_price']:$product['member_price'];
- $sales_price = $product['doctor_price'] !== null?$product['doctor_price']:$sales_price;
- $intPrice = intval($sales_price/100);
- $dotPrice = intval($sales_price%100);
- $dotPrice = str_pad($dotPrice,2,0,STR_PAD_LEFT);
- $product['sales_price'] = $intPrice.".".$dotPrice;
- $member_price = $product['member_price'];
- $intPrice = intval($member_price/100);
- $dotPrice = intval($member_price%100);
- $dotPrice = str_pad($dotPrice,2,0,STR_PAD_LEFT);
- $product['member_price'] = $intPrice.".".$dotPrice;
- return $product;
- }
- }
|