123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- /**
- * Author: luzheng.liu
- * Time: 2020/10/27 23:19
- */
- namespace app\index\controller;
- use app\common\service\SettingService;
- use app\index\BaseController;
- use app\index\model\SettingModel;
- use app\common\until\Until;
- use think\facade\Session;
- use think\Request;
- class Setting extends BaseController {
- public function index() {
- $input = request()->get();
- $model = new SettingModel();
- $model->setPage((int)$input['page'] ?: 1);
- $model->setPageSize((int)$input['pageSize'] ?: 10);
- // if($this->isAdmin()){
- // $where = [];
- // }else {
- // $where[] = ['status', '=', 1];
- // }
- $where = [];
- if (!empty($input['channel_name'])) {
- $where[] = ['channel_name', 'like', '%' . $input['channel_name'] . '%'];
- }
- $model->setWhere($where);
- $data = $model->getPageList($model);
- Until::output($data);
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read() {
- $model = new SettingModel();
- $data = $model::where(['id' => (int)input('id')])->find();
- Until::output(['info' => Until::modelToArray($data)]);
- }
- /**
- * 保存更新的资源
- *
- * @return \think\Response
- */
- public function update() {
- $input = Until::getInput();
- $rule = [
- 'site_id' => 'require',
- 'unique_key' => 'require',
- 'domain|域名' => 'require',
- 'channel_id|频道id' => 'require',
- 'channel_name|频道id' => 'require',
- 'channel_auth_code|频道授权码' => 'require',
- 'redirct_url|跳转链接' => 'require',
- 'auth_redirct_url|乙方跳转链接' => 'require',
- 'id' => 'require'
- ];
- Until::check($rule, $input);
- $service = new SettingService();
- $service->setAuthUrl($input['channel_id'], $input['redirct_url']);
- (new SettingModel())::where(['id' => (int)$input['id']])->update([
- 'site_id' => $input['site_id'],
- 'unique_key' => $input['unique_key'],
- 'domain' => $input['domain'],
- 'channel_id' => $input['channel_id'],
- 'channel_name' => $input['channel_name'],
- 'channel_auth_code' => $input['channel_auth_code'],
- 'redirct_url' => $input['redirct_url'],
- 'auth_redirct_url' => $input['auth_redirct_url'],
- ]);
- Until::output(['id' => $input['id']]);
- }
- public function save() {
- $input = Until::getInput();
- $rule = [
- 'site_id' => 'require',
- 'unique_key' => 'require',
- 'domain|域名' => 'require',
- 'channel_id|频道id' => 'require',
- 'channel_name|频道名称' => 'require',
- 'channel_auth_code|频道授权码' => 'require',
- 'redirct_url|跳转链接' => 'require',
- 'auth_redirct_url|乙方跳转链接' => 'require',
- ];
- Until::check($rule, $input);
- $service = new SettingService();
- $service->verifyChannelName($input['channel_id'], $input['channel_name']);
- $service->setAuthUrl($input['channel_id'], $input['redirct_url']);
- $id = (new SettingModel())->insertGetId([
- 'site_id' => $input['site_id'],
- 'unique_key' => $input['unique_key'],
- 'domain' => $input['domain'],
- 'channel_id' => $input['channel_id'],
- 'channel_name' => $input['channel_name'],
- 'channel_auth_code' => $input['channel_auth_code'],
- 'redirct_url' => $input['redirct_url'],
- 'auth_redirct_url' => $input['auth_redirct_url'],
- ]);
- Until::output(['id' => $id]);
- }
- public function authCode($channelId) {
- $authCode = (new SettingService())->getAuthCode((int)$channelId);
- Until::output(['authCode' => $authCode]);
- }
- }
|