BmPropAction.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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 BmPropAction extends CommonAction{
  10. public function index()
  11. {
  12. if(strim($_REQUEST['name'])!=''){
  13. $map['name'] = array('like','%'.strim($_REQUEST['name']).'%');
  14. }
  15. if($_REQUEST['is_animated']!=''&&intval($_REQUEST['is_animated'])!=-1)
  16. {
  17. $map['is_animated']=intval($_REQUEST['is_animated']);
  18. }
  19. if (method_exists ( $this, '_filter' )) {
  20. $this->_filter ( $map );
  21. }
  22. $name=$this->getActionName();
  23. $model = D ('prop');
  24. if (! empty ( $model )) {
  25. $this->_list ( $model, $map );
  26. }
  27. $list = $this->get("list");
  28. $cate_list = M("VideoCate")->findAll();
  29. $this->assign("cate_list",$cate_list);
  30. $this->display ();
  31. }
  32. public function add()
  33. {
  34. $this->assign("new_sort", M("Prop")->max("sort")+1);
  35. $this->display();
  36. }
  37. public function edit() {
  38. $id = intval($_REQUEST ['id']);
  39. $condition['id'] = $id;
  40. $vo = M('Prop')->where($condition)->find();
  41. $this->assign ( 'vo', $vo );
  42. $this->display ();
  43. }
  44. //彻底删除指定记录
  45. public function foreverdelete() {
  46. //彻底删除指定记录
  47. $ajax = intval($_REQUEST['ajax']);
  48. $id = $_REQUEST ['id'];
  49. if (isset ( $id )) {
  50. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  51. $rel_data = M('Prop')->where($condition)->findAll();
  52. foreach($rel_data as $data)
  53. {
  54. $info[] = $data['name'];
  55. }
  56. if($info) $info = implode(",",$info);
  57. $list = M('Prop')->where ( $condition )->delete();
  58. //删除相关预览图
  59. // foreach($rel_data as $data)
  60. // {
  61. // @unlink(get_real_path().$data['preview']);
  62. // }
  63. if ($list!==false) {
  64. //删除子动画
  65. $animate_condition = array ('prop_id' => array ('in', explode ( ',', $id ) ) );
  66. $list = M("PropAnimated")->where ( $animate_condition )->delete();
  67. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  68. clear_auto_cache("prop_list");
  69. clear_auto_cache("prop_id",array('id'=>$data['id']));
  70. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  71. } else {
  72. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  73. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  74. }
  75. } else {
  76. $this->error (l("INVALID_OPERATION"),$ajax);
  77. }
  78. }
  79. public function insert() {
  80. B('FilterString');
  81. $ajax = intval($_REQUEST['ajax']);
  82. $data = M('Prop')->create ();
  83. //开始验证有效性
  84. $this->assign("jumpUrl",u(MODULE_NAME."/add"));
  85. $m_config = load_auto_cache('m_config');
  86. $ticket_name = $m_config['ticket_name']!=''?$m_config['ticket_name']:'印票';
  87. if(!check_empty($data['name']))
  88. {
  89. $this->error("请输入名称");
  90. }
  91. if(!check_empty($data['icon']))
  92. {
  93. $this->error("请输入图标");
  94. }
  95. if(!check_empty($data['diamonds']))
  96. {
  97. if($data['is_red_envelope']==1){
  98. $this->error("请输入消费钻石");
  99. }
  100. }
  101. if((intval($data['score'])==0))
  102. {
  103. $data['score'] = 0;
  104. }
  105. if(intval($data['robot_diamonds'])==0)
  106. {
  107. $data['robot_diamonds'] = 0;
  108. }
  109. if($data['is_red_envelope']==1){
  110. if(!(intval($data['diamonds'])>0))
  111. {
  112. $this->error("消费钻石必须大于0");
  113. }
  114. if((intval($data['diamonds']))<=(intval($data['ticket'])))
  115. {
  116. $this->error("消费钻石必须大于主播获得的钻石数量");
  117. }
  118. if((intval($data['diamonds']))<=(intval($data['ticket']))+(intval($data['robot_diamonds'])))
  119. {
  120. $this->error("消费钻石必须大于(主播获得的钻石数量+机器人获得的钻石数量)");
  121. }
  122. }
  123. if(intval($data['ticket'])==0)
  124. {
  125. $data['ticket'] = 0;
  126. }
  127. if(intval($data['is_animated'])==2){
  128. if(!check_empty($data['anim_type']))
  129. {
  130. $this->error("请输入大型动画礼物类型");
  131. }
  132. }
  133. if((intval($data['diamonds'])==0)&&(intval($data['score'])==0)){
  134. if(intval($data['ticket'])!=0){
  135. $this->error('免费礼物的'.$ticket_name.'数量必须为0');
  136. }
  137. }
  138. // 更新数据
  139. $log_info = $data['name'];
  140. $list=M('Prop')->add($data);
  141. if (false !== $list) {
  142. //成功提示
  143. save_log($log_info.L("INSERT_SUCCESS"),1);
  144. clear_auto_cache("prop_list");
  145. $this->success(L("INSERT_SUCCESS"));
  146. } else {
  147. //错误提示
  148. save_log($log_info.L("INSERT_FAILED"),0);
  149. $this->error(L("INSERT_FAILED"));
  150. }
  151. }
  152. public function update() {
  153. B('FilterString');
  154. $data = M('Prop')->create();
  155. clear_auto_cache("prop_list");
  156. // if($_FILES['preview']['name']!='')
  157. // {
  158. // $result = $this->uploadImage();
  159. // if($result['status']==0)
  160. // {
  161. // $this->error($result['info'],$ajax);
  162. // }
  163. // //删除图片
  164. // @unlink(get_real_path().M("Article")->where("id=".$data['id'])->getField("preview"));
  165. // $data['preview'] = $result['data'][0]['bigrecpath'].$result['data'][0]['savename'];
  166. // }
  167. $m_config = load_auto_cache('m_config');
  168. $ticket_name = $m_config['ticket_name']!=''?$m_config['ticket_name']:'印票';
  169. $log_info = M('Prop')->where("id=".intval($data['id']))->getField("name");
  170. //开始验证有效性
  171. $this->assign("jumpUrl",u(MODULE_NAME."/edit",array("id"=>$data['id'])));
  172. if(!check_empty($data['name']))
  173. {
  174. $this->error("请输入名称");
  175. }
  176. if(!check_empty($data['icon']))
  177. {
  178. $this->error("请输入图标");
  179. }
  180. if(!check_empty($data['diamonds']))
  181. {
  182. if($data['is_red_envelope']==1){
  183. $this->error("请输入消费钻石");
  184. }
  185. }
  186. if((intval($data['score'])==0))
  187. {
  188. $data['score'] = 0;
  189. }
  190. if($data['is_red_envelope']==1){
  191. if(!(intval($data['diamonds'])>0))
  192. {
  193. $this->error("消费钻石必须大于0");
  194. }
  195. if((intval($data['diamonds']))<=(intval($data['ticket'])))
  196. {
  197. $this->error("消费钻石必须大于主播获得的钻石数量");
  198. }
  199. if((intval($data['diamonds']))<=(intval($data['ticket']))+(intval($data['robot_diamonds'])))
  200. {
  201. $this->error("消费钻石必须大于(主播获得的钻石数量+机器人获得的钻石数量)");
  202. }
  203. }
  204. if(intval($data['ticket'])==0)
  205. {
  206. $data['ticket'] = 0;
  207. }
  208. if(intval($data['robot_diamonds'])==0)
  209. {
  210. $data['robot_diamonds'] = 0;
  211. }
  212. if(intval($data['is_animated'])==2){
  213. if(!check_empty($data['anim_type']))
  214. {
  215. $this->error("请输入大型动画礼物类型");
  216. }
  217. }
  218. if((intval($data['diamonds'])==0)&&(intval($data['score'])==0)){
  219. if(intval($data['ticket'])!=0){
  220. $this->error('免费礼物的'.$ticket_name.'数量必须为0');
  221. }
  222. }
  223. // 更新数据
  224. $list=M('Prop')->save ($data);
  225. if (false !== $list) {
  226. //成功提示
  227. save_log($log_info.L("UPDATE_SUCCESS"),1);
  228. clear_auto_cache("prop_id",array('id'=>$data['id']));
  229. $this->success(L("UPDATE_SUCCESS"));
  230. } else {
  231. //错误提示
  232. save_log($log_info.L("UPDATE_FAILED"),0);
  233. $this->error(L("UPDATE_FAILED"),0,$log_info.L("UPDATE_FAILED"));
  234. }
  235. }
  236. public function set_effect()
  237. {
  238. clear_auto_cache("prop_list");
  239. $id = intval($_REQUEST['id']);
  240. $ajax = intval($_REQUEST['ajax']);
  241. $info = M('Prop')->where("id=".$id)->getField("name");
  242. $c_is_effect = M('Prop')->where("id=".$id)->getField("is_effect"); //当前状态
  243. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  244. M('Prop')->where("id=".$id)->setField("is_effect",$n_is_effect);
  245. save_log($info.l("SET_EFFECT_".$n_is_effect),1);
  246. $this->ajaxReturn($n_is_effect,l("SET_EFFECT_".$n_is_effect),1) ;
  247. }
  248. public function set_sort()
  249. {
  250. clear_auto_cache("prop_list");
  251. $id = intval($_REQUEST['id']);
  252. $sort = intval($_REQUEST['sort']);
  253. $log_info = M('Prop')->where("id=".$id)->getField("name");
  254. if(!check_sort($sort))
  255. {
  256. $this->error(l("SORT_FAILED"),1);
  257. }
  258. M("Prop")->where("id=".$id)->setField("sort",$sort);
  259. save_log($log_info.l("SORT_SUCCESS"),1);
  260. $this->success(l("SORT_SUCCESS"),1);
  261. }
  262. /**
  263. * 子动画
  264. */
  265. public function prop_item(){
  266. $prop_id = intval($_REQUEST['id']);
  267. $prop_info = M("Prop")->getById($prop_id);
  268. $this->assign("prop_info",$prop_info);
  269. if($prop_info)
  270. {
  271. $map['prop_id'] = $prop_info['id'];
  272. if (method_exists ( $this, '_filter' )) {
  273. $this->_filter ( $map );
  274. }
  275. $model = D ("PropAnimated");
  276. if (! empty ( $model )) {
  277. $this->_list ( $model, $map );
  278. }
  279. }
  280. $this->display();
  281. }
  282. /**
  283. * 添加子动画
  284. */
  285. public function add_prop_item()
  286. {
  287. $prop_id = intval($_REQUEST['id']);
  288. $prop_info = M("Prop")->getById($prop_id);
  289. $this->assign("prop_info",$prop_info);
  290. $this->display();
  291. }
  292. /**
  293. * 写入子动画
  294. */
  295. public function insert_prop_item() {
  296. B('FilterString');
  297. $ajax = intval($_REQUEST['ajax']);
  298. $data = M("PropAnimated")->create ();
  299. $Count = M('PropAnimated')->where('prop_id = '.$data['prop_id'])->count();
  300. if($Count>5){
  301. $this->error('已经添加五个动画!不能再添加');
  302. }
  303. //开始验证有效性
  304. $this->assign("jumpUrl",u(MODULE_NAME."/add_prop_item",array("id"=>$data['prop_id'])));
  305. $prop_name = M('Prop')->where('prop_id = '.$data['prop_id'])->getField("name");
  306. // 更新数据
  307. $list=M("PropAnimated")->add($data);
  308. $log_info = $prop_name."礼物动画: ".$data['prop_id'];
  309. if (false !== $list) {
  310. //成功提示
  311. save_log($log_info.L("INSERT_SUCCESS"),1);
  312. clear_auto_cache("prop_id",array('id'=>$data['prop_id']));
  313. $this->success(L("INSERT_SUCCESS"));
  314. } else {
  315. //错误提示
  316. save_log($log_info.L("INSERT_FAILED"),0);
  317. $this->error(L("INSERT_FAILED"));
  318. }
  319. }
  320. /**
  321. * 编辑子动画
  322. */
  323. public function edit_prop_item()
  324. {
  325. $id = intval($_REQUEST ['id']);
  326. $condition['id'] = $id;
  327. $vo = M("PropAnimated")->where($condition)->find();
  328. $this->assign ('vo', $vo );
  329. $prop_info = M("Prop")->where("id=".intval($vo['prop_id'])."")->find();
  330. $this->assign ( 'prop_info', $prop_info );
  331. $this->display();
  332. }
  333. /**
  334. * 更新子动画
  335. */
  336. public function update_prop_item() {
  337. B('FilterString');
  338. $ajax = intval($_REQUEST['ajax']);
  339. $data = M("PropAnimated")->create ();
  340. //开始验证有效性
  341. $this->assign("jumpUrl",u(MODULE_NAME."/edit_prop_item",array("id"=>$data['id'])));
  342. $prop_item=M("PropAnimated")->getById(intval($data['id']));
  343. if(!$prop_item)
  344. $this->error("更新失败");
  345. $prop_name = M('Prop')->where('prop_id = '.$data['prop_id'])->getField("name");
  346. // 更新数据
  347. $list=M("PropAnimated")->save($data);
  348. $log_info = $prop_name."礼物动画: ".$data['prop_id'];
  349. if (false !== $list) {
  350. //成功提示
  351. save_log($log_info.L("UPDATE_SUCCESS"),1);
  352. clear_auto_cache("prop_id",array('id'=>$data['prop_id']));
  353. $this->success(L("UPDATE_SUCCESS"));
  354. } else {
  355. //错误提示
  356. save_log($log_info.L("UPDATE_FAILED"),0);
  357. $this->error(L("UPDATE_FAILED"));
  358. }
  359. }
  360. /**
  361. * 删除子动画
  362. */
  363. public function del_prop_item()
  364. {
  365. $ajax = intval($_REQUEST['ajax']);
  366. $id = $_REQUEST ['id'];
  367. if (isset ( $id )) {
  368. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  369. $rel_data = M("PropAnimated")->where($condition)->findAll();
  370. foreach($rel_data as $data)
  371. {
  372. $prop_id = $data['prop_id'];
  373. }
  374. $prop_name = M('Prop')->where('prop_id = '.$prop_id)->getField("name");
  375. $info = $prop_name."礼物动画: ".$data['prop_id'];
  376. $list = M("PropAnimated")->where ( $condition )->delete();
  377. if ($list!==false) {
  378. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  379. clear_auto_cache("prop_id",array('id'=>$data['prop_id']));
  380. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  381. } else {
  382. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  383. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  384. }
  385. } else {
  386. $this->error (l("INVALID_OPERATION"),$ajax);
  387. }
  388. }
  389. }
  390. ?>