Special.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\controller;
  12. use app\admin\model\special\SpecialBarrage;
  13. use app\wap\model\activity\EventRegistration;
  14. use app\wap\model\activity\EventSignUp;
  15. use app\wap\model\live\LiveStudio;
  16. use app\wap\model\special\Grade;
  17. use app\wap\model\special\Lecturer;
  18. use app\wap\model\special\Special as SpecialModel;
  19. use app\wap\model\special\SpecialBuy;
  20. use app\wap\model\special\SpecialContent;
  21. use app\wap\model\special\SpecialCourse;
  22. use app\wap\model\special\SpecialRecord;
  23. use app\wap\model\special\SpecialRelation;
  24. use app\wap\model\special\SpecialSource;
  25. use app\wap\model\special\SpecialSubject;
  26. use app\wap\model\special\SpecialTask;
  27. use app\wap\model\special\SpecialWatch;
  28. use app\wap\model\store\StoreCart;
  29. use app\wap\model\store\StoreOrder;
  30. use app\wap\model\store\StorePink;
  31. use app\wap\model\user\User;
  32. use service\CanvasService;
  33. use service\JsonService;
  34. use service\SystemConfigService;
  35. use service\UtilService;
  36. use think\cache\driver\Redis;
  37. use think\Cookie;
  38. use think\exception\HttpException;
  39. use think\response\Json;
  40. use think\Session;
  41. use think\Url;
  42. use think\Db;
  43. use think\Request;
  44. use service\VodService;
  45. class Special extends AuthController
  46. {
  47. /*
  48. * 白名单
  49. * */
  50. public static function WhiteList()
  51. {
  52. return [
  53. 'details',
  54. 'get_pink_info',
  55. 'get_course_list',
  56. 'play',
  57. 'play_num',
  58. 'grade_list',
  59. 'set_barrage_index',
  60. 'get_barrage_list',
  61. 'special_cate',
  62. 'get_grade_cate',
  63. 'get_subject_cate',
  64. 'get_special_list',
  65. 'lecturerList',
  66. 'lecturerDetails',
  67. 'lecturerSpecial',
  68. 'teacher_detail',
  69. 'teacher_list',
  70. 'get_cloumn_task',
  71. 'activity_details',
  72. 'isMember',
  73. 'activityType',
  74. 'groupLists',
  75. ];
  76. }
  77. /**获取视频上传地址和凭证
  78. * @param string $videoId
  79. * @param int $type
  80. */
  81. public function get_video_playback_credentials($type=1,$videoId='')
  82. {
  83. $url=VodService::videoUploadAddressVoucher('',$type,$videoId);
  84. return JsonService::successful($url);
  85. }
  86. /**
  87. * 专题详情
  88. * @param $id int 专题id
  89. * @param $pinkId int 拼团id
  90. * @param $gift_uid int 赠送礼物用户
  91. * @param $gift_order_id string 礼物订单号
  92. * @return
  93. */
  94. 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*/)
  95. {
  96. if (!$id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
  97. if ($gift_uid && $gift_order_id) {
  98. if ($gift_uid == $this->uid) $this->failed('您不能领取自己的礼物', Url::build('special/grade_list'));
  99. if (!User::get($gift_uid)) $this->failed('赠送礼物的用户不存在', Url::build('my/my_gift'));
  100. $order = StoreOrder::where(['is_del' => 0, 'order_id' => $gift_order_id])->find();
  101. if (!$order) $this->failed('赠送的礼物订单不存在', Url::build('my/my_gift'));
  102. if ($order->total_num == $order->gift_count) $this->failed('礼物已被领取完',Url::build('special/grade_list'));
  103. }
  104. $special = SpecialModel::getOneSpecial($this->uid, $id, $pinkId);
  105. if ($special === false) $this->failed(SpecialModel::getErrorInfo('无法访问'), Url::build('index/index'));
  106. $special_money = SpecialModel::where('id', $id)->field('money, pay_type')->find();
  107. if (in_array($special_money['money'], [0, 0.00]) || in_array($special_money['pay_type'], [PAY_NO_MONEY, PAY_PASSWORD])) {
  108. $isPay = 1;
  109. }else{
  110. $isPay = (!$this->uid || $this->uid == 0) ? false : SpecialBuy::PaySpecial($id, $this->uid);
  111. }
  112. $site_name = SystemConfigService::get('site_name');
  113. $seo_title = SystemConfigService::get('seo_title');
  114. $site_logo = SystemConfigService::get('home_logo');
  115. $isPink = false;
  116. if (!$isPay && $this->uid && !$pinkId) {
  117. $pinkId = StorePink::where(['cid' => $id, 'status' => '1', 'uid' => $this->uid])->order('add_time desc')->value('id');
  118. if ($pinkId) {
  119. $isPink = true;
  120. } else {
  121. $pinkId = 0;
  122. }
  123. }
  124. $liveInfo = [];
  125. if (isset($special['special'])) {
  126. $specialinfo = $special['special'];
  127. $specialinfo = is_string($specialinfo) ? json_decode($specialinfo, true) : $specialinfo;
  128. if ((float)$specialinfo['money'] < 0) {
  129. $isPink = true;
  130. }
  131. if ($specialinfo['type'] == SPECIAL_LIVE) {
  132. $liveInfo = LiveStudio::where('special_id', $specialinfo['id'])->find();
  133. if (!$liveInfo) return $this->failed('直播间尚未查到!', Url::build('index/index'));
  134. if ($liveInfo->is_del) return $this->failed('直播间已经删除!', Url::build('index/index'));
  135. }
  136. }
  137. if ($this->uid) SpecialRecord::record($id, $this->uid);
  138. $user_level = !$this->uid ? 0 : User::getUserInfo($this->uid);
  139. $type=json_decode($special['special'])->type;
  140. if($type!=5 && $type!=4){
  141. $specialSourceId = SpecialSource::getSpecialSource($id);
  142. if($specialSourceId) $count=count($specialSourceId);
  143. else $count=0;
  144. }else{
  145. $count=0;
  146. $specialSourceId = SpecialSource::getSpecialSource($id);
  147. if(count($specialSourceId)){
  148. $specialSource=$specialSourceId->toArray();
  149. foreach ($specialSource as $key=>$value){
  150. $specialSourcetaskId = SpecialSource::getSpecialSource($value['source_id']);
  151. $count=bcadd($count,count($specialSourcetaskId),0);
  152. }
  153. }
  154. }
  155. $uids=Db::name('learning_records')->where(['special_id'=>$id])->column('uid');
  156. $record=[];
  157. $uids=array_unique($uids);
  158. foreach ($uids as $key=>$value){
  159. $user=User::where('uid',$value)->field('nickname,avatar')->find();
  160. if($user){
  161. $user=$user->toArray();
  162. array_push($record,$user);
  163. }
  164. }
  165. $this->assign($special);
  166. $this->assign('pinkId', $pinkId);
  167. $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0);
  168. $this->assign('count', $count);
  169. $this->assign('isPink', $isPink);
  170. $this->assign('record', json_encode($record));
  171. $this->assign('isPay', $isPay);
  172. $this->assign('liveInfo', json_encode($liveInfo));
  173. $this->assign('confing', compact('site_name', 'seo_title', 'site_logo'));
  174. $this->assign('orderId', $gift_order_id);
  175. $this->assign('partake', (int)$partake);
  176. $this->assign('link_pay', (int)$link_pay);
  177. $this->assign('gift', (int)$gift);
  178. $this->assign('link_pay_uid', $link_pay_uid);
  179. $this->assign('BarrageShowTime', SystemConfigService::get('barrage_show_time'));
  180. $this->assign('barrage_index', Cookie::get('barrage_index'));
  181. return $this->fetch();
  182. }
  183. /**
  184. * 礼物领取
  185. *
  186. * */
  187. public function receive_gift($orderId = '')
  188. {
  189. if (!$orderId) return JsonService::fail('缺少参数');
  190. if (StoreOrder::createReceiveGift($orderId, $this->uid) == false)
  191. return JsonService::fail(StoreOrder::getErrorInfo('领取失败'));
  192. else
  193. return JsonService::successful('领取成功');
  194. }
  195. /**
  196. * 获取单个拼团详情
  197. * $pinkId 拼团id
  198. * */
  199. public function get_pink_info($pinkId = 0)
  200. {
  201. $is_ok = 0;//判断拼团是否完成
  202. $userBool = 0;//判断当前用户是否在团内 0未在 1在
  203. $pinkBool = 0;//判断当前用户是否在团内 0未在 1在
  204. if(!$this->uid) return JsonService::fail('请先登录!');
  205. $pink = StorePink::getPinkUserOne($pinkId);
  206. if (isset($pink['is_refund']) && $pink['is_refund']) {
  207. return JsonService::fail('订单已退款', ['special_id' => $pink['cid']]);
  208. }
  209. if (!$pink) return JsonService::fail('参数错误', ['url' => Url::build('my/index')]);
  210. list($pinkAll, $pinkT, $count, $idAll, $uidAll) = StorePink::getPinkMemberAndPinkK($pink);
  211. if ($pinkT['status'] == 2)
  212. $pinkBool = 1;
  213. else {
  214. if (!$count || $count < 0) {//组团完成
  215. $pinkBool = StorePink::PinkComplete($uidAll, $idAll, $this->uid, $pinkT);
  216. } else {//拼团失败 退款
  217. $pinkBool = StorePink::PinkFail($this->uid, $idAll, $pinkAll, $pinkT, (int)$count, $pinkBool, $uidAll);
  218. }
  219. }
  220. if ($pinkBool === false) return JsonService::fail(StorePink::getErrorInfo());
  221. foreach ($pinkAll as $v) {
  222. if ($v['uid'] == $this->uid) $userBool = 1;
  223. }
  224. if ($pinkT['uid'] == $this->uid) $userBool = 1;
  225. $data['pinkBool'] = $pinkBool;
  226. $data['is_ok'] = $is_ok;
  227. $data['userBool'] = $userBool;
  228. $data['pinkT'] = $pinkT;
  229. $data['pinkAll'] = $pinkAll;
  230. $data['count'] = $count;
  231. $data['current_pink_order'] = StorePink::getCurrentPink($pinkId);
  232. $data['special'] = SpecialModel::getPinkSpecialInfo($pinkT['order_id'], $pinkId, $this->uid);
  233. return JsonService::successful($data);
  234. }
  235. /**
  236. * 专题收藏
  237. * @param $id int 专题id
  238. * @return json
  239. */
  240. public function collect($id = 0)
  241. {
  242. if (!$id) return JsonService::fail('缺少参数');
  243. if (SpecialRelation::SetCollect($this->uid, $id))
  244. return JsonService::successful('');
  245. else
  246. return JsonService::fail();
  247. }
  248. /**
  249. * 获取某个专题的任务视频列表
  250. * @return json
  251. * */
  252. public function get_course_list()
  253. {
  254. list($page, $limit, $special_id) = UtilService::getMore([
  255. ['page', 1],
  256. ['limit', 10],
  257. ['special_id', 0],
  258. ], null, true);
  259. $uid=$this->uid ? $this->uid : 0;
  260. //不登录也能查看
  261. $task_list = SpecialCourse::getSpecialSourceList($special_id, $limit, $page,$uid);
  262. if(!$task_list['list']) return JsonService::successful([]);
  263. foreach ($task_list['list'] as $k => $v) {
  264. $task_list['list'][$k]['type_name'] = SPECIAL_TYPE[$v['type']];
  265. $task_list['list'][$k]['taskTrue']=SpecialWatch::whetherWatch($this->uid,$special_id,$v['id']);
  266. }
  267. return JsonService::successful($task_list);
  268. }
  269. /**
  270. * 获取专栏套餐
  271. */
  272. public function get_cloumn_task()
  273. {
  274. list($page, $limit, $special_id, $source_id) = UtilService::getMore([
  275. ['page', 1],
  276. ['limit', 10],
  277. ['special_id', 0],
  278. ['source_id', 0],
  279. ], null, true);
  280. $uid=$this->uid ? $this->uid : 0;
  281. $task_list = SpecialCourse::get_cloumn_task($special_id, $source_id, $limit, $page,$uid);
  282. if(!$task_list['list']) return JsonService::successful([]);
  283. foreach ($task_list['list'] as $k => $v) {
  284. $task_list['list'][$k]['taskTrue']=SpecialWatch::whetherWatch($this->uid,$special_id,$v['id']);
  285. $task_list['list'][$k]['type_name'] = SPECIAL_TYPE[$v['type']];
  286. }
  287. return JsonService::successful($task_list);
  288. }
  289. /**
  290. * 播放数量增加
  291. * @param int $task_id 任务id
  292. * @return json
  293. * */
  294. public function play_num($task_id = 0,$special_id=0)
  295. {
  296. if ($task_id == 0 || $special_id == 0) return JsonService::fail('缺少参数');
  297. try{
  298. $add_task_play_count = SpecialTask::bcInc($task_id, 'play_count', 1);
  299. if ($add_task_play_count) {
  300. $special_source = SpecialSource::getSpecialSource((int)$special_id, [$task_id]);
  301. if ($special_source) {
  302. SpecialSource::where(['special_id' => $special_id, 'source_id' => $task_id])->setInc('play_count',1);
  303. }
  304. return JsonService::successful('ok');
  305. }else {
  306. return JsonService::fail('err');
  307. }
  308. }catch (\Exception $e) {
  309. return JsonService::fail('err');
  310. }
  311. }
  312. /**
  313. * 播放任务
  314. * @param int $task_id 任务id
  315. * @return string
  316. * */
  317. public function play($task_id = 0)
  318. {
  319. if (!$task_id) $this->failed('无法访问', Url::build('index/index'));
  320. Session::set('video_token_' . $task_id, md5(time() . $task_id));
  321. $tash = SpecialTask::get($task_id);
  322. if (!$tash) $this->failed('您查看的资源不存在', Url::build('index/index'));
  323. if ($tash->is_show == 0) $this->failed('您查看的资源已下架', Url::build('index/index'));
  324. $this->assign('link', Trust($tash->link));
  325. $this->assign('task_id', $task_id);
  326. return $this->fetch();
  327. }
  328. public function go_video($task_id = 0)
  329. {
  330. if (Cookie::has('video_token_count_' . $task_id)) {
  331. Cookie::set('video_token_count_' . $task_id, Cookie::get('video_token_count_' . $task_id) + 1);
  332. } else {
  333. Cookie::set('video_token_count_' . $task_id, 1);
  334. }
  335. if (Session::has('video_token_' . $task_id)) {
  336. $tash = SpecialTask::get($task_id);
  337. if (Cookie::get('video_token_count_' . $task_id) >= 2) {
  338. Session::delete('video_token_' . $task_id);
  339. }
  340. exit(file_get_contents($tash->link));
  341. } else {
  342. throw new HttpException(404, '您查看的链接不存在');
  343. }
  344. }
  345. /**
  346. * 拼团支付完成后页面
  347. * @param null $orderId
  348. * @return mixed|void
  349. */
  350. public function pink($orderId = null)
  351. {
  352. if (is_null($orderId)) $this->failed('缺少参数', Url::build('my/order_list'));
  353. $info = StoreOrder::getOrderSpecialInfo($orderId, $this->uid);
  354. if ($info === false) return $this->failed(StoreOrder::getErrorInfo(), Url::build('my/order_list'));
  355. $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';
  356. $this->assign('special_id', $info['special_id']);
  357. $this->assign('site_url', $site_url);
  358. $this->assign('info', json_encode($info));
  359. return $this->fetch();
  360. }
  361. public function create_order(){
  362. list($special_id, $pay_type_num, $payType, $pinkId, $total_num, $link_pay_uid,$signUp) = UtilService::PostMore([
  363. ['special_id', 0],
  364. ['pay_type_num', -1],
  365. ['payType', 'weixin'],
  366. ['pinkId', 0],
  367. ['total_num', 1],
  368. ['link_pay_uid', 0],
  369. ['sign',''],
  370. ], $this->request, true);
  371. switch ($pay_type_num){
  372. case 10://会员支付
  373. $this->create_member_order($special_id,$payType);
  374. break;
  375. case 20://报名支付
  376. $this->create_activity_order($special_id,$payType,$signUp);
  377. break;
  378. case 30://虚拟币充值
  379. $auth_api = new AuthApi();
  380. $auth_api->user_wechat_recharge($special_id, $payType);
  381. case 40: //商品购买
  382. $this->create_goods_order($special_id,$payType,$signUp);
  383. break;
  384. case 50: //订单再次支付
  385. $this->pay_order($special_id,$payType);
  386. break;
  387. default://专题支付
  388. $this->create_special_order($special_id, $pay_type_num, $payType, $pinkId, $total_num, $link_pay_uid);
  389. }
  390. }
  391. /**
  392. * 创建专题支付订单
  393. * @param int $special_id 专题id
  394. * @param int $pay_type 购买类型 1=礼物,2=普通购买,3=开团或者拼团
  395. * @throws \think\db\exception\DataNotFoundException
  396. * @throws \think\db\exception\ModelNotFoundException
  397. * @throws \think\exception\DbException
  398. */
  399. public function create_special_order($special_id, $pay_type_num, $payType, $pinkId, $total_num, $link_pay_uid)
  400. {
  401. if (!$special_id) return JsonService::fail('缺少购买参数');
  402. if ($pay_type_num == -1) return JsonService::fail('选择购买方式');
  403. if ($pinkId) {
  404. $orderId = StoreOrder::getStoreIdPink($pinkId);
  405. if (StorePink::getIsPinkUid($pinkId)) return JsonService::status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => $orderId]);
  406. if (StoreOrder::getIsOrderPink($pinkId)) return JsonService::status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => $orderId]);
  407. if (StorePink::getPinkStatusIng($pinkId)) return JsonService::status('ORDER_EXIST', '拼团已完成或者已过期无法参团', ['orderId' => $orderId]);
  408. if (StorePink::be(['uid' => $this->uid, 'type' => 1, 'cid' => $special_id, 'status' => 1])) return JsonService::status('ORDER_EXIST', '您已参见本专题的拼团,请结束后再进行参团');
  409. if (SpecialBuy::be(['uid' => $this->uid, 'special_id' => $special_id, 'is_del' => 0])) return JsonService::status('ORDER_EXIST', '您已购买此专题,不能在进行参团!');
  410. //处理拼团完成
  411. try {
  412. if ($pink = StorePink::get($pinkId)) {
  413. list($pinkAll, $pinkT, $count, $idAll, $uidAll) = StorePink::getPinkMemberAndPinkK($pink);
  414. if ($pinkT['status'] == 1) {
  415. if (!$count || $count < 0) {
  416. StorePink::PinkComplete($uidAll, $idAll, $pinkT['uid'], $pinkT);
  417. return JsonService::status('ORDER_EXIST', '当前拼团已完成,无法参团');
  418. } else
  419. StorePink::PinkFail($pinkT['uid'], $idAll, $pinkAll, $pinkT, $count, 0, $uidAll);
  420. } else if ($pinkT['status'] == 2) {
  421. return JsonService::status('ORDER_EXIST', '当前拼团已完成,无法参团');
  422. } else if ($pinkT['status'] == 3) {
  423. return JsonService::status('ORDER_EXIST', '拼团失败,无法参团');
  424. }
  425. }
  426. } catch (\Exception $e) {
  427. }
  428. }
  429. $special = SpecialModel::PreWhere()->find($special_id);
  430. if (!$special) return JsonService::status('ORDER_ERROR', '购买的专题不存在');
  431. $order = StoreOrder::createSpecialOrder($special, $pinkId, $pay_type_num, $this->uid, $payType, $link_pay_uid, $total_num);
  432. $orderId = $order['order_id'];
  433. $info = compact('orderId');
  434. if ($orderId) {
  435. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  436. if (!$orderInfo || !isset($orderInfo['paid'])) return JsonService::status('pay_error', '支付订单不存在!');
  437. if ($orderInfo['paid']) return JsonService::status('pay_error', '支付已支付!');
  438. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  439. if (StoreOrder::jsPayPrice($orderId, $this->userInfo['uid']))
  440. return JsonService::status('success', '微信支付成功', $info);
  441. else
  442. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  443. }
  444. switch ($payType) {
  445. case 'weixin':
  446. try {
  447. $jsConfig = StoreOrder::jsSpecialPay($orderId);
  448. } catch (\Exception $e) {
  449. return JsonService::status('pay_error', $e->getMessage(), $info);
  450. }
  451. $info['jsConfig'] = $jsConfig;
  452. return JsonService::status('wechat_pay', '订单创建成功', $info);
  453. break;
  454. case 'yue':
  455. if (StoreOrder::yuePay($orderId, $this->userInfo['uid']))
  456. return JsonService::status('success', '余额支付成功', $info);
  457. else
  458. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  459. break;
  460. case 'zhifubao':
  461. $info['pay_price'] = $orderInfo['pay_price'];
  462. $info['orderName'] = '专题购买';
  463. return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info)));
  464. break;
  465. }
  466. } else {
  467. return JsonService::fail(StoreOrder::getErrorInfo('订单生成失败!'));
  468. }
  469. }
  470. /**会员订单创建
  471. * @param $id
  472. * @param $payType
  473. * @throws \think\db\exception\DataNotFoundException
  474. * @throws \think\db\exception\ModelNotFoundException
  475. * @throws \think\exception\DbException
  476. */
  477. public function create_member_order($id,$payType)
  478. {
  479. if(!$id) return JsonService::fail('参数错误!');
  480. $order = StoreOrder::cacheMemberCreateOrder($this->userInfo['uid'],$id,$payType);
  481. $orderId = $order['order_id'];
  482. $info = compact('orderId');
  483. if ($orderId) {
  484. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  485. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  486. if ($orderInfo['paid']) exception('支付已支付!');
  487. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  488. if (StoreOrder::jsPayMePrice($orderId, $this->userInfo['uid']))
  489. return JsonService::status('success', '领取成功', $info);
  490. else
  491. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  492. } else {
  493. switch ($payType) {
  494. case 'weixin':
  495. try {
  496. $jsConfig = StoreOrder::jsPayMember($orderId);
  497. } catch (\Exception $e) {
  498. return JsonService::status('pay_error', $e->getMessage(), $info);
  499. }
  500. $info['jsConfig'] = $jsConfig;
  501. return JsonService::status('wechat_pay', '订单创建成功', $info);
  502. break;
  503. case 'zhifubao':
  504. $info['pay_price'] = $orderInfo['pay_price'];
  505. $info['orderName'] = '会员购买';
  506. return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info)));
  507. break;
  508. }
  509. }
  510. } else {
  511. return JsonService::fail(StoreOrder::getErrorInfo('领取失败!'));
  512. }
  513. }
  514. /**
  515. * 用户提交报名
  516. */
  517. public function create_activity_order($id,$payType,$signUp){
  518. if (!$id) JsonService::fail('参数有误');
  519. $order=EventSignUp::userEventSignUp($id,$signUp,$payType,$this->userInfo['uid']);
  520. $orderId = $order['order_id'];
  521. $info = compact('orderId');
  522. if ($orderId) {
  523. $orderInfo = EventSignUp::where('order_id', $orderId)->find();
  524. if (!$orderInfo || !isset($orderInfo['paid'])) return JsonService::status('pay_error', '支付订单不存在!');
  525. if ($orderInfo['paid']) return JsonService::status('pay_error', '支付已支付!');
  526. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  527. if (EventSignUp::jsPayPrice($orderId, $this->userInfo['uid']))
  528. return JsonService::status('success', '支付成功', $info);
  529. else
  530. return JsonService::status('pay_error', EventSignUp::getErrorInfo());
  531. }
  532. switch ($payType) {
  533. case 'weixin':
  534. try {
  535. $jsConfig = EventSignUp::jsPay($orderId);
  536. } catch (\Exception $e) {
  537. return JsonService::status('pay_error', $e->getMessage(), $info);
  538. }
  539. $info['jsConfig'] = $jsConfig;
  540. return JsonService::status('wechat_pay', '订单创建成功', $info);
  541. break;
  542. case 'yue':
  543. if (EventSignUp::yuePay($orderId, $this->userInfo['uid']))
  544. return JsonService::status('success', '余额支付成功', $info);
  545. else
  546. return JsonService::status('pay_error', EventSignUp::getErrorInfo());
  547. break;
  548. case 'zhifubao':
  549. $info['pay_price'] = $orderInfo['pay_price'];
  550. $info['orderName'] = '活动报名';
  551. return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info)));
  552. break;
  553. }
  554. } else {
  555. return JsonService::fail(EventSignUp::getErrorInfo('订单生成失败!'));
  556. }
  557. }
  558. /**
  559. * 购买完成后送礼物页面
  560. * @param string $orderId 订单id
  561. * @return strign
  562. * */
  563. public function gift_special($orderId = null)
  564. {
  565. if (is_null($orderId)) $this->failed('缺少订单号,无法进行赠送',Url::build('my/my_gift'));
  566. $uid=$this->uid;
  567. if(!$uid)$this->failed('未获取到用户信息!',Url::build('index/index'));
  568. $special = StoreOrder::getOrderIdToSpecial($orderId,$uid);
  569. if ($special === false) $this->failed(StoreOrder::getErrorInfo(),Url::build('my/my_gift'));
  570. $this->assign([
  571. 'orderId'=>$orderId,
  572. 'title'=>'赠送礼物',
  573. 'special_gift_banner'=>SystemConfigService::get('special_gift_banner'),
  574. '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,
  575. 'special'=>$special
  576. ]);
  577. return $this->fetch();
  578. }
  579. /**
  580. * 查看领取记录
  581. * @param $orderId string 订单id
  582. * @return html
  583. * */
  584. public function gift_receive($orderId = null)
  585. {
  586. if (is_null($orderId)) $this->failed('缺少订单号,无法查看领取记录',Url::build('my/my_gift'));
  587. $special = StoreOrder::getOrderIdGiftReceive($orderId);
  588. if ($special === false) $this->failed(StoreOrder::getErrorInfo(),Url::build('my/my_gift'));
  589. $this->assign($special);
  590. $this->assign('special_gift_banner', SystemConfigService::get('special_gift_banner'));
  591. return $this->fetch();
  592. }
  593. /**
  594. * 购买失败删除订单
  595. * @param string $orderId 订单id
  596. * @return json
  597. * */
  598. public function del_order($orderId = '')
  599. {
  600. if (StoreOrder::where('order_id', $orderId)->update(['is_del' => 1]))
  601. return JsonService::successful();
  602. else
  603. return JsonService::fail();
  604. }
  605. public function grade_list($type = 0)
  606. {
  607. $this->assign(compact('type'));
  608. return $this->fetch();
  609. }
  610. /**
  611. * 获取我购买的课程
  612. * @param int $type 课程类型
  613. * @param int $page 分页
  614. * @param int $limit 一页显示多少条
  615. * @return json
  616. * */
  617. public function get_grade_list($type = 0, $page = 1, $limit = 10, $search = '')
  618. {
  619. return JsonService::successful(SpecialModel::getGradeList($type, (int)$page, (int)$limit, $this->uid, $search));
  620. }
  621. /**
  622. * 拼团成功朋友圈海报展示
  623. * @param $special_id int 专题id
  624. * @return html
  625. * */
  626. public function poster_show($special_id = 0, $pinkId = 0, $is_help = 0)
  627. {
  628. if (!$special_id || !$pinkId) $this->failed('您查看的朋友去圈海报不存在',Url::build('spread/special'));
  629. $special = SpecialModel::getSpecialInfo($special_id);
  630. if ($special === false) $this->failed(SpecialModel::getErrorInfo(),Url::build('spread/special'));
  631. if (!$special['poster_image']) $this->failed('您查看的海报不存在',Url::build('spread/special'));
  632. $site_url = SystemConfigService::get('site_url') . Url::build('special/details') . '?id=' . $special['id'] . '&pinkId=' . $pinkId . '&partake=1' . ($is_help ? '&spread_uid=' . $this->uid : '');
  633. try {
  634. $filename = CanvasService::startPosterSpeclialIng($special_id, $special['poster_image'], $site_url);
  635. } catch (\Exception $e) {
  636. return $this->failed($e->getMessage(),Url::build('spread/special'));
  637. }
  638. $this->assign('filename', $filename);
  639. $this->assign('special', $special);
  640. $this->assign('is_help', $is_help);
  641. $this->assign('site_url', $site_url);
  642. return $this->fetch();
  643. }
  644. /**
  645. * 查看单个拼团状态
  646. * @param $pink_id int 拼团id
  647. * @return html
  648. * */
  649. public function order_pink($pink_id = '', $is_help = 0)
  650. {
  651. if (!$pink_id) $this->failed('缺少订单号',Url::build('my/order_list'));
  652. $this->assign([
  653. 'pink_id' => $pink_id,
  654. 'is_help' => $is_help,
  655. ]);
  656. return $this->fetch();
  657. }
  658. /**
  659. * 获取专题弹幕
  660. * @param int $special_id 专题id
  661. * @return json
  662. * */
  663. public function get_barrage_list($special_id = 0)
  664. {
  665. if(!$special_id) return JsonService::fail('确实参数!');
  666. if (SystemConfigService::get('open_barrage')) {
  667. $barrage = SpecialBarrage::where('is_show', 1)->order('sort desc,id desc')->field(['nickname', 'avatar', 'action'])->select();
  668. $barrage = count($barrage) ? $barrage->toArray() : [];
  669. foreach ($barrage as &$item) {
  670. $item['status_name'] = $item['action'] == 1 ? '1秒前发起了拼团' : '1秒前成功参团';
  671. unset($item['action']);
  672. }
  673. $special=SpecialModel::where('id',$special_id)->find();
  674. if(!$special) return JsonService::fail('确实参数!');
  675. if($special['is_pink']){
  676. $pinkList = StoreOrder::where(['o.cart_id' => $special_id, 'p.is_refund' => 0, 'o.refund_status' => 0, 'o.paid' => 1, 'p.is_false' => 0])
  677. ->join("__STORE_PINK__ p", 'p.order_id=o.order_id')
  678. ->join('__USER__ u', 'u.uid=o.uid')
  679. ->field(['u.nickname', 'u.avatar', 'p.status', 'p.k_id'])
  680. ->group('o.order_id')
  681. ->order('o.add_time desc')
  682. ->alias('o')
  683. ->select();
  684. $pinkList = count($pinkList) ? $pinkList->toArray() : [];
  685. foreach ($pinkList as &$item) {
  686. if ($item['status'] == 2 && $item['k_id'] == 0) {
  687. $item['status_name'] = '1秒前拼团成功';
  688. } else if ($item['status'] == 1 && $item['k_id'] == 0)
  689. $item['status_name'] = '1秒前发起了拼团';
  690. else if ($item['status'] == 2 && $item['k_id'] != 0)
  691. $item['status_name'] = '1秒前拼团成功';
  692. else if ($item['status'] == 1 && $item['k_id'] != 0)
  693. $item['status_name'] = '1秒前发起了拼团';
  694. else if ($item['status'] == 3)
  695. $item['status_name'] = '1秒前参团成功';
  696. unset($item['status'], $item['k_id']);
  697. }
  698. $barrageList = array_merge($pinkList, $barrage);
  699. shuffle($barrageList);
  700. }else{
  701. $barrageList = [];
  702. }
  703. } else $barrageList = [];
  704. return JsonService::successful($barrageList);
  705. }
  706. /**
  707. * 拼团列表
  708. */
  709. public function groupLists($special_id=0)
  710. {
  711. if(!$special_id) return JsonService::fail('确实参数!');
  712. $special=SpecialModel::where('id',$special_id)->find();
  713. if(!$special) return JsonService::fail('确实参数!');
  714. if($special['is_pink']) {
  715. $pinkList = StoreOrder::where(['o.cart_id' => $special_id, 'p.is_refund' => 0, 'o.refund_status' => 0, 'o.paid' => 1, 'p.is_false' => 0])
  716. ->join("__STORE_PINK__ p", 'p.order_id=o.order_id')
  717. ->join('__USER__ u', 'u.uid=o.uid')
  718. ->field(['u.nickname', 'u.avatar', 'p.status', 'p.k_id'])
  719. ->group('o.order_id')
  720. ->order('o.add_time desc')
  721. ->alias('o')
  722. ->select();
  723. $pinkList = count($pinkList) ? $pinkList->toArray() : [];
  724. }else{
  725. $pinkList =[];
  726. }
  727. return JsonService::successful($pinkList);
  728. }
  729. /**
  730. * 获取滚动index
  731. * @param int $index
  732. */
  733. public function set_barrage_index($index = 0)
  734. {
  735. return JsonService::successful(Cookie::set('barrage_index', $index));
  736. }
  737. /**
  738. * 专题分类
  739. * @return mixed
  740. */
  741. public function special_cate($cate_id = 0,$subject_id=0)
  742. {
  743. $this->assign([
  744. 'homeLogo' => SystemConfigService::get('home_logo'),
  745. 'cate_id' => (int)$cate_id,
  746. 'subject_id' => (int)$subject_id
  747. ]);
  748. return $this->fetch();
  749. }
  750. /**
  751. * 获取一级分类
  752. * @throws \think\db\exception\DataNotFoundException
  753. * @throws \think\db\exception\ModelNotFoundException
  754. * @throws \think\exception\DbException
  755. */
  756. public function get_grade_cate()
  757. {
  758. return JsonService::successful(Grade::where(['is_del'=>0,'is_show'=>1])->order('sort desc,id desc')->select());
  759. }
  760. /**
  761. * 获取二级分类
  762. * @param int $grade_id
  763. * @throws \think\db\exception\DataNotFoundException
  764. * @throws \think\db\exception\ModelNotFoundException
  765. * @throws \think\exception\DbException
  766. */
  767. public function get_subject_cate($grade_id = 0)
  768. {
  769. if (!$grade_id) {
  770. return JsonService::fail('缺少一级分类id');
  771. }
  772. return JsonService::successful(SpecialSubject::where(['is_show' => 1, 'grade_id' => $grade_id,'is_del'=>0])->order('sort desc,id desc')->select());
  773. }
  774. /**
  775. * 获取专题
  776. * @param int $subject_id
  777. * @param string $search
  778. * @param int $page
  779. * @param int $limit
  780. */
  781. public function get_special_list($subject_id = 0, $search = '', $page = 1, $limit = 10, $type = 0)
  782. {
  783. if (!$subject_id && $type == 0) {
  784. return JsonService::fail('缺少二级分类id');
  785. }
  786. $uid = $this->uid;
  787. return JsonService::successful(SpecialModel::getSpecialList(compact('subject_id', 'search', 'page', 'limit', 'type', 'uid')));
  788. }
  789. /**
  790. * 获取拼团专题
  791. */
  792. public function get_pink_special_list()
  793. {
  794. list($page, $limit) = UtilService::PostMore([
  795. ['page', 1],
  796. ['limit', 10]
  797. ], $this->request, true);
  798. return JsonService::successful(SpecialModel::getPinkSpecialList($page, $limit));
  799. }
  800. /**
  801. * 学习记录
  802. * @return mixed
  803. */
  804. public function record()
  805. {
  806. $this->assign([
  807. 'homeLogo' => SystemConfigService::get('home_logo'),
  808. ]);
  809. return $this->fetch();
  810. }
  811. /**
  812. * 是否可以播放
  813. * @param int $task_id 任务id
  814. * @return string
  815. * */
  816. public function get_task_link($task_id = 0)
  817. {
  818. $special_id = $this->request->param('special_id',0);
  819. if (!$special_id) return JsonService::fail('无法访问');
  820. if (!$task_id) return JsonService::fail('无法访问');
  821. $special_source = SpecialSource::getSpecialSource($special_id,[$task_id]);
  822. $tash = $special_source ? $special_source->toArray() : [];
  823. if (!$tash) {
  824. return JsonService::fail('您查看的视频已经下架');
  825. }else{
  826. return JsonService::successful($tash);
  827. }
  828. }
  829. /**
  830. * 课程详情
  831. * @param $id
  832. * @return mixed|void
  833. * @throws \think\Exception
  834. * @throws \think\db\exception\DataNotFoundException
  835. * @throws \think\db\exception\ModelNotFoundException
  836. * @throws \think\exception\DbException
  837. */
  838. public function task_info($id = 0, $specialId = 0)
  839. {
  840. if (!$id) {
  841. return $this->failed('缺少课程id,无法查看',Url::build('index/index'));
  842. }
  843. $taskInfo = SpecialTask::defaultWhere()->where('id', $id)->find();
  844. $special = SpecialModel::PreWhere()->where('id', $specialId)->find();
  845. if (!$special) {
  846. return $this->failed('您查看得专题不存在',Url::build('index/index'));
  847. }
  848. if (!$taskInfo) {
  849. return $this->failed('课程信息不存在无法观看',Url::build('index/index'));
  850. }
  851. if ($taskInfo['is_show'] == 0) {
  852. return $this->failed('该课程已经下架',Url::build('index/index'));
  853. }
  854. $isPay = SpecialBuy::PaySpecial($specialId, $this->uid);
  855. $special_content = SpecialContent::where('special_id',$specialId)->value("content");
  856. $content = htmlspecialchars_decode($taskInfo->detail ? $taskInfo->detail : $special_content);
  857. $user_level = !$this->uid ? 0 : User::getUserInfo($this->uid);
  858. $taskInfo->content = $content;
  859. if ($isPay || $special->pay_type == 0 || ($user_level['level'] > 0 && $special->member_pay_type == 0)) {
  860. $isPay = true;
  861. }else{
  862. $special_source = SpecialSource::where(['special_id' => $specialId,'source_id' => $id, 'pay_status' => 0])->find();
  863. if (!$special_source) {
  864. return $this->failed('您选择的素材不存在',Url::build('special/details',array('id'=>$specialId)));
  865. }else{
  866. $special_source = $special_source->toArray();
  867. $taskInfo = SpecialTask::defaultWhere()->order('sort DESC')->where('id', $special_source['source_id'])->find();
  868. if(!$taskInfo){
  869. return $this->failed('您选择的素材不存在',Url::build('special/details',array('id'=>$specialId)));
  870. }
  871. $taskInfo->content = $content;
  872. }
  873. }
  874. $this->assign('taskInfo', json_encode($taskInfo ? $taskInfo->toArray() : []));
  875. $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0);
  876. $this->assign('specialId', (int)$specialId);
  877. $this->assign('specialInfo', json_encode($special->toArray()));
  878. $this->assign('isPay', (int)$isPay);
  879. return $this->fetch();
  880. }
  881. /**检测用户身份
  882. * @throws \Exception
  883. */
  884. public function isMember()
  885. {
  886. $user_level = !$this->uid ? 0 : User::getUserInfo($this->uid);
  887. $data['is_member']=isset($user_level['level']) ? $user_level['level'] : 0;
  888. $data['now_money']=isset($user_level['now_money']) ? $user_level['now_money'] : 0;
  889. return JsonService::successful($data);
  890. }
  891. /**
  892. * 图文素材详情
  893. */
  894. public function task_text_info($id = 0, $specialId = 0)
  895. {
  896. if (!$id) {
  897. return $this->failed('缺少课程id,无法查看',Url::build('index/index'));
  898. }
  899. $taskInfo = SpecialTask::defaultWhere()->where('id', $id)->find();
  900. $special = SpecialModel::PreWhere()->where('id', $specialId)->find();
  901. if (!$special) {
  902. return $this->failed('您查看得专题不存在',Url::build('index/index'));
  903. }
  904. if (!$taskInfo) {
  905. return $this->failed('课程信息不存在无法观看',Url::build('index/index'));
  906. }
  907. if ($taskInfo['is_show'] == 0) {
  908. return $this->failed('该课程已经下架',Url::build('index/index'));
  909. }
  910. $isPay = SpecialBuy::PaySpecial($specialId, $this->uid);
  911. $content = htmlspecialchars_decode($taskInfo->content ? $taskInfo->content : "");
  912. $user_level = !$this->uid ? 0 : User::getUserInfo($this->uid);
  913. $taskInfo->content = $content;
  914. if ($isPay || $special->pay_type == 0 || ($user_level['level'] > 0 && $special->member_pay_type == 0)) {
  915. $isPay = true;
  916. }else{
  917. $special_source = SpecialSource::where(['special_id' => $specialId,'source_id' => $id,'pay_status' => 0])->find();
  918. if (!$special_source) {
  919. return $this->failed('您选择的素材不存在',Url::build('special/details',array('id'=>$specialId)));
  920. }else{
  921. $special_source = $special_source->toArray();
  922. $taskInfo = SpecialTask::defaultWhere()->order('sort DESC')->where('id', $special_source['source_id'])->find();
  923. if(!$taskInfo){
  924. return $this->failed('您选择的素材不存在',Url::build('special/details',array('id'=>$specialId)));
  925. }
  926. $taskInfo->content = $content;
  927. }
  928. }
  929. $this->assign('taskInfo', json_encode($taskInfo ? $taskInfo->toArray() : []));
  930. $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0);
  931. $this->assign('specialId', (int)$specialId);
  932. $this->assign('specialInfo', json_encode($special->toArray()));
  933. $this->assign('isPay', (int)$isPay);
  934. return $this->fetch('text_detail');
  935. }
  936. /**
  937. * 会员页
  938. * @return mixed
  939. */
  940. public function member_manage($type=1,$bid=0){
  941. $userInfo=User::getUserInfo($this->uid);
  942. $this->assign(['type'=>$type,'bid'=>$bid,'userInfo'=>$userInfo]);
  943. return $this->fetch('member/member_manage');
  944. }
  945. /**
  946. * 会员购买页
  947. * @return mixed
  948. */
  949. public function member_recharge(){
  950. $servicePhone=SystemConfigService::get('site_phone')?:'';
  951. $this->assign(['servicePhone'=>$servicePhone]);
  952. return $this->fetch('member/member_recharge');
  953. }
  954. /**
  955. * 充值页面
  956. */
  957. public function recharge_index($from='live',$stream_name = "")
  958. {
  959. $user_info = $this->userInfo;
  960. $gold_info = SystemConfigService::more("gold_name,gold_rate,gold_image");
  961. $recharge_price_list = [60,100,300,500,980,1980,2980,5180,15980];
  962. $gold_name=SystemConfigService::get('gold_name');//虚拟币名称
  963. $this->assign(compact('gold_name'));
  964. $this->assign('from',$from);
  965. $this->assign('stream_name',$stream_name);
  966. $this->assign('gold_info',json_encode($gold_info));
  967. $this->assign('recharge_price_list',json_encode($recharge_price_list));
  968. $this->assign('user_gold_num',$user_info['gold_num']);
  969. return $this->fetch('my/gold_coin');
  970. }
  971. /**
  972. * 储存素材观看时间
  973. */
  974. public function viewing($special_id=0,$task_id=0,$time=0){
  975. return JsonService::successful(SpecialWatch::materialViewing($this->userInfo['uid'],$special_id,$task_id,$time));
  976. }
  977. /**
  978. * 活动报名情况
  979. */
  980. public function activityType($id){
  981. $activity = EventRegistration::oneActivitys($id);
  982. if (!$activity) $this->failed('您查看的活动不存在',Url::build('activity/index'));
  983. $data['is_pay']=0;//是否购买报名过
  984. $data['is_restrictions']=0; //是否超过限购
  985. if($this->userInfo['uid']){
  986. $signCount=EventSignUp::where('activity_id',$id)->where('uid',$this->userInfo['uid'])->where('paid',1)->count();
  987. if($signCount){
  988. $data['is_pay']=1;
  989. if(bcsub($signCount,$activity['restrictions'],0)>=0 && $activity['restrictions']>0) $data['is_restrictions']=1;
  990. }
  991. }
  992. return JsonService::successful($data);
  993. }
  994. /**活动报名
  995. * @param string $id
  996. * @return mixed
  997. * @throws \think\Exception
  998. */
  999. public function activity_details($id = '')
  1000. {
  1001. $activity = EventRegistration::oneActivitys($id);
  1002. if (!$activity) $this->failed('您查看的活动不存在',Url::build('activity/index'));
  1003. $this->assign([
  1004. 'is_member' => isset($this->userInfo['level']) ? $this->userInfo['level'] : 0,
  1005. 'is_fill'=>$activity['is_fill'],
  1006. 'activity' => json_encode($activity),
  1007. 'activity_rules' => htmlspecialchars_decode($activity['activity_rules']),
  1008. 'content' => htmlspecialchars_decode($activity['content'])
  1009. ]);
  1010. return $this->fetch('activity/index');
  1011. }
  1012. /**商品订单提交
  1013. * @param string $cartId
  1014. * @return mixed|void
  1015. * @throws \Exception
  1016. */
  1017. public function confirm_order($cartId = '')
  1018. {
  1019. if(!is_string($cartId) || !$cartId ){
  1020. return $this->failed('请提交购买的商品!',Url::build('store/index'));
  1021. }
  1022. $user=User::getUserInfo($this->userInfo['uid']);
  1023. $cartGroup = StoreCart::getUserProductCartList($this->userInfo['uid'],$cartId,1,$user['level']);
  1024. if(count($cartGroup['invalid']))
  1025. return $this->failed($cartGroup['invalid'][0]['productInfo']['store_name'].'已失效!',Url::build('store/index'));
  1026. if(!$cartGroup['valid']) return $this->failed('请提交购买的商品!',Url::build('store/index'));
  1027. $cartInfo = $cartGroup['valid'];
  1028. $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo);
  1029. $this->assign([
  1030. 'level'=>$user['level'],
  1031. 'cartInfo'=>json_encode($cartInfo),
  1032. 'cartId'=>$cartId,
  1033. 'priceGroup'=>json_encode($priceGroup),
  1034. 'orderKey'=>StoreOrder::cacheOrderInfo($this->userInfo['uid'],$cartInfo,$priceGroup),
  1035. 'userInfo'=>json_encode($user)
  1036. ]);
  1037. return $this->fetch('store/order_confirm');
  1038. }
  1039. /**订单提交页修改商品数量
  1040. * @param string $cartId
  1041. * @param int $cateNum
  1042. */
  1043. public function getOrderPrice($cartId='',$cateNum=1,$price,$postage)
  1044. {
  1045. StoreCart::beginTrans();
  1046. $res=StoreCart::changeUserCartNum($cartId,$cateNum,$this->userInfo['uid']);
  1047. if(!$res)return JsonService::fail('商品数量修改失败!');
  1048. $user=User::getUserInfo($this->userInfo['uid']);
  1049. $cartGroup = StoreCart::getUserProductCartList($this->userInfo['uid'],$cartId,1,$user['level']);
  1050. if(count($cartGroup['invalid']))
  1051. return $this->failed($cartGroup['invalid'][0]['productInfo']['store_name'].'已失效!',Url::build('store/index'));
  1052. if(!$cartGroup['valid']) return $this->failed('请提交购买的商品!',Url::build('store/index'));
  1053. $cartInfo = $cartGroup['valid'];
  1054. $data['priceGroup']=StoreOrder::getOrderPriceGroup($cartInfo);
  1055. if(bcsub($data['priceGroup']['totalPrice'],bcsub($price,$postage,2),2)==0 && bcsub($data['priceGroup']['storePostage'],$postage,2)==0){
  1056. StoreCart::commitTrans();
  1057. $data['orderKey']=StoreOrder::cacheOrderInfo($this->userInfo['uid'],$cartInfo,$data['priceGroup']);
  1058. return JsonService::successful($data);
  1059. }else{
  1060. StoreCart::rollbackTrans();
  1061. return JsonService::fail('网络异常!');
  1062. }
  1063. }
  1064. /**
  1065. * 创建商品订单
  1066. * @param string $key
  1067. * @return \think\response\Json
  1068. */
  1069. public function create_goods_order($addressId,$payType,$signUp)
  1070. {
  1071. $data=json_decode($signUp,true);
  1072. if (!$data['key']) return JsonService::fail('参数错误!');
  1073. $key=$data['key'];
  1074. $mark=$data['mark'];
  1075. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $this->userInfo['uid'], 'is_del' => 0, 'type' => 2]))
  1076. return JsonService::status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  1077. $payType = strtolower($payType);
  1078. $order = StoreOrder::cacheKeyCreateOrder($this->userInfo['uid'], $key, $addressId, $payType,$mark);
  1079. $orderId = $order['order_id'];
  1080. $info = compact('orderId', 'key');
  1081. if ($orderId) {
  1082. $orderInfo = StoreOrder::where('order_id', $orderId)->where('type',2)->find();
  1083. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  1084. if ($orderInfo['paid']) exception('支付已支付!');
  1085. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  1086. if (StoreOrder::jsPayGoodsPrice($orderId, $this->userInfo['uid']))
  1087. return JsonService::status('success', '支付成功', $info);
  1088. else
  1089. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  1090. }
  1091. switch ($payType) {
  1092. case 'weixin':
  1093. try {
  1094. $jsConfig = StoreOrder::jsPay($orderId);
  1095. } catch (\Exception $e) {
  1096. return JsonService::status('pay_error', $e->getMessage(), $info);
  1097. }
  1098. $info['jsConfig'] = $jsConfig;
  1099. return JsonService::status('wechat_pay', '订单创建成功', $info);
  1100. break;
  1101. case 'yue':
  1102. if (StoreOrder::yueGoodsPay($orderId, $this->userInfo['uid']))
  1103. return JsonService::status('success', '余额支付成功', $info);
  1104. else
  1105. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  1106. break;
  1107. case 'zhifubao':
  1108. $info['pay_price'] = $orderInfo['pay_price'];
  1109. $info['orderName'] = '商品购买';
  1110. return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info)));
  1111. break;
  1112. }
  1113. } else {
  1114. return JsonService::fail(StoreOrder::getErrorInfo('订单生成失败!'));
  1115. }
  1116. }
  1117. /**
  1118. * 我的商品订单
  1119. */
  1120. public function order_store_list($type=0)
  1121. {
  1122. $this->assign(['type'=>$type]);
  1123. return $this->fetch('my/order_store_list');
  1124. }
  1125. /**
  1126. * 订单详情
  1127. * @return mixed
  1128. */
  1129. public function order($uni='')
  1130. {
  1131. if (!$uni || !$order = StoreOrder::getUserOrderDetail($this->userInfo['uid'], $uni)) return $this->redirect(Url::build('order_list'));
  1132. $this->assign([
  1133. 'order' => StoreOrder::tidyOrder($order, true,true)
  1134. ]);
  1135. return $this->fetch('my/order');
  1136. }
  1137. /**
  1138. * 支付订单
  1139. * @param string $uni
  1140. * @return \think\response\Json
  1141. */
  1142. public function pay_order($id = 0,$payType)
  1143. {
  1144. if (!$id) return JsonService::fail('参数错误!');
  1145. $order = StoreOrder::where('id', $id)->where('type',2)->where('uid', $this->userInfo['uid'])->where('is_del', 0)->find();
  1146. if (!$order) return JsonService::fail('订单不存在!');
  1147. if ($order['paid']) return JsonService::fail('该订单已支付!');
  1148. $info['orderId'] =$order['order_id'];
  1149. if($payType!=$order['pay_type']){
  1150. $res=StoreOrder::where('id', $id)->where('type',2)->where('uid', $this->userInfo['uid'])->where('is_del', 0)->update(['pay_type'=>$payType]);
  1151. if(!$res)return JsonService::fail('订单支付方式修改失败!');
  1152. }
  1153. if ($payType == 'weixin') {
  1154. try {
  1155. $jsConfig = StoreOrder::jsPay($order);
  1156. } catch (\Exception $e) {
  1157. return JsonService::fail($e->getMessage());
  1158. }
  1159. $info['jsConfig']=$jsConfig;
  1160. return JsonService::status('wechat_pay', '订单创建成功', $info);
  1161. } else if ($payType == 'yue') {
  1162. if ($res = StoreOrder::yueGoodsPay($order['order_id'], $this->userInfo['uid']))
  1163. return JsonService::status('success','余额支付成功',$info);
  1164. else
  1165. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  1166. } else if ($payType == 'zhifubao') {
  1167. $info['pay_price'] = $order['pay_price'];
  1168. $info['orderName'] = '商品购买';
  1169. return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($info)));
  1170. }
  1171. }
  1172. /**
  1173. * 讲师详情
  1174. * @return mixed
  1175. */
  1176. public function teacher_detail($id=0)
  1177. {
  1178. $this->assign('id',$id);
  1179. return $this->fetch();
  1180. }
  1181. /**
  1182. * 讲师列表
  1183. * @return mixed
  1184. */
  1185. public function teacher_list()
  1186. {
  1187. return $this->fetch();
  1188. }
  1189. /**
  1190. * 获取讲师详情
  1191. * @param $id
  1192. */
  1193. public function lecturerDetails($id)
  1194. {
  1195. $lecturer=Lecturer::details($id);
  1196. return JsonService::successful($lecturer);
  1197. }
  1198. /**
  1199. * 讲师名下课程
  1200. * @param int $lecturer_id
  1201. */
  1202. public function lecturerSpecial()
  1203. {
  1204. list($lecturer_id, $page, $limit) = UtilService::PostMore([
  1205. ['lecturer_id', 0],
  1206. ['page', 1],
  1207. ['limit', 10]
  1208. ], $this->request, true);
  1209. $list=SpecialModel::getLecturerSpecialList($lecturer_id,$page,$limit);
  1210. return JsonService::successful($list);
  1211. }
  1212. /**
  1213. * 讲师列表
  1214. */
  1215. public function lecturerList()
  1216. {
  1217. list($page,$limit) = UtilService::GetMore([
  1218. ['page', 1],
  1219. ['limit', 10]
  1220. ], $this->request, true);
  1221. $list=Lecturer::getLecturer($page,$limit);
  1222. return JsonService::successful($list);
  1223. }
  1224. }