Merchant.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/28
  6. */
  7. namespace app\controller\api\store\merchant;
  8. use think\App;
  9. use crmeb\basic\BaseController;
  10. use app\common\repositories\system\merchant\MerchantRepository as repository;
  11. use app\common\repositories\store\product\ProductRepository;
  12. use think\facade\Db;
  13. use think\facade\Log;
  14. use function Symfony\Component\VarDumper\Dumper\esc;
  15. class Merchant extends BaseController
  16. {
  17. protected $repository;
  18. protected $userInfo;
  19. private $merId;
  20. private $source;
  21. /**
  22. * ProductCategory constructor.
  23. * @param App $app
  24. * @param repository $repository
  25. */
  26. public function __construct(App $app, repository $repository)
  27. {
  28. parent::__construct($app);
  29. $this->repository = $repository;
  30. $this->userInfo =$this->request->isLogin() ? $this->request->userInfo():null;
  31. $this->source = $this->request->header('source');
  32. $this->merId = $this->request->header('merId');
  33. }
  34. /**
  35. * @Author:Qinii
  36. * @Date: 2020/5/27
  37. * @return mixed
  38. */
  39. public function lst()
  40. {
  41. [$page, $limit] = $this->getPage();
  42. $where = $this->request->params(['keyword','order','category_id']);
  43. return json_encode($where);
  44. return app('json')->success($this->repository->getList($where, $page,$limit,$this->userInfo));
  45. }
  46. /**
  47. * @Author:Qinii
  48. * @Date: 2020/5/29
  49. * @param $id
  50. * @return mixed
  51. */
  52. public function detail($id)
  53. {
  54. if(!$this->repository->apiGetOne($id))
  55. return app('json')->fail('店铺不存在');
  56. $lat=$this->request->param('lat','');
  57. $lng=$this->request->param('lng','');
  58. return app('json')->success($this->repository->detail($id,$this->userInfo,$lat, $lng));
  59. }
  60. /**
  61. * @Author:Qinii
  62. * @Date: 2020/5/29
  63. * @param $id
  64. * @return mixed
  65. */
  66. public function productList($id)
  67. {
  68. [$page, $limit] = $this->getPage();
  69. $where = $this->request->params(['keyword','order','mer_cate_id','price_on', 'price_off','brand_id']);
  70. $where['is_gift_bag'] = 0;
  71. $where['is_used'] = 1;
  72. $where['product_type'] = 0;
  73. $where['is_hide'] = 0;
  74. if($id==324){
  75. $where['mer_type']=1;
  76. }
  77. if($this->source=='yhc' && $this->merId==496){
  78. return app('json')->success($this->repository->productList_yhc($id,$where, $page, $limit,$this->userInfo));
  79. }
  80. return app('json')->success($this->repository->productList($id,$where, $page, $limit,$this->userInfo));
  81. }
  82. public function productTypeList()
  83. {
  84. $params= $this->request->params(['type','mer_cate_id','pageNum','pageSize','mer_id']);
  85. $name=$params['type'];
  86. $domain = $this->request->domain();
  87. $id=0;
  88. $type439=true;
  89. $is_commercetrade = 0;
  90. if($name=='dingsheng'){
  91. $id=486;
  92. }else if($name=='jingpin'){
  93. $id=439;
  94. $type439=false;
  95. }else if($name=='jifen'){
  96. $id=148;
  97. }else if($name=='gongchang'){
  98. if(strpos($domain, 'test.hebeiyhc.com') !== false) {
  99. // 域名中包含 "test.hebeiyhc.com'" 字符串
  100. $id=486;//测试环境工厂直供
  101. }else{
  102. $id=497;//生产环境工厂直供
  103. }
  104. }else if($name=='fugou'){
  105. $id=491;
  106. }// 商贸区
  107. else if($name=='commercetrade'){
  108. if (empty($params['mer_id'])) return app('json')->fail('店铺不存在');
  109. $id=$this->merId = $params['mer_id'];
  110. $is_commercetrade = 1;
  111. } else if ($name == 'sharedProsperity') {
  112. $id = 3447;
  113. }
  114. [$page, $limit] = $this->getPage();
  115. if($params['pageNum']!=''){
  116. $page=$params['pageNum'];
  117. }
  118. if($params['pageSize']!=''){
  119. $limit=$params['pageSize'];
  120. }
  121. $where = $this->request->params(['keyword','order','mer_cate_id', 'cate_id','price_on', 'price_off','brand_id']);
  122. $where['is_gift_bag'] = 0;
  123. $where['is_used'] = 1;
  124. $where['product_type'] = 0;
  125. $where['is_hide'] = 0;
  126. // log::info("====={$params['mer_cate_id']}===");
  127. if($params['mer_cate_id']){
  128. $where['cate_id'] = $params['mer_cate_id'];
  129. }
  130. $result = $this->repository->productList($id,$where, $page, $limit,$this->userInfo,$type439,$is_commercetrade);
  131. // ===== sort 相同则随机打乱顺序 =====
  132. // 默认排序为 sort DESC, create_time DESC。当多条商品 sort 值相同时,
  133. // 按 sort 分组,同组内随机打乱,使相同权重的商品每次展示顺序不同
  134. if (!empty($result['list'])) {
  135. try {
  136. $grouped = []; // 按 sort 值分组
  137. foreach ($result['list'] as $item) {
  138. $sortVal = $item['sort'] ?? 0;
  139. $grouped[$sortVal][] = $item;
  140. }
  141. // 同 sort 组内随机打乱
  142. $shuffled = [];
  143. foreach ($grouped as $sortVal => $group) {
  144. if (count($group) > 1) {
  145. shuffle($group);
  146. }
  147. $shuffled = array_merge($shuffled, $group);
  148. }
  149. $result['list'] = $shuffled;
  150. } catch (\Throwable $e) {
  151. Log::info('productTypeList sort 随机打乱失败: ' . $e->getMessage());
  152. }
  153. }
  154. // ===== sort 随机打乱结束 =====
  155. // ===== 混入推荐商品逻辑(每页3-5个,跨页不重复,随机插入) =====
  156. // 用户已登录且没有主动搜索时,将搜索关键词匹配的商品随机混入列表,保持每页商品数量不变
  157. // 跨页去重方案:一次性查询所有匹配商品形成"推荐池",按页码切片取不同子集
  158. $hasKeyword = !empty($params['keyword'] ?? '') || !empty($this->request->param('keyword', ''));
  159. if (!is_null($this->userInfo) && !empty($result['list']) && !$hasKeyword) {
  160. try {
  161. // 1. 获取用户最近的搜索关键词(SQL 层去重)
  162. $searchKeywords = Db::name('user_visit')
  163. ->where('uid', $this->userInfo['uid'])
  164. ->where('type', 'searchProduct')
  165. ->where('content', '<>', '')
  166. ->group('content')
  167. ->order('create_time', 'DESC')
  168. ->limit(5)
  169. ->column('content');
  170. $searchKeywords = array_filter($searchKeywords);
  171. if (!empty($searchKeywords)) {
  172. // 2. 查询所有匹配的商品ID(不 limit,形成推荐池),排除已在当前列表中的
  173. $existIds = array_column($result['list'], 'product_id');
  174. $matchQuery = Db::name('store_product')
  175. ->where('mer_id', $id)
  176. ->where('is_show', 1)
  177. ->where('status', 1)
  178. ->where('is_del', 0)
  179. ->where('is_gift_bag', 0)
  180. ->where('product_type', 0)
  181. ->where('price', '>', 0);
  182. // 关键词 LIKE 条件
  183. $matchQuery->where(function ($q) use ($searchKeywords) {
  184. foreach ($searchKeywords as $kw) {
  185. $q->whereOr('store_name', 'like', "%{$kw}%");
  186. }
  187. });
  188. if (!empty($existIds)) {
  189. $matchQuery->whereNotIn('product_id', $existIds);
  190. }
  191. // 查出所有匹配商品ID(推荐池),按 ID 排序保证跨页顺序一致
  192. $allMatchProductIds = $matchQuery->order('product_id', 'ASC')->column('product_id');
  193. if (!empty($allMatchProductIds)) {
  194. // 3. 根据页码切片:每页取 mixCount 个,不同页取不同区间
  195. $mixCount = min(5, $limit); // 每页混入3-5个,取上限5
  196. $totalPool = count($allMatchProductIds);
  197. // 如果推荐池足够大,按页码切片;否则循环复用但保证同一页内不重复
  198. if ($totalPool <= $mixCount) {
  199. // 池子太小:全部使用,但不同页之间可能重复(资源有限)
  200. $pageMatchIds = $allMatchProductIds;
  201. } else {
  202. // 池子足够:按页码取不同切片
  203. // 计算当前页的起始偏移量,确保不同页取不同区间
  204. $offset = (($page - 1) * $mixCount) % $totalPool;
  205. $pageMatchIds = array_slice($allMatchProductIds, $offset, $mixCount);
  206. // 如果切片不够 mixCount,从头部补足(环形取)
  207. if (count($pageMatchIds) < $mixCount) {
  208. $remainder = array_slice($allMatchProductIds, 0, $mixCount - count($pageMatchIds));
  209. $pageMatchIds = array_merge($pageMatchIds, $remainder);
  210. }
  211. }
  212. if (!empty($pageMatchIds)) {
  213. // 4. 直接用 pageMatchIds 查询 store_product 表获取基础数据
  214. // 再通过 pvParm 补充 yanglao/pv/jifen/gongxian 等格式化字段
  215. $baseProducts = Db::name('store_product')
  216. ->where('mer_id', $id)
  217. ->whereIn('product_id', $pageMatchIds)
  218. ->where('is_show', 1)
  219. ->where('status', 1)
  220. ->where('is_del', 0)
  221. ->select();
  222. $baseProducts = $baseProducts->toArray();
  223. $matchList = [];
  224. if (!empty($baseProducts)) {
  225. foreach ($baseProducts as $bp) {
  226. // 补充 pv/yanglao/jifen/gongxian 等字段
  227. $pvData = app()->make(ProductRepository::class)->pvParm($bp['product_id']);
  228. $bp['yanglao'] = $pvData['yanglao'] ?? '';
  229. $bp['pv'] = $pvData['pv'] ?? '';
  230. $bp['jifen'] = $pvData['jifen'] ?? '';
  231. $bp['gongxian'] = $pvData['gongxian'] ?? '';
  232. $bp['jfduihuan'] = $pvData['jfduihuan'] ?? '';
  233. $bp['jdduihuan'] = $pvData['jdduihuan'] ?? '';
  234. $bp['fzone_paytype'] = $pvData['fzone_paytype'] ?? '';
  235. $matchList[] = $bp;
  236. }
  237. }
  238. // 5. 随机混入:不移除原商品,将推荐商品随机插入到列表中
  239. $actualMixCount = min(count($matchList), $mixCount);
  240. if ($actualMixCount > 0) {
  241. $matchList = array_slice($matchList, 0, $actualMixCount);
  242. // 随机插入推荐商品(不移除任何原商品)
  243. foreach ($matchList as $ml) {
  244. $insertPos = rand(0, count($result['list']));
  245. array_splice($result['list'], $insertPos, 0, [$ml]);
  246. }
  247. }
  248. }
  249. }
  250. }
  251. } catch (\Throwable $e) {
  252. Log::info('productTypeList 混入推荐商品失败: ' . $e->getMessage());
  253. }
  254. }
  255. // ===== 混入推荐商品逻辑结束 =====
  256. return app('json')->success($result);
  257. }
  258. /**
  259. * 获取商户上架的商品列表
  260. * @return mixed
  261. */
  262. public function getProductList()
  263. {
  264. $params = request()->only(['pageNum', 'pageSize', 'mer_id']);
  265. $merId = $params['mer_id'] ?? 0;
  266. [$page, $limit] = $this->getPage();
  267. $where = request()->only(['keyword']);
  268. $where['is_gift_bag'] = 0;
  269. $where['is_used'] = 1;
  270. $where['product_type'] = 0;
  271. $where['is_hide'] = 0;
  272. $result = $this->repository->productList($merId, $where, $page, $limit, $this->userInfo);
  273. $formatList = [];
  274. foreach ($result['list'] as $productInfo) {
  275. $formatList[] = [
  276. 'type' => 0,//京东商品
  277. 'merId' => $productInfo['mer_id'],
  278. 'skuId' => '',//itemId 京东官方 已不返回skuId , 使用 联盟商品ID 代替skuId
  279. 'id' => $productInfo['product_id'] ?? '', //id
  280. 'name' => $productInfo['store_name'],//名称
  281. 'thumb' => $productInfo['image'] ?? '',//商品缩略图
  282. 'pv' => $productInfo['pv'],//PV金额
  283. 'gongxian' => $productInfo['gongxian'],
  284. 'jifen' => $productInfo['jifen'],
  285. 'yanglaojin' => $productInfo['yanglao'],
  286. 'commission' => $productInfo['concession_pri'],//佣金
  287. 'commission_rate' => null,//佣金比例
  288. 'coupon_money' => [],
  289. 'coupon_link' => '',
  290. 'lowestCouponPrice' => $productInfo['price'],
  291. 'price' => $productInfo['ot_price'], //价格
  292. 'imageList' => $productInfo['slider_image'], //图片合集
  293. 'materialUrl' => ''
  294. ];
  295. }
  296. return app('json')->success($formatList);
  297. }
  298. /**
  299. * 商贸区店铺商品列表
  300. * @return mixed
  301. * @throws \think\db\exception\DataNotFoundException
  302. * @throws \think\db\exception\DbException
  303. * @throws \think\db\exception\ModelNotFoundException
  304. */
  305. public function commerceProductList()
  306. {
  307. $params= $this->request->params(['pageNum','pageSize','category_id']);
  308. $mer_id_unset = [496,486,439,148,491];
  309. $domain = $this->request->domain();
  310. if(strpos($domain, 'test.hebeiyhc.com') !== false) {
  311. // 域名中包含 "test.hebeiyhc.com'" 字符串
  312. array_push($mer_id_unset, 486);
  313. }else{
  314. array_push($mer_id_unset, 497);
  315. }
  316. $is_commercetrade = 1;
  317. [$page, $limit] = $this->getPage();
  318. if($params['pageNum']!=''){
  319. $page=$params['pageNum'];
  320. }
  321. if($params['pageSize']!=''){
  322. $limit=$params['pageSize'];
  323. }
  324. $category_id = $params['category_id']?:0;
  325. $where['is_del'] = 0;
  326. $where['status'] = 1;
  327. $category_id && $where['category_id'] = $category_id;
  328. $hasProductMerIdList = Db::name('store_product')
  329. ->where('status', '=', 1)
  330. ->where('is_show', '=', 1)
  331. ->where('is_del', '=', 0)
  332. ->group('mer_id')
  333. ->field('mer_id')
  334. ->select();
  335. if ($hasProductMerIdList) {
  336. $hasProductMerIdList = array_column($hasProductMerIdList->toArray(), 'mer_id');
  337. }
  338. $query = Db::name('merchant')->where($where);
  339. if (!empty($hasProductMerIdList) && is_array($hasProductMerIdList)) {
  340. $query->whereIn('mer_id', $hasProductMerIdList);
  341. }
  342. $mer_list = $query->page($page)->limit($limit)->select();
  343. $where['is_gift_bag'] = 0;
  344. $where['is_used'] = 1;
  345. $where['product_type'] = 0;
  346. $where['is_hide'] = 0;
  347. $return_list = [];
  348. if($mer_list) {
  349. $mer_list = $mer_list->toArray();
  350. foreach ($mer_list as $mer) {
  351. if(in_array($mer['mer_id'],$mer_id_unset)) continue;
  352. $goods = $this->repository->productList($mer['mer_id'],$where, 1, 3,$this->userInfo,false,$is_commercetrade);
  353. if(empty($goods['list'])) continue;
  354. $mer['goods_list'] = $goods['list'];
  355. if (mb_strlen($mer['mer_name']) > 8) {
  356. $mer['mer_name'] = mb_substr($mer['mer_name'], 0, 8) . '...';
  357. }
  358. $return_list[] = $mer;
  359. }
  360. }
  361. return app('json')->success(['list'=>$return_list]);
  362. }
  363. /**
  364. * 查询代理人商品
  365. * @param $type
  366. * @return mixed
  367. */
  368. public function areaProductList()
  369. {
  370. [$page, $limit] = $this->getPage();
  371. $where = $this->request->params(['keyword','order','mer_cate_id','price_on', 'price_off','brand_id']);
  372. $where['is_gift_bag'] = 0;
  373. $where['is_used'] = 1;
  374. $where['product_type'] = 0;
  375. $where['is_hide'] = 0;
  376. $type = $this->request->param('type');
  377. Log::info('查询代理人商品请求参数,type:'.$type);
  378. $type = $type == 'district' ? 13 : ($type == 'town' ? 12 : ($type == 'village' ? 11 : -1));
  379. // $where['web_type'] = $type;
  380. $id = 324;
  381. $data = $this->repository->productList($id,$where, $page, $limit,$this->userInfo);
  382. Log::info('查询代理人商品返回'.json_encode($data,true));
  383. return app('json')->success($data);
  384. }
  385. /**
  386. * @Author:Qinii
  387. * @Date: 2020/5/29
  388. * @param int $id
  389. * @return mixed
  390. */
  391. public function categoryList($id)
  392. {
  393. if(!$this->repository->merExists($id))
  394. return app('json')->fail('店铺不存在');
  395. return app('json')->success($this->repository->categoryList($id));
  396. }
  397. public function qrcode($id)
  398. {
  399. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  400. if(!$mer)
  401. return app('json')->fail('店铺不存在');
  402. $type = $this->request->param('type');
  403. $is_payment = $this->request->param('is_payment', 0);
  404. switch ($type) {
  405. case 'routine':
  406. if ($is_payment) {
  407. $url = $this->repository->routineQrcode(intval($id), '/h5payment/index.html','_store_routine_payment.jpg');
  408. } else {
  409. $url = $this->repository->routineQrcode(intval($id));
  410. }
  411. break;
  412. default:
  413. if ($is_payment) {
  414. $url = $this->repository->wxQrcode(intval($id), '/h5payment/index.html', '_store_wap_payment.jpg', $mer->mer_avatar);
  415. } else {
  416. $url = $this->repository->wxQrcode(intval($id));
  417. }
  418. }
  419. return app('json')->success(compact('url'));
  420. }
  421. public function payQrCode($id){
  422. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  423. if(!$mer)
  424. return app('json')->fail('店铺不存在');
  425. $res = $this -> repository -> getQrCode($mer);
  426. return app('json') -> success($res);
  427. }
  428. /**
  429. * @Date: 2020/10/10
  430. * 店铺列表 :首页 最多十个
  431. * @return mixed
  432. */
  433. public function listindex()
  434. {
  435. // [$page, $limit] = $this->getPage();
  436. $page=input("page/d",1);
  437. $limit=input("limit/d",10);
  438. $keyword=input("keyword","");
  439. $order=input("order",0);
  440. $type=input("type",2);
  441. $lat=input("lat",1);
  442. $lng=input("lng",1);
  443. $data=[
  444. "lat"=>$lat,
  445. "lng"=>$lng,
  446. "keyword"=>$keyword,
  447. "order"=>$order
  448. ];
  449. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  450. }
  451. /**
  452. * @Date: 2020/10/10
  453. * 店铺列表:
  454. * @param $keyword //搜索
  455. * @param $order //排序
  456. * @param $category_id //分类id
  457. * @return mixed
  458. */
  459. public function list()
  460. {
  461. $category_id=input("category_id",0);
  462. $page=input("page/d",1);
  463. $limit=input("limit/d",10);
  464. $keyword=input("keyword","");
  465. $order=input("order",0);
  466. $type=input("type",0);
  467. $lat=input("lat",'113.643636');
  468. $lng=input("lng",'34.73841');
  469. $city_name=input("city_name",'');
  470. if ($type==2){
  471. $data=[
  472. "lat"=>empty($lat)?"113.643636":$lat,
  473. "lng"=>empty($lng)?"34.73841":$lng,
  474. "keyword"=>$keyword,
  475. "order"=>$order
  476. ];
  477. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  478. }
  479. $where=[];
  480. if ($category_id){
  481. $where["category_id"]=$category_id;
  482. }
  483. $data=[
  484. "lat"=>empty($lat)?"34.73841":$lat,
  485. "lng"=>empty($lng)?"113.643636":$lng,
  486. ];
  487. if ($city_name){
  488. $data["city_name"]=$city_name;
  489. }
  490. return app('json')->success($this->repository->getLists($data,1,10,1,$where));
  491. // return app('json')->success(['count'=>0,'list'=>[],'where'=>[]]);
  492. }
  493. /**
  494. * @Date: 2020/10/10
  495. * 店铺分类
  496. */
  497. public function merchantcategory()
  498. {
  499. [$page, $limit] = $this->getPage();
  500. return app('json')->success($this->repository->merchantcategory());
  501. }
  502. /**
  503. * 附近页面商家分类
  504. * @day 2020/10/30
  505. */
  506. public function mercat()
  507. {
  508. [$page, $limit] = $this->getPage();
  509. return app('json')->success($this->repository->mercat($page, $limit));
  510. }
  511. /*
  512. *分类下的商家列表
  513. * @author cabbage
  514. * @day 2020/10/30
  515. * */
  516. public function mercatStore(){
  517. [$page, $limit] = $this->getPage();
  518. $data = $this->request->params([
  519. 'order', //人气
  520. 'distance', //距离
  521. 'lat', //经度
  522. 'lng', //纬度
  523. 'user_id'
  524. ]);
  525. $where = $this->request->params([
  526. 'category_id', //商铺分类id
  527. 'keyword', //商铺名称
  528. ]);
  529. return app('json')->success($this->repository->getLst($data,$page,$limit,$where));
  530. // return app('json')->success([]);
  531. }
  532. /**
  533. * @param $id
  534. * @return mixed
  535. * @throws \think\db\exception\DbException
  536. * 店铺置顶
  537. */
  538. public function shop_topping($id)
  539. {
  540. if($id!=0){
  541. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>$id]);
  542. if($res!==false)
  543. $message='置顶成功';
  544. else
  545. $message='置顶失败';
  546. return app('json')->success($message);
  547. }else{
  548. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>0]);
  549. if($res!==false)
  550. $message='取消置顶成功';
  551. else
  552. $message='取消置顶失败';
  553. return app('json')->success($message);
  554. }
  555. }
  556. /**
  557. * @param $id
  558. * @return mixed
  559. * @throws \think\db\exception\DbException
  560. * 店铺点赞 or 店铺取消点赞
  561. */
  562. public function shop_fabulous($id)
  563. {
  564. $uid=$this->request->uid();
  565. $user_like=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->value('status');
  566. if($user_like=='0'){
  567. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>1]);
  568. if($res!==false)
  569. $message='点赞成功';
  570. else
  571. $message='点赞失败';
  572. }elseif ($user_like=='1'){
  573. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>0]);
  574. if($res!==false)
  575. $message='取消点赞成功';
  576. else
  577. $message='取消点赞失败';
  578. }else{
  579. $inser_data=[
  580. 'uid'=>$uid,
  581. 'mer_id'=>$id,
  582. 'ctime'=>time(),
  583. 'status'=>1
  584. ];
  585. $res=Db::name('store_fabulous')->insert($inser_data);
  586. if($res!==false)
  587. $message='点赞成功';
  588. else
  589. $message='点赞失败';
  590. }
  591. return app('json')->success($message);
  592. }
  593. }