UserTransferPropForm.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace common\models\forms;
  3. use common\helpers\Cache;
  4. use common\helpers\Date;
  5. use common\components\Model;
  6. use common\helpers\Form;
  7. use common\helpers\user\Balance;
  8. use common\helpers\user\Info;
  9. use common\helpers\user\Status;
  10. use common\libs\logging\operate\AdminOperate;
  11. use common\models\PerfPeriod;
  12. use common\models\Period;
  13. use common\models\UserWallet;
  14. use common\models\User;
  15. use common\models\UserClose;
  16. use common\models\UserInfo;
  17. use common\models\UserPerf;
  18. use common\models\UserStatusAudit;
  19. use common\models\Withdraw;
  20. use yii\base\Exception;
  21. /**
  22. * Login form
  23. */
  24. class UserTransferPropForm extends Model {
  25. public $userIds;
  26. public $allowTransfer;
  27. public $transferProp;
  28. public $remark;
  29. public function init() {
  30. parent::init();
  31. $this->adminOperateLogger = new AdminOperate([
  32. 'fetchClass' => UserInfo::class,
  33. ]);
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function rules() {
  39. return [
  40. [['userIds', 'transferProp', 'allowTransfer', 'remark'], 'trim'],
  41. [['transferProp', 'userIds'], 'required']
  42. ];
  43. }
  44. /**
  45. * 指定校验场景
  46. * @return array
  47. */
  48. public function scenarios() {
  49. $parentScenarios = parent::scenarios();
  50. $customScenarios = [
  51. 'change' => ['userIds', 'transferProp', 'allowTransfer', 'remark'],
  52. ];
  53. return array_merge($parentScenarios, $customScenarios);
  54. }
  55. public function attributeLabels() {
  56. return [
  57. 'userIds' => '会员ID',
  58. 'transferProp' => '转账比例',
  59. ];
  60. }
  61. /**
  62. * 调整比例
  63. * @return null
  64. * @throws \yii\db\Exception
  65. */
  66. public function change() {
  67. if (!$this->validate()) {
  68. return null;
  69. }
  70. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->userIds, 'USER_ID',['select'=>'USER_ID,ALLOW_TRANSFER,TRANSFER_PROP']);
  71. $db = \Yii::$app->db;
  72. $transaction = $db->beginTransaction();
  73. try {
  74. $allUidIn = implode("','", $this->userIds);
  75. if(!UserInfo::updateAll(['ALLOW_TRANSFER'=>$this->allowTransfer?$this->allowTransfer:0,'TRANSFER_PROP' => $this->transferProp], "USER_ID IN ('" . $allUidIn . "')")){
  76. throw new Exception('调整会员转账/提现比例失败');
  77. }
  78. $transaction->commit();
  79. } catch (Exception $e) {
  80. $transaction->rollBack();
  81. return null;
  82. }
  83. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->userIds, 'USER_ID',['select'=>'USER_ID,ALLOW_TRANSFER,TRANSFER_PROP']);
  84. $this->adminOperateLogger->setBatchField('USER_ID')->clean()->save([
  85. 'optType' => '调整会员转账/提现比例',
  86. 'remark' => $this->remark,
  87. ]);
  88. return $this->userIds;
  89. }
  90. }