ConfigController.php 30 KB

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