249 lines
7.5 KiB
PHP
249 lines
7.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\models\coach;
|
|
use app\components\EncryptHelper;
|
|
use app\models\Coach;
|
|
use app\models\CoachReview;
|
|
use app\models\common\CommonUserEditForm;
|
|
use app\models\Model;
|
|
use app\models\User;
|
|
use app\modules\admin\models\AdminModel;
|
|
|
|
class CoachActionForm 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 = Coach::findOne(['id' => $item,'is_delete' => 0]);
|
|
if($model == null){
|
|
$t->rollBack();
|
|
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,
|
|
'is_delete' => 0
|
|
]);
|
|
if($user != null){
|
|
$user->is_delete = 1;
|
|
if(!$user->save()){
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($user);
|
|
}
|
|
}
|
|
}
|
|
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
|
|
}
|
|
|
|
public function untie()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
foreach ($this->ids as $item){
|
|
$model = Coach::findOne(['id' => $item,'is_delete' => 0]);
|
|
if($model == null){
|
|
$t->rollBack();
|
|
return Model::asReturnError('该教练不存在或已被清理');
|
|
}
|
|
if($model->store_id == 0){
|
|
continue;
|
|
}
|
|
$model->store_id = 0;
|
|
$model->updated_at = time();
|
|
if(!$model->save()){
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
}
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
//提交至总部审核
|
|
public function review_status()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
foreach ($this->ids as $item){
|
|
$model = CoachReview::findOne(['id' => $item,'is_delete' => 0,'status_review' => 0]);
|
|
if($model == null){
|
|
return Model::asReturnError('该教练不存在或已被清理');
|
|
}
|
|
if($model->status_review == 1){
|
|
continue;
|
|
}
|
|
$model->status_review = 1;
|
|
$model->updated_at = time();
|
|
if(!$model->save()){
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
}
|
|
return Model::asReturnSuccess('操作成功');
|
|
|
|
}
|
|
|
|
|
|
//通过审核
|
|
public function review_yes()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
foreach ($this->ids as $item){
|
|
$model = CoachReview::findOne(['id' => $item,'is_delete' => 0,'status_review' => 1]);
|
|
if($model == null){
|
|
$t->rollBack();
|
|
return Model::asReturnError('该教练不存在或已被清理');
|
|
}
|
|
if($model->status_review == 2){
|
|
continue;
|
|
}
|
|
$model->status_review = 2;
|
|
$model->updated_at = time();
|
|
$model->status_time = time();
|
|
if(!$model->save()){
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
$user = User::findOne(['id'=>$model->user_id]);
|
|
if(empty($user)){
|
|
$t->rollBack();
|
|
return Model::asReturnError('教练用户不存在');
|
|
}
|
|
$form = new CoachEditForm();
|
|
$form->name = $user->real_name;
|
|
$form->mobile_phone = EncryptHelper::decryptMobilePhone($user->mobile_phone);
|
|
$form->coach_phone = $model->mobile_phone;
|
|
$form->coache_begin_time = date('Y-m-d',$model->coache_begin_time);
|
|
$form->title = $model->title;
|
|
$form->content = $model->content;
|
|
$form->coach_photo = $model->coach_photo;
|
|
$form->store_id = $model->store_id;
|
|
$form->number = $model->number;
|
|
$form->status = $model->status;
|
|
$form->qualification = $model->qualification;
|
|
$form->desc = $model->desc;
|
|
$form->model = new Coach();
|
|
$data = $form->edit();
|
|
if($data['code'] != 0){
|
|
$t->rollBack();
|
|
return Model::asReturnError($data['msg']);
|
|
}
|
|
}
|
|
$t->commit();
|
|
return $this->apiReturnSuccess('保存成功');
|
|
|
|
}
|
|
|
|
//驳回审核
|
|
public function review_no()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
foreach ($this->ids as $item){
|
|
$model = CoachReview::findOne(['id' => $item,'is_delete' => 0,'status_review' => 1]);
|
|
if($model == null){
|
|
return Model::asReturnError('该教练不存在或已被清理');
|
|
}
|
|
if($model->status_review == 3){
|
|
continue;
|
|
}
|
|
$model->status_review = 3;
|
|
$model->updated_at = time();
|
|
$model->status_time = time();
|
|
if(!$model->save()){
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
}
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
//教练申请删除
|
|
public function review_delete()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
foreach ($this->ids as $item){
|
|
$model = CoachReview::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,
|
|
'is_delete' => 0
|
|
]);
|
|
if($user != null){
|
|
$user->is_delete = 1;
|
|
if(!$user->save()){
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($user);
|
|
}
|
|
}
|
|
}
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
} |