浏览代码

充值(部分完成)

theo 3 年之前
父节点
当前提交
9f0d97e60b

+ 1 - 0
backendApi/modules/v1/models/lists/finance/RechargeList.php

@@ -123,6 +123,7 @@ class RechargeList extends \common\libs\dataList\DataList implements DataListInt
                 'SN' => ['isUserTable' => false, 'name' => '充值记录流水号'],
                 'USER_NAME' => ['isUserTable' => false, 'name' => '会员编号'],
                 'AUDIT_STATUS' => ['isUserTable' => false, 'name' => '审核状态', 'other' => 'select', 'selectData' => [['id' =>0, 'name' => '待审核'], ['id' => 1, 'name' => '已上传凭证'], ['id' => 2, 'name' => '已审核']]],
+                'RECHARGE_STATUS' => ['isUserTable' => false, 'name' => '充值状态', 'other' => 'select', 'selectData' => [['id' =>0, 'name' => 'New'], ['id' => 1, 'name' => 'Processing'], ['id' => 2, 'name' => 'Success']]],
                 'BANK_NO' => ['isUserTable' => false, 'name' => '汇款账号'],
                 'AMOUNT' => ['isUserTable' => false, 'name' => '充值金额'],
                 'CREATED_AT' => ['isUserTable' => false, 'name' => '申请时间', 'other' => 'date'],

+ 33 - 0
common/helpers/PayStack.php

@@ -4,6 +4,39 @@ namespace common\helpers;
 
 class PayStack
 {
+    /**
+     *
+     */
+    public static function transactionInit($currency, $amount, $email){
+        $secretKey = \Yii::$app->Paystack->testSecretKey;
+        $url = "https://api.paystack.co/transaction/initialize";
+        $fields = [
+            'email' => $email,
+            'amount' => $amount * 100
+        ];
+        $fields_string = http_build_query($fields);
+        //open connection
+        $ch = curl_init();
+
+        //set the url, number of POST vars, POST data
+        curl_setopt($ch,CURLOPT_URL, $url);
+        curl_setopt($ch,CURLOPT_POST, true);
+        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+            "Authorization: Bearer {$secretKey}",
+            "Cache-Control: no-cache",
+        ));
+        //So that curl_exec returns the contents of the cURL; rather than echoing it
+        curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
+        //execute post
+        $result = curl_exec($ch);
+        $result =  json_decode($result, true);
+        return [
+            'status'    => $result['status'],
+            'message'   => $result['message'],
+            'data'      => $result['data'],
+        ];
+    }
     /**
      * 交易支付.
      * @param $ref

+ 44 - 1
common/models/Recharge.php

@@ -15,7 +15,10 @@ use Yii;
  * @property int $RECHARGE_PERIOD_NUM 充值期数
  * @property int $RECHARGE_YEAR 充值年份
  * @property int $RECHARGE_MONTH 充值月份
+ * @property string $CURRENCY 货币(尼日利亚默认NGN)
  * @property string $AMOUNT 充值金额
+ * @property string $RECHARGE_ORDER_ID PS订单号
+ * @property int $RECHARGE_STATUS 充值状态
  * @property string $REAL_NAME 会员姓名
  * @property string $OPEN_BANK 开户行
  * @property string $BANK_ADDRESS 开户支行
@@ -42,6 +45,11 @@ class Recharge extends \common\components\ActiveRecord {
     const STATUS_AUDITED = 2;       // 已审核
     const STATUS_REFUSED = 3;       // 已拒绝
 
+    const STATUS_NEW = 0;
+    const STATUS_PROCESSING = 1;
+    const STATUS_SUCCESS = 2;
+    const STATUS_REJECT = 3;
+
     const STATUS_NAME = [
         self::STATUS_APPLIED => '待审核',
         self::STATUS_PROVED => '已上传凭证',
@@ -49,6 +57,12 @@ class Recharge extends \common\components\ActiveRecord {
         self::STATUS_REFUSED => '已拒绝',
     ];
 
+    const RECHARGE_STATUS_NAME = [
+        self::STATUS_NEW => 'NEW',
+        self::STATUS_PROCESSING => 'PROCESSING',
+        self::STATUS_SUCCESS => 'SUCCESS',
+        self::STATUS_REJECT => 'FAILED',
+    ];
     /**
      * @inheritdoc
      */
