mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 14:40:44 +00:00
feat: #20220802 数据库修改
This commit is contained in:
parent
ec7704bbb2
commit
3d40201c17
@ -15,7 +15,7 @@
|
|||||||
1. `composer install`
|
1. `composer install`
|
||||||
2. `cp .env.example .env`
|
2. `cp .env.example .env`
|
||||||
3. 修改 .env 配置项为本地配置
|
3. 修改 .env 配置项为本地配置
|
||||||
4. 创建数据库 `CREATE DATABASE IF NOT EXISTS `erp` DEFAULT CHARACTER SET utf8;`
|
4. 创建数据库 `CREATE DATABASE IF NOT EXISTS `erp` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;`
|
||||||
5. `php artisan migrate` 如果数据填充没有执行成功,则需要再次执行 `php artisan migrate:fresh --seed`
|
5. `php artisan migrate` 如果数据填充没有执行成功,则需要再次执行 `php artisan migrate:fresh --seed`
|
||||||
6. `php artisan key:generate`
|
6. `php artisan key:generate`
|
||||||
7. `php artisan update:super_admin_permissions` 更新超级管理员角色权限
|
7. `php artisan update:super_admin_permissions` 更新超级管理员角色权限
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$shop = Shop::query()->find(2);
|
$shop = Shop::query()->find(1);
|
||||||
$business = BusinessFactory::init()->make($shop->plat_id);
|
$business = BusinessFactory::init()->make($shop->plat_id);
|
||||||
$business->setShop($shop);
|
$business->setShop($shop);
|
||||||
// 下载商品列表
|
// 下载商品列表
|
||||||
@ -55,7 +55,7 @@ class Test extends Command
|
|||||||
// 订单下载
|
// 订单下载
|
||||||
$beginTime = DateTimeUtils::getMicroTime('2022-08-08');
|
$beginTime = DateTimeUtils::getMicroTime('2022-08-08');
|
||||||
$endTime = DateTimeUtils::getMicroTime('2022-08-09');
|
$endTime = DateTimeUtils::getMicroTime('2022-08-09');
|
||||||
$business->downloadOrders($beginTime, $endTime);
|
$business->downloadOrdersAndSave($beginTime, $endTime);
|
||||||
|
|
||||||
$this->info('执行测试成功');
|
$this->info('执行测试成功');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,8 +52,8 @@ class RegisterController extends Controller
|
|||||||
protected function validator(array $data)
|
protected function validator(array $data)
|
||||||
{
|
{
|
||||||
return Validator::make($data, [
|
return Validator::make($data, [
|
||||||
'name' => ['required', 'string', 'unique:users', 'max:255'],
|
'name' => ['required', 'string', 'unique:users', 'max:191'],
|
||||||
'email' => ['string', 'email', 'max:255', 'unique:users'],
|
'email' => ['string', 'email', 'max:191', 'unique:users'],
|
||||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||||
'role_id' => ['required', 'numeric', 'exists:roles,id'],
|
'role_id' => ['required', 'numeric', 'exists:roles,id'],
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class GoodsBrandsController extends Controller
|
|||||||
{
|
{
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'names' => 'required|array',
|
'names' => 'required|array',
|
||||||
'names.*' => 'required|string|max:255|unique:goods_brands,name',
|
'names.*' => 'required|string|max:191|unique:goods_brands,name',
|
||||||
]);
|
]);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
||||||
@ -68,7 +68,7 @@ class GoodsBrandsController extends Controller
|
|||||||
'name' => [
|
'name' => [
|
||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
||||||
'max:255',
|
'max:191',
|
||||||
Rule::unique('goods_brands')->ignore($id),
|
Rule::unique('goods_brands')->ignore($id),
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -336,7 +336,6 @@ class GoodsSkusController extends Controller
|
|||||||
$import = new GoodsSkusImport();
|
$import = new GoodsSkusImport();
|
||||||
$path = $request->file('goodsSkus');
|
$path = $request->file('goodsSkus');
|
||||||
Excel::import($import, $path);
|
Excel::import($import, $path);
|
||||||
$this->setAfterUpdate('');
|
|
||||||
$this->addLog(0, 'import');
|
$this->addLog(0, 'import');
|
||||||
} catch (ValidationException $exception) {
|
} catch (ValidationException $exception) {
|
||||||
$this->setValidatorFailResponse($exception->validator->getMessageBag()->getMessages());
|
$this->setValidatorFailResponse($exception->validator->getMessageBag()->getMessages());
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class GoodsTypesController extends Controller
|
|||||||
{
|
{
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'names' => 'required|array',
|
'names' => 'required|array',
|
||||||
'names.*' => 'required|string|max:255|unique:goods_types,name',
|
'names.*' => 'required|string|max:191|unique:goods_types,name',
|
||||||
]);
|
]);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
||||||
@ -68,7 +68,7 @@ class GoodsTypesController extends Controller
|
|||||||
'name' => [
|
'name' => [
|
||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
||||||
'max:255',
|
'max:191',
|
||||||
Rule::unique('goods_types')->ignore($id),
|
Rule::unique('goods_types')->ignore($id),
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class PermissionsController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'name' => 'required|string|max:255|unique:permissions,name',
|
'name' => 'required|string|max:191|unique:permissions,name',
|
||||||
]);
|
]);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
||||||
@ -63,7 +63,7 @@ class PermissionsController extends Controller
|
|||||||
public function update($id, Request $request)
|
public function update($id, Request $request)
|
||||||
{
|
{
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'name' => ['required', 'string', 'max:255', Rule::unique('permissions')->ignore($id),]
|
'name' => ['required', 'string', 'max:191', Rule::unique('permissions')->ignore($id),]
|
||||||
]);
|
]);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class RolesController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'name' => 'required|string|max:255|unique:roles,name',
|
'name' => 'required|string|max:191|unique:roles,name',
|
||||||
]);
|
]);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
||||||
@ -75,7 +75,7 @@ class RolesController extends Controller
|
|||||||
public function update($id, Request $request)
|
public function update($id, Request $request)
|
||||||
{
|
{
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'name' => ['required', 'string', 'max:255', Rule::unique('roles')->ignore($id),]
|
'name' => ['required', 'string', 'max:191', Rule::unique('roles')->ignore($id),]
|
||||||
]);
|
]);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class ShopsController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'name' => 'required|string|max:255|unique:shops,name',
|
'name' => 'required|string|max:191|unique:shops,name',
|
||||||
'plat_id' => 'required|integer',
|
'plat_id' => 'required|integer',
|
||||||
]);
|
]);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ class UsersController extends Controller
|
|||||||
public function store(Request $request, Faker $faker)
|
public function store(Request $request, Faker $faker)
|
||||||
{
|
{
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'name' => 'required|string|max:255|unique:users,name',
|
'name' => 'required|string|max:191|unique:users,name',
|
||||||
'password' => 'required|string|min:8|confirmed',
|
'password' => 'required|string|min:8|confirmed',
|
||||||
'email' => 'email',
|
'email' => 'email',
|
||||||
'role_name' => 'required|string|exists:roles,name'
|
'role_name' => 'required|string|exists:roles,name'
|
||||||
@ -67,7 +67,7 @@ class UsersController extends Controller
|
|||||||
'name' => [
|
'name' => [
|
||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
||||||
'max:255',
|
'max:191',
|
||||||
Rule::unique('users')->ignore($id),
|
Rule::unique('users')->ignore($id),
|
||||||
],
|
],
|
||||||
// 'old_password' => 'sometimes|required|string|min:8',
|
// 'old_password' => 'sometimes|required|string|min:8',
|
||||||
|
|||||||
@ -26,8 +26,8 @@ class GoodsRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
|
'id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
|
||||||
'title' => ['required', 'string', 'max:255'],
|
'title' => ['required', 'string', 'max:191'],
|
||||||
'img_url' => ['required', 'string', 'max:255'],
|
'img_url' => ['required', 'string', 'max:191'],
|
||||||
'type_id' => ['required', 'integer', 'exists:goods_types,id'],
|
'type_id' => ['required', 'integer', 'exists:goods_types,id'],
|
||||||
'brand_id' => ['integer', 'exists:goods_brands,id'],
|
'brand_id' => ['integer', 'exists:goods_brands,id'],
|
||||||
'goods_code' => ['required', 'alpha_dash', 'max:32', Rule::unique('goods')->ignore(request('goods_id'))],
|
'goods_code' => ['required', 'alpha_dash', 'max:32', Rule::unique('goods')->ignore(request('goods_id'))],
|
||||||
|
|||||||
@ -27,7 +27,7 @@ class GoodsSkuRequest extends FormRequest
|
|||||||
return [
|
return [
|
||||||
'id' => ['sometimes', 'required', 'integer', 'exists:goods_skus,id'],
|
'id' => ['sometimes', 'required', 'integer', 'exists:goods_skus,id'],
|
||||||
'goods_id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
|
'goods_id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
|
||||||
'title' => ['sometimes', 'required', 'string', 'max:255'],
|
'title' => ['sometimes', 'required', 'string', 'max:191'],
|
||||||
'sku_code' => ['sometimes', 'required', 'distinct', 'alpha_dash', 'max:32'],
|
'sku_code' => ['sometimes', 'required', 'distinct', 'alpha_dash', 'max:32'],
|
||||||
'status' => ['sometimes', 'required', 'integer', Rule::in([0, 1, 2])],
|
'status' => ['sometimes', 'required', 'integer', Rule::in([0, 1, 2])],
|
||||||
'num' => ['sometimes', 'required', 'integer'],
|
'num' => ['sometimes', 'required', 'integer'],
|
||||||
|
|||||||
@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Imports;
|
namespace App\Imports;
|
||||||
|
|
||||||
|
use App\Models\DailyStockRecord;
|
||||||
use App\Models\Goods;
|
use App\Models\Goods;
|
||||||
use App\Models\GoodsBrand;
|
use App\Models\GoodsBrand;
|
||||||
use App\Models\GoodsSku;
|
use App\Models\GoodsSku;
|
||||||
use App\Models\GoodsType;
|
use App\Models\GoodsType;
|
||||||
|
use App\Utils\DateTimeUtils;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||||
@ -30,11 +33,11 @@ class GoodsSkusImport implements ToCollection, SkipsEmptyRows
|
|||||||
unset($collection[0], $collection[1]);
|
unset($collection[0], $collection[1]);
|
||||||
$arr = $collection->toArray();
|
$arr = $collection->toArray();
|
||||||
$validator = Validator::make($arr, [
|
$validator = Validator::make($arr, [
|
||||||
'*.0' => ['required', 'string', 'max:255'],
|
'*.0' => ['required', 'string', 'max:191'],
|
||||||
'*.1' => ['required', 'string', 'max:255', 'exists:goods_types,name'],
|
'*.1' => ['required', 'string', 'max:191', 'exists:goods_types,name'],
|
||||||
'*.2' => ['string', 'max:255', 'exists:goods_brands,name'],
|
'*.2' => ['string', 'max:191', 'exists:goods_brands,name'],
|
||||||
'*.3' => ['required', 'alpha_dash', 'max:32'],
|
'*.3' => ['required', 'alpha_dash', 'max:32'],
|
||||||
'*.4' => ['required', 'string', 'max:255'],
|
'*.4' => ['required', 'string', 'max:191'],
|
||||||
'*.5' => ['required', 'distinct', 'alpha_dash', 'max:32'],
|
'*.5' => ['required', 'distinct', 'alpha_dash', 'max:32'],
|
||||||
'*.6' => ['required', 'string', Rule::in(['下架', '在售', '预警'])],
|
'*.6' => ['required', 'string', Rule::in(['下架', '在售', '预警'])],
|
||||||
'*.7' => ['required', 'max:10'],
|
'*.7' => ['required', 'max:10'],
|
||||||
@ -76,16 +79,33 @@ class GoodsSkusImport implements ToCollection, SkipsEmptyRows
|
|||||||
}
|
}
|
||||||
$skus[] = $sku;
|
$skus[] = $sku;
|
||||||
}
|
}
|
||||||
if ($newGoods) {
|
DB::beginTransaction();
|
||||||
$goods = new Goods();
|
try {
|
||||||
$goods->batchInsert(array_values($newGoods));
|
if ($newGoods) {
|
||||||
$hasGoods = Goods::query()->whereIn('goods_code', array_column($newGoods, 'goods_code'))->get(['id', 'goods_code'])->toArray();
|
$goods = new Goods();
|
||||||
$hasGoods = ArrayUtils::index($hasGoods, 'goods_code');
|
$goods->batchInsert(array_values($newGoods));
|
||||||
foreach ($skus as &$sku) {
|
$hasGoods = Goods::query()->whereIn('goods_code', array_column($newGoods, 'goods_code'))->get(['id', 'goods_code'])->toArray();
|
||||||
$sku['goods_id'] = isset($hasGoods[$sku['goods_id']]) ? $hasGoods[$sku['goods_id']]['id'] : $sku['goods_id'];
|
$hasGoods = ArrayUtils::index($hasGoods, 'goods_code');
|
||||||
|
foreach ($skus as &$newGoodsSku) {
|
||||||
|
$newGoodsSku['goods_id'] = isset($hasGoods[$newGoodsSku['goods_id']]) ? $hasGoods[$newGoodsSku['goods_id']]['id'] : $newGoodsSku['goods_id'];
|
||||||
|
}
|
||||||
|
unset($newGoodsSku);
|
||||||
}
|
}
|
||||||
|
$goodsSku = new GoodsSku();
|
||||||
|
$goodsSku->batchInsert(array_values($skus));
|
||||||
|
$collection = GoodsSku::query()->whereIn('sku_code', array_column($skus, 'sku_code'))->get(['id', 'sku_code'])->toArray();
|
||||||
|
$newRecords = [];
|
||||||
|
foreach ($collection as $sku) {
|
||||||
|
$newRecords[] = [
|
||||||
|
'sku_id' => $sku['id'],
|
||||||
|
'day' => DateTimeUtils::getToday(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$record = new DailyStockRecord();
|
||||||
|
$record->batchInsert($newRecords);
|
||||||
|
DB::commit();
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
DB::rollBack();
|
||||||
}
|
}
|
||||||
$goodsSku = new GoodsSku();
|
|
||||||
$goodsSku->batchInsert(array_values($skus));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,5 +9,29 @@ class BusinessGoodsSku extends Model
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $guarded = [];
|
protected $fillable = [
|
||||||
|
'shop_id',
|
||||||
|
'business_order_id',
|
||||||
|
'already_cancel_number',
|
||||||
|
'cancel_status',
|
||||||
|
'category_name',
|
||||||
|
'external_sku_id',
|
||||||
|
'goods_amount',
|
||||||
|
'goods_cost_price',
|
||||||
|
'goods_id',
|
||||||
|
'goods_name',
|
||||||
|
'goods_number',
|
||||||
|
'goods_price',
|
||||||
|
'goods_purchase_price',
|
||||||
|
'goods_specification',
|
||||||
|
'help_sell_amount',
|
||||||
|
'is_supplier',
|
||||||
|
'need_verification_number',
|
||||||
|
'shipping_status',
|
||||||
|
'sku_id',
|
||||||
|
'sub_order_sn',
|
||||||
|
'theoretically_refund_amount',
|
||||||
|
'thumb_url',
|
||||||
|
'verification_number',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,5 +9,40 @@ class BusinessOrder extends Model
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $guarded = [];
|
protected $fillable = [
|
||||||
|
'shop_id',
|
||||||
|
'receiver_address_detail',
|
||||||
|
'receiver_address_province',
|
||||||
|
'self_pick_site_no',
|
||||||
|
'discount_amount',
|
||||||
|
'theoretical_refund_amount',
|
||||||
|
'receiver_address_district',
|
||||||
|
'verification_status',
|
||||||
|
'inner_transaction_id',
|
||||||
|
'is_supplier',
|
||||||
|
'service_amount',
|
||||||
|
'supply_participate_no',
|
||||||
|
'updated_at',
|
||||||
|
'order_amount',
|
||||||
|
'receiver_address_city',
|
||||||
|
'receiver_name',
|
||||||
|
'business_note',
|
||||||
|
'buyer_memo',
|
||||||
|
'logistics_type',
|
||||||
|
'help_sell_nickname',
|
||||||
|
'activity_title',
|
||||||
|
'after_sales_status',
|
||||||
|
'mall_activity_type',
|
||||||
|
'transaction_id',
|
||||||
|
'activity_no',
|
||||||
|
'confirm_at',
|
||||||
|
'platform_discount_amount',
|
||||||
|
'participate_no',
|
||||||
|
'receiver_mobile',
|
||||||
|
'shipping_status',
|
||||||
|
'shipping_amount',
|
||||||
|
'cancel_status',
|
||||||
|
'nick_name',
|
||||||
|
'order_sn',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ abstract class BusinessClient
|
|||||||
|
|
||||||
abstract public function auth();
|
abstract public function auth();
|
||||||
|
|
||||||
abstract public function downloadGoodsList();
|
abstract public function downloadGoodsListAndBind();
|
||||||
|
|
||||||
abstract public function downloadGoods($skuId);
|
abstract public function downloadGoods($skuId);
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ abstract class BusinessClient
|
|||||||
|
|
||||||
abstract public function incrQuantity($skuId);
|
abstract public function incrQuantity($skuId);
|
||||||
|
|
||||||
abstract public function downloadOrders($beginTime, $endTime, $activityNo = '', $downloadType = 'default');
|
abstract public function downloadOrdersAndSave($beginTime, $endTime, $page = 1, $activityNo = '', $downloadType = 'default');
|
||||||
|
|
||||||
abstract public function saveOrders($orders);
|
abstract public function saveOrders($orders);
|
||||||
|
|
||||||
@ -86,12 +86,8 @@ abstract class BusinessClient
|
|||||||
'form_params' => $params
|
'form_params' => $params
|
||||||
];
|
];
|
||||||
$res = (new Client())->request('POST', $url, $headers);
|
$res = (new Client())->request('POST', $url, $headers);
|
||||||
|
$size = $res->getBody()->getSize();
|
||||||
$res = json_decode($res->getBody()->getContents(), true);
|
$res = json_decode($res->getBody()->getContents(), true);
|
||||||
$disableLogType = [
|
|
||||||
'pdd.ktt.goods.query.list',
|
|
||||||
'pdd.ktt.order.list',
|
|
||||||
'pdd.ktt.increment.order.query'
|
|
||||||
];
|
|
||||||
$log = new Log();
|
$log = new Log();
|
||||||
$log->module = 'plat';
|
$log->module = 'plat';
|
||||||
$log->action = 'POST';
|
$log->action = 'POST';
|
||||||
@ -99,7 +95,7 @@ abstract class BusinessClient
|
|||||||
$log->target_id = $this->skuId;
|
$log->target_id = $this->skuId;
|
||||||
$log->target_field = $params['type'];
|
$log->target_field = $params['type'];
|
||||||
$log->user_id = 1;
|
$log->user_id = 1;
|
||||||
if (!in_array($params['type'], $disableLogType, true)) {
|
if ($size < 64000) {
|
||||||
$log->message = json_encode($res, 256);
|
$log->message = json_encode($res, 256);
|
||||||
}
|
}
|
||||||
$log->save();
|
$log->save();
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class KuaiTuanTuan extends BusinessClient
|
|||||||
return $this->shop;
|
return $this->shop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downloadGoodsList($page = 1)
|
public function downloadGoodsListAndBind($page = 1)
|
||||||
{
|
{
|
||||||
[$type, $appendParams] = Goods::downloadGoods($this->shop->owner_id, $page);
|
[$type, $appendParams] = Goods::downloadGoods($this->shop->owner_id, $page);
|
||||||
$res = $this->doRequest($type, $appendParams);
|
$res = $this->doRequest($type, $appendParams);
|
||||||
@ -67,25 +67,29 @@ class KuaiTuanTuan extends BusinessClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 没有发起售后,未取消的订单
|
* 下载没有发起售后,未取消的订单
|
||||||
*
|
*
|
||||||
* @param $beginTime
|
* @param $beginTime
|
||||||
* @param $endTime
|
* @param $endTime
|
||||||
* @param $activityNo
|
* @param int $page
|
||||||
* @param $downloadType
|
* @param string $activityNo
|
||||||
|
* @param string $downloadType
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function downloadOrders($beginTime, $endTime, $activityNo = '', $downloadType = 'default')
|
public function downloadOrdersAndSave($beginTime, $endTime, $page = 1, $activityNo = '', $downloadType = 'default')
|
||||||
{
|
{
|
||||||
if ('increment' === $downloadType) {
|
if ('increment' === $downloadType) {
|
||||||
[$type, $appendParams] = Order::downloadIncrementOrders($beginTime, $endTime, $activityNo);
|
[$type, $appendParams] = Order::downloadIncrementOrders($beginTime, $endTime, $page);
|
||||||
} else {
|
} else {
|
||||||
[$type, $appendParams] = Order::downloadOrders($beginTime, $endTime, $activityNo);
|
[$type, $appendParams] = Order::downloadOrders($beginTime, $endTime, $page);
|
||||||
}
|
}
|
||||||
$res = $this->doRequest($type, $appendParams);
|
$res = $this->doRequest($type, $appendParams);
|
||||||
|
$this->saveOrders($res['ktt_order_list_response']['order_list']);
|
||||||
|
exit();
|
||||||
return $res['ktt_order_list_response']['order_list'];
|
$pageNum = ceil($res['ktt_order_list_response']['total_count'] / $appendParams['size']);
|
||||||
|
if ($pageNum > $page && 10 >= $page) {
|
||||||
|
$this->downloadOrdersAndSave($beginTime, $endTime, $page + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveOrders($orders)
|
public function saveOrders($orders)
|
||||||
|
|||||||
@ -3,20 +3,21 @@
|
|||||||
namespace App\Services\Business\KuaiTuanTuan;
|
namespace App\Services\Business\KuaiTuanTuan;
|
||||||
|
|
||||||
use App\Models\BusinessOrder;
|
use App\Models\BusinessOrder;
|
||||||
|
use App\Models\BusinessOrderItem;
|
||||||
|
|
||||||
class Order
|
class Order
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 根据成交时间拉取订单列表
|
* 根据成交时间拉取订单列表
|
||||||
*/
|
*/
|
||||||
public static function downloadOrders($beginTime, $endTime, $activityNo)
|
public static function downloadOrders($beginTime, $endTime, $page = 1)
|
||||||
{
|
{
|
||||||
$type = 'pdd.ktt.order.list';
|
$type = 'pdd.ktt.order.list';
|
||||||
$appendParams = [
|
$appendParams = [
|
||||||
'confirm_at_begin' => $beginTime, // 成交启始时间, 必填,毫秒时间戳
|
'confirm_at_begin' => $beginTime, // 成交启始时间, 必填,毫秒时间戳
|
||||||
'confirm_at_end' => $endTime, // 成交结束时间,必填, 毫秒时间戳,成交结束时间 - 成交启始时间 <= 24h
|
'confirm_at_end' => $endTime, // 成交结束时间,必填, 毫秒时间戳,成交结束时间 - 成交启始时间 <= 24h
|
||||||
'page_number' => 1, // 页码, 必填
|
'page_number' => $page, // 页码, 必填
|
||||||
'page_size' => 100, // 数量, 必填, 1~100
|
'page_size' => 1, // 数量, 必填, 1~100
|
||||||
// 非必填
|
// 非必填
|
||||||
// 'activity_no' => $activityNo, // 团号
|
// 'activity_no' => $activityNo, // 团号
|
||||||
'after_sales_status' => 0, // 售后状态, 可选 0-未发起售后 1-退款中 2-退款成功 3-待处理 4-拒绝退款 6-待(顾客)退货 7-待(团长)确认退货 8-(顾客)撤销 9-(系统)关闭
|
'after_sales_status' => 0, // 售后状态, 可选 0-未发起售后 1-退款中 2-退款成功 3-待处理 4-拒绝退款 6-待(顾客)退货 7-待(团长)确认退货 8-(顾客)撤销 9-(系统)关闭
|
||||||
@ -31,13 +32,13 @@ class Order
|
|||||||
/**
|
/**
|
||||||
* 快团团增量查订单
|
* 快团团增量查订单
|
||||||
*/
|
*/
|
||||||
public static function downloadIncrementOrders($beginTime, $endTime, $activityNo)
|
public static function downloadIncrementOrders($beginTime, $endTime, $page = 1)
|
||||||
{
|
{
|
||||||
$type = 'pdd.ktt.increment.order.query';
|
$type = 'pdd.ktt.increment.order.query';
|
||||||
$appendParams = [
|
$appendParams = [
|
||||||
'start_updated_at' => $beginTime, // 更新起始时间
|
'start_updated_at' => $beginTime, // 更新起始时间
|
||||||
'end_updated_at' => $endTime, // 更新结束时间
|
'end_updated_at' => $endTime, // 更新结束时间
|
||||||
'page_number' => 1, // 页码
|
'page_number' => $page, // 页码
|
||||||
'page_size' => 100, // 数量
|
'page_size' => 100, // 数量
|
||||||
// 非必填
|
// 非必填
|
||||||
// 'activity_no' => $activityNo, // 团号
|
// 'activity_no' => $activityNo, // 团号
|
||||||
@ -54,12 +55,13 @@ class Order
|
|||||||
public static function saveOrders(array $orders, $shopId)
|
public static function saveOrders(array $orders, $shopId)
|
||||||
{
|
{
|
||||||
foreach ($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
|
unset($order['custom_item_list'], $order['logistics_list'], $order['gift_order_list']);
|
||||||
$orderRecord = BusinessOrder::updateOrCreate(
|
$orderRecord = BusinessOrder::updateOrCreate(
|
||||||
['shop_id' => $shopId, 'order_sn' => $order['order_sn']],
|
['shop_id' => $shopId, 'order_sn' => $order['order_sn']],
|
||||||
$order
|
$order
|
||||||
);
|
);
|
||||||
foreach ($order['sub_order_list'] as $item) {
|
foreach ($order['sub_order_list'] as $item) {
|
||||||
$orderRecord = BusinessOrder::updateOrCreate(
|
BusinessOrderItem::updateOrCreate(
|
||||||
['shop_id' => $shopId, 'business_order_id' => $orderRecord->id, 'goods_id' => $item['goods_id'], 'sku_id' => $item['sku_id']],
|
['shop_id' => $shopId, 'business_order_id' => $orderRecord->id, 'goods_id' => $item['goods_id'], 'sku_id' => $item['sku_id']],
|
||||||
$item
|
$item
|
||||||
);
|
);
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class MiaoXuan extends BusinessClient
|
|||||||
// TODO: Implement auth() method.
|
// TODO: Implement auth() method.
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downloadGoodsList()
|
public function downloadGoodsListAndBind()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class MiaoXuan extends BusinessClient
|
|||||||
$this->formDataPostRequest($url, $appendParams);
|
$this->formDataPostRequest($url, $appendParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downloadOrders($beginTime, $endTime, $activityNo = '', $downloadType = 'default')
|
public function downloadOrdersAndSave($beginTime, $endTime, $page = 1, $activityNo = '', $downloadType = 'default')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -67,7 +67,7 @@ return [
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'timezone' => 'UTC',
|
'timezone' => 'PRC',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
@ -52,8 +52,8 @@ return [
|
|||||||
'username' => env('DB_USERNAME', ''),
|
'username' => env('DB_USERNAME', ''),
|
||||||
'password' => env('DB_PASSWORD', ''),
|
'password' => env('DB_PASSWORD', ''),
|
||||||
'unix_socket' => env('DB_SOCKET', ''),
|
'unix_socket' => env('DB_SOCKET', ''),
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8mb4',
|
||||||
'collation' => 'utf8_general_ci',
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
'prefix_indexes' => true,
|
'prefix_indexes' => true,
|
||||||
'strict' => true,
|
'strict' => true,
|
||||||
@ -71,7 +71,7 @@ return [
|
|||||||
'database' => env('DB_DATABASE', 'forge'),
|
'database' => env('DB_DATABASE', 'forge'),
|
||||||
'username' => env('DB_USERNAME', 'forge'),
|
'username' => env('DB_USERNAME', 'forge'),
|
||||||
'password' => env('DB_PASSWORD', ''),
|
'password' => env('DB_PASSWORD', ''),
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8mb4',
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
'prefix_indexes' => true,
|
'prefix_indexes' => true,
|
||||||
'schema' => 'public',
|
'schema' => 'public',
|
||||||
@ -86,7 +86,7 @@ return [
|
|||||||
'database' => env('DB_DATABASE', 'forge'),
|
'database' => env('DB_DATABASE', 'forge'),
|
||||||
'username' => env('DB_USERNAME', 'forge'),
|
'username' => env('DB_USERNAME', 'forge'),
|
||||||
'password' => env('DB_PASSWORD', ''),
|
'password' => env('DB_PASSWORD', ''),
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8mb4',
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
'prefix_indexes' => true,
|
'prefix_indexes' => true,
|
||||||
],
|
],
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class CreateUsersTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
Schema::defaultStringLength(191);
|
||||||
Schema::create('users', function (Blueprint $table) {
|
Schema::create('users', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
@ -23,6 +24,8 @@ class CreateUsersTable extends Migration
|
|||||||
$table->softDeletes();
|
$table->softDeletes();
|
||||||
$table->rememberToken();
|
$table->rememberToken();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
// 索引
|
||||||
|
$table->unique('name');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class CreateGoodsTypesTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
Schema::defaultStringLength(191);
|
||||||
Schema::create('goods_types', function (Blueprint $table) {
|
Schema::create('goods_types', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->string('name')->nullable(false);
|
$table->string('name')->nullable(false);
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class CreateGoodsBrandsTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
Schema::defaultStringLength(191);
|
||||||
Schema::create('goods_brands', function (Blueprint $table) {
|
Schema::create('goods_brands', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->string('name')->nullable(false);
|
$table->string('name')->nullable(false);
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class CreateGoodsTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
Schema::defaultStringLength(191);
|
||||||
Schema::create('goods', function (Blueprint $table) {
|
Schema::create('goods', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->string('title')->nullable(false);
|
$table->string('title')->nullable(false);
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class CreateGoodsSkusTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
Schema::defaultStringLength(191);
|
||||||
Schema::create('goods_skus', function (Blueprint $table) {
|
Schema::create('goods_skus', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->unsignedBigInteger('goods_id')->nullable(false)->comment('商品id');
|
$table->unsignedBigInteger('goods_id')->nullable(false)->comment('商品id');
|
||||||
@ -28,6 +29,7 @@ class CreateGoodsSkusTable extends Migration
|
|||||||
$table->unsignedInteger('reserve')->default(0)->comment('预留量');
|
$table->unsignedInteger('reserve')->default(0)->comment('预留量');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
// 索引
|
// 索引
|
||||||
|
$table->unique(['goods_id', 'sku_code']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class CreateMenusTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
Schema::defaultStringLength(191);
|
||||||
Schema::create('menus', function (Blueprint $table) {
|
Schema::create('menus', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->string('code', 32)->nullable(false)->comment('菜单编码');
|
$table->string('code', 32)->nullable(false)->comment('菜单编码');
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class CreateShopsTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
Schema::defaultStringLength(191);
|
||||||
Schema::create('shops', function (Blueprint $table) {
|
Schema::create('shops', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->string('name')->unique();
|
$table->string('name')->unique();
|
||||||
|
|||||||
@ -16,7 +16,7 @@ class CreateBusinessOrdersTable extends Migration
|
|||||||
Schema::create('business_orders', function (Blueprint $table) {
|
Schema::create('business_orders', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->integer('shop_id');
|
$table->integer('shop_id');
|
||||||
$table->bigInteger('activity_no')->nullable();
|
$table->string('activity_no')->nullable();
|
||||||
$table->string('activity_title')->nullable();
|
$table->string('activity_title')->nullable();
|
||||||
$table->bigInteger('after_sales_status')->nullable();
|
$table->bigInteger('after_sales_status')->nullable();
|
||||||
$table->string('business_note')->nullable();
|
$table->string('business_note')->nullable();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user