Special.php 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\activity\EventPrice;
  16. use app\wap\model\live\LiveStudio;
  17. use app\wap\model\special\Lecturer;
  18. use app\wap\model\special\Special as SpecialModel;
  19. use app\wap\model\special\LearningRecords;
  20. use app\wap\model\live\LivePlayback;
  21. use app\wap\model\special\SpecialBuy;
  22. use app\wap\model\special\SpecialContent;
  23. use app\wap\model\special\SpecialCourse;
  24. use app\wap\model\special\SpecialRecord;
  25. use app\wap\model\special\SpecialRelation;
  26. use app\wap\model\special\SpecialSource;
  27. use app\wap\model\special\SpecialSubject;
  28. use app\wap\model\special\SpecialTask;
  29. use app\wap\model\special\SpecialWatch;
  30. use app\wap\model\special\SpecialReply;
  31. use app\wap\model\special\SpecialExchange;
  32. use app\wap\model\special\SpecialBatch;
  33. use app\wap\model\special\SpecialLog;
  34. use app\wap\model\store\StoreCart;
  35. use app\wap\model\store\StoreOrder;
  36. use app\wap\model\store\StorePink;
  37. use app\wap\model\user\User;
  38. use service\CanvasService;
  39. use service\JsonService;
  40. use service\SystemConfigService;
  41. use service\UtilService;
  42. use think\cache\driver\Redis;
  43. use think\Cookie;
  44. use think\exception\HttpException;
  45. use think\response\Json;
  46. use think\Session;
  47. use think\Url;
  48. use think\Db;
  49. use think\Request;
  50. use service\VodService;
  51. use app\wap\model\routine\RoutineTemplate;
  52. use app\wap\model\topic\TestPaper;
  53. use app\wap\model\topic\TestPaperOrder;
  54. use app\wap\model\topic\CertificateRelated;
  55. use app\wap\model\topic\CertificateRecord;
  56. use app\wap\model\material\DataDownload;
  57. use app\wap\model\material\DataDownloadBuy;
  58. use app\wap\model\material\DataDownloadOrder;
  59. use app\wap\model\topic\Relation;
  60. /**专题
  61. * Class Special
  62. * @package app\wap\controller
  63. */
  64. class Special extends AuthController
  65. {
  66. /**
  67. * 白名单
  68. * */
  69. public static function WhiteList()
  70. {
  71. return [
  72. 'details',
  73. 'single_details',
  74. 'get_pink_info',
  75. 'get_course_list',
  76. 'play',
  77. 'play_num',
  78. 'grade_list',
  79. 'set_barrage_index',
  80. 'get_barrage_list',
  81. 'special_cate',
  82. 'get_grade_cate',
  83. 'get_subject_cate',
  84. 'get_special_list',
  85. 'get_cloumn_task',
  86. 'activity_details',
  87. 'isMember',
  88. 'activityType',
  89. 'groupLists',
  90. 'groupProjectList',
  91. 'learningRecords',
  92. 'numberCourses',
  93. 'addLearningRecords',
  94. 'groupWork',
  95. 'source_detail',
  96. 'getSourceDetail',
  97. 'relatedCourses',
  98. 'group_list',
  99. 'pinkIngLists',
  100. 'get_video_playback_credentials',
  101. 'getTemplateIds',
  102. 'special_reply_list',
  103. 'special_reply_data',
  104. 'inspect',
  105. 'SpecialDataDownload',
  106. 'data_details',
  107. 'exchange',
  108. 'question_index',
  109. 'special_validity',
  110. 'get_subject_info',
  111. ];
  112. }
  113. /**获取视频上传地址和凭证
  114. * @param string $videoId
  115. * @param int $type
  116. */
  117. public function get_video_playback_credentials($type = 1, $videoId = '')
  118. {
  119. $url = VodService::videoUploadAddressVoucher('', $type, $videoId);
  120. return JsonService::successful($url);
  121. }
  122. /**获取用户相关的订阅消息模版ID
  123. * @param $pay_type_num
  124. * @param $special_id
  125. */
  126. public function getTemplateIds($pay_type_num, $special_id)
  127. {
  128. $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
  129. if ($wechat_notification_message == 1) {
  130. $templateIds = '';
  131. } else {
  132. $templateIds = RoutineTemplate::getTemplateIdList($pay_type_num, $special_id);
  133. }
  134. return JsonService::successful($templateIds);
  135. }
  136. /**获取专题价格
  137. * @param $id
  138. * @return void
  139. * @throws \think\db\exception\DataNotFoundException
  140. * @throws \think\db\exception\ModelNotFoundException
  141. * @throws \think\exception\DbException
  142. */
  143. public function getSpecialPrice($id = 0)
  144. {
  145. if (!$id) return JsonService::fail('缺少参数');
  146. $special_money = SpecialModel::where('id', $id)->field('money,pay_type,member_money,member_pay_type')->find();
  147. if (!$special_money) return JsonService::fail('专题价格获取失败');
  148. return JsonService::successful($special_money);
  149. }
  150. /**
  151. * 专题详情
  152. * @param $id int 专题id
  153. * @param $pinkId int 拼团id
  154. * @param $gift_uid int 赠送礼物用户
  155. * @param $gift_order_id string 礼物订单号
  156. * @return
  157. */
  158. 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)
  159. {
  160. if (!$id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
  161. //leozhao add 课程记录
  162. if ($this->uid) {
  163. $log = SpecialLog::where(['sid' => $id, 'mid' => $this->uid])->find();
  164. if ($log) {
  165. $log->add_time = time();
  166. $log->save();
  167. } else {
  168. $specialLog = new SpecialLog();
  169. $data = ['sid' => $id, 'mid' => $this->uid, 'add_time' => time()];
  170. $specialLog->data($data)->save();
  171. }
  172. }
  173. //leozhao add 课程记录
  174. if ($gift_uid && $gift_order_id) {
  175. if ($gift_uid == $this->uid) $this->failed('您不能领取自己的礼物', Url::build('special/grade_list'));
  176. if (!User::get($gift_uid)) $this->failed('赠送礼物的用户不存在', Url::build('my/my_gift'));
  177. $order = StoreOrder::where(['is_del' => 0, 'order_id' => $gift_order_id])->find();
  178. if (!$order) $this->failed('赠送的礼物订单不存在', Url::build('my/my_gift'));
  179. if ($order->total_num == $order->gift_count) $this->failed('礼物已被领取完', Url::build('special/grade_list'));
  180. }
  181. $special = SpecialModel::getOneSpecial($this->uid, $id);
  182. if ($special === false) $this->failed(SpecialModel::getErrorInfo('无法访问'), Url::build('index/index'));
  183. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  184. if (!isset($special['special'])) $this->failed('专题信息未获得', Url::build('index/index'));
  185. $specialinfo = $special['special'];
  186. $specialinfo = is_string($specialinfo) ? json_decode($specialinfo, true) : $specialinfo;
  187. if (!$is_member && $specialinfo['is_mer_visible'] == 1) $this->failed('专题仅会员可以获得,请充值会员', Url::build('special/member_recharge'));
  188. if (in_array($specialinfo['money'], [0, 0.00]) || in_array($specialinfo['pay_type'], [PAY_NO_MONEY, PAY_PASSWORD])) {
  189. $isPay = 1;
  190. } else {
  191. $isPay = (!$this->uid || $this->uid == 0) ? false : SpecialBuy::PaySpecial($id, $this->uid);
  192. }
  193. $isBatch = SpecialBatch::isBatch($id);//专题是否开启兑换活动
  194. $isPink = false;
  195. if (!$isPay && $this->uid && !$pinkId) {
  196. $pinkId = StorePink::where(['cid' => $id, 'status' => '1', 'uid' => $this->uid])->order('add_time desc')->value('id');
  197. if ($pinkId) {
  198. $isPink = true;
  199. } else {
  200. $pinkId = 0;
  201. }
  202. }
  203. if ((float)$specialinfo['money'] < 0) {
  204. $isPink = true;
  205. }
  206. $liveInfo = [];
  207. if ($specialinfo['type'] == SPECIAL_LIVE) {
  208. $liveInfo = LiveStudio::where('special_id', $specialinfo['id'])->find();
  209. if (!$liveInfo) return $this->failed('直播间尚未查到!', Url::build('index/index'));
  210. if ($liveInfo->is_del) return $this->failed('直播间已经删除!', Url::build('index/index'));
  211. }
  212. $user_level = !$this->uid ? 0 : $this->userInfo;
  213. $site_url = SystemConfigService::get('site_url') . Url::build('special/details') . '?id=' . $id . '&spread_uid=' . $this->uid;
  214. $this->assign($special);
  215. $this->assign('pinkId', $pinkId);
  216. $this->assign('isBatch', $isBatch);
  217. $this->assign('site_url', $site_url);
  218. $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0);
  219. $this->assign('isPink', $isPink);
  220. $this->assign('isPay', $isPay);
  221. $this->assign('liveInfo', json_encode($liveInfo));
  222. $this->assign('orderId', $gift_order_id);
  223. $this->assign('link_pay', (int)$link_pay);
  224. $this->assign('gift', (int)$gift);
  225. $this->assign('link_pay_uid', $link_pay_uid);
  226. $this->assign('comment_switch', SystemConfigService::get('special_comment_switch'));//专题评论开关
  227. $this->assign('BarrageShowTime', SystemConfigService::get('barrage_show_time'));
  228. $this->assign('barrage_index', Cookie::get('barrage_index'));
  229. return $this->fetch();
  230. }
  231. /**获取课程可以使用时间
  232. * @param $id
  233. * @throws \think\Exception
  234. * @throws \think\db\exception\DataNotFoundException
  235. * @throws \think\db\exception\ModelNotFoundException
  236. * @throws \think\exception\DbException
  237. */
  238. public function special_validity($id)
  239. {
  240. $special_money = SpecialModel::where('id', $id)->field('money,pay_type,member_money,member_pay_type,is_mer_visible')->find();
  241. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  242. $validity = -1;
  243. if (in_array($special_money['money'], [0, 0.00]) || in_array($special_money['pay_type'], [PAY_NO_MONEY, PAY_PASSWORD])) {
  244. $validity = 0;
  245. } else {
  246. $isPay = (!$this->uid || $this->uid == 0) ? false : SpecialBuy::PaySpecial($id, $this->uid);
  247. if ($isPay) $validity = SpecialBuy::getSpecialEndTime($id, $this->uid);
  248. }
  249. if (in_array($special_money['member_money'], [0, 0.00]) || in_array($special_money['member_pay_type'], [PAY_NO_MONEY])) {
  250. if ($validity == -1 && $is_member) {
  251. $validity = bcsub($this->userInfo['overdue_time'], time(), 0);
  252. }
  253. }
  254. return JsonService::successful(['validity' => $validity]);
  255. }
  256. /**轻专题详情
  257. * @param int $id
  258. * @param int $pinkId
  259. * @param int $gift_uid
  260. * @param null $gift_order_id
  261. * @param int $link_pay_uid
  262. * @param int $partake
  263. * @param int $gift
  264. * @param int $link_pay
  265. * @return mixed
  266. * @throws \think\db\exception\DataNotFoundException
  267. * @throws \think\db\exception\ModelNotFoundException
  268. * @throws \think\exception\DbException
  269. */
  270. public function single_details($id = 0, $pinkId = 0, $gift_uid = 0, $gift_order_id = null, $link_pay_uid = 0, $partake = 0, $gift = 0, $link_pay = 0)
  271. {
  272. if (!$id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
  273. if ($gift_uid && $gift_order_id) {
  274. if ($gift_uid == $this->uid) $this->failed('您不能领取自己的礼物', Url::build('special/grade_list'));
  275. if (!User::get($gift_uid)) $this->failed('赠送礼物的用户不存在', Url::build('my/my_gift'));
  276. $order = StoreOrder::where(['is_del' => 0, 'order_id' => $gift_order_id])->find();
  277. if (!$order) $this->failed('赠送的礼物订单不存在', Url::build('my/my_gift'));
  278. if ($order->total_num == $order->gift_count) $this->failed('礼物已被领取完', Url::build('special/grade_list'));
  279. }
  280. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  281. $special = SpecialModel::getSingleOneSpecial($this->uid, $id);
  282. if ($special === false) $this->failed(SpecialModel::getErrorInfo('无法访问'), Url::build('index/index'));
  283. if (!isset($special['special'])) $this->failed('专题信息未获得', Url::build('index/index'));
  284. $specialinfo = $special['special'];
  285. $specialinfo = is_string($specialinfo) ? json_decode($specialinfo, true) : $specialinfo;
  286. if (!$is_member && $specialinfo['is_mer_visible'] == 1) $this->failed('专题仅会员可以获得,请充值会员', Url::build('special/member_recharge'));
  287. if (in_array($specialinfo['money'], [0, 0.00]) || in_array($specialinfo['pay_type'], [PAY_NO_MONEY, PAY_PASSWORD])) {
  288. $isPay = 1;
  289. } else {
  290. $isPay = (!$this->uid || $this->uid == 0) ? false : SpecialBuy::PaySpecial($id, $this->uid);
  291. }
  292. $isBatch = SpecialBatch::isBatch($id); //专题是否开启兑换活动
  293. $isPink = false;
  294. if (!$isPay && $this->uid && !$pinkId) {
  295. $pinkId = StorePink::where(['cid' => $id, 'status' => '1', 'uid' => $this->uid])->order('add_time desc')->value('id');
  296. if ($pinkId) {
  297. $isPink = true;
  298. } else {
  299. $pinkId = 0;
  300. }
  301. }
  302. if ((float)$specialinfo['money'] < 0) {
  303. $isPink = true;
  304. }
  305. $user_level = !$this->uid ? 0 : $this->userInfo;
  306. $site_url = SystemConfigService::get('site_url') . Url::build('special/single_details') . '?id=' . $id . '&spread_uid=' . $this->uid;
  307. $this->assign($special);
  308. $this->assign('pinkId', $pinkId);
  309. $this->assign('isBatch', $isBatch);
  310. $this->assign('site_url', $site_url);
  311. $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0);
  312. $this->assign('isPink', $isPink);
  313. $this->assign('isPay', $isPay);
  314. $this->assign('orderId', $gift_order_id);
  315. $this->assign('link_pay', (int)$link_pay);
  316. $this->assign('gift', (int)$gift);
  317. $this->assign('link_pay_uid', $link_pay_uid);
  318. $this->assign('comment_switch', SystemConfigService::get('special_comment_switch'));//专题评论开关
  319. $this->assign('BarrageShowTime', SystemConfigService::get('barrage_show_time'));
  320. $this->assign('barrage_index', Cookie::get('barrage_index'));
  321. return $this->fetch();
  322. }
  323. /**轻专题 图文内容
  324. * @param $try
  325. * @param $id
  326. * @return mixed
  327. */
  328. public function single_text_detail($try, $id)
  329. {
  330. $this->assign(['try' => $try, 'id' => $id]);
  331. return $this->fetch();
  332. }
  333. /**获取图文轻专题的内容
  334. * @param int $id
  335. * @throws \think\Exception
  336. * @throws \think\db\exception\DataNotFoundException
  337. * @throws \think\db\exception\ModelNotFoundException
  338. * @throws \think\exception\DbException
  339. */
  340. public function single_img_content($id = 0)
  341. {
  342. if (!$id) return JsonService::fail('缺少参数,无法访问');
  343. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  344. $data = SpecialModel::getSingleImgSpecialContent($id);
  345. if (in_array($data['money'], [0, 0.00]) || in_array($data['pay_type'], [PAY_NO_MONEY, PAY_PASSWORD]) || ($is_member > 0 && $data['member_pay_type'] == 0)) {
  346. $isPay = 1;
  347. } else {
  348. $isPay = (!$this->uid || $this->uid == 0) ? false : SpecialBuy::PaySpecial($id, $this->uid);
  349. }
  350. if(!$isPay) unset($data['content']);
  351. $site_url = SystemConfigService::get('site_url') . Url::build('special/single_details') . '?id=' . $id . '&spread_uid=' . $this->uid;
  352. $viewing_time = 0;
  353. if ($this->uid && $id) {
  354. $viewing_time = SpecialWatch::where(['uid' => $this->uid, 'special_id' => $id, 'task_id' => 0])->value('viewing_time');
  355. $viewing_time = $viewing_time ? $viewing_time : 0;
  356. }
  357. $data['viewing_time'] = $viewing_time;
  358. $data['is_member'] = $is_member;
  359. $data['isPay'] = $isPay;
  360. $data['link_url'] = $site_url;
  361. return JsonService::successful($data);
  362. }
  363. /**轻专题 音视频内容
  364. * @param $try
  365. * @param $id
  366. * @return mixed
  367. */
  368. public function single_con_detail($try, $id)
  369. {
  370. $this->assign(['try' => $try, 'id' => $id]);
  371. return $this->fetch();
  372. }
  373. /**获取音视频轻专题的内容
  374. * @param int $id
  375. * @throws \think\Exception
  376. * @throws \think\db\exception\DataNotFoundException
  377. * @throws \think\db\exception\ModelNotFoundException
  378. * @throws \think\exception\DbException
  379. */
  380. public function single_con_content($id = 0)
  381. {
  382. if (!$id) return JsonService::fail('缺少参数,无法访问');
  383. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  384. $taskInfo = SpecialModel::getSingleSpecialContent($id);
  385. if (in_array($taskInfo['money'], [0, 0.00]) || in_array($taskInfo['pay_type'], [PAY_NO_MONEY, PAY_PASSWORD]) || ($is_member > 0 && $taskInfo['member_pay_type'] == 0)) {
  386. $isPay = 1;
  387. } else {
  388. $isPay = (!$this->uid || $this->uid == 0) ? false : SpecialBuy::PaySpecial($id, $this->uid);
  389. }
  390. if ($isPay == false && !$taskInfo['singleProfile']['is_try']) {
  391. unset($taskInfo['singleProfile']['videoId'], $taskInfo['singleProfile']['link']);
  392. }
  393. $viewing_time = 0;
  394. if ($this->uid && $id) {
  395. $viewing_time = SpecialWatch::where(['uid' => $this->uid, 'special_id' => $id, 'task_id' => 0])->value('viewing_time');
  396. $viewing_time = $viewing_time ? $viewing_time : 0;
  397. }
  398. $site_url = SystemConfigService::get('site_url') . Url::build('special/single_details') . '?id=' . $id . '&spread_uid=' . $this->uid;
  399. $taskInfo['link_url'] = $site_url;
  400. $taskInfo['isPay'] = $isPay;
  401. $taskInfo['is_member'] = $is_member;
  402. $taskInfo['viewing_time'] = $viewing_time;
  403. return JsonService::successful($taskInfo);
  404. }
  405. /**专题下课程数量
  406. * @param $id
  407. */
  408. public function numberCourses($id)
  409. {
  410. $special = SpecialModel::PreWhere()->find($id);
  411. $count = SpecialModel::numberChapters($special->type, $id);
  412. return JsonService::successful($count);
  413. }
  414. /**获取拼团信息
  415. * @param int $id
  416. * @param int $pinkId
  417. */
  418. public function pinkIngLists($id = 0, $pinkId = 0)
  419. {
  420. $pinkIngList = StorePink::getPinkAll($id, 0, 0);
  421. foreach ($pinkIngList as &$item) {
  422. $item['difftime'] = [];
  423. $pinkAll = StorePink::getPinkMember($item['k_id'] ? $item['k_id'] : $item['id']);
  424. $pinkAll = StorePink::getPinkTFalseList($pinkAll, $item['k_id'] ? $item['k_id'] : $item['id'], $id);
  425. $pinkAllCount = count($pinkAll);
  426. $pinkT = $item['k_id'] ? StorePink::getPinkUserOne($item['k_id']) : $item;
  427. $item['num'] = bcsub($pinkT['people'], bcadd($pinkAllCount, 1, 0), 0);
  428. }
  429. return JsonService::successful($pinkIngList);
  430. }
  431. /**获取浏览人
  432. * @param $id
  433. * @throws \think\Exception
  434. * @throws \think\db\exception\DataNotFoundException
  435. * @throws \think\db\exception\ModelNotFoundException
  436. * @throws \think\exception\DbException
  437. */
  438. public function learningRecords($id)
  439. {
  440. $uids = LearningRecords::where(['special_id' => $id])->column('uid');
  441. $fake_sales = SpecialModel::where('id', $id)->value('fake_sales');
  442. $uids = array_unique($uids);
  443. $recordCoujnt = bcadd($fake_sales, count($uids), 0);
  444. if (count($uids) < 5) {
  445. if ($recordCoujnt >= 5) {
  446. $ic = bcsub(5, count($uids), 0);
  447. } else {
  448. $ic = bcsub($recordCoujnt, count($uids), 0);
  449. }
  450. if ($ic) {
  451. $maxid = User::where('status', 1)->max('uid');
  452. $minid = User::where('status', 1)->min('uid');
  453. for ($i = 0; $i < $ic; $i++) {
  454. $uid = rand($minid, $maxid);
  455. array_push($uids, $uid);
  456. }
  457. }
  458. } else {
  459. $uids = array_slice($uids, 0, 5);
  460. }
  461. $record = [];
  462. foreach ($uids as $key => $value) {
  463. $user = $this->userdata($value);
  464. array_push($record, $user);
  465. }
  466. $data['record'] = $record;
  467. $data['recordCoujnt'] = processingData($recordCoujnt);;
  468. return JsonService::successful($data);
  469. }
  470. public function userdata($uid)
  471. {
  472. $avatar = User::where('uid', $uid)->value('avatar');
  473. if ($avatar) {
  474. $user['avatar'] = $avatar;
  475. } else {
  476. $user['avatar'] = '/system/images/user_log.jpg';
  477. }
  478. return $user;
  479. }
  480. /**记录专题浏览人
  481. * @param $id
  482. * @throws \think\Exception
  483. * @throws \think\db\exception\DataNotFoundException
  484. * @throws \think\db\exception\ModelNotFoundException
  485. * @throws \think\exception\DbException
  486. */
  487. public function addLearningRecords($id)
  488. {
  489. $special = SpecialModel::PreWhere()->find($id);
  490. SpecialModel::where('id', $id)->setInc('browse_count');
  491. if ($this->uid) SpecialRecord::record($id, $this->uid);
  492. if ($this->uid) {
  493. $time = strtotime('today');
  494. LearningRecords::recordLearning($id, $this->uid, $time);
  495. if ($special->lecturer_id) {
  496. Lecturer::where('id', $special->lecturer_id)->setInc('study');
  497. }
  498. }
  499. return JsonService::successful('ok');
  500. }
  501. /**用户专题评价
  502. * @param int $special_id
  503. * @throws \think\db\exception\DataNotFoundException
  504. * @throws \think\db\exception\ModelNotFoundException
  505. * @throws \think\exception\DbException
  506. */
  507. public function user_comment_special($special_id = 0)
  508. {
  509. if (!$special_id) return JsonService::fail('参数错误!');
  510. $uid = $this->uid;
  511. if (SpecialReply::be(['special_id' => $special_id, 'uid' => $uid, 'is_del' => 0])) return JsonService::fail('该专题已评价!');
  512. $group = UtilService::postMore([
  513. ['comment', ''], ['pics', []], ['satisfied_score', 5]
  514. ]);
  515. if ($group['comment'] == '') return JsonService::fail('请填写评价内容');
  516. $group['comment'] = htmlspecialchars(trim($group['comment']));
  517. if (sensitive_words_filter($group['comment'])) return JsonService::fail('请注意您的用词,谢谢!!');
  518. if ($group['satisfied_score'] < 1) return JsonService::fail('请为专题满意度评分');
  519. $group = array_merge($group, [
  520. 'uid' => $uid,
  521. 'special_id' => $special_id
  522. ]);
  523. SpecialReply::beginTrans();
  524. $res = SpecialReply::reply($group);
  525. if (!$res) {
  526. SpecialReply::rollbackTrans();
  527. return JsonService::fail('评价失败!');
  528. }
  529. SpecialReply::uodateScore($special_id);
  530. SpecialReply::commitTrans();
  531. return JsonService::successful('评价成功!');
  532. }
  533. /**获取专题评价列表
  534. * @param string $special_id
  535. * @param int $page
  536. * @param int $limit
  537. * @param string $filter
  538. * @throws \think\db\exception\DataNotFoundException
  539. * @throws \think\db\exception\ModelNotFoundException
  540. * @throws \think\exception\DbException
  541. */
  542. public function special_reply_list($special_id = '', $page = 1, $limit = 8, $filter = 'all')
  543. {
  544. if (!$special_id || !is_numeric($special_id)) return JsonService::fail('参数错误!');
  545. if (!$this->uid) return JsonService::successful([]);
  546. $list = SpecialReply::getSpecialReplyList($special_id, $page, $limit, $filter, $this->uid);
  547. return JsonService::successful($list);
  548. }
  549. /**
  550. * 评价数据
  551. */
  552. public function special_reply_data($special_id = '')
  553. {
  554. if (!$special_id || !is_numeric($special_id)) return JsonService::fail('参数错误!');
  555. $data = SpecialReply::getSpecialReplyData($special_id);
  556. return JsonService::successful($data);
  557. }
  558. /**
  559. * 礼物领取
  560. *
  561. * */
  562. public function receive_gift($orderId = '')
  563. {
  564. if (!$orderId) return JsonService::fail('缺少参数');
  565. if (StoreOrder::createReceiveGift($orderId, $this->uid) == false)
  566. return JsonService::fail(StoreOrder::getErrorInfo('领取失败'));
  567. else
  568. return JsonService::successful('领取成功');
  569. }
  570. /**
  571. * 查看单个拼团状态
  572. * @param $pink_id int 拼团id
  573. * @return html
  574. * */
  575. public function order_pink($pink_id = '', $is_help = 0)
  576. {
  577. if (!$pink_id) $this->failed('缺少订单号', Url::build('my/order_list'));
  578. $this->assign([
  579. 'pink_id' => $pink_id,
  580. 'is_help' => $is_help,
  581. ]);
  582. return $this->fetch();
  583. }
  584. /**
  585. * 拼团支付完成后页面
  586. * @param null $orderId
  587. * @return mixed|void
  588. */
  589. public function pink($pink_id = 0, $special_id = 0, $is_help = 0, $orderId = null)
  590. {
  591. if (is_null($orderId) && $is_help == 0) {
  592. $orderId = StorePink::where(['id' => $pink_id, 'cid' => $special_id, 'uid' => $this->uid])->order('add_time desc')->value('order_id');
  593. } else if (is_null($orderId) && $is_help == 1) {
  594. $orderId = StorePink::where(['id' => $pink_id, 'cid' => $special_id, 'k_id' => 0])->order('add_time desc')->value('order_id');
  595. if (StorePink::be(['cid' => $special_id, 'uid' => $this->uid])) {
  596. $pink = StorePink::where(['cid' => $special_id, 'uid' => $this->uid])->field('id,k_id')->find();
  597. if ($pink && $pink_id == $pink['k_id'] || $pink_id == $pink['id']) {
  598. $is_help = 0;
  599. } else {
  600. return $this->failed('您已参与该专题的拼团,不能多次参与');
  601. }
  602. }
  603. }
  604. $info = StoreOrder::getOrderSpecialInfo($orderId, $this->uid);
  605. if ($info === false) return $this->failed(StoreOrder::getErrorInfo(), Url::build('my/details'));
  606. $site_url = SystemConfigService::get('site_url') . Url::build('special/pink') . '?pink_id=' . $info['pinkT']['id'] . '&special_id=' . $info['special']['id'] . '&is_help=1&spread_uid=' . $this->uid;
  607. $special = SpecialModel::PreWhere()->find($info['special_id']);
  608. if (!$special) $this->failed('专题不存在', Url::build('index/index'));
  609. $this->assign(['special_id' => $info['special_id'], 'site_url' => $site_url, 'info' => json_encode($info), 'pink_id' => $pink_id, 'is_help' => $is_help, 'is_light' => $special['is_light']]);
  610. return $this->fetch();
  611. }
  612. /**
  613. * 拼团专题列表
  614. */
  615. public function groupProjectList()
  616. {
  617. $where = UtilService::getMore([
  618. ['page', 1],
  619. ['limit', 10]
  620. ]);
  621. return JsonService::successful(SpecialModel::getPinkSpecialList($where['page'], $where['limit']));
  622. }
  623. /**
  624. * 拼团数量
  625. */
  626. public function groupWork()
  627. {
  628. $data['count'] = StorePink::where(['status' => 2])->count();
  629. $data['avatar'] = StorePink::where(['p.status' => 2])->alias('p')->join('User u', 'p.uid=u.uid')->field('u.avatar')->limit(0, 3)->select();
  630. return JsonService::successful($data);
  631. }
  632. /**
  633. * 获取单个拼团详情
  634. * $pinkId 拼团id
  635. * */
  636. public function get_pink_info($pinkId = 0)
  637. {
  638. $is_ok = 0;//判断拼团是否完成
  639. $userBool = 0;//判断当前用户是否在团内 0未在 1在
  640. $pinkBool = 0;//判断当前用户是否在团内 0未在 1在
  641. if (!$this->uid) return JsonService::fail('请先登录!');
  642. $pink = StorePink::getPinkUserOne($pinkId);
  643. if (isset($pink['is_refund']) && $pink['is_refund']) {
  644. return JsonService::fail('订单已退款', ['special_id' => $pink['cid']]);
  645. }
  646. if (!$pink) return JsonService::fail('参数错误', ['url' => Url::build('my/index')]);
  647. list($pinkAll, $pinkT, $count, $idAll, $uidAll) = StorePink::getPinkMemberAndPinkK($pink);
  648. if ($pinkT['status'] == 2)
  649. $pinkBool = 1;
  650. else {
  651. if (!$count || $count < 0) {//组团完成
  652. $pinkBool = StorePink::PinkComplete($uidAll, $idAll, $this->uid, $pinkT);
  653. } else {//拼团失败 退款
  654. $pinkBool = StorePink::PinkFail($this->uid, $idAll, $pinkAll, $pinkT, (int)$count, $pinkBool, $uidAll);
  655. }
  656. }
  657. if ($pinkBool === false) return JsonService::fail(StorePink::getErrorInfo());
  658. foreach ($pinkAll as $v) {
  659. if ($v['uid'] == $this->uid) $userBool = 1;
  660. }
  661. if ($pinkT['uid'] == $this->uid) $userBool = 1;
  662. $data['pinkBool'] = $pinkBool;
  663. $data['is_ok'] = $is_ok;
  664. $data['userBool'] = $userBool;
  665. $data['pinkT'] = $pinkT;
  666. $data['pinkAll'] = $pinkAll;
  667. $data['count'] = $count;
  668. $data['current_pink_order'] = StorePink::getCurrentPink($pinkId);
  669. $data['special'] = SpecialModel::getPinkSpecialInfo($pinkT['order_id'], $pinkId, $this->uid);
  670. return JsonService::successful($data);
  671. }
  672. /**
  673. * 专题收藏
  674. * @param $id int 专题id
  675. * @return json
  676. */
  677. public function collect($id = 0)
  678. {
  679. if (!$id) return JsonService::fail('缺少参数');
  680. if (SpecialRelation::SetCollect($this->uid, $id))
  681. return JsonService::successful('成功');
  682. else
  683. return JsonService::fail('失败');
  684. }
  685. /**
  686. * 获取某个专题的素材列表
  687. * @return json
  688. * */
  689. public function get_course_list()
  690. {
  691. list($page, $limit, $special_id) = UtilService::getMore([
  692. ['page', 1],
  693. ['limit', 10],
  694. ['special_id', 0],
  695. ], null, true);
  696. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  697. //不登录也能查看
  698. $task_list = SpecialCourse::getSpecialSourceList($special_id, $limit, $page, $this->uid, $is_member);
  699. if (!$task_list['list']) return JsonService::successful([]);
  700. foreach ($task_list['list'] as $k => $v) {
  701. $task_list['list'][$k]['type_name'] = SPECIAL_TYPE[$v['type']];
  702. if (!isset($task_list['list'][$k]['special_task'])) {
  703. $task_list['list'][$k]['watch'] = SpecialWatch::whetherWatch($this->uid, $special_id, $v['id']);
  704. }
  705. }
  706. return JsonService::successful($task_list);
  707. }
  708. /**
  709. * 获取专栏套餐 专栏关联的专题
  710. */
  711. public function get_cloumn_task()
  712. {
  713. list($page, $limit, $special_id, $source_id) = UtilService::getMore([
  714. ['page', 1],
  715. ['limit', 10],
  716. ['special_id', 0],
  717. ['source_id', 0],
  718. ], null, true);
  719. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  720. $task_list = SpecialCourse::get_cloumn_special($special_id, $source_id, $limit, $page, $this->uid, $is_member);
  721. if (!$task_list['list']) return JsonService::successful([]);
  722. foreach ($task_list['list'] as $k => $v) {
  723. $task_list['list'][$k]['type_name'] = SPECIAL_TYPE[$v['type']];
  724. if ($v['is_light']) {
  725. $task_list['list'][$k]['type'] = SpecialModel::lightType($v['light_type']);
  726. }
  727. }
  728. return JsonService::successful($task_list);
  729. }
  730. /**
  731. * 播放数量增加
  732. * @param int $task_id 任务id
  733. * @return json
  734. * */
  735. public function play_num($task_id = 0, $special_id = 0)
  736. {
  737. if ($task_id == 0 || $special_id == 0) return JsonService::fail('缺少参数');
  738. try {
  739. $add_task_play_count = SpecialTask::bcInc($task_id, 'play_count', 1);
  740. if ($add_task_play_count) {
  741. $special_source = SpecialSource::getSpecialSource((int)$special_id, [$task_id]);
  742. if ($special_source) {
  743. SpecialSource::where(['special_id' => $special_id, 'source_id' => $task_id])->setInc('play_count', 1);
  744. }
  745. return JsonService::successful('ok');
  746. } else {
  747. return JsonService::fail('err');
  748. }
  749. } catch (\Exception $e) {
  750. return JsonService::fail('err');
  751. }
  752. }
  753. /**
  754. * 播放任务
  755. * @param int $task_id 任务id
  756. * @return string
  757. * */
  758. public function play($task_id = 0)
  759. {
  760. if (!$task_id) $this->failed('无法访问', Url::build('index/index'));
  761. Session::set('video_token_' . $task_id, md5(time() . $task_id));
  762. $tash = SpecialTask::get($task_id);
  763. if (!$tash) $this->failed('您查看的资源不存在', Url::build('index/index'));
  764. if ($tash->is_show == 0) $this->failed('您查看的资源已下架', Url::build('index/index'));
  765. $this->assign('link', Trust($tash->link));
  766. $this->assign('task_id', $task_id);
  767. return $this->fetch();
  768. }
  769. public function go_video($task_id = 0)
  770. {
  771. if (Cookie::has('video_token_count_' . $task_id)) {
  772. Cookie::set('video_token_count_' . $task_id, Cookie::get('video_token_count_' . $task_id) + 1);
  773. } else {
  774. Cookie::set('video_token_count_' . $task_id, 1);
  775. }
  776. if (Session::has('video_token_' . $task_id)) {
  777. $tash = SpecialTask::get($task_id);
  778. if (Cookie::get('video_token_count_' . $task_id) >= 2) {
  779. Session::delete('video_token_' . $task_id);
  780. }
  781. exit(file_get_contents($tash->link));
  782. } else {
  783. throw new HttpException(404, '您查看的链接不存在');
  784. }
  785. }
  786. /**支付接口
  787. * @throws \think\db\exception\DataNotFoundException
  788. * @throws \think\db\exception\ModelNotFoundException
  789. * @throws \think\exception\DbException
  790. */
  791. public function create_order()
  792. {
  793. list($special_id, $pay_type_num, $payType, $from, $useGold, $pinkId, $total_num, $link_pay_uid, $key, $mark, $price_id, $event) = UtilService::PostMore([
  794. ['special_id', 0],
  795. ['pay_type_num', -1],
  796. ['payType', 'weixin'],
  797. ['from', 'weixin'],
  798. ['useGold', 0],
  799. ['pinkId', 0],
  800. ['total_num', 1],
  801. ['link_pay_uid', 0],
  802. ['key', ''],
  803. ['mark', ''],
  804. ['price_id', 0],
  805. ['event', []],
  806. ], $this->request, true);
  807. switch ($pay_type_num) {
  808. case 10://会员支付
  809. $this->create_member_order($special_id, $payType, $from);
  810. break;
  811. case 20://报名支付
  812. $this->create_activity_order($special_id, $payType, $price_id, $event, $from);
  813. break;
  814. case 30://虚拟币充值
  815. $auth_api = new AuthApi();
  816. $auth_api->user_wechat_recharge($special_id, $payType, $from);
  817. break;
  818. case 40: //商品购买
  819. $this->create_goods_order($special_id, $payType, $key, $useGold, $mark, $from);
  820. break;
  821. case 50: //订单再次支付
  822. $this->pay_order($special_id, $payType, $from);
  823. break;
  824. case 60: //试卷购买
  825. $this->create_test_paper_order($special_id, $payType, $from);
  826. break;
  827. case 70: //资料购买
  828. $this->create_data_download_order($special_id, $payType, $from);
  829. break;
  830. default://专题支付
  831. $this->create_special_order($special_id, $pay_type_num, $payType, $pinkId, $total_num, $link_pay_uid, $from);
  832. }
  833. }
  834. /**创建试卷支付订单
  835. * @param $test_id
  836. * @param $payType
  837. */
  838. public function create_data_download_order($data_id, $payType, $from = 'weixin')
  839. {
  840. $data = DataDownload::PreWhere()->find($data_id);
  841. if (!$data) return JsonService::status('ORDER_ERROR', '购买的资料不存在');
  842. $order = DataDownloadOrder::createDataDownloadOrder($data, $this->uid, $payType, 1);
  843. $orderId = $order['order_id'];
  844. $info = compact('orderId');
  845. if ($orderId) {
  846. $orderInfo = DataDownloadOrder::where('order_id', $orderId)->where('is_del', 0)->find();
  847. if (!$orderInfo || !isset($orderInfo['paid'])) return JsonService::status('pay_error', '支付订单不存在!');
  848. if ($orderInfo['paid']) return JsonService::status('pay_error', '支付已支付!');
  849. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  850. if (DataDownloadOrder::jsPayDataDownloadPrice($orderId, $this->uid))
  851. return JsonService::status('success', '支付成功', $info);
  852. else
  853. return JsonService::status('pay_error', DataDownloadOrder::getErrorInfo());
  854. } else {
  855. switch ($payType) {
  856. case 'weixin':
  857. try {
  858. if ($from == 'weixinh5') {
  859. $jsConfig = DataDownloadOrder::h5DataDownloadPay($orderId);
  860. } else {
  861. $jsConfig = DataDownloadOrder::jsDataDownloadPay($orderId);
  862. }
  863. } catch (\Exception $e) {
  864. return JsonService::status('pay_error', $e->getMessage(), $info);
  865. }
  866. $info['jsConfig'] = $jsConfig;
  867. if ($from == 'weixinh5') {
  868. return JsonService::status('wechat_h5_pay', '订单创建成功', $info);
  869. } else {
  870. return JsonService::status('wechat_pay', '订单创建成功', $info);
  871. }
  872. break;
  873. case 'yue':
  874. if (DataDownloadOrder::yueDataDownloadPay($orderId, $this->uid))
  875. return JsonService::status('success', '余额支付成功', $info);
  876. else
  877. return JsonService::status('pay_error', DataDownloadOrder::getErrorInfo());
  878. break;
  879. case 'zhifubao':
  880. $info['pay_price'] = $orderInfo['pay_price'];
  881. $info['orderName'] = '资料购买';
  882. return JsonService::status('zhifubao_pay', '订单创建成功', base64_encode(json_encode($info)));
  883. break;
  884. }
  885. }
  886. } else {
  887. return JsonService::fail(DataDownloadOrder::getErrorInfo('订单生成失败!'));
  888. }
  889. }
  890. /**创建试卷支付订单
  891. * @param $test_id
  892. * @param $payType
  893. */
  894. public function create_test_paper_order($test_id, $payType, $from = 'weixin')
  895. {
  896. $testPaper = TestPaper::PreExercisesWhere()->find($test_id);
  897. if (!$testPaper) return JsonService::status('ORDER_ERROR', '购买的试卷不存在');
  898. $order = TestPaperOrder::createTestPaperOrder($testPaper, $this->uid, $payType, 1);
  899. $orderId = $order['order_id'];
  900. $info = compact('orderId');
  901. if ($orderId) {
  902. $orderInfo = TestPaperOrder::where('order_id', $orderId)->where('is_del', 0)->find();
  903. if (!$orderInfo || !isset($orderInfo['paid'])) return JsonService::status('pay_error', '支付订单不存在!');
  904. if ($orderInfo['paid']) return JsonService::status('pay_error', '支付已支付!');
  905. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  906. if (TestPaperOrder::jsPayTestPaperPrice($orderId, $this->uid))
  907. return JsonService::status('success', '支付成功', $info);
  908. else
  909. return JsonService::status('pay_error', TestPaperOrder::getErrorInfo());
  910. } else {
  911. switch ($payType) {
  912. case 'weixin':
  913. try {
  914. if ($from == 'weixinh5') {
  915. $jsConfig = TestPaperOrder::h5TestPaperPay($orderId);
  916. } else {
  917. $jsConfig = TestPaperOrder::jsTestPaperPay($orderId);
  918. }
  919. } catch (\Exception $e) {
  920. return JsonService::status('pay_error', $e->getMessage(), $info);
  921. }
  922. $info['jsConfig'] = $jsConfig;
  923. if ($from == 'weixinh5') {
  924. return JsonService::status('wechat_h5_pay', '订单创建成功', $info);
  925. } else {
  926. return JsonService::status('wechat_pay', '订单创建成功', $info);
  927. }
  928. break;
  929. case 'yue':
  930. if (TestPaperOrder::yueTestPaperPay($orderId, $this->uid))
  931. return JsonService::status('success', '余额支付成功', $info);
  932. else
  933. return JsonService::status('pay_error', TestPaperOrder::getErrorInfo());
  934. break;
  935. case 'zhifubao':
  936. $info['pay_price'] = $orderInfo['pay_price'];
  937. $info['orderName'] = '试卷购买';
  938. return JsonService::status('zhifubao_pay', '订单创建成功', base64_encode(json_encode($info)));
  939. break;
  940. }
  941. }
  942. } else {
  943. return JsonService::fail(TestPaperOrder::getErrorInfo('订单生成失败!'));
  944. }
  945. }
  946. /**
  947. * 创建专题支付订单
  948. * @param int $special_id 专题id
  949. * @param int $pay_type 购买类型 1=礼物,2=普通购买,3=开团或者拼团
  950. * @throws \think\db\exception\DataNotFoundException
  951. * @throws \think\db\exception\ModelNotFoundException
  952. * @throws \think\exception\DbException
  953. */
  954. public function create_special_order($special_id, $pay_type_num, $payType, $pinkId, $total_num, $link_pay_uid, $from = 'weixin')
  955. {
  956. if (!$special_id) return JsonService::fail('缺少购买参数');
  957. if ($pay_type_num == -1) return JsonService::fail('选择购买方式');
  958. if ($pinkId && $pay_type_num != 1) {
  959. $orderId = StoreOrder::getStoreIdPink($pinkId);
  960. if (StorePink::getIsPinkUid($pinkId)) return JsonService::status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => $orderId]);
  961. if (StoreOrder::getIsOrderPink($pinkId)) return JsonService::status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => $orderId]);
  962. if (StorePink::getPinkStatusIng($pinkId)) return JsonService::status('ORDER_EXIST', '拼团已完成或者已过期无法参团', ['orderId' => $orderId]);
  963. if (StorePink::be(['uid' => $this->uid, 'type' => 1, 'cid' => $special_id, 'status' => 1])) return JsonService::status('ORDER_EXIST', '您已参见本专题的拼团,请结束后再进行参团');
  964. if (SpecialBuy::be(['uid' => $this->uid, 'special_id' => $special_id, 'is_del' => 0])) return JsonService::status('ORDER_EXIST', '您已获得此专题,不能在进行参团!');
  965. //处理拼团完成
  966. try {
  967. if ($pink = StorePink::get($pinkId)) {
  968. list($pinkAll, $pinkT, $count, $idAll, $uidAll) = StorePink::getPinkMemberAndPinkK($pink);
  969. if ($pinkT['status'] == 1) {
  970. if (!$count || $count < 0) {
  971. StorePink::PinkComplete($uidAll, $idAll, $pinkT['uid'], $pinkT);
  972. return JsonService::status('ORDER_EXIST', '当前拼团已完成,无法参团');
  973. } else
  974. StorePink::PinkFail($pinkT['uid'], $idAll, $pinkAll, $pinkT, $count, 0, $uidAll);
  975. } else if ($pinkT['status'] == 2) {
  976. return JsonService::status('ORDER_EXIST', '当前拼团已完成,无法参团');
  977. } else if ($pinkT['status'] == 3) {
  978. return JsonService::status('ORDER_EXIST', '拼团失败,无法参团');
  979. }
  980. }
  981. } catch (\Exception $e) {
  982. }
  983. }
  984. $special = SpecialModel::PreWhere()->find($special_id);
  985. if (!$special) return JsonService::status('ORDER_ERROR', '购买的专题不存在');
  986. $order = StoreOrder::createSpecialOrder($special, $pinkId, $pay_type_num, $this->uid, $payType, $link_pay_uid, $total_num);
  987. $orderId = $order['order_id'];
  988. $info = compact('orderId');
  989. if ($orderId) {
  990. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  991. if (!$orderInfo || !isset($orderInfo['paid'])) return JsonService::status('pay_error', '支付订单不存在!');
  992. if ($orderInfo['paid']) return JsonService::status('pay_error', '支付已支付!');
  993. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  994. if (StoreOrder::jsPayPrice($orderId, $this->uid))
  995. return JsonService::status('success', '支付成功', $info);
  996. else
  997. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  998. } else {
  999. switch ($payType) {
  1000. case 'weixin':
  1001. try {
  1002. if ($from == 'weixinh5') {
  1003. $jsConfig = StoreOrder::h5SpecialPay($orderId);
  1004. } else {
  1005. $jsConfig = StoreOrder::jsSpecialPay($orderId);
  1006. }
  1007. } catch (\Exception $e) {
  1008. return JsonService::status('pay_error', $e->getMessage(), $info);
  1009. }
  1010. $info['jsConfig'] = $jsConfig;
  1011. if ($from == 'weixinh5') {
  1012. return JsonService::status('wechat_h5_pay', '订单创建成功', $info);
  1013. } else {
  1014. return JsonService::status('wechat_pay', '订单创建成功', $info);
  1015. }
  1016. break;
  1017. case 'yue':
  1018. if (StoreOrder::yuePay($orderId, $this->uid))
  1019. return JsonService::status('success', '余额支付成功', $info);
  1020. else
  1021. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  1022. break;
  1023. case 'zhifubao':
  1024. $info['pay_price'] = $orderInfo['pay_price'];
  1025. $info['orderName'] = '专题购买';
  1026. return JsonService::status('zhifubao_pay', '订单创建成功', base64_encode(json_encode($info)));
  1027. break;
  1028. }
  1029. }
  1030. } else {
  1031. return JsonService::fail(StoreOrder::getErrorInfo('订单生成失败!'));
  1032. }
  1033. }
  1034. /**会员订单创建
  1035. * @param $id
  1036. * @param $payType
  1037. * @throws \think\db\exception\DataNotFoundException
  1038. * @throws \think\db\exception\ModelNotFoundException
  1039. * @throws \think\exception\DbException
  1040. */
  1041. public function create_member_order($id, $payType, $from = 'weixin')
  1042. {
  1043. if (!$id) return JsonService::fail('参数错误!');
  1044. $order = StoreOrder::cacheMemberCreateOrder($this->uid, $id, $payType);
  1045. $orderId = $order['order_id'];
  1046. $info = compact('orderId');
  1047. if ($orderId) {
  1048. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  1049. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  1050. if ($orderInfo['paid']) exception('支付已支付!');
  1051. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  1052. if (StoreOrder::jsPayMePrice($orderId, $this->uid))
  1053. return JsonService::status('success', '领取成功', $info);
  1054. else
  1055. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  1056. } else {
  1057. switch ($payType) {
  1058. case 'weixin':
  1059. try {
  1060. if ($from == 'weixinh5') {
  1061. $jsConfig = StoreOrder::h5PayMember($orderId);
  1062. } else {
  1063. $jsConfig = StoreOrder::jsPayMember($orderId);
  1064. }
  1065. } catch (\Exception $e) {
  1066. return JsonService::status('pay_error', $e->getMessage(), $info);
  1067. }
  1068. $info['jsConfig'] = $jsConfig;
  1069. if ($from == 'weixinh5') {
  1070. return JsonService::status('wechat_h5_pay', '订单创建成功', $info);
  1071. } else {
  1072. return JsonService::status('wechat_pay', '订单创建成功', $info);
  1073. }
  1074. break;
  1075. case 'zhifubao':
  1076. $info['pay_price'] = $orderInfo['pay_price'];
  1077. $info['orderName'] = '会员购买';
  1078. return JsonService::status('zhifubao_pay', '订单创建成功', base64_encode(json_encode($info)));
  1079. break;
  1080. }
  1081. }
  1082. } else {
  1083. return JsonService::fail(StoreOrder::getErrorInfo('领取失败!'));
  1084. }
  1085. }
  1086. /**
  1087. * 用户提交报名
  1088. */
  1089. public function create_activity_order($id, $payType, $price_id, $event, $from = 'weixin')
  1090. {
  1091. if (!$id) JsonService::fail('参数有误');
  1092. $order = EventSignUp::userEventSignUp($id, $price_id, json_encode($event), $payType, $this->uid);
  1093. $orderId = $order['order_id'];
  1094. $info = compact('orderId');
  1095. if ($orderId) {
  1096. $orderInfo = EventSignUp::where('order_id', $orderId)->find();
  1097. if (!$orderInfo || !isset($orderInfo['paid'])) return JsonService::status('pay_error', '支付订单不存在!');
  1098. if ($orderInfo['paid']) return JsonService::status('pay_error', '支付已支付!');
  1099. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  1100. if (EventSignUp::jsPayPrice($orderId, $this->uid))
  1101. return JsonService::status('success', '支付成功', $info);
  1102. else
  1103. return JsonService::status('pay_error', EventSignUp::getErrorInfo());
  1104. } else {
  1105. switch ($payType) {
  1106. case 'weixin':
  1107. try {
  1108. if ($from == 'weixinh5') {
  1109. $jsConfig = EventSignUp::h5Pay($orderId);
  1110. } else {
  1111. $jsConfig = EventSignUp::jsPay($orderId);
  1112. }
  1113. } catch (\Exception $e) {
  1114. return JsonService::status('pay_error', $e->getMessage(), $info);
  1115. }
  1116. $info['jsConfig'] = $jsConfig;
  1117. if ($from == 'weixinh5') {
  1118. return JsonService::status('wechat_h5_pay', '订单创建成功', $info);
  1119. } else {
  1120. return JsonService::status('wechat_pay', '订单创建成功', $info);
  1121. }
  1122. break;
  1123. case 'yue':
  1124. if (EventSignUp::yuePay($orderId, $this->uid))
  1125. return JsonService::status('success', '余额支付成功', $info);
  1126. else
  1127. return JsonService::status('pay_error', EventSignUp::getErrorInfo());
  1128. break;
  1129. case 'zhifubao':
  1130. $info['pay_price'] = $orderInfo['pay_price'];
  1131. $info['orderName'] = '活动报名';
  1132. return JsonService::status('zhifubao_pay', '订单创建成功', base64_encode(json_encode($info)));
  1133. break;
  1134. }
  1135. }
  1136. } else {
  1137. return JsonService::fail(EventSignUp::getErrorInfo('订单生成失败!'));
  1138. }
  1139. }
  1140. /**
  1141. * 购买完成后送礼物页面
  1142. * @param string $orderId 订单id
  1143. * @return strign
  1144. * */
  1145. public function gift_special($orderId = null)
  1146. {
  1147. if (is_null($orderId)) $this->failed('缺少订单号,无法进行赠送', Url::build('my/my_gift'));
  1148. if (!$this->uid) $this->failed('未获取到用户信息!', Url::build('index/index'));
  1149. $special = StoreOrder::getOrderIdToSpecial($orderId, $this->uid);
  1150. if ($special === false) $this->failed(StoreOrder::getErrorInfo(), Url::build('my/my_gift'));
  1151. if ($special['is_light']) {
  1152. $site_url = SystemConfigService::get('site_url') . Url::build('special/single_details') . '?id=' . $special['id'] . '&gift_uid=' . $this->uid . '&gift_order_id=' . $orderId . '&gift=1&spread_uid=' . $this->uid;
  1153. } else {
  1154. $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;
  1155. }
  1156. $this->assign([
  1157. 'orderId' => $orderId,
  1158. 'title' => '赠送礼物',
  1159. 'site_url' => $site_url,
  1160. 'special' => $special
  1161. ]);
  1162. return $this->fetch();
  1163. }
  1164. /**
  1165. * 查看领取记录
  1166. * @param $orderId string 订单id
  1167. * @return html
  1168. * */
  1169. public function gift_receive($orderId = null)
  1170. {
  1171. if (is_null($orderId)) $this->failed('缺少订单号,无法查看领取记录', Url::build('my/my_gift'));
  1172. $special = StoreOrder::getOrderIdGiftReceive($orderId);
  1173. if ($special === false) $this->failed(StoreOrder::getErrorInfo(), Url::build('my/my_gift'));
  1174. $this->assign($special);
  1175. return $this->fetch();
  1176. }
  1177. /**
  1178. * 购买失败删除订单
  1179. * @param string $orderId 订单id
  1180. * @return json
  1181. * */
  1182. public function del_order($orderId = '')
  1183. {
  1184. if (StoreOrder::where('order_id', $orderId)->update(['is_del' => 1]))
  1185. return JsonService::successful();
  1186. else
  1187. return JsonService::fail();
  1188. }
  1189. public function grade_list($type = 0)
  1190. {
  1191. $this->assign(compact('type'));
  1192. return $this->fetch();
  1193. }
  1194. public function grade_special($type = 0)
  1195. {
  1196. return $this->fetch();
  1197. }
  1198. /**
  1199. * 获取我的收藏
  1200. * @param int $type 课程类型
  1201. * @param int $page 分页
  1202. * @param int $limit 一页显示多少条
  1203. * @return json
  1204. * */
  1205. public function get_grade_list()
  1206. {
  1207. list($page, $limit, $active) = UtilService::GetMore([
  1208. ['page', 1],
  1209. ['limit', 10],
  1210. ['active', 0],
  1211. ], $this->request, true);
  1212. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  1213. return JsonService::successful(SpecialModel::getGradeList((int)$page, (int)$limit, $this->uid, $is_member, $active));
  1214. }
  1215. /**
  1216. * 获取我购买的课程
  1217. * @param int $type 课程类型
  1218. * @param int $page 分页
  1219. * @param int $limit 一页显示多少条
  1220. * @return json
  1221. * */
  1222. public function get_my_grade_list()
  1223. {
  1224. list($page, $limit, $active) = UtilService::GetMore([
  1225. ['page', 1],
  1226. ['limit', 10],
  1227. ['active', 0],
  1228. ], $this->request, true);
  1229. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  1230. return JsonService::successful(SpecialModel::getMyGradeList((int)$page, (int)$limit, $this->uid, $is_member, $active));
  1231. }
  1232. /**
  1233. * 拼团成功朋友圈海报展示
  1234. * @param $special_id int 专题id
  1235. * @return html
  1236. * */
  1237. public function poster_show($special_id = 0, $pinkId = 0, $is_help = 0)
  1238. {
  1239. if (!$special_id || !$pinkId) $this->failed('您查看的朋友去圈海报不存在', Url::build('spread/special'));
  1240. $special = SpecialModel::getSpecialInfo($special_id);
  1241. if ($special === false) $this->failed(SpecialModel::getErrorInfo(), Url::build('spread/special'));
  1242. if (!$special['poster_image']) $this->failed('您查看的海报不存在', Url::build('spread/special'));
  1243. $site_url = SystemConfigService::get('site_url') . Url::build('special/pink') . '?pink_id=' . $pinkId . '&special_id=' . $special['id'] . '&is_help=1&spread_uid=' . $this->uid;
  1244. $this->assign(['url' => $site_url, 'is_help' => $is_help, 'special' => json_encode($special)]);
  1245. return $this->fetch();
  1246. }
  1247. /**
  1248. * 获取专题弹幕
  1249. * @param int $special_id 专题id
  1250. * @return json
  1251. * */
  1252. public function get_barrage_list($special_id = 0)
  1253. {
  1254. if (!$special_id) return JsonService::fail('确实参数!');
  1255. if (SystemConfigService::get('open_barrage')) {
  1256. $barrage = SpecialBarrage::where('is_show', 1)->order('sort desc,id desc')->field(['nickname', 'avatar', 'action'])->select();
  1257. $barrage = count($barrage) ? $barrage->toArray() : [];
  1258. foreach ($barrage as &$item) {
  1259. $item['status_name'] = $item['action'] == 1 ? '1秒前发起了拼团' : '1秒前成功参团';
  1260. unset($item['action']);
  1261. }
  1262. $special = SpecialModel::where('id', $special_id)->find();
  1263. if (!$special) return JsonService::fail('确实参数!');
  1264. if ($special['is_pink']) {
  1265. $pinkList = StoreOrder::where(['o.cart_id' => $special_id, 'p.is_refund' => 0, 'o.refund_status' => 0, 'o.paid' => 1, 'p.is_false' => 0])
  1266. ->join("__STORE_PINK__ p", 'p.order_id=o.order_id')
  1267. ->join('__USER__ u', 'u.uid=o.uid')
  1268. ->field(['u.nickname', 'u.avatar', 'p.status', 'p.k_id'])
  1269. ->group('o.order_id')
  1270. ->order('o.add_time desc')
  1271. ->alias('o')
  1272. ->select();
  1273. $pinkList = count($pinkList) ? $pinkList->toArray() : [];
  1274. foreach ($pinkList as &$item) {
  1275. if ($item['status'] == 2 && $item['k_id'] == 0) {
  1276. $item['status_name'] = '1秒前拼团成功';
  1277. } else if ($item['status'] == 1 && $item['k_id'] == 0)
  1278. $item['status_name'] = '1秒前发起了拼团';
  1279. else if ($item['status'] == 2 && $item['k_id'] != 0)
  1280. $item['status_name'] = '1秒前拼团成功';
  1281. else if ($item['status'] == 1 && $item['k_id'] != 0)
  1282. $item['status_name'] = '1秒前发起了拼团';
  1283. else if ($item['status'] == 3)
  1284. $item['status_name'] = '1秒前参团成功';
  1285. unset($item['status'], $item['k_id']);
  1286. }
  1287. $barrageList = array_merge($pinkList, $barrage);
  1288. shuffle($barrageList);
  1289. } else {
  1290. $barrageList = [];
  1291. }
  1292. } else $barrageList = [];
  1293. return JsonService::successful($barrageList);
  1294. }
  1295. /**
  1296. * 拼团列表
  1297. */
  1298. public function groupLists($special_id = 0)
  1299. {
  1300. if (!$special_id) return JsonService::fail('确实参数!');
  1301. $special = SpecialModel::where('id', $special_id)->find();
  1302. if (!$special) return JsonService::fail('确实参数!');
  1303. if ($special['is_pink']) {
  1304. $pinkList = StoreOrder::where(['o.cart_id' => $special_id, 'p.is_refund' => 0, 'o.refund_status' => 0, 'o.paid' => 1, 'p.is_false' => 0])
  1305. ->join("__STORE_PINK__ p", 'p.order_id=o.order_id')
  1306. ->join('__USER__ u', 'u.uid=o.uid')
  1307. ->field(['u.nickname', 'u.avatar', 'p.status', 'p.k_id'])
  1308. ->group('o.order_id')
  1309. ->order('o.add_time desc')
  1310. ->alias('o')
  1311. ->select();
  1312. $pinkList = count($pinkList) ? $pinkList->toArray() : [];
  1313. } else {
  1314. $pinkList = [];
  1315. }
  1316. return JsonService::successful($pinkList);
  1317. }
  1318. /**
  1319. * 获取滚动index
  1320. * @param int $index
  1321. */
  1322. public function set_barrage_index($index = 0)
  1323. {
  1324. return JsonService::successful(Cookie::set('barrage_index', $index));
  1325. }
  1326. /**
  1327. * 专题分类
  1328. * @return mixed
  1329. */
  1330. public function special_cate($cate_id = 0, $subject_id = 0)
  1331. {
  1332. $this->assign([
  1333. 'homeLogo' => SystemConfigService::get('home_logo'),
  1334. 'cate_id' => (int)$cate_id,
  1335. 'subject_id' => (int)$subject_id
  1336. ]);
  1337. return $this->fetch();
  1338. }
  1339. /**
  1340. * 获取课程分类
  1341. * @throws \think\db\exception\DataNotFoundException
  1342. * @throws \think\db\exception\ModelNotFoundException
  1343. * @throws \think\exception\DbException
  1344. */
  1345. public function get_grade_cate()
  1346. {
  1347. $cateogry = SpecialSubject::with('children')->where(['is_show' => 1, 'is_del' => 0])->order('sort desc,id desc')->where('grade_id', 0)->select();
  1348. return JsonService::successful($cateogry->toArray());
  1349. }
  1350. /**
  1351. * 获取专题
  1352. * @param int $grade_id 一级分类ID
  1353. * @param int $subject_id 二级分类ID
  1354. * @param string $search
  1355. * @param int $page
  1356. * @param int $limit
  1357. * @param int $type 学习记录获取专题使用
  1358. */
  1359. public function get_special_list($grade_id = 0, $subject_id = 0, $search = '', $page = 1, $limit = 10, $type = 0)
  1360. {
  1361. $uid = $this->uid;
  1362. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  1363. $list = SpecialModel::getSpecialList(compact('grade_id', 'subject_id', 'search', 'page', 'limit', 'type', 'uid', 'is_member'));
  1364. return JsonService::successful($list);
  1365. }
  1366. /**
  1367. * 获取分类详情
  1368. */
  1369. public function get_subject_info($id = 0){
  1370. $biginfo = SpecialSubject::get($id);
  1371. if ($biginfo) $biginfo = $biginfo->toArray();
  1372. return JsonService::successful($biginfo);
  1373. }
  1374. /**
  1375. * 获取拼团专题
  1376. */
  1377. public function get_pink_special_list()
  1378. {
  1379. list($page, $limit) = UtilService::PostMore([
  1380. ['page', 1],
  1381. ['limit', 10]
  1382. ], $this->request, true);
  1383. return JsonService::successful(SpecialModel::getPinkSpecialList($page, $limit));
  1384. }
  1385. /**
  1386. * 学习记录
  1387. * @return mixed
  1388. */
  1389. public function record()
  1390. {
  1391. $this->assign(['homeLogo' => SystemConfigService::get('home_logo')]);
  1392. return $this->fetch();
  1393. }
  1394. /**
  1395. * 是否可以播放
  1396. * @param int $task_id 任务id
  1397. * @return string
  1398. * */
  1399. public function get_task_link($task_id = 0, $special_id = 0)
  1400. {
  1401. if (!$special_id || !$task_id) return JsonService::fail('缺少参数');
  1402. $special_source = SpecialSource::getSpecialSource($special_id, [$task_id]);
  1403. $tash = $special_source ? $special_source->toArray() : [];
  1404. if (!$tash) {
  1405. return JsonService::fail('您查看的视频已经下架');
  1406. } else {
  1407. return JsonService::successful($tash);
  1408. }
  1409. }
  1410. /**
  1411. * 课程详情
  1412. * @param $id
  1413. * @return mixed|void
  1414. * @throws \think\Exception
  1415. * @throws \think\db\exception\DataNotFoundException
  1416. * @throws \think\db\exception\ModelNotFoundException
  1417. * @throws \think\exception\DbException
  1418. */
  1419. public function task_info($id = 0, $specialId = 0)
  1420. {
  1421. if (!$id) return $this->failed('缺少课程id,无法查看', Url::build('index/index'));
  1422. $this->assign(['specialId' => $specialId, 'task_id' => $id]);
  1423. return $this->fetch();
  1424. }
  1425. /**检测用户身份
  1426. * @throws \Exception
  1427. */
  1428. public function isMember()
  1429. {
  1430. $user_level = !$this->uid ? 0 : $this->userInfo;
  1431. $data['is_member'] = isset($user_level['level']) ? $user_level['level'] : 0;
  1432. $data['now_money'] = isset($user_level['now_money']) ? $user_level['now_money'] : 0;
  1433. return JsonService::successful($data);
  1434. }
  1435. /**
  1436. * 图文素材详情
  1437. */
  1438. public function task_text_info($id = 0, $specialId = 0)
  1439. {
  1440. if (!$id) return $this->failed('缺少课程id,无法查看', Url::build('index/index'));
  1441. $this->assign(['specialId' => $specialId, 'task_id' => $id]);
  1442. return $this->fetch('text_detail');
  1443. }
  1444. /**
  1445. * @throws \think\Exception
  1446. * @throws \think\db\exception\DataNotFoundException
  1447. * @throws \think\db\exception\ModelNotFoundException
  1448. * @throws \think\exception\DbException
  1449. * special_id 专题ID task_id素材ID
  1450. */
  1451. public function getTaskInfo()
  1452. {
  1453. $data = UtilService::PostMore([
  1454. ['special_id', 0],
  1455. ['task_id', 0]
  1456. ], $this->request);
  1457. $taskInfo = SpecialTask::defaultWhere()->where('id', $data['task_id'])->find();
  1458. $special = SpecialModel::PreWhere()->where('id', $data['special_id'])->field('pay_type,money,member_pay_type,member_money')->find();
  1459. if (!$special) return JsonService::fail('您查看的专题不存在');
  1460. if (!$taskInfo) return JsonService::fail('课程信息不存在无法观看');
  1461. if ($taskInfo['is_show'] == 0) return JsonService::fail('该课程已经下架');
  1462. $isPay = SpecialBuy::PaySpecial($data['special_id'], $this->uid);
  1463. if ($taskInfo['type'] == 1) {
  1464. $content = htmlspecialchars_decode($taskInfo->content ? $taskInfo->content : "");
  1465. } else {
  1466. $special_content = SpecialContent::where('special_id', $data['special_id'])->value("content");
  1467. $content = htmlspecialchars_decode($taskInfo->detail ? $taskInfo->detail : $special_content);
  1468. }
  1469. $taskInfo->content = $content;
  1470. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  1471. if ($isPay || $special->pay_type == 0 || ($is_member > 0 && $special->member_pay_type == 0)) {
  1472. $isPay = true;
  1473. $isSourcePay = true;
  1474. } else {
  1475. $isPay = false;
  1476. $special_source = SpecialSource::where(['special_id' => $data['special_id'], 'source_id' => $data['task_id'], 'pay_status' => 0])->find();
  1477. if (!$special_source) {
  1478. $isSourcePay = false;
  1479. if ($isPay == false && $taskInfo['is_try']) {
  1480. unset($taskInfo['content']);
  1481. } else if ($isPay == false && !$taskInfo['is_try']) {
  1482. unset($taskInfo['content'], $taskInfo['videoId'], $taskInfo['link']);
  1483. }
  1484. } else {
  1485. $isSourcePay = true;
  1486. $special_source = $special_source->toArray();
  1487. $taskInfo = SpecialTask::defaultWhere()->where('id', $special_source['source_id'])->find();
  1488. if (!$taskInfo) return JsonService::fail('该素材无法观看');
  1489. $taskInfo->content = $content;
  1490. }
  1491. }
  1492. $site_url = SystemConfigService::get('site_url') . Url::build('special/details') . '?id=' . $data['special_id'] . '&spread_uid=' . $this->uid;
  1493. $array['link_url'] = $site_url;
  1494. $array['taskInfo'] = $taskInfo ? $taskInfo->toArray() : [];
  1495. $array['specialInfo'] = $special->toArray();
  1496. $array['is_member'] = $is_member;
  1497. $array['isPay'] = $isPay;
  1498. $array['isSourcePay'] = $isSourcePay;
  1499. return JsonService::successful($array);
  1500. }
  1501. /**
  1502. * 会员页
  1503. * @return mixed
  1504. */
  1505. public function member_manage($type = 1, $bid = 0)
  1506. {
  1507. $this->assign(['type' => $type, 'bid' => $bid, 'userInfo' => $this->userInfo]);
  1508. return $this->fetch('member/member_manage');
  1509. }
  1510. /**
  1511. * 会员购买页
  1512. * @return mixed
  1513. */
  1514. public function member_recharge()
  1515. {
  1516. $servicePhone = SystemConfigService::get('site_phone') ?: '';
  1517. $spread_poster_url = SystemConfigService::get('spread_poster_url');
  1518. $url = SystemConfigService::get('site_url') . Url::build('special/member_recharge', ['spread_uid' => $this->uid]);
  1519. $this->assign([
  1520. 'url' => $url,
  1521. 'servicePhone' => $servicePhone,
  1522. 'spread_poster_url' => $spread_poster_url
  1523. ]);
  1524. return $this->fetch('member/member_recharge');
  1525. }
  1526. /**
  1527. * 充值页面
  1528. */
  1529. public function recharge_index($from = 'my', $stream_name = "")
  1530. {
  1531. $user_info = $this->userInfo;
  1532. $gold_info = SystemConfigService::more("gold_name,gold_rate,gold_image");
  1533. $recharge_price_list = [60, 100, 300, 500, 980, 1980, 2980, 5180, 15980];
  1534. $gold_name = SystemConfigService::get('gold_name');//虚拟币名称
  1535. $this->assign(compact('gold_name'));
  1536. $this->assign('from', $from);
  1537. $this->assign('stream_name', $stream_name);
  1538. $this->assign('gold_info', json_encode($gold_info));
  1539. $this->assign('recharge_price_list', json_encode($recharge_price_list));
  1540. return $this->fetch('my/gold_coin');
  1541. }
  1542. /**
  1543. * 获取我的虚拟币数量
  1544. */
  1545. public function my_user_gold_num()
  1546. {
  1547. $user_info = $this->userInfo;
  1548. return JsonService::successful(['user_gold_num' => $user_info['gold_num']]);
  1549. }
  1550. /**
  1551. * 储存素材观看时间
  1552. */
  1553. public function viewing()
  1554. {
  1555. $data = UtilService::PostMore([
  1556. ['special_id', 0],
  1557. ['task_id', 0],
  1558. ['viewing_time', 0],
  1559. ['percentage', 0],
  1560. ['total', 0]
  1561. ], $this->request);
  1562. $res = SpecialWatch::materialViewing($this->uid, $data);
  1563. return JsonService::successful($res);
  1564. }
  1565. /**
  1566. * 专题检测是否达到领取证书标准
  1567. * $special_id 专题ID
  1568. * $is_light 是否为轻专题
  1569. */
  1570. public function inspect($special_id = 0, $is_light = 0)
  1571. {
  1572. if (!$this->uid) return JsonService::fail('err');
  1573. $res = CertificateRelated::getCertificateRelated($special_id, $is_light, 1, $this->uid);
  1574. if ($res) {
  1575. return JsonService::successful('ok');
  1576. } else {
  1577. return JsonService::fail('err');
  1578. }
  1579. }
  1580. /**用户领取证书
  1581. * $special_id 专题ID
  1582. */
  1583. public function getTheCertificate($special_id)
  1584. {
  1585. $res = CertificateRecord::getUserTheCertificate($special_id, 1, $this->uid);
  1586. if ($res) return JsonService::successful($res);
  1587. else return JsonService::fail('领取失败');
  1588. }
  1589. /**
  1590. * 活动报名情况
  1591. */
  1592. public function activityType($id)
  1593. {
  1594. $activity = EventRegistration::oneActivitys($id);
  1595. if (!$activity) return JsonService::fail('您查看的活动不存在');
  1596. $data['is_pay'] = 0;//是否购买报名过
  1597. $data['is_restrictions'] = 0; //是否超过限购
  1598. if ($this->uid) {
  1599. $signCount = EventSignUp::setWhere()->where(['activity_id' => $id, 'uid' => $this->uid])->count();
  1600. if ($signCount) {
  1601. $data['is_pay'] = 1;
  1602. if (bcsub($signCount, $activity['restrictions'], 0) >= 0 && $activity['restrictions'] > 0) $data['is_restrictions'] = 1;
  1603. }
  1604. }
  1605. return JsonService::successful($data);
  1606. }
  1607. /**活动报名
  1608. * @param int $id
  1609. * @return mixed
  1610. * @throws \think\Exception
  1611. */
  1612. public function activity_details($id = 0)
  1613. {
  1614. $activity = EventRegistration::oneActivitys($id);
  1615. if (!$activity) $this->failed('您查看的活动不存在', Url::build('activity/index'));
  1616. $this->assign([
  1617. 'is_member' => isset($this->userInfo['level']) ? $this->userInfo['level'] : 0,
  1618. 'is_fill' => $activity['is_fill'],
  1619. 'activity' => json_encode($activity),
  1620. 'activity_rules' => htmlspecialchars_decode($activity['activity_rules']),
  1621. 'content' => htmlspecialchars_decode($activity['content'])
  1622. ]);
  1623. return $this->fetch('activity/index');
  1624. }
  1625. /**活动报名信息填写
  1626. * @return mixed
  1627. */
  1628. public function event()
  1629. {
  1630. return $this->fetch('activity/event');
  1631. }
  1632. /**商品订单提交
  1633. * @param string $cartId
  1634. * @return mixed|void
  1635. * @throws \Exception
  1636. */
  1637. public function confirm_order($cartId = '')
  1638. {
  1639. if (!is_string($cartId) || !$cartId) {
  1640. return $this->failed('请提交购买的商品!', Url::build('store/index'));
  1641. }
  1642. $user = $this->userInfo;
  1643. $cartGroup = StoreCart::getUserProductCartList($this->uid, $cartId, 1, $user['level']);
  1644. if (count($cartGroup['invalid']))
  1645. return $this->failed($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!', Url::build('store/index'));
  1646. if (!$cartGroup['valid']) return $this->failed('请提交购买的商品!', Url::build('store/index'));
  1647. $cartInfo = $cartGroup['valid'];
  1648. $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo);
  1649. $ratio = SystemConfigService::get('deduction_proportion_ratio');
  1650. $ratio = bcdiv($ratio, 100, 2);
  1651. $gold_name = SystemConfigService::get('gold_name');//虚拟币名称
  1652. $this->assign([
  1653. 'level' => $user['level'],
  1654. 'gold_num' => $user['gold_num'],
  1655. 'gold_name' => $gold_name,
  1656. 'cartInfo' => json_encode($cartInfo),
  1657. 'cartId' => $cartId,
  1658. 'priceGroup' => json_encode($priceGroup),
  1659. 'orderKey' => StoreOrder::cacheOrderInfo($this->uid, $cartInfo, $priceGroup),
  1660. 'ratio' => $ratio
  1661. ]);
  1662. return $this->fetch('store/order_confirm');
  1663. }
  1664. /**订单提交页修改商品数量
  1665. * @param string $cartId
  1666. * @param int $cateNum
  1667. */
  1668. public function getOrderPrice($cartId = '', $cateNum = 1)
  1669. {
  1670. $res = StoreCart::changeUserCartNum($cartId, $cateNum, $this->uid);
  1671. if (!$res) return JsonService::fail('商品数量修改失败!');
  1672. $user = $this->userInfo;
  1673. $cartGroup = StoreCart::getUserProductCartList($this->uid, $cartId, 1, $user['level']);
  1674. if (count($cartGroup['invalid'])) return JsonService::fail($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!');
  1675. if (!$cartGroup['valid']) return JsonService::fail('请提交购买的商品!');
  1676. $cartInfo = $cartGroup['valid'];
  1677. $data['priceGroup'] = StoreOrder::getOrderPriceGroup($cartInfo);
  1678. $data['orderKey'] = StoreOrder::cacheOrderInfo($this->uid, $cartInfo, $data['priceGroup']);
  1679. return JsonService::successful($data);
  1680. }
  1681. /**
  1682. * 创建商品订单
  1683. * @param string $key
  1684. * @return \think\response\Json
  1685. */
  1686. public function create_goods_order($addressId, $payType, $key, $useGold, $mark, $from = 'weixin')
  1687. {
  1688. if (!$key) return JsonService::fail('参数错误!');
  1689. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $this->uid, 'is_del' => 0, 'type' => 2]))
  1690. return JsonService::status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  1691. $payType = strtolower($payType);
  1692. $order = StoreOrder::cacheKeyCreateOrder($this->uid, $key, $addressId, $payType, $useGold, $mark);
  1693. $orderId = $order['order_id'];
  1694. $info = compact('orderId', 'key');
  1695. if ($orderId) {
  1696. $orderInfo = StoreOrder::where('order_id', $orderId)->where('type', 2)->find();
  1697. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  1698. if ($orderInfo['paid']) exception('支付已支付!');
  1699. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  1700. if (StoreOrder::jsPayGoodsPrice($orderId, $this->uid))
  1701. return JsonService::status('success', '支付成功', $info);
  1702. else
  1703. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  1704. } else {
  1705. switch ($payType) {
  1706. case 'weixin':
  1707. try {
  1708. if ($from == 'weixinh5') {
  1709. $jsConfig = StoreOrder::h5Pay($orderId);
  1710. } else {
  1711. $jsConfig = StoreOrder::jsPay($orderId);
  1712. }
  1713. } catch (\Exception $e) {
  1714. return JsonService::status('pay_error', $e->getMessage(), $info);
  1715. }
  1716. $info['jsConfig'] = $jsConfig;
  1717. if ($from == 'weixinh5') {
  1718. return JsonService::status('wechat_h5_pay', '订单创建成功', $info);
  1719. } else {
  1720. return JsonService::status('wechat_pay', '订单创建成功', $info);
  1721. }
  1722. break;
  1723. case 'yue':
  1724. if (StoreOrder::yueGoodsPay($orderId, $this->uid))
  1725. return JsonService::status('success', '余额支付成功', $info);
  1726. else
  1727. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  1728. break;
  1729. case 'zhifubao':
  1730. $info['pay_price'] = $orderInfo['pay_price'];
  1731. $info['orderName'] = '商品购买';
  1732. return JsonService::status('zhifubao_pay', '订单创建成功', base64_encode(json_encode($info)));
  1733. break;
  1734. }
  1735. }
  1736. } else {
  1737. return JsonService::fail(StoreOrder::getErrorInfo('订单生成失败!'));
  1738. }
  1739. }
  1740. /**
  1741. * 我的商品订单
  1742. */
  1743. public function order_store_list($type = 9)
  1744. {
  1745. $this->assign(['type' => $type]);
  1746. return $this->fetch('my/order_store_list');
  1747. }
  1748. /**
  1749. * 订单详情
  1750. * @return mixed
  1751. */
  1752. public function order($uni = '')
  1753. {
  1754. if (!$uni || !$order = StoreOrder::getUserOrderDetail($this->uid, $uni)) return $this->redirect(Url::build('wap/my/order_list'));
  1755. $this->assign([
  1756. 'gold_name' => SystemConfigService::get('gold_name'),
  1757. 'order' => StoreOrder::tidyOrder($order, true, true)
  1758. ]);
  1759. return $this->fetch('my/order');
  1760. }
  1761. /**
  1762. * 支付订单
  1763. * @param string $uni
  1764. * @return \think\response\Json
  1765. */
  1766. public function pay_order($id, $payType, $from = 'weixin')
  1767. {
  1768. if (!$id) return JsonService::fail('参数错误!');
  1769. $order = StoreOrder::where('id', $id)->where('type', 2)->where('uid', $this->uid)->where('is_del', 0)->find();
  1770. if (!$order) return JsonService::fail('订单不存在!');
  1771. if ($order['paid']) return JsonService::fail('该订单已支付!');
  1772. $info['orderId'] = $order['order_id'];
  1773. if ($payType != $order['pay_type']) {
  1774. $res = StoreOrder::where('id', $id)->where('type', 2)->where('uid', $this->uid)->where('is_del', 0)->update(['pay_type' => $payType]);
  1775. if (!$res) return JsonService::fail('订单支付方式修改失败!');
  1776. }
  1777. $order['pay_type'] = $payType;
  1778. if ($payType != 'yue') {
  1779. if ($from == 'weixin' || $from == 'weixinh5') {
  1780. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  1781. }
  1782. }
  1783. if ($payType == 'weixin') {
  1784. try {
  1785. if ($from == 'weixinh5') {
  1786. $jsConfig = StoreOrder::h5Pay($order);
  1787. } else {
  1788. $jsConfig = StoreOrder::jsPay($order);
  1789. }
  1790. } catch (\Exception $e) {
  1791. return JsonService::fail($e->getMessage());
  1792. }
  1793. $info['jsConfig'] = $jsConfig;
  1794. if ($from == 'weixinh5') {
  1795. return JsonService::status('wechat_h5_pay', '订单创建成功', $info);
  1796. } else {
  1797. return JsonService::status('wechat_pay', '订单创建成功', $info);
  1798. }
  1799. } else if ($payType == 'yue') {
  1800. if ($res = StoreOrder::yueGoodsPay($order['order_id'], $this->uid))
  1801. return JsonService::status('success', '余额支付成功', $info);
  1802. else
  1803. return JsonService::status('pay_error', StoreOrder::getErrorInfo());
  1804. } else if ($payType == 'zhifubao') {
  1805. $info['pay_price'] = $order['pay_price'];
  1806. $info['orderName'] = '商品购买';
  1807. return JsonService::status('zhifubao_pay', '订单创建成功', base64_encode(json_encode($info)));
  1808. }
  1809. }
  1810. /**
  1811. * 素材详情
  1812. */
  1813. public function source_detail($id = 0)
  1814. {
  1815. if (!$id) return JsonService::fail('缺少参数');
  1816. $this->assign('id', $id);
  1817. return $this->fetch();
  1818. }
  1819. /**获取素材详情
  1820. * @param int $source_id
  1821. */
  1822. public function getSourceDetail($source_id = 0)
  1823. {
  1824. if (!$source_id) return JsonService::fail('缺少参数');
  1825. $taskInfo = SpecialTask::defaultWhere()->where('id', $source_id)->find();
  1826. SpecialTask::bcInc($source_id, 'play_count', 1);
  1827. return JsonService::successful($taskInfo);
  1828. }
  1829. /**相关课程
  1830. * @param int $source_id
  1831. * @throws \think\db\exception\DataNotFoundException
  1832. * @throws \think\db\exception\ModelNotFoundException
  1833. * @throws \think\exception\DbException
  1834. */
  1835. public function relatedCourses($source_id = 0)
  1836. {
  1837. if (!$source_id) return JsonService::fail('缺少参数');
  1838. $specialList = SpecialSource::where('source_id', $source_id)->column('special_id');
  1839. $array = [];
  1840. foreach ($specialList as $key => $value) {
  1841. $special = SpecialModel::PreWhere()->where('id', $value)->find();
  1842. if (!$special) continue;
  1843. $special['count'] = 0;
  1844. $specialSourceId = SpecialSource::getSpecialSource($value);
  1845. if ($specialSourceId) $special['count'] = count($specialSourceId);
  1846. $count = SpecialModel::learning_records($value);
  1847. $special['record'] = processingData(bcadd($count, $special['fake_sales'], 0));
  1848. array_push($array, $special);
  1849. }
  1850. return JsonService::successful($array);
  1851. }
  1852. /**
  1853. * 拼团列表
  1854. */
  1855. public function group_list()
  1856. {
  1857. $this->assign('group_background', SystemConfigService::get('group_background'));
  1858. return $this->fetch();
  1859. }
  1860. /**考试详情
  1861. * @return mixed
  1862. */
  1863. public function question_index($id)
  1864. {
  1865. if (!$id) $this->failed('缺少参数,无法访问');
  1866. $title = TestPaper::PreExercisesWhere()->where('id', $id)->value('title');
  1867. $user_level = !$this->uid ? 0 : $this->userInfo;
  1868. $this->assign(['uid' => $this->uid, 'titles' => $title, 'id' => $id, 'is_member' => isset($user_level['level']) ? $user_level['level'] : 0]);
  1869. return $this->fetch('topic/question_index');
  1870. }
  1871. /**
  1872. * 兑换码兑换专题
  1873. */
  1874. public function exchange($special_id = 0)
  1875. {
  1876. $this->assign('special_id', $special_id);
  1877. return $this->fetch();
  1878. }
  1879. /**
  1880. * 兑换码提交兑换
  1881. */
  1882. public function exchangeSubmit()
  1883. {
  1884. list($special_id, $code) = UtilService::PostMore([
  1885. ['special_id', 0],
  1886. ['code', '']
  1887. ], $this->request, true);
  1888. if (!$special_id || !$code) return JsonService::fail('缺少参数');
  1889. $data = SpecialExchange::userExchangeSubmit($this->uid, $special_id, $code);
  1890. if ($data)
  1891. return JsonService::successful($data);
  1892. else
  1893. return JsonService::fail(SpecialExchange::getErrorInfo('兑换失败!'));
  1894. }
  1895. /**
  1896. * 资料详情
  1897. * @param $id int 资料id
  1898. * @return
  1899. */
  1900. public function data_details($id = 0)
  1901. {
  1902. if (!$id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
  1903. $data = DataDownload::getOneDataDownload($this->uid, $id);
  1904. if ($data === false) $this->failed(DataDownload::getErrorInfo('无法访问'), Url::build('index/index'));
  1905. $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0;
  1906. $data_money = DataDownload::where('id', $id)->field('money,pay_type')->find();
  1907. if (in_array($data_money['money'], [0, 0.00]) || in_array($data_money['pay_type'], [PAY_NO_MONEY, PAY_PASSWORD])) {
  1908. $isPay = 1;
  1909. } else {
  1910. $isPay = (!$this->uid || $this->uid == 0) ? false : DataDownloadBuy::PayDataDownload($id, $this->uid);
  1911. }
  1912. $site_url = SystemConfigService::get('site_url') . Url::build('special/data_details') . '?id=' . $id . '&spread_uid=' . $this->uid;
  1913. $this->assign($data);
  1914. $this->assign('site_url', $site_url);
  1915. $this->assign('is_member', $is_member);
  1916. $this->assign('isPay', $isPay);
  1917. return $this->fetch();
  1918. }
  1919. /**专题关联的资料
  1920. * @param int $id
  1921. */
  1922. public function SpecialDataDownload($special_id = 0)
  1923. {
  1924. if (!$special_id) return JsonService::fail('缺少参数,无法访问');
  1925. $data_ids = Relation::setWhere(4, $special_id)->column('relation_id');
  1926. $data = DataDownload::PreWhere()->where('id', 'in', $data_ids)->order('sort desc,id desc')->select();
  1927. $data = count($data) > 0 ? $data->toArray() : [];
  1928. return JsonService::successful($data);
  1929. }
  1930. }