18315626215 5 years ago
parent
commit
cc65a66a5a

+ 78 - 10
.idea/workspace.xml

@@ -2,12 +2,12 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="0c798a10-12e9-4340-984e-11d11f343507" name="Default Changelist" comment="">
-      <change afterPath="$PROJECT_DIR$/.idea/php.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/application/api/model/Cashwechat.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/.idea/youxiangjie.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/youxiangjie.iml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/application/admin/controller/user/User.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/admin/controller/user/User.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/public/assets/js/require-table.js" beforeDir="false" afterPath="$PROJECT_DIR$/public/assets/js/require-table.js" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/thinkphp/library/think/Model.php" beforeDir="false" afterPath="$PROJECT_DIR$/thinkphp/library/think/Model.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/application/api/controller/Commodity.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/api/controller/Commodity.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/application/api/controller/Login.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/api/controller/Login.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/application/api/controller/Register.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/api/controller/Register.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/application/api/controller/User.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/api/controller/User.php" afterDir="false" />
     </list>
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
     <option name="SHOW_DIALOG" value="false" />
@@ -63,19 +63,20 @@
   <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
   <component name="PropertiesComponent">
     <property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
-    <property name="WebServerToolWindowFactoryState" value="true" />
+    <property name="WebServerToolWindowFactoryState" value="false" />
     <property name="WebServerToolWindowPanel.toolwindow.highlight.mappings" value="true" />
     <property name="WebServerToolWindowPanel.toolwindow.highlight.symlinks" value="true" />
     <property name="WebServerToolWindowPanel.toolwindow.show.date" value="false" />
     <property name="WebServerToolWindowPanel.toolwindow.show.permissions" value="false" />
     <property name="WebServerToolWindowPanel.toolwindow.show.size" value="false" />
-    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
+    <property name="last_opened_file_path" value="$PROJECT_DIR$/../bone" />
     <property name="node.js.detected.package.eslint" value="true" />
     <property name="node.js.detected.package.tslint" value="true" />
     <property name="node.js.path.for.package.eslint" value="project" />
     <property name="node.js.path.for.package.tslint" value="project" />
     <property name="node.js.selected.package.eslint" value="(autodetect)" />
     <property name="node.js.selected.package.tslint" value="(autodetect)" />
+    <property name="settings.editor.selected.configurable" value="preferences.sourceCode.PHP" />
   </component>
   <component name="RunDashboard">
     <option name="ruleStates">
@@ -101,7 +102,19 @@
       <updated>1575947922294</updated>
       <workItem from="1575947923604" duration="10146000" />
       <workItem from="1576024818220" duration="20064000" />
-      <workItem from="1576110627926" duration="628000" />
+      <workItem from="1576110627926" duration="18125000" />
+      <workItem from="1576200834678" duration="21855000" />
+      <workItem from="1576286197513" duration="15085000" />
+      <workItem from="1576458185640" duration="6279000" />
+      <workItem from="1576549353185" duration="12255000" />
+      <workItem from="1576630486480" duration="20617000" />
+      <workItem from="1576717318040" duration="16195000" />
+      <workItem from="1576802719439" duration="17393000" />
+      <workItem from="1576890129730" duration="13143000" />
+      <workItem from="1577062517620" duration="4389000" />
+      <workItem from="1577148582457" duration="1000" />
+      <workItem from="1577149538678" duration="240000" />
+      <workItem from="1577156028534" duration="13089000" />
     </task>
     <task id="LOCAL-00001" summary="提交测试">
       <created>1575956432691</created>
@@ -131,7 +144,56 @@
       <option name="project" value="LOCAL" />
       <updated>1575962376579</updated>
     </task>
