Merchant.php 24 KB

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