StarCrownLevelForm.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace common\models;
  3. use common\components\Model;
  4. use common\helpers\Form;
  5. use common\libs\logging\operate\AdminOperate;
  6. use common\models\DeclarationLevel;
  7. use common\models\StarCrownLevel;
  8. /**
  9. * Login form
  10. */
  11. class StarCrownLevelForm extends Model
  12. {
  13. public function init()
  14. {
  15. parent::init();
  16. $this->adminOperateLogger = new AdminOperate([
  17. 'fetchClass' => StarCrownLevel::class,
  18. ]);
  19. }
  20. /**
  21. * @inheritdoc
  22. */
  23. public function rules()
  24. {
  25. return [];
  26. }
  27. /**
  28. * 更新星级奖金
  29. * @return bool
  30. * @throws \yii\db\Exception
  31. */
  32. public function updateBonus()
  33. {
  34. $beforeData = StarCrownLevel::getBonusConfig();
  35. $this->adminOperateLogger->saveBeforeContent=$beforeData;
  36. $postData = \Yii::$app->request->post('data');
  37. $transaction = \Yii::$app->db->beginTransaction();
  38. try {
  39. foreach ($postData as $value) {
  40. $crownLevelModel = StarCrownLevel::findOne(['ID' => $value['ID']]);
  41. if ($crownLevelModel) {
  42. $crownLevelModel->TOURISM_PERCENT = $value['TOURISM_PERCENT'];
  43. $crownLevelModel->GARAGE_PERCENT = $value['GARAGE_PERCENT'];
  44. if (!$crownLevelModel->save()) {
  45. throw new \Exception(Form::formatErrorsForApi($crownLevelModel->getErrors()));
  46. }
  47. }
  48. }
  49. $transaction->commit();
  50. } catch (\Exception $e) {
  51. $transaction->rollBack();
  52. $this->addError('updateBonus', $e->getMessage());
  53. return null;
  54. }
  55. $afterData = StarCrownLevel::getBonusConfig();
  56. $this->adminOperateLogger->saveAfterContent = $afterData;
  57. unset($beforeData,$afterData);
  58. $this->adminOperateLogger->clean()->save([
  59. 'optType' => '更新星级奖金配置',
  60. ]);
  61. return true;
  62. }
  63. }