Merchant.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. * @throws \think\db\exception\DataNotFoundException
  133. * @throws \think\db\exception\DbException
  134. * @throws \think\db\exception\ModelNotFoundException
  135. */
  136. public function commerceProductList()
  137. {
  138. $params= $this->request->params(['pageNum','pageSize','category_id']);
  139. $mer_id_unset = [496,486,439,148,491];
  140. $domain = $this->request->domain();
  141. if(strpos($domain, 'test.hebeiyhc.com') !== false) {
  142. // 域名中包含 "test.hebeiyhc.com'" 字符串
  143. array_push($mer_id_unset, 486);
  144. }else{
  145. array_push($mer_id_unset, 497);
  146. }
  147. $is_commercetrade = 1;
  148. [$page, $limit] = $this->getPage();
  149. if($params['pageNum']!=''){
  150. $page=$params['pageNum'];
  151. }
  152. if($params['pageSize']!=''){
  153. $limit=$params['pageSize'];
  154. }
  155. $category_id = $params['category_id']?:32;
  156. $mer_list = Db::name('merchant')->where(['category_id' => $category_id,'status' => 1,'is_del' => 0])->page($page)->limit($limit)->select();
  157. $where['is_gift_bag'] = 0;
  158. $where['is_used'] = 1;
  159. $where['product_type'] = 0;
  160. $where['is_hide'] = 0;
  161. $return_list = [];
  162. if($mer_list) {
  163. $mer_list = $mer_list->toArray();
  164. foreach ($mer_list as $mer) {
  165. if(in_array($mer['mer_id'],$mer_id_unset)) continue;
  166. $goods = $this->repository->productList($mer['mer_id'],$where, 1, 3,$this->userInfo,false,$is_commercetrade);
  167. if(empty($goods['list'])) continue;
  168. $mer['goods_list'] = $goods['list'];
  169. $return_list[] = $mer;
  170. }
  171. }
  172. return app('json')->success(['list'=>$return_list]);
  173. }
  174. /**
  175. * 查询代理人商品
  176. * @param $type
  177. * @return mixed
  178. */
  179. public function areaProductList()
  180. {
  181. [$page, $limit] = $this->getPage();
  182. $where = $this->request->params(['keyword','order','mer_cate_id','price_on', 'price_off','brand_id']);
  183. $where['is_gift_bag'] = 0;
  184. $where['is_used'] = 1;
  185. $where['product_type'] = 0;
  186. $where['is_hide'] = 0;
  187. $type = $this->request->param('type');
  188. Log::info('查询代理人商品请求参数,type:'.$type);
  189. $type = $type == 'district' ? 13 : ($type == 'town' ? 12 : ($type == 'village' ? 11 : -1));
  190. // $where['web_type'] = $type;
  191. $id = 324;
  192. $data = $this->repository->productList($id,$where, $page, $limit,$this->userInfo);
  193. Log::info('查询代理人商品返回'.json_encode($data,true));
  194. return app('json')->success($data);
  195. }
  196. /**
  197. * @Author:Qinii
  198. * @Date: 2020/5/29
  199. * @param int $id
  200. * @return mixed
  201. */
  202. public function categoryList($id)
  203. {
  204. if(!$this->repository->merExists($id))
  205. return app('json')->fail('店铺不存在');
  206. return app('json')->success($this->repository->categoryList($id));
  207. }
  208. public function qrcode($id)
  209. {
  210. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  211. if(!$mer)
  212. return app('json')->fail('店铺不存在');
  213. $type = $this->request->param('type');
  214. $is_payment = $this->request->param('is_payment', 0);
  215. switch ($type) {
  216. case 'routine':
  217. if ($is_payment) {
  218. $url = $this->repository->routineQrcode(intval($id), '/h5payment/index.html','_store_routine_payment.jpg');
  219. } else {
  220. $url = $this->repository->routineQrcode(intval($id));
  221. }
  222. break;
  223. default:
  224. if ($is_payment) {
  225. $url = $this->repository->wxQrcode(intval($id), '/h5payment/index.html', '_store_wap_payment.jpg', $mer->mer_avatar);
  226. } else {
  227. $url = $this->repository->wxQrcode(intval($id));
  228. }
  229. }
  230. return app('json')->success(compact('url'));
  231. }
  232. public function payQrCode($id){
  233. $mer = \app\common\model\system\merchant\Merchant::getInstance()->where('mer_id', $id)->find();
  234. if(!$mer)
  235. return app('json')->fail('店铺不存在');
  236. $res = $this -> repository -> getQrCode($mer);
  237. return app('json') -> success($res);
  238. }
  239. /**
  240. * @Date: 2020/10/10
  241. * 店铺列表 :首页 最多十个
  242. * @return mixed
  243. */
  244. public function listindex()
  245. {
  246. // [$page, $limit] = $this->getPage();
  247. $page=input("page/d",1);
  248. $limit=input("limit/d",10);
  249. $keyword=input("keyword","");
  250. $order=input("order",0);
  251. $type=input("type",2);
  252. $lat=input("lat",1);
  253. $lng=input("lng",1);
  254. $data=[
  255. "lat"=>$lat,
  256. "lng"=>$lng,
  257. "keyword"=>$keyword,
  258. "order"=>$order
  259. ];
  260. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  261. }
  262. /**
  263. * @Date: 2020/10/10
  264. * 店铺列表:
  265. * @param $keyword //搜索
  266. * @param $order //排序
  267. * @param $category_id //分类id
  268. * @return mixed
  269. */
  270. public function list()
  271. {
  272. $category_id=input("category_id",0);
  273. $page=input("page/d",1);
  274. $limit=input("limit/d",10);
  275. $keyword=input("keyword","");
  276. $order=input("order",0);
  277. $type=input("type",0);
  278. $lat=input("lat",'113.643636');
  279. $lng=input("lng",'34.73841');
  280. $city_name=input("city_name",'');
  281. if ($type==2){
  282. $data=[
  283. "lat"=>empty($lat)?"113.643636":$lat,
  284. "lng"=>empty($lng)?"34.73841":$lng,
  285. "keyword"=>$keyword,
  286. "order"=>$order
  287. ];
  288. return app('json')->success($this->repository->getLists($data,$page,$limit,$type));
  289. }
  290. $where=[];
  291. if ($category_id){
  292. $where["category_id"]=$category_id;
  293. }
  294. $data=[
  295. "lat"=>empty($lat)?"34.73841":$lat,
  296. "lng"=>empty($lng)?"113.643636":$lng,
  297. ];
  298. if ($city_name){
  299. $data["city_name"]=$city_name;
  300. }
  301. return app('json')->success($this->repository->getLists($data,1,10,1,$where));
  302. // return app('json')->success(['count'=>0,'list'=>[],'where'=>[]]);
  303. }
  304. /**
  305. * @Date: 2020/10/10
  306. * 店铺分类
  307. */
  308. public function merchantcategory()
  309. {
  310. [$page, $limit] = $this->getPage();
  311. return app('json')->success($this->repository->merchantcategory());
  312. }
  313. /**
  314. * 附近页面商家分类
  315. * @day 2020/10/30
  316. */
  317. public function mercat()
  318. {
  319. [$page, $limit] = $this->getPage();
  320. return app('json')->success($this->repository->mercat($page, $limit));
  321. }
  322. /*
  323. *分类下的商家列表
  324. * @author cabbage
  325. * @day 2020/10/30
  326. * */
  327. public function mercatStore(){
  328. [$page, $limit] = $this->getPage();
  329. $data = $this->request->params([
  330. 'order', //人气
  331. 'distance', //距离
  332. 'lat', //经度
  333. 'lng', //纬度
  334. 'user_id'
  335. ]);
  336. $where = $this->request->params([
  337. 'category_id', //商铺分类id
  338. 'keyword', //商铺名称
  339. ]);
  340. return app('json')->success($this->repository->getLst($data,$page,$limit,$where));
  341. // return app('json')->success([]);
  342. }
  343. /**
  344. * @param $id
  345. * @return mixed
  346. * @throws \think\db\exception\DbException
  347. * 店铺置顶
  348. */
  349. public function shop_topping($id)
  350. {
  351. if($id!=0){
  352. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>$id]);
  353. if($res!==false)
  354. $message='置顶成功';
  355. else
  356. $message='置顶失败';
  357. return app('json')->success($message);
  358. }else{
  359. $res=Db::name('user')->where('uid',$this->request->uid())->update(['mer_topping'=>0]);
  360. if($res!==false)
  361. $message='取消置顶成功';
  362. else
  363. $message='取消置顶失败';
  364. return app('json')->success($message);
  365. }
  366. }
  367. /**
  368. * @param $id
  369. * @return mixed
  370. * @throws \think\db\exception\DbException
  371. * 店铺点赞 or 店铺取消点赞
  372. */
  373. public function shop_fabulous($id)
  374. {
  375. $uid=$this->request->uid();
  376. $user_like=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->value('status');
  377. if($user_like=='0'){
  378. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>1]);
  379. if($res!==false)
  380. $message='点赞成功';
  381. else
  382. $message='点赞失败';
  383. }elseif ($user_like=='1'){
  384. $res=Db::name('store_fabulous')->where('uid',$uid)->where('mer_id',$id)->update(['status'=>0]);
  385. if($res!==false)
  386. $message='取消点赞成功';
  387. else
  388. $message='取消点赞失败';
  389. }else{
  390. $inser_data=[
  391. 'uid'=>$uid,
  392. 'mer_id'=>$id,
  393. 'ctime'=>time(),
  394. 'status'=>1
  395. ];
  396. $res=Db::name('store_fabulous')->insert($inser_data);
  397. if($res!==false)
  398. $message='点赞成功';
  399. else
  400. $message='点赞失败';
  401. }
  402. return app('json')->success($message);
  403. }
  404. }