作者 何书鹏
1 个管道 的构建 通过 耗费 5 秒

api更新

... ... @@ -125,7 +125,27 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">充值积分每分需多少元:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score_price" class="form-control" name="row[score_recharge_price]" type="number" value="{$row.score_recharge_price}">
<input id="c-score_recharge_price" class="form-control" name="row[score_recharge_price]" type="number" value="{$row.score_recharge_price}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">客服二维码:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-service_qrcode" class="form-control" size="35" name="row[service_qrcode]" type="text" value="{$row.service_qrcode}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-service_qrcode" class="btn btn-danger plupload" data-input-id="c-service_qrcode" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-service_qrcode"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-service_qrcode" class="btn btn-primary fachoose" data-input-id="c-service_qrcode" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right"></span>
</div>
<ul class="row list-inline plupload-preview" id="p-service_qrcode"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">客服电话:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-service_phone" class="form-control" name="row[service_phone]" type="text" value="{$row.service_phone}">
</div>
</div>
<div class="form-group layer-footer">
... ...
... ... @@ -799,6 +799,11 @@ class Company extends Api
// 创建订单
$model = new PackageOrder;
$model->add($this->auth->getUser(), $param['pay_type']);
// 零元直接支付成功
if($model['pay_price'] <= 0){
(new Notify)->notifyPackageZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
$this->success('成功',[]);
}
//回调链接
$notifyurl = $this->request->root(true) . '/mobile/notify/notifyPackage/paytype/' . $param['pay_type'];
$model['pay_price'] = 0.01; //测试金额
... ...
... ... @@ -434,6 +434,28 @@ class Course extends Api
}
/**
* @ApiTitle (联系客服)
* @ApiSummary (联系客服)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1606961557",
"data": {
"service_qrcode": "http://qizhibang.brotop.cn/uploads/20200811/b9bbd60dcacbcb649579155f63b62558.png", //客服二维码
"service_phone": "0311-28907" //客服电话
}
})
*/
public function service()
{
$config = Db::name('mobile_config')->where('id',1)->field('service_qrcode,service_phone')->find();
$config['service_qrcode'] = !empty($config['service_qrcode']) ? cdnurl($config['service_qrcode'],true) : '';
$this->success('成功', $config);
}
/**
* @ApiTitle (购买预览)
* @ApiSummary (购买预览)
* @ApiMethod (POST)
... ... @@ -507,6 +529,11 @@ class Course extends Api
// 创建订单
$model = new CourseOrder;
$model->add($this->auth->getUser(), $order, $param['pay_type']);
// 零元直接支付成功
if($model['pay_price'] <= 0){
(new Notify)->notifyCourseZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
$this->success('成功',[]);
}
//回调链接
$notifyurl = $this->request->root(true) . '/mobile/notify/notifyCourse/paytype/' . $param['pay_type'];
$model['pay_price'] = 0.01; //测试金额
... ...
... ... @@ -25,7 +25,7 @@ class Notify extends Api
}
/**
* 课程
* 课程---------------------------------------------------------------------
*/
public function notifyCourse()
{
... ... @@ -39,21 +39,50 @@ class Notify extends Api
try {
$payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
$out_trade_no = $data['out_trade_no'];
// 处理订单逻辑
$order = CourseOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
// 学习人数加1
Db::name('mobile_course')->where('id',$order['course_id'])->setInc('study_num_real');
}
// 处理订单
$this->handleCourseOrder($out_trade_no,$payamount,$paytype);
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 密卷
* 课程-零元支付
*/
public function notifyCourseZero($out_trade_no,$payamount,$paytype)
{
Db::startTrans();
try {
$this->handleCourseOrder($out_trade_no,$payamount,$paytype);
Db::commit();
} catch (\think\exception\PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
return false;
} catch (\think\Exception $e) {
Db::rollback();
$this->error($e->getMessage());
return false;
}
return true;
}
/**
* 课程-处理订单
*/
private function handleCourseOrder($out_trade_no,$payamount,$paytype){
// 处理订单逻辑
$order = CourseOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
// 学习人数加1
Db::name('mobile_course')->where('id',$order['course_id'])->setInc('study_num_real');
}
return true;
}
/**
* 密卷-----------------------------------------------------------------------
*/
public function notifySecret()
{
... ... @@ -68,20 +97,50 @@ class Notify extends Api
$payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
$out_trade_no = $data['out_trade_no'];
// 处理订单逻辑
$order = SecretOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
// 购买量加1
Db::name('mobile_secret')->where('id',$order['course_id'])->setInc('buy_num_real');
}
//处理订单
$this->handleSecretOrder($out_trade_no,$payamount,$paytype);
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 积分
* 密卷-零元支付
*/
public function notifySecretZero($out_trade_no,$payamount,$paytype)
{
Db::startTrans();
try {
$this->handleSecretOrder($out_trade_no,$payamount,$paytype);
Db::commit();
} catch (\think\exception\PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
return false;
} catch (\think\Exception $e) {
Db::rollback();
$this->error($e->getMessage());
return false;
}
return true;
}
/**
* 密卷-处理订单
*/
private function handleSecretOrder($out_trade_no,$payamount,$paytype){
// 处理订单逻辑
$order = SecretOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
// 购买量加1
Db::name('mobile_secret')->where('id',$order['course_id'])->setInc('buy_num_real');
}
return true;
}
/**
* 积分----------------------------------------------------------------------
*/
public function notifyScore()
{
... ... @@ -96,20 +155,50 @@ class Notify extends Api
$payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
$out_trade_no = $data['out_trade_no'];
// 处理订单逻辑
$order = ScoreOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
// 增加积分
\app\common\model\User::score($order['score'],$order['user_id'],'充值积分');
}
// 处理订单
$this->handleScoreOrder($out_trade_no,$payamount,$paytype);
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 企业套餐
* 积分-零元支付
*/
public function notifyScoreZero($out_trade_no,$payamount,$paytype)
{
Db::startTrans();
try {
$this->handleScoreOrder($out_trade_no,$payamount,$paytype);
Db::commit();
} catch (\think\exception\PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
return false;
} catch (\think\Exception $e) {
Db::rollback();
$this->error($e->getMessage());
return false;
}
return true;
}
/**
* 积分-处理订单
*/
private function handleScoreOrder($out_trade_no,$payamount,$paytype){
// 处理订单逻辑
$order = ScoreOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
// 增加积分
\app\common\model\User::score($order['score'],$order['user_id'],'充值积分');
}
return true;
}
/**
* 企业套餐---------------------------------------------------------------------
*/
public function notifyPackage()
{
... ... @@ -125,20 +214,50 @@ class Notify extends Api
$out_trade_no = $data['out_trade_no'];
// 处理订单逻辑
$order = PackageOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
foreach ($order['package'] as $v){
// 购买量加1
Db::name('mobile_package')->where('id',$v['package_id'])->setInc('buy_num_real');
}
}
$this->handlePackageOrder($out_trade_no,$payamount,$paytype);
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 企业套餐-零元支付
*/
public function notifyPackageZero($out_trade_no,$payamount,$paytype)
{
Db::startTrans();
try {
$this->handlePackageOrder($out_trade_no,$payamount,$paytype);
Db::commit();
} catch (\think\exception\PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
return false;
} catch (\think\Exception $e) {
Db::rollback();
$this->error($e->getMessage());
return false;
}
return true;
}
/**
* 企业套餐-处理订单
*/
private function handlePackageOrder($out_trade_no,$payamount,$paytype){
// 处理订单逻辑
$order = PackageOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
foreach ($order['package'] as $v){
// 购买量加1
Db::name('mobile_package')->where('id',$v['package_id'])->setInc('buy_num_real');
}
}
return true;
}
/**
* 七牛云音频转码通知回调
* @ApiInternal
*/
... ...
... ... @@ -311,6 +311,11 @@ class Secret extends Api
// 创建订单
$model = new SecretOrder;
$model->add($this->auth->getUser(), $order, $param['pay_type']);
// 零元直接支付成功
if($model['pay_price'] <= 0){
(new Notify)->notifySecretZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
$this->success('成功',[]);
}
//回调链接
$notifyurl = $this->request->root(true) . '/mobile/notify/notifySecret/paytype/' . $param['pay_type'];
$model['pay_price'] = 0.01; //测试金额
... ...
... ... @@ -19,7 +19,7 @@ class Sms extends Api
* 发送验证码
*
* @param string $mobile 手机号
* @param string $event 事件名称:register=注册,resetpwd=忘记密码,changemobile1=修改手机号第一步,changemobile2=修改手机号第二步,changepwd=修改密码
* @param string $event 事件名称:register=注册,resetpwd=忘记密码,changemobile1=修改手机号第一步,changemobile2=修改手机号第二步,changepwd=修改密码,bind=绑定第三方
*/
public function send()
{
... ... @@ -48,6 +48,12 @@ class Sms extends Api
} elseif (in_array($event, ['changepwd', 'resetpwd', 'changemobile1']) && !$userinfo) {
//未注册
$this->error(__('未注册'));
} elseif ($event == 'bind' && $userinfo) {
$third = Db::name('user_third')->where('user_id',$userinfo['id'])->where('platform','wechat')->find();
if($third){
//被绑定
$this->error(__('该手机号已绑定微信'));
}
}
}
$ret = $this->getCode($mobile, null, $event);
... ...
... ... @@ -38,7 +38,7 @@ use Endroid\QrCode\QrCode;
*/
class User extends Api
{
protected $noNeedLogin = ['registerUser','agreementUser','registerCompany','agreementCompany','agreementPrivacy','login','resetpwd','exam','noLogin','problemList','problemInfo'];
protected $noNeedLogin = ['registerUser','agreementUser','registerCompany','agreementCompany','agreementPrivacy','login','thirdLogin','thirdBindMobile','resetpwd','exam','noLogin','problemList','problemInfo'];
protected $noNeedRight = ['*'];
public function _initialize()
... ... @@ -321,11 +321,12 @@ class User extends Api
'code':'1',
'msg':'返回成功',
"data": {
"bind_mobile": 是否已绑定手机号码0=否1=是,
"token": 用户token
}
})
*/
public function userThird() {
public function thirdLogin() {
$param = $this->request->param();
$validate = new Validate([
'nickname' => 'require',
... ... @@ -339,49 +340,46 @@ class User extends Api
$this->error($validate->getError());
}
// 判断用户是否已绑定该openid
$bind_mobile = 0;
$time = time();
$ip = request()->ip();
$third = UserThird::where('openid',$param['openid'])->find();
Db::startTrans();
if($third) {
// 修改第三方信息
$result = UserThird::where('id',$third['id'])->update([
'openname' => $param['nickname'],
'logintime'=>$time
]);
// 修改用户信息
$user = \app\common\model\User::get($third['user_id']);
if(!empty($param['nickname']) && empty($user['nickname'])){
$user->nickname = $param['nickname'];
}
if(!empty($param['avatar']) && (empty($user['image']) || stripos($user['image'], 'http') !== false)){
$user->image = $param['avatar'];
}
if(!empty($param['gender']) && !isset($user['sex'])){
$user->sex = $param['gender'] == 2 ? 0 : $param['gender'];
if($user){
Db::startTrans();
// 修改第三方信息
$result = $third->save([
'openname' => $param['nickname'],
'logintime'=>$time
]);
// 修改用户信息
if(empty($user['nickname'])){
$user->nickname = $param['nickname'];
}
if(!empty($param['avatar']) && (empty($user['image']) || stripos($user['image'], 'http') !== false)){
$user->image = $param['avatar'];
}
if(!empty($param['gender']) && !isset($user['sex'])){
$user->sex = $param['gender'] == 2 ? 0 : $param['gender'];
}
$user->loginip = $ip;
$user->logintime = $time;
$user->updatetime = $time;
$results = $user->save();
// 登录
$login = $this->auth->direct($third['user_id']);
if(!$result || !$results || !$login) {
Db::rollback();
$this->error('授权登录失败');
}
Db::commit();
$bind_mobile = 1;
$token = $this->auth->getToken();
}
$user->loginip = $ip;
$user->logintime = $time;
$user->updatetime = $time;
$results = $user->save();
// 登录
$login = $this->auth->direct($third['user_id']);
} else {
// 添加用户信息
$result = \app\common\model\User::create([
'nickname' => $param['nickname'],
'sex' => $param['gender'] == 2 ? 0 : $param['gender'],
'image' => $param['avatar'],
'status' => 'normal',
'jointime' => $time,
'joinip' => $ip,
'logintime' => $time,
'loginip' => $ip,
'prevtime' => $time
]);
// 添加第三方信息
$results = UserThird::create([
'user_id' => $result['id'],
$result = UserThird::create([
'openname' => $param['nickname'],
'platform' => 'wechat',
'openid' => $param['openid'],
... ... @@ -390,15 +388,169 @@ class User extends Api
'logintime' => $time,
'unionid' => $param['unionid'],
]);
// 登录
$login = $this->auth->direct($result['id']);
}
if(!$result || !$results || !$login) {
Db::rollback();
$this->error('授权登录失败');
if(!$result) {
Db::rollback();
$this->error('授权登录失败');
}
}
Db::commit();
$this->success('成功',['token'=>$this->auth->getToken()]);
$this->success('成功',['bind_mobile'=>$bind_mobile,'token'=>empty($token)?'':$token]);
}
/**
* 绑定手机号
* @ApiWeigh (91)
*
* @ApiTitle (第三方登录-绑定手机号)
* @ApiSummary (第三方登录-绑定手机号)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="mobile", type="integer", required=true, description="手机号码")
* @ApiParams (name="code", type="integer", required=true, description="验证码")
* @ApiParams (name="openid", type="integer", required=true, description="第三方登录返回的唯一识别数据")
* @ApiParams (name="nickname", type="integer", required=true, description="第三方账号昵称")
* @ApiParams (name="avatar", type="integer", required=false, description="第三方账号头像")
* @ApiParams (name="gender", type="integer", required=false, description="第三方性别")
*
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"token": 用户token,
"is_password": 是否设置密码(0,否;1,是)
}
})
*/
public function thirdBindMobile() {
if($this->request->isPost()) {
$param = $this->request->param();
$validate = new Validate([
'mobile' => 'require',
'code' => 'require|number|length:4',
'openid' => 'require',
]);
$validate->message([
'mobile.require' => '请输入您的手机号!',
'code.require' => '请输入数字验证码!',
'code.number' => '请输入正确的数字验证码!',
'code.length' => '数字验证码长度错误!',
'openid.require' => '缺少参数openid!',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
if (!Sms::check($param['mobile'], $param['code'], 'bind')) {
$this->error(__('Captcha is incorrect'));
}
// 判断用户是否已绑定该openid
$third = UserThird::where('openid',$param['openid'])->find();
if($third) {
$user_model = new \app\common\model\User();
$user = $user_model->get($third['user_id']);
Db::startTrans();
if($user) {
$this->error('已绑定手机号');
}
// 判断是否存在该手机号
$user = $user_model->where('mobile',$param['mobile'])->find();
$ip = request()->ip();
$time = time();
if(!$user) {
$user_insert = [
'username' => $param['mobile'],
'nickname' => $param['nickname'],
'image' => empty($param['avatar']) ? '/assets/img/avatar.png' : $param['avatar'],
'sex' => isset($param['gender']) && $param['gender'] == 0 ? 2 : 1,
'mobile' => $param['mobile'],
'jointime' => $time,
'joinip' => $ip,
'logintime' => $time,
'loginip' => $ip,
'prevtime' => $time,
'status' => 'normal',
];
$results = $user_model->isUpdate(false)->save($user_insert);
$this->auth->direct($user_model['id']);
$is_password = 0;
} else {
// 判断手机号是否已经绑定第三方
$third_user_data = UserThird::where('user_id',$user['id'])
->where('platform','wechat')
->find();
if($third_user_data) {
Db::rollback();
$this->error('该手机号已绑定微信');
}
// 修改用户信息
if(empty($user['nickname'])){
$user->nickname = $param['nickname'];
}
if(!empty($param['avatar']) && (empty($user['image']) || stripos($user['image'], 'http') !== false)){
$user->image = $param['avatar'];
}
if(!empty($param['gender']) && !isset($user['sex'])){
$user->sex = $param['gender'] == 2 ? 0 : $param['gender'];
}
$user->loginip = $ip;
$user->logintime = $time;
$user->updatetime = $time;
$results = $user->save();
$this->auth->direct($user['id']);
$is_password = $user['password'] ? 1 : 0;
}
$result = $third->save([
'logintime' => $time,
'user_id' => $user['id'],
]);
if(!$result || !$results) {
Db::rollback();
$this->error('第三方绑定失败');
}
Db::commit();
// 生成token
$token = $this->auth->getToken();
$this->success('绑定成功',['token'=>$token,'is_password'=>$is_password]);
}
}
}
/**
* 第三方登录-设置密码
* @ApiWeigh (91)
*
* @param string $password 密码
* @param string $confirm_password 确认密码
* @param string $mobile 手机号
* @param string $code 验证码
*/
public function thirdPassword()
{
$password = $this->request->request('password');
$confirm_password = $this->request->request('confirm_password');
$mobile = $this->request->request('mobile');
$code = $this->request->request('code');
if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('Mobile is incorrect'));
}
if ($confirm_password != $password) {
$this->error(__('密码与确认密码不一致'));
}
$ret = Sms::check($mobile, $code, 'bind');
if (!$ret) {
$this->error(__('Captcha is incorrect'));
}
if ($this->auth->password) {
$this->error('已设置过密码');
}
$salt = Random::alnum();
$password = $this->auth->getEncryptPassword($password, $salt);
$user_model = new \app\common\model\User();
$result = $user_model->update(['id' => $this->auth->id, 'password' => $password, 'salt' => $salt]);
if (!$result) {
$this->error('密码设置失败');
}
$this->success('密码设置成功');
}
/**
... ... @@ -1240,6 +1392,11 @@ class User extends Api
}
// 创建订单
$model->add($this->auth->getUser(), $order, $param['pay_type']);
// 零元直接支付成功
if($model['pay_price'] <= 0){
(new Notify)->notifyScoreZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
$this->success('成功',[]);
}
//回调链接
$notifyurl = $this->request->root(true) . '/mobile/notify/notifyScore/paytype/' . $param['pay_type'];
$model['pay_price'] = 0.01; //测试金额
... ...
... ... @@ -80,7 +80,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'expirationtime', title: __('有效期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
{field: 'mobile', title: __('注册手机号')},
{field: 'group_id', title: __('角色'), searchList: {"0":"普通用户","1":"公司用户"},formatter: Table.api.formatter.flag},
{field: 'group_id', title: __('角色'), searchList: {"0":"普通用户","1":"企业管理员"},formatter: Table.api.formatter.flag},
{field: 'createtime', title: __('注册时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
... ...
此 diff 太大无法显示。