| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104 |
- <?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/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']);
- $check = AlbumUserModel::where('wechat_union_id',$decryptedData['unionId'])->first();
- if(!$check){
- $add['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
- $add['open_id'] = $res['openid'];
- $add['wechat_union_id'] = $decryptedData['unionId'];
- $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_union_id',$res->wechat_union_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['open_id'] = $res['openid'];
- $save['model'] = 1;
- $res = AlbumUserModel::where('wechat_union_id',$decryptedData['unionId'])->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->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){
- $user_agent->get_count++;
- $user_agent->save();
- $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
- try{
- $this->sendLogsMessage($datas['store_id'],$agent->open_id,4,$userAuth->username);
- }catch (\Exception $e){
- }
- }else{
- $userAuth->up_agent_id = 0;
- }
- }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;
- $conf = AlbumManufacturerModel::where('store_id',$datas['store_id'])->first();
- $getPhone = $conf->getPhone;
- return $this->api(compact('token', 'user','getPhone'));
- } 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->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->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->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->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->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->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([['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"
- * "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',
- 'end' => 'required',
- 'start' => 'required',
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'end.required'=>'缺少结束时间参数',
- 'start.required'=>'缺少开始时间参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $store_id = $request->input('store_id');
- $end = $request->input('end');
- $start = $request->input('start');
- $end= date('Y-m-d H:i:s',$end);
- $start= date('Y-m-d H:i:s',$start);
- 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],['updated_at','>=',$start],['updated_at','<=',$end]])->orderBy('id','DESC')->groupBy('open_id')->get();
- $users = Array();
- if($count_user){
- foreach($count_user as $key=>$val){
- $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$val->store_id]])->select(['id','username','avatar','phone','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']);
- $user->time = $val->updated_at;
- 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->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->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->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->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->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('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',
- 'phone' => 'required',
- 'store_id' => 'required',
- ],[
- 'address.required'=>'缺少地址参数',
- 'real_name.required'=>'缺少信息参数',
- 'phone.required'=>'缺少电话参数',
- 'store_id.required'=>'缺少商户参数',
- ]);
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- $url = "https://apis.map.qq.com/ws/geocoder/v1/?address=".$data['address']."&key=U5DBZ-X5VCO-6UUWV-SGPU3-PD5X2-NDFXA";
- $local = $this->curl_get($url);
- $res = json_decode($local,true);
- $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 = $res['result']['location']['lon'];
- $agent_check->lat = $res['result']['location']['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":
- * "address":
- * "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','address']);
- if(!empty($customer)){
- $user = AlbumUserModel::where([['store_id',$store_id],['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} [address] 地址
- * @apiParam {string} [tips] 标签
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[
- * "purpose_level":
- * "address":
- * "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',
- 'address' => 'required',
- 'tips' => 'required',
- 'open_id'=>'required'
- ],[
- 'store_id.required'=>'缺少商户参数',
- 'address.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',
- ],[
- '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();
- if($user_agent) $res= AlbumWatchRecord::where([['action',3],['store_id',$store_id],['agent_id',$user_agent->id]])->groupBy('detail')->get('detail');
- $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],['detail',$detail]])->count();
- $arr[] = ['name'=>$goods->name,'count'=>$count];
- }
- }
- return $this->api($arr,0,'success');
- }
- /**
- * @api {get} /api/album/customer-goods-detail 获取客户浏览商品详细(customer-goods-detail)
- * @apiDescription 获取客户浏览商品详细(customer-goods-detail)
- * @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":
- * "time":
- * "style":
- * "cat":
- * },
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumCustomerGoodsDetail(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],['agent_id',$user_agent->id]])->get('detail','created_at')->toArray();
- $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){
- $style = AlbumProductStyleModel::where([['store_id',$store_id],['id',$goods->style]])->first();
- $cat = AlbumCatModel::where([['store_id',$store_id],['id',$goods->cat_id]])->first();
- $arr[] = ['name'=>$goods->name,'time'=>date('Y-m-d-h',strtotime($val['created_at'])),'style'=>$style->name,'cat'=>$cat->name];
- }
- }
- return $this->api($arr,0,'success');
- }
- }
|