489 lines
15 KiB
PHP
489 lines
15 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2021-4-17
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
|
||
namespace app\modules\api\controllers;
|
||
|
||
use app\components\EncryptHelper;
|
||
use app\models\Order;
|
||
use app\models\OrderDetail;
|
||
use app\models\QrcodeRecord;
|
||
use app\models\StoreUser;
|
||
use app\models\User;
|
||
use app\models\UserInformation;
|
||
use app\modules\api\behaviors\LoginBehavior;
|
||
use app\modules\api\models\CommentForm;
|
||
use app\modules\api\models\UserBasicInfoForm;
|
||
use app\modules\api\models\UserModifyForm;
|
||
|
||
class UserController extends Controller
|
||
{
|
||
public function behaviors()
|
||
{
|
||
return array_merge(parent::behaviors(), [
|
||
'login' => [
|
||
'class' => LoginBehavior::className(),
|
||
'ignore' => [
|
||
'api/user/add-qrcode-find'
|
||
]
|
||
]
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 基础信息
|
||
* @description 获取个人基础信息
|
||
* @method get
|
||
* @url /api/user/index
|
||
* @return {"code":0,"msg":"ok","data":{"user_id":"1","nickname":"admin","avatar_url":"http://app.tpl.dev.1nww.com/statics/images/avatar.jpg","gender":0,"gender_cn":"未知","is_modify_un":false,"type_cn":"管理员","is_admin":true}}
|
||
* @return_param is_modify_un boolean 是否可以修改用户名
|
||
* @return_param is_admin boolean 是否为管理员
|
||
* @return_param is_view int 是否已观看视频,0未观看,1已观看
|
||
* @return_param is_logout int 是否可提交注销,0可以提交,1可以撤销
|
||
* @remark
|
||
*/
|
||
public function actionIndex()
|
||
{
|
||
$form = new UserBasicInfoForm();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->isGuest ? 0 : \Yii::$app->user->identity->id;
|
||
$data = $form->search();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 修改头像
|
||
* @description 修改用户头像
|
||
* @method post
|
||
* @url /api/user/modify-avatar
|
||
* @param avatar_url 必选 string 头像地址,文件上传接口返回地址
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @remark
|
||
*/
|
||
public function actionModifyAvatar()
|
||
{
|
||
$form = new UserBasicInfoForm();
|
||
// $form->scenario = 'avatar';
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->modify_avatar();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 修改昵称
|
||
* @description 修改用户昵称
|
||
* @method post
|
||
* @url /api/user/modify-nickname
|
||
* @param nickname 必选 string 昵称
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @remark
|
||
*/
|
||
public function actionModifyNickname()
|
||
{
|
||
$form = new UserBasicInfoForm();
|
||
// $form->scenario = 'nickname';
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->modify_nickname();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 修改性别
|
||
* @description 修改用户性别
|
||
* @method post
|
||
* @url /api/user/modify-gender
|
||
* @param gender 必选 int 性别,0=未知,1=男,2=女,3=保密
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @remark
|
||
*/
|
||
public function actionModifyGender()
|
||
{
|
||
$form = new UserBasicInfoForm();
|
||
$form->scenario = 'gender';
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->modify_gender();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 修改所在城市
|
||
* @description 修改用户所在城市
|
||
* @method post
|
||
* @url /api/user/modify-city
|
||
* @param city_id 必选 int 城市ID
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @remark
|
||
*/
|
||
public function actionModifyCity()
|
||
{
|
||
$form = new UserBasicInfoForm();
|
||
$form->scenario = 'city';
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->modify_city();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 会员注册
|
||
* @method post
|
||
* @url /api/user/modify-user
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @remark
|
||
*/
|
||
public function actionModifyUser()
|
||
{
|
||
$post = \Yii::$app->request->post(); // attributes 转成键值对形式 key=> value
|
||
$form = new UserModifyForm();
|
||
$form->setScenario('modify_user');
|
||
$form->cx_mch_id = $this->cx_mch_id; //商户ID 没看到传参赋值 默认给0
|
||
$form->price = $post['price'];
|
||
unset($post['price']);
|
||
$form->attributes = $post;
|
||
$form->user_id = \Yii::$app->user->identity->id; //获取用户登陆ID
|
||
$data = $form->modify_user();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
|
||
/**
|
||
* 会员注册填充
|
||
* @return array
|
||
*/
|
||
public function actionModifyUserBuy()
|
||
{
|
||
$form = new UserModifyForm();
|
||
$form->setScenario('modify_user_buy');
|
||
$form->cx_mch_id = $this->cx_mch_id; //商户ID 没看到传参赋值 默认给0
|
||
$form->attributes = \Yii::$app->request->post(); // attributes 转成键值对形式 key=> value
|
||
$form->user_id = \Yii::$app->user->identity->id; //获取用户登陆ID
|
||
$data = $form->modify_user_buy();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 会员注册判断
|
||
* @method post
|
||
* @url /api/user/user-list
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @remark
|
||
*/
|
||
public function actionUserFind()
|
||
{
|
||
$form = new UserModifyForm();
|
||
$form->cx_mch_id = $this->cx_mch_id; //商户ID 没看到传参赋值 默认给0
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
|
||
$data = $form->verifyUserInfo();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
|
||
/**
|
||
*会员信息填充
|
||
*/
|
||
public function actionUserPersonal()
|
||
{
|
||
$form = new UserModifyForm();
|
||
$form->cx_mch_id = $this->cx_mch_id; //商户ID 没看到传参赋值 默认给0
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$request = \Yii::$app->request;
|
||
if ($request->isPost) {
|
||
$form->setScenario('user_personal');
|
||
$form->attributes = $request->post(); // attributes 转成键值对形式 key=> value;
|
||
}
|
||
$data = $form->userPersonal($request);
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
|
||
/**
|
||
* 用户评价
|
||
* @return array
|
||
*/
|
||
public function actionEvaluate()
|
||
{
|
||
$form = new CommentForm();
|
||
$form->cx_mch_id = $this->cx_mch_id; //商户ID 没看到传参赋值 默认给0
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$form->attributes = \Yii::$app->request->post(); // attributes 转成键值对形式 key=> value
|
||
$data = $form->evaluation();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
|
||
/**
|
||
* 评价查看
|
||
*/
|
||
public function actionEvaluateShow()
|
||
{
|
||
$form = new CommentForm();
|
||
$form->cx_mch_id = $this->cx_mch_id; //商户ID 没看到传参赋值 默认给0
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$form->attributes = \Yii::$app->request->get(); // attributes 转成键值对形式 key=> value
|
||
$data = $form->evaluationList();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 获取用户id的事件
|
||
* @description 修改用户所在城市
|
||
* @method get
|
||
* @param user_id int 用户id
|
||
* @url /api/user/get-user-id-event
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @remark
|
||
*/
|
||
public function actionGetUserIdEvent()
|
||
{
|
||
$id = \Yii::$app->request->get('user_id');
|
||
if (empty($id)) {
|
||
return $this->responseHandler(['code' => 1, 'msg' => 'ok', 'data' => []]);
|
||
}
|
||
$key = "api:user_event_data:{$id}";
|
||
$get = \Yii::$app->redis->hkeys($key);
|
||
if (empty($get)) {
|
||
\Yii::$app->redis->hset($key, "temp_field", 1);
|
||
return $this->responseHandler(['code' => 1, 'msg' => 'ok', 'data' => []]);
|
||
}
|
||
$event_id = '';
|
||
foreach ($get as $k => $v) {
|
||
if ($v == 'temp_field') {
|
||
continue;
|
||
}
|
||
$event_id = $v;
|
||
break;
|
||
}
|
||
if (empty($event_id)) {
|
||
return $this->responseHandler(['code' => 1, 'msg' => 'ok', 'data' => []]);
|
||
}
|
||
return $this->responseHandler(['code' => 0, 'msg' => 'ok', 'data' => ['event_id' => $event_id]]);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 停止用户id的事件
|
||
* @description 修改用户所在城市
|
||
* @method get
|
||
* @param user_id int 用户id
|
||
* @param event_id string 事件id
|
||
* @url /api/user/end-user-id-event
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @remark
|
||
*/
|
||
public function actionEndUserIdEvent()
|
||
{
|
||
$id = \Yii::$app->request->get('user_id');
|
||
$event_id = \Yii::$app->request->get('event_id');
|
||
if (empty($id) || empty($event_id)) {
|
||
return $this->responseHandler(['code' => 1, 'msg' => 'ok', 'data' => []]);
|
||
}
|
||
$key = "api:user_event_data:{$id}";
|
||
\Yii::$app->redis->hdel($key, $event_id);
|
||
return $this->responseHandler(['code' => 0, 'msg' => 'ok', 'data' => []]);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 呼叫服务员
|
||
* @title 呼叫服务员
|
||
* @description 呼叫服务员
|
||
* @method post
|
||
* @url /api/user/service-person
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @return_param data array 手机号,一维索引数组
|
||
* @remark
|
||
*/
|
||
public function actionServicePerson()
|
||
{
|
||
if (!\Yii::$app->request->isPost) {
|
||
$data = $this->invaildRequest();
|
||
return $this->responseHandler($data);
|
||
}
|
||
$user_id = \Yii::$app->user->identity->id;
|
||
$order = Order::find()->where(['is_delete' => 0, 'status' => [1,2], 'user_id' => $user_id])->orderBy(['id' => SORT_DESC])->one();
|
||
if (empty($order) || empty($order->store_id)) {
|
||
return $this->responseHandler(['code' => 1, 'msg' => '没有正在进行中的订单,无法呼叫']);
|
||
}
|
||
|
||
$store_id = $order->store_id;
|
||
|
||
$phone = [];
|
||
$user_ids = StoreUser::find()->where(['is_delete' => 0, 'store_id' => $store_id, 'user_type' => 2, 'status' => 0])->select('user_id')->column();
|
||
|
||
if (!empty($user_ids)) {
|
||
$mobile_phone = User::find()->where(['id' => $user_ids])->select('mobile_phone')->column();
|
||
if (!empty($mobile_phone)) {
|
||
foreach ($mobile_phone as &$item) {
|
||
$item = EncryptHelper::decryptMobilePhone($item);
|
||
}
|
||
$phone = $mobile_phone;
|
||
}
|
||
}
|
||
if (empty($phone)) {
|
||
return $this->responseHandler(['code' => 1, 'msg' => '订单所在门店未绑定服务人员,无法呼叫']);
|
||
}
|
||
return $this->responseHandler(['code' => 0, 'msg' => 'ok', 'data' => $phone]);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 二维码访问
|
||
* @title 二维码访问
|
||
* @description 二维码访问
|
||
* @method post
|
||
* @url /api/user/add-qrcode-find
|
||
* @param store_id int 门店id
|
||
* @param ball_id string 球车编号
|
||
* @return
|
||
* @return_param
|
||
* @remark
|
||
*/
|
||
public function actionAddQrcodeFind()
|
||
{
|
||
if (!\Yii::$app->request->isPost) {
|
||
$data = $this->invaildRequest();
|
||
return $this->responseHandler($data);
|
||
}
|
||
$user_id = 0;
|
||
if(!empty(\Yii::$app->user->identity)){
|
||
$user_id = \Yii::$app->user->identity->id ? \Yii::$app->user->identity->id :0;
|
||
}
|
||
$store_id = \Yii::$app->request->post('store_id');
|
||
$ball_id = \Yii::$app->request->post('ball_id');
|
||
if(!empty($ball_id)){
|
||
$unionid = $ball_id;
|
||
$type = 2;
|
||
}else{
|
||
$unionid = $store_id;
|
||
$type = 1;
|
||
}
|
||
$value = ['user_id' => $user_id,'store_id'=>$store_id,'ball_id'=>$ball_id];
|
||
$value = json_encode($value);
|
||
$obj = new QrcodeRecord();
|
||
$obj->unionid = $unionid;
|
||
$obj->data = $value;
|
||
$obj->type = $type;
|
||
$obj->created_at = time();
|
||
$obj->is_delete = 0;
|
||
$obj->deleted_at = 0;
|
||
$obj->save();
|
||
/*$time = time();
|
||
$date = date('Y-m-d');
|
||
$h = date('H');
|
||
if(!empty($store_id)){
|
||
$key = 'api:cxaibc:qrcode:store_id:'.$store_id.":date_{$date}:h_{$h}";
|
||
}
|
||
if(!empty($ball_id)){
|
||
$key = 'api:cxaibc:qrcode:ball_id:'.$ball_id.":date_{$date}:h_{$h}";
|
||
}
|
||
\Yii::$app->redis->rpush($key,$value);
|
||
$redis_name = "api:cxaibc:qrcode:date:list";
|
||
\Yii::$app->redis->lpush($redis_name,$date);*/
|
||
return $this->responseHandler([
|
||
'code'=>0,
|
||
'msg'=>'ok',
|
||
'data'=>''
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 用户首次下单时看完视频调用
|
||
* @description 用户首次下单时看完视频调用
|
||
* @method post
|
||
* @url /api/user/find-video
|
||
* @return
|
||
* @return_param
|
||
* @remark 注:可根据/api/user/index【用户/基础信息】接口获取到用户观看状态
|
||
*/
|
||
public function actionFindVideo()
|
||
{
|
||
$form = new UserBasicInfoForm();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->find_video();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 注销申请
|
||
* @description 注销申请
|
||
* @method post
|
||
* @url /api/user/account-logout
|
||
* @return
|
||
* @return_param
|
||
* @remark
|
||
*/
|
||
public function actionAccountLogout()
|
||
{
|
||
if (!\Yii::$app->request->isPost) {
|
||
$data = $this->invaildRequest();
|
||
return $this->responseHandler($data);
|
||
}
|
||
$form = new UserBasicInfoForm();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->account_logout();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息
|
||
* @title 撤销注销申请
|
||
* @description 撤销注销申请
|
||
* @method post
|
||
* @url /api/user/account-logout-revocation
|
||
* @return
|
||
* @return_param
|
||
* @remark
|
||
*/
|
||
public function actionAccountLogoutRevocation()
|
||
{
|
||
if (!\Yii::$app->request->isPost) {
|
||
$data = $this->invaildRequest();
|
||
return $this->responseHandler($data);
|
||
}
|
||
$form = new UserBasicInfoForm();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->account_logout_revocation();
|
||
return $this->responseHandler($data);
|
||
}
|
||
} |