소스 검색

基础调整

lizhen_gitee 3 년 전
부모
커밋
0ee6cabc41

+ 98 - 0
application/api/controller/Pay.php

@@ -0,0 +1,98 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+use addons\epay\library\Service;
+/**
+ * 充值
+ */
+class Pay extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    public function pay_config(){
+        $list = Db::name('pay_config')->where('is_show',1)->order('weight asc,id asc')->select();
+        $this->success('success',$list);
+    }
+
+    //创建订单
+    public function recharge(){
+
+        $rc_id = input('rc_id',0);
+        $uid = $this->auth->id;
+
+        if(!$rc_id){
+            $this->error('请选择会员套餐');
+        }
+
+
+        //赋值money
+        $recharge_config = Db::name('pay_config')->where('id',$rc_id)->find();
+        $money = $recharge_config['money'];
+
+        if($money<=0)
+        {
+            $this->error('支付金额必须大于0');
+        }
+        if($money > 10000){
+            $this->error('支付金额太大');
+        }
+
+        //创建订单
+        $data = [];
+        $data['status'] = 0;
+        $pay_no = createUniqueNo('P',$uid);
+        $data['pay_no'] = $pay_no;
+        $data['money'] = $money;
+        $data['payment_class'] = 'Wechat';
+        $data['user_id'] = $uid;
+        $data['ext_info'] =  json_encode(['subject'=>'充值会员支付']);
+        $data['memo'] =  '充值会员支付';
+        $data['createtime'] = time();
+        //$data['payment'] = 'miniapp';
+        $data['payment'] = 'mp';
+        $orderid = Db::name('pay_order')->insertGetId($data);
+
+        //创建回调
+        $even_data = [];
+        $even_data['event'] = 'success';
+        $even_data['class'] = 'app\common\model\Wallet';
+        $even_data['method'] = 'paySucc';
+        $even_data['args'] = json_encode(['user_id'=>$uid,'days'=>$recharge_config['days']]);
+        $even_data['pay_no'] = $pay_no;
+        Db::name('pay_event')->insertGetId($even_data);
+
+        $return = [
+            'pay_no'=>$pay_no,
+            'title' => '充值订单支付',
+        ];
+
+      /*  $this->success('success',$return);
+    }
+
+    public function topay(){*/
+
+        $openid = $this->auth->openid;
+        /*$pay_no = input('pay_no');
+        $orderInfo = Db::name('pay_order')->where('pay_no',$pay_no)->find();*/
+        //下单
+        $params = [
+            'type'         => 'wechat',
+            'orderid'      => $pay_no,
+            'title'        => $data['memo'],
+            'amount'       => $data['money'],
+            //'amount'       => 0.01,
+            //'method'       => 'miniapp',
+            'method'       => 'mp',
+            'openid'       => $openid,
+            'notifyurl' => $this->request->root(true) . '/notify.php',
+            'returnurl' => '',
+        ];
+        $res = Service::submitOrder($params);
+        $this->success('请求成功',json_decode($res,true));
+    }
+
+}

+ 1 - 1
application/api/controller/User.php

