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

225 lines
7.4 KiB

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