1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\model\api;
- use library\traits\ModelTrait;
- use think\Model;
- /**
- * @mixin \think\Model
- */
- class Product extends Model
- {
- use ModelTrait;
- public static function getProductList($data)
- {
- $cid = $data['cid'];
- $keyword = $data['keyword'];
- $page = $data['page'];
- $limit = $data['limit'];
- $model = self::where('is_del', 0)->where('is_show', 1);
- if($keyword != ''){
- $model->where('store_name|keyword', 'LIKE', "%$keyword%");
- }
- if($cid){
- if($cid > 0){
- $model->where('cate_id', $cid);
- }else{
- if($cid == -1){
- $model->where('issuing', 1);
- }
- if($cid == -2){
- $model->where('is_leftover', 1);
- }
- if($cid == -3) {
- $model->where('is_best', 1);
- }
- }
- if($data['sort'] == 'sort' || $data['sort'] == ''){
- $model->order('sort DESC, add_time DESC');
- }
- }else{
- $model->where('stars', '>', 1);
- if($data['sort'] == 'sort'){
- $model->order('stars DESC, sort DESC, add_time DESC');
- }
- }
- if($data['sort'] == 'sales'){
- $model->orderRaw('sales+ficti desc');
- }
- if($data['sort'] == 'commission'){
- $model->orderRaw('price-ot_price desc');
- }
- if($data['sort'] == 'new'){
- $model->order('add_time DESC');
- }
- $list = $model->page((int)$page, (int)$limit)->field('id,store_name,image,price,cost,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,label,is_new')->select();
- $list = count($list) ? $list->toArray() : [];
- $count = $model->count();
- return ['count' => $count, 'list' => $list];
- }
- 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,detail_image,sort,stock,store_info,store_name,unit_name,vip_price,spec_type,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,video_link,description,code,is_new')
- {
- $Product = self::where('is_del', 0)->where('is_show', 1)->where('id', $productId)->field($field)->find();
- if ($Product) return $Product->toArray();
- else return false;
- }
- public static function getGoodList($limit = 18, $field = '*')
- {
- $list = self::where('is_best', 1)->order('sort desc,id desc')->limit($limit)->field($field)->select();
- $list = count($list) ? $list->toArray() : [];
- return $list;
- }
- }
|