12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- /**
- * Author: luzheng.liu
- * Time: 2020/12/5 19:52
- */
- namespace app\api\model;
- use app\common\until\Until;
- use think\Db;
- class ProductModel extends BaseModel {
- const NORMAL = 1;
- const OFF = 2; //下架
- protected $table = 'product';
- public function getProductList() {
- $countModel = $this->alias('p')
- ->join('company c','c.id = p.company_id','left')
- ->join('brand b','b.id = p.brand_id','left')
- ->join('product_template ptemp','ptemp.product_id = p.id')
- ->join('store_product_template spt','spt.template_id = ptemp.template_id')
- ->join('product_type pt','pt.id = p.product_type_id','left');
- $selectModel = $this->alias('p')
- ->field('p.*,c.company_name,b.brand_name,pt.product_type_name,ptemp.price realPrice')
- ->join('company c', 'c.id = p.company_id', 'left')
- ->join('brand b', 'b.id = p.brand_id', 'left')
- ->join('product_type pt', 'pt.id = p.product_type_id', 'left')
- ->join('product_template ptemp','ptemp.product_id = p.id')
- ->join('store_product_template spt','spt.template_id = ptemp.template_id')
- ->order(['p.id' => 'desc']);
- return $this->joinModelPageList($countModel, $selectModel);
- }
- public function getProductInfo() {
- $selectModel = $this->alias('p')
- ->field('p.*,c.company_name,b.brand_name,pt.product_type_name,ptemp.price realPrice')
- ->join('company c','c.id = p.company_id')
- ->join('brand b','b.id = p.brand_id')
- ->join('product_template ptemp','ptemp.product_id = p.id')
- ->join('store_product_template spt','spt.template_id = ptemp.template_id')
- ->join('product_type pt','pt.id = p.product_type_id')
- ->where($this->getWhere())
- ->find();
- return Until::modelToArray($selectModel);
- }
- }
|