酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

139 lines
4.6 KiB

  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\dao\GroupDao;
  4. use app\common\controller\Backend;
  5. use think\Db;
  6. use think\Exception;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. /**
  10. * 渠道配置
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class CfChannelInfo extends Backend
  15. {
  16. protected $noNeedRight = ['getList'];
  17. /**
  18. * CfChannelInfo模型对象
  19. * @var \app\admin\model\CfChannelInfo
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\admin\model\CfChannelInfo;
  26. }
  27. public function import()
  28. {
  29. parent::import();
  30. }
  31. /**
  32. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  33. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  34. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  35. */
  36. /**
  37. * 添加
  38. */
  39. public function add()
  40. {
  41. if ($this->request->isPost()) {
  42. $params = $this->request->post("row/a");
  43. if ($params) {
  44. $params = $this->preExcludeFields($params);
  45. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  46. $params[$this->dataLimitField] = $this->auth->id;
  47. }
  48. $result = false;
  49. Db::startTrans();
  50. try {
  51. //是否采用模型验证
  52. if ($this->modelValidate) {
  53. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  54. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  55. $this->model->validateFailException(true)->validate($validate);
  56. }
  57. $params['create_id']=$this->auth->id;
  58. $groupDao = new GroupDao();
  59. $params['group_id'] = $groupDao->getTopGroup($this->auth->getGroupIds()[0]);
  60. $result = $this->model->allowField(true)->save($params);
  61. Db::commit();
  62. } catch (ValidateException $e) {
  63. Db::rollback();
  64. $this->error($e->getMessage());
  65. } catch (PDOException $e) {
  66. Db::rollback();
  67. $this->error($e->getMessage());
  68. } catch (Exception $e) {
  69. Db::rollback();
  70. $this->error($e->getMessage());
  71. }
  72. if ($result !== false) {
  73. $this->success();
  74. } else {
  75. $this->error(__('No rows were inserted'));
  76. }
  77. }
  78. $this->error(__('Parameter %s can not be empty', ''));
  79. }
  80. return $this->view->fetch();
  81. }
  82. /**
  83. * 查看
  84. */
  85. public function index()
  86. {
  87. //设置过滤方法
  88. $this->request->filter(['strip_tags', 'trim']);
  89. if ($this->request->isAjax()) {
  90. //如果发送的来源是Selectpage,则转发到Selectpage
  91. if ($this->request->request('keyField')) {
  92. return $this->selectpage();
  93. }
  94. $groupDao = new GroupDao();
  95. $group_id = $groupDao->getTopGroup($this->auth->getGroupIds()[0]);
  96. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  97. $list = $this->model
  98. ->where($where)
  99. ->where("group_id",'=',$group_id)
  100. ->order($sort, $order)
  101. ->paginate($limit);
  102. $result = array("total" => $list->total(), "rows" => $list->items());
  103. return json($result);
  104. }
  105. return $this->view->fetch();
  106. }
  107. public function getList(){
  108. $name=$this->request->post('name');
  109. $keyValue=$this->request->post('keyValue');
  110. $this->model->field('id,channel_name as name,commission_rate');
  111. $groupDao = new GroupDao();
  112. $group_id = $groupDao->getTopGroup($this->auth->getGroupIds()[0]);
  113. $where = ["group_id"=>$group_id];
  114. if($keyValue){
  115. $where = ['id'=>$keyValue,"group_id"=>$group_id];
  116. }elseif($name){
  117. $where = ['channel_name'=>['like','%'.$name.'%',"group_id"=>$group_id]];
  118. }
  119. $result= $this->model->where($where)->select();
  120. if($keyValue){
  121. return json(['list' => $result]);
  122. }
  123. return json(['list' => $result]);
  124. }
  125. }