Merchant.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. }
  111. [$page, $limit] = $this->getPage();
  112. if($params['pageNum']!=''){
  113. $page=$params['pageNum'];
  114. }
  115. if($params['pageSize']!=''){
  116. $limit=$params['pageSize'];
  117. }
  118. $where = $this->request->params(['keyword','order','mer_cate_id', 'cate_id','price_on', 'price_off','brand_id']);
  119. $where['is_gift_bag'] = 0;
  120. $where['is_used'] = 1;
  121. $where['product_type'] = 0;
  122. $where['is_hide'] = 0;
  123. // log::info("====={$params['mer_cate_id']}===");
  124. if($params['mer_cate_id']){
  125. $where['cate_id'] = $params['mer_cate_id'];
  126. }
  127. return app('json')->success($this->repository->productList($id,$where, $page, $limit,$this->userInfo,$type439,$is_commercetrade));
  128. }
  129. /**
  130. * 获取商户上架的商品列表
  131. * @return mixed
  132. */
  133. public function getProductList()
  134. {
  135. $params = request()->only(['pageNum', 'pageSize', 'mer_id']);
  136. $merId = $params['mer_id'] ?? 0;
  137. [$page, $limit] = $this->getPage();
  138. $where = request()->only(['keyword']);
  139. $where['is_gift_bag'] = 0;
  140. $where['is_used'] = 1;
  141. $where['product_type'] = 0;
  142. $where['is_hide'] = 0;
  143. $result = $this->repository->productList($merId, $where, $page, $limit, $this->userInfo);
  144. $formatList = [];
  145. foreach ($result['list'] as $productInfo) {
  146. $formatList[] = [
  147. 'type' => 0,//京东商品
  148. 'merId' => $productInfo['mer_id'],
  149. 'skuId' => '',//itemId 京东官方 已不返回skuId , 使用 联盟商品ID 代替skuId
  150. 'id' => $productInfo['product_id'] ?? '', //id
  151. 'name' => $productInfo['store_name'],//名称
  152. 'thumb' => $productInfo['image'] ?? '',//商品缩略图
  153. 'pv' => $productInfo['pv'],//PV金额
  154. 'gongxian' => $productInfo['gongxian'],
  155. 'jifen' => $productInfo['jifen'],
  156. 'yanglaojin' => $productInfo['yanglao'],
  157. 'commission' => $productInfo['concession_pri'],//佣金
  158. 'commission_rate' => null,//佣金比例
  159. 'coupon_money' => [],
  160. 'coupon_link' => '',
  161. 'lowestCouponPrice' => $productInfo['price'],
  162. 'price' => $productInfo['ot_price'], //价格
  163. 'imageList' => $productInfo['slider_image'], //图片合集
  164. 'materialUrl' => ''
  165. ];
  166. }
  167. return app('json')->success($formatList);
  168. }
  169. /**
  170. * 商贸区店铺商品列表
  171. * @return mixed
  172. * @throws \think\db\exception\DataNotFoundException
  173. * @throws \think\db\exception\DbException
  174. * @throws \think\db\exception\ModelNotFoundException
  175. */
  176. public function commerceProductList()
  177. {
  178. $params= $this->request->params(['pageNum','pageSize','category_id']);
  179. $mer_id_unset = [496,486,439,148,491];
  180. $domain = $this->request->domain();
  181. if(strpos($domain, 'test.hebeiyhc.com') !== false) {
  182. // 域名中包含 "test.hebeiyhc.com'" 字符串
  183. array_push($mer_id_unset, 486);
  184. }else{
  185. array_push($mer_id_unset, 497);
  186. }
  187. $is_commercetrade = 1;
  188. [$page, $limit] = $this->getPage();
  189. if($params['pageNum']!=''){
  190. $page=$params['pageNum'];
  191. }
  192. if($params['pageSize']!=''){
  193. $limit=$params['pageSize'];
  194. }
  195. $category_id = $params['category_id']?:0;
  196. $where['is_del'] = 0;
  197. $where['status'] = 1;
  198. $category_id && $where['category_id'] = $category_id;
  199. $hasProductMerIdList = Db::name('store_product')
  200. ->where('status', '=', 1)
  201. ->where('is_show', '=', 1)
  202. ->where('is_del', '=', 0)
  203. ->group('mer_id')
  204. ->field('mer_id')
  205. ->select();
  206. if ($hasProductMerIdList) {
  207. $hasProductMerIdList = array_column($hasProductMerIdList->toArray(), 'mer_id');
  208. }
  209. $query = Db::name('merchant')->where($where);
  210. if (!empty($hasProductMerIdList) && is_array($hasProductMerIdList)) {
  211. $query->whereIn('mer_id', $hasProductMerIdList);
  212. }
  213. $mer_list = $query->page($page)->limit($limit)->select();
  214. $where['is_gift_bag'] = 0;
  215. $where['is_used'] = 1;
  216. $where['product_type'] = 0;
  217. $where['is_hide'] = 0;
  218. $return_list = [];
  219. if($mer_list) {
  220. $mer_list = $mer_list->toArray();
  221. foreach ($mer_list as $mer) {
  222. if(in_array($mer['mer_id'],$mer_id_unset)) continue;
  223. $goods = $this->repository->productList($mer['mer_id'],$where, 1, 3,$this->userInfo,false,$is_commercetrade);
  224. if(empty($goods['list'])) continue;
  225. $mer['goods_list'] = $goods['list'];
  226. if (mb_strlen($mer['mer_name']) > 8) {
  227. $mer['mer_name'] = mb_substr($mer['mer_name'], 0, 8) . '...';
  228. }
  229. $return_list[] = $mer;
  230. }
  231. }
  232. return app('json')->success(['list'=>$return_list]);
  233. }
  234. /**
  235. * 查询代理人商品
  236. * @param $type
  237. * @return mixed
  238. */
  239. public function areaProductList()
  240. {
  241. [$page, $limit] = $this->getPage();
  242. $where = $this->request->params(['keyword','order','mer_cate_id','price_on', 'price_off','brand_id']);
  243. $where['is_gift_bag'] = 0;
  244. $where['is_used'] = 1;
  245. $where['product_type'] = 0;
  246. $where['is_hide'] = 0;
  247. $type = $this->request->param('type');
  248. Log::info('查询代理人商品请求参数,type:'.$type);
  249. $type = $type == 'district' ? 13 : ($type == 'town' ? 12 : ($type == 'village' ? 11 : -1));
  250. // $where['web_type'] = $type;
  251. $id = 324;
  252. $data = $this->repository->productList($id,$where, $page, $limit,$this->userInfo);
  253. Log::info('查询代理人商品返回'.json_encode($data,true));
  254. return app('json')->success($data);
  255. }
  256. /**
  257. * @Author:Qinii
  258. * @Date: 2020/5/29
  259. * @param int $id
  260. * @return mixed
  261. */
  262. public function categoryList($id)
  263. {
  264. if(!$this->repository->merExists($id))
  265. return app('json')->fail('店铺不存在');
  266. return app('json')->success($this->repository->categoryList($id));
  267. }
  268. public function qrcode($id)
  269. {
  270. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  271. if(!$mer)
  272. return app('json')->fail('店铺不存在');
  273. $type = $this->request->param('type');
  274. $is_payment = $this->request->param('is_payment', 0);
  275. switch ($type) {
  276. case 'routine':
  277. if ($is_payment) {
  278. $url = $this->repository->routineQrcode(intval($id), '/h5payment/index.html','_store_routine_payment.jpg');
  279. } else {
  280. $url = $this->repository->routineQrcode(intval($id));
  281. }
  282. break;
  283. default:
  284. if ($is_payment) {
  285. $url = $this->repository->wxQrcode(intval($id), '/h5payment/index.html', '_store_wap_payment.jpg', $mer->mer_avatar);
  286. } else {
  287. $url = $this->repository->wxQrcode(intval($id));
  288. }
  289. }
  290. return app('json')->success(compact('url'));
  291. }
  292. public function payQrCode($id){
  293. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  294. if(!$mer)
  295. return app('json')->fail('店铺不存在');
  296. $res = $this -> repository -> getQrCode($mer);
  297. return app('json') -> success($res);
  298. }
  299. /**
  300. * @Date: 2020/10/10
  301. * 店铺列表 :首页 最多十个
  302. * @return mixed
  303. */
  304. public function listindex()
  305. {
  306. // [$page, $limit] = $this->getPage();
  307. $page=input("page/d",1);
  308. $limit=input("limit/d",10);
  309. $keyword=input("keyword","");
  310. $order=input("order",0);
  311. $type=input("type",2);
  312. $lat=input("lat",1);
  313. $lng=input("lng",1);
  314. $data=[
  315. "lat"=>$lat,
  316. "lng"=>$lng,
  317. "keyword"=>$keyword,
  318. "order"=>$order
  319. ];
  320. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  321. }
  322. /**
  323. * @Date: 2020/10/10
  324. * 店铺列表:
  325. * @param $keyword //搜索
  326. * @param $order //排序
  327. * @param $category_id //分类id
  328. * @return mixed
  329. */
  330. public function list()
  331. {
  332. $category_id=input("category_id",0);
  333. $page=input("page/d",1);
  334. $limit=input("limit/d",10);
  335. $keyword=input("keyword","");
  336. $order=input("order",0);
  337. $type=input("type",0);
  338. $lat=input("lat",'113.643636');
  339. $lng=input("lng",'34.73841');
  340. $city_name=input("city_name",'');
  341. if ($type==2){
  342. $data=[
  343. "lat"=>empty($lat)?"113.643636":$lat,
  344. "lng"=>empty($lng)?"34.73841":$lng,
  345. "keyword"=>$keyword,
  346. "order"=>$order
  347. ];
  348. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  349. }
  350. $where=[];
  351. if ($category_id){
  352. $where["category_id"]=$category_id;
  353. }
  354. $data=[
  355. "lat"=>empty($lat)?"34.73841":$lat,
  356. "lng"=>empty($lng)?"113.643636":$lng,
  357. ];
  358. if ($city_name){
  359. $data["city_name"]=$city_name;
  360. }
  361. return app('json')->success($this->repository->getLists($data,1,10,1,$where));
  362. // return app('json')->success(['count'=>0,'list'=>[],'where'=>[]]);
  363. }
  364. /**
  365. * @Date: 2020/10/10
  366. * 店铺分类
  367. */
  368. public function merchantcategory()
  369. {
  370. [$page, $limit] = $this->getPage();
  371. return app('json')->success($this->repository->merchantcategory());
  372. }
  373. /**
  374. * 附近页面商家分类
  375. * @day 2020/10/30
  376. */
  377. public function mercat()
  378. {
  379. [$page, $limit] = $this->getPage();
  380. return app('json')->success($this->repository->mercat($page, $limit));
  381. }
  382. /*
  383. *分类下的商家列表
  384. * @author cabbage
  385. * @day 2020/10/30
  386. * */
  387. public function mercatStore(){
  388. [$page, $limit] = $this->getPage();
  389. $data = $this->request->params([
  390. 'order', //人气
  391. 'distance', //距离
  392. 'lat', //经度
  393. 'lng', //纬度
  394. 'user_id'
  395. ]);
  396. $where = $this->request->params([
  397. 'category_id', //商铺分类id
  398. 'keyword', //商铺名称
  399. ]);
  400. return app('json')->success($this->repository->getLst($data,$page,$limit,$where));
  401. // return app('json')->success([]);
  402. }
  403. /**
  404. * @param $id
  405. * @return mixed
  406. * @throws \think\db\exception\DbException
  407. * 店铺置顶
  408. */
  409. public function shop_topping($id)
  410. {
  411. if($id!=0){
  412. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>$id]);
  413. if($res!==false)
  414. $message='置顶成功';
  415. else
  416. $message='置顶失败';
  417. return app('json')->success($message);
  418. }else{
  419. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>0]);
  420. if($res!==false)
  421. $message='取消置顶成功';
  422. else
  423. $message='取消置顶失败';
  424. return app('json')->success($message);
  425. }
  426. }
  427. /**
  428. * @param $id
  429. * @return mixed
  430. * @throws \think\db\exception\DbException
  431. * 店铺点赞 or 店铺取消点赞
  432. */
  433. public function shop_fabulous($id)
  434. {
  435. $uid=$this->request->uid();
  436. $user_like=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->value('status');
  437. if($user_like=='0'){
  438. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>1]);
  439. if($res!==false)
  440. $message='点赞成功';
  441. else
  442. $message='点赞失败';
  443. }elseif ($user_like=='1'){
  444. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>0]);
  445. if($res!==false)
  446. $message='取消点赞成功';
  447. else
  448. $message='取消点赞失败';
  449. }else{
  450. $inser_data=[
  451. 'uid'=>$uid,
  452. 'mer_id'=>$id,
  453. 'ctime'=>time(),
  454. 'status'=>1
  455. ];
  456. $res=Db::name('store_fabulous')->insert($inser_data);
  457. if($res!==false)
  458. $message='点赞成功';
  459. else
  460. $message='点赞失败';
  461. }
  462. return app('json')->success($message);
  463. }
  464. }