SettingController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace addons\ScoreExpansion\backend\controllers;
  3. use addons\ScoreExpansion\common\services\SettingService;
  4. use common\enums\AddonsEnum;
  5. use common\enums\StatusEnum;
  6. use common\models\user\UserLevel;
  7. use Yii;
  8. class SettingController extends BaseController
  9. {
  10. public $enableCsrfValidation = false;
  11. /**
  12. * 首页
  13. *
  14. * @return string
  15. */
  16. public function actionIndex()
  17. {
  18. $service = new SettingService(['mall_id' => $this->mall_id]);
  19. if (Yii::$app->request->isAjax) {
  20. if (Yii::$app->request->isPost) {
  21. $params = Yii::$app->request->post();
  22. $res = Yii::$app->services->validate->validate($params, [
  23. [
  24. [
  25. 'frozen_status', 'activation_num', 'activation_time', 'transfer_status', 'transfer_red_type',
  26. 'activation_method', 'change_activation_integral', 'parent_store_frozen_integral', 'parent_store_integral',
  27. 'store_frozen_integral', 'store_integral',
  28. ], 'safe',
  29. ],
  30. [
  31. [
  32. 'auth_status', 'transfer_percentage', 'transfer_out_status', 'transfer_out_type', 'transfer_out_mode',
  33. 'time_limit', 'buy_frozen_integral', 'buy_integral', 'parent_frozen_integral', 'parent_integral',
  34. ], 'safe',
  35. ],
  36. [
  37. [
  38. 'transfer_out_service', 'transfer_out_balance', 'transfer_out_red_packet', 'transfer_out_contribution',
  39. 'transfer_out_hi_bei', 'give_type', 'integral_name',
  40. ], 'safe',
  41. ],
  42. [
  43. [
  44. 'reward_period', 'reward_frozen_score', 'reward_person_count', 'loop_num', 'level_condition',
  45. 'gift_method', 'score_reward_invert_freeze_points', 'is_enable_buy_goods_give_frozen_score',
  46. 'inactive_dates',
  47. ], 'safe',
  48. ],
  49. ]);
  50. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  51. // 保存配置
  52. return $service->setSetting($params)
  53. ? $this->success('ok')
  54. : $this->error('保存失败', $service->getError());
  55. } else {
  56. return $this->success('获取成功', $service->getSetting());
  57. }
  58. }
  59. $levelList = UserLevel::getUserLevel([['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED]], [], true, 'level,name');
  60. array_unshift($levelList, ['level' => 0, 'name' => '普通会员']);
  61. return $this->render($this->action->id, ['levelList' => json_encode($levelList)]);
  62. }
  63. }