EduDealSubmitAction.class.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 EduDealSubmitAction extends CommonAction
  10. {
  11. const AUTH_TYPE_TEACHER = '教师';//教师认证类型
  12. const AUTH_TYPE_ORG = '机构';//机构认证类型
  13. public function index()
  14. {
  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'] = array('in', '2,3');
  29. $map['is_effect'] = 0;
  30. $map['is_delete'] = 0;
  31. if (method_exists($this, '_filter')) {
  32. $this->_filter($map);
  33. }
  34. $name = 'EduDeal';
  35. $model = M($name);
  36. if (!empty ($model)) {
  37. $this->_list($model, $map);
  38. }
  39. $this->display();
  40. }
  41. public function edit()
  42. {
  43. $id = intval($_REQUEST ['id']);
  44. $condition['id'] = $id;
  45. $vo = M("EduDeal")->where($condition)->find();
  46. //状态
  47. if ($vo['deal_status'] == 1) {
  48. $vo['deal_status_name'] = '通过';
  49. } elseif ($vo['deal_status'] == 2) {
  50. $vo['deal_status_name'] = '未审核';
  51. } elseif ($vo['deal_status'] == 3) {
  52. $vo['deal_status_name'] = '未通过';
  53. }
  54. $vo['begin_time'] = to_date(to_timespan($vo['begin_time']), 'Y-m-d');
  55. $vo['end_time'] = to_date(to_timespan($vo['end_time']), 'Y-m-d');
  56. $vo['image'] = get_spec_image($vo['image']);
  57. //排序
  58. $max_sort = M("EduDeal")->max("sort");
  59. $this->assign('new_sort', $max_sort + 1);
  60. $this->assign('vo', $vo);
  61. //分类
  62. $cate_list = M("EduCourseCategory")->where("is_effect=1")->findAll();
  63. $this->assign('cate_list', $cate_list);
  64. //拥金
  65. $this->assign('default_pay_radio', app_conf("PAY_RADIO"));
  66. $this->display();
  67. }
  68. public function update()
  69. {
  70. B('FilterString');
  71. $data = M("EduDeal")->create();
  72. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  73. if ($data['deal_status'] != 1 && $data['deal_status'] != 3) {
  74. $this->error("请选择审核的操作");
  75. }
  76. $deal_info = M("EduDeal")->where("id=" . intval($data['id']))->find();
  77. $deal_user = M("User")->where("id=" . intval($deal_info['user_id']) . " and is_effect=1")->find();
  78. if (!$deal_user) {
  79. $this->error("发起人不存在");
  80. }
  81. if (!$deal_info) {
  82. $this->error("请选择审核的项目");
  83. }
  84. $day_second = 24 * 60 * 60;
  85. $begin_time_num = to_timespan(to_date(to_timespan($data['begin_time']), 'Y-m-d'));
  86. $end_time_num = to_timespan(to_date(to_timespan($data['end_time']), 'Y-m-d')) + $day_second;
  87. $video_begin_time_num = to_timespan($data['video_begin_time']);
  88. if ($data['deal_status'] == 1) {
  89. if ($data['name'] == '') {
  90. $this->error("请输入项目名称");
  91. }
  92. if (msubstr($data['name'], 0, 30, "utf-8", false) != $data['name']) {
  93. $this->error("项目名称不能超过30个字");
  94. }
  95. if (empty($data['image'])) {
  96. $this->error("项目名称不能超过30个字");
  97. $root['error'] = '请上传图片';
  98. return api_ajax_return($root);
  99. }
  100. if (!$begin_time_num) {
  101. $this->error("请输入项目开始时间");
  102. }
  103. if (!$end_time_num) {
  104. $this->error("请输入项目结束时间");
  105. }
  106. if (!$video_begin_time_num) {
  107. $this->error("请输入直播开始时间");
  108. }
  109. if ($begin_time_num < to_timespan(to_date(NOW_TIME, 'Y-m-d'))) {
  110. $this->error("开始时间不能小于当前时间");
  111. }
  112. if ($end_time_num < NOW_TIME) {
  113. $this->error("结束时间不能小于当前时间");
  114. }
  115. if ($end_time_num < $begin_time_num) {
  116. $this->error("结束时间不能小于开始时间");
  117. }
  118. if ($video_begin_time_num <= $end_time_num) {
  119. $this->error("直播开始时间要大于项目结束时间");
  120. }
  121. if ($data['limit_num'] <= 0) {
  122. $this->error("请输入目标数量");
  123. }
  124. if ($data['price'] <= 0) {
  125. $this->error("请输入支持价格");
  126. }
  127. if (empty($data['description'])) {
  128. $this->error("请输入详情描述");
  129. }
  130. //获取会员的tags写入项目中
  131. if ($deal_user['authentication_type'] == self::AUTH_TYPE_TEACHER) {
  132. $data['tags'] = M("EduTeacher")->where("user_id = " . $deal_user['id'] . "")->getField("tags");
  133. } elseif ($deal_user['authentication_type'] == self::AUTH_TYPE_ORG) {
  134. $data['tags'] = M("EduOrg")->where("user_id=" . $deal_user['id'] . "")->getField("tags");
  135. }
  136. } elseif ($data['deal_status'] == 3) {
  137. if (empty($data['no_pass_memo'])) {
  138. $this->error("请输入未通过理由");
  139. }
  140. $data['is_effect'] = 0;
  141. $data['sort'] = 0;
  142. }
  143. // 更新数据
  144. $data['begin_time'] = to_date($begin_time_num);
  145. $data['end_time'] = to_date($end_time_num - $day_second);
  146. $data['video_begin_time'] = to_date($video_begin_time_num - $video_begin_time_num % 60);
  147. $list = M("EduDeal")->save($data);
  148. $log_info = $deal_info['title'] . "(ID:" . $deal_info['id'] . ")";
  149. if (false !== $list) {
  150. //通知发起人项目状态
  151. if ($data['deal_status'] == 1 && $data['is_effect'] == 1) {
  152. $time = to_date(NOW_TIME, 'm-d H:i:s');
  153. FanweServiceCall('edu_video', 'push_deal', array(
  154. 'user_id' => $deal_info['user_id'],
  155. 'content' => "您发起的{$deal_info['name']},{$time}审核上架",
  156. ));
  157. }
  158. //成功提示
  159. $this->assign("jumpUrl", u(MODULE_NAME . "/index", array("id" => $data['id'])));
  160. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  161. $this->success(L("UPDATE_SUCCESS"));
  162. } else {
  163. //错误提示
  164. save_log($log_info . L("UPDATE_FAILED"), 0);
  165. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  166. }
  167. }
  168. public function foreverdelete()
  169. {
  170. //彻底删除指定记录
  171. $ajax = intval($_REQUEST['ajax']);
  172. $id = $_REQUEST ['id'];
  173. if (isset ($id)) {
  174. $condition = array('id' => array('in', explode(',', $id)));
  175. $rel_data = M("EduDeal")->where($condition)->findAll();
  176. foreach ($rel_data as $data) {
  177. $info[] = $data['title'];
  178. }
  179. if ($info) {
  180. $info = implode(",", $info);
  181. }
  182. $list = M("EduDeal")->where($condition)->delete();
  183. if ($list !== false) {
  184. save_log($info . l("FOREVER_DELETE_SUCCESS"), 1);
  185. $this->success(l("FOREVER_DELETE_SUCCESS"), $ajax);
  186. } else {
  187. save_log($info . l("FOREVER_DELETE_FAILED"), 0);
  188. $this->error(l("FOREVER_DELETE_FAILED"), $ajax);
  189. }
  190. } else {
  191. $this->error(l("INVALID_OPERATION"), $ajax);
  192. }
  193. }
  194. }
  195. ?>