Store.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/12/16 23:03
  5. */
  6. namespace app\api\controller;
  7. use app\api\BaseController;
  8. use app\api\model\AdminModel;
  9. use app\api\model\StoreModel;
  10. use app\common\until\Until;
  11. class Store extends BaseController {
  12. /**
  13. * @OA\Post(path="/api/Store/index",
  14. * tags={"门店管理"},
  15. * summary="门店列表",
  16. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  17. * @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
  18. * @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
  19. * @OA\Parameter(name="status", in="query", description="状态 1正常 2删除", @OA\Schema(type="integer",default="1")),
  20. * @OA\Parameter(name="name", in="query", description="门店名称", @OA\Schema(type="string")),
  21. * @OA\RequestBody(
  22. * ),
  23. * @OA\Response(response="200", description="请求成功")
  24. * )
  25. */
  26. public function index() {
  27. $input = request()->get();
  28. $model = new StoreModel();
  29. $model->setPage($input['page'] ?? 1);
  30. $model->setPageSize($input['pageSize'] ?? 10);
  31. if ($this->isAdmin()) {
  32. $where = [];
  33. } else {
  34. $where[] = ['s.status', '=', $model::NORMAL];
  35. }
  36. if (!empty($input['name'])){
  37. $where[] = ['s.store_name', 'like', "%{$input['name']}%"];
  38. }
  39. $model->setWhere($where);
  40. $data = $model->getStoreList();
  41. Until::output($data);
  42. }
  43. /**
  44. * @OA\Post(path="/api/Store/save",
  45. * tags={"门店管理"},
  46. * summary="保存门店信息",
  47. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  48. * @OA\RequestBody(
  49. * @OA\MediaType(
  50. * mediaType="multipart/form-data",
  51. * @OA\Schema(
  52. * @OA\Property(description="门店名称", property="name", type="string", default="测试门店1"),
  53. * @OA\Property(description="门店code", property="code", type="string", default="A001"),
  54. * @OA\Property(description="营业时间", property="openTime", type="string", default="06:00"),
  55. * @OA\Property(description="闭店时间", property="closeTime", type="string", default="22:00"),
  56. * @OA\Property(description="支付标识", property="payCode", type="string", default="paycode1"),
  57. * @OA\Property(description="所属集团id", property="groupId", type="integer", default="1"),
  58. * @OA\Property(description="所属公司id", property="companyId", type="integer", default="1"),
  59. * @OA\Property(description="所属品牌id", property="brandId", type="integer", default="1"),
  60. * @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"),
  61. * @OA\Property(description="纬度", property="latitude", type="string", default="31.241510099342623"),
  62. * @OA\Property(description="经度", property="longitude", type="string", default="121.32174958203123"),
  63. * @OA\Property(description="地址", property="address", type="string", default="上海市普陀区真北路"),
  64. * @OA\Property(description="联系电话", property="mobile", type="string", default="15656789876"),
  65. * @OA\Property(description="门店id", property="id", type="string", default=""),
  66. * @OA\Property(description="门店状态 1正常 2闭店 3暂歇", property="status", type="0"),
  67. * required={"name","code","openTime","closeTime","payCode","groupId","companyId","brandId","logo",
  68. * "latitude","longitude","address","mobile"})
  69. * )
  70. * ),
  71. * @OA\Response(response="200", description="请求成功")
  72. * )
  73. */
  74. public function save() {
  75. $input = Until::getInput();
  76. $rule = [
  77. 'name|门店名称' => 'require',
  78. 'code|门店code' => 'require',
  79. 'openTime|营业时间' => 'require',
  80. 'closeTime|闭店时间' => 'require',
  81. 'payCode|支付标识' => 'require',
  82. 'groupId|所属集团id' => 'require',
  83. 'companyId|所属公司id' => 'require',
  84. 'brandId|所属品牌id' => 'require',
  85. 'logo|logo的url' => 'require',
  86. 'latitude|纬度' => 'require',
  87. 'longitude|经度' => 'require',
  88. 'address|地址' => 'require',
  89. 'mobile|联系电话' => 'require',
  90. ];
  91. Until::check($rule, $input);
  92. $model = new StoreModel();
  93. if (!empty($input['id']) ) {
  94. $id = (int)$input['id'];
  95. $model::where(['id' => $id])->update([
  96. 'store_name' => $input['name'],
  97. 'store_code' => $input['code'],
  98. 'open_time' => $input['openTime'],
  99. 'close_time' => $input['closeTime'],
  100. 'pay_code' => $input['payCode'],
  101. 'group_id' => $input['groupId'],
  102. 'company_id' => $input['companyId'],
  103. 'brand_id' => $input['brandId'],
  104. 'logo' => $input['logo'],
  105. 'latitude' => $input['latitude'],
  106. 'longitude' => $input['longitude'],
  107. 'address' => $input['address'],
  108. 'mobile' => $input['mobile'],
  109. 'status' => $input['status']
  110. ]);
  111. } else {
  112. $id = $model->insertGetId([
  113. 'store_name' => $input['name'],
  114. 'store_code' => $input['code'],
  115. 'open_time' => $input['openTime'],
  116. 'close_time' => $input['closeTime'],
  117. 'pay_code' => $input['payCode'],
  118. 'group_id' => $input['groupId'],
  119. 'company_id' => $input['companyId'],
  120. 'brand_id' => $input['brandId'],
  121. 'logo' => $input['logo'],
  122. 'latitude' => $input['latitude'],
  123. 'longitude' => $input['longitude'],
  124. 'address' => $input['address'],
  125. 'mobile' => $input['mobile'],
  126. ]);
  127. }
  128. $info = $model::get($id);
  129. Until::output(['info' => Until::modelToArray($info)]);
  130. }
  131. /**
  132. * @OA\GET(path="/api/Store/read",
  133. * tags={"门店管理"},
  134. * summary="查看门店信息",
  135. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  136. * @OA\Parameter(name="id", in="query", description="门店id", @OA\Schema(type="ineger",default="1")),
  137. * @OA\RequestBody(
  138. * ),
  139. * @OA\Response(response="200", description="请求成功")
  140. * )
  141. */
  142. public function read($id) {
  143. $model = new StoreModel();
  144. $where[] = ['s.id', '=', (int)$id];
  145. $model->setWhere($where);
  146. $info = $model->getStoreInfo();
  147. Until::output(['info' => $info]);
  148. }
  149. /**
  150. * @OA\GET(path="/api/Store/delete",
  151. * tags={"门店管理"},
  152. * summary="删除门店信息",
  153. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  154. * @OA\Parameter(name="id", in="query", description="门店id", @OA\Schema(type="ineger",default="1")),
  155. * @OA\Parameter(name="status", in="query", description="1正常 2删除", @OA\Schema(type="ineger",default="1")),
  156. * @OA\RequestBody(
  157. * ),
  158. * @OA\Response(response="200", description="请求成功")
  159. * )
  160. */
  161. public function delete($id,$status) {
  162. $model = new StoreModel();
  163. $where[] = ['id', '=', (int)$id];
  164. $data = ['status' => (int)$status];
  165. $isSuccess = $model::where($where)->update($data);
  166. Until::output(['isSuccess' => $isSuccess]);
  167. }
  168. }