ShopController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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|string',
  42. ]);
  43. if ($validator->fails()) {
  44. return $this->jsonError($validator->errors()->first());
  45. }
  46. $ids = explode(",", $request['ids']);
  47. $data = [];
  48. foreach ($ids as $v){
  49. $shop = Shop::where('shop_id',$v)->first();
  50. if($shop){
  51. $data[][$shop->shop_id] =$shop->shop_name;
  52. }else{
  53. return $this->jsonError('失败 shop_id '.$v.'未找到');
  54. }
  55. }
  56. return $this->jsonSuccess($data);
  57. }
  58. }