@@ -80,7 +80,7 @@ class User extends Api
         }
         $user = \app\common\model\User::getByMobile($mobile);
         if ($user) {
-            if ($user->status != 'normal') {
+            if ($user->status != 1) {
                 $this->error(__('Account is locked'));
             }
             //如果已经有账号则直接登录

+ 159 - 0
application/api/controller/Userdongtai.php

@@ -0,0 +1,159 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 动态
+ */
+class Userdongtai extends Api
+{
+    protected $noNeedLogin = ['evaluate'];
+    protected $noNeedRight = ['*'];
+
+    //发布动态
+    public function addone(){
+        $title = input('title','');
+        $images = input('images','');
+        if(!$title && !$images){
+            $this->error(__('Invalid parameters'));
+        }
+
+        $data = [
+            'user_id' => $this->auth->id,
+            'title' => $title,
+            'images' => $images,
+            'createtime' => time(),
+            'updatetime' => time(),
+        ];
+
+
+        $id = Db::name('user_dongtai')->insertGetId($data);
+
+        $this->success('success',$id);
+    }
+
+    //自己看列表
+    public function my_lists(){
+
+        $list = Db::name('user_dongtai')->alias('dt')
+            ->join('user','dt.user_id = user.id','LEFT')
+            ->field('dt.id,dt.title,dt.images,dt.createtime,dt.sharenum,dt.goodnum,user.nickname,user.avatar')
+            ->where('dt.user_id',$this->auth->id)
+            ->order('dt.id desc')->autopage()->select();
+        $list = list_domain_image($list,['images','avatar']);
+        /*foreach($list as $key => &$val){
+            if($val['images']){
+                $val['images'] = explode(',',$val['images']);
+            }else{
+                $val['images'] = [];
+            }
+        }*/
+
+        $this->success('success',$list);
+    }
+
+    //详情
+    public function info(){
+        $id = input('id');
+
+        $info = Db::name('user_dongtai')->alias('p')
+            ->join('user','p.user_id = user.id','LEFT')
+            ->field('p.id,p.title,p.images,p.createtime,p.sharenum,p.goodnum,user.nickname,user.avatar')
+            ->where('p.id',$id)->find();
+        $info = info_domain_image($info,['images','avatar']);
+
+        /*if($info['images']){
+            $info['images'] = explode(',',$info['images']);
+        }else{
+            $info['images'] = [];
+        }*/
+
+        //是否点赞过
+        if($info){
+            $where = [
+                'dt_id' => $id,
+                'user_id'  => $this->auth->id,
+            ];
+            $check = Db::name('user_dongtai_good')->where($where)->find();
+
+            if($check){
+                $info['isgood'] = 1;
+            }else{
+                $info['isgood'] = 0;
+            }
+        }
+
+        //评论
+
+        $this->success('success',$info);
+    }
+
+    //评论
+    public function answer(){
+        $id = input('id');
+        $title = input('title','');
+        $to_user_id = input('to_user_id','');
+        $level = input('level',1);
+        if(!$title){
+            $this->error();
+        }
+
+        //最新楼层
+        $new_floor = 2;
+        $last_answer = Db::name('user_dongtai_answer')->where('dt_id',$id)->order('id desc')->value('floor');
+        if($last_answer){
+            $new_floor = $last_answer + 1;
+        }
+
+        //data
+        $data = [
+            'dt_id' => $id,
+            'floor' => $new_floor,
+            'user_id' => $this->auth->id,
+            'title' => $title,
+            'to_user_id' => $to_user_id,
+            'level' => $level,
+            'createtime' => time(),
+            'updatetime' => time(),
+        ];
+
+        $rs = Db::name('user_dongtai_answer')->insertGetId($data);
+        $this->success('评价成功');
+    }
+
+    //家长点赞
+    public function good(){
+        $id = input('id');
+
+        $where = [
+            'dt_id' => $id,
+            'user_id'  => $this->auth->id,
+        ];
+        $check = Db::name('user_dongtai_good')->where($where)->find();
+
+        if($check){
+            $this->error('已经赞过了');
+        }
+
+        Db::startTrans();
+        $rs = Db::name('user_dongtai_good')->insertGetId($where);
+        $up = Db::name('user_dongtai')->where('id',$id)->setInc('goodnum');
+
+        if($rs && $up !== false){
+            Db::commit();
+            $this->success('点赞成功');
+        }
+        Db::rollback();
+        $this->error('点赞失败');
+    }
+
+    //分享
+    public function sharenum(){
+        $id = input('id');
+        $up = Db::name('user_dongtai')->where('id',$id)->setInc('sharenum');
+        $this->success('操作成功');
+    }
+
+}

+ 76 - 0
application/common.php

@@ -481,3 +481,79 @@ if (!function_exists('check_ip_allowed')) {
         }
     }
 }
