ConfigController.php 28 KB

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