Merchant.php 24 KB

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