ConfigController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  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::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. $configs[$key]['TITLE'] = Yii::t('ctx', $config['LANGUAGE_KEY']);
  86. }
  87. return static::notice($configs);
  88. }
  89. /**
  90. * 奖金相关配置
  91. * @return mixed
  92. * @throws \yii\db\Exception
  93. * @throws \yii\web\HttpException
  94. */
  95. public function actionBonusOpt() {
  96. $configs = Config::find()->where("TYPE='bonus'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  97. foreach ($configs as $key => $config) {
  98. if ($config['OPTIONS']) {
  99. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  100. }
  101. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  102. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  103. }
  104. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SELECT_MULTIPLE) {
  105. $configs[$key]['VALUE'] = explode(',', $config['VALUE']);
  106. }
  107. if($config['INPUT_TYPE'] == Config::INPUT_TYPE_TABLE) {
  108. $configs[$key]['VALUE'] = Json::decode($config['VALUE']);
  109. }
  110. $configs[$key]['TITLE'] = Yii::t('ctx', $config['LANGUAGE_KEY']);
  111. }
  112. // 获取会员报单级别的相关参数
  113. $decLevel = Cache::getDecLevelConfig();
  114. // 获取会员聘级相关参数
  115. $empLevel = Cache::getEmpLevelConfig();
  116. $result = [
  117. 'config' => $configs,
  118. 'decLevel' => $decLevel,
  119. 'empLevel' => $empLevel,
  120. ];
  121. return static::notice($result);
  122. }
  123. /**
  124. * 基本奖金设置
  125. * @return mixed
  126. * @throws \yii\db\Exception
  127. * @throws \yii\web\HttpException
  128. */
  129. public function actionBonus() {
  130. $form = new ConfigForm();
  131. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  132. if ($form->updateBonus()) {
  133. Config::updateToCache();
  134. return static::notice(Yii::t('ctx', 'successfully'));
  135. } else {
  136. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  137. }
  138. }
  139. }
  140. /**
  141. * 修改会员级别相关的奖金配置
  142. * @return mixed
  143. * @throws \yii\db\Exception
  144. * @throws \yii\web\HttpException
  145. */
  146. public function actionBonusDecLevel() {
  147. $form = new DeclarationLevelForm();
  148. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  149. if ($form->updateBonus()) {
  150. DeclarationLevel::updateToCache();
  151. return static::notice(Yii::t('ctx', 'successfully'));
  152. } else {
  153. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  154. }
  155. }
  156. }
  157. /**
  158. * 修改奖金聘级相关的奖金配置
  159. * @return mixed
  160. * @throws \yii\db\Exception
  161. * @throws \yii\web\HttpException
  162. */
  163. public function actionBonusEmpLevel() {
  164. $form = new EmployLevelForm();
  165. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  166. if ($form->updateBonus()) {
  167. Cache::updateEmpLevelConfig();
  168. return static::notice(Yii::t('ctx', 'successfully'));
  169. } else {
  170. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  171. }
  172. }
  173. }
  174. /**
  175. * 修改会员星级相关的奖金配置
  176. * @return mixed
  177. * @throws \yii\db\Exception
  178. * @throws \yii\web\HttpException
  179. */
  180. public function actionBonusCrownLevel() {
  181. $form = new StarCrownLevelForm();
  182. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  183. if ($form->updateBonus()) {
  184. StarCrownLevel::updateToCache();
  185. return static::notice(Yii::t('ctx', 'successfully'));
  186. } else {
  187. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  188. }
  189. }
  190. }
  191. /**
  192. * 更新封期参数
  193. * @return mixed
  194. * @throws \yii\db\Exception
  195. * @throws \yii\web\HttpException
  196. */
  197. public function actionPeriod() {
  198. $form = new ConfigPeriodForm();
  199. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  200. if ($form->update()) {
  201. Config::updateToCache();
  202. // Log::adminHandle('更新封期参数', 1);
  203. return static::notice(Yii::t('ctx', 'successfully'));
  204. } else {
  205. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  206. }
  207. }
  208. // 获取priod的相关配置参数
  209. $configs = Config::find()->where("TYPE='period'")->indexBy('CONFIG_NAME')->orderBy('SORT ASC')->asArray()->all();
  210. foreach ($configs as $key => $config) {
  211. if ($config['OPTIONS']) {
  212. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  213. }
  214. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  215. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  216. }
  217. $configs[$key]['TITLE'] = Yii::t('ctx', $config['LANGUAGE_KEY']);
  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, Yii::t('ctx', 'successfully'), 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, Yii::t('ctx', 'successfully'), 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(Yii::t('ctx', 'successfully'));
  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. $form = new ConfigForm();
  352. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  353. if ($form->updateTransfer()) {
  354. Config::updateToCache();
  355. return static::notice(Yii::t('ctx', 'successfully'));
  356. } else {
  357. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  358. }
  359. }
  360. foreach ($configs as $key => $config) {
  361. if ($config['OPTIONS']) {
  362. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  363. }
  364. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  365. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  366. }
  367. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_TABLE) {
  368. $configs[$key]['VALUE'] = Json::decode($config['VALUE']);
  369. }
  370. $configs[$key]['TITLE'] = Yii::t('ctx', $config['LANGUAGE_KEY']);
  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. $form = new ConfigForm();
  384. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  385. if ($form->updateScore()) {
  386. Config::updateToCache();
  387. return static::notice(Yii::t('ctx', 'successfully'));
  388. } else {
  389. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  390. }
  391. }
  392. foreach ($configs as $key => $config) {
  393. if ($config['OPTIONS']) {
  394. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  395. }
  396. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  397. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  398. }
  399. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_TABLE) {
  400. $configs[$key]['VALUE'] = Json::decode($config['VALUE']);
  401. }
  402. $configs[$key]['TITLE'] = Yii::t('ctx', $config['LANGUAGE_KEY']);
  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. $form = new ConfigForm();
  416. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  417. if ($form->updateOther()) {
  418. Config::updateToCache();
  419. return static::notice(Yii::t('ctx', 'successfully'));
  420. } else {
  421. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  422. }
  423. }
  424. if (Yii::$app->request->post()) {
  425. $postData = Yii::$app->request->post();
  426. $transaction = Yii::$app->db->beginTransaction();
  427. try {
  428. foreach ($configs as $key => $value) {
  429. if (array_key_exists($key, $postData)) {
  430. if (!$postData[$key]) $postData[$key] = 0;
  431. Config::updateAll(['VALUE' => $postData[$key], 'UPDATED_AT' => Date::nowTime()], "CONFIG_NAME=:CONFIG_NAME", [':CONFIG_NAME' => $key]);
  432. }
  433. }
  434. Config::updateToCache();
  435. $transaction->commit();
  436. } catch (Exception $e) {
  437. $transaction->rollBack();
  438. return static::notice(Yii::t('ctx', 'failed'));
  439. }
  440. // Log::adminHandle('更新其他配置参数', 1);
  441. return static::notice(Yii::t('ctx', 'successfully'));
  442. }
  443. foreach ($configs as $key => $config) {
  444. if ($config['OPTIONS']) {
  445. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  446. }
  447. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  448. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  449. }
  450. $configs[$key]['TITLE'] = Yii::t('ctx', $config['LANGUAGE_KEY']);
  451. }
  452. return static::notice($configs);
  453. }
  454. /**
  455. * 查看报单级别
  456. * @return mixed
  457. * @throws \yii\web\HttpException
  458. */
  459. public function actionDecLevel() {
  460. $data = Cache::getDecLevelConfig();
  461. return static::notice(['list' => $data]);
  462. }
  463. public function actionMonthLimit() {
  464. if (Yii::$app->request->isPost) {
  465. $postData = Yii::$app->request->post();
  466. $month = $postData['month'];
  467. $ret = Config::updateAll(['VALUE' => $month, 'UPDATED_AT' => Date::nowTime()], "CONFIG_NAME=:CONFIG_NAME", [':CONFIG_NAME' => 'observePeriodLimit']);
  468. if ($ret) {
  469. return static::notice(Yii::t('ctx', 'successfully'));
  470. } else {
  471. return static::notice(Yii::t('ctx', 'failed'));
  472. }
  473. }
  474. $data = Config::find()
  475. ->where("CONFIG_NAME='observePeriodLimit'")
  476. ->asArray()
  477. ->one();
  478. $isSwitchUpgrade = Config::find()
  479. ->where("CONFIG_NAME='isOpenUpgrade'")
  480. ->asArray()
  481. ->one();
  482. return static::notice([
  483. 'observe' => $data,
  484. 'isOpenUpgrade' => $isSwitchUpgrade
  485. ]);
  486. }
  487. // 开关会员升级单功能
  488. public function actionOpenUpgrade() {
  489. if (Yii::$app->request->isPost) {
  490. $postData = Yii::$app->request->post();
  491. $isOpen = $postData['isOpen'];
  492. $ret = Config::updateAll(
  493. ['VALUE' => $isOpen, 'UPDATED_AT' => Date::nowTime()],
  494. "CONFIG_NAME=:CONFIG_NAME",
  495. [':CONFIG_NAME' => 'isOpenUpgrade']
  496. );
  497. if ($ret) {
  498. $msg = $isOpen == 1 ? Yii::t('ctx', 'on') : Yii::t('ctx', 'off');
  499. return static::notice(Yii::t('ctx', 'successfully'));
  500. } else {
  501. return static::notice(Yii::t('ctx', 'failed'));
  502. }
  503. }
  504. return static::notice(Yii::t('ctx', 'illegalRequest'), 405);
  505. }
  506. /**
  507. * 查看报单中心级别
  508. * @return mixed
  509. * @throws \yii\web\HttpException
  510. */
  511. public function actionDecRole() {
  512. $data = Cache::getDecRoleConfig();
  513. return static::notice(['list' => $data]);
  514. }
  515. /**
  516. * 修改报单中心级别
  517. * @return mixed
  518. * @throws \yii\web\HttpException
  519. */
  520. public function actionDecRoleEdit() {
  521. $id = Yii::$app->request->get('id');
  522. if (Yii::$app->request->isPost) {
  523. return static::edit(DecRoleForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  524. DecRole::updateToCache();
  525. });
  526. }
  527. $oneData = DecRole::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  528. return static::notice($oneData);
  529. }
  530. /**
  531. * 添加会员级别
  532. * @return mixed
  533. * @throws \yii\web\HttpException
  534. */
  535. public function actionDecLevelAdd() {
  536. if (Yii::$app->request->isPost) {
  537. return static::edit(DecLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  538. DeclarationLevel::updateToCache();
  539. // Log::adminHandle('添加会员级别', 1);
  540. });
  541. }
  542. return static::notice(Yii::t('ctx', 'illegalRequest'), 405);
  543. }
  544. /**
  545. * 修改会员级别
  546. * @return mixed
  547. * @throws \yii\web\HttpException
  548. */
  549. public function actionDecLevelEdit() {
  550. $id = Yii::$app->request->get('id');
  551. if (Yii::$app->request->isPost) {
  552. return static::edit(DecLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  553. DeclarationLevel::updateToCache();
  554. // Log::adminHandle('编辑报单级别参数', 1);
  555. });
  556. }
  557. $oneData = DeclarationLevel::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  558. return static::notice($oneData);
  559. }
  560. /**
  561. * 删除会员级别
  562. * @return mixed
  563. * @throws \yii\db\Exception
  564. * @throws \yii\web\HttpException
  565. */
  566. public function actionDecLevelDelete() {
  567. return static::delete(DeclarationLevel::class, '', function ($selected) {
  568. DeclarationLevel::updateToCache();
  569. // Log::adminHandle('删除报单级别', 1);
  570. });
  571. }
  572. /**
  573. * 查看会员聘级
  574. * @return mixed
  575. * @throws \yii\web\HttpException
  576. */
  577. public function actionEmpLevel() {
  578. $data = EmployLevel::lists('', [], [
  579. 'select' => 'E.*, ME.LEVEL_NAME AS MIN_EMPLOY_LEVEL_NAME',
  580. 'from' => EmployLevel::tableName() . ' AS E',
  581. 'join' => [
  582. ['LEFT JOIN', EmployLevel::tableName() . ' AS ME', 'ME.ID=E.MIN_EMPLOY_LEVEL']
  583. ],
  584. 'orderBy' => 'E.SORT ASC, E.CREATED_AT ASC'
  585. ]);
  586. return static::notice($data);
  587. }
  588. /**
  589. * 添加会员聘级
  590. * @return mixed
  591. * @throws \yii\web\HttpException
  592. */
  593. public function actionEmpLevelAdd() {
  594. if (Yii::$app->request->isPost) {
  595. return static::edit(EmployLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  596. EmployLevel::updateToCache();
  597. // Log::adminHandle('添加会员聘级', 1);
  598. });
  599. }
  600. // 获取所有聘级,以供选择
  601. $allLevel = EmployLevel::find()->where('1=1')->orderBy('SORT ASC')->asArray()->all();
  602. return static::notice($allLevel);
  603. }
  604. /**
  605. * 修改聘级
  606. * @return mixed
  607. * @throws \yii\web\HttpException
  608. */
  609. public function actionEmpLevelEdit() {
  610. $id = Yii::$app->request->get('id');
  611. if (Yii::$app->request->isPost) {
  612. return static::edit(EmployLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  613. EmployLevel::updateToCache();
  614. // Log::adminHandle('编辑会员聘级', 1);
  615. });
  616. }
  617. $oneData = EmployLevel::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  618. // 获取所有聘级,以供选择
  619. $allLevel = EmployLevel::find()->where('1=1')->orderBy('SORT ASC')->asArray()->all();
  620. $oneData['allLevel'] = $allLevel;
  621. return static::notice($oneData);
  622. }
  623. /**
  624. * 删除聘级
  625. * @return mixed
  626. * @throws \yii\db\Exception
  627. * @throws \yii\web\HttpException
  628. */
  629. public function actionEmpLevelDelete() {
  630. return static::delete(EmployLevel::class, '', function ($selected) {
  631. EmployLevel::updateToCache();
  632. // Log::adminHandle('删除会员聘级', 1);
  633. });
  634. }
  635. /**
  636. * 查看短信模板
  637. * @return mixed
  638. * @throws \yii\web\HttpException
  639. */
  640. public function actionSmsTemplate() {
  641. $data = SmsTemplate::lists('', [], ['orderBy' => 'CREATED_AT ASC']);
  642. return static::notice($data);
  643. }
  644. /**
  645. * 编辑短信模板
  646. * @return mixed
  647. * @throws \yii\web\HttpException
  648. */
  649. public function actionSmsTemplateEdit() {
  650. $id = Yii::$app->request->get('id');
  651. if (Yii::$app->request->isPost) {
  652. return parent::edit(SmsTemplateForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  653. SmsTemplate::updateDecToCache();
  654. SmsTemplate::updateEmpToCache();
  655. // Log::adminHandle('编辑短信模板', 1);
  656. });
  657. }
  658. $oneData = SmsTemplate::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  659. return static::notice(['oneData' => $oneData]);
  660. }
  661. /**
  662. * 提现金额等级
  663. * @return mixed
  664. * @throws \yii\web\HttpException
  665. */
  666. public function actionWithdrawLevel() {
  667. $data = WithdrawLevel::lists('', [], ['orderBy' => 'MIN_AMOUNT ASC']);
  668. return static::notice($data);
  669. }
  670. /**
  671. * 添加提现金额等级
  672. * @return mixed
  673. * @throws \yii\web\HttpException
  674. */
  675. public function actionWithdrawLevelAdd() {
  676. if (Yii::$app->request->isPost) {
  677. return static::edit(WithdrawLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  678. WithdrawLevel::updateToCache();
  679. // Log::adminHandle('添加提现金额等级', 1);
  680. });
  681. }
  682. }
  683. /**
  684. * 修改提现金额等级
  685. * @return mixed
  686. * @throws \yii\web\HttpException
  687. */
  688. public function actionWithdrawLevelEdit() {
  689. $id = Yii::$app->request->get('id');
  690. if (Yii::$app->request->isPost) {
  691. return static::edit(WithdrawLevelForm::class, Yii::t('ctx', 'successfully'), null, null, null, function () {
  692. WithdrawLevel::updateToCache();
  693. // Log::adminHandle('编辑提现金额等级', 1);
  694. });
  695. }
  696. $oneData = WithdrawLevel::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  697. return static::notice($oneData);
  698. }
  699. /**
  700. * 删除提现金额等级
  701. * @return mixed
  702. * @throws \yii\db\Exception
  703. * @throws \yii\web\HttpException
  704. */
  705. public function actionWithdrawLevelDelete() {
  706. return static::delete(WithdrawLevel::class, '', function ($selected) {
  707. WithdrawLevel::updateToCache();
  708. });
  709. }
  710. /**
  711. * 注册类型
  712. * @return mixed
  713. * @throws \yii\web\HttpException
  714. */
  715. public function actionRegType() {
  716. $data = RegType::lists('', [], [
  717. 'orderBy' => 'SORT ASC, CREATED_AT ASC'
  718. ]);
  719. return static::notice($data);
  720. }
  721. /**
  722. * 获取注册类型
  723. * @return mixed
  724. * @throws \yii\web\HttpException
  725. */
  726. public function actionRegTypeGet() {
  727. $id = Yii::$app->request->get('id');
  728. $regType = RegType::findOneAsArray('ID=:ID', [':ID' => $id]);
  729. if (!$regType) {
  730. return static::notice(Yii::t('ctx', 'dataNotExists'), 400);
  731. }
  732. 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']]);
  733. }
  734. /**
  735. * 修改注册类型
  736. * @return mixed
  737. * @throws \yii\web\HttpException
  738. */
  739. public function actionRegTypeEdit() {
  740. $id = Yii::$app->request->get('id');
  741. if (Yii::$app->request->isPost) {
  742. $formModel = new RegTypeForm();
  743. $formModel->scenario = 'edit';
  744. $formModel->id = $id;
  745. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  746. // Log::adminHandle('修改注册类型,ID为:' . $result['ID']);
  747. return static::notice(Yii::t('ctx', 'successfully'));
  748. } else {
  749. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  750. }
  751. }
  752. return static::notice(Yii::t('ctx', 'illegalRequest'), 405);
  753. }
  754. /**
  755. * 获取服务协议
  756. * @return mixed
  757. * @throws \yii\web\HttpException
  758. */
  759. public function actionPactGet() {
  760. $path = \Yii::getAlias('@common/runtime/datas/pact.php');
  761. if (!file_exists($path)) {
  762. $oneData = '';
  763. } else {
  764. $oneData = include $path;
  765. }
  766. return static::notice($oneData);
  767. }
  768. /**
  769. * 获取服务协议
  770. * @return mixed
  771. * @throws \yii\base\InvalidConfigException
  772. * @throws \yii\web\HttpException
  773. */
  774. public function actionPactEdit() {
  775. $path = \Yii::getAlias('@common/runtime/datas/pact.php');
  776. $post = Yii::$app->request->post();
  777. if (!isset($post['CONTENT']) || empty($post['CONTENT'])) {
  778. return static::notice('请输入协议内容', 400);
  779. }
  780. $now = Date::nowTime();
  781. $data = [
  782. 'UPDATED_AT' => $now,
  783. 'CONTENT' => addslashes($post['CONTENT']),
  784. 'ADM_NAME' => \Yii::$app->user->id,
  785. ];
  786. // Log::adminHandle('更新服务协议');
  787. $date = \Yii::$app->formatter->asDatetime($now);
  788. $content = "<?php" . PHP_EOL . "/**
  789. * 配置文件
  790. * @date {$date}
  791. */" . PHP_EOL;
  792. $content .= "return ";
  793. $content .= var_export($data, true);
  794. $content .= ";";
  795. file_put_contents($path, $content, LOCK_EX);
  796. return static::notice(Yii::t('ctx', 'successfully'));
  797. }
  798. }