修改订单发货

This commit is contained in:
Anyon 2020-09-18 13:09:49 +08:00
parent 9e1b5dbd14
commit 111223633a
4 changed files with 214 additions and 159 deletions

View File

@ -42,9 +42,7 @@ class Order extends Auth
}
$query = $this->_query('ShopOrder')->equal('status,order_no');
$result = $query->where($map)->order('id desc')->page(true, false, false, 20);
if (count($result['list']) > 0) {
OrderService::instance()->buildItemData($result['list']);
}
if (count($result['list']) > 0) OrderService::instance()->buildItemData($result['list']);
$this->success('获取订单数据成功!', $result);
}
@ -97,6 +95,7 @@ class Order extends Auth
'goods_spec' => $goodsItem['goods_spec'],
// 数量处理
'stock_sales' => $count,
'truck_tcode' => $goodsInfo['truck_tcode'],
'truck_count' => $goodsItem['number_express'] * $count,
// 费用字段
'price_market' => $goodsItem['price_market'],
@ -106,8 +105,9 @@ class Order extends Auth
];
}
// 统计订单金额
$order['amount_reduct'] = OrderService::instance()->getReduct();
$order['truck_count'] = array_sum(array_column($items, 'truck_count'));
$order['amount_goods'] = array_sum(array_column($items, 'total_selling'));
$order['amount_reduct'] = OrderService::instance()->getReduct();
$order['amount_total'] = $order['amount_goods'];
try {
// 订单数据写入
@ -134,33 +134,39 @@ class Order extends Auth
public function perfect()
{
$data = $this->_vali([
'order_no.require' => '订单单号不能为空!',
'address_code.require' => '收货地址不能为空!',
'code.require' => '地址编号不能为空!',
'order_no.require' => '订单单号不能为空!',
]);
// 收货地址
$map = ['mid' => $this->mid, 'code' => $data['address_code'], 'deleted' => 0];
$address = $this->app->db->name('DataMemberAddress')->where($map)->find();
if (empty($address)) $this->error('会员收货地址异常!');
// 订单检查
// 会员收货地址
$map = ['mid' => $this->mid, 'code' => $data['code'], 'deleted' => 0];
$addr = $this->app->db->name('DataMemberAddress')->where($map)->find();
if (empty($addr)) $this->error('会员收货地址异常!');
// 订单状态检查
$map = ['mid' => $this->mid, 'order_no' => $data['order_no']];
$order = $this->app->db->name('ShopOrder')->where($map)->whereIn('status', [1, 2])->find();
if (empty($order)) $this->error('订单状态异常,请重新下单!');
// 组装数据
$update = ['status' => 2];
$update['order_no'] = $data['order_no'];
$update['truck_code'] = $data['address_code'];
$update['truck_name'] = $address['name'];
$update['truck_phone'] = $address['phone'];
$update['truck_province'] = $address['province'];
$update['truck_city'] = $address['city'];
$update['truck_area'] = $address['area'];
$update['truck_address'] = $address['address'];
$update['truck_datetime'] = date('Y-m-d H:i:s');
// 运费计算 @todo 计算快递费用
// $result = TruckService::instance()->amount($address['province'], $order['express_rule_number'], $order['price_discount']);
// $update['price_express'] = $result['amount'];
// $update['price_total'] = $order['price_discount'] + $result['amount'];
// $update['express_rule_content'] = $result['content'];
if (empty($order)) $this->error('不能修改收货地址哦!');
// 根据地址计算运费
$map = ['status' => 1, 'deleted' => 0, 'order_no' => $data['order_no']];
$tcodes = $this->app->db->name('ShopOrderItem')->where($map)->column('truck_tcode');
[$amount, $tcode, $remark] = TruckService::instance()->amount($tcodes, $addr['province'], $addr['city'], $order['truck_count']);
// 创建订单发货信息
$express = ['template_code' => $tcode, 'template_remark' => $remark, 'template_amount' => $amount];
$express['mid'] = $this->mid;
$express['status'] = 1;
$express['order_no'] = $data['order_no'];
$express['address_code'] = $data['code'];
$express['address_name'] = $addr['name'];
$express['address_phone'] = $addr['phone'];
$express['address_province'] = $addr['province'];
$express['address_city'] = $addr['city'];
$express['address_area'] = $addr['area'];
$express['address_content'] = $addr['address'];
$express['address_datetime'] = date('Y-m-d H:i:s');
data_save('ShopOrderSend', $express, 'order_no');
// 更新订单状态,刷新订单金额
$map = ['mid' => $this->mid, 'order_no' => $data['order_no']];
$update = ['status' => 2, 'amount_express' => $express['template_amount']];
$update['amount_total'] = $order['amount_goods'] + $amount - $order['amount_reduct'] - $order['amount_discount'];
if ($this->app->db->name('ShopOrder')->where($map)->update($update) !== false) {
$this->success('订单确认成功!', $this->_getPaymentParams($order['order_no'], $order['amount_total']));
} else {
@ -182,7 +188,7 @@ class Order extends Auth
if ($order['status'] != 2) $this->error('该订单不能发起支付哦!');
if ($order['payment_status']) $this->error('订单已经支付,不需要再次支付哦!');
try {
$params = $this->_getPaymentParams($order['order_no'], $order['amount_total'] - $order['amount_reduct']);
$params = $this->_getPaymentParams($order['order_no'], $order['amount_total']);
$this->success('获取支付参数成功!', $params);
} catch (HttpResponseException $exception) {
throw $exception;

File diff suppressed because one or more lines are too long

View File

@ -15,11 +15,37 @@ class TruckService extends Service
{
/**
* 模拟计算快递费用
* @return string
* @param array $codes 模板编号
* @param string $provName 省份名称
* @param string $cityName 城市名称
* @param integer $truckCount 邮费基数
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function amount()
public function amount(array $codes, string $provName, string $cityName, int $truckCount = 0): array
{
return '0.00';
if (empty($codes)) return [0, '', '邮费模板编码为空!'];
$map = [['status', '=', 1], ['deleted', '=', 0], ['code', 'in', $codes]];
$template = $this->app->db->name('ShopTruckTemplate')->where($map)->order('sort desc,id desc')->find();
if (empty($template)) return [0, '', '邮费模板编码无效!'];
$rule = json_decode($template['normal'], true) ?: [];
foreach (json_decode($template['content'], true) ?: [] as $item) {
if (isset($item['city']) && is_array($item['city'])) foreach ($item['city'] as $city) {
if ($city['name'] === $provName && in_array($cityName, $city['subs'])) {
$rule = $item['rule'];
break 2;
}
}
}
[$firstNumber, $firstAmount] = [$rule['firstNumber'] ?: 0, $rule['firstAmount'] ?: 0];
[$repeatNumber, $repeatAmount] = [$rule['repeatNumber'] ?: 0, $rule['repeatAmount'] ?: 0];
if ($truckCount <= $firstNumber) {
return [$firstAmount, $template['code'], "首件计费,不超过{$firstNumber}"];
}
$amount = $repeatNumber > 0 ? $repeatAmount * ceil(($truckCount - $firstNumber) / $repeatNumber) : 0;
return [$firstAmount + $amount, $template['code'], "续件计费,超出{$firstNumber}件续件{$amount}"];
}
/**
@ -37,13 +63,9 @@ class TruckService extends Service
// 排序子集为空的省份和城市
foreach ($items as $ik => $item) {
foreach ($item['subs'] as $ck => $city) {
if (isset($city['subs']) && empty($city['subs'])) {
unset($items[$ik]['subs'][$ck]);
}
}
if (isset($item['subs']) && empty($item['subs'])) {
unset($items[$ik]);
if (isset($city['subs']) && empty($city['subs'])) unset($items[$ik]['subs'][$ck]);
}
if (isset($item['subs']) && empty($item['subs'])) unset($items[$ik]);
}
return $items;
}

View File

@ -6,7 +6,7 @@
<div class="layui-card-body padding-40">
<div class="layui-form-item relative block">
<span class="color-green font-w7 label-required-prev">商品标签</span>
<span class="color-desc margin-left-5">Label Name</span>
<span class="color-desc margin-left-5">Mark Name</span>
<div class="tags-container layui-textarea">
{foreach $marks as $mark}{if isset($vo.mark) && is_array($vo.mark) && in_array($mark, $vo.mark)}
<label class="think-checkbox notselect"><input checked type="checkbox" name="mark[]" value="{$mark}" lay-ignore> {$mark}</label>
@ -30,7 +30,7 @@
<span class="color-green font-w7 label-required-prev">运费模板</span>
<span class="color-desc margin-left-5">Truck Template</span>
<select class="layui-select" name="truck_tcode" lay-search>
<option value="">--- ---</option>
<option value="">--- ---</option>
{foreach $vo.truck_items as $truck}{if isset($vo.truck_tcode) and $vo.truck_tcode eq $truck.code}
<option selected value="{$truck.code}">{$truck.code} - {$truck.name|default=''}</option>
{else}