Other.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. <?php
  2. /**
  3. *------Create thems Controller------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2017-06-23 15:06:45------
  7. */
  8. namespace App\Api\Controller;
  9. use Illuminate\Support\Facades\DB;
  10. // ini_set('display_errors', 1);
  11. // error_reporting(E_ALL);
  12. class Other extends BaseController {
  13. /**
  14. * 轮播图
  15. */
  16. public function Banner() {
  17. $where = array();
  18. $type = $_REQUEST['type'] ? $_REQUEST['type'] : "1";
  19. $where['type'] = $type;
  20. $cachekey = md5( 'Banner'. implode($where));
  21. $cache= C()->get('cache')->get($cachekey);
  22. if(!empty($cache)){
  23. Render($cache, '1', lang()->get('success'));
  24. }
  25. $res = lm('banner', 'Commons')->getBanner($where);
  26. if ($res){
  27. $i=0;
  28. foreach ($res as $k=>$v){
  29. $res[$k]['num']=$i;
  30. $i++;
  31. }
  32. }
  33. C()->get('cache')->set($cachekey,$res,600);
  34. Render($res, '1', lang()->get('success'));
  35. }
  36. /**
  37. * 公告
  38. */
  39. public function Notice() {
  40. $res = lm('setinfo', 'Commons')->where('id', '19')->first();
  41. if(isset($res->infocontent)){
  42. $res->infocontent = str_replace('white-space:normal;', 'white-space:nowrap;', $res->infocontent);
  43. $res->infocontent = str_replace('white-space: normal;', 'white-space: nowrap;', $res->infocontent);
  44. }
  45. Render($res, '1', lang()->get('success'));
  46. }
  47. /**
  48. * 轮播图
  49. */
  50. public function BannerType() {
  51. $res = lm('advert', 'Commons')->getBanner();
  52. Render($res, '1', lang()->get('success'));
  53. }
  54. /**
  55. * pc帮助中心
  56. */
  57. public function Help()
  58. {
  59. $res = lm("game_type", 'commons')->where('close_status',1)->where('type','<','3')->orderBy('hot','desc')->select('play_desc as content', 'name as title','table_name','identity')
  60. ->get();
  61. if ($res){
  62. $res=$res->toArray();
  63. }else{
  64. $res=[];
  65. }
  66. $dat = lm('article', 'api')->orderBy('sort','desc')->where('type', 11)->oRwhere('type', 9)
  67. ->get();
  68. if ($dat){
  69. $dat=$dat->toArray();
  70. }else{
  71. $dat=[];
  72. }
  73. $da = lm('article', 'api')->orderBy('sort','desc')->where('type', 10)
  74. ->get();
  75. if ($da){
  76. $da=$da->toArray();
  77. }else{
  78. $da=[];
  79. }
  80. $data = [
  81. 'opencai' => $res,
  82. 'recharge' => $dat,
  83. 'quert' => $da,
  84. ];
  85. Render($data, '1', lang()->get('success'));
  86. }
  87. public function HelpData()
  88. {
  89. $identity = $_GET['identity'] ? $_GET['identity'] : '';
  90. $name = $_GET['name'] ? $_GET['name'] : '';
  91. if (empty($identity)) {
  92. Render('', '-10009', 'no game');
  93. return;
  94. }
  95. $arr = [ //向数据库追加数组 然后循环出来
  96. 'title' => $name,
  97. 'identity' => $identity,
  98. ];
  99. $where = '1 = 1';
  100. foreach ($arr as $key => $value) {
  101. //循环数组
  102. if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
  103. $where .= " AND {$key}='{$value}'"; //获取值
  104. }
  105. }
  106. $data = lm('article', 'api')->whereRaw($where)
  107. ->first();
  108. if ($data){
  109. $data=$data->toArray();
  110. }else{
  111. $data=[];
  112. }
  113. Render($data, '1', lang()->get('success'));
  114. }
  115. /**
  116. * 联系我们客服信息
  117. */
  118. public function GetNewNoticeinfo() {
  119. $info = lm('setinfo', 'commons')->where('infotype', 33)->get();
  120. if (!$info) {
  121. Render('', '-5006', lang('error')->get('-5006'));
  122. }
  123. $data = array();
  124. foreach ($info as $k => $v) {
  125. $data[$v['remarks']] = $v['infocontent'];
  126. }
  127. Render($data, 1);
  128. }
  129. public function GameExplan()
  130. {
  131. $game = isset($_GET['game']) ? trim($_GET['game']) : '';
  132. if (empty($game)) {
  133. Render('', '-10009', 'no game');
  134. return;
  135. }
  136. $data = lm("game_type", 'commons')->where("table_name", $game)->select('play_desc as content', 'name as title')->first();
  137. if (!$data) {
  138. Render('', '-10009', 'no game');
  139. return;
  140. }
  141. if ($data){
  142. $data = $data->toArray();
  143. }else{
  144. $data =[];
  145. }
  146. Render($data, '1', lang()->get('success'));
  147. }
  148. /**
  149. * 手机主页弹框内容
  150. */
  151. public function Mobile_tan()
  152. {
  153. $content = lm('setinfo', 'Commons')->where(['status' => 1, 'infotype' => 6])->first();
  154. if ($content) {
  155. $con = $content->toArray();
  156. } else {
  157. Render('', '-5001', lang()->get('fail'));
  158. }
  159. Render($con, '1', lang()->get('success'));
  160. }
  161. /**
  162. * 获得用户银行卡
  163. */
  164. public function GetBank()
  165. {
  166. $user_id = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  167. if (empty($user_id)) {
  168. Render('', '-4010', lang()->get('user not login'));
  169. }
  170. $res = array();
  171. $res = lm('account_bank', 'Commons')->where('account_identity', $user_id)->first();
  172. if ($res) {
  173. $res = $res->toArray();
  174. }
  175. if (!empty($res)) {
  176. Render($res, 1, lang()->get('success'));
  177. }
  178. Render('', '-2004', lang()->get('Please bind the bank card'));
  179. }
  180. /**
  181. * 检测试玩用户
  182. */
  183. public function CheckUser()
  184. {
  185. $user_id = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  186. if (empty($user_id)) {
  187. Render('', -4001, lang('error')->get('-4001'));
  188. }
  189. $res = lm('account', 'commons')->where('identity', $user_id)->first();
  190. if ($res) {
  191. Render($res, 1);
  192. }
  193. Render('', '-5001', lang('error')->get('-5001'));
  194. }
  195. //意见反馈
  196. public function FeedBack()
  197. {
  198. $user_id = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  199. $name = isset($_SESSION['uinfo']['account']) ? $_SESSION['uinfo']['account'] : '';
  200. $type = isset($_POST['type']) ? strip_tags($_POST['type']) : "";
  201. $content = isset($_POST['content']) ? strip_tags($_POST['content']) : "";
  202. $tel = isset($_POST['tel']) ? strip_tags($_POST['tel']) : "";
  203. $qq = isset($_POST['qq']) ? strip_tags($_POST['qq']) : "";
  204. $weixin = isset($_POST['weixin']) ? strip_tags($_POST['weixin']) : "";
  205. $dat = [
  206. 'account_identity' => $user_id,
  207. 'type' => $type,
  208. 'account_name' => $name,
  209. 'content' => $content,
  210. 'submit_time' => date('Y-m-d H:i:s',time()),
  211. ];
  212. if(!empty($tel))$dat['account_tel']=$tel;
  213. if(!empty($qq))$dat['account_qq']=$qq;
  214. if(!empty($weixin))$dat['account_weixin']=$weixin;
  215. $data = lm('feedback', 'Commons')->insert($dat);
  216. if ($data) {
  217. Render($data, 1, lang()->get('success'));
  218. } else {
  219. Render('', '-5001', lang('error')->get('-5001'));
  220. }
  221. }
  222. //意见反馈
  223. public function FeedBackList()
  224. {
  225. $user_id = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  226. $page = isset($_POST['page']) ? $_POST['page'] : "1";
  227. $lists = isset($_POST['lists']) ? $_POST['lists'] : "10";
  228. $list = $lists;
  229. //获取总页数
  230. $count_list = lm('feedback', 'Commons')->where('account_identity', $user_id)->count();
  231. $count_page = ceil($count_list / $list);
  232. $first = ($page - 1) * $list;
  233. $data = lm('feedback', 'Commons')->where('account_identity', $user_id)->orderBy('submit_time', 'desc')->offset($first)->limit($list)
  234. ->get();
  235. $dat = [
  236. 'see_status' => '1',
  237. ];
  238. $da = lm('feedback', 'Commons')->where('account_identity', $user_id)
  239. ->where('see_status', '0')
  240. ->where('status', '1')
  241. ->update($dat);
  242. if ($data) {
  243. $data = $data->toArray();
  244. $Iteas = [
  245. 'data' => $data,
  246. 'count_page' => $count_page,
  247. 'page' => $page,
  248. ];
  249. Render($Iteas, 1, lang()->get('success'));
  250. } else {
  251. Render('', '-5001', lang('error')->get('-5001'));
  252. }
  253. }
  254. //移动意见反馈
  255. public function FeedBackLists()
  256. {
  257. $user_id = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  258. $data = lm('feedback', 'Commons')->where('account_identity', $user_id)->orderBy('submit_time', 'desc')
  259. ->get();
  260. $dat = [
  261. 'see_status' => '1',
  262. ];
  263. $da = lm('feedback', 'Commons')->where('account_identity', $user_id)
  264. ->where('see_status', '0')
  265. ->where('status', '1')
  266. ->update($dat);
  267. if ($data) {
  268. $data = $data->toArray();
  269. $Iteas = [
  270. 'data' => $data,
  271. ];
  272. Render($Iteas, 1, lang()->get('success'));
  273. } else {
  274. Render('', '-5001', lang('error')->get('-5001'));
  275. }
  276. }
  277. //意见反馈
  278. public function FeedBackNum()
  279. {
  280. $user_id = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  281. $data = lm('feedback', 'Commons')->where('account_identity', $user_id)
  282. ->where('status', '1')
  283. ->where('see_status', '0')
  284. ->count();
  285. Render($data, 1, lang()->get('success'));
  286. }
  287. //我的消息
  288. public function Message()
  289. {
  290. $user_id = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  291. $user_name = isset($_SESSION['uinfo']['account']) ? $_SESSION['uinfo']['account'] : '';
  292. $timed=lm('account_detailed','Commons')->where('account_identity',$user_id)->first();
  293. $group_codes=$timed['group_code'];
  294. $group_codes_arr=explode(',',$group_codes);
  295. array_pop($group_codes_arr);
  296. $len=count($group_codes_arr);
  297. $register_time=$timed['register_time'];
  298. $sql = "SELECT count(*) as num FROM message WHERE message.type = 3 and ((add_time > '$register_time' AND message.add_type = '2') or add_type='1')";
  299. if(is_array($group_codes_arr)&&$len>0){
  300. $sql.=" and (";
  301. foreach ($group_codes_arr as $v){
  302. $sql.=" group_code like '%,".$v.",%' or";
  303. }
  304. $sql .= " toname = 'all') ";
  305. }
  306. $sql.="and id not in( SELECT message_id from message_read WHERE account_identity = '" . $user_id . "' GROUP BY message_id)";
  307. $sqls="SELECT count(*) as num FROM message WHERE type = 1 and toname = '$user_name' and id not in( SELECT message_id from message_read WHERE account_identity = '" . $user_id . "' GROUP BY message_id)";
  308. $num1=S('DB')->select($sql);
  309. $num2=S('DB')->select($sqls);
  310. $num=$num1[0]->num + $num2[0]->num;
  311. // return $num[0]->num;
  312. // $num=1;
  313. // $num=1;
  314. Render($num,1);
  315. }
  316. //新增:2018-12-06 Anton liu
  317. public function getHomeMsg(){
  318. $user_id = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  319. //获取最新首页弹出消息
  320. $msg = lm('message','Commons')
  321. ->where('type','=',3)
  322. ->where('is_show','=',1)
  323. ->orderBy('add_time','desc')
  324. ->first();
  325. if($msg){
  326. //查看是否已读
  327. $read = lm('message_read','Commons')
  328. ->where('message_id','=',$msg->id)
  329. ->where('account_identity','=',$user_id)
  330. ->first();
  331. if($read){
  332. Render('',-1);
  333. }else{
  334. Render($msg->toArray(),1);
  335. }
  336. }else{
  337. Render('',-1);
  338. }
  339. }
  340. function AllMessageOne(){
  341. $admin_id= isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  342. $admin_name= isset($_SESSION['uinfo']['account']) ? $_SESSION['uinfo']['account'] : '';
  343. $group_code=isset($_SESSION['uinfo']['group_code'])?$_SESSION['uinfo']['group_code']:0;
  344. $timed=lm('account_detailed','Commons')->where('account_identity',$admin_id)->first();
  345. $group_code_arr=explode(',',$group_code);
  346. array_pop($group_code_arr);//删除最后一个空元素
  347. $lenth=count($group_code_arr);
  348. $time=$timed['last_time'];
  349. $register_time=$timed['register_time'];
  350. $sql="SELECT * FROM message where message.type = 3 and ((add_time > '$register_time' AND message.add_type
  351. = '2') or add_type='1' ) ";
  352. if(is_array($group_code_arr)&&$lenth>0){
  353. $sql.=" and (";
  354. foreach ($group_code_arr as $k=> $v){
  355. $sql.= " group_code LIKE '%,".$v.",%' or";
  356. }
  357. $sql.=" toname = 'all')";
  358. }
  359. $sql.=" and id not in ( SELECT message_id from message_read WHERE account_identity = '$admin_id' GROUP BY message_id) order by add_time desc";
  360. $sqlone="SELECT * FROM message WHERE type = 1 and toname = '$admin_name' and id not in (SELECT message_id from message_read WHERE account_identity = '" . $admin_id . "' GROUP BY message_id) order by add_time desc ";
  361. $sqltwo="SELECT * FROM message WHERE add_time > '$time' and type = 2 and toname = '$admin_name' and id not in( SELECT message_id from message_read WHERE account_identity = '" . $admin_id . "' GROUP BY message_id) order by add_time desc ";
  362. $datas=S('DB')->select($sql);
  363. $dataone=S('DB')->select($sqlone);
  364. $datatwo=S('DB')->select($sqltwo);
  365. if(empty($datas)){
  366. $data= array_merge($dataone,$datas);
  367. }
  368. if(empty($dataone)){
  369. $data= array_merge($datas,$dataone);
  370. }
  371. if(empty($dataone) && empty($datas)){
  372. $datadd= [];
  373. }
  374. if(!empty($dataone) && !empty($datas)){
  375. $data= array_merge($datas,$dataone);
  376. }
  377. if (!empty($data)){
  378. $i=0;
  379. foreach ($data as $v){
  380. $dataddd[$v->id]=$v;
  381. }
  382. krsort($dataddd);
  383. foreach ($dataddd as $vv){
  384. $datadd[$i]=$vv;
  385. $i++;
  386. }
  387. }
  388. $sql = "SELECT count(*) as num FROM message WHERE message.type = 3 and ((add_time > '$register_time' AND message.add_type = '2') or add_type='1' )";
  389. if(is_array($group_code_arr)&&$lenth>0){
  390. $sql.=" and (";
  391. foreach ($group_code_arr as $k=> $v){
  392. $sql.= " group_code LIKE '%,".$v.",%' or";
  393. }
  394. $sql.=" toname = 'all')";
  395. }
  396. $sql.=" and id not in( SELECT message_id from message_read WHERE account_identity = '" . $admin_id . "' GROUP BY message_id)";
  397. $sqls = "SELECT count(*) as num FROM message WHERE type = 1 and toname = '$admin_name' and id not in( SELECT message_id from message_read WHERE account_identity = '" . $admin_id . "' GROUP BY message_id)";
  398. $num1=S('DB')->select($sql);
  399. $num2=S('DB')->select($sqls);
  400. $num=$num1[0]->num + $num2[0]->num;
  401. $datas=[
  402. 'dataone'=>$datadd,
  403. 'datatwo'=>$datatwo,
  404. 'data'=>$num,
  405. ];
  406. return $datas;
  407. }
  408. function AllMessagetwo(){
  409. $admin_id= isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  410. $time=lm('account_detailed','Commons')->where('account_identity',$admin_id)->first();
  411. $time=$time['last_time'];
  412. $admin_name= isset($_SESSION['uinfo']['account']) ? $_SESSION['uinfo']['account'] : '';
  413. $sql="select *,(select count(id) from message_read where message_id=message.id and account_identity = '{$admin_id}' ) as hasread from message where add_time > '$time' and type = 2 and toname = '$admin_name' order by add_time desc ";
  414. $data=S('DB')->select($sql);
  415. // $pagedata=$pagedata[0]['num']/$num;
  416. // dump();
  417. return array('data'=>$data);
  418. }
  419. function AllMessage(){
  420. $page=isset($_POST['page'])?intval($_POST['page']):'';
  421. $type=isset($_POST['type'])?intval($_POST['type']):"";
  422. $num=20;
  423. $admin_id= isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  424. $admin_name= isset($_SESSION['uinfo']['account']) ? $_SESSION['uinfo']['account'] : '';
  425. $account_group=isset($_SESSION['uinfo']['group_code'])?$_SESSION['uinfo']['group_code']:'';
  426. $group_code_arr=explode(',',$account_group);
  427. array_pop($group_code_arr);//删除最后一个空元素
  428. $lenth=count($group_code_arr);
  429. $timed=lm('account_detailed','Commons')->where('account_identity',$admin_id)->first();
  430. $register_time=$timed['register_time'];
  431. if (!empty($type)){
  432. $pagedata=lm('message','Commons')->where('type',3)->count();
  433. $nums=ceil($pagedata/$num);
  434. if ($page > $nums){
  435. $page= $nums;
  436. }elseif ($page == 0){
  437. $page=1;
  438. }
  439. $sql="select *,(select count(id) from message_read where message_id=message.id and account_identity = '{$admin_id}' ) as hasread from message where type = {$type} and message.type = 3 and message.id in (select message_id from message_read where status=1)";
  440. if(is_array($group_code_arr)&&$lenth>0){
  441. $sql.=" and (";
  442. foreach ($group_code_arr as $v){
  443. $sql.=" group_code like '%,".$v.",%' or";
  444. }
  445. $sql.=" toname ='all' )";
  446. }
  447. $sql.=" and id not in (select message_id from message_read where status=-1 and account_identity = '{$admin_id}') and ((add_time > '$register_time' AND message.add_type = '2') or add_type='1') order by add_time desc limit {$num} offset ".(($page-1)*$num);
  448. }else{
  449. // $pagedata=lm('message','Commons')->where('type',1)->where('toname',$admin_name)->count();
  450. $sqls="select count(*) as num from message where (type = 3 or (type = 1 and toname = '$admin_name')) and id not in (select message_id from message_read where status=-1 and account_identity = '{$admin_id}') ";
  451. $pagedata=S('DB')->select($sqls);
  452. $nums=ceil($pagedata[0]->num/$num);
  453. if ($page > $nums){
  454. $page= $nums;
  455. }elseif ($page == 0){
  456. $page=1;
  457. }
  458. $sql="select *,(select count(id) from message_read where message_id=message.id and account_identity = '{$admin_id}' ) as hasread from message where message.type = 3";
  459. if(is_array($group_code_arr)&&$lenth>0){
  460. $sql.=" and (";
  461. foreach ($group_code_arr as $v){
  462. $sql.=" group_code like '%,".$v.",%' or ";
  463. }
  464. $sql.=" toname = 'all')";
  465. }
  466. $sql.=" and id not in (select message_id from message_read where status=-1 and account_identity = '{$admin_id}') and ((add_time > '$register_time' AND message.add_type
  467. = '2') or add_type='1') or (type = 1 and toname = '$admin_name') order by add_time desc limit {$num} offset ".(($page-1)*$num);
  468. }
  469. $data=S('DB')->select($sql);
  470. $data = json_decode(json_encode($data),1);
  471. $new = $data;
  472. return array('data'=>$new,'cont'=>$pagedata,'page'=>$page);
  473. }
  474. function AllMessageModel(){
  475. $page=isset($_POST['page'])?intval($_POST['page']):1;
  476. $type=isset($_POST['type'])?intval($_POST['type']):"";
  477. $num=10;
  478. $pagedata=lm('message','Commons')->count();
  479. $admin_name= isset($_SESSION['uinfo']['account']) ? $_SESSION['uinfo']['account'] : '';
  480. $admin_id= isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  481. $timed=lm('account_detailed','Commons')->where('account_identity',$admin_id)->first();
  482. $group_codes=$timed['group_code'];
  483. $group_codes_arr=explode(',',$group_codes);
  484. array_pop($group_codes_arr);
  485. $len=count($group_codes_arr);
  486. $register_time=$timed['register_time'];
  487. if (!empty($type)){
  488. $sql="select *,(select count(id) from message_read where message_id=message.id and account_identity = '{$admin_id}' ) as hasread from message where type = {$type} and message.type = 3 ";
  489. if(is_array($group_codes_arr)&&$len>0){
  490. $sql.=" and (";
  491. foreach ($group_codes_arr as $v){
  492. $sql.=" group_code like '%,".$v.",%' or ";
  493. }
  494. $sql.=" toname = 'all')";
  495. }
  496. $sql.=" and id not in (select message_id from message_read where status=-1 and account_identity = '{$admin_id}') and ((add_time > '$register_time' AND message.add_type= '2') or add_type='1') order by add_time desc limit {$num} offset ".(($page-1)*$num);
  497. }else{
  498. $sql="select *,(select count(id) from message_read where message_id=message.id and account_identity = '{$admin_id}' ) as hasread from message where (type = 3 or (type = 1 and toname = '$admin_name')) and id not in (select message_id from message_read where status=-1 and account_identity = '{$admin_id}')";
  499. if(is_array($group_codes_arr)&&$len>0){
  500. $sql.=" and (";
  501. foreach ($group_codes_arr as $v){
  502. $sql.=" group_code like '%,".$v.",%' or ";
  503. }
  504. $sql.=" toname = 'all')";
  505. }
  506. $sql.=" and id not in (select message_id from message_read where status=-1 and account_identity = '{$admin_id}') and ((add_time > '$register_time' AND message.add_type
  507. = '2') or add_type='1') or (type = 1 and toname = '$admin_name') order by add_time desc limit {$num} offset ".(($page-1)*$num);
  508. }
  509. $data=S('DB')->select($sql);
  510. // if($data){
  511. // foreach ($data as $k=>$v){
  512. // $data_t[$k]['title']=$v->title;
  513. // $data_t[$k]['content']=$v->content;
  514. // $data_t[$k]['type']=$v->type;
  515. // $data_t[$k]['formname']=$v->formname;
  516. // $data_t[$k]['toname']=$v->toname;
  517. // $data_t[$k]['add_time']=$v->add_time;
  518. // $data_t[$k]['id']=$v->id;
  519. // $data_t[$k]['status']=$v->status;
  520. // $data_t[$k]['message_type']=$v->message_type;
  521. // $data_t[$k]['hasread']=$v->hasread;
  522. //// $data_t[$k]['desc']=substr(strip_tags($data_t[$k]['content']),0,100);
  523. // }
  524. // }
  525. // $pagedata=$pagedata[0]['num']/$num;
  526. // dump();
  527. //return array('data'=>$data_t,'cont'=>$pagedata,'page'=>$page);exit;
  528. // return Render(array('data'=>$data_t,'cont'=>$pagedata,'page'=>$page),1);
  529. return Render($data);
  530. }
  531. //消息列表
  532. public function MessageList()
  533. {
  534. $limit = isset($_GET['limit']) ? $_GET['limit'] : '10';
  535. $title =isset($_GET['title']) ? $_GET['title'] : '';
  536. $message_type = isset($_GET['message_type']) ? $_GET['message_type'] : '';
  537. $type = isset($_GET['type']) ? $_GET['type'] : '';
  538. $user_name = isset($_SESSION['uinfo']['account']) ? $_SESSION['uinfo']['account'] : '';
  539. $where = array();
  540. $wheres = array();
  541. if (!empty($title)) {
  542. $where[] = array('title', 'like', '%' . $title . '%');
  543. $wheres[] = array('title', 'like', '%' . $title . '%');
  544. }
  545. if (empty($type)) {
  546. $where[] = array('type', '!=', '4');
  547. $where[] = array('type', '!=', '2');
  548. $wheres[] = array('type', 'in', '2');
  549. $wheres[] = array('toname', '=', $user_name);
  550. }
  551. if (empty($message_type)) {
  552. $where[] = array('message_type', '=', '2');
  553. $wheres[] = array('message_type', '=', '2');
  554. }
  555. $data1 = $this->getlist($limit, $where);
  556. $data2 = $this->getlist($limit, $wheres);
  557. if (!empty($data1) || !empty($data2)){
  558. $data=array_merge($data1,$data2);
  559. }elseif (empty($data1)){
  560. $data=$data2;
  561. }elseif (empty($data2)){
  562. $data=$data1;
  563. }else{
  564. $data ="";
  565. }
  566. $admin_id= isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  567. $datas=$this->getlistd($admin_id);
  568. if (!empty($datas)){
  569. foreach ($data as $k=>$v){
  570. foreach ($datas as $vv){
  571. if($vv['type'] == '1' && $v['id'] == $vv['message_id']){
  572. $data[$k]['message_type']='1';
  573. }
  574. }
  575. }
  576. foreach ($data as $k=>$v){
  577. if($v['message_type'] == '2'){
  578. $dat[$k]=$v;
  579. }
  580. }
  581. if (!empty($dat)){
  582. $data= $dat;
  583. }else{
  584. $data="";
  585. }
  586. }
  587. if (!empty($data)) {
  588. foreach ($data as $k=>$v){
  589. foreach ($datas as $val){
  590. if ($v['id'] == $val['message_id'] && $val['type'] == '3'){
  591. $data[$k]['status']='3';
  592. }elseif ($v['id'] == $val['message_id']){
  593. $data[$k]['status']='1';
  594. }
  595. }
  596. }
  597. }
  598. return $data;
  599. }
  600. //已读消息
  601. public function Tmessage()
  602. {
  603. $id = isset($_POST['id']) ? $_POST['id'] : '';
  604. $admin_id=isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  605. $dataWhwew=[
  606. 'type'=>'2',
  607. ];
  608. $data= $this->MessageUp($id,$admin_id,$dataWhwew);
  609. return $data;
  610. }
  611. //是否弹出消息
  612. public function MessageRed()
  613. {
  614. $id = isset($_POST['id']) ? $_POST['id'] : '';
  615. $admin_id=isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  616. $dataWhwew=[
  617. 'message_id'=>$id,
  618. 'account_identity'=>$admin_id,
  619. 'add_time'=>date("Y-m-d H:i",time())
  620. ];
  621. $dataRead = $this->Messagelista($id,$admin_id);
  622. if ($dataRead < 0){
  623. $dataRead = $this->addMessage($dataWhwew);
  624. }
  625. return $dataRead;
  626. }
  627. //消息详情
  628. public function MessageL()
  629. {
  630. $id = isset($_POST['id']) ? $_POST['id'] : '';
  631. $dataRead = $this->MessagelistaL($id);
  632. if ($dataRead < 0){
  633. return -6030001222;
  634. }
  635. return $dataRead;
  636. }
  637. //添加消息数据
  638. function addMessage($data)
  639. {
  640. $res = lm('message_read','Commons')->insert($data);
  641. if (!$res) {
  642. return -6030001222;
  643. }
  644. return 1;
  645. }
  646. //查询一条数据
  647. function MessagelistaL($id)
  648. {
  649. $res = lm('message','Commons')->where('id',$id)->first();
  650. if (!$res) {
  651. return -6030001222;
  652. }
  653. return $res;
  654. }
  655. //查询一条数据
  656. function MessageUp($id,$admin_id,$data)
  657. {
  658. $res = lm('message_read','Commons')->where('message_id', $id)->where('account_identity', $admin_id)->update($data);
  659. if (!$res) {
  660. return -6030001222;
  661. }
  662. return $res;
  663. }
  664. function getlist($list = 10, $where = '') {
  665. $data = lm('message', 'Commons')->orderBy('add_time', 'desc');
  666. if (!empty($where) && is_array($where)) {
  667. $data = $data->where($where)->get();
  668. }
  669. if (!$data) {
  670. return -4010010022; //没有数据
  671. }
  672. return $data->toArray();
  673. }
  674. //查询消息
  675. function Messagelista($id, $admin_id)
  676. {
  677. $data = lm('message_read', 'Commons')->where('message_id', $id)->where('account_identity', $admin_id)->first();
  678. if (!$data) {
  679. return -4010010022; //没有数据
  680. }
  681. return 1;
  682. }
  683. function getlistd($id)
  684. {
  685. $data = lm('message_read', 'Commons')->where('account_identity', $id)->get();
  686. if (!$data) {
  687. return -4010010022; //没有数据
  688. }
  689. return $data->toArray();
  690. }
  691. //代理开关
  692. public function AgentList() {
  693. $data = lm('setinfo', 'Commons')->where('infotype', 13)->first();
  694. if ($data) {
  695. $data = $data->toArray();
  696. Render($data, 1, lang()->get('success'));
  697. } else {
  698. Render('', '-5001', lang('error')->get('-5001'));
  699. }
  700. }
  701. /**
  702. * 客服qq链接
  703. */
  704. public function GetQQ() {
  705. $info = lm('setinfo', 'commons')->where('infotype', 16)->first();
  706. if (!$info) {
  707. Render('', '-5006', lang('error')->get('-5006'));
  708. }
  709. $data['url'] = 'http://wpa.qq.com/msgrd?v=3&uin=' . $info->infocontent . '&site=qq&menu=yes';
  710. $data['wapurl'] = 'mqqwpa://im/chat?chat_type=wpa&uin=' . $info->infocontent . '&version=1';
  711. $data['iosurl'] = 'mqq://im/chat?chat_type=wpa&uin=' . $info->infocontent . '&version=1&src_type=web';
  712. $data['qq'] = $info->infocontent;
  713. Render($data, 1);
  714. }
  715. /**
  716. * 联系我们客服信息
  717. */
  718. public function GetConinfo() {
  719. $info = lm('setinfo', 'commons')->where('infotype', 1017)->get();
  720. if (!$info) {
  721. Render('', '-5006', lang('error')->get('-5006'));
  722. }
  723. $data = array();
  724. foreach ($info as $k => $v) {
  725. $data[$v['remarks']] = $v['infocontent'];
  726. }
  727. //新增图片服务器地址
  728. $img = lm('setinfo', 'commons')->where('infotype', 2004)->first();
  729. $data['imgserver'] = $img['infocontent'];
  730. Render($data, 1);
  731. }
  732. /**
  733. * 银行列表
  734. */
  735. public function BankList() {
  736. $bank = lm('band_bank', 'commons')->select('bank_name')->get();
  737. if (!$bank) {
  738. Render('', -5001, lang('error')->get('-5001'));
  739. }
  740. Render($bank->toArray(), 1);
  741. }
  742. public function DelMessageRed(){
  743. $id = isset($_POST['id']) ? $_POST['id'] : '';
  744. $admin_id=isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  745. $dataWhwew=[
  746. 'status'=>'-1',
  747. ];
  748. $ids = explode(',', $id);
  749. if (!is_array($ids) && intval($ids) < 0) {
  750. return -2002;
  751. }
  752. if (is_array($ids) && count($ids) > 0) {
  753. foreach ($ids as $k => $v) {
  754. if (intval($v) < 1) {
  755. unset($ids[$k]);
  756. }
  757. }
  758. }
  759. $res = lm('message','Commons')->whereIn('id',$ids)->first();
  760. if ($res['type'] == 1 ) {
  761. $data = lm('message','Commons')->whereIn('id',$ids)->delete();
  762. }else{
  763. $data= $this->DelMessageUp($ids,$admin_id,$dataWhwew);
  764. }
  765. return $data;
  766. }
  767. function DelMessageUp($id,$admin_id,$data)
  768. {
  769. $res = lm('message_read','Commons')->whereIn('message_id', $id)->where('account_identity', $admin_id)->update($data);
  770. if (!$res) {
  771. return -6030001222;
  772. }
  773. return $res;
  774. }
  775. function GetPageSet(){
  776. $data = lm('setinfo', 'commons')->where('infotype', 1024)->first();
  777. if (!$data) {
  778. Render('', '-5006', lang('error')->get('-5006'));
  779. }
  780. $data = $data->toArray();
  781. Render($data, 1,'获取信息成功');
  782. }
  783. }