mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
feat: #20220809 文件下载
This commit is contained in:
parent
a379270d7c
commit
12b734e916
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\GoodsSku;
|
||||
use App\Models\Shop;
|
||||
use App\Services\Business\BusinessFactory;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class Test extends Command
|
||||
@ -43,12 +43,20 @@ class Test extends Command
|
||||
$shop = Shop::query()->find(2);
|
||||
$business = BusinessFactory::init()->make($shop->plat_id);
|
||||
$business->setShop($shop);
|
||||
// 下载商品
|
||||
$business->downloadGoods(1);
|
||||
// 下载商品列表
|
||||
// $business->downloadGoodsList();
|
||||
|
||||
// 下载单个商品
|
||||
// $business->downloadGoods(1);
|
||||
|
||||
// 库存修改
|
||||
// $business->incrQuantity(1);
|
||||
|
||||
// 订单下载
|
||||
$beginTime = DateTimeUtils::getMicroTime('2022-08-08');
|
||||
$endTime = DateTimeUtils::getMicroTime('2022-08-09');
|
||||
$business->downloadOrders($beginTime, $endTime);
|
||||
|
||||
$this->info('执行测试成功');
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\GoodsSkuRequest;
|
||||
use App\Http\Resources\GoodsResource;
|
||||
use App\Models\Log as LogModel;
|
||||
use App\Utils\FormatUtils;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
@ -69,7 +69,7 @@ class GoodsController extends Controller
|
||||
foreach ($collection as $sku) {
|
||||
$newRecords[] = [
|
||||
'sku_id' => $sku['id'],
|
||||
'day' => FormatUtils::date(),
|
||||
'day' => DateTimeUtils::getToday(),
|
||||
];
|
||||
}
|
||||
$record = new DailyStockRecord();
|
||||
@ -89,6 +89,11 @@ class GoodsController extends Controller
|
||||
|
||||
public function download()
|
||||
{
|
||||
return Storage::download(resource_path('templates/goods_skus_import.xlsx'));
|
||||
$file = resource_path('templates/goods_skus_import.xlsx');
|
||||
$headers = [
|
||||
'Content-Type: application/xlsx',
|
||||
];
|
||||
|
||||
return response()->download($file, 'goods_skus_import.xlsx', $headers);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ use App\Http\Requests\GoodsSkuRequest;
|
||||
use App\Models\Goods;
|
||||
use App\Models\Log;
|
||||
use App\Models\Log as LogModel;
|
||||
use App\Utils\FormatUtils;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\GoodsSku;
|
||||
use App\Http\Resources\GoodsSkuResource;
|
||||
@ -45,7 +45,7 @@ class GoodsSkusController extends Controller
|
||||
->pluck('sku_id')
|
||||
->toArray();
|
||||
}
|
||||
$day = FormatUtils::date();
|
||||
$day = DateTimeUtils::getToday();
|
||||
$goodsSkus = GoodsSku::query()
|
||||
->whereIn('goods_id', $goodsIds)
|
||||
->when($ids, function ($query, $ids) {
|
||||
@ -156,7 +156,7 @@ class GoodsSkusController extends Controller
|
||||
$costLog['after_update'] = $goodsSku->cost;
|
||||
$logs[] = $costLog;
|
||||
// 今日到货
|
||||
$record = DailyStockRecord::query()->where('sku_id', $sku['id'])->where('day', FormatUtils::date())->first(['id', 'arrived_today_num']);
|
||||
$record = DailyStockRecord::query()->where('sku_id', $sku['id'])->where('day', DateTimeUtils::getToday())->first(['id', 'arrived_today_num']);
|
||||
$arrivedLog['target_field'] = 'arrived_today_num';
|
||||
$arrivedLog['before_update'] = $record->arrived_today_num;
|
||||
$record->arrived_today_num += $sku['arrived_today_num'];
|
||||
@ -193,7 +193,7 @@ class GoodsSkusController extends Controller
|
||||
'user_id' => $request->user()->id
|
||||
];
|
||||
// 今日到货
|
||||
$record = DailyStockRecord::query()->where('sku_id', $sku['id'])->where('day', FormatUtils::date())->first(['id', 'inventory']);
|
||||
$record = DailyStockRecord::query()->where('sku_id', $sku['id'])->where('day', DateTimeUtils::getToday())->first(['id', 'inventory']);
|
||||
$inventoryLog['target_field'] = 'inventory';
|
||||
$inventoryLog['before_update'] = $record->inventory;
|
||||
$record->inventory = $sku['inventory'];
|
||||
@ -225,7 +225,7 @@ class GoodsSkusController extends Controller
|
||||
$sku = GoodsSku::query()->where('id', $update['id'])->first(['id', 'two_days_ago_num', 'yesterday_num', 'num', 'stock']);
|
||||
$record = DailyStockRecord::query()
|
||||
->where('sku_id', $sku->id)
|
||||
->where('day', FormatUtils::date())
|
||||
->where('day', DateTimeUtils::getToday())
|
||||
->first();
|
||||
$this->setBeforeUpdate([
|
||||
'two_days_ago_num' => $sku->two_days_ago_num,
|
||||
@ -299,7 +299,7 @@ class GoodsSkusController extends Controller
|
||||
if ('loss_num' === $updateField) {
|
||||
$model = DailyStockRecord::query()
|
||||
->where('sku_id', $id)
|
||||
->where('day', FormatUtils::date())
|
||||
->where('day', DateTimeUtils::getToday())
|
||||
->first(['id', 'loss_num']);
|
||||
$this->log->message = $request->get('reason');
|
||||
$this->setBeforeUpdate($model->loss_num);
|
||||
|
||||
@ -6,8 +6,6 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\Log as LogModel;
|
||||
use App\Models\Menu;
|
||||
use App\Http\Resources\MenusResource;
|
||||
use App\Models\User;
|
||||
use App\Utils\ArrayUtils;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@ -23,7 +23,7 @@ abstract class BusinessClient
|
||||
|
||||
abstract public function incrQuantity($skuId);
|
||||
|
||||
abstract public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default');
|
||||
abstract public function downloadOrders($beginTime, $endTime, $activityNo = '', $downloadType = 'default');
|
||||
|
||||
abstract public function saveOrders($orders);
|
||||
|
||||
@ -92,7 +92,6 @@ abstract class BusinessClient
|
||||
'pdd.ktt.order.list',
|
||||
'pdd.ktt.increment.order.query'
|
||||
];
|
||||
if (!in_array($params['type'], $disableLogType, true)) {
|
||||
$log = new Log();
|
||||
$log->module = 'plat';
|
||||
$log->action = 'POST';
|
||||
@ -100,9 +99,10 @@ abstract class BusinessClient
|
||||
$log->target_id = $this->skuId;
|
||||
$log->target_field = $params['type'];
|
||||
$log->user_id = 1;
|
||||
if (!in_array($params['type'], $disableLogType, true)) {
|
||||
$log->message = json_encode($res, 256);
|
||||
$log->save();
|
||||
}
|
||||
$log->save();
|
||||
|
||||
if (isset($res['error_response'])) {
|
||||
throw new \Exception($res['error_response']['error_msg'], $res['error_response']['error_code']);
|
||||
|
||||
@ -66,7 +66,16 @@ class KuaiTuanTuan extends BusinessClient
|
||||
$this->doRequest($type, $appendParams);
|
||||
}
|
||||
|
||||
public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default')
|
||||
/**
|
||||
* 没有发起售后,未取消的订单
|
||||
*
|
||||
* @param $beginTime
|
||||
* @param $endTime
|
||||
* @param $activityNo
|
||||
* @param $downloadType
|
||||
* @return mixed
|
||||
*/
|
||||
public function downloadOrders($beginTime, $endTime, $activityNo = '', $downloadType = 'default')
|
||||
{
|
||||
if ('increment' === $downloadType) {
|
||||
[$type, $appendParams] = Order::downloadIncrementOrders($beginTime, $endTime, $activityNo);
|
||||
|
||||
@ -18,7 +18,7 @@ class Order
|
||||
'page_number' => 1, // 页码, 必填
|
||||
'page_size' => 100, // 数量, 必填, 1~100
|
||||
// 非必填
|
||||
'activity_no' => $activityNo, // 团号
|
||||
// 'activity_no' => $activityNo, // 团号
|
||||
'after_sales_status' => 0, // 售后状态, 可选 0-未发起售后 1-退款中 2-退款成功 3-待处理 4-拒绝退款 6-待(顾客)退货 7-待(团长)确认退货 8-(顾客)撤销 9-(系统)关闭
|
||||
'cancel_status' => 0, // 取消状态, 可选 0-未取消 1-已取消
|
||||
// 'shipping_status' => '', // 发货状态 0-未发货 1-已发货 2-部分发货 3-已收货
|
||||
@ -40,7 +40,7 @@ class Order
|
||||
'page_number' => 1, // 页码
|
||||
'page_size' => 100, // 数量
|
||||
// 非必填
|
||||
'activity_no' => $activityNo, // 团号
|
||||
// 'activity_no' => $activityNo, // 团号
|
||||
'after_sales_status' => 0, // 售后状态, 可选 0-未发起售后 1-退款中 2-退款成功 3-待处理 4-拒绝退款 6-待(顾客)退货 7-待(团长)确认退货 8-(顾客)撤销 9-(系统)关闭
|
||||
'cancel_status' => 0, // 取消状态, 可选 0-未取消 1-已取消
|
||||
// 'shipping_status' => '', // 发货状态 0-未发货 1-已发货 2-部分发货 3-已收货
|
||||
|
||||
@ -33,7 +33,7 @@ class MiaoXuan extends BusinessClient
|
||||
$this->formDataPostRequest($url, $appendParams);
|
||||
}
|
||||
|
||||
public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default')
|
||||
public function downloadOrders($beginTime, $endTime, $activityNo = '', $downloadType = 'default')
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
34
app/Utils/DateTimeUtils.php
Normal file
34
app/Utils/DateTimeUtils.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
class DateTimeUtils
|
||||
{
|
||||
/**
|
||||
* 今天7点到明天7点算作今天
|
||||
*/
|
||||
public static function getToday()
|
||||
{
|
||||
$time = time();
|
||||
$inventoryTime = strtotime(date('Y-m-d 07:00:00'));
|
||||
if ($time < $inventoryTime) {
|
||||
$time = strtotime('-1 day');
|
||||
}
|
||||
|
||||
return date('Y-m-d', $time);
|
||||
}
|
||||
|
||||
public static function getMicroTime($dateTime = null)
|
||||
{
|
||||
$time = microtime(true);
|
||||
if ($dateTime && is_string($dateTime)) {
|
||||
$time = strtotime($dateTime);
|
||||
}
|
||||
if ($dateTime && is_int($dateTime)) {
|
||||
$time = $dateTime;
|
||||
}
|
||||
$time *= 1000;
|
||||
|
||||
return ceil($time);
|
||||
}
|
||||
}
|
||||
@ -33,18 +33,4 @@ class FormatUtils
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 今天7点到明天7点算作今天
|
||||
*/
|
||||
public static function date()
|
||||
{
|
||||
$time = time();
|
||||
$inventoryTime = strtotime(date('Y-m-d 07:00:00'));
|
||||
if ($time < $inventoryTime) {
|
||||
$time = strtotime('-1 day');
|
||||
}
|
||||
|
||||
return date('Y-m-d', $time);
|
||||
}
|
||||
}
|
||||
|
||||
0
resources/templates/goods_skus_import.xlsx
Normal file → Executable file
0
resources/templates/goods_skus_import.xlsx
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user