Pub.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018-2020 rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: TABLE ME
  8. // +----------------------------------------------------------------------
  9. // | Date: 2020-08-25 17:23
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\controller;
  13. use app\model\api\ArticleModel;
  14. use think\facade\View;
  15. use app\BaseController;
  16. use app\Request;
  17. use library\services\UtilService;
  18. use library\utils\UtilsTool;
  19. use think\facade\Db;
  20. use think\Image;
  21. use think\Db as D;
  22. use app\model\api\AppBug;
  23. use app\model\api\User as UserModel;
  24. use app\model\api\AccessIp;
  25. use app\model\api\ShowTemplate;
  26. use app\model\api\UserShowTemplate;
  27. use app\model\api\ServiceType;
  28. use app\model\api\ServiceLabel;
  29. use app\model\api\ServiceTimeType;
  30. use app\model\api\UserWorkType;
  31. use app\model\api\InfoAudit;
  32. use app\model\api\TypeAudit;
  33. use app\model\api\Sys as SysModel;
  34. use app\model\api\Advert as AdvertModel;
  35. use library\utils\WxpayV2 as wxpayApi;
  36. class Pub extends BaseController
  37. {
  38. private $user = null;
  39. public function checkUser($token=null){
  40. if(empty($token)){
  41. return false;
  42. }
  43. $memData = (new UserModel)
  44. ->where('token',$token)
  45. ->where('status',1)
  46. ->find();
  47. if(empty($memData)){
  48. return false;
  49. }
  50. $this->user = $memData->toArray();
  51. return true;
  52. }
  53. /**
  54. * 获取支付类型数据
  55. */
  56. public function getPayTypeData(){
  57. $data = [
  58. ["code"=>"wxpay","title"=>"微信支付","img"=> env('appinfo.app_api_domain', '')."/resource/icon/"."wxicon.png"],
  59. ["code"=>"balance","title"=>"余额支付","img"=>env('appinfo.app_api_domain', '')."/resource/icon/"."balance.png"],
  60. ];
  61. return app('json')->success($data);
  62. }
  63. /**
  64. * 获取分享信息
  65. * @return type
  66. */
  67. public function getShareInfo(){
  68. $data = (new SysModel)->getDataInfo("share");
  69. return app('json')->success($data);
  70. }
  71. /**
  72. * 获取模板详情
  73. * @param Request $request
  74. * @return type
  75. */
  76. public function getShowTemplateItem($id){
  77. $data = (new ShowTemplate)
  78. ->field("id,title,price,old_price,status,imgs,is_hot,is_recommend,code,look_count,real_sales,unreal_sales")
  79. ->where("id",$id)
  80. ->find();
  81. if(empty($data)){
  82. return app('json')->fail("模板不存在");
  83. }
  84. if($data["is_init"]==0 && $data["status"]!=1){
  85. return app('json')->fail("模板已下架");
  86. }
  87. $data = $data->toArray();
  88. $data["is_use"] = 0;
  89. $data["imgs"] = getImageAr($data["imgs"]);
  90. $data["img"] = empty($data["imgs"]) ? "" : $data["imgs"][0];
  91. $data["sales_count"] = $data["real_sales"] + $data["unreal_sales"];
  92. unset($data["real_sales"]);
  93. unset($data["unreal_sales"]);
  94. //验证是否购买过并添加浏览记录
  95. $this->checkUser(request()->header("token", ""));
  96. if(!empty($this->user)){
  97. $data["is_use"]=(new UserShowTemplate)->where("uid",$this->user["uid"])->where("show_template_id",$data["id"])->count()>0?1:0;
  98. (new ShowTemplate)->where('id', $data["id"])->inc('look_count', 1)->update();
  99. }
  100. return app('json')->success($data);
  101. }
  102. /**
  103. * 获取皮肤模板列表
  104. * @param Request $request
  105. */
  106. public function getShowTemplateList(Request $request){
  107. $post = UtilService::getMore([
  108. ['is_hot', '0'],
  109. ['is_recommend', '0'],
  110. ['page', 1],
  111. ['pageSize', 50],
  112. ], $request);
  113. $where["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  114. $where["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  115. $where["status"] = 1;
  116. if((int)$post["is_hot"]==1){
  117. $where["is_hot"] = 1;
  118. }
  119. if((int)$post["is_recommend"]==1){
  120. $where["is_recommend"] = 1;
  121. }
  122. $data = (new ShowTemplate)->getDataList($where, "id,title,price,old_price,status,imgs,is_hot,is_recommend,code,look_count,real_sales,unreal_sales");
  123. return app('json')->success($data);
  124. }
  125. /**
  126. * 获取轮播图
  127. * @param Request $request
  128. */
  129. public function getBannerList(Request $request){
  130. $post = UtilService::getMore([
  131. ['type', ''],
  132. ['page', 1],
  133. ['pageSize', 50],
  134. ], $request);
  135. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  136. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  137. $where=[];
  138. $where[]=["is_show","=",1];
  139. $where[]=["page_id","=",70];
  140. $totalCount = (new AdvertModel)->where($where)->count();
  141. $data=null;
  142. if($totalCount>0){
  143. $data = (new AdvertModel)
  144. ->field("id,img,title,url")
  145. ->where($where)
  146. ->order("sort","desc")
  147. ->page($post["page"], $post["pageSize"])
  148. ->select();
  149. }
  150. $data = empty($data)?[]:$data;
  151. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
  152. }
  153. /**
  154. * 获取服务类型列表
  155. * @param Request $request
  156. * @return type
  157. */
  158. public function getServiceTypeList(Request $request){
  159. $post = UtilService::getMore([
  160. ['page', 1],
  161. ['pageSize', 50],
  162. ], $request);
  163. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  164. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  165. $post["status"] = 1;
  166. $data = (new ServiceType)->getList($post,"id,title,content,img");
  167. return app('json')->success($data);
  168. }
  169. /**
  170. * 获取标签列表
  171. * @param Request $request
  172. * @return type
  173. */
  174. public function getServiceLabelList(Request $request){
  175. $post = UtilService::getMore([
  176. ['page', 1],
  177. ['pageSize', 50],
  178. ], $request);
  179. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  180. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  181. $post["status"] = 1;
  182. $data = (new ServiceLabel)->getList($post,"id,title,type");
  183. return app('json')->success($data);
  184. }
  185. /**
  186. * 获取用户工作服务类型
  187. * @param Request $request
  188. */
  189. public function getUserWorkTypeList(Request $request){
  190. $post = UtilService::getMore([
  191. ['page', 1],
  192. ['pageSize', 50],
  193. ], $request);
  194. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  195. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  196. $post["status"] = 1;
  197. $data = (new UserWorkType)->getList($post,"id,title,content,img");
  198. return app('json')->success($data);
  199. }
  200. /**
  201. * 获取从业人员列表
  202. * @param Request $request
  203. * @return type
  204. */
  205. public function getWorkerList(Request $request){
  206. $post = UtilService::getMore([
  207. ['page', 1],
  208. ['pageSize', 50],
  209. ['work_type_id', ""],
  210. ], $request);
  211. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  212. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  213. $post["status"] = 1;
  214. $data = (new UserModel)->getApiWorkerList($post);
  215. foreach ($data['list'] as &$item) {
  216. $infoAuditDb = new InfoAudit();
  217. $infoData = $infoAuditDb->getItem(["status"=>1,"uid"=>$item["uid"]]);
  218. $item['is_type_audit'] = $item['is_type_audit']==1?1:0;
  219. $item['ancestral_place'] = !empty($infoData['ancestral_place']) ? $infoData['ancestral_place'] : '';
  220. }
  221. return app('json')->success($data);
  222. }
  223. /**
  224. * 获取服务时长类型
  225. * @param Request $request
  226. * @return type
  227. */
  228. public function getServiceTimeTypeList(Request $request){
  229. $post = UtilService::getMore([
  230. ['page', 1],
  231. ['pageSize', 50],
  232. ], $request);
  233. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  234. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  235. $post["status"] = 1;
  236. $data = (new ServiceTimeType)->getList($post,"title,code");
  237. return app('json')->success($data);
  238. }
  239. /**
  240. * 获取系统信息
  241. * @param Request $request
  242. */
  243. public function getSysData(Request $request){
  244. $data = (new Sys)->where("id",1)->find()->toArray();
  245. $data=[];
  246. return app("json")->success($data);
  247. }
  248. /**
  249. * 首页轮播
  250. * @param Request $request
  251. */
  252. public function getHomeBanner(Request $request){
  253. $data = (new AdvertModel)
  254. ->field("id,img,title,url")
  255. ->where("page_id",70)
  256. ->where("is_show",1)
  257. ->order("sort","desc")
  258. ->select()
  259. ->toArray();
  260. $data = empty($data)?[]:$data;
  261. return app("json")->success($data);
  262. }
  263. /**
  264. * 获取其他用户名片信息
  265. * @param Request $request
  266. */
  267. public function getCommonUserCardInfo(Request $request){
  268. [$uid] = UtilService::getMore([
  269. ['uid', '','empty',"用户信息为空"],
  270. ], $request,true);
  271. $userData = (new UserModel)->where("uid",$uid)->find();
  272. if(empty($userData)){
  273. return app('json')->fail("用户不存在");
  274. }
  275. $userData->toArray();
  276. $data = (new InfoAudit)->getItem(["uid"=>$uid,"status"=>1]);
  277. if(empty($data)){
  278. return app('json')->fail("当前用户还未通过审核");
  279. }
  280. $typeData = (new TypeAudit)->where("uid",$uid)->order("id","desc")->find();
  281. $data["is_type_audit"] = (empty($typeData) || $typeData["status"]!=1)?0:1;
  282. //名片浏览次数
  283. (new UserModel)->where('uid', $uid)->inc('card_look_count', 1)->update();
  284. $accessiInfo = [
  285. 'uid' => $uid,
  286. 'add_time' => time(),
  287. 'url_ip' => $request->ip(),
  288. ];
  289. $res = AccessIp::create($accessiInfo);
  290. // $add_time = time();//访问时间
  291. // $url_ip = $request->url();//访问IP
  292. $data["card_look_count"] = $userData["card_look_count"]+1;
  293. return app('json')->success($data);
  294. }
  295. /**
  296. * 名片浏览量排行榜
  297. * @param Request $request
  298. */
  299. public function getCardLookCountRank(Request $request) {
  300. $time = $request->param();
  301. $users = AccessIp::where('add_time','>=',$time['time'])
  302. ->where('add_time','<=',$time['times'])
  303. ->field('uid, count(*) as ip_count')
  304. ->group('uid')
  305. ->order('ip_count', 'desc')
  306. ->select();
  307. $rankList = [];
  308. foreach ($users as $key => $value) {
  309. $userInfo = (new UserModel)->where('uid', $value['uid'])->find();
  310. $auth = (new InfoAudit)->where('uid',$value['uid'])->find();
  311. $template = $this->getShowTemplateItem($value['uid']);
  312. $user_work_type_title = (new UserWorkType)->where('id',$auth['user_work_type_id'])->find();
  313. $rankList[] = [
  314. 'rank' => $key + 1,
  315. 'uid' => $value['uid'],
  316. 'name' => $userInfo['name'],
  317. 'avatar' => $userInfo['avatar'],
  318. 'card_look_count' => $value['ip_count'],
  319. 'template' => $template,
  320. 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
  321. 'ancestral_place' => $auth ? $auth['ancestral_place'] : '',
  322. 'auth_info' => $auth ? $auth->toArray() : [],
  323. 'user_work_type_id' => $user_work_type_title['title'],
  324. ];
  325. }
  326. $rankList = array_values(array_filter($rankList, function($item){
  327. return !empty($item['ancestral_place']);
  328. }));
  329. return app('json')->success($rankList);
  330. }
  331. //获取文章详情
  332. public function getArtDetail(\think\Request $request)
  333. {
  334. $id = $request->param('id');
  335. $article = ArticleModel::where('id', $id)->find();
  336. if (!$article) {
  337. return app('json')->fail('文章不存在');
  338. }
  339. return app('json')->success(['list' => [$article], 'count' => 1]);
  340. }
  341. /**
  342. * bug提交
  343. * @param Request $request
  344. */
  345. public function appBugSub(Request $request){
  346. [$error] = UtilService::getMore([
  347. ['error', '','empty',"错误信息为空"],
  348. ], $request,true);
  349. $deviceId = $request->header("deviceId", "");
  350. $deviceType = $request->header("deviceType", "");
  351. $fromPlat = $request->header("fromPlat", "");
  352. $version = $request->header("version", "");
  353. (new AppBug)->insert([
  354. "device_id" => $deviceId,
  355. "device_type" => $deviceType,
  356. "from_plat" => $fromPlat,
  357. "version" => $version,
  358. "error" => $error,
  359. "time" => time()
  360. ]);
  361. return app("json")->success("提交成功");
  362. }
  363. /**
  364. * 测试
  365. */
  366. public function appTest(Request $request){
  367. $labelData = (new ServiceLabel)->where("status",1)->where("id","in",["",1,2,6,7,8,0])->column('id');
  368. var_dump($labelData);exit;
  369. $money = $request->post("money",0);
  370. $money = bcadd("0", $money."",2);
  371. echo $money;exit;
  372. $xml = "<xml><appid><![CDATA[wx57a473fc2f83f7e5]]></appid>
  373. <attach><![CDATA[微信小程序支付]]></attach>
  374. <bank_type><![CDATA[OTHERS]]></bank_type>
  375. <cash_fee><![CDATA[1]]></cash_fee>
  376. <fee_type><![CDATA[CNY]]></fee_type>
  377. <is_subscribe><![CDATA[N]]></is_subscribe>
  378. <mch_id><![CDATA[1640972417]]></mch_id>
  379. <nonce_str><![CDATA[TTEMpfip075pcFNNhS5P60tDtis91veA]]></nonce_str>
  380. <openid><![CDATA[oOqrp4tndyR_iDwrGC5P7Y4moP2Y]]></openid>
  381. <out_trade_no><![CDATA[A202304201681959554328879382]]></out_trade_no>
  382. <result_code><![CDATA[SUCCESS]]></result_code>
  383. <return_code><![CDATA[SUCCESS]]></return_code>
  384. <sign><![CDATA[146B5ADFF5ADC399A92C60D62C54638A]]></sign>
  385. <time_end><![CDATA[20230420105928]]></time_end>
  386. <total_fee>1</total_fee>
  387. <trade_type><![CDATA[JSAPI]]></trade_type>
  388. <transaction_id><![CDATA[4200001803202304202712861307]]></transaction_id>
  389. </xml>";
  390. $wxpay = new wxpayApi();
  391. // $r = $wxpay->notifyCheckSign($xml);
  392. $r = $wxpay->searchOrderQuery("A202304201681959554328879382");
  393. var_dump($r);
  394. }
  395. }