Tpl.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace app\admin\controller\special\recharge;
  3. use app\common\controller\Backend;
  4. use app\common\library\Redis;
  5. use think\Controller;
  6. use think\Request;
  7. /**
  8. * 充值链-模板
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Tpl extends Backend
  13. {
  14. /**
  15. * SpecialRechargeTpl模型对象
  16. */
  17. protected $model = null;
  18. protected $urlModel = null;
  19. /**
  20. * 是否是关联查询
  21. */
  22. protected $relationSearch = true;
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. $this->model = model('SpecialRechargeTpl');
  27. $this->urlModel = model('SpecialRechargeUrl');
  28. $this->view->assign("statusList", $this->model->getStatusList());
  29. $this->assignconfig('business_line', 0);
  30. }
  31. /**
  32. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  33. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  34. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  35. */
  36. /**
  37. * 查看
  38. */
  39. public function index()
  40. {
  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. $total = $this->model
  52. ->where($where)
  53. ->order($sort, $order)
  54. ->count();
  55. $list = $this->model
  56. ->field("special_recharge_tpl.*, goods.money, goods.type, goods.kandian, goods.free_kandian, goods.day")
  57. ->join('goods', 'goods.id = special_recharge_tpl.goods_id')
  58. ->where($where)
  59. ->order($sort, $order)
  60. ->limit($offset, $limit)
  61. ->select();
  62. $result = array("total" => $total, "rows" => $list);
  63. return json($result);
  64. }
  65. return $this->view->fetch();
  66. }
  67. /**
  68. * 编辑
  69. */
  70. public function edit($ids = NULL)
  71. {
  72. $row = $this->model->get($ids);
  73. if (!$row)
  74. $this->error(__('No Results were found'));
  75. $adminIds = $this->getDataLimitAdminIds();
  76. if (is_array($adminIds))
  77. {
  78. if (!in_array($row[$this->dataLimitField], $adminIds))
  79. {
  80. $this->error(__('You have no permission'));
  81. }
  82. }
  83. if ($this->request->isPost())
  84. {
  85. $params = $this->request->post("row/a");
  86. if ($params)
  87. {
  88. /*
  89. * 已经弃用,如果为了兼容老版可取消注释
  90. foreach ($params as $k => &$v)
  91. {
  92. $v = is_array($v) ? implode(',', $v) : $v;
  93. }
  94. */
  95. try
  96. {
  97. //是否采用模型验证
  98. if ($this->modelValidate)
  99. {
  100. $name = basename(str_replace('\\', '/', get_class($this->model)));
  101. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
  102. $row->validate($validate);
  103. }
  104. $result = $row->allowField(true)->save($params);
  105. if ($result !== false)
  106. {
  107. $key = "SUT:".$ids;
  108. Redis::instance()->del($key);
  109. $this->success();
  110. }
  111. else
  112. {
  113. $this->error($row->getError());
  114. }
  115. }
  116. catch (\think\exception\PDOException $e)
  117. {
  118. $this->error($e->getMessage());
  119. }
  120. }
  121. $this->error(__('Parameter %s can not be empty', ''));
  122. }
  123. $goods = [
  124. 'show_type_text' => '',
  125. 'type_text' => '',
  126. 'money' => '',
  127. 'kandian' => '',
  128. 'free_kandian' => '',
  129. 'icon' => '',
  130. 'id' => '',
  131. 'free_day' => '',
  132. 'type' => '',
  133. 'day' => '',
  134. ];
  135. if (!empty($row['goods_id'])) {
  136. $goodsModel = model('goods');
  137. $goods = $goodsModel->where('id', $row['goods_id'])->find();
  138. }
  139. $this->view->assign("goods", $goods);
  140. $this->view->assign("row", $row);
  141. return $this->view->fetch();
  142. }
  143. /**
  144. * 复制链接
  145. * @param $tpl_id
  146. */
  147. public function copy($tpl_id)
  148. {
  149. //生成链接
  150. $row = $this->model->get($tpl_id);
  151. if (!$row)
  152. $this->error(__('No Results were found'));
  153. if ($row['status'] == 'hidden') {
  154. $this->error(__('模板不可用'));
  155. }
  156. $params = [
  157. 'tpl_id' => $tpl_id,
  158. 'out_trade_no' => '',
  159. 'user_id' => 0
  160. ];
  161. $result = $this->urlModel->allowField(true)->save($params);
  162. if ($result !== false) {
  163. $channel_id = $row['channel_id'];
  164. $url = '/index/index/rechargeurl?id='.$this->urlModel->getLastInsID();
  165. $data = [
  166. 'url' => getCurrentDomain($channel_id, $url),
  167. ];
  168. $this->success('', null, $data);
  169. } else
  170. {
  171. $this->error($this->urlModel->getError());
  172. }
  173. }
  174. }