You've already forked guangan
138 lines
5.2 KiB
PHP
138 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace plugin\ticket\controller;
|
|
|
|
use plugin\points_mall\service\UserPointService;
|
|
use plugin\ticket\model\TicketCommonReply;
|
|
use plugin\ticket\model\TicketTicket;
|
|
use plugin\ticket\model\TicketType;
|
|
use plugin\ticket\model\TicketUserShare;
|
|
use think\admin\Controller;
|
|
use think\admin\helper\QueryHelper;
|
|
use think\admin\model\SystemUser;
|
|
|
|
/**
|
|
* 用户随手拍
|
|
*/
|
|
class UserShare extends Controller
|
|
{
|
|
/**
|
|
* 随手拍列表
|
|
* @auth true
|
|
* @menu true
|
|
* @return void
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->title = '用户随手拍';
|
|
$this->type_list = TicketType::getList();
|
|
TicketUserShare::mQuery()->layTable(function () {
|
|
|
|
}, function (QueryHelper $query) {
|
|
$query->like(['title|content|ticket_address|contact_phone#keyword'])
|
|
->dateBetween(['create_at'])
|
|
->equal(['status', 'type_id']);
|
|
$query->append(['imgs_arr', 'type_name']);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 随手拍详情
|
|
* @auth true
|
|
* @menu true
|
|
* @return void
|
|
*/
|
|
public function detail()
|
|
{
|
|
$this->title = '随手拍详情';
|
|
$where = $this->_vali([
|
|
'id.require' => '随手拍ID不能为空',
|
|
]);
|
|
$this->vo = TicketUserShare::mk()->where($where)->with(['linked_ticket'])->findOrEmpty();
|
|
if ($this->vo->isEmpty()) $this->error('用户随手拍不存在!');
|
|
if (!$this->vo->linked_ticket_id) {
|
|
$this->ticket_list = TicketTicket::mk()->scope(['avail'])->select();
|
|
} else {
|
|
$this->ticket_list = [];
|
|
}
|
|
$this->type_list = TicketType::getList();
|
|
$this->user_list = SystemUser::query()->select();
|
|
$this->common_reply_list = TicketCommonReply::query()->scope(['avail'])->select();
|
|
$this->fetch('detail');
|
|
}
|
|
|
|
public function link()
|
|
{
|
|
$basic_data = $this->_vali([
|
|
'id.require' => '随手拍ID不能为空',
|
|
'_type.require' => '类型不能为空',
|
|
'content.require' => '回复内容不能为空',
|
|
'point_aware.require' => '奖励积分不能为空',
|
|
'point_aware.number' => '奖励积分必须为数字',
|
|
]);
|
|
$userShare = TicketUserShare::mk()->where(['id' => $basic_data['id']])->findOrEmpty();
|
|
if ($userShare->isEmpty()) $this->error('用户随手拍不存在!');
|
|
if ($userShare->status !== 0) $this->error('用户随手拍已处理!');
|
|
$ticket_id = null;
|
|
$result = "已形成工单交由专人处理";
|
|
switch ($basic_data['_type']) {
|
|
case 'new':
|
|
$data = $this->_vali([
|
|
'type_id.require' => '类型不能为空',
|
|
'user_id.require' => '请选择处理人员',
|
|
]);
|
|
$ticket = TicketTicket::mk()->create([
|
|
'source_type' => 1,
|
|
'type_id' => $data['type_id'],
|
|
'user_type' => 'user',
|
|
'user_id' => $userShare->user_id,
|
|
'current_admin_id' => $data['user_id'],
|
|
'title' => $userShare->title,
|
|
'content' => $userShare->content,
|
|
'ticket_region' => $userShare->ticket_region,
|
|
'ticket_address' => $userShare->ticket_address,
|
|
'contact_name' => $userShare->contact_name,
|
|
'contact_phone' => $userShare->contact_phone,
|
|
'lat' => $userShare->lat,
|
|
'lng' => $userShare->lng,
|
|
'imgs' => $userShare->imgs,
|
|
'status' => 0,
|
|
]);
|
|
$ticket->source = $userShare;
|
|
$ticket->save();
|
|
$ticket_id = $ticket->id;
|
|
break;
|
|
case 'exist':
|
|
$data = $this->_vali([
|
|
'ticket_id.require' => '请选择处理工单',
|
|
]);
|
|
$ticket = TicketTicket::mk()->where(['id' => $data['ticket_id']])->findOrEmpty();
|
|
if ($ticket->isEmpty()) $this->error('工单不存在!');
|
|
$ticket_id = $data['ticket_id'];
|
|
$ticket->source = $userShare;
|
|
$ticket->save();
|
|
break;
|
|
case 'skip':
|
|
$result = "已处理完毕";
|
|
break;
|
|
default:
|
|
$this->error('参数错误');
|
|
}
|
|
$userShare->linked_ticket_id = $ticket_id;
|
|
$userShare->response = $basic_data['content'];
|
|
$userShare->point_aware = $basic_data['point_aware'];
|
|
UserPointService::addUserPoint($userShare->user_id, $basic_data['point_aware'], '用户随手拍奖励积分');
|
|
$userShare->status = 1;
|
|
$userShare->save();
|
|
$adminInfo = $this->request->session('user');
|
|
$userShare->logs()->save([
|
|
'op_name' => $adminInfo["username"],
|
|
'content' => $basic_data['content'],
|
|
'result' => $result,
|
|
]);
|
|
$this->success('处理成功!');
|
|
}
|
|
} |