Notice.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <?php
  2. /**
  3. *------Create thems Controller------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2017-06-12 02:52:02------
  7. */
  8. namespace App\Api\Controller;
  9. /* ini_set('display_errors', 1);
  10. error_reporting(E_ALL);*/
  11. use App\Api\Model\ArticleType;
  12. class Notice extends BaseController {
  13. private $longExpireTime = 3600;
  14. private $ExpireTime = 60;
  15. private $shortExpireTime = 5;
  16. private $_cacheKey;
  17. Public function Index() {
  18. }
  19. /**
  20. * 获取内容
  21. * [getContent description]
  22. * @return [type] [description]
  23. */
  24. public function Content() {
  25. $identity = isset($_REQUEST['identity']) ? $_REQUEST['identity'] : "";
  26. if (empty($identity)) {
  27. Render(null, '-5005', lang()->get("notice no identity"));
  28. }
  29. //添加缓存Bruce
  30. /* if( $cache_data=C()->get('cache')->get($this->cacheKey(__FUNCTION__,$identity))){
  31. Render(json_decode($cache_data,1), "1", "success");
  32. }*/
  33. $data = lm('article')
  34. ->select('title', 'content', 's_title', 'time', 'author', 'img', 'type', 'mobileimg', 'mobilecontent')
  35. ->where('identity', "{$identity}")
  36. ->where('status', '1')
  37. ->first();
  38. if (!$data) {
  39. return '-5003';
  40. }
  41. $data = $data->toArray();
  42. if ($data) {
  43. // C()->get('cache')->set($this->_cacheKey,json_encode($data),$this->longExpireTime);
  44. Render($data, "1", "success");
  45. } else {
  46. Render($data, "-5004", lang()->get('Content fail data'));
  47. }
  48. }
  49. /**
  50. *查询帮助教程
  51. *
  52. */
  53. public function HelpTutorial() {
  54. $type = isset($_GET['type']) ? $_GET['type'] : '';
  55. $limit = isset($_GET['limit']) ? $_GET['limit'] : 3;
  56. if (empty($type)) {
  57. Render(null, '-5009');
  58. }
  59. //添加缓存Bruce
  60. if($cache_data=C()->get('cache')->get( $this->cacheKey(__FUNCTION__,$type))){
  61. Render(json_decode($cache_data,1), "1", "success");
  62. }
  63. $data = lm('article')
  64. ->select('identity', 'title', 'content', 'time')
  65. ->where('typebind', $type)
  66. ->where('status', '1')
  67. ->orderBy('sort', 'desc')
  68. ->limit($limit)
  69. ->get();
  70. if (!($data)) {
  71. return '-5008';
  72. }
  73. $data = $data->toArray();
  74. if ($data) {
  75. C()->get('cache')->set($this->_cacheKey,json_encode($data),$this->longExpireTime);
  76. Render($data, "1", "success");
  77. } else {
  78. Render($data, "-5007", '');
  79. }
  80. }
  81. /**
  82. * 资讯公告
  83. * [Tittle description]
  84. */
  85. public function Tittle() {
  86. $identity = isset($_GET['identity']) ? $_GET['identity'] : "";
  87. if (empty($identity)) {
  88. Render(null, '-5009');
  89. }
  90. //添加缓存Bruce
  91. if( $cache_data=C()->get('cache')->get($this->cacheKey(__FUNCTION__,$identity))){
  92. Render(json_decode($cache_data,1), "1", "success");
  93. }
  94. $data = lm('article')
  95. ->select('title', 'content', 'time', 'type', 'mobilecontent')
  96. ->where('identity', $identity)
  97. ->where('status', '1')
  98. ->get()
  99. ->toArray();
  100. if (!is_array($data)) {
  101. return '-5008';
  102. }
  103. if ($data) {
  104. C()->get('cache')->set($this->_cacheKey,json_encode($data),$this->shortExpireTime);
  105. Render($data, "1", "success");
  106. } else {
  107. Render($data, "-5007", '');
  108. }
  109. }
  110. //只显示优惠活动下面的子分类 type =3
  111. public function TypeName() {
  112. //添加缓存Bruce
  113. if( $cache_data=C()->get('cache')->get($this->cacheKey(__FUNCTION__))){
  114. Render(json_decode($cache_data,1), "1", "success");
  115. }
  116. $data = lm('articleType')
  117. ->select('id', 'cate_name as name', 'create_time as create_at')
  118. ->where(["parent_id" => 3])
  119. ->get()
  120. ->toArray();
  121. if (!is_array($data)) {
  122. return '-5008';
  123. }
  124. if ($data) {
  125. C()->get('cache')->set($this->_cacheKey,json_encode($data),$this->longExpireTime);
  126. Render($data, "1", "success");
  127. } else {
  128. Render($data, "-5007", '');
  129. }
  130. }
  131. /**
  132. * 点击更多
  133. * @return string
  134. */
  135. public function Mores() {
  136. $data = lm('article')
  137. ->select('identity', 'title', 'content', 'time')
  138. ->where('type', '2')
  139. ->where('status', 1)
  140. ->first();
  141. if (!$data) {
  142. return '-5011';
  143. }
  144. $data = $data->toArray();
  145. if ($data) {
  146. Render($data, "1", "success");
  147. } else {
  148. Render(null, "-5010", '');
  149. }
  150. }
  151. /**
  152. * 通知
  153. * [Notice description]
  154. */
  155. public function Notice() {
  156. $user = $this->_getList();
  157. Render($user, '1', 'success');
  158. }
  159. /**
  160. * 充值跑马灯
  161. * [recharge description]
  162. */
  163. public function RechargeDesc() {
  164. //缓存--Bruce
  165. if( $cache_data=C()->get('cache')->get($this->cacheKey(__FUNCTION__))){
  166. Render(json_decode($cache_data,1), "1", "success");
  167. }
  168. $list = lm('setinfo', 'commons')->where('infotype', 9)->select('infocontent')->first();
  169. if (empty($list)) {
  170. Render(null, '-2102', '');
  171. }
  172. C()->get('cache')->set($this->_cacheKey,json_encode($list['infocontent']),$this->longExpireTime);
  173. Render($list['infocontent'], '1', 'success');
  174. }
  175. /**
  176. * 通知封装
  177. * [_getList description]
  178. * @return [type] [description]
  179. */
  180. private function _getList() {
  181. try {
  182. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : "";
  183. // if (empty($type)) {
  184. // Render(null, '-5002', lang()->get('type fail get'));
  185. // }
  186. $curpage = isset($_POST['curpage']) ? intval($_POST['curpage']) : "1";
  187. $pagelist = '20';
  188. $firstcode = ($curpage - 1) * $pagelist;
  189. //获取总页数
  190. if($cache_data=C()->get('cache')->get($this->cacheKey(__FUNCTION__,$type.'$curpage'))){
  191. Render(json_decode($cache_data,1), "1", "success");
  192. }
  193. //文章类别
  194. $all_type = (new ArticleType)->type();
  195. /* $sontype = lm("ArticleType",'Api')->get()->toarray();
  196. var_dump($sontype);exit();*/
  197. //获取子类别
  198. $types = [];
  199. if (!empty($type)) {
  200. $_type = explode(',', $type);
  201. foreach ($_type as $v) {
  202. if (!empty($v)) {
  203. $types = array_merge($types, $this->getTree($all_type, $v));
  204. }
  205. }
  206. $types = array_column($types, 'id');
  207. $types = array_merge($_type, $types);
  208. } else {
  209. //为空的时候只显示优惠活动下的 id=3
  210. $types = array_merge($types, $this->getTree($all_type, 3));
  211. $types = array_column($types, 'id');
  212. $types = array_merge($types, [3]);
  213. }
  214. $tol_list = lm('article');
  215. if (empty($types)) {
  216. $datas = $tol_list->where('status', '1')->where('type', '!=', 8)->count();
  217. } else {
  218. if (count($types > 1)) {
  219. $datas = $tol_list->whereIn('type', $types)->where('status', '1')->count();
  220. } else {
  221. $datas = $tol_list->where('type', $types[0])->where('status', '1')->count();
  222. }
  223. }
  224. $tolpage = ceil($tol_list / $pagelist);
  225. $res = lm('article')
  226. ->leftJoin('lottery_money', 'article.child_id', '=', 'lottery_money.id')
  227. ->select('article.identity', 'article.title', 'article.content',
  228. 'article.s_title', 'article.time', 'article.author', 'article.img',
  229. 'article.child_id', 'article.type', 'article.mobilecontent',
  230. 'article.mobileimg', 'article.typebind', 'article.sort', 'article.id', 'lottery_money.type as act_cate');
  231. if (empty($types)) {
  232. $datas = $res->where('article.status', '1')->where('article.type', '!=', 8)
  233. ->orderBy('article.sort', 'desc')->orderBy('article.time', 'desc')
  234. ->skip("{$firstcode}")
  235. ->take("{$pagelist}")
  236. // ->leftjoin('')
  237. ->get()
  238. ->toArray();
  239. } else {
  240. if (count($types > 1)) {
  241. $datas = $res->whereIn('article.type', $types);
  242. } else {
  243. $datas = $res->where('article.type', $types[0]);
  244. }
  245. $datas = $datas->where('article.status', '1')
  246. ->orderBy('article.sort', 'desc')->orderBy('article.time', 'desc')
  247. ->skip("{$firstcode}")
  248. ->take("{$pagelist}")
  249. ->get()
  250. ->toArray();
  251. }
  252. if (!is_array($datas)) {
  253. return '-5001';
  254. }
  255. $data['data'] = $datas;
  256. $data['page']['curpage'] = $curpage;
  257. $data['page']['tolpage'] = $tolpage;
  258. C()->get('cache')->set($this->_cacheKey,json_encode($data),$this->shortExpireTime);
  259. return $data;
  260. } catch (\Exception $e) {
  261. // Render("",-5007);
  262. print $e->getMessage();
  263. exit();
  264. }
  265. }
  266. /**
  267. * 支付切换
  268. * [switch description]
  269. * @return [type] [description]
  270. */
  271. public function Switchs() {
  272. $status = isset($_POST['status']) ? $_POST['status'] : '-1';
  273. if (empty($status)) {
  274. Render(null, '-5017');
  275. }
  276. $identity = isset($_POST['identity']) ? $_POST['identity'] : '76d6e867-19bd-b553-c58d-4548561dd217';
  277. if (empty($identity)) {
  278. Render(null, '-5018');
  279. }
  280. $res = [
  281. 'status' => $status,
  282. ];
  283. $data = lm('payment')
  284. ->where('identity', $identity)
  285. ->update($res);
  286. if ($data) {
  287. Render($data, '1', 'success');
  288. } else {
  289. Render(null, '-5016', 'error');
  290. }
  291. }
  292. /**
  293. * 银行卡与人员管理
  294. * @return string
  295. */
  296. public function Bank_card_management() {
  297. $accountManager = new \Biz\Account\AccountManager();
  298. $uinfo = $accountManager->getCurrentUser();
  299. if ($uinfo) {
  300. $uinfo = json_encode($uinfo);
  301. $uinfo = json_decode($uinfo, 1);
  302. $gc = explode(',', $uinfo['group_code']);
  303. } else {
  304. Render('', -4001);
  305. }
  306. $temp = 1;
  307. $where='';
  308. if (!isset($gc)) {
  309. $where = "groups = '0,'";
  310. } else {
  311. foreach ($gc as $k => $v) {
  312. if (!empty($v)) {
  313. $where .= ($temp == 1) ? '(' : ' or ';
  314. $temp = 2;
  315. $where .= "groups like '%," . $v . ",%'";
  316. }
  317. }
  318. $where .= ($temp == 2) ? ')' : '';
  319. }
  320. $data = lm('system_bank', 'commons')->getInfos($where);
  321. if (!is_array($data)) {
  322. if (isset($gc)) {
  323. $where = "groups = '0,'";
  324. $data = lm('system_bank', 'commons')->getInfos($where);
  325. if (!is_array($data)) {
  326. Render(null, '-5025', 'error');
  327. }
  328. } else {
  329. Render(null, '-5025', 'error');
  330. }
  331. }
  332. if ($data) {
  333. Render($data, '1', 'success');
  334. } else {
  335. Render(null, '-5024', 'error');
  336. }
  337. }
  338. private function getTree($array, $pid = 0, $cen = 0) {
  339. $arr = array();
  340. $cen = ++$cen;
  341. $str = "";
  342. foreach ($array as $k => $v) {
  343. if ($v['parent_id'] == $pid) {
  344. $str = str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;", $cen - 1);
  345. $arr[] = ["id" => $v["id"], "name" => ($cen - 1 ? $str . "└" . $v["cate_name"] : $v["cate_name"])];
  346. unset($array[$k]);
  347. $arr = array_merge($arr, $this->getTree($array, $v['id'], $cen));
  348. }
  349. }
  350. return $arr;
  351. }
  352. /**
  353. * @param $keyAdd 附加数据
  354. * @return string 返回缓存keyo值
  355. */
  356. private function cacheKey($fun,$keyAdd=''){
  357. return $this->_cacheKey=md5( __CLASS__.'_'.$fun.'_'.$keyAdd);
  358. }
  359. }