ChapterController.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Book;
  3. use App\Modules\SendOrder\Models\SendOrder;
  4. use App\Modules\SendOrder\Services\SendOrderService;
  5. use App\Modules\Statistic\Services\WapVisitStatService;
  6. use App\Modules\User\Models\QappUser;
  7. use App\Modules\User\Services\UserBookCombinationConfigService;
  8. use Illuminate\Http\Request;
  9. use App\Http\Controllers\QuickApp\BaseController;
  10. use Redis;
  11. use App\Modules\Book\Services\ChapterService;
  12. use App\Modules\User\Services\ReadRecordService;
  13. use App\Http\Controllers\QuickApp\Book\Transformers\ChapterTransformer;
  14. use App\Modules\Book\Services\BookConfigService;
  15. use App\Http\Controllers\QuickApp\Book\Transformers\ChapterListTransformer;
  16. use App\Jobs\UserRententionJob;
  17. use App\Modules\Book\Services\BookService;
  18. use App\Modules\Subscribe\Services\BookOrderService;
  19. use App\Modules\Subscribe\Services\ChapterOrderService;
  20. use App\Modules\Subscribe\Services\YearOrderService;
  21. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  22. use App\Modules\Subscribe\Services\ChapterReminderService;
  23. use App\Modules\User\Services\UserDeepReadTagService;
  24. use App\Modules\UserTask\Services\BaseTask;
  25. use App\Modules\UserTask\Services\UserTaskService;
  26. use App\Modules\SendOrder\Models\QappSendOrder;
  27. class ChapterController extends BaseController
  28. {
  29. private $book_info;
  30. public function getCatalog(Request $request, $bid)
  31. {
  32. $bid = BookService::decodeBidStatic($bid);
  33. $lists = ChapterService::getChapterLists($bid);
  34. $book_info = BookConfigService::getBookById($bid);
  35. if (!$book_info) {
  36. return response()->error('PARAM_ERROR');
  37. }
  38. $this->book_info = $book_info;
  39. $lists = $this->getChapterCatalog($bid, $lists, $book_info);
  40. return response()->collection(new ChapterListTransformer, $lists);
  41. }
  42. public function getCatalogPerPage(Request $request, $bid)
  43. {
  44. $bid = BookService::decodeBidStatic($bid);
  45. $book_info = BookConfigService::getBookById($bid);
  46. if (!$book_info) {
  47. return response()->error('PARAM_ERROR');
  48. }
  49. $this->book_info = $book_info;
  50. $page_size = $request->input('page_size', 15);
  51. // if ($page_size >= 100) $page_size = 100;
  52. if ($page_size >= 20) $page_size = 20;
  53. // $page_size = 15;
  54. $res = ChapterService::getChapterListsPage($bid, $page_size);
  55. $lists = $this->getChapterCatalog($bid, $res, $book_info);
  56. return response()->pagination(new ChapterListTransformer, $lists);
  57. }
  58. private function getChapterCatalog(int $bid, $chapters, $book_info)
  59. {
  60. // 查询书籍是否限免
  61. $isFree = BookConfigService::judgeBookIsFree($bid);
  62. //渠道自定义vip章节
  63. //$vip_sequence = Redis::hget('channel:chapterfee:setting:' . $this->distribution_channel_id, $bid);
  64. $vip_sequence = BookService::getVipSequence($bid, $this->distribution_channel_id, $this->send_order_id);
  65. list($is_split, $is_change_chapter_name) = BookService::splitContent($bid);
  66. $change_chapter_name = 0;
  67. if ($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name)) {
  68. $change_chapter_name = 1;
  69. }
  70. $account = $this->getAccount();
  71. $work_wechat_info = $this->getWorkWechatInfo($bid);
  72. switch ($book_info->charge_type) {
  73. case 'BOOK':
  74. $price = $this->getPriceNew($book_info, 0, $account);
  75. $is_need_charge = $this->isBookNeedCharge($bid, $price);
  76. foreach ($chapters as $v) {
  77. $v->next_chapter_status = 0;
  78. $v->next_price = 0;
  79. $v->is_need_charge = $v->is_vip ? $is_need_charge : false;
  80. $v->price = $price;
  81. if ($work_wechat_info['force_add_work_wechat_type'] > 0 && $v->sequence >= $work_wechat_info['force_add_work_wechat_seq']){
  82. $v->force_add_work_wechat_type = $work_wechat_info['force_add_work_wechat_type'];
  83. $v->force_add_work_wechat_url = $work_wechat_info['force_add_work_wechat_url'];
  84. }else{
  85. $v->force_add_work_wechat_type = 0;
  86. $v->force_add_work_wechat_url = "";
  87. }
  88. // 限免判断
  89. if ($isFree) {
  90. $v->is_need_charge = false;
  91. $v->price = 0;
  92. }
  93. if ($vip_sequence) {
  94. if ($v->sequence >= $vip_sequence) {
  95. $v->is_vip = 1;
  96. } else {
  97. $v->is_vip = 0;
  98. }
  99. }
  100. //拆章
  101. if ($change_chapter_name) {
  102. $v->name = '第' . $v->sequence . '章';
  103. }
  104. }
  105. break;
  106. default:
  107. $chapterIds = $this->getChapterIds($chapters);
  108. $rules = ['check' => 0, 'paycid' => []];
  109. if (!$isFree && !empty($chapterIds)) {
  110. $rules = $this->getHandelData($bid, $chapterIds);
  111. }
  112. foreach ($chapters as $v) {
  113. if ($vip_sequence) {
  114. if ($v->sequence >= $vip_sequence) {
  115. $v->is_vip = 1;
  116. } else {
  117. $v->is_vip = 0;
  118. }
  119. }
  120. if ($work_wechat_info['force_add_work_wechat_type'] > 0 && $v->sequence >= $work_wechat_info['force_add_work_wechat_seq']){
  121. $v->force_add_work_wechat_type = $work_wechat_info['force_add_work_wechat_type'];
  122. $v->force_add_work_wechat_url = $work_wechat_info['force_add_work_wechat_url'];
  123. }else{
  124. $v->force_add_work_wechat_type = 0;
  125. $v->force_add_work_wechat_url = "";
  126. }
  127. // 限免判断
  128. if ($isFree) {
  129. $v->is_need_charge = false;
  130. $v->price = 0;
  131. } else {
  132. $v->price = $v->is_vip ? $this->getPriceNew($book_info, $v->size, $account) : 0;
  133. $v->is_need_charge = $v->is_vip ? $this->isChapterNeedChargeNew($v->id, $rules, $v->price) : false;
  134. }
  135. // //下一章付费信息
  136. $v->next_chapter_status = 0;
  137. $v->next_price = 0;
  138. // if($v->is_vip){
  139. // if(in_array($v->next_price,$chapterIds)){
  140. //
  141. // }else{
  142. // $next_chapter_order_status = $this->nextChapterOrderStatus($bid,$v->next_cid);
  143. // $v->next_chapter_status = $next_chapter_order_status['next_chapter_status'];
  144. // $v->next_price = $next_chapter_order_status['next_price'];
  145. // }
  146. //
  147. // }
  148. $v->next_chapter_status = $this->isSubscribe($v->id, $rules);
  149. $v->next_price = $v->price;
  150. //拆章
  151. if ($change_chapter_name) {
  152. $v->name = '第' . $v->sequence . '章';
  153. }
  154. }
  155. break;
  156. }
  157. return $chapters;
  158. }
  159. private function getChapterCatalogOld(int $bid, $chapters, $book_info)
  160. {
  161. // 查询书籍是否限免
  162. $isFree = BookConfigService::judgeBookIsFree($bid);
  163. //渠道自定义vip章节
  164. //$vip_sequence = Redis::hget('channel:chapterfee:setting:' . $this->distribution_channel_id, $bid);
  165. $vip_sequence = BookService::getVipSequence($bid, $this->distribution_channel_id, $this->send_order_id);
  166. list($is_split, $is_change_chapter_name) = BookService::splitContent($bid);
  167. $change_chapter_name = 0;
  168. if ($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name)) {
  169. $change_chapter_name = 1;
  170. }
  171. switch ($book_info->charge_type) {
  172. case 'BOOK':
  173. $price = $this->getPrice($book_info);
  174. $is_need_charge = $this->isBookNeedCharge($bid, $price);
  175. foreach ($chapters as $v) {
  176. $v->next_chapter_status = 0;
  177. $v->next_price = 0;
  178. $v->is_need_charge = $v->is_vip ? $is_need_charge : false;
  179. $v->price = $price;
  180. // 限免判断
  181. if ($isFree) {
  182. $v->is_need_charge = false;
  183. $v->price = 0;
  184. }
  185. if ($vip_sequence) {
  186. if ($v->sequence >= $vip_sequence) {
  187. $v->is_vip = 1;
  188. } else {
  189. $v->is_vip = 0;
  190. }
  191. }
  192. //拆章
  193. if ($change_chapter_name) {
  194. $v->name = '第' . $v->sequence . '章';
  195. }
  196. }
  197. break;
  198. default:
  199. foreach ($chapters as $v) {
  200. if ($vip_sequence) {
  201. if ($v->sequence >= $vip_sequence) {
  202. $v->is_vip = 1;
  203. } else {
  204. $v->is_vip = 0;
  205. }
  206. }
  207. // 限免判断
  208. if ($isFree) {
  209. $v->is_need_charge = false;
  210. $v->price = 0;
  211. } else {
  212. $v->price = $v->is_vip ? $this->getPrice($book_info, $v->size) : 0;
  213. $v->is_need_charge = $v->is_vip ? $this->isChapterNeedCharge($bid, $v->id, $v->price) : false;
  214. }
  215. //下一章付费信息
  216. $v->next_chapter_status = 0;
  217. $v->next_price = 0;
  218. if ($v->is_vip) {
  219. $next_chapter_order_status = $this->nextChapterOrderStatus($bid, $v->next_cid);
  220. $v->next_chapter_status = $next_chapter_order_status['next_chapter_status'];
  221. $v->next_price = $next_chapter_order_status['next_price'];
  222. }
  223. //拆章
  224. if ($change_chapter_name) {
  225. $v->name = '第' . $v->sequence . '章';
  226. }
  227. }
  228. break;
  229. }
  230. return $chapters;
  231. }
  232. public function index(Request $request, $bid, $cid)
  233. {
  234. $send_order_id = $request->header('send_order_id', '');
  235. $package = $request->header('x-package', '');
  236. //每次绑定用户和派单的关系
  237. $this->bindSendOrderId($this->uid, $send_order_id);
  238. $oldbid = $bid;
  239. $bid = BookService::decodeBidStatic($bid);
  240. //获取图书信息
  241. $book_info = BookConfigService::getBookById($bid);
  242. if (empty($book_info))
  243. return response()->error('QAPP_SYS_ERROR');
  244. $this->book_info = $book_info;
  245. $book_auth = BookConfigService::bookCopyright($bid, $this->distribution_channel_id);
  246. if ($book_auth == 2) {
  247. return response()->error('QAPP_OFF_SHELF');
  248. }
  249. //yuyuedu、xinghe 快应用这两个cp的书屏蔽下 wutong,wutong2,wutong3下所有内容都不放快应用
  250. if (in_array($book_info->cp_source, getHiddenCp($package)) && $book_auth != 1) {
  251. return response()->error('QAPP_OFF_SHELF');
  252. }
  253. if ($this->distribution_channel_id == 7477 && $bid == 13765) {
  254. $book_info->is_on_shelf = 2;
  255. }
  256. $special = get_special_bid();
  257. if (in_array($this->distribution_channel_id, [9487, 9390]) && in_array($book_info->bid, $special)) {
  258. $book_info->is_on_shelf = 2;
  259. }
  260. if ($bid == 58886) {
  261. $book_info->is_on_shelf = 0;
  262. }
  263. // 华为整改强制下架
  264. if ($this->distribution_channel_id == 13131 && in_array($bid,[13762,65327,66643])){
  265. $device = QappUser::where(['uid' => $this->uid])->where('created_at','>','2023-02-03')->value("device_info");
  266. $device = json_decode($device,true);
  267. $device = strtolower($device['manufacturer'] ?? "");
  268. if ($device == "huawei"){
  269. return response()->error('QAPP_OFF_SHELF');
  270. }
  271. if ($device == "huawei"){
  272. return response()->error('QAPP_OFF_SHELF');
  273. }
  274. $book_info->is_on_shelf = 4;
  275. }
  276. if (!in_array($book_info->is_on_shelf, [1, 2])) {
  277. if ($book_info->is_on_shelf != 4) {
  278. return response()->error('QAPP_OFF_SHELF');
  279. }
  280. //补充操作:如果该用户未订阅该下架的书籍则删除其阅读记录(书架不予显示)
  281. //判断是否属于包年用户
  282. $year_account = YearOrderService::getRecord($this->uid);
  283. if (!$year_account) {
  284. //获取书籍充值类型
  285. $charge_type = $book_info->charge_type;
  286. if ($charge_type == 'BOOK') {
  287. //是否购买过该书,购买过则不删除
  288. $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
  289. } elseif ($charge_type == 'CHAPTER') {
  290. if ($this->distribution_channel_id == 13131 && in_array($bid,[13762,65327,66643])){
  291. $res = ReadRecordService::getReadRecord($this->uid);
  292. if ($res){
  293. $res = array_column($res,null,'bid');
  294. $res = $res[$bid] ?? [];
  295. }
  296. if (is_empty($res)){
  297. return response()->error('QAPP_OFF_SHELF');
  298. }
  299. }
  300. //是否购买过该书章节,购买过则不删除
  301. $res = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
  302. } else {
  303. $res = false;
  304. }
  305. if (!$res) {
  306. ReadRecordService::delReadRecordStatic($this->uid, [$bid]);
  307. return response()->error('QAPP_OFF_SHELF');
  308. }
  309. }
  310. }
  311. //wutong,wutong2,wutong3下所有内容都不放快应用
  312. // if(in_array($book_info->cp_source,['wutong','wutong2','wutong3','youyan2'])){
  313. // return response()->error('QAPP_OFF_SHELF');
  314. // }
  315. $this->book_info = $book_info;
  316. //获取章节信息
  317. $chapter = ChapterService::getChapterNameById($cid, $bid);
  318. if (!$chapter) {
  319. //短推长
  320. $combination_chapter = $this->chapterNotExists($bid, $cid);
  321. if ($combination_chapter) {
  322. $chapter = $combination_chapter;
  323. $bid = $chapter->bid;
  324. $book_info = BookConfigService::getBookById($bid);
  325. $oldbid = \Hashids::encode($bid);
  326. $this->book_info = $book_info;
  327. } else {
  328. return response()->error('QAPP_SYS_ERROR');
  329. }
  330. }
  331. list($is_split, $is_change_chapter_name) = BookService::splitContent($bid);
  332. if ($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name)) {
  333. $chapter->name = '第' . $chapter->sequence . '章';
  334. }
  335. $is_next_day = date('Y-m-d', strtotime($this->user_info->created_at)) == date('Y-m-d', strtotime('-1 days'));
  336. if ($is_next_day) {
  337. $job = new UserRententionJob($this->uid, now(), $this->user_info->created_at);
  338. dispatch($job)->onConnection('rabbitmq')->onQueue('user_rentention_queue');
  339. }
  340. //自定义vip章节
  341. //$vip_sequence = Redis::hget('channel:chapterfee:setting:' . $this->distribution_channel_id, $bid);
  342. $vip_sequence = BookService::getVipSequence($bid, $this->distribution_channel_id, $this->send_order_id);
  343. if ($vip_sequence) {
  344. if ($chapter->sequence >= $vip_sequence) {
  345. $chapter->is_vip = 1;
  346. } else {
  347. $chapter->is_vip = 0;
  348. }
  349. }
  350. if ($chapter->is_vip == 0) {
  351. ReadRecordService::addReadLog($this->uid, [
  352. 'distribution_channel_id' => $this->distribution_channel_id,
  353. 'bid' => $bid,
  354. 'cid' => $chapter->id,
  355. 'uid' => $this->uid,
  356. 'send_order_id' => $this->send_order_id,
  357. 'sequence' => $chapter->sequence,
  358. ]);
  359. ReadRecordService::addReadRecord([
  360. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  361. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  362. ]);
  363. return response()->item(new ChapterTransformer, $this->getChapter($bid, $chapter->id, $chapter));
  364. }
  365. // 书籍是否限免
  366. $free = BookConfigService::judgeBookIsFree($bid);
  367. if ($free) {
  368. ReadRecordService::addReadLog($this->uid, [
  369. 'distribution_channel_id' => $this->distribution_channel_id,
  370. 'bid' => $bid,
  371. 'cid' => $chapter->id,
  372. 'uid' => $this->uid,
  373. 'send_order_id' => $this->send_order_id,
  374. 'sequence' => $chapter->sequence,
  375. ]);
  376. ReadRecordService::addReadRecord([
  377. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  378. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  379. ]);
  380. if ($chapter->is_vip == 1) {
  381. $fee = $this->getPrice($book_info, $chapter->size);
  382. $now = date('Y-m-d');
  383. Redis::hincrby('qapp:book:free:virtual:' . $free->id, $now, $fee);
  384. Redis::sadd('qapp:free:virtual' . $now, $free->id);
  385. Redis::sadd('qapp:free:virtual:uids' . $now . $free->id, $this->uid);
  386. Redis::sadd('qapp:free:virtual:uids' . $free->id, $this->uid);
  387. }
  388. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  389. }
  390. //已经付费
  391. if ($this->getOrderRecord($bid, $cid)) {
  392. ReadRecordService::addReadLog($this->uid, [
  393. 'distribution_channel_id' => $this->distribution_channel_id,
  394. 'bid' => $bid,
  395. 'cid' => $chapter->id,
  396. 'uid' => $this->uid,
  397. 'send_order_id' => $this->send_order_id,
  398. 'sequence' => $chapter->sequence,
  399. ]);
  400. ReadRecordService::addReadRecord([
  401. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  402. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  403. ]);
  404. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  405. }
  406. //未付费 要提醒
  407. $user_info = $this->user_info;
  408. //未付费 余额不足
  409. $fee = $this->getPrice($book_info, $chapter->size);
  410. $data = [
  411. 'book_id' => $oldbid,
  412. 'book_name' => $book_info->book_name,
  413. 'chapter_name' => $chapter->name,
  414. 'chapter_id' => $cid,
  415. 'pay_type' => $book_info->charge_type,
  416. 'fee' => $fee,
  417. 'user_balance' => $user_info->balance,
  418. 'product_id' => $book_info->product_id,
  419. 'uid' => $this->uid,
  420. 'distribution_channel_id' => $this->distribution_channel_id,
  421. 'is_discount' => 0,
  422. 'discount_fee' => '',
  423. 'discount' => ''
  424. ];
  425. if ($user_info['balance'] < $fee) {
  426. if ($book_info->charge_type == 'BOOK') {
  427. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  428. } elseif ($book_info->charge_type == 'CHAPTER') {
  429. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  430. } else {
  431. return response()->error('QAPP_SYS_ERROR');
  432. }
  433. }
  434. if (!$this->send_order_id) {
  435. if ($book_info->charge_type == 'BOOK') {
  436. return response()->error('QAPP_BOOK_BUY', $data);
  437. }/*else{
  438. return response()->error('QAPP_CHAPTER_BUY', $data);
  439. }*/
  440. }
  441. //付费 不提醒
  442. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, 0)) {
  443. UserTaskService::addUserTaskQueue($this->uid, BaseTask::read, UserTaskService::judge_trigger);
  444. ReadRecordService::addReadLog($this->uid, [
  445. 'distribution_channel_id' => $this->distribution_channel_id,
  446. 'bid' => $bid,
  447. 'cid' => $chapter->id,
  448. 'uid' => $this->uid,
  449. 'send_order_id' => $this->send_order_id,
  450. 'sequence' => $chapter->sequence,
  451. ]);
  452. ReadRecordService::addReadRecord([
  453. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  454. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  455. ]);
  456. //限免统计
  457. $free_book = BookConfigService::getByBidNoFilter($bid);
  458. if ($free_book) {
  459. if (strtotime($free_book->end_time) + 7 * 86400 >= strtotime(date('Y-m-d'))) {
  460. if (Redis::Sismember('qapp:free:virtual:uids' . $free_book->id, $this->uid)) {
  461. $now = date('Y-m-d');
  462. Redis::hincrby('qapp:book:free:actuality:' . $free_book->id, $now, $fee);
  463. Redis::sadd('qapp:free:actuality' . $now, $free_book->id);
  464. Redis::sadd('qapp:free:actuality:uids' . $now . $free_book->id, $this->uid);
  465. }
  466. }
  467. }
  468. if ($this->uid == 247081369) {
  469. $item = itemTransform(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  470. myLog('xueqi')->info($item);
  471. }
  472. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  473. } else {
  474. if ($book_info->charge_type == 'BOOK') {
  475. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  476. } elseif ($book_info->charge_type == 'CHAPTER') {
  477. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  478. } else {
  479. return response()->error('QAPP_SYS_ERROR');
  480. }
  481. }
  482. }
  483. public function pay(Request $request, $bid, $cid)
  484. {
  485. $remind = (int)$request->input('remind');
  486. $oldbid = $bid;
  487. $bid = BookService::decodeBidStatic($bid);
  488. $book_info = BookConfigService::getBookById($bid);;
  489. if (empty($book_info)) response()->error('QAPP_SYS_ERROR');
  490. $this->book_info = $book_info;
  491. if ($this->distribution_channel_id == 7477 && $bid == 13765) {
  492. $book_info->is_on_shelf = 2;
  493. }
  494. if ($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3) {
  495. if (!$this->isBookOrdered($bid)) {
  496. response()->error('QAPP_OFF_SHELF');
  497. }
  498. }
  499. //获取章节
  500. $chapter = ChapterService::getChapterNameById($cid, $bid);
  501. if (!$chapter) {
  502. $combination_chapter = $this->chapterNotExists($bid, $cid);
  503. if ($combination_chapter) {
  504. $chapter = $combination_chapter;
  505. $bid = $chapter->bid;
  506. $book_info = BookConfigService::getBookById($bid);
  507. $oldbid = \Hashids::encode($bid);
  508. $this->book_info = $book_info;
  509. } else {
  510. return response()->error('QAPP_SYS_ERROR');
  511. }
  512. }
  513. if ($this->getOrderRecord($bid, $cid)) {
  514. ReadRecordService::addReadLog($this->uid, [
  515. 'distribution_channel_id' => $this->distribution_channel_id,
  516. 'bid' => $bid,
  517. 'cid' => $chapter->id,
  518. 'uid' => $this->uid,
  519. 'send_order_id' => $this->send_order_id,
  520. 'sequence' => $chapter->sequence,
  521. ]);
  522. ReadRecordService::addReadRecord([
  523. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  524. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  525. ]);
  526. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  527. }
  528. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, $remind)) {
  529. UserTaskService::addUserTaskQueue($this->uid, BaseTask::read, UserTaskService::judge_trigger);
  530. ReadRecordService::addReadLog($this->uid, [
  531. 'distribution_channel_id' => $this->distribution_channel_id,
  532. 'bid' => $bid,
  533. 'cid' => $chapter->id,
  534. 'uid' => $this->uid,
  535. 'send_order_id' => $this->send_order_id,
  536. 'sequence' => $chapter->sequence,
  537. ]);
  538. ReadRecordService::addReadRecord([
  539. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  540. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  541. ]);
  542. $free_book = BookConfigService::getByBidNoFilter($bid);
  543. if ($free_book) {
  544. if (strtotime($free_book->end_time) + 7 * 86400 >= strtotime(date('Y-m-d'))) {
  545. if (Redis::Sismember('qapp:free:virtual:uids' . $free_book->id, $this->uid)) {
  546. $now = date('Y-m-d');
  547. $fee = $this->getPrice($book_info, $chapter->size);
  548. Redis::hincrby('qapp:book:free:actuality:' . $free_book->id, $now, $fee);
  549. Redis::sadd('qapp:free:actuality' . $now, $free_book->id);
  550. Redis::sadd('qapp:free:actuality:uids' . $now . $free_book->id, $this->uid);
  551. }
  552. }
  553. }
  554. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  555. } else {
  556. $fee = $this->getPrice($book_info, $chapter->size);
  557. $data = [
  558. 'book_id' => $oldbid,
  559. 'book_name' => $book_info->book_name,
  560. 'chapter_name' => $chapter->name,
  561. 'chapter_id' => $cid,
  562. 'pay_type' => $book_info->charge_type,
  563. 'fee' => $fee,
  564. 'user_balance' => $this->user_info['balance'],
  565. 'product_id' => $book_info->product_id,
  566. 'uid' => $this->uid,
  567. 'distribution_channel_id' => $this->distribution_channel_id,
  568. 'is_discount' => 0,
  569. 'discount_fee' => '',
  570. 'discount' => ''
  571. ];
  572. if ($book_info->charge_type == 'BOOK') {
  573. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  574. } elseif ($book_info->charge_type == 'CHAPTER') {
  575. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  576. } else {
  577. return response()->error('QAPP_SYS_ERROR');
  578. }
  579. }
  580. }
  581. /**
  582. * 余额支付
  583. * @param $book_info
  584. * @param $chapter_id
  585. * @param $chapter_size
  586. * @return bool
  587. */
  588. protected function balancePay($book_info, $chapter_id, $chapter_size, $chapter_name, $is_remind)
  589. {
  590. $fee = $this->getPrice($book_info, $chapter_size);
  591. if ((int)$this->user_info['balance'] >= $fee) {
  592. if ($this->bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)) {
  593. return true;
  594. }
  595. return false;
  596. } else {
  597. return false;
  598. }
  599. }
  600. /**
  601. * 获取章节内容
  602. * @param $bid
  603. * @param $cid
  604. * @return bool|mixed
  605. */
  606. protected function getChapter($bid, $cid, $chapter)
  607. {
  608. $chapter_content = ChapterService::getChapter($bid, $cid);
  609. if (!$chapter_content) return false;
  610. $chapter->content = trim(str_replace($chapter_content->name, '', $chapter_content->content));
  611. // 格式特殊处理
  612. $qian = array(" ", " ", "\t");
  613. $hou = array("", "", "");
  614. // 去掉所有空格
  615. $chapter->content = str_replace($qian, $hou, $chapter->content);
  616. // 2换行变1换行
  617. $chapter->content = str_replace("\n\n", "\n", $chapter->content);
  618. $chapter->content = str_replace("\r\n\r\n", "\r\n", $chapter->content);
  619. // \Log::info('getChapter_chapter:'.$bid.' cid:'.$cid);
  620. // \Log::info($chapter->content);
  621. //统计点击率
  622. $key = 'book_click_num_bid_' . $bid;
  623. $field = date('Y-m-d');
  624. $old = Redis::hget($key, $field);
  625. if (!$old) $old = 0;
  626. Redis::hset($key, $field, $old + 1);
  627. [$force_add_desk_type,$is_need_query_send_order] = $this->addDesktopType($bid, $chapter->sequence);
  628. $chapter->force_add_desk_type = $force_add_desk_type;
  629. $force_add_work_wechat_type = 0;
  630. $force_add_work_wechat_url = "";
  631. if($is_need_query_send_order){
  632. [$force_add_work_wechat_type, $force_add_work_wechat_url] = $this->addWorkWechatType($chapter->sequence);
  633. }
  634. $chapter->force_add_work_wechat_type = $force_add_work_wechat_type;
  635. $chapter->force_add_work_wechat_url = $force_add_work_wechat_url;
  636. //统计
  637. $this->stats();
  638. $next_chapter_order_status = $this->nextChapterOrderStatus($bid, $chapter->next_cid);
  639. $chapter->next_chapter_status = $next_chapter_order_status['next_chapter_status'];
  640. $chapter->next_price = $next_chapter_order_status['next_price'];
  641. $chapter->charge_type = $this->book_info->charge_type;
  642. $this->userBookCombination($chapter);
  643. return $chapter;
  644. }
  645. private function nextChapterOrderStatus($bid, $cid)
  646. {
  647. $chapter = ChapterService::getChapterNameById($cid, $bid);
  648. if (!$chapter || $chapter->is_vip == 0 || $this->book_info->charge_type == 'BOOK') {
  649. return ['next_chapter_status' => 0, 'next_price' => 0];
  650. }
  651. $is_paid = $this->getOrderRecord($bid, $cid);
  652. if ($is_paid) {
  653. return ['next_chapter_status' => 1, 'next_price' => 0];
  654. }
  655. $fee = $this->getPrice($this->book_info, $chapter->size);
  656. return ['next_chapter_status' => 2, 'next_price' => $fee];
  657. }
  658. //短续长
  659. private function userBookCombination($chapter)
  660. {
  661. if ($chapter->prev_cid && $chapter->next_cid) {
  662. return;
  663. }
  664. if ($chapter->next_cid == 0 && $this->book_info->charge_type == 'BOOK') {
  665. $bid = UserBookCombinationConfigService::selectAndSave($this->uid, $this->book_info->bid);
  666. if ($bid) {
  667. $bookInfo = BookConfigService::getBookById($bid);
  668. $chapter->next_cid = $bookInfo->first_cid;
  669. }
  670. }
  671. if ($chapter->prev_cid == 0 && $this->book_info->charge_type == 'CHAPTER') {
  672. $bid = UserBookCombinationConfigService::getShortBookFromLongBid($this->uid, $this->book_info->bid);
  673. if ($bid) {
  674. $bookInfo = BookConfigService::getBookById($bid);
  675. $chapter->prev_cid = $bookInfo->last_cid;
  676. }
  677. }
  678. }
  679. private function chapterNotExists($bid, $cid)
  680. {
  681. //1.全局图书组合配置
  682. $combination = BookConfigService::getCombinationInfo($bid);
  683. if ($combination) {
  684. $chapter = ChapterService::getChapterNameByIdNoCheck($cid);
  685. if ($chapter) {
  686. return $chapter;
  687. }
  688. return false;
  689. }
  690. //2.用户图书组合配置
  691. if ($this->book_info->charge_type == 'CHAPTER') {
  692. $user_combination = UserBookCombinationConfigService::getShortBookFromLongBook($this->uid, $bid);
  693. } else {
  694. $user_combination = UserBookCombinationConfigService::getLongBookFromShortBook($this->uid, $bid);
  695. }
  696. if ($user_combination) {
  697. $chapter = ChapterService::getChapterNameByIdNoCheck($cid);
  698. if ($chapter) {
  699. return $chapter;
  700. }
  701. return false;
  702. }
  703. return false;
  704. }
  705. /**
  706. * 添加订购记录
  707. * @param $book_info
  708. * @param $chapter_id
  709. * @param $fee
  710. * @return bool
  711. */
  712. protected function bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)
  713. {
  714. if ($book_info['charge_type'] == 'BOOK') {
  715. $data = [
  716. 'uid' => $this->uid,
  717. 'fee' => $fee,
  718. 'u' => $this->send_order_id,
  719. 'distribution_channel_id' => $this->distribution_channel_id,
  720. 'bid' => $book_info->bid,
  721. 'book_name' => $book_info->book_name,
  722. 'send_order_id' => $this->send_order_id,
  723. ];
  724. return BookOrderService::addOrderRecodeAndDecrUserBalance($data, $this->uid);
  725. } else {
  726. $data = [
  727. 'uid' => $this->uid,
  728. 'fee' => $fee,
  729. 'cid' => $chapter_id,
  730. 'bid' => $book_info->bid,
  731. 'distribution_channel_id' => $this->distribution_channel_id,
  732. 'book_name' => $book_info->book_name,
  733. 'chapter_name' => $chapter_name,
  734. 'send_order_id' => $this->send_order_id,
  735. 'is_remind' => $is_remind
  736. ];
  737. if ($is_remind) {
  738. $this->addOrderRemind($book_info->bid);
  739. }
  740. return ChapterOrderService::addOrderAndDecrUserBalance($data, $this->uid);
  741. }
  742. }
  743. protected function addOrderRemind($bid)
  744. {
  745. if (ChapterReminderService::checkIsNoReminder($this->uid, $bid)) {
  746. return true;
  747. } else {
  748. ChapterReminderService::add($this->uid, $bid);
  749. return true;
  750. }
  751. }
  752. /**
  753. * 是否订购提醒
  754. * @param $chapter_id
  755. * @return bool
  756. */
  757. protected function isOrderRemind($bid)
  758. {
  759. $is_no_reminder = ChapterReminderService::checkIsNoReminder($this->uid, $bid) ? 1 : 0;
  760. return $is_no_reminder == 0;
  761. }
  762. /**
  763. * 用户是否关注
  764. * @param $uid
  765. * @return bool
  766. */
  767. protected function getSubscribe()
  768. {
  769. $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  770. if ($res) return true;
  771. return false;
  772. }
  773. /**
  774. * 获取订购记录
  775. * @param $book_info
  776. * @param $chapter_id
  777. * @return bool
  778. */
  779. protected function getOrderRecord($bid, $chapter_id)
  780. {
  781. //包年记录
  782. $uid = $this->uid;
  783. $res = YearOrderService::getRecord($uid);
  784. if ($res) return true;
  785. $res = null;
  786. //单本订购记录
  787. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  788. if ($res) return true;
  789. $res = null;
  790. //章节订购记录
  791. $chapterOrder = new ChapterOrderService();
  792. if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
  793. return false;
  794. }
  795. /**
  796. * 计算价格
  797. * @param $book_info
  798. * @param $chapter_size
  799. * @return float
  800. */
  801. private function getPrice($book_info, $chapter_size = 0)
  802. {
  803. if ($book_info->charge_type == 'BOOK') {
  804. if (BookOrderService::isHasBookOrder($this->uid)) {
  805. $this->is_first_book_order = 0;
  806. return 1399;
  807. } else {
  808. $this->is_first_book_order = 1;
  809. return 899;
  810. }
  811. } else {
  812. // 获取投放后台账号,
  813. $account = '';
  814. $account_send_order = $this->getNowSendOrderInfo();
  815. if ($account_send_order) {
  816. $account = isset($account_send_order['account']) ? $account_send_order['account'] : '';
  817. }
  818. $fee = BookService::getPrice($book_info, $this->distribution_channel_id, $chapter_size, $account);
  819. return $fee;
  820. }
  821. }
  822. /**
  823. * 计算价格
  824. * @param $book_info
  825. * @param $chapter_size
  826. * @return float
  827. */
  828. private function getPriceNew($book_info, $chapter_size = 0, $account = "")
  829. {
  830. if ($book_info->charge_type == 'BOOK') {
  831. if (BookOrderService::isHasBookOrder($this->uid)) {
  832. $this->is_first_book_order = 0;
  833. return 1399;
  834. } else {
  835. $this->is_first_book_order = 1;
  836. return 899;
  837. }
  838. } else {
  839. return BookService::getPrice($book_info, $this->distribution_channel_id, $chapter_size, $account);
  840. }
  841. }
  842. /**
  843. * 获取投放后台账号,
  844. * name: getAccount
  845. * @return mixed|string
  846. * date 2022/10/20 11:29
  847. */
  848. protected function getAccount()
  849. {
  850. $account = '';
  851. $account_send_order = $this->getNowSendOrderInfo();
  852. if ($account_send_order) {
  853. $account = isset($account_send_order['account']) ? $account_send_order['account'] : '';
  854. }
  855. return $account;
  856. }
  857. /**
  858. * 用户添加标签
  859. * @param $book_info
  860. */
  861. protected function addTag($book_info)
  862. {
  863. if (!UserDeepReadTagService::isAddTag($this->uid, $book_info->bid)) {
  864. try {
  865. UserDeepReadTagService::addTag([
  866. 'uid' => $this->uid,
  867. 'bid' => $book_info->bid,
  868. 'book_name' => $book_info->book_name,
  869. 'category_id' => $book_info->category_id,
  870. 'category_name' => $book_info->category_name,
  871. 'sex_preference' => $book_info->channel_name ? $book_info->channel_name : '',
  872. 'distribution_channel_id' => $this->distribution_channel_id ? $this->distribution_channel_id : '0',
  873. 'send_order_id' => $this->send_order_id,
  874. ]);
  875. } catch (\Exception $e) {
  876. }
  877. }
  878. }
  879. protected function isBookOrdered($bid)
  880. {
  881. $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
  882. if ($chapter_order) return true;
  883. $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
  884. if ($res) return true;
  885. return false;
  886. }
  887. /**
  888. * 判断是否需要充值
  889. */
  890. private function isBookNeedCharge(int $bid, float $price)
  891. {
  892. $book_order = $this->getOrderRecord($bid, 0);
  893. if ($book_order) {
  894. return false;
  895. } else {
  896. $user_info = $this->user_info;
  897. return $user_info['balance'] < $price;
  898. }
  899. }
  900. /**
  901. * 判断章节是否需要充值
  902. */
  903. private function isChapterNeedCharge(int $bid, int $cid, float $price)
  904. {
  905. $book_order = $this->getOrderRecord($bid, $cid);
  906. if ($book_order) {
  907. return false;
  908. } else {
  909. $user_info = $this->user_info;
  910. return $user_info['balance'] < $price;
  911. }
  912. }
  913. private function stats()
  914. {
  915. //阅读器统计
  916. WapVisitStatService::recordReaderUvAndPv($this->uid, $this->distribution_channel_id);
  917. }
  918. //加桌类型
  919. private function addDesktopType($bid, $sequence)
  920. {
  921. $deault_force_add_desk_type = 0;
  922. $send_order_id = $this->GetBindSendOrderId($this->uid);
  923. $is_need_query_order = 0;
  924. if ($send_order_id) {
  925. $send_order_info = SendOrderService::getById($send_order_id);
  926. if (!$send_order_info) return [$deault_force_add_desk_type,$is_need_query_order];
  927. if ($send_order_info->book_id == $bid) {
  928. $is_need_query_order = 1;
  929. // 派单书籍和观看书籍一致,并设置了强加桌,判断当前章节和设置的强加桌章节
  930. if ($send_order_info->force_add_desk_type == 1 && $send_order_info->force_add_desk_seq) {
  931. //在设置的强加桌章节前一章开始
  932. if ($sequence >= ($send_order_info->force_add_desk_seq - 1)) {
  933. $force_add_desk_type = $send_order_info->force_add_desk_type;
  934. return [$force_add_desk_type,$is_need_query_order];
  935. }
  936. }
  937. if ($send_order_info->force_add_desk_type == 2) {
  938. if ($sequence >= $this->book_info->force_subscribe_chapter_seq && $sequence <= $this->book_info->force_subscribe_chapter_seq + 3) {
  939. $force_add_desk_type = $send_order_info->force_add_desk_type;
  940. return [$force_add_desk_type,$is_need_query_order];
  941. }
  942. }
  943. if ($send_order_info->force_add_desk_type == 3) {
  944. //弱加桌+强加桌 ,即强加桌章节之前的章节均弱加桌,之后的章节显示强加桌:
  945. $need_sequence = $send_order_info->force_add_desk_seq;
  946. if (!$need_sequence) {
  947. $need_sequence = $this->book_info->force_subscribe_chapter_seq;
  948. }
  949. if ($sequence >= ($need_sequence - 1)) {
  950. //之后的章节显示强加桌
  951. return [1,$is_need_query_order];
  952. } else {
  953. ////强加桌章节之前的章节均弱加桌
  954. return [2,$is_need_query_order];
  955. }
  956. }
  957. return [$deault_force_add_desk_type,$is_need_query_order];
  958. }
  959. }
  960. //无派单,或者派单书籍与 此次书籍不一致,直接使用 原书籍的默认强关章节
  961. $book_info = BookConfigService::getBookById($bid);
  962. if ($book_info && $book_info->force_subscribe_chapter_seq) {
  963. if ($sequence >= ($book_info->force_subscribe_chapter_seq - 1)) {
  964. return [2,$is_need_query_order];
  965. }
  966. }
  967. return [$deault_force_add_desk_type,$is_need_query_order];
  968. }
  969. private function addWorkWechatType($sequence)
  970. {
  971. $deault_force_add_desk_type = 0;
  972. $work_wechat_url = "";
  973. $send_order_id = $this->GetBindSendOrderId($this->uid);
  974. if ($send_order_id) {
  975. $send_order_info = QappSendOrder::getSendOrderById($send_order_id);
  976. if (!$send_order_info) return [$deault_force_add_desk_type, $work_wechat_url];
  977. if($send_order_info['force_add_work_wechat_status'] == 1 && $send_order_info['force_add_work_wechat_seq'] <= ($sequence+1)){
  978. $deault_force_add_desk_type =$send_order_info['force_add_work_wechat_type'];
  979. $work_wechat_url =$send_order_info['force_add_work_wechat_url'];
  980. }
  981. }
  982. return [$deault_force_add_desk_type, $work_wechat_url];
  983. }
  984. /**
  985. * [bindSendOrderId description]
  986. * @param [type] $uid [description]
  987. * @param [type] $send_order_id [description]
  988. * @return [type] [description]
  989. */
  990. public function bindSendOrderId($uid, $send_order_id)
  991. {
  992. if ($send_order_id) {
  993. $res = Redis::hset('book_read_chapter:' . $uid, 'send_order_id', $send_order_id);
  994. }
  995. }
  996. /**
  997. * [bindSendOrderId description]
  998. * @param [type] $uid [description]
  999. * @param [type] $send_order_id [description]
  1000. * @return [type] [description]
  1001. */
  1002. public function GetBindSendOrderId($uid)
  1003. {
  1004. try {
  1005. $send_order_id = Redis::hget('book_read_chapter:' . $uid, 'send_order_id');
  1006. if ($send_order_id)
  1007. return (int)$send_order_id;
  1008. } catch (\Exception $e) {
  1009. }
  1010. }
  1011. private function getChapterIds($chapters): array
  1012. {
  1013. $list = [];
  1014. if ($chapters) {
  1015. foreach ($chapters as $v) {
  1016. $list[] = $v->id;
  1017. }
  1018. }
  1019. return $list;
  1020. }
  1021. private function getHandelData(int $bid, array $chapterIds): array
  1022. {
  1023. $uid = $this->uid;
  1024. $res = YearOrderService::getRecord($uid);
  1025. if ($res) {
  1026. return $handle = ['check' => 0, 'paycid' => []];
  1027. }
  1028. $res = null;
  1029. //单本订购记录
  1030. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  1031. if ($res) {
  1032. return $handle = ['check' => 0, 'paycid' => []];
  1033. }
  1034. //章节订购记录
  1035. $chapterOrder = new ChapterOrderService();
  1036. $res = $chapterOrder->getOrdersByChapterIds($uid, $bid, $chapterIds);
  1037. return $handle = ['check' => 1, 'paycid' => $res];
  1038. }
  1039. /**
  1040. * 判断是否需要充值
  1041. * name: isChapterNeedChargeNew
  1042. * @param $cid
  1043. * @param $rules
  1044. * @return bool
  1045. * date 2022/10/20 16:08
  1046. */
  1047. private function isChapterNeedChargeNew($cid, $rules, $price = 0): bool
  1048. {
  1049. if ($rules['check'] != 1) {
  1050. return false;
  1051. }
  1052. if (empty($rules['paycid']) || !in_array($cid, $rules['paycid'])) {
  1053. $user_info = $this->user_info;
  1054. return $user_info['balance'] < $price;
  1055. } else {
  1056. return false;
  1057. }
  1058. }
  1059. /*****
  1060. * 是否订阅
  1061. * name: isSubscribe
  1062. * @param $cid
  1063. * @param $rules
  1064. * @return int
  1065. * date 2022/11/02 17:19
  1066. */
  1067. private function isSubscribe($cid, $rules): int
  1068. {
  1069. if ($rules['check'] != 1) {
  1070. return 1;
  1071. }
  1072. if (empty($rules['paycid']) || !in_array($cid, $rules['paycid'])) {
  1073. return 2;
  1074. } else {
  1075. return 1;
  1076. }
  1077. }
  1078. private function getWorkWechatInfo($bid)
  1079. {
  1080. $info = ['force_add_work_wechat_type' => 0,'force_add_work_wechat_url' => "",'force_add_work_wechat_seq' => 0];
  1081. $send_order_id = $this->GetBindSendOrderId($this->uid);
  1082. if ($send_order_id) {
  1083. $send_order_info = QappSendOrder::getSendOrderById($send_order_id);
  1084. if (!$send_order_info) return $info;
  1085. $send_order_bid = SendOrder::where(['id' => $send_order_id])->value('book_id');
  1086. if($send_order_info['force_add_work_wechat_status'] == 1 && $send_order_bid == $bid){
  1087. $info['force_add_work_wechat_type'] = $send_order_info['force_add_work_wechat_type'];
  1088. $info['force_add_work_wechat_url'] = $send_order_info['force_add_work_wechat_url'];
  1089. $info['force_add_work_wechat_seq'] = $send_order_info['force_add_work_wechat_seq'];
  1090. }else{
  1091. return $info;
  1092. }
  1093. }
  1094. return $info;
  1095. }
  1096. }