Merchant.php 12 KB

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