| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- // +----------------------------------------------------------------------
- // | saiadmin [ saiadmin快速开发框架 ]
- // +----------------------------------------------------------------------
- namespace plugin\saiadmin\app\logic\miniProgram;
- use plugin\saiadmin\app\model\miniProgram\MiniProgramShareSetting;
- use plugin\saiadmin\basic\think\BaseLogic;
- use plugin\saiadmin\exception\ApiException;
- /**
- * 小程序分享设置逻辑层
- */
- class ShareSettingsLogic extends BaseLogic
- {
- public function __construct()
- {
- $this->model = new MiniProgramShareSetting();
- }
- public function getItems(): array
- {
- return $this->model
- ->field(['id', 'share_name', 'share_title', 'share_image'])
- ->order('id', 'asc')
- ->select()
- ->toArray();
- }
- public function updateSetting(array $data): bool
- {
- $id = (int) ($data['id'] ?? 0);
- if ($id <= 0) {
- throw new ApiException('分享设置参数错误');
- }
- $model = $this->model->findOrEmpty($id);
- if ($model->isEmpty()) {
- throw new ApiException('分享设置不存在');
- }
- $shareName = trim((string) ($data['share_name'] ?? ''));
- $shareTitle = trim((string) ($data['share_title'] ?? ''));
- $shareImage = trim((string) ($data['share_image'] ?? ''));
- if ($shareName === '' || mb_strlen($shareName) > 100) {
- throw new ApiException('请输入正确的分享名称');
- }
- if ($shareTitle === '' || mb_strlen($shareTitle) > 255) {
- throw new ApiException('请输入正确的分享标题');
- }
- if (mb_strlen($shareImage) > 500) {
- throw new ApiException('分享图片地址不能超过 500 个字符');
- }
- return $model->save([
- 'share_name' => $shareName,
- 'share_title' => $shareTitle,
- 'share_image' => $shareImage,
- ]) !== false;
- }
- }
|