UserDecForm.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace common\models\forms;
  3. use common\components\Model;
  4. use common\helpers\Date;
  5. use common\libs\logging\operate\AdminOperate;
  6. use common\models\User;
  7. use common\models\UserInfo;
  8. use yii\base\Exception;
  9. /**
  10. * Login form
  11. */
  12. class UserDecForm extends Model {
  13. public $userIds;
  14. public $isDec;
  15. public $isStudio;
  16. public $isAtlas;
  17. public $isRecharge;
  18. public function init() {
  19. parent::init();
  20. $this->adminOperateLogger = new AdminOperate([
  21. 'fetchClass' => User::class,
  22. ]);
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public function rules() {
  28. return [
  29. [['userIds', 'isDec','isStudio', 'isAtlas', 'isRecharge'], 'trim'],
  30. [['userIds'], 'required'],
  31. ];
  32. }
  33. /**
  34. * 指定校验场景
  35. * @return array
  36. */
  37. public function scenarios() {
  38. $parentScenarios = parent::scenarios();
  39. $customScenarios = [
  40. 'isDec' => ['userIds', 'isDec'],
  41. 'isAtlas' => ['userIds', 'isAtlas'],
  42. 'isStudio' => ['userIds', 'isStudio'],
  43. 'isRecharge' => ['userIds', 'isRecharge'],
  44. ];
  45. return array_merge($parentScenarios, $customScenarios);
  46. }
  47. public function attributeLabels() {
  48. return [
  49. 'userIds' => '会员ID',
  50. 'isDec' => '是否报单中心',
  51. 'isStudio' => '是否工作室',
  52. 'isAtlas' => '是否显示图谱',
  53. 'isRecharge' => '是否显示充值',
  54. ];
  55. }
  56. public function beforeValidate() {
  57. return parent::beforeValidate();
  58. }
  59. /**
  60. * 是否报单中心
  61. * @return null
  62. * @throws \yii\db\Exception
  63. */
  64. public function isDec() {
  65. if (!$this->validate()) {
  66. return null;
  67. }
  68. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->userIds, 'ID',['select'=>'ID,IS_DEC']);
  69. $db = \Yii::$app->db;
  70. $transaction = $db->beginTransaction();
  71. try {
  72. $allUidIn = implode("','", $this->userIds);
  73. if (!User::updateAll(['IS_DEC' => $this->isDec ? $this->isDec : 0], "ID IN ('" . $allUidIn . "')")) {
  74. throw new Exception('设置报单中心更新失败');
  75. }
  76. $transaction->commit();
  77. } catch (Exception $e) {
  78. $transaction->rollBack();
  79. return null;
  80. }
  81. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->userIds, 'ID',['select'=>'ID,IS_DEC']);
  82. $this->adminOperateLogger->setBatchField('USER_ID')->clean()->save([
  83. 'optType' => $this->isDec ? '设置报单中心' : '取消报单中心',
  84. ]);
  85. return $this->userIds;
  86. }
  87. /**
  88. * 是否工作室
  89. * @return null
  90. * @throws \yii\db\Exception
  91. */
  92. public function isStudio() {
  93. if (!$this->validate()) {
  94. return null;
  95. }
  96. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->userIds, 'ID',['select'=>'ID,IS_STUDIO']);
  97. $db = \Yii::$app->db;
  98. $transaction = $db->beginTransaction();
  99. try {
  100. $allUidIn = implode("','", $this->userIds);
  101. if (!User::updateAll(['IS_STUDIO' => $this->isStudio ? $this->isStudio : 0], "ID IN ('" . $allUidIn . "')")) {
  102. throw new Exception('设置工作室更新失败');
  103. }
  104. $transaction->commit();
  105. } catch (Exception $e) {
  106. $transaction->rollBack();
  107. return null;
  108. }
  109. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->userIds, 'ID',['select'=>'ID,IS_STUDIO']);
  110. $this->adminOperateLogger->setBatchField('USER_ID')->clean()->save([
  111. 'optType' => $this->isStudio ? '设置工作室' : '取消工作室',
  112. ]);
  113. return $this->userIds;
  114. }
  115. /**
  116. * 是否显示图谱
  117. * @return null
  118. * @throws \yii\db\Exception
  119. */
  120. public function isAtlas() {
  121. if (!$this->validate()) {
  122. return null;
  123. }
  124. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->userIds, 'ID',['select'=>'ID,IS_ATLAS']);
  125. $db = \Yii::$app->db;
  126. $transaction = $db->beginTransaction();
  127. try {
  128. $allUidIn = implode("','", $this->userIds);
  129. if (!User::updateAll(['IS_ATLAS' => $this->isAtlas ? $this->isAtlas : 0], "ID IN ('" . $allUidIn . "')")) {
  130. throw new Exception('设置图谱更新失败');
  131. }
  132. $transaction->commit();
  133. } catch (Exception $e) {
  134. $transaction->rollBack();
  135. throw new Exception('设置图谱更新失败');
  136. return null;
  137. }
  138. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->userIds, 'ID',['select'=>'ID,IS_ATLAS']);
  139. $this->adminOperateLogger->setBatchField('USER_ID')->clean()->save([
  140. 'optType' => $this->isAtlas ? '显示图谱' : '隐藏图谱',
  141. ]);
  142. return $this->userIds;
  143. }
  144. /**
  145. * 是否显示充值
  146. * @return null
  147. * @throws \yii\db\Exception
  148. */
  149. public function isRecharge() {
  150. if (!$this->validate()) {
  151. return null;
  152. }
  153. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->userIds, 'ID',['select'=>'ID,IS_RECHARGE']);
  154. $db = \Yii::$app->db;
  155. $transaction = $db->beginTransaction();
  156. try {
  157. $allUidIn = implode("','", $this->userIds);
  158. if (!User::updateAll(['IS_RECHARGE' => $this->isRecharge ? $this->isRecharge : 0], "ID IN ('" . $allUidIn . "')")) {
  159. throw new Exception('充值管理设置更新失败');
  160. }
  161. $transaction->commit();
  162. } catch (Exception $e) {
  163. $transaction->rollBack();
  164. return null;
  165. }
  166. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->userIds, 'ID',['select'=>'ID,IS_RECHARGE']);
  167. $this->adminOperateLogger->setBatchField('USER_ID')->clean()->save([
  168. 'optType' => $this->isRecharge ? '显示充值' : '隐藏充值',
  169. ]);
  170. return $this->userIds;
  171. }
  172. }