增加关联关系
This commit is contained in:
@@ -11,6 +11,7 @@ use app\common\model\StockOrders;
|
||||
use support\Request;
|
||||
use app\common\model\User;
|
||||
use support\exception\BusinessException;
|
||||
use support\Db;
|
||||
|
||||
class StockOrdersService
|
||||
{
|
||||
@@ -48,6 +49,12 @@ class StockOrdersService
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
|
||||
$config['with'][] = 'items';
|
||||
$config['with'][] = 'items.options';
|
||||
$config['with'][] = 'items.moneyValues';
|
||||
$config['with'][] = 'accounts';
|
||||
$config['with'][] = 'moneyValues';
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
@@ -65,38 +72,47 @@ class StockOrdersService
|
||||
|
||||
public function serviceStore(Request $request, array $data = [])
|
||||
{
|
||||
$data = $this->preProcess('Store', $data, $request);
|
||||
$dl = $this->getDataLimitFromRequest($request);
|
||||
$created = $this->logicCreate($data, $dl); // 表1
|
||||
// 关联表较多,增加事务处理
|
||||
return Db::transaction(function () use ($request, $data) {
|
||||
$data = $this->preProcess('Store', $data, $request);
|
||||
$dl = $this->getDataLimitFromRequest($request);
|
||||
$created = $this->logicCreate($data, $dl); // 表1
|
||||
|
||||
// 车辆
|
||||
foreach ($data['veh_list'] as $veh) {
|
||||
$veh['order_id'] = $created->id;
|
||||
$item = StockOrderItems::create($veh); // 表2
|
||||
// 车辆
|
||||
foreach ($data['veh_list'] as $veh) {
|
||||
$veh['order_id'] = $created->id;
|
||||
$item = StockOrderItems::create($veh); // 表2
|
||||
|
||||
// 金额 // 表3
|
||||
$item->addMoney('official_price', $veh['currency'], $veh['amount'], $veh['rate'], '官方指导价');
|
||||
$item->addMoney('discount_price', $veh['currency'], $veh['amount'], $veh['rate'], '优惠价');
|
||||
$item->addMoney('unit_price', $veh['currency'], $veh['amount'], $veh['rate'], '单价');
|
||||
$item->addMoney('total_price', $veh['currency'], $veh['amount'], $veh['rate'], '总价');
|
||||
$item->addMoney('handling_fee', $veh['currency'], $veh['amount'], $veh['rate'], '手续费');
|
||||
$item->addMoney('fob_transport_fee', $veh['currency'], $veh['amount'], $veh['rate'], 'FOB运输费');
|
||||
$item->addMoney('port_misc_fee', $veh['currency'], $veh['amount'], $veh['rate'], '港杂');
|
||||
$item->addMoney('retrofit_fee', $veh['currency'], $veh['amount'], $veh['rate'], '改装费');
|
||||
// 金额 // 表3
|
||||
$item->addMoney('official_price', $veh['official_price']['currency'], $veh['official_price']['amount'], $veh['official_price']['rate'], '官方指导价');
|
||||
$item->addMoney('discount_price', $veh['discount_price']['currency'], $veh['discount_price']['amount'], $veh['discount_price']['rate'], '优惠价');
|
||||
$item->addMoney('unit_price', $veh['unit_price']['currency'], $veh['unit_price']['amount'], $veh['unit_price']['rate'], '单价');
|
||||
$item->addMoney('total_price', $veh['total_price']['currency'], $veh['total_price']['amount'], $veh['total_price']['rate'], '总价');
|
||||
$item->addMoney('handling_fee', $veh['handling_fee']['currency'], $veh['handling_fee']['amount'], $veh['handling_fee']['rate'], '手续费');
|
||||
$item->addMoney('fob_transport_fee', $veh['fob_transport_fee']['currency'], $veh['fob_transport_fee']['amount'], $veh['fob_transport_fee']['rate'], 'FOB运输费');
|
||||
$item->addMoney('port_misc_fee', $veh['port_misc_fee']['currency'], $veh['port_misc_fee']['amount'], $veh['port_misc_fee']['rate'], '港杂');
|
||||
$item->addMoney('retrofit_fee', $veh['retrofit_fee']['currency'], $veh['retrofit_fee']['amount'], $veh['retrofit_fee']['rate'], '改装费');
|
||||
|
||||
// 改装
|
||||
foreach ($data['veh_list']['modify_list'] as $modify) {
|
||||
$modify['order_item_id'] = $item->id;
|
||||
StockOrderItemOptions::create($modify); // 表4
|
||||
// 改装
|
||||
if (count($veh['modify_list']) > 0) {
|
||||
foreach ($veh['modify_list'] as $modify) {
|
||||
$modify['order_item_id'] = $item->id;
|
||||
StockOrderItemOptions::create($modify); // 表4
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 账户
|
||||
foreach ($data['account_list'] as $account) {
|
||||
$account['order_id'] = $created->id;
|
||||
StockOrderAccounts::create($account); // 表5
|
||||
}
|
||||
return $this->postProcess('Store', $created);
|
||||
// 账户
|
||||
if (count($data['account_list']) > 0) {
|
||||
foreach ($data['account_list'] as $account) {
|
||||
$account['order_id'] = $created->id;
|
||||
$account['remit_date'] = strtotime($account['remit_date']);
|
||||
StockOrderAccounts::create($account); // 表5
|
||||
}
|
||||
}
|
||||
|
||||
return $this->postProcess('Store', $created);
|
||||
});
|
||||
}
|
||||
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
@@ -110,10 +126,6 @@ class StockOrdersService
|
||||
$data['salesperson_id'] = $userId;
|
||||
$data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? '';
|
||||
|
||||
var_dump($data);
|
||||
|
||||
throw new BusinessException('测试异常');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user