Merchant.php 12 KB

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