+//结果集信息里,多个字段需要增加domain_name
+function list_domain_image($list,$field){
+    if(!$list || empty($list)){
+        return $list;
+    }
+    foreach($list as $vo => $info){
+        $list[$vo] = info_domain_image($info,$field);
+    }
+    return $list;
+}
+//单条信息里,多个字段需要增加domain_name
+//支持image,images
+function info_domain_image($data,$field){
+    if(!$data || empty($data)){
+        return $data;
+    }
+    foreach($data as $key => $val){
+        if(in_array($key,$field)){
+            $data[$key] = one_domain_image($val);
+        }
+    }
+    return $data;
+}
+//支持单个字段,需要增加domain_name
+//支持image,images
+function one_domain_image($one){
+    if(!$one){
+        return $one;
+    }
+    $domain_name = config('site.domain_name');
+    if(strpos($one,',')){
+        //逗号隔开的多个图片
+        $one = explode(',',$one);
+        foreach($one as $k => $v){
+            $one[$k] = $v ? $domain_name.$v : $v;
+        }
+        $one = implode(',',$one);
+    }else{
+        $one = $one ? $domain_name.$one : $one;
+    }
+    return $one;
+}
+
+//秒 转换 日月分
+function Sec2Time($time){
+    if(is_numeric($time)){
+        $value = array(
+            'years' => 0, 'days' => 0, 'hours' => 0,
+            'minutes' => 0, 'seconds' => 0,
+        );
+        /*if($time >= 31556926){
+            $value['years'] = floor($time/31556926);
+            $time = ($time%31556926);
+        }*/
+        if($time >= 86400){
+            $value['days'] = floor($time/86400);
+            $time = ($time%86400);
+        }
+        if($time >= 3600){
+            $value['hours'] = floor($time/3600);
+            $time = ($time%3600);
+        }
+        if($time >= 60){
+            $value['minutes'] = floor($time/60);
+            $time = ($time%60);
+        }
+        $value['seconds'] = floor($time);
+        //return (array) $value;
+        //$t=$value['years'] .'年'. $value['days'] .'天'.' '. $value['hours'] .'小时'. $value['minutes'] .'分'.$value['seconds'].'秒';
+        $t = $value['days'] .'天' . $value['hours'] .'小时'. $value['minutes'] .'分';
+        return $t;
+
+    }else{
+        return '0天';
+    }
+}

+ 6 - 0
application/common/controller/Api.php

@@ -170,6 +170,9 @@ class Api
      */
     protected function success($msg = '', $data = null, $code = 1, $type = null, array $header = [])
     {
+        if(empty($msg)){
+            $msg = '操作成功';
+        }
         $this->result($msg, $data, $code, $type, $header);
     }
 
@@ -183,6 +186,9 @@ class Api
      */
     protected function error($msg = '', $data = null, $code = 0, $type = null, array $header = [])
     {
+        if(empty($msg)){
+            $msg = __('Invalid parameters');
+        }
         $this->result($msg, $data, $code, $type, $header);
     }
 

+ 3 - 3
application/common/library/Auth.php

@@ -103,7 +103,7 @@ class Auth
                 $this->setError('Account not exist');
                 return false;
             }
-            if ($user['status'] != 'normal') {
+            if ($user['status'] != 1) {
                 $this->setError('Account is locked');
                 return false;
             }
@@ -217,7 +217,7 @@ class Auth
             return false;
         }
 
-        if ($user->status != 'normal') {
+        if ($user->status != 1) {
             $this->setError('Account is locked');
             return false;
         }
@@ -408,7 +408,7 @@ class Auth
             return [];
         }
         $rules = explode(',', $group->rules);
-        $this->rules = UserRule::where('status', 'normal')->where('id', 'in', $rules)->field('id,pid,name,title,ismenu')->select();
+        $this->rules = UserRule::where('status', 1)->where('id', 'in', $rules)->field('id,pid,name,title,ismenu')->select();
         return $this->rules;
     }
 

+ 26 - 0
new1.txt

@@ -0,0 +1,26 @@
+微信商户平台获取:微信支付商户号ID , 微信支付商户密钥
+微信开放平台:申请app并拿到 appid,  appid要与上面的微信支付商户号ID做绑定
+微信开放平台申请三方登录
+
+
+支付宝
+支付宝商户平台;申请应用ID拿到appid,应用私钥,和支付宝公钥
+
+
+ios端需要用到的苹果支付,苹果开发者账号
+
+
+网易一键本机手机号登录
+
+
+腾讯云服务器
+腾讯云即时通信im
+腾讯实时音视频TRTC
+腾讯云短信
+腾讯对象存储cos
+
+百度地图api
+
+极光推送
+
+备案域名

+ 21 - 0
thinkphp/library/think/db/Query.php

@@ -1435,6 +1435,27 @@ class Query
         return $this;
     }
 
+    //模仿上一个page,但是从paginate拿到page与list_rows
+    public function autopage(){
+        $config = Config::get('paginate');
+
+        /** @var Paginator $class */
+        $class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']);
+        $page  = isset($config['page']) ? (int) $config['page'] : call_user_func([
+            $class,
+            'getCurrentPage',
+        ], $config['var_page']);
+
+        $page = $page < 1 ? 1 : $page;
+
+        //list_rows
+        $listRows = isset($_REQUEST['listrow']) ? (int)$_REQUEST['listrow'] : $config['list_rows'];
+
+
+        $this->options['page'] = [intval($page), intval($listRows)];
+        return $this;
+    }
+
     /**
      * 分页查询
      * @param int|array $listRows 每页数量 数组表示配置参数