ShopController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019-05-06
  6. * Time: 16:01
  7. */
  8. namespace App\Http\Controllers\V1;
  9. use App\Shop;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\Validator;
  12. class ShopController extends Controller {
  13. /**
  14. * @param Request $request
  15. * @return array
  16. * 获取商户详情
  17. */
  18. public function getShop(Request $request){
  19. $data = $request->only('id');
  20. $validator = Validator::make($data, [
  21. 'id' => 'required|integer',
  22. ]);
  23. if ($validator->fails()) {
  24. return $this->jsonError($validator->errors()->first());
  25. }
  26. $res['data'] = Shop::where('shop_id',$data['id'])->first();
  27. if($res){
  28. return $this->jsonSuccess(['data'=>$res]);
  29. }else{
  30. return $this->jsonError('获取失败');
  31. }
  32. }
  33. /**
  34. * @param Request $request
  35. * @return array
  36. * 根据ids 获取商户
  37. */
  38. public function getShopList(Request $request){
  39. $data = $request->only('ids');
  40. $validator = Validator::make($data, [
  41. 'ids' => 'required|array',
  42. ]);
  43. if ($validator->fails()) {
  44. return $this->jsonError($validator->errors()->first());
  45. }
  46. $shop = Shop::whereIn('shop_id',$data['ids'])->where('status',0)->select('shop_id','shop_name')->get();
  47. if($shop){
  48. return $this->jsonSuccess($shop);
  49. }else{
  50. return $this->jsonError('失败未找到');
  51. }
  52. }
  53. }