ConfigController.php 28 KB

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