123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019-04-28
- * Time: 15:31
- */
- namespace App\Http\Controllers\V1;
- use App\Repositories\ShopRepository;
- use App\Shop;
- use App\ShopAccount;
- use App\Transformers\ShopsTransformer;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Validation\Rule;
- use League\Fractal\Manager;
- use League\Fractal\Resource\Item;
- use League\Fractal\Resource\Collection;
- use League\Fractal\Pagination\IlluminatePaginatorAdapter;
- class ShopController extends Controller {
- public function __construct(ShopRepository $shopRepository)
- {
- $this->shopRepository = $shopRepository;
- }
- //新增商家信息
- public function addShop(Request $request)
- {
- $data = $request->all();
- $validator = Validator::make($data, [
- 'shop_name' => 'required|max:11',
- 'shop_short_name' => 'required|string|max:100',
- 'mobile' => 'required|max:11',
- 'address' => 'required|string',
- 'province_name' => 'required|string|max:50',
- 'province_id' => 'required|integer|max:6',
- 'city_name' => 'required|string:max:50',
- 'city_id' => 'required|integer|max:6',
- 'contact_name' => 'string|max:50',
- 'contact_mobile' => 'max:16',
- 'shop_desc' => 'string|max:500',
- 'status' =>['required',Rule::in([0,1])],
- 'logo_img' => 'string',
- 'license_img' => 'required|string',
- 'food_trans_license' => 'required|string',
- 'other_license' => 'string',
- 'proportion'=>'required|digits_between:1,100|integer',
- 'verify_type'=>['required',Rule::in([0,1])],
- 'account'=>'string|max:20',
- 'password'=>'string|min:6|max:18'
- ]);
- if ($validator->fails()) {
- return $this->jsonError($validator->errors()->first());
- }
- if($data['account']){
- $shop_account = ShopAccount::where(['account'=>$data['account']])->first();
- if($shop_account){
- return $this->jsonError('该账号已存在,请重新输入');
- }
- }
- $shopRepository = new ShopRepository();
- $res = $shopRepository->saveShopAccount($data);
- if($res){
- return $this->jsonSuccess();
- }else{
- return $this->jsonError('添加失败');
- }
- }
- //详情
- public function view(Request $request)
- {
- $data = $request->all();
- $validator = Validator::make($data, [
- 'shop_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return $this->jsonError($validator->errors()->first());
- }
- $shop = Shop::where(['shop_id'=>$data['shop_id']])->first();
- $fractal = new Manager();
- $res = new Item($shop,new ShopsTransformer());
- $data = $fractal->createData($res)->toArray();
- if($data){
- return $this->jsonSuccess($data);
- }else{
- return $this->jsonError("操作失败");
- }
- }
- //列表
- public function list(Request $request){
- $shops = $this->shopRepository->shopList($request->all());
- $fractal = new Manager();
- $resource = new Collection($shops, new ShopsTransformer());
- $resource->setPaginator(new IlluminatePaginatorAdapter($shops));
- $data = $fractal->createData($resource)->toArray();
- $data['extra']['filters'] = ['shop_name','status'];
- $data['extra']['columns'] = ['shop_id','mobile','province_name','city_name','product_count','proportion','status'];
- return $data;
- }
- }
|