123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * Author: luzheng.liu
- * Time: 2020/12/16 23:03
- */
- namespace app\api\controller;
- use app\api\BaseController;
- use app\api\model\AdminModel;
- use app\api\model\StoreModel;
- use app\common\until\Until;
- class Store extends BaseController {
- /**
- * @OA\Post(path="/api/Store/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\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function index() {
- $input = request()->get();
- $model = new StoreModel();
- $model->setPage($input['page'] ?? 1);
- $model->setPageSize($input['pageSize'] ?? 10);
- if ($this->isAdmin()) {
- $where = [];
- } else {
- $where[] = ['s.status', '=', $model::NORMAL];
- }
- if (!empty($input['name'])){
- $where[] = ['s.store_name', 'like', "%{$input['name']}%"];
- }
- $model->setWhere($where);
- $data = $model->getStoreList();
- Until::output($data);
- }
- /**
- * @OA\Post(path="/api/Store/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="测试门店1"),
- * @OA\Property(description="门店code", property="code", type="string", default="A001"),
- * @OA\Property(description="营业时间", property="openTime", type="string", default="06:00"),
- * @OA\Property(description="闭店时间", property="closeTime", type="string", default="22:00"),
- * @OA\Property(description="支付标识", property="payCode", type="string", default="paycode1"),
- * @OA\Property(description="所属集团id", property="groupId", type="integer", default="1"),
- * @OA\Property(description="所属公司id", property="companyId", type="integer", default="1"),
- * @OA\Property(description="所属品牌id", property="brandId", type="integer", default="1"),
- * @OA\Property(description="logo的url", property="logo", type="string", default="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608146390523&di=02b955a1fa80d1c43c6289f846ddc42c&imgtype=0&src=http%3A%2F%2Fimg.sccnn.com%2Fbimg%2F338%2F38706.jpg"),
- * @OA\Property(description="纬度", property="latitude", type="string", default="31.241510099342623"),
- * @OA\Property(description="经度", property="longitude", type="string", default="121.32174958203123"),
- * @OA\Property(description="地址", property="address", type="string", default="上海市普陀区真北路"),
- * @OA\Property(description="联系电话", property="mobile", type="string", default="15656789876"),
- * @OA\Property(description="门店id", property="id", type="string", default=""),
- * @OA\Property(description="门店状态 1正常 2闭店 3暂歇", property="status", type="0"),
- * required={"name","code","openTime","closeTime","payCode","groupId","companyId","brandId","logo",
- * "latitude","longitude","address","mobile"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function save() {
- $input = Until::getInput();
- $rule = [
- 'name|门店名称' => 'require',
- 'code|门店code' => 'require',
- 'openTime|营业时间' => 'require',
- 'closeTime|闭店时间' => 'require',
- 'payCode|支付标识' => 'require',
- 'groupId|所属集团id' => 'require',
- 'companyId|所属公司id' => 'require',
- 'brandId|所属品牌id' => 'require',
- 'logo|logo的url' => 'require',
- 'latitude|纬度' => 'require',
- 'longitude|经度' => 'require',
- 'address|地址' => 'require',
- 'mobile|联系电话' => 'require',
- ];
- Until::check($rule, $input);
- $model = new StoreModel();
- if (!empty($input['id']) ) {
- $id = (int)$input['id'];
- $model::where(['id' => $id])->update([
- 'store_name' => $input['name'],
- 'store_code' => $input['code'],
- 'open_time' => $input['openTime'],
- 'close_time' => $input['closeTime'],
- 'pay_code' => $input['payCode'],
- 'group_id' => $input['groupId'],
- 'company_id' => $input['companyId'],
- 'brand_id' => $input['brandId'],
- 'logo' => $input['logo'],
- 'latitude' => $input['latitude'],
- 'longitude' => $input['longitude'],
- 'address' => $input['address'],
- 'mobile' => $input['mobile'],
- 'status' => $input['status']
- ]);
- } else {
- $id = $model->insertGetId([
- 'store_name' => $input['name'],
- 'store_code' => $input['code'],
- 'open_time' => $input['openTime'],
- 'close_time' => $input['closeTime'],
- 'pay_code' => $input['payCode'],
- 'group_id' => $input['groupId'],
- 'company_id' => $input['companyId'],
- 'brand_id' => $input['brandId'],
- 'logo' => $input['logo'],
- 'latitude' => $input['latitude'],
- 'longitude' => $input['longitude'],
- 'address' => $input['address'],
- 'mobile' => $input['mobile'],
- ]);
- }
- $info = $model::get($id);
- Until::output(['info' => Until::modelToArray($info)]);
- }
- /**
- * @OA\GET(path="/api/Store/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 StoreModel();
- $where[] = ['s.id', '=', (int)$id];
- $model->setWhere($where);
- $info = $model->getStoreInfo();
- Until::output(['info' => $info]);
- }
- /**
- * @OA\GET(path="/api/Store/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删除", @OA\Schema(type="ineger",default="1")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function delete($id,$status) {
- $model = new StoreModel();
- $where[] = ['id', '=', (int)$id];
- $data = ['status' => (int)$status];
- $isSuccess = $model::where($where)->update($data);
- Until::output(['isSuccess' => $isSuccess]);
- }
- }
|