Explorar el Código

MT4交易密码修改

jace hace 6 años
padre
commit
eb6116e68a

+ 15 - 0
normandcrm/admin/backend/models/MemberApi.php

@@ -161,6 +161,21 @@ class MemberApi extends BaseApi
         return static::updateMember($id, $data);
     }
 
+
+    /**
+     * 修改MT4用户密码
+     * @param int $id
+     * @param string $password
+     * @return array
+     */
+    public function updateMtPassword($id, $password)
+    {
+        $data['mtpassword'] = $password;
+        return static::updateMember($id, $data);
+    }
+
+
+
     /**
      * 后台代理商列表
      * @param array $data

+ 16 - 0
normandcrm/admin/backend/models/forms/MemberForm.php

@@ -183,6 +183,22 @@ class MemberForm extends Model
         }
     }
 
+    //修改mt4密码
+    public function updateMtPassword($pwd)
+    {
+        if ($pwd == null || trim($pwd) === '') {
+            $this->addError('pwd', '密码不能为空');
+            return false;
+        }
+        $api = new MemberApi();
+        $result = $api->updateMtPassword($this->id, $pwd);
+        if ($result['code'] == 1) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
     public function updateIsEnable($enable)
     {
         if (!is_numeric($enable) || !in_array($enable, [0, 1])) {

+ 23 - 0
normandcrm/admin/backend/modules/admin/controllers/MemberController.php

@@ -138,6 +138,29 @@ class MemberController extends BaseController
         }
     }
 
+    /**
+     * 修改用户MT4密码
+     * @return \yii\web\Response
+     * @throws NotFoundHttpException
+     */
+    public function actionModifyMtpwd()
+    {
+        try {
+            $model = new MemberForm(Yii::$app->getRequest()->post('id'));
+        } catch (\Exception $e) {
+            throw new NotFoundHttpException($e->getMessage());
+        }
+        $pwd = trim(Yii::$app->getRequest()->post('pwd'));
+
+        if ($model->updateMtPassword($pwd)) {
+            return $this->asJson(['isSuccess' => true, 'msg' => '操作成功']);
+        } else {
+            return $this->asJson(['isSuccess' => false, 'msg' => '操作失败']);
+        }
+    }
+
+    
+
     /**
      * 修改用户信息
      * @return \yii\web\Response

+ 42 - 0
normandcrm/admin/backend/modules/admin/views/member/view.php

@@ -49,6 +49,12 @@ use yii\helpers\Url;
                             <span onclick="modifyPwd()" class="input-group-addon">提交</span>
                         </div>
                         <div class="hr-line-dashed"></div>
+                        <div class="input-group">
+                            <span class="input-group-addon">修改MT4交易密码</span>
+                            <input id="modifyMtPwd" type="text" class="form-control">
+                            <span onclick="modifyMtPwd()" class="input-group-addon">提交</span>
+                        </div>
+                        <div class="hr-line-dashed"></div>
                         <div class="table-responsive">
                             <table class="table table-bordered">
                                 <!--
@@ -246,5 +252,41 @@ use yii\helpers\Url;
         }
     }
 
+    // mt4交易密码的函数
+    function modifyMtPwd(){
+        var pwd=$("#modifyMtPwd").val();
+        var reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{7,16}$/;
+        if(!reg.test(pwd)){
+            toastr.error('密码必须包含大小写和数字', "提示");
+            return;
+        }
+
+        if(pwd.length>0){
+            $.ajax({
+                type: "POST",
+                url: "<?= Url::to(['modify-mtpwd']) ?>",
+                data: {
+                    pwd:pwd,
+                    id:'<?= $member['id'] ?>'
+                },
+                dataType: "json",
+                beforeSend: function() {},
+                success: function(data) {
+
+                    if(data.isSuccess){
+                        toastr.success(data.msg, "提示");
+                    }else{
+                        toastr.error(data.msg, "提示");
+                    }
+
+                },
+                complete: function(XMLHttpRequest, textStatus) {
+                    $("#modifyMtPwd").val("");
+                },
+                error: function() {}
+            });
+        }
+    }
+
 </script>
 <?php $this->endBlock();?>

+ 30 - 0
normandcrm/service/backend/controllers/MemberController.php

@@ -8,6 +8,7 @@ use backend\models\Mt4Users;
 use backend\models\Open;
 use backend\models\UserMember;
 use backend\helpers\LogHelper;
+use common\lib\Mt4ManagerApi;
 use Yii;
 
 class MemberController extends BaseController
@@ -168,6 +169,35 @@ class MemberController extends BaseController
             return $this->outJson(0, [], '用户不存在');
         }
         $data = Yii::$app->getRequest()->post();
+        
+
+
+        if(isset($data['mtpassword']) && trim($data['mtpassword']) != '') {
+
+            // 对密码进行校验
+            if(preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{7,16}$/',$data['mtpassword'])){
+               
+                // open表的mt4_login_pwd更新
+                $openModel = Open::find()->where(['member_id' => $data['id']])->limit(1)->one();
+                $openModel->mt4_login_pwd = $data['mtpassword'];
+                $res1 = $openModel->save();
+                // 调用mt4更新方法
+                $Mt4ManagerApi = new Mt4ManagerApi();
+                $res2 = $Mt4ManagerApi->changePassword($openModel->mt4_login,$data['mtpassword']);
+                // 成功
+                if($res1&& !$res2){
+                    return $this->outJson(1, [], '操作成功');
+                }
+
+            }else{
+
+                return $this->outJson(0, [], '操作失败');
+
+            }
+
+            
+        }
+
 
         $username_num = Member::find()->select(['username'])->where(['username' => $data['username']])->andWhere(['!=', 'id', $data['id']])->limit(1)->asArray()->scalar();
         if ($username_num) {