| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /**
- * 用户反馈仓库
- */
- declare(strict_types=1);
- namespace App\Repositories;
- use App\Model\FeedbackModel;
- use App\Model\UserModel;
- use App\Repositories\Service\CommonService;
- use Carbon\Carbon;
- use KZ2\Repositories\Model\Repository;
- class FeedbackRepository extends Repository
- {
- public function model()
- {
- return FeedbackModel::class;
- }
- /**
- * 回复反馈
- * @return mixed
- * @throws \Psr\SimpleCache\InvalidArgumentException
- */
- public function feedbackReply($inputData)
- {
- $rid = strval(data_get($inputData, 'rid'));
- $uid = strval(data_get($inputData, 'uid'));
- $type = intval(data_get($inputData, 'type'));
- $content = strval(data_get($inputData, 'content'));
- $create = FeedbackModel::query()->create(
- [
- 'rid' => $rid,
- 'status' => 1,
- 'uid' => $uid,
- 'type' => $type,
- 'content' => $content,
- ]
- );
- // if ($type == 2) {
- // $create->content = make(CommonService::class)
- // ->getImageUrl($create->content);
- // }
- Carbon::setLocale('zh');
- $create->time = Carbon::parse($create->created_at)->diffForHumans();
- unset($create->uid, $create->created_at);
- return $create;
- }
- /**
- * 管理后台获取反馈列表
- */
- public function getAdminList($inputData)
- {
- $page = intval(data_get($inputData, 'page'));
- $page_size = intval(data_get($inputData, 'page_size'));
- $name = strval(data_get($inputData, 'name', ''));
- $code = strval(data_get($inputData, 'code', ''));
- $content = strval(data_get($inputData, 'content', ''));
- $status = strval(data_get($inputData, 'status', ''));
- // $user_id = strval(data_get($inputData, 'user_id', ''));
- $device_type = strval(data_get($inputData, 'device_type', ''));
- $query = 'SELECT uid, max(id) id FROM feedback GROUP BY uid';
- $model = FeedbackModel::query()
- ->with('user')->from('feedback as f1');
- if ($name) {
- $code = UserModel::query()->where('nick', 'like', $name . '%')
- ->value('code');
- }
- if (is_numeric($status)) {
- $model = $model->where('f1.status', $status);
- }
- if ($code) {
- $model = $model->where('f1.uid', $code);
- }
- if ($device_type) {
- $model = $model->where('f1.device_type', $device_type);
- }
- // if ($user_id) {
- // $model = $model->where('f1.user_id', $user_id);
- // }
- if ($content) {
- $model = $model->where('f1.content', 'like', '%' . $content . '%');
- }
- $list = $model->joinSub($query, 'f2', 'f1.uid', '=', 'f2.uid')
- ->whereRaw('f1.id = f2.id')
- ->orderByDesc('f1.created_at')
- ->paginate($page_size, ['*'], 'page', $page);
- // foreach ($list as $item) {
- // if ($item['type'] == 2) {
- // $item->content = make(CommonService::class)
- // ->getImageUrl($item->content, true);
- // }
- // }
- return $list;
- }
- public function getTalkList($uid, $page, $page_size)
- {
- $result = FeedbackModel::query()
- ->where(['uid' => $uid])
- ->paginate(
- $page_size,
- ['type','content','rid','created_at'],
- 'page',
- $page
- );
- foreach ($result as $v) {
- // if ($v->type == 2) {
- // $v->content = make(CommonService::class)
- // ->getImageUrl($v->content, true);
- // }
- Carbon::setLocale('zh');
- $v->time = Carbon::parse($v->created_at)->diffForHumans();
- unset($v->created_at);
- }
- return $result;
- }
- }
|