任务完成
This commit is contained in:
parent
2e9bd0d804
commit
42be630a28
|
|
@ -5,6 +5,7 @@ namespace app\admin\controller\orders;
|
|||
use app\admin\model\Order;
|
||||
use app\admin\model\OrderDispatch;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\Logic\OrderLogic;
|
||||
use think\Db;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
|
|
@ -195,7 +196,14 @@ class Dispatch2 extends Backend
|
|||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$params = $this->request->post('row/a');
|
||||
|
||||
if(isset($params['action']) && $params['action'] == 'finish'){
|
||||
|
||||
return $this->finish($ids);
|
||||
}
|
||||
|
||||
if (empty($params)) {
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
|
|
@ -221,6 +229,80 @@ class Dispatch2 extends Backend
|
|||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param $ids
|
||||
* @return string
|
||||
* @throws DbException
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function finish($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'));
|
||||
}
|
||||
|
||||
$order = Order::where('id',$row->id)->find();
|
||||
|
||||
if(empty($order)){
|
||||
$this->error(__('未找到关联订单'));
|
||||
}
|
||||
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->view->assign('row', $row);
|
||||
$this->view->assign('order', $order);
|
||||
$this->view->assign('action','finish');
|
||||
return $this->view->fetch('edit');
|
||||
}
|
||||
|
||||
|
||||
$params = $this->request->post('row/a');
|
||||
if (empty($params)) {
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
|
||||
$params = $this->preExcludeFields($params);
|
||||
|
||||
if(!in_array($row->status, $this->model->btnActiveStatusList('btn_finished'))){
|
||||
$this->error('任务状态变更,请刷新后操作');
|
||||
}
|
||||
|
||||
if($order->status != Order::STATUS_DISPATCHED){
|
||||
$this->error('订单状态已变更,请刷新后操作');
|
||||
}
|
||||
|
||||
$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);
|
||||
$OrderLogic = new OrderLogic();
|
||||
$OrderLogic -> dispachFinishAfter($row,['role'=>1,'auth'=>$this->auth]);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if (false === $result) {
|
||||
$this->error(__('No rows were updated'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消派单
|
||||
*
|
||||
|
|
@ -327,7 +409,6 @@ class Dispatch2 extends Backend
|
|||
$item->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]);
|
||||
//回退订单状态
|
||||
$order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]);
|
||||
|
||||
$params['order'] = $order;
|
||||
$params['role'] = 1;
|
||||
$params['auth'] = $this->auth;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,133 @@
|
|||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
|
||||
|
||||
{notempty name ='action'}
|
||||
|
||||
<input name="row[action]" type="hidden" value="{$action|htmlentities}">
|
||||
|
||||
<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-order_no" readonly data-field="order_no" type="text" value="{$order.order_no|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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-item_title" readonly type="text" value="{$order.item_title|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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-customer" readonly type="text" value="{$order.customer|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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-tel" readonly type="text" value="{$order.tel|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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-address" readonly type="text" value="{$order.address|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('当前师傅')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<input readonly type="text" value="{$row.worker_name|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('师傅电话')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<input readonly type="text" value="{$row.worker_tel|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('当前进度')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<input readonly type="text" value="{$row.status_text|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('已收款(¥)')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<input readonly type="text" value="{$order.online_amount|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{if $row['is_receipt'] }
|
||||
<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-total" data-rule="required" class="form-control" name="row[total]" type="number" min="0" value="{$row.total|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="c-image" class="control-label col-xs-12 col-sm-2">{:__('收款凭据')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<div class="input-group">
|
||||
<input id="c-image" class="form-control" size="35" name="row[image]" type="text" value="">
|
||||
<div class="input-group-addon no-border no-padding">
|
||||
<span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
|
||||
<span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
|
||||
</div>
|
||||
<span class="msg-box n-right"></span>
|
||||
</div>
|
||||
<ul class="row list-inline faupload-preview" id="p-image"></ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('完成图片')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<div class="input-group">
|
||||
<input id="c-images" class="form-control" size="50" name="row[images]" type="text">
|
||||
<div class="input-group-addon no-border no-padding">
|
||||
<span><button type="button" id="faupload-images" class="btn btn-danger faupload" data-input-id="c-images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="true" data-preview-id="p-images"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
|
||||
<span><button type="button" id="fachoose-images" class="btn btn-primary fachoose" data-input-id="c-images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
|
||||
</div>
|
||||
<span class="msg-box n-right" for="c-images"></span>
|
||||
</div>
|
||||
<ul class="row list-inline faupload-preview" id="p-images"></ul>
|
||||
</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-primary btn-embossed disabled">{:__('确认完成任务')}</button>
|
||||
<span class="warning">请确认无误后再操作</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{else /}
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
|
|
@ -35,21 +162,26 @@
|
|||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
|
||||
|
||||
<div class="radio">
|
||||
{foreach name="statusList" item="vo"}
|
||||
<label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label>
|
||||
{/foreach}
|
||||
{foreach name="statusList" item="vo"}
|
||||
<label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label>
|
||||
{/foreach}
|
||||
</div>
|
||||
|
||||
</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-primary btn-embossed disabled">{:__('OK')}</button>
|
||||
</div>
|
||||
</div>
|
||||
{notempty}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
|
|
|
|||
62
application/common/Logic/OrderLogic.php
Normal file
62
application/common/Logic/OrderLogic.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\Logic;
|
||||
|
||||
use app\admin\model\Order;
|
||||
use app\admin\model\OrderDispatch;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Exception;
|
||||
use think\exception\DbException;
|
||||
use think\Hook;
|
||||
|
||||
class OrderLogic
|
||||
{
|
||||
|
||||
private $OrderModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->OrderModel = new Order();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 任务完成以后,修改订单
|
||||
* $roleInfo = ['role'=>1,'auth'=>$userInfo,'remark'='']
|
||||
*
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispachFinishAfter(OrderDispatch $orderDispatch,$roleInfo=[]): void
|
||||
{
|
||||
|
||||
$order = $this->OrderModel->where('id',$orderDispatch->order_id)->find();
|
||||
if(!$order->status != Order::STATUS_DISPATCHED){
|
||||
throw new Exception('订单状态不允许当前操作');
|
||||
}
|
||||
|
||||
$orderUpdate = [
|
||||
'status' => Order::STATUS_CHECKING
|
||||
];
|
||||
if($orderDispatch->is_receipt == 1){ //要收款,计算确认尾款
|
||||
$offline_amount = $orderDispatch->total;
|
||||
$total = bcadd($order->online_amount,$offline_amount,2);
|
||||
$orderUpdate['offline_amount'] = $offline_amount;
|
||||
$orderUpdate['total'] = $total;
|
||||
}
|
||||
$order->allowField(true)->save($orderUpdate);
|
||||
|
||||
$params['role'] = $roleInfo['role'];
|
||||
$params['auth'] = $roleInfo['auth'];
|
||||
$params['order']= $order;
|
||||
$params['remark'] = $roleInfo['remark'] ?? $orderDispatch->remark;
|
||||
|
||||
Hook::listen('order_change', $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($,
|
|||
icon: 'fa fa-pencil',
|
||||
//title: __('Edit'),
|
||||
extend: 'data-toggle="tooltip" data-container="body"',
|
||||
classname: 'btn btn-xs btn-success btn-editone',
|
||||
classname: 'btn btn-xs btn-info btn-editone',
|
||||
visible:function(row){
|
||||
if(row.btn_edit){
|
||||
return true;
|
||||
|
|
@ -93,6 +93,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($,
|
|||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
name: 'finish',
|
||||
text:"完成",
|
||||
title:"完成",
|
||||
icon: 'fa fa-check',
|
||||
url: 'orders/dispatch2/finish',
|
||||
extend: 'data-toggle="tooltip" data-container="body"',
|
||||
classname: 'btn btn-xs btn-success btn-dialog',
|
||||
visible:function(row){
|
||||
if(row.btn_finished){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
],
|
||||
|
||||
}
|
||||
|
|
@ -165,6 +181,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($,
|
|||
edit: function () {
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
finish: function () {
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
api: {
|
||||
bindevent: function () {
|
||||
Form.api.bindevent($("form[role=form]"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user