EduDealAction.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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 EduDealAction extends CommonAction
  10. {
  11. public function index()
  12. {
  13. //把已直播的项目更新为已直播
  14. $this->update_deal_video_success();
  15. if (trim($_REQUEST['name']) != '') {
  16. $map['name'] = array('like', '%' . trim($_REQUEST['name']) . '%');
  17. }
  18. $user_id = intval($_REQUEST['user_id']);
  19. if ($user_id) {
  20. $map['user_id'] = array('eq', $user_id);
  21. }
  22. $create_time_2 = empty($_REQUEST['create_time_2']) ? to_date(get_gmtime(),
  23. 'Y-m-d') : strim($_REQUEST['create_time_2']);
  24. $create_time_2 = to_timespan($create_time_2) + 24 * 3600;
  25. if (trim($_REQUEST['create_time_1']) != '') {
  26. $map["create_time"] = array('between', array(to_timespan($_REQUEST['create_time_1']), $create_time_2));
  27. }
  28. $map['deal_status'] = 1;
  29. $map['is_delete'] = 0;
  30. if (method_exists($this, '_filter')) {
  31. $this->_filter($map);
  32. }
  33. $name = 'EduDeal';
  34. $model = M($name);
  35. if (!empty ($model)) {
  36. $this->_list($model, $map);
  37. }
  38. $this->display();
  39. }
  40. public function add()
  41. {
  42. }
  43. public function edit()
  44. {
  45. $id = intval($_REQUEST ['id']);
  46. $condition['id'] = $id;
  47. $vo = M("EduDeal")->where($condition)->find();
  48. //状态
  49. if ($vo['deal_status'] == 1) {
  50. $vo['deal_status_name'] = '通过';
  51. } elseif ($vo['deal_status'] == 2) {
  52. $vo['deal_status_name'] = '未审核';
  53. } elseif ($vo['deal_status'] == 3) {
  54. $vo['deal_status_name'] = '未通过';
  55. }
  56. $vo['begin_time'] = to_date(to_timespan($vo['begin_time']), 'Y-m-d');
  57. $vo['end_time'] = to_date(to_timespan($vo['end_time']), 'Y-m-d');
  58. $vo['image'] = get_spec_image($vo['image']);
  59. $this->assign('vo', $vo);
  60. //分类
  61. $cate_list = M("EduCourseCategory")->where("is_effect=1")->findAll();
  62. $this->assign('cate_list', $cate_list);
  63. //项目支付成功订单数
  64. $this->assign('order_count', $this->get_deal_order_count($id));
  65. //拥金
  66. $this->assign('default_pay_radio', app_conf("PAY_RADIO"));
  67. $this->display();
  68. }
  69. public function delete()
  70. {
  71. //彻底删除指定记录
  72. $ajax = intval($_REQUEST['ajax']);
  73. $id = $_REQUEST ['id'];
  74. if (isset ($id)) {
  75. $condition = array('id' => array('in', explode(',', $id)));
  76. $rel_data = M('EduDeal')->where($condition)->findAll();
  77. foreach ($rel_data as $data) {
  78. $num = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "edu_deal_order where deal_id = " . $data['id'] . " and order_status=1 and is_refund=0");
  79. if (intval($num) > 0) {
  80. $this->error($data['name'] . "[ID:" . $data['id'] . "]已经有人成功付款,无法删除", $ajax);
  81. }
  82. $info[] = $data['name'];
  83. }
  84. if ($info) {
  85. $info = implode(",", $info);
  86. }
  87. $list = M('EduDeal')->where($condition)->setField("is_delete", 1);
  88. if ($list !== false) {
  89. save_log($info . "成功移到回收站", 1);
  90. $this->success("成功移到回收站", $ajax);
  91. } else {
  92. save_log($info . "移到回收站出错", 0);
  93. $this->error("移到回收站出错", $ajax);
  94. }
  95. } else {
  96. $this->error(l("INVALID_OPERATION"), $ajax);
  97. }
  98. }
  99. public function insert()
  100. {
  101. }
  102. public function update()
  103. {
  104. B('FilterString');
  105. $data = M("EduDeal")->create();
  106. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  107. $deal_info = M("EduDeal")->where("id=" . intval($data['id']))->find();
  108. if (!$deal_info) {
  109. $this->error("发起人不存在");
  110. }
  111. //项目已有支付成功的订单时,不可以修改的字段用项目原数据覆盖
  112. $order_count = $this->get_deal_order_count($data['id']);
  113. if ($order_count > 0) {
  114. $data['begin_time'] = $deal_info['begin_time'];
  115. $data['limit_num'] = $deal_info['limit_num'];
  116. $data['price'] = $deal_info['price'];
  117. $data['pay_radio'] = $deal_info['pay_radio'];
  118. }
  119. $user_info = M("User")->where(array('id' => $deal_info['user_id'], 'is_effect' => 1))->find();
  120. if (empty($user_info)) {
  121. $this->error("发起人不存在");
  122. }
  123. if (!$deal_info) {
  124. $this->error("请选择编辑的项目");
  125. }
  126. if ($data['name'] == '') {
  127. $this->error("请输入项目名称");
  128. }
  129. if (msubstr($data['name'], 0, 30, "utf-8", false) != $data['name']) {
  130. $this->error("项目名称不能超过30个字");
  131. }
  132. if (empty($data['image'])) {
  133. $this->error("项目名称不能超过30个字");
  134. $root['error'] = '请上传图片';
  135. return api_ajax_return($root);
  136. }
  137. if (empty($data['description'])) {
  138. $this->error("请输入详情描述");
  139. }
  140. $day_second = 24 * 60 * 60;
  141. $begin_time_num = to_timespan(to_date(to_timespan($data['begin_time']), 'Y-m-d'));
  142. $end_time_num = to_timespan(to_date(to_timespan($data['end_time']), 'Y-m-d')) + $day_second;
  143. $video_begin_time_num = to_timespan($data['video_begin_time']);
  144. if (!$begin_time_num) {
  145. $this->error("请输入项目开始时间");
  146. }
  147. if (!$end_time_num) {
  148. $this->error("请输入项目结束时间");
  149. }
  150. if (!$video_begin_time_num) {
  151. $this->error("请输入直播开始时间");
  152. }
  153. if ($end_time_num <= $begin_time_num) {
  154. $this->error("项目结束时间小于开始时间");;
  155. }
  156. if ($video_begin_time_num <= $end_time_num) {
  157. $this->error("直播开始时间要大于项目结束时间");
  158. }
  159. if ($data['limit_num'] <= 0) {
  160. $this->error("请输入目标数量");
  161. }
  162. if ($data['price'] <= 0) {
  163. $this->error("请输入支持价格");
  164. }
  165. // 更新数据
  166. $data['begin_time'] = to_date($begin_time_num);
  167. $data['end_time'] = to_date($end_time_num - $day_second);
  168. $data['video_begin_time'] = to_date($video_begin_time_num - $video_begin_time_num % 60);
  169. $list = M("EduDeal")->save($data);
  170. $log_info = $data['name'] . "(ID:" . $data['id'] . ")";
  171. if (false !== $list) {
  172. //通知发起人项目状态
  173. if ($deal_info['is_effect'] == 0 && $data['is_effect'] == 1) {
  174. $time = to_date(NOW_TIME, 'm-d H:i:s');
  175. FanweServiceCall('edu_video', 'push_deal', array(
  176. 'user_id' => $deal_info['user_id'],
  177. 'content' => "您发起的{$deal_info['name']},{$time}审核上架",
  178. ));
  179. $class_id = $GLOBALS['db']->insert_id();
  180. $push_data = array(
  181. 'user_id' => $user_info['id'],
  182. 'nick_name' => $user_info['nick_name'],
  183. 'create_time' => NOW_TIME,
  184. 'content' => $user_info['nick_name'] . "发起了众筹「" . $deal_info['name'] . "」,去看看",
  185. 'ext_id' => $class_id,
  186. 'head_image' => get_spec_image($user_info['head_image']),
  187. 'status' => 0,//'推送状态(0:未推送,1:推送中;2:已推送)'
  188. 'push_type' => 0, //'推送状态(0:粉丝推送,1:全服推送)';
  189. 'type' => 10,
  190. );
  191. $GLOBALS['db']->autoExecute(DB_PREFIX . "edu_push_anchor", $push_data, 'INSERT');
  192. }
  193. //成功提示
  194. $this->assign("jumpUrl", u(MODULE_NAME . "/index", array("id" => $data['id'])));
  195. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  196. $this->success(L("UPDATE_SUCCESS"));
  197. } else {
  198. //错误提示
  199. save_log($log_info . L("UPDATE_FAILED"), 0);
  200. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  201. }
  202. }
  203. public function toogle_status()
  204. {
  205. $id = intval($_REQUEST['id']);
  206. $ajax = intval($_REQUEST['ajax']);
  207. $field = $_REQUEST['field'];
  208. $info = $id . "_" . $field;
  209. $c_is_effect = M(MODULE_NAME)->where("id=" . $id)->getField($field); //当前状态
  210. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  211. M(MODULE_NAME)->where("id=" . $id)->setField($field, $n_is_effect);
  212. //删除缓存
  213. save_log($info . l("SET_EFFECT_" . $n_is_effect), 1);
  214. $this->ajaxReturn($n_is_effect, l("SET_EFFECT_" . $n_is_effect), 1);
  215. }
  216. public function get_deal_order_count($id)
  217. {
  218. $order_count = M("EduDealOrder")->where("deal_id=" . intval($id) . " and order_status=1")->count();
  219. return intval($order_count);
  220. }
  221. /**
  222. * 支持列表
  223. */
  224. public function deal_support()
  225. {
  226. $deal_id = $_REQUEST['deal_id'];
  227. $deal_info = M("EduDeal")->where("id=" . intval($deal_id) . "")->find();
  228. if (!$deal_info) {
  229. $this->errors("众筹项目不存在");
  230. }
  231. $this->assign("deal_info", $deal_info);
  232. //列表过滤器,生成查询Map对象
  233. $map = $this->_search();
  234. $map['deal_id'] = $deal_id;
  235. $map['order_status'] = 1;
  236. //追加默认参数
  237. if ($this->get("default_map")) {
  238. $map = array_merge($map, $this->get("default_map"));
  239. }
  240. if (isset($_REQUEST['is_refund'])) {
  241. if ($_REQUEST['is_refund'] != 'NULL') {
  242. $map['is_refund'] = intval($_REQUEST['is_refund']);
  243. }
  244. }
  245. if (method_exists($this, '_filter')) {
  246. $this->_filter($map);
  247. }
  248. $model = M('EduDealOrder');
  249. if (!empty ($model)) {
  250. $this->_list($model, $map);
  251. }
  252. $this->display();
  253. }
  254. public function delete_order()
  255. {
  256. //彻底删除指定记录
  257. $ajax = intval($_REQUEST['ajax']);
  258. $id = $_REQUEST ['id'];
  259. if (isset ($id)) {
  260. $condition = array('id' => array('in', explode(',', $id)));
  261. $rel_data = M("EduDealOrder")->where($condition)->findAll();
  262. foreach ($rel_data as $data) {
  263. $info[] = "[项目ID" . $data['deal_id'] . "支持人ID:" . $data['user_id'] . "状态:" . $data['order_status'] . "]";
  264. $deal_ids[$data['deal_id']] = $data['deal_id'];
  265. }
  266. if ($info) {
  267. $info = implode(",", $info);
  268. }
  269. $list = M("EduDealOrder")->where($condition)->delete();
  270. if ($list !== false) {
  271. foreach ($deal_ids as $d_id) {
  272. FanweServiceCall('edu_deal', 'syn_deal', $d_id);
  273. }
  274. save_log($info . "成功删除", 1);
  275. $this->success("成功删除", $ajax);
  276. } else {
  277. save_log($info . "删除出错", 0);
  278. $this->error("删除出错", $ajax);
  279. }
  280. } else {
  281. $this->error(l("INVALID_OPERATION"), $ajax);
  282. }
  283. }
  284. public function order_refund()
  285. {
  286. $id = intval($_REQUEST['id']);
  287. $order_info = M("EduDealOrder")->getById($id);
  288. if ($order_info) {
  289. $count_pay_log = M("EduDealPayLog")->where("deal_id=" . intval($order_info['deal_id']))->count();
  290. if ($count_pay_log > 0) {
  291. $this->error("筹款已发,不能退款");
  292. }
  293. if ($order_info['is_refund'] == 0 && $order_info['order_status'] == 1) {
  294. $GLOBALS['db']->query("update " . DB_PREFIX . "edu_deal_order set is_refund = 1 where id = " . $id . " and is_refund = 0 and order_status=1");
  295. if ($GLOBALS['db']->affected_rows() > 0) {
  296. $deal_name = M("EduDeal")->where("id=" . intval($order_info['deal_id']) . "")->getField("name");
  297. $msg = "众筹直播(" . $deal_name . ")退款";
  298. require_once APP_ROOT_PATH . "system/libs/user.php";
  299. //会员钻石增加
  300. modify_account(array("diamonds" => ($order_info['pay'])), $order_info['user_id'], $msg,
  301. array('type' => 20));
  302. //会员账户 钻石变更日志表
  303. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/common_edu.php');
  304. insert_user_diamonds_log(array('diamonds' => $order_info['pay']), $order_info['user_id'], $msg, 6,
  305. $order_info['id']);
  306. //同步项目记录
  307. FanweServiceCall('edu_deal', 'syn_deal', $order_info['deal_id']);
  308. }
  309. $this->success("成功退款到会员余额");
  310. } elseif ($order_info['is_refund'] == 0 && $order_info['order_status'] == 0) {
  311. $this->error("订单未付款");
  312. } else {
  313. $this->error("已经退款");
  314. }
  315. } else {
  316. $this->error("没有该项目的支持");
  317. }
  318. }
  319. /**
  320. * 批量退款
  321. */
  322. public function batch_refund()
  323. {
  324. $page = intval($_REQUEST['page']);
  325. $page = ($page <= 0) ? 1 : $page;
  326. $page_size = 100;
  327. $deal_id = intval($_REQUEST['id']);
  328. $limit = (($page - 1) * $page_size) . "," . $page_size;
  329. $now_time = to_date(to_timespan(to_date(get_gmtime(), 'Y-m-d')));
  330. $deal_info = M("EduDeal")->where("id=" . $deal_id . " and is_delete = 0 and is_effect = 1 and is_success = 0 and end_time <'" . $now_time . "'")->find();
  331. if (!$deal_info) {
  332. $this->error("该项目不能批量退款");
  333. } else {
  334. require_once APP_ROOT_PATH . "system/libs/user.php";
  335. require_once APP_ROOT_PATH . "mapi/lib/core/common_edu.php";
  336. $refund_order_list = M("EduDealOrder")->where("deal_id=" . $deal_id . " and is_refund = 0 and order_status = 1")->limit($limit)->findAll();
  337. foreach ($refund_order_list as $k => $v) {
  338. $GLOBALS['db']->query("update " . DB_PREFIX . "edu_deal_order set is_refund = 1 where id = " . $v['id']);
  339. if ($GLOBALS['db']->affected_rows() > 0) {
  340. $msg = "众筹直播(" . $deal_info['name'] . ")退款";
  341. //会员钻石增加
  342. modify_account(array("diamonds" => ($v['pay'])), $v['user_id'], $msg, array('type' => 20));
  343. //会员账户 钻石变更日志表
  344. insert_user_diamonds_log(array('diamonds' => $v['pay']), $v['user_id'], $msg, 6, $v['id']);
  345. }
  346. }
  347. //同步项目记录
  348. FanweServiceCall('edu_deal', 'syn_deal', $deal_info['id']);
  349. $remain = M("EduDealOrder")->where("deal_id=" . $deal_id . " and is_refund = 0 and order_status = 1")->count();
  350. if ($remain == 0) {
  351. $jump_url = u("EduDeal/index");
  352. $this->assign("jumpUrl", $jump_url);
  353. $this->success("批量退款成功");
  354. } else {
  355. $jump_url = u("EduDeal/batch_refund", array("id" => $deal_id, "page" => $page + 1));
  356. $this->assign("jumpUrl", $jump_url);
  357. $this->success("批量退款中,请勿刷新页面,剩余" . $remain . "条订单未退款");
  358. }
  359. }
  360. }
  361. /**
  362. * 结算
  363. */
  364. public function pay_log()
  365. {
  366. $deal_id = intval($_REQUEST['id']);
  367. $deal_info = M("EduDeal")->getById($deal_id);
  368. //拥金
  369. $deal_info['commission'] = $deal_info['support_amount'] - ($deal_info['pay_amount']);
  370. $this->assign("deal_info", $deal_info);
  371. if ($deal_info) {
  372. $map['deal_id'] = $deal_info['id'];
  373. $model = D("EduDealPayLog");
  374. $paid_money = intval($model->where($map)->sum("money"));
  375. $remain_money = intval($deal_info['pay_amount'] - $paid_money);
  376. $this->assign("remain_money", $remain_money);
  377. $this->assign("paid_money", $paid_money);
  378. if (!empty ($model)) {
  379. $this->_list($model, $map);
  380. }
  381. }
  382. $this->display();
  383. }
  384. /**
  385. * 发款
  386. */
  387. public function add_pay_log()
  388. {
  389. $deal_id = intval($_REQUEST['id']);
  390. $deal_info = M("EduDeal")->where("is_success=1 and is_video=1 and id=" . $deal_id . "")->find();
  391. if (!$deal_info) {
  392. echo '<div style="padding:20px 0px;text-align:center;">项目不能结算</div>';
  393. return false;
  394. }
  395. //拥金
  396. $deal_info['commission'] = $deal_info['support_amount'] - ($deal_info['pay_amount']);
  397. $this->assign("deal_info", $deal_info);
  398. $map['deal_id'] = $deal_info['id'];
  399. $model = D("EduDealPayLog");
  400. $paid_money = intval($model->where($map)->sum("money"));
  401. $remain_money = intval($deal_info['pay_amount'] - $paid_money);
  402. $this->assign("paid_money", $paid_money);
  403. $this->assign("remain_money", $remain_money);
  404. $this->display();
  405. }
  406. /**
  407. * 确认发款
  408. */
  409. public function save_pay_log()
  410. {
  411. $deal_id = intval($_REQUEST['id']);
  412. $deal_info = M("EduDeal")->where("is_success=1 and is_video=1 and id=" . $deal_id . "")->find();
  413. $log_info = strim($_REQUEST['log_info']);
  414. if (!$deal_info) {
  415. $this->error("项目不能结算");
  416. }
  417. $map['deal_id'] = $deal_info['id'];
  418. $model = D("EduDealPayLog");
  419. $paid_money = $model->where($map)->sum("money");
  420. $remain_money = $deal_info['pay_amount'] - $paid_money;
  421. $money = $remain_money;
  422. if ($remain_money <= 0) {
  423. $this->error("已结算完了");
  424. }
  425. $user_info = M("user")->where("id=" . $deal_info['user_id'] . " and is_effect=1 ")->find();
  426. if (!$user_info) {
  427. $this->error("无效的项目发起人");
  428. }
  429. $log_info = $log_info == "" ? $deal_info['name'] . "项目结算" : $log_info;
  430. //增加发起人印票
  431. $ticket = $money;
  432. $GLOBALS['db']->query("update " . DB_PREFIX . "user set ticket = ticket + " . $ticket . " where id = " . $deal_info['user_id'] . " ");
  433. $re = $GLOBALS['db']->affected_rows();
  434. if ($re) {
  435. //更年新reids
  436. user_deal_to_reids(array($deal_info['user_id']));
  437. //印票变更日志表
  438. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/common_edu.php');
  439. insert_user_diamonds_log(array('ticket' => $money), $deal_info['user_id'], $log_info . "获得印票", 7,
  440. $deal_info['id']);
  441. //写入用户日志
  442. $data = array();
  443. $data['ticket'] = $ticket;
  444. $param['type'] = 20;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4表示保证金操作 5表示竞拍模块消费 6表示竞拍模块收益 20教育
  445. $log_msg = $log_info;//备注
  446. account_log_com($data, $deal_info['user_id'], $log_msg, $param);
  447. //写入发放日志
  448. $log['deal_id'] = $deal_info['id'];
  449. $log['money'] = $money;
  450. $log['create_time'] = get_gmtime();
  451. $log['log_info'] = $log_info;
  452. $model->add($log);
  453. save_log($log_info . $money, 1);
  454. FanweServiceCall('edu_deal', 'syn_deal', $deal_id);
  455. //通知发起人
  456. $this->success("结算成功");
  457. } else {
  458. $this->success("结算失败");
  459. }
  460. }
  461. /*
  462. *众筹项目直播列表
  463. * */
  464. public function deal_videos()
  465. {
  466. $deal_id = $_REQUEST['deal_id'];
  467. $deal = M("EduDeal")->where("id=" . $deal_id . "")->find();
  468. if ($deal) {
  469. $sql = "SELECT v.*,watch_number+virtual_watch_number+robot_num as all_watch_number,u.nick_name FROM " . DB_PREFIX . "video v LEFT JOIN " . DB_PREFIX . "user u ON u.id = v.user_id LEFT JOIN " . DB_PREFIX . "edu_video_info as ev ON ev.video_id = v.id
  470. where v.live_in in (1,3) and ev.deal_id=" . $deal_id . " order by v.id desc";
  471. $list = $GLOBALS['db']->getAll($sql, true, true);
  472. $sql2 = "SELECT v.*,watch_number+virtual_watch_number+robot_num as all_watch_number,u.nick_name FROM " . DB_PREFIX . "video_history v LEFT JOIN " . DB_PREFIX . "user u ON u.id = v.user_id LEFT JOIN " . DB_PREFIX . "edu_video_info as ev ON ev.video_id = v.id
  473. where v.group_id!='' and v.is_delete = 0 and v.is_del_vod = 0 and ev.deal_id=" . $deal_id . " order by v.id desc";
  474. $list2 = $GLOBALS['db']->getAll($sql2, true, true);
  475. $list = array_merge($list, $list2);
  476. } else {
  477. $list = array();
  478. }
  479. $this->assign('deal', $deal);
  480. $this->assign('list', $list);
  481. $this->display();
  482. }
  483. //查看直播(web2.1播放器)
  484. public function play()
  485. {
  486. $id = $_REQUEST['id'];
  487. $condition['id'] = $id;
  488. $video = M('Video')->where($condition)->find();
  489. if ($video) {
  490. $video = M('VideoHistory')->where($condition)->find();
  491. }
  492. $m_config = load_auto_cache("m_config");//初始化手机端配置
  493. $app_id = $m_config['vodset_app_id'];
  494. $this->assign('app_id', $app_id);
  495. if ($video) {
  496. require_once APP_ROOT_PATH . "/mapi/lib/core/common.php";
  497. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  498. $root = get_vodset_by_video_id($id);
  499. if (isset($root['vodset'])) {
  500. $play_list = array();
  501. $vodset = $root['vodset'];
  502. foreach ($vodset as $k => $v) {
  503. $playSet = $v['fileSet'];
  504. for ($i = sizeof($playSet) - 1; $i >= 0; $i--) {
  505. $play_list[] = $playSet[$i]['fileId'];
  506. $play_url_list[] = $playSet[$i]['playSet'];
  507. }
  508. }
  509. foreach ($play_url_list as $k2 => $v2) {
  510. foreach ($v2 as $kk => $vv) {
  511. //mp4
  512. if ($vv['definition'] == 0 && strpos($vv['url'], '.mp4')) {//原画mp4 播放URL
  513. $video['mp4_url'] = $vv['url'];
  514. }
  515. if ($vv['definition'] == 10) {//手机mp4 播放URL
  516. $video['mp4_sj_url'] = $vv['url'];
  517. }
  518. if ($vv['definition'] == 20) {//标清mp4 播放URL
  519. $video['mp4_sd_url'] = $vv['url'];
  520. }
  521. if ($vv['definition'] == 40 || $vv['definition'] == 30) {//高清mp4 播放URL
  522. $video['mp4_hd_url'] = $vv['url'];
  523. }
  524. //m3u8
  525. if ($vv['definition'] == 0 && strpos($vv['url'], '.m3u8')) {//原画m3u8 播放URL
  526. $video['m3u8_url'] = $vv['url'];
  527. }
  528. if (($vv['definition'] == 210) && strpos($vv['url'], '.m3u8')) {//手机m3u8 播放URL
  529. $video['m3u8_url'] = $vv['url'];
  530. }
  531. if (($vv['definition'] == 220) && strpos($vv['url'], '.m3u8')) {//标清m3u8 播放URL
  532. $video['m3u8_sd_url'] = $vv['url'];
  533. }
  534. if (($vv['definition'] == 230) && strpos($vv['url'], '.m3u8')) {//高清m3u8 播放URL
  535. $video['m3u8_hd_url'] = $vv['url'];
  536. }
  537. //flv
  538. if (strpos($vv['url'], '.flv') && $vv['definition'] == 0) {//原画flv 播放URL
  539. $video['flv_url'] = $vv['url'];
  540. }
  541. if (strpos($vv['url'], '.flv') && $vv['definition'] == 0) {//手机flv 播放URL
  542. $video['flv_sj_url'] = $vv['url'];
  543. }
  544. if (strpos($vv['url'], '.flv') && $vv['definition'] == 0) {//标清flv 播放URL
  545. $video['flv_sd_url'] = $vv['url'];
  546. }
  547. if (strpos($vv['url'], '.flv') && $vv['definition'] == 0) {//高清flv 播放URL
  548. $video['flv_hd_url'] = $vv['url'];
  549. }
  550. //rtmp
  551. if (!strpos($vv['url'], '.flv') && !strpos($vv['url'], '.mp4') && !strpos($vv['url'],
  552. '.m3u8') && $vv['definition'] == 0
  553. ) {//原画rtmp 播放URL
  554. $video['rtmp_url'] = $vv['url'];
  555. }
  556. if (!strpos($vv['url'], '.flv') && !strpos($vv['url'], '.mp4') && !strpos($vv['url'],
  557. '.m3u8') && $vv['definition'] == 0
  558. ) {//手机rtmp 播放URL
  559. $video['rtmp_sj_url'] = $vv['url'];
  560. }
  561. if (!strpos($vv['url'], '.flv') && !strpos($vv['url'], '.mp4') && !strpos($vv['url'],
  562. '.m3u8') && $vv['definition'] == 0
  563. ) {//标清rtmp 播放URL
  564. $video['rtmp_sd_url'] = $vv['url'];
  565. }
  566. if (!strpos($vv['url'], '.flv') && !strpos($vv['url'], '.mp4') && !strpos($vv['url'],
  567. '.m3u8') && $vv['definition'] == 0
  568. ) {//高清rtmp 播放URL
  569. $video['rtmp_hd_url'] = $vv['url'];
  570. }
  571. }
  572. }
  573. $this->assign("poster", $vodset[0]['fileSet'][sizeof($vodset[0]['fileSet']) - 1]['image_url']);
  574. } else {
  575. $this->assign("error", $root['error']);
  576. }
  577. } else {
  578. //直播
  579. $video['mp4_url'] = $video['play_mp4'];
  580. $video['m3u8_url'] = $video['play_hls'];
  581. $video['flv_url'] = $video['play_flv'];
  582. $video['rtmp_url'] = $video['play_rtmp'];
  583. }
  584. $this->assign("video", $video);
  585. $this->display();
  586. }
  587. /*
  588. * 把已直播的项目更新为已直播
  589. * */
  590. public function update_deal_video_success()
  591. {
  592. $deal_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "edu_deal where is_effect =1 and is_success=1 and is_video=0");
  593. foreach ($deal_list as $k => $v) {
  594. $sql = "select v.end_time,v.begin_time from " . DB_PREFIX . "edu_video_info as ev left join " . DB_PREFIX . "video as v on v.id=ev.video_id
  595. where ev.deal_id=" . intval($v['id']) . "";
  596. $video_list = $GLOBALS['db']->getAll($sql);
  597. foreach ($video_list as $k => $v) {
  598. if (($v['end_time'] - $v['begin_time']) >= (15 * 60)) {
  599. $GLOBALS['db']->query("update " . DB_PREFIX . "edu_deal set is_video=1,real_video_time=" . $v['begin_time'] . " where is_effect =1 and is_success=1 and is_video=0");
  600. break;
  601. }
  602. }
  603. }
  604. }
  605. }
  606. ?>