ShopController.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Models\Shop\WxShop;
  4. use App\Models\Shop\WxShopContact;
  5. use App\Models\Shop\WxShopFollow;
  6. use App\Models\Shop\WxShopGuaranteeRecord;
  7. use App\Models\Shop\WxShopOrder;
  8. use App\Models\System\AdminUser;
  9. use App\Models\Used\WxUsedGood;
  10. use App\Models\WxIcon;
  11. use App\Models\WxQuestion;
  12. use App\Wen\Utils\FieldUtils;
  13. use App\Wen\Utils\PostUtils;
  14. use App\Wen\Utils\Settings;
  15. use App\Wen\Utils\ShopUtils;
  16. use App\Wen\Utils\TaokeUtils;
  17. use App\Wen\Utils\UserUtils;
  18. use App\Wen\Utils\Utils;
  19. use App\Http\Controllers\Api\Repositories\PostsRepositores;
  20. use App\Models\Posts\WxPost;
  21. use App\Models\Posts\WxPostsImg;
  22. use App\Models\Posts\WxPostsGoods;
  23. use App\Models\Shop\WxShopAddress;
  24. use App\Models\Shop\WxShopCart;
  25. use App\Models\Shop\WxShopClassify;
  26. use App\Models\Shop\WxShopGoods;
  27. use App\Models\Shop\WxShopGoodsProduct;
  28. use App\Models\Shop\WxShopNotice;
  29. use App\Models\Shop\WxShopService;
  30. use App\Models\WxSlideshow;
  31. use App\Models\User\WxUser;
  32. use Illuminate\Http\Request;
  33. use Illuminate\Support\Facades\Cache;
  34. use Illuminate\Support\Facades\DB;
  35. class ShopController extends BaseController
  36. {
  37. /**
  38. * Shop轮播图
  39. */
  40. public function bannerAndNav(Request $request)
  41. {
  42. global $__MINI_GLOBAL_DEVICE__;
  43. $ban_ids = ShopUtils::get_ban_classes($__MINI_GLOBAL_DEVICE__);
  44. $icon_id_arr = explode(',', Settings::get('app_shop_nav_', ''));
  45. $icons = [];
  46. WxIcon::whereIn('id', $icon_id_arr)->orderBy(DB::raw('FIND_IN_SET(id, "' . implode(",", $icon_id_arr) . '"' . ")"))->get()->map(function ($v) use (&$icons, $ban_ids){
  47. if($v->type == 7 && in_array($v->target_id, $ban_ids)){
  48. }else{
  49. $icons[] = $v;
  50. }
  51. });
  52. $notice_ids = explode(',', Settings::get('app_shop_notice', ''));
  53. $result = [
  54. 'banners' => WxSlideshow::wherein('id', explode(',', Settings::get('app_shop_banner', '')))->orderBy('sort', 'desc')->get(['id', 'poster', 'target_id', 'slideshow_type']),
  55. 'navs' => $icons,
  56. 'notice' => WxShopNotice::whereIn('id', $notice_ids)->orderBy(DB::raw('FIND_IN_SET(id, "' . implode(",", $notice_ids) . '"' . ")"))->get(['id', 'title'])
  57. ];
  58. return $this->success($result);
  59. }
  60. /**
  61. * Shop通知详情
  62. */
  63. public function noticeDetail(Request $request)
  64. {
  65. $id = $request->id;
  66. $data = WxShopNotice::where('id', $id)->first();
  67. return $this->success($data);
  68. }
  69. /**
  70. * Shop分类
  71. */
  72. public function classify(Request $request)
  73. {
  74. $device = $request->header('device','');
  75. $depth = _empty_default_($request->depth, 3);
  76. $hierarchy = _empty_default_($request->hierarchy, 0);
  77. $shop_id = _empty_default_($request->shop_id, 0);
  78. if($depth == 3){
  79. $depth_arr = [3, null];
  80. }else{
  81. $depth_arr = [$depth];
  82. }
  83. if($hierarchy == 1){
  84. $depth_arr = [1, 2, 3, null];
  85. }
  86. $ban_device_status = [0];
  87. if(is_mini_examine_mode(11)){
  88. $ban_device_status[] = 2;
  89. }
  90. if($hierarchy == 1){
  91. $query = WxShopClassify::whereNotIn('in_'.$device, $ban_device_status);
  92. }else{
  93. $query = WxShopClassify::where('state', 1)->whereNotIn('in_'.$device, $ban_device_status);
  94. }
  95. if($shop_id > 0){
  96. $shop_classifys = WxShop::where('id', $shop_id)->value('shop_classifys');
  97. if(_empty_($shop_classifys)){
  98. return $this->fail(200003);
  99. }
  100. $query = $query->whereIn('id', explode(',', $shop_classifys));
  101. }else if($shop_id == -1){
  102. }
  103. $data = $query->whereIn('depth', $depth_arr )->orderBy('sort', 'desc')
  104. ->get(FieldUtils::shopClassifyColums());
  105. if($hierarchy == 1){
  106. $firsts = [];
  107. $seconds = [];
  108. $thirds = [];
  109. if($data){
  110. $data = $data->toArray();
  111. foreach ($data as $v){
  112. $v['sub'] = [];
  113. if($v['depth'] == 1){
  114. $firsts[$v['id']] = $v;
  115. }else if($v['depth'] == 2){
  116. $seconds[$v['id']] = $v;
  117. }else{
  118. $thirds[$v['id']] = $v;
  119. }
  120. }
  121. if($thirds){
  122. foreach ($thirds as $third_id => $third){
  123. $parent_id = $third['parent_id'];
  124. if($parent_id){
  125. if(isset($seconds[$parent_id])){
  126. $seconds[$parent_id]['sub'][] = $third;
  127. }
  128. }
  129. }
  130. }
  131. if($seconds){
  132. foreach ($seconds as $second_id => $second){
  133. $parent_id = $second['parent_id'];
  134. if($parent_id){
  135. if(isset($firsts[$parent_id])){
  136. $firsts[$parent_id]['sub'][] = $second;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. return $this->success(array_values($firsts));
  143. }else{
  144. return $this->success($data);
  145. }
  146. }
  147. /**
  148. * Shop首页板块推荐
  149. */
  150. public function plate(Request $request)
  151. {
  152. $data = WxShopClassify::where('state', 1)
  153. ->orderBy('sort', 'desc')->get(['id', 'name']);
  154. $data->map(function ($v) {
  155. $v->goods = WxShopGoods::where('state', 1)->where('classify_id', $v->id)
  156. ->orderBy('views', 'desc')->limit(3)
  157. ->get(['id', 'name', 'pic']);
  158. });
  159. return $this->success($data);
  160. }
  161. /**
  162. * Shop首页灵感推荐
  163. */
  164. public function inspiration(Request $request)
  165. {
  166. $data = WxShopGoods::where('state', 1)
  167. ->whereIn('id', explode(',', Settings::get('app_shop_accordion_goods', '')))
  168. ->limit(6)
  169. ->orderBy('sort', 'desc')
  170. ->get(['id', 'pic', 'tag', 'name', 'intro', 'vip_price']);
  171. return $this->success($data);
  172. }
  173. /**
  174. * Shop首页热榜推荐
  175. */
  176. public function hotList(Request $request)
  177. {
  178. $data = WxShopClassify::where('state', 1)->whereIn('id', Settings::get('app_shop_hot_list_classify', []))
  179. ->limit(6)->orderBy('sort', 'desc')->get(['id', 'name', 'intro', 'bg_img']);
  180. $data->map(function ($v) {
  181. $v->goods = WxShopGoods::where('state', 1)->where('classify_id', $v->id)
  182. ->limit(3)->orderBy('views', 'desc')
  183. ->get(['id', 'name', 'pic']);
  184. });
  185. return $this->success($data);
  186. }
  187. /**
  188. * Shop首页推荐
  189. */
  190. public function indexRecommend(Request $request)
  191. {
  192. global $__MINI_GLOBAL_DEVICE__;
  193. $ban_ids = ShopUtils::get_ban_classes($__MINI_GLOBAL_DEVICE__);
  194. $query = WxShopGoods::where('state', 1);
  195. if($ban_ids){
  196. $query = $query->whereNotIn('classify_id', $ban_ids);
  197. }
  198. $data = $query->orderBy('sort', 'desc')->orderBy('id', 'desc')
  199. // ->get(['id', 'pic', 'tag', 'name', 'intro', 'vip_price', 'price']);
  200. ->paginate(10);
  201. return $this->success($data);
  202. }
  203. /**
  204. * Shop商品详情
  205. */
  206. public function goodsDetails(Request $request)
  207. {
  208. global $__MINI_GLOBAL_MODE__;
  209. $id = $request->id;
  210. $uid = $request->uid;
  211. $dtk_id = $request->dtk_id;
  212. $tk_goodsid = $request->tk_goodsid;
  213. $tk_platform = $request->tk_platform;
  214. $force_update_id = false;
  215. if(_empty_($id)){
  216. $result = TaokeUtils::get_goods_id_from_taoke($dtk_id, $tk_goodsid, $tk_platform);
  217. if($result['code'] == 0){
  218. return $this->fail($result['data']);
  219. }
  220. $id = $result['data'];
  221. $force_update_id = true;
  222. }
  223. $device = $request->header('device','');
  224. if($device == 'pc'){
  225. $device = 'h5';
  226. }
  227. $ban_ids = ShopUtils::get_ban_classes($device);
  228. $data = WxShopGoods::where('id', $id)->whereNotIn('classify_id', $ban_ids)->with(['product'])->first();
  229. if($data){
  230. WxShopGoods::where('id', $id)->increment('views');
  231. if(_array_key($data, 'sku', '')){
  232. // 规格
  233. $attrs = json_decode($data['sku'], true);
  234. $data['param_data'] = $this->formatAttrs($attrs['attrs']);
  235. }else{
  236. $data['param_data'] = [];
  237. }
  238. // 服务
  239. if(isset($data['service_id'])){
  240. $data['service'] = WxShopService::whereIn('id', json_decode($data['service_id'], true))->get(['name', 'intro']);
  241. }else{
  242. $data['service'] = null;
  243. }
  244. // 处理时间
  245. $service_time_tip = '';
  246. if($data['service_time_start'] && $data['service_time_end']){
  247. $service_time_tip .= $data['service_time_start'].'-'.$data['service_time_end'];
  248. }
  249. if($data['service_date_start']){
  250. if($service_time_tip){
  251. $service_time_tip = ' '.$service_time_tip;
  252. }
  253. if(_empty_($data['service_date_end'])){
  254. if($service_time_tip){
  255. $service_time_tip = $data['service_date_start'] . $service_time_tip;
  256. }else{
  257. $service_time_tip = $data['service_date_start'].'全天';
  258. }
  259. }else{
  260. $service_time_tip .= ($data['service_date_start'] . '-' . $data['service_date_end']) . $service_time_tip;
  261. }
  262. }else{
  263. if($service_time_tip){
  264. if($service_time_tip){
  265. $service_time_tip = ' '.$service_time_tip;
  266. }
  267. $service_time_tip = '每天' . $service_time_tip;
  268. }
  269. }
  270. $data['service_time_tip'] = $service_time_tip;
  271. // 处理嘉宾
  272. if($data['guest_present']){
  273. $data['guests'] = WxUser::whereIn('id', explode(',', $data['guest_present']))->orderBy(DB::raw('FIND_IN_SET(id, "' . $data['guest_present'] . '"' . ")"))->get(FieldUtils::userInfoColums())
  274. ->map(function ($v){
  275. $v->user_avatar = $v->user_avatar . '?imageMogr2/crop/50x50/gravity/center/thumbnail/50x50';
  276. return $v;
  277. });
  278. }
  279. if(_array_key($data, 'contact_id', 0) > 0){
  280. $data['contact'] = WxShopContact::find($data['contact_id']);
  281. }
  282. if($force_update_id){
  283. $data['force_update_id'] = true;
  284. }else{
  285. $data['force_update_id'] = false;
  286. }
  287. $data['user_purchase'] = ShopUtils::user_buy_goods_times($uid, $data->id);
  288. if($__MINI_GLOBAL_MODE__ != 'examine'){
  289. if($data->shop_id > 0){
  290. $data->shop = WxShop::where('id', $data->shop_id )->first(FieldUtils::shopInfoColums());
  291. ShopUtils::shop_process($data->shop);
  292. if($data->shop->user_id != $data->user_id){
  293. _logger_(__file__, __line__, '出错了,商品数据与店铺数据对应不上,商品id:'.$data->id . ',店铺id:'.$data->shop->id);
  294. }
  295. }
  296. }
  297. if($uid > 0 && $id > 0){
  298. update_user_visit($uid, 3, $id);
  299. }
  300. return $this->success($data);
  301. }else{
  302. return $this->fail(200003, [], '无记录!');
  303. }
  304. }
  305. // 处理规格
  306. private function formatAttrs($attrs)
  307. {
  308. $data = [];
  309. foreach ($attrs as $k => $v) {
  310. foreach ($v as $ks => $vs) {
  311. $value[] = [
  312. 'value' => $vs
  313. ];
  314. }
  315. $data[] = [
  316. 'name' => $k,
  317. 'value' => $value
  318. ];
  319. $value = [];
  320. }
  321. return $data;
  322. }
  323. /**
  324. * Shop分类查询商品
  325. */
  326. public function classifyGoodsList(Request $request)
  327. {
  328. $cid = $request->cid;
  329. $device = $request->header('device','');
  330. $ban_ids = ShopUtils::get_ban_classes($device);
  331. if(in_array($cid, $ban_ids)){
  332. return $this->fail(200003, [], '无记录!');
  333. }
  334. if ($cid == -1) {
  335. $data = WxShopGoods::where('state', 1)
  336. ->orderBy('created_at', 'desc')
  337. ->paginate(6);
  338. } else if ($cid == 0) {
  339. $data = WxShopGoods::where('state', 1)
  340. ->orderBy('sort', 'desc')
  341. ->orderBy('views', 'desc')
  342. ->paginate(6);
  343. } else {
  344. $data = WxShopGoods::where('state', 1)->where('classify_id', $cid)
  345. ->orderBy('sort', 'desc')
  346. ->paginate(6);
  347. }
  348. return $this->success($data);
  349. }
  350. /**
  351. * Shop搜索商品
  352. */
  353. public function goodsSearch(Request $request)
  354. {
  355. $keyword = $request->keyword;
  356. $device = $request->header('device','');
  357. $ban_ids = ShopUtils::get_ban_classes($device);
  358. $shop_id = _empty_default_($request->shop_id, 0);
  359. $orderBy = _empty_default_($request->orderBy, 'sort');
  360. if(!in_array($orderBy, ['sort', 'buys', 'created_at', 'price'])){
  361. return $this->fail(200004);
  362. }
  363. $order = _empty_default_($request->order, 'desc');
  364. $limit = _between_(_empty_default_($request->limit, 10), 1, 100);
  365. $credit_type = $request->credit_type;
  366. if(_empty_($credit_type, true)){
  367. $credit_type = [0, 1];
  368. }
  369. if(is_string($credit_type)){
  370. $credit_type = explode(',', $credit_type);
  371. }
  372. foreach ($credit_type as $credit_type_){
  373. if(!in_array($credit_type_, [0, 1])){
  374. return $this->fail(200004);
  375. }
  376. }
  377. $minprice = _between_(_empty_default_($request->minPrice, 0), 0, 999999999);
  378. $maxPrice = _between_(_empty_default_($request->maxPrice, 999999999), 0, 999999999);
  379. if($minprice > $maxPrice){
  380. return $this->fail(200004);
  381. }
  382. $classify_id = _empty_default_($request->classify, 0);
  383. if(!in_array($order, ['desc', 'asc'])){
  384. return $this->fail(200004);
  385. }
  386. if($orderBy != 'price'){
  387. $order = 'desc';
  388. }
  389. $query = WxShopGoods::where('state', 1);
  390. $query = $query->where(function ($query_) use ($keyword) {
  391. $query_->orWhere('name', 'like', '%' . $keyword . '%')
  392. ->orWhere('intro', 'like', '%' . $keyword . '%')
  393. ->orWhere('content', 'like', '%' . $keyword . '%');
  394. });
  395. if($shop_id > 0){
  396. $query = $query->where('shop_id', $shop_id);
  397. }else if($shop_id == -1){
  398. $query = $query->where('shop_id', 0);
  399. }
  400. if($classify_id > 0){
  401. $query = $query->where('classify_id', $classify_id);
  402. }else{
  403. $query = $query->whereNotIn('classify_id', $ban_ids);
  404. }
  405. if($minprice > 0){
  406. $query = $query->where('price', '>=', $minprice);
  407. }
  408. if($maxPrice != 9999999999){
  409. $query = $query->where('price', '<=', $maxPrice);
  410. }
  411. $query = $query->whereIn('credit_type', $credit_type);
  412. $data = $query->orderBy($orderBy, $order)->orderBy('id', 'desc')->paginate($limit);
  413. return $this->success($data);
  414. }
  415. /**
  416. * Shop商品晒单
  417. */
  418. public function goodsPosts(Request $request)
  419. {
  420. $gid = $request->gid;
  421. $uid = $request->uid;
  422. $dtk_id = $request->dtk_id;
  423. $tk_goodsid = $request->tk_goodsid;
  424. $tk_platform = $request->tk_platform;
  425. if(_empty_($gid)){
  426. $result = TaokeUtils::get_goods_id_from_taoke($dtk_id, $tk_goodsid, $tk_platform);
  427. if($result['code'] == 0){
  428. return $this->fail($result['data']);
  429. }
  430. $gid = $result['data'];
  431. }
  432. $postsIds = WxPostsGoods::where('goods_id', $gid)->pluck('posts_id');//笔记ID列表
  433. $data = WxPost::where('is_examine', 1)
  434. ->where('posts_state', 0)
  435. ->whereIn('id', $postsIds)->orderBy('weight', 'desc')
  436. ->limit(5)->get();
  437. $results = [];
  438. if($data){
  439. $style = 0;
  440. $data->map(function ($v) use ($style, &$results){
  441. $posts_content = strip_tags($v->posts_content);
  442. $obj = [
  443. 'id' => $v->id,
  444. 'content' => PostUtils::get_the_title($posts_content, $v->id),
  445. 'author' => WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums()),
  446. 'imgs' => [
  447. ],
  448. 'img_res' => 0
  449. ];
  450. $images = [];
  451. if($v->video){
  452. $images[] = Utils::imgWithStyle($v->video->video_thumb_url, 2);
  453. }
  454. WxPostsImg::where('posts_id', $v->id)->get(['img_url', 'posts_id'])->map( function ($postImg) use ($style, &$images){
  455. if($style == -1){
  456. return $postImg;
  457. }
  458. $postImg->img_url = Utils::imgWithStyle($postImg->img_url, 2);
  459. $images[] = $postImg->img_url;
  460. });//图片
  461. preg_replace_callback("/<img.*?src[^\'\"]+[\'\"]([^\"\']+)[^>]+>/is", function ($r) use ($style, &$images){
  462. $images[] = Utils::imgWithStyle($r[1], 2);
  463. return '<img src="'.Utils::imgWithStyle($r[1], $style).'">';
  464. }, $v->posts_content);
  465. $obj['imgs'] = $images;
  466. $obj['img_res'] = count($images) > 3 ? (count($images) - 3) : 0;
  467. if($obj['img_res'] > 9){
  468. $obj['img_res'] = 9;
  469. }
  470. $results[] = $obj;
  471. });
  472. }
  473. return $this->success($results);
  474. }
  475. /**
  476. * Shop商品晒单
  477. */
  478. public function goodsPostsList(Request $request)
  479. {
  480. $gid = $request->gid;
  481. $uid = $request->uid;
  482. $data = PostsRepositores::goodsBaskPosts($uid, $gid);
  483. return $this->success($data);
  484. }
  485. public function guarantee_record(Request $request){
  486. $uid = $request->uid;
  487. if(_empty_($uid)){
  488. return $this->fail(200015);
  489. }
  490. $shop_id = WxUser::where('id', $uid)->value('shop_id');
  491. if(_empty_($shop_id)){
  492. return $this->fail(200003);
  493. }
  494. $limit = _between_(_empty_default_($request->limit, 10), 1, 100);
  495. $data = WxShopGuaranteeRecord::where('shop_id', $shop_id)->orderBy('id', 'desc')->simplePaginate($limit);
  496. return $this->success($data);
  497. }
  498. /**
  499. * 店铺信息
  500. */
  501. public function info(Request $request){
  502. $user_id = $request->user_id;
  503. $shop_id = $request->shop_id;
  504. global $__MINI_GLOBAL_CURRENT_USER_ID__;
  505. $is_admin = false;
  506. if(_empty_($user_id) && _empty_($shop_id)){
  507. return $this->fail(200001);
  508. }
  509. $shop_config = _empty_default_($request->shop_config, 0);
  510. $shop = null;
  511. if($user_id){
  512. $shop = WxShop::where('user_id', $user_id)->first(FieldUtils::shopInfoColums());
  513. }else{
  514. if($shop_id > 0){
  515. $shop = WxShop::where('id', $shop_id)->first(FieldUtils::shopInfoColums());
  516. ShopUtils::shop_process($shop);
  517. }else if($shop_id == -1){
  518. $shop = [
  519. 'id' => 0,
  520. 'shop_name' => '官方自营',
  521. 'shop_logo' => Settings::get('about_logo'),
  522. 'follow_count' => (WxShopFollow::where('shop_id', 0)->where('status', 1)->count()) ?: 0,
  523. 'is_follow' => WxShopFollow::where('user_id', $__MINI_GLOBAL_CURRENT_USER_ID__)->where('shop_id', 0)->where('status', 1)->exists(),
  524. 'status' => 1
  525. ];
  526. $is_admin = true;
  527. }
  528. }
  529. if(!$is_admin){
  530. if(_empty_($shop)){
  531. if($shop_config != 1){
  532. return $this->fail(200003);
  533. }
  534. }
  535. if($shop){
  536. $shop->status_tip = [0=>'审核中', 1=>'审核通过',2=>'审核拒绝', 3=> '系统惩罚下线', 4 => '管理员惩罚下线', 5=> '店主关停'][$shop->status];
  537. if(!_empty_($shop->admin_user_id)){
  538. $shop->admin_user = AdminUser::where('id', $shop->admin_user_id)->first(['id', 'username', 'name', 'avatar', 'uid', 'created_at']);
  539. if($shop->admin_user){
  540. $shop->admin_user['url_address'] = admin_url('');
  541. }
  542. }
  543. }
  544. }
  545. if($shop){
  546. $shop->contacts = WxShopContact::where('shop_id', $shop->id)->get();
  547. }
  548. if($shop_config == 1){
  549. $object_ids = explode(',', Settings::get('app_shop_apply_questions', ''));
  550. $config = [
  551. 'clause' => Settings::get('app_shop_apply_clause'),
  552. 'questions' => WxQuestion::whereIn('id', $object_ids)->orderBy(DB::raw('FIND_IN_SET(id, "' . implode(",", $object_ids) . '"' . ")"))->get()
  553. ];
  554. return $this->success(['shop'=>$shop, 'config'=>$config]);
  555. }
  556. return $this->success(['shop'=>$shop]);
  557. }
  558. /**
  559. * 关注店铺
  560. */
  561. public function follow(Request $request){
  562. $shop_id = _empty_default_($request->shop_id, 0);
  563. $status = _empty_default_($request->status, 0);
  564. $uid = $request->uid;
  565. if(_empty_($shop_id)){
  566. return $this->fail(200001);
  567. }
  568. if($shop_id == -1){
  569. $shop_id = 0;
  570. }
  571. if(!in_array($status, [0, 1])){
  572. return $this->fail(200004);
  573. }
  574. $model = WxShopFollow::where('user_id', $uid)->where('shop_id', $shop_id)->first();
  575. if($model){
  576. if($status == 1){
  577. if($model->status === 0){
  578. $model->status = 1;
  579. $model->save();
  580. }
  581. }else{
  582. if($model->status === 1){
  583. $model->status = 0;
  584. $model->save();
  585. }
  586. }
  587. }else{
  588. $new_model = new WxShopFollow();
  589. $new_model->user_id = $uid;
  590. $new_model->shop_id = $shop_id;
  591. $new_model->status = $status;
  592. $new_model->save();
  593. }
  594. return $this->success();
  595. }
  596. public function contact_process(Request $request){
  597. $action = _empty_default_($request->action , '');
  598. $uid = $request->uid;
  599. if($action == 'add'){
  600. $name = _empty_default_($request->name, '');
  601. $phone = _empty_default_($request->phone, '');
  602. $longitude = _empty_default_($request->longitude, 0);
  603. $latitude = _empty_default_($request->latitude, 0);
  604. $address_name = _empty_default_($request->address_name, '');
  605. $address_detailed = _empty_default_($request->address_detailed, '');
  606. if(_empty_($name) || _empty_($phone) || _empty_($longitude) || _empty_($latitude) || _empty_($address_name)){
  607. return $this->fail(200001);
  608. }
  609. $shop_id = WxShop::where('user_id', $uid)->value('id');
  610. if(_empty_($shop_id)){
  611. return $this->fail(200004, [], '你还没有申请店铺');
  612. }
  613. $contact = new WxShopContact();
  614. $contact->user_id = $uid;
  615. $contact->shop_id = $shop_id;
  616. $contact->name = $name;
  617. $contact->phone = $phone;
  618. $contact->longitude = $longitude;
  619. $contact->latitude = $latitude;
  620. $contact->address_name = $address_name;
  621. $contact->address_detail = $address_detailed;
  622. $r = $contact->save();
  623. if($r){
  624. return $this->success();
  625. }
  626. return $this->fail(200002);
  627. }else if($action == 'delete'){
  628. }
  629. }
  630. /**
  631. * Shop创建
  632. */
  633. public function add(Request $request){
  634. $uid = $request->uid;
  635. $user = WxUser::find($uid);
  636. if(!UserUtils::is_user_can_speak($uid)){
  637. return $this->fail(200043, [
  638. 'title' => '禁言中,无法言论',
  639. 'content' => '是否前往解除限制',
  640. 'confirmText' => '去解除',
  641. 'target_type' => 6,
  642. 'target_id' => '/pagesA/mine/unlock/unlock?user_id='.$uid
  643. ], '您当前处于禁言期间,无法言论');
  644. }
  645. if(WxShop::withTrashed()->where('user_id', $uid)->exists()){
  646. return $this->fail(200010, [], '一个账号只能拥有一个店铺');
  647. }
  648. $shopClassifys = _empty_default_($request->shopClassifys, []);
  649. if(is_string($shopClassifys)){
  650. $shopClassifys = explode(',', $shopClassifys);
  651. }
  652. if(!is_array($shopClassifys)){
  653. return $this->fail(200001, [], '请选择类目后提交');
  654. }
  655. if(_empty_($shopClassifys)){
  656. return $this->fail(200001, [], '请选择类目后提交');
  657. }
  658. if(WxShopClassify::whereIn('id', $shopClassifys)->count() != count($shopClassifys)){
  659. return $this->fail(200004, [], '所提交的经营类目不合法,请尝试重新提交');
  660. }
  661. $margin_least = 0;
  662. WxShopClassify::whereIn('id', $shopClassifys)->get()->map(function ($v) use (&$margin_least){
  663. $margin_least += $v->guarantee;
  664. });
  665. // 这个只代表当时的一个状态
  666. $real_name = $user->real_name;
  667. $real_id_card = $user->real_id_card;
  668. if(_empty_($real_name)){
  669. return $this->fail(200001, [], '您还没有实名');
  670. }
  671. DB::beginTransaction();
  672. try {
  673. // todo:
  674. $model = new WxShop();
  675. $model->user_id = $uid;
  676. $model->shop_type = 1;
  677. $model->head_id_card_num = $real_id_card;
  678. $model->head_name = $real_name;
  679. $model->shop_classifys = implode(',', $shopClassifys);
  680. $model->margin_least = $margin_least;
  681. $model->status = 0;
  682. $r = $model->save();
  683. if($r){
  684. WxUser::where('id', $uid)->update(['shop_id' => $model->id]);
  685. Cache::forget('get:cached:user:'.$uid);
  686. DB::commit();
  687. return $this->success(['id'=>$model->id]);
  688. }else{
  689. DB::rollBack();
  690. return $this->fail(200002);
  691. }
  692. } catch (\Exception $e) {
  693. _logger_(__file__, __line__, $e->getMessage());
  694. DB::rollBack();
  695. return $this->fail(200002);
  696. }
  697. }
  698. /**
  699. * Shop添加购物袋
  700. */
  701. public function addCart(Request $request)
  702. {
  703. $num = $request->num;
  704. $uid = $request->uid;
  705. $pid = $request->pid;
  706. $goods_id = $request->gid;
  707. $action = $request->action;
  708. if(!in_array($action, ['buy', 'cart', 'gold', 'used'])){
  709. $action = 'cart';
  710. }
  711. _limit_user('add:cart', $uid, 30);
  712. if($action == 'used'){
  713. if(_empty_($goods_id)){
  714. return $this->fail(200001);
  715. }
  716. $used_good = WxUsedGood::find($goods_id);
  717. if(_empty_($used_good)){
  718. return $this->fail(200003);
  719. }
  720. if($used_good->status != 1){
  721. return $this->fail(200004, [], '该商品状态已不可购');
  722. }
  723. if($used_good->image_urls){
  724. $used_good->pic = _array_key($used_good->image_urls[0], 'url', '') . '';
  725. $used_good->pic_width = _array_key($used_good->image_urls[0], 'width', '');
  726. $used_good->pic_height = _array_key($used_good->image_urls[0], 'height', '');
  727. if($used_good->pic_width >= 350){
  728. $old_widht = $used_good->pic_width;
  729. $used_good->pic_width = 352;
  730. $used_good->pic_height = (int)( (352 * $used_good->pic_width) / $old_widht );
  731. }
  732. }
  733. $model = new WxShopCart();
  734. $model->user_id = $uid;
  735. $model->seller_user_id = $used_good->user_id;
  736. $model->goods_id = $goods_id;
  737. $model->product_id = $pid;
  738. $model->goods_type = 6;
  739. $model->goods_pic = $used_good->pic;
  740. $model->goods_name = $used_good->title;
  741. $model->goods_product = '';
  742. $model->price = $used_good->price;
  743. $model->vip_price = $used_good->price;
  744. $model->credit_type = 1;
  745. $model->num = 1;
  746. $model->is_check = 1;
  747. $model->state = 6;
  748. $model->save();
  749. UserUtils::add_user_experience($uid, 10);
  750. return $this->success(['cart_id' => $model->id]);
  751. }else{
  752. if(_empty_($num) || _empty_($goods_id) || _empty_($pid) || $num <= 0){
  753. return $this->fail(200001);
  754. }
  755. $shop_goods = WxShopGoods::find($goods_id);
  756. if(_empty_($shop_goods)){
  757. return $this->fail(200003);
  758. }
  759. $can_purchase_times = $shop_goods->can_purchase_times;
  760. if($can_purchase_times != 0){
  761. if(ShopUtils::user_buy_goods_times($uid, $goods_id) >= $can_purchase_times){
  762. return $this->fail(800004);
  763. }
  764. }
  765. $WxShopGoodsProduct = WxShopGoodsProduct::find($pid);
  766. $pstock = $WxShopGoodsProduct->stock;
  767. if ($pstock > 0) {
  768. if($action == 'cart'){
  769. if($shop_goods->type == 5){
  770. return $this->fail(200001, [], '核销类型商品不能加入购物车');
  771. }
  772. $isExists = WxShopCart::where('user_id', $uid)->where('product_id', $pid)->where('state', 0)->exists();
  773. if ($isExists) {
  774. // WxShopCart::where('user_id', $uid)->where('product_id', $pid)
  775. // ->increment('num', (int)$num);
  776. } else {
  777. $model = new WxShopCart();
  778. $model->user_id = $uid;
  779. $model->seller_user_id = $shop_goods->user_id;
  780. $model->goods_id = $goods_id;
  781. $model->product_id = $pid;
  782. $model->goods_pic = $WxShopGoodsProduct->pic;
  783. $model->goods_name = $shop_goods->name;
  784. $model->goods_product = $WxShopGoodsProduct->param_value;
  785. $model->price = $WxShopGoodsProduct->price;
  786. $model->vip_price = $WxShopGoodsProduct->vip_price;
  787. $model->credit_type = $WxShopGoodsProduct->credit_type;
  788. $model->goods_type = $shop_goods->type;
  789. $model->num = $num;
  790. $model->is_check = 1;
  791. $model->save();
  792. }
  793. // WxShopGoodsProduct::where('id', $pid)->update(['stock' => $pstock - $num]);//减库存
  794. UserUtils::add_user_experience($uid, 10);
  795. return $this->success();
  796. }else if($action == 'buy' || $action == 'gold'){
  797. $model = new WxShopCart();
  798. $model->user_id = $uid;
  799. $model->seller_user_id = $shop_goods->user_id;
  800. $model->goods_id = $goods_id;
  801. $model->product_id = $pid;
  802. $model->goods_pic = $WxShopGoodsProduct->pic;
  803. $model->goods_name = $shop_goods->name;
  804. $model->goods_product = $WxShopGoodsProduct->param_value;
  805. $model->price = $WxShopGoodsProduct->price;
  806. $model->vip_price = $WxShopGoodsProduct->vip_price;
  807. $model->credit_type = $WxShopGoodsProduct->credit_type;
  808. $model->num = $num;
  809. $model->goods_type = $shop_goods->type;
  810. $model->is_check = 1;
  811. $model->state = $action == 'buy' ? 4 : 5;
  812. $model->save();
  813. // WxShopGoodsProduct::where('id', $pid)->update(['stock' => $pstock - $num]);//减库存
  814. UserUtils::add_user_experience($uid, 10);
  815. return $this->success(['cart_id' => $model->id]);
  816. }
  817. } else {
  818. return $this->fail(800001);
  819. }
  820. }
  821. }
  822. /**
  823. * Shop用户购物袋列表
  824. */
  825. public function userCartList(Request $request)
  826. {
  827. $uid = $request->uid;
  828. $pIds = WxShopCart::where('user_id', $uid)->pluck('product_id');//购物袋规格ID列表
  829. foreach ($pIds as $v) {
  830. $isExists = WxShopGoodsProduct::where('id', $v)->where('state', 0)->exists();
  831. if (!$isExists) {
  832. WxShopCart::where('user_id', $uid)->where('product_id', $v)->where('state', 0)
  833. ->update(['state' => 3]);
  834. }
  835. }
  836. $shop_state_0_goods = WxShopGoods::whereIn('id', WxShopCart::where('user_id', $uid)->pluck('goods_id')->toArray())->where('state', 0)->pluck('id');
  837. foreach ($shop_state_0_goods as $good_0_id){
  838. WxShopCart::where('user_id', $uid)->where('goods_id', $good_0_id)->where('state', 0)
  839. ->update(['state' => 3]);
  840. }
  841. $data = WxShopCart::where('user_id', $uid)
  842. ->whereIn('state', [0,3])
  843. ->orderBy('created_at', 'desc')
  844. ->get()->map(function ($v){
  845. if(_empty_($v->num)){
  846. $v->num = 1;
  847. }
  848. return $v;
  849. });
  850. return $this->success($data);
  851. }
  852. /**
  853. * Shop修改购物袋商品数量
  854. */
  855. public function saveCartNum(Request $request)
  856. {
  857. $uid = $request->uid;
  858. $pid = $request->pid;
  859. $num = $request->num;
  860. if(_empty_($num) || $num <= 0 || _empty_($pid)){
  861. return $this->fail(200001);
  862. }
  863. $stock = WxShopGoodsProduct::where('id', $pid)->value('stock');
  864. $cnum = WxShopCart::where('user_id', $uid)->where('product_id', $pid)->where('state', 0)->value('num');
  865. if ($stock > $num - $cnum) {
  866. WxShopCart::where('user_id', $uid)->where('product_id', $pid)->where('state', 0)
  867. ->update(['num' => $num]);
  868. $pstock = $stock - ($num - $cnum);
  869. WxShopGoodsProduct::where('id', $pid)->update(['stock' => $pstock]);//减库存
  870. return $this->success();
  871. } else {
  872. return $this->fail(800002, $stock);
  873. }
  874. }
  875. /**
  876. * Shop选中购物袋商品
  877. */
  878. public function checkCartGoods(Request $request)
  879. {
  880. $uid = $request->uid;
  881. $pid = $request->pid;
  882. $check = $request->check;
  883. WxShopCart::where('user_id', $uid)->where('product_id', $pid)->where('state', 0)
  884. ->update(['is_check' => $check]);
  885. return $this->success();
  886. }
  887. /**
  888. * Shop全选购物袋商品
  889. */
  890. public function allCheckCartGoods(Request $request)
  891. {
  892. $uid = $request->uid;
  893. $is_check = $request->is_check;
  894. WxShopCart::where('user_id', $uid)->where('state', 0)
  895. ->update(['is_check' => $is_check]);
  896. return $this->success();
  897. }
  898. /**
  899. * Shop删除购物袋商品
  900. */
  901. public function delCartGoods(Request $request)
  902. {
  903. $cid = $request->cid;
  904. if(_empty_($cid)){
  905. return $this->fail(200001);
  906. }
  907. WxShopCart::where('id', $cid)
  908. ->update(['state' => 1]);
  909. return $this->success();
  910. }
  911. /**
  912. * Shop用户默认地址
  913. */
  914. public function getCheckAdds(Request $request)
  915. {
  916. $uid = $request->uid;
  917. $aid = $request->aid;
  918. if ($aid == -1) {
  919. $data = WxShopAddress::where('user_id', $uid)->where('is_check', 1)->where('state', 0)->first();
  920. } else {
  921. $data = WxShopAddress::where('user_id', $uid)->where('id', $aid)->where('state', 0)->first();
  922. }
  923. return $this->success($data);
  924. }
  925. /**
  926. * Shop用户地址列表
  927. */
  928. public function getAddsList(Request $request)
  929. {
  930. $uid = $request->uid;
  931. $data = WxShopAddress::where('user_id', $uid)->where('state', 0)
  932. ->orderBy('is_check', 'desc')
  933. ->orderBy('created_at', 'desc')->get();
  934. return $this->success($data);
  935. }
  936. /**
  937. * Shop增加/修改地址
  938. */
  939. public function saveAdds(Request $request)
  940. {
  941. $uid = $request->uid;
  942. $aid = $request->aid;
  943. $name = $request->name;
  944. $mobile = $request->mobile;
  945. $province = $request->province;
  946. $city = $request->city;
  947. $county = $request->county;
  948. $adds = $request->adds;
  949. $is_check = $request->is_check;
  950. if ($is_check == 1) {
  951. WxShopAddress::where('user_id', $uid)->where('is_check', 1)->where('state', 0)->update(['is_check' => 0]);
  952. }
  953. if ($aid == -1) {
  954. $model = new WxShopAddress();
  955. $model->user_id = $uid;
  956. $model->name = $name;
  957. $model->mobile = $mobile;
  958. $model->province = $province;
  959. $model->city = $city;
  960. $model->county = $county;
  961. $model->adds = $adds;
  962. $model->is_check = $is_check;
  963. $model->save();
  964. } else {
  965. WxShopAddress::where('user_id', $uid)->where('id', $aid)->where('state', 0)
  966. ->update(['name' => $name,
  967. 'mobile' => $mobile,
  968. 'province' => $province,
  969. 'city' => $city,
  970. 'county' => $county,
  971. 'adds' => $adds,
  972. 'is_check' => $is_check]);
  973. }
  974. return $this->success();
  975. }
  976. /**
  977. * Shop用户删除地址
  978. */
  979. public function delAdds(Request $request)
  980. {
  981. $uid = $request->uid;
  982. $aid = $request->aid;
  983. $data = WxShopAddress::where('user_id', $uid)->where('id', $aid)->where('state', 0)
  984. ->update(['state' => 1]);
  985. return $this->success($data);
  986. }
  987. /**
  988. * Shop订单修改地址
  989. */
  990. public function orderAddress(Request $request){
  991. $order_id = $request->order_id;
  992. $aid = $request->aid;
  993. $uid = $request->uid;
  994. if(_empty_($order_id) || _empty_($aid)){
  995. return $this->fail(200001);
  996. }
  997. $order_id = _abs($order_id);
  998. $aid = _abs($aid);
  999. $shop_order = WxShopOrder::where('id', $order_id)->where('user_id', $uid)->where('status', 1)->first();
  1000. if(!$shop_order){
  1001. return $this->fail(200003);
  1002. }
  1003. $address = WxShopAddress::where('id', $aid)->where('user_id', $uid)->where('state', 0)->first();
  1004. if(!$address){
  1005. return $this->fail(200003);
  1006. }
  1007. $shop_order->adds_id = $address->id;
  1008. $shop_order->adds_name = $address->name;
  1009. $shop_order->adds_mobile = $address->mobile;
  1010. $shop_order->address = $address->province . $address->city . $address->county . $address->adds;
  1011. $r = $shop_order->save();
  1012. if($r){
  1013. return $this->success(['adds_id'=>$shop_order->adds_id,
  1014. 'adds_name'=>$shop_order->adds_name,
  1015. 'adds_mobile'=>$shop_order->adds_mobile, 'address'=>$shop_order->address]);
  1016. }else{
  1017. return $this->fail(200002);
  1018. }
  1019. }
  1020. /**
  1021. * Shop下单商品列表
  1022. */
  1023. public function pliceOrderGoods(Request $request)
  1024. {
  1025. $uid = $request->uid;
  1026. $cart_id = $request->cart_id;
  1027. if(_empty_($cart_id)){
  1028. $cart_id = 0;
  1029. }
  1030. if($cart_id > 0){
  1031. // 4: 人民币 5:金币
  1032. $data = WxShopCart::where('id', $cart_id)
  1033. ->get(['id', 'goods_id', 'goods_type', 'goods_name', 'goods_pic', 'goods_product', 'num', 'price', 'product_id', 'vip_price', 'credit_type']);
  1034. }else{
  1035. $data = WxShopCart::where('user_id', $uid)->where('is_check', 1)
  1036. ->where('state', 0)
  1037. ->get(['id', 'goods_id', 'goods_type', 'goods_name', 'goods_pic', 'goods_product', 'num', 'price', 'product_id', 'vip_price', 'credit_type']);
  1038. }
  1039. return $this->success($data);
  1040. }
  1041. /**
  1042. * Shop用户购物袋数量
  1043. */
  1044. public function userCartCount(Request $request)
  1045. {
  1046. $uid = $request->uid;
  1047. return $this->success(ShopUtils::user_cart_count($uid));
  1048. }
  1049. /**
  1050. * 解析淘客商品
  1051. */
  1052. public function taokeParseUrl(Request $request){
  1053. $url = $request->url;
  1054. if(_empty_($url)){
  1055. return $this->fail(200001);
  1056. }
  1057. $res = preg_match('$item\.m\.jd\.com/product/(\d+)\.html$', $url, $matchs);
  1058. if($res <= 0){
  1059. $res = preg_match('$item\.jd\.com/(\d+)\.html$', $url, $matchs);
  1060. }
  1061. if($res > 0){
  1062. if($matchs[1] > 0){
  1063. $goods_id_obj = TaokeUtils::get_goods_id_from_taoke(0, $matchs[1], 3);
  1064. if($goods_id_obj && $goods_id_obj['code'] == 1){
  1065. $goods = WxShopGoods::find($goods_id_obj['data']);
  1066. return $this->success(['id'=>$goods_id_obj['data'], 'name'=>$goods->name, 'pic'=>_array_key($goods->pic, 0, '')]);
  1067. }else{
  1068. _logger_(__file__, __line__, $url);
  1069. return $this->fail(200006, [], '解析失败,请等会再重试_jd');
  1070. }
  1071. }
  1072. }else{
  1073. if(preg_match('$haohuo\.jinritemai\.com$', $url) > 0 || preg_match('$v\.douyin\.com$', $url) > 0){
  1074. // 抖音
  1075. if(preg_match('$haohuo\.jinritemai\.com$', $url) > 0){
  1076. $res = preg_match('$[\?&]id=(\d+)$', $url, $matchs);
  1077. if($res > 0){
  1078. if($matchs[1] > 0){
  1079. $goods_id_obj = TaokeUtils::get_goods_id_from_taoke(0, $matchs[1], 5);
  1080. if($goods_id_obj && $goods_id_obj['code'] == 1){
  1081. $goods = WxShopGoods::find($goods_id_obj['data']);
  1082. return $this->success(['id'=>$goods_id_obj['data'], 'name'=>$goods->name, 'pic'=>_array_key($goods->pic, 0, '')]);
  1083. }else{
  1084. return $this->fail(200006, [], '解析失败,请等会再重试_dy1');
  1085. }
  1086. }
  1087. }else{
  1088. _logger_(__file__, __line__, $url);
  1089. return $this->fail(200006, [], '解析失败,请等会再重试_dy2');
  1090. }
  1091. }else{
  1092. return $this->fail(200004, [], '不支持抖音短链接,请把短连接放到浏览器,然后复制长链接进行尝试');
  1093. }
  1094. }else{
  1095. if(preg_match('$yangkeduo\.com$', $url) > 0){
  1096. $res = preg_match('$[\?&]goods_id=(\d+)$', $url, $matchs);
  1097. if($res > 0){
  1098. if($matchs[1] > 0){
  1099. $goods_id_obj = TaokeUtils::get_goods_id_from_taoke(0, $matchs[1], 4);
  1100. if($goods_id_obj && $goods_id_obj['code'] == 1){
  1101. $goods = WxShopGoods::find($goods_id_obj['data']);
  1102. return $this->success(['id'=>$goods_id_obj['data'], 'name'=>$goods->name, 'pic'=>_array_key($goods->pic, 0, '')]);
  1103. }else{
  1104. _logger_(__file__, __line__, $url);
  1105. return $this->fail(200006, [], '解析失败,请等会再重试_pdd');
  1106. }
  1107. }
  1108. }else{
  1109. _logger_(__file__, __line__, $url);
  1110. return $this->fail(200006, [], '解析失败,请等会再重试_pdd');
  1111. }
  1112. }else{
  1113. // 剪切版识别
  1114. $res = TaokeUtils::get_taobao_item_from_content($url);
  1115. if($res['code'] == 1){
  1116. }else{
  1117. // 淘口令解析
  1118. $res = TaokeUtils::get_taobao_item_from_taokouling($url);
  1119. if($res['code'] == 1){
  1120. }else{
  1121. return $this->fail(200006, [], '解析失败,暂时只支持淘宝,京东,拼多多,抖音的商品链接!_tb');
  1122. }
  1123. }
  1124. $goods_id_obj = TaokeUtils::get_goods_id_from_taoke(0, $res['data'], 1);
  1125. if($goods_id_obj && $goods_id_obj['code'] == 1){
  1126. $goods = WxShopGoods::find($goods_id_obj['data']);
  1127. return $this->success(['id'=>$goods_id_obj['data'], 'name'=>$goods->name, 'pic'=>_array_key($goods->pic, 0, '')]);
  1128. }else{
  1129. _logger_(__file__, __line__, $url);
  1130. return $this->fail(200006, [], '解析失败,请等会再重试_tb');
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. }