123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <?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\DiscussModel;
- use app\api\model\GroupModel;
- use app\api\model\StoreModel;
- use app\common\until\Until;
- use think\Db;
- class Store extends BaseController {
- /**
- * @OA\Get(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闭店 3歇业", @OA\Schema(type="integer",default="1")),
- * @OA\Parameter(name="name", in="query", description="门店名称", @OA\Schema(type="string")),
- * @OA\Parameter(name="lat", in="query", description="经度", @OA\Schema(type="string")),
- * @OA\Parameter(name="lon", in="query", description="纬度", @OA\Schema(type="string")),
- * @OA\Parameter(name="groupId", in="query", description="集团id", @OA\Schema(type="string")),
- * @OA\Parameter(name="type", in="query", description="类型 1为当前管理人员的门店", @OA\Schema(type="integer")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function index() {
- $input = Until::getInput();
- $model = new StoreModel();
- $model->setPage($input['page'] ?? 1);
- $model->setPageSize($input['pageSize'] ?? 10);
- $where = [];
- if (!empty($input['status'])) {
- $where[] = ['s.status', '=', $input['status']];
- }
- if (!$this->isAdmin()) {
- $where[] = ['s.status', '=', 1];
- }
- if (!empty($input['name'])) {
- $where[] = ['s.store_name', 'like', "%{$input['name']}%"];
- }
- if (!empty($input['groupId'])) {
- $ids = explode(',', $input['groupId']);
- $where[] = ['s.group_id', 'in', "{$ids}"];
- }
- if (!empty($input['type']) && $input['type'] == 1) {
- $model->setAdminId($this->adminId);
- $where[] = ['sr.admin_id', '=', $this->adminId];
- }
- $field = '';
- if (!empty($input['lon']) && !empty($input['lat'])) {
- $squares = Until::returnSquarePoint($input['lon'], $input['lat']);
- $where[] = ['s.latitude', '<>', 0];
- $where[] = ['s.latitude', '>', $squares['right-bottom']['lat']];
- $where[] = ['s.latitude', '<', $squares['left-top']['lat']];
- $where[] = ['s.longitude', '>', $squares['left-top']['lng']];
- $where[] = ['s.longitude', '<', $squares['right-bottom']['lng']];
- $field = "(6378.138 * 2 * asin(sqrt(pow(sin((s.latitude * pi() / 180 - " . $input['lat'] . " * pi() / 180) / 2),2) +
- cos(s.latitude * pi() / 180) * cos(" . $input['lat'] . " * pi() / 180) * pow(sin((s.longitude * pi() / 180 - "
- . $input['lon'] . " * pi() / 180) / 2),2))) ) as distance";
- }
- $model->setWhere($where);
- $data = $model->getStoreList($field);
- foreach ($data['list'] as &$info) {
- if (!empty($info['distance'])) {
- $info['distanceA'] = $info['distance'];
- $info['distance'] = number_format($info['distance'], 2) . "km";
- }
- }
- unset($info);
- 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="门店介绍", property="storeContent", type="string", default="本店所有商品照片为专业摄影师拍摄,后期起精心修制及色彩调整,尽量与实际商品保持一致。"),
- * @OA\Property(description="门店id", property="id", type="string", default=""),
- * @OA\Property(description="门店状态 1正常 2闭店 3暂歇", property="status", type="0"),
- * required={"name","code","openTime","closeTime","groupId","companyId","brandId","logo",
- * "latitude","longitude","address","mobile","storeContent"})
- * )
- * ),
- * @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',
- 'storeContent|门店介绍' => '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'],
- 'store_content' => $input['storeContent'],
- 'status' => $input['status']
- ]);
- } else {
- if (empty($input['payCode'])) {
- $input['payCode'] = (new GroupModel())::where(['id' => (int)$input['groupId']])->value('pay_code');
- }
- $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'],
- 'store_content' => $input['storeContent'] ?? '',
- ]);
- Db::table('store_role')->insertGetId(['store_id' => (int)$id, 'admin_id' => $this->adminId]);
- }
- $model->setWhere(['s.id' => (int)$id]);
- $info = $model->getStoreInfo();
- 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闭店 3暂歇", @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]);
- }
- /**
- * @OA\Post(path="/api/Store/getStore",
- * 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="lat", type="string", default=""),
- * @OA\Property(description="经度", property="lon", type="string", default=""),
- * required={"lat","lon"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function getStore() {
- $input = Until::getInput();
- $rule = [
- 'lat|纬度' => 'require',
- 'lon|经度' => 'require',
- ];
- Until::check($rule, $input);
- $model = new StoreModel();
- $squares = Until::returnSquarePoint($input['lon'], $input['lat']);
- $info = $model::where("status = 1 and latitude<>0 and latitude>{$squares['right-bottom']['lat']} and latitude<{$squares['left-top']['lat']} and
- longitude>{$squares['left-top']['lng']} and longitude<{$squares['right-bottom']['lng']}")
- ->field('*,' . "(6378.138 * 2 * asin(sqrt(pow(sin((latitude * pi() / 180 - " . $input['lat'] . " * pi() / 180) / 2),2) +
- cos(latitude * pi() / 180) * cos(" . $input['lat'] . " * pi() / 180) * pow(sin((longitude * pi() / 180 - " . $input['lon'] . " * pi() / 180) / 2),2))) * 1000) as distance")
- ->find();
- $info = Until::modelToArray($info);
- if (empty($info)) {
- Until::output(['info' => []]);
- }
- $disModel = new DiscussModel();
- $storeScore = $disModel::where(['store_id' => $info['id']])->avg('store_score');
- $info['score'] = (int)$storeScore;
- $distance = (float)(substr(($info['distance'] / 1000), 0, 6));
- $info['distance'] = number_format($distance, 2) . "km";
- Until::output(['info' => Until::modelToArray($info)]);
- }
- /**
- * @OA\GET(path="/api/Store/appointmentTime",
- * tags={"门店管理"},
- * summary="可预约时间",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="storeId", in="query", description="门店id", @OA\Schema(type="ineger",default="1")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function appointmentTime() {
- $input = Until::getInput();
- $data = [
- date('m-d'),
- date('m-d', strtotime('+1 day')),
- // '今天',
- // '明天',
- date('m-d', strtotime('+2 days')),
- date('m-d', strtotime('+3 days')),
- date('m-d', strtotime('+4 days')),
- date('m-d', strtotime('+5 days')),
- date('m-d', strtotime('+6 days')),
- ];
- Until::output(['date' => $data]);
- }
- }
|