-    <option name="localTasksCounter" value="5" />
+    <task id="LOCAL-00005" summary="12.11">
+      <created>1576112510049</created>
+      <option name="number" value="00005" />
+      <option name="presentableId" value="LOCAL-00005" />
+      <option name="project" value="LOCAL" />
+      <updated>1576112510049</updated>
+    </task>
+    <task id="LOCAL-00006" summary="12.14">
+      <created>1576286308499</created>
+      <option name="number" value="00006" />
+      <option name="presentableId" value="LOCAL-00006" />
+      <option name="project" value="LOCAL" />
+      <updated>1576286308499</updated>
+    </task>
+    <task id="LOCAL-00007" summary="12.16">
+      <created>1576466795333</created>
+      <option name="number" value="00007" />
+      <option name="presentableId" value="LOCAL-00007" />
+      <option name="project" value="LOCAL" />
+      <updated>1576466795333</updated>
+    </task>
+    <task id="LOCAL-00008" summary="12.18">
+      <created>1576630801360</created>
+      <option name="number" value="00008" />
+      <option name="presentableId" value="LOCAL-00008" />
+      <option name="project" value="LOCAL" />
+      <updated>1576630801360</updated>
+    </task>
+    <task id="LOCAL-00009" summary="12.18">
+      <created>1576662789638</created>
+      <option name="number" value="00009" />
+      <option name="presentableId" value="LOCAL-00009" />
+      <option name="project" value="LOCAL" />
+      <updated>1576662789638</updated>
+    </task>
+    <task id="LOCAL-00010" summary="12.20">
+      <created>1576803755290</created>
+      <option name="number" value="00010" />
+      <option name="presentableId" value="LOCAL-00010" />
+      <option name="project" value="LOCAL" />
+      <updated>1576803755290</updated>
+    </task>
+    <task id="LOCAL-00011" summary="12.21">
+      <created>1576920584714</created>
+      <option name="number" value="00011" />
+      <option name="presentableId" value="LOCAL-00011" />
+      <option name="project" value="LOCAL" />
+      <updated>1576920584714</updated>
+    </task>
+    <option name="localTasksCounter" value="12" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
@@ -154,6 +216,12 @@
     <MESSAGE value="提交测试" />
     <MESSAGE value="修改了默认登录" />
     <MESSAGE value="配置" />
-    <option name="LAST_COMMIT_MESSAGE" value="配置" />
+    <MESSAGE value="12.11" />
+    <MESSAGE value="12.14" />
+    <MESSAGE value="12.16" />
+    <MESSAGE value="12.18" />
+    <MESSAGE value="12.20" />
+    <MESSAGE value="12.21" />
+    <option name="LAST_COMMIT_MESSAGE" value="12.21" />
   </component>
 </project>

+ 3 - 0
application/api/controller/Commodity.php

@@ -17,6 +17,7 @@ class Commodity extends Api
 
     /**
      * 全部商品
+     * @ApiMethod   (POST)
      */
     public function commodityIndex()
     {
@@ -47,6 +48,7 @@ class Commodity extends Api
 
     /**
      * 分类下的商品
+     * @ApiMethod   (POST)
      * @param string $t_id 分类id
      */
     public function typeCommodity()
@@ -73,6 +75,7 @@ class Commodity extends Api
 
     /**
      * 商品详情
+     * @ApiMethod   (POST)
      * @param string $c_id 商品id
      * @param string $user_id 用户id
      */

+ 3 - 2
application/api/controller/Login.php

@@ -17,7 +17,7 @@ class Login extends Api
 
     /**
      * 会员登录
-     *
+     * @ApiMethod   (POST)
      * @param string $user_tel 账号
      * @param string $user_pwd 密码
      * @param string $user_openid qq或者微信openID
@@ -75,7 +75,7 @@ class Login extends Api
 
     /**
      * 验证手机号是否已存在
-     *
+     * @ApiMethod   (POST)
      * 可以通过@ApiInternal忽略请求的方法
      * @ApiInternal
      */
@@ -90,6 +90,7 @@ class Login extends Api
 
     /**
      * 服务协议
+     * @ApiMethod   (POST)
      */
     public function agreement()
     {

+ 6 - 3
application/api/controller/Register.php

@@ -16,7 +16,7 @@ class Register extends Api
 
     /**
      * 手机号注册
-     *
+     * @ApiMethod   (POST)
      * @param string $user_tel 账号
      * @param string $code 验证码
      * @param string $user_tjtel 推荐人手机号
@@ -75,6 +75,7 @@ class Register extends Api
                         'user_avatar'   => config('site.httpurl') . '/uploads/logo.img',
                         'create_time'   => date('Y-m-d H:i:s', time()),
                         'user_tjtel'    => $params['user_tjtel'],
+                        'type'          => $params['type'],
                     );
                     $addUser = $userModel->allowField(true)->save($data);
                     if ($addUser) {
@@ -84,7 +85,7 @@ class Register extends Api
                         return $this->result('注册失败', [], 100);
                     }
                 }
-                if ($params['type'] == 1) {
+                if ($params['type'] > 1) {
                     $rules = [
                         'user_nickname' => 'require',
                         'user_avatar'   => 'require',
@@ -107,6 +108,7 @@ class Register extends Api
                         'create_time'   => date('Y-m-d H:i:s', time()),
                         'user_tjtel'    => $params['user_tjtel'],
                         'user_openid'   => $params['user_openid'],
+                        'type'          => $params['type'],
                     );
                     $addUser = $userModel->allowField(true)->save($data);
                     if ($addUser) {
@@ -127,7 +129,7 @@ class Register extends Api
 
     /**
      * 手机号短信发送
-     *
+     * @ApiMethod   (POST)
      * @param string $user_tel 账号
      */
     public function registerTel()
@@ -216,4 +218,5 @@ class Register extends Api
         Cache::set($code, $code, 600);
         return $code;
     }
+
 }

