diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php new file mode 100644 index 0000000..cda01ab --- /dev/null +++ b/app/Console/Commands/Test.php @@ -0,0 +1,48 @@ +find(2); + $business = BusinessFactory::init()->make($shop->plat_id); + $business->setShop($shop); + $res = $business->downloadGoods(); + var_dump($res); + } +} diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index 71a6e25..3cf21f9 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -119,7 +119,8 @@ class GoodsSkusController extends Controller Rule::exists('goods_skus', 'id'), ], ]; - $validator = $this->validateUpdate($request->all(), $appendRules); + $skuRules = (new GoodsSkuRequest())->arrayRules('skus.*.'); + $validator = Validator::make($request->all(), array_merge($appendRules, $skuRules)); if ($validator->fails()) { $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); diff --git a/app/Http/Requests/GoodsSkuRequest.php b/app/Http/Requests/GoodsSkuRequest.php index c403df0..c12ba05 100644 --- a/app/Http/Requests/GoodsSkuRequest.php +++ b/app/Http/Requests/GoodsSkuRequest.php @@ -27,11 +27,11 @@ class GoodsSkuRequest extends FormRequest return [ 'id' => ['sometimes', 'required', 'integer', 'exists:goods_skus,id'], 'goods_id' => ['sometimes', 'required', 'integer', 'exists:goods,id'], - 'title' => ['required', 'string', 'max:255'], - 'sku_code' => ['required', 'distinct', 'alpha_dash', 'max:32'], - 'status' => ['required', 'integer', Rule::in([0, 1, 2])], - 'num' => ['required', 'integer'], - 'cost' => ['required', 'numeric'], + 'title' => ['sometimes', 'required', 'string', 'max:255'], + 'sku_code' => ['sometimes', 'required', 'distinct', 'alpha_dash', 'max:32'], + 'status' => ['sometimes', 'required', 'integer', Rule::in([0, 1, 2])], + 'num' => ['sometimes', 'required', 'integer'], + 'cost' => ['sometimes', 'required', 'numeric'], 'reference_price' => [ 'sometimes', 'numeric', diff --git a/app/Models/Shop.php b/app/Models/Shop.php index cee46e5..f45960b 100644 --- a/app/Models/Shop.php +++ b/app/Models/Shop.php @@ -16,7 +16,9 @@ class Shop extends Model 'pop_auth_token_create_response', ]; - protected $guarded = []; + protected $fillable = [ + 'access_token', 'expires_at', 'expires_in', 'owner_id', 'owner_name', 'refresh_token', 'refresh_token_expires_at', 'refresh_token_expires_in', 'scope', 'pop_auth_token_create_response', 'status' + ]; public function getStatusAttribute($value) { diff --git a/app/Services/Business/BusinessClient.php b/app/Services/Business/BusinessClient.php index af1c81d..4ef76d3 100644 --- a/app/Services/Business/BusinessClient.php +++ b/app/Services/Business/BusinessClient.php @@ -93,6 +93,9 @@ abstract class BusinessClient $log->user_id = 1; $log->message = json_encode($res, 256); $log->save(); + if (isset($res['error_response'])) { + throw new \Exception($res['error_response']['error_msg'], $res['error_response']['error_code']); + } return $res; } diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php index e63da0c..143f07d 100644 --- a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -30,7 +30,9 @@ class KuaiTuanTuan extends BusinessClient public function auth() { $accessToken = $this->getAccessTokenWithCode(); + $accessToken['scope'] = json_encode($accessToken['scope'], 256); $accessToken['pop_auth_token_create_response'] = json_encode($accessToken, 256); + $accessToken['status'] = 1; $this->shop->update($accessToken); return $this->shop; @@ -107,7 +109,7 @@ class KuaiTuanTuan extends BusinessClient 'timestamp' => time() ]; if ('pdd.pop.auth.token.create' !== $type) { - $publicParams['access_token'] = $this->getAccessToken(); + $publicParams['access_token'] = $this->getShop()->access_token; } $publicParams = array_merge($publicParams, $appendParams); $publicParams['sign'] = $this->getSign($publicParams); diff --git a/database/migrations/2022_08_02_022448_create_shops_table.php b/database/migrations/2022_08_02_022448_create_shops_table.php index 7fddb77..2cdeb16 100644 --- a/database/migrations/2022_08_02_022448_create_shops_table.php +++ b/database/migrations/2022_08_02_022448_create_shops_table.php @@ -18,12 +18,12 @@ class CreateShopsTable extends Migration $table->string('name')->unique(); $table->unsignedTinyInteger('plat_id')->comment('平台id'); $table->string('access_token')->nullable(); - $table->unsignedMediumInteger('expires_at')->nullable()->comment('access_token过期时间点'); + $table->unsignedBigInteger('expires_at')->nullable()->comment('access_token过期时间点'); $table->unsignedInteger('expires_in')->nullable()->comment('access_token过期时间段,10(表示10秒后过期)'); $table->string('owner_id')->nullable()->comment('商家店铺id'); $table->string('owner_name')->nullable()->comment('商家账号名称'); $table->string('refresh_token')->nullable()->comment('refresh token,可用来刷新access_token'); - $table->unsignedMediumInteger('refresh_token_expires_at')->nullable()->comment('Refresh token过期时间点'); + $table->unsignedBigInteger('refresh_token_expires_at')->nullable()->comment('Refresh token过期时间点'); $table->unsignedInteger('refresh_token_expires_in')->nullable()->comment('refresh_token过期时间段,10表示10秒后过期'); $table->text('scope')->nullable()->comment('接口列表'); $table->text('pop_auth_token_create_response')->nullable()->comment('授权认证信息'); diff --git a/database/migrations/2022_08_05_030834_create_business_goods_skus_table.php b/database/migrations/2022_08_05_030834_create_business_goods_skus_table.php index 18c9b5b..7a84e15 100644 --- a/database/migrations/2022_08_05_030834_create_business_goods_skus_table.php +++ b/database/migrations/2022_08_05_030834_create_business_goods_skus_table.php @@ -19,27 +19,27 @@ class CreateBusinessGoodsSkusTable extends Migration $table->bigInteger('self_sku_id')->nullable(); $table->string('activity_no')->nullable(); $table->string('category_name')->nullable(); - $table->mediumInteger('create_time')->nullable(); + $table->bigInteger('create_time')->nullable(); $table->text('goods_desc')->nullable(); $table->string('goods_id')->nullable(); $table->text('goods_image_list')->nullable(); $table->string('goods_name')->nullable(); $table->integer('is_activity_delete')->nullable(); $table->integer('limit_buy')->nullable(); - $table->mediumInteger('market_price')->nullable(); - $table->mediumInteger('update_time')->nullable(); + $table->bigInteger('market_price')->nullable(); + $table->bigInteger('update_time')->nullable(); $table->string('external_sku_id')->nullable(); - $table->mediumInteger('goods_purchase_price')->nullable(); - $table->mediumInteger('price_in_fen')->nullable(); - $table->mediumInteger('quantity')->nullable(); + $table->bigInteger('goods_purchase_price')->nullable(); + $table->bigInteger('price_in_fen')->nullable(); + $table->bigInteger('quantity')->nullable(); $table->integer('quantity_type')->nullable(); - $table->mediumInteger('reserve_quantity')->nullable(); - $table->mediumInteger('sku_id')->nullable(); - $table->mediumInteger('sold_quantity')->nullable(); + $table->bigInteger('reserve_quantity')->nullable(); + $table->bigInteger('sku_id')->nullable(); + $table->bigInteger('sold_quantity')->nullable(); $table->text('spec_list')->nullable(); $table->string('spec_name')->nullable(); $table->string('thumb_url')->nullable(); - $table->mediumInteger('total_quantity')->nullable(); + $table->bigInteger('total_quantity')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/2022_08_05_093629_create_business_orders_table.php b/database/migrations/2022_08_05_093629_create_business_orders_table.php index 7561823..69baab2 100644 --- a/database/migrations/2022_08_05_093629_create_business_orders_table.php +++ b/database/migrations/2022_08_05_093629_create_business_orders_table.php @@ -18,22 +18,22 @@ class CreateBusinessOrdersTable extends Migration $table->integer('shop_id'); $table->bigInteger('activity_no')->nullable(); $table->string('activity_title')->nullable(); - $table->mediumInteger('after_sales_status')->nullable(); + $table->bigInteger('after_sales_status')->nullable(); $table->string('business_note')->nullable(); $table->string('buyer_memo')->nullable(); $table->integer('cancel_status')->nullable(); - $table->mediumInteger('confirm_at')->nullable(); - $table->mediumInteger('discount_amount')->nullable(); + $table->bigInteger('confirm_at')->nullable(); + $table->bigInteger('discount_amount')->nullable(); $table->string('help_sell_nickname')->nullable(); $table->string('inner_transaction_id')->nullable(); $table->boolean('is_supplier')->nullable(); $table->integer('logistics_type')->nullable(); $table->integer('mall_activity_type')->nullable(); $table->string('nick_name')->nullable(); - $table->mediumInteger('order_amount')->nullable(); + $table->bigInteger('order_amount')->nullable(); $table->string('order_sn')->nullable(); $table->integer('participate_no')->nullable(); - $table->mediumInteger('platform_discount_amount')->nullable(); + $table->bigInteger('platform_discount_amount')->nullable(); $table->string('receiver_address_city')->nullable(); $table->string('receiver_address_detail')->nullable(); $table->string('receiver_address_district')->nullable(); @@ -46,12 +46,12 @@ class CreateBusinessOrdersTable extends Migration $table->string('self_pick_up_contact_mobile')->nullable(); $table->string('self_pick_up_contact_name')->nullable(); $table->string('self_pick_up_site_name')->nullable(); - $table->mediumInteger('service_amount')->nullable(); - $table->mediumInteger('shipping_amount')->nullable(); + $table->bigInteger('service_amount')->nullable(); + $table->bigInteger('shipping_amount')->nullable(); $table->integer('shipping_status')->nullable(); $table->string('supply_activity_no')->nullable(); $table->integer('supply_participate_no')->nullable(); - $table->mediumInteger('theoretical_refund_amount')->nullable(); + $table->bigInteger('theoretical_refund_amount')->nullable(); $table->string('transaction_id')->nullable(); $table->integer('verification_status')->nullable(); $table->timestamps(); diff --git a/database/migrations/2022_08_05_093658_create_business_order_items_table.php b/database/migrations/2022_08_05_093658_create_business_order_items_table.php index 325103c..0495831 100644 --- a/database/migrations/2022_08_05_093658_create_business_order_items_table.php +++ b/database/migrations/2022_08_05_093658_create_business_order_items_table.php @@ -21,21 +21,21 @@ class CreateBusinessOrderItemsTable extends Migration $table->integer('cancel_status')->nullable(); $table->string('category_name')->nullable(); $table->string('external_sku_id')->nullable(); - $table->mediumInteger('goods_amount')->nullable(); - $table->mediumInteger('goods_cost_price')->nullable(); - $table->mediumInteger('goods_id')->nullable(); + $table->bigInteger('goods_amount')->nullable(); + $table->bigInteger('goods_cost_price')->nullable(); + $table->bigInteger('goods_id')->nullable(); $table->string('goods_name')->nullable(); $table->integer('goods_number')->nullable(); - $table->mediumInteger('goods_price')->nullable(); - $table->mediumInteger('goods_purchase_price')->nullable(); + $table->bigInteger('goods_price')->nullable(); + $table->bigInteger('goods_purchase_price')->nullable(); $table->string('goods_specification')->nullable(); - $table->mediumInteger('help_sell_amount')->nullable(); + $table->bigInteger('help_sell_amount')->nullable(); $table->boolean('is_supplier')->nullable(); $table->integer('need_verification_number')->nullable(); $table->integer('shipping_status')->nullable(); - $table->mediumInteger('sku_id')->nullable(); + $table->bigInteger('sku_id')->nullable(); $table->string('sub_order_sn')->nullable(); - $table->mediumInteger('theoretically_refund_amount')->nullable(); + $table->bigInteger('theoretically_refund_amount')->nullable(); $table->string('thumb_url')->nullable(); $table->integer('verification_number')->nullable(); $table->timestamps();