ChildRoomAction.class.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/7/5
  6. * Time: 11:28
  7. */
  8. class ChildRoomAction extends CommonAction
  9. {
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. require_once APP_ROOT_PATH . "/admin/Lib/Action/VideoCommonAction.class.php";
  14. }
  15. //子房间列表
  16. public function index()
  17. {
  18. require_once APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php';
  19. require_once(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  20. $now = get_gmtime();
  21. $parameter = '';
  22. $sql_w = '';
  23. if (intval($_REQUEST['cate_id']) > 0) {
  24. $parameter .= "cate_id=" . intval($_REQUEST['cate_id']) . "&";
  25. $sql_w .= "v.cate_id=" . intval($_REQUEST['cate_id']) . " and ";
  26. }
  27. if (intval($_REQUEST['classified_id']) > 0) {
  28. $parameter .= "classified_id=" . intval($_REQUEST['classified_id']) . "&";
  29. $sql_w .= "v.classified_id=" . intval($_REQUEST['classified_id']) . " and ";
  30. }
  31. if (strim($_REQUEST['nick_name']) != '') {
  32. //name
  33. $user = M("User")->where("nick_name like '%" . trim($_REQUEST['nick_name']) . "%' ")->findAll();
  34. foreach ($user as $k => $v) {
  35. $user_arr_id[$k] = intval($v['id']);
  36. }
  37. $parameter .= "user_id in (" . implode(",", $user_arr_id) . ")&";
  38. $sql_w .= "v.user_id in (" . implode(",", $user_arr_id) . ") and ";
  39. } else {
  40. if (intval($_REQUEST['user_id']) > 0) {
  41. $parameter .= "user_id=" . intval($_REQUEST['user_id']) . "&";
  42. $sql_w .= "v.user_id=" . intval($_REQUEST['user_id']) . " and ";
  43. }
  44. }
  45. $create_time_2 = empty($_REQUEST['create_time_2']) ? to_date($now, 'Y-m-d') : strim($_REQUEST['create_time_2']);
  46. $create_time_2 = to_timespan($create_time_2) + 24 * 3600;
  47. if (trim($_REQUEST['create_time_1']) != '') {
  48. $parameter .= "create_time between '" . to_timespan($_REQUEST['create_time_1']) . "' and '" . $create_time_2 . "'&";
  49. $sql_w .= "v.create_time between '" . to_timespan($_REQUEST['create_time_1']) . "' and '" . $create_time_2 . "' and ";
  50. }
  51. $parameter .= "live_in in (1,2,3)&";
  52. $sql_w .= "v.live_in in (1,2,3) and ";
  53. $model = D();
  54. $sql_str = "SELECT v.*," .
  55. "(SELECT count(1) FROM " . DB_PREFIX . "child_room_viewer crv WHERE crv.child_room = v.id) as watch_number,cr.parent_id,watch_number + v.virtual_watch_number + v.robot_num as all_watch_number " .
  56. " FROM " . DB_PREFIX . "video v," . DB_PREFIX . "child_room cr WHERE v.id = cr.child_id ";
  57. $count_sql = "SELECT count(*) as tpcount FROM " . DB_PREFIX . "video v , " . DB_PREFIX . "child_room cr WHERE cr.child_id = v.id and 1=1 ";
  58. $sql_str .= " and " . $sql_w . " 1=1";
  59. $count_sql .= " and " . $sql_w . " 1=1";
  60. $voList = $this->_Sql_list($model, $sql_str, "&" . $parameter, 'sort_num', 0, $count_sql);
  61. //取洪峰观看人数
  62. foreach ($voList as &$value) {
  63. if (intval($value['live_in']) == 3) {
  64. $value['max_watch'] = "回播视频不显示";
  65. } else {
  66. $value['max_watch'] = "子房间不显示";
  67. }
  68. $value['pay_editable'] = 0;
  69. if (defined('OPEN_LIVE_PAY') && OPEN_LIVE_PAY == 1 && defined('OPEN_EDIT_VIDEO_PAY') && OPEN_EDIT_VIDEO_PAY == 1) {
  70. $value['pay_editable'] = 1;
  71. if ($value['is_live_pay'] == 1 && $value['live_pay_type'] == 0) {
  72. $value['pay_editable'] = 0;
  73. }
  74. }
  75. }
  76. if (defined('OPEN_LIVE_PAY') && OPEN_LIVE_PAY == 1) {
  77. $this->assign('is_pay_live', 1);
  78. } else {
  79. $this->assign('is_pay_live', 0);
  80. }
  81. $this->assign('url_name', get_manage_url_name());
  82. $this->assign('list', $voList);
  83. $cate_list = M("VideoCate")->findAll();
  84. $classified_list = M("VideoClassified")->findAll();
  85. $this->assign("classified_list", $classified_list);
  86. $this->assign("cate_list", $cate_list);
  87. $this->display();
  88. }
  89. //付费设置
  90. public function set_live_pay()
  91. {
  92. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  93. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  94. $video_id = intval($_REQUEST['id']);
  95. $video_redis = new VideoRedisService($video_id);
  96. $video = $video_redis->getRow_db($video_id, array('id', 'is_live_pay', 'live_fee'));
  97. $this->assign("video", $video);
  98. $this->display();
  99. }
  100. //修改付费设置
  101. public function modify_live_pay()
  102. {
  103. $video_id = intval($_REQUEST['id']);
  104. $video['id'] = $video_id;
  105. $video['live_pay_type'] = 0;
  106. $video['live_fee'] = 0;
  107. $video['is_live_pay'] = intval($_REQUEST['is_live_pay']);//是否付费
  108. $live_fee = intval($_REQUEST['live_fee']);//观看费用
  109. if ($video['is_live_pay']) {
  110. $video['live_pay_type'] = 1;
  111. $video['live_fee'] = $live_fee;
  112. }
  113. if ($video['live_fee'] && !preg_match('/^[0-9]*[1-9][0-9]*$/', $video['live_fee'])) {
  114. $this->error("观看费用必须为大于0的整数");
  115. }
  116. $list = M("Video")->save($video);
  117. if (false !== $list) {
  118. //redis同步
  119. require_once APP_ROOT_PATH . "/mapi/lib/core/common.php";
  120. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  121. sync_video_to_redis($video_id, '*', false);
  122. save_log($video_id . L("UPDATE_SUCCESS"), 1);
  123. $this->success(L("UPDATE_SUCCESS"));
  124. } else {
  125. //错误提示
  126. save_log($video_id . L("UPDATE_FAILED"), 0);
  127. $this->error(L("UPDATE_SUCCESS"));
  128. }
  129. }
  130. //修改上线状态
  131. public function set_demand_video_status()
  132. {
  133. require_once APP_ROOT_PATH . "/mapi/lib/core/common.php";
  134. $ajax = intval($_REQUEST['ajax']);
  135. $id = $_REQUEST['id'];
  136. $result['status'] = 0;
  137. if (isset ($id)) {
  138. $condition = array('id' => array('in', explode(',', $id)));
  139. $rel_data = M('Video')->where($condition)->findAll();
  140. $success_info = array();
  141. $fail_info = array();
  142. foreach ($rel_data as $data) {
  143. if ($data['live_in'] == 3) {
  144. //下架
  145. $m_config = load_auto_cache("m_config");
  146. if ($m_config['ios_check_version'] != '') {
  147. $sql = "select u.mobile from " . DB_PREFIX . "video v left join " . DB_PREFIX . "user u on u.id=v.user_id where v.id = " . $data['id'];
  148. $mobile = $GLOBALS['db']->getOne($sql, true, true);
  149. if ($mobile == '13888888888' || $mobile == '13999999999') {
  150. $sql = "select count(*) from " . DB_PREFIX . "video v left join " . DB_PREFIX . "user u on u.id=v.user_id where v.live_in=3 and (u.mobile = '13888888888' or u.mobile = '13999999999')";
  151. $video_count = $GLOBALS['db']->getOne($sql, true, true);
  152. if (intval($video_count) <= 1) {
  153. $result['status'] = 0;
  154. $result['info'] = '下线失败,审核期间必须有一个审核账号的历史直播!';
  155. admin_ajax_return($result);
  156. }
  157. }
  158. }
  159. $re = video_status($data['id'], 1);
  160. }
  161. //redis 同步结束
  162. $success_info[] = $data['id'];
  163. if ($re) {
  164. $result['status'] = 1;
  165. } else {
  166. $fail_info[] = $data['id'];
  167. }
  168. /*}else{
  169. $fail_info[] = $data['id'];
  170. }*/
  171. }
  172. if ($success_info) {
  173. $success_info = implode(",", $success_info);
  174. }
  175. if ($fail_info) {
  176. $fail_info = implode(",", $fail_info);
  177. }
  178. if ($re) {
  179. save_log($success_info . l("DEMAND_VIDEO_STATUS_SUCCESS"), 1);
  180. $result['info'] = '修改成功!';
  181. } else {
  182. if ($success_info) {
  183. save_log($success_info . l("DEMAND_VIDEO_STATUS_SUCCESS"), 1);
  184. }
  185. save_log($fail_info . l("DEMAND_VIDEO_STATUS_FAILED"), 0);
  186. $result['info'] = $fail_info . '修改失败!';
  187. }
  188. } else {
  189. $result['status'] = 0;
  190. $result['info'] = '编号错误';
  191. }
  192. admin_ajax_return($result);
  193. }
  194. public function video_set()
  195. {
  196. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  197. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  198. $video_id = intval($_REQUEST['id']);
  199. $video_redis = new VideoRedisService($video_id);
  200. $video = $video_redis->getRow_db($video_id,
  201. array('id', 'virtual_number', 'max_robot_num', 'virtual_watch_number'));
  202. $this->assign("video", $video);
  203. $this->display();
  204. }
  205. public function modify_video_set()
  206. {
  207. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  208. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  209. $video_id = intval($_REQUEST['id']);
  210. $video['virtual_number'] = intval($_REQUEST['virtual_number']);//1用户带机器人最大比例
  211. $video['virtual_watch_number'] = intval($_REQUEST['virtual_watch_number']);//直接设置机器人数
  212. $video['max_robot_num'] = intval($_REQUEST['robot_num']);//最大机器人头像数
  213. $robot_num = M("User")->where("is_effect=1 and is_robot = 1")->count();
  214. if ($video['robot_num'] > $robot_num) {
  215. $this->error("最大机器人头像数不能大于系统机器人头像总数" . $robot_num);
  216. }
  217. $video_redis = new VideoRedisService($video_id);
  218. $video_redis->update_db($video_id, $video);
  219. M(MODULE_NAME)->where("id=" . $video_id)->setField("max_robot_num", $video['max_robot_num']);
  220. $video_redis->update('video_virtual_watch_number', array($video_id => $video['virtual_watch_number']));
  221. save_log(l("ADMIN_MODIFY_ACCOUNT"), 1);
  222. $this->success(L("UPDATE_SUCCESS"));
  223. }
  224. //关闭房间
  225. function close_live()
  226. {
  227. $common = new VideoCommon();
  228. $data = $_REQUEST;
  229. $common->close_live($data);
  230. }
  231. public function set_sort()
  232. {
  233. $id = intval($_REQUEST['id']);
  234. $sort = intval($_REQUEST['sort']);
  235. $name = $this->getActionName();
  236. $log_info = M($name)->where("id=" . $id)->find();
  237. //print_r($log_info['user_id']);
  238. if (!check_sort($sort)) {
  239. $this->error(l("SORT_FAILED"), 1);
  240. }
  241. M("Video")->where("id=" . $id)->setField("sort", $sort);
  242. //print_r(M($name)->GetLastSql());
  243. require_once APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php';
  244. require_once APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php';
  245. $video_redis = new VideoRedisService($log_info['user_id']);
  246. //print_r($video_redis);
  247. //更新视频排序信息
  248. $return = $video_redis->update_video_sort($log_info['id'], $sort);
  249. save_log($log_info['title'] . l("SORT_SUCCESS"), 1);
  250. //clear_auto_cache("get_help_cache");
  251. $this->success(l("SORT_SUCCESS"), 1);
  252. }
  253. //设置推荐
  254. public function set_recommend()
  255. {
  256. $id = intval($_REQUEST['id']);
  257. $recommend = intval($_REQUEST['recommend']);
  258. $c_is_effect = M('Video')->where("id=" . $id)->getField("is_recommend"); //当前状态
  259. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  260. $result = M('Video')->where("id=" . $id)->setField("is_recommend", $n_is_effect);
  261. save_log("房间号" . $id . l("SET_RECOMMEND_" . $n_is_effect), 1);
  262. $this->ajaxReturn($n_is_effect, l("SET_RECOMMEND_" . $n_is_effect), 1);
  263. }
  264. public function set_hot_on()
  265. {
  266. $id = intval($_REQUEST['id']);
  267. $ajax = intval($_REQUEST['ajax']);
  268. $user_info = M("User")->getById($id);
  269. $c_is_effect = M("User")->where("id=" . $id)->getField("is_hot_on"); //当前状态
  270. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  271. $result = M("User")->where("id=" . $id)->setField("is_hot_on", $n_is_effect);
  272. $user_data = array();
  273. if ($result) {
  274. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  275. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
  276. $user_redis = new UserRedisService();
  277. $user_data['is_hot_on'] = $n_is_effect;
  278. $user_redis->update_db($id, $user_data);
  279. }
  280. save_log($user_info['nick_name'] . l("SET_HOT_ON_" . $n_is_effect), 1);
  281. $this->ajaxReturn($n_is_effect, l("SET_HOT_ON_" . $n_is_effect), 1);
  282. }
  283. //添加子房间
  284. public function add_child_room()
  285. {
  286. $video_list = $GLOBALS['db']->getAll("SELECT v.id , v.user_id , u.nick_name FROM " . DB_PREFIX . "video AS v , " . DB_PREFIX . "user AS u WHERE v.user_id = u.id AND v.live_in = 1 AND NOT EXISTS( SELECT * FROM " . DB_PREFIX . "child_room AS r WHERE r.child_id = v.id) order by v.sort");
  287. $this->assign('parent_room_list', $video_list);
  288. $this->display();
  289. }
  290. //编辑子房间
  291. public function edit_child_room()
  292. {
  293. $child_room_id = intval($_REQUEST['child_room_id']);
  294. $video_info = $GLOBALS['db']->getRow("SELECT v.id,v.user_id,v.cate_id,v.live_image,v.room_title FROM " . DB_PREFIX . "video v ," . DB_PREFIX . "child_room cr where v.id ={$child_room_id}");
  295. $video_info['room_id'] = $child_room_id;
  296. $video_info['nick_name'] = $GLOBALS['db']->getOne("SELECT nick_name FROM " . DB_PREFIX . "user WHERE id =" . intval($video_info['user_id']));
  297. $video_info['title'] = $GLOBALS['db']->getOne("SELECT title FROM " . DB_PREFIX . "video_cate WHERE id =" . intval($video_info['cate_id']));
  298. $video_info['parent_id'] = $GLOBALS['db']->getOne("SELECT parent_id FROM " . DB_PREFIX . "child_room WHERE child_id =" . $child_room_id);
  299. $video_list = $GLOBALS['db']->getAll("SELECT v.id , v.user_id , u.nick_name FROM " . DB_PREFIX . "video AS v , " . DB_PREFIX . "user AS u WHERE v.user_id = u.id AND v.live_in = 1 AND NOT EXISTS( SELECT * FROM " . DB_PREFIX . "child_room AS r WHERE r.child_id = v.id) order by v.sort");
  300. $this->assign('parent_room_list', $video_list);
  301. $this->assign('vo', $video_info);
  302. $this->display();
  303. }
  304. //插入数据
  305. public function insert_child_room()
  306. {
  307. $user_id = intval($_REQUEST['user_id']);
  308. $title = strim($_REQUEST['title']);
  309. $parent_id = intval($_REQUEST['parent_id']);
  310. $live_image = strim($_REQUEST['live_image']);
  311. $room_title = strim($_REQUEST['room_title']);
  312. if ($user_id == 0) {
  313. admin_ajax_return(array('status' => '0', 'error' => '请输入用户id'));
  314. }
  315. if (empty($room_title)) {
  316. admin_ajax_return(array('status' => '0', 'error' => '请输入直播间标题'));
  317. }
  318. $has_room = M('Video')->where('user_id =' . $user_id)->count();
  319. if ($has_room) {
  320. admin_ajax_return(array('status' => '0', 'error' => '该用户的房间未结束'));
  321. }
  322. $is_private = false;
  323. $monitor_time = to_date(NOW_TIME + 3600, 'Y-m-d H:i:s');
  324. $data = $this->create_video($user_id, $title, $is_private, $monitor_time, $room_title);//视频信息写入video表
  325. $data['live_image'] = $live_image;
  326. if ($parent_id) {
  327. $parent_info = $GLOBALS['db']->getRow("SELECT v.live_in,v.video_vid,v.play_url,v.push_rtmp,v.play_flv,v.play_mp4,v.play_hls,v.group_id,v.live_pay_type,v.live_fee,v.is_live_pay,v.create_type FROM " . DB_PREFIX . "video v where v.live_in in (1,3) and v.id =" . $parent_id);
  328. if (empty($parent_info)) {
  329. admin_ajax_return(array('status' => '0', 'error' => '主房间不存在'));
  330. }
  331. $data['video_vid'] = $parent_info['video_vid'];
  332. $data['play_flv'] = $parent_info['play_flv'];
  333. $data['play_url'] = $parent_info['play_url'];
  334. $data['play_mp4'] = $parent_info['play_mp4'];
  335. $data['play_hls'] = $parent_info['play_hls'];
  336. $data['live_in'] = $parent_info['live_in'];
  337. $data['prop_table'] = DB_PREFIX . "child_video_prop";
  338. $data['group_id'] = $parent_info['group_id'];
  339. $data['live_pay_type'] = $parent_info['live_pay_type'];
  340. $data['live_fee'] = $parent_info['live_fee'];
  341. $data['is_live_pay'] = $parent_info['is_live_pay'];
  342. $data['create_type'] = $parent_info['create_type'];
  343. }
  344. $GLOBALS['db']->autoExecute(DB_PREFIX . "video", $data, 'INSERT');
  345. if ($GLOBALS['db']->affected_rows()) {
  346. $child_data['child_id'] = $data['id'];
  347. $child_data['parent_id'] = $parent_id;
  348. if ($GLOBALS['db']->autoExecute(DB_PREFIX . "child_room", $child_data, 'INSERT')) {
  349. $res['status'] = 1;
  350. $res['error'] = '添加子房间成功';
  351. //同步到redis
  352. fanwe_require(APP_ROOT_PATH . "/mapi/lib/core/common.php");
  353. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  354. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  355. sync_video_to_redis($data['id'], '*', false);
  356. $video_redis = new VideoRedisService();
  357. $status['online_status'] = 1;
  358. $video_redis->update_db($data['id'], $status);
  359. $video_redis->redis->sAdd('video_child_room_' . $parent_id, $data['id']);
  360. } else {
  361. $res['status'] = 0;
  362. $res['error'] = '关联主房间失败!';
  363. }
  364. } else {
  365. $res['status'] = 0;
  366. $res['error'] = '添加子房间失败!';
  367. }
  368. admin_ajax_return($res);
  369. }
  370. //更新数据
  371. public function update_child_room()
  372. {
  373. $data['user_id'] = intval($_REQUEST['user_id']);
  374. $data['title'] = strim($_REQUEST['title']);
  375. $parent_id = intval($_REQUEST['parent_id']);
  376. $data['live_image'] = strim($_REQUEST['live_image']);
  377. $data['room_title'] = strim($_REQUEST['room_title']);
  378. $room_id = intval($_REQUEST['room_id']);
  379. if ($data['user_id'] == 0) {
  380. admin_ajax_return(array('status' => '0', 'error' => '请输入用户id'));
  381. }
  382. if (empty($data['room_title'])) {
  383. admin_ajax_return(array('status' => '0', 'error' => '请输入直播间标题'));
  384. }
  385. $has_room = M('Video')->where('user_id =' . $data['user_id'])->count();
  386. if (!$has_room) {
  387. admin_ajax_return(array('status' => '0', 'error' => '子房间不存在'));
  388. }
  389. //同步到redis
  390. fanwe_require(APP_ROOT_PATH . "/mapi/lib/core/common.php");
  391. if ($parent_id) {
  392. $parent_info = $GLOBALS['db']->getRow("SELECT v.live_in,v.video_vid,v.play_url,v.push_rtmp,v.play_flv,v.play_mp4,v.play_hls,v.group_id,v.live_pay_type,v.live_fee,v.is_live_pay,v.create_type FROM " . DB_PREFIX . "video v where v.live_in in (1,3) and v.id =" . $parent_id);
  393. if (empty($parent_info)) {
  394. admin_ajax_return(array('status' => '0', 'error' => '主房间不存在'));
  395. }
  396. $data['video_vid'] = $parent_info['video_vid'];
  397. $data['play_flv'] = $parent_info['play_flv'];
  398. $data['play_url'] = $parent_info['play_url'];
  399. $data['play_mp4'] = $parent_info['play_mp4'];
  400. $data['play_hls'] = $parent_info['play_hls'];
  401. $data['live_in'] = $parent_info['live_in'];
  402. $data['prop_table'] = DB_PREFIX . "child_video_prop";
  403. $data['group_id'] = $parent_info['group_id'];
  404. $data['live_pay_type'] = $parent_info['live_pay_type'];
  405. $data['live_fee'] = $parent_info['live_fee'];
  406. $data['is_live_pay'] = $parent_info['is_live_pay'];
  407. $data['create_type'] = $parent_info['create_type'];
  408. }
  409. if ($GLOBALS['db']->autoExecute(DB_PREFIX . "video", $data, 'UPDATE', 'id =' . $room_id)) {
  410. $child_data['parent_id'] = $parent_id;
  411. if ($GLOBALS['db']->autoExecute(DB_PREFIX . "child_room", $child_data, 'UPDATE', 'child_id =' . $room_id)) {
  412. $res['status'] = 1;
  413. $res['error'] = '编辑成功';
  414. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  415. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  416. sync_video_to_redis($room_id, '*', false);
  417. $video_redis = new VideoRedisService();
  418. $status['online_status'] = 1;
  419. $video_redis->update_db($room_id, $status);
  420. $video_redis->redis->sAdd('video_child_room_' . $parent_id, $room_id);
  421. } else {
  422. $res['status'] = 0;
  423. $res['error'] = '关联主房间失败!';
  424. }
  425. } else {
  426. $res['status'] = 0;
  427. $res['error'] = '编辑失败!';
  428. }
  429. admin_ajax_return($res);
  430. }
  431. public function create_video(
  432. $user_id,
  433. $title,
  434. $is_private,
  435. $monitor_time,
  436. $room_title,
  437. $cate_id = '',
  438. $province = '',
  439. $city = '',
  440. $share_type = ''
  441. ) {
  442. $condition['title'] = $title;
  443. if ($cate_id == 0 && $title != '') {
  444. $cate_id = M('video_cate')->where($condition)->getfield('id');
  445. if ($cate_id) {
  446. $is_newtitle = 0;
  447. } else {
  448. $is_newtitle = 1;
  449. }
  450. }
  451. if ($is_newtitle) {
  452. $data_cate = array();
  453. $data_cate['title'] = $title;
  454. $data_cate['is_effect'] = 1;
  455. $data_cate['is_delete'] = 0;
  456. $data_cate['create_time'] = NOW_TIME;
  457. M('video_cate')->add($data_cate);
  458. $cate_id = M('video_cate')->where($condition)->getfield('id');
  459. }
  460. if ($province == '') {
  461. $province = '火星';
  462. }
  463. if ($city == '') {
  464. $city = '火星';
  465. }
  466. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/common.php');
  467. $v_id = get_max_room_id(0);//视频ID
  468. $data = array();
  469. $data['id'] = $v_id;
  470. //room_type 房间类型 : 1私有群(Private),0公开群(Public),2聊天室(ChatRoom),3互动直播聊天室(AVChatRoom)
  471. $data['room_type'] = 3;
  472. $m_config = load_auto_cache("m_config");
  473. $data['virtual_number'] = intval($m_config['virtual_number']);
  474. $data['max_robot_num'] = intval($m_config['robot_num']);//允许添加的最大机器人数;
  475. $sql = "select sex,ticket,refund_ticket,user_level,fans_count,head_image,thumb_head_image from " . DB_PREFIX . "user where id = " . $user_id;
  476. $user = $GLOBALS['db']->getRow($sql, true, true);
  477. if (!$user) {
  478. admin_ajax_return(array(
  479. 'status' => 0,
  480. 'error' => '用户ID不存在'
  481. ));
  482. }
  483. $info = origin_image_info($user['head_image']);
  484. $data['head_image'] = get_spec_image($info['file_name']);
  485. $data['thumb_head_image'] = $user['thumb_head_image'];
  486. $data['sex'] = intval($user['sex']);//性别 0:未知, 1-男,2-女
  487. $data['video_type'] = 1;//0:腾讯云互动直播;1:腾讯云直播
  488. $data['monitor_time'] = $monitor_time;
  489. $data['create_type'] = 0;// 0:APP端创建的直播;1:PC端创建的直播
  490. $data['push_url'] = '';//video_type=1;1:腾讯云直播推流地址
  491. $data['play_url'] = '';//video_type=1;1:腾讯云直播播放地址(rmtp,flv)
  492. $data['share_type'] = $share_type;
  493. $data['title'] = $title;
  494. $data['cate_id'] = $cate_id;
  495. $data['user_id'] = $user_id;
  496. $data['live_in'] = 2;//live_in:是否直播中 1-直播中 0-已停止;2:正在创建直播;
  497. $data['watch_number'] = '';//'当前观看人数';
  498. $data['vote_number'] = '';//'获得票数';
  499. $data['province'] = $province;//'省';
  500. $data['city'] = $city;//'城市';
  501. $data['room_title'] = $room_title;
  502. $data['create_time'] = NOW_TIME;//'创建时间';
  503. $data['begin_time'] = NOW_TIME;//'开始时间';
  504. $data['end_time'] = '';//'结束时间';
  505. $data['is_hot'] = 1;//'1热门; 0:非热门';
  506. $data['is_new'] = 1; //'1新的; 0:非新的,直播结束时把它标识为:0?'
  507. $data['online_status'] = 1;//主播在线状态;1:在线(默认); 0:离开
  508. //sort_init(初始排序权重) = (用户可提现印票:fanwe_user.ticket - fanwe_user.refund_ticket) * 保留印票权重+ 直播/回看[回看是:0; 直播:9000000000 直播,需要排在最上面 ]+ fanwe_user.user_level * 等级权重+ fanwe_user.fans_count * 当前有的关注数权重
  509. $sort_init = (intval($user['ticket']) - intval($user['refund_ticket'])) * floatval($m_config['ticke_weight']);
  510. $sort_init += intval($user['user_level']) * floatval($m_config['level_weight']);
  511. $sort_init += intval($user['fans_count']) * floatval($m_config['focus_weight']);
  512. $data['sort_init'] = 200000000 + $sort_init;
  513. $data['sort_num'] = $data['sort_init'];
  514. return $data;
  515. }
  516. //观众列表
  517. public function viewer_list()
  518. {
  519. $child_id = intval($_REQUEST['child_room_id']);
  520. $user_id = intval($_REQUEST['user_id']);
  521. $nick_name = strim($_REQUEST['nick_name']);
  522. $sql_w = '';
  523. $parameter = '';
  524. //查询ID
  525. if ($user_id != '') {
  526. $parameter .= "u.id =" . $user_id . "&";
  527. $sql_w .= "u.id =" . $user_id . " and ";
  528. }
  529. //查询昵称
  530. if ($nick_name != '') {
  531. $parameter .= "u.nick_name like " . urlencode('%' . $nick_name . '%') . "&";
  532. $sql_w .= "u.nick_name like '%" . $nick_name . "%' and ";
  533. }
  534. $model = D('child_room_viewer');
  535. //子房间主播
  536. $child_video = M('Video')->where('id =' . $child_id)->field('user_id')->find();
  537. if (empty($child_video)) {
  538. $child_video = M('VideoHistory')->where('id =' . $child_id)->field('user_id')->find();
  539. }
  540. $where = " cv.child_room =" . $child_id . " and u.id != " . $child_video['user_id'];
  541. $sql_str = "SELECT u.id,u.nick_name,u.head_image,u.user_level,u.login_ip FROM " . DB_PREFIX . "user as u LEFT JOIN " . DB_PREFIX . "child_room_viewer as cv
  542. ON u.id = cv.user_id WHERE " . $where . " and " . $sql_w . " 1=1 ";
  543. $count_sql = "SELECT COUNT(u.id) as tpcount FROM " . DB_PREFIX . "user as u LEFT JOIN " . DB_PREFIX . "child_room_viewer as cv
  544. ON u.id = cv.user_id WHERE " . $where . " and " . $sql_w . " 1=1 ";
  545. $volist = $this->_Sql_list($model, $sql_str, '&' . $parameter, 1, 0, $count_sql);
  546. $this->assign("child_room_id", $child_id);
  547. $this->assign("list", $volist);
  548. $this->display();
  549. }
  550. //送礼物日志
  551. public function user_prop()
  552. {
  553. $user_id = intval($_REQUEST['user_id']);
  554. $room_id = intval($_REQUEST['room_id']);
  555. $user_info = M("User")->getById($user_id);
  556. $prop_list = M("prop")->where("is_effect <>0")->findAll();
  557. $prop_table = M("Video")->where("id =" . $room_id)->find();
  558. if (empty($prop_table)) {
  559. $prop_table = M("VideoHistory")->where("id =" . $room_id)->find();
  560. }
  561. $model = D("{$prop_table['prop_table']}");
  562. if (!isset($_REQUEST['prop_id'])) {
  563. $_REQUEST['prop_id'] = -1;
  564. }
  565. //查询礼物
  566. $parameter = '';
  567. $sql_w = '';
  568. if ($_REQUEST['prop_id'] != -1) {
  569. if (isset($data['prop_id'])) {
  570. $parameter .= "l.prop_id=" . intval($_REQUEST['prop_id']) . "&";
  571. $sql_w .= "l.prop_id=" . intval($_REQUEST['prop_id']) . " and ";
  572. }
  573. }
  574. $where = "l.from_user_id=" . $user_id . " and video_id =" . $room_id;
  575. $sql_str = "SELECT l.id,l.create_ym,l.to_user_id, l.create_time,l.prop_id,l.prop_name,l.from_user_id,l.create_date,l.num,l.total_ticket,u.nick_name,l.from_ip
  576. FROM {$prop_table['prop_table']} as l
  577. LEFT JOIN " . DB_PREFIX . "user AS u ON l.to_user_id = u.id" . " LEFT JOIN " . DB_PREFIX . "prop AS v ON l.prop_name = v.name" . "
  578. WHERE $where " . " and " . $sql_w . " 1=1 ";
  579. $count_sql = "SELECT count(l.id) as tpcount
  580. FROM {$prop_table['prop_table']} as l
  581. LEFT JOIN " . DB_PREFIX . "user AS u ON l.to_user_id = u.id" . " LEFT JOIN " . DB_PREFIX . "prop AS v ON l.prop_name = v.name" . "
  582. WHERE $where " . " and " . $sql_w . " 1=1 ";
  583. $volist = $this->_Sql_list($model, $sql_str, '&' . $parameter, 1, 0, $count_sql);
  584. foreach ($volist as $k => $v) {
  585. if ($volist[$k]['prop_id'] == 12) {
  586. $volist[$k]['total_ticket'] = '';
  587. }
  588. $volist[$k]['create_time'] = date('Y-m-d', $volist[$k]['create_time']);
  589. }
  590. $this->assign("user_info", $user_info);
  591. $this->assign("room_id", $room_id);
  592. $this->assign("prop", $prop_list);
  593. $this->assign("list", $volist);
  594. $this->display();
  595. }
  596. //送礼物日志
  597. public function prop_list()
  598. {
  599. $room_id = intval($_REQUEST['room_id']);
  600. $prop_list = M("prop")->where("is_effect <>0")->findAll();
  601. $prop_table = M("Video")->where("id =" . $room_id)->find();
  602. if (empty($prop_table)) {
  603. $prop_table = M("VideoHistory")->where("id =" . $room_id)->find();
  604. }
  605. $model = D("{$prop_table['prop_table']}");
  606. if (!isset($_REQUEST['prop_id'])) {
  607. $_REQUEST['prop_id'] = -1;
  608. }
  609. //查询礼物
  610. $parameter = '';
  611. $sql_w = '';
  612. if ($_REQUEST['prop_id'] != -1) {
  613. $parameter .= "l.prop_id=" . intval($_REQUEST['prop_id']) . "&";
  614. $sql_w .= "l.prop_id=" . intval($_REQUEST['prop_id']) . " and ";
  615. }
  616. $where = "video_id =" . $room_id;
  617. $sql_str = "SELECT l.id,l.create_ym,l.to_user_id, l.create_time,l.prop_id,l.prop_name,l.from_user_id,l.create_date,l.num,l.total_ticket,u.nick_name,l.from_ip
  618. FROM {$prop_table['prop_table']} as l
  619. LEFT JOIN " . DB_PREFIX . "user AS u ON l.to_user_id = u.id" . " LEFT JOIN " . DB_PREFIX . "prop AS v ON l.prop_name = v.name" . "
  620. WHERE $where " . " and " . $sql_w . " 1=1 ";
  621. $count_sql = "SELECT count(l.id) as tpcount
  622. FROM {$prop_table['prop_table']} as l
  623. LEFT JOIN " . DB_PREFIX . "user AS u ON l.to_user_id = u.id" . " LEFT JOIN " . DB_PREFIX . "prop AS v ON l.prop_name = v.name" . "
  624. WHERE $where " . " and " . $sql_w . " 1=1 ";
  625. $volist = $this->_Sql_list($model, $sql_str, '&' . $parameter, 1, 0, $count_sql);
  626. foreach ($volist as $k => $v) {
  627. if ($volist[$k]['prop_id'] == 12) {
  628. $volist[$k]['total_ticket'] = '';
  629. }
  630. $volist[$k]['create_time'] = date('Y-m-d', $volist[$k]['create_time']);
  631. }
  632. $this->assign("room_id", $room_id);
  633. $this->assign("prop", $prop_list);
  634. $this->assign("list", $volist);
  635. $this->display();
  636. }
  637. public function pay_list()
  638. {
  639. $room_id = intval($_REQUEST['room_id']);
  640. $where = "video_id =" . $room_id;
  641. $sql_str = "SELECT l.id , l.video_id, l.create_ym , l.to_user_id , l.create_time , l.from_user_id , l.create_date , l.live_fee , u.nick_name
  642. FROM " . DB_PREFIX . "child_live_pay_log as l
  643. LEFT JOIN " . DB_PREFIX . "user AS u ON l.to_user_id = u.id" . "
  644. WHERE $where ";
  645. $count_sql = "SELECT count(l.id) as tpcount
  646. FROM " . DB_PREFIX . "child_live_pay_log as l
  647. LEFT JOIN " . DB_PREFIX . "user AS u ON l . to_user_id = u . id" . "
  648. WHERE $where ";
  649. $model = D("child_live_pay_log");
  650. $volist = $this->_Sql_list($model, $sql_str, '', 1, 0, $count_sql);
  651. foreach ($volist as $k => $v) {
  652. $volist[$k]['create_time'] = date('Y-m-d H:i:s', $volist[$k]['create_time']);
  653. }
  654. $this->assign("room_id", $room_id);
  655. $this->assign("list", $volist);
  656. $this->display();
  657. }
  658. //子房间列表
  659. public function history_list()
  660. {
  661. require_once APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php';
  662. require_once(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  663. $now = get_gmtime();
  664. $parameter = '';
  665. $sql_w = '';
  666. if (intval($_REQUEST['cate_id']) > 0) {
  667. $parameter .= "cate_id=" . intval($_REQUEST['cate_id']) . "&";
  668. $sql_w .= "v.cate_id=" . intval($_REQUEST['cate_id']) . " and ";
  669. }
  670. if (intval($_REQUEST['classified_id']) > 0) {
  671. $parameter .= "classified_id=" . intval($_REQUEST['classified_id']) . "&";
  672. $sql_w .= "v.classified_id=" . intval($_REQUEST['classified_id']) . " and ";
  673. }
  674. if (strim($_REQUEST['nick_name']) != '') {
  675. //name
  676. $user = M("User")->where("nick_name like '%" . trim($_REQUEST['nick_name']) . "%' ")->findAll();
  677. foreach ($user as $k => $v) {
  678. $user_arr_id[$k] = intval($v['id']);
  679. }
  680. $parameter .= "user_id in (" . implode(",", $user_arr_id) . ")&";
  681. $sql_w .= "v.user_id in (" . implode(",", $user_arr_id) . ") and ";
  682. } else {
  683. if (intval($_REQUEST['user_id']) > 0) {
  684. $parameter .= "user_id=" . intval($_REQUEST['user_id']) . "&";
  685. $sql_w .= "v.user_id=" . intval($_REQUEST['user_id']) . " and ";
  686. }
  687. }
  688. $create_time_2 = empty($_REQUEST['create_time_2']) ? to_date($now, 'Y-m-d') : strim($_REQUEST['create_time_2']);
  689. $create_time_2 = to_timespan($create_time_2) + 24 * 3600;
  690. if (trim($_REQUEST['create_time_1']) != '') {
  691. $parameter .= "create_time between '" . to_timespan($_REQUEST['create_time_1']) . "' and '" . $create_time_2 . "'&";
  692. $sql_w .= "v.create_time between '" . to_timespan($_REQUEST['create_time_1']) . "' and '" . $create_time_2 . "' and ";
  693. }
  694. $parameter .= "live_in=0&";
  695. $sql_w .= "v.live_in=0 and ";
  696. $model = D();
  697. $sql_str = "SELECT v.*," .
  698. "(SELECT count(1) FROM " . DB_PREFIX . "child_room_viewer crv WHERE crv.child_room = v.id) as watch_number,cr.parent_id,watch_number + v.virtual_watch_number + v.robot_num as all_watch_number " .
  699. " FROM " . DB_PREFIX . "video_history v," . DB_PREFIX . "child_room cr WHERE v.id = cr.child_id ";
  700. $count_sql = "SELECT count(*) as tpcount FROM " . DB_PREFIX . "video_history v , " . DB_PREFIX . "child_room cr WHERE cr.child_id = v.id and 1=1 ";
  701. $sql_str .= " and " . $sql_w . " 1=1";
  702. $count_sql .= " and " . $sql_w . " 1=1";
  703. $voList = $this->_Sql_list($model, $sql_str, "&" . $parameter, 'sort_num', 0, $count_sql);
  704. //取洪峰观看人数
  705. foreach ($voList as &$value) {
  706. if (intval($value['live_in']) == 3) {
  707. $value['max_watch'] = "回播视频不显示";
  708. } else {
  709. $value['max_watch'] = "子房间不显示";
  710. }
  711. $value['pay_editable'] = 0;
  712. if (defined('OPEN_LIVE_PAY') && OPEN_LIVE_PAY == 1 && defined('OPEN_EDIT_VIDEO_PAY') && OPEN_EDIT_VIDEO_PAY == 1) {
  713. $value['pay_editable'] = 1;
  714. if ($value['is_live_pay'] == 1 && $value['live_pay_type'] == 0) {
  715. $value['pay_editable'] = 0;
  716. }
  717. }
  718. }
  719. if (defined('OPEN_LIVE_PAY') && OPEN_LIVE_PAY == 1) {
  720. $this->assign('is_pay_live', 1);
  721. } else {
  722. $this->assign('is_pay_live', 0);
  723. }
  724. $this->assign('url_name', get_manage_url_name());
  725. $this->assign('list', $voList);
  726. $cate_list = M("VideoCate")->findAll();
  727. $classified_list = M("VideoClassified")->findAll();
  728. $this->assign("classified_list", $classified_list);
  729. $this->assign("cate_list", $cate_list);
  730. $this->display();
  731. }
  732. //子房间账户关联列表
  733. public function account()
  734. {
  735. $now = get_gmtime();
  736. $parameter = '';
  737. $sql_w = '';
  738. if (strim($_REQUEST['nick_name']) != '') {
  739. //name
  740. $user = M("User")->where("nick_name like '%" . trim($_REQUEST['nick_name']) . "%' ")->findAll();
  741. foreach ($user as $k => $v) {
  742. $user_arr_id[$k] = intval($v['id']);
  743. }
  744. $parameter .= "user_id in (" . implode(",", $user_arr_id) . ")&";
  745. $sql_w .= "a.p_user_id in (" . implode(",", $user_arr_id) . ") and ";
  746. } else {
  747. if (intval($_REQUEST['user_id']) > 0) {
  748. $parameter .= "user_id=" . intval($_REQUEST['user_id']) . "&";
  749. $sql_w .= "a.p_user_id=" . intval($_REQUEST['user_id']) . " and ";
  750. }
  751. }
  752. $parameter .= " ";
  753. $sql_w .= " ";
  754. $model = D();
  755. $sql_str = "SELECT a.*," .
  756. " u.nick_name,u.head_image,u.thumb_head_image " .
  757. " FROM " . DB_PREFIX . "child_room_account a," . DB_PREFIX . "user u WHERE a.p_user_id = u.id ";
  758. $count_sql = "SELECT count(*) as tpcount FROM " . DB_PREFIX . "child_room_account a," . DB_PREFIX . "user u WHERE a.p_user_id = u.id ";
  759. $sql_str .= " and " . $sql_w . " 1=1";
  760. $count_sql .= " and " . $sql_w . " 1=1";
  761. $voList = $this->_Sql_list($model, $sql_str, "&" . $parameter, 'a.id', 0, $count_sql);
  762. foreach ($voList as &$value) {
  763. $value['head_image'] = get_spec_image($value['head_image']);
  764. if (empty($value['head_image'])) {
  765. $value['head_image'] = get_spec_image($value['thumb_head_image']);
  766. }
  767. }
  768. $this->assign('url_name', get_manage_url_name());
  769. $this->assign('list', $voList);
  770. $this->display();
  771. }
  772. //设置是否有效
  773. public function set_effect()
  774. {
  775. $id = intval($_REQUEST['id']);//树苗id
  776. $ajax = intval($_REQUEST['ajax']);
  777. $c_is_effect = M('ChildRoomAccount')->where("id=" . $id)->getField("is_effect"); //当前状态
  778. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  779. $result = M('ChildRoomAccount')->where("id=" . $id)->setField("is_effect", $n_is_effect);
  780. $this->ajaxReturn($n_is_effect, l("SET_EFFECT_" . $n_is_effect), 1);
  781. }
  782. //新增关联
  783. public function add_child_room_account()
  784. {
  785. $this->display();
  786. }
  787. //插入数据
  788. public function insert_child_room_account()
  789. {
  790. $data['room_title'] = strim($_REQUEST['room_title']);
  791. $data['price'] = strim($_REQUEST['price']);
  792. $data['p_user_id'] = intval($_REQUEST['p_user_id']);
  793. $data['c_user_id'] = strim($_REQUEST['c_user_id']);
  794. $data['video_code'] = strim($_REQUEST['video_code']);
  795. $data['is_effect'] = 1;
  796. if ($data['video_code'] != '') {
  797. if (!preg_match("/^[A-Za-z0-9]+$/", $data['video_code'])) {
  798. $return['error'] = "验证码只能是字母和数字";
  799. $return['status'] = 0;
  800. admin_ajax_return($return);
  801. }
  802. }
  803. if (empty($data['p_user_id'])) {
  804. admin_ajax_return(array(
  805. 'status' => 0,
  806. 'error' => '请输入主账号ID'
  807. ));
  808. }
  809. if (empty($data['c_user_id'])) {
  810. admin_ajax_return(array(
  811. 'status' => 0,
  812. 'error' => '请输子主账号ID'
  813. ));
  814. }
  815. if (M('ChildRoomAccount')->where('p_user_id =' . $data['p_user_id'])->count()) {
  816. admin_ajax_return(array(
  817. 'status' => 0,
  818. 'error' => '主账号用户子房间已存在'
  819. ));
  820. }
  821. $p_user = M('User')->where('id =' . $data['p_user_id'])->count();
  822. if (!$p_user) {
  823. admin_ajax_return(array(
  824. 'status' => 0,
  825. 'error' => '主账号用户不存在'
  826. ));
  827. }
  828. $user_id_arr = explode(',', $data['c_user_id']);
  829. $error_user = '';
  830. foreach ($user_id_arr as $value) {
  831. $c_user = M('User')->where('id =' . $value)->count();
  832. if (!$c_user) {
  833. $error_user .= $value . ',';
  834. }
  835. }
  836. if (!empty(trim($error_user))) {
  837. admin_ajax_return(array(
  838. 'status' => 0,
  839. 'error' => '子账号用户' . $error_user . '不存在'
  840. ));
  841. }
  842. $GLOBALS['db']->autoExecute(DB_PREFIX . "child_room_account", $data, 'INSERT');
  843. if ($GLOBALS['db']->affected_rows()) {
  844. admin_ajax_return(array(
  845. 'status' => 1,
  846. 'error' => '添加成功'
  847. ));
  848. }
  849. }
  850. //编辑关联
  851. public function edit_child_room_account()
  852. {
  853. $id = intval($_REQUEST['id']);
  854. $account_info = M('ChildRoomAccount')->where('id =' . $id)->find();
  855. $this->assign('vo', $account_info);
  856. $this->display();
  857. }
  858. //更新数据
  859. public function update_child_room_account()
  860. {
  861. $id = intval($_REQUEST['id']);
  862. $data['room_title'] = strim($_REQUEST['room_title']);
  863. $data['price'] = strim($_REQUEST['price']);
  864. $data['p_user_id'] = intval($_REQUEST['p_user_id']);
  865. $data['c_user_id'] = strim($_REQUEST['c_user_id']);
  866. $data['video_code'] = strim($_REQUEST['video_code']);
  867. if ($data['video_code'] != '') {
  868. if (!preg_match("/^[A-Za-z0-9]+$/", $data['video_code'])) {
  869. $return['error'] = "验证码只能是字母和数字";
  870. $return['status'] = 0;
  871. admin_ajax_return($return);
  872. }
  873. }
  874. $account_info = M('ChildRoomAccount')->where('id =' . $id)->find();
  875. if (empty($data['p_user_id'])) {
  876. admin_ajax_return(array(
  877. 'status' => 0,
  878. 'error' => '请输入主账号ID'
  879. ));
  880. }
  881. if (empty($data['c_user_id'])) {
  882. admin_ajax_return(array(
  883. 'status' => 0,
  884. 'error' => '请输子主账号ID'
  885. ));
  886. }
  887. if ($data['p_user_id'] != $account_info['p_user_id']) {
  888. if (M('ChildRoomAccount')->where('p_user_id =' . $data['p_user_id'])->count()) {
  889. admin_ajax_return(array(
  890. 'status' => 0,
  891. 'error' => '主账号用户子房间已存在'
  892. ));
  893. }
  894. }
  895. $p_user = M('User')->where('id =' . $data['p_user_id'])->count();
  896. if (!$p_user) {
  897. admin_ajax_return(array(
  898. 'status' => 0,
  899. 'error' => '主账号用户不存在'
  900. ));
  901. }
  902. $user_id_arr = explode(',', $data['c_user_id']);
  903. $error_user = '';
  904. foreach ($user_id_arr as $value) {
  905. $c_user = M('User')->where('id =' . $value)->count();
  906. if (!$c_user) {
  907. $error_user .= $value . ',';
  908. }
  909. }
  910. if (!empty(trim($error_user))) {
  911. admin_ajax_return(array(
  912. 'status' => 0,
  913. 'error' => '子账号用户' . $error_user . '不存在'
  914. ));
  915. }
  916. $GLOBALS['db']->autoExecute(DB_PREFIX . "child_room_account", $data, 'UPDATE', 'id =' . $id);
  917. if ($GLOBALS['db']->affected_rows()) {
  918. admin_ajax_return(array(
  919. 'status' => 1,
  920. 'error' => '编辑成功'
  921. ));
  922. }
  923. }
  924. }