| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978 |
- <?php
- namespace App\Http\Controllers\Api\V1;
- use App\Models\AlbumAgentModel;
- use App\Models\AlbumBannerModel;
- use App\Models\AlbumCatModel;
- use App\Models\AlbumCommentsModel;
- use App\Models\AlbumFavoriteModel;
- use App\Models\AlbumInformationModel;
- use App\Models\AlbumManufacturerModel;
- use App\Models\AlbumNavModel;
- use App\Models\AlbumNewsModel;
- use App\Models\AlbumProductModel;
- use App\Models\AlbumProductPriceModel;
- use App\Models\AlbumProductStyleModel;
- use App\Models\AlbumUserModel;
- use App\Models\AlbumXyxUserModel;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Validator, Response,Auth;
- use App\Services\Base\ErrorCode;
- use WXBizDataCrypt;
- use EasyWeChat\Factory;
- class AlbumController extends Controller
- {
- private $wechat_app;
- public function albumSetting(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ], [
- 'store_id.required' => '店铺信息未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $store_id = $request->store_id;
- //小程序設置
- $setting = AlbumManufacturerModel::where('store_id',$store_id)->first();
- //轮播图
- $banner = AlbumBannerModel::where('store_id',$store_id)->orderByDesc('sort')->get();
- //底部导航栏
- $navbar = AlbumNavModel::where([['store_id',$store_id],['state',0]])->orderByDesc('sort')->get();
- //顶部菜单栏
- $menus = AlbumNavModel::where([['store_id',$store_id],['state',1]])->orderByDesc('sort')->get();
- $news = AlbumNewsModel::where([['store_id',$store_id]])->orderByDesc('sort')->paginate(5);
- return $this->api(compact('setting','banner','news','navbar','menus'));
- }
- /**
- * @api {post} /api/album/login 登陆(login)
- * @apiDescription 登陆(login)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {string} code 小程序登录生成的code
- * @apiParam {string} nickName 微信昵称
- * @apiParam {string} avatar 微信头像
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- *
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumXcxLogin(Request $request)
- {
- $validator = Validator::make($request->all(),
- [
- 'code' => 'required',
- 'store_id' => 'required'
- /* 'nickName' => 'required',
- 'avatar' => 'required',*/
- ],
- [
- 'code.required' => 'code不能为空!',
- 'store_id.required' => 'store_id不能为空!'
- /*'nickName.required' => 'nickName不能为空!',
- 'avatar.required' => 'avatar不能为空!',*/
- ]
- );
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $storeid = $request->get('store_id');
- $this->wechat_app = AlbumManufacturerModel::where('store_id',$storeid)->first();
- $config = [
- 'app_id' => $this->wechat_app->app_id,
- 'secret' => $this->wechat_app->app_secret,
- // 下面为可选项
- // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
- 'response_type' => 'array',
- ];
- $app = Factory::miniProgram($config);
- $code = $request->get('code');
- $session = $app->auth->session($code);
- \Log::info(json_encode($session));
- $openid = $session['openid'];
- $userinfo = AlbumUserModel::where('wechat_open_id', $openid)->where('store_id',$storeid)->first(['id', 'username','wechat_open_id','avatar']);
- if (!$userinfo) {
- $data['wechat_open_id'] = $openid;
- $data['username'] = $request->get('nickName');
- $data['avatar'] = $request->get('avatar');
- $data['is_dealer'] = 0;
- $userinfo = AlbumUserModel::create($data);
- }
- if (Auth::loginUsingId($userinfo->id)) {
- $user = Auth::user();
- $token = $user->createToken($user->id . '-' . $user->openid)->accessToken;
- return $this->api(compact('token', 'user', 'session_key'));
- } else {
- return $this->error(ErrorCode::INCORRECT_USER_OR_PASS);
- }
- }
- /**
- * @api {post} /api/album/xyx_login 登陆(xyx_login)
- * @apiDescription 登陆(xyx_login)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [code]
- * @apiParam {int} [agent_id] 经销商id
- * @apiParam {int} [store_id] 商户id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImIyNGI3MzY3MDNmZDg3MGFjNTg2MWIxNDUzMDcyYjljYzFmNmJhMzE2NTAxZWVlNGYzM2M5MTIzNzFmNGYzZjg2MTY1M2YxMjE2YzE4OTFiIn0.eyJhdWQiOiI5IiwianRpIjoiYjI0YjczNjcwM2ZkODcwYWM1ODYxYjE0NTMwNzJiOWNjMWY2YmEzMTY1MDFlZWU0ZjMzYzkxMjM3MWY0ZjNmODYxNjUzZjEyMTZjMTg5MWIiLCJpYXQiOjE1NDA3OTYyMTYsIm5iZiI6MTU0MDc5NjIxNiwiZXhwIjoxNTcyMzMyMjE1LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.Ruihvl_HMCAHx9XDfeckz48Q_72kfG7vWDsqDrZWbrjq-yuNpM3LrUF-nlsKjedo97BwU_Apz-jnGVqr0ONKZlH-aBKDmIgM2aUZfFADsHhHNJH_oU2fMe1bOrjfUp-PJxfVWQS8c8h5RYmeqtzAYCKaD4P7OZbLmOX0YosKghpaGtiyE65s6jtrOXRhAzXAhYsZToQNBMokFVRqGih9EWuVp6EVwRtI3cb4IV6iQf08cX9DGlLLBJJzLWR5ZWgxJLAGrj5iMCWBl4JKVR8Fsy-xnx3EtrB7ODpJH6hB_u3XnUSAFuaG-KzMPLsj45iqg2hy53er2xtcfAowQFsPoAbZZu0n8c9hWt4GLemR6N1iZ3LBViv3tL5BK52pinQzAnmvltAhJP1YhfTOOjzkxcYVh2JeJagufEoxeeUarMMn21gQSFEzKFCimI7zZQxhT9leLpUn51DLD8Mu87NpYb3JN-JFbOlIDA7bDN3bNto7uuSuC4eBwPo3Ge0StuW4kjHsDTcrVF2He_8FdrPcPpGcvQsXQgv4vwlEhbL8dTlrOodum7H_tY_qUxUG1pEg6bfpn_82ej-AOSc9xi0nrhdcS9y_Z68rcwOJu8esI1pXm9TeQdZIDG85y_t74At8XN6oFcIM__6_dTne_3DHwijW-uOLupNky-5J4ILmZck",
- * "user": {
- * "user_id": 1,
- * "is_agent": 1,
- * "agent_id": 4
- * }
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumXyxLogin(Request $request)
- {
- $datas = $request->input();
- $validator = Validator::make($request->all(),
- [
- 'code' => 'required',
- 'agent_id' => 'required',
- 'store_id' => 'required'
- ],[
- 'code.required' => 'code不能为空!',
- 'agent_id.required' => 'agent_id不能为空!',
- 'store_id.required' => '站点ID不能为空!'
- ]
- );
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $this->wechat_app = AlbumManufacturerModel::where('store_id',$datas['store_id'])->first();
- if(!$this->wechat_app) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- $config = [
- 'app_id' => $this->wechat_app->xyx_id,
- 'secret' => $this->wechat_app->xyx_secret,
- // 下面为可选项
- // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
- 'response_type' => 'array',
- ];
- $app = Factory::miniProgram($config);
- $res = $app->auth->session($datas['code']);
- // dd($res);
- if (!$res || empty($res['openid'])) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '获取用户OpenId失败!', $validator->messages());
- }
- $session_key = $res['session_key'];
- $check = AlbumXyxUserModel::where('wechat_open_id',$res['openid'])->first();
- if(!$check){
- // $add['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
- $add['wechat_open_id'] = $res['openid'];
- $add['wechat_union_id'] = '';
- //$add['avatar'] = $datas['avatar'];
- $add['is_agent'] = 0;
- $add['store_id'] = $datas['store_id'];
- $res = AlbumXyxUserModel::create($add);
- if($res){
- $check = AlbumXyxUserModel::where('wechat_open_id',$res['openid'])->first();
- $user = [
- 'user_id'=>$check['id'],
- //'avatar'=>$check['avatar'],
- // 'username'=>$check['username'],
- 'is_agent'=>0,
- 'agent_id'=>'',
- ];
- }else{
- $user=[
- 'error'=>1
- ];
- }
- } else {
- //print_r($check);die;
- // $save['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
- // $save['avatar'] = $datas['avatar'];
- //$res = AlbumXyxUserModel::where('wechat_open_id',$res['openid'])->update($save);
- //echo 111;
- //print_r($check);die;
- if($check->is_agent == 1){
- $user_agent = AlbumAgentModel::where('user_id',$check->id)->first();
- $agent_id = $user_agent['id'];
- } else {
- $agent_id = '';
- }
- $user = [
- 'user_id'=>$check->id,
- //'avatar'=>$datas['avatar'],
- //'username'=>$datas['nickName'],
- 'is_agent'=>$check->is_agent,
- 'agent_id'=>$agent_id,
- ];
- }
- if (Auth::loginUsingId($check->id)) {
- $userAuth = Auth::user();
- if($check->is_agent ==1){
- $save['up_agent_id'] = $request->input('agent_id');
- }else{
- $save['up_agent_id'] = 0;
- }
- $userAuth->save();
- $token = $userAuth->createToken($userAuth->id . '-' . $userAuth->openid)->accessToken;
- return $this->api(compact('token', 'user'));
- } else {
- return $this->error(ErrorCode::INCORRECT_USER_OR_PASS);
- }
- }
- /*
- * curl get请求
- */
- public function curl_get($url)
- {
- //初始化
- $ch = curl_init();
- //设置选项,包括URL
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- private function getOpenid($code)
- {
- $api = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->wechat_app->app_id}&secret={$this->wechat_app->app_secret}&js_code={$code}&grant_type=authorization_code";
- $res = $this->curl_get($api);
- $res = json_decode($res, true);
- return $res;
- }
- private function getOpenidxyx($code)
- {
- //$api = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->wechat_app->xyx_id}&secret={$this->wechat_app->xyx_secret}&js_code={$code}&grant_type=authorization_code";
- $api = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->wechat_app->xyx_id}&secret={$this->wechat_app->xyx_secret}&js_code={$code}&grant_type=authorization_code";
- $res = $this->curl_get($api);
- $res = json_decode($res, true);
- return $res;
- }
- /**
- * @api {get} /api/album/goods 商品列表(goods)
- * @apiDescription 商品列表(goods)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [cat_id] 分类id
- * @apiParam {string} [keywords] 关键词.
- * @apiParam {int} [status] 状态 1 只选择热销 2 只选择最新上市 3只选择一个风格 4 同时选择热销和最新上市 5同时选择热销和风格 6同时选择最新上市和风格 7全选 0全不选
- * @apiParam {int} [style] 风格
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "goods": [
- * {
- * "id": 3,
- * "cover_pic": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
- * "name": "简约",
- * "style": "纯白",
- * "hot_cake": 1,
- * "news": 1,
- * "price": ""
- * }
- * ],
- * "name": 品牌名
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumGoods(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'cat_id' => 'required',
- 'store_id' => 'required',
- 'status' => 'required',
- ],[
- 'cat_id.required'=>'缺少分类参数',
- 'store_id.required'=>'缺少商户参数',
- 'status.required'=>'缺少状态参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- //dd($data);
- $cat_id = request('cat_id');
- $store_id = request('store_id');
- $status = request('status');
- $style = request('style');
- if(isset($data['keywords'])&&!empty($data['keywords'])) {
- $keywords = '%'.$data['keywords'].'%';
- $goods = AlbumProductModel::where([['name','like',$keywords],['store_id',$data['store_id']]]);
- } else {
- $goods = AlbumProductModel::where([['cat_id',$cat_id],['store_id',$store_id]]);
- }
- if($status == 1) {
- $goods->where([['hot_cake', 1]]);
- }
- if($status == 2){
- $goods->where('news',1);
- }
- if($status == 3){
- $goods->where('style',$style);
- }
- $goods = $goods->select('id','cover_pic','name','style','hot_cake','news')->orderByDesc('sort')->get();
- foreach($goods as $key =>$val){
- if(isset($data['agent_id'])){
- // dd(111);
- $check = AlbumProductPriceModel::where([['agent_id',$userAuth->up_agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
- if($check){
- $goods[$key]['price'] = $check->price;
- }else{
- $goods[$key]['price'] = '';
- }
- }else{
- $goods[$key]['price'] = '';
- }
- }
- $data =AlbumManufacturerModel::where('store_id',$store_id)->first();
- $name = $data['name'];
- return $this->api(compact('goods','name'));
- }
- /**
- * @api {get} /api/album/goods-detail 商品详细(goods-detail)
- * @apiDescription 商品列表(goods-detail)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [goods_id] 商品id
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "id": 3,
- * "store_id": 0,
- * "cat_id": 9,
- * "specifications_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
- * "style": "纯白",
- * "sort": 11,
- * "cover_pic": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
- * "hot_cake": 1,
- * "news": 1,
- * "detail": "<p>达达娃达娃达娃大青蛙大全大是大非如果v率v恶策但是许多女性的项目部的不行么法可没副本副本副本么方便</p>",
- * "created_at": "2018-05-19 15:09:04",
- * "updated_at": "2018-05-19 15:09:04",
- * "deleted_at": null,
- * "install_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
- * "name": "简约",
- * "detail_pic": ""
- * "price": "",
- * "mobile": "",
- * "address": "",
- * "is_favorite": 1,
- * "favorite_id": 4
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumGoodsDetail(Request $request)
- {
- // $userAuth = AlbumXyxUserModel::find(1);
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'goods_id' => 'required',
- ],[
- 'goods_id.required'=>'缺少商品参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $goods_id = request('goods_id');
- $store_id = request('store_id');
- $goods = AlbumProductModel::where([['id',$goods_id],['store_id',$store_id]])->first();
- if(!empty($goods) && $userAuth->up_agent_id != 0){
- $price = DB::table('album_product_price')->where([['agent_id',$userAuth->up_agent_id],['store_id',$store_id],['product_id',$goods['id']]])->first();
- if(!empty($price)){
- $goods->price = $price->price;
- $goods->mobile = $price->mobile;
- $address = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
- $goods->address = $address;
- }else{
- $goods->price = '';
- $goods->mobile = '';
- $goods->address = '';
- }
- $check_favorite = AlbumFavoriteModel::where([['user_id',$userAuth->id],['store_id',$store_id],['product_id',$goods['id']]])->first();
- // dd($check_favorite);
- if($check_favorite){
- $goods->is_favorite = 1;
- $goods->favorite_id = $check_favorite->id;
- }else{
- $goods->is_favorite = 0;
- $goods->favorite_id = '';
- }
- }
- return $this->api($goods);
- }
- /**
- * @api {get} /api/album/favorite_list 收藏列表(favorite_list)
- * @apiDescription 收藏列表(favorite_list)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": [
- * {
- * "id": 4,
- * "user_id": 1,
- * "deleted_at": null,
- * "created_at": "2018-10-29 15:51:47",
- * "updated_at": "2018-10-29 15:53:15",
- * "product_id": 3,
- * "store_id": 0,
- * "goods": {
- * "id": 3,
- * "store_id": 0,
- * "cat_id": 9,
- * "specifications_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
- * "style": "纯白",
- * "sort": 11,
- * "cover_pic": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
- * "hot_cake": 1,
- * "news": 1,
- * "detail": "<p>达达娃达娃达娃大青蛙大全大是大非如果v率v恶策但是许多女性的项目部的不行么法可没副本副本副本么方便</p>",
- * "created_at": "2018-05-19 15:09:04",
- * "updated_at": "2018-05-19 15:09:04",
- * "deleted_at": null,
- * "install_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
- * "name": "简约",
- * "detail_pic": ""
- * }
- * }
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumFavoriteList(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- $favorite = AlbumFavoriteModel::where([['user_id',$userAuth->id],['store_id',$data['store_id']]])->get();
- foreach ($favorite as $key=>$val) {
- $favorite[$key]['goods'] = AlbumProductModel::where([['id',$val['product_id']],['store_id',$data['store_id']]])->first();
- }
- return $this->api($favorite);
- }
- /**
- * @api {get} /api/album/checklogin 登陆应用(checklogin)
- * @apiDescription 登陆应用(checklogin)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- *
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumchecklogin(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- $favorite = AlbumManufacturerModel::where([['store_id',$data['store_id']]])->first();
- $conf = $favorite->redirectapp;
- return $this->api($conf);
- }
- /**
- * @api {get} /api/album/favorite_del 收藏删除(favorite_del)
- * @apiDescription 收藏删除(favorite_del)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiParam {int} [favorite_id] 收藏id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[]//返回状态
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumFavoriteDel(Request $request)
- {
- //$userAuth = AlbumXyxUserModel::find(1);
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'favorite_id' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'favorite_id.required'=>'缺少收藏参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- $favorite = AlbumFavoriteModel::find($data['favorite_id']);
- if(!$favorite){
- $d = [
- 'code' =>1,
- 'msg' =>'删除失败,或者该收藏已移除',
- ];
- } else {
- $res = $favorite->delete();
- if($res){
- $d = [
- 'code' =>1,
- 'msg' =>'删除成功',
- ];
- } else {
- $d = [
- 'code' =>1,
- 'msg' =>'删除失败,或者该收藏已移除',
- ];
- }
- }
- return $this->api($d);
- }
- /**
- * @api {get} /api/album/add_favorite 添加收藏(add_favorite)
- * @apiDescription 添加收藏(favorite_list)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {int} [product_id] 商品id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": []//返回信息
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumAddFavorite(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'product_id' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'product_id.required'=>'缺少商品参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- $check_user = AlbumXyxUserModel::find($userAuth->id);
- $check_f = AlbumFavoriteModel::where([['user_id',$userAuth->id],['product_id',$data['product_id']]])->first();
- if(!$check_user||$check_f){
- $d = [
- 'code' =>1,
- 'msg' =>'该用户不存在或者已添加',
- ];
- return $this->api($d);
- }
- $data['user_id'] = $userAuth->id;
- $res = AlbumFavoriteModel::create($data);
- if($res){
- $d = [
- 'code' =>0,
- 'msg' =>'success',
- ];
- }else{
- $d = [
- 'code' =>1,
- 'msg' =>'error',
- ];
- }
- return $this->api($d);
- }
- /**
- * @api {get} /api/album/cat 分类列表(cat)
- * @apiDescription 画册分类(cat)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [parent_id] 一级菜单传0 二级菜单的id从一级菜单里面获取
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": [
- * {
- * "id": 9,
- * "name": "圣地亚哥",
- * "parent_id": 0,
- * "level": "00",
- * "pic_url": "http://admin.xcx.com/upload/images/20180518/af6cc8fd71241744ccd638afc6ac25f2.png",
- * "created_at": "2018-05-19 14:55:48",
- * "updated_at": "2018-05-19 14:55:48",
- * "store_id": 0,
- * "deleted_at": null,
- * "sort": 0
- * }
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumCat(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $cat_id = 0;
- $store_id = request('store_id');
- $cats = AlbumCatModel::where([['parent_id',$cat_id],['store_id',$store_id]])->orderByDesc('sort')->get();
- return $this->api($cats);
- }
- /**
- * @api {get} /api/album/style 属性列表(style)
- * @apiDescription 分类样式(style)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": [
- * {
- * "id": 2,
- * "name": "1111",
- * "deleted_at": null,
- * "created_at": "2018-06-05 17:35:08",
- * "updated_at": "2018-06-05 17:35:08",
- * "store_id": 0
- * }
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumStyle(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $store_id = request('store_id');
- $style = AlbumProductStyleModel::where([['store_id',$store_id]])->orderByDesc('id')->get();
- return $this->api($style);
- }
- /**
- * @api {get} /api/album/set-price 经销商修改价格(set-price)
- * @apiDescription 画册(set-price)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [goods_id] 商品id
- * @apiParam {int} [agent_id] 经销商id 模拟值为10
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiParam {int} [type] 修改类型 0 电话 1 价格
- * @apiParam {string} [mobile] 电话号码
- * @apiParam {string} [address] 地址
- * @apiParam {double} [price] 价格
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[
- * "msg":返回信息,
- * "data":修改后价格
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumSetPrice(Request $request)
- {
- $userAuth = Auth('api')->user();
- $data = $request->all();
- //print_r($data);
- $save = array();
- $return_data = array();
- if($data['type'] == 0) {
- $save['mobile'] = $data['mobile'];
- $product = AlbumProductModel::where('store_id',$data['store_id'])->get();
- foreach($product as $key=>$val){
- $check = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
- if(empty($check)){
- $save['agent_id'] = $data['agent_id'];
- $save['store_id'] = $data['store_id'];
- $save['product_id'] = $val['id'];
- $res = AlbumProductPriceModel::create($save);
- }else{
- $res = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$val['id']]])->update($save);
- }
- if(!$res){
- $return['msg'] = 'error';
- return $this->api($return);
- }
- }
- $update_agent['phone'] = $data['mobile'];
- $update_agent['address'] = $data['address'];
- $update_res = AlbumAgentModel::where('id',$data['agent_id'])->update($update_agent);
- if(!$update_res){
- $return['msg'] = 'error';
- return $this->api($return);
- }
- $return_data['mobile'] = $data['mobile'];
- $return_data['address'] = $data['address'];
- $return['msg'] = 'success';
- } elseif ($data['type'] == 1){
- $save['price'] = $data['price'];
- $check = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->first();
- if(empty($check)){
- $save['agent_id'] = $data['agent_id'];
- $save['store_id'] = $data['store_id'];
- $save['product_id'] = $data['goods_id'];
- $res = AlbumProductPriceModel::create($save);
- }else{
- $res = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->update($save);
- }
- if($res){
- $return['msg'] = 'success';
- $return_data['price'] = $data['price'];
- } else {
- $return['msg'] = 'error';
- }
- }
- $return['data'] = $return_data;
- return $this->api($return);
- }
- }
|