酒店预订平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

OrderMain.php 8.0 KiB

3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Area;
  4. use app\admin\service\OrderMainDao;
  5. use app\admin\service\OrderMainService;
  6. use app\common\controller\Backend;
  7. use think\Db;
  8. use think\exception\PDOException;
  9. use think\exception\ValidateException;
  10. /**
  11. * 订单主管理
  12. *
  13. * @icon fa fa-circle-o
  14. */
  15. class OrderMain extends Backend
  16. {
  17. /**
  18. * OrderMain模型对象
  19. * @var \app\admin\model\OrderMain
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\admin\model\OrderMain;
  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_cf_channel_info b','a.channel_id = b.id','left')
  53. ->join('hbp_admin c','a.create_id = c.id','left')
  54. ->field("a.*,b.channel_name,c.nickname")
  55. ->where($where);
  56. if ($group_id){
  57. $list = $list
  58. ->where("group_id","=",$group_id)
  59. ->order($sort, $order)
  60. ->paginate($limit);
  61. }else{
  62. $list = $list
  63. ->order($sort, $order)
  64. ->paginate($limit);
  65. }
  66. $result = $list->items();
  67. foreach ($result as $k=>$item){
  68. switch ($item["order_status"]){
  69. case 0:
  70. $result[$k]["order_status"]="待处理";
  71. break;
  72. case 1:
  73. $result[$k]["order_status"]="已确认";
  74. break;
  75. case 2:
  76. $result[$k]["order_status"]="部分取消";
  77. break;
  78. case 10:
  79. $result[$k]["order_status"]="已完成";
  80. break;
  81. case 11:
  82. $result[$k]["order_status"]="已取消";
  83. break;
  84. }
  85. }
  86. $result = array("total" => $list->total(), "rows" =>$result);
  87. return json($result);
  88. }
  89. return $this->view->fetch();
  90. }
  91. /**
  92. * 添加
  93. */
  94. public function add()
  95. {
  96. if ($this->request->isPost()) {
  97. $params = $this->request->post("row/a");
  98. if ($params) {
  99. $params = $this->preExcludeFields($params);
  100. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  101. $params[$this->dataLimitField] = $this->auth->id;
  102. }
  103. $result = false;
  104. Db::startTrans();
  105. try {
  106. //是否采用模型验证
  107. if ($this->modelValidate) {
  108. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  109. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  110. $this->model->validateFailException(true)->validate($validate);
  111. }
  112. $params['create_id']=$this->auth->id;
  113. $params['group_id']=$this->auth->getGroupId();
  114. $result = $this->model->allowField(true)->save($params);
  115. Db::commit();
  116. } catch (ValidateException $e) {
  117. Db::rollback();
  118. $this->error($e->getMessage());
  119. } catch (PDOException $e) {
  120. Db::rollback();
  121. $this->error($e->getMessage());
  122. } catch (Exception $e) {
  123. Db::rollback();
  124. $this->error($e->getMessage());
  125. }
  126. if ($result !== false) {
  127. $this->success();
  128. } else {
  129. $this->error(__('No rows were inserted'));
  130. }
  131. }
  132. $this->error(__('Parameter %s can not be empty', ''));
  133. }
  134. return $this->view->fetch();
  135. }
  136. /**
  137. * 编辑
  138. */
  139. public function edit($ids = null)
  140. {
  141. $row = $this->model->get($ids);
  142. if (!$row) {
  143. $this->error(__('No Results were found'));
  144. }
  145. $adminIds = $this->getDataLimitAdminIds();
  146. if (is_array($adminIds)) {
  147. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  148. $this->error(__('You have no permission'));
  149. }
  150. }
  151. if ($this->request->isPost()) {
  152. $params = $this->request->post("row/a");
  153. if ($params) {
  154. $params = $this->preExcludeFields($params);
  155. $result = false;
  156. Db::startTrans();
  157. try {
  158. //是否采用模型验证
  159. if ($this->modelValidate) {
  160. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  161. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  162. $row->validateFailException(true)->validate($validate);
  163. }
  164. $result = $row->allowField(true)->save($params);
  165. Db::commit();
  166. } catch (ValidateException $e) {
  167. Db::rollback();
  168. $this->error($e->getMessage());
  169. } catch (PDOException $e) {
  170. Db::rollback();
  171. $this->error($e->getMessage());
  172. } catch (Exception $e) {
  173. Db::rollback();
  174. $this->error($e->getMessage());
  175. }
  176. if ($result !== false) {
  177. $this->success();
  178. } else {
  179. $this->error(__('No rows were updated'));
  180. }
  181. }
  182. $this->error(__('Parameter %s can not be empty', ''));
  183. }
  184. $this->view->assign("row", $row);
  185. return $this->view->fetch();
  186. }
  187. public function newEdit($id =null){
  188. $orderMain = $this->model->find($id);
  189. if (!$orderMain){
  190. return null;
  191. }
  192. $orderHotelList=(new \app\admin\model\OrderHotel())
  193. ->where("order_id","=",$id)
  194. ->find();
  195. $orderItemList=(new \app\admin\model\OrderItem())
  196. ->where("order_id","=",$id)
  197. ->find();
  198. $result = [
  199. "orderMain"=>$orderMain,
  200. "hotel"=>$orderHotelList,
  201. "item"=>$orderItemList
  202. ];
  203. return json($result);
  204. }
  205. /**
  206. * 新增主订单
  207. * @return \think\response\Json
  208. */
  209. public function newAdd(){
  210. $params=$this->request->post();
  211. $orderMainService = new OrderMainService();
  212. return json($orderMainService->createOrder($params));
  213. }
  214. private function insertOrderMain($params){
  215. $orderMain = new \app\admin\model\OrderMain();
  216. $params['create_id']=$this->auth->id;
  217. $params['group_id']=$this->auth->getGroupId();
  218. $result = $orderMain->allowField(true)->save($params);
  219. }
  220. }