Przeglądaj źródła

调整状态,优化充值上传

Jason 1 rok temu
rodzic
commit
fe69cd21d5

+ 2 - 2
application/admin/controller/user/User.php

@@ -65,8 +65,8 @@ class User extends Backend
                 $item->agent = $this->model->where('id', '=',  
                                 $path->where('user_id', $item->id)->where('is_agent', 1)->order('distance', 'desc')->value('parent_id'))
                              ->value('mobile');
-                $item->recharge = $in::where('status', 1)->where('user_id', $item->id)->sum('amount');
-                $item->withdraw = $out::where('status', 1)->where('user_id', $item->id)->sum('amount');
+                $item->recharge = $in::where('status', 200)->where('user_id', $item->id)->sum('amount');
+                $item->withdraw = $out::where('status', 200)->where('user_id', $item->id)->sum('amount');
             }  
             $result = array("total" => $list->total(), "rows" => $list->items());
 

+ 20 - 21
application/api/controller/Money.php

@@ -5,6 +5,7 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use app\common\model\Config;
 use app\common\model\MoneyIn;
+use app\common\model\MoneyOut;
 use app\common\model\Order AS OrderModel;
 use app\common\model\User AS UserModel;
 use think\Db;
@@ -29,7 +30,7 @@ class Money extends Api
 
         $data['amount_list'] = [100,200,500,1000,5000,10000];//快捷输入额度
         $data['usdt'] = $data['bank'] = 1;
-        $recharge_info = UserModel::getAgentInfoByAgentId($user['agent_id']);
+        $recharge_info = UserModel::getAgentRechargeInfoByAgentId($user['agent_id']);
         if(empty($recharge_info)){
             $this->error(__('无充值信息'));
         }
@@ -60,7 +61,7 @@ class Money extends Api
 
         $user = $this->auth->getUser();
 
-        $recharge_info = UserModel::getAgentInfoByAgentId($user['agent_id']);
+        $recharge_info = UserModel::getAgentRechargeInfoByAgentId($user['agent_id']);
         if(empty($recharge_info)){
             $this->error(__('无充值信息'));
         }
@@ -69,7 +70,7 @@ class Money extends Api
             'order_type' => $recharge_type,
             'user_id'   => $user['id'],
             'amount'    => $amount,
-            'status'    => 0,
+            'status'    => MoneyIn::Default,
             'agent_id'  => $recharge_info['agent_id']
         ];
 
@@ -140,16 +141,11 @@ class Money extends Api
         $user = $this->auth->getUser();
 
         $order_no = $this->request->post('order_no');
-        $img_url = $this->request->post('img_url');
 
         if (empty($order_no)) {
             $this->error(__('参数有误'));
         }
 
-        if (empty($img_url)) {
-            $this->error(__('参数有误'));
-        }
-
         $order_info = (new MoneyIn())
             ->where('user_id', $user['id'])
             ->where('order_no', $order_no)
@@ -158,7 +154,14 @@ class Money extends Api
             $this->error(__('参数有误'));
         }
 
