// +---------------------------------------------------------------------- namespace app\wap\controller; use app\admin\model\special\SpecialBarrage; use app\wap\model\activity\EventRegistration; use app\wap\model\activity\EventSignUp; use app\wap\model\live\LiveStudio; use app\wap\model\special\Grade; use app\wap\model\special\Lecturer; use app\wap\model\special\Special as SpecialModel; use app\wap\model\special\SpecialBuy; use app\wap\model\special\SpecialContent; use app\wap\model\special\SpecialCourse; use app\wap\model\special\SpecialRecord; use app\wap\model\special\SpecialRelation; use app\wap\model\special\SpecialSource; use app\wap\model\special\SpecialSubject; use app\wap\model\special\SpecialTask; use app\wap\model\special\SpecialWatch; use app\wap\model\store\StoreCart; use app\wap\model\store\StoreOrder; use app\wap\model\store\StorePink; use app\wap\model\user\User; use service\CanvasService; use service\JsonService; use service\SystemConfigService; use service\UtilService; use think\cache\driver\Redis; use think\Cookie; use think\exception\HttpException; use think\response\Json; use think\Session; use think\Url; use think\Db; use think\Request; use service\VodService; class Special extends AuthController { /* * 白名单 * */ public static function WhiteList() { return [ 'details', 'get_pink_info', 'get_course_list', 'play', 'play_num', 'grade_list', 'set_barrage_index', 'get_barrage_list', 'special_cate', 'get_grade_cate', 'get_subject_cate', 'get_special_list', 'lecturerList', 'lecturerDetails', 'lecturerSpecial', 'teacher_detail', 'teacher_list', 'get_cloumn_task', 'activity_details', 'isMember', 'activityType', 'groupLists', ]; } /**获取视频上传地址和凭证 * @param string $videoId * @param int $type */ public function get_video_playback_credentials($type=1,$videoId='') { $url=VodService::videoUploadAddressVoucher('',$type,$videoId); return JsonService::successful($url); } /** * 专题详情 * @param $id int 专题id * @param $pinkId int 拼团id * @param $gift_uid int 赠送礼物用户 * @param $gift_order_id string 礼物订单号 * @return */ public function details($id = 0, $pinkId = 0, $gift_uid = 0, $gift_order_id = null, $link_pay_uid = 0, $partake = 0, $gift = 0, $link_pay = 0/*, $activity = 0*/) { if (!$id) $this->failed('缺少参数,无法访问', Url::build('index/index')); if ($gift_uid && $gift_order_id) { if ($gift_uid == $this->uid) $this->failed('您不能领取自己的礼物', Url::build('special/grade_list')); if (!User::get($gift_uid)) $this->failed('赠送礼物的用户不存在', Url::build('my/my_gift')); $order = StoreOrder::where(['is_del' => 0, 'order_id' => $gift_order_id])->find(); if (!$order) $this->failed('赠送的礼物订单不存在', Url::build('my/my_gift')); if ($order->total_num == $order->gift_count) $this->failed('礼物已被领取完',Url::build('special/grade_list')); } $special = SpecialModel::getOneSpecial($this->uid, $id, $pinkId); if ($special === false) $this->failed(SpecialModel::getErrorInfo('无法访问'), Url::build('index/index')); $special_money = SpecialModel::where('id', $id)->field('money, pay_type')->find(); if (in_array($special_money['money'], [0, 0.00]) || in_array($special_money['pay_type'], [PAY_NO_MONEY, PAY_PASSWORD])) { $isPay = 1; }else{ $isPay = (!$this->uid || $this->uid == 0) ? false : SpecialBuy::PaySpecial($id, $this->uid); } $site_name = SystemConfigService::get('site_name'); $seo_title = SystemConfigService::get('seo_title'); $site_logo = SystemConfigService::get('home_logo'); $isPink = false; if (!$isPay && $this->uid && !$pinkId) { $pinkId = StorePink::where(['cid' => $id, 'status' => '1', 'uid' => $this->uid])->order('add_time desc')->value('id'); if ($pinkId) { $isPink = true; } else { $pinkId = 0; } } $liveInfo = []; if (isset($special['special'])) { $specialinfo = $special['special']; $specialinfo = is_string($specialinfo) ? json_decode($specialinfo, true) : $specialinfo; if ((float)$specialinfo['money'] < 0) { $isPink = true; } if ($specialinfo['type'] == SPECIAL_LIVE) { $liveInfo = LiveStudio::where('special_id', $specialinfo['id'])->find(); if (!$liveInfo) return $this->failed('直播间尚未查到!', Url::build('index/index')); if ($liveInfo->is_del) return $this->failed('直播间已经删除!', Url::build('index/index')); } } if ($this->uid) SpecialRecord::record($id, $this->uid); $user_level = !$this->uid ? 0 : User::getUserInfo($this->uid); $type=json_decode($special['special'])->type; if($type!=5 && $type!=4){ $specialSourceId = SpecialSource::getSpecialSource($id); if($specialSourceId) $count=count($specialSourceId); else $count=0; }else{ $count=0; $specialSourceId = SpecialSource::getSpecialSource($id); if(count($specialSourceId)){ $specialSource=$specialSourceId->toArray(); foreach ($specialSource as $key=>$value){ $specialSourcetaskId = SpecialSource::getSpecialSource($value['source_id']); $count=bcadd($count,count($specialSourcetaskId),0); } } } $uids=Db::name('learning_records')->where(['special_id'=>$id])->column('uid'); $record=[]; $uids=array_unique($uids); foreach ($uids as $key=>$value){ $user=User::where('uid',$value)->field('nickname,avatar')->find(); if($user){ $user=$user->toArray(); array_push($record,$user); } } $this->assign($special); $this->assign('pinkId', $pinkId); $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0); $this->assign('count', $count); $this->assign('isPink', $isPink); $this->assign('record', json_encode($record)); $this->assign('isPay', $isPay); $this->assign('liveInfo', json_encode($liveInfo)); $this->assign('confing', compact('site_name', 'seo_title', 'site_logo')); $this->assign('orderId', $gift_order_id); $this->assign('partake', (int)$partake); $this->assign('link_pay', (int)$link_pay); $this->assign('gift', (int)$gift); $this->assign('link_pay_uid', $link_pay_uid); $this->assign('BarrageShowTime', SystemConfigService::get('barrage_show_time')); $this->assign('barrage_index', Cookie::get('barrage_index')); return $this->fetch(); } /** * 礼物领取 * * */ public function receive_gift($orderId = '') { if (!$orderId) return JsonService::fail('缺少参数'); if (StoreOrder::createReceiveGift($orderId, $this->uid) == false) return JsonService::fail(StoreOrder::getErrorInfo('领取失败')); else return JsonService::successful('领取成功'); } /** * 获取单个拼团详情 * $pinkId 拼团id * */ public function get_pink_info($pinkId = 0) { $is_ok = 0;//判断拼团是否完成 $userBool = 0;//判断当前用户是否在团内 0未在 1在 $pinkBool = 0;//判断当前用户是否在团内 0未在 1在 if(!$this->uid) return JsonService::fail('请先登录!'); $pink = StorePink::getPinkUserOne($pinkId); if (isset($pink['is_refund']) && $pink['is_refund']) { return JsonService::fail('订单已退款', ['special_id' => $pink['cid']]); } if (!$pink) return JsonService::fail('参数错误', ['url' => Url::build('my/index')]); list($pinkAll, $pinkT, $count, $idAll, $uidAll) = StorePink::getPinkMemberAndPinkK($pink); if ($pinkT['status'] == 2) $pinkBool = 1; else { if (!$count || $count < 0) {//组团完成 $pinkBool = StorePink::PinkComplete($uidAll, $idAll, $this->uid, $pinkT); } else {//拼团失败 退款 $pinkBool = StorePink::PinkFail($this->uid, $idAll, $pinkAll, $pinkT, (int)$count, $pinkBool, $uidAll); } } if ($pinkBool === false) return JsonService::fail(StorePink::getErrorInfo()); foreach ($pinkAll as $v) { if ($v['uid'] == $this->uid) $userBool = 1; } if ($pinkT['uid'] == $this->uid) $userBool = 1; $data['pinkBool'] = $pinkBool; $data['is_ok'] = $is_ok; $data['userBool'] = $userBool; $data['pinkT'] = $pinkT; $data['pinkAll'] = $pinkAll; $data['count'] = $count; $data['current_pink_order'] = StorePink::getCurrentPink($pinkId); $data['special'] = SpecialModel::getPinkSpecialInfo($pinkT['order_id'], $pinkId, $this->uid); return JsonService::successful($data); } /** * 专题收藏 * @param $id int 专题id * @return json */ public function collect($id = 0) { if (!$id) return JsonService::fail('缺少参数'); if (SpecialRelation::SetCollect($this->uid, $id)) return JsonService::successful(''); else return JsonService::fail(); } /** * 获取某个专题的任务视频列表 * @return json * */ public function get_course_list() { list($page, $limit, $special_id) = UtilService::getMore([ ['page', 1], ['limit', 10], ['special_id', 0], ], null, true); $uid=$this->uid ? $this->uid : 0; //不登录也能查看 $task_list = SpecialCourse::getSpecialSourceList($special_id, $limit, $page,$uid); if(!$task_list['list']) return JsonService::successful([]); foreach ($task_list['list'] as $k => $v) { $task_list['list'][$k]['type_name'] = SPECIAL_TYPE[$v['type']]; $task_list['list'][$k]['taskTrue']=SpecialWatch::whetherWatch($this->uid,$special_id,$v['id']); } return JsonService::successful($task_list); } /** * 获取专栏套餐 */ public function get_cloumn_task() { list($page, $limit, $special_id, $source_id) = UtilService::getMore([ ['page', 1], ['limit', 10], ['special_id', 0], ['source_id', 0], ], null, true); $uid=$this->uid ? $this->uid : 0; $task_list = SpecialCourse::get_cloumn_task($special_id, $source_id, $limit, $page,$uid); if(!$task_list['list']) return JsonService::successful([]); foreach ($task_list['list'] as $k => $v) { $task_list['list'][$k]['taskTrue']=SpecialWatch::whetherWatch($this->uid,$special_id,$v['id']); $task_list['list'][$k]['type_name'] = SPECIAL_TYPE[$v['type']]; } return JsonService::successful($task_list); } /** * 播放数量增加 * @param int $task_id 任务id * @return json * */ public function play_num($task_id = 0,$special_id=0) { if ($task_id == 0 || $special_id == 0) return JsonService::fail('缺少参数'); try{ $add_task_play_count = SpecialTask::bcInc($task_id, 'play_count', 1); if ($add_task_play_count) { $special_source = SpecialSource::getSpecialSource((int)$special_id, [$task_id]); if ($special_source) { SpecialSource::where(['special_id' => $special_id, 'source_id' => $task_id])->setInc('play_count',1); } return JsonService::successful('ok'); }else { return JsonService::fail('err'); } }catch (\Exception $e) { return JsonService::fail('err'); } } /** * 播放任务 * @param int $task_id 任务id * @return string * */ public function play($task_id = 0) { if (!$task_id) $this->failed('无法访问', Url::build('index/index')); Session::set('video_token_' . $task_id, md5(time() . $task_id)); $tash = SpecialTask::get($task_id); if (!$tash) $this->failed('您查看的资源不存在', Url::build('index/index')); if ($tash->is_show == 0) $this->failed('您查看的资源已下架', Url::build('index/index')); $this->assign('link', Trust($tash->link)); $this->assign('task_id', $task_id); return $this->fetch(); } public function go_video($task_id = 0) { if (Cookie::has('video_token_count_' . $task_id)) { Cookie::set('video_token_count_' . $task_id, Cookie::get('video_token_count_' . $task_id) + 1); } else { Cookie::set('video_token_count_' . $task_id, 1); } if (Session::has('video_token_' . $task_id)) { $tash = SpecialTask::get($task_id); if (Cookie::get('video_token_count_' . $task_id) >= 2) { Session::delete('video_token_' . $task_id); } exit(file_get_contents($tash->link)); } else { throw new HttpException(404, '您查看的链接不存在'); } } /** * 拼团支付完成后页面 * @param null $orderId * @return mixed|void */ public function pink($orderId = null) { if (is_null($orderId)) $this->failed('缺少参数', Url::build('my/order_list')); $info = StoreOrder::getOrderSpecialInfo($orderId, $this->uid); if ($info === false) return $this->failed(StoreOrder::getErrorInfo(), Url::build('my/order_list')); $site_url = SystemConfigService::get('site_url') . Url::build('special/details') . '?id=' . $info['special']['id'] . '&pinkId=' . $info['pinkT']['id'] . '&partake=1&spread_uid=' . $this->uid . '#partake'; $this->assign('special_id', $info['special_id']); $this->assign('site_url', $site_url); $this->assign('info', json_encode($info)); return $this->fetch(); } public function create_order(){ list($special_id, $pay_type_num, $payType, $pinkId, $total_num, $link_pay_uid,$signUp) = UtilService::PostMore([ ['special_id', 0], ['pay_type_num', -1], ['payType', 'weixin'], ['pinkId', 0], ['total_num', 1], ['link_pay_uid', 0], ['sign',''], ], $this->request, true); switch ($pay_type_num){ case 10://会员支付 $this->create_member_order($special_id,$payType); break; case 20://报名支付 $this->create_activity_order($special_id,$payType,$signUp); break; case 30://虚拟币充值 $auth_api = new AuthApi(); $auth_api->user_wechat_recharge($special_id, $payType); case 40: //商品购买 $this->create_goods_order($special_id,$payType,$signUp); break; case 50: //订单再次支付 $this->pay_order($special_id,$payType); break; default://专题支付 $this->create_special_order($special_id, $pay_type_num, $payType, $pinkId, $total_num, $link_pay_uid); } } /** * 创建专题支付订单 * @param int $special_id 专题id * @param int $pay_type 购买类型 1=礼物,2=普通购买,3=开团或者拼团 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function create_special_order($special_id, $pay_type_num, $payType, $pinkId, $total_num, $link_pay_uid) { if (!$special_id) return JsonService::fail('缺少购买参数'); if ($pay_type_num == -1) return JsonService::fail('选择购买方式'); if ($pinkId) { $orderId = StoreOrder::getStoreIdPink($pinkId); if (StorePink::getIsPinkUid($pinkId)) return JsonService::status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => $orderId]); if (StoreOrder::getIsOrderPink($pinkId)) return JsonService::status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => $orderId]); if (StorePink::getPinkStatusIng($pinkId)) return JsonService::status('ORDER_EXIST', '拼团已完成或者已过期无法参团', ['orderId' => $orderId]); if (StorePink::be(['uid' => $this->uid, 'type' => 1, 'cid' => $special_id, 'status' => 1])) return JsonService::status('ORDER_EXIST', '您已参见本专题的拼团,请结束后再进行参团'); if (SpecialBuy::be(['uid' => $this->uid, 'special_id' => $special_id, 'is_del' => 0])) return JsonService::status('ORDER_EXIST', '您已购买此专题,不能在进行参团!'); //处理拼团完成 try { if ($pink = StorePink::get($pinkId)) { list($pinkAll, $pinkT, $count, $idAll, $uidAll) = StorePink::getPinkMemberAndPinkK($pink); if ($pinkT['status'] == 1) { if (!$count || $count < 0) { StorePink::PinkComplete($uidAll, $idAll, $pinkT['uid'], $pinkT); return JsonService::status('ORDER_EXIST', '当前拼团已完成,无法参团'); } else StorePink::PinkFail($pinkT['uid'], $idAll, $pinkAll, $pinkT, $count, 0, $uidAll); } else if ($pinkT['status'] == 2) { return JsonService::status('ORDER_EXIST', '当前拼团已完成,无法参团'); } else if ($pinkT['status'] == 3) { return JsonService::status('ORDER_EXIST', '拼团失败,无法参团'); } } } catch (\Exception $e) { } } $special = SpecialModel::PreWhere()->find($special_id); if (!$special) return JsonService::status('ORDER_ERROR', '购买的专题不存在'); $order = StoreOrder::createSpecialOrder($special, $pinkId, $pay_type_num, $this->uid, $payType, $link_pay_uid, $total_num); $orderId = $order['order_id']; $info = compact('orderId'); if ($orderId) { $orderInfo = StoreOrder::where('order_id', $orderId)->find(); if (!$orderInfo || !isset($orderInfo['paid'])) return JsonService::status('pay_error', '支付订单不存在!'); if ($orderInfo['paid']) return JsonService::status('pay_error', '支付已支付!'); if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) { if (StoreOrder::jsPayPrice($orderId, $this->userInfo['uid'])) return JsonService::status('success', '微信支付成功', $info); else return JsonService::status('pay_error', StoreOrder::getErrorInfo()); } switch ($payType) { case 'weixin': try { $jsConfig = StoreOrder::jsSpecialPay($orderId); } catch (\Exception $e) { return JsonService::status('pay_error', $e->getMessage(), $info); } $info['jsConfig'] = $jsConfig; return JsonService::status('wechat_pay', '订单创建成功', $info); break; case 'yue': if (StoreOrder::yuePay($orderId, $this->userInfo['uid'])) return JsonService::status('success', '余额支付成功', $info); else return JsonService::status('pay_error', StoreOrder::getErrorInfo()); break; case 'zhifubao': $info['pay_price'] = $orderInfo['pay_price']; $info['orderName'] = '专题购买'; return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info))); break; } } else { return JsonService::fail(StoreOrder::getErrorInfo('订单生成失败!')); } } /**会员订单创建 * @param $id * @param $payType * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function create_member_order($id,$payType) { if(!$id) return JsonService::fail('参数错误!'); $order = StoreOrder::cacheMemberCreateOrder($this->userInfo['uid'],$id,$payType); $orderId = $order['order_id']; $info = compact('orderId'); if ($orderId) { $orderInfo = StoreOrder::where('order_id', $orderId)->find(); if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!'); if ($orderInfo['paid']) exception('支付已支付!'); if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) { if (StoreOrder::jsPayMePrice($orderId, $this->userInfo['uid'])) return JsonService::status('success', '领取成功', $info); else return JsonService::status('pay_error', StoreOrder::getErrorInfo()); } else { switch ($payType) { case 'weixin': try { $jsConfig = StoreOrder::jsPayMember($orderId); } catch (\Exception $e) { return JsonService::status('pay_error', $e->getMessage(), $info); } $info['jsConfig'] = $jsConfig; return JsonService::status('wechat_pay', '订单创建成功', $info); break; case 'zhifubao': $info['pay_price'] = $orderInfo['pay_price']; $info['orderName'] = '会员购买'; return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info))); break; } } } else { return JsonService::fail(StoreOrder::getErrorInfo('领取失败!')); } } /** * 用户提交报名 */ public function create_activity_order($id,$payType,$signUp){ if (!$id) JsonService::fail('参数有误'); $order=EventSignUp::userEventSignUp($id,$signUp,$payType,$this->userInfo['uid']); $orderId = $order['order_id']; $info = compact('orderId'); if ($orderId) { $orderInfo = EventSignUp::where('order_id', $orderId)->find(); if (!$orderInfo || !isset($orderInfo['paid'])) return JsonService::status('pay_error', '支付订单不存在!'); if ($orderInfo['paid']) return JsonService::status('pay_error', '支付已支付!'); if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) { if (EventSignUp::jsPayPrice($orderId, $this->userInfo['uid'])) return JsonService::status('success', '支付成功', $info); else return JsonService::status('pay_error', EventSignUp::getErrorInfo()); } switch ($payType) { case 'weixin': try { $jsConfig = EventSignUp::jsPay($orderId); } catch (\Exception $e) { return JsonService::status('pay_error', $e->getMessage(), $info); } $info['jsConfig'] = $jsConfig; return JsonService::status('wechat_pay', '订单创建成功', $info); break; case 'yue': if (EventSignUp::yuePay($orderId, $this->userInfo['uid'])) return JsonService::status('success', '余额支付成功', $info); else return JsonService::status('pay_error', EventSignUp::getErrorInfo()); break; case 'zhifubao': $info['pay_price'] = $orderInfo['pay_price']; $info['orderName'] = '活动报名'; return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info))); break; } } else { return JsonService::fail(EventSignUp::getErrorInfo('订单生成失败!')); } } /** * 购买完成后送礼物页面 * @param string $orderId 订单id * @return strign * */ public function gift_special($orderId = null) { if (is_null($orderId)) $this->failed('缺少订单号,无法进行赠送',Url::build('my/my_gift')); $uid=$this->uid; if(!$uid)$this->failed('未获取到用户信息!',Url::build('index/index')); $special = StoreOrder::getOrderIdToSpecial($orderId,$uid); if ($special === false) $this->failed(StoreOrder::getErrorInfo(),Url::build('my/my_gift')); $this->assign([ 'orderId'=>$orderId, 'title'=>'赠送礼物', 'special_gift_banner'=>SystemConfigService::get('special_gift_banner'), 'site_url'=>SystemConfigService::get('site_url') . Url::build('special/details') . '?id=' . $special['id'] . '&gift_uid=' . $this->uid . '&gift_order_id=' . $orderId . '&gift=1&spread_uid=' . $this->uid, 'special'=>$special ]); return $this->fetch(); } /** * 查看领取记录 * @param $orderId string 订单id * @return html * */ public function gift_receive($orderId = null) { if (is_null($orderId)) $this->failed('缺少订单号,无法查看领取记录',Url::build('my/my_gift')); $special = StoreOrder::getOrderIdGiftReceive($orderId); if ($special === false) $this->failed(StoreOrder::getErrorInfo(),Url::build('my/my_gift')); $this->assign($special); $this->assign('special_gift_banner', SystemConfigService::get('special_gift_banner')); return $this->fetch(); } /** * 购买失败删除订单 * @param string $orderId 订单id * @return json * */ public function del_order($orderId = '') { if (StoreOrder::where('order_id', $orderId)->update(['is_del' => 1])) return JsonService::successful(); else return JsonService::fail(); } public function grade_list($type = 0) { $this->assign(compact('type')); return $this->fetch(); } /** * 获取我购买的课程 * @param int $type 课程类型 * @param int $page 分页 * @param int $limit 一页显示多少条 * @return json * */ public function get_grade_list($type = 0, $page = 1, $limit = 10, $search = '') { return JsonService::successful(SpecialModel::getGradeList($type, (int)$page, (int)$limit, $this->uid, $search)); } /** * 拼团成功朋友圈海报展示 * @param $special_id int 专题id * @return html * */ public function poster_show($special_id = 0, $pinkId = 0, $is_help = 0) { if (!$special_id || !$pinkId) $this->failed('您查看的朋友去圈海报不存在',Url::build('spread/special')); $special = SpecialModel::getSpecialInfo($special_id); if ($special === false) $this->failed(SpecialModel::getErrorInfo(),Url::build('spread/special')); if (!$special['poster_image']) $this->failed('您查看的海报不存在',Url::build('spread/special')); $site_url = SystemConfigService::get('site_url') . Url::build('special/details') . '?id=' . $special['id'] . '&pinkId=' . $pinkId . '&partake=1' . ($is_help ? '&spread_uid=' . $this->uid : ''); try { $filename = CanvasService::startPosterSpeclialIng($special_id, $special['poster_image'], $site_url); } catch (\Exception $e) { return $this->failed($e->getMessage(),Url::build('spread/special')); } $this->assign('filename', $filename); $this->assign('special', $special); $this->assign('is_help', $is_help); $this->assign('site_url', $site_url); return $this->fetch(); } /** * 查看单个拼团状态 * @param $pink_id int 拼团id * @return html * */ public function order_pink($pink_id = '', $is_help = 0) { if (!$pink_id) $this->failed('缺少订单号',Url::build('my/order_list')); $this->assign([ 'pink_id' => $pink_id, 'is_help' => $is_help, ]); return $this->fetch(); } /** * 获取专题弹幕 * @param int $special_id 专题id * @return json * */ public function get_barrage_list($special_id = 0) { if(!$special_id) return JsonService::fail('确实参数!'); if (SystemConfigService::get('open_barrage')) { $barrage = SpecialBarrage::where('is_show', 1)->order('sort desc,id desc')->field(['nickname', 'avatar', 'action'])->select(); $barrage = count($barrage) ? $barrage->toArray() : []; foreach ($barrage as &$item) { $item['status_name'] = $item['action'] == 1 ? '1秒前发起了拼团' : '1秒前成功参团'; unset($item['action']); } $special=SpecialModel::where('id',$special_id)->find(); if(!$special) return JsonService::fail('确实参数!'); if($special['is_pink']){ $pinkList = StoreOrder::where(['o.cart_id' => $special_id, 'p.is_refund' => 0, 'o.refund_status' => 0, 'o.paid' => 1, 'p.is_false' => 0]) ->join("__STORE_PINK__ p", 'p.order_id=o.order_id') ->join('__USER__ u', 'u.uid=o.uid') ->field(['u.nickname', 'u.avatar', 'p.status', 'p.k_id']) ->group('o.order_id') ->order('o.add_time desc') ->alias('o') ->select(); $pinkList = count($pinkList) ? $pinkList->toArray() : []; foreach ($pinkList as &$item) { if ($item['status'] == 2 && $item['k_id'] == 0) { $item['status_name'] = '1秒前拼团成功'; } else if ($item['status'] == 1 && $item['k_id'] == 0) $item['status_name'] = '1秒前发起了拼团'; else if ($item['status'] == 2 && $item['k_id'] != 0) $item['status_name'] = '1秒前拼团成功'; else if ($item['status'] == 1 && $item['k_id'] != 0) $item['status_name'] = '1秒前发起了拼团'; else if ($item['status'] == 3) $item['status_name'] = '1秒前参团成功'; unset($item['status'], $item['k_id']); } $barrageList = array_merge($pinkList, $barrage); shuffle($barrageList); }else{ $barrageList = []; } } else $barrageList = []; return JsonService::successful($barrageList); } /** * 拼团列表 */ public function groupLists($special_id=0) { if(!$special_id) return JsonService::fail('确实参数!'); $special=SpecialModel::where('id',$special_id)->find(); if(!$special) return JsonService::fail('确实参数!'); if($special['is_pink']) { $pinkList = StoreOrder::where(['o.cart_id' => $special_id, 'p.is_refund' => 0, 'o.refund_status' => 0, 'o.paid' => 1, 'p.is_false' => 0]) ->join("__STORE_PINK__ p", 'p.order_id=o.order_id') ->join('__USER__ u', 'u.uid=o.uid') ->field(['u.nickname', 'u.avatar', 'p.status', 'p.k_id']) ->group('o.order_id') ->order('o.add_time desc') ->alias('o') ->select(); $pinkList = count($pinkList) ? $pinkList->toArray() : []; }else{ $pinkList =[]; } return JsonService::successful($pinkList); } /** * 获取滚动index * @param int $index */ public function set_barrage_index($index = 0) { return JsonService::successful(Cookie::set('barrage_index', $index)); } /** * 专题分类 * @return mixed */ public function special_cate($cate_id = 0,$subject_id=0) { $this->assign([ 'homeLogo' => SystemConfigService::get('home_logo'), 'cate_id' => (int)$cate_id, 'subject_id' => (int)$subject_id ]); return $this->fetch(); } /** * 获取一级分类 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function get_grade_cate() { return JsonService::successful(Grade::where(['is_del'=>0,'is_show'=>1])->order('sort desc,id desc')->select()); } /** * 获取二级分类 * @param int $grade_id * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function get_subject_cate($grade_id = 0) { if (!$grade_id) { return JsonService::fail('缺少一级分类id'); } return JsonService::successful(SpecialSubject::where(['is_show' => 1, 'grade_id' => $grade_id,'is_del'=>0])->order('sort desc,id desc')->select()); } /** * 获取专题 * @param int $subject_id * @param string $search * @param int $page * @param int $limit */ public function get_special_list($subject_id = 0, $search = '', $page = 1, $limit = 10, $type = 0) { if (!$subject_id && $type == 0) { return JsonService::fail('缺少二级分类id'); } $uid = $this->uid; return JsonService::successful(SpecialModel::getSpecialList(compact('subject_id', 'search', 'page', 'limit', 'type', 'uid'))); } /** * 获取拼团专题 */ public function get_pink_special_list() { list($page, $limit) = UtilService::PostMore([ ['page', 1], ['limit', 10] ], $this->request, true); return JsonService::successful(SpecialModel::getPinkSpecialList($page, $limit)); } /** * 学习记录 * @return mixed */ public function record() { $this->assign([ 'homeLogo' => SystemConfigService::get('home_logo'), ]); return $this->fetch(); } /** * 是否可以播放 * @param int $task_id 任务id * @return string * */ public function get_task_link($task_id = 0) { $special_id = $this->request->param('special_id',0); if (!$special_id) return JsonService::fail('无法访问'); if (!$task_id) return JsonService::fail('无法访问'); $special_source = SpecialSource::getSpecialSource($special_id,[$task_id]); $tash = $special_source ? $special_source->toArray() : []; if (!$tash) { return JsonService::fail('您查看的视频已经下架'); }else{ return JsonService::successful($tash); } } /** * 课程详情 * @param $id * @return mixed|void * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function task_info($id = 0, $specialId = 0) { if (!$id) { return $this->failed('缺少课程id,无法查看',Url::build('index/index')); } $taskInfo = SpecialTask::defaultWhere()->where('id', $id)->find(); $special = SpecialModel::PreWhere()->where('id', $specialId)->find(); if (!$special) { return $this->failed('您查看得专题不存在',Url::build('index/index')); } if (!$taskInfo) { return $this->failed('课程信息不存在无法观看',Url::build('index/index')); } if ($taskInfo['is_show'] == 0) { return $this->failed('该课程已经下架',Url::build('index/index')); } $isPay = SpecialBuy::PaySpecial($specialId, $this->uid); $special_content = SpecialContent::where('special_id',$specialId)->value("content"); $content = htmlspecialchars_decode($taskInfo->detail ? $taskInfo->detail : $special_content); $user_level = !$this->uid ? 0 : User::getUserInfo($this->uid); $taskInfo->content = $content; if ($isPay || $special->pay_type == 0 || ($user_level['level'] > 0 && $special->member_pay_type == 0)) { $isPay = true; }else{ $special_source = SpecialSource::where(['special_id' => $specialId,'source_id' => $id, 'pay_status' => 0])->find(); if (!$special_source) { return $this->failed('您选择的素材不存在',Url::build('special/details',array('id'=>$specialId))); }else{ $special_source = $special_source->toArray(); $taskInfo = SpecialTask::defaultWhere()->order('sort DESC')->where('id', $special_source['source_id'])->find(); if(!$taskInfo){ return $this->failed('您选择的素材不存在',Url::build('special/details',array('id'=>$specialId))); } $taskInfo->content = $content; } } $this->assign('taskInfo', json_encode($taskInfo ? $taskInfo->toArray() : [])); $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0); $this->assign('specialId', (int)$specialId); $this->assign('specialInfo', json_encode($special->toArray())); $this->assign('isPay', (int)$isPay); return $this->fetch(); } /**检测用户身份 * @throws \Exception */ public function isMember() { $user_level = !$this->uid ? 0 : User::getUserInfo($this->uid); $data['is_member']=isset($user_level['level']) ? $user_level['level'] : 0; $data['now_money']=isset($user_level['now_money']) ? $user_level['now_money'] : 0; return JsonService::successful($data); } /** * 图文素材详情 */ public function task_text_info($id = 0, $specialId = 0) { if (!$id) { return $this->failed('缺少课程id,无法查看',Url::build('index/index')); } $taskInfo = SpecialTask::defaultWhere()->where('id', $id)->find(); $special = SpecialModel::PreWhere()->where('id', $specialId)->find(); if (!$special) { return $this->failed('您查看得专题不存在',Url::build('index/index')); } if (!$taskInfo) { return $this->failed('课程信息不存在无法观看',Url::build('index/index')); } if ($taskInfo['is_show'] == 0) { return $this->failed('该课程已经下架',Url::build('index/index')); } $isPay = SpecialBuy::PaySpecial($specialId, $this->uid); $content = htmlspecialchars_decode($taskInfo->content ? $taskInfo->content : ""); $user_level = !$this->uid ? 0 : User::getUserInfo($this->uid); $taskInfo->content = $content; if ($isPay || $special->pay_type == 0 || ($user_level['level'] > 0 && $special->member_pay_type == 0)) { $isPay = true; }else{ $special_source = SpecialSource::where(['special_id' => $specialId,'source_id' => $id,'pay_status' => 0])->find(); if (!$special_source) { return $this->failed('您选择的素材不存在',Url::build('special/details',array('id'=>$specialId))); }else{ $special_source = $special_source->toArray(); $taskInfo = SpecialTask::defaultWhere()->order('sort DESC')->where('id', $special_source['source_id'])->find(); if(!$taskInfo){ return $this->failed('您选择的素材不存在',Url::build('special/details',array('id'=>$specialId))); } $taskInfo->content = $content; } } $this->assign('taskInfo', json_encode($taskInfo ? $taskInfo->toArray() : [])); $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0); $this->assign('specialId', (int)$specialId); $this->assign('specialInfo', json_encode($special->toArray())); $this->assign('isPay', (int)$isPay); return $this->fetch('text_detail'); } /** * 会员页 * @return mixed */ public function member_manage($type=1,$bid=0){ $userInfo=User::getUserInfo($this->uid); $this->assign(['type'=>$type,'bid'=>$bid,'userInfo'=>$userInfo]); return $this->fetch('member/member_manage'); } /** * 会员购买页 * @return mixed */ public function member_recharge(){ $servicePhone=SystemConfigService::get('site_phone')?:''; $this->assign(['servicePhone'=>$servicePhone]); return $this->fetch('member/member_recharge'); } /** * 充值页面 */ public function recharge_index($from='live',$stream_name = "") { $user_info = $this->userInfo; $gold_info = SystemConfigService::more("gold_name,gold_rate,gold_image"); $recharge_price_list = [60,100,300,500,980,1980,2980,5180,15980]; $gold_name=SystemConfigService::get('gold_name');//虚拟币名称 $this->assign(compact('gold_name')); $this->assign('from',$from); $this->assign('stream_name',$stream_name); $this->assign('gold_info',json_encode($gold_info)); $this->assign('recharge_price_list',json_encode($recharge_price_list)); $this->assign('user_gold_num',$user_info['gold_num']); return $this->fetch('my/gold_coin'); } /** * 储存素材观看时间 */ public function viewing($special_id=0,$task_id=0,$time=0){ return JsonService::successful(SpecialWatch::materialViewing($this->userInfo['uid'],$special_id,$task_id,$time)); } /** * 活动报名情况 */ public function activityType($id){ $activity = EventRegistration::oneActivitys($id); if (!$activity) $this->failed('您查看的活动不存在',Url::build('activity/index')); $data['is_pay']=0;//是否购买报名过 $data['is_restrictions']=0; //是否超过限购 if($this->userInfo['uid']){ $signCount=EventSignUp::where('activity_id',$id)->where('uid',$this->userInfo['uid'])->where('paid',1)->count(); if($signCount){ $data['is_pay']=1; if(bcsub($signCount,$activity['restrictions'],0)>=0 && $activity['restrictions']>0) $data['is_restrictions']=1; } } return JsonService::successful($data); } /**活动报名 * @param string $id * @return mixed * @throws \think\Exception */ public function activity_details($id = '') { $activity = EventRegistration::oneActivitys($id); if (!$activity) $this->failed('您查看的活动不存在',Url::build('activity/index')); $this->assign([ 'is_member' => isset($this->userInfo['level']) ? $this->userInfo['level'] : 0, 'is_fill'=>$activity['is_fill'], 'activity' => json_encode($activity), 'activity_rules' => htmlspecialchars_decode($activity['activity_rules']), 'content' => htmlspecialchars_decode($activity['content']) ]); return $this->fetch('activity/index'); } /**商品订单提交 * @param string $cartId * @return mixed|void * @throws \Exception */ public function confirm_order($cartId = '') { if(!is_string($cartId) || !$cartId ){ return $this->failed('请提交购买的商品!',Url::build('store/index')); } $user=User::getUserInfo($this->userInfo['uid']); $cartGroup = StoreCart::getUserProductCartList($this->userInfo['uid'],$cartId,1,$user['level']); if(count($cartGroup['invalid'])) return $this->failed($cartGroup['invalid'][0]['productInfo']['store_name'].'已失效!',Url::build('store/index')); if(!$cartGroup['valid']) return $this->failed('请提交购买的商品!',Url::build('store/index')); $cartInfo = $cartGroup['valid']; $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo); $this->assign([ 'level'=>$user['level'], 'cartInfo'=>json_encode($cartInfo), 'cartId'=>$cartId, 'priceGroup'=>json_encode($priceGroup), 'orderKey'=>StoreOrder::cacheOrderInfo($this->userInfo['uid'],$cartInfo,$priceGroup), 'userInfo'=>json_encode($user) ]); return $this->fetch('store/order_confirm'); } /**订单提交页修改商品数量 * @param string $cartId * @param int $cateNum */ public function getOrderPrice($cartId='',$cateNum=1,$price,$postage) { StoreCart::beginTrans(); $res=StoreCart::changeUserCartNum($cartId,$cateNum,$this->userInfo['uid']); if(!$res)return JsonService::fail('商品数量修改失败!'); $user=User::getUserInfo($this->userInfo['uid']); $cartGroup = StoreCart::getUserProductCartList($this->userInfo['uid'],$cartId,1,$user['level']); if(count($cartGroup['invalid'])) return $this->failed($cartGroup['invalid'][0]['productInfo']['store_name'].'已失效!',Url::build('store/index')); if(!$cartGroup['valid']) return $this->failed('请提交购买的商品!',Url::build('store/index')); $cartInfo = $cartGroup['valid']; $data['priceGroup']=StoreOrder::getOrderPriceGroup($cartInfo); if(bcsub($data['priceGroup']['totalPrice'],bcsub($price,$postage,2),2)==0 && bcsub($data['priceGroup']['storePostage'],$postage,2)==0){ StoreCart::commitTrans(); $data['orderKey']=StoreOrder::cacheOrderInfo($this->userInfo['uid'],$cartInfo,$data['priceGroup']); return JsonService::successful($data); }else{ StoreCart::rollbackTrans(); return JsonService::fail('网络异常!'); } } /** * 创建商品订单 * @param string $key * @return \think\response\Json */ public function create_goods_order($addressId,$payType,$signUp) { $data=json_decode($signUp,true); if (!$data['key']) return JsonService::fail('参数错误!'); $key=$data['key']; $mark=$data['mark']; if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $this->userInfo['uid'], 'is_del' => 0, 'type' => 2])) return JsonService::status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]); $payType = strtolower($payType); $order = StoreOrder::cacheKeyCreateOrder($this->userInfo['uid'], $key, $addressId, $payType,$mark); $orderId = $order['order_id']; $info = compact('orderId', 'key'); if ($orderId) { $orderInfo = StoreOrder::where('order_id', $orderId)->where('type',2)->find(); if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!'); if ($orderInfo['paid']) exception('支付已支付!'); if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) { if (StoreOrder::jsPayGoodsPrice($orderId, $this->userInfo['uid'])) return JsonService::status('success', '支付成功', $info); else return JsonService::status('pay_error', StoreOrder::getErrorInfo()); } switch ($payType) { case 'weixin': try { $jsConfig = StoreOrder::jsPay($orderId); } catch (\Exception $e) { return JsonService::status('pay_error', $e->getMessage(), $info); } $info['jsConfig'] = $jsConfig; return JsonService::status('wechat_pay', '订单创建成功', $info); break; case 'yue': if (StoreOrder::yueGoodsPay($orderId, $this->userInfo['uid'])) return JsonService::status('success', '余额支付成功', $info); else return JsonService::status('pay_error', StoreOrder::getErrorInfo()); break; case 'zhifubao': $info['pay_price'] = $orderInfo['pay_price']; $info['orderName'] = '商品购买'; return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info))); break; } } else { return JsonService::fail(StoreOrder::getErrorInfo('订单生成失败!')); } } /** * 我的商品订单 */ public function order_store_list($type=0) { $this->assign(['type'=>$type]); return $this->fetch('my/order_store_list'); } /** * 订单详情 * @return mixed */ public function order($uni='') { if (!$uni || !$order = StoreOrder::getUserOrderDetail($this->userInfo['uid'], $uni)) return $this->redirect(Url::build('order_list')); $this->assign([ 'order' => StoreOrder::tidyOrder($order, true,true) ]); return $this->fetch('my/order'); } /** * 支付订单 * @param string $uni * @return \think\response\Json */ public function pay_order($id = 0,$payType) { if (!$id) return JsonService::fail('参数错误!'); $order = StoreOrder::where('id', $id)->where('type',2)->where('uid', $this->userInfo['uid'])->where('is_del', 0)->find(); if (!$order) return JsonService::fail('订单不存在!'); if ($order['paid']) return JsonService::fail('该订单已支付!'); $info['orderId'] =$order['order_id']; if($payType!=$order['pay_type']){ $res=StoreOrder::where('id', $id)->where('type',2)->where('uid', $this->userInfo['uid'])->where('is_del', 0)->update(['pay_type'=>$payType]); if(!$res)return JsonService::fail('订单支付方式修改失败!'); } if ($payType == 'weixin') { try { $jsConfig = StoreOrder::jsPay($order); } catch (\Exception $e) { return JsonService::fail($e->getMessage()); } $info['jsConfig']=$jsConfig; return JsonService::status('wechat_pay', '订单创建成功', $info); } else if ($payType == 'yue') { if ($res = StoreOrder::yueGoodsPay($order['order_id'], $this->userInfo['uid'])) return JsonService::status('success','余额支付成功',$info); else return JsonService::status('pay_error', StoreOrder::getErrorInfo()); } else if ($payType == 'zhifubao') { $info['pay_price'] = $order['pay_price']; $info['orderName'] = '商品购买'; return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info))); } } /** * 讲师详情 * @return mixed */ public function teacher_detail($id=0) { $this->assign('id',$id); return $this->fetch(); } /** * 讲师列表 * @return mixed */ public function teacher_list() { return $this->fetch(); } /** * 获取讲师详情 * @param $id */ public function lecturerDetails($id) { $lecturer=Lecturer::details($id); return JsonService::successful($lecturer); } /** * 讲师名下课程 * @param int $lecturer_id */ public function lecturerSpecial() { list($lecturer_id, $page, $limit) = UtilService::PostMore([ ['lecturer_id', 0], ['page', 1], ['limit', 10] ], $this->request, true); $list=SpecialModel::getLecturerSpecialList($lecturer_id,$page,$limit); return JsonService::successful($list); } /** * 讲师列表 */ public function lecturerList() { list($page,$limit) = UtilService::GetMore([ ['page', 1], ['limit', 10] ], $this->request, true); $list=Lecturer::getLecturer($page,$limit); return JsonService::successful($list); } }