<?php

namespace App\Http\Controllers\Shop;

use App\Http\Controllers\Controller;
use App\Models\BusinessGoodsSku;
use App\Models\DeveloperConfig;
use App\Models\GoodsSku;
use App\Models\Shop;
use App\Http\Resources\ShopsResource;
use App\Models\ShopSender;
use App\Models\ShopShip;
use App\Services\Business\KuaiTuanTuan\FaceSheet;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use App\Services\Business\BusinessFactory;
use Illuminate\Validation\Rule;
use App\Models\BusinessOrderItem;

class ShopSendsController extends Controller
{
    public function index(Request $request)
    {
        $shopSender = ShopSender::query()->filter()->paginate($request->get('per_page'));

        return JsonResource::collection($shopSender);
    }

    public function store(Request $request)
    {
        $params = $request->validate([
            'id' => 'sometimes',
            'shop_id' => 'required|int',
            'province' => 'required',
            'city' => 'required',
            'district' => 'required',
            'detail' => 'required',
            'name' => 'required',
            'mobile' => 'required',
            'sort' => 'sometimes',
            'wp_code' => 'sometimes',
        ], [
            'shop_id.required' => '请选择店铺',
            'province.required' => '请选择省份',
            'city.required' => '请选择城市',
            'district.required' => '请选择地区',
            'detail.required' => '请填写详细地址',
        ]);
        $params['wp_code'] = $params['wp_code'] ?? 'JD';
        $params['country'] = $params['country'] ?? '中国';
        if (empty($params['id'])) {
            $shopSender = new ShopSender();
            $shopSender->fill($params);
            $shopSender->save();
        } else {
            ShopSender::query()->where('id', $params['id'])->update($params);
        }

        return response($this->res, $this->res['httpCode']);
    }


}
