commit
4f6a114f5b
@ -43,6 +43,11 @@ class Test extends Command
|
||||
*/
|
||||
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]);
|
||||
// $this->info('全部下架');
|
||||
|
||||
@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\DailyStockRecord;
|
||||
use App\Models\Log;
|
||||
use App\Utils\ArrayUtils;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
@ -40,25 +42,14 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
|
||||
];
|
||||
$map = [
|
||||
'cost' => ['成本', '更新前成本', '更新后成本'],
|
||||
'inventory' => ['库存', '盘点', '更新前盘点'],
|
||||
'inventory' => ['库存', '盘点', '上新'],
|
||||
];
|
||||
$headTitle = array_merge($headTitle, $map[$this->type]);
|
||||
$day = DateTimeUtils::getToday();
|
||||
$update = [];
|
||||
$logs = Log::query()
|
||||
->select(['target_id', 'before_update', 'after_update'])
|
||||
->where('target_type', 'goods_sku')
|
||||
->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'];
|
||||
}
|
||||
if ('cost' === $this->type) {
|
||||
$update = $this->getChangeCostLogs();
|
||||
}
|
||||
if ('inventory' === $this->type) {
|
||||
$update = $this->getInventoryRecord();
|
||||
}
|
||||
$ids = array_keys($update);
|
||||
if (empty($ids)) {
|
||||
@ -69,13 +60,10 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
|
||||
return $query->whereIn('id', $ids);
|
||||
})
|
||||
->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();
|
||||
if (empty($data)) {
|
||||
return [$headTitle];
|
||||
@ -95,12 +83,51 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
|
||||
}
|
||||
if ('inventory' === $this->type) {
|
||||
$arr[6] = (string)$item['stock'];
|
||||
$arr[7] = (string)$item['daily']['inventory'];
|
||||
$arr[8] = (string)$update[$item['id']]['before_update'];
|
||||
$arr[7] = (string)$update[$item['id']]['inventory'];
|
||||
$arr[8] = (string)$update[$item['id']]['arrived_today_num'];
|
||||
}
|
||||
$bodyData[] = $arr;
|
||||
}
|
||||
unset($arr);
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,5 +73,56 @@ class Goods
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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}";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,76 +93,27 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* @author: czw (725551805@qq.com)
|
||||
* @description: 滚动条下一个
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
* @Date: 2022-03-02 19:50:50
|
||||
*/
|
||||
next() {
|
||||
this.hanletop();
|
||||
},
|
||||
/**
|
||||
* @author: czw (725551805@qq.com)
|
||||
* @description: 滚动最底部
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
* @Date: 2022-03-02 19:51:03
|
||||
*/
|
||||
hanletop() {
|
||||
document.getElementById("bottom").scrollIntoView({ behavior: "smooth" });
|
||||
},
|
||||
/**
|
||||
* @author: czw (725551805@qq.com)
|
||||
* @description: 滚动最顶部
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
* @Date: 2022-03-02 19:51:07
|
||||
*/
|
||||
hanlebottom() {
|
||||
document.getElementById("top").scrollIntoView({ behavior: "smooth" });
|
||||
},
|
||||
/**
|
||||
* @author: czw (725551805@qq.com)
|
||||
* @description: 退出登录
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
* @Date: 2022-03-02 09:41:37
|
||||
*/
|
||||
hanleLogout() {
|
||||
removeToken();
|
||||
this.$router.push({ path: "/Login" });
|
||||
},
|
||||
/**
|
||||
* @author: czw (725551805@qq.com)
|
||||
* @description: table页跳转
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
* @Date: 2022-03-01 22:27:27
|
||||
*/
|
||||
handlerclick(e) {
|
||||
if (this.$route.path !== e) {
|
||||
this.$router.push({ path: e });
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @author: czw (725551805@qq.com)
|
||||
* @description: 导航栏折叠
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
* @Date: 2022-03-01 22:25:47
|
||||
*/
|
||||
add() {
|
||||
this.show = !this.show;
|
||||
},
|
||||
/**
|
||||
* @author: czw (725551805@qq.com)
|
||||
* @description: 删除
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
* @Date: 2022-03-01 16:53:49
|
||||
*/
|
||||
hanblDelete(index, titie) {
|
||||
var list = this.levelData[index].name;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user