diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index bd0b5d0..abdd780 100755 --- a/application/admin/controller/Ajax.php +++ b/application/admin/controller/Ajax.php @@ -2,6 +2,7 @@ namespace app\admin\controller; +use app\admin\command\Util; use app\common\controller\Backend; use app\common\exception\UploadException; use app\common\library\Upload; @@ -289,6 +290,26 @@ class Ajax extends Backend $provincelist = Db::name('area')->where($where)->field('id as value,name')->select(); $this->success('', '', $provincelist); } + /** + * 读取省市区数据,联动列表 + */ + public function areaList() + { + $province = $this->request->post('province', ''); + $city = $this->request->post('city', ''); + $where = ['pid' => 0, 'level' => 1]; + $provincelist = null; + if ($province !== '') { + $where['pid'] = $province; + $where['level'] = 2; + if ($city !== '') { + $where['pid'] = $city; + $where['level'] = 3; + } + } + $provincelist = Db::name('area')->where($where)->field('id as value,name')->select(); + return json(Util::returnArrSu("",$provincelist->toArray())); + } /** * 生成后缀图标 diff --git a/application/admin/controller/CfHotelInfo.php b/application/admin/controller/CfHotelInfo.php index 2a882d0..0e145fc 100755 --- a/application/admin/controller/CfHotelInfo.php +++ b/application/admin/controller/CfHotelInfo.php @@ -3,6 +3,7 @@ namespace app\admin\controller; use app\admin\model\Area; +use app\admin\service\CfHotelInfoService; use app\common\controller\Backend; use think\Db; use think\exception\PDOException; @@ -15,17 +16,17 @@ use think\exception\ValidateException; */ class CfHotelInfo extends Backend { - + /** - * CfHotelInfo模型对象 - * @var \app\admin\model\CfHotelInfo + * PaymentOrder模型对象 + * @var \app\admin\model\PaymentOrder */ protected $model = null; public function _initialize() { parent::_initialize(); - $this->model = new \app\admin\model\CfHotelInfo; + $this->model = new \app\admin\model\PaymentOrder; } @@ -40,170 +41,38 @@ class CfHotelInfo extends Backend * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ - /** - * 查看 - */ - public function index() - { - //设置过滤方法 - $this->request->filter(['strip_tags', 'trim']); - if ($this->request->isAjax()) { - //如果发送的来源是Selectpage,则转发到Selectpage - if ($this->request->request('keyField')) { - return $this->selectpage(); - } - list($where, $sort, $order, $offset, $limit) = $this->buildparams(); - $group_id=$this->auth->getGroupId(); - $list = $this->model - ->alias("a") - ->join('hbp_admin c','a.create_id = c.id','left') - ->field("a.*,c.nickname") - ->where($where); - if ($group_id){ - $list = $list - ->where("group_id","=",$group_id) - ->order($sort, $order) - ->paginate($limit); - }else{ - $list = $list - ->order($sort, $order) - ->paginate($limit); - } - $result = array("total" => $list->total(), "rows" => $list->items()); - return json($result); - } - return $this->view->fetch(); - } - public function getHotelList(){ - $name=$this->request->post('name'); - $keyValue=$this->request->post('keyValue'); - $result= $this->model->getList($name,$keyValue); - if($keyValue){ - return json(['list' => $result]); - } - return json(['list' => $result]); + /****=========================================**/ + /** + * 获取列表 + * @return \think\response\Json + */ + public function getList(){ + $params=$this->request->post(); + $service = new CfHotelInfoService(); + return json($service->getList($params)); } /** - * 添加 + * 保存记录 + * @return \think\response\Json */ - public function add() - { - if ($this->request->isPost()) { - - $params = $this->request->post("row/a"); - if ($params) { - $params = $this->preExcludeFields($params); - - if ($this->dataLimit && $this->dataLimitFieldAutoFill) { - $params[$this->dataLimitField] = $this->auth->id; - } - $result = false; - Db::startTrans(); - try { - //是否采用模型验证 - if ($this->modelValidate) { - $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; - $this->model->validateFailException(true)->validate($validate); - } - $area=new Area(); - if ($params["area"]){ - $params["area_name"]=$area->where("id","=",$params["area"])->value("name"); - } - if ($params["province"]){ - $params["province_name"]=$area->where("id","=",$params["province"])->value("name"); - } - if ($params["city"]){ - $params["city_name"]=$area->where("id","=",$params["city"])->value("name"); - } - $params['create_id']=$this->auth->id; - $params['group_id']=$this->auth->getGroupId(); - $result = $this->model->allowField(true)->save($params); - Db::commit(); - } catch (ValidateException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { - Db::rollback(); - $this->error($e->getMessage()); - } - if ($result !== false) { - $this->success(); - } else { - $this->error(__('No rows were inserted')); - } - } - $this->error(__('Parameter %s can not be empty', '')); - } - return $this->view->fetch(); + public function save(){ + $params=$this->request->post(); + $params['create_id']=$this->auth->id; + $params['group_id']=$this->auth->getGroupId(); + $service = new CfHotelInfoService(); + return json($service->save($params)); } - /** - * 编辑 + * 删除 + * @return \think\response\Json */ - public function edit($ids = null) - { - $row = $this->model->get($ids); - if (!$row) { - $this->error(__('No Results were found')); - } - $adminIds = $this->getDataLimitAdminIds(); - if (is_array($adminIds)) { - if (!in_array($row[$this->dataLimitField], $adminIds)) { - $this->error(__('You have no permission')); - } - } - if ($this->request->isPost()) { - $params = $this->request->post("row/a"); - if ($params) { - $params = $this->preExcludeFields($params); - $result = false; - Db::startTrans(); - try { - //是否采用模型验证 - if ($this->modelValidate) { - $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; - $row->validateFailException(true)->validate($validate); - } - $area=new Area(); - if ($params["area"]){ - $params["area_name"]=$area->where("id","=",$params["area"])->value("name"); - } - if ($params["province"]){ - $params["province_name"]=$area->where("id","=",$params["province"])->value("name"); - } - if ($params["city"]){ - $params["city_name"]=$area->where("id","=",$params["city"])->value("name"); - } - $result = $row->allowField(true)->save($params); - Db::commit(); - } catch (ValidateException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { - Db::rollback(); - $this->error($e->getMessage()); - } - if ($result !== false) { - $this->success(); - } else { - $this->error(__('No rows were updated')); - } - } - $this->error(__('Parameter %s can not be empty', '')); - } - $this->view->assign("row", $row); - return $this->view->fetch(); + public function delAll(){ + $params=$this->request->post(); + $service = new CfHotelInfoService(); + return json($service->del($params)); } } diff --git a/application/admin/dao/CfHotelInfoDao.php b/application/admin/dao/CfHotelInfoDao.php new file mode 100644 index 0000000..bf8bf0c --- /dev/null +++ b/application/admin/dao/CfHotelInfoDao.php @@ -0,0 +1,103 @@ + $param['hotel_name'], + 'hotel_phone' => $param['hotel_phone'], + 'area' => $param['area'], + 'area_name' => $param['area_name'], + 'province' => $param['province'], + 'province_name' => $param['province_name'], + 'city' => $param['city'], + 'city_name' => $param['city_name'], + 'detail_address' => $param['detail_address'] + ]; + $receiptOrder = new CfHotelInfo(); + if (empty($param['id'])) { + $data['create_id'] = $param['create_id']; + $data['group_id'] = $param['group_id']; + $id = $receiptOrder->insertGetId($data); + return Util::returnArrSu("", $id); + } else { + $receiptOrder->save($data, ['id' => $param['id']]); + return Util::returnArrSu("", $param['id']); + } + } catch (\Exception $e) { + return Util::returnArrEr("更新记录失败:" . $e->getMessage()); + } + } + + /** + * 获取列表 + * @param $param + * @return array + */ + public function getList($param) + { + try { + $where = ["del_flag"=>0]; + if (!empty($param['hotel_name'])) { + $where['hotel_name'] = ["like","%".$param['hotel_name']."%"]; + } + if (!empty($param['hotel_phone'])) { + $where["hotel_phone"] = $param['hotel_phone']; + } + if (!empty($param['area'])) { + $where["area"] = $param['area']; + } + if (!empty($param['province'])) { + $where["province"] = $param['province']; + } + if (!empty($param['city'])) { + $where["city"] = $param['city']; + } + $offset = ($param['pageNum'] - 1) * $param['pageSize']; + $model = new CfHotelInfo(); + $total = $model->where($where)->count(); + $list = $model->where($where) + ->limit($offset, $param['pageSize']) + ->order("id","DESC")->select(); + $data = ["total" => $total, "list" => $list->toArray()]; + return Util::returnArrSu("", $data); + } catch (\Exception $e) { + return Util::returnArrSu("", ["total" => 0, "list" => []]); + } + } + + /** + * 删除 + * @param $id + * @return array + */ + public function del($id){ + try { + //设置收购单状态 + $receiptOrder = new CfHotelInfo(); + $receiptOrder->save(['del_flag' => 1], ['id' => $id]); + return Util::returnArrSu(); + } catch (\Exception $e) { + return Util::returnArrEr("修改状态失败" . $e->getMessage()); + } + } +} \ No newline at end of file diff --git a/application/admin/service/CfHotelInfoService.php b/application/admin/service/CfHotelInfoService.php new file mode 100644 index 0000000..89919f9 --- /dev/null +++ b/application/admin/service/CfHotelInfoService.php @@ -0,0 +1,45 @@ +getList($param); + } + + /** + * 保存记录 + * @param $param + * @return array + */ + public function save($param){ + $dao = new CfHotelInfoDao(); + return $dao->save($param); + } + + /** + * 删除记录 + * @param $param + * @return array + */ + public function del($param){ + $dao = new CfHotelInfoDao(); + return $dao->del($param['id']); + } +} \ No newline at end of file diff --git a/application/admin/view/cf_hotel_info/index.html b/application/admin/view/cf_hotel_info/index.html index 8794410..ba07060 100755 --- a/application/admin/view/cf_hotel_info/index.html +++ b/application/admin/view/cf_hotel_info/index.html @@ -1,35 +1,438 @@ -
- {:build_heading()} - -
-
- - + + + + + + + + +
+
+ + + + + + + + + + + + + + + + +
+ + + + + +
+ +
+
+
+
+ + + +
+
+ + + +
+
+ + + + + + + + + + + + + + + +
+
+ + + +
+
+ 保存 +
+
+
+
+ + + + + + + + +