Merchant.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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, $limit);
  240. if ($actualMixCount > 0) {
  241. $matchList = array_slice($matchList, 0, $actualMixCount);
  242. // 随机选择要移除的商品位置
  243. $removeKeys = array_rand($result['list'], $actualMixCount);
  244. if (!is_array($removeKeys)) {
  245. $removeKeys = [$removeKeys];
  246. }
  247. // 从大到小排序,避免删除时索引错乱
  248. rsort($removeKeys);
  249. foreach ($removeKeys as $rk) {
  250. array_splice($result['list'], $rk, 1);
  251. }
  252. // 随机插入推荐商品
  253. foreach ($matchList as $ml) {
  254. $insertPos = rand(0, count($result['list']));
  255. array_splice($result['list'], $insertPos, 0, [$ml]);
  256. }
  257. }
  258. }
  259. }
  260. }
  261. } catch (\Throwable $e) {
  262. Log::info('productTypeList 混入推荐商品失败: ' . $e->getMessage());
  263. }
  264. }
  265. // ===== 混入推荐商品逻辑结束 =====
  266. return app('json')->success($result);
  267. }
  268. /**
  269. * 获取商户上架的商品列表
  270. * @return mixed
  271. */
  272. public function getProductList()
  273. {
  274. $params = request()->only(['pageNum', 'pageSize', 'mer_id']);
  275. $merId = $params['mer_id'] ?? 0;
  276. [$page, $limit] = $this->getPage();
  277. $where = request()->only(['keyword']);
  278. $where['is_gift_bag'] = 0;
  279. $where['is_used'] = 1;
  280. $where['product_type'] = 0;
  281. $where['is_hide'] = 0;
  282. $result = $this->repository->productList($merId, $where, $page, $limit, $this->userInfo);
  283. $formatList = [];
  284. foreach ($result['list'] as $productInfo) {
  285. $formatList[] = [
  286. 'type' => 0,//京东商品
  287. 'merId' => $productInfo['mer_id'],
  288. 'skuId' => '',//itemId 京东官方 已不返回skuId , 使用 联盟商品ID 代替skuId
  289. 'id' => $productInfo['product_id'] ?? '', //id
  290. 'name' => $productInfo['store_name'],//名称
  291. 'thumb' => $productInfo['image'] ?? '',//商品缩略图
  292. 'pv' => $productInfo['pv'],//PV金额
  293. 'gongxian' => $productInfo['gongxian'],
  294. 'jifen' => $productInfo['jifen'],
  295. 'yanglaojin' => $productInfo['yanglao'],
  296. 'commission' => $productInfo['concession_pri'],//佣金
  297. 'commission_rate' => null,//佣金比例
  298. 'coupon_money' => [],
  299. 'coupon_link' => '',
  300. 'lowestCouponPrice' => $productInfo['price'],
  301. 'price' => $productInfo['ot_price'], //价格
  302. 'imageList' => $productInfo['slider_image'], //图片合集
  303. 'materialUrl' => ''
  304. ];
  305. }
  306. return app('json')->success($formatList);
  307. }
  308. /**
  309. * 商贸区店铺商品列表
  310. * @return mixed
  311. * @throws \think\db\exception\DataNotFoundException
  312. * @throws \think\db\exception\DbException
  313. * @throws \think\db\exception\ModelNotFoundException
  314. */
  315. public function commerceProductList()
  316. {
  317. $params= $this->request->params(['pageNum','pageSize','category_id']);
  318. $mer_id_unset = [496,486,439,148,491];
  319. $domain = $this->request->domain();
  320. if(strpos($domain, 'test.hebeiyhc.com') !== false) {
  321. // 域名中包含 "test.hebeiyhc.com'" 字符串
  322. array_push($mer_id_unset, 486);
  323. }else{
  324. array_push($mer_id_unset, 497);
  325. }
  326. $is_commercetrade = 1;
  327. [$page, $limit] = $this->getPage();
  328. if($params['pageNum']!=''){
  329. $page=$params['pageNum'];
  330. }
  331. if($params['pageSize']!=''){
  332. $limit=$params['pageSize'];
  333. }
  334. $category_id = $params['category_id']?:0;
  335. $where['is_del'] = 0;
  336. $where['status'] = 1;
  337. $category_id && $where['category_id'] = $category_id;
  338. $hasProductMerIdList = Db::name('store_product')
  339. ->where('status', '=', 1)
  340. ->where('is_show', '=', 1)
  341. ->where('is_del', '=', 0)
  342. ->group('mer_id')
  343. ->field('mer_id')
  344. ->select();
  345. if ($hasProductMerIdList) {
  346. $hasProductMerIdList = array_column($hasProductMerIdList->toArray(), 'mer_id');
  347. }
  348. $query = Db::name('merchant')->where($where);
  349. if (!empty($hasProductMerIdList) && is_array($hasProductMerIdList)) {
  350. $query->whereIn('mer_id', $hasProductMerIdList);
  351. }
  352. $mer_list = $query->page($page)->limit($limit)->select();
  353. $where['is_gift_bag'] = 0;
  354. $where['is_used'] = 1;
  355. $where['product_type'] = 0;
  356. $where['is_hide'] = 0;
  357. $return_list = [];
  358. if($mer_list) {
  359. $mer_list = $mer_list->toArray();
  360. foreach ($mer_list as $mer) {
  361. if(in_array($mer['mer_id'],$mer_id_unset)) continue;
  362. $goods = $this->repository->productList($mer['mer_id'],$where, 1, 3,$this->userInfo,false,$is_commercetrade);
  363. if(empty($goods['list'])) continue;
  364. $mer['goods_list'] = $goods['list'];
  365. if (mb_strlen($mer['mer_name']) > 8) {
  366. $mer['mer_name'] = mb_substr($mer['mer_name'], 0, 8) . '...';
  367. }
  368. $return_list[] = $mer;
  369. }
  370. }
  371. return app('json')->success(['list'=>$return_list]);
  372. }
  373. /**
  374. * 查询代理人商品
  375. * @param $type
  376. * @return mixed
  377. */
  378. public function areaProductList()
  379. {
  380. [$page, $limit] = $this->getPage();
  381. $where = $this->request->params(['keyword','order','mer_cate_id','price_on', 'price_off','brand_id']);
  382. $where['is_gift_bag'] = 0;
  383. $where['is_used'] = 1;
  384. $where['product_type'] = 0;
  385. $where['is_hide'] = 0;
  386. $type = $this->request->param('type');
  387. Log::info('查询代理人商品请求参数,type:'.$type);
  388. $type = $type == 'district' ? 13 : ($type == 'town' ? 12 : ($type == 'village' ? 11 : -1));
  389. // $where['web_type'] = $type;
  390. $id = 324;
  391. $data = $this->repository->productList($id,$where, $page, $limit,$this->userInfo);
  392. Log::info('查询代理人商品返回'.json_encode($data,true));
  393. return app('json')->success($data);
  394. }
  395. /**
  396. * @Author:Qinii
  397. * @Date: 2020/5/29
  398. * @param int $id
  399. * @return mixed
  400. */
  401. public function categoryList($id)
  402. {
  403. if(!$this->repository->merExists($id))
  404. return app('json')->fail('店铺不存在');
  405. return app('json')->success($this->repository->categoryList($id));
  406. }
  407. public function qrcode($id)
  408. {
  409. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  410. if(!$mer)
  411. return app('json')->fail('店铺不存在');
  412. $type = $this->request->param('type');
  413. $is_payment = $this->request->param('is_payment', 0);
  414. switch ($type) {
  415. case 'routine':
  416. if ($is_payment) {
  417. $url = $this->repository->routineQrcode(intval($id), '/h5payment/index.html','_store_routine_payment.jpg');
  418. } else {
  419. $url = $this->repository->routineQrcode(intval($id));
  420. }
  421. break;
  422. default:
  423. if ($is_payment) {
  424. $url = $this->repository->wxQrcode(intval($id), '/h5payment/index.html', '_store_wap_payment.jpg', $mer->mer_avatar);
  425. } else {
  426. $url = $this->repository->wxQrcode(intval($id));
  427. }
  428. }
  429. return app('json')->success(compact('url'));
  430. }
  431. public function payQrCode($id){
  432. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  433. if(!$mer)
  434. return app('json')->fail('店铺不存在');
  435. $res = $this -> repository -> getQrCode($mer);
  436. return app('json') -> success($res);
  437. }
  438. /**
  439. * @Date: 2020/10/10
  440. * 店铺列表 :首页 最多十个
  441. * @return mixed
  442. */
  443. public function listindex()
  444. {
  445. // [$page, $limit] = $this->getPage();
  446. $page=input("page/d",1);
  447. $limit=input("limit/d",10);
  448. $keyword=input("keyword","");
  449. $order=input("order",0);
  450. $type=input("type",2);
  451. $lat=input("lat",1);
  452. $lng=input("lng",1);
  453. $data=[
  454. "lat"=>$lat,
  455. "lng"=>$lng,
  456. "keyword"=>$keyword,
  457. "order"=>$order
  458. ];
  459. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  460. }
  461. /**
  462. * @Date: 2020/10/10
  463. * 店铺列表:
  464. * @param $keyword //搜索
  465. * @param $order //排序
  466. * @param $category_id //分类id
  467. * @return mixed
  468. */
  469. public function list()
  470. {
  471. $category_id=input("category_id",0);
  472. $page=input("page/d",1);
  473. $limit=input("limit/d",10);
  474. $keyword=input("keyword","");
  475. $order=input("order",0);
  476. $type=input("type",0);
  477. $lat=input("lat",'113.643636');
  478. $lng=input("lng",'34.73841');
  479. $city_name=input("city_name",'');
  480. if ($type==2){
  481. $data=[
  482. "lat"=>empty($lat)?"113.643636":$lat,
  483. "lng"=>empty($lng)?"34.73841":$lng,
  484. "keyword"=>$keyword,
  485. "order"=>$order
  486. ];
  487. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  488. }
  489. $where=[];
  490. if ($category_id){
  491. $where["category_id"]=$category_id;
  492. }
  493. $data=[
  494. "lat"=>empty($lat)?"34.73841":$lat,
  495. "lng"=>empty($lng)?"113.643636":$lng,
  496. ];
  497. if ($city_name){
  498. $data["city_name"]=$city_name;
  499. }
  500. return app('json')->success($this->repository->getLists($data,1,10,1,$where));
  501. // return app('json')->success(['count'=>0,'list'=>[],'where'=>[]]);
  502. }
  503. /**
  504. * @Date: 2020/10/10
  505. * 店铺分类
  506. */
  507. public function merchantcategory()
  508. {
  509. [$page, $limit] = $this->getPage();
  510. return app('json')->success($this->repository->merchantcategory());
  511. }
  512. /**
  513. * 附近页面商家分类
  514. * @day 2020/10/30
  515. */
  516. public function mercat()
  517. {
  518. [$page, $limit] = $this->getPage();
  519. return app('json')->success($this->repository->mercat($page, $limit));
  520. }
  521. /*
  522. *分类下的商家列表
  523. * @author cabbage
  524. * @day 2020/10/30
  525. * */
  526. public function mercatStore(){
  527. [$page, $limit] = $this->getPage();
  528. $data = $this->request->params([
  529. 'order', //人气
  530. 'distance', //距离
  531. 'lat', //经度
  532. 'lng', //纬度
  533. 'user_id'
  534. ]);
  535. $where = $this->request->params([
  536. 'category_id', //商铺分类id
  537. 'keyword', //商铺名称
  538. ]);
  539. return app('json')->success($this->repository->getLst($data,$page,$limit,$where));
  540. // return app('json')->success([]);
  541. }
  542. /**
  543. * @param $id
  544. * @return mixed
  545. * @throws \think\db\exception\DbException
  546. * 店铺置顶
  547. */
  548. public function shop_topping($id)
  549. {
  550. if($id!=0){
  551. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>$id]);
  552. if($res!==false)
  553. $message='置顶成功';
  554. else
  555. $message='置顶失败';
  556. return app('json')->success($message);
  557. }else{
  558. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>0]);
  559. if($res!==false)
  560. $message='取消置顶成功';
  561. else
  562. $message='取消置顶失败';
  563. return app('json')->success($message);
  564. }
  565. }
  566. /**
  567. * @param $id
  568. * @return mixed
  569. * @throws \think\db\exception\DbException
  570. * 店铺点赞 or 店铺取消点赞
  571. */
  572. public function shop_fabulous($id)
  573. {
  574. $uid=$this->request->uid();
  575. $user_like=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->value('status');
  576. if($user_like=='0'){
  577. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>1]);
  578. if($res!==false)
  579. $message='点赞成功';
  580. else
  581. $message='点赞失败';
  582. }elseif ($user_like=='1'){
  583. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>0]);
  584. if($res!==false)
  585. $message='取消点赞成功';
  586. else
  587. $message='取消点赞失败';
  588. }else{
  589. $inser_data=[
  590. 'uid'=>$uid,
  591. 'mer_id'=>$id,
  592. 'ctime'=>time(),
  593. 'status'=>1
  594. ];
  595. $res=Db::name('store_fabulous')->insert($inser_data);
  596. if($res!==false)
  597. $message='点赞成功';
  598. else
  599. $message='点赞失败';
  600. }
  601. return app('json')->success($message);
  602. }
  603. }