diff --git a/app/admin/common.php b/app/admin/common.php index 3ff30dd..fd2aa8a 100644 --- a/app/admin/common.php +++ b/app/admin/common.php @@ -140,6 +140,13 @@ function get_admin_rule() return $rule; } +//读取商品分类 +function get_store_category() +{ + $store_category = Db::connect('shop')->table('eb_store_category')->field('store_category_id as id,pid,cate_name as title,sort,level')->where(['is_show' => 1])->select()->toArray(); + return $store_category; +} + //读取模块列表 function get_admin_module() { diff --git a/app/admin/controller/StoreProduct.php b/app/admin/controller/StoreProduct.php new file mode 100644 index 0000000..fcffc05 --- /dev/null +++ b/app/admin/controller/StoreProduct.php @@ -0,0 +1,145 @@ +model = new StoreProductModel(); + $this->uid = get_login_admin('id'); + } + /** + * 数据列表 + */ + public function datalist() + { + if (request()->isAjax()) { + $param = get_params(); + $where = []; + if (isset($param['keywords']) && !empty($param['keywords'])){ + $where[]=['store_name','like','%'.$param['keywords'].'%']; + } + $list = $this->model->getStoreProductList($where,$param); + return table_assign(0, '', $list); + } + else{ + return view(); + } + } + + /** + * 添加 + */ + public function add() + { + if (request()->isAjax()) { + $param = get_params(); + + // 检验完整性 + try { + validate(StoreProductValidate::class)->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + + $this->model->addStoreProduct($param); + }else{ + + $store_brand= Db::connect('shop')->table('eb_store_brand')->where(['is_show' => 1]) + ->select(); + View::assign('store_brand', $store_brand); + return view(); + } + } + + + /** + * 编辑 + */ + public function edit() + { + $param = get_params(); + + if (request()->isAjax()) { + // 检验完整性 + try { + validate(StoreProductValidate::class)->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + + $this->model->editStoreProduct($param); + }else{ + $product_id = isset($param['product_id']) ? $param['product_id'] : 0; + $detail = $this->model->getStoreProductById($product_id); + if (!empty($detail)) { + $detail['content'] = Db::table('cms_store_product_content')->where('product_id',$detail['product_id'])->value('content'); + View::assign('detail', $detail); + $store_brand= Db::connect('shop')->table('eb_store_brand')->where(['is_show' => 1]) + ->select(); + View::assign('store_brand', $store_brand); + return view(); + } + else{ + throw new \think\exception\HttpException(404, '找不到页面'); + } + } + } + + + /** + * 查看信息 + */ + public function read() + { + $param = get_params(); + $product_id = isset($param['product_id']) ? $param['product_id'] : 0; + $detail = $this->model->getStoreProductById($product_id); + if (!empty($detail)) { + $detail['content'] = Db::table('cms_store_product_content')->where('product_id',$detail['product_id'])->value('content'); + View::assign('detail', $detail); + $store_brand= Db::connect('shop')->table('eb_store_brand')->where(['is_show' => 1]) + ->select(); + View::assign('store_brand', $store_brand); + return view(); + } + else{ + throw new \think\exception\HttpException(404, '找不到页面'); + } + } + + /** + * 删除 + * type=0,逻辑删除,默认 + * type=1,物理删除 + */ + public function del() + { + $param = get_params(); + $product_id = isset($param['product_id']) ? $param['product_id'] : 0; + $type = isset($param['type']) ? $param['type'] : 0; + + $this->model->delStoreProductById($product_id,$type); + } +} diff --git a/app/admin/model/StoreProduct.php b/app/admin/model/StoreProduct.php new file mode 100644 index 0000000..0cbd642 --- /dev/null +++ b/app/admin/model/StoreProduct.php @@ -0,0 +1,106 @@ +field('product_id,mer_id,store_name,store_info,keyword,brand_id,cate_id,unit_name,sort,sales,price,cost,ot_price,stock,is_hot,is_benefit,temp_id,spec_type,image,slider_image,once_max_count,once_min_count,integral_rate,integral_total,integral_price_total,labels,delivery_free,type,extend,pay_limit,svip_price_type,svip_price,mer_svip_status,param_temp_id')->order($order)->paginate($rows, false, ['query' => $param]); + return $list; + } + + /** + * 添加数据 + * @param $param + */ + public function addStoreProduct($param) + { + $insertId = 0; + try { + $param['create_time'] = date('Y-m-d H:i:s'); + $param['status'] = 1; + $insertId = self::strict(false)->field(true)->insertGetId($param); +// 写入商品详情表 + $data['product_id'] = $insertId; + $data['content'] = $param['content']; + Db::table('cms_store_product_content')->strict(false)->field(true)->insertGetId($data); + add_log('add', $insertId, $param); + } catch(\Exception $e) { + return to_assign(1, '操作失败,原因:'.$e->getMessage()); + } + return to_assign(0,'操作成功',['aid'=>$insertId]); + } + + /** + * 编辑信息 + * @param $param + */ + public function editStoreProduct($param) + { + try { +// $param['update_time'] = time(); + self::where('product_id', $param['product_id'])->strict(false)->field(true)->update($param); + // 修改商品详情表 + $data['content'] = $param['content']; + Db::table('cms_store_product_content')->where('product_id', $param['product_id'])->strict(false)->field(true)->update($data); + add_log('edit', $param['product_id'], $param); + } catch(\Exception $e) { + return to_assign(1, '操作失败,原因:'.$e->getMessage()); + } + return to_assign(); + } + + + /** + * 根据id获取信息 + * @param $id + */ + public function getStoreProductById($id) + { + $info = self::where('product_id', $id)->find(); + return $info; + } + + /** + * 删除信息 + * @param $id + * @return array + */ + public function delStoreProductById($id,$type=0) + { + if($type==0){ + //逻辑删除 + try { + $param['delete_time'] = time(); + self::where('product_id', $id)->update(['delete_time'=>time()]); + add_log('delete', $id); + } catch(\Exception $e) { + return to_assign(1, '操作失败,原因:'.$e->getMessage()); + } + } + else{ + //物理删除 + try { + self::where('product_id', $id)->delete(); + add_log('delete', $id); + } catch(\Exception $e) { + return to_assign(1, '操作失败,原因:'.$e->getMessage()); + } + } + return to_assign(); + } +} + diff --git a/app/admin/validate/StoreProductValidate.php b/app/admin/validate/StoreProductValidate.php new file mode 100644 index 0000000..1592da1 --- /dev/null +++ b/app/admin/validate/StoreProductValidate.php @@ -0,0 +1,20 @@ + 'require', +]; + + protected $message = [ + 'store_name.require' => '商品名称不能为空', +]; +} \ No newline at end of file diff --git a/app/admin/view/store_product/add.html b/app/admin/view/store_product/add.html new file mode 100644 index 0000000..5d56126 --- /dev/null +++ b/app/admin/view/store_product/add.html @@ -0,0 +1,222 @@ +{extend name="common/base"/} +{block name="style"} + +{/block} + +{block name="body"} +
+

