AjaxController.class.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. <?php
  2. namespace Mobile\Controller;
  3. class AjaxController extends MobileController
  4. {
  5. protected function _initialize()
  6. {
  7. parent::_initialize();
  8. $allow_action=array("getJsonMenu","upimgs","allfinance","allsum","allcoin","trends","getJsonTop","getTradelog","getDepth","getEntrustAndUsercoin","getChat","upChat","upcomment","subcomment","getJsonMobile","top_coin_menu","allcoin_a");
  9. if(!in_array(ACTION_NAME,$allow_action)){
  10. $this->error(L("非法操作!"));
  11. }
  12. }
  13. public function getJsonMenu($ajax = 'json')
  14. {
  15. $data = (APP_DEBUG ? null : S('getJsonMenu'));
  16. if (!$data) {
  17. foreach (C('market') as $k => $v) {
  18. $v['xnb'] = explode('_', $v['name'])[0];
  19. $v['rmb'] = explode('_', $v['name'])[1];
  20. $data[$k]['name'] = $v['name'];
  21. $data[$k]['img'] = $v['xnbimg'];
  22. $data[$k]['title'] = $v['title'];
  23. }
  24. S('getJsonMenu', $data);
  25. }
  26. if ($ajax) {
  27. exit(json_encode($data));
  28. } else {
  29. return $data;
  30. }
  31. }
  32. //上传用户身份证
  33. public function upimgs()
  34. {
  35. if (!userid()) {
  36. echo "nologin";
  37. }
  38. $upload = new \Think\Upload();
  39. $upload->maxSize = 3145728;
  40. $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
  41. $upload->rootPath = './Upload/payimg/';
  42. $upload->autoSub = false;
  43. $info = $upload->upload();
  44. foreach ($info as $k => $v) {
  45. $path = $v['savepath'] . $v['savename'];
  46. echo $path;
  47. exit();
  48. }
  49. }
  50. /** 自定义分区查询 改.HAOMA20181030 **/
  51. public function allcoin_a($id=1,$ajax = 'json')
  52. {
  53. //$data = (APP_DEBUG ? null : S('trandata_allcoin'));
  54. $trandata_data = array();
  55. $trandata_data['info'] = L("数据异常");
  56. $trandata_data['status'] = 0;
  57. $trandata_data['url'] = "";
  58. // 市场交易记录
  59. $marketLogs = array();
  60. foreach (C('market') as $k => $v) {
  61. $_tmp = null;
  62. if (!empty($_tmp)) {
  63. $marketLogs[$k] = $_tmp;
  64. } else {
  65. $tradeLog = M('TradeLog')->where(array('status' => 1, 'market' => $k))->order('id desc')->limit(50)->select();
  66. $_data = array();
  67. foreach ($tradeLog as $_k => $v) {
  68. $_data['tradelog'][$_k]['addtime'] = date('m-d H:i:s', $v['addtime']);
  69. $_data['tradelog'][$_k]['type'] = $v['type'];
  70. $_data['tradelog'][$_k]['price'] = $v['price'] * 1;
  71. $_data['tradelog'][$_k]['num'] = round($v['num'], 6);
  72. $_data['tradelog'][$_k]['mum'] = round($v['mum'], 2);
  73. }
  74. $marketLogs[$k] = $_data;
  75. S('getTradelog' . $k, $_data);
  76. }
  77. }
  78. $volume_24h = array();
  79. $tradeAmount_24h = array();
  80. if ($marketLogs) {
  81. foreach (C('market') as $k => $v) {
  82. $_tradeLogs['num'] = M('TradeLog')->where(array(
  83. 'status' => 1,
  84. 'market' => $k,
  85. 'addtime' => array('gt', time() - (60 * 60 * 24))
  86. ))->sum('num');
  87. $_tradeLogs['mum'] = M('TradeLog')->where(array(
  88. 'status' => 1,
  89. 'market' => $k,
  90. 'addtime' => array('gt', time() - (60 * 60 * 24))
  91. ))->sum('mum');
  92. if ($_tradeLogs) {
  93. $volume_24h[$k] = round($_tradeLogs['num'], 4); // 24小时 交易量
  94. $tradeAmount_24h[$k] = round($_tradeLogs['mum'], 4); // 24小时 交易额
  95. }
  96. }
  97. }
  98. if (!$data) {
  99. $trandata_data['info']=L("数据正常");
  100. $trandata_data['status']=1;
  101. $trandata_data['url']="";
  102. foreach (C('market') as $k => $v) {
  103. if ($v['jiaoyiqu'] == $id) {
  104. $xnb = strtoupper(explode('_', $v['name'])[0]);
  105. $market = strtoupper(explode('_', $v['name'])[1]);
  106. //币种简称
  107. $trandata_data['url'][$k][0] = $xnb;
  108. //币种市场
  109. $trandata_data['url'][$k][1] = $market;
  110. //最新成交价
  111. $trandata_data['url'][$k][2] = round($v['new_price'], $v['round']);
  112. //买一价
  113. $trandata_data['url'][$k][3] = round($v['buy_price'], $v['round']);
  114. //卖一价
  115. $trandata_data['url'][$k][4] = round($v['sell_price'], $v['round']);
  116. //交易额
  117. $trandata_data['url'][$k][5] = isset($tradeAmount_24h[$k]) ? $tradeAmount_24h[$k] : 0;//round($v['volume'] * $v['new_price'], 2) * 1;
  118. $trandata_data['url'][$k][6] = '';
  119. //交易量
  120. $trandata_data['url'][$k][7] = isset($volume_24h[$k]) ? $volume_24h[$k] : 0;//round($v['volume'], 4) * 1;
  121. //涨跌幅
  122. $trandata_data['url'][$k][8] = round($v['change'], 2);
  123. //链接专用
  124. $trandata_data['url'][$k][9] = $v['name'];
  125. //图图标地址
  126. $trandata_data['url'][$k][10] = $v['xnbimg'];
  127. //最高价
  128. $trandata_data['url'][$k][11] = round($v['max_price'], $v['round']);
  129. //最低价
  130. $trandata_data['url'][$k][12] = round($v['min_price'], $v['round']);
  131. $rmbs = 0;
  132. $market = explode('_', $v['name'])[1];
  133. if ($market==Anchor_CNY) { //锚定法币
  134. $rmbs = bcdiv($v['new_price'] * C('MYCOIN'),1,$v['round']) * 1;
  135. }
  136. if ($market=='btc') {
  137. //$rmbs = round($v['info']['new_price'] * C('BTC'),2);
  138. $rmbs = bcdiv($v['new_price'] * C('market')['btc_'.Anchor_CNY]['new_price'],1,$v['round']) * 1;
  139. }
  140. if ($market=='eth') {
  141. //$rmbs = NumToStr(round($v['info']['new_price'] * C('market')['eth_'.Anchor_CNY]['new_price']),6);
  142. $rmbs = bcdiv($v['new_price'] * C('market')['eth_'.Anchor_CNY]['new_price'],1,$v['round']) * 1;
  143. }
  144. if ($market=='usdt') {
  145. $rmbs = bcdiv($v['new_price'] * C('market')['usdt_'.Anchor_CNY]['new_price'],1,$v['round']) * 1;
  146. }
  147. if ($market=='mob') {
  148. $rmbs = bcdiv($v['new_price'] * C('market')['mob_'.Anchor_CNY]['new_price'],1,$v['round']) * 1;
  149. }
  150. $trandata_data['url'][$k][14] = $rmbs;
  151. }
  152. }
  153. }
  154. if ($ajax) {
  155. echo json_encode($trandata_data);
  156. unset($trandata_data);
  157. exit();
  158. } else {
  159. return $trandata_data;
  160. }
  161. }
  162. public function index_b_trends($ajax = 'json')
  163. {
  164. $data = (APP_DEBUG ? null : S('trends'));
  165. if (!$data) {
  166. foreach (C('market') as $k => $v) {
  167. $tendency = json_decode($v['tendency'], true);
  168. $data[$k]['data'] = $tendency;
  169. $data[$k]['yprice'] = $v['new_price'];
  170. }
  171. S('trends', $data);
  172. }
  173. if ($ajax) {
  174. exit(json_encode($data));
  175. } else {
  176. return $data;
  177. }
  178. }
  179. public function allfinance($ajax = 'json')
  180. {
  181. if (!userid()) {
  182. return false;
  183. }
  184. $UserCoin = M('UserCoin')->where(array('userid' => userid()))->find();
  185. $cny['zj'] = 0;
  186. foreach (C('coin') as $k => $v) {
  187. if ($v['name'] == 'cny') {
  188. $cny['ky'] = $UserCoin[$v['name']] * 1;
  189. $cny['dj'] = $UserCoin[$v['name'] . 'd'] * 1;
  190. $cny['zj'] = $cny['zj'] + $cny['ky'] + $cny['dj'];
  191. } else {
  192. if (C('market')[$v['name'] . '_cny']['new_price']) {
  193. $jia = C('market')[$v['name'] . '_cny']['new_price'];
  194. } else {
  195. $jia = 1;
  196. }
  197. $cny['zj'] = round($cny['zj'] + (($UserCoin[$v['name']] + $UserCoin[$v['name'] . 'd']) * $jia), 2) * 1;
  198. }
  199. }
  200. $data = round($cny['zj'], 8);
  201. // $data = NumToStr($data);
  202. $data = number_format($data,2);//千分位显示
  203. if ($ajax) {
  204. exit(json_encode($data));
  205. } else {
  206. return $data;
  207. }
  208. }
  209. public function allsum($ajax = 'json')
  210. {
  211. $data = (APP_DEBUG ? null : S('allsum'));
  212. if (!$data) {
  213. $data = M('TradeLog')->sum('mum');
  214. S('allsum', $data);
  215. }
  216. $data = round($data);
  217. $data = str_repeat('0', 12 - strlen($data)) . (string) $data;
  218. if ($ajax) {
  219. exit(json_encode($data));
  220. } else {
  221. return $data;
  222. }
  223. }
  224. public function allcoin($ajax = 'json')
  225. {
  226. $data = (APP_DEBUG ? null : S('allcoin'));
  227. if (!$data) {
  228. foreach (C('market') as $k => $v) {
  229. $data[$k][0] = $v['title'];
  230. $data[$k][1] = round($v['new_price'], $v['round']);
  231. $data[$k][2] = round($v['buy_price'], $v['round']);
  232. $data[$k][3] = round($v['sell_price'], $v['round']);
  233. $data[$k][4] = round($v['volume'] * $v['new_price'], 2) * 1;
  234. $data[$k][5] = '';
  235. $data[$k][6] = round($v['volume'], 2) * 1;
  236. $data[$k][7] = round($v['change'], 2);
  237. $data[$k][8] = $v['name'];
  238. $data[$k][9] = $v['xnbimg'];
  239. $data[$k][10] = '';
  240. }
  241. S('allcoin', $data);
  242. }
  243. if ($ajax) {
  244. exit(json_encode($data));
  245. } else {
  246. return $data;
  247. }
  248. }
  249. public function trends($ajax = 'json')
  250. {
  251. $data = (APP_DEBUG ? null : S('trends'));
  252. if (!$data) {
  253. foreach (C('market') as $k => $v) {
  254. $tendency = json_decode($v['tendency'], true);
  255. $data[$k]['data'] = $tendency;
  256. $data[$k]['yprice'] = $v['new_price'];
  257. }
  258. S('trends', $data);
  259. }
  260. if ($ajax) {
  261. exit(json_encode($data));
  262. } else {
  263. return $data;
  264. }
  265. }
  266. public function top_coin_menu($ajax = 'json')
  267. {
  268. $data = (APP_DEBUG ? null : S('trandata_getTopCoinMenu'));
  269. $trandata_getCoreConfig = getCoreConfig();
  270. if(!$trandata_getCoreConfig){
  271. $this->error('核心配置有误');
  272. }
  273. if (!$data) {
  274. $data = array();
  275. foreach($trandata_getCoreConfig['indexcat'] as $k=>$v){
  276. $data[$k][title] = $v;
  277. }
  278. foreach (C('market') as $k => $v) {
  279. $v['xnb'] = explode('_', $v['name'])[0];
  280. $v['rmb'] = explode('_', $v['name'])[1];
  281. $data_tmp['img'] = $v['xnbimg'];
  282. $data_tmp['title'] = $v['navtitle'];
  283. $data[$v['jiaoyiqu']]['data'][$k] = $data_tmp;
  284. unset($data_tmp);
  285. }
  286. S('trandata_getTopCoinMenu', $data);
  287. }
  288. if ($ajax) {
  289. exit(json_encode($data));
  290. } else {
  291. return $data;
  292. }
  293. }
  294. /* public function getJsonTop($market = NULL, $ajax = 'json')
  295. {
  296. // 过滤非法字符----------------S
  297. if (checkstr($market)) {
  298. $this->error(L('您输入的信息有误!'));
  299. }
  300. // 过滤非法字符----------------E
  301. $data = (APP_DEBUG ? null : S('getJsonTop' . $market));
  302. // var_dump( S('getJsonTop' . $market));die;
  303. if (!$data) {
  304. if ($market) {
  305. $xnb = explode('_', $market)[0];
  306. $rmb = explode('_', $market)[1];
  307. foreach (C('market') as $k => $v) {
  308. $v['xnb'] = explode('_', $v['name'])[0];
  309. $v['rmb'] = explode('_', $v['name'])[1];
  310. $data['list'][$k]['name'] = $v['name'];
  311. $data['list'][$k]['img'] = $v['xnbimg'];
  312. $data['list'][$k]['title'] = $v['title'];
  313. $data['list'][$k]['new_price'] = $v['new_price'];
  314. }
  315. $data['info']['img'] = C('market')[$market]['xnbimg'];
  316. $data['info']['title'] = C('market')[$market]['title'];
  317. $data['info']['new_price'] = C('market')[$market]['new_price'];
  318. $data['info']['max_price'] = C('market')[$market]['max_price'];
  319. $data['info']['min_price'] = C('market')[$market]['min_price'];
  320. $data['info']['buy_price'] = C('market')[$market]['buy_price'];
  321. $data['info']['sell_price'] = C('market')[$market]['sell_price'];
  322. $data['info']['volume'] = C('market')[$market]['volume'];
  323. $data['info']['change'] = C('market')[$market]['change'];
  324. //以下是本地测试,或者其他使用
  325. if($market['jiaoyiqu']==0){//交易区0为usdt
  326. $data['info']['rmb'] = round(C('market')[$market]['new_price']*C('usdt'),2);
  327. }
  328. if($market['jiaoyiqu']==1){//交易区1为USDT
  329. $data['info']['rmb'] = round(C('market')[$market]['new_price']*C('btc'),2);
  330. }
  331. if($market['jiaoyiqu']==2){//交易区2为ETH
  332. $data['info']['rmb'] = round(C('market')[$market]['new_price']*C('eth'),2);
  333. }
  334. if($market['jiaoyiqu']==3){//交易区0为自己的币种
  335. $data['info']['rmb'] = round(C('market')[$market]['new_price']*C('mycoin'),2);
  336. }
  337. S('getJsonTop' . $market, $data);
  338. }
  339. }
  340. if ($ajax) {
  341. exit(json_encode($data));
  342. } else {
  343. return $data;
  344. }
  345. }*/
  346. // 交易中心调用
  347. public function getJsonTop($market = NULL, $ajax = 'json')
  348. {
  349. // 过滤非法字符----------------S
  350. if (checkstr($market)) {
  351. $this->error('您输入的信息有误!');
  352. }
  353. // 过滤非法字符----------------E
  354. $data = (APP_DEBUG ? null : S("getJsonTop" . $market));
  355. if (!$data) {
  356. if ($market) {
  357. $xnb = explode("_", $market)[0];
  358. $rmb = explode("_", $market)[1];
  359. // 24小时 交易量
  360. $volume_24h = 0;
  361. $volume_24h = M('TradeLog')->where(array(
  362. 'market' => $market,
  363. 'addtime' => array('gt', time() - (60 * 60 * 24))
  364. ))->sum('num');
  365. $volume_24h = round($volume_24h, 4);
  366. /* foreach (C("market") as $k => $v) {
  367. $v["xnb"] = explode("_", $v["name"])[0];
  368. $v["rmb"] = explode("_", $v["name"])[1];
  369. $data["list"][$k]["name"] = $v["name"];
  370. $data["list"][$k]["img"] = $v["xnbimg"];
  371. $data["list"][$k]["title"] = $v["title"];
  372. $data["list"][$k]["new_price"] = $v["new_price"];
  373. $data["list"][$k]["change"] = $v["change"];
  374. $data["list"][$k]['coin_name'] = strtoupper($v["xnb"]);
  375. }*/
  376. $data["info"]["img"] = C("market")[$market]["xnbimg"];
  377. $data["info"]["title"] = C("market")[$market]["title"];
  378. $data["info"]["new_price"] = C("market")[$market]["new_price"];
  379. $data["info"]["max_price"] = C("market")[$market]["max_price"];
  380. $data["info"]["min_price"] = C("market")[$market]["min_price"];
  381. $data["info"]["buy_price"] = C("market")[$market]["buy_price"];
  382. $data["info"]["sell_price"] = C("market")[$market]["sell_price"];
  383. $data["info"]["volume"] = isset($volume_24h) ? $volume_24h : 0;//C("market")[$market]["volume"];
  384. $data["info"]["change"] = C("market")[$market]["change"];
  385. S("getJsonTop" . $market, $data);
  386. }
  387. }
  388. if ($ajax) {
  389. exit(json_encode($data));
  390. } else {
  391. return $data;
  392. }
  393. }
  394. public function getJsonMobile($market = NULL, $ajax = 'json')
  395. {
  396. // $data = (APP_DEBUG ? null : S('getJsonMobile' . $market));
  397. // var_dump( S('getJsonMobile' . $market));die;
  398. // var_dump(C('market'));die;
  399. foreach (C('market') as $k => $v) {
  400. $v['xnb'] = explode('_', $v['name'])[0];
  401. $v['rmb'] = explode('_', $v['name'])[1];
  402. // $data[$k] = $k;
  403. $data[$k]['name'] = $v['xnb'];
  404. // $data[$k]['name'] = $v['name'];
  405. // $data[$k]['img'] = $v['xnbimg'];
  406. // $data[$k]['title'] = $v['title'];
  407. $data[$k]['new_price'] = $v['new_price'];
  408. $data[$k]['max_price'] = $v['max_price'];
  409. $data[$k]['min_price'] = $v['min_price'];
  410. $data[$k]['buy_price'] = $v['buy_price'];
  411. $data[$k]['sell_price'] = $v['sell_price'];
  412. $data[$k]['volume'] = round( $v['volume'],2);
  413. $data[$k]['change'] = $v['change'];
  414. $data[$k]['cje'] =round($v['volume'] * $v['new_price'], 2);
  415. if ($data[$k]['volume'] > 10000 && $data[$k]['volume'] < 100000000) {
  416. $data[$k]['cjl'] = (intval($data[$k]['volume'] / 10000*100)/100) . L("万");
  417. }
  418. if ($data[$k]['volume'] > 100000000) {
  419. $data[$k]['cjl'] = (intval($data[$k]['volume'] / 100000000*100)/100) . L("亿");
  420. }
  421. if ($data[$k]['cje'] > 10000 && $data[$k]['cje'] < 100000000) {
  422. $data[$k]['cje']= (intval($data[$k]['cje'] / 10000*100)/100) . L("万");
  423. }
  424. if ($data[$k]['cje'] > 100000000) {
  425. $data[$k]['cje'] = (intval($data[$k]['cje'] / 100000000*100)/100) . L("亿");
  426. }
  427. }
  428. // var_dump($data);die;
  429. // $data['info']['img'] = C('market')[$market]['xnbimg'];
  430. // $data['info']['title'] = C('market')[$market]['title'];
  431. // $data['info']['new_price'] = C('market')[$market]['new_price'];
  432. // $data['info']['max_price'] = C('market')[$market]['max_price'];
  433. // $data['info']['min_price'] = C('market')[$market]['min_price'];
  434. // $data['info']['buy_price'] = C('market')[$market]['buy_price'];
  435. // $data['info']['sell_price'] = C('market')[$market]['sell_price'];
  436. // $data['info']['volume'] = C('market')[$market]['volume'];
  437. // $data['info']['change'] = C('market')[$market]['change'];
  438. S('getJsonMobile' , $data);
  439. // var_dump($data);die;
  440. if ($ajax) {
  441. exit(json_encode($data));
  442. } else {
  443. // var_dump($data);
  444. return $data;
  445. }
  446. }
  447. public function getTradelog($market = NULL, $ajax = 'json')
  448. {
  449. // 过滤非法字符----------------S
  450. if (checkstr($market)) {
  451. $this->error(L('您输入的信息有误!'));
  452. }
  453. // 过滤非法字符----------------E
  454. $data = (APP_DEBUG ? null : S('getTradelog' . $market));
  455. if (!$data) {
  456. $tradeLog = M('TradeLog')->where(array('status' => 1, 'market' => $market))->order('id desc')->limit(20)->select();
  457. if ($tradeLog) {
  458. foreach ($tradeLog as $k => $v) {
  459. $data['tradelog'][$k]['addtime'] = date('m-d H:i:s', $v['addtime']);
  460. $data['tradelog'][$k]['type'] = $v['type'];
  461. $data['tradelog'][$k]['price'] = $v['price'] * 1;
  462. $data['tradelog'][$k]['num'] = round($v['num'], 6);
  463. $data['tradelog'][$k]['mum'] = round($v['mum'], 6);
  464. }
  465. S('getTradelog' . $market, $data);
  466. }
  467. }
  468. if ($ajax) {
  469. exit(json_encode($data));
  470. } else {
  471. return $data;
  472. }
  473. }
  474. public function getDepth($market = NULL, $trade_moshi = 1,$limts = 5, $ajax = 'json')
  475. {
  476. // 过滤非法字符----------------S
  477. if (checkstr($market) || checkstr($trade_moshi) || checkstr($limts)) {
  478. $this->error(L('您输入的信息有误!'));
  479. }
  480. // 过滤非法字符----------------E
  481. if (!C('market')[$market]) {
  482. return null;
  483. }
  484. $data_getDepth = (APP_DEBUG ? null : S('getDepth'));
  485. if (!$data_getDepth[$market][$trade_moshi]) {
  486. $limt = $limts;
  487. $mo = M();
  488. if ($trade_moshi == 99) {
  489. $buy = $mo->query('select id,price,sum(num-deal)as nums from tw_trade where status=0 and type=1 and market =\'' . $market . '\' group by price order by price desc limit ' . $limt . ';');
  490. $sell = $mo->query('select id,price,sum(num-deal)as nums from tw_trade where status=0 and type=2 and market =\'' . $market . '\' group by price order by price asc limit ' . $limt . ';');
  491. }
  492. if ($trade_moshi == 1) {
  493. $buy = $mo->query('select id,price,sum(num-deal)as nums from tw_trade where status=0 and type=1 and market =\'' . $market . '\' group by price order by price desc limit ' . $limt . ';');
  494. $sell = array_reverse($mo->query('select id,price,sum(num-deal)as nums from tw_trade where status=0 and type=2 and market =\'' . $market . '\' group by price order by price asc limit ' . $limt . ';'));
  495. }
  496. if ($trade_moshi == 3) {
  497. $buy = $mo->query('select id,price,sum(num-deal)as nums from tw_trade where status=0 and type=1 and market =\'' . $market . '\' group by price order by price desc limit ' . $limt . ';');
  498. $sell = null;
  499. }
  500. if ($trade_moshi == 4) {
  501. $buy = null;
  502. $sell = array_reverse($mo->query('select id,price,sum(num-deal)as nums from tw_trade where status=0 and type=2 and market =\'' . $market . '\' group by price order by price asc limit ' . $limt . ';'));
  503. }
  504. if ($buy) {
  505. $maxNums = maxArrayKey($buy, 'nums') / 2;
  506. foreach ($buy as $k => $v) {
  507. $data['depth']['buy'][$k] = array(floatval($v['price'] * 1), floatval($v['nums'] * 1));
  508. $data['depth']['buypbar'][$k] = ((($maxNums < $v['nums'] ? $maxNums : $v['nums']) / $maxNums) * 100);
  509. }
  510. } else {
  511. $data['depth']['buy'] = '';
  512. $data['depth']['buypbar'] = '';
  513. }
  514. if ($sell) {
  515. $maxNums = maxArrayKey($sell, 'nums') / 2;
  516. foreach ($sell as $k => $v) {
  517. $data['depth']['sell'][$k] = array(floatval($v['price'] * 1), floatval($v['nums'] * 1));
  518. $data['depth']['sellpbar'][$k] = ((($maxNums < $v['nums'] ? $maxNums : $v['nums']) / $maxNums) * 100);
  519. }
  520. } else {
  521. $data['depth']['sell'] = '';
  522. $data['depth']['sellpbar'] = '';
  523. }
  524. //print_r($data);
  525. $data_getDepth[$market][$trade_moshi] = $data;
  526. S('getDepth', $data_getDepth);
  527. } else {
  528. $data = $data_getDepth[$market][$trade_moshi];
  529. }
  530. if ($ajax) {
  531. exit(json_encode($data));
  532. } else {
  533. return $data;
  534. }
  535. }
  536. public function getEntrustAndUsercoin($market = NULL, $ajax = 'json')
  537. {
  538. // 过滤非法字符----------------S
  539. if (checkstr($market)) {
  540. $this->error(L('您输入的信息有误!'));
  541. }
  542. // 过滤非法字符----------------E
  543. if (!userid()) {
  544. return null;
  545. }
  546. if (!C('market')[$market]) {
  547. return null;
  548. }
  549. $result = M()->query('select id,price,num,deal,mum,type,fee,status,addtime from tw_trade where status=0 and market=\'' . $market . '\' and userid=' . userid() . ' order by id desc limit 10;');
  550. if ($result) {
  551. foreach ($result as $k => $v) {
  552. $data['entrust'][$k]['addtime'] = date('m-d H:i:s', $v['addtime']);
  553. $data['entrust'][$k]['addtime2'] = date('H:i:s', $v['addtime']);
  554. $data['entrust'][$k]['type'] = $v['type'];
  555. $data['entrust'][$k]['price'] = $v['price'] * 1;
  556. $data['entrust'][$k]['num'] = round($v['num'], 6);
  557. $data['entrust'][$k]['deal'] = round($v['deal'], 6);
  558. $data['entrust'][$k]['id'] = round($v['id']);
  559. }
  560. } else {
  561. $data['entrust'] = null;
  562. }
  563. $userCoin = M('UserCoin')->where(array('userid' => userid()))->find();
  564. if ($userCoin) {
  565. $xnb = explode('_', $market)[0];
  566. $rmb = explode('_', $market)[1];
  567. $data['usercoin']['xnb'] = floatval($userCoin[$xnb]);
  568. $data['usercoin']['xnbd'] = floatval($userCoin[$xnb . 'd']);
  569. $data['usercoin']['cny'] = floatval($userCoin[$rmb]);
  570. $data['usercoin']['cnyd'] = floatval($userCoin[$rmb . 'd']);
  571. } else {
  572. $data['usercoin'] = null;
  573. }
  574. // 处理开盘闭盘交易时间===开始
  575. $times = date('G',time());
  576. $minute = date('i',time());
  577. $minute = intval($minute);
  578. $data['time_state'] = 0;
  579. if (($times <= C('market')[$market]['start_time'] && $minute< intval(C('market')[$market]['start_minute']))|| ( $times > C('market')[$market]['stop_time'] && $minute>= intval(C('market')[$market]['stop_minute'] ))) {
  580. $data['time_state'] = 1;
  581. }
  582. if (($times <C('market')[$market]['start_time'] )|| $times > C('market')[$market]['stop_time']) {
  583. $data['time_state'] = 1;
  584. } else {
  585. if ($times == C('market')[$market]['start_time']) {
  586. if ($minute< intval(C('market')[$market]['start_minute'])) {
  587. $data['time_state'] = 1;
  588. }
  589. } elseif ($times == C('market')[$market]['stop_time']) {
  590. if (($minute > C('market')[$market]['stop_minute'])) {
  591. $data['time_state'] = 1;
  592. }
  593. }
  594. }
  595. // 处理周六周日是否可交易===开始
  596. $weeks = date('N',time());
  597. if(!C('market')[$market]['agree6']){
  598. if($weeks == 6){
  599. $data['time_state'] = 1;
  600. }
  601. }
  602. if(!C('market')[$market]['agree7']){
  603. if($weeks == 7){
  604. $data['time_state'] = 1;
  605. }
  606. }
  607. //处理周六周日是否可交易===结束
  608. if ($ajax) {
  609. exit(json_encode($data));
  610. } else {
  611. return $data;
  612. }
  613. }
  614. public function getChat($ajax = 'json')
  615. {
  616. $chat = (APP_DEBUG ? null : S('getChat'));
  617. if (!$chat) {
  618. $chat = M('Chat')->where(array('status' => 1))->order('id desc')->limit(500)->select();
  619. S('getChat', $chat);
  620. }
  621. asort($chat);
  622. if ($chat) {
  623. foreach ($chat as $k => $v) {
  624. $data[] = array((int) $v['id'], $v['username'], $v['content']);
  625. }
  626. } else {
  627. $data = '';
  628. }
  629. if ($ajax) {
  630. exit(json_encode($data));
  631. } else {
  632. return $data;
  633. }
  634. }
  635. public function upChat($content)
  636. {
  637. exit;
  638. if (!userid()) {
  639. $this->error(L('请先登录...'));
  640. }
  641. $content = msubstr($content, 0, 20, 'utf-8', false);
  642. if (!$content) {
  643. $this->error(L('请先输入内容'));
  644. }
  645. if (APP_DEMO) {
  646. $this->error(L('测试站暂时不能聊天!'));
  647. }
  648. if (time() < (session('chat' . userid()) + 10)) {
  649. $this->error(L('不能发送过快'));
  650. }
  651. $id = M('Chat')->add(array('userid' => userid(), 'username' => username(), 'content' => $content, 'addtime' => time(), 'status' => 1));
  652. if ($id) {
  653. S('getChat', null);
  654. session('chat' . userid(), time());
  655. $this->success($id);
  656. } else {
  657. $this->error(L('发送失败'));
  658. }
  659. }
  660. public function upcomment($msgaaa, $s1, $s2, $s3, $xnb)
  661. {
  662. exit;
  663. if (empty($msgaaa)) {
  664. $this->error(L('提交内容错误'));
  665. }
  666. if (!check($s1, 'd')) {
  667. $this->error(L('技术评分错误'));
  668. }
  669. if (!check($s2, 'd')) {
  670. $this->error(L('应用评分错误'));
  671. }
  672. if (!check($s3, 'd')) {
  673. $this->error(L('前景评分错误'));
  674. }
  675. if (!userid()) {
  676. $this->error(L('请先登录!'));
  677. }
  678. if (M('CoinComment')->where(array(
  679. 'userid' => userid(),
  680. 'coinname' => $xnb,
  681. 'addtime' => array('gt', time() - 60)
  682. ))->find()) {
  683. $this->error(L('请不要频繁提交!'));
  684. }
  685. if (M('Coin')->where(array('name' => $xnb))->save(array(
  686. 'tp_zs' => array('exp', 'tp_zs+1'),
  687. 'tp_js' => array('exp', 'tp_js+' . $s1),
  688. 'tp_yy' => array('exp', 'tp_yy+' . $s2),
  689. 'tp_qj' => array('exp', 'tp_qj+' . $s3)
  690. ))) {
  691. if (M('CoinComment')->add(array('userid' => userid(), 'coinname' => $xnb, 'content' => $msgaaa, 'addtime' => time(), 'status' => 1))) {
  692. $this->success(L('提交成功'));
  693. } else {
  694. $this->error(L('提交失败!'));
  695. }
  696. } else {
  697. $this->error(L('提交失败!'));
  698. }
  699. }
  700. public function subcomment($id, $type)
  701. {
  702. // 过滤非法字符----------------S
  703. if (checkstr($id) || checkstr($type)) {
  704. $this->error(L('您输入的信息有误!'));
  705. }
  706. // 过滤非法字符----------------E
  707. if ($type != 1) {
  708. if ($type != 2) {
  709. if ($type != 3) {
  710. $this->error(L('参数错误!'));
  711. } else {
  712. $type = 'xcd';
  713. }
  714. } else {
  715. $type = 'tzy';
  716. }
  717. } else {
  718. $type = 'cjz';
  719. }
  720. if (!check($id, 'd')) {
  721. $this->error(L('参数错误'));
  722. }
  723. if (!userid()) {
  724. $this->error(L('请先登录!'));
  725. }
  726. if (S('subcomment' . userid() . $id)) {
  727. $this->error(L('请不要频繁提交!'));
  728. }
  729. if (M('CoinComment')->where(array('id' => $id))->setInc($type, 1)) {
  730. S('subcomment' . userid() . $id, 1);
  731. $this->success(L('提交成功'));
  732. } else {
  733. $this->error(L('提交失败!'));
  734. }
  735. }
  736. }
  737. ?>