作者 何书鹏

配送

... ... @@ -67,7 +67,7 @@ class Litestoreorder extends Backend
->select();
foreach ($list as $row) {
$row->visible(['id','order_no','total_price','pay_price','pay_time','express_price','freight_time','receipt_time','order_status','updatetime']);
$row->visible(['id','order_no','total_price','pay_price','pay_status','pay_time','express_price','freight_status','freight_time','receipt_time','order_status','updatetime']);
$row->visible(['address']);
$row->getRelation('address')->visible(['name']);
$row->visible(['rider']);
... ... @@ -107,4 +107,27 @@ class Litestoreorder extends Backend
$this->view->assign('vo', $row);
return $this->view->fetch();
}
// 快捷匹配骑手
public function render(){
if($this->request->isPost())
{
$id = input('get.ids');
$row = $this->model->get($id);
$row['pay_status'] == '10' && $this->error('订单未支付,禁止分配骑手');
$row['freight_status'] = "20";
$row['freight_time'] = time();
$row['rider_user_id'] = input('post.virtual_name');
$row->save();
$param = [
'order_id' => $row->id,
'user_id' => input('post.virtual_name'),
'address_id' => $row['address']['id'],
'price' => $row->express_price,
];
RiderOrder::create($param);
$this->success();
}
return $this->view->fetch();
}
}
... ...
... ... @@ -134,7 +134,7 @@
</fieldset>
{in name="$vo.freight_status" value="10"}
{if condition="$vo.pay_status == '20' and $vo.freight_status == '10' and $vo.order_status == '10'"}
<fieldset>
<legend><h4>发货信息</h4></legend>
<div class="form-group">
... ... @@ -158,6 +158,6 @@
<button type="button" id="send" data-type="send" class="btn btn-success btn-embossed">确认发货</button>
</div>
</div>
{/in}
{/if}
</form>
\ No newline at end of file
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('选择骑手')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-virtual_name" data-rule="required" data-source="user/user/index" data-field="nickname" data-params='{"custom[rider]":2}' class="form-control selectpage form-control" name="virtual_name" type="text" value="">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
... ... @@ -7,6 +7,7 @@ namespace app\api\controller;
use addons\epay\library\Service;
use app\api\model\GoodsComment;
use app\api\model\GoodsSpec;
use app\api\model\RiderOrder;
use app\api\model\SpecValue;
use app\api\model\Third;
use app\api\model\UserAddress;
... ... @@ -609,13 +610,24 @@ class Order extends Api
if (!is_numeric($order_id)) $this->error('参数不合法');
$model = new \app\api\model\Order();
$order = $model::get($order_id);
if (!$order) $this->error('订单不存在');
if ($order['receipt_status'] == 20) $this->error('订单已收货,请勿重复提交');
if ($order['rider_status'] == 10) $this->error('骑手未送达,请稍后提交');
$order->receipt_status = '20';
$order->receipt_time = time();
$order->isUpdate()->save();
$order = $model->get($order_id);
empty($order) && $this->error('订单不存在');
$order['receipt_status'] == '20' && $this->error('订单已收货,请勿重复提交');
$rider_order = RiderOrder::where('order_id',$order_id)->find();
empty($rider_order) && $this->error('骑手订单不存在');
// 修改订单信息
$order->rider_status = '20'; //送达状态:已送达
$order->receipt_status = '20'; //收货状态:已收货
$order->receipt_time = time(); //收货时间
$order->save();
// 修改配送单信息
$rider_order->status = '2'; //已送达
$rider_order->sendtime = time(); //送达时间
$rider_order->save();
// 发放订单运费
\app\common\model\User::money($order->express_price,$order->rider_user_id,'订单运费');
$this->success('收货成功');
}
... ...
... ... @@ -320,30 +320,26 @@ class Rider extends Api
public function orderService()
{
$id = $this->request->post('id');
$rider_order = RiderOrder::get($id);
empty($rider_order) && $this->error('骑手订单不存在');
$ordermodel = new \app\api\model\Order();
$order = $ordermodel
->where('id',$rider_order['order_id'])
->find();
$order = $ordermodel->get($rider_order['order_id']);
empty($order) && $this->error('订单不存在');
if ($order['rider_status'] == 20) $this->error('该订单已送达');
$order->rider_status = '20';
// 修改订单信息
$order->rider_status = '20'; //送达状态:已送达
$order->receipt_status = '20'; //收货状态:已收货
$order->receipt_time = time(); //收货时间
$order->save();
$rider_order->status = '2';
$rider_order->sendtime = time();
// 修改配送单信息
$rider_order->status = '2'; //已送达
$rider_order->sendtime = time(); //送达时间
$rider_order->save();
$user = $this->auth->getUser();
$data = [
'user_id' => $this->auth->id,
'money' => $order->express_price,
'before' => $user->money,
'after' => $order->express_price+$user->money,
'memo' => '订单运费',
];
$user->setInc('money',$order->express_price);
$moneymodel = new UserMoneyLog();
$moneymodel->isUpdate(false)->save($data);
// 发放订单运费
User::money($order->express_price,$order->rider_user_id,'订单运费');
$this->success('送达成功',$order);
}
... ...
... ... @@ -39,6 +39,32 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
formatter: Controller.api.status_formatter},
{field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'address.name', title: __('Address.name'),operate: false},
{
field: 'rider.nickname',
title: __('选择配送骑手'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'detail',
text: __('选择配送骑手'),
title: __('选择配送骑手'),
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-fighter-jet',
url: 'litestore/litestoreorder/render?ids={ids}',
callback: function (data) {
Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
},
visible: function (row) {
//返回true时按钮显示,返回false隐藏
if(row.pay_status == '20' && row.freight_status == '10' && row.order_status == '10'){
return true;
}
}
}
],
formatter: Table.api.formatter.buttons
},
{field: 'rider.nickname', title: __('骑手')},
{field: 'operate', title: __('Operate'), table: table, buttons: [
{name: 'send', text: __('view'), icon: 'fa fa-eye', classname: 'btn btn-xs btn-warning btn-dialog chakan', url: 'litestore/litestoreorder/detail'},
... ... @@ -90,6 +116,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
});
Controller.api.bindevent();
},
render: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
... ...