AlbumController.php 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\AgentBannerModel;
  4. use App\Models\AlbumAgentModel;
  5. use App\Models\AlbumBannerModel;
  6. use App\Models\AlbumCatModel;
  7. use App\Models\AlbumFavoriteModel;
  8. use App\Models\AlbumFormId;
  9. use App\Models\AlbumManufacturerModel;
  10. use App\Models\AlbumNavModel;
  11. use App\Models\AlbumNewsModel;
  12. use App\Models\AlbumProductModel;
  13. use App\Models\AlbumProductPriceModel;
  14. use App\Models\AlbumProductStyleModel;
  15. use App\Models\AlbumStatisticalModel;
  16. use App\Models\AlbumUserModel;
  17. use App\Models\AlbumWatchRecord;
  18. use App\Models\CustomerCatRecordModel;
  19. use App\Models\CustomerDetailsModel;
  20. use EasyWeChat\Kernel\Messages\Text;
  21. use Illuminate\Http\Request;
  22. use Illuminate\Support\Facades\Cache;
  23. use Illuminate\Support\Facades\DB;
  24. use Illuminate\Support\Facades\Log;
  25. use Tinify\Tinify;
  26. use Validator, Response,Auth;
  27. use App\Services\Base\ErrorCode;
  28. use WXBizDataCrypt;
  29. use EasyWeChat\Factory;
  30. class AlbumController extends Controller
  31. {
  32. private $wechat_app;
  33. public function albumSetting(Request $request)
  34. {
  35. $validator = Validator::make($request->all(), [
  36. 'store_id' => 'required',
  37. ], [
  38. 'store_id.required' => '店铺信息未知',
  39. ]);
  40. if ($validator->fails()) {
  41. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  42. }
  43. $store_id = $request->store_id;
  44. //小程序設置
  45. $setting = AlbumManufacturerModel::where('store_id', $store_id)->first();
  46. //轮播图
  47. $banner = AlbumBannerModel::where('store_id', $store_id)->orderByDesc('sort')->get();
  48. //底部导航栏
  49. $navbar = AlbumNavModel::where([['store_id', $store_id],['state',0]])->orderByDesc('sort')->get();
  50. //顶部菜单栏
  51. $menus = AlbumNavModel::where([['store_id', $store_id],['state',1]])->orderByDesc('sort')->get();
  52. $news = AlbumNewsModel::where([['store_id', $store_id]])->orderByDesc('sort')->paginate(5);
  53. $userAuth = Auth('api')->user();
  54. $agent_set = array();
  55. if ($userAuth && $userAuth->is_dealer == 1) {
  56. $user_agent = AlbumAgentModel::where('user_id', $userAuth->id)->first();
  57. $agent_set['set_price_point'] = $user_agent->set_price_point;
  58. $agent_set['is_show_ma_price'] = $user_agent->is_show_ma_price;
  59. }
  60. return $this->api(compact('setting', 'banner', 'news', 'navbar', 'menus', 'agent_set'));
  61. }
  62. /**
  63. * @api {post} /api/album/xyx_login 登陆(xyx_login)
  64. * @apiDescription 登陆(xyx_login)
  65. * @apiGroup Album
  66. * @apiPermission none
  67. * @apiVersion 0.1.0
  68. * @apiParam {int} [code]
  69. * @apiParam {int} [agent_id] 经销商id
  70. * @apiParam {int} [store_id] 商户id
  71. * @apiSuccessExample {json} Success-Response:
  72. * HTTP/1.1 200 OK
  73. * {
  74. * "status": true,
  75. * "status_code": 0,
  76. * "message": "",
  77. * "data": {
  78. * "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",
  79. * "user": {
  80. * "user_id": 1,
  81. * "is_agent": 1,
  82. * "agent_id": 4
  83. * }
  84. * }
  85. * }
  86. * @apiErrorExample {json} Error-Response:
  87. * HTTP/1.1 400 Bad Request
  88. * {
  89. * "state": false,
  90. * "code": 1000,
  91. * "message": "传入参数不正确",
  92. * "data": null or []
  93. * }
  94. * 可能出现的错误代码:
  95. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  96. */
  97. public function albumXyxLogin(Request $request)
  98. {
  99. $datas = $request->input();
  100. $validator = Validator::make($request->all(), [
  101. 'code' => 'required',
  102. 'agent_id' => 'required',
  103. 'nickName' => 'required',
  104. 'iv' => 'required',
  105. 'encryptData' => 'required',
  106. 'avatar' => 'required',
  107. 'store_id' => 'required'
  108. ], [
  109. 'code.required' => 'code不能为空!',
  110. 'agent_id.required' => 'agent_id不能为空!',
  111. 'nickName.required' => '昵称不能为空!',
  112. 'iv.required' => '偏移量不能为空!',
  113. 'encryptData.required' => '加密数据不能为空!',
  114. 'avatar.required' => '头像不能为空!',
  115. 'store_id.required' => '站点ID不能为空!'
  116. ]);
  117. if ($validator->fails()) {
  118. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  119. }
  120. $this->wechat_app = AlbumManufacturerModel::where('store_id', $datas['store_id'])->first();
  121. if (!$this->wechat_app) {
  122. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '厂家参数未初始化!', $validator->messages());
  123. }
  124. $config = [
  125. 'app_id' => $this->wechat_app->xyx_id,
  126. 'secret' => $this->wechat_app->xyx_secret,
  127. // 下面为可选项
  128. // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
  129. 'response_type' => 'array',
  130. ];
  131. $app = Factory::miniProgram($config);
  132. $res = $app->auth->session($datas['code']);
  133. if (!$res || empty($res['openid'])) {
  134. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '获取用户OpenId失败!', $validator->messages());
  135. }
  136. $session = $res['session_key'];
  137. $decryptedData = $app->encryptor->decryptData($session, $datas['iv'], $datas['encryptData']);
  138. if (!isset($decryptedData['unionId'])) {
  139. $check = AlbumUserModel::where([['open_id', $res['openid']],['store_id',$datas['store_id']]])->first();
  140. } else {
  141. $check = AlbumUserModel::where([['wechat_union_id', $decryptedData['unionId']],['store_id',$datas['store_id']]])->first();
  142. }
  143. if (!$check) {
  144. $add['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
  145. $add['open_id'] = $res['openid'];
  146. $add['wechat_union_id'] = isset($decryptedData['unionId']) ? $decryptedData['unionId'] : '';
  147. $add['avatar'] = $datas['avatar'];
  148. $add['is_dealer'] = 0;
  149. $add['model'] = 1;
  150. $add['store_id'] = $datas['store_id'];
  151. $res = AlbumUserModel::create($add);
  152. if ($res) {
  153. $check = $res;
  154. $user = [
  155. 'user_id' => $check->id,
  156. 'phone' => '',
  157. 'is_agent' => 0,
  158. 'agent_id' => '',
  159. ];
  160. } else {
  161. $user = [
  162. 'error' => 1
  163. ];
  164. }
  165. } else {
  166. $save['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
  167. $save['avatar'] = $datas['avatar'];
  168. $save['model'] = 1;
  169. AlbumUserModel::where('open_id', $res['openid'])->update($save);
  170. if ($check->is_dealer == 1) {
  171. $user_agent = AlbumAgentModel::where([['user_id',$check->id],['status',1]])->first();
  172. $agent_id = $user_agent['id'];
  173. } else {
  174. $agent_id = '';
  175. }
  176. $user = [
  177. 'user_id' => $check->id,
  178. 'phone' => $check->phone,
  179. 'is_agent' => $check->is_dealer,
  180. 'agent_id' => $agent_id,
  181. ];
  182. }
  183. if (Auth::loginUsingId($check->id)) {
  184. $userAuth = Auth::user();
  185. if ($check->is_dealer == 0) {
  186. if ($request->input('agent_id') != 0) {
  187. $userAuth->up_agent_id = $request->input('agent_id');
  188. }
  189. $add_record['agent_id'] = $userAuth->up_agent_id;
  190. $add_record['open_id'] = $check->open_id;
  191. $add_record['action'] = 4;
  192. $add_record['store_id'] = $datas['store_id'];
  193. $add_record['detail'] = null;
  194. $check_new_customer = AlbumWatchRecord::where([
  195. ['agent_id', $userAuth->up_agent_id],['open_id', $check->open_id],['store_id', $datas['store_id']]
  196. ])->first();
  197. $check_user = AlbumWatchRecord::where([
  198. ['open_id', $check->open_id],['store_id', $datas['store_id']]
  199. ])->first();
  200. \Log::info($check_user);
  201. if ($check_user) {
  202. $add_record['is_new'] = 0;
  203. } else {
  204. $add_record['is_new'] = 1;
  205. }
  206. // \Log::info($add_record);
  207. AlbumWatchRecord::create($add_record);
  208. dd($check_user);
  209. $user_agent = AlbumAgentModel::where([['id',$add_record['agent_id']],['store_id',$datas['store_id']]])->first();
  210. //dd($user_agent);
  211. if ($user_agent) {
  212. if (empty($check_new_customer)) {
  213. $user_agent->get_count++;
  214. }
  215. $user_agent->interactive++;
  216. $user_agent->pointCount++;
  217. $user_agent->newCount = $user_agent->pointCount + $user_agent->favoriteCount + $user_agent->callCount + $user_agent->share_times + $user_agent->get_count;
  218. $user_agent->save();
  219. $agent = AlbumUserModel::where([['id',$user_agent->user_id],['store_id',$datas['store_id']]])->first();
  220. $this->sendLogsMessage($datas['store_id'], $agent->open_id, 4, $userAuth->username, $agent->g_open_id);
  221. } else {
  222. $userAuth->up_agent_id = 0;
  223. }
  224. } else {
  225. $userAuth->up_agent_id = 0;
  226. }
  227. $userAuth->save();
  228. $user['up_agent_id'] = $userAuth->up_agent_id;
  229. $user['role'] = $userAuth->role;
  230. if (!file_exists(public_path() . '/base/poster/avatar/' . $datas['store_id'])) {
  231. mkdir(public_path() . '/base/poster/avatar/' . $datas['store_id'], 0755, true);
  232. }
  233. $res_image = getUrlImage($userAuth->avatar, public_path() . '/base/poster/avatar/' . $datas['store_id'] . "/$userAuth->id.jpg");
  234. imageToCircle($res_image);
  235. $token = $userAuth->createToken($userAuth->id . '-' . $userAuth->openid)->accessToken;
  236. $conf = AlbumManufacturerModel::where('store_id', $datas['store_id'])->first();
  237. $getPhone = $conf->getPhone;
  238. $getFocus = $conf->getFocus;
  239. return $this->api(compact('token', 'user', 'getPhone', 'getFocus'));
  240. } else {
  241. return $this->error(ErrorCode::INCORRECT_USER_OR_PASS);
  242. }
  243. }
  244. /**
  245. * @param $url
  246. * @return mixed
  247. */
  248. public function curlGet($url)
  249. {
  250. //初始化
  251. $ch = curl_init();
  252. //设置选项,包括URL
  253. curl_setopt($ch, CURLOPT_URL, $url);
  254. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  255. curl_setopt($ch, CURLOPT_HEADER, 0);
  256. $output = curl_exec($ch);
  257. curl_close($ch);
  258. return $output;
  259. }
  260. /**
  261. * @api {get} /api/album/goods 商品列表(goods)
  262. * @apiDescription 商品列表(goods)
  263. * @apiGroup Album
  264. * @apiPermission none
  265. * @apiVersion 0.1.0
  266. * @apiParam {int} [cat_id] 分类id
  267. * @apiParam {string} [keywords] 关键词.
  268. * @apiParam {int} [status] 状态 1 只选择热销 2 只选择最新上市 3只选择一个风格 4 同时选择热销和最新上市 5同时选择热销和风格 6同时选择最新上市和风格 7全选 0全不选
  269. * @apiParam {int} [style] 风格
  270. * @apiSuccessExample {json} Success-Response:
  271. * HTTP/1.1 200 OK
  272. * {
  273. * "status": true,
  274. * "status_code": 0,
  275. * "message": "",
  276. * "data": {
  277. * "goods": [
  278. * {
  279. * "id": 3,
  280. * "cover_pic": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  281. * "name": "简约",
  282. * "style": "纯白",
  283. * "hot_cake": 1,
  284. * "news": 1,
  285. * "price": ""
  286. * }
  287. * ],
  288. * "name": 品牌名
  289. * }
  290. * }
  291. * @apiErrorExample {json} Error-Response:
  292. * HTTP/1.1 400 Bad Request
  293. * {
  294. * "state": false,
  295. * "code": 1000,
  296. * "message": "传入参数不正确",
  297. * "data": null or []
  298. * }
  299. * 可能出现的错误代码:
  300. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  301. */
  302. public function albumGoods(Request $request)
  303. {
  304. $userAuth = Auth('api')->user();
  305. if (!$userAuth) {
  306. return $this->error(ErrorCode::ERROR_POWER, '登陆过期!');
  307. }
  308. $validator = Validator::make($request->all(), [
  309. 'cat_id' => 'required',
  310. 'parent_id' => 'required',
  311. 'store_id' => 'required',
  312. 'status' => 'required',
  313. ], [
  314. 'cat_id.required' => '缺少分类参数',
  315. 'parent_id.required' => '缺少父分类参数',
  316. 'store_id.required' => '缺少商户参数',
  317. 'status.required' => '缺少状态参数',
  318. ]);
  319. if ($validator->fails()) {
  320. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  321. }
  322. $data = $request->input();
  323. $cat_id = request('cat_id');
  324. $store_id = request('store_id');
  325. $parent_id = request('parent_id');
  326. $select_info = ['cat_id' => $cat_id,'parent_id' => $parent_id];
  327. if ($userAuth->up_agent_id != 0 && $cat_id != "undefined" && $parent_id != "undefined") {
  328. $add_record['agent_id'] = $userAuth->up_agent_id;
  329. $add_record['open_id'] = $userAuth->open_id;
  330. $add_record['action'] = 2;
  331. $add_record['store_id'] = $store_id;
  332. $add_record['detail'] = json_encode($select_info);
  333. AlbumWatchRecord::create($add_record);
  334. $user_agent = AlbumAgentModel::where('id', $userAuth->up_agent_id)->first();
  335. $user_agent->interactive++;
  336. $user_agent->save();
  337. $agent = AlbumUserModel::where('id', $user_agent->user_id)->first();
  338. try {
  339. $this->sendLogsMessage($store_id, $agent->open_id, 2, $userAuth->username, $agent->g_open_id);
  340. } catch (\Exception $e) {
  341. \Log::info($e);
  342. }
  343. }
  344. if (isset($data['keywords']) && !empty($data['keywords'])) {
  345. $keywords = '%' . $data['keywords'] . '%';
  346. $goods = AlbumProductModel::where([['name','like',$keywords],['store_id',$data['store_id']],['cat_id',$cat_id],['store_id',$store_id]]);
  347. } else {
  348. $goods = AlbumProductModel::where([['cat_id',$cat_id],['store_id',$store_id]]);
  349. }
  350. if ($userAuth->up_agent_id != 0) {
  351. $agent_in = AlbumAgentModel::where('id', $userAuth->up_agent_id)->first();
  352. $set_show_price = $agent_in->is_show_ma_price;
  353. } else {
  354. $set_show_price = 0;
  355. }
  356. if ($userAuth->is_dealer == 1) {
  357. $agent_me = AlbumAgentModel::where('user_id', $userAuth->id)->first();
  358. $set_show_price = $agent_me->is_show_ma_price;
  359. }
  360. $goods = $goods->select('id', 'cover_pic', 'thumb', 'name', 'style', 'hot_cake', 'news', 'price_default', 'ma_price', 'ma_price_comment')->orderByDesc('sort')->paginate(9);
  361. foreach ($goods as $key => $val) {
  362. if ($userAuth->is_dealer != 1) {
  363. if ($userAuth->up_agent_id == 0) {
  364. $goods[$key]['price'] = '';
  365. } else {
  366. $check = AlbumProductPriceModel::where([['agent_id',$userAuth->up_agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
  367. if ($check) {
  368. $goods[$key]['price'] = $check->price;
  369. } else {
  370. $goods[$key]['price'] = '';
  371. }
  372. }
  373. } elseif ($userAuth->is_dealer == 1) {
  374. $user_agent = AlbumAgentModel::where('user_id', $userAuth->id)->first();
  375. $agent_id = $user_agent['id'];
  376. $check = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
  377. if ($check) {
  378. $goods[$key]['price'] = $check->price;
  379. } else {
  380. $goods[$key]['price'] = '';
  381. }
  382. }
  383. }
  384. $data = AlbumManufacturerModel::where('store_id', $store_id)->first();
  385. $name = $data['name'];
  386. return $this->api(compact('goods', 'name', 'set_show_price'));
  387. }
  388. /**
  389. * @api {get} /api/album/goods-detail 商品详细(goods-detail)
  390. * @apiDescription 商品列表(goods-detail)
  391. * @apiGroup Album
  392. * @apiPermission none
  393. * @apiVersion 0.1.0
  394. * @apiParam {int} [goods_id] 商品id
  395. * @apiParam {int} [store_id] 商户id 模拟值为0
  396. * @apiSuccessExample {json} Success-Response:
  397. * HTTP/1.1 200 OK
  398. * {
  399. * "status": true,
  400. * "status_code": 0,
  401. * "message": "",
  402. * "data": {
  403. * "id": 3,
  404. * "store_id": 0,
  405. * "cat_id": 9,
  406. * "specifications_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  407. * "style": "纯白",
  408. * "sort": 11,
  409. * "cover_pic": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  410. * "hot_cake": 1,
  411. * "news": 1,
  412. * "detail": "<p>达达娃达娃达娃大青蛙大全大是大非如果v率v恶策但是许多女性的项目部的不行么法可没副本副本副本么方便</p>",
  413. * "created_at": "2018-05-19 15:09:04",
  414. * "updated_at": "2018-05-19 15:09:04",
  415. * "deleted_at": null,
  416. * "install_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  417. * "name": "简约",
  418. * "detail_pic": ""
  419. * "price": "",
  420. * "price_default": "",
  421. * "mobile": "",
  422. * "address": "",
  423. * "realname": "",
  424. * "is_favorite": 1,
  425. * "favorite_id": 4
  426. * }
  427. * }
  428. * @apiErrorExample {json} Error-Response:
  429. * HTTP/1.1 400 Bad Request
  430. * {
  431. * "state": false,
  432. * "code": 1000,
  433. * "message": "传入参数不正确",
  434. * "data": null or []
  435. * }
  436. * 可能出现的错误代码:
  437. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  438. */
  439. public function albumGoodsDetail(Request $request)
  440. {
  441. // $userAuth = AlbumXyxUserModel::find(1);
  442. $userAuth = Auth('api')->user();
  443. if (!$userAuth) {
  444. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  445. }
  446. $validator = Validator::make($request->all(), [
  447. 'goods_id' => 'required',
  448. 'store_id' => 'required',
  449. ], [
  450. 'goods_id.required' => '缺少商品参数',
  451. 'store_id_id.required' => '缺少STORE参数',
  452. ]);
  453. if ($validator->fails()) {
  454. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  455. }
  456. $goods_id = request('goods_id');
  457. $store_id = request('store_id');
  458. $select_info = ['goods_id' => $goods_id];
  459. if ($userAuth->up_agent_id != 0) {
  460. $add_record['agent_id'] = $userAuth->up_agent_id;
  461. $add_record['open_id'] = $userAuth->open_id;
  462. $add_record['action'] = 3;
  463. $add_record['store_id'] = $store_id;
  464. $add_record['detail'] = json_encode($select_info);
  465. AlbumWatchRecord::create($add_record);
  466. $user_agent = AlbumAgentModel::where('id', $userAuth->up_agent_id)->first();
  467. $user_agent->interactive++;
  468. $user_agent->save();
  469. $agent = AlbumUserModel::where('id', $user_agent->user_id)->first();
  470. try {
  471. $this->sendLogsMessage($store_id, $agent->open_id, 3, $userAuth->username, $agent->g_open_id);
  472. } catch (\Exception $e) {
  473. \Log::info($e);
  474. }
  475. }
  476. $ma = AlbumManufacturerModel::where('store_id', $store_id)->first();
  477. $goods = AlbumProductModel::where([['id',$goods_id],['store_id',$store_id]])->first();
  478. $cat_record['agent_id'] = $userAuth->up_agent_id;
  479. $cat_record['open_id'] = $userAuth->open_id;
  480. $cat_record['store_id'] = $store_id;
  481. $cat_record['cat_id'] = $goods->cat_id;
  482. CustomerCatRecordModel::create($cat_record);
  483. if (!empty($goods) && $userAuth->is_dealer != 1) {
  484. $address = AlbumAgentModel::where('id', $userAuth->up_agent_id)->first();
  485. $price = DB::table('album_product_price')->where([['agent_id',$userAuth->up_agent_id],['store_id',$store_id],['product_id',$goods['id']]])->first();
  486. if (!empty($price)) {
  487. $goods->price = $price->price;
  488. } else {
  489. $goods->price = '';
  490. }
  491. $check_favorite = AlbumFavoriteModel::where([['user_id',$userAuth->id],['store_id',$store_id],['product_id',$goods['id']]])->first();
  492. //dd($check_favorite);
  493. if ($check_favorite) {
  494. $goods->is_favorite = 1;
  495. $goods->favorite_id = $check_favorite->id;
  496. } else {
  497. $goods->is_favorite = 0;
  498. $goods->favorite_id = '';
  499. }
  500. } elseif (!empty($goods) && $userAuth->is_dealer == 1) {
  501. $address = AlbumAgentModel::where([['store_id', $store_id],['user_id', $userAuth->id]])->first();
  502. $price = DB::table('album_product_price')->where([['agent_id',$address->id],['store_id',$store_id],['product_id',$goods['id']]])->first();
  503. if (!empty($price)) {
  504. $goods->price = $price->price;
  505. } else {
  506. $goods->price = '';
  507. }
  508. $goods->is_favorite = 0;
  509. $goods->favorite_id = '';
  510. }
  511. if ($userAuth->up_agent_id == 0 || !$address) {
  512. $goods->price = '';
  513. $goods->mobile = $ma->phone;
  514. $goods->address = $ma->address;
  515. $goods->realname = $ma->name;
  516. $goods->avatar = $ma->avatar;
  517. } else {
  518. $agent = AlbumUserModel::where('id', $address->user_id)->first();
  519. $goods->mobile = $address->phone;
  520. $goods->address = $address->address;
  521. $goods->realname = $address->name;
  522. $goods->avatar = $agent->avatar;
  523. }
  524. return $this->api($goods);
  525. }
  526. /**
  527. * @api {get} /api/album/favorite_list 收藏列表(favorite_list)
  528. * @apiDescription 收藏列表(favorite_list)
  529. * @apiGroup Album
  530. * @apiPermission none
  531. * @apiVersion 0.1.0
  532. * @apiParam {int} [store_id] 商户id 模拟值为0
  533. * @apiSuccessExample {json} Success-Response:
  534. * HTTP/1.1 200 OK
  535. * {
  536. * "status": true,
  537. * "status_code": 0,
  538. * "message": "",
  539. * "data": [
  540. * {
  541. * "id": 4,
  542. * "user_id": 1,
  543. * "deleted_at": null,
  544. * "created_at": "2018-10-29 15:51:47",
  545. * "updated_at": "2018-10-29 15:53:15",
  546. * "product_id": 3,
  547. * "store_id": 0,
  548. * "goods": {
  549. * "id": 3,
  550. * "store_id": 0,
  551. * "cat_id": 9,
  552. * "specifications_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  553. * "style": "纯白",
  554. * "sort": 11,
  555. * "cover_pic": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  556. * "hot_cake": 1,
  557. * "news": 1,
  558. * "detail": "<p>达达娃达娃达娃大青蛙大全大是大非如果v率v恶策但是许多女性的项目部的不行么法可没副本副本副本么方便</p>",
  559. * "created_at": "2018-05-19 15:09:04",
  560. * "updated_at": "2018-05-19 15:09:04",
  561. * "deleted_at": null,
  562. * "install_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  563. * "name": "简约",
  564. * "detail_pic": ""
  565. * }
  566. * }
  567. * ]
  568. * }
  569. * @apiErrorExample {json} Error-Response:
  570. * HTTP/1.1 400 Bad Request
  571. * {
  572. * "state": false,
  573. * "code": 1000,
  574. * "message": "传入参数不正确",
  575. * "data": null or []
  576. * }
  577. * 可能出现的错误代码:
  578. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  579. */
  580. public function albumFavoriteList(Request $request)
  581. {
  582. $userAuth = Auth('api')->user();
  583. if (!$userAuth) {
  584. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  585. }
  586. $validator = Validator::make($request->all(), [
  587. 'store_id' => 'required',
  588. ], [
  589. 'store_id.required' => '缺少商户参数',
  590. ]);
  591. if ($validator->fails()) {
  592. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  593. }
  594. $data = $request->input();
  595. $favorite = AlbumFavoriteModel::where([['user_id',$userAuth->id],['store_id',$data['store_id']]])->get();
  596. foreach ($favorite as $key => $val) {
  597. $favorite[$key]['goods'] = AlbumProductModel::where([['id',$val['product_id']],['store_id',$data['store_id']]])->first();
  598. }
  599. return $this->api($favorite);
  600. }
  601. /**
  602. * @api {post} /api/album/get-watch-recored 查看客户浏览情况(get-watch-recored)
  603. * @apiDescription 查看客户浏览情况(get-watch-recored)
  604. * @apiGroup Album
  605. * @apiPermission none
  606. * @apiVersion 0.1.0
  607. * @apiParam {int} [store_id] 商户id 模拟值为0
  608. * @apiParam {int} [type] 查询方式 1 按用户 2 按时间 3 按类型
  609. * @apiParam {int} [user_id] user_id
  610. * @apiParam {int} [action] 行为类型 1 收藏 2查看类目 3查看商品 4登陆 5点击图片 6 点击导航 7一键拨号
  611. * @apiParam {int} [start_time] 查询开始时间
  612. * @apiParam {int} [end_time] 查询结束时间
  613. * @apiSuccessExample {json} Success-Response:
  614. * HTTP/1.1 200 OK
  615. * {
  616. * "status": true,
  617. * "status_code": 0,
  618. * "message": "",
  619. * "data": [
  620. * "type1":{ 1 收藏 2查看类目 3查看商品 4登陆 5点击图片 6 点击导航 7一键拨号
  621. * "time": 2018-1-1 10:10:12,
  622. * "action": '做了什么什么都做',
  623. * "user": [
  624. * "username":"王小贱",
  625. * "avatar":"awdawdawdawdawdawd",头像
  626. * "phone":"1123123123123"
  627. * ]
  628. * }
  629. * ...
  630. * "count":6;
  631. * ]
  632. * }
  633. * @apiErrorExample {json} Error-Response:
  634. * HTTP/1.1 400 Bad Request
  635. * {
  636. * "state": false,
  637. * "code": 1000,
  638. * "message": "传入参数不正确",
  639. * "data": null or []
  640. * }
  641. * 可能出现的错误代码:
  642. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  643. */
  644. public function albumGetWatchRecord(Request $request)
  645. {
  646. $userAuth = Auth('api')->user();
  647. if (!$userAuth) {
  648. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  649. }
  650. $validator = Validator::make($request->all(), [
  651. 'store_id' => 'required',
  652. 'type' => 'required'
  653. ], [
  654. 'store_id.required' => '缺少商户参数',
  655. 'type.required' => '缺少类型参数',
  656. ]);
  657. if ($validator->fails()) {
  658. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  659. }
  660. $type = $request->input('type');
  661. $store_id = $request->input('store_id');
  662. if ($userAuth->is_dealer != 1) {
  663. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  664. }
  665. $user_agent = AlbumAgentModel::where('user_id', $userAuth->id)->first();
  666. $query = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id]]);
  667. switch ($type) {
  668. case '1':
  669. if (!$request->input('user_id')) {
  670. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!');
  671. }
  672. $user = AlbumUserModel::find(request('user_id'));
  673. $query = $query->where('open_id', $user->open_id);
  674. break;
  675. case '2':
  676. if (!$request->input('start_time') || !$request->input('end_time')) {
  677. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!');
  678. }
  679. $start_time = date('Y-m-d H:i:s', $request->input('start_time'));
  680. $end_time = date('Y-m-d H:i:s', $request->input('end_time'));
  681. $query = $query->where([['created_at','>=',$start_time],['created_at','<=',$end_time]]);
  682. break;
  683. case '3':
  684. if (!$request->input('action')) {
  685. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!');
  686. }
  687. $query = $query->where([['action',$request->input('action')]]);
  688. break;
  689. }
  690. $res = $query->get();
  691. $action = '';
  692. foreach ($res as $key => $val) {
  693. \Log::info('action:' . $val->action . ',id:' . $val->id . ';end');
  694. if ($val->action == 4) {
  695. $action = '进入我的画册';
  696. } elseif ($val->action == 1 || $val->action == 3) {
  697. $goods_data = json_decode($val->detail, true);
  698. $goods_id = $goods_data['goods_id'];
  699. $goods = AlbumProductModel::find($goods_id);
  700. if (!$goods) {
  701. continue;
  702. }
  703. $cat = AlbumCatModel::find($goods->cat_id);
  704. $val->action == 1 ? $act = '收藏' : $act = '查看';
  705. if (empty($cat)) {
  706. continue;
  707. }
  708. $action = $act . '了您的' . $cat->name . '分类下的商品 ' . $goods->name;
  709. } elseif ($val->action == 2) {
  710. $cat_data = json_decode($val->detail, true);
  711. if ($cat_data['cat_id'] == "undefined" || !$cat_data['cat_id']) {
  712. continue;
  713. }
  714. $cat = AlbumCatModel::find($cat_data['cat_id']);
  715. if (empty($cat)) {
  716. continue;
  717. }
  718. $action = '浏览了您的 ' . $cat->name . '分类下的商品列表';
  719. } elseif ($val->action == 5) {
  720. $goods_data = json_decode($val->detail, true);
  721. $goods_id = $goods_data['goods_id'];
  722. $goods = AlbumProductModel::find($goods_id);
  723. if (!$goods) {
  724. continue;
  725. }
  726. $cat = AlbumCatModel::find($goods->cat_id);
  727. if (empty($cat)) {
  728. continue;
  729. }
  730. $action = '点击了您的' . $cat->name . '分类下的商品 ' . $goods->name . '的' . $goods_data['detail'];
  731. } elseif ($val->action == 6) {
  732. $detail = json_decode($val->detail, true);
  733. $address = $detail['detail'];
  734. $action = '查看了您的地址' . $address . ',并且点击了导航';
  735. } elseif ($val->action == 7) {
  736. $detail = json_decode($val->detail, true);
  737. $phone = $detail['detail'];
  738. $action = '查看了您的电话' . $phone . ',并且点击了拨号';
  739. }
  740. $user = AlbumUserModel::where([
  741. ['open_id',$val->open_id],['store_id',$val->store_id]
  742. ])->select(['username','avatar','phone'])->first();
  743. $data_res[] = [
  744. 'time' => $val->created_at,
  745. 'action' => $action,
  746. 'user' => $user
  747. ];
  748. }
  749. return $this->api(compact('data_res'));
  750. }
  751. /**
  752. * @api {post} /api/album/get_data_goods 获取访问数据(get_data_goods)
  753. * @apiDescription 获取访问数据(get_data_goods)
  754. * @apiGroup Album
  755. * @apiPermission 需要登录
  756. * @apiVersion 0.1.0
  757. * @apiParam {int} [store_id] 商户id 模拟值为0
  758. * @apiSuccessExample {json} Success-Response:
  759. * HTTP/1.1 200 OK
  760. * {
  761. * "status": true,
  762. * "status_code": 0,
  763. * "message": "",
  764. * "data": [
  765. * {
  766. * "1": [
  767. * 'name':'asdawd',
  768. * 'point':'asdawd',
  769. * 'num':'1',
  770. * ],
  771. * }
  772. * ]
  773. * }
  774. * @apiErrorExample {json} Error-Response:
  775. * HTTP/1.1 400 Bad Request
  776. * {
  777. * "state": false,
  778. * "code": 1000,
  779. * "message": "传入参数不正确",
  780. * "data": null or []
  781. * }
  782. * 可能出现的错误代码:
  783. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  784. */
  785. public function albumGetDataGoods(Request $request)
  786. {
  787. $userAuth = Auth('api')->user();
  788. if (!$userAuth) {
  789. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  790. }
  791. $validator = Validator::make($request->all(), [
  792. 'store_id' => 'required'
  793. ], [
  794. 'store_id.required' => '缺少商户参数'
  795. ]);
  796. if ($validator->fails()) {
  797. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  798. }
  799. $store_id = $request->input('store_id');
  800. if ($userAuth->is_dealer != 1) {
  801. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  802. }
  803. $user_agent = AlbumAgentModel::where('user_id', $userAuth->id)->first();
  804. $res = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id],['action',3]])->get();
  805. $arr = array();
  806. $total = 0;
  807. foreach ($res as $key => $val) {
  808. $goods_data = json_decode($val->detail, true);
  809. $goods_id = $goods_data['goods_id'];
  810. $goods = AlbumProductModel::find($goods_id);
  811. if (!$goods) {
  812. continue;
  813. }
  814. if (isset($arr[$goods->id])) {
  815. $arr[$goods->id]['num']++;
  816. } else {
  817. $arr[$goods->id]['num'] = 1;
  818. $arr[$goods->id]['name'] = $goods->name;
  819. }
  820. $total++;
  821. }
  822. foreach ($arr as $key => $val) {
  823. $arr[$key]['point'] = ($val['num'] / $total * 100) . '%';
  824. }
  825. return $this->api(compact('arr'));
  826. }
  827. /**
  828. * @api {post} /api/album/get_data_cat 获取分类访问数据(get_data_cat)
  829. * @apiDescription 获取分类访问数据(get_data_cat)
  830. * @apiGroup Album
  831. * @apiPermission 需要登录
  832. * @apiVersion 0.1.0
  833. * @apiParam {int} [store_id] 商户id 模拟值为0
  834. * @apiParam {int} [parent_id]
  835. * @apiSuccessExample {json} Success-Response:
  836. * HTTP/1.1 200 OK
  837. * {
  838. * "status": true,
  839. * "status_code": 0,
  840. * "message": "",
  841. * "data": [
  842. * {
  843. * "1": [
  844. * 'name':'asdawd',
  845. * 'point':'asdawd',
  846. * 'num':'1',
  847. * ],
  848. * }
  849. * ]
  850. * }
  851. * @apiErrorExample {json} Error-Response:
  852. * HTTP/1.1 400 Bad Request
  853. * {
  854. * "state": false,
  855. * "code": 1000,
  856. * "message": "传入参数不正确",
  857. * "data": null or []
  858. * }
  859. * 可能出现的错误代码:
  860. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  861. */
  862. public function albumGetDataCat(Request $request)
  863. {
  864. $userAuth = Auth('api')->user();
  865. if (!$userAuth) {
  866. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  867. }
  868. $validator = Validator::make($request->all(), [
  869. 'store_id' => 'required',
  870. 'parent_id' => 'required'
  871. ], [
  872. 'store_id.required' => '缺少商户参数',
  873. 'parent_id.required' => '缺少风格参数',
  874. ]);
  875. if ($validator->fails()) {
  876. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  877. }
  878. $store_id = $request->input('store_id');
  879. $parent_id = $request->input('parent_id');
  880. if ($userAuth->is_dealer != 1) {
  881. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  882. }
  883. $user_agent = AlbumAgentModel::where('user_id', $userAuth->id)->first();
  884. $cat = AlbumCatModel::where([['store_id',$store_id],['parent_id', $parent_id]])->get(['name','id'])->toArray();
  885. $total = 0;
  886. foreach ($cat as $key => $val){
  887. $count = CustomerCatRecordModel::where([['agent_id',$user_agent->id],['store_id',$store_id],['cat_id',$val['id']]])->count();
  888. $total += $count;
  889. $cat[$key]['num'] = $count;
  890. }
  891. foreach ($cat as $key => $val) {
  892. if ($val['num'] == 0 || $total == 0) {
  893. $cat[$key]['point'] = 0;
  894. } else {
  895. $cat[$key]['point'] = ($val['num'] / $total * 100) . '%';
  896. }
  897. }
  898. return $this->api(compact('cat'));
  899. }
  900. /**
  901. * @api {post} /api/album/get_data_cat_single 单用户获取分类访问数据(get_data_cat_single)
  902. * @apiDescription 单用户获取分类访问数据(get_data_cat_single)
  903. * @apiGroup Album
  904. * @apiPermission 需要登录
  905. * @apiVersion 0.1.0
  906. * @apiParam {int} [store_id] 商户id 模拟值为0
  907. * @apiParam {int} [open_id]
  908. * @apiParam {int} [parent_id]
  909. * @apiSuccessExample {json} Success-Response:
  910. * HTTP/1.1 200 OK
  911. * {
  912. * "status": true,
  913. * "status_code": 0,
  914. * "message": "",
  915. * "data": [
  916. * {
  917. * "1": [
  918. * 'name':'asdawd',
  919. * 'point':'asdawd',
  920. * 'num':'1',
  921. * ],
  922. * }
  923. * ]
  924. * }
  925. * @apiErrorExample {json} Error-Response:
  926. * HTTP/1.1 400 Bad Request
  927. * {
  928. * "state": false,
  929. * "code": 1000,
  930. * "message": "传入参数不正确",
  931. * "data": null or []
  932. * }
  933. * 可能出现的错误代码:
  934. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  935. */
  936. public function albumGetDataCatSingle(Request $request)
  937. {
  938. $userAuth = Auth('api')->user();
  939. if (!$userAuth) {
  940. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  941. }
  942. $validator = Validator::make($request->all(), [
  943. 'store_id' => 'required',
  944. 'open_id' => 'required',
  945. 'parent_id' => 'required'
  946. ], [
  947. 'store_id.required' => '缺少商户参数',
  948. 'open_id.required' => '缺少风格参数',
  949. 'parent_id.required' => '缺少父分类参数',
  950. // 'end.required'=>'缺少结束时间参数',
  951. //'start.required'=>'缺少开始时间参数',
  952. ]);
  953. if ($validator->fails()) {
  954. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  955. }
  956. $store_id = $request->input('store_id');
  957. $open_id = $request->input('open_id');
  958. $parent_id = $request->input('parent_id');
  959. $end = $request->input('end');
  960. $start = $request->input('start');
  961. if (!$end) {
  962. $end = time();
  963. }
  964. if (!$start) {
  965. $start = 0;
  966. }
  967. $end = date('Y-m-d H:i:s', $end);
  968. $start = date('Y-m-d H:i:s', $start);
  969. if ($userAuth->is_dealer != 1) {
  970. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  971. }
  972. $user_agent = AlbumAgentModel::where('user_id', $userAuth->id)->first();
  973. $cat = AlbumCatModel::where([['store_id',$store_id],['parent_id',$parent_id]])->get(['name','id'])->toArray();
  974. $total = 0;
  975. foreach ($cat as $key => $val) {
  976. $count = CustomerCatRecordModel::where([['agent_id',$user_agent->id],['store_id',$store_id],['open_id',$open_id],['cat_id',$val['id']],['updated_at','>=',$start],['updated_at','<=',$end]])->count();
  977. $total += $count;
  978. $cat[$key]['num'] = $count;
  979. }
  980. foreach ($cat as $key => $val) {
  981. if ($val['num'] == 0 || $total == 0) {
  982. $cat[$key]['point'] = 0;
  983. } else {
  984. $cat[$key]['point'] = ($val['num'] / $total * 100) . '%';
  985. }
  986. }
  987. return $this->api(compact('cat'));
  988. }
  989. /**
  990. * @api {post} /api/album/get-cart-of-watch 客户浏览情况概览(get-cart-of-watch)
  991. * @apiDescription 客户浏览情况概览(get-cart-of-watch)
  992. * @apiGroup Album
  993. * @apiPermission none
  994. * @apiVersion 0.1.0
  995. * @apiParam {int} [store_id] 商户id 模拟值为0
  996. * @apiSuccessExample {json} Success-Response:
  997. * HTTP/1.1 200 OK
  998. * {
  999. * "status": true,
  1000. * "status_code": 0,
  1001. * "message": "",
  1002. * "data": [
  1003. * "count_today":0,
  1004. * "count_all":0,
  1005. * "count_share":0,
  1006. * "user": {
  1007. * "username":"王小贱",
  1008. * "avatar":"awdawdawdawdawdawd",头像
  1009. * "phone":"1123123123123"
  1010. * "open_id":"1123123123123"
  1011. * }
  1012. * "count":6,
  1013. * "action":[
  1014. * "type1":1,
  1015. * "type2":1,
  1016. * "type3":1,
  1017. * "type4":1,
  1018. * "type5":1,
  1019. * "type6":1,
  1020. * "type7":1,
  1021. * ]
  1022. * ]
  1023. * }
  1024. * @apiErrorExample {json} Error-Response:
  1025. * HTTP/1.1 400 Bad Request
  1026. * {
  1027. * "state": false,
  1028. * "code": 1000,
  1029. * "message": "传入参数不正确",
  1030. * "data": null or []
  1031. * }
  1032. * 可能出现的错误代码:
  1033. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1034. */
  1035. public function albumGetCartOfWatch(Request $request)
  1036. {
  1037. $userAuth = Auth('api')->user();
  1038. if (!$userAuth) {
  1039. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  1040. }
  1041. $validator = Validator::make($request->all(), [
  1042. 'store_id' => 'required',
  1043. 'end' => 'required',
  1044. 'start' => 'required',
  1045. ], [
  1046. 'store_id.required' => '缺少商户参数',
  1047. 'end.required' => '缺少结束时间参数',
  1048. 'start.required' => '缺少开始时间参数',
  1049. ]);
  1050. if ($validator->fails()) {
  1051. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1052. }
  1053. $store_id = $request->input('store_id');
  1054. $end = $request->input('end');
  1055. $start = $request->input('start');
  1056. $end= date('Y-m-d H:i:s',$end);
  1057. $start= date('Y-m-d H:i:s',$start);
  1058. if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  1059. // if($userAuth->up_agent_id==0) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未选择经销商!', $validator->messages());
  1060. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  1061. $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();
  1062. $checkAllstart = mktime(0,0,0,date('m'),date('d'),date('Y'));
  1063. $checkAllend = $checkAllstart+86400;
  1064. $checkAllstart = date('Y-m-d H:i:s',$checkAllstart);
  1065. $checkAllend = date('Y-m-d H:i:s',$checkAllend);
  1066. $count_today = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id],['updated_at','>=',$checkAllstart],['updated_at','<=',$checkAllend]])->groupBy('open_id')->count();
  1067. $count_list = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id]])->groupBy('open_id')->get();
  1068. $count_all = count($count_list);
  1069. $count_share = $user_agent->share_times;
  1070. $users = Array();
  1071. if($count_user){
  1072. foreach($count_user as $key=>$val){
  1073. $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$val->store_id]])->select(['id','username','avatar','phone','open_id'])->first();
  1074. $customer = CustomerDetailsModel::where([['store_id',$store_id],['open_id',$val->open_id],['agent_id',$user_agent->id]])->first(['purpose_level','comment','tips']);
  1075. $user->time = $val->updated_at;
  1076. if($customer){
  1077. $user->purpose_level = $customer->purpose_level;
  1078. $user->comment = $customer->comment;
  1079. $user->tips = $customer->tips;
  1080. }else{
  1081. $user->purpose_level = 0;
  1082. $user->comment = 0;
  1083. $user->tips = 0;
  1084. }
  1085. $users[] = $user;
  1086. }
  1087. }
  1088. $count = count($users);
  1089. $action = Array();
  1090. for($i=1;$i<=7;$i++){
  1091. $res = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id],['action',$i]])->get();
  1092. $action['type'.$i] = count($res);
  1093. }
  1094. return $this->api(compact('count','users','action','count_today','count_all','count_share'));
  1095. }
  1096. /**
  1097. * @api {get} /api/album/checklogin 登陆应用(checklogin)
  1098. * @apiDescription 登陆应用(checklogin)
  1099. * @apiGroup Album
  1100. * @apiPermission none
  1101. * @apiVersion 0.1.0
  1102. * @apiParam {int} [store_id] 商户id 模拟值为0
  1103. * @apiSuccessExample {json} Success-Response:
  1104. * HTTP/1.1 200 OK
  1105. * {
  1106. * "status": true,
  1107. * "status_code": 0,
  1108. * "message": "",
  1109. * "data": {
  1110. *
  1111. * }
  1112. * }
  1113. * @apiErrorExample {json} Error-Response:
  1114. * HTTP/1.1 400 Bad Request
  1115. * {
  1116. * "state": false,
  1117. * "code": 1000,
  1118. * "message": "传入参数不正确",
  1119. * "data": null or []
  1120. * }
  1121. * 可能出现的错误代码:
  1122. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1123. */
  1124. public function albumchecklogin(Request $request)
  1125. {
  1126. $validator = Validator::make($request->all(), [
  1127. 'store_id' => 'required',
  1128. ],[
  1129. 'store_id.required'=>'缺少商户参数',
  1130. ]);
  1131. if ($validator->fails()) {
  1132. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1133. }
  1134. $data = $request->input();
  1135. $favorite = AlbumManufacturerModel::where([['store_id',$data['store_id']]])->first();
  1136. $conf = $favorite->redirectapp;
  1137. return $this->api($conf);
  1138. }
  1139. /**
  1140. * @api {get} /api/album/favorite_del 收藏删除(favorite_del)
  1141. * @apiDescription 收藏删除(favorite_del)
  1142. * @apiGroup Album
  1143. * @apiPermission none
  1144. * @apiVersion 0.1.0
  1145. * @apiParam {int} [store_id] 商户id 模拟值为0
  1146. * @apiParam {int} [favorite_id] 收藏id
  1147. * @apiSuccessExample {json} Success-Response:
  1148. * HTTP/1.1 200 OK
  1149. * {
  1150. * "status": true,
  1151. * "status_code": 0,
  1152. * "message": "",
  1153. * "data":[]//返回状态
  1154. * }
  1155. * @apiErrorExample {json} Error-Response:
  1156. * HTTP/1.1 400 Bad Request
  1157. * {
  1158. * "state": false,
  1159. * "code": 1000,
  1160. * "message": "传入参数不正确",
  1161. * "data": null or []
  1162. * }
  1163. * 可能出现的错误代码:
  1164. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1165. */
  1166. public function albumFavoriteDel(Request $request)
  1167. {
  1168. //$userAuth = AlbumXyxUserModel::find(1);
  1169. $userAuth = Auth('api')->user();
  1170. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  1171. $validator = Validator::make($request->all(), [
  1172. 'store_id' => 'required',
  1173. 'favorite_id' => 'required',
  1174. ],[
  1175. 'store_id.required'=>'缺少商户参数',
  1176. 'favorite_id.required'=>'缺少收藏参数',
  1177. ]);
  1178. if ($validator->fails()) {
  1179. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1180. }
  1181. $data = $request->input();
  1182. $favorite = AlbumFavoriteModel::find($data['favorite_id']);
  1183. if(!$favorite){
  1184. $d = [
  1185. 'code' =>1,
  1186. 'msg' =>'删除失败,或者该收藏已移除',
  1187. ];
  1188. } else {
  1189. $res = $favorite->delete();
  1190. if($res){
  1191. $d = [
  1192. 'code' =>1,
  1193. 'msg' =>'删除成功',
  1194. ];
  1195. } else {
  1196. $d = [
  1197. 'code' =>1,
  1198. 'msg' =>'删除失败,或者该收藏已移除',
  1199. ];
  1200. }
  1201. }
  1202. return $this->api($d);
  1203. }
  1204. /**
  1205. * @api {get} /api/album/save_form_id 添加Form_id(save_form_id)
  1206. * @apiDescription 添加Form_id(save_form_id)
  1207. * @apiGroup Album
  1208. * @apiPermission none
  1209. * @apiVersion 0.1.0
  1210. * @apiParam {int} [store_id] 商户id
  1211. * @apiParam {int} [form_id] form_id
  1212. * @apiSuccessExample {json} Success-Response:
  1213. * HTTP/1.1 200 OK
  1214. * {
  1215. * "status": true,
  1216. * "status_code": 0,
  1217. * "message": "",
  1218. * "data": []//返回信息
  1219. * }
  1220. * @apiErrorExample {json} Error-Response:
  1221. * HTTP/1.1 400 Bad Request
  1222. * {
  1223. * "state": false,
  1224. * "code": 1000,
  1225. * "message": "传入参数不正确",
  1226. * "data": null or []
  1227. * }
  1228. * 可能出现的错误代码:
  1229. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1230. */
  1231. public function albumSaveFormId(Request $request)
  1232. {
  1233. $userAuth = Auth('api')->user();
  1234. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  1235. $validator = Validator::make($request->all(), [
  1236. 'store_id' => 'required',
  1237. 'form_id' => 'required',
  1238. ],[
  1239. 'store_id.required'=>'缺少商户参数',
  1240. 'form_id.required'=>'缺少FormId',
  1241. ]);
  1242. if ($validator->fails()) {
  1243. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1244. }
  1245. $data = $request->input();
  1246. $data['open_id'] = $userAuth->open_id;
  1247. $res = AlbumFormId::create($data);
  1248. if($res){
  1249. $d = [
  1250. 'code' =>0,
  1251. 'msg' =>'success',
  1252. ];
  1253. }else{
  1254. $d = [
  1255. 'code' =>1,
  1256. 'msg' =>'error',
  1257. ];
  1258. }
  1259. return $this->api($d);
  1260. }
  1261. /**
  1262. * @api {get} /api/album/add_favorite 添加收藏(add_favorite)
  1263. * @apiDescription 添加收藏(favorite_list)
  1264. * @apiGroup Album
  1265. * @apiPermission none
  1266. * @apiVersion 0.1.0
  1267. * @apiParam {int} [store_id] 商户id
  1268. * @apiParam {int} [product_id] 商品id
  1269. * @apiSuccessExample {json} Success-Response:
  1270. * HTTP/1.1 200 OK
  1271. * {
  1272. * "status": true,
  1273. * "status_code": 0,
  1274. * "message": "",
  1275. * "data": []//返回信息
  1276. * }
  1277. * @apiErrorExample {json} Error-Response:
  1278. * HTTP/1.1 400 Bad Request
  1279. * {
  1280. * "state": false,
  1281. * "code": 1000,
  1282. * "message": "传入参数不正确",
  1283. * "data": null or []
  1284. * }
  1285. * 可能出现的错误代码:
  1286. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1287. */
  1288. public function albumAddFavorite(Request $request)
  1289. {
  1290. $userAuth = Auth('api')->user();
  1291. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  1292. $validator = Validator::make($request->all(), [
  1293. 'store_id' => 'required',
  1294. 'product_id' => 'required',
  1295. ],[
  1296. 'store_id.required'=>'缺少商户参数',
  1297. 'product_id.required'=>'缺少商品参数',
  1298. ]);
  1299. if ($validator->fails()) {
  1300. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1301. }
  1302. $data = $request->input();
  1303. $time = mktime(0,0,0,date('m'),date('d'),date('y'));
  1304. $check = AlbumStatisticalModel::where([['time',$time],['store_id',$data['store_id']]])->first();
  1305. if($check){
  1306. $check->share_times ++;
  1307. $check->save();
  1308. }else{
  1309. $add['time'] = $time;
  1310. $add['store_id'] = $data['store_id'];
  1311. $add['share_times'] = 0;
  1312. $add['favorite_times'] = 1;
  1313. AlbumStatisticalModel::create($add);
  1314. }
  1315. $select_info = ['goods_id' => $data['product_id']];
  1316. if ($userAuth->up_agent_id != 0) {
  1317. $agent = AlbumAgentModel::where('id'. 'up_agent_id')->first();
  1318. $agent->favoriteCount++;
  1319. $agent->interactive++;
  1320. $agent->newCount = $agent->pointCount + $agent->favoriteCount + $agent->callCount + $agent->share_times + $agent->get_count;
  1321. $agent->save();
  1322. $add_record['agent_id'] = $userAuth->up_agent_id;
  1323. $add_record['open_id'] = $userAuth->open_id;
  1324. $add_record['action'] = 1;
  1325. $add_record['store_id'] = $data['store_id'];
  1326. $add_record['detail'] = json_encode($select_info);
  1327. $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
  1328. $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
  1329. try{
  1330. $this->sendLogsMessage($data['store_id'],$agent->open_id,1,$userAuth->username,$agent->g_open_id);
  1331. }catch (\Exception $e){
  1332. }
  1333. AlbumWatchRecord::create($add_record);
  1334. }
  1335. $check_user = AlbumUserModel::find($userAuth->id);
  1336. $check_f = AlbumFavoriteModel::where([['user_id',$userAuth->id],['product_id',$data['product_id']]])->first();
  1337. if(!$check_user||$check_f){
  1338. $d = [
  1339. 'code' =>1,
  1340. 'msg' =>'该用户不存在或者已添加',
  1341. ];
  1342. return $this->api($d);
  1343. }
  1344. $data['user_id'] = $userAuth->id;
  1345. $res = AlbumFavoriteModel::create($data);
  1346. if($res){
  1347. $d = [
  1348. 'code' =>0,
  1349. 'id'=>$res->id,
  1350. 'msg' =>'success',
  1351. ];
  1352. }else{
  1353. $d = [
  1354. 'code' =>1,
  1355. 'msg' =>'error',
  1356. ];
  1357. }
  1358. return $this->api($d);
  1359. }
  1360. /**
  1361. * @api {get} /api/album/cat 分类列表(cat)
  1362. * @apiDescription 画册分类(cat)
  1363. * @apiGroup Album
  1364. * @apiPermission none
  1365. * @apiVersion 0.1.0
  1366. * @apiParam {int} [parent_id] 一级菜单传0 二级菜单的id从一级菜单里面获取
  1367. * @apiParam {int} [store_id] 商户id 模拟值为0
  1368. * @apiSuccessExample {json} Success-Response:
  1369. * HTTP/1.1 200 OK
  1370. * {
  1371. * "status": true,
  1372. * "status_code": 0,
  1373. * "message": "",
  1374. * "data": [
  1375. * {
  1376. * "id": 9,
  1377. * "name": "圣地亚哥",
  1378. * "parent_id": 0,
  1379. * "level": "00",
  1380. * "pic_url": "http://admin.xcx.com/upload/images/20180518/af6cc8fd71241744ccd638afc6ac25f2.png",
  1381. * "created_at": "2018-05-19 14:55:48",
  1382. * "updated_at": "2018-05-19 14:55:48",
  1383. * "store_id": 0,
  1384. * "deleted_at": null,
  1385. * "sort": 0
  1386. * }
  1387. * ]
  1388. * }
  1389. * @apiErrorExample {json} Error-Response:
  1390. * HTTP/1.1 400 Bad Request
  1391. * {
  1392. * "state": false,
  1393. * "code": 1000,
  1394. * "message": "传入参数不正确",
  1395. * "data": null or []
  1396. * }
  1397. * 可能出现的错误代码:
  1398. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1399. */
  1400. public function albumCat(Request $request)
  1401. {
  1402. $validator = Validator::make($request->all(), [
  1403. 'store_id' => 'required',
  1404. ],[
  1405. 'store_id.required'=>'缺少商户参数',
  1406. ]);
  1407. if ($validator->fails()) {
  1408. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1409. }
  1410. $cat_id = $request->input('cat_id') ?? 0;
  1411. $store_id = request('store_id');
  1412. $cats = AlbumCatModel::where([['parent_id',$cat_id],['store_id',$store_id]])->orderByDesc('sort')->get();
  1413. return $this->api($cats);
  1414. }
  1415. /**
  1416. * @api {get} /api/album/style 属性列表(style)
  1417. * @apiDescription 分类样式(style)
  1418. * @apiGroup Album
  1419. * @apiPermission none
  1420. * @apiVersion 0.1.0
  1421. * @apiParam {int} [store_id] 商户id 模拟值为0
  1422. * @apiSuccessExample {json} Success-Response:
  1423. * HTTP/1.1 200 OK
  1424. * {
  1425. * "status": true,
  1426. * "status_code": 0,
  1427. * "message": "",
  1428. * "data": [
  1429. * {
  1430. * "id": 2,
  1431. * "name": "1111",
  1432. * "deleted_at": null,
  1433. * "created_at": "2018-06-05 17:35:08",
  1434. * "updated_at": "2018-06-05 17:35:08",
  1435. * "store_id": 0
  1436. * }
  1437. * ]
  1438. * }
  1439. * @apiErrorExample {json} Error-Response:
  1440. * HTTP/1.1 400 Bad Request
  1441. * {
  1442. * "state": false,
  1443. * "code": 1000,
  1444. * "message": "传入参数不正确",
  1445. * "data": null or []
  1446. * }
  1447. * 可能出现的错误代码:
  1448. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1449. */
  1450. public function albumStyle(Request $request)
  1451. {
  1452. $validator = Validator::make($request->all(), [
  1453. 'store_id' => 'required',
  1454. ],[
  1455. 'store_id.required'=>'缺少商户参数',
  1456. ]);
  1457. if ($validator->fails()) {
  1458. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1459. }
  1460. $store_id = request('store_id');
  1461. $style = AlbumProductStyleModel::where([['store_id',$store_id]])->orderByDesc('id')->get();
  1462. return $this->api($style);
  1463. }
  1464. /**
  1465. * @api {get} /api/album/set-price 经销商修改价格(set-price)
  1466. * @apiDescription 画册(set-price)
  1467. * @apiGroup Album
  1468. * @apiPermission none
  1469. * @apiVersion 0.1.0
  1470. * @apiParam {int} [goods_id] 商品id
  1471. * @apiParam {int} [store_id] 商户id 模拟值为0
  1472. * @apiParam {double} [price] 价格
  1473. * @apiSuccessExample {json} Success-Response:
  1474. * HTTP/1.1 200 OK
  1475. * {
  1476. * "status": true,
  1477. * "status_code": 0,
  1478. * "message": "",
  1479. * "data":[
  1480. * "msg":返回信息,
  1481. * "data":修改后价格
  1482. * ]
  1483. * }
  1484. * @apiErrorExample {json} Error-Response:
  1485. * HTTP/1.1 400 Bad Request
  1486. * {
  1487. * "state": false,
  1488. * "code": 1000,
  1489. * "message": "传入参数不正确",
  1490. * "data": null or []
  1491. * }
  1492. * 可能出现的错误代码:
  1493. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1494. */
  1495. public function albumSetPrice(Request $request)
  1496. {
  1497. $userAuth = Auth('api')->user();
  1498. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  1499. $agent_id = $user_agent['id'];
  1500. $data = $request->all();
  1501. $product = AlbumProductModel::where('id', $data['goods_id'])->first();
  1502. //print_r($data);
  1503. $save = array();
  1504. $return_data = array();
  1505. $save['price'] = $data['price'];
  1506. $check = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->first();
  1507. if(empty($check)){
  1508. $save['agent_id'] = $agent_id;
  1509. $save['store_id'] = $data['store_id'];
  1510. $save['cat_id'] = $product->cat_id;
  1511. $save['name'] = $product->name;
  1512. $save['product_id'] = $data['goods_id'];
  1513. $res = AlbumProductPriceModel::create($save);
  1514. }else{
  1515. $res = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->update($save);
  1516. }
  1517. if($res){
  1518. $return['msg'] = 'success';
  1519. $return_data['price'] = $data['price'];
  1520. } else {
  1521. $return['msg'] = 'error';
  1522. }
  1523. $return['data'] = $return_data;
  1524. return $this->api($return);
  1525. }
  1526. /**
  1527. * @api {post} /api/album/set-phone 获取用户号码(set-phone)
  1528. * @apiDescription 获取用户号码(set-phone)
  1529. * @apiGroup Album
  1530. * @apiPermission none
  1531. * @apiVersion 0.1.0
  1532. * @apiParam {int} [store_id] 商户id 模拟值为0
  1533. * @apiParam {string} [code] code
  1534. * @apiParam {string} [iv] 偏移量
  1535. * @apiParam {string} [encrypted] 加密参数
  1536. * @apiSuccessExample {json} Success-Response:
  1537. * HTTP/1.1 200 OK
  1538. * {
  1539. * "status": true,
  1540. * "status_code": 0,
  1541. * "message": "",
  1542. * "data":[
  1543. * "msg":返回信息,
  1544. * ]
  1545. * }
  1546. * @apiErrorExample {json} Error-Response:
  1547. * HTTP/1.1 400 Bad Request
  1548. * {
  1549. * "state": false,
  1550. * "code": 1000,
  1551. * "message": "传入参数不正确",
  1552. * "data": null or []
  1553. * }
  1554. * 可能出现的错误代码:
  1555. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1556. */
  1557. public function albumSavePhone(Request $request)
  1558. {
  1559. $userAuth = Auth('api')->user();
  1560. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  1561. $validator = Validator::make($request->all(), [
  1562. 'store_id' => 'required',
  1563. 'code' => 'required',
  1564. 'iv' => 'required',
  1565. 'encrypted' => 'required',
  1566. ],[
  1567. 'store_id.required'=>'缺少商户参数',
  1568. 'code.required'=>'缺少code参数',
  1569. 'iv.required'=>'缺少偏移量参数',
  1570. 'encrypted.required'=>'缺少加密参数',
  1571. ]);
  1572. if ($validator->fails()) {
  1573. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1574. }
  1575. $this->wechat_app = AlbumManufacturerModel::where('store_id',$request->input('store_id'))->first();
  1576. $config = [
  1577. 'app_id' => $this->wechat_app->xyx_id,
  1578. 'secret' => $this->wechat_app->xyx_secret,
  1579. // 下面为可选项
  1580. // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
  1581. 'response_type' => 'array',
  1582. ];
  1583. $app = Factory::miniProgram($config);
  1584. $res = $app->auth->session($request->input('code'));
  1585. if (!$res || empty($res['openid'])) {
  1586. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '获取用户OpenId失败!', $validator->messages());
  1587. }
  1588. $session_key = $res['session_key'];
  1589. $pc = new WXBizDataCrypt($this->wechat_app->xyx_id, $session_key);
  1590. $errCode = $pc->decryptData($request->input('encrypted'), $request->input('iv'), $data);
  1591. if($errCode==0){
  1592. $data = json_decode($data,true);
  1593. $userAuth->phone = $data['phoneNumber'];
  1594. $res = $userAuth->save();
  1595. if($res){
  1596. return $this->api(['msg'=>'success']);
  1597. }else{
  1598. return $this->api(['msg'=>'error']);
  1599. }
  1600. }elseif($errCode == -41003){
  1601. return $this->api(['msg'=>'请求错误,请重试']);
  1602. }
  1603. }
  1604. /**
  1605. * @api {post} /api/album/set-watch 获取用户操作记录(set-watch)
  1606. * @apiDescription 获取用户操作记录(set-watch)
  1607. * @apiGroup Album
  1608. * @apiPermission none
  1609. * @apiVersion 0.1.0
  1610. * @apiParam {int} [store_id] 商户id 模拟值为0
  1611. * @apiParam {string} [detail] 详细
  1612. * @apiParam {string} [type] 5点击图片 6 点击导航 7一键拨号
  1613. * @apiSuccessExample {json} Success-Response:
  1614. * HTTP/1.1 200 OK
  1615. * {
  1616. * "status": true,
  1617. * "status_code": 0,
  1618. * "message": "",
  1619. * "data":[
  1620. * "msg":返回信息,
  1621. * ]
  1622. * }
  1623. * @apiErrorExample {json} Error-Response:
  1624. * HTTP/1.1 400 Bad Request
  1625. * {
  1626. * "state": false,
  1627. * "code": 1000,
  1628. * "message": "传入参数不正确",
  1629. * "data": null or []
  1630. * }
  1631. * 可能出现的错误代码:
  1632. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1633. */
  1634. public function albumSetWatch(Request $request)
  1635. {
  1636. $userAuth = Auth('api')->user();
  1637. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  1638. $validator = Validator::make($request->all(), [
  1639. 'store_id' => 'required',
  1640. 'type' => 'required',
  1641. 'detail' => 'required',
  1642. ],[
  1643. 'store_id.required'=>'缺少商户参数',
  1644. 'type.required'=>'缺少类型参数',
  1645. 'detail.required'=>'缺少详细参数',
  1646. ]);
  1647. if ($validator->fails()) {
  1648. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1649. }
  1650. $data = $request->input();
  1651. if($data['type']==5&&!empty($data['goods_id'])) {
  1652. $select_info = ['goods_id'=>$data['goods_id'],'detail'=>$data['detail']];
  1653. }elseif($data['type']==5&&empty($data['goods_id'])){
  1654. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '缺少goodsid');
  1655. }else{
  1656. $select_info = ['detail'=>$data['detail']];
  1657. }
  1658. if($userAuth->up_agent_id!=0){
  1659. $add_record['agent_id'] = $userAuth->up_agent_id;
  1660. $add_record['open_id'] = $userAuth->open_id;
  1661. $add_record['action'] = $data['type'];
  1662. $add_record['store_id'] = $data['store_id'];
  1663. $add_record['detail'] = json_encode($select_info);
  1664. // dd($add_record);
  1665. $res = AlbumWatchRecord::create($add_record);
  1666. $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
  1667. if ($data['type'] == 7 || $data['type'] == 6) {
  1668. $user_agent->callCount++;
  1669. $user_agent->interactive++;
  1670. $user_agent->newCount = $user_agent->pointCount + $user_agent->favoriteCount + $user_agent->callCount + $user_agent->share_times + $user_agent->get_count;
  1671. $user_agent->save();
  1672. }
  1673. $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
  1674. if($res){
  1675. try{
  1676. $this->sendLogsMessage($data['store_id'],$agent->open_id,$data['type'],$userAuth->username,$agent->g_open_id);
  1677. }catch (\Exception $e){
  1678. }
  1679. return $this->api(['msg'=>'success']);
  1680. }else{
  1681. return $this->api(['msg'=>'error']);
  1682. }
  1683. }
  1684. }
  1685. public function test()
  1686. {
  1687. getUrlImage('111', public_path() . '/base/poster/avatar/' . 1 . "/1.jpg");
  1688. /*$weChatApp = AlbumManufacturerModel::where('store_id', 1)->first();\Log::info('2221');
  1689. $config = [
  1690. 'app_id' => $weChatApp->G_app_id,
  1691. 'secret' => $weChatApp->G_app_secret,
  1692. 'response_type' => 'array',
  1693. ];\Log::info('2224');
  1694. $app = Factory::officialAccount($config);
  1695. $text = new Text('111');//dd($text);
  1696. $res_msg = $app->customer_service->message($text)->to('o_O0HuA4ugJG0npjLSL_Cd33FN8c')->send();dd($res_msg);*/
  1697. //\Tinify\setKey('8NTpkbbHjKxSDxhWqNftM1cPDcQTs3CD');
  1698. //$source = \Tinify\fromUrl("https://tinypng.com/images/panda-happy.png");
  1699. //$source->toFile(public_path() . '/base/poster/download/111.png');
  1700. echo 111;
  1701. }
  1702. /**
  1703. * @param $storeid
  1704. * @param $open_id
  1705. * @param $action 1 收藏 2查看类目 3查看商品 4登陆 5点击图片 6 点击导航 7一键拨号
  1706. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  1707. */
  1708. private function sendLogsMessage($storeid,$open_id,$action,$name,$g_open_id)
  1709. {
  1710. $user = AlbumUserModel::where('open_id',$open_id)->first();
  1711. $formId = AlbumFormId::where([['open_id',$open_id]])->first();
  1712. $content = '';
  1713. switch ($action){
  1714. case 1:
  1715. $content = '收藏了您的产品';
  1716. break;
  1717. case 2;
  1718. $content = '查看了您的产品列表';
  1719. break;
  1720. case 3;
  1721. $content = '查看了您的商品';
  1722. break;
  1723. case 4;
  1724. $content = '进入了您的画册';
  1725. break;
  1726. case 5;
  1727. $content = '点击了您的某款产品详情';
  1728. break;
  1729. case 6;
  1730. $content = '点击了导航到您的位置';
  1731. break;
  1732. case 7;
  1733. $content = '点击了您的号码';
  1734. break;
  1735. case 8;
  1736. $content = '分享了您的画册';
  1737. break;
  1738. }
  1739. $weChatApp = AlbumManufacturerModel::where('store_id', $storeid)->first();//\Log::info('2221');
  1740. $res_account = $this->accountMesage($g_open_id,$weChatApp,$name,$content);
  1741. // \Log::info($res_account);
  1742. if($user && $formId && (!$weChatApp->G_app_id || !$weChatApp->G_app_secret)){
  1743. $config_app = [
  1744. 'app_id' => $weChatApp->app_id,
  1745. 'secret' => $weChatApp->app_secret,
  1746. 'response_type' => 'array',
  1747. ];
  1748. $app_x = Factory::miniProgram($config_app);
  1749. $res = $app_x->template_message->send([
  1750. 'touser' => $open_id,
  1751. 'template_id' => '9PDTfnhsRvdNwpPMIcYLL7wQF4SZkB8-9ZhXUfthbmw',
  1752. 'page' => 'pages/sell/sell',
  1753. 'form_id' => $formId->form_id,
  1754. 'data' => [
  1755. 'keyword1' => $name,
  1756. 'keyword2' => $content,
  1757. 'keyword3' => date('Y-m-d H:i'),
  1758. ],
  1759. ]);
  1760. // dd($res);
  1761. if($res){
  1762. $formId->delete();
  1763. }
  1764. }
  1765. }
  1766. /**
  1767. * send account message
  1768. *
  1769. * @param $g_open_id string
  1770. * @param $weChatApp object
  1771. * @param $name string
  1772. * @param $content string
  1773. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  1774. *
  1775. * @return array|string
  1776. */
  1777. private function accountMesage($g_open_id,$weChatApp,$name,$content)
  1778. {
  1779. // Cache::flush();
  1780. $value = Cache::get($g_open_id);
  1781. \Log::info($value);\Log::info('2225');
  1782. if ($g_open_id && (!$value || ($value + 60) <= time())) {
  1783. Cache::put($g_open_id, time(), 1);
  1784. $config = [
  1785. 'app_id' => $weChatApp->G_app_id,
  1786. 'secret' => $weChatApp->G_app_secret,
  1787. 'response_type' => 'array',
  1788. ];
  1789. $app = Factory::officialAccount($config);
  1790. $res = $app->template_message->send([
  1791. 'touser' => $g_open_id,
  1792. 'template_id' => 'lXMh2Xjg62C4LjB50QVi9ETbcvU21WElvqNCHBCsWuM',
  1793. 'url' => '',
  1794. 'data' => [
  1795. 'keyword1' => $name,
  1796. 'keyword2' => $content,
  1797. 'keyword3' => date('Y-m-d H:i'),
  1798. ],
  1799. 'miniprogram' => [
  1800. 'appid' => $weChatApp->app_id,
  1801. 'pagepath' => 'pages/sell/sell'
  1802. ],
  1803. ]);
  1804. return $res;
  1805. } else {
  1806. return false;
  1807. }
  1808. }
  1809. /**
  1810. * @api {get} /api/album/add_agent 申请经销商(add_agent)
  1811. * @apiDescription 申请经销商(add_agent)
  1812. * @apiGroup Album
  1813. * @apiPermission none
  1814. * @apiVersion 0.1.0
  1815. * @apiParam {int} [store_id] 商户id
  1816. * @apiParam {int} [realname] 姓名
  1817. * @apiParam {int} [address] 地址
  1818. * @apiParam {double} [lat] lat
  1819. * @apiParam {double} [lon] lon
  1820. * @apiParam {int} [phone] 电话
  1821. * @apiSuccessExample {json} Success-Response:
  1822. * HTTP/1.1 200 OK
  1823. * {
  1824. * "status": true,
  1825. * "status_code": 0,
  1826. * "message": "",
  1827. * "data": []//返回信息
  1828. * }
  1829. * @apiErrorExample {json} Error-Response:
  1830. * HTTP/1.1 400 Bad Request
  1831. * {
  1832. * "state": false,
  1833. * "code": 1000,
  1834. * "message": "传入参数不正确",
  1835. * "data": null or []
  1836. * }
  1837. * 可能出现的错误代码:
  1838. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1839. */
  1840. public function albumAddAgent(Request $request)
  1841. {
  1842. $userAuth = Auth('api')->user();
  1843. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  1844. $validator = Validator::make($request->all(), [
  1845. 'realname' => 'required',
  1846. 'address' => 'required',
  1847. 'phone' => 'required',
  1848. 'store_id' => 'required',
  1849. ],[
  1850. 'address.required'=>'缺少地址参数',
  1851. 'realname.required'=>'缺少信息参数',
  1852. 'phone.required'=>'缺少电话参数',
  1853. 'store_id.required'=>'缺少商户参数',
  1854. ]);
  1855. if ($validator->fails()) {
  1856. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1857. }
  1858. $data = $request->input();
  1859. $url = "https://apis.map.qq.com/ws/geocoder/v1/?address=".$data['address']."&key=".env('QQMAP');
  1860. $local = $this->curlGet($url);
  1861. $res = json_decode($local,true);
  1862. $agent_check = AlbumAgentModel::where([['store_id',$data['store_id']],['user_id',$userAuth->id]])->first();
  1863. if($agent_check){
  1864. if($agent_check->status==0) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户已提交申请!');
  1865. $agent_check->phone = $data['phone'];
  1866. $agent_check->address = $data['address'];
  1867. $agent_check->lon = $res['result']['location']['lng'];
  1868. $agent_check->lat = $res['result']['location']['lat'];
  1869. $agent_check->realname = $data['realname'];
  1870. if($agent_check->save()) return $this->api([
  1871. 'code' =>0,
  1872. 'msg' =>'success',
  1873. ]);
  1874. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '保存失败!');
  1875. }
  1876. $data['status'] = 0;
  1877. $data['user_id'] = $userAuth->id;
  1878. $data['lon'] = $res['result']['location']['lng'];
  1879. $data['lat'] = $res['result']['location']['lat'];
  1880. $data['name'] = $userAuth->username;
  1881. $res = AlbumAgentModel::create($data);
  1882. if($res){
  1883. $d = [
  1884. 'code' =>0,
  1885. 'msg' =>'success',
  1886. ];
  1887. }else{
  1888. $d = [
  1889. 'code' =>1,
  1890. 'msg' =>'error',
  1891. ];
  1892. }
  1893. return $this->api($d);
  1894. }
  1895. /**
  1896. * @api {get} /api/album/get-agent-address 获取经销商地址(get-agent-address)
  1897. * @apiDescription 获取经销商地址(get-agent-address)
  1898. * @apiGroup Album
  1899. * @apiPermission none
  1900. * @apiVersion 0.1.0
  1901. * @apiSuccessExample {json} Success-Response:
  1902. * HTTP/1.1 200 OK
  1903. * {
  1904. * "status": true,
  1905. * "status_code": 0,
  1906. * "message": "",
  1907. * "data":[
  1908. * "realname":
  1909. * "phone":
  1910. * "address":
  1911. * ]
  1912. * }
  1913. * @apiErrorExample {json} Error-Response:
  1914. * HTTP/1.1 400 Bad Request
  1915. * {
  1916. * "state": false,
  1917. * "code": 1000,
  1918. * "message": "传入参数不正确",
  1919. * "data": null or []
  1920. * }
  1921. * 可能出现的错误代码:
  1922. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1923. */
  1924. public function albumGetAgentAdress(Request $request)
  1925. {
  1926. $userAuth = Auth('api')->user();
  1927. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  1928. $validator = Validator::make($request->all(), [
  1929. 'store_id' => 'required',
  1930. ],[
  1931. 'store_id.required'=>'缺少商户参数',
  1932. ]);
  1933. if ($validator->fails()) {
  1934. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  1935. }
  1936. $data = $request->input();
  1937. if($userAuth->is_dealer == 1){
  1938. $user_agent = AlbumAgentModel::where([['store_id',$data['store_id']],['user_id',$userAuth->id]])->first(['address','phone','realname']);
  1939. }else{
  1940. $user_agent = null;
  1941. }
  1942. return $this->api(compact('user_agent'));
  1943. }
  1944. /**
  1945. * @api {get} /api/album/get-banner 获取banner和視頻(get-banner)
  1946. * @apiDescription 获取banner和視頻(get-banner)
  1947. * @apiGroup Album
  1948. * @apiPermission none
  1949. * @apiVersion 0.1.0
  1950. * @apiSuccessExample {json} Success-Response:
  1951. * HTTP/1.1 200 OK
  1952. * {
  1953. * "status": true,
  1954. * "status_code": 0,
  1955. * "message": "",
  1956. * "data":[
  1957. * "video":{
  1958. * 'url':22222,
  1959. * 'name':22222,
  1960. * 'type':22222,
  1961. * 'agent_id':22222,
  1962. * }
  1963. * "banner":{
  1964. * 'url':22222,
  1965. * 'name':22222,
  1966. * 'type':22222,
  1967. * 'agent_id':22222,
  1968. * },
  1969. * ]
  1970. * }
  1971. * @apiErrorExample {json} Error-Response:
  1972. * HTTP/1.1 400 Bad Request
  1973. * {
  1974. * "state": false,
  1975. * "code": 1000,
  1976. * "message": "传入参数不正确",
  1977. * "data": null or []
  1978. * }
  1979. * 可能出现的错误代码:
  1980. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1981. */
  1982. public function albumGetBanner(Request $request)
  1983. {
  1984. $userAuth = Auth('api')->user();
  1985. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  1986. if($userAuth->up_agent_id == 0){
  1987. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  1988. $agent_id = $user_agent['id'];
  1989. }else{
  1990. $agent_id = $userAuth->up_agent_id;
  1991. }
  1992. $banner = AgentBannerModel::where([['agent_id',$agent_id],['type',0]])->get();
  1993. $video = AgentBannerModel::where([['agent_id',$agent_id],['type',1]])->first();
  1994. return $this->api(compact('banner','video'));
  1995. }
  1996. /**
  1997. * @api {get} /api/album/get-customer 获取客户信息(get-customer)
  1998. * @apiDescription 获取客户信息(get-customer)
  1999. * @apiGroup Album
  2000. * @apiPermission none
  2001. * @apiVersion 0.1.0
  2002. * @apiParam {int} [store_id] 商户id
  2003. * @apiParam {string} [openid_id] open_id
  2004. * @apiSuccessExample {json} Success-Response:
  2005. * HTTP/1.1 200 OK
  2006. * {
  2007. * "status": true,
  2008. * "status_code": 0,
  2009. * "message": "",
  2010. * "data":[
  2011. * "purpose_level":
  2012. * "comment":
  2013. * "address":
  2014. * "phone":
  2015. * "tips":
  2016. * ]
  2017. * }
  2018. * @apiErrorExample {json} Error-Response:
  2019. * HTTP/1.1 400 Bad Request
  2020. * {
  2021. * "state": false,
  2022. * "code": 1000,
  2023. * "message": "传入参数不正确",
  2024. * "data": null or []
  2025. * }
  2026. * 可能出现的错误代码:
  2027. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  2028. */
  2029. public function albumGetCustomer(Request $request)
  2030. {
  2031. $userAuth = Auth('api')->user();
  2032. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  2033. $validator = Validator::make($request->all(), [
  2034. 'store_id' => 'required',
  2035. 'open_id'=>'required'
  2036. ],[
  2037. 'store_id.required'=>'缺少商户参数',
  2038. 'open_id.required'=>'缺少用户参数',
  2039. ]);
  2040. if ($validator->fails()) {
  2041. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  2042. }
  2043. $store_id = $request->input('store_id');
  2044. $open_id = $request->input('open_id');
  2045. if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  2046. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  2047. $customer = CustomerDetailsModel::where([['store_id',$store_id],['open_id',$open_id],['agent_id',$user_agent->id]])->first(['purpose_level','comment','tips','address']);
  2048. if(!empty($customer)){
  2049. $user = AlbumUserModel::where([['store_id',$store_id],['open_id',$open_id]])->first();
  2050. $customer->phone = $user->phone;
  2051. $customer->avatar = $user->avatar;
  2052. $customer->username = $user->username;
  2053. } else {
  2054. $customer = (object)[
  2055. 'purpose_level' => 1,
  2056. 'comment' => '备注名',
  2057. 'tips' => '客户有合作意向',
  2058. 'address' => '四川省成都市'
  2059. ];
  2060. }
  2061. return $this->api(compact('customer'));
  2062. }
  2063. /**
  2064. * @api {post} /api/album/set-customer 设置客户信息(set-customer)
  2065. * @apiDescription 设置客户信息(set-customer)
  2066. * @apiGroup Album
  2067. * @apiPermission none
  2068. * @apiVersion 0.1.0
  2069. * @apiParam {int} [store_id] 商户id
  2070. * @apiParam {string} [openid_id] openid
  2071. * @apiParam {string} [key] 键
  2072. * @apiParam {string} [value] 值
  2073. * @apiSuccessExample {json} Success-Response:
  2074. * HTTP/1.1 200 OK
  2075. * {
  2076. * "status": true,
  2077. * "status_code": 0,
  2078. * "message": "",
  2079. * "data":[
  2080. * "purpose_level":
  2081. * "address":
  2082. * "comment":
  2083. * "phone":
  2084. * "tips":
  2085. * ]
  2086. * }
  2087. * @apiErrorExample {json} Error-Response:
  2088. * HTTP/1.1 400 Bad Request
  2089. * {
  2090. * "state": false,
  2091. * "code": 1000,
  2092. * "message": "传入参数不正确",
  2093. * "data": null or []
  2094. * }
  2095. * 可能出现的错误代码:
  2096. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  2097. */
  2098. public function albumSetCustomer(Request $request)
  2099. {
  2100. $userAuth = Auth('api')->user();
  2101. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  2102. $validator = Validator::make($request->all(), [
  2103. 'store_id' => 'required',
  2104. 'key' => 'required',
  2105. 'value' => 'required',
  2106. 'open_id' => 'required',
  2107. ],[
  2108. 'store_id.required'=>'缺少商户参数',
  2109. 'key.required'=>'缺少键参数',
  2110. 'value.required'=>'缺少值参数',
  2111. 'open_id.required'=>'缺少用户参数',
  2112. ]);
  2113. if ($validator->fails()) {
  2114. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  2115. }
  2116. $store_id = $request->input('store_id');
  2117. $open_id = $request->input('open_id');
  2118. $key = $request->input('key');
  2119. $value = $request->input('value');
  2120. if($userAuth->is_dealer != 1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  2121. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  2122. if ($key == 'phone') {
  2123. $user = AlbumUserModel::where([['store_id',$store_id],['open_id',$open_id]])->first();
  2124. $user->phone = $value;
  2125. $user->save();
  2126. return $this->api([], 0, 'success');
  2127. }
  2128. $customer = CustomerDetailsModel::where([['store_id',$store_id],['open_id',$open_id],['agent_id',$user_agent->id]])->first(['purpose_level','comment','tips','address']);
  2129. if($customer){
  2130. /// $customer->$key = $value;
  2131. $update[$key] = $value;
  2132. CustomerDetailsModel::where([['store_id',$store_id],['open_id',$open_id],['agent_id',$user_agent->id]])->update($update);
  2133. // $customer->save();
  2134. }else{
  2135. $add['agent_id'] = $user_agent->id;
  2136. $add['open_id'] = $open_id;
  2137. $add['store_id'] = $store_id;
  2138. $add[$key] = $value;
  2139. $user = CustomerDetailsModel::create($add);
  2140. }
  2141. return $this->api([],0,'success');
  2142. }
  2143. /**
  2144. * @api {get} /api/album/customer-goods 获取客户浏览商品统计(customer-goods)
  2145. * @apiDescription 获取客户浏览商品统计(customer-goods)
  2146. * @apiGroup Album
  2147. * @apiPermission none
  2148. * @apiVersion 0.1.0
  2149. * @apiParam {int} [store_id] 商户id
  2150. * @apiSuccessExample {json} Success-Response:
  2151. * HTTP/1.1 200 OK
  2152. * {
  2153. * "status": true,
  2154. * "status_code": 0,
  2155. * "message": "",
  2156. * "data":[
  2157. * {
  2158. * "name":
  2159. * "count":
  2160. * },
  2161. * ]
  2162. * }
  2163. * @apiErrorExample {json} Error-Response:
  2164. * HTTP/1.1 400 Bad Request
  2165. * {
  2166. * "state": false,
  2167. * "code": 1000,
  2168. * "message": "传入参数不正确",
  2169. * "data": null or []
  2170. * }
  2171. * 可能出现的错误代码:
  2172. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  2173. */
  2174. public function albumCustomerGoods(Request $request)
  2175. {
  2176. $userAuth = Auth('api')->user();
  2177. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  2178. $validator = Validator::make($request->all(), [
  2179. 'store_id' => 'required',
  2180. 'open_id' => 'required',
  2181. // 'end' => 'required',
  2182. // 'start' => 'required',
  2183. ],[
  2184. 'store_id.required'=>'缺少商户参数',
  2185. 'open_id.required'=>'缺少用户参数',
  2186. // 'end.required'=>'缺少结束时间参数',
  2187. // 'start.required'=>'缺少开始时间参数',
  2188. ]);
  2189. if ($validator->fails()) {
  2190. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  2191. }
  2192. $store_id = $request->input('store_id');
  2193. $open_id = $request->input('open_id');
  2194. $end = $request->input('end');
  2195. $start = $request->input('start');
  2196. if (!$end) {
  2197. $end = time();
  2198. }
  2199. if (!$start) {
  2200. $start = 0;
  2201. }
  2202. $end= date('Y-m-d H:i:s',$end);
  2203. $start= date('Y-m-d H:i:s',$start);
  2204. if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  2205. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  2206. if($user_agent) $res= AlbumWatchRecord::where([['action',3],['store_id',$store_id],['agent_id',$user_agent->id],['open_id',$open_id],['updated_at','>=',$start],['updated_at','<=',$end]])->groupBy('detail')->get(['detail']);
  2207. $arr = array();
  2208. foreach ($res as $key=>$val){
  2209. $detail = json_decode($val['detail'],true);
  2210. //dd($detail);die;
  2211. $goods_id = $detail['goods_id'];
  2212. $goods = AlbumProductModel::where([['id',$goods_id]])->first();
  2213. if($goods){
  2214. $count= AlbumWatchRecord::where([['action',3],['store_id',$store_id],['detail',$val['detail']],['agent_id',$user_agent->id],['open_id',$open_id]])->count();
  2215. $arr[] = ['name'=>$goods->name,'count'=>$count];
  2216. }
  2217. }
  2218. return $this->api($arr,0,'success');
  2219. }
  2220. /**
  2221. * @api {post} /api/album/customer-goods-detail 获取客户浏览商品详细(customer-goods-detail)
  2222. * @apiDescription 获取客户浏览商品详细(customer-goods-detail)
  2223. * @apiGroup Album
  2224. * @apiPermission none
  2225. * @apiVersion 0.1.0
  2226. * @apiParam {int} [store_id] 商户id
  2227. * @apiParam {string} [open_id] openid
  2228. * @apiSuccessExample {json} Success-Response:
  2229. * HTTP/1.1 200 OK
  2230. * {
  2231. * "status": true,
  2232. * "status_code": 0,
  2233. * "message": "",
  2234. * "data":[
  2235. * {
  2236. * "name":
  2237. * "time":
  2238. * "style":
  2239. * "cat":
  2240. * },
  2241. * ]
  2242. * }
  2243. * @apiErrorExample {json} Error-Response:
  2244. * HTTP/1.1 400 Bad Request
  2245. * {
  2246. * "state": false,
  2247. * "code": 1000,
  2248. * "message": "传入参数不正确",
  2249. * "data": null or []
  2250. * }
  2251. * 可能出现的错误代码:
  2252. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  2253. */
  2254. public function albumCustomerGoodsDetail(Request $request)
  2255. {
  2256. $userAuth = Auth('api')->user();
  2257. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  2258. $validator = Validator::make($request->all(), [
  2259. 'store_id' => 'required',
  2260. 'open_id'=>'required',
  2261. // 'end' => 'required',
  2262. // 'start' => 'required',
  2263. ],[
  2264. 'store_id.required'=>'缺少商户参数',
  2265. 'open_id.required'=>'缺少用户参数',
  2266. // 'end.required'=>'缺少结束时间参数',
  2267. // 'start.required'=>'缺少开始时间参数',
  2268. ]);
  2269. if ($validator->fails()) {
  2270. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  2271. }
  2272. $store_id = $request->input('store_id');
  2273. $open_id = $request->input('open_id');
  2274. $end = $request->input('end');
  2275. $start = $request->input('start');
  2276. if (!$end) {
  2277. $end = time();
  2278. }
  2279. if (!$start) {
  2280. $start = 0;
  2281. }
  2282. $end= date('Y-m-d H:i:s',$end);
  2283. $start= date('Y-m-d H:i:s',$start);
  2284. if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  2285. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  2286. if($user_agent) $res= AlbumWatchRecord::where([['action',3],['store_id',$store_id],['open_id',$open_id],['agent_id',$user_agent->id],['updated_at','>=',$start],['updated_at','<=',$end]])->orderByDesc('id')->get(['detail','created_at'])->toArray();
  2287. $arr = array();
  2288. foreach ($res as $key=>$val){
  2289. $detail = json_decode($val['detail'],true);
  2290. //dd($detail);die;
  2291. $goods_id = $detail['goods_id'];
  2292. $goods = AlbumProductModel::where([['id',$goods_id]])->first();
  2293. if($goods){
  2294. $cat = AlbumCatModel::where([['store_id',$store_id],['id',$goods->cat_id]])->first();
  2295. if (isset($arr[date('Y-m-d H:i', strtotime($val['created_at']))])) {
  2296. if (isset($arr[date('Y-m-d H:i', strtotime($val['created_at']))][$goods->id])) {
  2297. $arr[date('Y-m-d H:i', strtotime($val['created_at']))][$goods->id]['times']++;
  2298. } else {
  2299. $arr[date('Y-m-d H:i', strtotime($val['created_at']))][$goods->id] = [
  2300. 'name' => $goods->name,
  2301. 'cat' => $cat->name,
  2302. 'thumb' => $goods->thumb,
  2303. 'time' => date('Y-m-d H:i', strtotime($val['created_at'])),
  2304. 'times' => 1
  2305. ];
  2306. }
  2307. } else {
  2308. $arr[date('Y-m-d H:i', strtotime($val['created_at']))][$goods->id] = [
  2309. 'name' => $goods->name,
  2310. 'cat' => $cat->name,
  2311. 'thumb' => $goods->thumb,
  2312. 'time' => date('Y-m-d H:i', strtotime($val['created_at'])),
  2313. 'times' => 1
  2314. ];
  2315. }
  2316. }
  2317. krsort($arr);
  2318. }
  2319. return $this->api($arr,0,'success');
  2320. }
  2321. /**
  2322. * @api {post} /api/album/get-count-favorite 获取客户收藏商品详细(get-count-favorite)
  2323. * @apiDescription 获取客户收藏商品详细(get-count-favorite)
  2324. * @apiGroup Album
  2325. * @apiPermission AUTH
  2326. * @apiVersion 0.1.0
  2327. * @apiParam {int} [store_id] 商户id
  2328. * @apiSuccessExample {json} Success-Response:
  2329. * HTTP/1.1 200 OK
  2330. * {
  2331. * "status": true,
  2332. * "status_code": 0,
  2333. * "message": "",
  2334. * "data":[
  2335. * {
  2336. * "name":
  2337. * "count":
  2338. * "product_id":
  2339. * },
  2340. * ]
  2341. * }
  2342. * @apiErrorExample {json} Error-Response:
  2343. * HTTP/1.1 400 Bad Request
  2344. * {
  2345. * "state": false,
  2346. * "code": 1000,
  2347. * "message": "传入参数不正确",
  2348. * "data": null or []
  2349. * }
  2350. * 可能出现的错误代码:
  2351. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  2352. */
  2353. public function albumGetCountOfFavorite(Request $request)
  2354. {
  2355. $userAuth = Auth('api')->user();
  2356. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  2357. $validator = Validator::make($request->all(), [
  2358. 'store_id' => 'required',
  2359. ],[
  2360. 'store_id.required'=>'缺少商户参数',
  2361. ]);
  2362. if ($validator->fails()) {
  2363. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  2364. }
  2365. $store_id = $request->input('store_id');
  2366. if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  2367. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  2368. $count_user = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id]])->orderBy('id','DESC')->groupBy('open_id')->get();
  2369. $users = Array();
  2370. if($count_user){
  2371. foreach($count_user as $key=>$val){
  2372. $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$val->store_id]])->select(['id','username','avatar','phone','open_id'])->first();
  2373. $users[] = $user->id;
  2374. }
  2375. }
  2376. $res = AlbumFavoriteModel::whereIn('user_id',$users)->where([['store_id',$store_id]])->groupBy('product_id')->get(['product_id'])->toArray();
  2377. foreach($res as $key=>$val){
  2378. $goods = AlbumProductModel::where([['id',$val['product_id']],['store_id',$store_id]])->first();
  2379. if(!$goods){
  2380. unset($res[$key]);continue;
  2381. }
  2382. $res[$key]['name'] = $goods->name;
  2383. // dd($res);
  2384. $res[$key]['count'] = AlbumFavoriteModel::whereIn('user_id',$users)->where([['store_id',$store_id],['product_id',$val['product_id']]])->count();
  2385. }
  2386. return $this->api($res,0,'success');
  2387. }
  2388. /**
  2389. * @api {get} /api/album/get-user-info 获取客户详细(get-user-info)
  2390. * @apiDescription 获取客户详细(get-user-info)
  2391. * @apiGroup Album
  2392. * @apiPermission AUTH
  2393. * @apiVersion 0.1.0
  2394. * @apiSuccessExample {json} Success-Response:
  2395. * HTTP/1.1 200 OK
  2396. * {
  2397. * "status": true,
  2398. * "status_code": 0,
  2399. * "message": "",
  2400. * "data":[
  2401. * {
  2402. * "username":
  2403. * "is_dealer":
  2404. * ...
  2405. * },
  2406. * ]
  2407. * }
  2408. * @apiErrorExample {json} Error-Response:
  2409. * HTTP/1.1 400 Bad Request
  2410. * {
  2411. * "state": false,
  2412. * "code": 1000,
  2413. * "message": "传入参数不正确",
  2414. * "data": null or []
  2415. * }
  2416. * 可能出现的错误代码:
  2417. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  2418. */
  2419. public function albumGetUserInfo(Request $request)
  2420. {
  2421. $userAuth = Auth('api')->user();
  2422. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  2423. if($userAuth->is_dealer == 1){
  2424. $user_agent = AlbumAgentModel::where([['user_id',$userAuth->id],['status',1]])->first();
  2425. $agent_id = $user_agent['id'];
  2426. } else {
  2427. $agent_id = '';
  2428. }
  2429. $user['is_agent'] = $userAuth->is_dealer;
  2430. $user['agent_id'] = $agent_id;
  2431. return $this->api($user,0,'success');
  2432. }
  2433. /**
  2434. * @api {post} /api/album/statistical 记录分享次数(statistical)
  2435. * @apiDescription 记录分享次数(statistical)
  2436. * @apiGroup Album
  2437. * @apiPermission AUTH
  2438. * @apiVersion 0.1.0
  2439. * @apiParam {int} [store_id] 商户id
  2440. * @apiParam {int} [goods_id] 商品id
  2441. * @apiSuccessExample {json} Success-Response:
  2442. * HTTP/1.1 200 OK
  2443. * {
  2444. * "status": true,
  2445. * "status_code": 0,
  2446. * "message": "success",
  2447. * "data":[]
  2448. * }
  2449. * @apiErrorExample {json} Error-Response:
  2450. * HTTP/1.1 400 Bad Request
  2451. * {
  2452. * "state": false,
  2453. * "code": 1000,
  2454. * "message": "传入参数不正确",
  2455. * "data": null or []
  2456. * }
  2457. * 可能出现的错误代码:
  2458. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  2459. */
  2460. public function albumStatistical(Request $request)
  2461. {
  2462. $userAuth = Auth('api')->user();
  2463. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  2464. $validator = Validator::make($request->all(), [
  2465. 'store_id' => 'required',
  2466. ],[
  2467. 'store_id.required'=>'缺少商户参数',
  2468. ]);
  2469. if ($validator->fails()) {
  2470. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  2471. }
  2472. $store_id = $request->input('store_id');
  2473. $goods_id = $request->input('goods_id');
  2474. if($userAuth->up_agent_id !=0){
  2475. $user_agent = AlbumAgentModel::where([['id',$userAuth->up_agent_id],['status',1]])->first();
  2476. $user_agent->share_times++;
  2477. $user_agent->interactive++;
  2478. $user_agent->newCount = $user_agent->pointCount + $user_agent->favoriteCount + $user_agent->callCount + $user_agent->share_times + $user_agent->get_count;
  2479. $user_agent->save();
  2480. }
  2481. $time = mktime(0,0,0,date('m'),date('d'),date('y'));
  2482. $check = AlbumStatisticalModel::where([['time',$time],['store_id',$store_id]])->first();
  2483. if($check){
  2484. $check->share_times ++;
  2485. $check->save();
  2486. }else{
  2487. $add['time'] = $time;
  2488. $add['store_id'] = $store_id;
  2489. $add['share_times'] = 1;
  2490. $add['favorite_times'] = 0;
  2491. AlbumStatisticalModel::create($add);
  2492. }
  2493. if($userAuth->up_agent_id!=0 && !empty($goods_id)){
  2494. $add_record['agent_id'] = $userAuth->up_agent_id;
  2495. $add_record['open_id'] = $userAuth->open_id;
  2496. $add_record['action'] = 8;
  2497. $add_record['store_id'] = $store_id;
  2498. $add_record['detail'] = $goods_id;
  2499. $res = AlbumWatchRecord::create($add_record);
  2500. }
  2501. return $this->api([],0,'success');
  2502. }
  2503. /**
  2504. * @api {post} /api/album/get_statistical 获取分享记录(get-statistical)
  2505. * @apiDescription 获取分享记录(get-statistical)
  2506. * @apiGroup Album
  2507. * @apiPermission AUTH
  2508. * @apiVersion 0.1.0
  2509. * @apiParam {int} [store_id] 商户id
  2510. * @apiParam {int} [open_id] open_id
  2511. * @apiParam {int} [type] 1 尺寸统计 2拨打电话 3 分享
  2512. * @apiSuccessExample {json} Success-Response:
  2513. * HTTP/1.1 200 OK
  2514. * {
  2515. * "status": true,
  2516. * "status_code": 0,
  2517. * "message": "success",
  2518. * "data":[
  2519. * {
  2520. * 'content':xxxxx,
  2521. * 'time':xxx-xx-xx,
  2522. * },
  2523. * ]
  2524. * }
  2525. * @apiErrorExample {json} Error-Response:
  2526. * HTTP/1.1 400 Bad Request
  2527. * {
  2528. * "state": false,
  2529. * "code": 1000,
  2530. * "message": "传入参数不正确",
  2531. * "data": null or []
  2532. * }
  2533. * 可能出现的错误代码:
  2534. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  2535. */
  2536. public function albumGetStatistical(Request $request)
  2537. {
  2538. $userAuth = Auth('api')->user();
  2539. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  2540. $validator = Validator::make($request->all(), [
  2541. 'store_id' => 'required',
  2542. 'open_id' => 'required',
  2543. 'type' => 'required',
  2544. // 'end' => 'required',
  2545. // 'start' => 'required',
  2546. ],[
  2547. 'store_id.required'=>'缺少商户参数',
  2548. 'open_id.required'=>'缺少用户参数',
  2549. 'type.required'=>'缺少类型参数',
  2550. // 'end.required'=>'缺少结束时间参数',
  2551. // 'start.required'=>'缺少开始时间参数',
  2552. ]);
  2553. if ($validator->fails()) {
  2554. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  2555. }
  2556. $data = $request->input();
  2557. $res = array();
  2558. $end = $request->input('end');
  2559. $start = $request->input('start');
  2560. if (!$end) {
  2561. $end = time();
  2562. }
  2563. if (!$start) {
  2564. $start = 0;
  2565. }
  2566. $end= date('Y-m-d H:i:s',$end);
  2567. $start= date('Y-m-d H:i:s',$start);
  2568. if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  2569. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  2570. $user = AlbumUserModel::where([['open_id',$data['open_id']],['store_id',$data['store_id']]])->first();
  2571. if ($data['type'] == 1) { //尺寸统计
  2572. $record = AlbumWatchRecord::where([['open_id',$data['open_id']],['agent_id',$user_agent->id],['detail','like','%'.'u5c3a'.'%'],['action',5],['store_id',$data['store_id']],['updated_at','>=',$start],['updated_at','<=',$end]])->get();
  2573. foreach ($record as $key=>$val){
  2574. $detail = json_decode($val['detail'],true);
  2575. $goods = AlbumProductModel::where([['store_id',$data['store_id']],['id',$detail['goods_id']]])->first();
  2576. if (!$goods) {
  2577. continue;
  2578. }
  2579. $res[] = [
  2580. 'content' => $user->username . '点击' . $goods->name . $detail['detail'],
  2581. 'time' => date('Y-m-d H:i',strtotime($val['created_at']))
  2582. ];
  2583. }
  2584. } elseif ($data['type'] == 2) { //拨打电话
  2585. $record = AlbumWatchRecord::where([['open_id',$data['open_id']],['agent_id',$user_agent->id],['action',7],['store_id',$data['store_id']],['updated_at','>=',$start],['updated_at','<=',$end]])->get();
  2586. foreach ($record as $key=>$val){
  2587. $res[] = [
  2588. 'content' => $user->username . '拨打了经销商电话',
  2589. 'time' => date('Y-m-d H:i',strtotime($val['created_at']))
  2590. ];
  2591. }
  2592. } else {
  2593. $record = AlbumWatchRecord::where([['open_id',$data['open_id']],['agent_id',$user_agent->id],['action',8],['store_id',$data['store_id']],['updated_at','>=',$start],['updated_at','<=',$end]])->get();
  2594. foreach ($record as $key=>$val){
  2595. $goods = AlbumProductModel::where([['store_id',$data['store_id']],['id',$val['detail']]])->first();
  2596. $style = AlbumProductStyleModel::where([['store_id',$data['store_id']],['id',$goods->style]])->first();
  2597. $cat = AlbumCatModel::where([['store_id',$data['store_id']],['id',$goods->cat_id]])->first();
  2598. $res[] = [
  2599. 'content' => "$user->username 分享了 $style->name $cat->name $goods->name ",
  2600. 'time' => date('Y-m-d H:i',strtotime($val['created_at']))
  2601. ];
  2602. }
  2603. }
  2604. return $this->api(compact('res'));
  2605. }
  2606. /**
  2607. * @api {post} /api/album/agent_price_set 厂家价格设置(agent_price_set)
  2608. * @apiDescription 厂家价格设置(agent_price_set)
  2609. * @apiGroup Album
  2610. * @apiPermission AUTH
  2611. * @apiVersion 0.1.0
  2612. * @apiParam {int} [store_id] 商户id
  2613. * @apiParam {int} [point] 价格设置比例 为0不设置
  2614. * @apiParam {int} [is_show_ma_price] 厂家价格是否可见 0 不可见 1 可见
  2615. * @apiSuccessExample {json} Success-Response:
  2616. * HTTP/1.1 200 OK
  2617. * {
  2618. * "status": true,
  2619. * "status_code": 0,
  2620. * "message": "success",
  2621. * "data":[]
  2622. * }
  2623. * @apiErrorExample {json} Error-Response:
  2624. * HTTP/1.1 400 Bad Request
  2625. * {
  2626. * "state": false,
  2627. * "code": 1000,
  2628. * "message": "传入参数不正确",
  2629. * "data": null or []
  2630. * }
  2631. * 可能出现的错误代码:
  2632. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  2633. */
  2634. public function albumAgentPriceSet(Request $request)
  2635. {
  2636. $userAuth = Auth('api')->user();
  2637. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  2638. $validator = Validator::make($request->all(), [
  2639. 'is_show_ma_price' => 'required',
  2640. 'store_id' => 'required',
  2641. 'point' => 'required',
  2642. ],[
  2643. 'is_show_ma_price.required'=>'缺少设置参数',
  2644. 'store_id.required' => '缺少store参数',
  2645. 'point.required'=>'缺少比例参数',
  2646. ]);
  2647. if ($validator->fails()) {
  2648. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  2649. }
  2650. $data = $request->input();
  2651. if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
  2652. $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
  2653. $user_agent->is_show_ma_price = $data['is_show_ma_price'];
  2654. $user_agent->save();
  2655. $product = AlbumProductModel::where('store_id',$data['store_id'])->get(['id','ma_price']);
  2656. foreach ($product as $key=>$val) {
  2657. $save['price'] = $val['ma_price'] * (1 + $data['point'] / 100);
  2658. $check = AlbumProductPriceModel::where([['agent_id',$user_agent->id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
  2659. if(empty($check)){
  2660. $save['agent_id'] = $user_agent->id;
  2661. $save['store_id'] = $data['store_id'];
  2662. $save['cat_id'] = $val['cat_id'];
  2663. $save['name'] = $val['name'];
  2664. $save['product_id'] = $val['id'];
  2665. AlbumProductPriceModel::create($save);
  2666. }else{
  2667. AlbumProductPriceModel::where([['agent_id',$user_agent->id],['store_id',$data['store_id']],['product_id',$val['id']]])->update($save);
  2668. }
  2669. }
  2670. $user_agent->set_price_point = $data['point'];
  2671. $user_agent->save();
  2672. return $this->api([],0,'success');
  2673. }
  2674. }