123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- <?php
- // +----------------------------------------------------------------------
- // | [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2018-2020 rights reserved.
- // +----------------------------------------------------------------------
- // | Author: TABLE ME
- // +----------------------------------------------------------------------
- // | Date: 2020-08-25 17:23
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\api\controller;
- use app\model\api\ArticleModel;
- use think\facade\View;
- use app\BaseController;
- use app\Request;
- use library\services\UtilService;
- use library\utils\UtilsTool;
- use think\facade\Db;
- use think\Image;
- use think\Db as D;
- use app\model\api\AppBug;
- use app\model\api\User as UserModel;
- use app\model\api\AccessIp;
- use app\model\api\ShowTemplate;
- use app\model\api\UserShowTemplate;
- use app\model\api\ServiceType;
- use app\model\api\ServiceLabel;
- use app\model\api\ServiceTimeType;
- use app\model\api\UserWorkType;
- use app\model\api\InfoAudit;
- use app\model\api\TypeAudit;
- use app\model\api\Sys as SysModel;
- use app\model\api\Advert as AdvertModel;
- use library\utils\WxpayV2 as wxpayApi;
- class Pub extends BaseController
- {
- private $user = null;
- public function checkUser($token=null){
- if(empty($token)){
- return false;
- }
- $memData = (new UserModel)
- ->where('token',$token)
- ->where('status',1)
- ->find();
- if(empty($memData)){
- return false;
- }
- $this->user = $memData->toArray();
- return true;
- }
- /**
- * 获取支付类型数据
- */
- public function getPayTypeData(){
- $data = [
- ["code"=>"wxpay","title"=>"微信支付","img"=> env('appinfo.app_api_domain', '')."/resource/icon/"."wxicon.png"],
- ["code"=>"balance","title"=>"余额支付","img"=>env('appinfo.app_api_domain', '')."/resource/icon/"."balance.png"],
- ];
- return app('json')->success($data);
- }
-
- /**
- * 获取分享信息
- * @return type
- */
- public function getShareInfo(){
- $data = (new SysModel)->getDataInfo("share");
- return app('json')->success($data);
- }
-
- /**
- * 获取模板详情
- * @param Request $request
- * @return type
- */
- public function getShowTemplateItem($id){
- $data = (new ShowTemplate)
- ->field("id,title,price,old_price,status,imgs,is_hot,is_recommend,code,look_count,real_sales,unreal_sales")
- ->where("id",$id)
- ->find();
- if(empty($data)){
- return app('json')->fail("模板不存在");
- }
- if($data["is_init"]==0 && $data["status"]!=1){
- return app('json')->fail("模板已下架");
- }
- $data = $data->toArray();
- $data["is_use"] = 0;
- $data["imgs"] = getImageAr($data["imgs"]);
- $data["img"] = empty($data["imgs"]) ? "" : $data["imgs"][0];
- $data["sales_count"] = $data["real_sales"] + $data["unreal_sales"];
- unset($data["real_sales"]);
- unset($data["unreal_sales"]);
- //验证是否购买过并添加浏览记录
- $this->checkUser(request()->header("token", ""));
- if(!empty($this->user)){
- $data["is_use"]=(new UserShowTemplate)->where("uid",$this->user["uid"])->where("show_template_id",$data["id"])->count()>0?1:0;
- (new ShowTemplate)->where('id', $data["id"])->inc('look_count', 1)->update();
- }
- return app('json')->success($data);
- }
-
- /**
- * 获取皮肤模板列表
- * @param Request $request
- */
- public function getShowTemplateList(Request $request){
- $post = UtilService::getMore([
- ['is_hot', '0'],
- ['is_recommend', '0'],
- ['page', 1],
- ['pageSize', 50],
- ], $request);
- $where["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $where["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $where["status"] = 1;
- if((int)$post["is_hot"]==1){
- $where["is_hot"] = 1;
- }
- if((int)$post["is_recommend"]==1){
- $where["is_recommend"] = 1;
- }
- $data = (new ShowTemplate)->getDataList($where, "id,title,price,old_price,status,imgs,is_hot,is_recommend,code,look_count,real_sales,unreal_sales");
- return app('json')->success($data);
- }
- /**
- * 获取轮播图
- * @param Request $request
- */
- public function getBannerList(Request $request){
- $post = UtilService::getMore([
- ['type', ''],
- ['page', 1],
- ['pageSize', 50],
- ], $request);
- $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $where=[];
- $where[]=["is_show","=",1];
- $where[]=["page_id","=",70];
- $totalCount = (new AdvertModel)->where($where)->count();
- $data=null;
- if($totalCount>0){
- $data = (new AdvertModel)
- ->field("id,img,title,url")
- ->where($where)
- ->order("sort","desc")
- ->page($post["page"], $post["pageSize"])
- ->select();
- }
- $data = empty($data)?[]:$data;
- return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
- }
-
- /**
- * 获取服务类型列表
- * @param Request $request
- * @return type
- */
- public function getServiceTypeList(Request $request){
- $post = UtilService::getMore([
- ['page', 1],
- ['pageSize', 50],
- ], $request);
- $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $post["status"] = 1;
- $data = (new ServiceType)->getList($post,"id,title,content,img");
- return app('json')->success($data);
- }
- /**
- * 获取标签列表
- * @param Request $request
- * @return type
- */
- public function getServiceLabelList(Request $request){
- $post = UtilService::getMore([
- ['page', 1],
- ['pageSize', 50],
- ], $request);
- $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $post["status"] = 1;
- $data = (new ServiceLabel)->getList($post,"id,title,type");
- return app('json')->success($data);
- }
-
- /**
- * 获取用户工作服务类型
- * @param Request $request
- */
- public function getUserWorkTypeList(Request $request){
- $post = UtilService::getMore([
- ['page', 1],
- ['pageSize', 50],
- ], $request);
- $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $post["status"] = 1;
- $data = (new UserWorkType)->getList($post,"id,title,content,img");
- return app('json')->success($data);
- }
- /**
- * 获取从业人员列表
- * @param Request $request
- * @return type
- */
- public function getWorkerList(Request $request){
- $post = UtilService::getMore([
- ['page', 1],
- ['pageSize', 50],
- ['work_type_id', ""],
- ], $request);
- $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $post["status"] = 1;
- $data = (new UserModel)->getApiWorkerList($post);
- foreach ($data['list'] as &$item) {
- $infoAuditDb = new InfoAudit();
- $infoData = $infoAuditDb->getItem(["status"=>1,"uid"=>$item["uid"]]);
- $item['is_type_audit'] = $item['is_type_audit']==1?1:0;
- $item['ancestral_place'] = !empty($infoData['ancestral_place']) ? $infoData['ancestral_place'] : '';
- }
- return app('json')->success($data);
- }
-
-
-
-
- /**
- * 获取服务时长类型
- * @param Request $request
- * @return type
- */
- public function getServiceTimeTypeList(Request $request){
- $post = UtilService::getMore([
- ['page', 1],
- ['pageSize', 50],
- ], $request);
- $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $post["status"] = 1;
- $data = (new ServiceTimeType)->getList($post,"title,code");
- return app('json')->success($data);
- }
-
-
-
-
-
-
-
- /**
- * 获取系统信息
- * @param Request $request
- */
- public function getSysData(Request $request){
- $data = (new Sys)->where("id",1)->find()->toArray();
- $data=[];
- return app("json")->success($data);
- }
- /**
- * 首页轮播
- * @param Request $request
- */
- public function getHomeBanner(Request $request){
- $data = (new AdvertModel)
- ->field("id,img,title,url")
- ->where("page_id",70)
- ->where("is_show",1)
- ->order("sort","desc")
- ->select()
- ->toArray();
- $data = empty($data)?[]:$data;
- return app("json")->success($data);
- }
- /**
- * 获取其他用户名片信息
- * @param Request $request
- */
- public function getCommonUserCardInfo(Request $request){
- [$uid] = UtilService::getMore([
- ['uid', '','empty',"用户信息为空"],
- ], $request,true);
- $userData = (new UserModel)->where("uid",$uid)->find();
- if(empty($userData)){
- return app('json')->fail("用户不存在");
- }
- $userData->toArray();
- $data = (new InfoAudit)->getItem(["uid"=>$uid,"status"=>1]);
- if(empty($data)){
- return app('json')->fail("当前用户还未通过审核");
- }
- $typeData = (new TypeAudit)->where("uid",$uid)->order("id","desc")->find();
- $data["is_type_audit"] = (empty($typeData) || $typeData["status"]!=1)?0:1;
- //名片浏览次数
- (new UserModel)->where('uid', $uid)->inc('card_look_count', 1)->update();
- $accessiInfo = [
- 'uid' => $uid,
- 'add_time' => time(),
- 'url_ip' => $request->ip(),
- ];
- $res = AccessIp::create($accessiInfo);
- // $add_time = time();//访问时间
- // $url_ip = $request->url();//访问IP
- $data["card_look_count"] = $userData["card_look_count"]+1;
- return app('json')->success($data);
- }
- /**
- * 名片浏览量排行榜
- * @param Request $request
- */
- public function getCardLookCountRank(Request $request) {
- $time = $request->param();
- $users = AccessIp::where('add_time','>=',$time['time'])
- ->where('add_time','<=',$time['times'])
- ->field('uid, count(*) as ip_count')
- ->group('uid')
- ->order('ip_count', 'desc')
- ->select();
- $rankList = [];
- foreach ($users as $key => $value) {
- $userInfo = (new UserModel)->where('uid', $value['uid'])->find();
- $auth = (new InfoAudit)->where('uid',$value['uid'])->find();
- $template = $this->getShowTemplateItem($value['uid']);
- $user_work_type_title = (new UserWorkType)->where('id',$auth['user_work_type_id'])->find();
- $rankList[] = [
- 'rank' => $key + 1,
- 'uid' => $value['uid'],
- 'name' => $userInfo['name'],
- 'avatar' => $userInfo['avatar'],
- 'card_look_count' => $value['ip_count'],
- 'template' => $template,
- 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
- 'ancestral_place' => $auth ? $auth['ancestral_place'] : '',
- 'auth_info' => $auth ? $auth->toArray() : [],
- 'user_work_type_id' => $user_work_type_title['title'],
- ];
- }
- $rankList = array_values(array_filter($rankList, function($item){
- return !empty($item['ancestral_place']);
- }));
- return app('json')->success($rankList);
- }
- //获取文章详情
- public function getArtDetail(\think\Request $request)
- {
- $id = $request->param('id');
- $article = ArticleModel::where('id', $id)->find();
- if (!$article) {
- return app('json')->fail('文章不存在');
- }
- return app('json')->success(['list' => [$article], 'count' => 1]);
- }
-
- /**
- * bug提交
- * @param Request $request
- */
- public function appBugSub(Request $request){
- [$error] = UtilService::getMore([
- ['error', '','empty',"错误信息为空"],
- ], $request,true);
- $deviceId = $request->header("deviceId", "");
- $deviceType = $request->header("deviceType", "");
- $fromPlat = $request->header("fromPlat", "");
- $version = $request->header("version", "");
- (new AppBug)->insert([
- "device_id" => $deviceId,
- "device_type" => $deviceType,
- "from_plat" => $fromPlat,
- "version" => $version,
- "error" => $error,
- "time" => time()
- ]);
- return app("json")->success("提交成功");
- }
-
- /**
- * 测试
- */
- public function appTest(Request $request){
-
-
- $labelData = (new ServiceLabel)->where("status",1)->where("id","in",["",1,2,6,7,8,0])->column('id');
- var_dump($labelData);exit;
-
- $money = $request->post("money",0);
- $money = bcadd("0", $money."",2);
- echo $money;exit;
-
-
- $xml = "<xml><appid><![CDATA[wx57a473fc2f83f7e5]]></appid>
- <attach><![CDATA[微信小程序支付]]></attach>
- <bank_type><![CDATA[OTHERS]]></bank_type>
- <cash_fee><![CDATA[1]]></cash_fee>
- <fee_type><![CDATA[CNY]]></fee_type>
- <is_subscribe><![CDATA[N]]></is_subscribe>
- <mch_id><![CDATA[1640972417]]></mch_id>
- <nonce_str><![CDATA[TTEMpfip075pcFNNhS5P60tDtis91veA]]></nonce_str>
- <openid><![CDATA[oOqrp4tndyR_iDwrGC5P7Y4moP2Y]]></openid>
- <out_trade_no><![CDATA[A202304201681959554328879382]]></out_trade_no>
- <result_code><![CDATA[SUCCESS]]></result_code>
- <return_code><![CDATA[SUCCESS]]></return_code>
- <sign><![CDATA[146B5ADFF5ADC399A92C60D62C54638A]]></sign>
- <time_end><![CDATA[20230420105928]]></time_end>
- <total_fee>1</total_fee>
- <trade_type><![CDATA[JSAPI]]></trade_type>
- <transaction_id><![CDATA[4200001803202304202712861307]]></transaction_id>
- </xml>";
-
- $wxpay = new wxpayApi();
- // $r = $wxpay->notifyCheckSign($xml);
- $r = $wxpay->searchOrderQuery("A202304201681959554328879382");
- var_dump($r);
-
-
- }
-
-
- }
|