添加

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
商品名称*
平台商品分类* +
+ +
+
品牌选择* +
+ +
+
商品封面图 +
+ +
+ + +
+
+
商品轮播图 +
+ +
+ + +
+
+
单位*
商品关键字*
售价*
成本价*
市场价*
库存*
商品简介 + +
商品详情 + +
+
+ + +
+
+{/block} + + + +{block name="script"} + + +{/block} + \ No newline at end of file diff --git a/app/admin/view/store_product/datalist.html b/app/admin/view/store_product/datalist.html new file mode 100644 index 0000000..fcc2a6f --- /dev/null +++ b/app/admin/view/store_product/datalist.html @@ -0,0 +1,173 @@ +{extend name="common/base"/} + +{block name="body"} + +
+
+
+ +
+ +
+
+
+ + + + + +{/block} + + + +{block name="script"} + +{/block} + \ No newline at end of file diff --git a/app/admin/view/store_product/edit.html b/app/admin/view/store_product/edit.html new file mode 100644 index 0000000..6f8858a --- /dev/null +++ b/app/admin/view/store_product/edit.html @@ -0,0 +1,222 @@ +{extend name="common/base"/} +{block name="style"} + +{/block} + +{block name="body"} +
+

编辑文章表

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
商品名称*
平台商品分类* +
+ +
+
品牌选择* +
+ +
+
商品封面图 +
+ +
+ + +
+
+
商品轮播图 +
+ +
+ + +
+
+
单位*
商品关键字*
售价*
成本价*
市场价*
库存*
商品简介 + +
商品详情 + +
+
+ + + +
+
+{/block} + + + +{block name="script"} + + +{/block} + \ No newline at end of file diff --git a/app/admin/view/store_product/read.html b/app/admin/view/store_product/read.html new file mode 100644 index 0000000..7d7f54d --- /dev/null +++ b/app/admin/view/store_product/read.html @@ -0,0 +1,144 @@ +{extend name="common/base"/} +{block name="style"} + +{/block} + +{block name="body"} +
+

