ChapterController.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  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])->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. $book_info->is_on_shelf = 4;
  272. }
  273. if (!in_array($book_info->is_on_shelf, [1, 2])) {
  274. if ($book_info->is_on_shelf != 4) {
  275. return response()->error('QAPP_OFF_SHELF');
  276. }
  277. //补充操作:如果该用户未订阅该下架的书籍则删除其阅读记录(书架不予显示)
  278. //判断是否属于包年用户
  279. $year_account = YearOrderService::getRecord($this->uid);
  280. if (!$year_account) {
  281. //获取书籍充值类型
  282. $charge_type = $book_info->charge_type;
  283. if ($charge_type == 'BOOK') {
  284. //是否购买过该书,购买过则不删除
  285. $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
  286. } elseif ($charge_type == 'CHAPTER') {
  287. if ($this->distribution_channel_id == 13131 && in_array($bid,[13762,65327,66643])){
  288. $res = ReadRecordService::getReadRecord($this->uid);
  289. if ($res){
  290. $res = array_column($res,null,'bid');
  291. $res = $res[$bid] ?? [];
  292. }
  293. if (is_empty($res)){
  294. return response()->error('QAPP_OFF_SHELF');
  295. }
  296. }
  297. //是否购买过该书章节,购买过则不删除
  298. $res = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
  299. } else {
  300. $res = false;
  301. }
  302. if (!$res) {
  303. ReadRecordService::delReadRecordStatic($this->uid, [$bid]);
  304. return response()->error('QAPP_OFF_SHELF');
  305. }
  306. }
  307. }
  308. //wutong,wutong2,wutong3下所有内容都不放快应用
  309. // if(in_array($book_info->cp_source,['wutong','wutong2','wutong3','youyan2'])){
  310. // return response()->error('QAPP_OFF_SHELF');
  311. // }
  312. $this->book_info = $book_info;
  313. //获取章节信息
  314. $chapter = ChapterService::getChapterNameById($cid, $bid);
  315. if (!$chapter) {
  316. //短推长
  317. $combination_chapter = $this->chapterNotExists($bid, $cid);
  318. if ($combination_chapter) {
  319. $chapter = $combination_chapter;
  320. $bid = $chapter->bid;
  321. $book_info = BookConfigService::getBookById($bid);
  322. $oldbid = \Hashids::encode($bid);
  323. $this->book_info = $book_info;
  324. } else {
  325. return response()->error('QAPP_SYS_ERROR');
  326. }
  327. }
  328. list($is_split, $is_change_chapter_name) = BookService::splitContent($bid);
  329. if ($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name)) {
  330. $chapter->name = '第' . $chapter->sequence . '章';
  331. }
  332. $is_next_day = date('Y-m-d', strtotime($this->user_info->created_at)) == date('Y-m-d', strtotime('-1 days'));
  333. if ($is_next_day) {
  334. $job = new UserRententionJob($this->uid, now(), $this->user_info->created_at);
  335. dispatch($job)->onConnection('rabbitmq')->onQueue('user_rentention_queue');
  336. }
  337. //自定义vip章节
  338. //$vip_sequence = Redis::hget('channel:chapterfee:setting:' . $this->distribution_channel_id, $bid);
  339. $vip_sequence = BookService::getVipSequence($bid, $this->distribution_channel_id, $this->send_order_id);
  340. if ($vip_sequence) {
  341. if ($chapter->sequence >= $vip_sequence) {
  342. $chapter->is_vip = 1;
  343. } else {
  344. $chapter->is_vip = 0;
  345. }
  346. }
  347. if ($chapter->is_vip == 0) {
  348. ReadRecordService::addReadLog($this->uid, [
  349. 'distribution_channel_id' => $this->distribution_channel_id,
  350. 'bid' => $bid,
  351. 'cid' => $chapter->id,
  352. 'uid' => $this->uid,
  353. 'send_order_id' => $this->send_order_id,
  354. 'sequence' => $chapter->sequence,
  355. ]);
  356. ReadRecordService::addReadRecord([
  357. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  358. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  359. ]);
  360. return response()->item(new ChapterTransformer, $this->getChapter($bid, $chapter->id, $chapter));
  361. }
  362. // 书籍是否限免
  363. $free = BookConfigService::judgeBookIsFree($bid);
  364. if ($free) {
  365. ReadRecordService::addReadLog($this->uid, [
  366. 'distribution_channel_id' => $this->distribution_channel_id,
  367. 'bid' => $bid,
  368. 'cid' => $chapter->id,
  369. 'uid' => $this->uid,
  370. 'send_order_id' => $this->send_order_id,
  371. 'sequence' => $chapter->sequence,
  372. ]);
  373. ReadRecordService::addReadRecord([
  374. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  375. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  376. ]);
  377. if ($chapter->is_vip == 1) {
  378. $fee = $this->getPrice($book_info, $chapter->size);
  379. $now = date('Y-m-d');
  380. Redis::hincrby('qapp:book:free:virtual:' . $free->id, $now, $fee);
  381. Redis::sadd('qapp:free:virtual' . $now, $free->id);
  382. Redis::sadd('qapp:free:virtual:uids' . $now . $free->id, $this->uid);
  383. Redis::sadd('qapp:free:virtual:uids' . $free->id, $this->uid);
  384. }
  385. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  386. }
  387. //已经付费
  388. if ($this->getOrderRecord($bid, $cid)) {
  389. ReadRecordService::addReadLog($this->uid, [
  390. 'distribution_channel_id' => $this->distribution_channel_id,
  391. 'bid' => $bid,
  392. 'cid' => $chapter->id,
  393. 'uid' => $this->uid,
  394. 'send_order_id' => $this->send_order_id,
  395. 'sequence' => $chapter->sequence,
  396. ]);
  397. ReadRecordService::addReadRecord([
  398. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  399. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  400. ]);
  401. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  402. }
  403. //未付费 要提醒
  404. $user_info = $this->user_info;
  405. //未付费 余额不足
  406. $fee = $this->getPrice($book_info, $chapter->size);
  407. $data = [
  408. 'book_id' => $oldbid,
  409. 'book_name' => $book_info->book_name,
  410. 'chapter_name' => $chapter->name,
  411. 'chapter_id' => $cid,
  412. 'pay_type' => $book_info->charge_type,
  413. 'fee' => $fee,
  414. 'user_balance' => $user_info->balance,
  415. 'product_id' => $book_info->product_id,
  416. 'uid' => $this->uid,
  417. 'distribution_channel_id' => $this->distribution_channel_id,
  418. 'is_discount' => 0,
  419. 'discount_fee' => '',
  420. 'discount' => ''
  421. ];
  422. if ($user_info['balance'] < $fee) {
  423. if ($book_info->charge_type == 'BOOK') {
  424. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  425. } elseif ($book_info->charge_type == 'CHAPTER') {
  426. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  427. } else {
  428. return response()->error('QAPP_SYS_ERROR');
  429. }
  430. }
  431. if (!$this->send_order_id) {
  432. if ($book_info->charge_type == 'BOOK') {
  433. return response()->error('QAPP_BOOK_BUY', $data);
  434. }/*else{
  435. return response()->error('QAPP_CHAPTER_BUY', $data);
  436. }*/
  437. }
  438. //付费 不提醒
  439. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, 0)) {
  440. UserTaskService::addUserTaskQueue($this->uid, BaseTask::read, UserTaskService::judge_trigger);
  441. ReadRecordService::addReadLog($this->uid, [
  442. 'distribution_channel_id' => $this->distribution_channel_id,
  443. 'bid' => $bid,
  444. 'cid' => $chapter->id,
  445. 'uid' => $this->uid,
  446. 'send_order_id' => $this->send_order_id,
  447. 'sequence' => $chapter->sequence,
  448. ]);
  449. ReadRecordService::addReadRecord([
  450. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  451. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  452. ]);
  453. //限免统计
  454. $free_book = BookConfigService::getByBidNoFilter($bid);
  455. if ($free_book) {
  456. if (strtotime($free_book->end_time) + 7 * 86400 >= strtotime(date('Y-m-d'))) {
  457. if (Redis::Sismember('qapp:free:virtual:uids' . $free_book->id, $this->uid)) {
  458. $now = date('Y-m-d');
  459. Redis::hincrby('qapp:book:free:actuality:' . $free_book->id, $now, $fee);
  460. Redis::sadd('qapp:free:actuality' . $now, $free_book->id);
  461. Redis::sadd('qapp:free:actuality:uids' . $now . $free_book->id, $this->uid);
  462. }
  463. }
  464. }
  465. if ($this->uid == 247081369) {
  466. $item = itemTransform(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  467. myLog('xueqi')->info($item);
  468. }
  469. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  470. } else {
  471. if ($book_info->charge_type == 'BOOK') {
  472. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  473. } elseif ($book_info->charge_type == 'CHAPTER') {
  474. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  475. } else {
  476. return response()->error('QAPP_SYS_ERROR');
  477. }
  478. }
  479. }
  480. public function pay(Request $request, $bid, $cid)
  481. {
  482. $remind = (int)$request->input('remind');
  483. $oldbid = $bid;
  484. $bid = BookService::decodeBidStatic($bid);
  485. $book_info = BookConfigService::getBookById($bid);;
  486. if (empty($book_info)) response()->error('QAPP_SYS_ERROR');
  487. $this->book_info = $book_info;
  488. if ($this->distribution_channel_id == 7477 && $bid == 13765) {
  489. $book_info->is_on_shelf = 2;
  490. }
  491. if ($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3) {
  492. if (!$this->isBookOrdered($bid)) {
  493. response()->error('QAPP_OFF_SHELF');
  494. }
  495. }
  496. //获取章节
  497. $chapter = ChapterService::getChapterNameById($cid, $bid);
  498. if (!$chapter) {
  499. $combination_chapter = $this->chapterNotExists($bid, $cid);
  500. if ($combination_chapter) {
  501. $chapter = $combination_chapter;
  502. $bid = $chapter->bid;
  503. $book_info = BookConfigService::getBookById($bid);
  504. $oldbid = \Hashids::encode($bid);
  505. $this->book_info = $book_info;
  506. } else {
  507. return response()->error('QAPP_SYS_ERROR');
  508. }
  509. }
  510. if ($this->getOrderRecord($bid, $cid)) {
  511. ReadRecordService::addReadLog($this->uid, [
  512. 'distribution_channel_id' => $this->distribution_channel_id,
  513. 'bid' => $bid,
  514. 'cid' => $chapter->id,
  515. 'uid' => $this->uid,
  516. 'send_order_id' => $this->send_order_id,
  517. 'sequence' => $chapter->sequence,
  518. ]);
  519. ReadRecordService::addReadRecord([
  520. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  521. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  522. ]);
  523. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  524. }
  525. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, $remind)) {
  526. UserTaskService::addUserTaskQueue($this->uid, BaseTask::read, UserTaskService::judge_trigger);
  527. ReadRecordService::addReadLog($this->uid, [
  528. 'distribution_channel_id' => $this->distribution_channel_id,
  529. 'bid' => $bid,
  530. 'cid' => $chapter->id,
  531. 'uid' => $this->uid,
  532. 'send_order_id' => $this->send_order_id,
  533. 'sequence' => $chapter->sequence,
  534. ]);
  535. ReadRecordService::addReadRecord([
  536. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  537. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  538. ]);
  539. $free_book = BookConfigService::getByBidNoFilter($bid);
  540. if ($free_book) {
  541. if (strtotime($free_book->end_time) + 7 * 86400 >= strtotime(date('Y-m-d'))) {
  542. if (Redis::Sismember('qapp:free:virtual:uids' . $free_book->id, $this->uid)) {
  543. $now = date('Y-m-d');
  544. $fee = $this->getPrice($book_info, $chapter->size);
  545. Redis::hincrby('qapp:book:free:actuality:' . $free_book->id, $now, $fee);
  546. Redis::sadd('qapp:free:actuality' . $now, $free_book->id);
  547. Redis::sadd('qapp:free:actuality:uids' . $now . $free_book->id, $this->uid);
  548. }
  549. }
  550. }
  551. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  552. } else {
  553. $fee = $this->getPrice($book_info, $chapter->size);
  554. $data = [
  555. 'book_id' => $oldbid,
  556. 'book_name' => $book_info->book_name,
  557. 'chapter_name' => $chapter->name,
  558. 'chapter_id' => $cid,
  559. 'pay_type' => $book_info->charge_type,
  560. 'fee' => $fee,
  561. 'user_balance' => $this->user_info['balance'],
  562. 'product_id' => $book_info->product_id,
  563. 'uid' => $this->uid,
  564. 'distribution_channel_id' => $this->distribution_channel_id,
  565. 'is_discount' => 0,
  566. 'discount_fee' => '',
  567. 'discount' => ''
  568. ];
  569. if ($book_info->charge_type == 'BOOK') {
  570. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  571. } elseif ($book_info->charge_type == 'CHAPTER') {
  572. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  573. } else {
  574. return response()->error('QAPP_SYS_ERROR');
  575. }
  576. }
  577. }
  578. /**
  579. * 余额支付
  580. * @param $book_info
  581. * @param $chapter_id
  582. * @param $chapter_size
  583. * @return bool
  584. */
  585. protected function balancePay($book_info, $chapter_id, $chapter_size, $chapter_name, $is_remind)
  586. {
  587. $fee = $this->getPrice($book_info, $chapter_size);
  588. if ((int)$this->user_info['balance'] >= $fee) {
  589. if ($this->bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)) {
  590. return true;
  591. }
  592. return false;
  593. } else {
  594. return false;
  595. }
  596. }
  597. /**
  598. * 获取章节内容
  599. * @param $bid
  600. * @param $cid
  601. * @return bool|mixed
  602. */
  603. protected function getChapter($bid, $cid, $chapter)
  604. {
  605. $chapter_content = ChapterService::getChapter($bid, $cid);
  606. if (!$chapter_content) return false;
  607. $chapter->content = trim(str_replace($chapter_content->name, '', $chapter_content->content));
  608. // 格式特殊处理
  609. $qian = array(" ", " ", "\t");
  610. $hou = array("", "", "");
  611. // 去掉所有空格
  612. $chapter->content = str_replace($qian, $hou, $chapter->content);
  613. // 2换行变1换行
  614. $chapter->content = str_replace("\n\n", "\n", $chapter->content);
  615. $chapter->content = str_replace("\r\n\r\n", "\r\n", $chapter->content);
  616. // \Log::info('getChapter_chapter:'.$bid.' cid:'.$cid);
  617. // \Log::info($chapter->content);
  618. //统计点击率
  619. $key = 'book_click_num_bid_' . $bid;
  620. $field = date('Y-m-d');
  621. $old = Redis::hget($key, $field);
  622. if (!$old) $old = 0;
  623. Redis::hset($key, $field, $old + 1);
  624. [$force_add_desk_type,$is_need_query_send_order] = $this->addDesktopType($bid, $chapter->sequence);
  625. $chapter->force_add_desk_type = $force_add_desk_type;
  626. $force_add_work_wechat_type = 0;
  627. $force_add_work_wechat_url = "";
  628. if($is_need_query_send_order){
  629. [$force_add_work_wechat_type, $force_add_work_wechat_url] = $this->addWorkWechatType($chapter->sequence);
  630. }
  631. $chapter->force_add_work_wechat_type = $force_add_work_wechat_type;
  632. $chapter->force_add_work_wechat_url = $force_add_work_wechat_url;
  633. //统计
  634. $this->stats();
  635. $next_chapter_order_status = $this->nextChapterOrderStatus($bid, $chapter->next_cid);
  636. $chapter->next_chapter_status = $next_chapter_order_status['next_chapter_status'];
  637. $chapter->next_price = $next_chapter_order_status['next_price'];
  638. $chapter->charge_type = $this->book_info->charge_type;
  639. $this->userBookCombination($chapter);
  640. return $chapter;
  641. }
  642. private function nextChapterOrderStatus($bid, $cid)
  643. {
  644. $chapter = ChapterService::getChapterNameById($cid, $bid);
  645. if (!$chapter || $chapter->is_vip == 0 || $this->book_info->charge_type == 'BOOK') {
  646. return ['next_chapter_status' => 0, 'next_price' => 0];
  647. }
  648. $is_paid = $this->getOrderRecord($bid, $cid);
  649. if ($is_paid) {
  650. return ['next_chapter_status' => 1, 'next_price' => 0];
  651. }
  652. $fee = $this->getPrice($this->book_info, $chapter->size);
  653. return ['next_chapter_status' => 2, 'next_price' => $fee];
  654. }
  655. //短续长
  656. private function userBookCombination($chapter)
  657. {
  658. if ($chapter->prev_cid && $chapter->next_cid) {
  659. return;
  660. }
  661. if ($chapter->next_cid == 0 && $this->book_info->charge_type == 'BOOK') {
  662. $bid = UserBookCombinationConfigService::selectAndSave($this->uid, $this->book_info->bid);
  663. if ($bid) {
  664. $bookInfo = BookConfigService::getBookById($bid);
  665. $chapter->next_cid = $bookInfo->first_cid;
  666. }
  667. }
  668. if ($chapter->prev_cid == 0 && $this->book_info->charge_type == 'CHAPTER') {
  669. $bid = UserBookCombinationConfigService::getShortBookFromLongBid($this->uid, $this->book_info->bid);
  670. if ($bid) {
  671. $bookInfo = BookConfigService::getBookById($bid);
  672. $chapter->prev_cid = $bookInfo->last_cid;
  673. }
  674. }
  675. }
  676. private function chapterNotExists($bid, $cid)
  677. {
  678. //1.全局图书组合配置
  679. $combination = BookConfigService::getCombinationInfo($bid);
  680. if ($combination) {
  681. $chapter = ChapterService::getChapterNameByIdNoCheck($cid);
  682. if ($chapter) {
  683. return $chapter;
  684. }
  685. return false;
  686. }
  687. //2.用户图书组合配置
  688. if ($this->book_info->charge_type == 'CHAPTER') {
  689. $user_combination = UserBookCombinationConfigService::getShortBookFromLongBook($this->uid, $bid);
  690. } else {
  691. $user_combination = UserBookCombinationConfigService::getLongBookFromShortBook($this->uid, $bid);
  692. }
  693. if ($user_combination) {
  694. $chapter = ChapterService::getChapterNameByIdNoCheck($cid);
  695. if ($chapter) {
  696. return $chapter;
  697. }
  698. return false;
  699. }
  700. return false;
  701. }
  702. /**
  703. * 添加订购记录
  704. * @param $book_info
  705. * @param $chapter_id
  706. * @param $fee
  707. * @return bool
  708. */
  709. protected function bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)
  710. {
  711. if ($book_info['charge_type'] == 'BOOK') {
  712. $data = [
  713. 'uid' => $this->uid,
  714. 'fee' => $fee,
  715. 'u' => $this->send_order_id,
  716. 'distribution_channel_id' => $this->distribution_channel_id,
  717. 'bid' => $book_info->bid,
  718. 'book_name' => $book_info->book_name,
  719. 'send_order_id' => $this->send_order_id,
  720. ];
  721. return BookOrderService::addOrderRecodeAndDecrUserBalance($data, $this->uid);
  722. } else {
  723. $data = [
  724. 'uid' => $this->uid,
  725. 'fee' => $fee,
  726. 'cid' => $chapter_id,
  727. 'bid' => $book_info->bid,
  728. 'distribution_channel_id' => $this->distribution_channel_id,
  729. 'book_name' => $book_info->book_name,
  730. 'chapter_name' => $chapter_name,
  731. 'send_order_id' => $this->send_order_id,
  732. 'is_remind' => $is_remind
  733. ];
  734. if ($is_remind) {
  735. $this->addOrderRemind($book_info->bid);
  736. }
  737. return ChapterOrderService::addOrderAndDecrUserBalance($data, $this->uid);
  738. }
  739. }
  740. protected function addOrderRemind($bid)
  741. {
  742. if (ChapterReminderService::checkIsNoReminder($this->uid, $bid)) {
  743. return true;
  744. } else {
  745. ChapterReminderService::add($this->uid, $bid);
  746. return true;
  747. }
  748. }
  749. /**
  750. * 是否订购提醒
  751. * @param $chapter_id
  752. * @return bool
  753. */
  754. protected function isOrderRemind($bid)
  755. {
  756. $is_no_reminder = ChapterReminderService::checkIsNoReminder($this->uid, $bid) ? 1 : 0;
  757. return $is_no_reminder == 0;
  758. }
  759. /**
  760. * 用户是否关注
  761. * @param $uid
  762. * @return bool
  763. */
  764. protected function getSubscribe()
  765. {
  766. $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  767. if ($res) return true;
  768. return false;
  769. }
  770. /**
  771. * 获取订购记录
  772. * @param $book_info
  773. * @param $chapter_id
  774. * @return bool
  775. */
  776. protected function getOrderRecord($bid, $chapter_id)
  777. {
  778. //包年记录
  779. $uid = $this->uid;
  780. $res = YearOrderService::getRecord($uid);
  781. if ($res) return true;
  782. $res = null;
  783. //单本订购记录
  784. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  785. if ($res) return true;
  786. $res = null;
  787. //章节订购记录
  788. $chapterOrder = new ChapterOrderService();
  789. if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
  790. return false;
  791. }
  792. /**
  793. * 计算价格
  794. * @param $book_info
  795. * @param $chapter_size
  796. * @return float
  797. */
  798. private function getPrice($book_info, $chapter_size = 0)
  799. {
  800. if ($book_info->charge_type == 'BOOK') {
  801. if (BookOrderService::isHasBookOrder($this->uid)) {
  802. $this->is_first_book_order = 0;
  803. return 1399;
  804. } else {
  805. $this->is_first_book_order = 1;
  806. return 899;
  807. }
  808. } else {
  809. // 获取投放后台账号,
  810. $account = '';
  811. $account_send_order = $this->getNowSendOrderInfo();
  812. if ($account_send_order) {
  813. $account = isset($account_send_order['account']) ? $account_send_order['account'] : '';
  814. }
  815. $fee = BookService::getPrice($book_info, $this->distribution_channel_id, $chapter_size, $account);
  816. return $fee;
  817. }
  818. }
  819. /**
  820. * 计算价格
  821. * @param $book_info
  822. * @param $chapter_size
  823. * @return float
  824. */
  825. private function getPriceNew($book_info, $chapter_size = 0, $account = "")
  826. {
  827. if ($book_info->charge_type == 'BOOK') {
  828. if (BookOrderService::isHasBookOrder($this->uid)) {
  829. $this->is_first_book_order = 0;
  830. return 1399;
  831. } else {
  832. $this->is_first_book_order = 1;
  833. return 899;
  834. }
  835. } else {
  836. return BookService::getPrice($book_info, $this->distribution_channel_id, $chapter_size, $account);
  837. }
  838. }
  839. /**
  840. * 获取投放后台账号,
  841. * name: getAccount
  842. * @return mixed|string
  843. * date 2022/10/20 11:29
  844. */
  845. protected function getAccount()
  846. {
  847. $account = '';
  848. $account_send_order = $this->getNowSendOrderInfo();
  849. if ($account_send_order) {
  850. $account = isset($account_send_order['account']) ? $account_send_order['account'] : '';
  851. }
  852. return $account;
  853. }
  854. /**
  855. * 用户添加标签
  856. * @param $book_info
  857. */
  858. protected function addTag($book_info)
  859. {
  860. if (!UserDeepReadTagService::isAddTag($this->uid, $book_info->bid)) {
  861. try {
  862. UserDeepReadTagService::addTag([
  863. 'uid' => $this->uid,
  864. 'bid' => $book_info->bid,
  865. 'book_name' => $book_info->book_name,
  866. 'category_id' => $book_info->category_id,
  867. 'category_name' => $book_info->category_name,
  868. 'sex_preference' => $book_info->channel_name ? $book_info->channel_name : '',
  869. 'distribution_channel_id' => $this->distribution_channel_id ? $this->distribution_channel_id : '0',
  870. 'send_order_id' => $this->send_order_id,
  871. ]);
  872. } catch (\Exception $e) {
  873. }
  874. }
  875. }
  876. protected function isBookOrdered($bid)
  877. {
  878. $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
  879. if ($chapter_order) return true;
  880. $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
  881. if ($res) return true;
  882. return false;
  883. }
  884. /**
  885. * 判断是否需要充值
  886. */
  887. private function isBookNeedCharge(int $bid, float $price)
  888. {
  889. $book_order = $this->getOrderRecord($bid, 0);
  890. if ($book_order) {
  891. return false;
  892. } else {
  893. $user_info = $this->user_info;
  894. return $user_info['balance'] < $price;
  895. }
  896. }
  897. /**
  898. * 判断章节是否需要充值
  899. */
  900. private function isChapterNeedCharge(int $bid, int $cid, float $price)
  901. {
  902. $book_order = $this->getOrderRecord($bid, $cid);
  903. if ($book_order) {
  904. return false;
  905. } else {
  906. $user_info = $this->user_info;
  907. return $user_info['balance'] < $price;
  908. }
  909. }
  910. private function stats()
  911. {
  912. //阅读器统计
  913. WapVisitStatService::recordReaderUvAndPv($this->uid, $this->distribution_channel_id);
  914. }
  915. //加桌类型
  916. private function addDesktopType($bid, $sequence)
  917. {
  918. $deault_force_add_desk_type = 0;
  919. $send_order_id = $this->GetBindSendOrderId($this->uid);
  920. $is_need_query_order = 0;
  921. if ($send_order_id) {
  922. $send_order_info = SendOrderService::getById($send_order_id);
  923. if (!$send_order_info) return [$deault_force_add_desk_type,$is_need_query_order];
  924. if ($send_order_info->book_id == $bid) {
  925. $is_need_query_order = 1;
  926. // 派单书籍和观看书籍一致,并设置了强加桌,判断当前章节和设置的强加桌章节
  927. if ($send_order_info->force_add_desk_type == 1 && $send_order_info->force_add_desk_seq) {
  928. //在设置的强加桌章节前一章开始
  929. if ($sequence >= ($send_order_info->force_add_desk_seq - 1)) {
  930. $force_add_desk_type = $send_order_info->force_add_desk_type;
  931. return [$force_add_desk_type,$is_need_query_order];
  932. }
  933. }
  934. if ($send_order_info->force_add_desk_type == 2) {
  935. if ($sequence >= $this->book_info->force_subscribe_chapter_seq && $sequence <= $this->book_info->force_subscribe_chapter_seq + 3) {
  936. $force_add_desk_type = $send_order_info->force_add_desk_type;
  937. return [$force_add_desk_type,$is_need_query_order];
  938. }
  939. }
  940. if ($send_order_info->force_add_desk_type == 3) {
  941. //弱加桌+强加桌 ,即强加桌章节之前的章节均弱加桌,之后的章节显示强加桌:
  942. $need_sequence = $send_order_info->force_add_desk_seq;
  943. if (!$need_sequence) {
  944. $need_sequence = $this->book_info->force_subscribe_chapter_seq;
  945. }
  946. if ($sequence >= ($need_sequence - 1)) {
  947. //之后的章节显示强加桌
  948. return [1,$is_need_query_order];
  949. } else {
  950. ////强加桌章节之前的章节均弱加桌
  951. return [2,$is_need_query_order];
  952. }
  953. }
  954. return [$deault_force_add_desk_type,$is_need_query_order];
  955. }
  956. }
  957. //无派单,或者派单书籍与 此次书籍不一致,直接使用 原书籍的默认强关章节
  958. $book_info = BookConfigService::getBookById($bid);
  959. if ($book_info && $book_info->force_subscribe_chapter_seq) {
  960. if ($sequence >= ($book_info->force_subscribe_chapter_seq - 1)) {
  961. return [2,$is_need_query_order];
  962. }
  963. }
  964. return [$deault_force_add_desk_type,$is_need_query_order];
  965. }
  966. private function addWorkWechatType($sequence)
  967. {
  968. $deault_force_add_desk_type = 0;
  969. $work_wechat_url = "";
  970. $send_order_id = $this->GetBindSendOrderId($this->uid);
  971. if ($send_order_id) {
  972. $send_order_info = QappSendOrder::getSendOrderById($send_order_id);
  973. if (!$send_order_info) return [$deault_force_add_desk_type, $work_wechat_url];
  974. if($send_order_info['force_add_work_wechat_status'] == 1 && $send_order_info['force_add_work_wechat_seq'] <= ($sequence+1)){
  975. $deault_force_add_desk_type =$send_order_info['force_add_work_wechat_type'];
  976. $work_wechat_url =$send_order_info['force_add_work_wechat_url'];
  977. }
  978. }
  979. return [$deault_force_add_desk_type, $work_wechat_url];
  980. }
  981. /**
  982. * [bindSendOrderId description]
  983. * @param [type] $uid [description]
  984. * @param [type] $send_order_id [description]
  985. * @return [type] [description]
  986. */
  987. public function bindSendOrderId($uid, $send_order_id)
  988. {
  989. if ($send_order_id) {
  990. $res = Redis::hset('book_read_chapter:' . $uid, 'send_order_id', $send_order_id);
  991. }
  992. }
  993. /**
  994. * [bindSendOrderId description]
  995. * @param [type] $uid [description]
  996. * @param [type] $send_order_id [description]
  997. * @return [type] [description]
  998. */
  999. public function GetBindSendOrderId($uid)
  1000. {
  1001. try {
  1002. $send_order_id = Redis::hget('book_read_chapter:' . $uid, 'send_order_id');
  1003. if ($send_order_id)
  1004. return (int)$send_order_id;
  1005. } catch (\Exception $e) {
  1006. }
  1007. }
  1008. private function getChapterIds($chapters): array
  1009. {
  1010. $list = [];
  1011. if ($chapters) {
  1012. foreach ($chapters as $v) {
  1013. $list[] = $v->id;
  1014. }
  1015. }
  1016. return $list;
  1017. }
  1018. private function getHandelData(int $bid, array $chapterIds): array
  1019. {
  1020. $uid = $this->uid;
  1021. $res = YearOrderService::getRecord($uid);
  1022. if ($res) {
  1023. return $handle = ['check' => 0, 'paycid' => []];
  1024. }
  1025. $res = null;
  1026. //单本订购记录
  1027. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  1028. if ($res) {
  1029. return $handle = ['check' => 0, 'paycid' => []];
  1030. }
  1031. //章节订购记录
  1032. $chapterOrder = new ChapterOrderService();
  1033. $res = $chapterOrder->getOrdersByChapterIds($uid, $bid, $chapterIds);
  1034. return $handle = ['check' => 1, 'paycid' => $res];
  1035. }
  1036. /**
  1037. * 判断是否需要充值
  1038. * name: isChapterNeedChargeNew
  1039. * @param $cid
  1040. * @param $rules
  1041. * @return bool
  1042. * date 2022/10/20 16:08
  1043. */
  1044. private function isChapterNeedChargeNew($cid, $rules, $price = 0): bool
  1045. {
  1046. if ($rules['check'] != 1) {
  1047. return false;
  1048. }
  1049. if (empty($rules['paycid']) || !in_array($cid, $rules['paycid'])) {
  1050. $user_info = $this->user_info;
  1051. return $user_info['balance'] < $price;
  1052. } else {
  1053. return false;
  1054. }
  1055. }
  1056. /*****
  1057. * 是否订阅
  1058. * name: isSubscribe
  1059. * @param $cid
  1060. * @param $rules
  1061. * @return int
  1062. * date 2022/11/02 17:19
  1063. */
  1064. private function isSubscribe($cid, $rules): int
  1065. {
  1066. if ($rules['check'] != 1) {
  1067. return 1;
  1068. }
  1069. if (empty($rules['paycid']) || !in_array($cid, $rules['paycid'])) {
  1070. return 2;
  1071. } else {
  1072. return 1;
  1073. }
  1074. }
  1075. private function getWorkWechatInfo($bid)
  1076. {
  1077. $info = ['force_add_work_wechat_type' => 0,'force_add_work_wechat_url' => "",'force_add_work_wechat_seq' => 0];
  1078. $send_order_id = $this->GetBindSendOrderId($this->uid);
  1079. if ($send_order_id) {
  1080. $send_order_info = QappSendOrder::getSendOrderById($send_order_id);
  1081. if (!$send_order_info) return $info;
  1082. $send_order_bid = SendOrder::where(['id' => $send_order_id])->value('book_id');
  1083. if($send_order_info['force_add_work_wechat_status'] == 1 && $send_order_bid == $bid){
  1084. $info['force_add_work_wechat_type'] = $send_order_info['force_add_work_wechat_type'];
  1085. $info['force_add_work_wechat_url'] = $send_order_info['force_add_work_wechat_url'];
  1086. $info['force_add_work_wechat_seq'] = $send_order_info['force_add_work_wechat_seq'];
  1087. }else{
  1088. return $info;
  1089. }
  1090. }
  1091. return $info;
  1092. }
  1093. }