| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114 |
- <?php
- namespace App\Http\Controllers\Api\V1;
- use App\Models\AgentBannerModel;
- use App\Models\AlbumAgentModel;
- use App\Models\AlbumBannerModel;
- use App\Models\AlbumCatModel;
- use App\Models\AlbumCommentsModel;
- use App\Models\AlbumFavoriteModel;
- use App\Models\AlbumFormId;
- 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\AlbumWatchRecord;
- use App\Models\AlbumXyxUserModel;
- use App\Models\CustomerCatRecordModel;
- use App\Models\CustomerDetailsModel;
- use App\User;
- 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',
- 'nickName' => 'required',
- 'iv' => 'required',
- 'encryptData' => 'required',
- 'avatar' => 'required',
- 'store_id' => 'required'
- ],[
- 'code.required' => 'code不能为空!',
- 'agent_id.required' => 'agent_id不能为空!',
- 'nickName.required' => '昵称不能为空!',
- 'iv.required' => '昵称不能为空!',
- 'encryptData.required' => '昵称不能为空!',
- 'avatar.required' => '头像不能为空!',
- '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 = $res['session_key'];
- $decryptedData = $app->encryptor->decryptData($session, $datas['iv'], $datas['encryptData']);
- dd($decryptedData);die;
- $check = AlbumUserModel::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['model'] = 1;
- $add['store_id'] = $datas['store_id'];
- $res = AlbumUserModel::create($add);
- // dd($res);
- if($res){
- $check = AlbumUserModel::where([['wechat_open_id',$res->wechat_open_id],['store_id',$datas['store_id']]])->first();
- $user = [
- 'user_id'=>$check['id'],
- //'avatar'=>$check['avatar'],
- // 'username'=>$check['username'],
- 'phone'=>$check->phone,
- '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'];
- $save['model'] = 1;
- $res = AlbumUserModel::where('wechat_open_id',$res['openid'])->update($save);
- //echo 111;
- //print_r($check);die;
- if($check->is_dealer == 1){
- $user_agent = AlbumAgentModel::where([['user_id',$check->id],['status',1]])->first();
- $agent_id = $user_agent['id'];
- } else {
- $agent_id = '';
- }
- $user = [
- 'user_id'=>$check->id,
- 'phone'=>$check->phone,
- //'avatar'=>$datas['avatar'],
- //'username'=>$datas['nickName'],
- 'is_agent'=>$check->is_dealer,
- 'agent_id'=>$agent_id,
- ];
- }
- // echo 111;die;
- if (Auth::loginUsingId($check->id)) {
- $userAuth = Auth::user();
- if($check->is_dealer ==0){
- if($request->input('agent_id')!=0){
- $userAuth->up_agent_id = $request->input('agent_id');
- }
- $add_record['agent_id'] = $request->input('agent_id');
- $add_record['open_id'] = $check->wechat_open_id;
- $add_record['action'] = 4;
- $add_record['store_id'] = $datas['store_id'];
- $add_record['detail'] = null;
- AlbumWatchRecord::create($add_record);
- // dd($add_record);
- // print_r($add_record['agent_id']);die;
- $user_agent = AlbumAgentModel::where('id',$add_record['agent_id'])->first();
- //dd($user_agent);
- if($user_agent){
- $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
- try{
- $this->sendLogsMessage($datas['store_id'],$agent->wechat_open_id,4,$userAuth->username);
- }catch (\Exception $e){
- }
- }
- }else{
- $userAuth->up_agent_id = 0;
- }//dd($userAuth);
- $userAuth->save();
- $user['up_agent_id'] = $userAuth->up_agent_id;
- $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();
- if(!$userAuth) return $this->error(ErrorCode::ERROR_POWER, '登陆过期!');
- $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');
- $select_info = ['cat_id'=>$cat_id,'style'=>$style];
- if($userAuth->up_agent_id!=0&&$cat_id!="undefined"&&$style!="undefined"){
- $add_record['agent_id'] = $userAuth->up_agent_id;
- $add_record['open_id'] = $userAuth->wechat_open_id;
- $add_record['action'] = 2;
- $add_record['store_id'] = $store_id;
- $add_record['detail'] = json_encode($select_info);
- AlbumWatchRecord::create($add_record);
- $cat_record['agent_id'] = $userAuth->up_agent_id;
- $cat_record['open_id'] = $userAuth->wechat_open_id;
- $cat_record['store_id'] = $store_id;
- $cat_record['style_id'] = $style;
- $cat_record['cat_id'] = $cat_id;
- CustomerCatRecordModel::create($cat_record);
- $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
- $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
- try{
- $this->sendLogsMessage($store_id,$agent->wechat_open_id,2,$userAuth->username);
- }catch (\Exception $e){
- }
- }
- if(isset($data['keywords'])&&!empty($data['keywords'])) {
- $keywords = '%'.$data['keywords'].'%';
- $goods = AlbumProductModel::where([['name','like',$keywords],['store_id',$data['store_id']],['cat_id',$cat_id],['store_id',$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','price_default')->orderByDesc('sort')->get();
- foreach($goods as $key =>$val){
- if($userAuth->is_dealer != 1){
- if($userAuth->up_agent_id==0){
- $goods[$key]['price'] = '';
- }else{
- $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'] = '';
- }
- }
- }elseif($userAuth->is_dealer == 1){
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- $agent_id = $user_agent['id'];
- $check = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
- if($check){
- $goods[$key]['price'] = $check->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": "",
- * "price_default": "",
- * "mobile": "",
- * "address": "",
- * "realname": "",
- * "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',
- 'store_id' => 'required',
- ],[
- 'goods_id.required'=>'缺少商品参数',
- 'store_id_id.required'=>'缺少STORE参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $goods_id = request('goods_id');
- $store_id = request('store_id');
- $select_info = ['goods_id'=>$goods_id];
- if($userAuth->up_agent_id!=0){
- $add_record['agent_id'] = $userAuth->up_agent_id;
- $add_record['open_id'] = $userAuth->wechat_open_id;
- $add_record['action'] = 3;
- $add_record['store_id'] = $store_id;
- $add_record['detail'] = json_encode($select_info);
- AlbumWatchRecord::create($add_record);
- $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
- $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
- try{
- $this->sendLogsMessage($store_id,$agent->wechat_open_id,3,$userAuth->username);
- }catch (\Exception $e){
- }
- }
- $ma = AlbumManufacturerModel::where('store_id',$store_id)->first();
- $goods = AlbumProductModel::where([['id',$goods_id],['store_id',$store_id]])->first();
- $address = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
- if(!empty($goods) && $userAuth->is_dealer != 1){
- $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;
- }else{
- $goods->price = '';
- }
- $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 = '';
- }
- }elseif(!empty($goods) && $userAuth->is_dealer == 1){
- $agent_id = $address['id'];
- $price = DB::table('album_product_price')->where([['agent_id',$agent_id],['store_id',$store_id],['product_id',$goods['id']]])->first();
- if(!empty($price)){
- $goods->price = $price->price;
- }else{
- $goods->price = '';
- }
- $goods->is_favorite = 0;
- $goods->favorite_id = '';
- }
- if($userAuth->up_agent_id == 0 || !$address){
- $goods->price = '';
- $goods->mobile = $ma->phone;
- $goods->address = $ma->address;
- $goods->realname = $ma->name;
- $goods->avatar = $ma->avatar;
- }else{
- $agent = AlbumUserModel::where('id',$address->user_id)->first();
- $goods->mobile = $address->phone;
- $goods->address = $address->address;
- $goods->realname = $address->name;
- $goods->avatar = $agent->avatar;
- }
- 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 {post} /api/album/get-watch-recored 查看客户浏览情况(get-watch-recored)
- * @apiDescription 查看客户浏览情况(get-watch-recored)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiParam {int} [type] 查询方式 1 按用户 2 按时间 3 按类型
- * @apiParam {int} [user_id] user_id
- * @apiParam {int} [action] 行为类型 1 收藏 2查看类目 3查看商品 4登陆 5点击图片 6 点击导航 7一键拨号
- * @apiParam {int} [start_time] 查询开始时间
- * @apiParam {int} [end_time] 查询结束时间
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": [
- * "type1":{ 1 收藏 2查看类目 3查看商品 4登陆 5点击图片 6 点击导航 7一键拨号
- * "time": 2018-1-1 10:10:12,
- * "action": '做了什么什么都做',
- * "user": [
- * "username":"王小贱",
- * "avatar":"awdawdawdawdawdawd",头像
- * "phone":"1123123123123"
- * ]
- * }
- * ...
- * "count":6;
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumGetWatchRecord(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'type'=>'required'
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'type.required'=>'缺少类型参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $type = $request->input('type');
- $store_id = $request->input('store_id');
- if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- $query = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id]]);
- switch ($type){
- case '1':
- if(!$request->input('user_id')) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!');
- $user = AlbumUserModel::find(request('user_id'));
- $query = $query->where('open_id',$user->wechat_open_id);
- break;
- case '2':
- if(!$request->input('start_time')||!$request->input('end_time')) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!');
- $start_time = date('Y-m-d H:i:s',$request->input('start_time'));
- $end_time = date('Y-m-d H:i:s',$request->input('end_time'));//dd($start_time.';'.$end_time);
- $query = $query->where([['created_at','>=',$start_time],['created_at','<=',$end_time]]);
- break;
- case '3':
- if(!$request->input('action')) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!');
- $query = $query->where([['action',$request->input('action')]]);
- break;
- }
- $res = $query->get();
- $action = '';
- foreach($res as $key=>$val){
- \Log::info('action:'.$val->action.',id:'.$val->id.';end');
- if($val->action==4){
- $action = '进入我的画册';
- }elseif($val->action == 1||$val->action ==3){
- $goods_data = json_decode($val->detail,true);
- $goods_id = $goods_data['goods_id'];
- $goods = AlbumProductModel::find($goods_id);
- $cat = AlbumCatModel::find($goods->cat_id);
- $style = AlbumProductStyleModel::find($goods->style);
- $val->action == 1? $act = '收藏':$act = '查看';if(empty($style)||empty($cat)) continue;
- $action = $act.'了您的'.$cat->name.'分类下的'.$style->name.'风格的商品 '.$goods->name;
- }elseif($val->action == 2){
- //dd(111);
- $cat_data = json_decode($val->detail,true);
- if($cat_data['cat_id']=="undefined"||$cat_data['style']=="undefined"||!$cat_data['style']||!$cat_data['cat_id']) continue;
- $cat = AlbumCatModel::find($cat_data['cat_id']);
- $style = AlbumProductStyleModel::find($cat_data['style']);
- if(empty($style)||empty($cat)) continue;
- $action = '浏览了您的 '.$cat->name.'分类下的 '.$style->name.'风格的商品列表';
- }elseif($val->action==5){
- $goods_data = json_decode($val->detail,true);
- $goods_id = $goods_data['goods_id'];
- $goods = AlbumProductModel::find($goods_id);
- $cat = AlbumCatModel::find($goods->cat_id);
- $style = AlbumProductStyleModel::find($goods->style);if(empty($style)||empty($cat)) continue;
- $action = '点击了您的'.$cat->name.'分类下的'.$style->name.'风格的商品 '.$goods->name.'的'.$goods_data['detail'];
- }elseif($val->action==6){
- $detail = json_decode($val->detail,true);
- $address = $detail['detail'];
- $action = '查看了您的地址'.$address.',并且点击了导航';
- }elseif($val->action==7){
- $detail = json_decode($val->detail,true);
- $phone = $detail['detail'];
- $action = '查看了您的电话'.$phone.',并且点击了拨号';
- }
- $user = AlbumUserModel::where([['wechat_open_id',$val->open_id],['store_id',$val->store_id]])->select(['username','avatar','phone'])->first();
- // dd(111);
- $data_res[] = [
- 'time'=>$val->created_at,
- 'action'=>$action,
- 'user'=>$user
- ];
- }
- return $this->api(compact('data_res'));
- }
- /**
- * @api {post} /api/album/get_data_goods 获取访问数据(get_data_goods)
- * @apiDescription 获取访问数据(get_data_goods)
- * @apiGroup Album
- * @apiPermission 需要登录
- * @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": [
- * {
- * "1": [
- * 'name':'asdawd',
- * 'point':'asdawd',
- * 'num':'1',
- * ],
- * }
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumGetDataGoods(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());
- }
- $store_id = $request->input('store_id');
- if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- $res = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id],['action',3]])->get();
- $arr = array();
- $total = 0;
- foreach($res as $key=>$val){
- $goods_data = json_decode($val->detail,true);
- $goods_id = $goods_data['goods_id'];
- $goods = AlbumProductModel::find($goods_id);
- if(isset($arr[$goods->id])){
- $arr[$goods->id]['num']++;
- }else{
- $arr[$goods->id]['num']=1;
- $arr[$goods->id]['name']=$goods->name;
- }
- $total++;
- }
- foreach($arr as $key=>$val){
- $arr[$key]['point'] = ($val['num']/$total*100).'%';
- }
- return $this->api(compact('arr'));
- }
- /**
- * @api {post} /api/album/get_data_cat 获取分类访问数据(get_data_cat)
- * @apiDescription 获取分类访问数据(get_data_cat)
- * @apiGroup Album
- * @apiPermission 需要登录
- * @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": [
- * {
- * "1": [
- * 'name':'asdawd',
- * 'point':'asdawd',
- * 'num':'1',
- * ],
- * }
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumGetDataCat(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'style_id' => 'required'
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'style_id.required'=>'缺少风格参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $store_id = $request->input('store_id');
- $style_id = $request->input('style_id');
- if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- $cat = AlbumCatModel::where('store_id',$store_id)->get(['name','id'])->toArray();
- $total = 0;
- foreach ($cat as $key=>$val){
- $count = CustomerCatRecordModel::where([['agent_id',$user_agent->id],['store_id',$store_id],['style_id',$style_id],['cat_id',$val['id']]])->count();
- $total += $count;
- $cat[$key]['num'] = $count;
- }
- foreach($cat as $key=>$val){
- if($val['num']==0||$total==0){
- $cat[$key]['point']=0;
- }else{
- $cat[$key]['point'] = ($val['num']/$total*100).'%';
- }
- }
- return $this->api(compact('cat'));
- }
- /**
- * @api {post} /api/album/get-cart-of-watch 客户浏览情况概览(get-cart-of-watch)
- * @apiDescription 客户浏览情况概览(get-cart-of-watch)
- * @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": [
- * "user": {
- * "username":"王小贱",
- * "avatar":"awdawdawdawdawdawd",头像
- * "phone":"1123123123123"
- * "wechat_open_id":"1123123123123"
- * }
- * "count":6,
- * "action":[
- * "type1":1,
- * "type2":1,
- * "type3":1,
- * "type4":1,
- * "type5":1,
- * "type6":1,
- * "type7":1,
- * ]
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumGetCartOfWatch(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());
- }
- $store_id = $request->input('store_id');
- if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
- // if($userAuth->up_agent_id==0) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未选择经销商!', $validator->messages());
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- $count_user = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id]])->groupBy('open_id')->get();
- $users = Array();
- if($count_user){
- foreach($count_user as $key=>$val){
- $user = AlbumUserModel::where([['wechat_open_id',$val->open_id],['store_id',$val->store_id]])->select(['id','username','avatar','phone','wechat_open_id'])->first();
- $customer = CustomerDetailsModel::where([['store_id',$store_id],['open_id',$val->open_id],['agent_id',$user_agent->id]])->first(['purpose_level','comment','tips']);
- if($customer){
- $user->purpose_level = $customer->purpose_level;
- $user->comment = $customer->comment;
- $user->tips = $customer->tips;
- }else{
- $user->purpose_level = 0;
- $user->comment = 0;
- $user->tips = 0;
- }
- $users[] = $user;
- }
- }
- $count = count($users);
- $action = Array();
- for($i=1;$i<=7;$i++){
- $res = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id],['action',$i]])->get();
- $action['type'.$i] = count($res);
- }
- return $this->api(compact('count','users','action'));
- }
- /**
- * @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/save_form_id 添加Form_id(save_form_id)
- * @apiDescription 添加Form_id(save_form_id)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {int} [form_id] form_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 albumSaveFormId(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'form_id' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'form_id.required'=>'缺少FormId',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- $data['open_id'] = $userAuth->wechat_open_id;
- $res = AlbumFormId::create($data);
- if($res){
- $d = [
- 'code' =>0,
- 'msg' =>'success',
- ];
- }else{
- $d = [
- 'code' =>1,
- 'msg' =>'error',
- ];
- }
- 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();
- $select_info = ['goods_id'=>$data['product_id']];
- if($userAuth->up_agent_id!=0){
- $add_record['agent_id'] = $userAuth->up_agent_id;
- $add_record['open_id'] = $userAuth->wechat_open_id;
- $add_record['action'] = 1;
- $add_record['store_id'] = $data['store_id'];
- $add_record['detail'] = json_encode($select_info);
- $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
- $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
- try{
- $this->sendLogsMessage($data['store_id'],$agent->wechat_open_id,1,$userAuth->username);
- }catch (\Exception $e){
- }
- AlbumWatchRecord::create($add_record);
- }
- $check_user = AlbumUserModel::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,
- 'id'=>$res->id,
- '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} [store_id] 商户id 模拟值为0
- * @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();
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- $agent_id = $user_agent['id'];
- $data = $request->all();
- //print_r($data);
- $save = array();
- $return_data = array();
- $save['price'] = $data['price'];
- $check = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->first();
- if(empty($check)){
- $save['agent_id'] = $agent_id;
- $save['store_id'] = $data['store_id'];
- $save['product_id'] = $data['goods_id'];
- $res = AlbumProductPriceModel::create($save);
- }else{
- $res = AlbumProductPriceModel::where([['agent_id',$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);
- }
- /**
- * @api {post} /api/album/set-phone 获取用户号码(set-phone)
- * @apiDescription 获取用户号码(set-phone)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiParam {string} [code] code
- * @apiParam {string} [iv] 偏移量
- * @apiParam {string} [encrypted] 加密参数
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[
- * "msg":返回信息,
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumSavePhone(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'code' => 'required',
- 'iv' => 'required',
- 'encrypted' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'code.required'=>'缺少code参数',
- 'iv.required'=>'缺少偏移量参数',
- 'encrypted.required'=>'缺少加密参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $this->wechat_app = AlbumManufacturerModel::where('store_id',$request->input('store_id'))->first();
- $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($request->input('code'));
- if (!$res || empty($res['openid'])) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '获取用户OpenId失败!', $validator->messages());
- }
- $session_key = $res['session_key'];
- $pc = new WXBizDataCrypt($this->wechat_app->xyx_id, $session_key);
- $errCode = $pc->decryptData($request->input('encrypted'), $request->input('iv'), $data);
- if($errCode==0){
- $data = json_decode($data,true);
- $userAuth->phone = $data['phoneNumber'];
- $res = $userAuth->save();
- if($res){
- return $this->api(['msg'=>'success']);
- }else{
- return $this->api(['msg'=>'error']);
- }
- }elseif($errCode == -41003){
- return $this->api(['msg'=>'请求错误,请重试']);
- }
- }
- /**
- * @api {post} /api/album/set-watch 获取用户操作记录(set-watch)
- * @apiDescription 获取用户操作记录(set-watch)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id 模拟值为0
- * @apiParam {string} [detail] 详细
- * @apiParam {string} [type] 5点击图片 6 点击导航 7一键拨号
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[
- * "msg":返回信息,
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumSetWatch(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'type' => 'required',
- 'detail' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'type.required'=>'缺少类型参数',
- 'detail.required'=>'缺少详细参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- if($data['type']==5&&!empty($data['goods_id'])) {
- $select_info = ['goods_id'=>$data['goods_id'],'detail'=>$data['detail']];
- }elseif($data['type']==5&&empty($data['goods_id'])){
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '缺少goodsid');
- }else{
- $select_info = ['detail'=>$data['detail']];
- }
- if($userAuth->up_agent_id!=0){
- $add_record['agent_id'] = $userAuth->up_agent_id;
- $add_record['open_id'] = $userAuth->wechat_open_id;
- $add_record['action'] = $data['type'];
- $add_record['store_id'] = 1;
- $add_record['detail'] = json_encode($select_info);
- // dd($add_record);
- $res = AlbumWatchRecord::create($add_record);
- $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
- $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
- if($res){
- try{
- $this->sendLogsMessage($data['store_id'],$agent->wechat_open_id,$data['type'],$userAuth->username);
- }catch (\Exception $e){
- }
- return $this->api(['msg'=>'success']);
- }else{
- return $this->api(['msg'=>'error']);
- }
- }
- }
- /**
- * @param $storeid
- * @param $open_id
- * @param $action 1 收藏 2查看类目 3查看商品 4登陆 5点击图片 6 点击导航 7一键拨号
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
- */
- private function sendLogsMessage($storeid,$open_id,$action,$name)
- {
- $user = AlbumUserModel::where('wechat_open_id',$open_id)->first();
- $formId = AlbumFormId::where([['open_id',$open_id]])->first();
- if($user&&$formId){
- $content = '';
- switch ($action){
- case 1:
- $content = '有用户收藏了您的产品';
- break;
- case 2;
- $content = '有用户查看了您的产品列表';
- break;
- case 3;
- $content = '有用户查看了您的商品';
- break;
- case 4;
- $content = '有用户进入了您的画册';
- break;
- case 5;
- $content = '有用户点击了您的某款产品详情';
- break;
- case 6;
- $content = '有用户点击了导航到您的位置';
- break;
- case 7;
- $content = '有用户点击了您的号码';
- break;
- }
- $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);
- $res = $app->template_message->send([
- 'touser' => $open_id,
- 'template_id' => '9PDTfnhsRvdNwpPMIcYLL7wQF4SZkB8-9ZhXUfthbmw',
- 'page' => 'pages/logs/logs',
- 'form_id' => $formId->form_id,
- 'data' => [
- 'keyword1' => $name,
- 'keyword2' => $content,
- 'keyword3' => date('Y-m-d H:i'),
- ],
- ]);
- // dd($res);
- if($res){
- $formId->delete();
- }
- }
- }
- /**
- * @api {get} /api/album/add_agent 申请经销商(add_agent)
- * @apiDescription 申请经销商(add_agent)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {int} [realname] 姓名
- * @apiParam {int} [address] 地址
- * @apiParam {double} [lat] lat
- * @apiParam {double} [lon] lon
- * @apiParam {int} [phone] 电话
- * @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 albumAddAgent(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'realname' => 'required',
- 'address' => 'required',
- 'lon' => 'required',
- 'lat' => 'required',
- 'phone' => 'required',
- 'store_id' => 'required',
- ],[
- 'address.required'=>'缺少地址参数',
- 'lon.required'=>'缺少lon参数',
- 'lat.required'=>'缺少lat参数',
- 'real_name.required'=>'缺少信息参数',
- 'phone.required'=>'缺少电话参数',
- 'store_id.required'=>'缺少商户参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- $agent_check = AlbumAgentModel::where([['store_id',$data['store_id']],['user_id',$userAuth->id]])->first();
- if($agent_check){
- if($agent_check->status==0) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户已提交申请!');
- $agent_check->phone = $data['phone'];
- $agent_check->address = $data['address'];
- $agent_check->lon = $data['lon'];
- $agent_check->lat = $data['lat'];
- $agent_check->realname = $data['realname'];
- if($agent_check->save()) return $this->api([
- 'code' =>0,
- 'msg' =>'success',
- ]);
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '保存失败!');
- }
- $data['status'] = 0;
- $data['user_id'] = $userAuth->id;
- $data['name'] = $userAuth->username;
- $res = AlbumAgentModel::create($data);
- if($res){
- $d = [
- 'code' =>0,
- 'msg' =>'success',
- ];
- }else{
- $d = [
- 'code' =>1,
- 'msg' =>'error',
- ];
- }
- return $this->api($d);
- }
- /**
- * @api {get} /api/album/get-agent-address 获取经销商地址(get-agent-address)
- * @apiDescription 获取经销商地址(get-agent-address)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[
- * "realname":
- * "phone":
- * "address":
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumGetAgentAdress(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();
- if($userAuth->is_dealer == 1){
- $user_agent = AlbumAgentModel::where([['store_id',$data['store_id']],['user_id',$userAuth->id]])->first(['address','phone','realname']);
- }else{
- $user_agent = null;
- }
- return $this->api(compact('user_agent'));
- }
- /**
- * @api {get} /api/album/get-banner 获取banner和視頻(get-banner)
- * @apiDescription 获取banner和視頻(get-banner)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[
- * "video":{
- * 'url':22222,
- * 'name':22222,
- * 'type':22222,
- * 'agent_id':22222,
- * }
- * "banner":{
- * 'url':22222,
- * 'name':22222,
- * 'type':22222,
- * 'agent_id':22222,
- * },
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumGetBanner(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- if($userAuth->up_agent_id == 0){
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- $agent_id = $user_agent['id'];
- }else{
- $agent_id = $userAuth->up_agent_id;
- }
- $banner = AgentBannerModel::where([['agent_id',$agent_id],['type',0]])->get();
- $video = AgentBannerModel::where([['agent_id',$agent_id],['type',1]])->first();
- return $this->api(compact('banner','video'));
- }
- /**
- * @api {get} /api/album/get-customer 获取客户信息(get-customer)
- * @apiDescription 获取客户信息(get-customer)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {string} [openid_id] open_id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[
- * "purpose_level":
- * "comment":
- * "phone":
- * "tips":
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumGetCustomer(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'open_id'=>'required'
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'open_id.required'=>'缺少用户参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $store_id = $request->input('store_id');
- $open_id = $request->input('open_id');
- if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- $customer = CustomerDetailsModel::where([['store_id',$store_id],['open_id',$open_id],['agent_id',$user_agent->id]])->first(['purpose_level','comment','tips']);
- if(!empty($customer)){
- $user = AlbumUserModel::where([['store_id',$store_id],['wechat_open_id',$open_id]])->first();
- $customer->phone = $user->phone;
- }
- return $this->api(compact('customer'));
- }
- /**
- * @api {post} /api/album/set-customer 设置客户信息(set-customer)
- * @apiDescription 设置客户信息(set-customer)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {string} [openid_id] openid
- * @apiParam {int} [level] 意向等级 1 25% 2 50% 3 75% 4 100%
- * @apiParam {string} [comment] 备注
- * @apiParam {string} [tips] 标签
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[
- * "purpose_level":
- * "comment":
- * "phone":
- * "tips":
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumSetCustomer(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'purpose_level' => 'required',
- 'comment' => 'required',
- 'tips' => 'required',
- 'open_id'=>'required'
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'purpose_level.required'=>'缺少意向等级参数',
- 'comment.required'=>'缺少客户备注参数',
- 'tips.required'=>'缺少标签参数',
- 'open_id.required'=>'缺少用户参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $store_id = $request->input('store_id');
- $open_id = $request->input('open_id');
- $add = $request->input();
- if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- $customer = CustomerDetailsModel::where([['store_id',$store_id],['open_id',$open_id],['agent_id',$user_agent->id]])->first(['purpose_level','comment','tips']);
- $add['agent_id'] = $user_agent->id;
- $user = CustomerDetailsModel::create($add);
- $customer->phone = $user->phone;
- return $this->api([],0,'success');
- }
- /**
- * @api {get} /api/album/customer-goods 获取客户浏览商品统计(customer-goods)
- * @apiDescription 获取客户浏览商品统计(customer-goods)
- * @apiGroup Album
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[
- * {
- * "name":
- * "count":
- * },
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumCustomerGoods(Request $request)
- {
- $userAuth = Auth('api')->user();
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'open_id'=>'required'
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'open_id.required'=>'缺少用户参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $store_id = $request->input('store_id');
- $open_id = $request->input('open_id');
- if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
- $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
- if($user_agent) $res= AlbumWatchRecord::where([['action',3],['store_id',$store_id],['open_id',$open_id]])->get();
- $arr = array();
- foreach ($res as $key=>$val){
- $detail = json_decode($val['detail'],true);
- //dd($detail);die;
- $goods_id = $detail['goods_id'];
- $goods = AlbumProductModel::where([['id',$goods_id]])->first();
- if($goods){
- $count= AlbumWatchRecord::where([['action',3],['store_id',$store_id],['open_id',$open_id],['detail',$detail]])->count();
- $arr[] = ['name'=>$goods->name,'count'=>$count];
- }
- }
- return $this->api($arr,0,'success');
- }
- }
|