345 lines
11 KiB
PHP
345 lines
11 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\CardUnion;
|
|
use app\models\District;
|
|
use app\models\Store;
|
|
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\StoreActionForm;
|
|
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\store\StoreOrderForm;
|
|
use app\modules\admin\models\storeUser\StoreUserActionForm;
|
|
use app\modules\admin\models\storeUser\StoreUserEditForm;
|
|
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 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);
|
|
}
|
|
$storeUser = null;
|
|
$user = null;
|
|
$area = [];
|
|
if ($model != null) {
|
|
$storeUser = StoreUser::findOne(['store_id' => $model->id, 'is_delete' => 0, 'user_type' => 1]);
|
|
$user = User::findOne(['id' => $storeUser->user_id]);
|
|
$area = json_decode($model->area, true);
|
|
$area = empty($area) ? [] : array_values($area);
|
|
}
|
|
$district = District::getTerritorial();
|
|
$district = (new Serializer())->encode($district);
|
|
$return_url = \Yii::$app->request->referrer;
|
|
return $this->render('edit', [
|
|
'model' => $model,
|
|
'return_url' => $return_url,
|
|
'district' => $district,
|
|
'storeUser' => $storeUser,
|
|
'user' => $user,
|
|
'area' => json_encode($area, JSON_UNESCAPED_UNICODE)
|
|
]);
|
|
|
|
}
|
|
|
|
//删除门店
|
|
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'];
|
|
$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 actionStoreUser()
|
|
{
|
|
if (\Yii::$app->request->isAjax) {
|
|
$form = new StoreUserListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
return $this->render('store-user');
|
|
}
|
|
|
|
//门店人员管理创建/编辑
|
|
public function actionStoreUserEdit($id = 0)
|
|
{
|
|
$model = StoreUser::findOne([
|
|
'id' => $id,
|
|
'is_delete' => 0
|
|
]);
|
|
if ($model == null)
|
|
$model = new StoreUser();
|
|
if (\Yii::$app->request->isPost) {
|
|
$form = new StoreUserEditForm();
|
|
$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);
|
|
}
|
|
if ($model != null) {
|
|
$user = User::findOne(['id' => $model->user_id]);
|
|
} else {
|
|
$user = new User();
|
|
}
|
|
if (empty($user)) {
|
|
$user = new User();
|
|
}
|
|
$store = Store::find()->where(['is_delete' => 0])->asArray()->all();
|
|
return $this->render('store-user-edit', [
|
|
'store' => $store,
|
|
'password' => '12345678',
|
|
'model' => $model,
|
|
'user' => $user,
|
|
'return_url' => '',
|
|
]);
|
|
}
|
|
|
|
//门店人员管理删除
|
|
public function actionStoreUserDelete()
|
|
{
|
|
if (!\Yii::$app->request->isPost) {
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new StoreUserActionForm();
|
|
$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 StoreUserActionForm();
|
|
$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']);
|
|
}
|
|
|
|
|
|
} |