123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /**
- * Author: luzheng.liu
- * Time: 2020/12/16 23:06
- */
- namespace app\api\controller;
- use app\api\BaseController;
- use app\api\exception\ApiException;
- use app\api\model\GroupModel;
- use app\api\model\StoreModel;
- use app\common\until\Until;
- class Group extends BaseController {
- /**
- * @OA\Get(path="/api/Group/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\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function index() {
- $input = Until::getInput();
- $model = new GroupModel();
- $model->setPage($input['page'] ?? 1);
- $model->setPageSize($input['pageSize'] ?? 10);
- $where = [];
- $where[] = ['gr.admin_id','=',$this->adminId];
- $model->setWhere($where);
- $data = $model->getGroupList();
- $ids = array_column($data['list'], 'id');
- $storeList = (new StoreModel())::where([['group_id', 'in', $ids]])->select();
- $storeList = Until::modelToArray($storeList);
- $groupStore = [];
- foreach ($storeList as $info) {
- $groupStore[$info['group_id']][] = $info;
- }
- foreach ($data['list'] as &$info) {
- $info['storeList'] = $groupStore[$info['id']];
- }
- Until::output($data);
- }
- /**
- * @OA\Post(path="/api/Group/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="四海集团"),
- * required={"name"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function save() {
- $input = Until::getInput();
- $rule = [
- 'name|集团名称' => 'require',
- ];
- Until::check($rule, $input);
- $model = new GroupModel();
- $info = $model::where(['group_name' => $input['name']])->find();
- if ($info !== null) {
- throw new ApiException('集团名称不许重复');
- }
- if (!empty($input['id']) ) {
- $id = (int)$input['id'];
- $model::where(['id' => $id])->update([
- 'group_name' => $input['name']
- ]);
- } else {
- $id = $model->insertGetId([
- 'group_name' => $input['name']
- ]);
- }
- $info = $model::get($id);
- Until::output(['info' => Until::modelToArray($info)]);
- }
- public function delete($id,$status) {
- $model = new GroupModel();
- $where[] = ['id', '=', (int)$id];
- $data = ['status' => (int)$status];
- $isSuccess = $model::where($where)->update($data);
- Until::output(['isSuccess' => $isSuccess]);
- }
- }
|