ChapterController.php 46 KB

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