ProductModel.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/12/5 19:52
  5. */
  6. namespace app\api\model;
  7. use app\common\until\Until;
  8. use think\Db;
  9. class ProductModel extends BaseModel {
  10. const NORMAL = 1;
  11. const OFF = 2; //下架
  12. protected $table = 'product';
  13. public function getProductList() {
  14. $countModel = $this->alias('p')
  15. ->join('company c','c.id = p.company_id','left')
  16. ->join('brand b','b.id = p.brand_id','left')
  17. ->join('product_template ptemp','ptemp.product_id = p.id')
  18. ->join('store_product_template spt','spt.template_id = ptemp.template_id')
  19. ->join('product_type pt','pt.id = p.product_type_id','left');
  20. $selectModel = $this->alias('p')
  21. ->field('p.*,c.company_name,b.brand_name,pt.product_type_name,ptemp.price realPrice')
  22. ->join('company c', 'c.id = p.company_id', 'left')
  23. ->join('brand b', 'b.id = p.brand_id', 'left')
  24. ->join('product_type pt', 'pt.id = p.product_type_id', 'left')
  25. ->join('product_template ptemp','ptemp.product_id = p.id')
  26. ->join('store_product_template spt','spt.template_id = ptemp.template_id')
  27. ->order(['p.id' => 'desc']);
  28. return $this->joinModelPageList($countModel, $selectModel);
  29. }
  30. public function getProductInfo() {
  31. $selectModel = $this->alias('p')
  32. ->field('p.*,c.company_name,b.brand_name,pt.product_type_name,ptemp.price realPrice')
  33. ->join('company c','c.id = p.company_id')
  34. ->join('brand b','b.id = p.brand_id')
  35. ->join('product_template ptemp','ptemp.product_id = p.id')
  36. ->join('store_product_template spt','spt.template_id = ptemp.template_id')
  37. ->join('product_type pt','pt.id = p.product_type_id')
  38. ->where($this->getWhere())
  39. ->find();
  40. return Until::modelToArray($selectModel);
  41. }
  42. }