作者 郭文星

123

@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 namespace app\admin\controller; 3 namespace app\admin\controller;
4 4
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
  6 +use think\exception\DbException;
  7 +use think\response\Json;
6 8
7 /** 9 /**
8 * 路线管理 10 * 路线管理
@@ -22,7 +24,7 @@ class Route extends Backend @@ -22,7 +24,7 @@ class Route extends Backend
22 { 24 {
23 parent::_initialize(); 25 parent::_initialize();
24 $this->model = new \app\admin\model\Route; 26 $this->model = new \app\admin\model\Route;
25 - $this->view->assign("typeList", $this->model->getTypeList()); 27 +
26 } 28 }
27 29
28 30
@@ -33,5 +35,30 @@ class Route extends Backend @@ -33,5 +35,30 @@ class Route extends Backend
33 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 35 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
34 */ 36 */
35 37
36 - 38 + /**
  39 + * 查看
  40 + *
  41 + * @return string|Json
  42 + * @throws \think\Exception
  43 + * @throws DbException
  44 + */
  45 + public function index()
  46 + {
  47 + //设置过滤方法
  48 + $this->request->filter(['strip_tags', 'trim']);
  49 + if (false === $this->request->isAjax()) {
  50 + return $this->view->fetch();
  51 + }
  52 + //如果发送的来源是 Selectpage,则转发到 Selectpage
  53 + if ($this->request->request('keyField')) {
  54 + return $this->selectpage();
  55 + }
  56 + [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  57 + $list = $this->model
  58 + ->where($where)
  59 + ->order($sort, $order)
  60 + ->paginate($limit);
  61 + $result = ['total' => $list->total(), 'rows' => $list->items()];
  62 + return json($result);
  63 + }
37 } 64 }
  1 +<?php
  2 +
  3 +namespace app\admin\controller;
  4 +
  5 +use app\common\controller\Backend;
  6 +use think\Db;
  7 +use think\exception\DbException;
  8 +use think\exception\PDOException;
  9 +use think\exception\ValidateException;
  10 +use think\response\Json;
  11 +
  12 +/**
  13 + * 详细地址
  14 + *
  15 + * @icon fa fa-circle-o
  16 + */
  17 +class Specificaddress extends Backend
  18 +{
  19 +
  20 + /**
  21 + * Specificaddress模型对象
  22 + * @var \app\admin\model\Specificaddress
  23 + */
  24 + protected $model = null;
  25 +
  26 + public function _initialize()
  27 + {
  28 + parent::_initialize();
  29 + $this->model = new \app\admin\model\Specificaddress;
  30 + $route_id = $this->request->param("route_id");
  31 + $this->view->assign("route_id", $route_id);
  32 +
  33 + }
  34 +
  35 +
  36 +
  37 + /**
  38 + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  39 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  40 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  41 + */
  42 +
  43 + /**
  44 + * 查看
  45 + *
  46 + * @return string|Json
  47 + * @throws \think\Exception
  48 + * @throws DbException
  49 + */
  50 + public function index()
  51 + {
  52 + //设置过滤方法
  53 + $this->request->filter(['strip_tags', 'trim']);
  54 + if (false === $this->request->isAjax()) {
  55 + return $this->view->fetch();
  56 + }
  57 + //如果发送的来源是 Selectpage,则转发到 Selectpage
  58 + if ($this->request->request('keyField')) {
  59 + return $this->selectpage();
  60 + }
  61 + [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  62 + $list = $this->model
  63 + ->where($where)
  64 + ->order($sort, $order)
  65 + ->paginate($limit);
  66 + $result = ['total' => $list->total(), 'rows' => $list->items()];
  67 + return json($result);
  68 + }
  69 + /**
  70 + * 添加
  71 + *
  72 + * @return string
  73 + * @throws \think\Exception
  74 + */
  75 + public function add()
  76 + {
  77 + if (false === $this->request->isPost()) {
  78 + return $this->view->fetch();
  79 + }
  80 + $params = $this->request->post('row/a');
  81 + if (empty($params)) {
  82 + $this->error(__('Parameter %s can not be empty', ''));
  83 + }
  84 + $params = $this->preExcludeFields($params);
  85 +
  86 + if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  87 + $params[$this->dataLimitField] = $this->auth->id;
  88 + }
  89 + $result = false;
  90 + Db::startTrans();
  91 + try {
  92 + //是否采用模型验证
  93 + if ($this->modelValidate) {
  94 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  95 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  96 + $this->model->validateFailException()->validate($validate);
  97 + }
  98 + $result = $this->model->allowField(true)->save($params);
  99 + Db::commit();
  100 + } catch (ValidateException|PDOException|Exception $e) {
  101 + Db::rollback();
  102 + $this->error($e->getMessage());
  103 + }
  104 + if ($result === false) {
  105 + $this->error(__('No rows were inserted'));
  106 + }
  107 + $this->success();
  108 + }
  109 +
  110 +}
