241 行
8.0 KiB
PHP
241 行
8.0 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\Backend;
|
|
|
|
/**
|
|
* 师傅档案
|
|
*
|
|
* @icon fa fa-circle-o
|
|
*/
|
|
class Master extends Backend
|
|
{
|
|
|
|
/**
|
|
* Master模型对象
|
|
* @var \app\admin\model\Master
|
|
*/
|
|
protected $model = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new \app\admin\model\Master;
|
|
$this->view->assign("workStatusList", $this->model->getWorkStatusList());
|
|
$this->view->assign("verifyStatusList", $this->model->getVerifyStatusList());
|
|
}
|
|
|
|
protected $relationSearch = true;
|
|
|
|
public function index()
|
|
{
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
if (false === $this->request->isAjax()) {
|
|
return $this->view->fetch();
|
|
}
|
|
if ($this->request->request('keyField')) {
|
|
return $this->selectpage();
|
|
}
|
|
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
|
$list = $this->model
|
|
->with(['user'])
|
|
->where($where)
|
|
->order($sort, $order)
|
|
->paginate($limit);
|
|
|
|
// 合并查出当前页每个师傅拥有的技能
|
|
$items = $list->items();
|
|
$masterIds = array_column($items, 'id');
|
|
$skillsGroup = [];
|
|
if (!empty($masterIds)) {
|
|
$allSkills = \think\Db::name('master_skill')
|
|
->where('master_id', 'in', $masterIds)
|
|
->where('status', 'normal')
|
|
->select();
|
|
foreach ($allSkills as $sk) {
|
|
$name = !empty($sk['skill_name']) ? $sk['skill_name'] : '';
|
|
if ($name) {
|
|
$skillsGroup[$sk['master_id']][] = $name;
|
|
}
|
|
}
|
|
}
|
|
foreach ($items as &$it) {
|
|
$it['skills_list'] = $skillsGroup[$it['id']] ?? [];
|
|
}
|
|
|
|
$result = ['total' => $list->total(), 'rows' => $items];
|
|
return json($result);
|
|
}
|
|
|
|
/**
|
|
* 师傅服务技能管理(内置于师傅列表)
|
|
*/
|
|
public function skills($ids = null)
|
|
{
|
|
$row = $this->model->find($ids);
|
|
if (!$row) {
|
|
$this->error(__('No Results were found'));
|
|
}
|
|
|
|
if ($this->request->isPost()) {
|
|
$selectedSkills = (array)$this->request->post('skills/a', []);
|
|
$customText = trim((string)$this->request->post('custom_text', ''));
|
|
|
|
// 1. 处理自定义输入的技能
|
|
$customNames = [];
|
|
if (!empty($customText)) {
|
|
$parts = preg_split('/[,,\s]+/u', $customText);
|
|
foreach ($parts as $p) {
|
|
$p = trim($p);
|
|
if (!empty($p) && !in_array($p, $customNames) && !in_array($p, $selectedSkills)) {
|
|
$customNames[] = $p;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. 清理当前师傅原有的技能
|
|
\think\Db::name('master_skill')->where('master_id', $row['id'])->delete();
|
|
|
|
// 3. 写入选中的技能
|
|
$dictRows = \think\Db::name('skill_dict')->where('name', 'in', $selectedSkills)->select();
|
|
$dictMap = [];
|
|
foreach ($dictRows as $dr) {
|
|
$dictMap[$dr['name']] = $dr;
|
|
}
|
|
|
|
$now = time();
|
|
foreach ($selectedSkills as $sName) {
|
|
$dict = $dictMap[$sName] ?? null;
|
|
\think\Db::name('master_skill')->insert([
|
|
'master_id' => $row['id'],
|
|
'cat_id' => 0,
|
|
'skill_id' => $dict ? $dict['id'] : 0,
|
|
'skill_name' => $sName,
|
|
'category' => $dict ? $dict['category'] : '服务技能',
|
|
'is_custom' => 0,
|
|
'cert_image' => '',
|
|
'status' => 'normal',
|
|
'createtime' => $now
|
|
]);
|
|
}
|
|
|
|
// 4. 处理自定义输入的技能(沉淀入库)
|
|
foreach ($customNames as $cName) {
|
|
$exist = \think\Db::name('skill_dict')->where('name', $cName)->find();
|
|
if (!$exist) {
|
|
$skillDictId = \think\Db::name('skill_dict')->insertGetId([
|
|
'category_id'=> 0,
|
|
'category' => '其他技能',
|
|
'name' => $cName,
|
|
'source' => 'custom',
|
|
'master_id' => $row['id'],
|
|
'weigh' => 0,
|
|
'status' => 'normal',
|
|
'createtime' => $now,
|
|
'updatetime' => $now
|
|
]);
|
|
} else {
|
|
$skillDictId = $exist['id'];
|
|
}
|
|
|
|
\think\Db::name('master_skill')->insert([
|
|
'master_id' => $row['id'],
|
|
'cat_id' => 0,
|
|
'skill_id' => $skillDictId,
|
|
'skill_name' => $cName,
|
|
'category' => '其他技能',
|
|
'is_custom' => 1,
|
|
'cert_image' => '',
|
|
'status' => 'normal',
|
|
'createtime' => $now
|
|
]);
|
|
}
|
|
|
|
$this->success('技能配置更新成功');
|
|
}
|
|
|
|
// 读取技能字典全部分类与技能
|
|
$categories = \think\Db::name('skill_category')->where('status', 'normal')->order('weigh desc')->select();
|
|
$allDictSkills = \think\Db::name('skill_dict')->where('status', 'normal')->order('weigh desc')->select();
|
|
|
|
$catTree = [];
|
|
foreach ($categories as $cat) {
|
|
$catTree[$cat['name']] = [];
|
|
}
|
|
foreach ($allDictSkills as $item) {
|
|
$cName = $item['category'];
|
|
if (!isset($catTree[$cName])) {
|
|
$catTree[$cName] = [];
|
|
}
|
|
$catTree[$cName][] = $item;
|
|
}
|
|
|
|
// 读取当前师傅已拥有的技能
|
|
$mySkills = \think\Db::name('master_skill')->where('master_id', $row['id'])->select();
|
|
$selectedSkills = [];
|
|
$customArr = [];
|
|
foreach ($mySkills as $ms) {
|
|
if ($ms['is_custom'] == 1) {
|
|
$customArr[] = $ms['skill_name'];
|
|
} else {
|
|
$selectedSkills[] = $ms['skill_name'];
|
|
}
|
|
}
|
|
|
|
$this->view->assign('row', $row);
|
|
$this->view->assign('catTree', $catTree);
|
|
$this->view->assign('selectedSkills', $selectedSkills);
|
|
$this->view->assign('customText', implode(' ', $customArr));
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
/**
|
|
* 师傅全景档案画像
|
|
*/
|
|
public function detail($ids = null)
|
|
{
|
|
$row = $this->model->with(['user'])->find($ids);
|
|
if (!$row) {
|
|
$this->error(__('No Results were found'));
|
|
}
|
|
|
|
// 1. 最近接单记录
|
|
$recentOrders = \think\Db::name('order')
|
|
->where('master_id', $row['id'])
|
|
->order('id desc')
|
|
->limit(6)
|
|
->select();
|
|
|
|
// 2. 提现流水
|
|
$recentWithdraws = \think\Db::name('withdraw')
|
|
->where('master_id', $row['id'])
|
|
->order('id desc')
|
|
->limit(5)
|
|
->select();
|
|
|
|
// 3. 服务好评记录
|
|
$recentReviews = \think\Db::name('review')
|
|
->where('master_id', $row['id'])
|
|
->order('id desc')
|
|
->limit(5)
|
|
->select();
|
|
|
|
// 4. 服务技能与认证证书
|
|
$skills = \think\Db::name('master_skill')
|
|
->alias('s')
|
|
->join('service_cat c', 'c.id = s.cat_id', 'LEFT')
|
|
->where('s.master_id', $row['id'])
|
|
->field('s.*, c.name as cat_name')
|
|
->select();
|
|
|
|
$this->view->assign('row', $row);
|
|
$this->view->assign('recentOrders', $recentOrders);
|
|
$this->view->assign('recentWithdraws', $recentWithdraws);
|
|
$this->view->assign('recentReviews', $recentReviews);
|
|
$this->view->assign('skills', $skills);
|
|
|
|
return $this->view->fetch();
|
|
}
|
|
}
|