123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- namespace App\Http\Controllers\Channel\OfficialAccount;
- use App\Http\Controllers\Channel\BaseController as ChannelBaseController;
- use App\Http\Controllers\Channel\OfficialAccount\Transformers\SmartPushMsgTransformer;
- use Illuminate\Http\Request;
- use GuzzleHttp\Client;
- use App\Modules\OfficialAccount\Services\SmartPushMsgService;
- use App\Modules\Statistic\Services\SendStatistics;
- /**
- * 智能推送
- * @author zhoulingjie
- *
- */
- class SmartPushsController extends ChannelBaseController
- {
- /**
- * @apiDefine OfficialAccount 公众号
- */
- /**
- * @apiVersion 1.0.0
- * @api {GET} OfficialAccount/smartPushMsgById 通过id获取自定义智能推荐内容
- * @apiGroup OfficialAccount
- * @apiName smartPushMsgById
- * @apiParam {String} id 关键字信息id.
- */
- function smartPushMsgById(Request $request)
- {
- $id = $request->has('id') ? $request->input('id') : '';
- if(empty($id)) {
- return response()->error("PARAM_EMPTY");
- }
- $smartPushMsg['id'] = $id;
- $smartPushMsgService = SmartPushMsgService::smartPushMsgById($smartPushMsg);
- return response()->item(new SmartPushMsgTransformer(), $smartPushMsgService);
- }
- /**
- * @apiVersion 1.0.0
- * @api {GET} OfficialAccount/smartPushByDistributionChannelIdAndCategorySex 获取自定义智能推送内容
- * @apiGroup OfficialAccount
- * @apiName smartPushByDistributionChannelIdAndCategorySex
- * @apiParam {String} category_type 类别.
- * @apiParam {String} sex 性别.
- */
- function smartPushByDistributionChannelIdAndCategorySex(Request $request)
- {
- $distribution_channel_id = $this->getChannelId();
- $category_type = $request->has('category_type') ? $request->input('category_type') : '';
- if(empty($category_type)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $sex = $request->has('sex') ? $request->input('sex') : '';
- if(empty($sex)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $smartPushsMsg = array();
- $smartPushsMsg['distribution_channel_id'] = $distribution_channel_id;
- $smartPushsMsg['category_type'] = $category_type;
- $smartPushsMsg['sex'] = $sex;
- $smartPushsMsgService = SmartPushMsgService::smartPushByDistributionChannelIdAndCategorySex($smartPushsMsg);
- if($smartPushsMsgService->description){
- $smartPushsMsgService->description = json_decode($smartPushsMsgService->description);
- }
- return response()->item(new SmartPushMsgTransformer(), $smartPushsMsgService);
- }
-
- /**
- * @apiVersion 1.0.0
- * @api {GET} OfficialAccount/checkSexAllEdit 检测是否男女都编辑过了
- * @apiGroup OfficialAccount
- * @apiName checkSexAllEdit
- * @apiParam {String} category_type 类别.
- */
-
- function checkSexAllEdit(Request $request)
- {
-
- $distribution_channel_id = $this->getChannelId();
- $category_type = $request->has('category_type') ? $request->input('category_type') : '';
- if(empty($category_type)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $smartPushsMsg = array();
- $smartPushsMsg['distribution_channel_id'] = $distribution_channel_id;
- $smartPushsMsg['category_type'] = $category_type;
-
- $resultStatus = SmartPushMsgService::checkSexAllEdit($smartPushsMsg);
- if ($resultStatus == 1) {
- return response()->success();
- }else {
- return response()->error('SMART_PUSHS_NOT_ALL_EDIT');
- }
- }
- /**
- * @apiVersion 1.0.0
- * @api {POST} OfficialAccount/addSmartPushMsg 添加自定义智能推送
- * @apiGroup OfficialAccount
- * @apiName addSmartPushMsg
- * @apiParam {String} name 标题.
- * @apiParam {String} category_type 分类.
- * @apiParam {String} content 内容.
- * @apiParam {String} sex 性别 男:a 女:b.
- */
- function addSmartPushMsg(Request $request)
- {
- \Log::info('addSmartPushMsg_start');
- \Log::info($request->all());
- $name = $request->has('name') ? $request->input('name') : '';
- if(empty($name)) {
- return response()->error("PARAM_EMPTY");
- }
- $category_type = $request->has('category_type') ? $request->input('category_type') : '';
- if(empty($category_type)) {
- return response()->error("PARAM_EMPTY");
- }
- $content = $request->has('content') ? $request->input('content') : '';
- if(empty($content)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $sex = $request->has('sex') ? $request->input('sex') : '';
- if(empty($sex)) {
- return response()->error("PARAM_EMPTY");
- }
- $description = $request->has('description') ? $request->input('description') : '';
- $book_name = $request->has('book_name') ? $request->input('book_name') : '';
- if(empty($book_name)) {
- return response()->error("PARAM_EMPTY");
- }
- $chapter_name = $request->has('chapter_name') ? $request->input('chapter_name') : '';
- if(empty($chapter_name)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $distribution_channel_id = $this->getChannelId();
- $smartPushMsgs['name'] = $name;
- $smartPushMsgs['category_type'] = $category_type;
- $smartPushMsgs['content'] = json_encode($content);
- $smartPushMsgs['description'] = json_encode($description);
- $smartPushMsgs['book_name'] = $book_name;
- $smartPushMsgs['chapter_name'] = $chapter_name;
- $smartPushMsgs['sex'] = $sex;
- $smartPushMsgs['distribution_channel_id'] = $distribution_channel_id;
- $smartPushMsgs['status'] = 1;
-
- $resultStatus = SmartPushMsgService::addSmartPushMsg($smartPushMsgs);
- if ($resultStatus == 1) {
- return response()->success();
- }elseif ($resultStatus == 2) {
- return response()->error('SMART_PUSHS_UNSUCCESSFUL');
- }elseif ($resultStatus == 3) {
- return response()->error('SMART_PUSHS_UNSUCCESSFUL');
- }
- elseif ($resultStatus == 0) {
- return response()->error('SMART_PUSHS_UNSUCCESSFUL');
- }else{
- return response()->error('SMART_PUSHS_UNSUCCESSFUL');
- }
- }
-
- /**
- * @apiVersion 1.0.0
- * @api {POST} OfficialAccount/updateSmartPushMsg 更新自定义智能推送
- * @apiGroup OfficialAccount
- * @apiName updateSmartPushMsg
- * @apiParam {String} id 主键.
- * @apiParam {String} name 标题.
- * @apiParam {String} category_type 分类.
- * @apiParam {String} content 内容.
- * @apiParam {String} sex 性别 男:a 女:b.
- */
-
- function updateSmartPushMsg(Request $request)
- {
- \Log::info('updateSmartPushMsg_start');
- \Log::info($request->all());
-
- $id = $request->has('id') ? $request->input('id') : '';
- if(empty($id)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $name = $request->has('name') ? $request->input('name') : '';
- if(empty($name)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $category_type = $request->has('category_type') ? $request->input('category_type') : '';
- if(empty($category_type)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $content = $request->has('content') ? $request->input('content') : '';
- if(empty($content)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $sex = $request->has('sex') ? $request->input('sex') : '';
- if(empty($sex)) {
- return response()->error("PARAM_EMPTY");
- }
- $description = $request->has('description') ? $request->input('description') : '';
- $book_name = $request->has('book_name') ? $request->input('book_name') : '';
- if(empty($book_name)) {
- return response()->error("PARAM_EMPTY");
- }
- $chapter_name = $request->has('chapter_name') ? $request->input('chapter_name') : '';
- if(empty($chapter_name)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $distribution_channel_id = $this->getChannelId();
-
- $smartPushMsgs['id'] = $id;
- $smartPushMsgs['name'] = $name;
- $smartPushMsgs['category_type'] = $category_type;
- $smartPushMsgs['content'] = json_encode($content);
- $smartPushMsgs['description'] = json_encode($description);
- $smartPushMsgs['book_name'] = $book_name;
- $smartPushMsgs['chapter_name'] = $chapter_name;
- $smartPushMsgs['sex'] = $sex;
- $smartPushMsgs['distribution_channel_id'] = $distribution_channel_id;
- $smartPushMsgs['status'] = 1;
-
- $resultStatus = SmartPushMsgService::updateSmartPushMsg($smartPushMsgs);
-
- if ($resultStatus == 1) {
- return response()->success();
- }elseif ($resultStatus == 2) {
- return response()->error('SMART_PUSHS_UNSUCCESSFUL');
- }elseif ($resultStatus == 3) {
- return response()->error('SMART_PUSHS_UNSUCCESSFUL');
- }
- elseif ($resultStatus == 0) {
- return response()->error('SMART_PUSHS_UNSUCCESSFUL');
- }else{
- return response()->error('SMART_PUSHS_UNSUCCESSFUL');
- }
-
- }
- }
|