ConfigController.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace backendApi\modules\v1\controllers;
  9. use backendApi\modules\v1\models\Admin;
  10. use common\helpers\Cache;
  11. use common\helpers\Date;
  12. use common\helpers\Form;
  13. use common\helpers\Log;
  14. use common\helpers\Tool;
  15. use common\models\CalcBonus;
  16. use common\models\DecRole;
  17. use common\models\forms\ClearDataForm;
  18. use common\models\forms\ConfigBonusForm;
  19. use common\models\forms\ConfigForm;
  20. use common\models\forms\ConfigPeriodForm;
  21. use common\models\forms\DecLevelForm;
  22. use common\models\forms\DecRoleForm;
  23. use common\models\forms\RegTypeForm;
  24. use common\models\forms\DeclarationLevelForm;
  25. use common\models\forms\EmployLevelForm;
  26. use common\models\FlowBonus;
  27. use common\models\forms\OcrApiForm;
  28. use common\models\forms\SmsApiForm;
  29. use common\models\forms\SmsTemplateForm;
  30. use common\models\StarCrownLevelForm;
  31. use common\models\forms\WithdrawLevelForm;
  32. use common\models\OcrApi;
  33. use common\models\PerfCompany;
  34. use common\models\PerfMonth;
  35. use common\models\Period;
  36. use common\models\ReconsumePool;
  37. use common\models\RegType;
  38. use common\models\DeclarationLevel;
  39. use common\models\EmployLevel;
  40. use common\models\SmsApi;
  41. use common\models\SmsTemplate;
  42. use common\models\StarCrownLevel;
  43. use common\models\UserBonus;
  44. use common\models\UserClose;
  45. use common\models\UserInfo;
  46. use common\models\UserNetwork;
  47. use common\models\UserRelation;
  48. use common\models\WithdrawLevel;
  49. use Yii;
  50. use common\models\Config;
  51. use yii\base\Exception;
  52. use yii\helpers\Json;
  53. class ConfigController extends BaseController {
  54. public $modelClass = Config::class;
  55. public function behaviors() {
  56. $behaviors = parent::behaviors();
  57. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  58. return $behaviors;
  59. }
  60. /**
  61. * 站点设置
  62. * @return mixed
  63. * @throws \yii\db\Exception
  64. * @throws \yii\web\HttpException
  65. */
  66. public function actionBase() {
  67. // 获取priod的相关配置参数
  68. $configs = Config::actionBaseConfig(); //Config::find()->where("TYPE='base'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  69. $form = new ConfigForm();
  70. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  71. if ($form->updateBase()) {
  72. Config::updateToCache();
  73. return static::notice(Yii::t('ctx', 'successfully'));
  74. } else {
  75. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  76. }
  77. }
  78. foreach ($configs as $key => $config) {
  79. if ($config['OPTIONS']) {
  80. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  81. }
  82. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  83. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  84. }
  85. }
  86. return static::notice($configs);
  87. }
  88. /**
  89. * 奖金相关配置
  90. * @return mixed
  91. * @throws \yii\db\Exception
  92. * @throws \yii\web\HttpException
  93. */
  94. public function actionBonusOpt() {
  95. $configs = Config::actionBonusOpt();//Config::find()->where("TYPE='bonus'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  96. foreach ($configs as $key => $config) {
  97. if ($config['OPTIONS']) {
  98. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  99. }
  100. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  101. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  102. }
  103. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SELECT_MULTIPLE) {
  104. $configs[$key]['VALUE'] = explode(',', $config['VALUE']);
  105. }
  106. if($config['INPUT_TYPE'] == Config::INPUT_TYPE_TABLE) {
  107. $configs[$key]['VALUE'] = Json::decode($config['VALUE']);
  108. }
  109. }
  110. // 获取会员报单级别的相关参数
  111. $decLevel = DeclarationLevel::configGetDeclarationLevelOrderBySort();//DeclarationLevel::find()->orderBy('SORT ASC')->asArray()->all();
  112. // 获取会员聘级相关参数
  113. $empLevel = EmployLevel::getAllDataWithNumIndex();
  114. // 获取会员星级相关参数
  115. $crownLevel = StarCrownLevel::getAllDataWithNumIndex();
  116. $result = [
  117. 'config' => $configs,
  118. 'decLevel' => $decLevel,
  119. 'empLevel' => $empLevel,
  120. 'crownLevel' => $crownLevel,
  121. ];
  122. return static::notice($result);
  123. }
  124. /**
  125. * 基本奖金设置
  126. * @return mixed
  127. * @throws \yii\db\Exception
  128. * @throws \yii\web\HttpException
  129. */
  130. public function actionBonus() {
  131. $form = new ConfigForm();
  132. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  133. if ($form->updateBonus()) {
  134. Config::updateToCache();
  135. return static::notice(Yii::t('ctx', 'successfully'));
  136. } else {
  137. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  138. }
  139. }
  140. }
  141. /**
  142. * 修改会员级别相关的奖金配置
  143. * @return mixed
  144. * @throws \yii\db\Exception
  145. * @throws \yii\web\HttpException
  146. */
  147. public function actionBonusDecLevel() {
  148. $form = new DeclarationLevelForm();
  149. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  150. if ($form->updateBonus()) {
  151. DeclarationLevel::updateToCache();
  152. return static::notice(Yii::t('ctx', 'successfully'));
  153. } else {
  154. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  155. }
  156. }
  157. }
  158. /**
  159. * 修改奖金聘级相关的奖金配置
  160. * @return mixed
  161. * @throws \yii\db\Exception
  162. * @throws \yii\web\HttpException
  163. */
  164. public function actionBonusEmpLevel() {
  165. $form = new EmployLevelForm();
  166. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  167. if ($form->updateBonus()) {
  168. Cache::updateEmpLevelConfig();
  169. return static::notice(Yii::t('ctx', 'successfully'));
  170. } else {
  171. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  172. }
  173. }
  174. }
  175. /**
  176. * 修改会员星级相关的奖金配置
  177. * @return mixed
  178. * @throws \yii\db\Exception
  179. * @throws \yii\web\HttpException
  180. */
  181. public function actionBonusCrownLevel() {
  182. $form = new StarCrownLevelForm();
  183. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  184. if ($form->updateBonus()) {
  185. StarCrownLevel::updateToCache();
  186. return static::notice(Yii::t('ctx', 'successfully'));
  187. } else {
  188. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  189. }
  190. }
  191. }
  192. /**
  193. * 更新封期参数
  194. * @return mixed
  195. * @throws \yii\db\Exception
  196. * @throws \yii\web\HttpException
  197. */
  198. public function actionPeriod() {
  199. $form = new ConfigPeriodForm();
  200. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  201. if ($form->update()) {
  202. Config::updateToCache();
  203. // Log::adminHandle('更新封期参数', 1);
  204. return static::notice('期数已开始更新');
  205. } else {
  206. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  207. }
  208. }
  209. // 获取priod的相关配置参数
  210. $configs = Config::find()->where("TYPE='period'")->indexBy('CONFIG_NAME')->orderBy('SORT ASC')->asArray()->all();
  211. foreach ($configs as $key => $config) {
  212. if ($config['OPTIONS']) {
  213. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  214. }
  215. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  216. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  217. }
  218. }
  219. return static::notice($configs);
  220. }
  221. /**
  222. * 接口设置
  223. * @return mixed
  224. * @throws \yii\web\HttpException
  225. */
  226. public function actionApiOpt(){
  227. return static::notice('1');
  228. }
  229. /**
  230. * 查看OcrApi接口
  231. * @return mixed
  232. * @throws \yii\web\HttpException
  233. */
  234. public function actionOcrApi() {
  235. $condition = '';
  236. $params = [];
  237. $data = OcrApi::lists($condition, $params, [
  238. 'select' => 'OA.*,ADMC.ADMIN_NAME CREATE_ADMIN_NAME,ADMU.ADMIN_NAME UPDATE_ADMIN_NAME',
  239. 'from' => OcrApi::tableName() . ' AS OA',
  240. 'join' => [
  241. ['LEFT JOIN', Admin::tableName() . ' AS ADMC', 'ADMC.ID=OA.CREATE_ADMIN'],
  242. ['LEFT JOIN', Admin::tableName() . ' AS ADMU', 'ADMU.ID=OA.UPDATE_ADMIN'],
  243. ],
  244. 'orderBy' => 'OA.CREATED_AT ASC',
  245. ]);
  246. return static::notice($data);
  247. }
  248. /**
  249. * 修改OcrApi接口
  250. * @return mixed
  251. * @throws \yii\web\HttpException
  252. */
  253. public function actionOcrApiEdit() {
  254. $id = Yii::$app->request->get('id');
  255. if (Yii::$app->request->isPost) {
  256. return static::edit(OcrApiForm::class, 'OcrApi配置成功', null, null, null, function () {
  257. OcrApi::updateToCache();
  258. // Log::adminHandle('编辑OCRAPI参数配置', 1);
  259. });
  260. }
  261. $oneData = OcrApi::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  262. if ($oneData['CONFIG']) {
  263. $oneData['CONFIG'] = Json::decode($oneData['CONFIG']);
  264. }
  265. // 获取可供编辑的字段
  266. $oneData['apiType'] = '百度OCR';
  267. $oneData['CONFIGS'] = \common\helpers\ocr\OcrApi::apiConfigs($oneData['API_NAME']);
  268. return static::notice($oneData);
  269. }
  270. /**
  271. * 短信接口查看
  272. * @return mixed
  273. * @throws \yii\web\HttpException
  274. */
  275. public function actionSmsApi() {
  276. $condition = '';
  277. $params = [];
  278. $data = SmsApi::lists($condition, $params, [
  279. 'select' => 'OA.*,ADMC.ADMIN_NAME CREATE_ADMIN_NAME,ADMU.ADMIN_NAME UPDATE_ADMIN_NAME',
  280. 'from' => SmsApi::tableName() . ' AS OA',
  281. 'join' => [
  282. ['LEFT JOIN', Admin::tableName() . ' AS ADMC', 'ADMC.ID=OA.CREATE_ADMIN'],
  283. ['LEFT JOIN', Admin::tableName() . ' AS ADMU', 'ADMU.ID=OA.UPDATE_ADMIN'],
  284. ],
  285. 'orderBy' => 'OA.CREATED_AT ASC',
  286. ]);
  287. return static::notice($data);
  288. }
  289. /**
  290. * 短信接口编辑
  291. * @return mixed
  292. * @throws \yii\web\HttpException
  293. */
  294. public function actionSmsApiEdit() {
  295. $id = Yii::$app->request->get('id');
  296. if (Yii::$app->request->isPost) {
  297. return static::edit(SmsApiForm::class, 'SmsApi配置成功', null, null, null, function () {
  298. SmsApi::updateToCache();
  299. // Log::adminHandle('编辑SMSAPI参数配置', 1);
  300. });
  301. }
  302. $oneData = SmsApi::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  303. if ($oneData['CONFIG']) {
  304. $oneData['CONFIG'] = Json::decode($oneData['CONFIG']);
  305. }
  306. $oneData['apiType'] = '短信接口';
  307. // 获取可供编辑的字段
  308. $oneData['CONFIGS'] = \common\libs\api\sms\SmsApi::apiConfigs($oneData['API_NAME']);
  309. return static::notice($oneData);
  310. }
  311. /**
  312. * 短信配置
  313. * @return mixed
  314. * @throws \yii\db\Exception
  315. * @throws \yii\web\HttpException
  316. */
  317. public function actionSms() {
  318. // 获取priod的相关配置参数
  319. $configs = Config::find()->where("TYPE='sms'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  320. $form = new ConfigForm();
  321. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  322. if ($form->updateSms()) {
  323. Config::updateToCache();
  324. return static::notice('更新短信配置成功');
  325. } else {
  326. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  327. }
  328. }
  329. foreach ($configs as $key => $config) {
  330. if ($config['OPTIONS']) {
  331. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  332. }
  333. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  334. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  335. }
  336. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SELECT) {
  337. $configs[$key]['VALUE'] = explode(",",$config['VALUE']);
  338. }
  339. }
  340. return static::notice($configs);
  341. }
  342. /**
  343. * 转账配置
  344. * @return mixed
  345. * @throws \yii\db\Exception
  346. * @throws \yii\web\HttpException
  347. */
  348. public function actionTransfer() {
  349. // 获取priod的相关配置参数
  350. $configs = Config::find()->where("TYPE='transfer'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  351. $configs = Tool::convertLanguage($configs, 'TITLE');
  352. $form = new ConfigForm();
  353. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  354. if ($form->updateTransfer()) {
  355. Config::updateToCache();
  356. return static::notice(Yii::t('ctx', 'successfully'));
  357. } else {
  358. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  359. }
  360. }
  361. foreach ($configs as $key => $config) {
  362. if ($config['OPTIONS']) {
  363. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  364. }
  365. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  366. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  367. }
  368. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_TABLE) {
  369. $configs[$key]['VALUE'] = Json::decode($config['VALUE']);
  370. }
  371. }
  372. return static::notice($configs);
  373. }
  374. /**
  375. * 分数配置
  376. * @return mixed
  377. * @throws \yii\db\Exception
  378. * @throws \yii\web\HttpException
  379. */
  380. public function actionScore() {
  381. // 获取priod的相关配置参数
  382. $configs = Config::find()->where("TYPE='score'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  383. $configs = Tool::convertLanguage($configs, 'TITLE');
  384. $form = new ConfigForm();
  385. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  386. if ($form->updateScore()) {
  387. Config::updateToCache();
  388. return static::notice('更新分数配置成功');
  389. } else {
  390. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  391. }
  392. }
  393. foreach ($configs as $key => $config) {
  394. if ($config['OPTIONS']) {
  395. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  396. }
  397. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  398. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  399. }
  400. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_TABLE) {
  401. $configs[$key]['VALUE'] = Json::decode($config['VALUE']);
  402. }
  403. }
  404. return static::notice($configs);
  405. }
  406. /**
  407. * 其他配置
  408. * @return mixed
  409. * @throws \yii\db\Exception
  410. * @throws \yii\web\HttpException
  411. */
  412. public function actionOther() {
  413. // 获取priod的相关配置参数
  414. $configs = Config::find()->where("TYPE='other'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  415. $configs = Tool::convertLanguage($configs, 'TITLE');
  416. $form = new ConfigForm();
  417. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  418. if ($form->updateOther()) {
  419. Config::updateToCache();
  420. return static::notice(Yii::t('ctx', 'successfully'));
  421. } else {
  422. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  423. }
  424. }
  425. if (Yii::$app->request->post()) {
  426. $postData = Yii::$app->request->post();
  427. $transaction = Yii::$app->db->beginTransaction();
  428. try {
  429. foreach ($configs as $key => $value) {
  430. if (array_key_exists($key, $postData)) {
  431. if (!$postData[$key]) $postData[$key] = 0;
  432. Config::updateAll(['VALUE' => $postData[$key], 'UPDATED_AT' => Date::nowTime()], "CONFIG_NAME=:CONFIG_NAME", [':CONFIG_NAME' => $key]);
  433. }
  434. }
  435. Config::updateToCache();
  436. $transaction->commit();
  437. } catch (Exception $e) {
  438. $transaction->rollBack();
  439. return static::notice('配置更新失败,请重试');
  440. }
  441. // Log::adminHandle('更新其他配置参数', 1);
  442. return static::notice('配置更新成功');
  443. }
  444. foreach ($configs as $key => $config) {
  445. if ($config['OPTIONS']) {
  446. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  447. }
  448. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  449. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  450. }
  451. }
  452. return static::notice($configs);
  453. }
  454. /**
  455. * 查看报单级别
  456. * @return mixed
  457. * @throws \yii\web\HttpException
  458. */
  459. public function actionDecLevel() {
  460. $data = DeclarationLevel::lists('', [], [
  461. 'orderBy' => 'SORT ASC, CREATED_AT ASC'
  462. ]);
  463. if (!empty($data['list'])) {
  464. foreach ($data['list'] as &$v) {
  465. if (isset($v['LANGUAGE_KEY']) && !empty($v['LANGUAGE_KEY'])) {
  466. $v['TITLE'] = \Yii::t('ctx', $v['LANGUAGE_KEY']);
  467. }
  468. }
  469. }
  470. return static::notice($data);
  471. }
  472. public function actionMonthLimit() {
  473. if (Yii::$app->request->isPost) {
  474. $postData = Yii::$app->request->post();
  475. $month = $postData['month'];
  476. $ret = Config::updateAll(['VALUE' => $month, 'UPDATED_AT' => Date::nowTime()], "CONFIG_NAME=:CONFIG_NAME", [':CONFIG_NAME' => 'observePeriodLimit']);
  477. if ($ret) {
  478. return static::notice('更新观察期成功');
  479. } else {
  480. return static::notice('更新观察期失败,请重试');
  481. }
  482. }
  483. $data = Config::find()
  484. ->where("CONFIG_NAME='observePeriodLimit'")
  485. ->asArray()
  486. ->one();
  487. if (!empty($data) && isset($data['LANGUAGE_KEY']) && !empty($data['LANGUAGE_KEY'])) {
  488. $data['TITLE'] = \Yii::t('ctx', $data['LANGUAGE_KEY']);
  489. }
  490. $isSwitchUpgrade = Config::find()
  491. ->where("CONFIG_NAME='isOpenUpgrade'")
  492. ->asArray()
  493. ->one();
  494. if (!empty($isSwitchUpgrade) && isset($isSwitchUpgrade['LANGUAGE_KEY']) && !empty($isSwitchUpgrade['LANGUAGE_KEY'])) {
  495. $isSwitchUpgrade['TITLE'] = \Yii::t('ctx', $isSwitchUpgrade['LANGUAGE_KEY']);
  496. }
  497. return static::notice([
  498. 'observe' => $data,
  499. 'isOpenUpgrade' => $isSwitchUpgrade
  500. ]);
  501. }
  502. // 开关会员升级单功能
  503. public function actionOpenUpgrade() {
  504. if (Yii::$app->request->isPost) {
  505. $postData = Yii::$app->request->post();
  506. $isOpen = $postData['isOpen'];
  507. $ret = Config::updateAll(
  508. ['VALUE' => $isOpen, 'UPDATED_AT' => Date::nowTime()],
  509. "CONFIG_NAME=:CONFIG_NAME",
  510. [':CONFIG_NAME' => 'isOpenUpgrade']
  511. );
  512. if ($ret) {
  513. $msg = $isOpen == 1 ? '开启' : '关闭';
  514. return static::notice("$msg,操作成功");
  515. } else {
  516. return static::notice('操作失败,请重试');
  517. }
  518. }
  519. return static::notice(Yii::t('ctx', 'illegalRequest'), 405);
  520. }
  521. /**
  522. * 查看报单中心级别
  523. * @return mixed
  524. * @throws \yii\web\HttpException
  525. */
  526. public function actionDecRole() {
  527. $data = DecRole::lists('', [], [
  528. 'orderBy' => 'SORT ASC'
  529. ]);
  530. if (!empty($data['list'])) {
  531. foreach ($data['list'] as &$v) {
  532. if (isset($v['LANGUAGE_KEY']) && !empty($v['LANGUAGE_KEY'])) {
  533. $v['ROLE_NAME'] = \Yii::t('ctx', $v['LANGUAGE_KEY']);
  534. }
  535. }
  536. }
  537. return static::notice($data);
  538. }
  539. /**
  540. * 修改报单中心级别
  541. * @return mixed
  542. * @throws \yii\web\HttpException
  543. */
  544. public function actionDecRoleEdit() {
  545. $id = Yii::$app->request->get('id');
  546. if (Yii::$app->request->isPost) {
  547. return static::edit(DecRoleForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  548. DecRole::updateToCache();
  549. });
  550. }
  551. $oneData = DecRole::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  552. return static::notice($oneData);
  553. }
  554. /**
  555. * 添加会员级别
  556. * @return mixed
  557. * @throws \yii\web\HttpException
  558. */
  559. public function actionDecLevelAdd() {
  560. if (Yii::$app->request->isPost) {
  561. return static::edit(DecLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  562. DeclarationLevel::updateToCache();
  563. // Log::adminHandle('添加会员级别', 1);
  564. });
  565. }
  566. return static::notice(Yii::t('ctx', 'illegalRequest'), 405);
  567. }
  568. /**
  569. * 修改会员级别
  570. * @return mixed
  571. * @throws \yii\web\HttpException
  572. */
  573. public function actionDecLevelEdit() {
  574. $id = Yii::$app->request->get('id');
  575. if (Yii::$app->request->isPost) {
  576. return static::edit(DecLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  577. DeclarationLevel::updateToCache();
  578. // Log::adminHandle('编辑报单级别参数', 1);
  579. });
  580. }
  581. $oneData = DeclarationLevel::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  582. return static::notice($oneData);
  583. }
  584. /**
  585. * 删除会员级别
  586. * @return mixed
  587. * @throws \yii\db\Exception
  588. * @throws \yii\web\HttpException
  589. */
  590. public function actionDecLevelDelete() {
  591. return static::delete(DeclarationLevel::class, '', function ($selected) {
  592. DeclarationLevel::updateToCache();
  593. // Log::adminHandle('删除报单级别', 1);
  594. });
  595. }
  596. /**
  597. * 查看会员聘级
  598. * @return mixed
  599. * @throws \yii\web\HttpException
  600. */
  601. public function actionEmpLevel() {
  602. $data = EmployLevel::lists('', [], [
  603. 'select' => 'E.*, ME.LEVEL_NAME AS MIN_EMPLOY_LEVEL_NAME',
  604. 'from' => EmployLevel::tableName() . ' AS E',
  605. 'join' => [
  606. ['LEFT JOIN', EmployLevel::tableName() . ' AS ME', 'ME.ID=E.MIN_EMPLOY_LEVEL']
  607. ],
  608. 'orderBy' => 'E.SORT ASC, E.CREATED_AT ASC'
  609. ]);
  610. return static::notice($data);
  611. }
  612. /**
  613. * 添加会员聘级
  614. * @return mixed
  615. * @throws \yii\web\HttpException
  616. */
  617. public function actionEmpLevelAdd() {
  618. if (Yii::$app->request->isPost) {
  619. return static::edit(EmployLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  620. EmployLevel::updateToCache();
  621. // Log::adminHandle('添加会员聘级', 1);
  622. });
  623. }
  624. // 获取所有聘级,以供选择
  625. $allLevel = EmployLevel::find()->where('1=1')->orderBy('SORT ASC')->asArray()->all();
  626. return static::notice($allLevel);
  627. }
  628. /**
  629. * 修改聘级
  630. * @return mixed
  631. * @throws \yii\web\HttpException
  632. */
  633. public function actionEmpLevelEdit() {
  634. $id = Yii::$app->request->get('id');
  635. if (Yii::$app->request->isPost) {
  636. return static::edit(EmployLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  637. EmployLevel::updateToCache();
  638. // Log::adminHandle('编辑会员聘级', 1);
  639. });
  640. }
  641. $oneData = EmployLevel::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  642. // 获取所有聘级,以供选择
  643. $allLevel = EmployLevel::find()->where('1=1')->orderBy('SORT ASC')->asArray()->all();
  644. $oneData['allLevel'] = $allLevel;
  645. return static::notice($oneData);
  646. }
  647. /**
  648. * 删除聘级
  649. * @return mixed
  650. * @throws \yii\db\Exception
  651. * @throws \yii\web\HttpException
  652. */
  653. public function actionEmpLevelDelete() {
  654. return static::delete(EmployLevel::class, '', function ($selected) {
  655. EmployLevel::updateToCache();
  656. // Log::adminHandle('删除会员聘级', 1);
  657. });
  658. }
  659. /**
  660. * 查看短信模板
  661. * @return mixed
  662. * @throws \yii\web\HttpException
  663. */
  664. public function actionSmsTemplate() {
  665. $data = SmsTemplate::lists('', [], ['orderBy' => 'CREATED_AT ASC']);
  666. return static::notice($data);
  667. }
  668. /**
  669. * 编辑短信模板
  670. * @return mixed
  671. * @throws \yii\web\HttpException
  672. */
  673. public function actionSmsTemplateEdit() {
  674. $id = Yii::$app->request->get('id');
  675. if (Yii::$app->request->isPost) {
  676. return parent::edit(SmsTemplateForm::class, '短信模板编辑成功', null, null, null, function () {
  677. SmsTemplate::updateDecToCache();
  678. SmsTemplate::updateEmpToCache();
  679. // Log::adminHandle('编辑短信模板', 1);
  680. });
  681. }
  682. $oneData = SmsTemplate::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  683. return static::notice(['oneData' => $oneData]);
  684. }
  685. /**
  686. * 提现金额等级
  687. * @return mixed
  688. * @throws \yii\web\HttpException
  689. */
  690. public function actionWithdrawLevel() {
  691. $data = WithdrawLevel::lists('', [], ['orderBy' => 'MIN_AMOUNT ASC']);
  692. return static::notice($data);
  693. }
  694. /**
  695. * 添加提现金额等级
  696. * @return mixed
  697. * @throws \yii\web\HttpException
  698. */
  699. public function actionWithdrawLevelAdd() {
  700. if (Yii::$app->request->isPost) {
  701. return static::edit(WithdrawLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  702. WithdrawLevel::updateToCache();
  703. // Log::adminHandle('添加提现金额等级', 1);
  704. });
  705. }
  706. }
  707. /**
  708. * 修改提现金额等级
  709. * @return mixed
  710. * @throws \yii\web\HttpException
  711. */
  712. public function actionWithdrawLevelEdit() {
  713. $id = Yii::$app->request->get('id');
  714. if (Yii::$app->request->isPost) {
  715. return static::edit(WithdrawLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  716. WithdrawLevel::updateToCache();
  717. // Log::adminHandle('编辑提现金额等级', 1);
  718. });
  719. }
  720. $oneData = WithdrawLevel::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  721. return static::notice($oneData);
  722. }
  723. /**
  724. * 删除提现金额等级
  725. * @return mixed
  726. * @throws \yii\db\Exception
  727. * @throws \yii\web\HttpException
  728. */
  729. public function actionWithdrawLevelDelete() {
  730. return static::delete(WithdrawLevel::class, '', function ($selected) {
  731. WithdrawLevel::updateToCache();
  732. });
  733. }
  734. /**
  735. * 注册类型
  736. * @return mixed
  737. * @throws \yii\web\HttpException
  738. */
  739. public function actionRegType() {
  740. $data = RegType::lists('', [], [
  741. 'orderBy' => 'SORT ASC, CREATED_AT ASC'
  742. ]);
  743. return static::notice($data);
  744. }
  745. /**
  746. * 获取注册类型
  747. * @return mixed
  748. * @throws \yii\web\HttpException
  749. */
  750. public function actionRegTypeGet() {
  751. $id = Yii::$app->request->get('id');
  752. $regType = RegType::findOneAsArray('ID=:ID', [':ID' => $id]);
  753. if (!$regType) {
  754. return static::notice(Yii::t('ctx', 'dataNotExists'), 400);
  755. }
  756. return static::notice(['id' => $regType['ID'], 'typeName' => $regType['TYPE_NAME'], 'isPact' => $regType['IS_PACT'], 'monthAmount' => $regType['MONTH_LIMIT_AMOUNT'], 'yearAmount' => $regType['YEAR_LIMIT_AMOUNT'], 'remark' => $regType['REMARK']]);
  757. }
  758. /**
  759. * 修改注册类型
  760. * @return mixed
  761. * @throws \yii\web\HttpException
  762. */
  763. public function actionRegTypeEdit() {
  764. $id = Yii::$app->request->get('id');
  765. if (Yii::$app->request->isPost) {
  766. $formModel = new RegTypeForm();
  767. $formModel->scenario = 'edit';
  768. $formModel->id = $id;
  769. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  770. // Log::adminHandle('修改注册类型,ID为:' . $result['ID']);
  771. return static::notice(Yii::t('ctx', 'successfully'));
  772. } else {
  773. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  774. }
  775. }
  776. return static::notice(Yii::t('ctx', 'illegalRequest'), 405);
  777. }
  778. /**
  779. * 获取服务协议
  780. * @return mixed
  781. * @throws \yii\web\HttpException
  782. */
  783. public function actionPactGet() {
  784. $path = \Yii::getAlias('@common/runtime/datas/pact.php');
  785. if (!file_exists($path)) {
  786. $oneData = '';
  787. } else {
  788. $oneData = include $path;
  789. }
  790. return static::notice($oneData);
  791. }
  792. /**
  793. * 获取服务协议
  794. * @return mixed
  795. * @throws \yii\base\InvalidConfigException
  796. * @throws \yii\web\HttpException
  797. */
  798. public function actionPactEdit() {
  799. $path = \Yii::getAlias('@common/runtime/datas/pact.php');
  800. $post = Yii::$app->request->post();
  801. if (!isset($post['CONTENT']) || empty($post['CONTENT'])) {
  802. return static::notice('请输入协议内容', 400);
  803. }
  804. $now = Date::nowTime();
  805. $data = [
  806. 'UPDATED_AT' => $now,
  807. 'CONTENT' => addslashes($post['CONTENT']),
  808. 'ADM_NAME' => \Yii::$app->user->id,
  809. ];
  810. // Log::adminHandle('更新服务协议');
  811. $date = \Yii::$app->formatter->asDatetime($now);
  812. $content = "<?php" . PHP_EOL . "/**
  813. * 配置文件
  814. * @date {$date}
  815. */" . PHP_EOL;
  816. $content .= "return ";
  817. $content .= var_export($data, true);
  818. $content .= ";";
  819. file_put_contents($path, $content, LOCK_EX);
  820. return static::notice('更新服务协议成功');
  821. }
  822. /**
  823. * 汇率配置.
  824. * @return mixed
  825. * @throws \yii\db\Exception
  826. * @throws \yii\web\HttpException
  827. */
  828. public function actionExchangeRate() {
  829. $post = Yii::$app->request->post();
  830. unset($post['synchronize']);
  831. $form = new ConfigForm();
  832. if (\Yii::$app->request->isPost && $form->load($post, '')) {
  833. if ($form->updateExchangeRate()) {
  834. Config::updateToCache();
  835. return static::notice(Yii::t('ctx', 'successfully'));
  836. } else {
  837. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  838. }
  839. }
  840. $oneData = Config::find()->where('CONFIG_NAME=:CONFIG_NAME', [':CONFIG_NAME' => 'exchangeRate'])->asArray()->one();
  841. $oneData = Tool::convertLanguage($oneData, 'TITLE');
  842. return static::notice($oneData);
  843. }
  844. }