| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- namespace common\models\forms;
- use common\components\Model;
- use common\helpers\Date;
- use common\libs\logging\operate\AdminOperate;
- use common\models\User;
- use common\models\UserInfo;
- use yii\base\Exception;
- /**
- * Login form
- */
- class UserDecForm extends Model {
- public $userIds;
- public $isDec;
- public $isStudio;
- public $isAtlas;
- public $isRecharge;
- public function init() {
- parent::init();
- $this->adminOperateLogger = new AdminOperate([
- 'fetchClass' => User::class,
- ]);
- }
- /**
- * @inheritdoc
- */
- public function rules() {
- return [
- [['userIds', 'isDec','isStudio', 'isAtlas', 'isRecharge'], 'trim'],
- [['userIds'], 'required'],
- ];
- }
- /**
- * 指定校验场景
- * @return array
- */
- public function scenarios() {
- $parentScenarios = parent::scenarios();
- $customScenarios = [
- 'isDec' => ['userIds', 'isDec'],
- 'isAtlas' => ['userIds', 'isAtlas'],
- 'isStudio' => ['userIds', 'isStudio'],
- 'isRecharge' => ['userIds', 'isRecharge'],
- ];
- return array_merge($parentScenarios, $customScenarios);
- }
- public function attributeLabels() {
- return [
- 'userIds' => '会员ID',
- 'isDec' => '是否报单中心',
- 'isStudio' => '是否工作室',
- 'isAtlas' => '是否显示图谱',
- 'isRecharge' => '是否显示充值',
- ];
- }
- public function beforeValidate() {
- return parent::beforeValidate();
- }
- /**
- * 是否报单中心
- * @return null
- * @throws \yii\db\Exception
- */
- public function isDec() {
- if (!$this->validate()) {
- return null;
- }
- $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->userIds, 'ID',['select'=>'ID,IS_DEC']);
- $db = \Yii::$app->db;
- $transaction = $db->beginTransaction();
- try {
- $allUidIn = implode("','", $this->userIds);
- if (!User::updateAll(['IS_DEC' => $this->isDec ? $this->isDec : 0], "ID IN ('" . $allUidIn . "')")) {
- throw new Exception('设置报单中心更新失败');
- }
- $transaction->commit();
- } catch (Exception $e) {
- $transaction->rollBack();
- return null;
- }
- $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->userIds, 'ID',['select'=>'ID,IS_DEC']);
- $this->adminOperateLogger->setBatchField('USER_ID')->clean()->save([
- 'optType' => $this->isDec ? '设置报单中心' : '取消报单中心',
- ]);
- return $this->userIds;
- }
- /**
- * 是否工作室
- * @return null
- * @throws \yii\db\Exception
- */
- public function isStudio() {
- if (!$this->validate()) {
- return null;
- }
- $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->userIds, 'ID',['select'=>'ID,IS_STUDIO']);
- $db = \Yii::$app->db;
- $transaction = $db->beginTransaction();
- try {
- $allUidIn = implode("','", $this->userIds);
- if (!User::updateAll(['IS_STUDIO' => $this->isStudio ? $this->isStudio : 0], "ID IN ('" . $allUidIn . "')")) {
- throw new Exception('设置工作室更新失败');
- }
- $transaction->commit();
- } catch (Exception $e) {
- $transaction->rollBack();
- return null;
- }
- $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->userIds, 'ID',['select'=>'ID,IS_STUDIO']);
- $this->adminOperateLogger->setBatchField('USER_ID')->clean()->save([
- 'optType' => $this->isStudio ? '设置工作室' : '取消工作室',
- ]);
- return $this->userIds;
- }
- /**
- * 是否显示图谱
- * @return null
- * @throws \yii\db\Exception
- */
- public function isAtlas() {
- if (!$this->validate()) {
- return null;
- }
- $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->userIds, 'ID',['select'=>'ID,IS_ATLAS']);
- $db = \Yii::$app->db;
- $transaction = $db->beginTransaction();
- try {
- $allUidIn = implode("','", $this->userIds);
- if (!User::updateAll(['IS_ATLAS' => $this->isAtlas ? $this->isAtlas : 0], "ID IN ('" . $allUidIn . "')")) {
- throw new Exception('设置图谱更新失败');
- }
- $transaction->commit();
- } catch (Exception $e) {
- $transaction->rollBack();
- return null;
- }
- $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->userIds, 'ID',['select'=>'ID,IS_ATLAS']);
- $this->adminOperateLogger->setBatchField('USER_ID')->clean()->save([
- 'optType' => $this->isAtlas ? '显示图谱' : '隐藏图谱',
- ]);
- return $this->userIds;
- }
- /**
- * 是否显示充值
- * @return null
- * @throws \yii\db\Exception
- */
- public function isRecharge() {
- if (!$this->validate()) {
- return null;
- }
- $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->userIds, 'ID',['select'=>'ID,IS_RECHARGE']);
- $db = \Yii::$app->db;
- $transaction = $db->beginTransaction();
- try {
- $allUidIn = implode("','", $this->userIds);
- if (!User::updateAll(['IS_RECHARGE' => $this->isRecharge ? $this->isRecharge : 0], "ID IN ('" . $allUidIn . "')")) {
- throw new Exception('充值管理设置更新失败');
- }
- $transaction->commit();
- } catch (Exception $e) {
- $transaction->rollBack();
- return null;
- }
- $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->userIds, 'ID',['select'=>'ID,IS_RECHARGE']);
- $this->adminOperateLogger->setBatchField('USER_ID')->clean()->save([
- 'optType' => $this->isRecharge ? '显示充值' : '隐藏充值',
- ]);
- return $this->userIds;
- }
- }
|