CustomMsgController.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. <?php
  2. namespace App\Http\Controllers\Channel\OfficialAccount;
  3. use App\Http\Controllers\Channel\BaseController as ChannelBaseController;
  4. use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomMsgControllerTransformer;
  5. use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomMsgSwitchMultyTransformer;
  6. use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomMsgSwitchTransformer;
  7. use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomSendMsgsTransformers;
  8. use App\Http\Controllers\Channel\OfficialAccount\Transformers\OfficialImgtextUrlsTransformer;
  9. use App\Http\Controllers\Channel\Promotion\Transformers\DocumentCoversTransformer;
  10. use App\Http\Controllers\Channel\Promotion\Transformers\HeadlinelTransformer;
  11. use App\Modules\Statistic\Services\WapVisitStatService;
  12. use App\Modules\OfficialAccount\Services\CustomMsgService;
  13. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  14. use App\Modules\Promotion\Services\PromotionService;
  15. use GuzzleHttp\Client;
  16. use Illuminate\Http\Request;
  17. use OSS\Core\OssException;
  18. use OSS\OssClient;
  19. class CustomMsgController extends ChannelBaseController
  20. {
  21. /**
  22. * @apiDefine OfficialAccount 公众号
  23. */
  24. /**
  25. * @apiVersion 1.0.0
  26. * @api {GET} OfficialAccount/customerImgUrlByChannelId 渠道下获取客服图片
  27. * @apiGroup OfficialAccount
  28. * @apiName customerImgUrlByChannelId
  29. * @apiSuccess {String} customer_img_url 客服图片.
  30. * @apiSuccessExample {json} Success-Response:
  31. *
  32. * {
  33. * "code": 0,
  34. * "msg": "",
  35. * "data": []
  36. * }
  37. */
  38. function customerImgUrlByChannelId(Request $request)
  39. {
  40. $distribution_channel_id = $this->getChannelId();
  41. $distributionChannelSetting = CustomMsgService::customerImgUrlByChannelId($distribution_channel_id);
  42. if (!empty($distributionChannelSetting)) {
  43. # code...
  44. return response()->item(new CustomMsgControllerTransformer(), $distributionChannelSetting);
  45. } else {
  46. return response()->success(['data' => 0]);
  47. }
  48. }
  49. /**
  50. * @apiVersion 1.0.0
  51. * @api {GET} OfficialAccount/uploadCustomerImgUrl 上传客服图片至OSS
  52. * @apiGroup OfficialAccount
  53. * @apiName uploadCustomerImgUrl
  54. * @apiParam {String} customer_img_url 事件类型.
  55. * @apiSuccess {String} customer_img_url 客服图片.
  56. * @apiSuccessExample {json} Success-Response:
  57. *
  58. * {
  59. * "code": 0,
  60. * "msg": "",
  61. * "data": []
  62. * }
  63. */
  64. function uploadCustomerImgUrl(Request $request)
  65. {
  66. $distribution_channel_id = $this->getChannelId();
  67. if ($request->hasFile('photo')) {
  68. $file = $request->file('photo');
  69. // array:15 [▼
  70. // "server" => "AliyunOSS"
  71. // "date" => "Fri, 15 Dec 2017 10:03:12 GMT"
  72. // "content-length" => "0"
  73. // "connection" => "keep-alive"
  74. // "x-oss-request-id" => "5A339DDF12058D9711FE3BDE"
  75. // "etag" => ""874C0E0C357FBC3BE12404389D17A742""
  76. // "x-oss-hash-crc64ecma" => "12762020141128995984"
  77. // "content-md5" => "h0wODDV/vDvhJAQ4nRenQg=="
  78. // "x-oss-server-time" => "12"
  79. // "info" => array:27 [▶]
  80. // "oss-request-url" => "http://yueduyun.oss-cn-hangzhou.aliyuncs.com/service/customimage_1_1513332191.WechatIMG77.jpeg"
  81. // "oss-redirects" => 0
  82. // "oss-stringtosign" => """
  83. // PUT\n
  84. // \n
  85. // image/jpeg\n
  86. // Fri, 15 Dec 2017 10:03:11 GMT\n
  87. // /yueduyun/service/customimage_1_1513332191.WechatIMG77.jpeg
  88. // """
  89. // "oss-requestheaders" => array:5 [▶]
  90. // "body" => ""
  91. // ]
  92. $ossImgBackData = $this->ossObject()->uploadFile(env('OSS_BUCKET', 'zhuishuyun'), 'service/customimage_' . $distribution_channel_id . '_' . time() . '.' . $file->getClientOriginalName(), $file->path());
  93. $ossImg = $ossImgBackData['oss-request-url'];
  94. $customerImgPram['distribution_channel_id'] = $distribution_channel_id;
  95. $customerImgPram['customer_img_url'] = $ossImg;
  96. $sustomMsgService = CustomMsgService::updateCustomerImgUrl($customerImgPram);
  97. return response()->item(new CustomMsgControllerTransformer(), $sustomMsgService);
  98. }
  99. }
  100. /**
  101. * OSS文件操作
  102. */
  103. function ossObject()
  104. {
  105. $accessKeyId = env('OSS_ACCESS_ID');
  106. $accessKeySecret = env('OSS_ACCESS_KEY');
  107. $endpoint = env('OSS_END_POINT');
  108. $ossClient = null;
  109. try {
  110. $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
  111. } catch (OssException $e) {
  112. return null;
  113. }
  114. return $ossClient;
  115. }
  116. //-------------------------------------------------客服消息配置开关Start---------------------------CustomMsgSwitchs
  117. /**
  118. * @apiVersion 1.0.0
  119. * @api {GET} OfficialAccount/customMsgSwitchSetting 客服消息开关设置
  120. * @apiGroup OfficialAccount
  121. * @apiName customMsgSwitchSetting
  122. * @apiParam {String} custom_category 客服消息类别.
  123. * @apiParam {String} status 客服消息状态 1:开,2:关.
  124. * @apiSuccessExample {json} Success-Response:
  125. *
  126. * {
  127. * "code": 0,
  128. * "msg": "",
  129. * "data": []
  130. * }
  131. */
  132. function customMsgSwitchSetting(Request $request)
  133. {
  134. $distribution_channel_id = $this->getChannelId();
  135. $custom_category = $request->has('custom_category') ? $request->input('custom_category') : '';
  136. if (empty($custom_category)) {
  137. return response()->error("PARAM_EMPTY");
  138. }
  139. $status = $request->has('status') ? $request->input('status') : '';
  140. if (empty($status)) {
  141. return response()->error("PARAM_EMPTY");
  142. }
  143. $is_self_content = $request->has('is_self_content') ? $request->input('is_self_content') : '0';
  144. $customMsgService = CustomMsgService::customMsgSwitchSetting($distribution_channel_id, $custom_category, $status, $is_self_content);
  145. if ($customMsgService == 1) {
  146. return response()->success();
  147. } elseif ($customMsgService == 2) {
  148. return response()->error('CUSTOMS_SETTING_FAILED');
  149. } elseif ($customMsgService == 0) {
  150. return response()->error('HAS_NO_CUSTOMS');
  151. } else {
  152. return response()->error('CUSTOMS_SETTING_FAILED');
  153. }
  154. }
  155. /**
  156. * @apiVersion 1.0.0
  157. * @api {GET} OfficialAccount/customMsgSwitchsByChannelId 客服消息开关列表获取
  158. * @apiGroup OfficialAccount
  159. * @apiName customMsgSwitchsByChannelId
  160. * @apiSuccessExample {json} Success-Response:
  161. *
  162. * {
  163. * "code": 0,
  164. * "msg": "",
  165. * "data": [
  166. * {
  167. * "title": "未支付提醒",
  168. * "custom_category": "not_pay",
  169. * "status": "1",
  170. * "distribution_channel_id": 1,
  171. * "id": 1
  172. * },
  173. * {
  174. * "title": "定制书籍推送",
  175. * "custom_category": "point_push",
  176. * "status": "0",
  177. * "distribution_channel_id": 1,
  178. * "id": 2
  179. * },
  180. * {
  181. * "title": "热门书籍推送",
  182. * "custom_category": "hot_push",
  183. * "status": "1",
  184. * "distribution_channel_id": 1,
  185. * "id": 3
  186. * }
  187. * ]
  188. * }
  189. */
  190. function customMsgSwitchsByChannelId(Request $request)
  191. {
  192. $distribution_channel_id = $this->getChannelId();
  193. $customMsgService = CustomMsgService::customMsgSwitchsByChannelId($distribution_channel_id);
  194. if (!empty($customMsgService)) {
  195. return response()->collection(new CustomMsgSwitchMultyTransformer(), $customMsgService);
  196. } else {
  197. return response()->success(['data' => 0]);
  198. }
  199. }
  200. /**
  201. * @apiVersion 1.0.0
  202. * @api {GET} OfficialAccount/customMsgSwitchsByChannelCate 获取指定客服消息开关
  203. * @apiGroup OfficialAccount
  204. * @apiParam {String} custom_category 客服消息类别.
  205. * @apiName customMsgSwitchsByChannelCate
  206. * @apiSuccessExample {json} Success-Response:
  207. *
  208. * {
  209. * "code": 0,
  210. * "msg": "",
  211. * "data": {
  212. * "title": "热门书籍推送",
  213. * "custom_category": "hot_push",
  214. * "status": "1",
  215. * "distribution_channel_id": 1,
  216. * "id": 3
  217. * }
  218. * }
  219. */
  220. function customMsgSwitchsByChannelCate(Request $request)
  221. {
  222. $distribution_channel_id = $this->getChannelId();
  223. $custom_category = $request->has('custom_category') ? $request->input('custom_category') : '';
  224. if (empty($custom_category)) {
  225. return response()->error("PARAM_EMPTY");
  226. }
  227. $customMsgService = CustomMsgService::customMsgSwitchsByChannelCate($distribution_channel_id, $custom_category);
  228. if (!empty($customMsgService)) {
  229. return response()->item(new CustomMsgSwitchTransformer(), $customMsgService);
  230. } else {
  231. return response()->success(['data' => 0]);
  232. }
  233. }
  234. //-------------------------------------------------客服消息配置开关End---------------------------CustomMsgSwitchs
  235. //-------------------------------------------------编辑发送客服消息Start---------------------------CustomSendMsg
  236. /**
  237. * @apiVersion 1.0.0
  238. * @api {GET} OfficialAccount/customSendMsgsByChannelId 发送客服消息列表获取
  239. * @apiGroup OfficialAccount
  240. * @apiName customSendMsgsByChannelId
  241. * @apiSuccessExample {json} Success-Response:
  242. *
  243. * {
  244. * "code": 0,
  245. * "msg": "",
  246. * "data": [
  247. * {
  248. * "id": 2,
  249. * "name": "测试222",
  250. * "send_time": "2017-12-26 11:11:11",
  251. * "content": "横眉冷对千夫指,俯首甘为孺子牛",
  252. * "redirect_url": "http:\/\/www.baidu.com\/what?am=1",
  253. * "status": null,
  254. * "distribution_channel_id": 1,
  255. * "subscribe_time": "z",
  256. * "sex": "z",
  257. * "balance": "z",
  258. * "order_type": "z",
  259. * "category_id": "z"
  260. * },
  261. * {
  262. * "id": 1,
  263. * "name": "测试111",
  264. * "send_time": "2017-12-26 11:11:11",
  265. * "content": "横眉冷对千夫指,俯首甘为孺子牛",
  266. * "redirect_url": "http:\/\/www.baidu.com\/yes?en",
  267. * "status": null,
  268. * "distribution_channel_id": 1,
  269. * "subscribe_time": "z",
  270. * "sex": "z",
  271. * "balance": "z",
  272. * "order_type": "z",
  273. * "category_id": "z"
  274. * }
  275. * ]
  276. * }
  277. */
  278. function customSendMsgsByChannelId(Request $request)
  279. {
  280. $distribution_channel_id = $this->getChannelId();
  281. $customMsgServices = CustomMsgService::customSendMsgsByChannelId($distribution_channel_id);
  282. if (!empty($customMsgServices)) {
  283. foreach($customMsgServices as $key=>$customMsgService){
  284. if($customMsgService->is_full_send){
  285. $customMsgServices[$key]->user_category = '服务号全量用户';
  286. }elseif($customMsgService->subscribe_time == 'z' &&
  287. $customMsgService->sex == 'z' &&
  288. $customMsgService->balance == 'z' &&
  289. $customMsgService->order_type == 'z' &&
  290. $customMsgService->category_id == 'z' ){
  291. $customMsgServices[$key]->user_category = '追书云全部用户';
  292. }else{
  293. $customMsgServices[$key]->user_category = '追书云标签用户';
  294. }
  295. }
  296. return response()->pagination(new CustomSendMsgsTransformers(), $customMsgServices);
  297. } else {
  298. return response()->success(['data' => 0]);
  299. }
  300. }
  301. function searchCustomSendMsgs(Request $request)
  302. {
  303. \Log::info('searchCustomSendMsgs_start');
  304. $start_time = $request->has('start_time') ? $request->input('start_time') : '';
  305. $end_time = $request->has('end_time') ? $request->input('end_time') : '';
  306. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  307. $task_name = $request->has('task_name') ? $request->input('task_name') : '';
  308. if ($start_time < '2018-11-02') {
  309. \Log::info('searchCustomSendMsgs,update_start_time:' . $start_time);
  310. $start_time = '2018-11-02';
  311. }
  312. $distribution_channel_id = $this->getChannelId();
  313. $param = [
  314. 'distribution_channel_id' => $distribution_channel_id,
  315. 'start_time' => $start_time,
  316. 'end_time' => $end_time,
  317. 'book_name' => $book_name,
  318. 'task_name' => $task_name
  319. ];
  320. $customMsgServices = CustomMsgService::searchCustomSendMsgs($param, false);
  321. if (!empty($customMsgServices)) {
  322. foreach ($customMsgServices as $key => $customMsgService) {
  323. $fromtype = 'custom_' . $customMsgService->id;
  324. $statistics = WapVisitStatService::innerCustomerAllStats($fromtype);
  325. $customMsgServices[$key]->uv = isset($statistics['uv']) ? $statistics['uv'] : '';
  326. $customMsgServices[$key]->pv = isset($statistics['pv']) ? $statistics['pv'] : '';
  327. $customMsgServices[$key]->register_user_num = isset($statistics['register_user_num']) ? $statistics['register_user_num'] : '';
  328. $customMsgServices[$key]->pay_user_num = isset($statistics['pay_user_num']) ? $statistics['pay_user_num'] : '';
  329. $customMsgServices[$key]->charge_amount = isset($statistics['charge_amount']) ? $statistics['charge_amount'] : '';
  330. }
  331. return response()->pagination(new CustomSendMsgsTransformers(), $customMsgServices);
  332. } else {
  333. return response()->success(['data' => 0]);
  334. }
  335. }
  336. function exportCustomSendMsgs(Request $request)
  337. {
  338. \Log::info('exportCustomSendMsgs_start');
  339. $start_time = $request->has('start_time') ? $request->input('start_time') : '';
  340. $end_time = $request->has('end_time') ? $request->input('end_time') : '';
  341. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  342. $task_name = $request->has('task_name') ? $request->input('task_name') : '';
  343. if ($start_time < '2018-11-02') {
  344. \Log::info('searchCustomSendMsgs,update_start_time:' . $start_time);
  345. $start_time = '2018-11-02';
  346. }
  347. $distribution_channel_id = $this->getChannelId();
  348. $param = [
  349. 'distribution_channel_id' => $distribution_channel_id,
  350. 'start_time' => $start_time,
  351. 'end_time' => $end_time,
  352. 'book_name' => $book_name,
  353. 'task_name' => $task_name
  354. ];
  355. $customMsgServices = CustomMsgService::searchCustomSendMsgs($param, true);
  356. header("Content-type:application/vnd.ms-excel");
  357. header("Content-Disposition:attachment;filename=" . "客服消息" . date("YmdHis") . ".csv");
  358. echo iconv("UTF-8", "GBK", "\"类型\",\"id\",\"任务名称\",\"小说\",\"章节\",\"pv\",\"uv\",\"充值用户\",\"充值总额\"\r\n");
  359. if (!empty($customMsgServices)) {
  360. foreach ($customMsgServices as $key => $customMsgService) {
  361. $fromtype = 'custom_' . $customMsgService->id;
  362. $statistics = WapVisitStatService::innerCustomerAllStats($fromtype);
  363. $uv = empty($statistics['uv']) ? 0 : $statistics['uv'];
  364. $pv = empty($statistics['pv']) ? 0 : $statistics['pv'];
  365. $pay_user_num = empty($statistics['pay_user_num']) ? 0 : $statistics['pay_user_num'];
  366. $charge_amount = empty($statistics['charge_amount']) ? 0 : $statistics['charge_amount'];
  367. echo("\"" . iconv("UTF-8", "GBK", '客服消息') . "\",");
  368. echo("\"" . iconv("UTF-8", "GBK", $customMsgService->id) . "\",");
  369. echo("\"" . iconv("UTF-8", "GBK//IGNORE", $customMsgService->name ? $customMsgService->name : '未填') . "\",");
  370. echo("\"" . iconv("UTF-8", "GBK//IGNORE", $customMsgService->book_name ? $customMsgService->book_name : '未填') . "\",");
  371. echo("\"" . iconv("UTF-8", "GBK//IGNORE", $customMsgService->chapter_name ? $customMsgService->chapter_name : '未填') . "\",");
  372. echo("\"" . iconv("UTF-8", "GBK", $pv) . "\",");
  373. echo("\"" . iconv("UTF-8", "GBK", $uv) . "\",");
  374. echo("\"" . iconv("UTF-8", "GBK", $pay_user_num) . "\",");
  375. echo("\"" . iconv("UTF-8", "GBK", $charge_amount) . "\"\r\n");
  376. }
  377. }
  378. exit();
  379. }
  380. /**
  381. * @apiVersion 1.0.0
  382. * @api {GET} OfficialAccount/customSendMsgsById 通过ID获取指定客服消息
  383. * @apiGroup OfficialAccount
  384. * @apiName customSendMsgsById
  385. * @apiParam {String} id 客服消息id.
  386. * @apiSuccessExample {json} Success-Response:
  387. *
  388. * {
  389. * "code": 0,
  390. * "msg": "",
  391. * "data": {
  392. * "id": 1,
  393. * "name": "测试111",
  394. * "send_time": "2017-12-26 11:11:11",
  395. * "content": "横眉冷对千夫指,俯首甘为孺子牛",
  396. * "redirect_url": "http:\/\/www.baidu.com\/yes?en",
  397. * "status": null,
  398. * "distribution_channel_id": 1,
  399. * "subscribe_time": "z",
  400. * "sex": "z",
  401. * "balance": "z",
  402. * "order_type": "z",
  403. * "category_id": "z"
  404. * }
  405. * }
  406. */
  407. function customSendMsgsById(Request $request)
  408. {
  409. $id = $request->has('id') ? $request->input('id') : '';
  410. if (empty($id)) {
  411. return response()->error("PARAM_EMPTY");
  412. }
  413. $customMsgService = CustomMsgService::customSendMsgsById($id);
  414. if (!empty($customMsgService)) {
  415. if ($customMsgService->description) {
  416. $customMsgService->description = json_decode($customMsgService->description);
  417. }
  418. return response()->item(new CustomSendMsgsTransformers(), $customMsgService);
  419. } else {
  420. return response()->success(['data' => 0]);
  421. }
  422. }
  423. /**
  424. * @apiVersion 1.0.0
  425. * @api {GET} OfficialAccount/stopCustomSendMsgsById 停止发送客服消息
  426. * @apiGroup OfficialAccount
  427. * @apiName stopCustomSendMsgsById
  428. * @apiParam {String} id 客服消息id.
  429. * @apiSuccessExample {json} Success-Response:
  430. *
  431. * {
  432. * "code": 0,
  433. * "msg": "",
  434. * "data": {
  435. * }
  436. * }
  437. */
  438. function stopCustomSendMsgsById(Request $request)
  439. {
  440. $id = $request->has('id') ? $request->input('id') : '';
  441. if (empty($id)) {
  442. return response()->error("PARAM_EMPTY");
  443. }
  444. $customMsgService = CustomMsgService::updateCustomSendMsgsStatus($id);
  445. if ($customMsgService == 1) {
  446. return response()->success();
  447. } elseif ($customMsgService == 2) {
  448. return response()->error('CUSTOMS_SEND_FAILED');
  449. } elseif ($customMsgService == 4) {
  450. return response()->error('CUSTOMMSG_IS_SEDDING');
  451. } elseif ($customMsgService == 0) {
  452. return response()->error('CUSTOMS_SEND_FAILED');
  453. } else {
  454. return response()->error('CUSTOMS_SEND_FAILED');
  455. }
  456. }
  457. /**
  458. * @apiVersion 1.0.0
  459. * @api {GET} OfficialAccount/forceUserCountByCustomPrams 通过参数获取用户
  460. * @apiGroup OfficialAccount
  461. * @apiName wechatTemplateMsgById
  462. * @apiParam {String} subscribe_time 关注时间(a:5天内,b:5-15天,c:15-30天,d:30天以上,z:不限)
  463. * @apiParam {String} sex 性别(a:男,b:女,z:不限)
  464. * @apiParam {String} order_type 付费情况(a:未付费,b:已付费,c:VIP用户,z:不限)
  465. * @apiParam {String} balance 账户余额.(a:低于500,b:500-2000,c:2000-5000,z:不限)
  466. * @apiParam {String} category_id 书籍分类.(分类id,z:不限)
  467. * @apiSuccess {String} num 用户数量.
  468. * @apiSuccessExample {json} Success-Response:
  469. *
  470. * {
  471. * "code": 0,
  472. * "msg": "",
  473. * "data": {
  474. * "num": 20
  475. * }
  476. * }
  477. */
  478. function forceUserCountByCustomPrams(Request $request)
  479. {
  480. // dd(11);
  481. $distribution_channel_id = $this->getChannelId();
  482. $subscribe_time = $request->has('subscribe_time') ? $request->input('subscribe_time') : '';
  483. if (empty($subscribe_time)) {
  484. return response()->error("PARAM_EMPTY");
  485. }
  486. $appids = $request->has('appids') ? $request->input('appids') : '';
  487. if (empty($appids)) {
  488. return response()->error("PARAM_EMPTY");
  489. }
  490. $sex = $request->has('sex') ? $request->input('sex') : '';
  491. if (empty($sex)) {
  492. return response()->error("PARAM_EMPTY");
  493. }
  494. $balance = $request->has('balance') ? $request->input('balance') : '';
  495. if (empty($balance)) {
  496. return response()->error("PARAM_EMPTY");
  497. }
  498. $order_type = $request->has('order_type') ? $request->input('order_type') : '';
  499. if (empty($order_type)) {
  500. return response()->error("PARAM_EMPTY");
  501. }
  502. $category_id = $request->has('category_id') ? $request->input('category_id') : '';
  503. if (empty($category_id)) {
  504. return response()->error("PARAM_EMPTY");
  505. }
  506. $appidArray = explode(',', $appids);
  507. $usernum = 0;
  508. for ($j = 0; $j < count($appidArray); $j++) {
  509. $skip = 0;
  510. while ($skip <= 2500000) {
  511. \Log::info('-----------客服消息-------分页取强关用户,目前页数----------' . $skip);
  512. //5,获取所选条件下筛选出的用户
  513. $sign_time = 'z';
  514. $force_user = ForceSubscribeService::forceUserCountByCustomPrams($appidArray[$j], $distribution_channel_id, $subscribe_time, $sex, $balance, $category_id, $order_type, $sign_time, $skip);
  515. if (count($force_user) > 0) {
  516. $usernum += count($force_user);
  517. } else {
  518. break;
  519. }
  520. $skip += count($force_user);
  521. }
  522. }
  523. return response()->success(['num' => $usernum]);
  524. }
  525. /**
  526. * @apiVersion 1.0.0
  527. * @api {GET} OfficialAccount/addCustomSendMsgs 发送客服消息
  528. * @apiGroup OfficialAccount
  529. * @apiName addCustomSendMsgs
  530. * @apiParam {String} appid 服务号.
  531. * @apiParam {String} name 客服消息标题.
  532. * @apiParam {String} send_time 客服消息发送时间.
  533. * @apiParam {String} content 客服消息内容. 格式:[[{"title":"横眉冷对千夫指,俯首甘为孺子牛"},{"description":"横眉冷对千夫指,俯首甘为孺子牛"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}],[{"title":"来他家做佣人半年,结果天天被男主人这样!"},{"description":"来他家做佣人半年,结果天天被男主人这样!"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}]]
  534. * @apiParam {String} redirect_url 点击消息重定向地址.
  535. * @apiParam {String} subscribe_time 用户强关时间段.
  536. * @apiParam {String} sex 用户性别.
  537. * @apiParam {String} balance 用户账户余额.
  538. * @apiParam {String} order_type 用户订单状态.
  539. * @apiParam {String} category_id 读书分类.
  540. * @apiSuccessExample {json} Success-Response:
  541. *
  542. * {
  543. * "code": 0,
  544. * "msg": "",
  545. * "data": []
  546. * }
  547. */
  548. function addCustomSendMsgs(Request $request)
  549. {
  550. $distribution_channel_id = $this->getChannelId();
  551. \Log::info('addCustomSendMsgs_start:'.$distribution_channel_id);
  552. \Log::info($request->all());
  553. $name = $request->has('name') ? $request->input('name') : '';
  554. if (empty($name)) {
  555. return response()->error("PARAM_EMPTY");
  556. }
  557. $appid = $request->has('appid') ? $request->input('appid') : '';
  558. if (empty($appid)) {
  559. return response()->error("PARAM_EMPTY");
  560. }
  561. $send_time = $request->has('send_time') ? $request->input('send_time') : '';
  562. if (empty($send_time)) {
  563. return response()->error("PARAM_EMPTY");
  564. }
  565. $content = $request->has('content') ? $request->input('content') : '';
  566. if (empty($content)) {
  567. return response()->error("PARAM_EMPTY");
  568. }
  569. $redirect_url = $request->has('redirect_url') ? $request->input('redirect_url') : '';
  570. if (empty($redirect_url)) {
  571. return response()->error("PARAM_EMPTY");
  572. }
  573. $subscribe_time = $request->has('subscribe_time') ? $request->input('subscribe_time') : '';
  574. if (empty($subscribe_time)) {
  575. return response()->error("PARAM_EMPTY");
  576. }
  577. $sex = $request->has('sex') ? $request->input('sex') : '';
  578. if (empty($sex)) {
  579. return response()->error("PARAM_EMPTY");
  580. }
  581. $balance = $request->has('balance') ? $request->input('balance') : '';
  582. if (empty($balance)) {
  583. return response()->error("PARAM_EMPTY");
  584. }
  585. $order_type = $request->has('order_type') ? $request->input('order_type') : '';
  586. if (empty($order_type)) {
  587. return response()->error("PARAM_EMPTY");
  588. }
  589. $category_id = $request->has('category_id') ? $request->input('category_id') : '';
  590. if (empty($category_id)) {
  591. return response()->error("PARAM_EMPTY");
  592. }
  593. $is_activity = $request->has('is_activity') ? $request->input('is_activity') : '0';
  594. $description = $request->has('description') ? $request->input('description') : '';
  595. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  596. $chapter_name = $request->has('chapter_name') ? $request->input('chapter_name') : '';
  597. if ($is_activity == '0') {
  598. if (empty($book_name)) {
  599. return response()->error("PARAM_EMPTY");
  600. }
  601. if (empty($chapter_name)) {
  602. return response()->error("PARAM_EMPTY");
  603. }
  604. }
  605. $user_condition = $request->has('user_condition') ? $request->input('user_condition') : '';
  606. $is_full_send = $request->has('is_full_send') ? $request->input('is_full_send') : '0';
  607. \Log::info('addCustomSendMsgs_after_check:'.$distribution_channel_id);
  608. $customMsgPrams['appid'] = $appid;
  609. $customMsgPrams['name'] = $name;
  610. $customMsgPrams['send_time'] = $send_time;
  611. $customMsgPrams['is_activity'] = $is_activity;
  612. $customMsgPrams['content'] = json_encode($content);
  613. $customMsgPrams['description'] = json_encode($description);
  614. $customMsgPrams['book_name'] = $book_name;
  615. $customMsgPrams['chapter_name'] = $chapter_name;
  616. $customMsgPrams['redirect_url'] = $redirect_url;
  617. $customMsgPrams['subscribe_time'] = $subscribe_time;
  618. $customMsgPrams['sex'] = $sex;
  619. $customMsgPrams['balance'] = $balance;
  620. $customMsgPrams['order_type'] = $order_type;
  621. $customMsgPrams['category_id'] = $category_id;
  622. $customMsgPrams['is_full_send'] = $is_full_send;
  623. $customMsgPrams['distribution_channel_id'] = $distribution_channel_id;
  624. $customMsgPrams['status'] = '1';
  625. $customMsgPrams['user_condition'] = $user_condition;
  626. //先判断在发送时间段1小时以内,有没有发起过相同的模板消息,如果有发送过,就提示用户已经创建过相同模板消息,不创建新的模板消息
  627. $isSendCustomer = CustomMsgService::isSendCustomerAtSameTime($customMsgPrams);
  628. if (!empty($isSendCustomer)) {
  629. \Log::info('已经发送过该客服消息');
  630. \Log::info($isSendCustomer['id']);
  631. \Log::info($isSendCustomer['status']);
  632. \Log::info($isSendCustomer['del_flag']);
  633. return response()->error('CUSTOMS_DOUBLE_FAILED');
  634. }
  635. $customMsgService = CustomMsgService::addCustomSendMsgs($customMsgPrams);
  636. if ($customMsgService == 1) {
  637. return response()->success();
  638. } elseif ($customMsgService == 2) {
  639. return response()->error('CUSTOMS_SEND_FAILED');
  640. } elseif ($customMsgService == 3) {
  641. return response()->error('CUSTOMS_DOUBLE_FAILED');
  642. } elseif ($customMsgService == 0) {
  643. return response()->error('CUSTOMS_SEND_FAILED');
  644. } else {
  645. return response()->error('CUSTOMS_SEND_FAILED');
  646. }
  647. }
  648. /**
  649. * @apiVersion 1.0.0
  650. * @api {GET} OfficialAccount/editCustomSendMsgs 发送客服消息
  651. * @apiGroup OfficialAccount
  652. * @apiName editCustomSendMsgs
  653. * @apiParam {String} appid 服务号.
  654. * @apiParam {String} name 客服消息标题.
  655. * @apiParam {String} send_time 客服消息发送时间.
  656. * @apiParam {String} content 客服消息内容. 格式:[[{"title":"横眉冷对千夫指,俯首甘为孺子牛"},{"description":"横眉冷对千夫指,俯首甘为孺子牛"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}],[{"title":"来他家做佣人半年,结果天天被男主人这样!"},{"description":"来他家做佣人半年,结果天天被男主人这样!"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}]]
  657. * @apiParam {String} redirect_url 点击消息重定向地址.
  658. * @apiParam {String} subscribe_time 用户强关时间段.
  659. * @apiParam {String} sex 用户性别.
  660. * @apiParam {String} balance 用户账户余额.
  661. * @apiParam {String} order_type 用户订单状态.
  662. * @apiParam {String} category_id 读书分类.
  663. * @apiParam {String} id id.
  664. * @apiSuccessExample {json} Success-Response:
  665. *
  666. * {
  667. * "code": 0,
  668. * "msg": "",
  669. * "data": []
  670. * }
  671. */
  672. function editCustomSendMsgs(Request $request)
  673. {
  674. $distribution_channel_id = $this->getChannelId();
  675. $name = $request->has('name') ? $request->input('name') : '';
  676. if (empty($name)) {
  677. return response()->error("PARAM_EMPTY");
  678. }
  679. $appid = $request->has('appid') ? $request->input('appid') : '';
  680. if (empty($appid)) {
  681. return response()->error("PARAM_EMPTY");
  682. }
  683. $send_time = $request->has('send_time') ? $request->input('send_time') : '';
  684. if (empty($send_time)) {
  685. return response()->error("PARAM_EMPTY");
  686. }
  687. $content = $request->has('content') ? $request->input('content') : '';
  688. if (empty($content)) {
  689. return response()->error("PARAM_EMPTY");
  690. }
  691. $redirect_url = $request->has('redirect_url') ? $request->input('redirect_url') : '';
  692. if (empty($redirect_url)) {
  693. return response()->error("PARAM_EMPTY");
  694. }
  695. $subscribe_time = $request->has('subscribe_time') ? $request->input('subscribe_time') : '';
  696. if (empty($subscribe_time)) {
  697. return response()->error("PARAM_EMPTY");
  698. }
  699. $sex = $request->has('sex') ? $request->input('sex') : '';
  700. if (empty($sex)) {
  701. return response()->error("PARAM_EMPTY");
  702. }
  703. $balance = $request->has('balance') ? $request->input('balance') : '';
  704. if (empty($balance)) {
  705. return response()->error("PARAM_EMPTY");
  706. }
  707. $order_type = $request->has('order_type') ? $request->input('order_type') : '';
  708. if (empty($order_type)) {
  709. return response()->error("PARAM_EMPTY");
  710. }
  711. $category_id = $request->has('category_id') ? $request->input('category_id') : '';
  712. if (empty($category_id)) {
  713. return response()->error("PARAM_EMPTY");
  714. }
  715. $is_activity = $request->has('is_activity') ? $request->input('is_activity') : '0';
  716. $description = $request->has('description') ? $request->input('description') : '';
  717. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  718. $chapter_name = $request->has('chapter_name') ? $request->input('chapter_name') : '';
  719. if ($is_activity == '0') {
  720. if (empty($book_name)) {
  721. return response()->error("PARAM_EMPTY");
  722. }
  723. if (empty($chapter_name)) {
  724. return response()->error("PARAM_EMPTY");
  725. }
  726. }
  727. $is_full_send = $request->has('is_full_send') ? $request->input('is_full_send') : '0';
  728. $user_condition = $request->has('user_condition') ? $request->input('user_condition') : '';
  729. $id = $request->has('id') ? $request->input('id') : '';
  730. if (empty($id)) {
  731. return response()->error("PARAM_EMPTY");
  732. }
  733. $customMsgPrams['appid'] = $appid;
  734. $customMsgPrams['name'] = $name;
  735. $customMsgPrams['send_time'] = $send_time;
  736. $customMsgPrams['is_activity'] = $is_activity;
  737. $customMsgPrams['content'] = json_encode($content);
  738. $customMsgPrams['description'] = json_encode($description);
  739. $customMsgPrams['book_name'] = $book_name;
  740. $customMsgPrams['chapter_name'] = $chapter_name;
  741. $customMsgPrams['redirect_url'] = $redirect_url;
  742. $customMsgPrams['subscribe_time'] = $subscribe_time;
  743. $customMsgPrams['sex'] = $sex;
  744. $customMsgPrams['balance'] = $balance;
  745. $customMsgPrams['order_type'] = $order_type;
  746. $customMsgPrams['category_id'] = $category_id;
  747. $customMsgPrams['is_full_send'] = $is_full_send;
  748. $customMsgPrams['distribution_channel_id'] = $distribution_channel_id;
  749. $customMsgPrams['status'] = '1';
  750. $customMsgPrams['user_condition'] = $user_condition;
  751. $customMsgPrams['id'] = $id;
  752. $customMsgService = CustomMsgService::editCustomSendMsgs($customMsgPrams);
  753. if ($customMsgService == 1) {
  754. return response()->success();
  755. } elseif ($customMsgService == 2) {
  756. return response()->error('CUSTOMS_SEND_FAILED');
  757. } elseif ($customMsgService == 4) {
  758. return response()->error('CUSTOMMSG_IS_SEDDING');
  759. } elseif ($customMsgService == 0) {
  760. return response()->error('CUSTOMS_SEND_FAILED');
  761. } else {
  762. return response()->error('CUSTOMS_SEND_FAILED');
  763. }
  764. }
  765. /**
  766. * @apiVersion 1.0.0
  767. * @api {GET} OfficialAccount/delCustomSendMsgs 删除客服消息
  768. * @apiGroup OfficialAccount
  769. * @apiName delCustomSendMsgs
  770. * @apiParam {String} id 客服消息id.
  771. * @apiSuccessExample {json} Success-Response:
  772. *
  773. * {
  774. * "code": 0,
  775. * "msg": "",
  776. * "data": {
  777. * }
  778. * }
  779. */
  780. function delCustomSendMsgs(Request $request)
  781. {
  782. $id = $request->has('id') ? $request->input('id') : '';
  783. if (empty($id)) {
  784. return response()->error("PARAM_EMPTY");
  785. }
  786. \Log::info('》》》》》》》》》》》》》》获取删除客服消息时所传的ID');
  787. \Log::info($id);
  788. $customSendMsgsPrams['id'] = $id;
  789. $customMsgService = CustomMsgService::delCustomSendMsgs($customSendMsgsPrams);
  790. \Log::info('》》》》》》》》》》》》》》获取删除客服消息 返回结果');
  791. \Log::info($customMsgService);
  792. if ($customMsgService == 1) {
  793. return response()->success();
  794. } elseif ($customMsgService == 2) {
  795. return response()->error('CUSTOMS_SEND_FAILED');
  796. } elseif ($customMsgService == 4) {
  797. return response()->error('CUSTOMMSG_IS_SEDDING');
  798. } elseif ($customMsgService == 0) {
  799. return response()->error('CUSTOMS_SEND_FAILED');
  800. } else {
  801. return response()->error('CUSTOMS_SEND_FAILED');
  802. }
  803. }
  804. /**
  805. * @apiVersion 1.0.0
  806. * @api {GET} OfficialAccount/getAllDocumentCovers 获取所有图库素材
  807. * @apiGroup OfficialAccount
  808. * @apiName getAllDocumentCovers
  809. * @apiSuccessExample {json} Success-Response:
  810. *
  811. * {
  812. * "code": 0,
  813. * "msg": "",
  814. * "data": [
  815. * {
  816. * "id": 1,
  817. * "origin_cover": "https:\/\/yueduyun.oss-cn-hangzhou.aliyuncs.com\/document_covers\/1.jpg"
  818. * },
  819. * {
  820. * "id": 2,
  821. * "origin_cover": "https:\/\/yueduyun.oss-cn-hangzhou.aliyuncs.com\/document_covers\/2.jpg"
  822. * },
  823. * {
  824. * "id": 3,
  825. * "origin_cover": "https:\/\/yueduyun.oss-cn-hangzhou.aliyuncs.com\/document_covers\/3.jpg"
  826. * }
  827. * ]
  828. * }
  829. */
  830. function getAllDocumentCovers(Request $request)
  831. {
  832. $distribution_channel_id = $this->getChannelId();
  833. $promotionService = PromotionService::getAllMessageDocumentCovers($distribution_channel_id);
  834. if (!empty($promotionService)) {
  835. return response()->collection(new DocumentCoversTransformer(), $promotionService);
  836. } else {
  837. return response()->success(['data' => 0]);
  838. }
  839. }
  840. /**
  841. * @apiVersion 1.0.0
  842. * @api {GET} OfficialAccount/getAllHeadlinesNoType 获取所有标签文案
  843. * @apiGroup OfficialAccount
  844. * @apiName getAllHeadlinesNoType
  845. * @apiSuccessExample {json} Success-Response:
  846. *
  847. * {
  848. * "code": 0,
  849. * "msg": "",
  850. * "data": [
  851. * {
  852. * "id": 1,
  853. * "title": "三姐妹怀孕,孩子的父亲竟是同一人,婆婆竟然这样说..."
  854. * },
  855. * {
  856. * "id": 2,
  857. * "title": "看哭5000万人,一对32岁夫妻离婚后的聊天记录..."
  858. * }
  859. * ]
  860. * }
  861. */
  862. function getAllHeadlinesNoType(Request $request)
  863. {
  864. $promotionService = PromotionService::getHeadlines();
  865. if (!empty($promotionService)) {
  866. return response()->collection(new HeadlinelTransformer(), $promotionService);
  867. } else {
  868. return response()->success(['data' => 0]);
  869. }
  870. }
  871. /**
  872. * @apiVersion 1.0.0
  873. * @api {GET} OfficialAccount/testAddCustomSendMsgs 测试向单个用户发送客服消息
  874. * @apiGroup OfficialAccount
  875. * @apiName testAddCustomSendMsgs
  876. * @apiParam {String} appid 服务号.
  877. * @apiParam {String} uid 服务号.
  878. * @apiParam {String} name 客服消息标题.
  879. * @apiParam {String} content 客服消息内容. 格式:[[{"title":"横眉冷对千夫指,俯首甘为孺子牛"},{"description":"横眉冷对千夫指,俯首甘为孺子牛"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}],[{"title":"来他家做佣人半年,结果天天被男主人这样!"},{"description":"来他家做佣人半年,结果天天被男主人这样!"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}]]
  880. * @apiParam {String} redirect_url 点击消息重定向地址.
  881. * @apiSuccessExample {json} Success-Response:
  882. *
  883. * {
  884. * "code": 0,
  885. * "msg": "",
  886. * "data": []
  887. * }
  888. */
  889. function testAddCustomSendMsgs(Request $request)
  890. {
  891. $distribution_channel_id = $this->getChannelId();
  892. $appid = $request->has('appid') ? $request->input('appid') : '';
  893. if (empty($appid)) {
  894. return response()->error("PARAM_EMPTY");
  895. }
  896. $name = $request->has('name') ? $request->input('name') : '';
  897. if (empty($name)) {
  898. return response()->error("PARAM_EMPTY");
  899. }
  900. $content = $request->has('content') ? $request->input('content') : '';
  901. if (empty($content)) {
  902. return response()->error("PARAM_EMPTY");
  903. }
  904. $redirect_url = $request->has('redirect_url') ? $request->input('redirect_url') : '';
  905. if (empty($redirect_url)) {
  906. return response()->error("PARAM_EMPTY");
  907. }
  908. $uid = $request->has('uid') ? $request->input('uid') : '';
  909. if (empty($uid)) {
  910. return response()->error("PARAM_EMPTY");
  911. }
  912. $customMsgPrams['appid'] = $appid;
  913. $customMsgPrams['name'] = $name;
  914. $customMsgPrams['content'] = json_encode($content);
  915. $customMsgPrams['redirect_url'] = $redirect_url;
  916. $customMsgPrams['distribution_channel_id'] = $distribution_channel_id;
  917. $customMsgPrams['uid'] = $uid;
  918. $customMsgService = CustomMsgService::testAddCustomSendMsgs($customMsgPrams);
  919. if ($customMsgService == 1) {
  920. return response()->success();
  921. } elseif ($customMsgService == 2) {
  922. return response()->error('CUSTOMS_SEND_FAILED');
  923. } elseif ($customMsgService == 0) {
  924. return response()->error('CUSTOMS_SEND_FAILED');
  925. } else {
  926. return response()->error('CUSTOMS_SEND_FAILED');
  927. }
  928. }
  929. //-------------------------------------------------编辑发送客服消息End---------------------------CustomSendMsg
  930. //-------------------------------------------------生成图文链接Start---------------------------
  931. /**
  932. * 生成图文链接
  933. */
  934. function createOfficialImgTxtUrl(Request $request)
  935. {
  936. \Log::info('createOfficialImgTxtUrl_start');
  937. // \Log::info($request->all());
  938. //图片链接
  939. $img_url = $request->has('img_url') ? $request->input('img_url') : '';
  940. if (empty($img_url)) {
  941. return response()->error("PARAM_EMPTY");
  942. }
  943. //文章内容
  944. $content = $request->has('content') ? $request->input('content') : '';
  945. if (empty($content)) {
  946. return response()->error("PARAM_EMPTY");
  947. }
  948. //推广标题
  949. $title = $request->has('title') ? $request->input('title') : '';
  950. if (empty($title)) {
  951. return response()->error("PARAM_EMPTY");
  952. }
  953. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  954. if (empty($book_name)) {
  955. return response()->error("PARAM_EMPTY");
  956. }
  957. $chapter_sequence = $request->has('chapter_sequence') ? $request->input('chapter_sequence') : '';
  958. if (empty($chapter_sequence)) {
  959. return response()->error("PARAM_EMPTY");
  960. }
  961. $qrcode_Img = $request->has('qrcode_Img') ? $request->input('qrcode_Img') : '';
  962. $send_orders_id = $request->has('send_orders_id') ? $request->input('send_orders_id') : '';
  963. $send_orders_name = $request->has('send_orders_name') ? $request->input('send_orders_name') : '';
  964. $send_orders_url = $request->has('send_orders_url') ? $request->input('send_orders_url') : '';
  965. $distribution_channel_id = $this->getChannelId();
  966. \Log::info('createOfficialImgTxtUrl_start2:'.$distribution_channel_id.' book_name:'.$book_name.' chapter_sequence:'.$chapter_sequence);
  967. $officialImgTxtUrlPrams['distribution_channel_id'] = $distribution_channel_id;
  968. $officialImgTxtUrlPrams['img_url'] = $img_url;
  969. $officialImgTxtUrlPrams['content'] = $content;
  970. $officialImgTxtUrlPrams['title'] = $title;
  971. $officialImgTxtUrlPrams['book_name'] = $book_name;
  972. $officialImgTxtUrlPrams['chapter_sequence'] = $chapter_sequence;
  973. $officialImgTxtUrlPrams['send_orders_id'] = $send_orders_id;
  974. $officialImgTxtUrlPrams['send_orders_name'] = $send_orders_name;
  975. $officialImgTxtUrlPrams['send_orders_url'] = $send_orders_url;
  976. $customMsgService = CustomMsgService::createOfficialImgTxtUrl($officialImgTxtUrlPrams);
  977. if (!empty($customMsgService)) {
  978. # code...
  979. return response()->success(['img_url' => $customMsgService]);
  980. } else {
  981. return response()->error('OFFICIAL_IMGTXT_FAILED');
  982. }
  983. }
  984. /**
  985. * 获取图文列表
  986. */
  987. function getOfficialImgTxtUrl(Request $request)
  988. {
  989. $distribution_channel_id = $this->getChannelId();
  990. $customMsgService = CustomMsgService::getOfficialImgTxtUrl($distribution_channel_id);
  991. if (!empty($customMsgService)) {
  992. # code...
  993. return response()->pagination(new OfficialImgtextUrlsTransformer(), $customMsgService);
  994. } else {
  995. return response()->success(['data' => 0]);
  996. }
  997. }
  998. /**
  999. * 根据标题获取图文列表
  1000. */
  1001. function getOfficialImgTxtUrlByBookName(Request $request)
  1002. {
  1003. $distribution_channel_id = $this->getChannelId();
  1004. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  1005. if (empty($book_name)) {
  1006. return response()->error("PARAM_EMPTY");
  1007. }
  1008. $customMsgService = CustomMsgService::getOfficialImgTxtUrlByBookName($distribution_channel_id, $book_name);
  1009. if (!empty($customMsgService)) {
  1010. # code...
  1011. return response()->pagination(new OfficialImgtextUrlsTransformer(), $customMsgService);
  1012. } else {
  1013. return response()->success(['data' => 0]);
  1014. }
  1015. }
  1016. /**
  1017. * 上传二维码图片
  1018. */
  1019. function uploadQrcodeImgToWechat(Request $request)
  1020. {
  1021. $distribution_channel_id = $this->getChannelId();
  1022. $qrcode_Img = $request->has('qrcode_Img') ? $request->input('qrcode_Img') : '';
  1023. if (empty($qrcode_Img)) {
  1024. return response()->error("PARAM_EMPTY");
  1025. }
  1026. $officialImgTxtUrlPrams['distribution_channel_id'] = $distribution_channel_id;
  1027. $officialImgTxtUrlPrams['qrcode_Img'] = $qrcode_Img;
  1028. $result = CustomMsgService::uploadQrcodeImgToWechat($officialImgTxtUrlPrams);
  1029. if ($result) {
  1030. # code...
  1031. return response()->success(['media_id' => $result['media_id'], 'url' => $result['url']]);
  1032. } else {
  1033. return response()->success();
  1034. }
  1035. }
  1036. function uploadQrcodeImgToOss(Request $request)
  1037. {
  1038. \Log::info('-----------------OSS上传二维码图片');
  1039. $distribution_channel_id = $this->getChannelId();
  1040. if ($request->hasFile('photo')) {
  1041. $file = $request->file('photo');
  1042. $ossImgBackData = $this->ossObject()->uploadFile(env('OSS_BUCKET', 'zhuishuyun'), 'service/qrcodeimg_' . $distribution_channel_id . '_' . time() . '.' . $file->getClientOriginalName(), $file->path());
  1043. $ossImg = $ossImgBackData['oss-request-url'];
  1044. \Log::info('-----------------OSS上传二维码图片成功');
  1045. \Log::info($ossImg);
  1046. return response()->success(['qrcode_img' => $ossImg]);
  1047. } else {
  1048. \Log::info('-----------------没获取到传过来的图片');
  1049. }
  1050. }
  1051. /**
  1052. * 删除图文素材
  1053. */
  1054. function delOfficialImgTxtUrl(Request $request)
  1055. {
  1056. $id = $request->has('id') ? $request->input('id') : '';
  1057. if (empty($id)) {
  1058. return response()->error("PARAM_EMPTY");
  1059. }
  1060. $customMsgServiceStatus = CustomMsgService::delOfficialImgTxtUrl($id);
  1061. if ($customMsgServiceStatus == 1) {
  1062. return response()->success();
  1063. } elseif ($customMsgServiceStatus == 2) {
  1064. return response()->error('OFFICIAL_IMGTXT_FOUNDFAILED');
  1065. } elseif ($customMsgServiceStatus == 0) {
  1066. return response()->error('OFFICIAL_IMGTXT_DELFAILED');
  1067. } else {
  1068. return response()->error('OFFICIAL_IMGTXT_DELFAILED');
  1069. }
  1070. }
  1071. //-------------------------------------------------生成图文链接End---------------------------
  1072. }