620 lines
19 KiB
PHP
620 lines
19 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\admin\controllers;
|
|
|
|
use app\components\Serializer;
|
|
use app\models\auth\Role;
|
|
use app\models\auth\RoleUser;
|
|
use app\models\Box;
|
|
use app\models\CardUnion;
|
|
use app\models\District;
|
|
use app\models\Store;
|
|
use app\models\StoreBj;
|
|
use app\models\StoreEarnings;
|
|
use app\models\StoreUser;
|
|
use app\models\User;
|
|
use app\modules\admin\behaviors\LoginBehavior;
|
|
use app\components\EncryptHelper;
|
|
use app\modules\admin\models\BindLogListForm;
|
|
use app\modules\admin\models\store\BoxActionForm;
|
|
use app\modules\admin\models\store\BoxEditForm;
|
|
use app\modules\admin\models\store\BoxListForm;
|
|
use app\modules\admin\models\store\DevActionForm;
|
|
use app\modules\admin\models\store\DevListForm;
|
|
use app\modules\admin\models\store\StoreActionForm;
|
|
use app\modules\admin\models\store\StoreBjActionForm;
|
|
use app\modules\admin\models\store\StoreBjEditForm;
|
|
use app\modules\admin\models\store\StoreBjListForm;
|
|
use app\modules\admin\models\store\StoreEaringsListForm;
|
|
use app\modules\admin\models\store\StoreEditForm;
|
|
use app\modules\admin\models\store\StoreListForm;
|
|
use app\modules\admin\models\storeMake\StoreMakeActionForm;
|
|
use app\modules\admin\models\storeMake\StoreMakeListForm;
|
|
use app\modules\admin\models\storeUser\StoreUserActionForm;
|
|
use app\modules\admin\models\storeUser\StoreUserListForm;
|
|
|
|
|
|
class StoreController extends Controller
|
|
{
|
|
public function behaviors()
|
|
{
|
|
return array_merge(parent::behaviors(), [
|
|
'login' => [
|
|
'class' => LoginBehavior::className(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
//门店列表
|
|
public function actionIndex()
|
|
{
|
|
if (\Yii::$app->request->isAjax) {
|
|
$form = new StoreListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$district = District::getTerritorial();
|
|
$district = (new Serializer())->encode($district);
|
|
return $this->render('index', [
|
|
'district' => $district,
|
|
'province_id' => '',
|
|
'city_id' => '',
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
//店长列表
|
|
public function actionShopowner()
|
|
{
|
|
if (\Yii::$app->request->isAjax) {
|
|
$form = new StoreUserListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
return $this->render('shopowner');
|
|
|
|
}
|
|
|
|
|
|
//店长预约列表
|
|
public function actionStoreMake()
|
|
{
|
|
if (\Yii::$app->request->isAjax) {
|
|
$form = new StoreMakeListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
$user_list = StoreUser::find()
|
|
->where([
|
|
'is_delete' => 0,
|
|
])
|
|
->orderBy(['id' => SORT_DESC])
|
|
->select('id,user_id,username')->asArray()->all();
|
|
|
|
return $this->render('store-make', [
|
|
'user_list' => $user_list,
|
|
]);
|
|
|
|
}
|
|
|
|
//店长预约同意
|
|
public function actionStoreMakeStatusYes()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreMakeActionForm();
|
|
$post = \Yii::$app->request->post();
|
|
// $form->user_id = $post['distribution_user_id'];
|
|
$form->make_time = $post['make_time'];
|
|
$form->id = $post['id'];
|
|
$form->store_id = $post['store_id'];
|
|
$data = $form->statusYes();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//店长预约拒绝
|
|
public function actionStoreMakeStatusNo()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreMakeActionForm();
|
|
$post = \Yii::$app->request->post();
|
|
$form->id = $post['id'];
|
|
$data = $form->statusNo();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
|
|
//绑定记录
|
|
public function actionBind()
|
|
{
|
|
$time = time();
|
|
$date = date('Y-m-d H:00:00', $time - 60 * 60 * 12) . " - " . date('Y-m-d H:00:00', $time);
|
|
$store = Store::find()->select('id,name')->where(['is_delete' => 0])->asArray()->all();
|
|
return $this->render('bind', [
|
|
'store' => $store,
|
|
'date' => $date,
|
|
]);
|
|
}
|
|
|
|
|
|
/**
|
|
* @ Author : Lw
|
|
* @ CreateTime : 2022-11-15
|
|
* @ Info : 获取场地扫码数据
|
|
*/
|
|
public function actionGetCdQrData()
|
|
{
|
|
$obj = new StoreEaringsListForm();
|
|
$get = \Yii::$app->request->get();
|
|
if ($get['store_id'] == 0) {
|
|
unset($get['store_id']);
|
|
}
|
|
$obj->attributes = $get;
|
|
$res = $obj->getStoreList();
|
|
return $this->responseHandler($res);
|
|
}
|
|
|
|
|
|
//门店编辑、创建
|
|
public function actionEdit($id = 0)
|
|
{
|
|
$model = Store::findOne([
|
|
'id' => $id,
|
|
'is_delete' => 0
|
|
]);
|
|
if ($model == null)
|
|
$model = new Store();
|
|
if (\Yii::$app->request->isPost) {
|
|
$form = new StoreEditForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->model = $model;
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->creator_user_id = \Yii::$app->admin->identity->user_id;
|
|
$data = $form->edit();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$role_list = Role::find()
|
|
->where([
|
|
'is_delete' => 0,
|
|
'cx_mch_id' => $this->cx_mch_id,
|
|
'creator_user_id' => \Yii::$app->admin->identity->user_id,
|
|
'name' => '门店管理员'
|
|
])
|
|
->select('id,name')->asArray()->all();
|
|
foreach ($role_list as $index => $item) {
|
|
$item['checked'] = true;
|
|
$role_list[$index] = $item;
|
|
}
|
|
$district = District::getTerritorial();
|
|
$district = (new Serializer())->encode($district);
|
|
$card = CardUnion::find()->select('id,card_number,name')->andWhere(['is_delete' => 0])->asArray()->all();
|
|
if (!empty($card)) {
|
|
foreach ($card as $index2 => &$item2) {
|
|
$item2['name_cn'] = $item2['name'] . '-' . $item2['card_number'];
|
|
}
|
|
}
|
|
$return_url = \Yii::$app->request->referrer;
|
|
return $this->render('edit', [
|
|
'model' => $model,
|
|
'return_url' => $return_url,
|
|
'district' => $district,
|
|
'password' => '12345678',
|
|
'role_list' => $role_list,
|
|
'card' => $card,
|
|
]);
|
|
|
|
}
|
|
|
|
//删除门店
|
|
public function actionDelete()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->delete();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//营业
|
|
public function actionStatusYes()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->status_yes();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//停业
|
|
public function actionStatusNo()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->status_no();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//门店收益
|
|
public function actionStoreEarings()
|
|
{
|
|
$get = \Yii::$app->request->get();
|
|
|
|
// $store_id = \Yii::$app->store->identity->store_id;
|
|
|
|
if (\Yii::$app->request->isAjax) {
|
|
$form = new StoreEaringsListForm();
|
|
$form->attributes = $get;
|
|
$form->store_id = $get['store_id']??0;
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$start_time = !empty($get['start_time']) ? strtotime($get['start_time']) : 0;
|
|
$end_time = !empty($get['end_time']) ? strtotime($get['end_time']) : time();
|
|
$sum = StoreEarnings::find()->where(['between', 'created_at', $start_time, $end_time])->andWhere([
|
|
'is_delete' => 0,
|
|
])->sum('money');
|
|
$sum = empty($sum) ? 0 : $sum;
|
|
|
|
$store = Store::find()->select('id,name')->where(['is_delete' => 0])->asArray()->all();
|
|
|
|
return $this->render('earings', [
|
|
'store' => $store,
|
|
'store_money' => $sum,
|
|
]);
|
|
}
|
|
|
|
|
|
//门店保洁
|
|
public function actionStoreBj()
|
|
{
|
|
if (\Yii::$app->request->isAjax) {
|
|
$form = new StoreBjListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
return $this->render('store-bj');
|
|
}
|
|
|
|
|
|
//门店人员管理
|
|
public function actionStoreUser()
|
|
{
|
|
if (\Yii::$app->request->isAjax) {
|
|
$form = new BoxListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
return $this->render('store-user');
|
|
}
|
|
|
|
//保洁人员管理创建/编辑
|
|
public function actionStoreBjEdit($id = 0)
|
|
{
|
|
$model = StoreBj::findOne([
|
|
'id' => $id,
|
|
'is_delete' => 0
|
|
]);
|
|
if ($model == null)
|
|
$model = new StoreBj();
|
|
if (\Yii::$app->request->isPost) {
|
|
$form = new StoreBjEditForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->model = $model;
|
|
$data = $form->edit();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
$store = Store::find()->where(['is_delete' => 0])->asArray()->all();
|
|
$return_url = \Yii::$app->request->referrer;
|
|
|
|
return $this->render('store-bj-edit', [
|
|
'store' => $store,
|
|
'model' => $model,
|
|
'return_url' => $return_url,
|
|
]);
|
|
}
|
|
|
|
//门店保洁人员管理删除
|
|
public function actionStoreBjDelete()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreBjActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->delete();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//门店保洁人员管理切换为正常状态
|
|
public function actionStoreBjStatusYes()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreBjActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->statusYes();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//门店保洁人员管理切换为封禁状态
|
|
public function actionStoreBjStatusNo()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreBjActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->statusNo();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
|
|
//门店人员管理创建/编辑
|
|
public function actionStoreUserEdit($id = 0)
|
|
{
|
|
$model = Box::findOne([
|
|
'id' => $id,
|
|
'is_delete' => 0
|
|
]);
|
|
if ($model == null)
|
|
$model = new Box();
|
|
if (\Yii::$app->request->isPost) {
|
|
$form = new BoxEditForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->model = $model;
|
|
$data = $form->edit();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$model->device = json_decode($model->device, true);
|
|
$store = Store::find()->where(['is_delete' => 0])->asArray()->all();
|
|
$return_url = \Yii::$app->request->referrer;
|
|
|
|
return $this->render('store-user-edit', [
|
|
'store' => $store,
|
|
'model' => $model,
|
|
'return_url' => $return_url,
|
|
]);
|
|
}
|
|
|
|
|
|
//门店人员管理删除
|
|
public function actionStoreUserDelete()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new BoxActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->delete();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//门店人员管理切换为正常状态
|
|
public function actionStoreUserStatusYes()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new BoxActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->statusYes();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//门店人员管理切换为封禁状态
|
|
public function actionStoreUserStatusNo()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreUserActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->statusNo();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//查看门店二维码
|
|
public function actionFindQrcode()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->getStoreQrcode();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//打包下载门店二维码
|
|
public function actionBatchQrcode()
|
|
{
|
|
$form = new StoreActionForm();
|
|
$data = $form->BatchQrcode();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
/**
|
|
* @ Author : Lw
|
|
* @ CreateTime : 2023-02-10
|
|
* @ Info : 用户短信设置
|
|
*/
|
|
public function actionStoreUserSetsms()
|
|
{
|
|
$type = \Yii::$app->request->post('type');
|
|
$mobile_phone = \Yii::$app->request->post('mobile_phone');
|
|
if (empty($type) || empty($mobile_phone)) {
|
|
return $this->responseHandler(['code' => 1, 'msg' => '请求错误']);
|
|
}
|
|
$arr = [
|
|
'gjsms' => "api:cxaibc:mqtt:send_sms:{$mobile_phone}", // 告警
|
|
'ghsms' => "api:cxaibc:gh:send_sms:{$mobile_phone}",// 归还
|
|
];
|
|
if (empty($arr[$type])) {
|
|
return $this->responseHandler(['code' => 1, 'msg' => '请求错误']);
|
|
}
|
|
$get = \Yii::$app->redis->get($arr[$type]);
|
|
if (empty($get) || $get == 'send') {
|
|
\Yii::$app->redis->set($arr[$type], 'nosend');
|
|
} else {
|
|
\Yii::$app->redis->set($arr[$type], 'send');
|
|
}
|
|
return $this->responseHandler(['code' => 0, 'msg' => 'ok']);
|
|
}
|
|
|
|
|
|
//店长审核通过
|
|
public function actionShopownerStatusYes()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreUserActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->statusYes();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//店长审核拒绝
|
|
public function actionShopownerStatusNo()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreUserActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->statusNo();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//店长审核成功短信store-make-send-yes-sms
|
|
public function actionStoreMakeSendYesSms()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreUserActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->actionStoreMakeSendYesSms();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
//店长审核拒绝短信
|
|
public function actionStoreMakeSendNoSms()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreUserActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->actionStoreMakeSendNoSms();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
|
|
//店长审核删除
|
|
public function actionStoreMakeDelete()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreUserActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->actionStoreMakeDelete();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
|
|
/**
|
|
* 设备列表
|
|
* @return array|string
|
|
*/
|
|
public function actionDevList()
|
|
{
|
|
|
|
if (\Yii::$app->request->isAjax) {
|
|
$form = new DevListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
$store_list = Store::find()
|
|
->where([
|
|
'is_delete' => 0,
|
|
])
|
|
->orderBy(['id' => SORT_DESC])
|
|
->select('id,name')->asArray()->all();
|
|
|
|
return $this->render('dev-list', [
|
|
'store_list' => $store_list,
|
|
]);
|
|
|
|
}
|
|
|
|
/**
|
|
* 设备分配门店
|
|
* @return array|string
|
|
*/
|
|
public function actionDevEdit()
|
|
{
|
|
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new DevActionForm();
|
|
$post = \Yii::$app->request->post();
|
|
$form->store_id = $post['store_id'];
|
|
$form->id = $post['id'];
|
|
$data = $form->status_yes();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
|
|
} |