备货单完善
This commit is contained in:
@@ -43,21 +43,8 @@ class StockOrderItems extends Model
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id', 'order_id', 'product_code', 'sku_id', 'sku_snapshot',
|
||||
'model_snapshot', 'quantity', 'color_interior_coide', 'color_interior_snapshot',
|
||||
'color_exterior_coide', 'color_exterior_snapshot', 'remark',
|
||||
// 'unit_price',
|
||||
// 'handling_fee',
|
||||
// 'fob_transport_fee',
|
||||
// 'port_misc_fee',
|
||||
// 'retrofit_fee',
|
||||
// 'total_price',
|
||||
'created_at', 'updated_at',
|
||||
// 'unit_price_value_id',
|
||||
// 'handling_fee_value_id',
|
||||
// 'fob_transport_fee_value_id',
|
||||
// 'port_misc_fee_value_id',
|
||||
// 'retrofit_fee_value_id',
|
||||
// 'total_price_value_id'
|
||||
'model_snapshot', 'quantity', 'color_interior_code', 'color_interior_snapshot',
|
||||
'color_exterior_code', 'color_exterior_snapshot', 'remark', 'vin', 'created_at', 'updated_at'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
use app\common\traits\HasMoneyJournal;
|
||||
|
||||
class StockOrders extends Model
|
||||
{
|
||||
@@ -58,6 +59,13 @@ class StockOrders extends Model
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
use HasMoneyJournal;
|
||||
// 实现抽象方法
|
||||
protected static function moneyObjectScene(): string
|
||||
{
|
||||
return 'stock_orders';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联订单项
|
||||
*/
|
||||
|
||||
@@ -45,6 +45,22 @@ class StockOrdersService
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 业务id
|
||||
if (isset($p['salesperson_id']) && $p['salesperson_id']) {
|
||||
$config['where']['salesperson_id'] = $p['salesperson_id'];
|
||||
}
|
||||
// 初、终版
|
||||
$config['where']['is_final'] = $p['is_final'] ?? 0;
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['pi_no', 'order_no', 'customer_snapshot'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'show':
|
||||
@@ -79,6 +95,10 @@ class StockOrdersService
|
||||
$created = $this->logicCreate($data, $dl); // 表1
|
||||
|
||||
// 车辆
|
||||
$cifTotalAmount = 0;
|
||||
$cifTotalAmountRate = 0;
|
||||
$cifTotalAmountCurrency = 'CNY';
|
||||
// $profit = 0;
|
||||
foreach ($data['veh_list'] as $veh) {
|
||||
$veh['order_id'] = $created->id;
|
||||
$item = StockOrderItems::create($veh); // 表2
|
||||
@@ -93,6 +113,15 @@ class StockOrdersService
|
||||
$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'], '改装费');
|
||||
|
||||
// 利润
|
||||
$profit = $veh['unit_price']['amount'] - ($veh['official_price']['amount'] / $created->contract_exchange_rate) - $veh['discount_price']['amount'] - $veh['handling_fee']['amount'] - $veh['fob_transport_fee']['amount'] - $veh['port_misc_fee']['amount'] - $veh['retrofit_fee']['amount'];
|
||||
$item->addMoney('profit', $veh['unit_price']['currency'], $profit, $veh['unit_price']['rate'], '利润');
|
||||
|
||||
// cif_total_amount
|
||||
$cifTotalAmount += $veh['total_price']['amount'];
|
||||
$cifTotalAmountRate = $veh['retrofit_fee']['rate'];
|
||||
$cifTotalAmountCurrency = $veh['retrofit_fee']['currency'];
|
||||
|
||||
// 改装
|
||||
if (count($veh['modify_list']) > 0) {
|
||||
foreach ($veh['modify_list'] as $modify) {
|
||||
@@ -102,6 +131,9 @@ class StockOrdersService
|
||||
}
|
||||
}
|
||||
|
||||
// 计算&&插入 表1
|
||||
$created->addMoney('cif_total_amount', $cifTotalAmountCurrency, $cifTotalAmount, $cifTotalAmountRate, '合计到岸价');
|
||||
|
||||
// 账户
|
||||
if (count($data['account_list']) > 0) {
|
||||
foreach ($data['account_list'] as $account) {
|
||||
@@ -129,17 +161,17 @@ class StockOrdersService
|
||||
return $data;
|
||||
}
|
||||
|
||||
// protected function afterServiceStore($res)
|
||||
// {
|
||||
|
||||
// return $res;
|
||||
// }
|
||||
|
||||
|
||||
public function serviceShow(Request $request)
|
||||
protected function afterServiceStore($res)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'show');
|
||||
$item = $this->logicShow($config);
|
||||
return $this->postProcess('Show', $item);
|
||||
// 处理原单
|
||||
if ($res->is_final == 1 && $res->object_id > 0) {
|
||||
$order = StockOrders::find($res->object_id);
|
||||
$order->is_use = 1;
|
||||
$order->object_id = $res->id;
|
||||
if (!$order->save()) {
|
||||
flg('备货单【'.$order->order_no.'】创建终版成功,但更新原单失败');
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@@ -23,20 +23,102 @@ class StockOrdersController extends BaseController
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (isset($data['eta_ship_date'])) $data['eta_ship_date'] = date('Y-m-d', $data['eta_ship_date']);
|
||||
if (isset($data['biz_date'])) $data['biz_date'] = date('Y-m-d', $data['biz_date']);
|
||||
if (isset($data['latest_arrival_date'])) $data['latest_arrival_date'] = date('Y-m-d', $data['latest_arrival_date']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
protected function showFormat($data)
|
||||
{
|
||||
if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (isset($data['eta_ship_date'])) $data['eta_ship_date'] = date('Y-m-d', $data['eta_ship_date']);
|
||||
if (isset($data['biz_date'])) $data['biz_date'] = date('Y-m-d', $data['biz_date']);
|
||||
if (isset($data['latest_arrival_date'])) $data['latest_arrival_date'] = date('Y-m-d', $data['latest_arrival_date']);
|
||||
if (count($data['moneyValues']) > 0) {
|
||||
foreach ($data['moneyValues'] as $mvs) {
|
||||
$data['cif_total_amount'] = [
|
||||
'exchange_rate' => $mvs['exchange_rate'],
|
||||
'amount' => $mvs['amount'],
|
||||
'currency' => $mvs['currency'],
|
||||
'id' => $mvs['id']
|
||||
];
|
||||
}
|
||||
}
|
||||
unset($data['moneyValues']);
|
||||
|
||||
foreach ($data['items'] as &$item) {
|
||||
foreach ($item['moneyValues'] as $mv) {
|
||||
$item[$mv['field']] = [
|
||||
'exchange_rate' => $mv['exchange_rate'],
|
||||
'amount' => $mv['amount'],
|
||||
'currency' => $mv['currency'],
|
||||
'id' => $mv['id']
|
||||
];
|
||||
}
|
||||
unset($item['moneyValues']);
|
||||
|
||||
foreach ($item['options'] as $opt) {
|
||||
$item['modify_list'][] = [
|
||||
"id" => $opt['id'],
|
||||
"order_item_id" => $opt['order_item_id'],
|
||||
"option_id" => $opt['option_id'],
|
||||
"option_name_snapshot" => $opt['option_name_snapshot'],
|
||||
"option_price" => $opt['option_price']
|
||||
];
|
||||
}
|
||||
unset($item['options']);
|
||||
}
|
||||
unset($item);
|
||||
|
||||
|
||||
foreach ($data['accounts'] as $acc) {
|
||||
$data['account_list'][] = [
|
||||
"id" => $acc['id'],
|
||||
"order_id" => $acc['order_id'],
|
||||
"seq_no" => $acc['seq_no'],
|
||||
"remit_country_id" => $acc['remit_country_id'],
|
||||
"remit_country_name_snapshot" => $acc['remit_country_name_snapshot'],
|
||||
"remit_date" => date('Y-m-d', $acc['remit_date']),
|
||||
"currency_code" => $acc['currency_code'],
|
||||
"currency_name_snapshot" => $acc['currency_name_snapshot'],
|
||||
"account_id" => $acc['account_id'],
|
||||
"account_name_snapshot" => $acc['account_name_snapshot'],
|
||||
"remitter_name" => $acc['remitter_name'],
|
||||
"amount" => $acc['amount']
|
||||
];
|
||||
}
|
||||
unset($data['accounts']);
|
||||
|
||||
$data['veh_list'] = $data['items'];
|
||||
unset($data['items']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function copyOrder(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->copyOrder($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
|
||||
public function desc(Request $request)
|
||||
{
|
||||
|
||||
$data = [
|
||||
|
||||
Reference in New Issue
Block a user