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

内购充值

<?php
namespace app\admin\controller\mobile\recharge;
use app\common\controller\Backend;
/**
* 充值产品管理
*
* @icon fa fa-circle-o
*/
class Recharge extends Backend
{
/**
* Recharge模型对象
* @var \app\admin\model\mobile\recharge\Recharge
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\mobile\recharge\Recharge;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = false;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->visible(['id','name','price','product_id','createtime']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
... ...
<?php
namespace app\admin\controller\mobile\recharge;
use app\common\controller\Backend;
/**
* 充值订单管理
*
* @icon fa fa-circle-o
*/
class RechargeOrder extends Backend
{
/**
* RechargeOrder模型对象
* @var \app\admin\model\mobile\recharge\RechargeOrder
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\mobile\recharge\RechargeOrder;
$this->view->assign("payTypeList", $this->model->getPayTypeList());
$this->view->assign("payStatusList", $this->model->getPayStatusList());
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = false;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->visible(['id','order_sn','pay_price','pay_type','pay_status','pay_time','money','createtime','updatetime']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
... ...
<?php
return [
'Id' => 'ID',
'Name' => '充值名称',
'Price' => '价格',
'Product_id' => '苹果内购产品id',
'Createtime' => '创建时间',
'Updatetime' => '更新时间'
];
... ...
<?php
return [
'Id' => 'ID',
'User_id' => '用户ID',
'Recharge_id' => '套餐ID',
'Order_sn' => '订单号',
'Pay_price' => '实际支付金额',
'Pay_type' => '支付方式',
'Pay_type wechat' => '微信',
'Pay_type alipay' => '支付宝',
'Pay_type ios' => '苹果',
'Pay_status' => '支付状态',
'Pay_status 0' => '未支付',
'Pay_status 1' => '已支付',
'Pay_time' => '支付时间',
'Money' => '充值金额',
'Transaction_id' => '交易单号',
'Product_id' => '苹果内购产品id',
'Createtime' => '创建时间',
'Updatetime' => '更新时间'
];
... ...
<?php
namespace app\admin\model\mobile\recharge;
use think\Model;
class Recharge extends Model
{
// 表名
protected $name = 'mobile_recharge';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
}
... ...
<?php
namespace app\admin\model\mobile\recharge;
use think\Model;
class RechargeOrder extends Model
{
// 表名
protected $name = 'mobile_recharge_order';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'pay_type_text',
'pay_status_text',
'pay_time_text'
];
public function getPayTypeList()
{
return ['wechat' => __('Pay_type wechat'), 'alipay' => __('Pay_type alipay'), 'ios' => __('Pay_type ios')];
}
public function getPayStatusList()
{
return ['0' => __('Pay_status 0'), '1' => __('Pay_status 1')];
}
public function getPayTypeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
$list = $this->getPayTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getPayStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['pay_status']) ? $data['pay_status'] : '');
$list = $this->getPayStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getPayTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setPayTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
}
... ...
<?php
namespace app\admin\validate\mobile\recharge;
use think\Validate;
class Recharge extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<?php
namespace app\admin\validate\mobile\recharge;
use think\Validate;
class RechargeOrder extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Price')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-price" data-rule="required" class="form-control" step="0.01" name="row[price]" type="number" value="0.00">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Product_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-product_id" data-rule="required" class="form-control" name="row[product_id]" type="text">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Price')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-price" data-rule="required" class="form-control" step="0.01" name="row[price]" type="number" value="{$row.price|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Product_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-product_id" data-rule="required" class="form-control" name="row[product_id]" type="text" value="{$row.product_id|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('mobile/recharge/recharge/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('mobile/recharge/recharge/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('mobile/recharge/recharge/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('mobile/recharge/recharge/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
<div class="dropdown btn-group {:$auth->check('mobile/recharge/recharge/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('mobile/recharge/recharge/edit')}"
data-operate-del="{:$auth->check('mobile/recharge/recharge/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Recharge_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-recharge_id" data-rule="required" data-source="recharge/index" class="form-control selectpage" name="row[recharge_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Order_sn')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-order_sn" data-rule="required" class="form-control" name="row[order_sn]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_price')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-pay_price" data-rule="required" class="form-control" step="0.01" name="row[pay_price]" type="number" value="0.00">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_type')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-pay_type" data-rule="required" class="form-control selectpicker" name="row[pay_type]">
{foreach name="payTypeList" item="vo"}
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="payStatusList" item="vo"}
<label for="row[pay_status]-{$key}"><input id="row[pay_status]-{$key}" name="row[pay_status]" type="radio" value="{$key}" {in name="key" value="0"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-pay_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[pay_time]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Money')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-money" data-rule="required" class="form-control" name="row[money]" type="number" value="0">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Transaction_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-transaction_id" data-rule="required" data-source="transaction/index" class="form-control selectpage" name="row[transaction_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Product_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-product_id" data-rule="required" data-source="product/index" class="form-control selectpage" name="row[product_id]" type="text" value="">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Recharge_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-recharge_id" data-rule="required" data-source="recharge/index" class="form-control selectpage" name="row[recharge_id]" type="text" value="{$row.recharge_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Order_sn')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-order_sn" data-rule="required" class="form-control" name="row[order_sn]" type="text" value="{$row.order_sn|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_price')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-pay_price" data-rule="required" class="form-control" step="0.01" name="row[pay_price]" type="number" value="{$row.pay_price|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_type')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-pay_type" data-rule="required" class="form-control selectpicker" name="row[pay_type]">
{foreach name="payTypeList" item="vo"}
<option value="{$key}" {in name="key" value="$row.pay_type"}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="payStatusList" item="vo"}
<label for="row[pay_status]-{$key}"><input id="row[pay_status]-{$key}" name="row[pay_status]" type="radio" value="{$key}" {in name="key" value="$row.pay_status"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-pay_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[pay_time]" type="text" value="{:$row.pay_time?datetime($row.pay_time):''}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Money')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-money" data-rule="required" class="form-control" name="row[money]" type="number" value="{$row.money|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Transaction_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-transaction_id" data-rule="required" data-source="transaction/index" class="form-control selectpage" name="row[transaction_id]" type="text" value="{$row.transaction_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Product_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-product_id" data-rule="required" data-source="product/index" class="form-control selectpage" name="row[product_id]" type="text" value="{$row.product_id|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('mobile/recharge/recharge_order/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('mobile/recharge/recharge_order/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('mobile/recharge/recharge_order/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('mobile/recharge/recharge_order/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
<div class="dropdown btn-group {:$auth->check('mobile/recharge/recharge_order/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('mobile/recharge/recharge_order/edit')}"
data-operate-del="{:$auth->check('mobile/recharge/recharge_order/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -569,7 +569,7 @@ class Course extends Api
* @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=开")
* @ApiParams (name="pay_type", type="string", required=true, description="支付方式:wechat=微信,alipay=支付宝")
* @ApiParams (name="pay_type", type="string", required=true, description="支付方式:wechat=微信,alipay=支付宝,ios=苹果内购")
*
* @ApiReturn({
"code": 1,
... ... @@ -593,14 +593,18 @@ class Course extends Api
if(!$order = $this->model->payView($this->auth->getUser(),$param)){
$this->error($this->model->getError(),null,$this->model->getCode());
}
if (!$param['pay_type'] || !in_array($param['pay_type'], ['alipay', 'wechat'])) {
if (!$param['pay_type'] || !in_array($param['pay_type'], ['alipay', 'wechat', 'money'])) {
$this->error("请选择支付方式");
}
$user = $this->auth->getUser();
if($param['pay_type'] == 'money' && $user['money'] < $order['pay_price']){
$this->error('余额不足');
}
// 创建订单
$model = new CourseOrder;
$model->add($this->auth->getUser(), $order, $param['pay_type']);
$model->add($user, $order, $param['pay_type']);
// 零元直接支付成功
if($model['pay_price'] <= 0){
if($model['pay_price'] <= 0 || $param['pay_type'] == 'money'){
(new Notify)->notifyCourseZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
$this->success('成功',[]);
}
... ...
... ... @@ -7,12 +7,13 @@ use app\mobile\model\CourseOrder;
use app\mobile\model\SecretOrder;
use app\mobile\model\ScoreOrder;
use app\mobile\model\PackageOrder;
use app\mobile\model\RechargeOrder;
use app\mobile\model\User;
use addons\qiniu\library\Auth;
use app\common\model\Attachment;
/**
* 异步接口
* @ApiInternal
*/
class Notify extends Api
{
... ... @@ -26,6 +27,7 @@ class Notify extends Api
/**
* 课程---------------------------------------------------------------------
* @ApiInternal
*/
public function notifyCourse()
{
... ... @@ -48,6 +50,7 @@ class Notify extends Api
/**
* 课程-零元支付
* @ApiInternal
*/
public function notifyCourseZero($out_trade_no,$payamount,$paytype)
{
... ... @@ -69,6 +72,7 @@ class Notify extends Api
/**
* 课程-处理订单
* @ApiInternal
*/
private function handleCourseOrder($out_trade_no,$payamount,$paytype){
// 处理订单逻辑
... ... @@ -84,6 +88,7 @@ class Notify extends Api
/**
* 密卷-----------------------------------------------------------------------
* @ApiInternal
*/
public function notifySecret()
{
... ... @@ -107,6 +112,7 @@ class Notify extends Api
/**
* 密卷-零元支付
* @ApiInternal
*/
public function notifySecretZero($out_trade_no,$payamount,$paytype)
{
... ... @@ -128,6 +134,7 @@ class Notify extends Api
/**
* 密卷-处理订单
* @ApiInternal
*/
private function handleSecretOrder($out_trade_no,$payamount,$paytype){
// 处理订单逻辑
... ... @@ -143,6 +150,7 @@ class Notify extends Api
/**
* 积分----------------------------------------------------------------------
* @ApiInternal
*/
public function notifyScore()
{
... ... @@ -166,6 +174,7 @@ class Notify extends Api
/**
* 积分-零元支付
* @ApiInternal
*/
public function notifyScoreZero($out_trade_no,$payamount,$paytype)
{
... ... @@ -187,6 +196,7 @@ class Notify extends Api
/**
* 积分-处理订单
* @ApiInternal
*/
private function handleScoreOrder($out_trade_no,$payamount,$paytype){
// 处理订单逻辑
... ... @@ -202,6 +212,7 @@ class Notify extends Api
/**
* 企业套餐---------------------------------------------------------------------
* @ApiInternal
*/
public function notifyPackage()
{
... ... @@ -225,6 +236,7 @@ class Notify extends Api
/**
* 企业套餐-零元支付
* @ApiInternal
*/
public function notifyPackageZero($out_trade_no,$payamount,$paytype)
{
... ... @@ -246,6 +258,7 @@ class Notify extends Api
/**
* 企业套餐-处理订单
* @ApiInternal
*/
private function handlePackageOrder($out_trade_no,$payamount,$paytype){
// 处理订单逻辑
... ... @@ -295,4 +308,151 @@ class Notify extends Api
return json(['ret' => 'failed']);
}
}
/**
* ios内购支付调试接口
*
* @ApiTitle (ios内购支付调试接口)
* @ApiSummary (ios内购支付调试接口)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="order_sn", type="string", required=true, description="订单号")
* @ApiParams (name="apple_receipt", type="string", required=true, description="ios支付成功返回的凭证数据")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
}
})
*
*/
public function iosCheck(){
// 苹果内购的验证收据,由客户端传过来
$apple_receipt = input("post.apple_receipt", "");
$out_trade_no = input("post.order_sn", "");
$jsonData = ["receipt-data"=>$apple_receipt];
$jsonData1 = json_encode($jsonData);
$response = $this->http_post_data($jsonData1, true);
if($response->status==21007) {
$response = $this->http_post_data($jsonData1, false);
}else if ($response->status==21008) {
$response = $this->http_post_data($jsonData1, true);
}
if($response->status == 0){
// 允许名单数组
$bundlelist=['com.zhanghao.GMAT'];
$bundleid= $response->receipt->bundle_id;
if($bundleid && in_array($bundleid,$bundlelist)) {
// 最近交易
if($response->receipt->in_app && !empty($response->receipt->in_app)){
// 获取本次购买的信息
$in_app = end($response->receipt->in_app);
// 产品ID
$product_id = $in_app->product_id;
if($product_id && !empty($product_id)){
// 产品ID数组
$productids = [
"com.zhanghao.GMAT_12",
"com.zhanghao.GMAT_73",
"com.zhanghao.GMAT_113",
"com.zhanghao.GMAT_288",
"com.zhanghao.GMAT_488",
"com.zhanghao.GMAT_798"
];
if(in_array($product_id, $productids)){
// 查询该比交易是否已经成功
$transaction_id = $in_app->transaction_id;// 本次购买苹果内购的唯一标识,相当于订单号
$transactionWhere['transaction_id'] = $transaction_id;
$transactionWhere['pay_status'] = 1;
$havePay = RechargeOrder::where($transactionWhere)->find();
!empty($havePay) && $this->error('已经支付过了');
$haveOrder = RechargeOrder::where('order_sn',$out_trade_no)->find();
empty($haveOrder) && $this->error('订单不存在');
// 主动购买会有订单号
$order = RechargeOrder::where(['order_sn'=>$out_trade_no,'pay_status'=>0])->find();
if(!empty($order)){
//这里做逻辑处理
Db::startTrans();
$result = $order->isUpdate(true)->save([
'pay_status' => 1,
'pay_time' => time(),
'transaction_id' => $transaction_id,
'product_id' => $product_id,
]);
// 增加用户余额
$user = User::field('id,money')->where('id', $order['user_id'])->find();
$result_user = User::where('id', $order['user_id'])->setInc('money', $order['money']);
// 增加余额变动记录
$result_money_log = \app\common\model\MoneyLog::create([
'user_id' => $order['user_id'],
'money' => $order['money'],
'before' => $user['money'],
'after' => $user['money'] + $order['money'],
'memo' => '苹果内购充值余额',
'createtime' => time()
]);
if (!$result || !$result_user || !$result_money_log) {
Db::rollback();
$this->error('订单处理失败');
}
Db::commit();
}
$this->success('支付成功');
} else{
$this->error('非法product_id');
}
}else{
$this->error('produce_id不存在伪造充值');
}
}else{
$this->error('伪造充值');
}
}else{
$this->error('凭据bundleid不在白名单之内');
}
}else{
$code = $response->status;
$messagearr[21000] = "App Store无法读取你提供的JSON数据";
$messagearr[21002] = "收据数据不符合格式";
$messagearr[21003] = "收据无法被验证";
$messagearr[21004] = "你提供的共享密钥和账户的共享密钥不一致";
$messagearr[21005] = "收据服务器当前不可用";
$messagearr[21006] = "收据是有效的,但订阅服务已经过期。当收到这个信息时,解码后的收据信息也包含在返回内容中";
$messagearr[21007] = "收据信息是测试用(sandbox),但却被发送到产品环境中验证";
$messagearr[21008] = "收据信息是产品环境中使用,但却被发送到测试环境中验证";
$this->error($messagearr[$code]);
}
}
/**
* curl请求苹果app_store验证地址
* @param $data_string 验证字符串
* @param $istest 是否是测试地址 true正式地址 false测试地址
* @return mixed
*/
private function http_post_data($data_string, $istest) {
if ($istest) {
// 正式验证地址
$url = 'https://buy.itunes.apple.com/verifyReceipt';
} else {
// 测试验证地址
$url = 'https://sandbox.itunes.apple.com/verifyReceipt';
}
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL, $url);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle,CURLOPT_HEADER, 0);
curl_setopt($curl_handle,CURLOPT_POST, true);
curl_setopt($curl_handle,CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl_handle,CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl_handle,CURLOPT_SSL_VERIFYPEER, 0);
$response_json =curl_exec($curl_handle);
$response =json_decode($response_json);
curl_close($curl_handle);
return $response;
}
}
\ No newline at end of file
... ...
... ... @@ -16,6 +16,8 @@ use app\mobile\model\CourseAppraise;
use app\mobile\model\SecretOrder;
use app\mobile\model\ScoreSpec;
use app\mobile\model\ScoreOrder;
use app\mobile\model\Recharge;
use app\mobile\model\RechargeOrder;
use app\mobile\model\QuestionCollect;
use app\mobile\model\CourseCollect;
use app\mobile\model\QuestionNote;
... ... @@ -1342,7 +1344,7 @@ class User extends Api
$param = $this->request->param();
$model = new ScoreOrder;
if(!$order = $model->payView($this->auth->getUser(),$param)){
$this->error($model->getError(),null,$this->model->getCode());
$this->error($model->getError(),null,$model->getCode());
}
$this->success(__('成功'),$order);
}
... ... @@ -1370,7 +1372,7 @@ class User extends Api
$param = $this->request->param();
$model = new ScoreOrder;
if(!$order = $model->payView($this->auth->getUser(),$param)){
$this->error($model->getError(),null,$this->model->getCode());
$this->error($model->getError(),null,$model->getCode());
}
if (!$param['pay_type'] || !in_array($param['pay_type'], ['alipay', 'wechat'])) {
$this->error("请选择支付方式");
... ... @@ -2272,6 +2274,7 @@ class User extends Api
}
/**
* @ApiWeigh (8)
* @ApiTitle (我自己的学习列表)
* @ApiSummary (我自己的学习列表)
* @ApiMethod (POST)
... ... @@ -2345,4 +2348,64 @@ class User extends Api
}
$this->success('success',$data);
}
/**
* @ApiWeigh (7)
* @ApiTitle (内购充值列表)
* @ApiSummary (内购充值列表)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1614425430",
"data": {
"money": "0.00", //当前余额
"list": [{
"id": 6, //充值产品ID
"name": "308元", //充值名称
"price": "308.00", //充值金额
"product_id": "123", //苹果内购产品ID
"createtime": 1614423262,
"updatetime": 1614423262
}]
}
})
*/
public function rechargeList()
{
$money = $this->auth->money;
$list = Recharge::all();
$this->success('成功', compact('money','list'));
}
/**
* @ApiWeigh (6)
* @ApiTitle (充值)
* @ApiSummary (充值)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="recharge_id", type="int", required=false, description="充值产品ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "积分说明" //积分说明内容
})
*/
public function recharge()
{
$param = $this->request->param();
$model = new RechargeOrder;
if(!$order = $model->payView($param)){
$this->error($model->getError(),null,$model->getCode());
}
// 创建订单
$model->add($this->auth->getUser(), $order, 'ios');
$this->success('成功',['order_sn'=>$model['order_sn']]);
}
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
class Recharge extends Model
{
// 表名
protected $name = 'mobile_recharge';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
use think\Db;
class RechargeOrder extends Model
{
// 表名
protected $name = 'mobile_recharge_order';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 错误提示
public $error = '';
// 状态码
public $code = 0;
/**
* 下单预览
*/
public function payView($data)
{
if(empty($data['recharge_id'])){
$this->setError('缺少必要参数');
return false;
}
$info = Recharge::get($data['recharge_id']);
if(empty($info)){
$this->setError('充值产品信息不存在');
return false;
}
return [
'recharge_id' => $data['recharge_id'],
'pay_price' => $info['price'],
'money' => $info['price']
];
}
/**
* 新增订单
*/
public function add($user, $order, $pay_type)
{
$this->save([
'user_id' => $user['id'],
'recharge_id' => $order['recharge_id'],
'order_sn' => get_order_sn(),
'pay_price' => $order['pay_price'],
'pay_type' => $pay_type,
'money' => $order['money']
]);
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
... ...
... ... @@ -3094,7 +3094,8 @@
"study": [{ //学习平台入口
"title": "天津市二级建造师课程", //标题
"image": "http://qizhibang.brotop.cn/uploads/20210127/Fowbl73z1EpqVj0cBILbJL06myDf.png", //图片
"type_id": 3 //科目分类ID
"type_id": 3, //科目分类ID
"is_enter": 1 //是否可进入:0=否,1=是
}],
"class": { //优选课程入口
"title": "2020版一建二建课程" //标题
... ... @@ -7903,7 +7904,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2021-01-28 14:17:49 </div>
Generated on 2021-01-30 09:24:42 </div>
<div class="col-md-6" align="right">
<a href="./" target="_blank">企智帮</a>
</div>
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'mobile/recharge/recharge/index' + location.search,
add_url: 'mobile/recharge/recharge/add',
edit_url: 'mobile/recharge/recharge/edit',
del_url: 'mobile/recharge/recharge/del',
multi_url: 'mobile/recharge/recharge/multi',
table: 'mobile_recharge',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'name', title: __('Name')},
{field: 'price', title: __('Price'), operate:'BETWEEN'},
{field: 'product_id', title: __('Product_id')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'mobile/recharge/recharge_order/index' + location.search,
add_url: 'mobile/recharge/recharge_order/add',
edit_url: 'mobile/recharge/recharge_order/edit',
del_url: 'mobile/recharge/recharge_order/del',
multi_url: 'mobile/recharge/recharge_order/multi',
table: 'mobile_recharge_order',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'order_sn', title: __('Order_sn')},
{field: 'pay_price', title: __('Pay_price'), operate:'BETWEEN'},
{field: 'pay_type', title: __('Pay_type'), searchList: {"wechat":__('Pay_type wechat'),"alipay":__('Pay_type alipay'),"ios":__('Pay_type ios')}, formatter: Table.api.formatter.normal},
{field: 'pay_status', title: __('Pay_status'), searchList: {"0":__('Pay_status 0'),"1":__('Pay_status 1')}, formatter: Table.api.formatter.status},
{field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'money', title: __('Money')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
此 diff 太大无法显示。