Product.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\model\api;
  3. use library\traits\ModelTrait;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class Product extends Model
  9. {
  10. use ModelTrait;
  11. public static function getProductList($data)
  12. {
  13. $cid = $data['cid'];
  14. $page = $data['page'];
  15. $limit = $data['limit'];
  16. if($cid){
  17. $model = self::where('cate_id', $cid);
  18. }else{
  19. $model = self::where('is_best', 1);
  20. }
  21. $model->order('sort DESC, add_time DESC');
  22. $list = $model->page((int)$page, (int)$limit)->field('id,store_name,image,price,cost,ot_price')->select();
  23. $list = count($list) ? $list->toArray() : [];
  24. return $list;
  25. }
  26. public static function getValidProduct($productId, $field = 'add_time,browse,cate_id,code_path,cost,ficti,id,image,is_sub,is_best,is_del,is_hot,is_show,keyword,ot_price,postage,price,sales,slider_image,sort,stock,store_info,store_name,unit_name,vip_price,spec_type,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,video_link,description')
  27. {
  28. $Product = self::where('is_del', 0)->where('is_show', 1)->where('id', $productId)->field($field)->find();
  29. if ($Product) return $Product->toArray();
  30. else return false;
  31. }
  32. }