diff --git a/application/admin/controller/store/StoreProduct.php b/application/admin/controller/store/StoreProduct.php index 10a0dd5b..19d08549 100644 --- a/application/admin/controller/store/StoreProduct.php +++ b/application/admin/controller/store/StoreProduct.php @@ -8,6 +8,7 @@ use app\admin\model\store\StoreProductAttr; use app\admin\model\store\StoreProductAttrResult; use app\admin\model\store\StoreProductRelation; use app\admin\model\system\SystemConfig; +use service\JsonService; use traits\CurdControllerTrait; use service\UtilService as Util; use service\JsonService as Json; @@ -41,43 +42,87 @@ class StoreProduct extends AuthController */ public function index() { - $where = Util::getMore([ - ['type',$this->request->param('type')], - ['cate_id',''], - ['is_show',''], - ['store_name',''], - ['sales',''], - ['export',0] - ],$this->request); - $this->assign('cate',CategoryModel::getTierList()); + $type=$this->request->param('type'); + //获取分类 + $this->assign('cate',CategoryModel::getTierList()); //出售中产品 - $data = ['is_show'=>1,'is_del'=>0]; - $onsale = ProductModel::where($data)->count(); + $onsale = ProductModel::where(['is_show'=>1,'is_del'=>0])->count(); //待上架产品 - $data = ['is_show'=>0,'is_del'=>0]; - $forsale = ProductModel::where($data)->count(); + $forsale = ProductModel::where(['is_show'=>0,'is_del'=>0])->count(); //仓库中产品 - $data = ['is_del'=>0]; - $warehouse = ProductModel::where($data)->count(); + $warehouse = ProductModel::where(['is_del'=>0])->count(); //已经售馨产品 - $data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>0]; - $outofstock = ProductModel::alias('p') - ->join('StoreProductAttrValue pav','p.id=pav.product_id','LEFT') - ->where($data)->count(); + $outofstock = ProductModel::getModelObject()->where(ProductModel::setData(4))->count(); //警戒库存 - $data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>['elt',1]]; - $policeforce = ProductModel::alias('p') - ->join('StoreProductAttrValue pav','p.id=pav.product_id','LEFT') - ->where($data)->count(); + $policeforce =ProductModel::getModelObject()->where(ProductModel::setData(5))->count(); //回收站 - $data = ['is_del'=>1]; - $recycle = ProductModel::where($data)->count(); - $this->assign(compact('where','onsale','forsale','warehouse','outofstock','policeforce','recycle')); - $this->assign(ProductModel::systemPage($where,$this->adminInfo)); + $recycle = ProductModel::where(['is_del'=>1])->count(); + + $this->assign(compact('type','onsale','forsale','warehouse','outofstock','policeforce','recycle')); return $this->fetch(); } - + /** + * 异步查找产品 + * + * @return json + */ + public function product_ist(){ + $where=Util::getMore([ + ['page',1], + ['limit',20], + ['store_name',''], + ['cate_id',''], + ['excel',0], + ['type',$this->request->param('type')] + ]); + return JsonService::successlayui(ProductModel::ProductList($where)); + } + /** + * 设置单个产品上架|下架 + * + * @return json + */ + public function set_show($is_show='',$id=''){ + ($is_show=='' || $id=='') && JsonService::fail('缺少参数'); + $res=ProductModel::where(['id'=>$id])->update(['is_show'=>(int)$is_show]); + if($res){ + return JsonService::successful($is_show==1 ? '上架成功':'下架成功'); + }else{ + return JsonService::fail($is_show==1 ? '上架失败':'下架失败'); + } + } + /** + * 快速编辑 + * + * @return json + */ + public function set_product($field='',$id='',$value=''){ + $field=='' || $id=='' || $value=='' && JsonService::fail('缺少参数'); + if(ProductModel::where(['id'=>$id])->update([$field=>$value])) + return JsonService::successful('保存成功'); + else + return JsonService::fail('保存失败'); + } + /** + * 设置批量产品上架 + * + * @return json + */ + public function product_show(){ + $post=Util::postMore([ + ['ids',[]] + ]); + if(empty($post['ids'])){ + return JsonService::fail('请选择需要上架的产品'); + }else{ + $res=ProductModel::where('id','in',$post['ids'])->update(['is_show'=>1]); + if($res) + return JsonService::successful('上架成功'); + else + return JsonService::fail('上架失败'); + } + } /** * 显示创建资源表单页. * diff --git a/application/admin/model/store/StoreProduct.php b/application/admin/model/store/StoreProduct.php index 8ac70bac..850ccb7a 100644 --- a/application/admin/model/store/StoreProduct.php +++ b/application/admin/model/store/StoreProduct.php @@ -27,82 +27,101 @@ class StoreProduct extends ModelBasic use ModelTrait; /** - * @param $where + * 获取连表查询条件 + * @param $type * @return array */ - public static function systemPage($where,$adminInfo){ - $model = new self; - $model = $model->alias('p'); - if($where['store_name'] != '') $model = $model->where('p.store_name|p.keyword|p.id','LIKE',"%$where[store_name]%"); - if($where['cate_id'] != '') $model = $model->where('p.cate_id','LIKE',"%$where[cate_id]%"); - switch ($where['type']){ + public static function setData($type){ + switch ((int)$type){ case 1: - $data = ['p.is_show'=>1,'is_del'=>0]; - $model = $model->where($data); + $data = ['p.is_show'=>1,'p.is_del'=>0]; break; case 2: - $data = ['p.is_show'=>0,'is_del'=>0]; - $model = $model->where($data); + $data = ['p.is_show'=>0,'p.is_del'=>0]; break; case 3: $data = ['p.is_del'=>0]; - $model = $model->where($data); break; case 4: $data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>0]; - $model = $model->where($data); break; case 5: $data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>['elt',1]]; - $model = $model->where($data); break; case 6: $data = ['p.is_del'=>1]; - $model = $model->where($data); break; }; - $model = $model->field('p.*,sum("pav.stock") as vstock'); - $model = $model->join('StoreProductAttrValue pav','p.id=pav.product_id','LEFT'); - $model = $model->group('p.id'); - $order = ''; - if($where['sales'] != '') $order .= $where['sales']; - $order .= 'p.id desc'; - $model = $model->order($order); - if($where['export'] == 1){ - $list = $model->select()->toArray(); - $export = []; - foreach ($list as $index=>$item){ - $cateName = CategoryModel::where('id','IN',$item['cate_id'])->column('cate_name','id'); if(is_array($cateName)){ $cateNameStr = implode(',',$cateName); } - $export[] = [ - $item['store_name'], - $item['store_info'], - $cateName, - '¥'.$item['price'], - $item['stock'], - $item['sales'], - StoreProductRelation::where('product_id',$item['id'])->where('type','like')->count(), - StoreProductRelation::where('product_id',$item['id'])->where('type','collect')->count() - ]; - $list[$index] = $item; + return isset($data) ? $data: []; + } + /** + * 获取连表MOdel + * @param $model + * @return object + */ + public static function getModelObject($where=[]){ + $model=new self(); + $model=$model->alias('p')->join('StoreProductAttrValue pav','p.id=pav.product_id','LEFT'); + if(!empty($where)){ + $model=$model->group('p.id'); + if(isset($where['type']) && $where['type']!='' && ($data=self::setData($where['type']))){ + $model = $model->where($data); + } + if(isset($where['store_name']) && $where['store_name']!=''){ + $model = $model->where('p.store_name|p.keyword|p.id','LIKE',"%$where[store_name]%"); + } + if(isset($where['cate_id']) && trim($where['cate_id'])!=''){ + $model = $model->where('p.cate_id','LIKE',"%$where[cate_id]%"); + } + if(isset($where['order']) && $where['order']!=''){ + $model = $model->order(self::setOrder($where['order'])); } - PHPExcelService::setExcelHeader(['产品名称','产品简介','产品分类','价格','库存','销量','点赞人数','收藏人数']) - ->setExcelTile('产品导出','产品信息'.time(),'操作人昵称:'.$adminInfo['real_name'].' 生成时间:'.date('Y-m-d H:i:s',time())) - ->setExcelContent($export) - ->ExcelSave(); } - return self::page($model,function($item){ + return $model; + } + /* + * 获取产品列表 + * @param $where array + * @return array + * + */ + public static function ProductList($where){ + $model=self::getModelObject($where)->field(['p.*','sum(pav.stock) as vstock']); + if($where['excel']==0) $model=$model->page((int)$where['page'],(int)$where['limit']); + $data=($data=$model->select()) && count($data) ? $data->toArray():[]; + foreach ($data as &$item){ $cateName = CategoryModel::where('id','IN',$item['cate_id'])->column('cate_name','id'); - if(is_array($cateName)){ - $item['cate_name'] = implode(',',$cateName); } + $item['cate_name']=is_array($cateName) ? implode(',',$cateName) : ''; $item['collect'] = StoreProductRelation::where('product_id',$item['id'])->where('type','collect')->count();//收藏 $item['like'] = StoreProductRelation::where('product_id',$item['id'])->where('type','like')->count();//点赞 $item['stock'] = self::getStock($item['id'])>0?self::getStock($item['id']):$item['stock'];//库存 $item['stock_attr'] = self::getStock($item['id'])>0 ? true : false;//库存 $item['sales_attr'] = self::getSales($item['id']);//属性销量 $item['visitor'] = Db::name('store_visit')->where('product_id',$item['id'])->where('product_type','product')->count(); - - },$where); + } + if($where['excel']==1){ + $export = []; + foreach ($data as $index=>$item){ + $export[] = [ + $item['store_name'], + $item['store_info'], + $item['cate_name'], + '¥'.$item['price'], + $item['stock'], + $item['sales'], + $item['like'], + $item['collect'] + ]; + } + PHPExcelService::setExcelHeader(['产品名称','产品简介','产品分类','价格','库存','销量','点赞人数','收藏人数']) + ->setExcelTile('产品导出','产品信息'.time(),' 生成时间:'.date('Y-m-d H:i:s',time())) + ->setExcelContent($export) + ->ExcelSave(); + } + $count=self::getModelObject($where)->count(); + return compact('count','data'); } + public static function getChatrdata($type,$data){ $legdata=['销量','数量','点赞','收藏']; $model=self::setWhereType(self::order('id desc'),$type); @@ -361,7 +380,7 @@ class StoreProduct extends ModelBasic ->select(); $count=self::setWhere($where)->where('a.is_pay',1)->group('a.product_id')->count(); foreach ($data as &$item){ - $item['sum_price']=bcdiv($item['num_product'],$item['price'],true); + $item['sum_price']=bcdiv($item['num_product'],$item['price'],2); } return compact('data','count'); } diff --git a/application/admin/view/store/store_product/index.php b/application/admin/view/store/store_product/index.php index 3da9a9df..ad4b9540 100644 --- a/application/admin/view/store/store_product/index.php +++ b/application/admin/view/store/store_product/index.php @@ -1,373 +1,344 @@ {extend name="public/container"} -{block name="head_top"} - - - - - - - - -{/block} {block name="content"} -
-
- -
-
- -
-
-
-
-
-
-
- + + {volist name='cate' id='vo'} + {/volist} - - - - - - -
- - - - - - - - - - -
-
- - - - - - +
+ +
+ +
-
- - +
+
+ + +
+
+
+ +
+
+
+ +
+
+
+ +
+ {switch name='type'} + {case value="1"} + + {/case} + {case value="2"} + + {/case} + {/switch} +
+
+ + + + + + + + + + + +
-
- - - - - - - - - - - - - - - - - - - - {volist name="list" id="vo"} - - - - - - - - - - - - - - - - - - {/volist} - -
编号产品图片产品名称产品价格虚拟销量商品访客数商品浏览量 -
- - -
-
库存排序点赞收藏操作
- - - {$vo.store_name} - - {$vo.store_name}
- 价格:{$vo.price}
- 分类:{$vo.cate_name} -
- {$vo.price} - - - {$vo.ficti} - - {$vo.visitor} - - {$vo.browse} - - {$vo.sales} - - {$vo.stock} - - - {$vo.sort} - - -   {$vo.collect} - - - -   {$vo.like} - - -
-
- - - - -
-
- - - - - - - - - - -
- {include file="public/inner_page"}
-{/block} -{block name="script"} + {/block}