Merchant.php 11 KB

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