mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-23 18:00:29 +08:00
修改邮费规则字段
This commit is contained in:
parent
4a6cb18292
commit
985d136450
@ -105,17 +105,16 @@ class Order extends Auth
|
||||
];
|
||||
}
|
||||
// 统计订单金额
|
||||
$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'];
|
||||
$order['amount_goods'] = array_sum(array_column($items, 'total_selling'));
|
||||
$order['amount_total'] = $order['amount_goods'] - $order['amount_reduct'];
|
||||
try {
|
||||
// 订单数据写入
|
||||
$this->app->db->name('ShopOrder')->insert($order);
|
||||
$this->app->db->name('ShopOrderItem')->insertAll($items);
|
||||
// 同步商品库存及销量
|
||||
foreach ($codes as $code) GoodsService::instance()->syncStock($code);
|
||||
// 返回前端订单编号
|
||||
// 返回订单数据给接口
|
||||
$order['items'] = $items;
|
||||
$this->success('预购订单创建成功,请补全收货地址', $order);
|
||||
} catch (HttpResponseException $exception) {
|
||||
@ -144,15 +143,18 @@ class Order extends Auth
|
||||
// 订单状态检查
|
||||
$map = ['mid' => $this->mid, 'order_no' => $data['order_no']];
|
||||
$order = $this->app->db->name('ShopOrder')->where($map)->whereIn('status', [1, 2])->find();
|
||||
$tCount = $this->app->db->name('ShopOrderItem')->where($map)->sum('truck_count');
|
||||
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']);
|
||||
$tCode = $this->app->db->name('ShopOrderItem')->where($map)->column('truck_tcode');
|
||||
[$amount, $tCount, $tCode, $remark] = TruckService::instance()->amount($tCode, $addr['province'], $addr['city'], $tCount);
|
||||
// 创建订单发货信息
|
||||
$express = ['template_code' => $tcode, 'template_remark' => $remark, 'template_amount' => $amount];
|
||||
$express['mid'] = $this->mid;
|
||||
$express['status'] = 1;
|
||||
$express = [
|
||||
'mid' => $this->mid, 'status' => 1,
|
||||
'template_code' => $tCode, 'template_count' => $tCount,
|
||||
'template_remark' => $remark, 'template_amount' => $amount,
|
||||
];
|
||||
$express['order_no'] = $data['order_no'];
|
||||
$express['address_code'] = $data['code'];
|
||||
$express['address_name'] = $addr['name'];
|
||||
|
File diff suppressed because one or more lines are too long
@ -19,17 +19,17 @@ class TruckService extends Service
|
||||
* @param string $provName 省份名称
|
||||
* @param string $cityName 城市名称
|
||||
* @param integer $truckCount 邮费基数
|
||||
* @return array
|
||||
* @return array [邮费金额, 计费基数, 模板编号, 计算描述]
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function amount(array $codes, string $provName, string $cityName, int $truckCount = 0): array
|
||||
{
|
||||
if (empty($codes)) return [0, '', '邮费模板编码为空!'];
|
||||
if (empty($codes)) return [0, $truckCount, '', '邮费模板编码为空!'];
|
||||
$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, '', '邮费模板编码无效!'];
|
||||
if (empty($template)) return [0, $truckCount, '', '邮费模板编码无效!'];
|
||||
$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) {
|
||||
@ -42,10 +42,10 @@ class TruckService extends Service
|
||||
[$firstNumber, $firstAmount] = [$rule['firstNumber'] ?: 0, $rule['firstAmount'] ?: 0];
|
||||
[$repeatNumber, $repeatAmount] = [$rule['repeatNumber'] ?: 0, $rule['repeatAmount'] ?: 0];
|
||||
if ($truckCount <= $firstNumber) {
|
||||
return [$firstAmount, $template['code'], "首件计费,不超过{$firstNumber}件"];
|
||||
return [$firstAmount, $truckCount, $template['code'], "首件计费,不超过{$firstNumber}件"];
|
||||
}
|
||||
$amount = $repeatNumber > 0 ? $repeatAmount * ceil(($truckCount - $firstNumber) / $repeatNumber) : 0;
|
||||
return [$firstAmount + $amount, $template['code'], "续件计费,超出{$firstNumber}件续件{$amount}元"];
|
||||
return [$firstAmount + $amount, $truckCount, $template['code'], "续件计费,超出{$firstNumber}件续件{$amount}元"];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user