mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
鲜花2.0-接口测试bug修复
This commit is contained in:
parent
3313c4a713
commit
7e33e1f3f7
@ -49,9 +49,9 @@ class CheckSkuQualityPeriod extends Command
|
||||
|
||||
//查询未处理过的快过期的异常订单
|
||||
$purchaseRecords = DB::table('purchase_records as a')
|
||||
->select("a.created_at", "a.num", "b.title", "b.stock", "a.id", "a.sku_id", "b.external_sku_id")
|
||||
->select("a.created_at", "a.num", "b.title", "b.stock", "a.id", "b.id as sku_id", "b.external_sku_id")
|
||||
->leftJoin('goods_skus as b', 'a.sku_id', '=', 'b.id')
|
||||
->where("a.status", "=", 0)
|
||||
->where("a.check_status", "=", 0)
|
||||
->whereBetween('a.expire_time', [$startTime, $endTime])->get();
|
||||
Log::info('purchaseRecords',(array)$purchaseRecords);
|
||||
if ($purchaseRecords->isNotEmpty()) {
|
||||
@ -60,7 +60,7 @@ class CheckSkuQualityPeriod extends Command
|
||||
foreach ($purchaseRecords as $v) {
|
||||
// 单独采购单后续总和小于库存表示该sku没有卖完
|
||||
$totalPurchaseNum = PurchaseRecords::query()->where('id', '>=', $v->id)
|
||||
->where('sku_id',"=",$v->sku_id)->sum('num');
|
||||
->where('external_sku_id',"=",$v->external_sku_id)->sum('num');
|
||||
if ($totalPurchaseNum < $v->stock) {
|
||||
$messageService->skuQualityPeriodNoticeMessage((array)$v);
|
||||
}
|
||||
@ -69,7 +69,7 @@ class CheckSkuQualityPeriod extends Command
|
||||
|
||||
}
|
||||
PurchaseRecords::query()->whereIn('id', $updateIds)->update([
|
||||
"status" => 1
|
||||
"check_status" => 1
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class KttOrderAfterSaleQuery extends Command
|
||||
{
|
||||
$shops = Shop::query()->where('plat_id', Shop::$PLAT_KTT)->where('status', Shop::$STATUS_AUTHORIZED)->get();
|
||||
$endTime = DateTimeUtils::getMicroTime();
|
||||
$beginTime = $endTime - (15 * 60 * 1000)-1000;//售后单每15min查询一次 多查询一次
|
||||
$beginTime = $endTime - (60*15 * 60 * 1000)-1000;//售后单每15min查询一次 多查询一次
|
||||
foreach ($shops as $shop) {
|
||||
BusinessFactory::init()->make($shop->plat_id)->setShop($shop)->downloadAfterSaleOrdersAndSave($beginTime, $endTime);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class KttOrderQuery extends Command
|
||||
{
|
||||
$shops = Shop::query()->where('plat_id', Shop::$PLAT_KTT)->where('status', Shop::$STATUS_AUTHORIZED)->get();
|
||||
$endTime = DateTimeUtils::getMicroTime();
|
||||
$beginTime = $endTime - 63000;
|
||||
$beginTime = $endTime - 63000*20;
|
||||
foreach ($shops as $shop) {
|
||||
BusinessFactory::init()->make($shop->plat_id)->setShop($shop)->downloadOrdersAndSave($beginTime, $endTime + 3000);
|
||||
}
|
||||
|
||||
@ -12,7 +12,9 @@ use App\Models\Log;
|
||||
use App\Models\Log as LogModel;
|
||||
use App\Models\LossRecords;
|
||||
use App\Models\Suppliers;
|
||||
use App\Models\User;
|
||||
use App\Services\GoodSku\GoodSkuService;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@ -64,12 +66,16 @@ class LossRecordController extends Controller
|
||||
}
|
||||
$goodsSku = GoodsSku::query()->where('external_sku_id', "=", $request->external_sku_id)->first();
|
||||
if (!empty($goodsSku)) {
|
||||
$buyerUserId = User::query()->where("name", $allParams['buyer_name'] ?? '')
|
||||
->pluck("id")->first();
|
||||
$today = DateTimeUtils::getToday();
|
||||
//保存記錄
|
||||
$lossRecords = new LossRecords();
|
||||
$lossRecords->sku_id = $goodsSku->id;
|
||||
$lossRecords->external_sku_id = $allParams['external_sku_id'];
|
||||
$lossRecords->num = $allParams['num'];
|
||||
$lossRecords->cost = $allParams['cost'];
|
||||
$lossRecords->date = $today;
|
||||
$lossRecords->buyer_user_id = $allParams['buyer_user_id'] ?? ($buyerUserId ?? 0);
|
||||
$lossRecords->buyer_name = $allParams['buyer_name'] ?? '';
|
||||
$lossRecords->reason = $allParams['reason'] ?? '';
|
||||
$lossRecords->save();
|
||||
@ -95,7 +101,8 @@ class LossRecordController extends Controller
|
||||
//进行校验验证
|
||||
$validator = Validator::make($allParams, [
|
||||
'reason' => 'sometimes|string',
|
||||
'buyer_name' => 'sometimes|string'
|
||||
'buyer_name' => 'sometimes|string',
|
||||
'buyer_user_id' => 'sometimes|integer'
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
//校验失败返回异常
|
||||
@ -106,6 +113,7 @@ class LossRecordController extends Controller
|
||||
if (!empty($lossRecords)) {
|
||||
//更新記錄
|
||||
$lossRecords->buyer_name = $allParams['buyer_name'] ?? '';
|
||||
$lossRecords->buyer_user_id = $allParams['buyer_user_id'] ?? 0;
|
||||
$lossRecords->reason = $allParams['reason'] ?? '';
|
||||
$lossRecords->save();
|
||||
} else {
|
||||
@ -149,10 +157,10 @@ class LossRecordController extends Controller
|
||||
$goodsSkuItem = $goodsSkuMap[$v['external_sku_id']];
|
||||
//保存記錄
|
||||
$lossRecords = new LossRecords();
|
||||
$lossRecords->sku_id = $goodsSkuItem['id'] ?? 0;
|
||||
$lossRecords->external_sku_id = $v['external_sku_id'];
|
||||
$lossRecords->num = $v['num'];
|
||||
$lossRecords->cost = $v['cost'];
|
||||
$lossRecords->buyer_user_id = $v['buyer_user_id'] ?? 0;
|
||||
$lossRecords->buyer_name = $v['buyer_name'] ?? '';
|
||||
$lossRecords->reason = $v['reason'] ?? '';
|
||||
$lossRecords->save();
|
||||
|
||||
@ -13,8 +13,10 @@ use App\Models\Log;
|
||||
use App\Models\Log as LogModel;
|
||||
use App\Models\PurchaseRecords;
|
||||
use App\Models\Suppliers;
|
||||
use App\Models\User;
|
||||
use App\Services\DeveloperConfig\DeveloperConfigService;
|
||||
use App\Services\GoodSku\GoodSkuService;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
@ -33,6 +35,7 @@ class PurchaseRecordController extends Controller
|
||||
'target_type' => 'purchase_record',
|
||||
]);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$builder = PurchaseRecords::query()->filter()->with("goodsSku:id,name,external_sku_id,title");
|
||||
@ -65,15 +68,21 @@ class PurchaseRecordController extends Controller
|
||||
$goodsSku = GoodsSku::query()->where('external_sku_id', "=", $request->external_sku_id)->first();
|
||||
if (!empty($goodsSku)) {
|
||||
$expireDay = DeveloperConfigService::getDefaultExpireDay();
|
||||
$today = DateTimeUtils::getToday();
|
||||
$buyerUserId = User::query()->where("name", $allParams['buyer_name'] ?? '')
|
||||
->pluck("id")->first();
|
||||
$supplierId = Suppliers::query()->where("name", $allParams['supplier_name'] ?? '')
|
||||
->pluck("id")->first();
|
||||
//保存記錄
|
||||
$purchaseRecords = new PurchaseRecords();
|
||||
$purchaseRecords->sku_id = $goodsSku->id ?? 0;
|
||||
$purchaseRecords->external_sku_id = $allParams['external_sku_id'];
|
||||
$purchaseRecords->num = $allParams['num'];
|
||||
$purchaseRecords->cost = $allParams['cost'];
|
||||
$purchaseRecords->date = $today;
|
||||
$purchaseRecords->buyer_user_id = $allParams['buyer_user_id'] ?? ($buyerUserId ?? 0);
|
||||
$purchaseRecords->buyer_name = $allParams['buyer_name'] ?? '';
|
||||
$purchaseRecords->supplier_name = $allParams['supplier_name'] ?? '';
|
||||
$purchaseRecords->supplier_id = $allParams['supplier_id'] ?? 0;
|
||||
$purchaseRecords->supplier_id = $allParams['supplier_id'] ?? ($supplierId ?? 0);
|
||||
if (!empty($allParams['expire_time'])) {
|
||||
$purchaseRecords->expire_time = Carbon::parse($allParams['expire_time'])->toDateTimeString();
|
||||
} else {
|
||||
@ -116,6 +125,7 @@ class PurchaseRecordController extends Controller
|
||||
if (!empty($goodsSku)) {
|
||||
//可以修改的記錄
|
||||
$purchaseRecords = PurchaseRecords::query()->find($id);
|
||||
$purchaseRecords->buyer_user_id = $allParams['buyer_user_id'] ?? 0;
|
||||
$purchaseRecords->buyer_name = $allParams['buyer_name'] ?? '';
|
||||
$purchaseRecords->supplier_name = $allParams['supplier_name'] ?? '';
|
||||
$purchaseRecords->supplier_id = $allParams['supplier_id'] ?? 0;
|
||||
@ -164,15 +174,17 @@ class PurchaseRecordController extends Controller
|
||||
$goodsSkuMap = $goodsSku->pluck(null, 'external_sku_id')->toArray();
|
||||
$updateIds = [];
|
||||
$expireDay = DeveloperConfigService::getDefaultExpireDay();
|
||||
$today = DateTimeUtils::getToday();
|
||||
//开始保存数据
|
||||
foreach ($purchaseOrders as $v) {
|
||||
$goodsSkuItem = $goodsSkuMap[$v['external_sku_id']];
|
||||
//保存記錄
|
||||
$purchaseRecords = new PurchaseRecords();
|
||||
$purchaseRecords->sku_id = $goodsSkuItem['id'] ?? 0;
|
||||
$purchaseRecords->external_sku_id = $v['external_sku_id'];
|
||||
$purchaseRecords->num = $v['num'];
|
||||
$purchaseRecords->cost = $v['cost'];
|
||||
$purchaseRecords->date = $today;
|
||||
$purchaseRecords->buyer_user_id = $allParams['buyer_user_id'] ?? 0;
|
||||
$purchaseRecords->buyer_name = $v['buyer_name'] ?? '';
|
||||
$purchaseRecords->supplier_name = $v['supplier_name'] ?? '';
|
||||
$purchaseRecords->supplier_id = $v['supplier_id'] ?? 0;
|
||||
|
||||
@ -28,7 +28,6 @@ class GoodsRequest extends FormRequest
|
||||
'id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
|
||||
'title' => ['required', 'string', 'max:191'],
|
||||
'type_id' => ['required', 'integer', 'exists:goods_types,id'],
|
||||
'brand_id' => ['integer', 'exists:goods_brands,id'],
|
||||
'goods_code' => ['required', 'alpha_dash', 'max:32', Rule::unique('goods')->ignore(request('goods_id'))],
|
||||
];
|
||||
}
|
||||
|
||||
@ -8,6 +8,8 @@ use App\Models\DailyStockRecord;
|
||||
use App\Models\GoodsSku;
|
||||
use App\Models\LossRecords;
|
||||
use App\Models\PurchaseRecords;
|
||||
use App\Models\User;
|
||||
use App\Services\DeveloperConfig\DeveloperConfigService;
|
||||
use App\Services\GoodSku\GoodSkuService;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Exception;
|
||||
@ -26,11 +28,13 @@ class LossImport implements ToArray, SkipsEmptyRows
|
||||
if (!empty($collection)) {
|
||||
unset($collection[0]);
|
||||
$externalSkuIds = [];
|
||||
$buyerNames = [];
|
||||
foreach ($collection as &$row) {
|
||||
$row = array_map(static function ($v) {
|
||||
return trim($v);
|
||||
}, $row);
|
||||
$externalSkuIds[] = $row[0];
|
||||
$buyerNames[] = $row[4];
|
||||
}
|
||||
unset($row);
|
||||
$updateIds = [];
|
||||
@ -39,7 +43,9 @@ class LossImport implements ToArray, SkipsEmptyRows
|
||||
->get(['id', 'status', 'external_sku_id', 'stock', "sale_stock", "cost"])
|
||||
->toArray();
|
||||
$hasGoodsSkus = ArrayUtils::index($hasGoodsSkus, 'external_sku_id');
|
||||
|
||||
$buyerUserIdKeyByNameMap = User::query()->whereIn("name", $buyerNames)->get()
|
||||
->pluck("id", "name")->toArray();
|
||||
$today = DateTimeUtils::getToday();
|
||||
//excel字段排序 編碼 商品名稱 报损數量 成本价 采购人名称 报损原因
|
||||
foreach ($collection as $row) {
|
||||
if (!isset($hasGoodsSkus[$row[0]])) {
|
||||
@ -49,10 +55,11 @@ class LossImport implements ToArray, SkipsEmptyRows
|
||||
$goodsSkuItem = $hasGoodsSkus[$row[0]];
|
||||
//保存記錄
|
||||
$lossRecords = new LossRecords();
|
||||
$lossRecords->sku_id = $goodsSkuItem['id'] ?? 0;
|
||||
$lossRecords->external_sku_id = $row[0];
|
||||
$lossRecords->num = $row[2];
|
||||
$lossRecords->cost = $row[3];
|
||||
$lossRecords->date = $today;
|
||||
$lossRecords->buyer_user_id = $buyerUserIdKeyByNameMap[$row[4]] ?? 0;
|
||||
$lossRecords->buyer_name = $row[4] ?? '';
|
||||
$lossRecords->reason = $row[5] ?? '';
|
||||
$lossRecords->save();
|
||||
|
||||
@ -7,6 +7,8 @@ use App\Jobs\SyncCostToMiaoXuan;
|
||||
use App\Models\DailyStockRecord;
|
||||
use App\Models\GoodsSku;
|
||||
use App\Models\PurchaseRecords;
|
||||
use App\Models\Suppliers;
|
||||
use App\Models\User;
|
||||
use App\Services\DeveloperConfig\DeveloperConfigService;
|
||||
use App\Services\GoodSku\GoodSkuService;
|
||||
use App\Utils\DateTimeUtils;
|
||||
@ -27,11 +29,15 @@ class PurchaseImport implements ToArray, SkipsEmptyRows
|
||||
if (!empty($collection)) {
|
||||
unset($collection[0]);
|
||||
$externalSkuIds = [];
|
||||
$supplierNames = [];
|
||||
$buyerNames = [];
|
||||
foreach ($collection as &$row) {
|
||||
$row = array_map(static function ($v) {
|
||||
return trim($v);
|
||||
}, $row);
|
||||
$externalSkuIds[] = $row[0];
|
||||
$buyerNames[] = $row[4];
|
||||
$supplierNames[] = $row[5];
|
||||
}
|
||||
unset($row);
|
||||
$updateIds = [];
|
||||
@ -40,7 +46,13 @@ class PurchaseImport implements ToArray, SkipsEmptyRows
|
||||
->get(['id', 'status', 'external_sku_id', 'stock', "sale_stock", "cost"])
|
||||
->toArray();
|
||||
$hasGoodsSkus = ArrayUtils::index($hasGoodsSkus, 'external_sku_id');
|
||||
//获取供货商
|
||||
$supplierIdKeyByNameMap = Suppliers::query()->whereIn("supplier_name", $supplierNames)->get()
|
||||
->pluck("id", "supplier_name")->toArray();
|
||||
$buyerUserIdKeyByNameMap = User::query()->whereIn("name", $buyerNames)->get()
|
||||
->pluck("id", "name")->toArray();
|
||||
$expireDay = DeveloperConfigService::getDefaultExpireDay();
|
||||
$today = DateTimeUtils::getToday();
|
||||
//excel字段排序 編碼 商品名稱 导购數量 成本价 采购人名称 供应商名称 保质期
|
||||
foreach ($collection as $row) {
|
||||
if (!isset($hasGoodsSkus[$row[0]])) {
|
||||
@ -50,12 +62,14 @@ class PurchaseImport implements ToArray, SkipsEmptyRows
|
||||
$goodsSkuItem = $hasGoodsSkus[$row[0]];
|
||||
//保存記錄
|
||||
$purchaseRecords = new PurchaseRecords();
|
||||
$purchaseRecords->sku_id = $goodsSkuItem['id'] ?? 0;
|
||||
$purchaseRecords->external_sku_id = $row[0];
|
||||
$purchaseRecords->num = $row[2];
|
||||
$purchaseRecords->cost = $row[3];
|
||||
$purchaseRecords->date = $today;
|
||||
$purchaseRecords->buyer_user_id = $buyerUserIdKeyByNameMap[$row[4]] ?? 0;
|
||||
$purchaseRecords->buyer_name = $row[4] ?? '';
|
||||
$purchaseRecords->supplier_name = $row[5] ?? '';
|
||||
$purchaseRecords->supplier_id = $supplierIdKeyByNameMap[$row[5]] ?? 0;
|
||||
$purchaseRecords->expire_time = !empty($row[6]) ? Carbon::parse($row[6])->toDateTimeString()
|
||||
: Carbon::now()->addDays($expireDay)->toDateTimeString();
|
||||
$purchaseRecords->save();
|
||||
|
||||
@ -15,19 +15,19 @@ class CreatePurchaseRecordsTable extends Migration
|
||||
{
|
||||
Schema::create('purchase_records', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->bigInteger('sku_id')->nullable()->comment('goods sku表的id');
|
||||
$table->string('external_sku_id')->comment('唯一sku标识');
|
||||
$table->date('date')->nullable()->comment('日期');;
|
||||
$table->Integer('num')->default(0)->comment('采购数量');
|
||||
$table->unsignedDecimal('cost')->default(0)->comment('成本');
|
||||
$table->Integer('buyer_user_id')->default(0)->comment('购买人用户id');;
|
||||
$table->string('buyer_name')->nullable()->comment('采购人');
|
||||
$table->string('status')->default(0)->comment('盘点完近似状态 0未完成1已售卖完成');
|
||||
$table->string('check_status')->default(0)->comment('盘点完近似状态 0未完成1已售卖完成');
|
||||
$table->string('expire_time')->nullable()->comment('保质期时间');
|
||||
$table->string('supplier_name')->nullable()->comment('供应商名称');
|
||||
$table->Integer('supplier_id')->nullable()->comment('供应商id');
|
||||
// 索引
|
||||
$table->index('sku_id');
|
||||
$table->index('external_sku_id');
|
||||
$table->index('status');
|
||||
$table->index('check_status');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
@ -15,14 +15,14 @@ class CreateLossRecordsTable extends Migration
|
||||
{
|
||||
Schema::create('loss_records', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->bigInteger('sku_id')->nullable()->comment('goods sku表的id');
|
||||
$table->string('external_sku_id')->comment('唯一sku标识');
|
||||
$table->date('date')->nullable()->comment('日期');;
|
||||
$table->Integer('num')->default(0)->comment('报损数量');
|
||||
$table->unsignedDecimal('cost')->default(0)->comment('成本');
|
||||
$table->Integer('buyer_user_id')->default(0)->comment('购买人用户id');;
|
||||
$table->string('buyer_name')->nullable()->comment('采购人');
|
||||
$table->string('reason')->nullable()->comment('报损原因');
|
||||
// 索引
|
||||
$table->index('sku_id');
|
||||
$table->index('external_sku_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@ -28,6 +28,9 @@ class AddOrderTotalAmountToDailyStockRecord extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
if (Schema::hasColumn('daily_stock_records', 'order_total_amount')) {
|
||||
return;
|
||||
}
|
||||
Schema::table('daily_stock_record', function (Blueprint $table) {
|
||||
//
|
||||
$table->dropColumn('order_total_amount');
|
||||
|
||||
@ -28,8 +28,8 @@ class CreateBusinessAfterSaleOrders extends Migration
|
||||
$table->json('image_list')->nullable()->comment('图片列表');
|
||||
$table->json('return_goods_extension')->nullable()->comment('退款物流信息');
|
||||
$table->integer('apply_type')->default(0)->comment('售后单类型 0-仅退款 1-退货退款');
|
||||
$table->string('after_sale_created_at')->nullable()->comment('售后单三方创建时间');
|
||||
$table->string('after_sale_updated_at')->nullable()->comment('售后单三方更新时间');
|
||||
$table->dateTime('after_sale_created_at')->nullable()->comment('售后单三方创建时间');
|
||||
$table->dateTime('after_sale_updated_at')->nullable()->comment('售后单三方更新时间');
|
||||
|
||||
$table->unique(["shop_id",'order_sn']);
|
||||
$table->index('order_sn');
|
||||
|
||||
@ -13,8 +13,6 @@ class CheckPriceTest extends TestCase
|
||||
*/
|
||||
public function testBasicTest()
|
||||
{
|
||||
$checkPrice =new \App\Console\Commands\CheckPrice();
|
||||
$checkPrice->handle();
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user