文章详情

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
商品名称*
商户商品分类* +
+ +
+
品牌选择* +
+ +
+
商品封面图 +
+ +
+ + +
+
+
商品轮播图 +
+ +
+ + +
+
+
单位*
商品关键字*
售价*
成本价*
市场价*
库存*
商品简介 + +
商品详情 + +
+
+{/block} + \ No newline at end of file diff --git a/app/api/controller/StoreProduct.php b/app/api/controller/StoreProduct.php new file mode 100644 index 0000000..115df8a --- /dev/null +++ b/app/api/controller/StoreProduct.php @@ -0,0 +1,120 @@ + ['except' => ['list','add'] ] + ]; + + /** + * 商品列表 + */ + public function list($page=0,$limit=10){ + $post = get_params(); + $where[] = ['status','=',1]; + $where[] = ['is_del','=',0]; + $where[] = ['is_show','=',1]; + if(empty($post['mer_id'])){ + $this->apiError('缺少参数'); + } + $log = Db::table('cms_store_add_log')->where('mer_id',$post['mer_id'])->column('product_id'); + if($log){ + $where[] = ['product_id','not in',$log]; + } + $res = Db::table('cms_store_product') + ->where($where) + ->page($page,$limit) + ->order('sort desc id desc') + ->select(); + $this->apiSuccess('OK',$res); + } + + /** + * 一键导入商品 + */ + public function add(){ + $post = get_params(); + if(empty($post['mer_id']) || empty($post['product_ids'])){ + $this->apiError('缺少参数'); + } + Db::startTrans(); + try { + $where[] = ['product_id','in',$post['product_ids']]; + $data = Db::table('cms_store_product')->where($where)->select()->toArray(); + if($data){ + $day = date('Y-m-d H:i:s'); + $log['mer_id'] = $post['mer_id']; + $log['create_time'] = $day; + foreach ($data as $k =>$v){ + //写入导入记录 + $log['product_id'] = $v['product_id']; + Db::table('cms_store_add_log')->insert($log); + $old_product_id = $v['product_id']; + unset($v['product_id']); + //导入商品表 + $v['mer_id'] = $post['mer_id']; + $product_id = Db::connect('shop')->table('eb_store_product')->insertGetId($v); + +// 写入商品搜索信息表 + $store_spu['mer_id'] = $post['mer_id']; + $store_spu['product_id'] = $product_id; + $store_spu['status'] = 1; + $store_spu['store_name'] = $v['store_name']; + $store_spu['keyword'] = $v['mer_id']; + $store_spu['price'] = $v['price']; + $store_spu['rank'] = $v['sort']; + $store_spu['create_time'] = $day; + $store_spu['temp_id'] = $v['temp_id']; + Db::connect('shop')->table('eb_store_spu')->insert($store_spu); + +// 写入商品详情表 + $ccc = Db::table('cms_store_product_content')->where('product_id',$old_product_id)->value('content'); + $content['content'] = $ccc ??''; + $content['product_id'] = $product_id; + Db::connect('shop')->table('eb_store_product_content')->insert($content); +// 写入SKU表 + $attr['product_id'] = $product_id; + $attr['sku'] = ' '; //库存 + $attr['stock'] = $v['stock']; //库存 + $attr['image'] = $v['image']; + $attr['cost'] = $v['cost'];//成本价 + $attr['ot_price'] = $v['ot_price'];//原价 + $attr['price'] = $v['price'];//价格 + $attr['unique'] = set_salt(12);//唯一值 + $attr['svip_price'] = $v['svip_price'];//会员价 + Db::connect('shop')->table('eb_store_product_attr_value')->insert($attr); +// 写入商品商户分类关联表 + $cate['product_id'] = $product_id; + $cate['mer_cate_id'] = $v['cate_id']; + $cate['mer_id'] = $post['mer_id']; + Db::connect('shop')->table('eb_store_product_cate')->insert($cate); + } + } + + Db::commit(); + $this->apiSuccess('操作成功'); + } catch (ValidateException $e) { + Db::rollback(); + $this->apiError($e->getMessage()); + } + } + + + + +}