diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 6de1491..7a1804e 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -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('全部下架'); diff --git a/app/Exports/GoodsSkusExport.php b/app/Exports/GoodsSkusExport.php index dbec937..cc5a781 100644 --- a/app/Exports/GoodsSkusExport.php +++ b/app/Exports/GoodsSkusExport.php @@ -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'); + } } diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index 73b3f02..1c8635f 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -72,7 +72,7 @@ class GoodsSkusController extends Controller $query->where('day', $day); }]) ->orderBy('updated_at', 'desc') - ->paginate($request->get('per_page')); + ->paginate(10); foreach ($goodsSkus as &$sku) { $externalSkuId = $sku['goods']['goods_code'] . '_' . $sku['sku_code']; $lastInventoryTime = $sku['daily']['inventory_time']; diff --git a/app/Services/Business/KuaiTuanTuan/Goods.php b/app/Services/Business/KuaiTuanTuan/Goods.php index 4a9b981..6e1bfac 100644 --- a/app/Services/Business/KuaiTuanTuan/Goods.php +++ b/app/Services/Business/KuaiTuanTuan/Goods.php @@ -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]; + } } diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php index e7ebc08..7ff3f74 100644 --- a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -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); + } } diff --git a/resources/frontend/src/views/index.vue b/resources/frontend/src/views/index.vue index 0b833c6..6fc0fbd 100644 --- a/resources/frontend/src/views/index.vue +++ b/resources/frontend/src/views/index.vue @@ -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;