GamesAction.class.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维p2p借贷系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class GamesAction extends CommonAction
  10. {
  11. public function index()
  12. {
  13. if (strim($_REQUEST['name']) != '') {
  14. $map['name'] = array('like', '%' . strim($_REQUEST['name']) . '%');
  15. }
  16. $name = $this->getActionName();
  17. $model = D($name);
  18. if (!empty($model)) {
  19. $this->_list($model, $map);
  20. }
  21. $list = $this->get("list");
  22. foreach ($list as $key => $value) {
  23. $list[$key]['image'] = get_spec_image($value['image']);
  24. }
  25. $this->assign('list', $list);
  26. $this->display();
  27. }
  28. public function edit()
  29. {
  30. $id = intval($_REQUEST['id']);
  31. $condition['id'] = $id;
  32. $vo = M(MODULE_NAME)->where($condition)->find();
  33. $vo['image'] = get_spec_image($vo['image']);
  34. $this->assign('vo', $vo);
  35. $this->assign('op', json_decode($vo['option'], 1));
  36. $this->assign('banker', OPEN_BANKER_MODULE);
  37. $this->assign('diamond_game', OPEN_DIAMOND_GAME_MODULE);
  38. $this->display();
  39. }
  40. public function update()
  41. {
  42. B('FilterString');
  43. $data = M(MODULE_NAME)->create();
  44. $option = [];
  45. foreach ($data['option'] as $key => $value) {
  46. $option[$key + 1] = floatval($value);
  47. }
  48. $data['option'] = json_encode($option);
  49. //clear_auto_cache("prop_list");
  50. $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("name");
  51. //开始验证有效性
  52. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  53. if (!check_empty($data['name'])) {
  54. $this->error("请输入名称");
  55. }
  56. if (!check_empty($data['image'])) {
  57. $this->error("请输入图标");
  58. }
  59. // if(intval($data['principal']) == 0)
  60. // {
  61. // $this->error("请输入游戏底金");
  62. // }
  63. if (intval($data['commission_rate']) < 0) {
  64. $this->error("请输入佣金比率,0-100");
  65. }
  66. if (intval($data['long_time']) == 0) {
  67. $this->error("请输入游戏时长");
  68. }
  69. if (intval($data['rate']) == '') {
  70. $data['rate'] = 0;
  71. }
  72. if (!check_empty($data['description'])) {
  73. $this->error("请输入游戏描述");
  74. }
  75. if (intval($data['long_time']) < 20 || intval($data['long_time']) > 99) {
  76. $this->error("请输入游戏时长,20-99");
  77. }
  78. // 更新数据
  79. $list = M(MODULE_NAME)->save($data);
  80. if (false !== $list) {
  81. //成功提示
  82. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  83. clear_auto_cache("prop_id", array('id' => $data['id']));
  84. $this->success(L("UPDATE_SUCCESS"));
  85. } else {
  86. //错误提示
  87. save_log($log_info . L("UPDATE_FAILED"), 0);
  88. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  89. }
  90. }
  91. public function betLog()
  92. {
  93. $user_id = intval($_REQUEST['user_id']);
  94. $game_log_id = intval($_REQUEST['game_log_id']);
  95. if ($user_id) {
  96. $map['user_id'] = $user_id;
  97. }
  98. if ($game_log_id) {
  99. $map['game_log_id'] = $game_log_id;
  100. }
  101. $model = D('coin_log');
  102. if (!empty($model)) {
  103. $this->_list($model, $map);
  104. }
  105. $this->assign("is_diamond", defined('OPEN_DIAMOND_GAME_MODULE') && OPEN_DIAMOND_GAME_MODULE == 1);
  106. $this->display();
  107. }
  108. public function addCoin()
  109. {
  110. if ($_POST) {
  111. $user_id = intval($_REQUEST['user_id']);
  112. $coin = intval($_REQUEST['coin']);
  113. if (!($user_id && $coin)) {
  114. $this->ajax_return(array(
  115. 'status' => 0,
  116. 'error' => '参数错误',
  117. ));
  118. }
  119. $where = array('id' => $user_id);
  120. $user_model = M('user');
  121. $res = $user_model->setInc('coin', $where, $coin);
  122. $account_diamonds = $user_model->getField('coin', $where);
  123. if ($res) {
  124. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  125. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
  126. $user_redis = new UserRedisService();
  127. $user_redis->inc_field($user_id, 'coin', $coin);
  128. $data = array(
  129. 'user_id' => $user_id,
  130. 'game_log_id' => -1,
  131. 'diamonds' => $coin,
  132. 'account_diamonds' => $account_diamonds,
  133. 'memo' => '后台修改',
  134. 'create_time' => NOW_TIME,
  135. );
  136. M('coin_log')->add($data);
  137. $this->ajax_return(array(
  138. 'status' => 1,
  139. 'error' => '更新成功',
  140. ));
  141. }
  142. $this->ajax_return(array(
  143. 'status' => 0,
  144. 'error' => '更新失败',
  145. ));
  146. } else {
  147. $user_id = intval($_REQUEST['user_id']);
  148. $user_model = M('user');
  149. $user_info = $user_model->field(array('id', 'nick_name', 'coin'))->find($user_id);
  150. $this->assign("user_info", $user_info);
  151. $this->display();
  152. }
  153. }
  154. protected function ajax_return($data)
  155. {
  156. header("Content-Type:text/html; charset=utf-8");
  157. echo (json_encode($data));
  158. exit;
  159. }
  160. public function bankerLog()
  161. {
  162. $sort = $_REQUEST['_sort'] ? 'asc' : 'desc';
  163. $order = str_replace('`', '', trim($_REQUEST['_order']));
  164. $p = intval($_REQUEST['p']);
  165. $user_id = intval($_REQUEST['user_id']);
  166. $video_id = intval($_REQUEST['video_id']);
  167. $is_history = intval($_REQUEST['is_history']);
  168. $where = "where status in ('3','4')";
  169. if ($user_id) {
  170. $where .= " and `user_id`= $user_id";
  171. }
  172. if ($video_id) {
  173. $where .= " and `video_id`= $video_id";
  174. }
  175. $table1 = DB_PREFIX . 'banker_log';
  176. $table2 = DB_PREFIX . 'banker_log_history';
  177. $select1 = "SELECT * FROM $table1 $where";
  178. $select2 = "SELECT * FROM $table2 $where";
  179. $str_order = '';
  180. if ($order) {
  181. $str_order = "order by `$order` $sort";
  182. } else {
  183. $str_order = "order by `id` $sort";
  184. }
  185. $count = "SELECT count(1) as count FROM ($select1 UNION $select2) AS a";
  186. $count = M()->query($count);
  187. $count = intval($count[0]['count']);
  188. $p = new Page($count, '');
  189. $limit = ' limit ' . $p->firstRow . ',' . $p->listRows;
  190. $page = $p->show();
  191. $select = "SELECT * FROM ($select1 UNION $select2) AS a $str_order $limit";
  192. $voList = M()->query($select);
  193. $sortAlt = $sort == 'desc' ? l("ASC_SORT") : l("DESC_SORT");
  194. $this->assign('list', $voList);
  195. $this->assign('sort', $sort);
  196. $this->assign('order', $order);
  197. $this->assign('sortImg', $sort);
  198. $this->assign('sortType', $sortAlt);
  199. $this->assign("page", $page);
  200. $this->assign("nowPage", $p->nowPage);
  201. $this->display();
  202. }
  203. }