@@ -85,6 +99,7 @@ class Recharge extends \common\components\ActiveRecord {
             'RECHARGE_PERIOD_NUM' => '充值期数',
             'RECHARGE_YEAR' => '充值年份',
             'RECHARGE_MONTH' => '充值月份',
+            'CURRENCY' => '货币',
             'AMOUNT' => '充值金额',
             'REAL_NAME' => '会员姓名',
             'OPEN_BANK' => '汇款银行',
@@ -187,5 +202,33 @@ class Recharge extends \common\components\ActiveRecord {
         $total = self::find()->where('AUDIT_STATUS=:AUDIT_STATUS', [':AUDIT_STATUS' => $type])->sum('AMOUNT');
         return $total ? $total : '0.00';
     }
-
+    /**
+     *
+     */
+    public static function sendToPaystack(){
+        $url = "https://api.paystack.co/transaction/initialize";
+        $am = random_int(100, 4000);
+        $fields = [
+            'email' => "fl@bd.com",
+            'amount' => $am
+        ];
+        $fields_string = http_build_query($fields);
+        //open connection
+        $ch = curl_init();
+        $sk = 'sk_test_1d16378c8be9efabc71b05754190b9c3f6999402'; //taisino
+        //$sk = 'sk_test_5ece72377432376f5cf6bb5c468395a650220309'; //elken
+        //set the url, number of POST vars, POST data
+        curl_setopt($ch,CURLOPT_URL, $url);
+        curl_setopt($ch,CURLOPT_POST, true);
+        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+            "Authorization: Bearer $sk",
+            "Cache-Control: no-cache",
+        ));
+        //So that curl_exec returns the contents of the cURL; rather than echoing it
+        curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
+        //execute post
+        //$result = curl_exec($ch);
+        echo $result;
+    }
 }

+ 21 - 8
common/models/forms/RechargeForm.php

@@ -6,6 +6,7 @@ use common\components\Model;
 use common\helpers\Cache;
 use common\helpers\Date;
 use common\helpers\Form;
+use common\helpers\PayStack;
 use common\helpers\Tool;
 use common\helpers\user\Cash;
 use common\helpers\user\Info;
