|
|
@@ -14,9 +14,12 @@ namespace App\Services\Api;
|
|
|
use App\Helpers\Jwt;
|
|
|
use App\Models\ActionLogModel;
|
|
|
use App\Models\MemberModel;
|
|
|
+use App\Models\OrderModel;
|
|
|
use App\Models\VipModel;
|
|
|
use App\Services\BaseService;
|
|
|
+use App\Services\ConfigService;
|
|
|
use App\Services\MpService;
|
|
|
+use App\Services\PaymentService;
|
|
|
use App\Services\RedisService;
|
|
|
use App\Services\SmsService;
|
|
|
use phpQrcode\QRcode;
|
|
|
@@ -96,23 +99,23 @@ class MemberService extends BaseService
|
|
|
}
|
|
|
|
|
|
// 更新
|
|
|
- if(!RedisService::get("caches:members:login_{$userId}")){
|
|
|
- $system = isset($params['system'])? $params['system'] : [];
|
|
|
- $system = $system && !is_array($system)? json_decode($system,true) : $system;
|
|
|
- $appSources = isset($system['app_sources']) && $system['app_sources']? $system['app_sources'] : 'ios';
|
|
|
- $uuid = isset($system['uuid'])? $system['uuid'] : '';
|
|
|
- $version = isset($system['app_version'])? $system['app_version'] : '';
|
|
|
+ if (!RedisService::get("caches:members:login_{$userId}")) {
|
|
|
+ $system = isset($params['system']) ? $params['system'] : [];
|
|
|
+ $system = $system && !is_array($system) ? json_decode($system, true) : $system;
|
|
|
+ $appSources = isset($system['app_sources']) && $system['app_sources'] ? $system['app_sources'] : 'ios';
|
|
|
+ $uuid = isset($system['uuid']) ? $system['uuid'] : '';
|
|
|
+ $version = isset($system['app_version']) ? $system['app_version'] : '';
|
|
|
$updateData = [
|
|
|
- 'update_time'=> time(),
|
|
|
- 'login_ip'=> get_client_ip(),
|
|
|
- 'login_time'=> time(),
|
|
|
- 'device_code'=> $uuid,
|
|
|
- 'login_count'=> DB::raw("login_count+1"),
|
|
|
- 'app_version'=> $version,
|
|
|
- 'device'=> $appSources=='ios'? 1 : 2,
|
|
|
+ 'update_time' => time(),
|
|
|
+ 'login_ip' => get_client_ip(),
|
|
|
+ 'login_time' => time(),
|
|
|
+ 'device_code' => $uuid,
|
|
|
+ 'login_count' => DB::raw("login_count+1"),
|
|
|
+ 'app_version' => $version,
|
|
|
+ 'device' => $appSources == 'ios' ? 1 : 2,
|
|
|
];
|
|
|
- $this->model->where(['id'=> $userId])->update($updateData);
|
|
|
- RedisService::set("caches:members:login_{$userId}",$updateData, rand(300,600));
|
|
|
+ $this->model->where(['id' => $userId])->update($updateData);
|
|
|
+ RedisService::set("caches:members:login_{$userId}", $updateData, rand(300, 600));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -123,7 +126,7 @@ class MemberService extends BaseService
|
|
|
// 结果返回
|
|
|
$result = [
|
|
|
'access_token' => $token,
|
|
|
- 'info' => ['uid' => $userId,'nickname' => $data['nickname']],
|
|
|
+ 'info' => ['uid' => $userId, 'nickname' => $data['nickname']],
|
|
|
];
|
|
|
|
|
|
// 用户缓存信息
|
|
|
@@ -141,7 +144,7 @@ class MemberService extends BaseService
|
|
|
* @param array $params
|
|
|
* @return array|false
|
|
|
*/
|
|
|
- public function mpAuth($code, $params=[])
|
|
|
+ public function mpAuth($code, $params = [])
|
|
|
{
|
|
|
// 账号登录
|
|
|
if (empty($code)) {
|
|
|
@@ -151,34 +154,34 @@ class MemberService extends BaseService
|
|
|
|
|
|
// 获取授权用户信息
|
|
|
$phone = '';
|
|
|
- $pcode = isset($params['pcode'])? $params['pcode'] : '';
|
|
|
- if($pcode){
|
|
|
+ $pcode = isset($params['pcode']) ? $params['pcode'] : '';
|
|
|
+ if ($pcode) {
|
|
|
$phoneData = MpService::make()->getPhoneNumber($pcode);
|
|
|
- $phoneData = isset($phoneData['phone_info'])? $phoneData['phone_info'] : [];
|
|
|
- $phone = isset($phoneData['phoneNumber'])? $phoneData['phoneNumber'] : '';
|
|
|
+ $phoneData = isset($phoneData['phone_info']) ? $phoneData['phone_info'] : [];
|
|
|
+ $phone = isset($phoneData['phoneNumber']) ? $phoneData['phoneNumber'] : '';
|
|
|
}
|
|
|
|
|
|
- if(empty($phone)){
|
|
|
+ if (empty($phone)) {
|
|
|
$this->error = 2014;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$userInfo = MpService::make()->getUserInfo($code);
|
|
|
- $openid = isset($userInfo['openid'])? $userInfo['openid'] : '';
|
|
|
- if(empty($userInfo)){
|
|
|
+ $openid = isset($userInfo['openid']) ? $userInfo['openid'] : '';
|
|
|
+ if (empty($userInfo)) {
|
|
|
$this->error = MpService::make()->getError();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if(empty($openid)){
|
|
|
+ if (empty($openid)) {
|
|
|
$this->error = 1042;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证是否注册,没有则注册
|
|
|
- $where = ['mobile'=>$phone,'mark' => 1];
|
|
|
+ $where = ['mobile' => $phone, 'mark' => 1];
|
|
|
$data = $this->model->where($where)
|
|
|
- ->select(['id','openid', 'mobile', 'user_type', 'nickname','entry_type','need_paper', 'code', 'status'])
|
|
|
+ ->select(['id', 'openid', 'mobile', 'user_type', 'nickname', 'entry_type', 'need_paper', 'code', 'status'])
|
|
|
->first();
|
|
|
$data = $data ? $data->toArray() : [];
|
|
|
$userId = isset($data['id']) ? $data['id'] : 0;
|
|
|
@@ -191,48 +194,47 @@ class MemberService extends BaseService
|
|
|
}
|
|
|
|
|
|
|
|
|
- $system = isset($params['system'])? $params['system'] : [];
|
|
|
- $system = $system && !is_array($system)? json_decode($system,true) : $system;
|
|
|
- $appSources = isset($system['app_sources']) && $system['app_sources']? $system['app_sources'] : 'ios';
|
|
|
- $uuid = isset($system['uuid'])? $system['uuid'] : '';
|
|
|
- $version = isset($system['app_version'])? $system['app_version'] : '';
|
|
|
- if(empty($data)){
|
|
|
+ $system = isset($params['system']) ? $params['system'] : [];
|
|
|
+ $system = $system && !is_array($system) ? json_decode($system, true) : $system;
|
|
|
+ $appSources = isset($system['app_sources']) && $system['app_sources'] ? $system['app_sources'] : 'ios';
|
|
|
+ $uuid = isset($system['uuid']) ? $system['uuid'] : '';
|
|
|
+ $version = isset($system['app_version']) ? $system['app_version'] : '';
|
|
|
+ if (empty($data)) {
|
|
|
|
|
|
- $userId = $this->model->max('id')+1;
|
|
|
+ $userId = $this->model->max('id') + 1;
|
|
|
$data = [
|
|
|
- 'nickname'=> $phone? '微信用户'.substr($phone,-6,6) : '微信用户'.$userId,
|
|
|
- 'openid'=> $openid,
|
|
|
- 'mobile'=> $phone,
|
|
|
- 'password'=> $phone? get_password(substr($phone,-6,6)) : get_password('123456'),
|
|
|
- 'login_ip'=> get_client_ip(),
|
|
|
- 'create_time'=> time(),
|
|
|
- 'login_time'=> time(),
|
|
|
- 'login_count'=> DB::raw("login_count+1"),
|
|
|
- 'app_version'=> $version,
|
|
|
- 'app_uuid'=> $uuid,
|
|
|
- 'device'=> $appSources=='ios'? 1 : 2,
|
|
|
+ 'nickname' => $phone ? '微信用户' . substr($phone, -6, 6) : '微信用户' . $userId,
|
|
|
+ 'openid' => $openid,
|
|
|
+ 'mobile' => $phone,
|
|
|
+ 'password' => $phone ? get_password(substr($phone, -6, 6)) : get_password('123456'),
|
|
|
+ 'login_ip' => get_client_ip(),
|
|
|
+ 'create_time' => time(),
|
|
|
+ 'login_time' => time(),
|
|
|
+ 'login_count' => DB::raw("login_count+1"),
|
|
|
+ 'app_version' => $version,
|
|
|
+ 'app_uuid' => $uuid,
|
|
|
+ 'device' => $appSources == 'ios' ? 1 : 2,
|
|
|
];
|
|
|
- if($this->model->insertGetId($data)){
|
|
|
+ if ($this->model->insertGetId($data)) {
|
|
|
$this->error = 2012;
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
- // 更新登录信息
|
|
|
- else if(!RedisService::get("caches:members:login_{$userId}")){
|
|
|
+ } // 更新登录信息
|
|
|
+ else if (!RedisService::get("caches:members:login_{$userId}")) {
|
|
|
$updateData = [
|
|
|
- 'login_ip'=> get_client_ip(),
|
|
|
- 'create_time'=> time(),
|
|
|
- 'login_time'=> time(),
|
|
|
- 'app_uuid'=> $uuid,
|
|
|
- 'login_count'=> DB::raw("login_count+1"),
|
|
|
- 'app_version'=> $version,
|
|
|
- 'device'=> $appSources=='ios'? 1 : 2,
|
|
|
+ 'login_ip' => get_client_ip(),
|
|
|
+ 'create_time' => time(),
|
|
|
+ 'login_time' => time(),
|
|
|
+ 'app_uuid' => $uuid,
|
|
|
+ 'login_count' => DB::raw("login_count+1"),
|
|
|
+ 'app_version' => $version,
|
|
|
+ 'device' => $appSources == 'ios' ? 1 : 2,
|
|
|
];
|
|
|
- if($openid){
|
|
|
+ if ($openid) {
|
|
|
$updateData['openid'] = $openid;
|
|
|
}
|
|
|
- $this->model->where(['id'=> $userId])->update($updateData);
|
|
|
- RedisService::set("caches:members:login_{$userId}",$updateData, rand(180,300));
|
|
|
+ $this->model->where(['id' => $userId])->update($updateData);
|
|
|
+ RedisService::set("caches:members:login_{$userId}", $updateData, rand(180, 300));
|
|
|
}
|
|
|
|
|
|
// 获取登录授权token
|
|
|
@@ -240,10 +242,10 @@ class MemberService extends BaseService
|
|
|
$token = $jwt->getToken($userId);
|
|
|
|
|
|
// 结果返回
|
|
|
- $setEntry = $entryType && $needPaper? 1 : 0;
|
|
|
+ $setEntry = $entryType && $needPaper ? 1 : 0;
|
|
|
$result = [
|
|
|
'access_token' => $token,
|
|
|
- 'info' => ['uid' => $userId,'openid'=>$openid,'set_entry'=>$setEntry,'nickname' => $data['nickname']],
|
|
|
+ 'info' => ['uid' => $userId, 'openid' => $openid, 'set_entry' => $setEntry, 'nickname' => $data['nickname']],
|
|
|
];
|
|
|
|
|
|
// 用户缓存信息
|
|
|
@@ -282,13 +284,13 @@ class MemberService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if(!$this->model->where(['id'=>$userId])->update(['password'=> get_password($password),'update_time'=>time()])){
|
|
|
+ if (!$this->model->where(['id' => $userId])->update(['password' => get_password($password), 'update_time' => time()])) {
|
|
|
$this->error = 2030;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 操作日志
|
|
|
- ActionLogModel::setRecord($userId,['type'=>2,'title'=>'重置密码','content'=>'重置登录密码','module'=>'member']);
|
|
|
+ ActionLogModel::setRecord($userId, ['type' => 2, 'title' => '重置密码', 'content' => '重置登录密码', 'module' => 'member']);
|
|
|
ActionLogModel::record();
|
|
|
|
|
|
$this->error = 2031;
|
|
|
@@ -300,15 +302,15 @@ class MemberService extends BaseService
|
|
|
* @param $where
|
|
|
* @param array $field
|
|
|
*/
|
|
|
- public function getInfo($where, array $field = [], $refresh=true)
|
|
|
+ public function getInfo($where, array $field = [], $refresh = true)
|
|
|
{
|
|
|
- $cacheKey = "caches:members:info_".(!is_array($where)? $where.'_':'').md5(json_encode($where).json_encode($field));
|
|
|
+ $cacheKey = "caches:members:info_" . (!is_array($where) ? $where . '_' : '') . md5(json_encode($where) . json_encode($field));
|
|
|
$info = RedisService::get($cacheKey);
|
|
|
- if($info && !$refresh){
|
|
|
+ if ($info && !$refresh) {
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
- $defaultField = ['id', 'user_type', 'realname', 'mobile', 'nickname','is_zg_vip','zg_vip_expired','is_zsb_vip','is_zsb_vip','zsb_vip_expired','is_video_vip','video_vip_expired','balance', 'code', 'openid', 'status', 'avatar'];
|
|
|
+ $defaultField = ['id', 'user_type', 'realname', 'mobile', 'nickname', 'is_zg_vip', 'zg_vip_expired', 'is_zsb_vip', 'is_zsb_vip', 'zsb_vip_expired', 'is_video_vip', 'video_vip_expired', 'balance', 'code', 'openid', 'status', 'avatar'];
|
|
|
$field = $field ? $field : $defaultField;
|
|
|
if (is_array($where)) {
|
|
|
$info = $this->model->where(['mark' => 1])->where($where)->select($field)->first();
|
|
|
@@ -326,28 +328,28 @@ class MemberService extends BaseService
|
|
|
$info['mobile_text'] = $info['mobile'] ? format_mobile($info['mobile']) : '';
|
|
|
}
|
|
|
|
|
|
- if(isset($info['create_time'])){
|
|
|
+ if (isset($info['create_time'])) {
|
|
|
$info['create_at'] = datetime(strtotime($info['create_time']));
|
|
|
}
|
|
|
|
|
|
$isVip = 0;
|
|
|
$vipExpired = '';
|
|
|
- $isZgVip = isset($info['is_zg_vip'])? $info['is_zg_vip'] : 0;
|
|
|
- $zgVipExpired = isset($info['zg_vip_expired']) && !empty($info['zg_vip_expired'])? $info['zg_vip_expired'] : '';
|
|
|
- if($isZgVip && $zgVipExpired && $zgVipExpired>date('Y-m-d H:i:s')){
|
|
|
+ $isZgVip = isset($info['is_zg_vip']) ? $info['is_zg_vip'] : 0;
|
|
|
+ $zgVipExpired = isset($info['zg_vip_expired']) && !empty($info['zg_vip_expired']) ? $info['zg_vip_expired'] : '';
|
|
|
+ if ($isZgVip==1 && $zgVipExpired && $zgVipExpired > date('Y-m-d H:i:s')) {
|
|
|
$isVip = 1;
|
|
|
$isZgVip = 1;
|
|
|
$vipExpired = $zgVipExpired;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$isZgVip = 0;
|
|
|
}
|
|
|
|
|
|
- $isZsbVip = isset($info['is_zsb_vip'])? $info['is_zsb_vip'] : 0;
|
|
|
- $zsbVipExpired = isset($info['zsb_vip_expired']) && !empty($info['zsb_vip_expired'])? $info['zsb_vip_expired'] : '';
|
|
|
- if($isZsbVip && $zsbVipExpired && $zsbVipExpired>date('Y-m-d H:i:s')){
|
|
|
+ $isZsbVip = isset($info['is_zsb_vip']) ? $info['is_zsb_vip'] : 0;
|
|
|
+ $zsbVipExpired = isset($info['zsb_vip_expired']) && !empty($info['zsb_vip_expired']) ? $info['zsb_vip_expired'] : '';
|
|
|
+ if ($isZsbVip==1 && $zsbVipExpired && $zsbVipExpired > date('Y-m-d H:i:s')) {
|
|
|
$isVip = 1;
|
|
|
- $vipExpired = $zsbVipExpired>$vipExpired? $zsbVipExpired : $vipExpired;
|
|
|
- }else{
|
|
|
+ $vipExpired = $zsbVipExpired > $vipExpired ? $zsbVipExpired : $vipExpired;
|
|
|
+ } else {
|
|
|
$isZsbVip = 0;
|
|
|
}
|
|
|
|
|
|
@@ -357,7 +359,7 @@ class MemberService extends BaseService
|
|
|
$info['vip_expired'] = $vipExpired;
|
|
|
$info['zg_vip_expired'] = $zgVipExpired;
|
|
|
$info['zsb_vip_expired'] = $zsbVipExpired;
|
|
|
- $info['video_vip_expired'] = isset($info['video_vip_expired']) && !empty($info['video_vip_expired'])? $info['video_vip_expired'] : '';
|
|
|
+ $info['video_vip_expired'] = isset($info['video_vip_expired']) && !empty($info['video_vip_expired']) ? $info['video_vip_expired'] : '';
|
|
|
RedisService::set($cacheKey, $info, rand(5, 10));
|
|
|
}
|
|
|
|
|
|
@@ -421,13 +423,13 @@ class MemberService extends BaseService
|
|
|
public function modify($userId, $params)
|
|
|
{
|
|
|
$cacheLockKey = "caches:members:modify_{$userId}";
|
|
|
- if(RedisService::get($cacheLockKey)){
|
|
|
+ if (RedisService::get($cacheLockKey)) {
|
|
|
$this->error = 1034;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 用户验证
|
|
|
- RedisService::set($cacheLockKey, ['user_id'=> $userId,'params'=>$params], rand(2,3));
|
|
|
+ RedisService::set($cacheLockKey, ['user_id' => $userId, 'params' => $params], rand(2, 3));
|
|
|
$info = $this->model->where(['id' => $userId, 'mark' => 1])
|
|
|
->select(['id', 'password', 'status'])
|
|
|
->first();
|
|
|
@@ -460,7 +462,7 @@ class MemberService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if(empty($newPassword)){
|
|
|
+ if (empty($newPassword)) {
|
|
|
$this->error = 1039;
|
|
|
RedisService::clear($cacheLockKey);
|
|
|
return false;
|
|
|
@@ -499,13 +501,13 @@ class MemberService extends BaseService
|
|
|
public function setEntry($userId, $params)
|
|
|
{
|
|
|
$cacheLockKey = "caches:members:entry_{$userId}";
|
|
|
- if(RedisService::get($cacheLockKey)){
|
|
|
+ if (RedisService::get($cacheLockKey)) {
|
|
|
$this->error = 1034;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 用户验证
|
|
|
- RedisService::set($cacheLockKey, ['user_id'=> $userId,'params'=>$params], rand(2,3));
|
|
|
+ RedisService::set($cacheLockKey, ['user_id' => $userId, 'params' => $params], rand(2, 3));
|
|
|
$info = $this->model->where(['id' => $userId, 'mark' => 1])
|
|
|
->select(['id', 'password', 'status'])
|
|
|
->first();
|
|
|
@@ -517,8 +519,8 @@ class MemberService extends BaseService
|
|
|
|
|
|
// 密码校验
|
|
|
$data = [
|
|
|
- 'entry_type'=> isset($params['entry_type'])? intval($params['entry_type']) : 0,
|
|
|
- 'need_paper'=> isset($params['need_paper'])? intval($params['need_paper']) : 0,
|
|
|
+ 'entry_type' => isset($params['entry_type']) ? intval($params['entry_type']) : 0,
|
|
|
+ 'need_paper' => isset($params['need_paper']) ? intval($params['need_paper']) : 0,
|
|
|
'update_time' => time()
|
|
|
];
|
|
|
|
|
|
@@ -538,23 +540,151 @@ class MemberService extends BaseService
|
|
|
* @param int $type
|
|
|
* @return array|mixed
|
|
|
*/
|
|
|
- public function getVipList($type=1)
|
|
|
+ public function getVipList($type = 1)
|
|
|
{
|
|
|
$cacheKey = "caches:members:vipList:{$type}";
|
|
|
$datas = RedisService::get($cacheKey);
|
|
|
- if($datas){
|
|
|
+ if ($datas) {
|
|
|
return $datas;
|
|
|
}
|
|
|
|
|
|
- $datas = VipModel::where(['type'=> $type,'status'=>1,'mark'=>1])
|
|
|
- ->select(['id','name','type','price','day','remark','status'])
|
|
|
- ->orderBy('id','asc')
|
|
|
+ $datas = VipModel::where(['type' => $type, 'status' => 1, 'mark' => 1])
|
|
|
+ ->select(['id', 'name', 'type', 'price', 'day', 'remark', 'status'])
|
|
|
+ ->orderBy('id', 'asc')
|
|
|
->get();
|
|
|
- $datas = $datas? $datas->toArray() : [];
|
|
|
- if($datas){
|
|
|
+ $datas = $datas ? $datas->toArray() : [];
|
|
|
+ if ($datas) {
|
|
|
RedisService::set($cacheKey, $datas, rand(3600, 7200));
|
|
|
}
|
|
|
|
|
|
return $datas;
|
|
|
}
|
|
|
+
|
|
|
+ public function vipBuy($userId, $vipId)
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:members:vipBuy:{$userId}_{$vipId}";
|
|
|
+ if (RedisService::get($cacheKey . '_lock')) {
|
|
|
+ $this->error = '请不要频繁提交~';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ RedisService::set($cacheKey, ['date' => date('Y-m-d H:i:s')], rand(2, 3));
|
|
|
+ $vipInfo = VipModel::where(['id' => $vipId, 'status' => 1, 'mark' => 1])
|
|
|
+ ->select(['id', 'type', 'price', 'day', 'status'])
|
|
|
+ ->first();
|
|
|
+ $price = isset($vipInfo['price']) ? floatval($vipInfo['price']) : 0;
|
|
|
+ $day = isset($vipInfo['day']) ? intval($vipInfo['day']) : 0;
|
|
|
+ $vipType = isset($vipInfo['type']) && $vipInfo['type']? intval($vipInfo['type']) : 1;
|
|
|
+ $vipName = isset($vipInfo['name'])? $vipInfo['name'] : '';
|
|
|
+ if (empty($vipInfo)) {
|
|
|
+ $this->error = '该VIP已下架';
|
|
|
+ RedisService::clear($cacheKey . '_lock');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($price <= 0 || $day <= 0) {
|
|
|
+ $this->error = '该VIP参数错误';
|
|
|
+ RedisService::clear($cacheKey . '_lock');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = $this->model->where(['id' => $userId, 'mark' => 1])
|
|
|
+ ->select(['id','is_zg_vip', 'zg_vip_expired','is_zsb_vip','zsb_vip_expired','is_video_vip','video_expired', 'status'])
|
|
|
+ ->first();
|
|
|
+ $isZgVip = isset($info['is_zg_vip'])? $info['is_zg_vip'] : '';
|
|
|
+ $isZsbVip = isset($info['is_zsb_vip'])? $info['is_zsb_vip'] : '';
|
|
|
+ $isVideoVip = isset($info['is_video_vip'])? $info['is_video_vip'] : '';
|
|
|
+ $zgVipExpired = isset($info['zg_vip_expired'])? $info['zg_vip_expired'] : '';
|
|
|
+ $zsbVipExpired = isset($info['zsb_vip_expired'])? $info['zsb_vip_expired'] : '';
|
|
|
+ $videoVipExpired = isset($info['zsb_vip_expired'])? $info['zsb_vip_expired'] : '';
|
|
|
+ if (!$info || $info['status'] != 1) {
|
|
|
+ $this->error = 1045;
|
|
|
+ RedisService::clear($cacheKey . '_lock');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证是否
|
|
|
+ $expiredTime = time();
|
|
|
+ $vipLimitOpen = ConfigService::make()->getConfigByCode('vip_limit_more', 1);
|
|
|
+ if($vipLimitOpen){
|
|
|
+ // 已开通职高VIP无法再开通
|
|
|
+ if($vipType == 1 && ($isZgVip==1 && $zgVipExpired >= date('Y-m-d H:i:s'))){
|
|
|
+ $this->error = '抱歉,您的职高VIP未到期,到期后再尝试~';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 已开通专升本VIP无法再开通
|
|
|
+ if($vipType == 2 && ($isZsbVip==1 && $zsbVipExpired >= date('Y-m-d H:i:s'))){
|
|
|
+ $this->error = '抱歉,您的专升本VIP未到期,到期后再尝试~';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 已开通全部视频VIP无法再开通
|
|
|
+ if($vipType == 3 && ($isVideoVip && $videoVipExpired >= date('Y-m-d H:i:s'))){
|
|
|
+ $this->error = '抱歉,您的已开通全部视频VIP,请到期后再尝试~';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if($vipType == 1 && $isZgVip==1 && $zgVipExpired >= date('Y-m-d H:i:s')){
|
|
|
+ $expiredTime = strtotime($zgVipExpired);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($vipType == 2 && $isZsbVip==1 && $zsbVipExpired >= date('Y-m-d H:i:s')){
|
|
|
+ $expiredTime = strtotime($zsbVipExpired);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($vipType == 3 && $isVideoVip==1 && $videoVipExpired >= date('Y-m-d H:i:s')){
|
|
|
+ $expiredTime = strtotime($videoVipExpired);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建订单
|
|
|
+ $orderNo = get_order_num('VP');
|
|
|
+ $order = [
|
|
|
+ 'order_no'=> $orderNo,
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'goods_id'=> $vipId,
|
|
|
+ 'total'=> $price,
|
|
|
+ 'expired_at'=> date('Y-m-d H:i:s', $expiredTime + $day * 86400),
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'remark'=> "购买{$vipName}VIP",
|
|
|
+ 'status'=>1,
|
|
|
+ 'mark'=>1
|
|
|
+ ];
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ if(!$orderId = OrderModel::insertGetId($order)){
|
|
|
+ $this->error = '创建购买订单失败';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* TODO 支付处理 */
|
|
|
+ $payOrder = [
|
|
|
+ 'type'=> 1,
|
|
|
+ 'order_no'=> $orderNo,
|
|
|
+ 'pay_money'=> $price,
|
|
|
+ 'body'=> "购买{$vipName}VIP",
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 调起支付
|
|
|
+ $payment = PaymentService::make()->wechatPay($info, $payOrder,'vip');
|
|
|
+ if(empty($payment)){
|
|
|
+ DB::rollBack();
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = PaymentService::make()->getError();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户操作记录
|
|
|
+ DB::commit();
|
|
|
+ $this->error = 2122;
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return [
|
|
|
+ 'order_id'=> $orderId,
|
|
|
+ 'payment'=> $payment,
|
|
|
+ 'total'=> $payOrder['pay_money'],
|
|
|
+ 'pay_type'=> $payType,
|
|
|
+ ];
|
|
|
+
|
|
|
+ }
|
|
|
}
|