AlbumController.php 109 KB

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