备货单&审批流程
This commit is contained in:
@@ -2,9 +2,15 @@
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\StockOrderAccounts;
|
||||
use app\common\model\StockOrderItemOptions;
|
||||
use app\common\model\StockOrderItems;
|
||||
use app\common\validate\StockOrdersValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\StockOrders;
|
||||
use support\Request;
|
||||
use app\common\model\User;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
class StockOrdersService
|
||||
{
|
||||
@@ -28,4 +34,100 @@ class StockOrdersService
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
public function serviceStore(Request $request, array $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
|
||||
|
||||
// 金额 // 表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'], '改装费');
|
||||
|
||||
// 改装
|
||||
foreach ($data['veh_list']['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);
|
||||
}
|
||||
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
{
|
||||
$userId = $request->user->uid;
|
||||
|
||||
$data['order_no'] = generateStockNo();
|
||||
$data['biz_date'] = strtotime($data['biz_date']);
|
||||
$data['eta_ship_date'] = strtotime($data['eta_ship_date']);
|
||||
$data['latest_arrival_date'] = strtotime($data['latest_arrival_date']);
|
||||
$data['salesperson_id'] = $userId;
|
||||
$data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? '';
|
||||
|
||||
var_dump($data);
|
||||
|
||||
throw new BusinessException('测试异常');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// protected function afterServiceStore($res)
|
||||
// {
|
||||
|
||||
// return $res;
|
||||
// }
|
||||
|
||||
|
||||
public function serviceShow(Request $request)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'show');
|
||||
$item = $this->logicShow($config);
|
||||
return $this->postProcess('Show', $item);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user