| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\ComplaintModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 投诉建议管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class ComplaintService
- * @package App\Services\Api
- */
- class ComplaintService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * ComplaintService constructor.
- */
- public function __construct()
- {
- $this->model = new ComplaintModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['a.mark' => 1];
- $status = isset($params['status']) ? $params['status'] : 0;
- $userId = isset($params['user_id']) ? $params['user_id'] : 0;
- if ($userId > 0) {
- $where['a.user_id'] = $userId;
- }
- if ($status > 0) {
- $where['a.status'] = $status;
- }
- $list = $this->model->from('complaint as a')
- ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
- ->where($where)
- ->where(function ($query) use ($params) {
- $keyword = isset($params['keyword']) ? $params['keyword'] : '';
- if ($keyword) {
- $query->where('a.content', 'like', "%{$keyword}%");
- }
- })
- ->select(['a.*'])
- ->orderBy('a.create_time', 'desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- if ($list) {
- foreach ($list['data'] as &$item) {
- $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
- }
- }
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- }
- /**
- * 提交内容
- * @param $userId
- * @param $params
- * @return mixed
- */
- public function submit($userId, $params)
- {
- $albums = isset($params['albums']) ? get_format_images($params['albums'], '') : '';
- $realname = isset($params['realname']) ? trim($params['realname']) : '';
- $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
- $content = isset($params['content']) ? trim($params['content']) : '';
- if (empty($realname)) {
- $this->error = '请填写姓名';
- return false;
- }
- if (empty($mobile)) {
- $this->error = '请填写联系方式';
- return false;
- }
- if (empty($content)) {
- $this->error = '请填写您的问题';
- return false;
- }
- $cacheKey = "caches:members:complaint:{$userId}";
- if (RedisService::get($cacheKey)) {
- $this->error = '您近期已经提交过,请30秒后重试';
- return false;
- }
- $data = [
- 'user_id' => $userId,
- 'realname' => $realname,
- 'mobile' => $mobile,
- 'content' => $content,
- 'albums' => $albums,
- 'create_time' => time(),
- 'update_time' => time(),
- 'status' => 1,
- 'mark' => 1,
- ];
- if (!$id = $this->model->insertGetId($data)) {
- $this->error = '提交失败';
- return false;
- }
- $this->error = '提交成功';
- RedisService::set($cacheKey, $data, 30);
- return ['id' => $id];
- }
- }
|