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

合并分支 'heshupeng' 到 'master'

短信限制修改



查看合并请求 !2
... ... @@ -328,6 +328,7 @@ class Course extends Api
* @ApiSummary (购买预览)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="course_id", type="int", required=true, description="课程ID")
* @ApiParams (name="spec_id", type="int", required=true, description="课程规格ID")
* @ApiParams (name="score_switch", type="int", description="积分开关:0=关,1=开")
... ... @@ -362,6 +363,7 @@ class Course extends Api
* @ApiSummary (购买)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="course_id", type="int", required=true, description="课程ID")
* @ApiParams (name="spec_id", type="int", required=true, description="课程规格ID")
* @ApiParams (name="score_switch", type="int", description="积分开关:0=关,1=开")
... ... @@ -396,34 +398,8 @@ class Course extends Api
$model = new CourseOrder;
$model->add($this->auth->getUser(), $order, $param['pay_type']);
//回调链接
$notifyurl = $this->request->root(true) . '/mobile/course/notifyx/paytype/' . $param['pay_type'];
$notifyurl = $this->request->root(true) . '/mobile/notify/notifyCourse/paytype/' . $param['pay_type'];
$payment = Service::submitOrder($model['pay_price'], $model['order_sn'], $param['pay_type'], '课程', $notifyurl, null, 'app');
$this->success('成功',$payment);
}
/**
* 支付成功
*/
public function notifyx()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
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()]);
}
} catch (Exception $e) {
}
echo $pay->success();
}
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\controller;
use think\Db;
use app\common\controller\Api;
use app\mobile\model\CourseOrder;
use app\mobile\model\SecretOrder;
use app\mobile\model\ScoreOrder;
/**
* 支付异步接口
* @ApiInternal
*/
class Notify extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
}
/**
* 课程
*/
public function notifyCourse()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
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()]);
}
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 密卷
*/
public function notifySecret()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
try {
$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()]);
}
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 积分
*/
public function notifyScore()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
try {
$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'],'充值积分');
}
} catch (Exception $e) {
}
echo $pay->success();
}
}
\ No newline at end of file
... ...
... ... @@ -160,6 +160,7 @@ class Secret extends Api
* @ApiSummary (购买预览)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="secret_id", type="int", required=true, description="密卷ID")
* @ApiParams (name="spec_id", type="int", required=true, description="密卷规格ID")
* @ApiParams (name="score_switch", type="int", description="积分开关:0=关,1=开")
... ... @@ -194,6 +195,7 @@ class Secret extends Api
* @ApiSummary (购买)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="secret_id", type="int", required=true, description="密卷ID")
* @ApiParams (name="spec_id", type="int", required=true, description="密卷规格ID")
* @ApiParams (name="score_switch", type="int", description="积分开关:0=关,1=开")
... ... @@ -228,34 +230,8 @@ class Secret extends Api
$model = new SecretOrder;
$model->add($this->auth->getUser(), $order, $param['pay_type']);
//回调链接
$notifyurl = $this->request->root(true) . '/mobile/secret/notifyx/paytype/' . $param['pay_type'];
$notifyurl = $this->request->root(true) . '/mobile/notify/notifySecret/paytype/' . $param['pay_type'];
$payment = Service::submitOrder($model['pay_price'], $model['order_sn'], $param['pay_type'], '密卷', $notifyurl, null, 'app');
$this->success('成功',$payment);
}
/**
* 支付成功
*/
public function notifyx()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
try {
$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()]);
}
} catch (Exception $e) {
}
echo $pay->success();
}
}
\ No newline at end of file
... ...
... ... @@ -34,7 +34,7 @@ class Sms extends Api
$this->error(__('发送频繁'));
}
$ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
if ($ipSendTotal >= 5) {
if ($ipSendTotal >= 500) {
$this->error(__('发送频繁'));
}
if ($event) {
... ... @@ -83,6 +83,7 @@ class Sms extends Api
/**
* 校验验证码
* @ApiInternal
*/
public static function check($mobile, $code, $event = 'default')
{
... ...
... ... @@ -16,6 +16,9 @@ use app\mobile\model\CourseOrder;
use app\mobile\model\CourseAppraise;
use app\mobile\model\SecretOrder;
use app\mobile\model\ScoreSpec;
use app\mobile\model\ScoreOrder;
use app\mobile\model\QuestionCollect;
use addons\epay\library\Service;
/**
* 我的接口
... ... @@ -665,13 +668,15 @@ class User extends Api
*/
public function scoreLog()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$list = \app\common\model\ScoreLog::where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v['createtime'] = date('Y.m.d H:i',$v['createtime']);
})->toArray();
$this->success('成功', $content);
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
/**
... ... @@ -712,13 +717,49 @@ class User extends Api
}
/**
* @ApiTitle (积分充值预览)
* @ApiSummary (积分充值预览)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="score_spec_id", type="int", required=false, description="套餐ID")
* @ApiParams (name="score", type="int", required=false, description="自定义积分")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599046220",
"data": {
"id": 1, //试卷ID
"title": "测试试卷", //试卷标题
"year": 2015, //年费(单位:年)
"time": 100, //答题时间(单位:分)
"pass_score": 80, //合格分数
"description": "这个还行", //试卷描述
"do_num": 10, //回答人数
"full_score": 100 //试卷分数(单位:分)
}
})
*/
public function scoreRechargeView()
{
$param = $this->request->param();
$model = new ScoreOrder;
if(!$order = $model->payView($this->auth->getUser(),$param)){
$this->error($model->getError(),null,$this->model->getCode());
}
$this->success(__('成功'),$order);
}
/**
* @ApiTitle (充值积分)
* @ApiSummary (充值积分)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="score_spec_id", type="int", required=false, description="积分套餐ID")
* @ApiParams (name="score", type="int", required=true, description="评价星数")
* @ApiParams (name="score", type="int", required=false, description="自定义积分")
* @ApiParams (name="pay_type", type="string", required=true, description="支付方式:wechat=微信,alipay=支付宝")
*
* @ApiReturn({
"code": 1,
... ... @@ -729,8 +770,50 @@ class User extends Api
*/
public function scoreRecharge()
{
$param = $this->request->param();
$model = new ScoreOrder;
if(!$order = $model->payView($this->auth->getUser(),$param)){
$this->error($model->getError(),null,$this->model->getCode());
}
if (!$param['pay_type'] || !in_array($param['pay_type'], ['alipay', 'wechat'])) {
$this->error("请选择支付方式");
}
// 创建订单
$model->add($this->auth->getUser(), $order, $param['pay_type']);
//回调链接
$notifyurl = $this->request->root(true) . '/mobile/notify/notifyScore/paytype/' . $param['pay_type'];
$payment = Service::submitOrder($model['pay_price'], $model['order_sn'], $param['pay_type'], '积分', $notifyurl, null, 'app');
$this->success('成功',$payment);
}
$content = Db::name('mobile_config')->where('id',1)->value('user_score_intro');
$this->success('成功', $content);
/**
* @ApiTitle (我的收藏-题目)
* @ApiSummary (我的收藏-题目)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "积分说明" //积分说明内容
})
*/
public function collectQuestionList()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = QuestionCollect::with(['question'])
->where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v['createtime'] = date('Y.m.d H:i',$v['createtime']);
$v->getRelation('question')->visible(['title','type']);
})->toArray();
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
}
\ No newline at end of file
... ...
... ... @@ -12,4 +12,9 @@ class QuestionCollect extends Model
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
// 题目
public function question(){
return $this->belongsTo('Question');
}
}
\ No newline at end of file
... ...
... ... @@ -13,32 +13,92 @@ class ScoreOrder extends Model
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 错误提示
public $error = '';
// 状态码
public $code = 0;
/**
* 下单预览
*/
public function payView($user,$data)
{
if(empty($data['score_spec_id']) && empty($data['score'])){
$this->setError('缺少必要参数');
return false;
}
// 充值积分每分需多少元
$score_recharge_price = Db::name('mobile_config')->where('id',1)->value('score_recharge_price');
// 套餐ID
if(!empty($data['score_spec_id'])){
$info = ScoreSpec::get($data['score_spec_id']);
if(empty($info)){
$this->setError('套餐信息不存在');
return false;
}
$pay_price = bcmul($score_recharge_price,$info['spec_score'],2);
$score = $info['score'];
}else{
$pay_price = bcmul($score_recharge_price,$data['score'],2);
$score = $data['score'];
}
return [
'score_spec_id' => !empty($data['score_spec_id']) ? $data['score_spec_id'] : 0,
'pay_price' => $pay_price,
'score' => $score
];
}
/**
* 新增订单
*/
public function add($user, $order, $pay_type)
{
Db::startTrans();
$save_data = [
'user_id' => $user['id'],
'score_spec_id' => $order['info']['id'],
'order_sn' => get_order_sn(),
'pay_price' => $order['pay_price'],
'pay_type' => $pay_type,
'score' => $order['score']
];
$this->save([
'user_id' => $user['id'],
'score_spec_id' => $order['info']['id'],
'score_spec_id' => $order['score_spec_id'],
'order_sn' => get_order_sn(),
'pay_price' => $order['pay_price'],
'pay_type' => $pay_type,
'score' => $order['score']
]);
// 用掉积分
\app\common\model\User::score($order['score'],$user['id'],'充值积分');
Db::commit();
return true;
}
/**
* 设置错误信息
* @param $error
*/
private function setError($error,$code=0)
{
empty($this->error) && $this->error = $error;
$this->code = $code;
}
/**
* 是否存在错误
* @return bool
*/
private function hasError()
{
return !empty($this->error);
}
/**
* 获取错误信息
* @return string
*/
public function getError()
{
return $this->error;
}
/**
* 获取状态码
* @return string
*/
public function getCode()
{
return $this->code;
}
}
\ No newline at end of file
... ...
此 diff 太大无法显示。