DateAction.class.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 DateAction extends CommonAction{
  10. public function index()
  11. {
  12. if(strim($_REQUEST['title'])!=''){
  13. $map['title'] = array('like','%'.strim($_REQUEST['title']).'%');
  14. }
  15. if (method_exists ( $this, '_filter' )) {
  16. $this->_filter ( $map );
  17. }
  18. $name=$this->getActionName();
  19. $model = D ($name);
  20. if (! empty ( $model )) {
  21. $this->_list ( $model, $map );
  22. }
  23. $this->display ();
  24. }
  25. public function add()
  26. {
  27. $this->display();
  28. }
  29. public function edit() {
  30. $id = intval($_REQUEST ['id']);
  31. $condition['id'] = $id;
  32. $vo = M(MODULE_NAME)->where($condition)->find();
  33. $this->assign ( 'vo', $vo );
  34. $this->display ();
  35. }
  36. //彻底删除指定记录
  37. public function foreverdelete() {
  38. //彻底删除指定记录
  39. $ajax = intval($_REQUEST['ajax']);
  40. $id = $_REQUEST ['id'];
  41. if (isset ( $id )) {
  42. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  43. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  44. foreach($rel_data as $data)
  45. {
  46. $info[] = $data['title'];
  47. }
  48. if($info) $info = implode(",",$info);
  49. $list = M(MODULE_NAME)->where ( $condition )->delete();
  50. if ($list!==false) {
  51. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  52. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  53. } else {
  54. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  55. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  56. }
  57. } else {
  58. $this->error (l("INVALID_OPERATION"),$ajax);
  59. }
  60. }
  61. public function insert() {
  62. B('FilterString');
  63. $data = M(MODULE_NAME)->create ();
  64. //开始验证有效性
  65. $this->assign("jumpUrl",u(MODULE_NAME."/add"));
  66. if(!check_empty($data['title']))
  67. {
  68. $this->error("请输入项目标题");
  69. }
  70. if(!check_empty($data['price'])){
  71. $data['price'] = 0;
  72. //$this->error("请输入预约费用");
  73. }else{
  74. if(!preg_match('/^[0-9]+(.[0-9]{0,2})?$/', $data['price'])){
  75. $this->error("预约费用必须是数字且最多两位小数");
  76. }
  77. }
  78. // 更新数据
  79. $log_info = $data['title'];
  80. $data['create_time'] = NOW_TIME;
  81. $list=M(MODULE_NAME)->add($data);
  82. if (false !== $list) {
  83. //成功提示
  84. save_log($log_info.L("INSERT_SUCCESS"),1);
  85. $this->success(L("INSERT_SUCCESS"));
  86. } else {
  87. //错误提示
  88. save_log($log_info.L("INSERT_FAILED"),0);
  89. $this->error(L("INSERT_FAILED"));
  90. }
  91. }
  92. public function update() {
  93. B('FilterString');
  94. $data = M(MODULE_NAME)->create();
  95. $log_info = M(MODULE_NAME)->where("id=".intval($data['id']))->getField("title");
  96. //开始验证有效性
  97. $this->assign("jumpUrl",u(MODULE_NAME."/edit",array("id"=>$data['id'])));
  98. if(!check_empty($data['title']))
  99. {
  100. $this->error("请输入项目标题");
  101. }
  102. if(!check_empty($data['price'])){
  103. $data['price'] = 0;
  104. //$this->error("请输入预约费用");
  105. }else{
  106. if(!preg_match('/^[0-9]+(.[0-9]{0,2})?$/', $data['price'])){
  107. $this->error("预约费用必须是数字且最多两位小数");
  108. }
  109. }
  110. // 更新数据
  111. $list=M(MODULE_NAME)->save ($data);
  112. if (false !== $list) {
  113. //成功提示
  114. save_log($log_info.L("UPDATE_SUCCESS"),1);
  115. $this->success(L("UPDATE_SUCCESS"));
  116. } else {
  117. //错误提示
  118. save_log($log_info.L("UPDATE_FAILED"),0);
  119. $this->error(L("UPDATE_FAILED"),0,$log_info.L("UPDATE_FAILED"));
  120. }
  121. }
  122. //用户预约记录
  123. public function date_list(){
  124. $id = intval($_REQUEST['id']);
  125. $date = M(MODULE_NAME)->getById($id);
  126. $this->assign("date",$date);
  127. $map['date_id'] = $id;
  128. if (method_exists ( $this, '_filter' )) {
  129. $this->_filter ( $map );
  130. }
  131. $model = M ("UserDate");
  132. if (! empty ( $model )) {
  133. $this->_list ( $model, $map );
  134. }
  135. $this->assign ( 'module_name', MODULE_NAME );
  136. $this->display ();
  137. }
  138. //删除预约记录
  139. public function del_date_list(){
  140. //彻底删除指定记录
  141. $date_id = intval($_REQUEST['date_id']);
  142. $id = $_REQUEST ['id'];
  143. if (isset ( $id )) {
  144. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  145. $rel_data = M("UserDate")->where($condition)->findAll();
  146. foreach($rel_data as $data)
  147. {
  148. $info[] = $data['name'];
  149. }
  150. if($info) $info = implode(",",$info);
  151. $list = M("UserDate")->where ( $condition )->delete();
  152. if ($list!==false) {
  153. save_log("项目ID".$date_id."预约人".$info.l("FOREVER_DELETE_SUCCESS"),1);
  154. $result['status'] = 1;
  155. $result['info'] = '删除成功';
  156. } else {
  157. save_log("项目ID".$date_id."预约人".$info.l("FOREVER_DELETE_FAILED"),0);
  158. $result['status'] = 0;
  159. $result['info'] = '删除失败';
  160. }
  161. } else {
  162. $result['status'] = 0;
  163. $result['info'] = '编号错误';
  164. }
  165. admin_ajax_return($result);
  166. }
  167. //改变预约状态
  168. public function change_status(){
  169. $id = intval($_REQUEST['id']);
  170. $status = intval($_REQUEST['status']);
  171. $re = M("UserDate")->where("id=".$id)->setField("status",$status);
  172. if($status==1){
  173. $status_str = '已约见';
  174. }elseif($status==2){
  175. $status_str = '拒绝约见';
  176. }else{
  177. $status_str = '取消约见';
  178. }
  179. if($re){
  180. if($status==1){
  181. $date_id = $GLOBALS['db']->getOne("select date_id from ".DB_PREFIX."user_date where id = ".$id);
  182. $GLOBALS['db']->query("update ".DB_PREFIX."date set seen_count=seen_count+1 where id = ".$date_id);
  183. $reservation_config = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."conf where `name`='RESERVATION_CONFIG'");
  184. $value = unserialize($reservation_config['value']);
  185. $value['seen_count'] = $value['seen_count'] + 1;
  186. $value = serialize($value);
  187. $GLOBALS['db']->query("update ".DB_PREFIX."conf set value='".$value."' where `name`='RESERVATION_CONFIG'");
  188. }
  189. $result['status'] = 1;
  190. $result['info'] = $status_str.'成功';
  191. save_log($id.$status_str."成功",1);
  192. }else{
  193. $result['status'] = 0;
  194. $result['info'] = $status_str.'失败';
  195. save_log($id.$status_str."失败",1);
  196. }
  197. admin_ajax_return($result);
  198. }
  199. }
  200. ?>