...
|
...
|
@@ -1681,6 +1681,97 @@ class User extends Api |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (创建苹果订单)
|
|
|
* @ApiSummary (创建苹果订单)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/iphone_order)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
*
|
|
|
* @ApiParams (name="video_id", type="string", required=true, description="视频ID")
|
|
|
* @ApiParams (name="video_attr", type="string", required=true, description="视频品质属性")
|
|
|
* @ApiParams (name="pic_id", type="string", required=true, description="图片ID")
|
|
|
* @ApiParams (name="total", type="float", required=true, description="总价格")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1571492001",
|
|
|
"data": {
|
|
|
"order_id"://订单ID
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function iphone_order()
|
|
|
{
|
|
|
$param['user_id'] = $this->uid;
|
|
|
|
|
|
//接收视频ID加视频属性
|
|
|
$video['id'] = $this->request->post('video_id');
|
|
|
$video['attr'] = $this->request->post('video_attr');
|
|
|
|
|
|
//接收图片的ID
|
|
|
$pic_id = $this->request->param('pic_id');
|
|
|
|
|
|
//价格
|
|
|
$param['total'] = $this->request->post('total');
|
|
|
if(empty( $param['total'])){
|
|
|
$this->error(['code'=>2,'msg'=>'缺少必要参数']);
|
|
|
}elseif ( $param['total']<=0){
|
|
|
$this->error(['code'=>3,'msg'=>'非法操作']);
|
|
|
}
|
|
|
|
|
|
$where['user_id'] = ['eq',$param['user_id']];
|
|
|
$where['status'] = ['eq',2];
|
|
|
|
|
|
if(!empty($video['id']) && !empty($video['attr'])){
|
|
|
//查看该图片或者该视频属性是否已经购买过
|
|
|
$res = Db::name('iphone')
|
|
|
->where($where)
|
|
|
->field('video_id')
|
|
|
->select();
|
|
|
foreach ($res as &$v){
|
|
|
$v['video_id'] = unserialize($v['video_id']);
|
|
|
if(!empty($v['video_id']) && !empty($video)){
|
|
|
foreach ($v['video_id'] as $v1){
|
|
|
foreach ($video as &$v2){
|
|
|
if($v1['id'] == $v2['id'] && $v1['attr'] == $v2['attr']){
|
|
|
$this->error(['code'=>2,'msg'=>'该属性的视频已经购买过了','video_id'=>$v2['id']]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$param['video_id'] = serialize($video);
|
|
|
}else{
|
|
|
//查询图片ID
|
|
|
$arr = Db::name('iphone')
|
|
|
->field('pic_id')
|
|
|
->where($where)
|
|
|
->select();
|
|
|
foreach ($arr as &$v){
|
|
|
if(!empty($v['pic_id'])){
|
|
|
if($v['pic_id'] == $pic_id){
|
|
|
$this->error(['code'=>2,'msg'=>'该图片已经购买过了','pic_id'=>$pic_id]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$param['pic_id'] = $pic_id;
|
|
|
}
|
|
|
$param['createtime'] = time();
|
|
|
$param['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
|
|
|
$data = Db::name('order')
|
|
|
->insertGetId($param);
|
|
|
if(empty($data)){
|
|
|
$this->error(['code'=>2,'msg'=>'sql执行失败']);
|
|
|
}
|
|
|
$this->success('SUCCESS',['order_id'=>$data]);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//将多个一维数组转为二维数组
|
|
|
public function array_merge_more($keys, ...$arrs){
|
|
|
// 检查参数是否正确
|
...
|
...
|
|