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

270 lines
8.6 KiB

  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\service\ReceiptOrderDao;
  4. use app\admin\service\ReceiptOrderService;
  5. use app\common\controller\Backend;
  6. use think\Db;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. /**
  10. * 收款账单管理
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class ReceiptOrder extends Backend
  15. {
  16. protected $noNeedLogin = ['getOrderMainList',"getList"];
  17. /**
  18. * ReceiptOrder模型对象
  19. * @var \app\admin\model\ReceiptOrder
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\admin\model\ReceiptOrder;
  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 index()
  40. {
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags', 'trim']);
  43. if ($this->request->isAjax()) {
  44. //如果发送的来源是Selectpage,则转发到Selectpage
  45. if ($this->request->request('keyField')) {
  46. return $this->selectpage();
  47. }
  48. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  49. $group_id=$this->auth->getGroupId();
  50. $list = $this->model
  51. ->alias("a")
  52. ->join('hbp_admin c','a.create_id = c.id','left')
  53. ->field("a.*,c.nickname")
  54. ->where($where);
  55. if ($group_id){
  56. $list = $list
  57. ->where("group_id","=",$group_id)
  58. ->order($sort, $order)
  59. ->paginate($limit);
  60. }else{
  61. $list = $list
  62. ->order($sort, $order)
  63. ->paginate($limit);
  64. }
  65. $res = $list->items();
  66. foreach ($res as $k=>$item){
  67. switch ($item["status"]){
  68. case 0:
  69. $res[$k]["status"]="未付款";
  70. break;
  71. case 1:
  72. $res[$k]["status"]="已付款";
  73. break;
  74. }
  75. }
  76. $result = array("total" => $list->total(), "rows" => $list->items());
  77. return json($result);
  78. }
  79. return $this->view->fetch();
  80. }
  81. /**
  82. * 添加
  83. */
  84. public function add()
  85. {
  86. if ($this->request->isPost()) {
  87. $params = $this->request->post("row/a");
  88. if ($params) {
  89. $params = $this->preExcludeFields($params);
  90. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  91. $params[$this->dataLimitField] = $this->auth->id;
  92. }
  93. $result = false;
  94. Db::startTrans();
  95. try {
  96. //是否采用模型验证
  97. if ($this->modelValidate) {
  98. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  99. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  100. $this->model->validateFailException(true)->validate($validate);
  101. }
  102. $params['create_id']=$this->auth->id;
  103. $params['group_id']=$this->auth->getGroupId();
  104. $result = $this->model->allowField(true)->save($params);
  105. Db::commit();
  106. } catch (ValidateException $e) {
  107. Db::rollback();
  108. $this->error($e->getMessage());
  109. } catch (PDOException $e) {
  110. Db::rollback();
  111. $this->error($e->getMessage());
  112. } catch (Exception $e) {
  113. Db::rollback();
  114. $this->error($e->getMessage());
  115. }
  116. if ($result !== false) {
  117. $this->success();
  118. } else {
  119. $this->error(__('No rows were inserted'));
  120. }
  121. }
  122. $this->error(__('Parameter %s can not be empty', ''));
  123. }
  124. return $this->view->fetch();
  125. }
  126. /**
  127. * 编辑
  128. */
  129. public function edit($ids = null)
  130. {
  131. $row = $this->model->get($ids);
  132. if (!$row) {
  133. $this->error(__('No Results were found'));
  134. }
  135. $adminIds = $this->getDataLimitAdminIds();
  136. if (is_array($adminIds)) {
  137. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  138. $this->error(__('You have no permission'));
  139. }
  140. }
  141. if ($this->request->isPost()) {
  142. $params = $this->request->post("row/a");
  143. if ($params) {
  144. $params = $this->preExcludeFields($params);
  145. $result = false;
  146. Db::startTrans();
  147. try {
  148. //是否采用模型验证
  149. if ($this->modelValidate) {
  150. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  151. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  152. $row->validateFailException(true)->validate($validate);
  153. }
  154. $result = $row->allowField(true)->save($params);
  155. Db::commit();
  156. } catch (ValidateException $e) {
  157. Db::rollback();
  158. $this->error($e->getMessage());
  159. } catch (PDOException $e) {
  160. Db::rollback();
  161. $this->error($e->getMessage());
  162. } catch (Exception $e) {
  163. Db::rollback();
  164. $this->error($e->getMessage());
  165. }
  166. if ($result !== false) {
  167. $this->success();
  168. } else {
  169. $this->error(__('No rows were updated'));
  170. }
  171. }
  172. $this->error(__('Parameter %s can not be empty', ''));
  173. }
  174. $this->view->assign("row", $row);
  175. return $this->view->fetch();
  176. }
  177. /**
  178. * 保存记录
  179. * @return \think\response\Json
  180. */
  181. public function save(){
  182. $params=$this->request->post();
  183. $params['create_id']=$this->auth->id;
  184. $params['group_id']=$this->auth->getGroupId();
  185. $service = new ReceiptOrderService();
  186. $result = $service->save($params);
  187. return json($result);
  188. }
  189. /**
  190. * 获取列表
  191. * @return \think\response\Json
  192. */
  193. public function getList(){
  194. $params=$this->request->post();
  195. $service = new ReceiptOrderService();
  196. $result = $service->getList($params);
  197. return json($result);
  198. }
  199. /**
  200. * 状态设置
  201. * @return \think\response\Json
  202. */
  203. public function setStatus(){
  204. $params=$this->request->post();
  205. $service = new ReceiptOrderService();
  206. $result = $service->setStatus($params['id'],$params['status']);
  207. return json($result);
  208. }
  209. /**
  210. * 添加到收款单
  211. * @return \think\response\Json
  212. */
  213. public function addOrderMain(){
  214. $params=$this->request->post();
  215. $service = new ReceiptOrderService();
  216. $result = $service->addOrderMain($params['id'],$params['order_id']);
  217. return json($result);
  218. }
  219. /**
  220. * 移除收购单
  221. * @return \think\response\Json
  222. */
  223. public function removeOrderMain(){
  224. $params=$this->request->post();
  225. $service = new ReceiptOrderService();
  226. $result = $service->removeOrderMain($params['order_id']);
  227. return json($result);
  228. }
  229. /**
  230. * 获取订单列表
  231. * @return \think\response\Json
  232. */
  233. public function getOrderMainList(){
  234. $params=$this->request->post();
  235. $service = new ReceiptOrderService();
  236. $result = $service->getOrderMainList($params);
  237. return json($result);
  238. }
  239. /**
  240. * 删除收款单
  241. */
  242. public function delAll(){
  243. $params=$this->request->post();
  244. $service = new ReceiptOrderService();
  245. $result = $service->delAll($params['id']);
  246. return json($result);
  247. }
  248. }