-        if ($order_info['status'] != 0) {
+        //上传图片
+        $file_info = ali_oss_upload($this->request, 'recharge', $order_no);
+        if($file_info['code'] == 0){
+            $this->error($file_info['msg']);
+        }
+        $img_url = $file_info['data']['full_url'];
+
+        if ($order_info['status'] != MoneyIn::Default) {
             if (empty($order_info['img_url'])) {
                 (new MoneyIn())
                     ->where('order_no', $order_no)
@@ -173,7 +176,7 @@ class Money extends Api
             ->where('order_no', $order_no)
             ->update([
                 'img_url' => $img_url,
-                'status'  => 1,
+                'status'  => MoneyIn::Pending,
             ]);
         $this->success(__('提交成功'));
     }
@@ -186,18 +189,14 @@ class Money extends Api
     {
         $user = $this->auth->getUser();
 
-        $data['balance']    = $user['balance'];
-        $data['usdt'] = $data['bank'] = 1;
-        $recharge_info = UserModel::getAgentInfoByAgentId($user['agent_id']);
-        if(empty($recharge_info)){
-            $this->error(__('无充值信息'));
-        }
-        if(empty($recharge_info['usdt'])){
-            $data['usdt'] = 0;
-        }
-        if(empty($recharge_info['bank'])){
-            $data['bank'] = 0;
+        $data['balance']        = $user['balance'];
+        $data['money_out_sum']  = MoneyOut::where('user_id', $user['id'])->where('status', MoneyOut::Success)->sum('amount');
+
+        $withdraw_info = UserModel::getAgentWithdrawInfoByAgentId($user['agent_id']);
+        if(empty($withdraw_info)){
+            $this->error(__('无提现信息'));
         }
+        $data = array_merge($data, $withdraw_info);
 
         $this->success('', $data);
     }

+ 28 - 1
application/common/model/MoneyIn.php

@@ -23,7 +23,34 @@ class MoneyIn extends Model
         'create_time_text',
         'update_time_text'
     ];
-    
+
+    //状态
+    const Default   = 0;
+    const Pending   = 100;
+    const Success   = 200;
+    const Fail      = 400;
+    const Cancel    = 500;
+
+    /*
+     * 订单状态
+     */
+    public function getStatusNames($type = -1){
+        $status_names = [
+            '-1'                    => __('全部状态'),
+            self::Default           => __('待支付'),
+            self::Pending           => __('待处理'),
+            self::Success           => __('完成'),
+            self::Fail              => __('失败'),
+            self::Cancel            => __('取消'),
+        ];
+        if($type == -1){
+            return $status_names;
+        }
+        if(isset($status_names[$type])){
+            return $status_names[$type];
+        }
+        return __('未定义');
+    }
 
     //操作列表
     public function getTypeList()

+ 27 - 1
application/common/model/MoneyOut.php

@@ -23,8 +23,34 @@ class MoneyOut extends Model
         'create_time_text',
         'update_time_text'
     ];
-    
 
+    //状态
+    const Default   = 0;
+    const Pending   = 100;
+    const Success   = 200;
+    const Fail      = 400;
+    const Cancel    = 500;
+
+    /*
+     * 订单状态
+     */
+    public function getStatusNames($type = -1){
+        $status_names = [
+            '-1'                    => __('全部状态'),
+            self::Default           => __('默认'),
+            self::Pending           => __('待处理'),
+            self::Success           => __('完成'),
+            self::Fail              => __('失败'),
+            self::Cancel            => __('取消'),
+        ];
+        if($type == -1){
+            return $status_names;
+        }
+        if(isset($status_names[$type])){
+            return $status_names[$type];
+        }
+        return __('未定义');
+    }
     
     //操作列表
     public function getTypeList()

+ 27 - 1
application/common/model/User.php

@@ -52,7 +52,7 @@ class User extends Model
      * @param $invitation_code
      * @return array|null
      */
-    public static function getAgentInfoByAgentId($agent_id)
+    public static function getAgentRechargeInfoByAgentId($agent_id)
     {
         $data['usdt']     = '';
         $data['bank']     = [];
@@ -91,6 +91,32 @@ class User extends Model
         }
         return $data;
     }
+    /**
+     * 获取代理信息
+     * @param $invitation_code
+     * @return array|null
+     */
+    public static function getAgentWithdrawInfoByAgentId($agent_id)
+    {
+        $data['agent_id'] = $agent_id;
+        $info = self::where('id', $agent_id)
+            ->where('is_agent', 1)
+            ->where('is_lock', 0)
+            ->where('is_delete', 0)
+            ->find();
+        if(empty($info)){
+            //没找到代理时,默认显示系统配置
+            $data['usdt'] = (new Config())->getValue('withdraw_usdt_switch');
+            $data['bank'] = (new Config())->getValue('withdraw_bank_switch');
+            $data['agent_id'] = 0;
+            return $data;
+        }
+
+        $data['usdt'] = $info['agent_out_usdt'];
+        $data['bank'] = $info['agent_out_bank'];
+
+        return $data;
+    }
 
     /**
      * 获取个人URL

+ 1 - 1
public/assets/js/backend/trade/money_in.js

@@ -34,7 +34,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'account_name', title: __('Account_name'), operate: 'LIKE'},
                         {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                         {field: 'status', title: __("Status"), 
-                            searchList: {0:__('待支付'), 1:__('待处理'), 3:__('成功'), 2:__('取消')},
+                            searchList: {0:__('待支付'), 100:__('待处理'), 200:__('成功'), 400:__('失败'), 500:__('取消')},
                             formatter: Table.api.formatter.status
                         },
                         {field: 'admins.nickname', title: __('Admin_id')},