Merchant.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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. if (!is_null($this->userInfo) && !empty($result['list'])) {
  159. try {
  160. // 1. 获取用户最近的搜索关键词(去重)
  161. $searchKeywords = Db::name('user_visit')
  162. ->where('uid', $this->userInfo['uid'])
  163. ->where('type', 'searchProduct')
  164. ->where('content', '<>', '')
  165. ->order('create_time', 'DESC')
  166. ->limit(5)
  167. ->column('content');
  168. $searchKeywords = array_unique(array_filter($searchKeywords));
  169. if (!empty($searchKeywords)) {
  170. // 2. 查询所有匹配的商品ID(不 limit,形成推荐池),排除已在当前列表中的
  171. $existIds = array_column($result['list'], 'product_id');
  172. $matchQuery = Db::name('store_product')
  173. ->where('mer_id', $id)
  174. ->where('is_show', 1)
  175. ->where('status', 1)
  176. ->where('is_del', 0)
  177. ->where('is_gift_bag', 0)
  178. ->where('product_type', 0)
  179. ->where('price', '>', 0);
  180. // 关键词 LIKE 条件
  181. $matchQuery->where(function ($q) use ($searchKeywords) {
  182. foreach ($searchKeywords as $kw) {
  183. $q->whereOr('store_name', 'like', "%{$kw}%");
  184. }
  185. });
  186. if (!empty($existIds)) {
  187. $matchQuery->whereNotIn('product_id', $existIds);
  188. }
  189. // 查出所有匹配商品ID(推荐池),按 ID 排序保证跨页顺序一致
  190. $allMatchProductIds = $matchQuery->order('product_id', 'ASC')->column('product_id');
  191. if (!empty($allMatchProductIds)) {
  192. // 3. 根据页码切片:每页取 mixCount 个,不同页取不同区间
  193. $mixCount = min(5, $limit); // 每页混入3-5个,取上限5
  194. $totalPool = count($allMatchProductIds);
  195. // 如果推荐池足够大,按页码切片;否则循环复用但保证同一页内不重复
  196. if ($totalPool <= $mixCount) {
  197. // 池子太小:全部使用,但不同页之间可能重复(资源有限)
  198. $pageMatchIds = $allMatchProductIds;
  199. } else {
  200. // 池子足够:按页码取不同切片
  201. // 计算当前页的起始偏移量,确保不同页取不同区间
  202. $offset = (($page - 1) * $mixCount) % $totalPool;
  203. $pageMatchIds = array_slice($allMatchProductIds, $offset, $mixCount);
  204. // 如果切片不够 mixCount,从头部补足(环形取)
  205. if (count($pageMatchIds) < $mixCount) {
  206. $remainder = array_slice($allMatchProductIds, 0, $mixCount - count($pageMatchIds));
  207. $pageMatchIds = array_merge($pageMatchIds, $remainder);
  208. }
  209. }
  210. if (!empty($pageMatchIds)) {
  211. // 4. 直接用 pageMatchIds 查询 store_product 表获取基础数据
  212. // 再通过 pvParm 补充 yanglao/pv/jifen/gongxian 等格式化字段
  213. $baseProducts = Db::name('store_product')
  214. ->where('mer_id', $id)
  215. ->whereIn('product_id', $pageMatchIds)
  216. ->where('is_show', 1)
  217. ->where('status', 1)
  218. ->where('is_del', 0)
  219. ->select();
  220. $baseProducts = $baseProducts->toArray();
  221. $matchList = [];
  222. if (!empty($baseProducts)) {
  223. foreach ($baseProducts as $bp) {
  224. // 补充 pv/yanglao/jifen/gongxian 等字段
  225. $pvData = app()->make(ProductRepository::class)->pvParm($bp['product_id']);
  226. $bp['yanglao'] = $pvData['yanglao'] ?? '';
  227. $bp['pv'] = $pvData['pv'] ?? '';
  228. $bp['jifen'] = $pvData['jifen'] ?? '';
  229. $bp['gongxian'] = $pvData['gongxian'] ?? '';
  230. $bp['jfduihuan'] = $pvData['jfduihuan'] ?? '';
  231. $bp['jdduihuan'] = $pvData['jdduihuan'] ?? '';
  232. $bp['fzone_paytype'] = $pvData['fzone_paytype'] ?? '';
  233. $matchList[] = $bp;
  234. }
  235. }
  236. // 5. 随机混入:从原列表中随机移除同等数量商品,再随机插入推荐商品
  237. $actualMixCount = min(count($matchList), $mixCount, $limit);
  238. if ($actualMixCount > 0) {
  239. $matchList = array_slice($matchList, 0, $actualMixCount);
  240. // 随机选择要移除的商品位置
  241. $removeKeys = array_rand($result['list'], $actualMixCount);
  242. if (!is_array($removeKeys)) {
  243. $removeKeys = [$removeKeys];
  244. }
  245. // 从大到小排序,避免删除时索引错乱
  246. rsort($removeKeys);
  247. foreach ($removeKeys as $rk) {
  248. array_splice($result['list'], $rk, 1);
  249. }
  250. // 随机插入推荐商品
  251. foreach ($matchList as $ml) {
  252. $insertPos = rand(0, count($result['list']));
  253. array_splice($result['list'], $insertPos, 0, [$ml]);
  254. }
  255. }
  256. }
  257. }
  258. }
  259. } catch (\Throwable $e) {
  260. Log::info('productTypeList 混入推荐商品失败: ' . $e->getMessage());
  261. }
  262. }
  263. // ===== 混入推荐商品逻辑结束 =====
  264. return app('json')->success($result);
  265. }
  266. /**
  267. * 获取商户上架的商品列表
  268. * @return mixed
  269. */
  270. public function getProductList()
  271. {
  272. $params = request()->only(['pageNum', 'pageSize', 'mer_id']);
  273. $merId = $params['mer_id'] ?? 0;
  274. [$page, $limit] = $this->getPage();
  275. $where = request()->only(['keyword']);
  276. $where['is_gift_bag'] = 0;
  277. $where['is_used'] = 1;
  278. $where['product_type'] = 0;
  279. $where['is_hide'] = 0;
  280. $result = $this->repository->productList($merId, $where, $page, $limit, $this->userInfo);
  281. $formatList = [];
  282. foreach ($result['list'] as $productInfo) {
  283. $formatList[] = [
  284. 'type' => 0,//京东商品
  285. 'merId' => $productInfo['mer_id'],
  286. 'skuId' => '',//itemId 京东官方 已不返回skuId , 使用 联盟商品ID 代替skuId
  287. 'id' => $productInfo['product_id'] ?? '', //id
  288. 'name' => $productInfo['store_name'],//名称
  289. 'thumb' => $productInfo['image'] ?? '',//商品缩略图
  290. 'pv' => $productInfo['pv'],//PV金额
  291. 'gongxian' => $productInfo['gongxian'],
  292. 'jifen' => $productInfo['jifen'],
  293. 'yanglaojin' => $productInfo['yanglao'],
  294. 'commission' => $productInfo['concession_pri'],//佣金
  295. 'commission_rate' => null,//佣金比例
  296. 'coupon_money' => [],
  297. 'coupon_link' => '',
  298. 'lowestCouponPrice' => $productInfo['price'],
  299. 'price' => $productInfo['ot_price'], //价格
  300. 'imageList' => $productInfo['slider_image'], //图片合集
  301. 'materialUrl' => ''
  302. ];
  303. }
  304. return app('json')->success($formatList);
  305. }
  306. /**
  307. * 商贸区店铺商品列表
  308. * @return mixed
  309. * @throws \think\db\exception\DataNotFoundException
  310. * @throws \think\db\exception\DbException
  311. * @throws \think\db\exception\ModelNotFoundException
  312. */
  313. public function commerceProductList()
  314. {
  315. $params= $this->request->params(['pageNum','pageSize','category_id']);
  316. $mer_id_unset = [496,486,439,148,491];
  317. $domain = $this->request->domain();
  318. if(strpos($domain, 'test.hebeiyhc.com') !== false) {
  319. // 域名中包含 "test.hebeiyhc.com'" 字符串
  320. array_push($mer_id_unset, 486);
  321. }else{
  322. array_push($mer_id_unset, 497);
  323. }
  324. $is_commercetrade = 1;
  325. [$page, $limit] = $this->getPage();
  326. if($params['pageNum']!=''){
  327. $page=$params['pageNum'];
  328. }
  329. if($params['pageSize']!=''){
  330. $limit=$params['pageSize'];
  331. }
  332. $category_id = $params['category_id']?:0;
  333. $where['is_del'] = 0;
  334. $where['status'] = 1;
  335. $category_id && $where['category_id'] = $category_id;
  336. $hasProductMerIdList = Db::name('store_product')
  337. ->where('status', '=', 1)
  338. ->where('is_show', '=', 1)
  339. ->where('is_del', '=', 0)
  340. ->group('mer_id')
  341. ->field('mer_id')
  342. ->select();
  343. if ($hasProductMerIdList) {
  344. $hasProductMerIdList = array_column($hasProductMerIdList->toArray(), 'mer_id');
  345. }
  346. $query = Db::name('merchant')->where($where);
  347. if (!empty($hasProductMerIdList) && is_array($hasProductMerIdList)) {
  348. $query->whereIn('mer_id', $hasProductMerIdList);
  349. }
  350. $mer_list = $query->page($page)->limit($limit)->select();
  351. $where['is_gift_bag'] = 0;
  352. $where['is_used'] = 1;
  353. $where['product_type'] = 0;
  354. $where['is_hide'] = 0;
  355. $return_list = [];
  356. if($mer_list) {
  357. $mer_list = $mer_list->toArray();
  358. foreach ($mer_list as $mer) {
  359. if(in_array($mer['mer_id'],$mer_id_unset)) continue;
  360. $goods = $this->repository->productList($mer['mer_id'],$where, 1, 3,$this->userInfo,false,$is_commercetrade);
  361. if(empty($goods['list'])) continue;
  362. $mer['goods_list'] = $goods['list'];
  363. if (mb_strlen($mer['mer_name']) > 8) {
  364. $mer['mer_name'] = mb_substr($mer['mer_name'], 0, 8) . '...';
  365. }
  366. $return_list[] = $mer;
  367. }
  368. }
  369. return app('json')->success(['list'=>$return_list]);
  370. }
  371. /**
  372. * 查询代理人商品
  373. * @param $type
  374. * @return mixed
  375. */
  376. public function areaProductList()
  377. {
  378. [$page, $limit] = $this->getPage();
  379. $where = $this->request->params(['keyword','order','mer_cate_id','price_on', 'price_off','brand_id']);
  380. $where['is_gift_bag'] = 0;
  381. $where['is_used'] = 1;
  382. $where['product_type'] = 0;
  383. $where['is_hide'] = 0;
  384. $type = $this->request->param('type');
  385. Log::info('查询代理人商品请求参数,type:'.$type);
  386. $type = $type == 'district' ? 13 : ($type == 'town' ? 12 : ($type == 'village' ? 11 : -1));
  387. // $where['web_type'] = $type;
  388. $id = 324;
  389. $data = $this->repository->productList($id,$where, $page, $limit,$this->userInfo);
  390. Log::info('查询代理人商品返回'.json_encode($data,true));
  391. return app('json')->success($data);
  392. }
  393. /**
  394. * @Author:Qinii
  395. * @Date: 2020/5/29
  396. * @param int $id
  397. * @return mixed
  398. */
  399. public function categoryList($id)
  400. {
  401. if(!$this->repository->merExists($id))
  402. return app('json')->fail('店铺不存在');
  403. return app('json')->success($this->repository->categoryList($id));
  404. }
  405. public function qrcode($id)
  406. {
  407. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  408. if(!$mer)
  409. return app('json')->fail('店铺不存在');
  410. $type = $this->request->param('type');
  411. $is_payment = $this->request->param('is_payment', 0);
  412. switch ($type) {
  413. case 'routine':
  414. if ($is_payment) {
  415. $url = $this->repository->routineQrcode(intval($id), '/h5payment/index.html','_store_routine_payment.jpg');
  416. } else {
  417. $url = $this->repository->routineQrcode(intval($id));
  418. }
  419. break;
  420. default:
  421. if ($is_payment) {
  422. $url = $this->repository->wxQrcode(intval($id), '/h5payment/index.html', '_store_wap_payment.jpg', $mer->mer_avatar);
  423. } else {
  424. $url = $this->repository->wxQrcode(intval($id));
  425. }
  426. }
  427. return app('json')->success(compact('url'));
  428. }
  429. public function payQrCode($id){
  430. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  431. if(!$mer)
  432. return app('json')->fail('店铺不存在');
  433. $res = $this -> repository -> getQrCode($mer);
  434. return app('json') -> success($res);
  435. }
  436. /**
  437. * @Date: 2020/10/10
  438. * 店铺列表 :首页 最多十个
  439. * @return mixed
  440. */
  441. public function listindex()
  442. {
  443. // [$page, $limit] = $this->getPage();
  444. $page=input("page/d",1);
  445. $limit=input("limit/d",10);
  446. $keyword=input("keyword","");
  447. $order=input("order",0);
  448. $type=input("type",2);
  449. $lat=input("lat",1);
  450. $lng=input("lng",1);
  451. $data=[
  452. "lat"=>$lat,
  453. "lng"=>$lng,
  454. "keyword"=>$keyword,
  455. "order"=>$order
  456. ];
  457. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  458. }
  459. /**
  460. * @Date: 2020/10/10
  461. * 店铺列表:
  462. * @param $keyword //搜索
  463. * @param $order //排序
  464. * @param $category_id //分类id
  465. * @return mixed
  466. */
  467. public function list()
  468. {
  469. $category_id=input("category_id",0);
  470. $page=input("page/d",1);
  471. $limit=input("limit/d",10);
  472. $keyword=input("keyword","");
  473. $order=input("order",0);
  474. $type=input("type",0);
  475. $lat=input("lat",'113.643636');
  476. $lng=input("lng",'34.73841');
  477. $city_name=input("city_name",'');
  478. if ($type==2){
  479. $data=[
  480. "lat"=>empty($lat)?"113.643636":$lat,
  481. "lng"=>empty($lng)?"34.73841":$lng,
  482. "keyword"=>$keyword,
  483. "order"=>$order
  484. ];
  485. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  486. }
  487. $where=[];
  488. if ($category_id){
  489. $where["category_id"]=$category_id;
  490. }
  491. $data=[
  492. "lat"=>empty($lat)?"34.73841":$lat,
  493. "lng"=>empty($lng)?"113.643636":$lng,
  494. ];
  495. if ($city_name){
  496. $data["city_name"]=$city_name;
  497. }
  498. return app('json')->success($this->repository->getLists($data,1,10,1,$where));
  499. // return app('json')->success(['count'=>0,'list'=>[],'where'=>[]]);
  500. }
  501. /**
  502. * @Date: 2020/10/10
  503. * 店铺分类
  504. */
  505. public function merchantcategory()
  506. {
  507. [$page, $limit] = $this->getPage();
  508. return app('json')->success($this->repository->merchantcategory());
  509. }
  510. /**
  511. * 附近页面商家分类
  512. * @day 2020/10/30
  513. */
  514. public function mercat()
  515. {
  516. [$page, $limit] = $this->getPage();
  517. return app('json')->success($this->repository->mercat($page, $limit));
  518. }
  519. /*
  520. *分类下的商家列表
  521. * @author cabbage
  522. * @day 2020/10/30
  523. * */
  524. public function mercatStore(){
  525. [$page, $limit] = $this->getPage();
  526. $data = $this->request->params([
  527. 'order', //人气
  528. 'distance', //距离
  529. 'lat', //经度
  530. 'lng', //纬度
  531. 'user_id'
  532. ]);
  533. $where = $this->request->params([
  534. 'category_id', //商铺分类id
  535. 'keyword', //商铺名称
  536. ]);
  537. return app('json')->success($this->repository->getLst($data,$page,$limit,$where));
  538. // return app('json')->success([]);
  539. }
  540. /**
  541. * @param $id
  542. * @return mixed
  543. * @throws \think\db\exception\DbException
  544. * 店铺置顶
  545. */
  546. public function shop_topping($id)
  547. {
  548. if($id!=0){
  549. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>$id]);
  550. if($res!==false)
  551. $message='置顶成功';
  552. else
  553. $message='置顶失败';
  554. return app('json')->success($message);
  555. }else{
  556. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>0]);
  557. if($res!==false)
  558. $message='取消置顶成功';
  559. else
  560. $message='取消置顶失败';
  561. return app('json')->success($message);
  562. }
  563. }
  564. /**
  565. * @param $id
  566. * @return mixed
  567. * @throws \think\db\exception\DbException
  568. * 店铺点赞 or 店铺取消点赞
  569. */
  570. public function shop_fabulous($id)
  571. {
  572. $uid=$this->request->uid();
  573. $user_like=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->value('status');
  574. if($user_like=='0'){
  575. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>1]);
  576. if($res!==false)
  577. $message='点赞成功';
  578. else
  579. $message='点赞失败';
  580. }elseif ($user_like=='1'){
  581. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>0]);
  582. if($res!==false)
  583. $message='取消点赞成功';
  584. else
  585. $message='取消点赞失败';
  586. }else{
  587. $inser_data=[
  588. 'uid'=>$uid,
  589. 'mer_id'=>$id,
  590. 'ctime'=>time(),
  591. 'status'=>1
  592. ];
  593. $res=Db::name('store_fabulous')->insert($inser_data);
  594. if($res!==false)
  595. $message='点赞成功';
  596. else
  597. $message='点赞失败';
  598. }
  599. return app('json')->success($message);
  600. }
  601. }