Fufengroup.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\library\Redis;
  5. use app\main\constants\CacheConstants;
  6. use think\Controller;
  7. use think\Request;
  8. /**
  9. *
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Fufengroup extends Backend
  14. {
  15. /**
  16. * @var \app\common\model\FufenGroup
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = model('FufenGroup');
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 删除
  32. */
  33. public function del($ids = "")
  34. {
  35. if ($ids)
  36. {
  37. $pk = $this->model->getPk();
  38. $list = $this->model->where($pk, 'in', $ids)->select();
  39. $count = 0;
  40. foreach ($list as $k => $v)
  41. {
  42. $channel_ids = explode(',', $v['channel_ids']);
  43. foreach ($channel_ids as $channel_id) {
  44. Redis::instance()->del(CacheConstants::getChannelWxpayIds($channel_id));
  45. }
  46. $count += $v->delete();
  47. }
  48. if ($count)
  49. {
  50. $this->success();
  51. }
  52. else
  53. {
  54. $this->error(__('No rows were deleted'));
  55. }
  56. }
  57. $this->error(__('Parameter %s can not be empty', 'ids'));
  58. }
  59. /**
  60. * 编辑
  61. */
  62. public function edit($ids = NULL)
  63. {
  64. $row = $this->model->get($ids);
  65. if (!$row)
  66. $this->error(__('No Results were found'));
  67. $adminIds = $this->getDataLimitAdminIds();
  68. if (is_array($adminIds))
  69. {
  70. if (!in_array($row[$this->dataLimitField], $adminIds))
  71. {
  72. $this->error(__('You have no permission'));
  73. }
  74. }
  75. if ($this->request->isPost())
  76. {
  77. $params = $this->request->post("row/a");
  78. if ($params)
  79. {
  80. /*
  81. * 已经弃用,如果为了兼容老版可取消注释
  82. foreach ($params as $k => &$v)
  83. {
  84. $v = is_array($v) ? implode(',', $v) : $v;
  85. }
  86. */
  87. try
  88. {
  89. //是否采用模型验证
  90. if ($this->modelValidate)
  91. {
  92. $name = basename(str_replace('\\', '/', get_class($this->model)));
  93. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
  94. $row->validate($validate);
  95. }
  96. $result = $row->allowField(true)->save($params);
  97. if ($result !== false)
  98. {
  99. $channel_ids = explode(',', $row['channel_ids']);
  100. foreach ($channel_ids as $channel_id) {
  101. Redis::instance()->del(CacheConstants::getChannelWxpayIds($channel_id));
  102. }
  103. $this->success();
  104. }
  105. else
  106. {
  107. $this->error($row->getError());
  108. }
  109. }
  110. catch (\think\exception\PDOException $e)
  111. {
  112. $this->error($e->getMessage());
  113. }
  114. }
  115. $this->error(__('Parameter %s can not be empty', ''));
  116. }
  117. $this->view->assign("row", $row);
  118. return $this->view->fetch();
  119. }
  120. }