SendOrderController.php 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hp
  5. * Date: 2017/11/22
  6. * Time: 11:36
  7. */
  8. namespace App\Http\Controllers\Channel\SendOrder;
  9. use App\Http\Controllers\Channel\BaseController;
  10. use App\Http\Controllers\Channel\SendOrder\Transformers\SendOrderTransformer;
  11. use App\Modules\Book\Services\BookConfigService;
  12. use App\Modules\Book\Services\ChapterService;
  13. use App\Modules\Channel\Services\ChannelService;
  14. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  15. use App\Modules\Promotion\Services\PromotionService;
  16. use App\Modules\SendOrder\Services\SendOrderService;
  17. use App\Modules\Statistic\Services\WapVisitStatService;
  18. use App\Modules\Trade\Services\OrderService;
  19. use App\Modules\User\Services\UserService;
  20. use DB;
  21. use Hashids;
  22. use Illuminate\Http\Request;
  23. class SendOrderController extends BaseController
  24. {
  25. /**
  26. * @apiDefine sendOrder 派单
  27. */
  28. /**
  29. * @apiVersion 1.0.0
  30. * @api {GET} sendOrder/getSendOrders 获取派单列表
  31. * @apiGroup sendOrder
  32. * @apiName getSendOrders
  33. * @apiParam{Number} [sendOrder_id] 派单id(可不传)
  34. * @apiParam{Number} [book_id] 书本id(可不传)
  35. * @apiParam{String} [name] 派单名称(可不传)
  36. * @apiParam{String} [book_name] 书名(可不传)
  37. * @apiParam{String} [start_time] 开始时间(可不传)
  38. * @apiParam{String} [end_time] 结束时间(可不传)
  39. * @apiParam{String} [pre_send_date_start] 预计发布时间开始(可不传)
  40. * @apiParam{String} [pre_send_date_end] 预计发布时间结束(可不传)
  41. * @apiParam{String} [promotion_point] 派单源 微信(默认)or浏览器(微信:1,浏览器:2)
  42. * @apiSuccess {Number} id 派单id.
  43. * @apiSuccess {String} distribution_channel_id 渠道id
  44. * @apiSuccess {String} entrance 入口
  45. * @apiSuccess {String} name 渠道名称
  46. * @apiSuccess {Number} book_id 书本id
  47. * @apiSuccess {String} channel_type 渠道类型
  48. * @apiSuccess {Number} document_cover_id 文案封面id
  49. * @apiSuccess {Number} headline_id 标题id
  50. * @apiSuccess {Number} body_template_id ID. 内容模板id
  51. * @apiSuccess {Number} original_guide_id 原文引导id
  52. * @apiSuccess {Number} qr_code_id 二维码
  53. * @apiSuccess {Number} subscribe_chapter_id 关注章节ID
  54. * @apiSuccess {Number} document_end_chapter_seq 结束章节序号
  55. * @apiSuccess {String} book_name 图书名称
  56. * @apiSuccess {String} chapter_name 章节名称
  57. * @apiSuccess {String} updated_at 更新时间
  58. * @apiSuccess {String} created_at 创建时间
  59. * @apiSuccess {String} pre_send_date 预计发布时间
  60. * @apiSuccess {String} sex_preference 性别偏好
  61. * @apiSuccess {String} subscribe_chapter_name 关注章节名称
  62. * @apiSuccess {String} subscribe_chapter_seq 关注章节序号
  63. * @apiSuccess {Number} remark 备注
  64. * @apiSuccess {Number} star_num 星星数
  65. * @apiSuccess {Number} cost 成本
  66. * @apiSuccess {Number} totalChargeAmount 充值总额数
  67. * @apiSuccess {Number} registerNum 注册数
  68. * @apiSuccess {Number} payUserNum 付费用户数
  69. * @apiSuccess {Number} clickNum 点击数数
  70. * @apiSuccess {Number} browserClickNum 浏览器端pv
  71. * @apiSuccess {Number} browserClickNumUV 浏览器端uv
  72. * @apiSuccess {Number} fansNum 粉丝数
  73. * @apiSuccess {Number} promotion_page_id 推广页面id
  74. * @apiSuccess {String} redirect_url 重定向url
  75. * @apiSuccess {String} qrcode 二维码
  76. * @apiSuccess {String} domain 域名
  77. * @apiSuccess {String} consumeTotalFee 派单下的消费的币的总和
  78. * @apiSuccess {String} consumeChargeFee 派单下的消费的充值币
  79. * @apiSuccess {String} consumeRewardFee 派单下的消费的奖励币
  80. * @apiSuccessExample {json} Success-Response:
  81. *
  82. * {
  83. * "code": 0,
  84. * "msg": "",
  85. *
  86. * "data": [
  87. * {
  88. * "id": 5,
  89. * "distribution_channel_id": null,
  90. * "entrance": "书架",
  91. * "name": "acai",
  92. * "book_id": null,
  93. * "channel_type": "AUTHENTICATED",
  94. * "chapter_id": null,
  95. * "document_cover_id": null,
  96. * "headline_id": null,
  97. * "body_template_id": null,
  98. * "original_guide_id": null,
  99. * "subscribe_chapter_id": null,
  100. * "book_name": null,
  101. * "document_end_chapter_seq"=12.
  102. * "sex_preference": "男频",
  103. * "chapter_name": null,
  104. * "updated_at": "2017-11-22 14:40:46",
  105. * "created_at": "2017-11-22 14:40:46",
  106. * "pre_send_date": "2018/11/12"
  107. * "subscribe_chapter_name": null,
  108. * "subscribe_chapter_seq": null,
  109. * "remark": "0",
  110. * "star_num": 0,
  111. * "fansNum": 0,
  112. * "cost":1111
  113. * "totalChargeAmount": 0,
  114. * "registerNum": 0,
  115. * "payUserNum": 0,
  116. * "clickNum": 0,
  117. * "promotion_page_id": 1111,
  118. * "redirect_url": ""
  119. * "qrcode": ""
  120. * "domain":"leque"
  121. * "toatlOrderCount":12,
  122. * "vipOrderCount":12,
  123. * "normalOrderCount":12,
  124. * },
  125. * {
  126. * "id": 11,
  127. * "distribution_channel_id": 123,
  128. * "entrance": null,
  129. * "name": "acai",
  130. * "book_id": 111,
  131. * "cost":1111
  132. * "channel_type": "AUTHENTICATED",
  133. * "chapter_id": 1111,
  134. * "document_cover_id": 899,
  135. * "headline_id": 12334,
  136. * "body_template_id": 3455,
  137. * "document_end_chapter_seq"=12.
  138. * "original_guide_id": 344,
  139. * "subscribe_chapter_id": 11111,
  140. * "book_name": "dpcq",
  141. * "sex_preference": "男频",
  142. * "chapter_name": "ssss",
  143. * "domain":"leque"
  144. * "updated_at": "2017-11-22 14:40:46",
  145. * "created_at": "2017-11-22 14:40:46",
  146. * "subscribe_chapter_name": null,
  147. * "subscribe_chapter_seq": null,
  148. * "remark": "0",
  149. * "star_num": 0,
  150. * "fansNum": 0,
  151. * "totalChargeAmount": 0,
  152. * "addUserNum": 0,
  153. * "payUserNum": 0,
  154. * "clickNum": 0,
  155. * "toatlOrderCount":12,
  156. * "vipOrderCount":12,
  157. * "normalOrderCount":12,
  158. * "promotion_page_id": null,
  159. * "redirect_url": ""
  160. * "qrcode": ""
  161. * }
  162. * ],
  163. * "meta": {
  164. * "total": 1,
  165. * "per_page": 15,
  166. * "current_page": 1,
  167. * "last_page": 1,
  168. * "next_page_url": "",
  169. * "prev_page_url": ""
  170. * }
  171. * }
  172. */
  173. function getSendOrders(Request $request)
  174. {
  175. $distribution_channel_id = $this->getChannelId();
  176. $name = $request->has('name') ? $request->input('name') : '';
  177. $book_id = $request->has('book_id') ? $request->input('book_id') : '';
  178. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  179. $id = $sendOrderId = $request->has('sendOrder_id') ? $request->input('sendOrder_id') : '';
  180. $promotion_type = $request->has('promotion_type') ? $request->input('promotion_type') : '';
  181. $import_company_name = $request->has('company_name') ? $request->input('company_name') : '';
  182. $pre_send_date_end = $request->has('pre_send_date_end') ? $request->input('pre_send_date_end') : '';
  183. $pre_send_date_start = $request->has('pre_send_date_start') ? $request->input('pre_send_date_start') : '';
  184. $start_time = $request->has('start_time') && !empty($request->input('start_time')) ? $request->input('start_time') : '';
  185. $end_time = $request->has('end_time') && !empty($request->input('end_time')) ? date('Y-m-d H:i:s', strtotime($request->input('end_time')) + 86400 - 1) : '';
  186. $promotion_point = $request->has('promotion_point') ? $request->input('promotion_point') : 1;
  187. //$data = SendOrderService::getSendOrders($bookId, $distribution_channel_id, $name, $bookName, $sendOrderId, $start_time, $end_time, false);
  188. $data = SendOrderService::search(compact(
  189. 'book_id',
  190. 'distribution_channel_id',
  191. 'name',
  192. 'pre_send_date_end',
  193. 'import_company_name',
  194. 'pre_send_date_start',
  195. 'promotion_type',
  196. 'pre_send_date',
  197. 'book_name',
  198. 'start_time',
  199. 'end_time',
  200. 'id',
  201. 'promotion_point'
  202. ));
  203. $send_order_export_special_channel = env('SEND_ORDER_EXPORT_SPECIAL_CHANNEL');
  204. $isExistSpecialChannel = in_array($distribution_channel_id, explode(',', $send_order_export_special_channel));
  205. foreach ($data as $item) {
  206. $itemName = $item->name;
  207. if ($isExistSpecialChannel) {
  208. if (strpos($itemName, "-")) {
  209. $strs = explode('-', $itemName);
  210. if (count($strs) == 4) {
  211. $date = $this->getFormatDate($strs[2], $item->created_at);
  212. $strs[2] = date('Y/m/d', strtotime($date));
  213. $itemName = implode('-', $strs);
  214. if (!$item->pre_send_date) {
  215. $item->pre_send_date = $date;
  216. }
  217. } elseif (count($strs) == 6) {
  218. $date = $this->getFullDate($strs[2], $strs[3], $strs[4], $item->created_at);
  219. if (!$item->pre_send_date) {
  220. $item->pre_send_date = $date;
  221. }
  222. $itemName = $strs[0] . '-' . $strs[1] . '-' . $date . '-' . $strs[5];
  223. }
  224. }
  225. }
  226. $sendOrderId = $item->id;
  227. $item->name = $itemName;
  228. $browser_visit_info = SendOrderService::getBrowserUvAndPv($sendOrderId);
  229. $item->browserClickNum = $browser_visit_info['pv'];
  230. $item->browserClickNumUV = $browser_visit_info['uv'];
  231. $item->clickNum = SendOrderService::getPv($sendOrderId);
  232. $item->clickNumUV = SendOrderService::getUv($sendOrderId);//uv
  233. $item->payUserNum = OrderService::getPayUserNum($sendOrderId);
  234. $item->registerNum = UserService::getPromotionTotal($sendOrderId);
  235. $item->fansNum = ForceSubscribeService::getNewFansNum($sendOrderId);
  236. $item->continue_read_uv = SendOrderService::getContinueTotalReadUv($item->id);
  237. if ($promotion_point == 2) {
  238. $item->promotion_url = 'https://bsite' . encodeDistributionChannelId($distribution_channel_id) . '.leyuee.com/yun/' . $item->id;
  239. } else {
  240. $item->promotion_url = 'https://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . $this->getDomainByBid($item->book_id) . '/yun/' . $item->id;
  241. }
  242. $item->totalChargeAmount = (float)OrderService::getAmount(['send_order_id' => $sendOrderId]);
  243. // $item->totalChargeAmount = OrderService::getPromotionRegUserRechargeAmount(['send_order_id' => $item->id]);
  244. $item->qrcode = "";//"data:image/png;base64," . base64_encode(QrCode::format('png')->size(200)->generate($promotion_url));
  245. // $bookOrderInfo = BookOrderService::getSendorderTotal($sendOrderId, $start_time, $end_time);
  246. // $chapterOrderInfo = ChapterOrderService::getSendorderTotal($sendOrderId, $start_time, $end_time);
  247. $item->consumeChargeFee = 0;//$bookOrderInfo['charge_balance'] + $chapterOrderInfo['charge_balance'];
  248. $item->consumeRewardFee = 0;//$bookOrderInfo['reward_balance'] + $chapterOrderInfo['reward_balance'];;
  249. $item->consumeTotalFee = 0;//$item->consumeChargeFee + $item->consumeRewardFee;
  250. }
  251. return response()->pagination(new SendOrderTransformer, $data);
  252. }
  253. function getFullDate($year, $month, $day, $created_at = '')
  254. {
  255. if (strlen($year) != 4) {
  256. if ($created_at) {
  257. $year = date('Y', strtotime($created_at));
  258. } else {
  259. $year = date('Y');
  260. }
  261. }
  262. if (strlen($month) == 1) {
  263. $month = '0' . $month;
  264. }
  265. if (strlen($day) == 1) {
  266. $day = '0' . $day;
  267. }
  268. $date = $year . $month . $day;
  269. $date = date('Y/m/d', strtotime($date));
  270. return $date;
  271. }
  272. function getFormatDate($date, $created_at = '')
  273. {
  274. $count = strlen($date);
  275. if ($created_at) {
  276. $year = date('Y', strtotime($created_at));
  277. } else {
  278. $year = date('Y');
  279. }
  280. if (2 == $count) {
  281. $date = $year . '0' . $date[0] . '0' . $date[1];
  282. } elseif (3 == $count) {
  283. if (0 === strpos($date, '0')) {
  284. $date = $year . substr($date, 0, 2) . '0' . $date[2];
  285. } else {
  286. $date = $year . '0' . $date;
  287. }
  288. } elseif (4 == $count) {
  289. $date = $year . $date;
  290. }
  291. return $date;
  292. }
  293. /**
  294. * 根据图书id获取域名
  295. * @param $bid
  296. */
  297. function getDomainByBid($bid = '')
  298. {
  299. $domain = 'leyuee.com';
  300. //如果图书id为空,则返回默认的域名
  301. if (!empty($bid)) {
  302. $bookConfig = BookConfigService::getBookById($bid);
  303. if ($bookConfig) {
  304. $domain = $bookConfig->promotion_domain;
  305. }
  306. }
  307. return $domain;
  308. }
  309. /**
  310. * @apiVersion 1.0.0
  311. * @apiDescription 派单列表导出
  312. * @api {GET} sendOrder/exportSendOrders 派单列表导出
  313. * @apiGroup sendOrder
  314. * @apiName exportSendOrders
  315. * @apiParam{Number} [sendOrder_id] 派单id(可不传)
  316. * @apiParam{Number} [book_id] 书本id(可不传)
  317. * @apiParam{String} [book_name] 书名(可不传)
  318. * @apiParam{String} [name] 派单名称(可不传)
  319. * @apiParam{String} [pre_send_date_start] 预计发布时间开始(可不传)
  320. * @apiParam{String} [pre_send_date_end] 预计发布时间结束(可不传)
  321. * @apiParam{String} [start_time] 开始时间(可不传)
  322. * @apiParam{String} [end_time] 结束时间(可不传)
  323. * @apiParam{String} [promotion_point] 派单源 微信(默认)or浏览器(微信:1,浏览器:2)
  324. * @apiSuccess {Number} id 派单id.
  325. * @apiSuccess {String} distribution_channel_id 渠道id
  326. * @apiSuccess {String} entrance 入口
  327. * @apiSuccess {String} name 渠道名称
  328. * @apiSuccess {Number} book_id 书本id
  329. * @apiSuccess {String} channel_type 渠道类型
  330. * @apiSuccess {Number} document_cover_id 文案封面id
  331. * @apiSuccess {Number} headline_id 标题id
  332. * @apiSuccess {Number} body_template_id ID. 内容模板id
  333. * @apiSuccess {Number} original_guide_id 原文引导id
  334. * @apiSuccess {Number} subscribe_chapter_id 关注章节ID
  335. * @apiSuccess {String} book_name 图书名称
  336. * @apiSuccess {String} chapter_name 章节名称
  337. * @apiSuccess {Number} cost 成本
  338. * @apiSuccess {String} updated_at 更新时间
  339. * @apiSuccess {String} created_at 创建时间
  340. * @apiSuccess {String} subscribe_chapter_name 关注章节名称
  341. * @apiSuccess {String} subscribe_chapter_seq 关注章节序号
  342. * @apiSuccess {Number} remark 备注
  343. * @apiSuccess {Number} star_num 星星数
  344. * @apiSuccess {Number} totalChargeAmount 充值总额数
  345. * @apiSuccess {Number} registerNum 注册数
  346. * @apiSuccess {Number} payUserNum 付费用户数
  347. * @apiSuccess {Number} clickNum 点击数数
  348. * @apiSuccess {Number} fansNum 粉丝数
  349. * @apiSuccess {Number} promotion_page_id 推广页面id
  350. * @apiSuccess {String} redirect_url 重定向url
  351. * @apiSuccessExample {json} Success-Response:
  352. *
  353. * {
  354. * "code": 0,
  355. * "msg": "",
  356. *
  357. * "data": [
  358. * {
  359. * "id": 5,
  360. * "distribution_channel_id": null,
  361. * "entrance": "书架",
  362. * "name": "acai",
  363. * "book_id": null,
  364. * "channel_type": "AUTHENTICATED",
  365. * "chapter_id": null,
  366. * "document_cover_id": null,
  367. * "headline_id": null,
  368. * "body_template_id": null,
  369. * "original_guide_id": null,
  370. * "subscribe_chapter_id": null,
  371. * "book_name": null,
  372. * "chapter_name": null,
  373. * "updated_at": "2017-11-22 14:40:46",
  374. * "created_at": "2017-11-22 14:40:46",
  375. * "subscribe_chapter_name": null,
  376. * "subscribe_chapter_seq": null,
  377. * "remark": "0",
  378. * "star_num": 0,
  379. * "fansNum": 0,
  380. * "cost":111,
  381. * "totalChargeAmount": 0,
  382. * "registerNum": 0,
  383. * "payUserNum": 0,
  384. * "clickNum": 0,
  385. * "promotion_page_id": 1111,
  386. * "redirect_url": ""
  387. * },
  388. * {
  389. * "id": 11,
  390. * "distribution_channel_id": 123,
  391. * "entrance": null,
  392. * "name": "acai",
  393. * "book_id": 111,
  394. * "channel_type": "AUTHENTICATED",
  395. * "chapter_id": 1111,
  396. * "document_cover_id": 899,
  397. * "headline_id": 12334,
  398. * "body_template_id": 3455,
  399. * "original_guide_id": 344,
  400. * "subscribe_chapter_id": 11111,
  401. * "book_name": "dpcq",
  402. * "cost":1111
  403. * "chapter_name": "ssss",
  404. * "updated_at": "2017-11-22 14:40:46",
  405. * "created_at": "2017-11-22 14:40:46",
  406. * "subscribe_chapter_name": null,
  407. * "subscribe_chapter_seq": null,
  408. * "remark": "0",
  409. * "star_num": 0,
  410. * "fansNum": 0,
  411. * "totalChargeAmount": 0,
  412. * "addUserNum": 0,
  413. * "payUserNum": 0,
  414. * "clickNum": 0,
  415. * "promotion_page_id": null,
  416. * "redirect_url": ""
  417. * }
  418. * ],
  419. * "meta": {
  420. * "total": 1,
  421. * "per_page": 15,
  422. * "current_page": 1,
  423. * "last_page": 1,
  424. * "next_page_url": "",
  425. * "prev_page_url": ""
  426. * }
  427. * }
  428. */
  429. function exportSendOrders(Request $request)
  430. {
  431. set_time_limit(0);
  432. $distribution_channel_id = $this->getChannelId();
  433. $name = $request->has('name') ? $request->input('name') : '';
  434. $book_id = $request->has('book_id') ? $request->input('book_id') : '';
  435. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  436. $id = $request->has('sendOrder_id') ? $request->input('sendOrder_id') : '';
  437. $promotion_type = $request->has('promotion_type') ? $request->input('promotion_type') : '';
  438. $pre_send_date_end = $request->has('pre_send_date_end') ? $request->input('pre_send_date_end') : '';
  439. $import_company_name = $request->has('company_name') ? $request->input('company_name') : '';
  440. $pre_send_date_start = $request->has('pre_send_date_start') ? $request->input('pre_send_date_start') : '';
  441. $start_time = $request->has('start_time') && !empty($request->input('start_time')) ? $request->input('start_time') : '';
  442. $promotion_point = $request->has('promotion_point') ? $request->input('promotion_point') : 1;
  443. $send_order_export_special_channel = env('SEND_ORDER_EXPORT_SPECIAL_CHANNEL');
  444. $isExistSpecialChannel = in_array($distribution_channel_id, explode(',', $send_order_export_special_channel));
  445. $end_time = $request->has('end_time') && !empty($request->input('end_time')) ? date('Y-m-d H:i:s', strtotime(trim($request->input('end_time'))) + 86400 - 1) : '';
  446. //$data = SendOrderService::getSendOrders($bookId, $distribution_channel_id, $name, $bookName, $sendOrderId, $start_time, $end_time, true);
  447. $data = SendOrderService::search(compact('book_id', 'distribution_channel_id', 'name', 'import_company_name', 'pre_send_date_end', 'pre_send_date_start', 'promotion_type', 'book_name', 'start_time', 'end_time', 'id', 'promotion_point'), true);
  448. header("Content-type:application/vnd.ms-excel");
  449. header("Content-Disposition:attachment;filename=" . "派单列表" . date("YmdHis") . ".csv");
  450. $specialChannelIdStats = env('SPECIAL_CHANNEL_STATS', 211);
  451. if ($isExistSpecialChannel) {
  452. if (in_array($distribution_channel_id, explode(',', $specialChannelIdStats))) {
  453. echo mb_convert_encoding("\"推广名称\",\"预计发送时间\",\"推广员\",\"书名\",\"点击数\",\"新增用户\",\"注册用户数\",\"新增关注\",\"新增关注率\",\"新关成本\",\"付费用户\",\"首充用户数\",\"成本\",\"累计充值\",\"累计充值成本率\",\"72小时累计充值总额\",\"72小时累计充值回本率\",\"7日充值总额\",\"公司名称\",\"总粉丝数\",\"累计UV大于20的时间\",\"推广位置\",\"小说来源\",\"推广链接\",\"章节名称\",\"充值总额\",\"充值成本率\",\"30日充值总额\",\"30日回本率\",\"24小时充值总额\",\"24小时回本率\",\"72小时充值总额\",\"72小时回本率\",\"30日累计充值总额\",\"30日累计充值回本率\",\"60日累计充值总额\",\"创建时间\",\"首日累计订阅人数\",\"首日累计订阅总额\",\"三日累计订阅人数\",\"三日累计订阅总额\",\"累计订阅人数\",\"累计订阅总额\"\r\n", 'GBK', 'UTF-8');
  454. } else {
  455. echo mb_convert_encoding("\"推广名称\",\"预计发送时间\",\"推广员\",\"书名\",\"点击数\",\"新增用户\",\"注册用户数\",\"新增关注\",\"新增关注率\",\"新关成本\",\"付费用户\",\"首充用户数\",\"成本\",\"累计充值\",\"累计充值成本率\",\"72小时累计充值总额\",\"72小时累计充值回本率\",\"7日充值总额\",\"公司名称\",\"总粉丝数\",\"累计UV大于20的时间\",\"推广位置\",\"小说来源\",\"推广链接\",\"章节名称\",\"充值总额\",\"充值成本率\",\"30日充值总额\",\"30日回本率\",\"24小时充值总额\",\"24小时回本率\",\"72小时充值总额\",\"72小时回本率\",\"30日累计充值总额\",\"30日累计充值回本率\",\"60日累计充值总额\",\"创建时间\"\r\n", 'GBK', 'UTF-8');
  456. }
  457. } else {
  458. echo mb_convert_encoding("\"推广名称\",\"推广链接\",\"书名\",\"章节名称\",\"点击数\",\"新增用户\",\"注册用户数\",\"新增关注\",\"新增关注率\",\"付费用户\",\"首充用户数\",\"充值总额\",\"成本\",\"充值成本率\",\"24小时充值总额\",\"24小时回本率\",\"72小时充值总额\",\"72小时回本率\",\"30日累计充值总额\",\"60日累计充值总额\",\"创建时间\"\r\n", 'GBK', 'UTF-8');
  459. }
  460. if ($data) {
  461. foreach ($data as $item) {
  462. $item->clickNum = SendOrderService::getPv($item->id);
  463. $item->clickNumUV = SendOrderService::getUv($item->id);//uv
  464. $item->payUserNum = OrderService::getPayUserNum($item->id);
  465. $item->fansNum = ForceSubscribeService::getNewFansNum($item->id);
  466. $item->registerNum = UserService::getPromotionTotal($item->id);
  467. $item->totalChargeAmount = (float)OrderService::getAmount(['send_order_id' => $item->id]);
  468. // $item->totalChargeAmount = OrderService::getPromotionRegUserRechargeAmount(['send_order_id' => $item->id]);
  469. $itemName = $item->name;
  470. $promotionUrl = "https://site" . $distribution_channel_id . "." . ($this->getDomainByBid($item->book_id ? $item->book_id : '')) . "/yun/" . $item->id;
  471. /*$stats_obj = SendOrderStat::where('send_order_id',$item->id)->first();
  472. $item->one_day_recharge = $stats_obj->recharge_amount_in_one_day;
  473. $item->three_days_recharge = $stats_obj->recharge_amount_in_three_days;*/
  474. //计算123 渠道号的 24小时 、72小时、7天,30日充值成本和回本
  475. $oneDayChargeAmount = 'NAV';
  476. $threeDayChargeAmount = 'NAV';
  477. $sevenDayChargeAmount = 'NAV';
  478. $thirtyDayChargeAmount = 'NAV';
  479. $promotionRegUserRecharge = 0; //累计充值
  480. $promotionRegUserRechargeAmountInOneMonth = 0; //30天累计充值
  481. $promotionRegUserRechargeAmountInTwoMonth = 0; //60天累计充值
  482. $promotionRegUserRechargeAmountInThreeDays = 0; //72小时累计充值
  483. $firstChargeUserNum = SendOrderService::getFirstChargeUserNum($item->id);
  484. $uv20Time = $item->send_time;//SendOrderService::getUv20Time($item->id);
  485. if ($uv20Time) {
  486. $send_time_24h_later = strtotime($uv20Time) + 86400;
  487. $send_time_72h_later = strtotime($uv20Time) + 3 * 86400;
  488. $send_time_7d_later = strtotime($uv20Time) + 7 * 86400;
  489. $send_time_30d_later = strtotime($uv20Time) + 30 * 86400;
  490. $promotionRegUserRecharge = OrderService::getPromotionRegUserRechargeAmount(['send_order_id' => $item->id]);
  491. $promotionRegUserRechargeAmountInOneMonth = OrderService::getPromotionRegUserRechargeAmount(['send_order_id' => $item->id, 'end_time' => date("Y-m-d H:i:s", strtotime($uv20Time) + 30 * 86400)]);
  492. $promotionRegUserRechargeAmountInThreeDays = OrderService::getPromotionRegUserRechargeAmount(['send_order_id' => $item->id, 'end_time' => date("Y-m-d H:i:s", strtotime($uv20Time) + 3 * 86400)]);
  493. $promotionRegUserRechargeAmountInTwoMonth = OrderService::getPromotionRegUserRechargeAmount(['send_order_id' => $item->id, 'end_time' => date("Y-m-d H:i:s", strtotime($uv20Time) + 60 * 86400)]);
  494. //计算24小时内的充值
  495. if ($send_time_24h_later < time()) {
  496. $selctEndTime = date('Y-m-d H:i:s', $send_time_24h_later);
  497. $oneDayChargeAmount = OrderService::getAmount(['send_order_id' => $item->id, 'begin_time' => $uv20Time, 'end_time' => $selctEndTime]);
  498. }
  499. //计算72小时内的充值
  500. if ($send_time_72h_later < time()) {
  501. $selctEndTime = date('Y-m-d H:i:s', $send_time_72h_later);
  502. $threeDayChargeAmount = OrderService::getAmount(['send_order_id' => $item->id, 'begin_time' => $uv20Time, 'end_time' => $selctEndTime]);
  503. }
  504. //计算7日内的充值
  505. if ($send_time_7d_later < time()) {
  506. $selctEndTime = date('Y-m-d H:i:s', $send_time_7d_later);
  507. $sevenDayChargeAmount = OrderService::getAmount(['send_order_id' => $item->id, 'begin_time' => $uv20Time, 'end_time' => $selctEndTime]);
  508. }
  509. //计算30日内的充值
  510. if ($send_time_30d_later < time()) {
  511. $selctEndTime = date('Y-m-d H:i:s', $send_time_30d_later);
  512. $thirtyDayChargeAmount = OrderService::getAmount(['send_order_id' => $item->id, 'begin_time' => $uv20Time, 'end_time' => $selctEndTime]);
  513. }
  514. }
  515. if ($isExistSpecialChannel) {
  516. $promotionSource = '-';
  517. if (strpos($itemName, "-")) {
  518. $strs = explode('-', $itemName);
  519. if (count($strs) == 4) {
  520. $date = $this->getFormatDate($strs[2], $item->created_at);
  521. $date = date('Y/m/d', strtotime($date));
  522. $promotionSource = $strs[1];
  523. echo("\"" . mb_convert_encoding($strs[0], "GBK", "UTF-8") . "\",");
  524. echo("\"" . $date . "\",");
  525. echo("\"" . mb_convert_encoding($strs[3], "GBK", "UTF-8") . "\",");
  526. } elseif (count($strs) == 6) {
  527. $promotionSource = $strs[1];
  528. $date = $this->getFullDate($strs[2], $strs[3], $strs[4], $item->created_at);
  529. echo("\"" . mb_convert_encoding($strs[0], "GBK", "UTF-8") . "\",");
  530. echo("\"" . $date . "\",");
  531. echo("\"" . mb_convert_encoding($strs[5], "GBK", "UTF-8") . "\",");
  532. } else {
  533. echo("\"" . mb_convert_encoding($itemName, "GBK", "UTF-8") . "\",");
  534. echo("\"" . mb_convert_encoding('-', "GBK", "UTF-8") . "\",");
  535. echo("\"" . mb_convert_encoding('-', "GBK", "UTF-8") . "\",");
  536. }
  537. } else {
  538. echo("\"" . mb_convert_encoding($itemName, "GBK", "UTF-8") . "\",");
  539. echo("\"" . mb_convert_encoding('-', "GBK", "UTF-8") . "\",");
  540. echo("\"" . mb_convert_encoding('-', "GBK", "UTF-8") . "\",");
  541. }
  542. echo("\"" . mb_convert_encoding($item->book_name ? $item->book_name : '书名为空', "GBK", "UTF-8") . "\",");
  543. echo("\"" . $item->clickNum . "\",");
  544. echo("\"" . $item->clickNumUV . "\",");
  545. echo("\"" . $item->registerNum . "\",");
  546. echo("\"" . $item->fansNum . "\",");
  547. echo("\"" . ($this->getPersentAmount($item->fansNum, $item->registerNum)) . "\",");
  548. echo("\"" . ((int)$item->fansNum != 0 ? round($item->cost / $item->fansNum, 2) : 0) . "\",");
  549. echo("\"" . $item->payUserNum . "\",");
  550. echo("\"" . $firstChargeUserNum . "\",");
  551. echo("\"" . $item->cost . "\",");
  552. echo("\"" . $promotionRegUserRecharge . "\",");
  553. echo("\"" . ($this->getPersentAmount($promotionRegUserRecharge, $item->cost)) . "\",");
  554. echo("\"" . mb_convert_encoding($promotionRegUserRechargeAmountInThreeDays, "GBK", "UTF-8") . "\",");
  555. echo("\"" . mb_convert_encoding($this->getPersentAmount($promotionRegUserRechargeAmountInThreeDays, $item->cost), "GBK", "UTF-8") . "\",");
  556. echo("\"" . $sevenDayChargeAmount . "\",");
  557. echo("\"" . mb_convert_encoding($item->import_company_name ? $item->import_company_name : '未填', "GBK", "UTF-8") . "\",");
  558. echo("\"" . $item->fansNum . "\",");
  559. echo("\"" . mb_convert_encoding($uv20Time ? $uv20Time : '未到20', "GBK", "UTF-8") . "\",");
  560. echo("\"" . $promotionSource . "\",");
  561. $cpSource = '未知';
  562. if ($item->book_id) {
  563. $bookConfig = BookConfigService::getBookById($item->book_id);
  564. if ($bookConfig) {
  565. $cpSource = $bookConfig->cp_source;
  566. }
  567. }
  568. echo("\"" . mb_convert_encoding($cpSource, "GBK", "UTF-8") . "\",");
  569. echo("\"" . $promotionUrl . "\",");
  570. echo("\"" . mb_convert_encoding($item->chapter_name ? $item->chapter_name : '章节名称为空', "GBK", "UTF-8") . "\",");
  571. echo("\"" . $item->totalChargeAmount . "\",");
  572. echo("\"" . ($this->getPersentAmount($item->totalChargeAmount, $item->cost)) . "\",");
  573. echo("\"" . mb_convert_encoding($thirtyDayChargeAmount, "GBK", "UTF-8") . "\",");
  574. echo("\"" . ($this->getPersentAmount($thirtyDayChargeAmount, $item->cost)) . "\",");
  575. echo("\"" . mb_convert_encoding($oneDayChargeAmount, "GBK", "UTF-8") . "\",");
  576. echo("\"" . ($this->getPersentAmount($oneDayChargeAmount, $item->cost)) . "\",");
  577. echo("\"" . mb_convert_encoding($threeDayChargeAmount, "GBK", "UTF-8") . "\",");
  578. echo("\"" . ($this->getPersentAmount($threeDayChargeAmount, $item->cost)) . "\",");
  579. echo("\"" . $promotionRegUserRechargeAmountInOneMonth . "\",");
  580. //30日累计充值回本率
  581. echo("\"" . mb_convert_encoding($this->getPersentAmount($promotionRegUserRechargeAmountInOneMonth, $item->cost), "GBK", "UTF-8") . "\",");
  582. echo("\"" . $promotionRegUserRechargeAmountInTwoMonth . "\",");
  583. //echo("\"" . $item->created_at->toDateTimeString() . "\"\r\n");
  584. if (in_array($distribution_channel_id, explode(',', $specialChannelIdStats))) {
  585. echo("\"" . $item->created_at->toDateTimeString() . "\",");
  586. if ($item->send_time) {
  587. $special_stats_date = date('Y-m-d', strtotime($item->send_time));
  588. } else {
  589. $special_stats_date = '';
  590. }
  591. $special_stats = WapVisitStatService::getSpecialChannelIdStats($item->id, $special_stats_date);
  592. echo("\"" . $special_stats['first_day_subscribe_num'] . "\",");
  593. echo("\"" . $special_stats['first_day_subscribe_amount'] . "\",");
  594. echo("\"" . $special_stats['three_day_subscribe_num'] . "\",");
  595. echo("\"" . $special_stats['three_day_subscribe_amount'] . "\",");
  596. echo("\"" . $special_stats['total_subscribe_num'] . "\",");
  597. echo("\"" . $special_stats['total_subscribe_amount'] . "\"\r\n");
  598. } else {
  599. echo("\"" . $item->created_at->toDateTimeString() . "\"\r\n");
  600. }
  601. } else {
  602. echo("\"" . mb_convert_encoding($itemName, "GBK", "UTF-8") . "\",");
  603. echo("\"" . $promotionUrl . "\",");
  604. echo("\"" . mb_convert_encoding($item->book_name ? $item->book_name : '书名为空', "GBK", "UTF-8") . "\",");
  605. echo("\"" . mb_convert_encoding($item->chapter_name ? $item->chapter_name : '章节名称为空', "GBK", "UTF-8") . "\",");
  606. echo("\"" . $item->clickNum . "\",");
  607. echo("\"" . $item->clickNumUV . "\",");
  608. echo("\"" . $item->registerNum . "\",");
  609. echo("\"" . $item->fansNum . "\",");
  610. echo("\"" . ($this->getPersentAmount($item->fansNum, $item->registerNum)) . "\",");
  611. echo("\"" . $item->payUserNum . "\",");
  612. echo("\"" . $firstChargeUserNum . "\",");
  613. echo("\"" . $item->totalChargeAmount . "\",");
  614. echo("\"" . $item->cost . "\",");
  615. echo("\"" . ($this->getPersentAmount($item->totalChargeAmount, $item->cost)) . "\",");
  616. echo("\"" . mb_convert_encoding($oneDayChargeAmount, "GBK", "UTF-8") . "\",");
  617. echo("\"" . ($this->getPersentAmount($oneDayChargeAmount, $item->cost)) . "\",");
  618. echo("\"" . mb_convert_encoding($threeDayChargeAmount, "GBK", "UTF-8") . "\",");
  619. echo("\"" . ($this->getPersentAmount($threeDayChargeAmount, $item->cost)) . "\",");
  620. echo("\"" . $promotionRegUserRechargeAmountInOneMonth . "\",");
  621. echo("\"" . $promotionRegUserRechargeAmountInTwoMonth . "\",");
  622. echo("\"" . $item->created_at->toDateTimeString() . "\"\r\n");
  623. }
  624. }
  625. }
  626. exit();
  627. }
  628. /**
  629. * 计算成本率
  630. * @param $amount 充值金额
  631. * @param $cost 成本
  632. * @return int|string
  633. */
  634. function getPersentAmount($amount, $cost)
  635. {
  636. if (is_numeric($amount)) {
  637. if (abs($cost) < 0.01) {
  638. $persentResult = '100%';
  639. } else {
  640. $persentResult = round(($amount / $cost) * 100, 2) . '%';
  641. }
  642. } else {
  643. $persentResult = '0%';
  644. }
  645. return $persentResult;
  646. }
  647. /**
  648. * @apiVersion 1.0.0
  649. * @apiDescription 更新派单星级数和备注
  650. * @api {POST} sendOrder/updateStarNumAndRemark 更新派单星级数和备注
  651. * @apiGroup sendOrder
  652. * @apiName updateStarNumAndRemark
  653. * @apiParam{Number} id 派单id.
  654. * @apiParam{Number} distribution_channel_id 渠道id.
  655. * @apiParam{Number} star_num 派单星级数
  656. * @apiParam{String} remark 派单备注
  657. * @apiSuccessExample {json} Success-Response:
  658. *
  659. * {
  660. * "code": 0,
  661. * "msg": "",
  662. * "data":[]
  663. * }
  664. */
  665. function updateStarNumAndRemark(Request $request)
  666. {
  667. $distribution_channel_id = $this->getChannelId();
  668. $id = $request->has('id') ? $request->input('id') : '';
  669. $remark = $request->has('remark') ? $request->input('remark') : '';
  670. $starNum = $request->has('star_num') ? $request->input('star_num') : '';
  671. if (empty($id) || empty($distribution_channel_id) || empty($starNum)) {
  672. return response()->error("PARAM_EMPTY");
  673. }
  674. if (!is_numeric($starNum)) {
  675. return response()->error("PARAM_ERROR");
  676. }
  677. $data = SendOrderService::updateStarNumAndRemark($id, $distribution_channel_id, $starNum, $remark);
  678. if ($data) {
  679. return response()->success();
  680. }
  681. return response()->error("HANDLE_FAILED");
  682. }
  683. /**
  684. * @apiVersion 1.0.0
  685. * @apiDescription 生成一个章节内容的派单
  686. * @api {POST} sendOrder/createFromChapter 生成一个章节内容的派单
  687. * @apiGroup sendOrder
  688. * @apiName createFromChapter
  689. * @apiParam {String} name 派单渠道名称.
  690. * @apiParam{Number} cost 成本.
  691. * @apiParam {String} distribution_channel_id 渠道id
  692. * @apiParam {String} channel_type 派单渠道类型.(允许值: AUTHENTICATED, UNAUTHENTICATED)
  693. * @apiParam {String} book_id 书本id
  694. * @apiParam {String} promotion_type 推广类型[INTERVAL、EXTERVAL]. 内部、外部
  695. * @apiParam {String} book_name 书本名称
  696. * @apiParam {String} chapter_id 章节id
  697. * @apiParam {String} qr_code_id 二维码id.
  698. * @apiParam {String} chapter_name 章节名称
  699. * @apiParam {String} headline_id 推广标题id
  700. * @apiParam {String} body_template_id 内容模板id
  701. * @apiParam {String} document_cover_id 文案封面id
  702. * @apiParam {String} original_guide_id 原文引导ID.
  703. * @apiParam {String} subscribe_chapter_id 强制订阅章节id
  704. * @apiParam {String} subscribe_chapter_name 强制订阅章节名称
  705. * @apiParam {String} subscribe_chapter_seq 强制订阅章节序号
  706. * @apiParam {String} document_end_chapter_seq 最后章节序号
  707. * @apiParam {String} sex_preference 性别偏向
  708. * @apiParam{String} [promotion_point] 派单源 微信(默认)or浏览器(微信:1,浏览器:2)
  709. * @apiSuccess {Number} id 派单id
  710. * @apiSuccess {String} promotion_url 推广链接
  711. * @apiSuccess {String} name 派单名称
  712. * @apiSuccessExample {json} Success-Response:
  713. *
  714. * {
  715. * "code": 0,
  716. * "msg": "",
  717. * "data":{"id":5,"promotion_url":"http:\/\/www . xs . com\/promotion\/index\/123456","name":"派单名称"}
  718. * }
  719. */
  720. function createFromChapter(Request $request)
  721. {
  722. $distribution_channel_id = $this->getChannelId();
  723. $name = $request->has('name') ? $request->input('name') : '';
  724. $promotion_type = $request->has('promotion_type') ? $request->input('promotion_type') : '';
  725. $cost = $request->has('cost') ? $request->input('cost') : 0;
  726. $book_id = $request->has('book_id') ? $request->input('book_id') : '';
  727. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  728. $chapter_id = $request->has('chapter_id') ? $request->input('chapter_id') : '';
  729. $qr_code_id = $request->has('qr_code_id') ? $request->input('qr_code_id') : '';
  730. $headline_id = $request->has('headline_id') ? $request->input('headline_id') : '';
  731. $chapter_name = $request->has('chapter_name') ? $request->input('chapter_name') : '';
  732. $channel_type = $request->has('channel_type') ? $request->input('channel_type') : '';
  733. $sex_preference = $request->has('sex_preference') ? $request->input('sex_preference') : '';
  734. $body_template_id = $request->has('body_template_id') ? $request->input('body_template_id') : '';
  735. $document_cover_id = $request->has('document_cover_id') ? $request->input('document_cover_id') : '';
  736. $original_guide_id = $request->has('original_guide_id') ? $request->input('original_guide_id') : '';
  737. $subscribe_chapter_id = $request->has('subscribe_chapter_id') ? $request->input('subscribe_chapter_id') : '';
  738. $subscribe_chapter_seq = $request->has('subscribe_chapter_seq') ? $request->input('subscribe_chapter_seq') : '';
  739. $subscribe_chapter_name = $request->has('subscribe_chapter_name') ? $request->input('subscribe_chapter_name') : '';
  740. $document_end_chapter_seq = $request->has('document_end_chapter_seq') ? $request->input('document_end_chapter_seq') : '';
  741. if (!$name || !$channel_type || !$promotion_type || !$book_id || !$book_name || !$sex_preference || !$document_end_chapter_seq || !$chapter_id || !$chapter_name || !$original_guide_id || !$headline_id || !$body_template_id || !$document_cover_id || !$document_cover_id || !$subscribe_chapter_id || !$subscribe_chapter_name || !$subscribe_chapter_seq) return response()->error('PARAM_EMPTY');
  742. if (empty($qr_code_id)) {
  743. $qr_code_id = 0;
  744. }
  745. $promotion_point = $request->has('promotion_point') ? $request->input('promotion_point') : 1;
  746. if (!in_array($promotion_point, [1, 2])) {
  747. $promotion_point = 1;
  748. }
  749. $redirect_url = "/reader?bid={$book_id}&cid={$chapter_id}";
  750. $book_id = Hashids::decode($book_id)[0];
  751. if ($book_id == 2423 && time() >= strtotime('2018-10-10 00:00:00') && time() <= strtotime('2018-10-15 00:00:00')) {
  752. return response()->error('CONTENT_MAINTAIN');
  753. }
  754. if ($promotion_point == 2) {
  755. $domain = 'leyuee.com';
  756. } else {
  757. $domain = $this->getDomainByBid($book_id);
  758. }
  759. $charge_type = $this->getBookChargeTypeByBid($book_id);
  760. $sendOrder = SendOrderService::createFromChapter(compact('name', 'channel_type', 'promotion_type', 'charge_type', 'cost', 'qr_code_id', 'domain', 'sex_preference', 'book_id', 'book_name', 'chapter_id', 'chapter_name', 'document_end_chapter_seq', 'original_guide_id', 'headline_id', 'body_template_id', 'document_cover_id', 'subscribe_chapter_id', 'subscribe_chapter_name', 'subscribe_chapter_seq', 'distribution_channel_id', 'redirect_url', 'promotion_point'));
  761. if ($promotion_point == 2) {
  762. $promotion_url = 'https://bsite' . encodeDistributionChannelId($distribution_channel_id) . '.leyuee.com/yun/' . $sendOrder->id;
  763. } else {
  764. $promotion_url = 'https://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . $this->getDomainByBid($book_id) . '/yun/' . $sendOrder->id;
  765. }
  766. return response()->success(['id' => $sendOrder->id, 'promotion_url' => $promotion_url, 'name' => $name]);
  767. }
  768. /**
  769. * 通过推广模板图片生成
  770. * @param Request $request
  771. * @return mixed
  772. */
  773. function createFromPromotionImageTemplate(Request $request)
  774. {
  775. $distribution_channel_id = $this->getChannelId();
  776. $book_id = $request->has('book_id') ? $request->input('book_id') : '';
  777. $cost = $request->has('cost') ? $request->input('cost') : '';
  778. $name = $request->has('name') ? $request->input('name') : '';
  779. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  780. $promotion_point = $request->has('promotion_point') ? $request->input('promotion_point') : '';
  781. $promotion_type = $request->has('promotion_type') ? $request->input('promotion_type') : '';
  782. $channel_type = $request->has('channel_type') ? $request->input('channel_type') : '';
  783. $chapter_name = $request->has('chapter_name') ? $request->input('chapter_name') : '';
  784. $chapter_id = $request->has('chapter_id') ? $request->input('chapter_id') : '';
  785. $headline_id = $request->has('headline_id') ? $request->input('headline_id') : ''; //标题
  786. $image_id = $request->has('template_image_id') ? $request->input('template_image_id') : ''; //模板图片id
  787. $original_guide_id = $request->has('original_guide_id') ? $request->input('original_guide_id') : ''; //原文引导
  788. $subscribe_chapter_seq = $request->has('subscribe_chapter_seq') ? $request->input('subscribe_chapter_seq') : '';
  789. $subscribe_chapter_name = $request->has('subscribe_chapter_name') ? $request->input('subscribe_chapter_name') : '';
  790. $subscribe_chapter_id = $request->has('subscribe_chapter_id') ? $request->input('subscribe_chapter_id') : '';
  791. // 文案标题,推广图模板,原文引导,推广图模式
  792. $redirect_url = "/reader?bid={$book_id}&cid={$chapter_id}";
  793. $book_id = Hashids::decode($book_id)[0];
  794. $domain = $this->getDomainByBid($book_id);
  795. $charge_type = $this->getBookChargeTypeByBid($book_id);
  796. if ($book_id == 2423 && time() >= strtotime('2018-10-10 00:00:00') && time() <= strtotime('2018-10-15 00:00:00')) {
  797. return response()->error('CONTENT_MAINTAIN');
  798. }
  799. if (!$headline_id || !$original_guide_id || !$image_id || !$chapter_name || !$book_id || !$subscribe_chapter_id || !$subscribe_chapter_name || !$subscribe_chapter_seq || !$chapter_id || !$channel_type || !$promotion_type || !$name || !$promotion_point || !$book_name) {
  800. return response()->error('PARAM_EMPTY');
  801. } else {
  802. $sendOrder = SendOrderService::createFromChapter(compact('book_id', 'book_name', 'subscribe_chapter_seq', 'subscribe_chapter_name', 'subscribe_chapter_id', 'chapter_name', 'promotion_type', 'promotion_point', 'name', 'cost', 'channel_type', 'headline_id', 'original_guide_id', 'chapter_id', 'charge_type', 'domain', 'distribution_channel_id', 'redirect_url'));
  803. $promotion_url = 'https://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . $this->getDomainByBid($book_id) . '/yun/' . $sendOrder->id;
  804. return response()->success(['id' => $sendOrder->id, 'promotion_url' => $promotion_url]);
  805. }
  806. }
  807. /**
  808. * 根据图书id获取图书的收费类型
  809. * @param string $bid
  810. */
  811. function getBookChargeTypeByBid($bid = '')
  812. {
  813. $charge_type = '';
  814. $bookConfig = BookConfigService::getBookById($bid);
  815. if ($bookConfig) {
  816. $charge_type = $bookConfig->charge_type;
  817. }
  818. return $charge_type;
  819. }
  820. /**
  821. * @apiVersion 1.0.0
  822. * @apiDescription 生成目录中的章节的派单
  823. * @api {POST} sendOrder/createFromDirectory 生成一个目录的派单
  824. * @apiGroup sendOrder
  825. * @apiName createFromDirectory
  826. * @apiParam {String} name 派单渠道名称.
  827. * @apiParam{Number} cost 成本.
  828. * @apiParam {String} channel_type 派单渠道类型.(允许值: AUTHENTICATED, UNAUTHENTICATED)
  829. * @apiParam {String} book_id 书本id
  830. * @apiParam {String} promotion_type 推广类型[INTERVAL、EXTERVAL]. 内部、外部
  831. * @apiParam {String} qr_code_id 二维码id.
  832. * @apiParam {String} book_name 书本名称
  833. * @apiParam {String} chapter_id 章节id
  834. * @apiParam {String} chapter_name 章节名称
  835. * @apiParam {String} subscribe_chapter_id 强制订阅章节id
  836. * @apiParam {String} subscribe_chapter_name 强制订阅章节名称
  837. * @apiParam {String} subscribe_chapter_seq 强制订阅章节序号
  838. * @apiParam{String} [promotion_point] 派单源 微信(默认)or浏览器(微信:1,浏览器:2)
  839. * @apiSuccess {Number} id 派单id
  840. * @apiSuccess {String} promotion_url 推广链接
  841. * @apiSuccess {String} name 派单名称
  842. * @apiSuccessExample {json} Success-Response:
  843. *
  844. * {
  845. * "code": 0,
  846. * "msg": "",
  847. * "data":{"id":5,"promotion_url":"http:\/\/www . xs . com\/promotion\/index\/123456","name":"派单名称"}
  848. * }
  849. */
  850. function createFromDirectory(Request $request)
  851. {
  852. $distribution_channel_id = $this->getChannelId();
  853. $name = $request->has('name') ? $request->input('name') : '';
  854. $cost = $request->has('cost') ? $request->input('cost') : 0;
  855. $book_id = $request->has('book_id') ? $request->input('book_id') : '';
  856. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  857. $chapter_id = $request->has('chapter_id') ? $request->input('chapter_id') : '';
  858. $qr_code_id = $request->has('qr_code_id') ? $request->input('qr_code_id') : '';
  859. $chapter_name = $request->has('chapter_name') ? $request->input('chapter_name') : '';
  860. $channel_type = $request->has('channel_type') ? $request->input('channel_type') : '';
  861. $promotion_type = $request->has('promotion_type') ? $request->input('promotion_type') : '';
  862. $subscribe_chapter_id = $request->has('subscribe_chapter_id') ? $request->input('subscribe_chapter_id') : '';
  863. $subscribe_chapter_seq = $request->has('subscribe_chapter_seq') ? $request->input('subscribe_chapter_seq') : '';
  864. $subscribe_chapter_name = $request->has('subscribe_chapter_name') ? $request->input('subscribe_chapter_name') : '';
  865. $promotion_point = $request->has('promotion_point') ? $request->input('promotion_point') : 1;
  866. if (!in_array($promotion_point, [1, 2])) {
  867. $promotion_point = 1;
  868. }
  869. if (!$name || !$channel_type || !$promotion_type || !$book_id || !$book_name || !$chapter_id || !$chapter_name || !$subscribe_chapter_id || !$subscribe_chapter_seq || !$subscribe_chapter_name) return response()->error('PARAM_EMPTY');
  870. if (empty($qr_code_id)) {
  871. $qr_code_id = 0;
  872. }
  873. $redirect_url = "/reader?bid={$book_id}&cid={$chapter_id}";
  874. $book_id = Hashids::decode($book_id)[0];
  875. if ($book_id == 2423 && time() >= strtotime('2018-10-10 00:00:00') && time() <= strtotime('2018-10-15 00:00:00')) {
  876. return response()->error('CONTENT_MAINTAIN');
  877. }
  878. if ($promotion_point == 2) {
  879. $domain = 'leyuee.com';
  880. } else {
  881. $domain = $this->getDomainByBid($book_id);
  882. }
  883. $charge_type = $this->getBookChargeTypeByBid($book_id);
  884. $sendOrder = SendOrderService::createFromDirectory(compact(
  885. 'name',
  886. 'channel_type',
  887. 'promotion_type',
  888. 'charge_type',
  889. 'cost',
  890. 'domain',
  891. 'book_id',
  892. 'qr_code_id',
  893. 'book_name',
  894. 'chapter_id',
  895. 'subscribe_chapter_id',
  896. 'subscribe_chapter_name',
  897. 'subscribe_chapter_seq',
  898. 'chapter_name',
  899. 'distribution_channel_id',
  900. 'redirect_url',
  901. 'promotion_point'
  902. ));
  903. // $promotion_url = '/yun/' . $sendOrder->id;
  904. if ($promotion_point == 2) {
  905. $promotion_url = 'https://bsite' . encodeDistributionChannelId($distribution_channel_id) . '.leyuee.com/yun/' . $sendOrder->id;
  906. } else {
  907. $promotion_url = 'https://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . $this->getDomainByBid($book_id) . '/yun/' . $sendOrder->id;
  908. }
  909. return response()->success(['id' => $sendOrder->id, 'promotion_url' => $promotion_url, 'name' => $name]);
  910. }
  911. function uploadSendOrders(Request $request)
  912. {
  913. if (!$request->hasFile('sendOrderFile')) {
  914. return response()->error('PARAM_EMPTY');
  915. }
  916. $qr_code_id = 0;
  917. $channel_type = 'AUTHENTICATED';
  918. $distribution_channel_id = $this->getChannelId();
  919. $file_name = date('YmdHis') . '.csv';
  920. $file = $request->file('sendOrderFile');
  921. if (null != $file) {
  922. $path = $request->sendOrderFile->storeAs('sendorder', $file_name);
  923. $path = storage_path('app/' . $path);
  924. header("Content-type:application/vnd.ms-excel");
  925. header("Content-Disposition:attachment;filename=" . "派单信息" . date("YmdHis") . ".csv");
  926. echo mb_convert_encoding("\"派单id\",\"渠道名称\",\"成本\",\"预计发送时间\",\"粉丝数\",\"图书名称\",\"图书id\",\"原文链接章节\",\"内外部\",\"公司名称\",\"代理商名称\",\"代理商介绍\",\"原文链接\"\r\n", 'GBK', 'UTF-8');
  927. $file = fopen($path, "r");
  928. //遍历读取每一行数据
  929. $currentIndex = 0;
  930. while ($data = fgetcsv($file)) {
  931. \Log::info($data);
  932. if (!$data[6]) continue;
  933. if ($currentIndex > 0) {
  934. $date = $this->getFormatDate($data[2]);
  935. $date = date('Y-m-d', strtotime($date));
  936. $data[2] = $date;
  937. $name = mb_convert_encoding(trim($data[0]), "UTF-8", "GBK") . '-' . +trim($data[1]) . '-' . trim($data[2]) . '-' . mb_convert_encoding(trim($data[3]), "UTF-8", "GBK");
  938. $cost = $data[4];
  939. $fan_num = (int)(trim($data[5]) * 10000);
  940. \Log::info($fan_num);
  941. $book_name = mb_convert_encoding(trim($data[6]), "UTF-8", "GBK");
  942. $book_id = trim($data[7]);
  943. $chapter_sqp = trim($data[8]);
  944. $reciver_promotion_type = mb_convert_encoding(trim($data[9]), "UTF-8", "GBK");
  945. $import_company_name = mb_convert_encoding(trim($data[10]), "UTF-8", "GBK");
  946. $agent_name = mb_convert_encoding(trim($data[11]), "UTF-8", "GBK");
  947. $agent_intro = mb_convert_encoding(trim($data[12]), "UTF-8", "GBK");
  948. $chapter = ChapterService::getChapterInfoByBidAndSeq($book_id, $chapter_sqp);
  949. $chapter_id = $chapter->id;
  950. $chapter_name = $chapter->name;
  951. $promotion_type = ($reciver_promotion_type == '内部') ? 'INTERNAL' : 'EXTERNAL';
  952. $domain = $this->getDomainByBid($book_id);
  953. $charge_type = $this->getBookChargeTypeByBid($book_id);
  954. $book_id = Hashids::encode($book_id);
  955. $redirect_url = "/reader?bid=$book_id&cid=$chapter_id";
  956. $book_id = Hashids::decode($book_id)[0];
  957. if (!$name || !$channel_type || !$promotion_type || !$book_id || !$book_name || !$chapter_id || !$chapter_name || !$import_company_name || !$fan_num) {
  958. return response()->error('PARAM_EMPTY');
  959. }
  960. $pre_send_date = $date;
  961. $sendOrder = SendOrderService::createFromDirectory(compact('name', 'channel_type', 'promotion_type', 'pre_send_date', 'import_company_name', 'fan_num', 'charge_type', 'cost', 'domain', 'book_id', 'qr_code_id', 'book_name', 'chapter_id', 'chapter_name', 'distribution_channel_id', 'redirect_url'));
  962. $promotion_url = 'https://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . $this->getDomainByBid($book_id) . '/yun/' . $sendOrder->id;
  963. $send_order_id = $sendOrder->id;
  964. if ($agent_name && $agent_intro) {
  965. $created_at = date("Y-m-d H:i:s");
  966. $updated_at = date("Y-m-d H:i:s");
  967. $params = compact('send_order_id', 'agent_name', 'agent_intro', 'created_at', 'updated_at');
  968. DB::table('agent_info')->insert($params);
  969. }
  970. echo("\"" . $sendOrder->id . "\",");
  971. echo("\"" . mb_convert_encoding($name, "GBK", "UTF-8") . "\",");
  972. echo("\"" . $cost . "\",");
  973. echo("\"" . date('Y/m/d', strtotime($date)) . "\",");
  974. echo("\"" . $fan_num . "\",");
  975. echo("\"" . mb_convert_encoding($book_name, "GBK", "UTF-8") . "\",");
  976. echo("\"" . mb_convert_encoding($book_id, "GBK", "UTF-8") . "\",");
  977. echo("\"" . $chapter_id . "\",");
  978. echo("\"" . mb_convert_encoding($reciver_promotion_type, "GBK", "UTF-8") . "\",");
  979. echo("\"" . mb_convert_encoding($import_company_name, "GBK", "UTF-8") . "\",");
  980. echo("\"" . mb_convert_encoding($agent_name ? $agent_name : "未知", "GBK", "UTF-8") . "\",");
  981. echo("\"" . mb_convert_encoding($agent_intro ? $agent_intro : "未知", "GBK", "UTF-8") . "\",");
  982. echo("\"" . $promotion_url . "\"\r\n");
  983. }
  984. $currentIndex++;
  985. }
  986. }
  987. exit();
  988. }
  989. /**
  990. * @apiVersion 1.0.0
  991. * @apiDescription 生成一个页面推广的派单
  992. * @api {POST} sendOrder/createFromPage 生成一个页面推广的派单
  993. * @apiGroup sendOrder
  994. * @apiName createFromPage
  995. * @apiParam{Number} cost 成本.
  996. * @apiParam{String} name 派单渠道名称.
  997. * @apiParam{String} promotion_type 推广类型[INTERVAL、EXTERVAL]. 内部、外部
  998. * @apiParam{String} qr_code_id 二维码id.
  999. * @apiParam{String} channel_type 派单渠道类型.(允许值: AUTHENTICATED, UNAUTHENTICATED)
  1000. * @apiParam{String} page_id 页面ID
  1001. * @apiParam{String} [promotion_point] 派单源 微信(默认)or浏览器(微信:1,浏览器:2)
  1002. * @apiSuccess {Number} id 派单id
  1003. * @apiSuccess {String} promotion_url 推广链接
  1004. * @apiSuccess {String} name 派单名称
  1005. * @apiSuccessExample {json} Success-Response:
  1006. *
  1007. * {
  1008. * "code": 0,
  1009. * "msg": "",
  1010. * "data":{"id":5,"promotion_url":"http:\/\/www . xs . com\/promotion\/index\/123456","name":"派单名称"}
  1011. * }
  1012. */
  1013. function createFromPage(Request $request)
  1014. {
  1015. $name = $request->has('name') ? $request->input('name') : '';
  1016. $cost = $request->has('cost') ? $request->input('cost') : 0;
  1017. $promotion_type = $request->has('promotion_type') ? $request->input('promotion_type') : '';
  1018. $page_id = $request->has('page_id') ? $request->input('page_id') : '';
  1019. $qr_code_id = $request->has('qr_code_id') ? $request->input('qr_code_id') : '';
  1020. $channel_type = $request->has('channel_type') ? $request->input('channel_type') : '';
  1021. $page = PromotionService::getById($page_id);
  1022. if (!$name || !$channel_type || !$page_id || !$page) return response()->error('PARAM_EMPTY');
  1023. if (empty($qr_code_id)) {
  1024. $qr_code_id = 0;
  1025. }
  1026. $promotion_point = $request->has('promotion_point') ? $request->input('promotion_point') : 1;
  1027. if (in_array($promotion_point, [1, 2])) {
  1028. $promotion_point = 1;
  1029. }
  1030. $entrance = $page->title;
  1031. $redirect_url = $page->link;
  1032. $distribution_channel_id = $this->getChannelId();
  1033. $domain = $this->getDomainByBid();
  1034. $sendOrder = SendOrderService::createFromPage(compact('name', 'channel_type', 'promotion_type', 'cost', 'qr_code_id', 'domain', 'page_id', 'entrance', 'distribution_channel_id', 'redirect_url', 'promotion_point'));
  1035. // $promotion_url = '/yun/' . $sendOrder->id;
  1036. if ($promotion_point == 2) {
  1037. $promotion_url = 'https://bsite' . encodeDistributionChannelId($distribution_channel_id) . '.leyuee.com/yun/' . $sendOrder->id;
  1038. } else {
  1039. $promotion_url = 'https://site' . encodeDistributionChannelId($distribution_channel_id) . '.leyuee.com/yun/' . $sendOrder->id;
  1040. }
  1041. //$promotion_url = 'https://'.$site . encodeDistributionChannelId($distribution_channel_id) . '.' . $this->getDomainByBid('') . '/yun/' . $sendOrder->id;
  1042. return response()->success(['id' => $sendOrder->id, 'promotion_url' => $promotion_url, 'name' => $name]);
  1043. }
  1044. /**
  1045. * @apiVersion 1.0.0
  1046. * @apiDescription 更新派单
  1047. * @api {POST} sendOrder/updateSendOrderInfo 更新派单
  1048. * @apiGroup sendOrder
  1049. * @apiName updateSendOrderInfo
  1050. * @apiParam {Number} id 派单id.
  1051. * @apiParam {String} name 派单名称
  1052. * @apiParam {Number} cost 派单成本
  1053. * @apiParam {String} channel_type 派单渠道类型.(允许值: AUTHENTICATED, UNAUTHENTICATED)
  1054. * @apiSuccessExample {json} Success-Response:
  1055. *
  1056. * {
  1057. * "code": 0,
  1058. * "msg": "",
  1059. * "data":[]
  1060. * }
  1061. */
  1062. function updateSendOrderInfo(Request $request)
  1063. {
  1064. $distribution_channel_id = $this->getChannelId();
  1065. $id = $request->has('id') ? $request->input('id') : '';
  1066. $name = $request->has('name') ? $request->input('name') : '';
  1067. $cost = $request->has('cost') ? $request->input('cost') : '';
  1068. $channel_type = $request->has('channel_type') ? $request->input('channel_type') : '';
  1069. $promotion_type = $request->has('promotion_type') ? $request->input('promotion_type') : '';
  1070. $subscribe_chapter_seq = $request->input('subscribe_chapter_seq', '');
  1071. if (empty($name) && empty($channel_type) && empty($cost) && empty($promotion_type)) {
  1072. return response()->error("PARAM_EMPTY");
  1073. }
  1074. $subscribe_chapter = [];
  1075. if ($subscribe_chapter_seq) {
  1076. $send_orders = SendOrderService::getById($id);
  1077. $bid = $send_orders->book_id;
  1078. $chapter_info = ChapterService::getChapterInfoByBidAndSeq($bid, $subscribe_chapter_seq);
  1079. if (!$chapter_info) {
  1080. return response()->error('PARAM_ERROR');
  1081. }
  1082. $subscribe_chapter_id = $chapter_info->id;
  1083. $subscribe_chapter['subscribe_chapter_id'] = $subscribe_chapter_id;
  1084. $subscribe_chapter['subscribe_chapter_seq'] = $subscribe_chapter_seq;
  1085. $subscribe_chapter['subscribe_chapter_name'] = $chapter_info->name;
  1086. }
  1087. $pre_send_date = null;
  1088. $send_order_export_special_channel = env('SEND_ORDER_EXPORT_SPECIAL_CHANNEL');
  1089. $isExistSpecialChannel = in_array($distribution_channel_id, explode(',', $send_order_export_special_channel));
  1090. if ($isExistSpecialChannel && $name && strpos($name, "-")) {
  1091. $strs = explode('-', $name);
  1092. if (count($strs) == 4) {
  1093. $date = $this->getFormatDate($strs[2]);
  1094. $date = date('Y-m-d', strtotime($date));
  1095. $pre_send_date = $date;
  1096. }
  1097. }
  1098. $data = SendOrderService::updateSendOrderInfo($id, $distribution_channel_id, $name, $pre_send_date, $channel_type, $cost, $promotion_type, $subscribe_chapter);
  1099. if ($data) {
  1100. return response()->success();
  1101. } else {
  1102. return response()->error("HANDLE_FAILED");
  1103. }
  1104. }
  1105. /**
  1106. * @apiVersion 1.0.0
  1107. * @apiDescription 删除派单
  1108. * @api {POST} sendOrder/removeSendOrder 删除派单
  1109. * @apiGroup sendOrder
  1110. * @apiName removeSendOrder
  1111. * @apiParam {Number} id 派单id.
  1112. * @apiSuccessExample {json} Success-Response:
  1113. *
  1114. * {
  1115. * "code": 0,
  1116. * "msg": "",
  1117. * "data":[]
  1118. * }
  1119. */
  1120. function removeSendOrder(Request $request)
  1121. {
  1122. $distribution_channel_id = $this->getChannelId();
  1123. $id = $request->has('id') ? $request->input('id') : '';
  1124. $data = SendOrderService::removeSendOrder($id, $distribution_channel_id);
  1125. if ($data) {
  1126. return response()->success();
  1127. } else {
  1128. return response()->error("HANDLE_FAILED");
  1129. }
  1130. }
  1131. /**
  1132. * @apiVersion 1.0.0
  1133. * @apiDescription 设置成本
  1134. * @api {POST} sendOrder/setCost 设置成本
  1135. * @apiGroup sendOrder
  1136. * @apiName setCost
  1137. * @apiParam{Number}id 派单id.
  1138. * @apiParam{Number}cost 成本.
  1139. * @apiSuccessExample {json} Success-Response:
  1140. *
  1141. * {
  1142. * "code": 0,
  1143. * "msg": "",
  1144. * "data":[]
  1145. * }
  1146. */
  1147. function setCost(Request $request)
  1148. {
  1149. $distribution_channel_id = $this->getChannelId();
  1150. $id = $request->has('id') ? $request->input('id') : '';
  1151. $cost = $request->has('cost') ? $request->input('cost') : '';
  1152. if (empty($id) || empty($cost)) {
  1153. return response()->error("PARAM_EMPTY");
  1154. }
  1155. if (!is_numeric($cost)) {
  1156. return response()->error("PARAM_ERROR");
  1157. }
  1158. $data = SendOrderService::setSendOrderCost($id, $distribution_channel_id, $cost);
  1159. if ($data) {
  1160. return response()->success(compact('cost'));
  1161. } else {
  1162. return response()->error("HANDLE_FAILED");
  1163. }
  1164. }
  1165. /**
  1166. * 匹配原文链接
  1167. * @param Request $request
  1168. */
  1169. static function checkOriginUrl(Request $request)
  1170. {
  1171. if (!$request->hasFile('orginUrlFile')) {
  1172. return response()->error('PARAM_EMPTY');
  1173. }
  1174. $file_name = date('YmdHis') . '.csv';
  1175. $file = $request->file('orginUrlFile');
  1176. if (null != $file) {
  1177. $path = $request->orginUrlFile->storeAs('orginUrl', $file_name);
  1178. $path = storage_path('app/' . $path);
  1179. header("Content-type:application/vnd.ms-excel");
  1180. header("Content-Disposition:attachment;filename=" . "原文链接" . date("YmdHis") . ".csv");
  1181. echo mb_convert_encoding("\"公众号\",\"正确原文链接\",\"预览图文链接\",\"链接中解析到的url\",\"是否匹配\"\r\n", 'GBK', 'UTF-8');
  1182. $file = fopen($path, "r");
  1183. //遍历读取每一行数据
  1184. $currentIndex = 0;
  1185. while ($data = fgetcsv($file)) {
  1186. \Log::info('data---1:' . json_encode($data));
  1187. if (!$data[0] || !$data[1] || !$data[2]) continue;
  1188. if ($currentIndex > 0) {
  1189. \Log::info('data---2:' . $data[2]);
  1190. $data[2] = str_replace('https', 'http', $data[2]);
  1191. $data[2] = str_replace('http', 'https', $data[2]);
  1192. $content = ChannelService::getContentByUrl($data[2]);
  1193. \Log::info($content);
  1194. $searchUrl = '';
  1195. $findStrEnd = ';';
  1196. $findStrBegin = 'msg_source_url =';
  1197. //解析页面中的msg_source_url的内容
  1198. $startIndex = strpos($content, $findStrBegin);
  1199. if ($startIndex > 0) {
  1200. \Log::info('开始进入了');
  1201. $endIndex = strpos($content, $findStrEnd, $startIndex);
  1202. if ($endIndex > $startIndex) {
  1203. $startIndex = $startIndex + strlen($findStrBegin) + 2;
  1204. $searchUrl = substr($content, $startIndex, $endIndex - $startIndex - 1);
  1205. }
  1206. //判断解析到的msg_source_url是否加密
  1207. \Log::info($searchUrl);
  1208. $url_items = parse_url($searchUrl);
  1209. \Log::info($url_items);
  1210. $distribution_channel_id = str_replace('site', '', explode('.', $url_items['host'])[0]);
  1211. if (!is_numeric($distribution_channel_id)) {
  1212. $deal_distribution_channel_id = decodeDistributionChannelId($distribution_channel_id);
  1213. //需要解密
  1214. $searchUrl = str_replace('site' . $distribution_channel_id, 'site' . $deal_distribution_channel_id, $searchUrl);
  1215. }
  1216. }
  1217. //判断上传的url是否加密
  1218. $deal_url = $data[1];
  1219. $url_items = parse_url($deal_url);
  1220. $distribution_channel_id = str_replace('site', '', explode('.', $url_items['host'])[0]);
  1221. //需要解密
  1222. if (!is_numeric($distribution_channel_id)) {
  1223. $deal_distribution_channel_id = decodeDistributionChannelId($distribution_channel_id);
  1224. $deal_url = str_replace('site' . $distribution_channel_id, 'site' . $deal_distribution_channel_id, $deal_url);
  1225. }
  1226. $isMatch = ($searchUrl == $deal_url) ? '匹配' : '不匹配';
  1227. $data[0] = mb_convert_encoding(trim($data[0]), "UTF-8", "GBK");
  1228. echo("\"" . mb_convert_encoding($data[0], "GBK", "UTF-8") . "\",");
  1229. echo("\"" . mb_convert_encoding($data[1], "GBK", "UTF-8") . "\",");
  1230. echo("\"" . mb_convert_encoding($data[2], "GBK", "UTF-8") . "\",");
  1231. echo("\"" . mb_convert_encoding($searchUrl ? $searchUrl : '未找到', "GBK", "UTF-8") . "\",");
  1232. echo("\"" . mb_convert_encoding($isMatch, "GBK", "UTF-8") . "\"\r\n");
  1233. }
  1234. $currentIndex++;
  1235. }
  1236. }
  1237. exit();
  1238. }
  1239. /**
  1240. * 加密、解密原文链接
  1241. * @param Request $request
  1242. */
  1243. function decryptOrEncrptOriginUrl(Request $request)
  1244. {
  1245. $originUrl = $request->has('origin_url') ? $request->input('origin_url') : '';
  1246. if (empty($originUrl)) {
  1247. return response()->error("PARAM_EMPTY");
  1248. }
  1249. $url_items = parse_url($originUrl);
  1250. $distribution_channel_id = str_replace('site', '', explode('.', $url_items['host'])[0]);
  1251. //需要加密
  1252. if (is_numeric($distribution_channel_id)) {
  1253. $deal_distribution_channel_id = encodeDistributionChannelId($distribution_channel_id);
  1254. //需要解密
  1255. } else {
  1256. $deal_distribution_channel_id = decodeDistributionChannelId($distribution_channel_id);
  1257. }
  1258. $originUrl = str_replace('site' . $distribution_channel_id, 'site' . $deal_distribution_channel_id, $originUrl);
  1259. return response()->success(['originUrl' => $originUrl]);
  1260. }
  1261. }