123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace Modules\WechatPlatform\Http\Controllers;
- use Catch\Base\CatchController;
- use Catch\Exceptions\FailedException;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Modules\Manage\Enmus\MiniprogramType;
- use Modules\User\Http\Controllers\UserTrait;
- use Modules\WechatPlatform\Http\Requests\WechatKeywordsRequest;
- use Modules\WechatPlatform\Services\WechatKeywordsService;
- class WechatKeywordsController extends CatchController
- {
- use UserTrait;
-
- public function List(Request $request)
- {
- }
-
- public function add(WechatKeywordsRequest $request)
- {
- $param = $request->validated();
- $param = $this->WechatKeywordsParam($param);
- $userContext = $this->getUserContext(null);
- $param['user_id'] = $userContext['loginUser']->id;
- $param['puser_id'] = $userContext['loginUser']->pid;
- return WechatKeywordsService::addKeyword($param);
- }
- private function WechatKeywordsParam(mixed $param)
- {
- if (getProp($param,'type') != 'miniprogram'){
- return $param;
- }
- $info = DB::table('miniprogram')->where('id',$param['miniprogram_id'])->first();
- if(empty($info)){
- throw new FailedException("小程序不正确");
- }
- if($info->status != 1){
- throw new FailedException("此小程序暂不提供使用");
- }
- if ($info->type != MiniprogramType::WEIXIN->value()){
- throw new FailedException("关键词回复设置仅支持微信小程序");
- }
- $param['miniprogram_appid'] = $info->appid;
- $info = DB::table('user_has_miniprograms')->where('uid',$this->getLoginUserId())->where('miniprogram_id',$param['miniprogram_id'])->where('is_enabled',1)->value('id');
- if(empty($info)){
- throw new FailedException("没有此小程序的使用权限");
- }
- return $param;
- }
-
- public function edit($id, WechatKeywordsRequest $request)
- {
- }
-
- public function detail($id)
- {
- }
-
- public function allocation($id,Request $request)
- {
- }
-
- public function del($id)
- {
- }
- }
|