鲜花2.0-库存成本,周数据导出功能修改+增加库存变更记录
This commit is contained in:
parent
bf67357601
commit
25f805496d
@ -82,7 +82,8 @@ class LossRecordController extends Controller
|
||||
$lossRecords->reason = $allParams['reason'] ?? '';
|
||||
$lossRecords->phenomenon = $v['phenomenon'] ?? '';
|
||||
$lossRecords->save();
|
||||
$updateIds = GoodSkuService::computeSkuStock($goodsSku->toArray(), ['num' => 0 - $allParams['num'], "cost" => $allParams['cost']]);
|
||||
$updateIds = GoodSkuService::computeSkuStock($goodsSku->toArray()
|
||||
, ['num' => 0 - $allParams['num'], "cost" => $allParams['cost'],"user_id"=>$request->user()->id]);
|
||||
event(new BatchStockUpdateEvent($updateIds));
|
||||
} else {
|
||||
$this->res = [
|
||||
@ -177,7 +178,8 @@ class LossRecordController extends Controller
|
||||
$lossRecords->phenomenon = $v['phenomenon'] ?? '';
|
||||
$lossRecords->save();
|
||||
|
||||
$updateIds = GoodSkuService::computeSkuStock($goodsSkuItem, ['num' => 0 - $v['num'], "cost" => $v['cost']]);
|
||||
$updateIds = GoodSkuService::computeSkuStock($goodsSkuItem
|
||||
, ['num' => 0 - $v['num'], "cost" => $v['cost'],"user_id"=>$request->user()->id]);
|
||||
$allUpdateIds = array_merge($allUpdateIds, $updateIds);
|
||||
}
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ class PurchaseRecordController extends Controller
|
||||
|
||||
}
|
||||
$purchaseRecords->save();
|
||||
|
||||
$allParams['user_id'] = $request->user()->id;
|
||||
$updateIds = GoodSkuService::computeSkuStock($goodsSku->toArray(), $allParams, TargetTypeEnum::PURCHASE);
|
||||
event(new BatchStockUpdateEvent($updateIds));
|
||||
} else {
|
||||
@ -165,7 +165,8 @@ class PurchaseRecordController extends Controller
|
||||
$validator = Validator::make($request->all(), [
|
||||
'purchaseOrders' => 'required|array',
|
||||
'purchaseOrders.*.external_sku_id' => 'required|string',
|
||||
'purchaseOrders.*.num' => 'required|integer']);
|
||||
'purchaseOrders.*.num' => 'required|integer',
|
||||
'purchaseOrders.*.cost' => 'required',]);
|
||||
//参数校验
|
||||
if ($validator->fails()) {
|
||||
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
||||
@ -200,7 +201,7 @@ class PurchaseRecordController extends Controller
|
||||
$purchaseRecords->supplier_id = $v['supplier_id'] ?? 0;
|
||||
$purchaseRecords->expire_time = Carbon::now()->addDays($expireDay)->toDateTimeString();
|
||||
$purchaseRecords->save();
|
||||
|
||||
$v['user_id'] = $request->user()->id;
|
||||
$updateIds = GoodSkuService::computeSkuStock($goodsSkuItem, $v, TargetTypeEnum::PURCHASE);
|
||||
$allUpdateIds = array_merge($allUpdateIds, $updateIds);
|
||||
}
|
||||
|
||||
@ -26,14 +26,15 @@ class SuppliersController extends Controller
|
||||
$suppliers = Suppliers::query()->paginate($request->get('per_page'));
|
||||
return JsonResource::collection($suppliers);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
//获取所有参数
|
||||
$allParams =$request->all();
|
||||
$allParams = $request->all();
|
||||
//进行校验验证
|
||||
$validator = Validator::make($allParams, [
|
||||
'supplier_name' => 'required|string',
|
||||
'company_name' => 'required|string',
|
||||
'company_name' => 'required|string',
|
||||
'address' => 'sometimes|string',
|
||||
'link_tel' => 'sometimes|string',
|
||||
'payment_account' => 'sometimes|string',
|
||||
@ -65,11 +66,11 @@ class SuppliersController extends Controller
|
||||
public function update($id, Request $request)
|
||||
{
|
||||
//获取所有参数
|
||||
$allParams =$request->all();
|
||||
$allParams = $request->all();
|
||||
//进行校验验证
|
||||
$validator = Validator::make($allParams, [
|
||||
'supplier_name' => 'required|string',
|
||||
'company_name' => 'required|string',
|
||||
'company_name' => 'required|string',
|
||||
'address' => 'sometimes|string',
|
||||
'link_tel' => 'sometimes|string',
|
||||
'payment_account' => 'sometimes|string',
|
||||
|
||||
@ -2,18 +2,12 @@
|
||||
|
||||
namespace App\Imports;
|
||||
|
||||
use App\Events\BatchStockUpdateEvent;
|
||||
use App\Jobs\SyncCostToMiaoXuan;
|
||||
use App\Models\DailyStockRecord;
|
||||
use App\Models\GoodsSku;
|
||||
use App\Models\TodayPrice;
|
||||
use App\Services\GoodSku\GoodSkuService;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\ToArray;
|
||||
use App\Utils\ArrayUtils;
|
||||
|
||||
class InventoryImport implements ToArray, SkipsEmptyRows
|
||||
{
|
||||
|
||||
@ -64,10 +64,17 @@ class GoodsSku extends Model
|
||||
|
||||
public function getThumbUrlAttribute($value)
|
||||
{
|
||||
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
if(empty($value)){
|
||||
return $this->attributes['title']??'';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 此规格从属于一个商品
|
||||
*/
|
||||
|
||||
@ -12,6 +12,7 @@ use App\Models\Log as LogModel;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use App\Utils\GeneratorUtils;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@ -50,6 +51,7 @@ class GoodSkuService
|
||||
Log::info("库存盘点前完整信息", $skusWithCombinationGoods);
|
||||
Log::info("需要操作的库存数据", $inventoryKeyBySkuIdMap);
|
||||
$batchNumber = GeneratorUtils::generateBatchNumber("import");
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach ($skusWithCombinationGoods as $sku) {
|
||||
@ -68,8 +70,8 @@ class GoodSkuService
|
||||
foreach ($inventoryKeyBySkuIdMap as $skuId => $realStock) {
|
||||
//库存修改 盘点是直接覆盖
|
||||
$skuData = GoodsSku::query()->where('id', $skuId)->first();
|
||||
if(!empty($skuData)){
|
||||
$costLogs[] = static::addStockLog($skuData, []
|
||||
if (!empty($skuData)) {
|
||||
$costLogs[] = static::addStockLog($skuData
|
||||
, TargetTypeEnum::INVENTORY, ['stock' => $realStock]);
|
||||
$skuData->stock = $realStock;
|
||||
$skuData->save();
|
||||
@ -142,7 +144,7 @@ class GoodSkuService
|
||||
->update($updateParam);
|
||||
$updateIds[] = $goodsSkuItem['id'];
|
||||
$updateParams[] = $updateParam;
|
||||
$costLogs[] = static::addStockLog($goodsSkuItem, $changeData, $targetType, $updateParam);
|
||||
$costLogs[] = static::addStockLog($goodsSkuItem, $targetType, $updateParam);
|
||||
|
||||
} else {
|
||||
$combinationGood = CombinationGood::query()->with('goodsSkuItem:id,stock,sale_stock')
|
||||
@ -157,7 +159,7 @@ class GoodSkuService
|
||||
|
||||
$updateIds[] = $item['goodsSkuItem']['id'];
|
||||
$updateParams[] = $updateParam;
|
||||
$costLogs[] = static::addStockLog($item['goodsSkuItem'], $changeData, $targetType, $updateParam);
|
||||
$costLogs[] = static::addStockLog($item['goodsSkuItem'], $targetType, $updateParam);
|
||||
}
|
||||
}
|
||||
$log = new LogModel();
|
||||
@ -166,14 +168,15 @@ class GoodSkuService
|
||||
return $updateIds;
|
||||
}
|
||||
|
||||
public static function addStockLog($goodsSkuItem, $changeData, $targetType = TargetTypeEnum::LOSS, $updateParam)
|
||||
public static function addStockLog($goodsSkuItem, $targetType = TargetTypeEnum::LOSS, $updateParam)
|
||||
{
|
||||
$userId = Auth::id();
|
||||
$costLog = [
|
||||
'module' => 'goodSkus',
|
||||
'action' => "POST",
|
||||
'target_type' => $targetType,
|
||||
'target_id' => $goodsSkuItem['id'] ?? 0,
|
||||
'user_id' => $changeData['user_id'] ?? 999,
|
||||
'user_id' => $userId ?? 999,
|
||||
"target_field" => "stock"
|
||||
];
|
||||
$costLog['before_update'] = json_encode($goodsSkuItem);
|
||||
|
||||
@ -15,8 +15,8 @@ class CreatePurchaseRecordsTable extends Migration
|
||||
{
|
||||
Schema::create('purchase_records', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('external_sku_id',100)->comment('唯一sku标识');
|
||||
$table->string('batch_number')->nullable()->comment('批次号');
|
||||
$table->string('external_sku_id',60)->comment('唯一sku标识');
|
||||
$table->string('batch_number',60)->nullable()->comment('批次号');
|
||||
$table->date('date')->nullable()->comment('日期');;
|
||||
$table->Integer('num')->default(0)->comment('采购数量');
|
||||
$table->unsignedDecimal('cost')->default(0)->comment('成本');
|
||||
@ -29,6 +29,7 @@ class CreatePurchaseRecordsTable extends Migration
|
||||
// 索引
|
||||
$table->index('external_sku_id');
|
||||
$table->index('created_at');
|
||||
$table->index('batch_number');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@ class CreateLossRecordsTable extends Migration
|
||||
{
|
||||
Schema::create('loss_records', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('external_sku_id',100)->comment('唯一sku标识');
|
||||
$table->string('batch_number')->nullable()->comment('批次号');
|
||||
$table->string('external_sku_id',60)->comment('唯一sku标识');
|
||||
$table->string('batch_number',60)->nullable()->comment('批次号');
|
||||
$table->date('date')->nullable()->comment('日期');
|
||||
$table->Integer('num')->default(0)->comment('报损数量');
|
||||
$table->unsignedDecimal('cost')->default(0)->comment('成本');
|
||||
@ -28,6 +28,7 @@ class CreateLossRecordsTable extends Migration
|
||||
// 索引
|
||||
$table->index('external_sku_id');
|
||||
$table->index('created_at');
|
||||
$table->index('batch_number');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
@ -21,8 +21,8 @@ class CreateSuppliersTable extends Migration
|
||||
$table->string('link_tel',100)->nullable()->comment('联系方式');
|
||||
$table->string('payment_account',100)->nullable()->comment('支付方式');
|
||||
$table->string('supply_type')->nullable()->comment('供应类型');
|
||||
$table->string('agent_name')->nullable()->comment('代理人名称');
|
||||
$table->Integer('agent_id')->nullable()->comment('代理人id');
|
||||
$table->string('agent_name')->nullable()->comment('开发维护人');
|
||||
$table->Integer('agent_id')->nullable()->comment('开发维护人id');
|
||||
|
||||
$table->index('supplier_name');
|
||||
$table->timestamps();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user