234 lines
6.7 KiB
PHP
234 lines
6.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\models\storeUser;
|
|
|
|
use app\components\FlashStorage;
|
|
use app\models\Admin;
|
|
use app\models\auth\RoleUser;
|
|
use app\models\Model;
|
|
use app\models\sms\SmsMsgHelper;
|
|
use app\models\sms\SmsTpl;
|
|
use app\models\Store;
|
|
use app\models\StoreMake;
|
|
use app\models\StoreUser;
|
|
use app\models\User;
|
|
use app\modules\admin\models\AdminModel;
|
|
use app\modules\api\models\StoreCityForm;
|
|
use yii\data\Pagination;
|
|
|
|
class StoreUserActionForm extends AdminModel
|
|
{
|
|
|
|
public $ids;
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['ids'], 'required'],
|
|
[['ids'], 'safe'],
|
|
];
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'ids' => '选择项',
|
|
];
|
|
}
|
|
|
|
//删除
|
|
public function delete()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
foreach ($this->ids as $item){
|
|
$model = StoreUser::findOne([
|
|
'id' => $item,
|
|
'is_delete' => 0,
|
|
]);
|
|
if($model == null){
|
|
return Model::asReturnError('该账号不存在或已被清理');
|
|
}
|
|
if($model->is_delete == 1){
|
|
continue;
|
|
}
|
|
|
|
$model->is_delete = 1;
|
|
$model->deleted_at = time();
|
|
if(!$model->save()){
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
$user = User::findOne(['id' => $model->user_id]);
|
|
if($user != null){
|
|
$user->type = 0;
|
|
if(!$user->save()){
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($user);
|
|
}
|
|
}
|
|
if($model->user_type == '1'){
|
|
$admin = \Yii::$app->db->createCommand()->update(Admin::tableName(), ['is_delete' => 1], ['user_id' => $model->user_id,'is_delete' => 0])->execute();
|
|
$role = RoleUser::updateAll(['is_delete' => 1], ['is_delete' => 0, 'user_id' => $model->user_id, 'cx_mch_id' => 0]);
|
|
if(!$admin){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('账号重置失败');
|
|
}
|
|
if(!$role){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('权限重置失败');
|
|
}
|
|
}
|
|
}
|
|
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
|
|
|
|
}
|
|
|
|
//正常
|
|
public function statusYes()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
foreach ($this->ids as $item){
|
|
$model = StoreUser::findOne([
|
|
'id' => $item,
|
|
'is_delete' => 0,
|
|
'status' => 1,
|
|
]);
|
|
if($model == null){
|
|
return Model::asReturnError('该账号不存在或已被清理');
|
|
}
|
|
if($model->status == 0){
|
|
continue;
|
|
}
|
|
|
|
$model->status = 0;
|
|
$model->updated_at = time();
|
|
if(!$model->save()){
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
}
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
//封禁
|
|
public function statusNo()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
foreach ($this->ids as $item){
|
|
$model = StoreUser::findOne([
|
|
'id' => $item,
|
|
'is_delete' => 0,
|
|
'status' => 0,
|
|
]);
|
|
if($model == null){
|
|
return Model::asReturnError('该账号不存在或已被清理');
|
|
}
|
|
if($model->status == 1){
|
|
continue;
|
|
}
|
|
$model->status = 1;
|
|
$model->updated_at = time();
|
|
if(!$model->save()){
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
}
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
//店长审核成功短信
|
|
public function actionStoreMakeSendYesSms()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$find = StoreMake::findOne([
|
|
'id' => $this->id,
|
|
]);
|
|
if(empty($find)){
|
|
return Model::asReturnError('暂无数据');
|
|
}
|
|
$find_user = User::findOne([
|
|
'id' => $find->id,
|
|
]);
|
|
$find_store = Store::findOne([
|
|
'id' => $find->store_id,
|
|
]);
|
|
// 发送短信
|
|
$sms_sender = new SmsMsgHelper($this->cx_mch_id);
|
|
$tpl_type = SmsTpl::getTplKey(1);
|
|
$date = date('Y-m-d 08:00:00',$find->make_time);
|
|
$end_date = date('Y-m-d 08:00:00',$find->make_time);
|
|
$sms_sender->sender($find_user->mobile_phone, $tpl_type, $find_user->mobile_prefix, $find_user->id,[
|
|
'store' => $find_store->name."[{$find_store->region}{$find_store->location_detail}]",
|
|
'date' => $date,
|
|
'msg' => "已预约成功,请在日期到达门店,兼职时长:{$date} - {$end_date} 联系电话:{$find_store->store_mobile}",
|
|
]);
|
|
// 变更状态
|
|
$find->is_send_sms = 1;
|
|
$find->save();
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
//店长审核失败短信
|
|
public function actionStoreMakeSendNoSms()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$find = StoreMake::findOne([
|
|
'id' => $this->id,
|
|
]);
|
|
if(empty($find)){
|
|
return Model::asReturnError('暂无数据');
|
|
}
|
|
// 发送短信
|
|
$find_user = User::findOne([
|
|
'id' => $find->id,
|
|
]);
|
|
$find_store = Store::findOne([
|
|
'id' => $find->store_id,
|
|
]);
|
|
// 发送短信
|
|
$sms_sender = new SmsMsgHelper($this->cx_mch_id);
|
|
$tpl_type = SmsTpl::getTplKey(1);
|
|
$date = date('Y-m-d 08:00:00',$find->make_time);
|
|
$sms_sender->sender($find_user->mobile_phone, $tpl_type, $find_user->mobile_prefix, $find_user->id,[
|
|
'store' => $find_store->name."[{$find_store->region}{$find_store->location_detail}]",
|
|
'date' => $date,
|
|
'msg' => "预约失败, 联系电话:{$find_store->store_mobile}",
|
|
]);
|
|
|
|
// 变更状态
|
|
$find->is_send_sms = 1;
|
|
$find->save();
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
|
|
} |