CustomMsgController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <?php
  2. namespace App\Http\Controllers\Manage\OfficialAccount;
  3. use App\Http\Controllers\Manage\BaseController;
  4. use App\Modules\OfficialAccount\Services\CustomMsgService;
  5. use App\Modules\OfficialAccount\Services\BatchCustomMsgService;
  6. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  7. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  8. use App\Modules\OfficialAccount\Models\OfficialAccount;
  9. use App\Http\Controllers\Manage\OfficialAccount\Transformers\CustomSendMsgsTransformers;
  10. use App\Http\Controllers\Manage\OfficialAccount\Transformers\BatchCustomSendMsgsTransformers;
  11. use Illuminate\Http\Request;
  12. use GuzzleHttp\Client;
  13. use Hashids;
  14. use App\Modules\Book\Services\BookConfigService;
  15. use App\Modules\Statistic\Services\SendStatistics;
  16. class CustomMsgController extends BaseController
  17. {
  18. /**
  19. * @apiVersion 1.0.0
  20. * @api {GET} OfficialAccount/customSendMsgsByTrusteeship 全部发送客服消息列表获取
  21. * @apiGroup OfficialAccount
  22. * @apiName customSendMsgsByTrusteeship
  23. */
  24. function customSendMsgsByTrusteeship(Request $request) {
  25. \Log::info('customSendMsgsByTrusteeship');
  26. $param = array();
  27. $param['trusteeship'] = 1;
  28. $customMsgServices = CustomMsgService::customSendMsgsByTrusteeship($param);
  29. // 统计
  30. foreach($customMsgServices as $key=>$customMsgService){
  31. $temp_customMsgService = $customMsgService;
  32. $customMsgService->pv = '';
  33. $customMsgService->uv = '';
  34. $customMsgService->total_order_num = '';
  35. $customMsgService->suc_order_num = '';
  36. $customMsgService->order_suc_rate = '';
  37. $pv = $uv = $total_order_num = $suc_order_num = $order_suc_rate = array();
  38. for($i=1;$i<=4;$i++){
  39. $temp_statistics= $this->get_custom_msg_statistics($temp_customMsgService,$i);
  40. $pv[$i] = $temp_statistics->pv;
  41. $uv[$i] = $temp_statistics->uv;
  42. $total_order_num[$i] = $temp_statistics->total_order_num;
  43. $suc_order_num[$i] = $temp_statistics->suc_order_num;
  44. $order_suc_rate[$i] = $temp_statistics->order_suc_rate;
  45. $success_order_sum[$i] = $temp_statistics->success_order_sum;
  46. }
  47. // 解析bid,非贪婪匹配
  48. $matches = array();
  49. preg_match_all('/bid=(.*?)&cid/', $customMsgService->content, $matches);
  50. $bids = isset($matches[1])?$matches[1]:array();
  51. $simple_bids = $book_names = array();
  52. $j = 1;
  53. if(!empty($bids)){
  54. foreach($bids as $bid){
  55. $simple_bid = Hashids::decode($bid);
  56. if(isset($simple_bid[0]) && !empty($simple_bid[0])){
  57. $simple_bids[$j] = $simple_bid[0];
  58. $book = BookConfigService::getBookById($simple_bid[0]);
  59. $book_names[$j] = isset($book->book_name)?$book->book_name:'';
  60. $j++;
  61. }
  62. }
  63. }
  64. $customMsgService->bids = json_encode($simple_bids);
  65. $customMsgService->book_names = json_encode($book_names);
  66. $customMsgService->pv = json_encode($pv);
  67. $customMsgService->uv = json_encode($uv);
  68. $customMsgService->total_order_num = json_encode($total_order_num);
  69. $customMsgService->suc_order_num = json_encode($suc_order_num);
  70. $customMsgService->order_suc_rate = json_encode($order_suc_rate);
  71. $customMsgService->success_order_sum = json_encode($success_order_sum);
  72. // 公众号名称
  73. $official_account = OfficialAccount::officialAccountByAppid($customMsgService->appid);
  74. $customMsgService->official_account_name = isset($official_account->nickname)?$official_account->nickname:'';
  75. $customMsgServices[$key] = $customMsgService;
  76. }
  77. if (!empty($customMsgServices)) {
  78. return response()->pagination(new CustomSendMsgsTransformers(), $customMsgServices);
  79. }else{
  80. return response()->success(['data'=>0]);
  81. }
  82. }
  83. /**
  84. * @apiVersion 1.0.0
  85. * @api {GET} OfficialAccount/customSendMsgsByTrusteeshipAndBacthNo 发送客服消息列表获取
  86. * @apiGroup OfficialAccount
  87. * @apiName customSendMsgsByTrusteeshipAndBacthNo
  88. * @apiParam {String} batch_no 批次id.
  89. */
  90. function customSendMsgsByTrusteeshipAndBacthNo(Request $request) {
  91. $batch_no = $request->has('batch_no') ? $request->input('batch_no') : '';
  92. if(empty($batch_no)) {
  93. return response()->error("PARAM_EMPTY");
  94. }
  95. $param = array();
  96. $param['trusteeship'] = 1;
  97. $param['batch_no'] = $batch_no;
  98. $customMsgService = CustomMsgService::customSendMsgsByTrusteeshipAndBacthNo($param);
  99. if (!empty($customMsgService)) {
  100. return response()->collection(new CustomSendMsgsTransformers(), $customMsgService);
  101. }else{
  102. return response()->success(['data'=>0]);
  103. }
  104. }
  105. /**
  106. * @apiVersion 1.0.0
  107. * @api {GET} OfficialAccount/batchCustomMsgsList 获取批次客服消息列表
  108. * @apiGroup OfficialAccount
  109. * @apiName batchCustomMsgsList
  110. */
  111. function batchCustomMsgsList(Request $request) {
  112. \Log::info('batchCustomMsgsList_start:');
  113. $batchCustomMsgs = BatchCustomMsgService::batchCustomMsgList();
  114. \Log::info($batchCustomMsgs);
  115. foreach($batchCustomMsgs as $batch_key=>$batchCustomMsg){
  116. // 得到渠道列表
  117. $param = array();
  118. $param['trusteeship'] = 1;
  119. $param['batch_no'] = $batchCustomMsg->id;
  120. \Log::info('batchCustomMsgsList:id:'.$batchCustomMsg->id);
  121. $child_custom_msgs = CustomMsgService::customSendMsgsByTrusteeshipAndBacthNo($param);
  122. $pv = $uv = $pay_user_num = $total_order_num = $suc_order_num = $order_suc_rate = $success_order_sum = array();
  123. $simple_bids = $book_names = array();
  124. // 子渠道汇总,统计到每本书的级别
  125. foreach($child_custom_msgs as $key=>$customMsgService){
  126. // \Log::info('key:'.$key);
  127. $temp_customMsgService = $customMsgService;
  128. for($i=1;$i<=4;$i++){
  129. $temp_statistics= $this->get_custom_msg_statistics($temp_customMsgService,$i);
  130. // init
  131. if(!isset($pv[$i])) {
  132. $pv[$i] = $uv[$i] = $pay_user_num[$i] = $total_order_num[$i] = $suc_order_num[$i]=$order_suc_rate[$i]=$success_order_sum[$i]=0;
  133. }
  134. $pv[$i] += $temp_statistics->pv;
  135. $uv[$i] += $temp_statistics->uv;
  136. $pay_user_num[$i] += $temp_statistics->pay_user_num;
  137. $total_order_num[$i] += $temp_statistics->total_order_num;
  138. $suc_order_num[$i] += $temp_statistics->suc_order_num;
  139. $order_suc_rate[$i] += $temp_statistics->order_suc_rate;
  140. $success_order_sum[$i] += $temp_statistics->success_order_sum;
  141. break;
  142. }
  143. // 同1批次,内容一致
  144. if($key == 0){
  145. \Log::info('key0');
  146. // \Log::info($customMsgService);
  147. // 解析bid,非贪婪匹配
  148. $matches = array();
  149. preg_match_all('/bid=(.*?)&cid/', $customMsgService->content, $matches);
  150. $bids = isset($matches[1])?$matches[1]:array();
  151. $j = 1;
  152. if(!empty($bids)){
  153. foreach($bids as $bid){
  154. $simple_bid = Hashids::decode($bid);
  155. if(isset($simple_bid[0]) && !empty($simple_bid[0])){
  156. $simple_bids[$j] = $simple_bid[0];
  157. $book = BookConfigService::getBookById($simple_bid[0]);
  158. $book_names[$j] = isset($book->book_name)?$book->book_name:'';
  159. $j++;
  160. }
  161. }
  162. }
  163. }
  164. $batchCustomMsg->user_num += $customMsgService->user_num;
  165. }
  166. $batchCustomMsg->pv = json_encode($pv);
  167. $batchCustomMsg->uv = json_encode($uv);
  168. $batchCustomMsg->pay_user_num = json_encode($pay_user_num);
  169. $batchCustomMsg->total_order_num = json_encode($total_order_num);
  170. $batchCustomMsg->suc_order_num = json_encode($suc_order_num);
  171. $batchCustomMsg->order_suc_rate = json_encode($order_suc_rate);
  172. $batchCustomMsg->success_order_sum = json_encode($success_order_sum);
  173. $batchCustomMsg->bids = json_encode($simple_bids);
  174. $batchCustomMsg->book_names = json_encode($book_names);
  175. $batchCustomMsgs[$batch_key] = $batchCustomMsg;
  176. }
  177. if (!empty($batchCustomMsgs)) {
  178. return response()->pagination(new BatchCustomSendMsgsTransformers(), $batchCustomMsgs);
  179. }else{
  180. return response()->success(['data'=>0]);
  181. }
  182. }
  183. /**
  184. * @apiVersion 1.0.0
  185. * @api {GET} OfficialAccount/batchCustomMsgById 通过ID获取指定批次客服消息
  186. * @apiGroup OfficialAccount
  187. * @apiName batchCustomMsgById
  188. * @apiParam {String} id 批次id.
  189. */
  190. function batchCustomMsgById(Request $request) {
  191. $id = $request->has('id') ? $request->input('id') : '';
  192. if(empty($id)) {
  193. return response()->error("PARAM_EMPTY");
  194. }
  195. \Log::info('batchCustomMsgById:'.$id);
  196. $param = array();
  197. $param['id'] = $id;
  198. $batchCustomMsgService = BatchCustomMsgService::batchCustomMsgById($param);
  199. // \Log::info($batchCustomMsgService);
  200. if (!empty($batchCustomMsgService)) {
  201. return response()->item(new BatchCustomSendMsgsTransformers(), $batchCustomMsgService);
  202. }else{
  203. return response()->success(['data'=>0]);
  204. }
  205. }
  206. /**
  207. * @apiVersion 1.0.0
  208. * @api {GET} OfficialAccount/updateBatchCustomSendMsgStatusById 更新发送客服消息
  209. * @apiGroup OfficialAccount
  210. * @apiName updateBatchCustomSendMsgStatusById
  211. * @apiParam {String} id 客服消息批次id.
  212. * @apiParam {String} status 状态 1待发送 3发送成功 4删除 8发送中 .
  213. * @apiParam {String} del_flag 是否删除:1是 0否.
  214. * @apiSuccessExample {json} Success-Response:
  215. *
  216. * {
  217. * "code": 0,
  218. * "msg": "",
  219. * "data": {
  220. * }
  221. * }
  222. */
  223. function updateBatchCustomSendMsgStatusById(Request $request) {
  224. $id = $request->has('id') ? $request->input('id') : '';
  225. if(empty($id)) {
  226. return response()->error("PARAM_EMPTY");
  227. }
  228. $status = $request->has('status') ? $request->input('status') : '';
  229. if(empty($status)) {
  230. return response()->error("PARAM_EMPTY");
  231. }
  232. $del_flag = $request->has('del_flag') ? $request->input('del_flag') : '0';
  233. \Log::info('updateBatchCustomSendMsgStatusById_start,id:'.$id.' status:'.$status.' $del_flag:'.$del_flag);
  234. $param = array();
  235. $param['id'] = $id;
  236. $param['status'] = $status;
  237. $param['del_flag'] = $del_flag;
  238. $batch_res = BatchCustomMsgService::updateBatchCustomSendMsgStatusById($param);
  239. // 循环子消息
  240. $param = array();
  241. $param['trusteeship'] = 1;
  242. $param['batch_no'] = $id;
  243. $customMsgServices = CustomMsgService::customSendMsgsByTrusteeshipAndBacthNo($param);
  244. // \Log::info($customMsgServices);
  245. if(!empty($customMsgServices)){
  246. foreach($customMsgServices as $customMsgService){
  247. \Log::info('stopBatchCustomSendMsgsById_single:'.json_encode($customMsgService));
  248. $customMsgService = CustomMsgService::updateCustomSendMsgsStatusMulty($customMsgService->id,$status,$del_flag);
  249. }
  250. }
  251. if ($batch_res == 1) {
  252. return response()->success();
  253. }else {
  254. return response()->error('CUSTOMS_SETTING_FAILED');
  255. }
  256. }
  257. /**
  258. * @apiVersion 1.0.0
  259. * @api {GET} OfficialAccount/batchAddCustomSendMsgs 批量添加客服消息
  260. * @apiGroup OfficialAccount
  261. * @apiName batchAddCustomSendMsgs
  262. * @apiParam {String} name 客服消息标题.
  263. * @apiParam {String} send_time 客服消息发送时间.
  264. * @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"}]]
  265. * @apiParam {String} redirect_url 点击消息重定向地址.
  266. * @apiParam {String} sex 用户性别.
  267. * @apiSuccessExample {json} Success-Response:
  268. *
  269. * {
  270. * "code": 0,
  271. * "msg": "",
  272. * "data": []
  273. * }
  274. */
  275. function batchAddCustomSendMsgs(Request $request) {
  276. \Log::info('manage_batchAddCustomSendMsgs_start');
  277. \Log::info($request->all());
  278. $name = $request->has('name') ? $request->input('name') : '';
  279. if(empty($name)) {
  280. return response()->error("PARAM_EMPTY");
  281. }
  282. $send_time = $request->has('send_time') ? $request->input('send_time') : '';
  283. if(empty($send_time)) {
  284. return response()->error("PARAM_EMPTY");
  285. }
  286. $content = $request->has('content') ? $request->input('content') : '';
  287. if(empty($content)) {
  288. return response()->error("PARAM_EMPTY");
  289. }
  290. $redirect_url = $request->has('redirect_url') ? $request->input('redirect_url') : '';
  291. if(empty($redirect_url)) {
  292. return response()->error("PARAM_EMPTY");
  293. }
  294. $sex = $request->has('sex') ? $request->input('sex') : '';
  295. if(empty($sex)) {
  296. return response()->error("PARAM_EMPTY");
  297. }
  298. $customMsgPrams['name'] = $name;
  299. $customMsgPrams['send_time'] = $send_time;
  300. $customMsgPrams['content'] = json_encode($content);
  301. $customMsgPrams['redirect_url'] = $redirect_url;
  302. $customMsgPrams['sex'] = $sex;
  303. $customMsgPrams['subscribe_time'] = 'g';// 关注1天前,有过交互的
  304. $customMsgPrams['trusteeship'] = '1'; // 托管
  305. $customMsgPrams['balance'] = 'z';
  306. $customMsgPrams['order_type'] = 'z';
  307. $customMsgPrams['category_id'] = 'z';
  308. $customMsgPrams['status'] = '1';
  309. $customMsgPrams['is_show_list'] = '0';// 分销界面不展示
  310. \Log::info($customMsgPrams);
  311. $batch_no = '';
  312. $batch_res = BatchCustomMsgService::addBatchCustomSendMsgs($customMsgPrams,$batch_no);
  313. \Log::info('$batch_res:'.$batch_res.' $batch_no:'.$batch_no);
  314. if($batch_res == 1){
  315. $customMsgPrams['batch_no'] = $batch_no;
  316. $official_accounts = OfficialAccountService::getTrusteeshipOfficialAccounts();
  317. \Log::info('getTrusteeshipOfficialAccounts');
  318. // \Log::info($official_accounts);
  319. foreach($official_accounts as $official_account){
  320. $customMsgPrams['appid'] = $official_account->appid;
  321. $customMsgPrams['distribution_channel_id'] = $official_account->distribution_channel_id;
  322. \Log::info('getTrusteeshipOfficialAccounts:appid:'.$official_account->appid.' distribution_channel_id:'.$official_account->distribution_channel_id);
  323. //先判断在发送时间段1小时以内,有没有发起过相同的模板消息,如果有发送过,就提示用户已经创建过相同模板消息,不创建新的模板消息
  324. $isSendCustomer = CustomMsgService::isSendCustomerAtSameTime($customMsgPrams);
  325. if (!empty($isSendCustomer)) {
  326. \Log::info('isSendCustomerAtSameTime already_send:appid:'.$customMsgPrams['appid'].' distribution_channel_id:'.$customMsgPrams['distribution_channel_id']);
  327. continue;
  328. }
  329. $customMsgService = CustomMsgService::addCustomSendMsgs($customMsgPrams);
  330. }
  331. }
  332. if ($batch_res == 1) {
  333. return response()->success();
  334. }elseif ($batch_res == 2) {
  335. return response()->error('CUSTOMS_SEND_FAILED');
  336. }elseif ($batch_res == 3) {
  337. return response()->error('CUSTOMS_DOUBLE_FAILED');
  338. }elseif ($batch_res == 4) {
  339. return response()->error('CUSTOMS_DOUBLE_FAILED');
  340. }elseif ($batch_res == 0) {
  341. return response()->error('CUSTOMS_SEND_FAILED');
  342. }
  343. else{
  344. return response()->error('CUSTOMS_SEND_FAILED');
  345. }
  346. }
  347. /**
  348. * @apiVersion 1.0.0
  349. * @api {GET} OfficialAccount/editCustomSendMsgs 编辑客服消息
  350. * @apiGroup OfficialAccount
  351. * @apiName editCustomSendMsgs
  352. * @apiParam {String} appid 服务号,英文逗号隔开.
  353. * @apiParam {String} distribution_channel_id 渠道号.
  354. * @apiParam {String} name 客服消息标题.
  355. * @apiParam {String} send_time 客服消息发送时间.
  356. * @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"}]]
  357. * @apiParam {String} redirect_url 点击消息重定向地址.
  358. * @apiParam {String} sex 用户性别.
  359. * @apiParam {String} id id.
  360. * @apiSuccessExample {json} Success-Response:
  361. *
  362. * {
  363. * "code": 0,
  364. * "msg": "",
  365. * "data": []
  366. * }
  367. */
  368. // 批量编辑暂时不支持,逻辑复杂
  369. function editCustomSendMsgs(Request $request) {
  370. \Log::info('editCustomSendMsgs_start');
  371. \Log::info($request->all());
  372. return response()->error("PARAM_EMPTY");
  373. }
  374. /**
  375. * @apiVersion 1.0.0
  376. * @api {GET} OfficialAccount/testAddCustomSendMsgs 测试向单个用户发送客服消息
  377. * @apiGroup OfficialAccount
  378. * @apiName testAddCustomSendMsgs
  379. * @apiParam {String} uid 用户id或者openid.
  380. * @apiParam {String} name 客服消息标题.
  381. * @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"}]]
  382. * @apiParam {String} redirect_url 点击消息重定向地址.
  383. * @apiSuccessExample {json} Success-Response:
  384. *
  385. * {
  386. * "code": 0,
  387. * "msg": "",
  388. * "data": []
  389. * }
  390. */
  391. function testAddCustomSendMsgs(Request $request) {
  392. \Log::info('testAddCustomSendMsgs_start');
  393. \Log::info($request->all());
  394. $name = $request->has('name') ? $request->input('name') : '';
  395. if(empty($name)) {
  396. return response()->error("PARAM_EMPTY");
  397. }
  398. $content = $request->has('content') ? $request->input('content') : '';
  399. if(empty($content)) {
  400. return response()->error("PARAM_EMPTY");
  401. }
  402. $redirect_url = $request->has('redirect_url') ? $request->input('redirect_url') : '';
  403. if(empty($redirect_url)) {
  404. return response()->error("PARAM_EMPTY");
  405. }
  406. $uid = $request->has('uid') ? $request->input('uid') : '';
  407. if(empty($uid)) {
  408. return response()->error("PARAM_EMPTY");
  409. }
  410. $customMsgPrams['name'] = $name;
  411. $customMsgPrams['redirect_url'] = $redirect_url;
  412. $customMsgPrams['uid'] = $uid;
  413. $customMsgPrams['distribution_channel_id'] = 14;// 线上改为14
  414. $customMsgPrams['appid'] = 'wxb2aaa55b088f12e9,wxdbc486f1b4f6a8c3';
  415. // 测试发送加上域名
  416. foreach($content as $key=>$_content){
  417. // \Log::info($_content);
  418. $url = env('PROTOCOL').'://site'.encodeDistributionChannelId($customMsgPrams['distribution_channel_id']).'.'.env('CUSTOM_HOST').'.com'.$_content[2]['url'];
  419. \Log::info('key:'.$key.' url:'.$url);
  420. $content[$key][2]['url'] = $url;
  421. }
  422. $customMsgPrams['content'] = json_encode($content);
  423. $customMsgService = CustomMsgService::testAddCustomSendMsgs($customMsgPrams);
  424. if ($customMsgService == 1) {
  425. return response()->success();
  426. }elseif ($customMsgService == 2) {
  427. return response()->error('CUSTOMS_SEND_FAILED');
  428. }elseif ($customMsgService == 0) {
  429. return response()->error('CUSTOMS_SEND_FAILED');
  430. }else{
  431. return response()->error('CUSTOMS_SEND_FAILED');
  432. }
  433. }
  434. public static function get_custom_msg_statistics($customMsgService,$num){
  435. $start_date = date('Y-m-d',strtotime('-7 day'));
  436. $end_date = date('Y-m-d',strtotime('+1 day'));
  437. $stat_type = 'custom_'.$customMsgService->id.'_'.$num;
  438. // \Log::info('get_custom_msg_statistics:'.$customMsgService->distribution_channel_id.' start_date:'.$start_date.' end_date:'.$end_date.' stat_type:'.$stat_type);
  439. $user_pay_stat = SendStatistics::getWechatMsgUseRecord($customMsgService->distribution_channel_id,$stat_type,$start_date,$end_date);
  440. // \Log::info('get_custom_msg_statistics:');\Log::info($user_pay_stat);
  441. $customMsgService->uv = isset($user_pay_stat['uv'])?$user_pay_stat['uv']:0;
  442. $customMsgService->pv = isset($user_pay_stat['pv'])?$user_pay_stat['pv']:0;
  443. $customMsgService->pay_user_num = isset($user_pay_stat['user_num'])?$user_pay_stat['user_num']:0;
  444. $customMsgService->total_order_num = isset($user_pay_stat['order_count'])?$user_pay_stat['order_count']:0;
  445. $customMsgService->suc_order_num = isset($user_pay_stat['success_order_count'])?$user_pay_stat['success_order_count']:0;
  446. $customMsgService->success_order_sum = isset($user_pay_stat['success_order_sum'])?$user_pay_stat['success_order_sum']:0;
  447. if(isset($customMsgService->total_order_num) && $customMsgService->total_order_num > 0){
  448. $customMsgService->order_suc_rate = round(100*$customMsgService->suc_order_num/$customMsgService->total_order_num,2);
  449. }else{
  450. $customMsgService->order_suc_rate = 0;
  451. }
  452. return $customMsgService;
  453. }
  454. }