ProductModel.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\common\model;
  3. /**
  4. * 产品信息表
  5. * Class ProductModel
  6. * @package app\common\model
  7. */
  8. class ProductModel extends BaseModel
  9. {
  10. protected $table = 'product';
  11. public function getProductPage($page,$pageSize,$condition=[],$is_count = false,$order=''){
  12. $join=[
  13. ['product_type type','type.type_id=product.type_id','LEFT'],
  14. ];
  15. $this->alias('product')
  16. ->field('product.*,type.type_name')
  17. ->join($join);
  18. if(!empty($condition)){
  19. $this->where($condition);
  20. }
  21. if(!empty($order)){
  22. $this->order($order);
  23. }
  24. if($is_count){
  25. return $this->count();
  26. }
  27. return $this->page($page,$pageSize)->select();
  28. }
  29. /**
  30. * 获取商品和商品促销信息给首页用
  31. * @param array $condition
  32. * @param int $doctor_no
  33. * @return false|\PDOStatement|string|\think\Collection
  34. */
  35. public function getProductAndPromoList($condition=[],$doctor_no=0,$order='',$action='2'){
  36. //开始获取产品和促销信息
  37. $this->alias('product')
  38. ->field('product.*,doctor_guide.price as doctor_price,product_promo.price as promo_price,product_config.config_id,product_type.type_name')
  39. ->join('product_promo product_promo','product.product_no=product_promo.product_no and product_promo.status=1','left')
  40. ->join('product_config product_config','product.product_no=product_config.product_no and product_config.status=1','left');
  41. if($action==2){
  42. $this->join('doctor_guide doctor_guide',"doctor_guide.product_no=product.product_no and doctor_guide.doctor_no=$doctor_no",'left');
  43. }else{
  44. $this ->join('doctor_guide doctor_guide',"doctor_guide.product_no=product.product_no and doctor_guide.doctor_no=$doctor_no",'right');
  45. }
  46. $this ->join('product_type product_type','product.type_id = product_type.type_id and product_type.status=1','left')
  47. ->where($condition);
  48. if($order){
  49. $this->order($order);
  50. }
  51. $list = $this->select();
  52. //echo $this->getLastSql();exit;
  53. //print_r($list);exit;
  54. foreach($list as &$product){
  55. // echo $product['product_name'];echo "<br/>";
  56. $sales_price = $product['promo_price'] !== null?$product['promo_price']:$product['member_price'];
  57. $sales_price = $product['doctor_price'] !== null?$product['doctor_price']:$sales_price;
  58. $intPrice = intval($sales_price/100);
  59. $dotPrice = intval($sales_price%100);
  60. $dotPrice = str_pad($dotPrice,2,0,STR_PAD_LEFT);
  61. $product['sales_price'] = $intPrice.".".$dotPrice;
  62. $member_price = $product['member_price'];
  63. $intPrice = intval($member_price/100);
  64. $dotPrice = intval($member_price%100);
  65. $dotPrice = str_pad($dotPrice,2,0,STR_PAD_LEFT);
  66. $product['member_price'] = $intPrice.".".$dotPrice;
  67. }
  68. //exit;
  69. return $list;
  70. }
  71. public function getProductAndPromoOne($condition=[],$doctor_no=0){
  72. //开始获取产品和促销信息
  73. $product = $this->alias('product')
  74. ->field('product.*,doctor_guide.price as doctor_price,product_promo.price as promo_price,product_config.config_id,product_type.type_name')
  75. ->join('product_promo product_promo','product.product_no=product_promo.product_no and product_promo.status=1','left')
  76. ->join('product_config product_config','product.product_no=product_config.product_no and product_config.status=1','left')
  77. ->join('doctor_guide doctor_guide',"doctor_guide.product_no=product.product_no and doctor_guide.doctor_no=$doctor_no",'left')
  78. ->join('product_type product_type','product.type_id = product_type.type_id and product_type.status=1','left')
  79. ->where($condition)
  80. ->find();
  81. // print_r($product);exit;
  82. $sales_price = $product['promo_price'] !== null?$product['promo_price']:$product['member_price'];
  83. $sales_price = $product['doctor_price'] !== null?$product['doctor_price']:$sales_price;
  84. $intPrice = intval($sales_price/100);
  85. $dotPrice = intval($sales_price%100);
  86. $dotPrice = str_pad($dotPrice,2,0,STR_PAD_LEFT);
  87. $product['sales_price'] = $intPrice.".".$dotPrice;
  88. $member_price = $product['member_price'];
  89. $intPrice = intval($member_price/100);
  90. $dotPrice = intval($member_price%100);
  91. $dotPrice = str_pad($dotPrice,2,0,STR_PAD_LEFT);
  92. $product['member_price'] = $intPrice.".".$dotPrice;
  93. return $product;
  94. }
  95. }