123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <?php
- /**
- * Author: luzheng.liu
- * Time: 2020/12/16 23:06
- */
- namespace app\api\controller;
- use app\api\BaseController;
- use app\api\model\AdminModel;
- use app\api\model\BrandModel;
- use app\api\model\CompanyModel;
- use app\api\model\GroupModel;
- use app\api\model\PayModel;
- use app\api\model\ProductModel;
- use app\api\model\ProductTypeModel;
- use app\common\until\Until;
- use think\Db;
- class Product extends BaseController {
- /**
- * @OA\Get(path="/api/Product/index",
- * tags={"产品管理"},
- * summary="产品列表",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
- * @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
- * @OA\Parameter(name="status", in="query", description="状态 1正常 2删除", @OA\Schema(type="integer",default="1")),
- * @OA\Parameter(name="name", in="query", description="产品名称", @OA\Schema(type="string")),
- * @OA\Parameter(name="brandId", in="query", description="品牌id", @OA\Schema(type="integer")),
- * @OA\Parameter(name="companyId", in="query", description="公司id", @OA\Schema(type="integer")),
- * @OA\Parameter(name="productTypeId", in="query", description="产品类型id", @OA\Schema(type="integer")),
- * @OA\Parameter(name="type", in="query", description="产品分类 1洗浴 2小食", @OA\Schema(type="integer")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function index() {
- $input = Until::getInput();
- $model = new ProductModel();
- $model->setPage($input['page'] ?? 1);
- $model->setPageSize($input['pageSize'] ?? 10);
- $where = [];
- if ($this->isAdmin() && !empty($input['status'])) {
- $where[] = ['p.status', '=', ];
- } else {
- $where[] = ['p.status', '=', $model::NORMAL];
- }
- if (!empty($input['name'])) {
- $where[] = ['p.product_name', 'like', "%{$input['name']}%"];
- }
- if (!empty($input['brandId'])) {
- $where[] = ['p.brand_id', '=', "{$input['brandId']}"];
- }
- if (!empty($input['groupId'])) {
- $where[] = ['p.group_id', '=', "{$input['groupId']}"];
- }
- if (!empty($input['companyId'])) {
- $where[] = ['p.company_id', '=', "{$input['companyId']}"];
- }
- // if (!empty($input['storeId'])) {
- // $where[] = ['s.id', '=', "{$input['storeId']}"];
- // }
- if (!empty($input['productTypeId'])) {
- $where[] = ['pt.id', '=', $input['productTypeId']];
- $where[] = ['pt.status', '=', 1];
- }
- if (!empty($input['type'])) {
- $where[] = ['p.type', '=', (int)$input['type']];
- }else {
- $where[] = ['p.type', '=', 1];
- }
- $model->setWhere($where);
- $data = $model->getProductList();
- Until::output($data);
- }
- /**
- * @OA\Get(path="/api/Product/typeList",
- * tags={"产品管理"},
- * summary="产品类型列表",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
- * @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
- * @OA\Parameter(name="type", in="query", description="1为洗浴 2为小食 3全部", @OA\Schema(type="integer",default="1")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function typeList() {
- $input = Until::getInput();
- $model = new ProductTypeModel();
- $model->setPage($input['page'] ?? 1);
- $model->setPageSize($input['pageSize'] ?? 10);
- $where = [];
- if (!$this->isAdmin()) {
- $where[] = ['status','=', 1];
- }
- if (!empty($input['type']) && $input['type'] == 2) {
- $where[] = ['type','=', 2];
- }
- if (!empty($input['type']) && $input['type'] == 1) {
- $where[] = ['type','=', 1];
- }
- $model->setWhere($where);
- $data = $model->getProductTypeList();
- foreach ($data['list'] as &$v) {
- $v['title'] = $v['product_type_name'];
- }
- Until::output($data);
- }
- /**
- * @OA\Post(path="/api/Product/saveType",
- * tags={"产品管理"},
- * summary="保存产品类型信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="产品类型名称", property="name", type="string", default="精油推背"),
- * @OA\Property(description="产品类型图片", property="imgUrl", type="integer", default="http://xxx.com"),
- * @OA\Property(description="类型 1位洗浴 2为小食", property="type", type="integer", default="1"),
- * required={"name","imgUrl"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function saveType() {
- $input = Until::getInput();
- $rule = [
- 'name|分类名称' => 'require',
- 'imgUrl|产品分类图片' => 'require',
- ];
- Until::check($rule, $input);
- $model = new ProductTypeModel();
- if (!empty($input['id'])) {
- $id = (int)$input['id'];
- $model::where(['id' => $id])->update([
- 'product_type_name' => $input['name'],
- 'product_type_img' => $input['imgUrl'] ?? '',
- 'type' => $input['type'] ?? 1,
- ]);
- } else {
- $model->insertGetId([
- 'product_type_name' => $input['name'],
- 'product_type_img' => $input['imgUrl'] ?? '',
- 'type' => $input['type'] ?? 1
- ]);
- }
- Until::output(['isSuccess' => 1]);
- }
- /**
- * @OA\GET(path="/api/Product/deleteType",
- * tags={"产品管理"},
- * summary="删除(屏蔽)产品类型信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="id", in="query", description="产品id", @OA\Schema(type="ineger",default="1")),
- * @OA\Parameter(name="status", in="query", description="1正常 0禁用", @OA\Schema(type="ineger",default="1")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function deleteType() {
- $input = Until::getInput();
- $rule = [
- 'id' => 'require',
- 'status' => 'require',
- ];
- Until::check($rule, $input);
- $model = new ProductTypeModel();
- $where[] = ['id', '=', (int)$input['id']];
- $data = ['status' => (int)$input['status']];
- $isSuccess = $model::where($where)->update($data);
- Until::output(['isSuccess' => $isSuccess]);
- }
- /**
- * @OA\Post(path="/api/Product/save",
- * tags={"产品管理"},
- * summary="保存产品信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="产品名称", property="name", type="string", default="精油推背"),
- * @OA\Property(description="产品图片", property="imgUrl", type="integer", default="http://xxx.com"),
- * @OA\Property(description="原价", property="oldPrice", type="string", default="88.00"),
- * @OA\Property(description="现价", property="currentPrice", type="string", default="66.00"),
- * @OA\Property(description="产品介绍(富文本编辑)", property="productContent", type="string", default="本产品由xxx精油。。"),
- * @OA\Property(description="公司id", property="companyId", type="string", default="1"),
- * @OA\Property(description="品牌id", property="brandId", type="string", default="1"),
- * @OA\Property(description="状态 1正常 2下架", property="status", type="integer", default="1"),
- * @OA\Property(description="产品类型id", property="productTypeId", type="integer", default="1"),
- * @OA\Property(description="产品分类 1 洗浴 2小食", property="type", type="integer", default="1"),
- * required={"name","imgUrl","oldPrice","currentPrice","companyId","brandId","productContent"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function save() {
- $input = Until::getInput();
- $rule = [
- 'name|产品名称' => 'require',
- 'imgUrl|产品图片' => 'require',
- 'oldPrice|原价' => 'require',
- 'currentPrice|现价' => 'require',
- 'companyId|公司id' => 'require',
- 'brandId|品牌id' => 'require',
- 'productContent|产品内容' => 'require',
- 'productTypeId|产品类型' => 'require'
- ];
- Until::check($rule, $input);
- $model = new ProductModel();
- if (!empty($input['id'])) {
- $id = (int)$input['id'];
- $model::where(['id' => $id])->update([
- 'product_name' => $input['name'],
- 'product_img' => $input['imgUrl'],
- 'old_price' => $input['oldPrice'],
- 'current_price' => $input['currentPrice'],
- 'company_id' => $input['companyId'],
- 'brand_id' => $input['brandId'],
- 'product_content' => $input['productContent'],
- 'product_type_id' => $input['productTypeId'],
- 'status' => $input['status'] ?? 1,
- ]);
- } else {
- $id = $model->insertGetId([
- 'product_name' => $input['name'],
- 'product_img' => $input['imgUrl'],
- 'old_price' => $input['oldPrice'],
- 'current_price' => $input['currentPrice'],
- 'company_id' => $input['companyId'],
- 'brand_id' => $input['brandId'],
- 'product_content' => $input['productContent'],
- 'status' => $input['status'] ?? 1,
- 'product_type_id' => $input['productTypeId'],
- 'type' => $input['type'] ?? 1
- ]);
- }
- $model->setWhere([['p.id', '=', (int)$id]]);
- $info = $model->getProductInfo();
- Until::output(['info' => $info]);
- }
- /**
- * @OA\GET(path="/api/Product/read",
- * tags={"产品管理"},
- * summary="查看产品信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="id", in="query", description="产品id", @OA\Schema(type="ineger",default="1")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function read($id) {
- $model = new ProductModel();
- $where[] = ['p.id', '=', (int)$id];
- $model->setWhere($where);
- $info = $model->getProductInfo();
- Until::output(['info' => $info]);
- }
- /**
- * @OA\GET(path="/api/Product/delete",
- * tags={"产品管理"},
- * summary="删除产品信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="id", in="query", description="产品id", @OA\Schema(type="ineger",default="1")),
- * @OA\Parameter(name="status", in="query", description="1正常 2下架 3删除", @OA\Schema(type="ineger",default="1")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function delete($id, $status) {
- $model = new ProductModel();
- $where[] = ['id', '=', (int)$id];
- $data = ['status' => (int)$status];
- $isSuccess = $model::where($where)->update($data);
- Until::output(['isSuccess' => $isSuccess]);
- }
- }
|