123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- namespace app\api\controller;
- use app\admin\model\CustomMediaPush;
- use app\admin\model\CustomUrl;
- use app\common\controller\Api;
- use think\Db;
- use think\Exception;
- use think\Log;
- /**
- * Custom 相关接口
- */
- class Custom extends Api
- {
- //如果$noNeedLogin为空表示所有接口都需要登录才能请求
- //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
- //如果接口已经设置无需登录,那也就无需鉴权了
- //
- // 无需登录的接口,*表示全部
- protected $noNeedLogin = ['handlestatusapi', 'subscribedelayapi'];
- // 无需鉴权的接口,*表示全部
- protected $noNeedRight = ['handlestatusapi', 'subscribedelayapi'];
- /**
- * @param ids 需要更改的custom_id(array)
- * @param status : (send => 发送中 , hidden => 发送完成)
- * @throws \Exception
- */
- public function handlestatusapi()
- {
- $custom_model = new \app\admin\model\Custom();
- $customUrl_model = new CustomUrl();
- $customMediaPush_model = new CustomMediaPush();
- $params = input();
- $custom_list = $params['custom_list'] ?? [];
- $status = $params['status'] ?? '';
- Log::info('==== handlestatusapi start ====');
- Log::info(print_r($params, true));
- if ($custom_list && $status) {
- $status_origin = [
- \app\common\constants\Custom::CUSTOM_STATUE_SEND,
- \app\common\constants\Custom::CUSTOM_STATUE_HIDDEN
- ];
- if (in_array($status, $status_origin)) {
- $custom_ids_str = implode(',', array_column($custom_list, 'id'));
- if ($status == \app\common\constants\Custom::CUSTOM_STATUE_SEND) {
- # 1.根据参数 media_id,更改custom 表中的状态 ( 如果是status == send , 只需要更改 statue 字段)
- try {
- $custom_model->where('id', 'in', $custom_ids_str)
- ->update(['statue' => $status]);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- $this->error($e->getMessage());
- }
- $custom_push_status = \app\common\constants\Custom::CUSTOM_MEDIA_PUSH_STATUS_SENDING;
- } else {
- # 1.根据参数 media_id,更改custom 表中的状态
- foreach ($custom_list as $k => $item) {
- try {
- $send_num = $item['send_num'] ?? 0;
- $custom_model->where('id', 'eq', $item['id'])
- ->update(['statue' => $status, 'send_num' => $send_num]);
- Log::info('custom 表中的数据statue send_num 更新完成');
- } catch (Exception $e) {
- Log::error($e->getMessage());
- $this->error($e->getMessage());
- }
- }
- $custom_push_status = \app\common\constants\Custom::CUSTOM_MEDIA_PUSH_STATUS_SENT;
- # 5. 更改 custom_url.sendstatus
- if ($status == \app\common\constants\Custom::CUSTOM_STATUE_HIDDEN) {
- try {
- $customUrl_model->where('custom_id', 'in', $custom_ids_str)
- ->update(['sendstatus' => \app\common\constants\Custom::CUSTOM_URL_SENDSTATUS_SENT]);
- Log::info('custom_url 表中的数据更新完成');
- } catch (Exception $e) {
- Log::error($e->getMessage());
- $this->error($e->getMessage());
- }
- }
- }
- # 2.根据参数 media_id,获取需要更改状态的 custom_media_push_id
- $push_ids = $custom_model->where('id', 'in', $custom_ids_str)
- ->column('custom_media_push_id');
- # 3.去掉重复的custom_media_push_id
- $push_ids = array_unique($push_ids);
- if ($push_ids) {
- $custom_push_ids_str = implode(',', $push_ids);
- # 4. 更改 custom_media_push 的状态
- try {
- $customMediaPush_model->where('id', 'in', $custom_push_ids_str)
- ->update(['status' => $custom_push_status]);
- Log::info('custom_media_push 表中的数据更新完成');
- } catch (Exception $e) {
- Log::error($e->getMessage());
- $this->error($e->getMessage());
- }
- }
- } else {
- Log::info('参数status错误');
- $this->error('参数status错误');
- }
- } else {
- $this->error('参数custom_list或status不存在');
- }
- Log::info('handlestatusapi Success');
- Log::info('==== handlestatusapi end ====');
- $this->success('成功');
- }
- /**
- * 关注延时推送的配置
- */
- public function subscribedelayapi()
- {
- $channelId = 0;
- $params = json_decode(file_get_contents("php://input"), true);
- if ($params) {
- $channelId = $params['channel_id'] ?? 0;
- }
- if (!$channelId) {
- $channelId = $this->request->param('channel_id', 0);
- }
- $data = model("SubscribeDelayPush")->getInfo($channelId);
- $result = [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ];
- exit(json_encode($result, JSON_UNESCAPED_SLASHES));
- }
- }
|