酒店预订平台
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.
 
 
 
 
 
 

188 lines
6.4 KiB

  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\exception\PDOException;
  6. use think\exception\ValidateException;
  7. /**
  8. * 收款账单管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class ReceiptOrder extends Backend
  13. {
  14. /**
  15. * ReceiptOrder模型对象
  16. * @var \app\admin\model\ReceiptOrder
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\ReceiptOrder;
  23. }
  24. public function import()
  25. {
  26. parent::import();
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. /**
  34. * 查看
  35. */
  36. public function index()
  37. {
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  46. $group_id=$this->auth->getGroupId();
  47. $list = $this->model
  48. ->alias("a")
  49. ->join('hbp_admin c','a.create_id = c.id','left')
  50. ->field("a.*,c.nickname")
  51. ->where($where);
  52. if ($group_id){
  53. $list = $list
  54. ->where("group_id","=",$group_id)
  55. ->order($sort, $order)
  56. ->paginate($limit);
  57. }else{
  58. $list = $list
  59. ->order($sort, $order)
  60. ->paginate($limit);
  61. }
  62. $res = $list->items();
  63. foreach ($res as $k=>$item){
  64. switch ($item["status"]){
  65. case 0:
  66. $res[$k]["status"]="未付款";
  67. break;
  68. case 1:
  69. $res[$k]["status"]="已付款";
  70. break;
  71. }
  72. }
  73. $result = array("total" => $list->total(), "rows" => $list->items());
  74. return json($result);
  75. }
  76. return $this->view->fetch();
  77. }
  78. /**
  79. * 添加
  80. */
  81. public function add()
  82. {
  83. if ($this->request->isPost()) {
  84. $params = $this->request->post("row/a");
  85. if ($params) {
  86. $params = $this->preExcludeFields($params);
  87. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  88. $params[$this->dataLimitField] = $this->auth->id;
  89. }
  90. $result = false;
  91. Db::startTrans();
  92. try {
  93. //是否采用模型验证
  94. if ($this->modelValidate) {
  95. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  96. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  97. $this->model->validateFailException(true)->validate($validate);
  98. }
  99. $params['create_id']=$this->auth->id;
  100. $params['group_id']=$this->auth->getGroupId();
  101. $result = $this->model->allowField(true)->save($params);
  102. Db::commit();
  103. } catch (ValidateException $e) {
  104. Db::rollback();
  105. $this->error($e->getMessage());
  106. } catch (PDOException $e) {
  107. Db::rollback();
  108. $this->error($e->getMessage());
  109. } catch (Exception $e) {
  110. Db::rollback();
  111. $this->error($e->getMessage());
  112. }
  113. if ($result !== false) {
  114. $this->success();
  115. } else {
  116. $this->error(__('No rows were inserted'));
  117. }
  118. }
  119. $this->error(__('Parameter %s can not be empty', ''));
  120. }
  121. return $this->view->fetch();
  122. }
  123. /**
  124. * 编辑
  125. */
  126. public function edit($ids = null)
  127. {
  128. $row = $this->model->get($ids);
  129. if (!$row) {
  130. $this->error(__('No Results were found'));
  131. }
  132. $adminIds = $this->getDataLimitAdminIds();
  133. if (is_array($adminIds)) {
  134. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  135. $this->error(__('You have no permission'));
  136. }
  137. }
  138. if ($this->request->isPost()) {
  139. $params = $this->request->post("row/a");
  140. if ($params) {
  141. $params = $this->preExcludeFields($params);
  142. $result = false;
  143. Db::startTrans();
  144. try {
  145. //是否采用模型验证
  146. if ($this->modelValidate) {
  147. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  148. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  149. $row->validateFailException(true)->validate($validate);
  150. }
  151. $result = $row->allowField(true)->save($params);
  152. Db::commit();
  153. } catch (ValidateException $e) {
  154. Db::rollback();
  155. $this->error($e->getMessage());
  156. } catch (PDOException $e) {
  157. Db::rollback();
  158. $this->error($e->getMessage());
  159. } catch (Exception $e) {
  160. Db::rollback();
  161. $this->error($e->getMessage());
  162. }
  163. if ($result !== false) {
  164. $this->success();
  165. } else {
  166. $this->error(__('No rows were updated'));
  167. }
  168. }
  169. $this->error(__('Parameter %s can not be empty', ''));
  170. }
  171. $this->view->assign("row", $row);
  172. return $this->view->fetch();
  173. }
  174. }