Shelfoperate.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: lytian
  5. * Date: 2019/4/9
  6. * Time: 17:19
  7. */
  8. namespace app\admin\controller\clientmanage\clientconfig;
  9. use app\common\controller\Backend;
  10. use app\common\library\Redis;
  11. /**
  12. * 阳光app功能配置管理
  13. *
  14. * @icon fa fa-circle-o
  15. */
  16. class Shelfoperate extends Backend
  17. {
  18. /**
  19. * ClientConfig模型对象
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = model('ClientConfig');
  26. $this->view->assign("funTypeList", $this->model->getFunTypeList());
  27. $this->view->assign("typeList", $this->model->getTypeList());
  28. $this->view->assign("userPayTypeList", $this->model->getUserPayTypeList());
  29. $this->view->assign("positionList", $this->model->getPositionList());
  30. $this->view->assign("statusList", $this->model->getStatusList());
  31. }
  32. /**
  33. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  34. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  35. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  36. */
  37. //运营位管理列表
  38. public function business()
  39. {
  40. $funType = 1;
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags']);
  43. if ($this->request->isAjax())
  44. {
  45. //如果发送的来源是Selectpage,则转发到Selectpage
  46. if ($this->request->request('pkey_name'))
  47. {
  48. return $this->selectpage();
  49. }
  50. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  51. $condition = [
  52. 'fun_type' => ['eq', $funType],
  53. ];
  54. $total = $this->model
  55. ->where($where)
  56. ->where($condition)
  57. ->order($sort, $order)
  58. ->count();
  59. $list = $this->model
  60. ->where($where)
  61. ->where($condition)
  62. ->order($sort, $order)
  63. ->limit($offset, $limit)
  64. ->select();
  65. $result = array("total" => $total, "rows" => $list);
  66. return json($result);
  67. }
  68. $this->assignconfig('funtype', $funType);
  69. $this->assign('funtype', $funType);
  70. return $this->view->fetch('index');
  71. }
  72. //弹窗管理
  73. public function popup()
  74. {
  75. $funType = 2;
  76. //设置过滤方法
  77. $this->request->filter(['strip_tags']);
  78. if ($this->request->isAjax())
  79. {
  80. //如果发送的来源是Selectpage,则转发到Selectpage
  81. if ($this->request->request('pkey_name'))
  82. {
  83. return $this->selectpage();
  84. }
  85. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  86. $condition = [
  87. 'fun_type' => ['eq', $funType],
  88. ];
  89. $total = $this->model
  90. ->where($where)
  91. ->where($condition)
  92. ->order($sort, $order)
  93. ->count();
  94. $list = $this->model
  95. ->where($where)
  96. ->where($condition)
  97. ->order($sort, $order)
  98. ->limit($offset, $limit)
  99. ->select();
  100. $result = array("total" => $total, "rows" => $list);
  101. return json($result);
  102. }
  103. $this->assignconfig('funtype', $funType);
  104. $this->assign('funtype', $funType);
  105. return $this->view->fetch('index');
  106. }
  107. //loading管理
  108. public function loading()
  109. {
  110. $funType = 3;
  111. //设置过滤方法
  112. $this->request->filter(['strip_tags']);
  113. if ($this->request->isAjax())
  114. {
  115. //如果发送的来源是Selectpage,则转发到Selectpage
  116. if ($this->request->request('pkey_name'))
  117. {
  118. return $this->selectpage();
  119. }
  120. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  121. $condition = [
  122. 'fun_type' => ['eq', $funType],
  123. ];
  124. $total = $this->model
  125. ->where($where)
  126. ->where($condition)
  127. ->order($sort, $order)
  128. ->count();
  129. $list = $this->model
  130. ->where($where)
  131. ->where($condition)
  132. ->order($sort, $order)
  133. ->limit($offset, $limit)
  134. ->select();
  135. $result = array("total" => $total, "rows" => $list);
  136. return json($result);
  137. }
  138. $this->assignconfig('funtype', $funType);
  139. $this->assign('funtype', $funType);
  140. return $this->view->fetch('index');
  141. }
  142. /**
  143. * 添加
  144. */
  145. public function add()
  146. {
  147. $funtype = $this->request->param('funtype', 1);
  148. if ($this->request->isPost())
  149. {
  150. $params = $this->request->post("row/a");
  151. if ($params)
  152. {
  153. /*
  154. * 已经弃用,如果为了兼容老版可取消注释
  155. foreach ($params as $k => &$v)
  156. {
  157. $v = is_array($v) ? implode(',', $v) : $v;
  158. }
  159. */
  160. if ($this->dataLimit)
  161. {
  162. $params[$this->dataLimitField] = $this->auth->id;
  163. }
  164. try
  165. {
  166. //是否采用模型验证
  167. if ($this->modelValidate)
  168. {
  169. $name = basename(str_replace('\\', '/', get_class($this->model)));
  170. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  171. $this->model->validate($validate);
  172. }
  173. if ($funtype == 2) {
  174. $params['position'] = implode(',', $params['position']);
  175. }
  176. $result = $this->model->allowField(true)->save($params);
  177. if ($result !== false)
  178. {
  179. $this->success();
  180. }
  181. else
  182. {
  183. $this->error($this->model->getError());
  184. }
  185. }
  186. catch (\think\exception\PDOException $e)
  187. {
  188. $this->error($e->getMessage());
  189. }
  190. }
  191. $this->error(__('Parameter %s can not be empty', ''));
  192. }
  193. $this->assignconfig('funtype', $funtype);
  194. $this->assign('funtype', $funtype);
  195. return $this->view->fetch();
  196. }
  197. /**
  198. * 编辑
  199. */
  200. public function edit($ids = NULL)
  201. {
  202. $row = $this->model->get($ids);
  203. if (!$row)
  204. $this->error(__('No Results were found'));
  205. $adminIds = $this->getDataLimitAdminIds();
  206. if (is_array($adminIds))
  207. {
  208. if (!in_array($row[$this->dataLimitField], $adminIds))
  209. {
  210. $this->error(__('You have no permission'));
  211. }
  212. }
  213. if ($this->request->isPost())
  214. {
  215. $params = $this->request->post("row/a");
  216. if ($params)
  217. {
  218. /*
  219. * 已经弃用,如果为了兼容老版可取消注释
  220. foreach ($params as $k => &$v)
  221. {
  222. $v = is_array($v) ? implode(',', $v) : $v;
  223. }
  224. */
  225. try
  226. {
  227. //是否采用模型验证
  228. if ($this->modelValidate)
  229. {
  230. $name = basename(str_replace('\\', '/', get_class($this->model)));
  231. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
  232. $row->validate($validate);
  233. }
  234. if ($row['fun_type'] == 2) {
  235. $params['position'] = implode(',', $params['position']);
  236. }
  237. $result = $row->allowField(true)->save($params);
  238. if ($result !== false)
  239. {
  240. $this->model->delCache($ids);
  241. $this->success();
  242. }
  243. else
  244. {
  245. $this->error($row->getError());
  246. }
  247. }
  248. catch (\think\exception\PDOException $e)
  249. {
  250. $this->error($e->getMessage());
  251. }
  252. }
  253. $this->error(__('Parameter %s can not be empty', ''));
  254. }
  255. $this->view->assign("row", $row);
  256. $activityName = '';
  257. if (!empty($row['client_activity_id'])) {
  258. $activity = model('activity')->get($row['client_activity_id']);
  259. $activityName = $activity->name;
  260. }
  261. $this->view->assign("selected", explode(',', $row['position']));
  262. $this->view->assign("activityName", $activityName);
  263. $this->assignconfig("type", $row['type']);
  264. $this->assignconfig("funtype", $row['fun_type']);
  265. return $this->view->fetch();
  266. }
  267. public function setlose($ids = NULL)
  268. {
  269. $row = $this->model->get($ids);
  270. if (!$row)
  271. $this->error(__('No Results were found'));
  272. $adminIds = $this->getDataLimitAdminIds();
  273. if (is_array($adminIds))
  274. {
  275. if (!in_array($row[$this->dataLimitField], $adminIds))
  276. {
  277. $this->error(__('You have no permission'));
  278. }
  279. }
  280. if ($this->request->isPost())
  281. {
  282. $params = ['status' => 0];
  283. if ($params)
  284. {
  285. /*
  286. * 已经弃用,如果为了兼容老版可取消注释
  287. foreach ($params as $k => &$v)
  288. {
  289. $v = is_array($v) ? implode(',', $v) : $v;
  290. }
  291. */
  292. try
  293. {
  294. //是否采用模型验证
  295. if ($this->modelValidate)
  296. {
  297. $name = basename(str_replace('\\', '/', get_class($this->model)));
  298. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
  299. $row->validate($validate);
  300. }
  301. $result = $row->allowField(true)->save($params);
  302. if ($result !== false)
  303. {
  304. $this->success();
  305. }
  306. else
  307. {
  308. $this->error($row->getError());
  309. }
  310. }
  311. catch (\think\exception\PDOException $e)
  312. {
  313. $this->error($e->getMessage());
  314. }
  315. }
  316. $this->error(__('Parameter %s can not be empty', ''));
  317. }
  318. }
  319. }