作者 郭文星

13

... ... @@ -22,14 +22,15 @@ class Specificaddress extends Backend
* @var \app\admin\model\Specificaddress
*/
protected $model = null;
protected $routemodel = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Specificaddress;
$this->routemodel=new \app\admin\model\Route();
$route_id = $this->request->param("route_id");
$this->view->assign("route_id", $route_id);
}
... ... @@ -60,9 +61,15 @@ class Specificaddress extends Backend
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->with(['route'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
$row->visible(['id','specific_address','route_id']);
$row->visible(['route']);
$row->getRelation('route')->visible(['name']);
}
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
... ... @@ -74,7 +81,11 @@ class Specificaddress extends Backend
*/
public function add()
{
if (false === $this->request->isPost()) {
$route_id = $this->request->param("route_id");
$route=$this->routemodel->find($route_id);
$this->view->assign("route", $route);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
... ... @@ -104,7 +115,57 @@ class Specificaddress extends Backend
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
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) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
$route_id = $this->request->param("route_id");
$route=$this->routemodel->find($route_id);
$this->view->assign("route", $route);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$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()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
}
... ...
... ... @@ -2,6 +2,7 @@
return [
'Id' => 'ID',
'Route_id' => '线路',
'Route_id' => '线路编号',
'Route.name' => '线路',
'Specific_address' => '详细地址'
];
... ...
... ... @@ -27,13 +27,16 @@ class Specificaddress extends Model
protected $append = [
];
public function route()
{
return $this->belongsTo('Route', 'route_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
... ...
... ... @@ -8,7 +8,11 @@
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Specific_address')}:</label>
{if $route.type==1}
<label class="control-label col-xs-12 col-sm-2">目的地:</label>
{else}
<label class="control-label col-xs-12 col-sm-2">上车点:</label>
{/if}
<div class="col-xs-12 col-sm-8">
<input id="c-specific_address" class="form-control" name="row[specific_address]" type="text">
</div>
... ...
... ... @@ -7,7 +7,11 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Specific_address')}:</label>
{if $route.type==1}
<label class="control-label col-xs-12 col-sm-2">目的地:</label>
{else}
<label class="control-label col-xs-12 col-sm-2">上车点:</label>
{/if}
<div class="col-xs-12 col-sm-8">
<input id="c-specific_address" class="form-control" name="row[specific_address]" type="text" value="{$row.specific_address|htmlentities}">
</div>
... ...
... ... @@ -90,6 +90,7 @@ class Car extends Base
$phone = $this->request->param("phone");//联系手机号码
$user_name = $this->request->param("user_name");//联系人
$position = $this->request->param("position");//上车地址
$specificaddress_id = $this->request->param("specificaddress_id");//上车地址
$seat_no = $this->request->param("seat_no");//座位
$lat = $this->request->param("lat");//经度
$lng = $this->request->param("lng");//维度
... ... @@ -150,6 +151,7 @@ class Car extends Base
"car_id"=>$car_id,
"order_review_id"=>$order_review_id,
"route_id"=>$route_id,
"specificaddress_id"=>$specificaddress_id,
"user_id"=>$this->auth->id,
"phone"=>$phone,
"user_name"=>$user_name,
... ... @@ -961,6 +963,7 @@ class Car extends Base
$route_id = $this->request->param("route_id");//线路
$position = $this->request->param("position");//上车地址
$lat = $this->request->param("lat");//经度
$specificaddress_id = $this->request->param("specificaddress_id");//区域id
$lng = $this->request->param("lng");//维度
$number = $this->request->param("number");//乘车人数
$carmodel_id = $this->request->param("carmodel_id");//乘车人数
... ... @@ -978,6 +981,7 @@ class Car extends Base
"price"=>$price,
"driver_id"=>$driver['id'],
"is_qrcode"=>$is_qrcode,
"specificaddress_id"=>$specificaddress_id,
"reservation_time"=>$reservation_time,
"is_pay"=>"2",//未支付
"route_id"=>$route_id,
... ... @@ -1025,6 +1029,7 @@ class Car extends Base
$carmodel_id = $this->request->param("carmodel_id");//乘车人数
$reservation_time = $this->request->param("reservation_time");//预约时间
$phone = $this->request->param("phone");//联系电话
$specificaddress_id = $this->request->param("specificaddress_id");//区域id
$intended_driver_id = $this->request->param("intended_driver_id");//意向司机
$remarks = $this->request->param("remarks");//备注
$driver=Db::name("driver")->where("id",$intended_driver_id)->find();
... ... @@ -1036,6 +1041,7 @@ class Car extends Base
"order_no"=>getOrderSn(),
"price"=>$price,
"is_qrcode"=>$is_qrcode,
"specificaddress_id"=>$specificaddress_id,
"reservation_time"=>$reservation_time,
"is_pay"=>"1",//未支付
"route_id"=>$route_id,
... ... @@ -1144,10 +1150,8 @@ class Car extends Base
$indexList = array_keys($charArray);
$itemArr = array_values($charArray);
}
array_unshift($indexList, "*");
$this->success("数据获取成功", ["indexList" => $indexList, "itemArr" => $itemArr]);
}
... ... @@ -1208,14 +1212,15 @@ class Car extends Base
"order_no"=>getOrderSn(),
];
$res=Db::name("order")->where("id",$order['id'])->update($data);
$userinfo = Db::name('user')
$order=Db::name("order")->where("order_no",$order_no)->find();
$userinfo = Db::name('user')
->where(['id' => $this->auth->id])
->field('id,wx_xcx_openid')
->find();
$notifyURI = $this->doman . '/addons/epay/api/OrderPayNtf';
$params = [
'amount' => $data['price'],
'orderid' => $data['order_no'],
'amount' => $order['price'],
'orderid' => $order['order_no'],
'type' => 'wechat',
'notifyurl' => $notifyURI,
'method' => 'miniapp',
... ...
... ... @@ -29,6 +29,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'route_id', title: __('Route_id')},
{field: 'route.name', title: __('Route.name')},
{field: 'specific_address', title: __('Specific_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
... ...