鲜花2.0-采购流程变更
This commit is contained in:
parent
a43d8b0c81
commit
7fb90a77f9
@ -53,14 +53,15 @@ class CheckSkuQualityPeriod extends Command
|
|||||||
->leftJoin('goods_skus as b', 'a.sku_id', '=', 'b.id')
|
->leftJoin('goods_skus as b', 'a.sku_id', '=', 'b.id')
|
||||||
->where("a.check_status", "=", 0)
|
->where("a.check_status", "=", 0)
|
||||||
->whereBetween('a.expire_time', [$startTime, $endTime])->get();
|
->whereBetween('a.expire_time', [$startTime, $endTime])->get();
|
||||||
Log::info('purchaseRecords',(array)$purchaseRecords);
|
Log::info('purchaseRecords', (array)$purchaseRecords);
|
||||||
if ($purchaseRecords->isNotEmpty()) {
|
if ($purchaseRecords->isNotEmpty()) {
|
||||||
$messageService = new MessageService();
|
$messageService = new MessageService();
|
||||||
$updateIds = [];
|
$updateIds = [];
|
||||||
foreach ($purchaseRecords as $v) {
|
foreach ($purchaseRecords as $v) {
|
||||||
// 单独采购单后续总和小于库存表示该sku没有卖完
|
// 单独采购单后续总和小于库存表示该sku没有卖完
|
||||||
$totalPurchaseNum = PurchaseRecords::query()->where('id', '>=', $v->id)
|
$totalPurchaseNum = PurchaseRecords::query()->where('date', '>=', $v->date)
|
||||||
->where('external_sku_id',"=",$v->external_sku_id)->sum('num');
|
->where('external_sku_id', "=", $v->external_sku_id)
|
||||||
|
->where("status", 1)->sum('num');
|
||||||
if ($totalPurchaseNum < $v->stock) {
|
if ($totalPurchaseNum < $v->stock) {
|
||||||
$messageService->skuQualityPeriodNoticeMessage((array)$v);
|
$messageService->skuQualityPeriodNoticeMessage((array)$v);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class DailyStockRecordReport extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'daily:report:stock_record';
|
protected $signature = 'daily:report:stock_record {date?}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -46,7 +46,10 @@ class DailyStockRecordReport extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$date = Carbon::yesterday()->format('Y-m-d');
|
$date = $this->argument('date');
|
||||||
|
if (is_null($date)) {
|
||||||
|
$date = Carbon::yesterday()->format('Y-m-d');
|
||||||
|
}
|
||||||
$startDateTime = Carbon::parse($date)->startOfDay()->toDateTimeString();
|
$startDateTime = Carbon::parse($date)->startOfDay()->toDateTimeString();
|
||||||
$endDateTime = Carbon::parse($date)->endOfDay()->toDateTimeString();
|
$endDateTime = Carbon::parse($date)->endOfDay()->toDateTimeString();
|
||||||
//统计订单数量
|
//统计订单数量
|
||||||
@ -63,12 +66,13 @@ class DailyStockRecordReport extends Command
|
|||||||
//统计采购单数量
|
//统计采购单数量
|
||||||
$purchaseRecords = PurchaseRecords::query()
|
$purchaseRecords = PurchaseRecords::query()
|
||||||
->select(DB::raw("sum(num) as arrived_today_num"), "external_sku_id")
|
->select(DB::raw("sum(num) as arrived_today_num"), "external_sku_id")
|
||||||
->whereBetween("created_at", [$startDateTime, $endDateTime])
|
->whereBetween("date", [$startDateTime, $endDateTime])
|
||||||
|
->where("status",1)
|
||||||
->groupBy("external_sku_id")->get()->pluck(null, "external_sku_id")->toArray();
|
->groupBy("external_sku_id")->get()->pluck(null, "external_sku_id")->toArray();
|
||||||
//统计报损数量
|
//统计报损数量
|
||||||
$lossRecords = LossRecords::query()
|
$lossRecords = LossRecords::query()
|
||||||
->select(DB::raw("sum(num) as loss_num"), "external_sku_id")
|
->select(DB::raw("sum(num) as loss_num"), "external_sku_id")
|
||||||
->whereBetween("created_at", [$startDateTime, $endDateTime])
|
->whereBetween("date", [$startDateTime, $endDateTime])
|
||||||
->groupBy("external_sku_id")->get()->pluck(null, "external_sku_id")->toArray();
|
->groupBy("external_sku_id")->get()->pluck(null, "external_sku_id")->toArray();
|
||||||
Log::info("{$date}每日库存记录", ["orderItems" => $orderItems
|
Log::info("{$date}每日库存记录", ["orderItems" => $orderItems
|
||||||
, "purchaseRecords" => $purchaseRecords, "lossRecords" => $lossRecords]);
|
, "purchaseRecords" => $purchaseRecords, "lossRecords" => $lossRecords]);
|
||||||
|
|||||||
@ -135,7 +135,6 @@ class LossRecordController extends Controller
|
|||||||
|
|
||||||
public function lossBatchStore(Request $request)
|
public function lossBatchStore(Request $request)
|
||||||
{
|
{
|
||||||
\Illuminate\Support\Facades\Log::info("test", (array)$request->all());
|
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'lossOrders' => 'required|array',
|
'lossOrders' => 'required|array',
|
||||||
'lossOrders.*.external_sku_id' => 'required|string',
|
'lossOrders.*.external_sku_id' => 'required|string',
|
||||||
|
|||||||
@ -145,6 +145,9 @@ class PurchaseRecordController extends Controller
|
|||||||
if (!empty($allParams['expire_time'])) {
|
if (!empty($allParams['expire_time'])) {
|
||||||
$purchaseRecords->expire_time = Carbon::parse($allParams['expire_time'])->toDateTimeString();
|
$purchaseRecords->expire_time = Carbon::parse($allParams['expire_time'])->toDateTimeString();
|
||||||
}
|
}
|
||||||
|
if (!empty($allParams['date'])) {
|
||||||
|
$purchaseRecords->date = Carbon::parse($allParams['date'])->toDateString();
|
||||||
|
}
|
||||||
if (!empty($allParams['arrived_time'])) {
|
if (!empty($allParams['arrived_time'])) {
|
||||||
$purchaseRecords->arrived_time = Carbon::parse($allParams['arrived_time'])->toDateTimeString();
|
$purchaseRecords->arrived_time = Carbon::parse($allParams['arrived_time'])->toDateTimeString();
|
||||||
}
|
}
|
||||||
@ -264,18 +267,32 @@ class PurchaseRecordController extends Controller
|
|||||||
'purchaseOrders.*.status' => 'required|in:1,2']);
|
'purchaseOrders.*.status' => 'required|in:1,2']);
|
||||||
$allUpdateIds = [];
|
$allUpdateIds = [];
|
||||||
foreach ($params['purchaseOrders'] as $v) {
|
foreach ($params['purchaseOrders'] as $v) {
|
||||||
$purchaseRecords = PurchaseRecords::query()->with("goodsSku")->where("id", $v['id'])->first();
|
$purchaseRecordBuilder = PurchaseRecords::query()->with("goodsSku")->where("id", $v['id'])->first();
|
||||||
if (empty($purchaseRecords)) {
|
if (empty($purchaseRecordBuilder)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$purchaseRecords->status = $v['status'];
|
$purchaseRecords = $purchaseRecordBuilder->toArray();
|
||||||
$purchaseRecords->save();
|
if (empty($purchaseRecords['goods_sku'])) {
|
||||||
if (PurchaseStatusEnum::CHECK_SUCCESS == $v['status']) {
|
continue;
|
||||||
$updateIds = GoodSkuService::computeSkuStock($v['goodsSku'], $v, TargetTypeEnum::PURCHASE);
|
}
|
||||||
$allUpdateIds = array_merge($allUpdateIds, $updateIds);
|
if ($purchaseRecords['status'] == $v['status']) {
|
||||||
|
throw new \Exception("id:{$v["id"]}状态未变更,请勿重复操作");
|
||||||
|
}
|
||||||
|
DB::beginTransaction();
|
||||||
|
try {
|
||||||
|
if (PurchaseStatusEnum::CHECK_SUCCESS == $v['status']) {
|
||||||
|
$updateIds = GoodSkuService::computeSkuStock($purchaseRecords['goods_sku'], $purchaseRecords, TargetTypeEnum::PURCHASE);
|
||||||
|
$allUpdateIds = array_merge($allUpdateIds, $updateIds);
|
||||||
|
}
|
||||||
|
$purchaseRecordBuilder->status = $v['status'];
|
||||||
|
$purchaseRecordBuilder->save();
|
||||||
|
DB::commit();
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
DB::rollBack();
|
||||||
|
\Illuminate\Support\Facades\Log::error("质检审核事务异常", ["error" => $exception->getMessage()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!empty($allUpdateIds)){
|
if (!empty($allUpdateIds)) {
|
||||||
event(new BatchStockUpdateEvent(collect($allUpdateIds)->unique()->toArray()));
|
event(new BatchStockUpdateEvent(collect($allUpdateIds)->unique()->toArray()));
|
||||||
}
|
}
|
||||||
return response($this->res, $this->res['httpCode']);
|
return response($this->res, $this->res['httpCode']);
|
||||||
|
|||||||
@ -74,6 +74,11 @@ class PurchaseImport implements ToArray, SkipsEmptyRows
|
|||||||
if (!empty($row[6])) {
|
if (!empty($row[6])) {
|
||||||
$purchaseRecords->date = DateTimeUtils::excelUploadDateToString($row[6], $today);
|
$purchaseRecords->date = DateTimeUtils::excelUploadDateToString($row[6], $today);
|
||||||
}
|
}
|
||||||
|
if (!empty($row[7])) {
|
||||||
|
$purchaseRecords->arrived_time = DateTimeUtils::excelUploadDateToString($row[7], $today,"Y-m-d H:i:s");
|
||||||
|
}else{
|
||||||
|
$purchaseRecords->arrived_time = $today;
|
||||||
|
}
|
||||||
$purchaseRecords->buyer_user_id = $buyerUserIdKeyByNameMap[$row[4]] ?? 0;
|
$purchaseRecords->buyer_user_id = $buyerUserIdKeyByNameMap[$row[4]] ?? 0;
|
||||||
$purchaseRecords->buyer_name = $row[4] ?? '';
|
$purchaseRecords->buyer_name = $row[4] ?? '';
|
||||||
$purchaseRecords->supplier_name = $row[5] ?? '';
|
$purchaseRecords->supplier_name = $row[5] ?? '';
|
||||||
|
|||||||
@ -14,6 +14,7 @@ class PurchaseRecords extends Model
|
|||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
public $fieldSearchable = [
|
public $fieldSearchable = [
|
||||||
'external_sku_id',
|
'external_sku_id',
|
||||||
|
'status'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function goodsSku()
|
public function goodsSku()
|
||||||
|
|||||||
@ -33,6 +33,10 @@ class MiaoXuan extends BusinessClient
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function downloadAfterSaleOrdersAndSave($beginTime, $endTime, $page = 1){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function batchIncrQuantity($businessGoodsSkus, $num, $incremental)
|
public function batchIncrQuantity($businessGoodsSkus, $num, $incremental)
|
||||||
{
|
{
|
||||||
$batchAppendParams = [];
|
$batchAppendParams = [];
|
||||||
|
|||||||
@ -52,12 +52,17 @@ class DateTimeUtils
|
|||||||
return $d && $d->format($format) === $date;
|
return $d && $d->format($format) === $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function excelUploadDateToString($excelData, $defaultTime)
|
public static function excelUploadDateToString($excelData, $defaultTime, $format = "Y-m-d")
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return date("Y-m-d", ($excelData - 25569) * 24 * 3600);
|
$time = ($excelData - 25569) * 24 * 3600;
|
||||||
|
if ($format == "Y-m-d H:i:s") {
|
||||||
|
$time = $time - 8 * 3600;
|
||||||
|
}
|
||||||
|
return date($format, $time);
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
Log::error("时间转化出错", $exception->getMessage());
|
Log::error("时间转化出错", [$exception->getMessage()]);
|
||||||
}
|
}
|
||||||
return $defaultTime;
|
return $defaultTime;
|
||||||
|
|
||||||
|
|||||||
@ -532,54 +532,54 @@ return [
|
|||||||
],
|
],
|
||||||
'PURCHASE_RECORD' => [
|
'PURCHASE_RECORD' => [
|
||||||
'id' => 192,
|
'id' => 192,
|
||||||
'name' => '入库采购',
|
'name' => '商品采购',
|
||||||
'parent_id' => 19,
|
'parent_id' => 19,
|
||||||
'show' => 1,
|
'show' => 1,
|
||||||
],
|
],
|
||||||
'purchase_record.index' => [
|
'purchase_record.index' => [
|
||||||
'id' => 1921,
|
'id' => 1921,
|
||||||
'name' => '入库采购首页',
|
'name' => '商品采购首页',
|
||||||
'parent_id' => 192
|
'parent_id' => 192
|
||||||
],
|
],
|
||||||
'purchase_record.update' => [
|
'purchase_record.update' => [
|
||||||
'id' => 1922,
|
'id' => 1922,
|
||||||
'name' => '入库采购更新',
|
'name' => '商品采购更新',
|
||||||
'parent_id' => 192
|
'parent_id' => 192
|
||||||
],
|
],
|
||||||
'purchase_record.store' => [
|
'purchase_record.store' => [
|
||||||
'id' => 1923,
|
'id' => 1923,
|
||||||
'name' => '入库采购新增',
|
'name' => '商品采购新增',
|
||||||
'parent_id' => 192
|
'parent_id' => 192
|
||||||
],
|
],
|
||||||
'purchase_record.purchase_import' => [
|
'purchase_record.purchase_import' => [
|
||||||
'id' => 1924,
|
'id' => 1924,
|
||||||
'name' => '入库采购批量导入',
|
'name' => '商品采购批量导入',
|
||||||
'parent_id' => 192
|
'parent_id' => 192
|
||||||
],
|
],
|
||||||
'purchase_record.purchase_batch_store' => [
|
'purchase_record.purchase_batch_store' => [
|
||||||
'id' => 1925,
|
'id' => 1925,
|
||||||
'name' => '入库采购批量导入',
|
'name' => '商品采购批量导入',
|
||||||
'parent_id' => 192
|
'parent_id' => 192
|
||||||
],
|
],
|
||||||
'LOSS_RECORD' => [
|
'LOSS_RECORD' => [
|
||||||
'id' => 193,
|
'id' => 193,
|
||||||
'name' => '报损记录',
|
'name' => '仓库报损',
|
||||||
'parent_id' => 19,
|
'parent_id' => 19,
|
||||||
'show' => 1,
|
'show' => 1,
|
||||||
],
|
],
|
||||||
'loss_record.index' => [
|
'loss_record.index' => [
|
||||||
'id' => 1931,
|
'id' => 1931,
|
||||||
'name' => '报损记录首页',
|
'name' => '仓库报损首页',
|
||||||
'parent_id' => 193
|
'parent_id' => 193
|
||||||
],
|
],
|
||||||
'loss_record.update' => [
|
'loss_record.update' => [
|
||||||
'id' => 1932,
|
'id' => 1932,
|
||||||
'name' => '报损记录更新',
|
'name' => '仓库报损更新',
|
||||||
'parent_id' => 193
|
'parent_id' => 193
|
||||||
],
|
],
|
||||||
'loss_record.store' => [
|
'loss_record.store' => [
|
||||||
'id' => 1933,
|
'id' => 1933,
|
||||||
'name' => '报损记录新增',
|
'name' => '仓库报损新增',
|
||||||
'parent_id' => 193
|
'parent_id' => 193
|
||||||
],
|
],
|
||||||
'loss_record.loss_import' => [
|
'loss_record.loss_import' => [
|
||||||
@ -594,30 +594,41 @@ return [
|
|||||||
],
|
],
|
||||||
'DAILY_STOCK_RECORD' => [
|
'DAILY_STOCK_RECORD' => [
|
||||||
'id' => 194,
|
'id' => 194,
|
||||||
'name' => '盘点记录',
|
'name' => '库存盘点',
|
||||||
'parent_id' => 19,
|
'parent_id' => 19,
|
||||||
'show' => 1,
|
'show' => 1,
|
||||||
],
|
],
|
||||||
'daily_stock_record.index' => [
|
'daily_stock_record.index' => [
|
||||||
'id' => 1941,
|
'id' => 1941,
|
||||||
'name' => '盘点记录首页',
|
'name' => '库存盘点首页',
|
||||||
'parent_id' => 194
|
'parent_id' => 194
|
||||||
],
|
],
|
||||||
'daily_stock_record.store' => [
|
'daily_stock_record.store' => [
|
||||||
'id' => 1942,
|
'id' => 1942,
|
||||||
'name' => '盘点记录新增',
|
'name' => '库存盘点新增',
|
||||||
'parent_id' => 194
|
'parent_id' => 194
|
||||||
],
|
],
|
||||||
'daily_stock_record.inventory_import' => [
|
'daily_stock_record.inventory_import' => [
|
||||||
'id' => 1943,
|
'id' => 1943,
|
||||||
'name' => '盘点记录批量导入',
|
'name' => '库存盘点批量导入',
|
||||||
'parent_id' => 194
|
'parent_id' => 194
|
||||||
],
|
],
|
||||||
'daily_stock_record.inventory_batch_store' => [
|
'daily_stock_record.inventory_batch_store' => [
|
||||||
'id' => 1944,
|
'id' => 1944,
|
||||||
'name' => '盘点记录批量导入',
|
'name' => '库存盘点批量导入',
|
||||||
'parent_id' => 194
|
'parent_id' => 194
|
||||||
],
|
],
|
||||||
|
'PURCHASE_RECORD_CHECK' => [
|
||||||
|
'id' => 195,
|
||||||
|
'name' => '质检入库',
|
||||||
|
'parent_id' => 19,
|
||||||
|
'show' => 1,
|
||||||
|
],
|
||||||
|
'purchase_record.purchase_batch_check' => [
|
||||||
|
'id' => 1951,
|
||||||
|
'name' => '质检审核',
|
||||||
|
'parent_id' => 195,
|
||||||
|
],
|
||||||
'sale_statistics' => [
|
'sale_statistics' => [
|
||||||
'id' => 181,
|
'id' => 181,
|
||||||
'name' => 'sku销售统计',
|
'name' => 'sku销售统计',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user