+ 124 - 12
application/api/controller/User.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\api\model\Address;
+use app\api\model\Cashwechat;
 use app\api\model\Foot;
 use app\api\model\Realname;
 use app\api\model\Record;
@@ -31,7 +32,7 @@ class User extends Api
 
     /**
      * 用户显示
-     *
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      */
     public function userInfo()
@@ -52,7 +53,7 @@ class User extends Api
 
     /**
      * 修改昵称
-     *
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      * @param string $user_nickname 用户昵称
      */
@@ -79,7 +80,7 @@ class User extends Api
 
     /**
      * 修改密码
-     *
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      * @param string $user_pwd 用户密码
      * @param string $user_qrpwd 重复 密码
@@ -122,7 +123,7 @@ class User extends Api
 
     /**
      * 修改支付密码
-     *
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      * @param string $user_tel 手机号
      * @param string $code 验证码
@@ -186,6 +187,7 @@ class User extends Api
     /**
      * 实名认证
      *
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      * @param string $user_nickname 姓名
      * @param string $idcard 身份证号
@@ -219,6 +221,7 @@ class User extends Api
 
     /**
      * 常见问题
+     * @ApiMethod   (POST)
      */
     public function question()
     {
@@ -232,7 +235,7 @@ class User extends Api
 
     /**
      * 我的团队
-     *
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      */
     public function team()
@@ -258,7 +261,7 @@ class User extends Api
 
     /**
      * 我的地址
-     *
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      */
     public function address()
@@ -277,7 +280,7 @@ class User extends Api
 
     /**
      * 地址添加
-     *
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      * @param string $a_name 姓名
      * @param string $a_tel 手机号
@@ -328,6 +331,7 @@ class User extends Api
 
     /**
      * 地址修改
+     * @ApiMethod   (POST)
      * @param string $a_id 地址id
      * @param string $a_name 姓名
      * @param string $a_tel 手机号
@@ -356,6 +360,7 @@ class User extends Api
 
     /**
      * 地址删除
+     * @ApiMethod   (POST)
      * @param string $a_id 地址id
      */
     public function addressDel()
@@ -376,7 +381,7 @@ class User extends Api
 
     /**
      * 我的客服
-     *
+     * @ApiMethod   (POST)
      */
     public function coursetomer()
     {
@@ -390,6 +395,7 @@ class User extends Api
 
     /**
      * 我的红豆
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      */
     public function redbean()
@@ -408,6 +414,7 @@ class User extends Api
 
     /**
      * 我的红豆
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      * @param string $user_redbean 兑换个数
      */
@@ -468,6 +475,7 @@ class User extends Api
 
     /**
      * 我的红豆兑换记录
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      */
     public function redbeanRecord()
@@ -486,6 +494,7 @@ class User extends Api
 
     /**
      * 我的足迹显示
+     * @ApiMethod   (POST)
      * @param string $user_id 用户id
      */
     public function footIndex()
@@ -503,20 +512,123 @@ class User extends Api
             return $this->result('暂无数据', '', 100);
         }
     }