@@ -5,9 +5,6 @@ return [ @@ -5,9 +5,6 @@ return [
5 'Name' => '线路名称', 5 'Name' => '线路名称',
6 'Start_address' => '开始地址', 6 'Start_address' => '开始地址',
7 'End_address' => '结束地址', 7 'End_address' => '结束地址',
8 - 'Type' => '线路类型',  
9 - 'Type 1' => '城际',  
10 - 'Type 2' => '计票',  
11 - 'Price' => '城际价格', 8 + 'Price' => '价格',
12 'Create_time' => '创建时间' 9 'Create_time' => '创建时间'
13 ]; 10 ];
  1 +<?php
  2 +
  3 +return [
  4 + 'Id' => 'ID',
  5 + 'Route_id' => '线路',
  6 + 'Specific_address' => '详细地址'
  7 +];
@@ -25,24 +25,12 @@ class Route extends Model @@ -25,24 +25,12 @@ class Route extends Model
25 25
26 // 追加属性 26 // 追加属性
27 protected $append = [ 27 protected $append = [
28 - 'type_text',  
29 'create_time_text' 28 'create_time_text'
30 ]; 29 ];
31 30
32 31
33 32
34 - public function getTypeList()  
35 - {  
36 - return ['1' => __('Type 1'), '2' => __('Type 2')];  
37 - }  
38 -  
39 33
40 - public function getTypeTextAttr($value, $data)  
41 - {  
42 - $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');  
43 - $list = $this->getTypeList();  
44 - return isset($list[$value]) ? $list[$value] : '';  
45 - }  
46 34
47 35
48 public function getCreateTimeTextAttr($value, $data) 36 public function getCreateTimeTextAttr($value, $data)
  1 +<?php
  2 +
  3 +namespace app\admin\model;
  4 +
  5 +use think\Model;
  6 +
  7 +
  8 +class Specificaddress extends Model
  9 +{
  10 +
  11 +
  12 +
  13 +
  14 +
  15 + // 表名
  16 + protected $name = 'specificaddress';
  17 +
  18 + // 自动写入时间戳字段
  19 + protected $autoWriteTimestamp = false;
  20 +
  21 + // 定义时间戳字段名
  22 + protected $createTime = false;
  23 + protected $updateTime = false;
  24 + protected $deleteTime = false;
  25 +
  26 + // 追加属性
  27 + protected $append = [
  28 +
  29 + ];
  30 +
  31 +
  32 +
  33 +
  34 +
  35 +
  36 +
  37 +
  38 +
  39 +
  40 +}
  1 +<?php
  2 +
  3 +namespace app\admin\validate;
  4 +
  5 +use think\Validate;
  6 +
  7 +class Specificaddress extends Validate
  8 +{
  9 + /**
  10 + * 验证规则
  11 + */
  12 + protected $rule = [
  13 + ];
  14 + /**
  15 + * 提示消息
  16 + */
  17 + protected $message = [
  18 + ];
  19 + /**
  20 + * 验证场景
  21 + */
  22 + protected $scene = [
  23 + 'add' => [],
  24 + 'edit' => [],
  25 + ];
  26 +
  27 +}
