作者 郭盛

修改接口

... ... @@ -1767,6 +1767,8 @@ class User extends Api
"msg": "成功",
"time": "1571492001",
"data": {
"is_vip"://是否是会员1是0否
"is_enough"://余额是否充足1充足2不足
"order_id"://订单ID
}
})
... ... @@ -1774,11 +1776,14 @@ class User extends Api
public function iphone_order()
{
$param['user_id'] = $this->uid;
$user = Db::name('user')->where('id',$param['user_id'])->field('mobile,id,type')->find();
$user = Db::name('user')->where('id',$param['user_id'])->field('mobile,id,type,is_vip,money,mobile')->find();
if($user['type'] == 0){
$this->error('该功能只支持苹果用户');
}
//查看用户是否是vip
$data['is_vip'] = $user['is_vip'];
//接收视频ID加视频属性
$video['id'] = $this->request->post('video_id');
$video['attr'] = $this->request->post('video_attr');
... ... @@ -1799,9 +1804,12 @@ class User extends Api
$this->error(['code'=>3,'msg'=>'非法操作']);
}
//查询用户余额是否充足
if($user['money'] < $param['total']){
$data['is_enough'] = 2;
$where['user_id'] = ['eq',$param['user_id']];
$where['status'] = ['eq',2];
if(!empty($video['id']) && !empty($video['attr'])){
$video_s = serialize($video);
//查看该图片或者该视频属性是否已经购买过
... ... @@ -1843,8 +1851,87 @@ class User extends Api
$send = new Pay();
$send->sms($mobile,$content);
$send->sms($mobile1,$content);
$this->success('SUCCESS',['order_id'=>$data]);
$this->success('SUCCESS',$data);
}
}else{
$data['is_enough'] = 1;
$where['user_id'] = ['eq',$param['user_id']];
$where['status'] = ['eq',2];
if(!empty($video['id']) && !empty($video['attr'])){
$video_s = serialize($video);
//查看该图片或者该视频属性是否已经购买过
$res = Db::name('iphone')
->where($where)
->where('video_id',$video_s)
->find();
if(!empty($res)){
$this->error(['code'=>2,'msg'=>'该属性的视频已经购买过了']);
}
$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_order = Db::name('iphone')
->insertGetId($param);
if(empty($data_order)){
$this->error(['code'=>2,'msg'=>'sql执行失败']);
}else{
$send = new Pay();
//修改用户余额以及订单状态 同时给用户发送短信
$update = $user['money'] - $param['total'];
Db::name('user')->where('id',$param['user_id'])->update(['money'=>$update]);
Db::name('iphone')->where('id',$data_order)->update(['status'=>2]);
//查询订单数据
$order_info = Db::name('iphone')->where('id',$data_order)->find();
//用户购买的什么素材
if(empty($order_info['video_id'])){
$pic = Db::name('pic')->where('id',$data['pic_id'])->find();
//发送短信,通知客户
$mobile = $user['mobile'];
$content = "【仁甲看见SHOP】,感谢您购买仁甲看见SHOP素材。图片标题:$pic[title],云盘地址:$pic[url]";
//发送短信
$send->sms($mobile,$content);
}elseif (empty($data['pic_id'])){
$video_id = unserialize($data['video_id']);
$video = Db::name('video')->where('id',$video_id['id'])->find();
//发送短信,通知客户
$mobile = $user['mobile'];
if($video_id['attr'] == 1){
$content = "【仁甲看见SHOP】,感谢您购买仁甲看见SHOP素材。视频标题:$video[title],云盘地址:$video[two_url]";
}elseif ($video_id['attr'] == 2){
$content = "【仁甲看见SHOP】,感谢您购买仁甲看见SHOP素材。视频标题:$video[title],云盘地址:$video[four_url]";
}elseif ($video_id['attr'] == 3){
$content = "【仁甲看见SHOP】,感谢您购买仁甲看见SHOP素材。视频标题:$video[title],云盘地址:$video[eight_url]";
}
//发送短信
$send->sms($mobile,$content);
}
}
}
}
... ...