+
     /**
      * 我的足迹删除
+     * @ApiMethod   (POST)
      * @param string $f_id 足迹id
      */
-    public function footDel () {
+    public function footDel()
+    {
         $params = $this->request->post();
         if (!isset($params['f_id'])) {
             return $this->result('网络错误', [], 100);
         }
-        $footDel = Foot::where('f_id',$params['f_id'])->delete();
+        $footDel = Foot::where('f_id', $params['f_id'])->delete();
         if ($footDel) {
-            return $this->result('删除成功',[],200);
+            return $this->result('删除成功', [], 200);
+        } else {
+            return $this->result('删除失败', [], 100);
+        }
+    }
+
+    /**
+     * 会员提现价格显示
+     * @ApiMethod   (POST)
+     */
+    public function cashMoney()
+    {
+        $data = Db::name('cash_money')->select();
+        return $this->result('', $data, 200);
+    }
+
+    /**
+     * 会员提现到第几次
+     * @ApiMethod   (POST)
+     * @param string $user_id 用户id
+     */
+    public function cashIndex()
+    {
+        $params = $this->request->post();
+        if (!isset($params['user_id'])) {
+            return $this->result('网络错误', [], 100);
+        }
+        $data = UsersModel::Where('user_id', $params['user_id'])->field('user_id,cash_level')->find();
+        if ($data) {
+            return $this->result('', $data, 200);
         } else {
-            return $this->result('删除失败',[],100);
+            return $this->result('网络错误', '', 100);
+        }
+    }
+
+    /**
+     * 会员提现
+     * @ApiMethod   (POST)
+     * @param string $user_id 用户id
+     * @param string $money 金额
+     */
+    public function cash()
+    {
+        $params = $this->request->post();
+        $rules = [
+            'user_id' => 'require|number',
+            'money'   => 'require|number',
+        ];
+        $msg = [
+            'user_id.require' => '网络错误',
+            'money.require'   => '请选择提现金额',
+            'user_id.number'  => '网络错误',
+            'money.number'    => '网络错误',
+        ];
+        $validata = $this->validate($params,$rules,$msg);
+        if (is_string($validata)) {
+            return $this->result($validata,[],100);
+        }
+        if(!preg_match("/^[1-9][0-9]*$/" ,$params['money'])){
+            return $this->result('请输入正整数',[],100);
+        }
+//        //检测提现金额表中是否有这个金额
+        $is_money = Db::name('cash_money')->where('money',$params['money'])->find();
+//        if (!$is_money) {
+//            return $this->result('该金额暂不支持提现',[],100);
+//        }
+//        //判断是否该提现这个次数了
+        $user_cash_level = UsersModel::where('user_id',$params['user_id'])->find();
+//        if ($user_cash_level) {
+//            if ($user_cash_level['cash_level'] + 1 != 9) { //最后一个不算
+//                if($is_money['c_id'] != $user_cash_level['cash_level'] + 1) {
+//                    return $this->result('请按照顺序提现',[],100);
+//                }
+//            }
+//        }
+        if ($user_cash_level['user_money'] < $params['money']) {
+            return $this->result('余额不足',[],100);
+        }
+        if ($user_cash_level['type'] != 1) {
+            return $this->result('请先微信授权在提现',[],100);
+        }
+        Db::startTrans();
+        try{
+            $updMoney = UsersModel::where('user_id',$params['user_id'])->setDec('user_money',$params['money']);
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->result('网络错误,提现失败',[],100);
+        }
+        if ($updMoney) {
+            $number = rand(100,999).time();
+            $data = [
+                'user_id' => $params['user_id'],
+                'money' => $params['money'],
+                'state' => 1,
+                'create_time' => date('Y-m-d H:i:s',time()),
+                'number' => $number,
+            ];
+            $add_log = Db::name('cash_log')->insert($data);
+            $cashWeChat = new Cashwechat();
+            $res = $cashWeChat->sendMoney(1,"oRrdQt-L9A0WfDGT-nwHC24Er0tI",'余额提现',$user_cash_level['user_nickname'],$number);
+
+            return $res;
         }
     }
 }