@@ -18,7 +18,6 @@ @@ -18,7 +18,6 @@
18 <input id="c-end_address" class="form-control" name="row[end_address]" type="text"> 18 <input id="c-end_address" class="form-control" name="row[end_address]" type="text">
19 </div> 19 </div>
20 </div> 20 </div>
21 -  
22 <div class="form-group"> 21 <div class="form-group">
23 <label class="control-label col-xs-12 col-sm-2">{:__('Price')}:</label> 22 <label class="control-label col-xs-12 col-sm-2">{:__('Price')}:</label>
24 <div class="col-xs-12 col-sm-8"> 23 <div class="col-xs-12 col-sm-8">
@@ -18,7 +18,6 @@ @@ -18,7 +18,6 @@
18 <input id="c-end_address" class="form-control" name="row[end_address]" type="text" value="{$row.end_address|htmlentities}"> 18 <input id="c-end_address" class="form-control" name="row[end_address]" type="text" value="{$row.end_address|htmlentities}">
19 </div> 19 </div>
20 </div> 20 </div>
21 -  
22 <div class="form-group"> 21 <div class="form-group">
23 <label class="control-label col-xs-12 col-sm-2">{:__('Price')}:</label> 22 <label class="control-label col-xs-12 col-sm-2">{:__('Price')}:</label>
24 <div class="col-xs-12 col-sm-8"> 23 <div class="col-xs-12 col-sm-8">
  1 +<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('Route_id')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-route_id" data-rule="required" data-source="route/index" class="form-control selectpage" name="row[route_id]" type="text" value="{$route_id}">
  7 + </div>
  8 +
  9 + </div>
  10 + <div class="form-group">
  11 + <label class="control-label col-xs-12 col-sm-2">{:__('Specific_address')}:</label>
  12 + <div class="col-xs-12 col-sm-8">
  13 + <input id="c-specific_address" class="form-control" name="row[specific_address]" type="text">
  14 + </div>
  15 + </div>
  16 + <div class="form-group layer-footer">
  17 + <label class="control-label col-xs-12 col-sm-2"></label>
  18 + <div class="col-xs-12 col-sm-8">
  19 + <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
  20 + </div>
  21 + </div>
  22 +</form>
  1 +<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('Route_id')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-route_id" data-rule="required" data-source="route/index" class="form-control selectpage" name="row[route_id]" type="text" value="{$row.route_id|htmlentities}">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label class="control-label col-xs-12 col-sm-2">{:__('Specific_address')}:</label>
  11 + <div class="col-xs-12 col-sm-8">
  12 + <input id="c-specific_address" class="form-control" name="row[specific_address]" type="text" value="{$row.specific_address|htmlentities}">
  13 + </div>
  14 + </div>
  15 + <div class="form-group layer-footer">
  16 + <label class="control-label col-xs-12 col-sm-2"></label>
  17 + <div class="col-xs-12 col-sm-8">
  18 + <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
  19 + </div>
  20 + </div>
  21 +</form>
  1 +<div class="panel panel-default panel-intro">
  2 + {:build_heading()}
  3 +
  4 + <div class="panel-body">
  5 + <div id="myTabContent" class="tab-content">
  6 + <div class="tab-pane fade active in" id="one">
  7 + <div class="widget-body no-padding">
  8 + <div id="toolbar" class="toolbar">
  9 + <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
  10 + <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('specificaddress/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
  11 + <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('specificaddress/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
  12 + <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('specificaddress/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
  13 +
  14 +
  15 +
  16 +
  17 +
  18 + </div>
  19 + <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
  20 + data-operate-edit="{:$auth->check('specificaddress/edit')}"
  21 + data-operate-del="{:$auth->check('specificaddress/del')}"
  22 + width="100%">
  23 + </table>
  24 + </div>
  25 + </div>
  26 +
  27 + </div>
  28 + </div>
  29 +</div>
@@ -118,7 +118,6 @@ class Car extends Base @@ -118,7 +118,6 @@ class Car extends Base
118 ->find(); 118 ->find();
119 119
120 if(!$order_review){ 120 if(!$order_review){
121 -  
122 $order_review_id=Db::name("order_review") 121 $order_review_id=Db::name("order_review")
123 ->insertGetId([ 122 ->insertGetId([
124 "car_id"=>$car_id, 123 "car_id"=>$car_id,
@@ -130,7 +129,6 @@ class Car extends Base @@ -130,7 +129,6 @@ class Car extends Base
130 }else{ 129 }else{
131 $order_review_id=$order_review['id']; 130 $order_review_id=$order_review['id'];
132 } 131 }
133 -  
134 //计算价格 132 //计算价格
135 $seatres=Db::name("seat")->where("id",$car['seat_id'])->find(); 133 $seatres=Db::name("seat")->where("id",$car['seat_id'])->find();
136 $seat_no_array = explode(",", $seat_no); 134 $seat_no_array = explode(",", $seat_no);
@@ -1116,20 +1114,13 @@ class Car extends Base @@ -1116,20 +1114,13 @@ class Car extends Base
1116 $indexList = []; 1114 $indexList = [];
1117 $itemArr = []; 1115 $itemArr = [];
1118 $list = Db::name("route")->where($where) 1116 $list = Db::name("route")->where($where)
1119 - ->select(); 1117 + ->select();
  1118 + foreach ($list as $k=>$v){
  1119 + $list[$k]['specificaddress']=Db::name("specificaddress")->where("route_id",$list[$k]['id'])->select();
  1120 + }
1120 $charArray = []; 1121 $charArray = [];
1121 - $back_data = [];  
1122 if (!empty($list)) { 1122 if (!empty($list)) {
1123 - $count = count($list);  
1124 - $addnum = 500;//因为即时通讯人员状态每次限制查500人;所以得分开查  
1125 - for ($i = 0; $i < $count; $i = $i + $addnum) {  
1126 - if ($count - $i > 0) {  
1127 - $j = $i - 1 > 0 ? $i : 0;  
1128 - $data = array_slice($list, $j, $addnum);  
1129 -  
1130 1123
1131 - }  
1132 - }  
1133 $staff_names = array_column($list, 'end_address'); 1124 $staff_names = array_column($list, 'end_address');
1134 array_multisort($staff_names, SORT_ASC, $list); 1125 array_multisort($staff_names, SORT_ASC, $list);
1135 1126
@@ -1164,20 +1155,13 @@ class Car extends Base @@ -1164,20 +1155,13 @@ class Car extends Base
1164 $itemArr = []; 1155 $itemArr = [];
1165 $list = Db::name("route")->where($where) 1156 $list = Db::name("route")->where($where)
1166 ->select(); 1157 ->select();
  1158 + foreach ($list as $k=>$v){
  1159 + $list[$k]['specificaddress']=Db::name("specificaddress")->where("route_id",$list[$k]['id'])->select();
  1160 + }
1167 $charArray = []; 1161 $charArray = [];
1168 - $back_data = [];  
1169 if (!empty($list)) { 1162 if (!empty($list)) {
1170 - $count = count($list);  
1171 - $addnum = 500;//因为即时通讯人员状态每次限制查500人;所以得分开查  
1172 - for ($i = 0; $i < $count; $i = $i + $addnum) {  
1173 - if ($count - $i > 0) {  
1174 - $j = $i - 1 > 0 ? $i : 0;  
1175 - $data = array_slice($list, $j, $addnum);  
1176 - }  
1177 - }  
1178 $staff_names = array_column($list, 'start_address'); 1163 $staff_names = array_column($list, 'start_address');
1179 array_multisort($staff_names, SORT_ASC, $list); 1164 array_multisort($staff_names, SORT_ASC, $list);
1180 -  
1181 foreach ($list as $k => $v) { 1165 foreach ($list as $k => $v) {
1182 $char = getFirstChar($v['start_address']); 1166 $char = getFirstChar($v['start_address']);
1183 $nameArray = array(); 1167 $nameArray = array();
@@ -31,8 +31,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -31,8 +31,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
31 {field: 'end_address', title: __('End_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, 31 {field: 'end_address', title: __('End_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
32 {field: 'price', title: __('Price'), operate:'BETWEEN'}, 32 {field: 'price', title: __('Price'), operate:'BETWEEN'},
33 {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 33 {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
34 - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}  
35 - ] 34 + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
  35 + buttons:[
  36 +
  37 + {
  38 + name: 'farm_planting_realityplan',
  39 + text:"具体到达地址",
  40 + title: function (row) {
  41 + return "查看《"+row.name +"》具体到达地址"
  42 + },
  43 + extend:'data-area=["94%","94%"]',
  44 + classname: 'btn btn-xs btn-primary btn-dialog',
  45 + icon: 'fa fa-recipt',
  46 + url: 'specificaddress/index?route_id={id}',
  47 + visible: function (row) {
  48 + return true;
  49 + },
  50 + },
  51 +
  52 + ]
  53 +
  54 + }]
36 ] 55 ]
37 }); 56 });
38 57
  1 +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2 +
  3 + var Controller = {
  4 + index: function () {
  5 + console.log("eeeeeeeeeeeeeeeeeeeee")
  6 + console.log(location)
  7 + console.log("eeeeeeeeeeeeeeeeeeeee")
  8 + // 初始化表格参数配置
  9 + Table.api.init({
  10 + extend: {
  11 + index_url: 'specificaddress/index' + location.search,
  12 + add_url: 'specificaddress/add'+ location.search,
  13 + edit_url: 'specificaddress/edit',
  14 + del_url: 'specificaddress/del',
  15 + multi_url: 'specificaddress/multi',
  16 + import_url: 'specificaddress/import',
  17 + table: 'specificaddress',
  18 + }
  19 + });
  20 +
  21 + var table = $("#table");
  22 +
  23 + // 初始化表格
  24 + table.bootstrapTable({
  25 + url: $.fn.bootstrapTable.defaults.extend.index_url,
  26 + pk: 'id',
  27 + sortName: 'id',
  28 + columns: [
  29 + [
  30 + {checkbox: true},
  31 + {field: 'id', title: __('Id')},
  32 + {field: 'route_id', title: __('Route_id')},
  33 + {field: 'specific_address', title: __('Specific_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  34 + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  35 + ]
  36 + ]
  37 + });
  38 +
  39 + // 为表格绑定事件
  40 + Table.api.bindevent(table);
  41 + },
  42 + add: function () {
  43 +
  44 + Controller.api.bindevent();
  45 + },
  46 + edit: function () {
  47 + Controller.api.bindevent();
  48 + },
  49 + api: {
  50 + bindevent: function () {
  51 + Form.api.bindevent($("form[role=form]"));
  52 + }
  53 + }
  54 + };
  55 + return Controller;
  56 +});