SmartPushsController.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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\SmartPushMsgTransformer;
  5. use Illuminate\Http\Request;
  6. use GuzzleHttp\Client;
  7. use App\Modules\OfficialAccount\Services\SmartPushMsgService;
  8. use App\Modules\Statistic\Services\SendStatistics;
  9. /**
  10. * 智能推送
  11. * @author zhoulingjie
  12. *
  13. */
  14. class SmartPushsController extends ChannelBaseController
  15. {
  16. /**
  17. * @apiDefine OfficialAccount 公众号
  18. */
  19. /**
  20. * @apiVersion 1.0.0
  21. * @api {GET} OfficialAccount/smartPushMsgById 通过id获取自定义智能推荐内容
  22. * @apiGroup OfficialAccount
  23. * @apiName smartPushMsgById
  24. * @apiParam {String} id 关键字信息id.
  25. */
  26. function smartPushMsgById(Request $request)
  27. {
  28. $id = $request->has('id') ? $request->input('id') : '';
  29. if(empty($id)) {
  30. return response()->error("PARAM_EMPTY");
  31. }
  32. $smartPushMsg['id'] = $id;
  33. $smartPushMsgService = SmartPushMsgService::smartPushMsgById($smartPushMsg);
  34. return response()->item(new SmartPushMsgTransformer(), $smartPushMsgService);
  35. }
  36. /**
  37. * @apiVersion 1.0.0
  38. * @api {GET} OfficialAccount/smartPushByDistributionChannelIdAndCategorySex 获取自定义智能推送内容
  39. * @apiGroup OfficialAccount
  40. * @apiName smartPushByDistributionChannelIdAndCategorySex
  41. * @apiParam {String} category_type 类别.
  42. * @apiParam {String} sex 性别.
  43. */
  44. function smartPushByDistributionChannelIdAndCategorySex(Request $request)
  45. {
  46. $distribution_channel_id = $this->getChannelId();
  47. $category_type = $request->has('category_type') ? $request->input('category_type') : '';
  48. if(empty($category_type)) {
  49. return response()->error("PARAM_EMPTY");
  50. }
  51. $sex = $request->has('sex') ? $request->input('sex') : '';
  52. if(empty($sex)) {
  53. return response()->error("PARAM_EMPTY");
  54. }
  55. $smartPushsMsg = array();
  56. $smartPushsMsg['distribution_channel_id'] = $distribution_channel_id;
  57. $smartPushsMsg['category_type'] = $category_type;
  58. $smartPushsMsg['sex'] = $sex;
  59. $smartPushsMsgService = SmartPushMsgService::smartPushByDistributionChannelIdAndCategorySex($smartPushsMsg);
  60. if($smartPushsMsgService->description){
  61. $smartPushsMsgService->description = json_decode($smartPushsMsgService->description);
  62. }
  63. return response()->item(new SmartPushMsgTransformer(), $smartPushsMsgService);
  64. }
  65. /**
  66. * @apiVersion 1.0.0
  67. * @api {GET} OfficialAccount/checkSexAllEdit 检测是否男女都编辑过了
  68. * @apiGroup OfficialAccount
  69. * @apiName checkSexAllEdit
  70. * @apiParam {String} category_type 类别.
  71. */
  72. function checkSexAllEdit(Request $request)
  73. {
  74. $distribution_channel_id = $this->getChannelId();
  75. $category_type = $request->has('category_type') ? $request->input('category_type') : '';
  76. if(empty($category_type)) {
  77. return response()->error("PARAM_EMPTY");
  78. }
  79. $smartPushsMsg = array();
  80. $smartPushsMsg['distribution_channel_id'] = $distribution_channel_id;
  81. $smartPushsMsg['category_type'] = $category_type;
  82. $resultStatus = SmartPushMsgService::checkSexAllEdit($smartPushsMsg);
  83. if ($resultStatus == 1) {
  84. return response()->success();
  85. }else {
  86. return response()->error('SMART_PUSHS_NOT_ALL_EDIT');
  87. }
  88. }
  89. /**
  90. * @apiVersion 1.0.0
  91. * @api {POST} OfficialAccount/addSmartPushMsg 添加自定义智能推送
  92. * @apiGroup OfficialAccount
  93. * @apiName addSmartPushMsg
  94. * @apiParam {String} name 标题.
  95. * @apiParam {String} category_type 分类.
  96. * @apiParam {String} content 内容.
  97. * @apiParam {String} sex 性别 男:a 女:b.
  98. */
  99. function addSmartPushMsg(Request $request)
  100. {
  101. \Log::info('addSmartPushMsg_start');
  102. \Log::info($request->all());
  103. $name = $request->has('name') ? $request->input('name') : '';
  104. if(empty($name)) {
  105. return response()->error("PARAM_EMPTY");
  106. }
  107. $category_type = $request->has('category_type') ? $request->input('category_type') : '';
  108. if(empty($category_type)) {
  109. return response()->error("PARAM_EMPTY");
  110. }
  111. $content = $request->has('content') ? $request->input('content') : '';
  112. if(empty($content)) {
  113. return response()->error("PARAM_EMPTY");
  114. }
  115. $sex = $request->has('sex') ? $request->input('sex') : '';
  116. if(empty($sex)) {
  117. return response()->error("PARAM_EMPTY");
  118. }
  119. $description = $request->has('description') ? $request->input('description') : '';
  120. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  121. if(empty($book_name)) {
  122. return response()->error("PARAM_EMPTY");
  123. }
  124. $chapter_name = $request->has('chapter_name') ? $request->input('chapter_name') : '';
  125. if(empty($chapter_name)) {
  126. return response()->error("PARAM_EMPTY");
  127. }
  128. $distribution_channel_id = $this->getChannelId();
  129. $smartPushMsgs['name'] = $name;
  130. $smartPushMsgs['category_type'] = $category_type;
  131. $smartPushMsgs['content'] = json_encode($content);
  132. $smartPushMsgs['description'] = json_encode($description);
  133. $smartPushMsgs['book_name'] = $book_name;
  134. $smartPushMsgs['chapter_name'] = $chapter_name;
  135. $smartPushMsgs['sex'] = $sex;
  136. $smartPushMsgs['distribution_channel_id'] = $distribution_channel_id;
  137. $smartPushMsgs['status'] = 1;
  138. $resultStatus = SmartPushMsgService::addSmartPushMsg($smartPushMsgs);
  139. if ($resultStatus == 1) {
  140. return response()->success();
  141. }elseif ($resultStatus == 2) {
  142. return response()->error('SMART_PUSHS_UNSUCCESSFUL');
  143. }elseif ($resultStatus == 3) {
  144. return response()->error('SMART_PUSHS_UNSUCCESSFUL');
  145. }
  146. elseif ($resultStatus == 0) {
  147. return response()->error('SMART_PUSHS_UNSUCCESSFUL');
  148. }else{
  149. return response()->error('SMART_PUSHS_UNSUCCESSFUL');
  150. }
  151. }
  152. /**
  153. * @apiVersion 1.0.0
  154. * @api {POST} OfficialAccount/updateSmartPushMsg 更新自定义智能推送
  155. * @apiGroup OfficialAccount
  156. * @apiName updateSmartPushMsg
  157. * @apiParam {String} id 主键.
  158. * @apiParam {String} name 标题.
  159. * @apiParam {String} category_type 分类.
  160. * @apiParam {String} content 内容.
  161. * @apiParam {String} sex 性别 男:a 女:b.
  162. */
  163. function updateSmartPushMsg(Request $request)
  164. {
  165. \Log::info('updateSmartPushMsg_start');
  166. \Log::info($request->all());
  167. $id = $request->has('id') ? $request->input('id') : '';
  168. if(empty($id)) {
  169. return response()->error("PARAM_EMPTY");
  170. }
  171. $name = $request->has('name') ? $request->input('name') : '';
  172. if(empty($name)) {
  173. return response()->error("PARAM_EMPTY");
  174. }
  175. $category_type = $request->has('category_type') ? $request->input('category_type') : '';
  176. if(empty($category_type)) {
  177. return response()->error("PARAM_EMPTY");
  178. }
  179. $content = $request->has('content') ? $request->input('content') : '';
  180. if(empty($content)) {
  181. return response()->error("PARAM_EMPTY");
  182. }
  183. $sex = $request->has('sex') ? $request->input('sex') : '';
  184. if(empty($sex)) {
  185. return response()->error("PARAM_EMPTY");
  186. }
  187. $description = $request->has('description') ? $request->input('description') : '';
  188. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  189. if(empty($book_name)) {
  190. return response()->error("PARAM_EMPTY");
  191. }
  192. $chapter_name = $request->has('chapter_name') ? $request->input('chapter_name') : '';
  193. if(empty($chapter_name)) {
  194. return response()->error("PARAM_EMPTY");
  195. }
  196. $distribution_channel_id = $this->getChannelId();
  197. $smartPushMsgs['id'] = $id;
  198. $smartPushMsgs['name'] = $name;
  199. $smartPushMsgs['category_type'] = $category_type;
  200. $smartPushMsgs['content'] = json_encode($content);
  201. $smartPushMsgs['description'] = json_encode($description);
  202. $smartPushMsgs['book_name'] = $book_name;
  203. $smartPushMsgs['chapter_name'] = $chapter_name;
  204. $smartPushMsgs['sex'] = $sex;
  205. $smartPushMsgs['distribution_channel_id'] = $distribution_channel_id;
  206. $smartPushMsgs['status'] = 1;
  207. $resultStatus = SmartPushMsgService::updateSmartPushMsg($smartPushMsgs);
  208. if ($resultStatus == 1) {
  209. return response()->success();
  210. }elseif ($resultStatus == 2) {
  211. return response()->error('SMART_PUSHS_UNSUCCESSFUL');
  212. }elseif ($resultStatus == 3) {
  213. return response()->error('SMART_PUSHS_UNSUCCESSFUL');
  214. }
  215. elseif ($resultStatus == 0) {
  216. return response()->error('SMART_PUSHS_UNSUCCESSFUL');
  217. }else{
  218. return response()->error('SMART_PUSHS_UNSUCCESSFUL');
  219. }
  220. }
  221. }