CultureSceneBackgroundController.class.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * 场景背景管理
  5. * @author 晓宇
  6. * @version 0.0.1
  7. * @datetime 2019-03-29
  8. */
  9. class CultureSceneBackgroundController extends CommonController
  10. {
  11. /**
  12. * [_initialize 前置操作-继承公共前置方法]
  13. */
  14. public function _initialize()
  15. {
  16. // 调用父类前置方法
  17. parent::_initialize();
  18. // 登录校验
  19. $this->Is_Login();
  20. // 权限校验
  21. $this->Is_Power();
  22. }
  23. /**
  24. * [Index 场景背景列表]
  25. */
  26. public function Index()
  27. {
  28. // 参数
  29. $param = array_merge($_POST, $_GET);
  30. // 模型模型
  31. $m = D('Culture/CultureSceneBackground');
  32. // 条件
  33. $where = $this->GetIndexWhere();
  34. // 分页
  35. $number = MyC('admin_page_number');
  36. $page_param = array(
  37. 'number' => $number,
  38. 'total' => $m->where($where)->count(),
  39. 'where' => $param,
  40. 'url' => U('Culture/CultureSceneBackground/Index'),
  41. );
  42. $page = new \My\Page($page_param);
  43. // 获取列表
  44. $field = array('scene_background_id', 'scene_background_name', 'thumb', 'description', 'sale_price', 'is_lock', 'is_unlock_buy', 'created_at', 'updated_at');
  45. $list = $this->SetDataHandle($m->field($field)->where($where)->limit($page->GetPageStarNumber(), $number)->order('scene_background_id desc')->select());
  46. // 参数
  47. $this->assign('param', $param);
  48. // 分页
  49. $this->assign('page_html', $page->GetPageHtml());
  50. // 数据列表
  51. $this->assign('list', $list);
  52. $this->display('Index');
  53. }
  54. /**
  55. * [SetDataHandle 数据处理]
  56. * @param [array] $data [场景背景数据]
  57. * @return [array] [处理好的数据]
  58. */
  59. private function SetDataHandle($data)
  60. {
  61. return $data;
  62. }
  63. /**
  64. * [GetIndexWhere 场景背景列表条件]
  65. */
  66. private function GetIndexWhere()
  67. {
  68. $where = array();
  69. // 模糊
  70. if(!empty($_REQUEST['keyword']))
  71. {
  72. $like_keyword = array('like', '%'.I('keyword').'%');
  73. $where[] = array(
  74. 'scene_background_name' => $like_keyword,
  75. );
  76. }
  77. // 是否更多条件
  78. if(I('is_more', 0) == 1)
  79. {
  80. // 表达式
  81. if(!empty($_REQUEST['time_start']))
  82. {
  83. $where['created_at'][] = array('gt', I('time_start') . ' 00:00:00');
  84. }
  85. if(!empty($_REQUEST['time_end']))
  86. {
  87. $where['created_at'][] = array('lt', I('time_end') . ' 23:59:59');
  88. }
  89. }
  90. $where['deleted_at'] = ["exp", "is null"];
  91. return $where;
  92. }
  93. /**
  94. * [SaveInfo 场景背景添加/编辑页面]
  95. */
  96. public function SaveInfo()
  97. {
  98. // 场景背景信息
  99. $data = empty($_REQUEST['scene_background_id']) ? array() : D('Culture/CultureSceneBackground')->find(I('scene_background_id'));
  100. $this->assign('data', $data);
  101. // 场景列表
  102. $map['deleted_at'] = ["exp", "is null"];
  103. $scenes = D("Culture/CultureScene")->where($map)->select();
  104. $this->assign('scenes', $scenes);
  105. $this->display('SaveInfo');
  106. }
  107. /**
  108. * [Save 场景背景添加/编辑]
  109. */
  110. public function Save()
  111. {
  112. // 是否ajax请求
  113. if(!IS_AJAX)
  114. {
  115. $this->error(L('common_unauthorized_access'));
  116. }
  117. if(isset($_POST['is_lock'])){
  118. $_POST['is_lock'] = 1;
  119. }else{
  120. $_POST['is_lock'] = 0;
  121. }
  122. if(isset($_POST['is_unlock_buy'])){
  123. $_POST['is_unlock_buy'] = 1;
  124. }else{
  125. $_POST['is_unlock_buy'] = 0;
  126. }
  127. // 添加
  128. if(empty($_POST['scene_background_id']))
  129. {
  130. $this->Add();
  131. // 编辑
  132. } else {
  133. $this->Edit();
  134. }
  135. }
  136. /**
  137. * [Add 场景背景添加]
  138. */
  139. private function Add()
  140. {
  141. // 场景背景模型
  142. $m = D('Culture/CultureSceneBackground');
  143. // 数据自动校验
  144. if($m->create($_POST, 1))
  145. {
  146. $m->created_at = date('Y-m-d H:i:s');
  147. $m->updated_at = date('Y-m-d H:i:s');
  148. // 数据添加
  149. if($m->add())
  150. {
  151. $this->ajaxReturn(L('common_operation_add_success'));
  152. } else {
  153. $this->ajaxReturn(L('common_operation_add_error'), -100);
  154. }
  155. } else {
  156. $this->ajaxReturn($m->getError(), -1);
  157. }
  158. }
  159. /**
  160. * [Edit 场景背景编辑]
  161. */
  162. private function Edit()
  163. {
  164. // 场景背景模型
  165. $m = D('Culture/CultureSceneBackground');
  166. // 数据自动校验
  167. if($m->create($_POST, 2))
  168. {
  169. $m->updated_at = date('Y-m-d H:i:s');
  170. // 更新数据库
  171. if($m->where(array('scene_background_id'=>I('scene_background_id')))->save())
  172. {
  173. $this->ajaxReturn(L('common_operation_edit_success'));
  174. } else {
  175. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  176. }
  177. } else {
  178. $this->ajaxReturn($m->getError(), -1);
  179. }
  180. }
  181. /**
  182. * [Delete 场景背景删除]
  183. */
  184. public function Delete()
  185. {
  186. // 是否ajax请求
  187. if(!IS_AJAX)
  188. {
  189. $this->error(L('common_unauthorized_access'));
  190. }
  191. // 参数处理
  192. $id = I('id');
  193. // 删除数据
  194. if(!empty($id))
  195. {
  196. // 场景背景模型
  197. $m = D('Culture/CultureSceneBackground');
  198. // 场景背景是否存在
  199. $scene_background = $m->where(array('scene_background_id'=>$id))->count();
  200. if(empty($scene_background))
  201. {
  202. $this->ajaxReturn(L('common_user_no_exist_error'), -2);
  203. }
  204. // 删除场景背景
  205. $update_data['deleted_at'] = date('Y-m-d H:i:s');
  206. $state = $m->where(array('scene_background_id'=>$id))->save($update_data);
  207. if($state !== false)
  208. {
  209. $this->ajaxReturn(L('common_operation_delete_success'));
  210. } else {
  211. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  212. }
  213. } else {
  214. $this->ajaxReturn(L('common_param_error'), -1);
  215. }
  216. }
  217. }