feat: #100000 基础完成
This commit is contained in:
parent
21cd070e92
commit
dd84256472
35
app/Events/GroupSetEvent.php
Normal file
35
app/Events/GroupSetEvent.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class GroupSetEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $groupId;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($groupId)
|
||||
{
|
||||
$this->groupId = $groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Group;
|
||||
|
||||
use App\Events\GroupSetEvent;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\GroupsRequest;
|
||||
use App\Http\Resources\GoodsSkuResource;
|
||||
@ -86,6 +87,7 @@ class GroupsController extends Controller
|
||||
}
|
||||
(new GroupGoods())->batchInsert($groupGoods);
|
||||
DB::commit();
|
||||
event(new GroupSetEvent($group->id));
|
||||
} catch (\Exception $exception) {
|
||||
DB::rollBack();
|
||||
$this->res = [
|
||||
@ -153,6 +155,7 @@ class GroupsController extends Controller
|
||||
);
|
||||
}
|
||||
DB::commit();
|
||||
event(new GroupSetEvent($id));
|
||||
} catch (\Exception $exception) {
|
||||
DB::rollBack();
|
||||
$this->res = [
|
||||
|
||||
37
app/Listeners/GroupQueryListener.php
Normal file
37
app/Listeners/GroupQueryListener.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\GroupSetEvent;
|
||||
use App\Models\Groups;
|
||||
use App\Models\Shop;
|
||||
use App\Services\Business\BusinessFactory;
|
||||
|
||||
class GroupQueryListener
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param GroupSetEvent $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(GroupSetEvent $event)
|
||||
{
|
||||
$shopId = Groups::query()->where('group_Id', $event->groupId)->value('shop_id');
|
||||
$shop = Shop::query()->find($shopId);
|
||||
$client = BusinessFactory::init()->make($shop['plat_id'])->setShopWithId($shop['id']);
|
||||
$client->createGroup($event->groupId);
|
||||
sleep(1);
|
||||
$client->queryGroupStatus($event->groupId);
|
||||
}
|
||||
}
|
||||
@ -2,13 +2,14 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Listeners\StockWarning;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use App\Listeners\UpdateBusinessGoodsStock;
|
||||
use App\Events\BusinessOrdersUpdate;
|
||||
use App\Events\GroupSetEvent;
|
||||
use App\Events\StockUpdateEvent;
|
||||
use App\Listeners\GroupQueryListener;
|
||||
use App\Listeners\StockUpdateListener;
|
||||
use App\Listeners\StockWarning;
|
||||
use App\Listeners\UpdateBusinessGoodsStock;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
@ -26,6 +27,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
StockUpdateListener::class,
|
||||
StockWarning::class,
|
||||
],
|
||||
GroupSetEvent::class => [
|
||||
GroupQueryListener::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -85,44 +85,5 @@ class Goods
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
57
app/Services/Business/KuaiTuanTuan/Groups.php
Normal file
57
app/Services/Business/KuaiTuanTuan/Groups.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Business\KuaiTuanTuan;
|
||||
|
||||
use App\Models\Groups as GroupsModel;
|
||||
use App\Models\GroupGoods;
|
||||
|
||||
class Groups
|
||||
{
|
||||
public static function createGroup($localGroupId)
|
||||
{
|
||||
$type = 'pdd.ktt.group.create';
|
||||
$group = GroupsModel::query()->find($localGroupId);
|
||||
$groupGoods = GroupGoods::query()
|
||||
->where('group_id', $group->id)
|
||||
->with(['goodsSku:id,stock'])
|
||||
->get();
|
||||
$goodsSkus = [];
|
||||
foreach ($groupGoods as $item) {
|
||||
$goodsSkus[] = [
|
||||
'category_name' => $item['category_name'],
|
||||
'goods_desc' => $item['goods_desc'],
|
||||
'goods_name' => $item['goods_name'],
|
||||
'limit_buy' => $item['limit_buy'],
|
||||
'market_price' => $item['market_price'],
|
||||
'sku_list' => [
|
||||
'external_sku_id' => $item['external_sku_id'],
|
||||
'price_in_fen' => $item['price_in_fen'],
|
||||
'quantity_type' => 0,
|
||||
'spec_id_list' => [],
|
||||
'total_quantity' => $item['goodsSku']['stock'],
|
||||
]
|
||||
];
|
||||
}
|
||||
$appendParams = [
|
||||
'end_time' => $group['end_time'] * 1000,
|
||||
'goods_list' => json_encode([$goodsSkus]),
|
||||
'is_save_preview' => $group['is_save_preview'],
|
||||
'start_time' => $group['start_time'] * 1000,
|
||||
'title' => $group['title'],
|
||||
];
|
||||
|
||||
return [$type, $appendParams];
|
||||
}
|
||||
|
||||
public static function queryGroupStatus($localGroupId)
|
||||
{
|
||||
$type = 'pdd.ktt.group.query.status';
|
||||
$group = GroupsModel::query()->find($localGroupId);
|
||||
$appendParams = [
|
||||
'activity_no' => $group->activity_no
|
||||
];
|
||||
|
||||
return [$type, $appendParams];
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,9 @@ namespace App\Services\Business\KuaiTuanTuan;
|
||||
|
||||
use App\Models\BusinessGoodsSku;
|
||||
use App\Models\GoodsSku;
|
||||
use App\Models\GroupGoods;
|
||||
use App\Services\Business\BusinessClient;
|
||||
use App\Models\Groups as GroupsModel;
|
||||
|
||||
class KuaiTuanTuan extends BusinessClient
|
||||
{
|
||||
@ -158,17 +160,40 @@ class KuaiTuanTuan extends BusinessClient
|
||||
return $this->doRequest($type, $appendParams);
|
||||
}
|
||||
|
||||
public function createGroup()
|
||||
public function createGroup($localGroupId)
|
||||
{
|
||||
[$type, $appendParams] = Goods::createGroup();
|
||||
|
||||
return $this->doRequest($type, $appendParams);
|
||||
[$type, $appendParams] = Groups::createGroup($localGroupId);
|
||||
$res = $this->doRequest($type, $appendParams);
|
||||
if (isset($res['response']['success'])) {
|
||||
$group = GroupsModel::query()->find($localGroupId);
|
||||
$group->activity_no = $res['response']['activity_no'];
|
||||
$group->save();
|
||||
}
|
||||
|
||||
public function queryGroupStatus()
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function queryGroupStatus($localGroupId)
|
||||
{
|
||||
[$type, $appendParams] = Goods::queryGroupStatus();
|
||||
[$type, $appendParams] = Groups::queryGroupStatus($localGroupId);
|
||||
$res = $this->doRequest($type, $appendParams);
|
||||
if (isset($res['response'])) {
|
||||
$group = GroupsModel::query()->find($localGroupId);
|
||||
$group->error_msg = $res['response']['error_msg'];
|
||||
$group->qr_code_url = $res['response']['qr_code_url'];
|
||||
$group->status = $res['response']['status'];
|
||||
$group->save();
|
||||
foreach ($res['response']['goods_list'] as $goods) {
|
||||
$groupGoods = GroupGoods::query()
|
||||
->where('group_id', $localGroupId)
|
||||
->where('external_sku_id', $goods['external_sku_id'])
|
||||
->find();
|
||||
$groupGoods->erp_goods_id = $goods['goods_id'];
|
||||
$groupGoods->erp_sku_id = $goods['sku_list'][0]['sku_id'];
|
||||
$groupGoods->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->doRequest($type, $appendParams);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user