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

297 lines
9.5 KiB

  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Area;
  4. use app\admin\service\OrderMainService;
  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 OrderMain extends Backend
  15. {
  16. /**
  17. * OrderMain模型对象
  18. * @var \app\admin\model\OrderMain
  19. */
  20. protected $model = null;
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = new \app\admin\model\OrderMain;
  25. }
  26. public function import()
  27. {
  28. parent::import();
  29. }
  30. /**
  31. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  32. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  33. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  34. */
  35. /**
  36. * 查看
  37. */
  38. public function index()
  39. {
  40. //设置过滤方法
  41. $this->request->filter(['strip_tags', 'trim']);
  42. if ($this->request->isAjax()) {
  43. //如果发送的来源是Selectpage,则转发到Selectpage
  44. if ($this->request->request('keyField')) {
  45. return $this->selectpage();
  46. }
  47. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  48. $group_id=$this->auth->getGroupId();
  49. $list = $this->model
  50. ->alias("a")
  51. ->join('hbp_cf_channel_info b','a.channel_id = b.id','left')
  52. ->join('hbp_admin c','a.create_id = c.id','left')
  53. ->field("a.*,b.channel_name,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. $result = $list->items();
  66. foreach ($result as $k=>$item){
  67. switch ($item["order_status"]){
  68. case 0:
  69. $result[$k]["order_status"]="待处理";
  70. break;
  71. case 1:
  72. $result[$k]["order_status"]="已确认";
  73. break;
  74. case 2:
  75. $result[$k]["order_status"]="部分取消";
  76. break;
  77. case 10:
  78. $result[$k]["order_status"]="已完成";
  79. break;
  80. case 11:
  81. $result[$k]["order_status"]="已取消";
  82. break;
  83. }
  84. }
  85. $result = array("total" => $list->total(), "rows" =>$result);
  86. return json($result);
  87. }
  88. return $this->view->fetch();
  89. }
  90. /**
  91. * 添加
  92. */
  93. public function add()
  94. {
  95. if ($this->request->isPost()) {
  96. $params = $this->request->post("row/a");
  97. if ($params) {
  98. $params = $this->preExcludeFields($params);
  99. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  100. $params[$this->dataLimitField] = $this->auth->id;
  101. }
  102. $result = false;
  103. Db::startTrans();
  104. try {
  105. //是否采用模型验证
  106. if ($this->modelValidate) {
  107. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  108. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  109. $this->model->validateFailException(true)->validate($validate);
  110. }
  111. $params['create_id']=$this->auth->id;
  112. $params['group_id']=$this->auth->getGroupId();
  113. $result = $this->model->allowField(true)->save($params);
  114. Db::commit();
  115. } catch (ValidateException $e) {
  116. Db::rollback();
  117. $this->error($e->getMessage());
  118. } catch (PDOException $e) {
  119. Db::rollback();
  120. $this->error($e->getMessage());
  121. } catch (Exception $e) {
  122. Db::rollback();
  123. $this->error($e->getMessage());
  124. }
  125. if ($result !== false) {
  126. $this->success();
  127. } else {
  128. $this->error(__('No rows were inserted'));
  129. }
  130. }
  131. $this->error(__('Parameter %s can not be empty', ''));
  132. }
  133. return $this->view->fetch();
  134. }
  135. /**
  136. * 编辑
  137. */
  138. public function edit($ids = null)
  139. {
  140. $row = $this->model->get($ids);
  141. if (!$row) {
  142. $this->error(__('No Results were found'));
  143. }
  144. $adminIds = $this->getDataLimitAdminIds();
  145. if (is_array($adminIds)) {
  146. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  147. $this->error(__('You have no permission'));
  148. }
  149. }
  150. if ($this->request->isPost()) {
  151. $params = $this->request->post("row/a");
  152. if ($params) {
  153. $params = $this->preExcludeFields($params);
  154. $result = false;
  155. Db::startTrans();
  156. try {
  157. //是否采用模型验证
  158. if ($this->modelValidate) {
  159. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  160. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  161. $row->validateFailException(true)->validate($validate);
  162. }
  163. $result = $row->allowField(true)->save($params);
  164. Db::commit();
  165. } catch (ValidateException $e) {
  166. Db::rollback();
  167. $this->error($e->getMessage());
  168. } catch (PDOException $e) {
  169. Db::rollback();
  170. $this->error($e->getMessage());
  171. } catch (Exception $e) {
  172. Db::rollback();
  173. $this->error($e->getMessage());
  174. }
  175. if ($result !== false) {
  176. $this->success();
  177. } else {
  178. $this->error(__('No rows were updated'));
  179. }
  180. }
  181. $this->error(__('Parameter %s can not be empty', ''));
  182. }
  183. $this->view->assign("row", $row);
  184. return $this->view->fetch();
  185. }
  186. public function newEdit($id =null){
  187. $orderMain = $this->model->find($id);
  188. if (!$orderMain){
  189. return null;
  190. }
  191. $orderHotelList=(new \app\admin\model\OrderHotel())
  192. ->where("order_id","=",$id)
  193. ->find();
  194. $orderItemList=(new \app\admin\model\OrderItem())
  195. ->where("order_id","=",$id)
  196. ->find();
  197. $result = [
  198. "orderMain"=>$orderMain,
  199. "hotel"=>$orderHotelList,
  200. "item"=>$orderItemList
  201. ];
  202. return json($result);
  203. }
  204. /**
  205. * 订单页面保存接口
  206. * @return \think\response\Json
  207. */
  208. public function save(){
  209. $params=$this->request->post();
  210. $params['create_id']=$this->auth->id;
  211. $params['group_id']=$this->auth->getGroupId();
  212. $orderMainService = new OrderMainService();
  213. Db::startTrans();
  214. $result = $orderMainService->saveOrder($params);
  215. if (!$result['flag']) {
  216. Db::rollback();
  217. } else {
  218. Db::commit();
  219. }
  220. return json($result);
  221. }
  222. /**
  223. * 子订单保存接口
  224. * @return \think\response\Json
  225. */
  226. public function subOrderSave(){
  227. $params=$this->request->post();
  228. $orderMainService = new OrderMainService();
  229. Db::startTrans();
  230. $result = $orderMainService->subOrderSave($params);
  231. if (!$result['flag']) {
  232. Db::rollback();
  233. } else {
  234. Db::commit();
  235. }
  236. return json($result);
  237. }
  238. /**
  239. * 删除子订单
  240. * @return \think\response\Json
  241. */
  242. public function delSubOrder(){
  243. $params=$this->request->post();
  244. $orderMainService = new OrderMainService();
  245. $result = $orderMainService->delSubOrder($params);
  246. return json($result);
  247. }
  248. /**
  249. * 获取订单详情
  250. * @return \think\response\Json
  251. */
  252. public function getShowInfo(){
  253. $params=$this->request->post();
  254. $orderMainService = new OrderMainService();
  255. $result = $orderMainService->getOrderInfo($params['id']);
  256. return json($result);
  257. }
  258. public function newAdd(){
  259. $params=$this->request->post();
  260. $hotelMain = $params["orderMain"];
  261. $this->insertOrderMain($hotelMain);
  262. return ;
  263. }
  264. private function insertOrderMain($params){
  265. $orderMain = new \app\admin\model\OrderMain();
  266. $params['create_id']=$this->auth->id;
  267. $params['group_id']=$this->auth->getGroupId();
  268. $result = $orderMain->allowField(true)->save($params);
  269. }
  270. }