feat: #10000 盘点表导出修改

快团团创建商品/团购
This commit is contained in:
赵世界 2022-10-12 15:26:38 +08:00
parent 466fb4d839
commit d5ac4238e8
6 changed files with 130 additions and 75 deletions

View File

@ -43,6 +43,11 @@ class Test extends Command
*/ */
public function handle() public function handle()
{ {
$shop = Shop::query()->find(1);
$business = BusinessFactory::init()->make($shop->plat_id);
$business->setShop($shop);
var_dump($business->queryGroupStatus());
exit();
// 下架商品 // 下架商品
// GoodsSku::query()->where('status', '<>', 0)->update(['status' => 0]); // GoodsSku::query()->where('status', '<>', 0)->update(['status' => 0]);
// $this->info('全部下架'); // $this->info('全部下架');

View File

@ -2,7 +2,9 @@
namespace App\Exports; namespace App\Exports;
use App\Models\DailyStockRecord;
use App\Models\Log; use App\Models\Log;
use App\Utils\ArrayUtils;
use App\Utils\DateTimeUtils; use App\Utils\DateTimeUtils;
use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\ShouldAutoSize;
@ -40,25 +42,14 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
]; ];
$map = [ $map = [
'cost' => ['成本', '更新前成本', '更新后成本'], 'cost' => ['成本', '更新前成本', '更新后成本'],
'inventory' => ['库存', '盘点', '更新前盘点'], 'inventory' => ['库存', '盘点', '上新'],
]; ];
$headTitle = array_merge($headTitle, $map[$this->type]); $headTitle = array_merge($headTitle, $map[$this->type]);
$day = DateTimeUtils::getToday(); if ('cost' === $this->type) {
$update = []; $update = $this->getChangeCostLogs();
$logs = Log::query() }
->select(['target_id', 'before_update', 'after_update']) if ('inventory' === $this->type) {
->where('target_type', 'goods_sku') $update = $this->getInventoryRecord();
->where('target_field', $this->type)
->where('created_at', '>', $day)
->orderBy('id', 'asc')
->get();
foreach ($logs as $log) {
if ($log['before_update'] != $log['after_update'] || (int)$log['after_update']) {
if (!isset($update[$log['target_id']])) {
$update[$log['target_id']]['before_update'] = $log['before_update'];
}
$update[$log['target_id']]['after_update'] = $log['after_update'];
}
} }
$ids = array_keys($update); $ids = array_keys($update);
if (empty($ids)) { if (empty($ids)) {
@ -69,13 +60,10 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
return $query->whereIn('id', $ids); return $query->whereIn('id', $ids);
}) })
->with(['goods' => function ($query) { ->with(['goods' => function ($query) {
$query->with(['type:id,name', 'brand:id,name']); $query->with(['type:id,name', 'brand:id,name'])
->orderBy('type_id')
->orderBy('brand_id');
}]); }]);
if ('inventory' === $this->type) {
$model->with(['daily' => function ($query) use ($day) {
$query->where('day', $day);
}]);
}
$data = $model->get()->toArray(); $data = $model->get()->toArray();
if (empty($data)) { if (empty($data)) {
return [$headTitle]; return [$headTitle];
@ -95,12 +83,51 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
} }
if ('inventory' === $this->type) { if ('inventory' === $this->type) {
$arr[6] = (string)$item['stock']; $arr[6] = (string)$item['stock'];
$arr[7] = (string)$item['daily']['inventory']; $arr[7] = (string)$update[$item['id']]['inventory'];
$arr[8] = (string)$update[$item['id']]['before_update']; $arr[8] = (string)$update[$item['id']]['arrived_today_num'];
} }
$bodyData[] = $arr; $bodyData[] = $arr;
} }
unset($arr); unset($arr);
return [$headTitle, $bodyData]; return [$headTitle, $bodyData];
} }
private function getChangeCostLogs()
{
$day = DateTimeUtils::getToday();
$logs = Log::query()
->select(['target_id', 'before_update', 'after_update'])
->where('target_type', 'goods_sku')
->where('target_field', 'cost')
->where('created_at', '>', $day)
->orderBy('id', 'asc')
->get();
$update = [];
foreach ($logs as $log) {
if ($log['before_update'] !== $log['after_update'] || (int)$log['after_update']) {
if (!isset($update[$log['target_id']])) {
$update[$log['target_id']]['before_update'] = $log['before_update'];
}
$update[$log['target_id']]['after_update'] = $log['after_update'];
}
}
return $update;
}
private function getInventoryRecord()
{
$day = date('Y-m-d', strtotime('-1 day'));
$records = DailyStockRecord::query()
->select(['sku_id', 'inventory', 'arrived_today_num'])
->where('day', $day)
->where(function ($query) {
$query->where('arrived_today_num', '<>', 0)
->orWhere('inventory', '<>', 0);
})
->get()
->toArray();
return ArrayUtils::index($records, 'sku_id');
}
} }

View File

