cxgj/modules/api/controllers/StoreController.php
2023-11-27 09:45:13 +08:00

378 lines
10 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\modules\api\controllers;
use app\models\DeviceUniqueConfig;
use app\models\DeviceUniqueData;
use function AlibabaCloud\Client\value;
use app\models\Banner;
use app\models\Store;
use app\models\StoreUser;
use app\modules\admin\models\store\BoxListForm;
use app\modules\api\models\BoxForm;
use app\modules\api\models\StoreForm;
use app\modules\api\models\StoreCityForm;
use app\modules\api\models\StoreUserForm;
use app\modules\api\models\UserBasicInfoForm;
use Yii;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use app\modules\api\behaviors\LoginBehavior;
/**
*m门店
*/
class StoreController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return array_merge(parent::behaviors(), [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
'login' => [
'class' => LoginBehavior::className(),
'ignore' => [
'api/store/page',
'api/store/index',
'api/store/store-one',
'api/store/store-home',
'api/store/coach',
'api/store/city',
'api/store/test-avg',
'api/store/shopowner',
'api/store/store-service',
'api/store/box',
'api/store/shopowner-make',
'api/store/shopowner-make-list',
'api/store/check-out',
]
]
]);
}
/**
* showdoc
* @catalog 门店
* @title 门店列表
* @description 门店列表
* @method get
* @url /api/store/index
* @param page 非必选 int 页码不传默认为1
* @param limit 非必选 int 每页显示条数不传默认10条
* @param city_id 非必选 string 城市id
* @param name 非必选 string 搜索内容
* @param lat 非必选 string 纬度
* @param lng 非必选 string 经度
* @return {"code":0,"msg":"ok","data":{}}
* @remark
*/
public function actionIndex()
{
$request = Yii::$app->request;
$get = $request->get();
$storeForm = new StoreForm();
$storeForm->page = $get['page'];
$storeForm->limit = $get['limit'];
$cityId = $get['city_id'];
$name = $get['name'];
$lat = $get['lat'];
$lng = $get['lng'];
$data = $storeForm->search($cityId, $name, $lat, $lng);
return $this->responseHandler($data);
}
//门店信息
public function actionStoreOne()
{
$request = Yii::$app->request;
$get = $request->get();
$storeForm = new StoreForm();
$storeForm->store_id = $get['store_id'];
$data = $storeForm->searchOne();
return $this->responseHandler($data);
}
/**
* showdoc
* @catalog 门店
* @title 切换门店
* @description 切换门店
* @method post
* @url /api/store/store-binding
* @param store_id 必选 int 页码不传默认为1
* @return {"code":0,"msg":"ok","data":{}}
* @remark
*/
public function actionStoreBinding()
{
$form = new StoreForm();
$form->scenario = 'city';
$post = \Yii::$app->request->post('store_id');
$form->cx_mch_id = $this->cx_mch_id;
$form->user_id = \Yii::$app->user->identity->id ?? 0;
$form->store_id = $post;
$data = $form->storeBinding();
return $this->responseHandler($data);
}
/**
* showdoc
* @catalog 门店
* @title 首页附近门店
* @description 首页附近门店
* @method get
* @url /api/store/store-home
* @param lat 必选 int 纬度
* @param lng 必选 int 经度
* @return {"code":0,"msg":"ok","data":{}}
* @remark
*/
public function actionStoreHome()
{
$request = Yii::$app->request;
$get = $request->get();
$storeForm = new StoreForm();
$storeForm->cx_mch_id = $this->cx_mch_id;
$storeForm->user_id = \Yii::$app->user->identity->id ?? 0;
$lat = $get['lat'];
$lng = $get['lng'];
$store_id = $get['store_id'] ?? 0;
$data = $storeForm->storeHome($lat, $lng, $store_id);
return $this->responseHandler($data);
}
public function avg($data)
{
$res = [];
foreach ($data as $key => $val) {
foreach ($val as $k => $v) {
if (empty($k)) {
$res[$k] = [];
}
$res[$k][] = floatval($v);
}
}
$count = count($data);
foreach ($res as $key => $val) {
$res[$key] = strval(round(array_sum($val) / $count, 2));
}
return $res;
}
// 测试结果
public function actionTestAvg()
{
$select = DeviceUniqueData::find()->limit(100)->select('*')->asArray()->all();
$arr = [];
foreach ($select as $key => $val) {
$arr[] = json_decode($val['data'], true);
}
$start_time = microtime(1);
$res = $this->avg($arr);
$end_time = microtime(1);
$console = [
'执行时长' => $end_time - $start_time,
'数量' => count($arr),
'结果' => $res,
];
var_dump($console);
exit();
}
public function actionConfigTest()
{
$select = DeviceUniqueData::find()->where(['id' => 1])->select('data')->asArray()->one();
$data = json_decode($select['data'], true);
foreach ($data as $key => $value) {
$arr[$key] = 1;
}
$model = new DeviceUniqueConfig();
$model->user_id = 0;
$model->config = json_encode($arr);
$model->created_at = time();
$model->save();
}
/**
* showdoc
* @catalog 门店
* @title 城市索引列表
* @description 本接口提供门店城市索引列表
* @method get
* @url /api/store/city
* @return {"code":0,"msg":"ok","data":{"X":[{"id":"146","parent_id":"13","name":"厦门市","level":"city"}]}}
* @remark
*/
public function actionCity()
{
$form = new StoreCityForm();
$data = $form->search();
return $this->responseHandler($data);
}
/**
* 门店服务
*/
public function actionStoreService()
{
$form = new StoreForm();
$data = $form->storeGoodsList();
return $this->responseHandler($data);
}
/**
* 包厢
*/
public function actionBox()
{
$request = Yii::$app->request;
$get = $request->get();
$form = new BoxForm();
$form->page = $get['page'] ?? 1;
$form->limit = $get['limit'] ?? 99;
$form->box_id = $get['box_id'];
$form->store_id = $get['store_id'];
$form->date = $get['date'];
$form->user_id = \Yii::$app->user->identity->id;
$data = $form->search();
return $this->responseHandler($data);
}
/**
* showdoc
* @catalog 门店申请
* @title 门店申请
* @description 本接口提供小门店申请
* @method get
* @url /api/store/shopowner
* @param username 必选 string 订单ID
* @param store_id 必选 string 设备码
* @return {"code":0,"msg":"提交申请成功","data":[]}
* @remark
*/
public function actionShopowner()
{
$request = Yii::$app->request;
$post = $request->post();
$form = new StoreUserForm();
$form->store_id = $post['store_id'];
$form->username = $post['username'];
$form->user_id = \Yii::$app->user->identity->id;
// $form->user_id = 2;
$data = $form->apply();
return $this->responseHandler($data);
}
/**
* showdoc
* @catalog 店长预约
* @title 店长预约
* @description 本接口提供店长预约
* @method get
* @url /api/store/shopowner-make
* @param username 必选 string 订单ID
* @param store_id 必选 string 设备码
* @return {"code":0,"msg":"提交申请成功","data":[]}
* @remark
*/
public function actionShopownerMake()
{
$request = Yii::$app->request;
$post = $request->get();
$form = new StoreUserForm();
$form->store_id = $post['store_id'];
$form->date = $post['date'];
$form->data = $post['data'];
$form->user_id = \Yii::$app->user->identity->id;
// $form->user_id = 2;
$data = $form->shopowner_make();
return $this->responseHandler($data);
}
/**
* showdoc
* @catalog 店长预约
* @title 店长预约-已预约信息
* @description 本接口提供已预约信息
* @method get
* @url /api/store/shopowner-make-list
* @param username 必选 string 订单ID
* @param store_id 必选 string 设备码
* @return {"code":0,"msg":"提交申请成功","data":[]}
* @remark
*/
public function actionShopownerMakeList()
{
$request = Yii::$app->request;
$post = $request->get();
$form = new StoreUserForm();
$form->store_id = $post['store_id'];
$form->user_id = \Yii::$app->user->identity->id;
$data = $form->actionShopownerMakeList();
return $this->responseHandler($data);
}
/**
* showdoc
* @catalog 离店
* @title 离店
* @description 本接口提供离店
* @method get
* @url /api/store/check-out
* @param store_id 必选 string 门店ID
* @return array
* @throws \Exception
*/
public function actionCheckOut()
{
$request = Yii::$app->request;
$post = $request->get();
$form = new StoreUserForm();
$form->store_id = $post['store_id'];
$form->user_id = \Yii::$app->user->identity->id;
$data = $form->checkOut();
return $this->responseHandler($data);
}
/**
* showdoc
* @catalog 店长公告
* @title 店长公告
* @description 本接口提供店长公告
* @method get
* @url /api/store/page
* @param store_id 必选 string 门店ID
* @return array
* @throws \Exception
*/
public function actionPage()
{
$request = Yii::$app->request;
$post = $request->get();
$form = new StoreUserForm();
$form->store_id = $post['store_id'];
$form->user_id = \Yii::$app->user->identity->id;
$data = $form->page();
return $this->responseHandler($data);
}
}