ConfigController.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  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 backendApi\modules\v1\models\User;
  11. use common\components\Redis;
  12. use common\helpers\Cache;
  13. use common\helpers\Date;
  14. use common\helpers\Form;
  15. use common\helpers\Log;
  16. use common\helpers\Tool;
  17. use common\models\CalcBonus;
  18. use common\models\DecRole;
  19. use common\models\forms\ClearDataForm;
  20. use common\models\forms\ConfigBonusForm;
  21. use common\models\forms\ConfigForm;
  22. use common\models\forms\ConfigPeriodForm;
  23. use common\models\forms\DecLevelForm;
  24. use common\models\forms\DecRoleForm;
  25. use common\models\forms\RegTypeForm;
  26. use common\models\forms\DeclarationLevelForm;
  27. use common\models\forms\EmployLevelForm;
  28. use common\models\FlowBonus;
  29. use common\models\forms\OcrApiForm;
  30. use common\models\forms\SmsApiForm;
  31. use common\models\forms\SmsTemplateForm;
  32. use common\models\forms\WithdrawLevelForm;
  33. use common\models\OcrApi;
  34. use common\models\PerfCompany;
  35. use common\models\PerfMonth;
  36. use common\models\Period;
  37. use common\models\ReconsumePool;
  38. use common\models\RegType;
  39. use common\models\DeclarationLevel;
  40. use common\models\EmployLevel;
  41. use common\models\SmsApi;
  42. use common\models\SmsTemplate;
  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\BaiduRegion;
  49. use common\models\Region;
  50. use common\models\WithdrawLevel;
  51. use Yii;
  52. use common\models\Config;
  53. use yii\base\Exception;
  54. use yii\helpers\Json;
  55. class ConfigController extends BaseController {
  56. public $modelClass = Config::class;
  57. public function behaviors() {
  58. $behaviors = parent::behaviors();
  59. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  60. return $behaviors;
  61. }
  62. /**
  63. * 站点设置
  64. * @return mixed
  65. * @throws \yii\db\Exception
  66. * @throws \yii\web\HttpException
  67. */
  68. public function actionBase() {
  69. // 获取priod的相关配置参数
  70. $configs = Config::find()->where("TYPE='base'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  71. $form = new ConfigForm();
  72. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  73. if ($form->updateBase()) {
  74. Config::updateToCache();
  75. return static::notice('更新站点设置成功');
  76. } else {
  77. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  78. }
  79. }
  80. foreach ($configs as $key => $config) {
  81. if ($config['OPTIONS']) {
  82. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  83. }
  84. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  85. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  86. }
  87. }
  88. return static::notice($configs);
  89. }
  90. /**
  91. * 奖金相关配置
  92. * @return mixed
  93. * @throws \yii\db\Exception
  94. * @throws \yii\web\HttpException
  95. */
  96. public function actionBonusOpt() {
  97. $configs = Config::find()->where("TYPE='bonus'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  98. foreach ($configs as $key => $config) {
  99. if ($config['OPTIONS']) {
  100. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  101. }
  102. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  103. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  104. }
  105. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SELECT_MULTIPLE) {
  106. $configs[$key]['VALUE'] = explode(',', $config['VALUE']);
  107. }
  108. if($config['INPUT_TYPE'] == Config::INPUT_TYPE_TABLE) {
  109. $configs[$key]['VALUE'] = Json::decode($config['VALUE']);
  110. }
  111. }
  112. // 获取会员报单级别的相关参数
  113. $decLevel = DeclarationLevel::find()->orderBy('SORT ASC')->asArray()->all();
  114. // 获取会员聘级相关参数
  115. // $empLevel = EmployLevel::getAllDataWithNumIndex();
  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('更新奖金配置成功');
  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('更新级别奖金配置成功');
  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('更新聘级奖金配置成功');
  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 actionPeriod() {
  181. $form = new ConfigPeriodForm();
  182. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  183. if ($form->update()) {
  184. Config::updateToCache();
  185. // Log::adminHandle('更新封期参数', 1);
  186. return static::notice('期数已开始更新');
  187. } else {
  188. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  189. }
  190. }
  191. // 获取priod的相关配置参数
  192. $configs = Config::find()->where("TYPE='period'")->indexBy('CONFIG_NAME')->orderBy('SORT ASC')->asArray()->all();
  193. foreach ($configs as $key => $config) {
  194. if ($config['OPTIONS']) {
  195. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  196. }
  197. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  198. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  199. }
  200. }
  201. return static::notice($configs);
  202. }
  203. /**
  204. * 接口设置
  205. * @return mixed
  206. * @throws \yii\web\HttpException
  207. */
  208. public function actionApiOpt(){
  209. return static::notice('1');
  210. }
  211. /**
  212. * 查看OcrApi接口
  213. * @return mixed
  214. * @throws \yii\web\HttpException
  215. */
  216. public function actionOcrApi() {
  217. $condition = '';
  218. $params = [];
  219. $data = OcrApi::lists($condition, $params, [
  220. 'select' => 'OA.*,ADMC.ADMIN_NAME CREATE_ADMIN_NAME,ADMU.ADMIN_NAME UPDATE_ADMIN_NAME',
  221. 'from' => OcrApi::tableName() . ' AS OA',
  222. 'join' => [
  223. ['LEFT JOIN', Admin::tableName() . ' AS ADMC', 'ADMC.ID=OA.CREATE_ADMIN'],
  224. ['LEFT JOIN', Admin::tableName() . ' AS ADMU', 'ADMU.ID=OA.UPDATE_ADMIN'],
  225. ],
  226. 'orderBy' => 'OA.CREATED_AT ASC',
  227. ]);
  228. return static::notice($data);
  229. }
  230. /**
  231. * 修改OcrApi接口
  232. * @return mixed
  233. * @throws \yii\web\HttpException
  234. */
  235. public function actionOcrApiEdit() {
  236. $id = Yii::$app->request->get('id');
  237. if (Yii::$app->request->isPost) {
  238. return static::edit(OcrApiForm::class, 'OcrApi配置成功', null, null, null, function () {
  239. OcrApi::updateToCache();
  240. // Log::adminHandle('编辑OCRAPI参数配置', 1);
  241. });
  242. }
  243. $oneData = OcrApi::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  244. if ($oneData['CONFIG']) {
  245. $oneData['CONFIG'] = Json::decode($oneData['CONFIG']);
  246. }
  247. // 获取可供编辑的字段
  248. $oneData['apiType'] = '百度OCR';
  249. $oneData['CONFIGS'] = \common\helpers\ocr\OcrApi::apiConfigs($oneData['API_NAME']);
  250. return static::notice($oneData);
  251. }
  252. /**
  253. * 短信接口查看
  254. * @return mixed
  255. * @throws \yii\web\HttpException
  256. */
  257. public function actionSmsApi() {
  258. $condition = '';
  259. $params = [];
  260. $data = SmsApi::lists($condition, $params, [
  261. 'select' => 'OA.*,ADMC.ADMIN_NAME CREATE_ADMIN_NAME,ADMU.ADMIN_NAME UPDATE_ADMIN_NAME',
  262. 'from' => SmsApi::tableName() . ' AS OA',
  263. 'join' => [
  264. ['LEFT JOIN', Admin::tableName() . ' AS ADMC', 'ADMC.ID=OA.CREATE_ADMIN'],
  265. ['LEFT JOIN', Admin::tableName() . ' AS ADMU', 'ADMU.ID=OA.UPDATE_ADMIN'],
  266. ],
  267. 'orderBy' => 'OA.CREATED_AT ASC',
  268. ]);
  269. return static::notice($data);
  270. }
  271. /**
  272. * 短信接口编辑
  273. * @return mixed
  274. * @throws \yii\web\HttpException
  275. */
  276. public function actionSmsApiEdit() {
  277. $id = Yii::$app->request->get('id');
  278. if (Yii::$app->request->isPost) {
  279. return static::edit(SmsApiForm::class, 'SmsApi配置成功', null, null, null, function () {
  280. SmsApi::updateToCache();
  281. // Log::adminHandle('编辑SMSAPI参数配置', 1);
  282. });
  283. }
  284. $oneData = SmsApi::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  285. if ($oneData['CONFIG']) {
  286. $oneData['CONFIG'] = Json::decode($oneData['CONFIG']);
  287. }
  288. $oneData['apiType'] = '短信接口';
  289. // 获取可供编辑的字段
  290. $oneData['CONFIGS'] = \common\libs\api\sms\SmsApi::apiConfigs($oneData['API_NAME']);
  291. return static::notice($oneData);
  292. }
  293. /**
  294. * 短信配置
  295. * @return mixed
  296. * @throws \yii\db\Exception
  297. * @throws \yii\web\HttpException
  298. */
  299. public function actionSms() {
  300. // 获取priod的相关配置参数
  301. $configs = Config::find()->where("TYPE='sms'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  302. $form = new ConfigForm();
  303. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  304. if ($form->updateSms()) {
  305. Config::updateToCache();
  306. return static::notice('更新短信配置成功');
  307. } else {
  308. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  309. }
  310. }
  311. foreach ($configs as $key => $config) {
  312. if ($config['OPTIONS']) {
  313. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  314. }
  315. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  316. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  317. }
  318. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SELECT) {
  319. $configs[$key]['VALUE'] = explode(",",$config['VALUE']);
  320. }
  321. }
  322. return static::notice($configs);
  323. }
  324. /**
  325. * 转账配置
  326. * @return mixed
  327. * @throws \yii\db\Exception
  328. * @throws \yii\web\HttpException
  329. */
  330. public function actionTransfer() {
  331. // 获取priod的相关配置参数
  332. $configs = Config::find()->where("TYPE='transfer'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  333. $form = new ConfigForm();
  334. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  335. if ($form->updateTransfer()) {
  336. Config::updateToCache();
  337. return static::notice('更新转账配置成功');
  338. } else {
  339. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  340. }
  341. }
  342. foreach ($configs as $key => $config) {
  343. if ($config['OPTIONS']) {
  344. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  345. }
  346. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  347. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  348. }
  349. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_TABLE) {
  350. $configs[$key]['VALUE'] = Json::decode($config['VALUE']);
  351. }
  352. }
  353. return static::notice($configs);
  354. }
  355. /**
  356. * 分数配置
  357. * @return mixed
  358. * @throws \yii\db\Exception
  359. * @throws \yii\web\HttpException
  360. */
  361. public function actionScore() {
  362. // 获取priod的相关配置参数
  363. $configs = Config::find()->where("TYPE='score'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  364. $form = new ConfigForm();
  365. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  366. if ($form->updateScore()) {
  367. Config::updateToCache();
  368. return static::notice('更新分数配置成功');
  369. } else {
  370. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  371. }
  372. }
  373. foreach ($configs as $key => $config) {
  374. if ($config['OPTIONS']) {
  375. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  376. }
  377. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  378. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  379. }
  380. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_TABLE) {
  381. $configs[$key]['VALUE'] = Json::decode($config['VALUE']);
  382. }
  383. }
  384. return static::notice($configs);
  385. }
  386. /**
  387. * 其他配置
  388. * @return mixed
  389. * @throws \yii\db\Exception
  390. * @throws \yii\web\HttpException
  391. */
  392. public function actionOther() {
  393. // 获取priod的相关配置参数
  394. $configs = Config::find()->where("TYPE='other'")->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
  395. $form = new ConfigForm();
  396. if (Yii::$app->request->post() && $form->load(Yii::$app->request->post(), '')) {
  397. if ($form->updateOther()) {
  398. Config::updateToCache();
  399. return static::notice('更新其他配置成功');
  400. } else {
  401. return static::notice(Form::formatErrorsForApi($form->getErrors()), 422);
  402. }
  403. }
  404. if (Yii::$app->request->post()) {
  405. $postData = Yii::$app->request->post();
  406. $transaction = Yii::$app->db->beginTransaction();
  407. try {
  408. foreach ($configs as $key => $value) {
  409. if (array_key_exists($key, $postData)) {
  410. if (!$postData[$key]) $postData[$key] = 0;
  411. Config::updateAll(['VALUE' => $postData[$key], 'UPDATED_AT' => Date::nowTime()], "CONFIG_NAME=:CONFIG_NAME", [':CONFIG_NAME' => $key]);
  412. }
  413. }
  414. Config::updateToCache();
  415. $transaction->commit();
  416. } catch (Exception $e) {
  417. $transaction->rollBack();
  418. return static::notice('配置更新失败,请重试');
  419. }
  420. // Log::adminHandle('更新其他配置参数', 1);
  421. return static::notice('配置更新成功');
  422. }
  423. foreach ($configs as $key => $config) {
  424. if ($config['OPTIONS']) {
  425. $configs[$key]['OPTIONS'] = Json::decode($config['OPTIONS']);
  426. }
  427. if ($config['INPUT_TYPE'] == Config::INPUT_TYPE_SWITCH) {
  428. $configs[$key]['VALUE'] = boolval($config['VALUE']);
  429. }
  430. }
  431. return static::notice($configs);
  432. }
  433. /**
  434. * 查看报单级别
  435. * @return mixed
  436. * @throws \yii\web\HttpException
  437. */
  438. public function actionDecLevel() {
  439. $data = DeclarationLevel::lists('', [], [
  440. 'orderBy' => 'SORT ASC, CREATED_AT ASC'
  441. ]);
  442. return static::notice($data);
  443. }
  444. public function actionMonthLimit() {
  445. if (Yii::$app->request->isPost) {
  446. $postData = Yii::$app->request->post();
  447. $month = $postData['month'];
  448. $ret = Config::updateAll(['VALUE' => $month, 'UPDATED_AT' => Date::nowTime()], "CONFIG_NAME=:CONFIG_NAME", [':CONFIG_NAME' => 'observePeriodLimit']);
  449. if ($ret) {
  450. return static::notice('更新观察期成功');
  451. } else {
  452. return static::notice('更新观察期失败,请重试');
  453. }
  454. }
  455. $data = Config::find()
  456. ->where("CONFIG_NAME='observePeriodLimit'")
  457. ->asArray()
  458. ->one();
  459. $isSwitchUpgrade = Config::find()
  460. ->where("CONFIG_NAME='isOpenUpgrade'")
  461. ->asArray()
  462. ->one();
  463. return static::notice([
  464. 'observe' => $data,
  465. 'isOpenUpgrade' => $isSwitchUpgrade
  466. ]);
  467. }
  468. // 开关会员升级单功能
  469. public function actionOpenUpgrade() {
  470. if (Yii::$app->request->isPost) {
  471. $postData = Yii::$app->request->post();
  472. $isOpen = $postData['isOpen'];
  473. $ret = Config::updateAll(['VALUE' => $isOpen, 'UPDATED_AT' => Date::nowTime()], "CONFIG_NAME=:CONFIG_NAME", [':CONFIG_NAME' => 'isOpenUpgrade']);
  474. if ($ret) {
  475. Cache::updateSystemConfig();
  476. $msg = $isOpen == 1 ? '开启' : '关闭';
  477. return static::notice("$msg,操作成功");
  478. } else {
  479. return static::notice('操作失败,请重试');
  480. }
  481. }
  482. return static::notice('非法请求');
  483. }
  484. /**
  485. * 查看报单中心级别
  486. * @return mixed
  487. * @throws \yii\web\HttpException
  488. */
  489. public function actionDecRole() {
  490. $data = DecRole::lists('', [], [
  491. 'orderBy' => 'SORT ASC'
  492. ]);
  493. return static::notice($data);
  494. }
  495. /**
  496. * 修改报单中心级别
  497. * @return mixed
  498. * @throws \yii\web\HttpException
  499. */
  500. public function actionDecRoleEdit() {
  501. $id = Yii::$app->request->get('id');
  502. if (Yii::$app->request->isPost) {
  503. return static::edit(DecRoleForm::class, '报单中心级别修改成功', null, null, null, function () {
  504. DecRole::updateToCache();
  505. });
  506. }
  507. $oneData = DecRole::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  508. return static::notice($oneData);
  509. }
  510. /**
  511. * 添加会员级别
  512. * @return mixed
  513. * @throws \yii\web\HttpException
  514. */
  515. public function actionDecLevelAdd() {
  516. if (Yii::$app->request->isPost) {
  517. return static::edit(DecLevelForm::class, '会员级别添加成功', null, null, null, function () {
  518. DeclarationLevel::updateToCache();
  519. // Log::adminHandle('添加会员级别', 1);
  520. });
  521. }
  522. return static::notice('非发请求', 405);
  523. }
  524. /**
  525. * 修改会员级别
  526. * @return mixed
  527. * @throws \yii\web\HttpException
  528. */
  529. public function actionDecLevelEdit() {
  530. $id = Yii::$app->request->get('id');
  531. if (Yii::$app->request->isPost) {
  532. return static::edit(DecLevelForm::class, '会员级别修改成功', null, null, null, function () {
  533. DeclarationLevel::updateToCache();
  534. // Log::adminHandle('编辑报单级别参数', 1);
  535. });
  536. }
  537. $oneData = DeclarationLevel::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  538. return static::notice($oneData);
  539. }
  540. /**
  541. * 删除会员级别
  542. * @return mixed
  543. * @throws \yii\db\Exception
  544. * @throws \yii\web\HttpException
  545. */
  546. public function actionDecLevelDelete() {
  547. return static::delete(DeclarationLevel::class, '', function ($selected) {
  548. DeclarationLevel::updateToCache();
  549. // Log::adminHandle('删除报单级别', 1);
  550. });
  551. }
  552. /**
  553. * 查看会员聘级
  554. * @return mixed
  555. * @throws \yii\web\HttpException
  556. */
  557. public function actionEmpLevel() {
  558. $data = EmployLevel::lists('', [], [
  559. 'select' => 'E.*, ME.LEVEL_NAME AS MIN_EMPLOY_LEVEL_NAME',
  560. 'from' => EmployLevel::tableName() . ' AS E',
  561. 'join' => [
  562. ['LEFT JOIN', EmployLevel::tableName() . ' AS ME', 'ME.ID=E.MIN_EMPLOY_LEVEL']
  563. ],
  564. 'orderBy' => 'E.SORT ASC, E.CREATED_AT ASC'
  565. ]);
  566. return static::notice($data);
  567. }
  568. /**
  569. * 添加会员聘级
  570. * @return mixed
  571. * @throws \yii\web\HttpException
  572. */
  573. public function actionEmpLevelAdd() {
  574. if (Yii::$app->request->isPost) {
  575. return static::edit(EmployLevelForm::class, '会员聘级添加成功', null, null, null, function () {
  576. EmployLevel::updateToCache();
  577. // Log::adminHandle('添加会员聘级', 1);
  578. });
  579. }
  580. // 获取所有聘级,以供选择
  581. $allLevel = EmployLevel::find()->where('1=1')->orderBy('SORT ASC')->asArray()->all();
  582. return static::notice($allLevel);
  583. }
  584. /**
  585. * 修改聘级
  586. * @return mixed
  587. * @throws \yii\web\HttpException
  588. */
  589. public function actionEmpLevelEdit() {
  590. $id = Yii::$app->request->get('id');
  591. if (Yii::$app->request->isPost) {
  592. return static::edit(EmployLevelForm::class, '会员聘级修改成功', null, null, null, function () {
  593. EmployLevel::updateToCache();
  594. // Log::adminHandle('编辑会员聘级', 1);
  595. });
  596. }
  597. $oneData = EmployLevel::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  598. // 获取所有聘级,以供选择
  599. $allLevel = EmployLevel::find()->where('1=1')->orderBy('SORT ASC')->asArray()->all();
  600. $oneData['allLevel'] = $allLevel;
  601. return static::notice($oneData);
  602. }
  603. /**
  604. * 删除聘级
  605. * @return mixed
  606. * @throws \yii\db\Exception
  607. * @throws \yii\web\HttpException
  608. */
  609. public function actionEmpLevelDelete() {
  610. return static::delete(EmployLevel::class, '', function ($selected) {
  611. EmployLevel::updateToCache();
  612. // Log::adminHandle('删除会员聘级', 1);
  613. });
  614. }
  615. /**
  616. * 查看短信模板
  617. * @return mixed
  618. * @throws \yii\web\HttpException
  619. */
  620. public function actionSmsTemplate() {
  621. $data = SmsTemplate::lists('', [], ['orderBy' => 'CREATED_AT ASC']);
  622. return static::notice($data);
  623. }
  624. /**
  625. * 编辑短信模板
  626. * @return mixed
  627. * @throws \yii\web\HttpException
  628. */
  629. public function actionSmsTemplateEdit() {
  630. $id = Yii::$app->request->get('id');
  631. if (Yii::$app->request->isPost) {
  632. return parent::edit(SmsTemplateForm::class, '短信模板编辑成功', null, null, null, function () {
  633. SmsTemplate::updateDecToCache();
  634. SmsTemplate::updateEmpToCache();
  635. // Log::adminHandle('编辑短信模板', 1);
  636. });
  637. }
  638. $oneData = SmsTemplate::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  639. return static::notice(['oneData' => $oneData]);
  640. }
  641. /**
  642. * 提现金额等级
  643. * @return mixed
  644. * @throws \yii\web\HttpException
  645. */
  646. public function actionWithdrawLevel() {
  647. $data = WithdrawLevel::lists('', [], ['orderBy' => 'MIN_AMOUNT ASC']);
  648. return static::notice($data);
  649. }
  650. /**
  651. * 添加提现金额等级
  652. * @return mixed
  653. * @throws \yii\web\HttpException
  654. */
  655. public function actionWithdrawLevelAdd() {
  656. if (Yii::$app->request->isPost) {
  657. return static::edit(WithdrawLevelForm::class, '提现金额等级添加成功', null, null, null, function () {
  658. WithdrawLevel::updateToCache();
  659. // Log::adminHandle('添加提现金额等级', 1);
  660. });
  661. }
  662. }
  663. /**
  664. * 修改提现金额等级
  665. * @return mixed
  666. * @throws \yii\web\HttpException
  667. */
  668. public function actionWithdrawLevelEdit() {
  669. $id = Yii::$app->request->get('id');
  670. if (Yii::$app->request->isPost) {
  671. return static::edit(WithdrawLevelForm::class, '提现金额等级修改成功', null, null, null, function () {
  672. WithdrawLevel::updateToCache();
  673. // Log::adminHandle('编辑提现金额等级', 1);
  674. });
  675. }
  676. $oneData = WithdrawLevel::find()->where('ID=:ID', [':ID' => $id])->asArray()->one();
  677. return static::notice($oneData);
  678. }
  679. /**
  680. * 删除提现金额等级
  681. * @return mixed
  682. * @throws \yii\db\Exception
  683. * @throws \yii\web\HttpException
  684. */
  685. public function actionWithdrawLevelDelete() {
  686. return static::delete(WithdrawLevel::class, '', function ($selected) {
  687. WithdrawLevel::updateToCache();
  688. });
  689. }
  690. /**
  691. * 注册类型
  692. * @return mixed
  693. * @throws \yii\web\HttpException
  694. */
  695. public function actionRegType() {
  696. $data = RegType::lists('', [], [
  697. 'orderBy' => 'SORT ASC, CREATED_AT ASC'
  698. ]);
  699. return static::notice($data);
  700. }
  701. /**
  702. * 获取注册类型
  703. * @return mixed
  704. * @throws \yii\web\HttpException
  705. */
  706. public function actionRegTypeGet() {
  707. $id = Yii::$app->request->get('id');
  708. $regType = RegType::findOneAsArray('ID=:ID', [':ID' => $id]);
  709. if (!$regType) {
  710. return static::notice('数据不存在', 400);
  711. }
  712. 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']]);
  713. }
  714. /**
  715. * 修改注册类型
  716. * @return mixed
  717. * @throws \yii\web\HttpException
  718. */
  719. public function actionRegTypeEdit() {
  720. $id = Yii::$app->request->get('id');
  721. if (Yii::$app->request->isPost) {
  722. $formModel = new RegTypeForm();
  723. $formModel->scenario = 'edit';
  724. $formModel->id = $id;
  725. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  726. // Log::adminHandle('修改注册类型,ID为:' . $result['ID']);
  727. return static::notice('修改注册类型成功');
  728. } else {
  729. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  730. }
  731. }
  732. return static::notice('非法请求', 400);
  733. }
  734. /**
  735. * 获取服务协议
  736. * @return mixed
  737. * @throws \yii\web\HttpException
  738. */
  739. public function actionPactGet() {
  740. $path = \Yii::getAlias('@common/runtime/datas/pact.php');
  741. if (!file_exists($path)) {
  742. $oneData = '';
  743. } else {
  744. $oneData = include $path;
  745. }
  746. return static::notice($oneData);
  747. }
  748. /**
  749. * 获取服务协议
  750. * @return mixed
  751. * @throws \yii\base\InvalidConfigException
  752. * @throws \yii\web\HttpException
  753. */
  754. public function actionPactEdit() {
  755. $path = \Yii::getAlias('@common/runtime/datas/pact.php');
  756. $post = Yii::$app->request->post();
  757. if (!isset($post['CONTENT']) || empty($post['CONTENT'])) {
  758. return static::notice('请输入协议内容', 400);
  759. }
  760. $now = Date::nowTime();
  761. $data = [
  762. 'UPDATED_AT' => $now,
  763. 'CONTENT' => addslashes($post['CONTENT']),
  764. 'ADM_NAME' => \Yii::$app->user->id,
  765. ];
  766. // Log::adminHandle('更新服务协议');
  767. $date = \Yii::$app->formatter->asDatetime($now);
  768. $content = "<?php" . PHP_EOL . "/**
  769. * 配置文件
  770. * @date {$date}
  771. */" . PHP_EOL;
  772. $content .= "return ";
  773. $content .= var_export($data, true);
  774. $content .= ";";
  775. file_put_contents($path, $content, LOCK_EX);
  776. return static::notice('更新服务协议成功');
  777. }
  778. /**
  779. * 获取当前在线用户
  780. * @return mixed
  781. * @throws \yii\base\InvalidConfigException
  782. * @throws \yii\web\HttpException
  783. */
  784. public function actionUserOnline() {
  785. $params = Yii::$app->request->get();
  786. $page = $params['page'];
  787. $pageSize = $params['pageSize'];
  788. $redisKey = $params['filterStatus'] == 1 ? 'user:timeOut' : 'admin:timeOut';
  789. $redisKeyUserInfo = 'user:baseInfo';
  790. $tokens = Yii::$app->tokenRedis->hgetall($redisKey);
  791. $timeOut = Yii::$app->params['operationTimeOut'];
  792. $currentTime = time();
  793. $user_info = [];
  794. if($tokens && is_array($tokens)){
  795. foreach($tokens as $k=>$v){
  796. //判断是否是hash的key
  797. $last_time = Yii::$app->tokenRedis->hget($redisKey,$v);
  798. if($last_time && ( $currentTime - $last_time < $timeOut )){
  799. if( $params['filterStatus'] == 1){
  800. $user_data = json_decode(Yii::$app->tokenRedis->hget($redisKeyUserInfo,$v),true);
  801. $user_info['list'][$k]['ID'] = $user_data['USER_NAME'];
  802. $user_info['list'][$k]['REAL_NAME'] = $user_data['REAL_NAME'];
  803. $user_info['list'][$k]['UPDATE_TIME'] = date('Y-m-d H:i:s',$last_time);
  804. } else {
  805. $user_data = User::find()->where(['ID'=>$v])->asArray()->one();
  806. $user_info['list'][$k]['ID'] = $user_data['ADMIN_NAME'];
  807. $user_info['list'][$k]['REAL_NAME'] = $user_data['REAL_NAME'];
  808. $user_info['list'][$k]['UPDATE_TIME'] = date('Y-m-d H:i:s',$last_time);
  809. }
  810. }
  811. }
  812. }
  813. if($user_info){
  814. $user_info['list'] = array_values($user_info['list']);
  815. $totalCount = count($user_info['list']);
  816. $limit = ($page - 1) * $pageSize;
  817. array_multisort(array_column($user_info['list'],'UPDATE_TIME'), SORT_DESC,$user_info['list']);
  818. $user_info['list'] = array_slice($user_info['list'],$limit,$pageSize);
  819. $user_info['totalCount'] = $totalCount;
  820. $user_info['pageSize'] = $pageSize;
  821. }
  822. return static::notice($user_info);
  823. }
  824. public static function actionInitRegionXls() {
  825. BaiduRegion::deleteAll();
  826. BaiduRegion::importXls(0,1000);
  827. return static::notice('导入成功');
  828. }
  829. public static function actionRegion() {
  830. // 开始查找bd区划,先找县级和以上
  831. // $bdProv = BaiduRegion::_getBdProv();
  832. // foreach ($bdProv as $prov) {
  833. //
  834. // }
  835. $bdCity = BaiduRegion::_getBdCity();
  836. print_r("检查新增地市".PHP_EOL);
  837. foreach ($bdCity as $city) {
  838. $p = BaiduRegion::_checkInNc($city['CITY_CODE']);
  839. if (!$p) {
  840. print_r($city['CITY_NAME'].'找不到,添加'.PHP_EOL);
  841. // print_r($city);
  842. if(BaiduRegion::addNcRegion($region_code=$city['CITY_CODE'], $region_name=$city['CITY_NAME'], $pid=$city['PROV_CODE'], $deep=3)){
  843. print_r("添加成功".PHP_EOL);
  844. }else{
  845. $regionM = Region::findOne(["REGION_CODE"=>$city['CITY_CODE']]);
  846. $regionM->STATUS = 1;
  847. $regionM->save();
  848. print_r("启用成功".PHP_EOL);
  849. }
  850. }
  851. }
  852. $bdCounty = BaiduRegion::_getBdCounty();
  853. // print_r("检查新增县".PHP_EOL);
  854. foreach ($bdCounty as $county) {
  855. $p = BaiduRegion::_checkInNc($county['COUNTY_CODE']);
  856. if (!$p){
  857. print_r($county['COUNTY_NAME'].' 区县找不到,添加'.PHP_EOL);
  858. // print_r($county);
  859. if(BaiduRegion::addNcRegion($region_code=$county['COUNTY_CODE'], $region_name=$county['COUNTY_NAME'], $pid=$county['CITY_CODE'], $deep=4)){
  860. // print_r("添加成功".PHP_EOL);
  861. }else{
  862. $regionM = Region::findOne(["REGION_CODE"=>$county['COUNTY_CODE']]);
  863. $regionM->STATUS = 1;
  864. $regionM->save();
  865. // print_r("启用成功".PHP_EOL);
  866. }
  867. }
  868. }
  869. $bdTown = BaiduRegion::_getBdTown(); // 只取省直辖县,直筒子市的乡镇
  870. print_r("检查新增地乡镇".PHP_EOL);
  871. foreach ($bdTown as $town) {
  872. $p = BaiduRegion::_checkInNc($town['TOWN_CODE']);
  873. // print_r($p);
  874. if (!$p) {
  875. print_r($town['TOWN_CODE'].$town['TOWN_NAME'].' 镇 找不到,添加'.PHP_EOL);
  876. // print_r($town);
  877. if(BaiduRegion::addNcRegion($region_code=$town['TOWN_CODE'], $region_name=$town['TOWN_NAME'], $pid=$town['COUNTY_CODE'], $deep=5)){
  878. // print_r("添加成功".PHP_EOL);
  879. }else{
  880. $regionM = Region::findOne(["REGION_CODE"=>$town['TOWN_CODE']]);
  881. $regionM->STATUS = 1;
  882. $regionM->save();
  883. // print_r("启用成功".PHP_EOL);
  884. }
  885. }
  886. }
  887. $ncAllRegion = BaiduRegion::_getAllNcRegion();
  888. foreach ($ncAllRegion as $ncRegi) {
  889. if(strlen($ncRegi['REGION_CODE'])==9){
  890. $model = Region::findOne(["REGION_CODE"=>$ncRegi['REGION_CODE'], "STATUS"=>1]);
  891. $model->DEEP = 5;
  892. $model->save();
  893. $ncRegi['DEEP'] = 5;
  894. }
  895. $t = BaiduRegion::_checkInBd($ncRegi['REGION_CODE'], $ncRegi['REGION_NAME'], $ncRegi['PID'], $ncRegi['DEEP']);
  896. if(!$t){
  897. // print_r($ncRegi['REGION_CODE'].$ncRegi['REGION_NAME']." 在百度没有,标记删除".$ncRegi['DEEP'].PHP_EOL);
  898. $regionM = Region::findOne(["REGION_CODE"=>$ncRegi['REGION_CODE'], "STATUS"=>1]);
  899. $regionM->STATUS = '0';
  900. $regionM->save();
  901. } else {
  902. if($t['REGION_NAME']!=$ncRegi['REGION_NAME']) {
  903. // print_r($ncRegi['REGION_CODE'] . $ncRegi['REGION_NAME'] . " 更名,需修改" . PHP_EOL);
  904. $regionM = Region::findOne(["REGION_CODE"=>$ncRegi['REGION_CODE'], "STATUS"=>1]);
  905. $regionM->REGION_NAME = $t['REGION_NAME'];
  906. $regionM->save();
  907. }
  908. if($t['PID']!=$ncRegi['PID']){
  909. // print_r($ncRegi['REGION_CODE'] . $ncRegi['REGION_NAME'] . " 上级".$ncRegi['PID']."需修改". $t['PID'] . PHP_EOL);
  910. $regionM = Region::findOne(["REGION_CODE"=>$ncRegi['REGION_CODE'], "STATUS"=>1]);
  911. $regionM->PID = $t['PID'];
  912. $regionM->save();
  913. }
  914. }
  915. }
  916. return static::notice('更新成功');
  917. }
  918. public function actionRegionJs() {
  919. $ncProv = BaiduRegion::_getAllNcProv();
  920. // print_r($ncProv);
  921. $prov_list = [];
  922. $ar_region_array = [
  923. '86' => $prov_list
  924. ];
  925. foreach ($ncProv as $prov) {
  926. $ar_region_array['86'][$prov['REGION_CODE']] = $prov['REGION_NAME'];
  927. $ar_region_array[$prov['REGION_CODE']] = [];
  928. }
  929. // 普通地市,直筒子市
  930. $ncCity = BaiduRegion::_getAllNcCity();
  931. foreach($ncCity as $city){
  932. $ar_region_array[$city['PID']][$city['REGION_CODE']] = $city['REGION_NAME'];
  933. $ncCounty = BaiduRegion::_getAllNcCountyByCity($city['REGION_CODE']);
  934. foreach ($ncCounty as $county) {
  935. $ar_region_array[$city['REGION_CODE']][$county['REGION_CODE']] = $county['REGION_NAME'];
  936. }
  937. }
  938. // 直辖县级市
  939. $ncHighCounty = BaiduRegion::_getAllNcCounty();
  940. foreach ($ncHighCounty as $county) {
  941. $ar_region_array[$county['PID']][$county['REGION_CODE']] = $county['REGION_NAME'];
  942. $ncTown = BaiduRegion::_getAllNcTownByCity($county['REGION_CODE']);
  943. foreach ($ncTown as $town) {
  944. $ar_region_array[$county['REGION_CODE']][$town['REGION_CODE']] = $town['REGION_NAME'];
  945. }
  946. }
  947. $ar_region_data = json_encode($ar_region_array,JSON_UNESCAPED_UNICODE);
  948. $str = (string)$ar_region_data;
  949. $str = "const AR_REGION_DATA = ".$str;
  950. file_put_contents("/Volumes/HDD/workshop/old/ar.upload.ming/cdn/jsdata/ar_region_data.js", $str);
  951. return static::notice('生成JS成功');
  952. }
  953. public function actionRenewRegionCache() {
  954. if(Region::updateToCache()){
  955. return static::notice('刷新成功');
  956. } else {
  957. return static::notice('刷新失败');
  958. }
  959. }
  960. }