Merchant.php 12 KB

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