Merchant.php 25 KB

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