SiteController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace frontendApi\modules\v1\controllers;
  9. use common\helpers\Alarm;
  10. use common\helpers\Cache;
  11. use common\helpers\LoggerTool;
  12. use common\helpers\snowflake\PageSnowFake;
  13. use common\helpers\Tool;
  14. use common\models\Ad;
  15. use common\models\AdLocation;
  16. use common\models\ArticleCategory;
  17. use common\models\BaUser;
  18. use common\models\DecOrder;
  19. use common\models\DecRole;
  20. use common\models\Order;
  21. use common\models\OrderGoods;
  22. use common\models\PerfPeriod;
  23. use common\models\Period;
  24. use common\models\ShopGoods;
  25. use Yii;
  26. use frontendApi\modules\v1\models\User;
  27. use common\helpers\parsedown\Parsedown;
  28. class SiteController extends BaseController
  29. {
  30. public $modelClass = User::class;
  31. /**
  32. * 请求服务器时间差
  33. * @return mixed
  34. * @throws \yii\web\HttpException
  35. */
  36. public function actionDaysDiff(){
  37. return static::notice(['daysDiff'=>Yii::$app->params['daysDiff']]);
  38. }
  39. /**
  40. * 获取广告
  41. * @return mixed
  42. * @throws \yii\web\HttpException
  43. */
  44. public function actionAd(){
  45. $lid = Yii::$app->request->get('lid');
  46. $adLocation = AdLocation::findUseSlaves()->where('ID=:ID', [':ID'=>$lid])->asArray()->one();
  47. $query = Ad::findUseSlaves()->select('ID,IMAGE,LID,TITLE,CONTENT,TYPE')->where('LID=:LID AND STATUS=1', [':LID'=>$lid])->orderBy('SORT ASC')->asArray();
  48. $data = [];
  49. if($adLocation['TYPE'] == AdLocation::TYPE_SLIDE){
  50. $data = $query->all();
  51. } elseif($adLocation['TYPE'] == AdLocation::TYPE_IMAGE) {
  52. $data = $query->one();
  53. }
  54. return static::notice($data);
  55. }
  56. /**
  57. * 请求手机基础信息
  58. * @return array
  59. */
  60. public function actionMobileBaseInfo(){
  61. // 会员级别
  62. $decLevels = Cache::getDecLevelConfig();
  63. // 聘级
  64. $empLevels = Cache::getEmpLevelConfig();
  65. // 时间差
  66. $daysDiff = Yii::$app->params['daysDiff'];
  67. // 钱包
  68. $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
  69. return [
  70. 'decLevels' => $decLevels,
  71. 'empLevels' => $empLevels,
  72. 'daysDiff' => $daysDiff,
  73. 'shopWalletType' => $shopWalletType,
  74. ];
  75. }
  76. public function actions()
  77. {
  78. $actions = parent::actions();
  79. $actions['captcha'] = [
  80. 'class' => 'common\helpers\CaptchaAction',
  81. 'width' => 120,
  82. 'height' => 40,
  83. 'padding' => 0,
  84. 'minLength' => 4,
  85. 'maxLength' => 4,
  86. 'offset'=>8, //设置字符偏移量 有效果
  87. 'testLimit'=>1,
  88. ];
  89. return $actions;
  90. }
  91. /**
  92. * 请求页面数据
  93. * @return mixed
  94. * @throws \yii\web\HttpException
  95. */
  96. public function actionPageData() {
  97. $pageId = PageSnowFake::instance()->generateId();
  98. return static::notice(['pageId'=>$pageId]);
  99. }
  100. /**
  101. * 请求基础信息
  102. * @return array
  103. */
  104. public function actionBaseInfo(){
  105. $userId = '419322759496208384';
  106. $sysConfig = Cache::getSystemConfig();
  107. $mesureUpCondition = $sysConfig['monthPcsPvFxCondition']['VALUE']; // 月达标条件 NG默认30
  108. $_calcYearMonth = '2022-10-08';
  109. $_periodNum = 103;
  110. // 条件1: 当月消费30BV
  111. $pv = PerfPeriod::find()->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND PERIOD_NUM<=:PERIOD_NUM',
  112. ['USER_ID'=>$userId, 'CALC_MONTH'=>$_calcYearMonth, 'PERIOD_NUM'=>$_periodNum])
  113. ->SUM('PV_PCS');
  114. if ($pv >= $mesureUpCondition) {
  115. return static::notice(['daysDiff'=>Yii::$app->params['daysDiff'], 'rs' => 1]);
  116. }
  117. // 条件2: 任意水机+150粒的EKSP
  118. $orderEKSP = Order::find()
  119. ->alias('O')
  120. ->join('INNER JOIN', OrderGoods::tableName() . ' AS G', 'O.SN = G.ORDER_SN')
  121. ->where("O.IS_DELETE=0 AND O.USER_ID=:USER_ID AND O.CALC_MONTH=:CALC_MONTH AND O.PERIOD_NUM<=:PERIOD_NUM AND G.SKU_CODE=:SKU_CODE",
  122. ['USER_ID' => $userId, 'CALC_MONTH' => $_calcYearMonth, 'PERIOD_NUM' => $_periodNum, ':SKU_CODE' => 'BA'])
  123. ->count();
  124. if (!$orderEKSP) {
  125. return static::notice(['daysDiff'=>Yii::$app->params['daysDiff'], 'rs' => 2]);
  126. }
  127. // 所有分期商品
  128. $instalmentShopGoods = ShopGoods::find()->where('INSTALMENT>0 AND STATUS=1')->select('GOODS_NO')->column();
  129. $instalmentShopGoods = implode("','", $instalmentShopGoods);
  130. $orderInstalment = Order::find()
  131. ->alias('O')
  132. ->join('INNER JOIN', OrderGoods::tableName() . ' AS G', 'O.SN = G.ORDER_SN')
  133. ->where("O.IS_DELETE=0 AND O.USER_ID=:USER_ID AND O.CALC_MONTH=:CALC_MONTH AND O.PERIOD_NUM<=:PERIOD_NUM AND G.SKU_CODE IN ('{$instalmentShopGoods}')",
  134. ['USER_ID' => $userId, 'CALC_MONTH' => $_calcYearMonth, 'PERIOD_NUM' => $_periodNum])
  135. ->count();
  136. if (!$orderInstalment) {
  137. return static::notice(['daysDiff'=>Yii::$app->params['daysDiff'], 'rs' => 3]);
  138. }
  139. // 会员级别
  140. $decLevels = Cache::getDecLevelConfig();
  141. // 聘级
  142. $empLevels = Cache::getEmpLevelConfig();
  143. // 皇冠星级
  144. $crownLevels = Cache::getStarCrownLevelConfig();
  145. // 菜单
  146. $menu = require Yii::getAlias('@frontendApi/config/menu.php');
  147. $menu = $this->_childMenu($menu);
  148. // 时间差
  149. $daysDiff = Yii::$app->params['daysDiff'];
  150. // 钱包
  151. $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
  152. //期数显示
  153. $periodNum = Period::instance()->getNowPeriodNum();
  154. $curYM = Period::find()->select("CALC_YEAR,CALC_MONTH")->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $periodNum])->asArray()->one();
  155. $plist = Period::find()->select("PERIOD_NUM")->where('CALC_YEAR=:CALC_YEAR AND CALC_MONTH=:CALC_MONTH', [':CALC_YEAR' => $curYM['CALC_YEAR'],':CALC_MONTH'=>$curYM['CALC_MONTH']])->orderBy('PERIOD_NUM ASC')->asArray()->all();
  156. $weeks = count($plist);
  157. $wkrd = '';
  158. foreach ($plist as $k=>$v){
  159. if($v['PERIOD_NUM']==$periodNum){
  160. $wkrd =$k+1;break;
  161. }
  162. }
  163. if($wkrd==1){
  164. $wkrd.='st';
  165. }else{
  166. $wkrd.='nd';
  167. }
  168. $monthArray = [
  169. 1 => 'Jan',
  170. 2 => 'Feb',
  171. 3 => 'Mar',
  172. 4 => 'Apr',
  173. 5 => 'May',
  174. 6 => 'Jun',
  175. 7 => 'Jul',
  176. 8 => 'Aug',
  177. 9 => 'Sep',
  178. 10 => 'Oct',
  179. 11 => 'Nov',
  180. 12 => 'Dec',
  181. ];
  182. return [
  183. 'decLevels' => $decLevels,
  184. 'empLevels' => $empLevels,
  185. 'crownLevels' => $crownLevels,
  186. 'menu' => $menu,
  187. 'daysDiff' => $daysDiff,
  188. 'periodNum' => $periodNum . ',' . $wkrd . ' PC of ' . $monthArray[$curYM['CALC_MONTH']],
  189. 'shopWalletType' => $shopWalletType,
  190. 'whetherBA' => false,
  191. ];
  192. }
  193. private function _childMenu($parentArray){
  194. $menuResult = [];
  195. foreach($parentArray as $key => $parentMenu){
  196. if($key !== 'article'){
  197. // 菜单是否显示
  198. if(isset($parentMenu['show']) && !$parentMenu['show']){
  199. continue;
  200. }
  201. if($this->_teamworkChkMenu($parentMenu)){
  202. continue;
  203. }
  204. if($this->_decChkMenu($parentMenu)){
  205. continue;
  206. }
  207. // 查看是否有该控制器的权限
  208. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  209. if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
  210. }
  211. // 查看是否有权限
  212. if(isset($parentMenu['action']) && $parentMenu['action']){
  213. if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
  214. }
  215. // 子菜单同样设置
  216. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  217. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  218. }
  219. }
  220. $menuResult[] = $parentMenu;
  221. }
  222. return $menuResult;
  223. }
  224. /**
  225. * 虚拟会员hz解决暂写死
  226. * @param $menu
  227. * @return bool
  228. */
  229. private function _teamworkChkMenu($menu){
  230. if (User::getEnCodeInfo(\Yii::$app->user->id)['IS_UNION']==1) {
  231. if(in_array($menu['routePath'],['dashboard/index','user','user/index','finance','finance/index','finance/period','finance/flow-bonus','finance/withdraw'])) return true;
  232. }
  233. return false;
  234. }
  235. /**
  236. * 报单中心显示菜单
  237. * @param $menu
  238. * @return bool
  239. */
  240. private function _decChkMenu($menu) {
  241. if(!isset($menu['allow'])){
  242. return false;
  243. }
  244. if($menu['allow']=='studio'){
  245. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  246. if($isStudio==1){
  247. return false;
  248. }
  249. }
  250. if($menu['allow']=='declarer'){
  251. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  252. if(!$isDecReg) return false;
  253. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  254. if($isDec==1){
  255. return false;
  256. }
  257. }
  258. if($menu['allow']=='transferRecordSwitch'){
  259. $transferRecordSwitch = isset(Cache::getSystemConfig()['transferRecordSwitch']) ? Cache::getSystemConfig()['transferRecordSwitch']['VALUE'] : '';
  260. if($transferRecordSwitch) return false;
  261. }
  262. if($menu['allow']=='transferSwitch'){
  263. $transferSwitch = isset(Cache::getSystemConfig()['transferSwitch']) ? Cache::getSystemConfig()['transferSwitch']['VALUE'] : '';
  264. if($transferSwitch) return false;
  265. }
  266. if($menu['allow']=='pastBonusSwitch'){
  267. $pastBonusSwitch = isset(Cache::getSystemConfig()['pastBonusSwitch'])
  268. ? Cache::getSystemConfig()['pastBonusSwitch']['VALUE']
  269. : '';
  270. if($pastBonusSwitch) return false;
  271. }
  272. if($menu['allow']=='newBonusSwitch'){
  273. // ???
  274. $newBonusSwitch = isset(Cache::getSystemConfig()['newBonusSwitch'])
  275. ? Cache::getSystemConfig()['newBonusSwitch']['VALUE']
  276. : '';
  277. if($newBonusSwitch) return false;
  278. }
  279. return true;
  280. }
  281. public function actionDoc(){
  282. $docCssPath = \Yii::$app->basePath.'/libs/doc/markdown.css';
  283. $treeCssPath = \Yii::$app->basePath.'/libs/doc/tree.css';
  284. $treeJsPath = \Yii::$app->basePath.'/libs/doc/tree.js';
  285. $docfilePath = \Yii::$app->basePath.'/libs/doc/shopApiReadMe.md';
  286. $docCssStyle = file_get_contents($docCssPath);
  287. $docContent = file_get_contents($docfilePath);
  288. $treeCssStyle= file_get_contents($treeCssPath);
  289. $treeJsPath= file_get_contents($treeJsPath);
  290. $parsedown = Parsedown::instance();
  291. $result = '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">';
  292. $result .= '<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>';
  293. $result .= "<script>{$treeJsPath}</script>";
  294. $result .= "<style>{$treeCssStyle}</style>";
  295. $result .= "<style>{$docCssStyle}</style></head>";
  296. $result .= '<body><div class="markdown-body">';
  297. $result .= $parsedown->text($docContent);
  298. $result .= '</div></body></html>';
  299. print_r($result);
  300. exit();
  301. }
  302. /**
  303. * 站点设置
  304. * @return mixed
  305. * @throws \yii\web\HttpException
  306. */
  307. public function actionConfig() {
  308. $systemConfig = Cache::getSystemConfig();
  309. if ($systemConfig['siteClose']['VALUE']) {
  310. $siteCloseInfo = $systemConfig['siteCloseInfo']['VALUE'];
  311. return static::notice(['siteClose' => true, 'siteCloseInfo' => $siteCloseInfo]);
  312. }
  313. $siteTitle = $systemConfig['siteTitle']['VALUE'];
  314. return static::notice(['siteClose' => false, 'siteTitle' => $siteTitle]);
  315. }
  316. /**
  317. * 请求基础信息
  318. * @return array
  319. */
  320. public function actionBaBaseInfo(){
  321. // 菜单
  322. $menu = require Yii::getAlias('@frontendApi/config/menuBA.php');
  323. // 获取全部文章分类
  324. $allArticleCategory = ArticleCategory::getAllCategory();
  325. foreach($allArticleCategory as $category){
  326. $menu['article']['child'][] = ['name'=>$category['CATE_NAME'], 'class'=>'', 'icon'=>'', 'controller'=>'article', 'action'=>'list', 'routePath'=>'article/list/'.$category['ID'], 'show'=>1,];
  327. }
  328. $menu = $this->_childBaMenu($menu);
  329. // 时间差
  330. $daysDiff = Yii::$app->params['daysDiff'];
  331. // 钱包
  332. $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
  333. return [
  334. 'decLevels' => '',
  335. 'empLevels' => '',
  336. 'menu' => $menu,
  337. 'daysDiff' => $daysDiff,
  338. 'shopWalletType' => $shopWalletType,
  339. 'whetherBA' => true,
  340. ];
  341. }
  342. private function _childBaMenu($parentArray) {
  343. $menuResult = [];
  344. foreach ($parentArray as $key => $parentMenu) {
  345. if ($key !== 'article'){
  346. // 菜单是否显示
  347. if (isset($parentMenu['show']) && !$parentMenu['show']) {
  348. continue;
  349. }
  350. // 查看是否有该控制器的权限
  351. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  352. if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
  353. }
  354. // 查看是否有权限
  355. if(isset($parentMenu['action']) && $parentMenu['action']){
  356. if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
  357. }
  358. // 子菜单同样设置
  359. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  360. $parentMenu['child'] = $this->_childBaMenu($parentMenu['child']);
  361. }
  362. }
  363. $menuResult[] = $parentMenu;
  364. }
  365. return $menuResult;
  366. }
  367. /**
  368. * 发送钉钉测试信息
  369. * @return mixed
  370. * @throws \yii\web\HttpException
  371. */
  372. public function actionSendNotice()
  373. {
  374. $data = [
  375. 'code' => 400,
  376. 'message' => 'autoSendDingTalk',
  377. ];
  378. return static::notice(['data' => $data['bug监控正常运行,没有发现异常.']]);
  379. }
  380. public function actionSendNotify()
  381. {
  382. Alarm::reportAlarm([
  383. 'stance' => 1,
  384. 'brand' => 'OTA',
  385. 'message' => '预警信息测试',
  386. ]);
  387. return static::notice('成功', 0);
  388. }
  389. }