@ -72,7 +72,7 @@ class GoodsSkusController extends Controller
$query->where('day', $day); $query->where('day', $day);
}]) }])
->orderBy('updated_at', 'desc') ->orderBy('updated_at', 'desc')
->paginate($request->get('per_page')); ->paginate(10);
foreach ($goodsSkus as &$sku) { foreach ($goodsSkus as &$sku) {
$externalSkuId = $sku['goods']['goods_code'] . '_' . $sku['sku_code']; $externalSkuId = $sku['goods']['goods_code'] . '_' . $sku['sku_code'];
$lastInventoryTime = $sku['daily']['inventory_time']; $lastInventoryTime = $sku['daily']['inventory_time'];

View File

@ -73,5 +73,56 @@ class Goods
return [$type, $appendParams]; return [$type, $appendParams];
} }
public static function createSpec()
{
$type = 'pdd.ktt.goods.create.spec';
$appendParams = [
'spec_map' => json_encode([
'字母' => ['A', 'B']
])
];
return [$type, $appendParams];
}
public static function createGroup()
{
$type = 'pdd.ktt.group.create';
$skuList = [
'external_sku_id' => 'world_123',
'price_in_fen' => 1000000,
'quantity_type' => 0,
'spec_id_list' => [3908559014],
'total_quantity' => 10,
];
$goods = [
'category_name' => '分类名',
'goods_desc' => '测试使用',
'goods_name' => '字母a',
'limit_buy' => 1,
'market_price' => 100000,
'sku_list' => [$skuList]
];
$appendParams = [
'end_time' => 1667385374000,
'goods_list' => json_encode([$goods]),
'is_save_preview' => 0,
'start_time' => 1665385374000,
'title' => '世界鲜花团购大赏',
];
return [$type, $appendParams];
}
public static function queryGroupStatus()
{
$type = 'pdd.ktt.group.query.status';
$appendParams = [
'activity_no' => '0d0t6e4ji-KSYKxdgpMZHmTqFwU0p1Qg'
];
return [$type, $appendParams];
}
} }

View File

@ -150,4 +150,25 @@ class KuaiTuanTuan extends BusinessClient
return "https://oauth.pinduoduo.com/authorize/ktt?client_id={$this->clientId}&redirect_uri={$this->redirectUri}&state={$state}"; return "https://oauth.pinduoduo.com/authorize/ktt?client_id={$this->clientId}&redirect_uri={$this->redirectUri}&state={$state}";
} }
public function createSku()
{
[$type, $appendParams] = Goods::createSpec();
return $this->doRequest($type, $appendParams);
}
public function createGroup()
{
[$type, $appendParams] = Goods::createGroup();
return $this->doRequest($type, $appendParams);
}
public function queryGroupStatus()
{
[$type, $appendParams] = Goods::queryGroupStatus();
return $this->doRequest($type, $appendParams);
}
} }

View File

@ -93,76 +93,27 @@ export default {
}, },
}, },
methods: { methods: {
/**
* @author: czw (725551805@qq.com)
* @description: 滚动条下一个
* @param {*}
* @return {*}
* @Date: 2022-03-02 19:50:50
*/
next() { next() {
this.hanletop(); this.hanletop();
}, },
/**
* @author: czw (725551805@qq.com)
* @description: 滚动最底部
* @param {*}
* @return {*}
* @Date: 2022-03-02 19:51:03
*/
hanletop() { hanletop() {
document.getElementById("bottom").scrollIntoView({ behavior: "smooth" }); document.getElementById("bottom").scrollIntoView({ behavior: "smooth" });
}, },
/**
* @author: czw (725551805@qq.com)
* @description: 滚动最顶部
* @param {*}
* @return {*}
* @Date: 2022-03-02 19:51:07
*/
hanlebottom() { hanlebottom() {
document.getElementById("top").scrollIntoView({ behavior: "smooth" }); document.getElementById("top").scrollIntoView({ behavior: "smooth" });
}, },
/**
* @author: czw (725551805@qq.com)
* @description: 退出登录
* @param {*}
* @return {*}
* @Date: 2022-03-02 09:41:37
*/
hanleLogout() { hanleLogout() {
removeToken(); removeToken();
this.$router.push({ path: "/Login" }); this.$router.push({ path: "/Login" });
}, },
/**
* @author: czw (725551805@qq.com)
* @description: table页跳转
* @param {*}
* @return {*}
* @Date: 2022-03-01 22:27:27
*/
handlerclick(e) { handlerclick(e) {
if (this.$route.path !== e) { if (this.$route.path !== e) {
this.$router.push({ path: e }); this.$router.push({ path: e });
} }
}, },
/**
* @author: czw (725551805@qq.com)
* @description: 导航栏折叠
* @param {*}
* @return {*}
* @Date: 2022-03-01 22:25:47
*/
add() { add() {
this.show = !this.show; this.show = !this.show;
}, },
/**
* @author: czw (725551805@qq.com)
* @description: 删除
* @param {*}
* @return {*}
* @Date: 2022-03-01 16:53:49
*/
hanblDelete(index, titie) { hanblDelete(index, titie) {
var list = this.levelData[index].name; var list = this.levelData[index].name;