@@ -31,6 +32,7 @@ class RechargeForm extends Model {
 //    public $bankCounty;
 
     public $sn;
+    public $currency;
     public $amount;
     public $bankRealName;
 
@@ -42,7 +44,7 @@ class RechargeForm extends Model {
     public function rules() {
         return [
             [['userName', 'idCard', 'applyAmount', 'auditStatus', 'remark', 'selectedIds', 'sn','amount', 'bankRealName', 'bankNo'], 'trim'],
-            [['selectedIds', 'auditStatus', 'userName','applyAmount','openBank','bankNo','bankAddress'], 'required'],
+            [['selectedIds', 'auditStatus', 'userName','applyAmount', 'currency'/*,'openBank','bankNo','bankAddress'*/], 'required'],
             [['selectedIds'], 'exist', 'targetClass' => Recharge::class, 'targetAttribute' => 'ID', 'message' => '充值申请不存在'],
             [['userName'], 'exist', 'targetClass' => UserInfo::class, 'targetAttribute' => 'USER_NAME', 'message' => '会员不存在'],
             [['applyAmount'], 'price'],
@@ -60,7 +62,7 @@ class RechargeForm extends Model {
         $parentScenarios = parent::scenarios();
         $customScenarios = [
             'addByAdmin' => ['userName', 'applyAmount'],
-            'addByUser' => ['applyAmount','openBank','bankNo','bankAddress'],
+            'addByUser' => ['applyAmount','openBank','bankNo','bankAddress','currency'],
             'statusByAdmin' => ['selectedIds', 'auditStatus', 'createRemark'],
         ];
         return array_merge($parentScenarios, $customScenarios);
@@ -74,9 +76,10 @@ class RechargeForm extends Model {
             'selectedIds' => '充值申请ID',
             'userName' => '会员编号',
             'applyAmount' => '申请充值的金额',
-            'openBank' => '汇款银行',
-            'bankNo' => '汇款账号',
-            'bankAddress' => '银行支行',
+//            'openBank' => '汇款银行',
+//            'bankNo' => '汇款账号',
+//            'bankAddress' => '银行支行',
+            'currency' => '货币',
 //            'bankProvince' => '银行省',
 //            'bankCity' => '银行市',
 //            'bankCounty' => '银行县',
@@ -185,6 +188,12 @@ class RechargeForm extends Model {
         }
         $db = \Yii::$app->db;
         $transaction = $db->beginTransaction();
+        // 向paystack发起订单
+        $userInfo = Info::baseInfo($this->_userId);
+        $rechargeOrder = PayStack::transactionInit($this->currency, $this->applyAmount, $userInfo['EMAIL']);
+        if($rechargeOrder['status']!=1){
+            throw new Exception('api error');
+        }
         try {
             $nowTime = Date::nowTime();
             $period = Recharge::getPeriod($nowTime);
@@ -199,10 +208,14 @@ class RechargeForm extends Model {
             $rechargeModel->RECHARGE_PERIOD_NUM = $period['nowPeriodNum'];
             $rechargeModel->RECHARGE_YEAR = $period['nowYear'];
             $rechargeModel->RECHARGE_MONTH = $period['nowMonth'];
+            $rechargeModel->CURRENCY = $this->currency;
             $rechargeModel->AMOUNT = $this->applyAmount;
-            $rechargeModel->OPEN_BANK = $this->openBank;
-            $rechargeModel->BANK_ADDRESS = $this->bankAddress;
-            $rechargeModel->BANK_NO = $this->bankNo;
+            $rechargeModel->RECHARGE_REF = $rechargeOrder['data']['reference'];
+            $rechargeModel->RECHARGE_ORDER_ID = $rechargeOrder['data']['access_code'];
+            $rechargeModel->RECHARGE_STATUS = 0;
+            $rechargeModel->OPEN_BANK = 'a';
+            $rechargeModel->BANK_ADDRESS = 'b';
+            $rechargeModel->BANK_NO = 'c';
 //            $rechargeModel->BANK_PROVINCE = $this->bankProvince ?? 0;
 //            $rechargeModel->BANK_CITY = $this->bankCity ?? 0;
 //            $rechargeModel->BANK_COUNTY = $this->bankCounty ?? 0;

+ 2 - 2
frontendApi/config/menu.php

@@ -94,9 +94,9 @@ return [
             ['name'=>'转账记录', 'class'=>'', 'icon'=>'', 'controller'=>'finance', 'action'=>'transfer-list', 'routePath'=>'finance/transfer-list', 'show'=>1,'allow'=>'transferRecordSwitch'],
             ['name'=>'我要转账', 'class'=>'', 'icon'=>'', 'controller'=>'finance', 'action'=>'transfer-add', 'routePath'=>'finance/transfer-add', 'show'=>1,'allow'=>'transferSwitch'],
             ['name'=>'提现明细', 'class'=>'', 'icon'=>'', 'controller'=>'finance', 'action'=>'withdraw', 'routePath'=>'finance/withdraw', 'show'=>1,],
-            ['name'=>'申请提现', 'class'=>'', 'icon'=>'', 'controller'=>'finance', 'action'=>'withdraw-add', 'routePath'=>'finance/withdraw-add', 'show'=>0,],
+            ['name'=>'申请提现', 'class'=>'', 'icon'=>'', 'controller'=>'finance', 'action'=>'withdraw-add', 'routePath'=>'finance/withdraw-add', 'show'=>1,],
             ['name'=>'充值明细', 'class'=>'', 'icon'=>'', 'controller'=>'finance', 'action'=>'recharge', 'routePath'=>'finance/recharge', 'show'=>1,],
-            ['name'=>'申请充值', 'class'=>'', 'icon'=>'', 'controller'=>'finance', 'action'=>'recharge-add', 'routePath'=>'finance/recharge-add', 'show'=>0,],
+            ['name'=>'申请充值', 'class'=>'', 'icon'=>'', 'controller'=>'finance', 'action'=>'recharge-add', 'routePath'=>'finance/recharge-add', 'show'=>1,],
         ]
     ],
     'article'=>[

+ 2 - 2
frontendApi/modules/v1/controllers/FinanceController.php

@@ -489,11 +489,11 @@ class FinanceController extends BaseController {
             'orderBy' => 'CREATED_AT DESC',
         ]);
         foreach ($data['list'] as $key => $value) {
-            $data['list'][$key]['OPEN_BANK_NAME'] = $value['OPEN_BANK'] ? OpenBank::getCnName($value['OPEN_BANK']) : '';
+//            $data['list'][$key]['OPEN_BANK_NAME'] = $value['OPEN_BANK'] ? OpenBank::getCnName($value['OPEN_BANK']) : '';
             //$data['list'][$key]['BANK_PROVINCE_NAME'] = $value['BANK_PROVINCE'] ? Region::getCnName($value['BANK_PROVINCE']) : '';
             //$data['list'][$key]['BANK_CITY_NAME'] = $value['BANK_CITY'] ? Region::getCnName($value['BANK_CITY']) : '';
             //$data['list'][$key]['BANK_COUNTY_NAME'] = $value['BANK_COUNTY'] ? Region::getCnName($value['BANK_COUNTY']) : '';
-            $data['list'][$key]['STATUS_NAME'] = Recharge::STATUS_NAME[$value['AUDIT_STATUS']];
+            $data['list'][$key]['STATUS_NAME'] = Recharge::RECHARGE_STATUS_NAME[$value['RECHARGE_STATUS']];
         }
         return static::notice($data);
     }

+ 80 - 89
frontendEle/src/views/finance/recharge-add.vue

@@ -1,100 +1,91 @@
 <template>
-    <div v-loading="loading">
-        <div class="white-box">
-            <el-form ref="form"  label-width="250px" class="form-page">
-                <el-form-item label="充值金额">
-                    <el-input v-model="form.applyAmount"></el-input>
-                </el-form-item>
-                <el-form-item label="银行账号">
-                    <el-input v-model="form.bankNo"></el-input>
-                </el-form-item>
-                <el-form-item label="汇款银行">
-                    <el-select v-model="form.openBank" placeholder="请选择开户行">
-                        <el-option v-for="(item,index) in allOpenBank" :key="index" :label="item.BANK_NAME"
-                                   :value="item.BANK_CODE"></el-option>
-                    </el-select>
-                </el-form-item>
-
-                <el-form-item label="开户支行">
-                    <el-input v-model="form.bankAddress"></el-input>
-                </el-form-item>
-
-                <el-form-item>
-                    <el-button type="primary" @click="onSubmits" :loading="submitButtonStat">保存</el-button>
-                </el-form-item>
-            </el-form>
-        </div>
+  <div v-loading="loading">
+    <div class="white-box">
+      <el-form ref="form"  label-width="250px" class="form-page">
+        <el-form-item label="货币">
+          <el-select v-model="form.currency" placeholder="请选择">
+            <el-option
+              v-for="item in currencyList"
+              :key="item.value"
+              :label="item.label"
+              :value="item.value">
+            </el-option>
+          </el-select>
+        </el-form-item>
+        <el-form-item label="充值金额">
+            <el-input v-model="form.applyAmount"></el-input>
+        </el-form-item>
+        <el-form-item>
+            <el-button type="primary" @click="onSubmits" :loading="submitButtonStat">保存</el-button>
+        </el-form-item>
+      </el-form>
     </div>
+  </div>
 </template>
 
 <script>
-    import Vue from 'vue'
-    import network from '@/utils/network'
-    import baseInfo from '@/utils/baseInfo'
-    import store from '@/utils/vuexStore'
-    export default {
-        name: "recharge-add",
-        mounted() {
-            this.getData()
-        },
-        data(){
-            return{
-
-                form:{
-                    applyAmount:'',
-                    bankNo:'',
-                    bankAddress:'',
-                    openBank:'',
-
-
-                },
-                loading: false,
-                allOpenBank: null,
-                submitButtonStat: false
-            }
-        },
-        methods: {
-            getData () {
-
-                network.getData(`/finance/recharge-add`).then(response => {
-                    console.log(response)
-                    this.loading = false;
-                    this.allOpenBank = response.allOpenBank;
-
-                }).catch(() => {
-                });
-
-            },
-            onSubmits() {
-                this.submitButtonStat = true
-                let path = '/finance/recharge-add'
-                let postData = {
-                    openBank: this.form.openBank,
-                    bankAddress: this.form.bankAddress,
-                    bankNo: this.form.bankNo,
-                    applyAmount: this.form.applyAmount,
-
-
-                };
-
-                return network.postData(path, postData).then(response => {
-                    console.log(response);
-                    this.$message({
-                        message: response,
-                        type: 'success'
-                    })
-                    this.submitButtonStat = false
-                    this.$router.go(-1)
-                }).catch(() => {
-                    this.submitButtonStat = false
-                })
-            },
+import Vue from 'vue'
+import network from '@/utils/network'
+import baseInfo from '@/utils/baseInfo'
+import store from '@/utils/vuexStore'
+export default {
+  name: "recharge-add",
+  mounted() {
+    this.getData()
+  },
+  data(){
+    return{
+      currencyList: {
+        'NGN': {
+          'value': 'NGN',
+          'label': 'Nigeria naira (NGN)'
         }
-
-
+      },
+      form:{
+        currency: 'NGN',
+        applyAmount: '',
+        // bankNo: '',
+        // bankAddress: '',
+        // openBank: '',
+      },
+      loading: false,
+      allOpenBank: null,
+      submitButtonStat: false
     }
+  },
+  methods: {
+    getData () {
+      network.getData(`/finance/recharge-add`).then(response => {
+        console.log(response)
+        this.loading = false;
+        this.allOpenBank = response.allOpenBank;
+      }).catch(() => {
+      });
+    },
+    onSubmits() {
+      this.submitButtonStat = true
+      let path = '/finance/recharge-add'
+      let postData = {
+        currency: this.form.currency,
+        applyAmount: this.form.applyAmount,
+      };
+      return network.postData(path, postData).then(response => {
+        // console.log(postData)
+        // console.log(response);
+        this.$message({
+          message: response,
+          type: 'success'
+        })
+        this.submitButtonStat = false
+        this.$router.go(-1)
+      }).catch(() => {
+        this.submitButtonStat = false
+      })
+    },
+  }
+}
 </script>
 
 <style scoped>
 
-</style>
+</style>

+ 36 - 24
frontendEle/src/views/finance/recharge.vue

@@ -3,43 +3,55 @@
         <div v-loading="loading">
             <div class="white-box">
                 <el-table class="withdraw-table" :data="tableData" stripe style="width: 100%;">
-
-                    <el-table-column label="创建时间">
+                    <el-table-column label="SN" prop="SN" width="200px"><!--货币名称-->
+                    </el-table-column>
+                    <el-table-column label="创建时间" width="160px">
                         <template slot-scope="scope">
                             {{tool.formatDate(scope.row.CREATED_AT)}}
                         </template>
                     </el-table-column>
 
-                    <el-table-column label="充值金额" prop="AMOUNT">
+<!--                    <el-table-column label="RECHARGE ORDER ID" prop="RECHARGE_ORDER_ID" width="200px">&lt;!&ndash;PS订单ID&ndash;&gt;-->
+<!--                    </el-table-column>-->
 
+                    <el-table-column label="CURRENCY" prop="CURRENCY" width="100px"><!--货币名称-->
                     </el-table-column>
 
-                    <el-table-column label="充值状态名称">
-                        <template slot-scope="scope">
-                        <el-tag :type="tool.statusType(scope.row.AUDIT_STATUS)">{{scope.row.STATUS_NAME}}</el-tag>
-                        </template>
+                    <el-table-column label="充值金额" prop="AMOUNT" width="150px">
                     </el-table-column>
-                    <el-table-column label="汇款银行" prop="OPEN_BANK_NAME">
 
+                    <el-table-column label="充值状态" width="200px">
+                      <template slot-scope="scope">
+                        <el-tag :type="tool.statusType(scope.row.RECHARGE_STATUS)">{{scope.row.STATUS_NAME}}</el-tag>
+                      </template>
                     </el-table-column>
 
-                    <el-table-column label="我的汇款账号" prop="BANK_NO">
-
+                    <el-table-column label="动作">
+                      <template slot-scope="scope">
+<!--                        <el-button type="primary" plain>主要按钮</el-button>-->
+<!--                        <el-button type="success" plain>成功按钮</el-button>-->
+<!--                        <el-button type="info" plain>信息按钮</el-button>-->
+<!--                        <el-button type="warning" plain>警告按钮</el-button>-->
+<!--                        <el-button type="danger" plain>危险按钮</el-button>-->
+                        <template v-if="scope.row.RECHARGE_STATUS==0">
+                          <el-button type="primary" plain>去支付</el-button>
+                          <el-button type="info" plain disabled>验证</el-button>
+                        </template>
+                        <template v-else-if="scope.row.RECHARGE_STATUS==1">
+                          <el-button type="info" plain disabled>已支付</el-button>
+                          <el-button type="primary" plain>验证</el-button>
+                        </template>
+                        <template v-else-if="scope.row.RECHARGE_STATUS==2">
+                          <el-button type="info" plain disabled>已支付</el-button>
+                          <el-button type="info" plain disabled>已验证</el-button>
+                        </template>
+                        <template v-else>
+                          <el-button type="danger" plain disabled>支付失败</el-button>
+                          <el-button type="danger" plain disabled>验证</el-button>
+                        </template>
+                      </template>
                     </el-table-column>
 
-                      <el-table-column label="打印凭证" width="200">
-                            <template slot-scope="scope">
-                                <el-button type="primary" size="small" @click="handleAddInvoiceShow(scope.row)"
-                                           v-if="scope.row.AUDIT_STATUS==='0'" icon="el-icon-upload">上传凭证
-                                </el-button>
-
-                                <el-button type="success" size="small" @click="handleInvoiceShow(scope.row)"
-                                           v-if="scope.row.AUDIT_STATUS!=='0'" icon="el-icon-view">查看凭证
-                                </el-button>
-                            </template>
-                        </el-table-column>
-
-
                 </el-table>
                 <div class="white-box-footer">
                     <el-button type="primary" size="small" @click="handleAdd">我要充值</el-button>
@@ -215,4 +227,4 @@
 
 <style scoped>
 
-</style>
+</style>