ChapterController.php 46 KB

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