+ 101 - 0
application/api/model/Cashwechat.php

@@ -0,0 +1,101 @@
+<?php
+namespace app\api\model;
+use think\Model;
+
+class Cashwechat extends Model
+{
+
+    public function sendMoney($amount,$re_openid,$desc='推荐奖励',$check_name='',$number){
+//        $total_amount = (100) * $amount;
+        $total_amount = $amount;
+        $data=array(
+            'mch_appid'=> 'wx032e75bf42061b96',//商户账号appid
+            'mchid'=> '1550903451',//商户号
+            'nonce_str'=> $this->createNoncestr(),//随机字符串
+            'partner_trade_no'=> $number,//商户订单号
+            'openid'=> $re_openid,//用户openid
+            'check_name'=>'NO_CHECK',//校验用户姓名选项,
+            're_user_name'=> $check_name,//收款用户姓名
+            'amount'=>$total_amount,//金额
+            'desc'=> $desc,//企业付款描述信息
+            'spbill_create_ip'=> '47.111.157.216',//Ip地址
+        );
+        $secrect_key = 'b3ae6bbf3cc4fa017eb169ae219e2c27';//API密码
+        $data = array_filter($data);
+        ksort($data);
+        $str ='';
+        foreach($data as $k=>$v) {
+            $str.=$k.'='.$v.'&';
+        }
+        $str.='key='.$secrect_key;
+        $data['sign'] = md5($str);
+        $xml = $this->arraytoxml($data);
+        $url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; //调用接口
+        $res = $this->wx_curl($xml,$url);
+        $return = $this->xmltoarray($res);
+
+        $responseObj = simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA);
+        halt($responseObj);
+        echo $res= $responseObj->return_code;  //SUCCESS  如果返回来SUCCESS,则发生成功,处理自己的逻辑
+        halt($res);
+        return $res;
+    }
+
+    public function createNoncestr($length =32){
+        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
+        $str ="";
+        for ( $i = 0; $i < $length; $i++ )  {
+            $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
+        }
+        return $str;
+    }
+
+    public function arraytoxml($data){
+        $str='<xml>';
+        foreach($data as $k=>$v) {
+            $str.='<'.$k.'>'.$v.'</'.$k.'>';
+        }
+        $str.='</xml>';
+        return $str;
+    }
+
+    public function xmltoarray($xml) {
+        //禁止引用外部xml实体
+        libxml_disable_entity_loader(true);
+        $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
+        $val = json_decode(json_encode($xmlstring),true);
+        return $val;
+    }
+
+    public function wx_curl($vars,$url,$second = 30, $aHeader = array())
+    {
+        $isdir = ROOT_PATH . "public/cert/";                  //证书位置
+        $ch = curl_init();                                               //初始化curl
+        curl_setopt($ch, CURLOPT_TIMEOUT, $second);                      //设置执行最长秒数
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);                     //要求结果为字符串且输出到屏幕上
+        curl_setopt($ch, CURLOPT_URL, $url);                             //抓取指定网页
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);                  // 终止从服务端进行验证
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);                 //
+        curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');                    //证书类型
+        curl_setopt($ch, CURLOPT_SSLCERT, $isdir . 'apiclient_cert.pem');//证书位置
+        curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');                     //CURLOPT_SSLKEY中规定的私钥的加密类型
+        curl_setopt($ch, CURLOPT_SSLKEY, $isdir . 'apiclient_key.pem');  //证书位置
+        if (count($aHeader) >= 1) {
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);//设置头部
+        }
+        curl_setopt($ch, CURLOPT_POST, 1);          //post提交方式
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);//全部数据使用HTTP协议中的"POST"操作来发送
+
+        $data = curl_exec($ch);//执行回话
+        if ($data) {
+            curl_close($ch);
+            return $data;
+        } else {
+            $error = curl_errno($ch);
+            echo "call faild, errorCode:$error\n";
+            curl_close($ch);
+            return false;
+        }
+
+    }
+}