Org.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <?php
  2. namespace app\sys\controller;
  3. use app\event\Msg;
  4. use app\logics\EmployeeLogic;
  5. use think\facade\View;
  6. use app\logics\OrgLogic;
  7. use app\model\Company;
  8. use app\model\CrmImportLog;
  9. use app\model\Customer;
  10. use app\model\CustomerClue;
  11. use app\model\Employee;
  12. use app\model\Footprints;
  13. use app\model\Org as OrgModel;
  14. use think\facade\Db;
  15. use app\model\CreditsSetting;
  16. use think\facade\Request;
  17. use app\model\Designer;
  18. use app\model\Decostyle;
  19. use app\model\Housetype;
  20. use app\model\Setting;
  21. use app\model\RenovatePrice;
  22. use app\model\CompanyVrshow;
  23. class Org
  24. {
  25. /**
  26. * 面板
  27. */
  28. public function index()
  29. {
  30. $request = request();
  31. //待审核数量
  32. $where[] = ['root_id', '=', $request->employee->root_id];
  33. $where[] = ['state', '=', '待审核'];
  34. $where[] = ['verified', '=', 0];
  35. $count = Employee::where($where)->count();
  36. View::assign('count', $count);
  37. View::assign('root', $request->employee->root_id);
  38. return View::fetch();
  39. }
  40. /**
  41. * 获取公司下的组织结构与小程序设置
  42. */
  43. public function struct()
  44. {
  45. $datastr = OrgLogic::struc(request()->employee['root_id']);
  46. $datastr = json_decode($datastr, true);
  47. return json(['code' => 0, 'data' => $datastr]);
  48. }
  49. public function removenode()
  50. {
  51. $id = input('id');
  52. // 原结构获取
  53. // $datastr = OrgLogic::struc(request()->employee->root_id);
  54. //$org = OrgModel::where([['id', '=', $id]])->findOrEmpty();
  55. $org = OrgModel::where([['id', '=', $id], ['path', 'like', request()->employee->root_id . '-%']])->findOrEmpty();
  56. if ($org->isEmpty()) return json(['code' => 1, 'msg' => '删除失败,机构不存在']);
  57. if (!$org->level) {
  58. return json(['code' => 101, 'msg' => '根节点不可删除!']);
  59. }
  60. // 判断节点是否是该企业节点
  61. $path = explode('-', $org->path);
  62. if ($path[0] != request()->employee->root_id) return json(['code' => 1, 'msg' => '删除失败,机构不存在']);
  63. $result = OrgLogic::disnode($id, $msg);
  64. if ($result !== true) {
  65. return json(['code' => $result, 'msg' => $msg]);
  66. }
  67. dataStatistics(request()->employee->root_id,'org_count',1,'dec');//manage应用首页统计数据
  68. return json(['code' => 0, 'msg' => '删除成功']);
  69. }
  70. /**
  71. * 部门资源交接
  72. */
  73. public function receive($from, $to)
  74. {
  75. $check = OrgModel::where([['id', 'in', [$from, $to]], ['path', 'like', request()->employee->root_id . '-%']])->count();
  76. if ($check != 2) return json(['code' => 1, 'msg' => '异常请求']);
  77. // 被交接部门查找
  78. $fromOrg = OrgModel::find($from);
  79. // 被交接子部门查找
  80. $delIds = OrgModel::where([['path', 'like', $fromOrg->path . '%']])->column('id');
  81. /** 资源交接 */
  82. // 交接客户
  83. Customer::where([['org_id', 'in', $delIds]])->update(['org_id' => $to]);
  84. // 交接线索
  85. CustomerClue::where([['org_id', 'in', $delIds]])->update(['org_id' => $to]);
  86. // 交接足迹
  87. Footprints::where([['org_id', 'in', $delIds]])->update(['org_id' => $to]);
  88. // 交接资源库(资源导入记录)
  89. CrmImportLog::where([['org_id', 'in', $delIds]])->update(['org_id' => $to]);
  90. // 删除部门
  91. OrgModel::where([['id', 'in', $delIds]])->delete();
  92. return json(['code' => 0, 'msg' => '交接完成']);
  93. }
  94. public function addnode()
  95. {
  96. $request = request();
  97. $param = $request->only(['id', 'pid', 'name', 'org_type']);
  98. // 如果是修改
  99. if (isset($param['id']) && !empty($param['id'])) {
  100. Db::startTrans();
  101. $theObj = OrgModel::where([['id', '=', $param['id']], ['path', 'like', $request->employee->root_id . '-%']])->find();
  102. if (empty($theObj)) return json(['code' => 1, 'msg' => '数据不存在']);
  103. $oldName = $theObj->info;
  104. $theObj->info = preg_replace('/\/[^\/]*$/', '/' . $param['name'], $theObj->info);
  105. $theObj->name = $param['name'];
  106. $theObj->save();
  107. // 子部门名称修改
  108. $childs = OrgModel::where([['path', 'like', $theObj->path . '%'], ['id', '<>', $theObj->id]])->select();
  109. foreach ($childs as $item) {
  110. $item->info = preg_replace("/^" . preg_quote($oldName, '/') . "/", $theObj->info, $item->info);
  111. $item->save();
  112. }
  113. Db::commit();
  114. return json(['code' => 0, 'msg' => '更新成功']);
  115. } else {
  116. $theObj = OrgModel::where([['id', '=', $param['pid']], ['path', 'like', $request->employee->root_id . '-%']])->find();
  117. if (empty($theObj)) return json(['code' => 1, 'msg' => '添加失败']);
  118. $org = OrgModel::create([
  119. 'pid' => $param['pid'],
  120. 'name' => $param['name'],
  121. 'org_type' => !empty($param['org_type']) ? $param['org_type'] : $theObj->org_type,
  122. 'level' => $theObj->level + 1,
  123. 'info' => $theObj->info . '/' . $param['name']
  124. ]);
  125. $org->path = $theObj->path . $org->id . '-';
  126. $org->save();
  127. dataStatistics($request->employee->root_id,'org_count',1,'inc');//manage应用首页统计数据
  128. return json(['code' => 0, 'data' => $org->id]);
  129. }
  130. }
  131. // public function invitelink()
  132. // {
  133. // $orgid = input('orgid');
  134. // $therole = input('therole');
  135. // $is_manager = input('is_manager');
  136. // $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  137. // $cryptedstr = $aec->encrypt('orgid=' . $orgid . '&role=' . $therole . '&is_manager=' . $is_manager . '&pos=1&ts=' . time());
  138. // $link = Request()->domain() . '/index/index/invite/?al=' . $cryptedstr;
  139. // return json_encode(['code' => 0, 'msg' => '获取成功', 'link' => $link]);
  140. // }
  141. public function employee()
  142. {
  143. $org = input('org', '', 'intval');
  144. $param['page'] = input('page', 1);
  145. $param['limit'] = input('limit', 10);
  146. if (empty($org)) {
  147. $org = request()->employee->root_id;
  148. }
  149. $employee = EmployeeLogic::employeelist($org, [], $param['page'], $param['limit']);
  150. $data = [];
  151. foreach($employee as $item){
  152. $data[] = ['id'=>$item['id'], 'name'=>$item['name']];
  153. }
  154. return json(['code' => 0, 'data' => $data]);
  155. }
  156. public function employee4resource($org, $keyword = '')
  157. {
  158. $param['page'] = input('page', 1);
  159. $param['limit'] = input('limit', 10);
  160. $where = [];
  161. if ($keyword) {
  162. $where[] = ['name', 'like', '%' . $keyword . '%'];
  163. }
  164. $employee = EmployeeLogic::employeelist4resource($org, $where, $param['page'], $param['limit']);
  165. return json(['code' => 0, 'data' => $employee]);
  166. }
  167. // /**
  168. // * 小程序绑定
  169. // */
  170. // public function miniprogram()
  171. // {
  172. // $request = request();
  173. // $param = $request->param();
  174. // $param['root_id'] = $request->employee->root_id;
  175. // $program = Miniprogram::where([['root_id', '=', $param['root_id']]])->findOrEmpty();
  176. // $accessToken = getAccessToken($param['appid'], $param['secret']);
  177. // if (empty($accessToken)) return json(['code' => 1, 'msg' => '配置失败,appid,secret不正确或小程序业务域名未配置']);
  178. // // 邀请二维码生成
  179. // $miniQr = new Qrcode();
  180. // // 1)管理员二维码
  181. // $qr = $miniQr->getUnlimited($accessToken, [
  182. // 'scene' => 'manager=' . $param['root_id'],
  183. // 'page' => 'mycustomer/pages/invite/invite',
  184. // 'width' => '280px',
  185. // 'check_path' => false
  186. // ]);
  187. // $rs = json_decode($qr, true);
  188. // if (!is_null($rs)) {
  189. // trace($rs, 'error');
  190. // return json(['code' => 1, 'msg' => '配置失败,appid,secret不正确或小程序业务域名未配置']);
  191. // }
  192. // $managerQr = 'invite' . DIRECTORY_SEPARATOR . uniqid() . '.jpeg';
  193. // ossContentUpload($managerQr, $qr);
  194. // // 2)员工二维码
  195. // $qr = $miniQr->getUnlimited($accessToken, [
  196. // 'scene' => 'employee=' . $param['root_id'],
  197. // 'page' => 'mycustomer/pages/invite/invite',
  198. // 'width' => '280px',
  199. // 'check_path' => false
  200. // ]);
  201. // $rs = json_decode($qr, true);
  202. // if (!is_null($rs)) {
  203. // return json(['code' => 1, 'msg' => '配置失败,appid,secret不正确或小程序业务域名未配置']);
  204. // }
  205. // $employeeQr = 'invite' . DIRECTORY_SEPARATOR . uniqid() . '.jpeg';
  206. // ossContentUpload($employeeQr, $qr);
  207. // $param['manager_qr'] = $managerQr;
  208. // $param['employee_qr'] = $employeeQr;
  209. // $param['accesstoken'] = $accessToken;
  210. // $param['expire'] = time() + 7100;
  211. // $param['company'] = OrgModel::where('id', $param['root_id'])->value('name');
  212. // // 检测id是否是root
  213. // $program->save($param);
  214. // return json(['code' => 0, 'msg' => '保存成功', 'data' => $param]);
  215. // }
  216. public function transfer($id, $pid)
  217. {
  218. $request = request();
  219. $theObj = OrgModel::where([['id', '=', $id], ['path', 'like', $request->employee->root_id . '-%']])->find();
  220. // 根组织不可迁移
  221. if (empty($theObj) || $theObj->pid == 0) return json(['code' => 1, 'msg' => '转移失败']);
  222. // 判断是从上级往下级迁移
  223. $isChildren = OrgModel::where([['id', '=', $pid], ['path', 'like', $theObj->path . '%']])->count();
  224. if ($isChildren) return json(['code' => 1, 'msg' => '不能将上级部门转移到自身的子部门中']);
  225. $pObj = OrgModel::where([['id', '=', $pid], ['path', 'like', $request->employee->root_id . '-%']])->find();
  226. if (empty($pObj)) return json(['code' => 1, 'msg' => '转移失败']);
  227. if ($pObj->org_type == 2 && $theObj->org_type != 2) return json(['code' => 1, 'msg' => '销售部不能能迁移到设计部门下']);
  228. // 克隆原数据
  229. $oldObj = clone $theObj;
  230. $theObj->level = $pObj->level + 1;
  231. $theObj->path = $pObj->path . $theObj->id . '-';
  232. $theObj->pid = $pObj->id;
  233. $theObj->info = $pObj->info . '/' . $theObj->name;
  234. $theObj->save();
  235. // 子组织迁移修改
  236. $childrens = OrgModel::where([['path', 'like', $oldObj->path . '%']])->select();
  237. foreach ($childrens as $child) {
  238. $child->level = $child->level - $oldObj->level + $theObj->level;
  239. $child->path = preg_replace('/^' . $oldObj->path . '/', $theObj->path, $child->path);
  240. $child->info = preg_replace('/^' . str_replace('/', '\/', $oldObj->info) . '/', $theObj->info, $child->info);
  241. $child->save();
  242. }
  243. return json(['code' => 0, 'msg' => '迁移成功']);
  244. }
  245. /**
  246. * 更改领导
  247. */
  248. public function leaders($id, $leader)
  249. {
  250. $request = request();
  251. // 将检索该部门下的所有领导更新成员工
  252. $leaderIds = Employee::where(['org_id' => $id, 'root_id' => $request->employee->root_id, 'is_manager' => 1])->column('id');
  253. $removeLeader = array_diff($leaderIds, $leader);
  254. $setLeader = array_diff($leader, $leaderIds);
  255. Employee::where([['org_id', '=', $id], ['root_id', '=', $request->employee->root_id], ['id', 'in', $setLeader]])->update(['is_manager' => 1]);
  256. Employee::where([['org_id', '=', $id], ['root_id', '=', $request->employee->root_id], ['id', 'in', $removeLeader]])->update(['is_manager' => 0]);
  257. $orgName = OrgModel::where([['id', '=', $id], ['path', 'like', $request->employee->root_id . '-%']])->value('name');
  258. if ($setLeader && $orgName)
  259. event(new Msg($setLeader, '您被' . $request->employee->name . '添加为' . $orgName . '负责人身份,请知晓!', 'setleader'));
  260. if ($removeLeader)
  261. event(new Msg($removeLeader, '您的负责人身份被' . $request->employee->name . '移除了,请知晓!', 'removeleader'));
  262. // Employee::where(['org_id' => $id, 'root_id' => request()->employee->root_id])->update(['is_manager' => 0]);
  263. // 更新该部门下的领导
  264. // Employee::where([['org_id', '=', $id], ['root_id', '=', request()->employee->root_id], ['id', 'in', $leader]])->update(['is_manager' => 1]);
  265. return json(['code' => 0, 'msg' => '更改成功']);
  266. }
  267. /**
  268. * 设置企业
  269. */
  270. public function company()
  271. {
  272. $request = request();
  273. $data = Company::where(['root_id' => $request->employee->root_id])->find();
  274. View::assign('data', $data);
  275. View::assign('logo', $data->getData('logo'));
  276. $disable_day_setting = Setting::where([['name', '=', 'disable_day'], ['root_id', '=', $request->employee->root_id]])->findOrEmpty();
  277. $disable_day = '';
  278. if (!$disable_day_setting->isEmpty()) {
  279. $disable_day = $disable_day_setting['content'];
  280. }
  281. View::assign('disable_day', $disable_day);
  282. return View::fetch();
  283. }
  284. //单独获取vr链接地址
  285. public function company_vrlist()
  286. {
  287. $request = request();
  288. $list = CompanyVrshow::where([['root_id','=',$request->employee->root_id],['type','=',1]])->field('id,name,url')->select()->toArray();
  289. if(empty($list)) $list = [['id'=>'','name'=>'','url'=>'']];
  290. return json(['code'=>0,'data'=>$list,'msg'=>'获取成功']);
  291. }
  292. /**
  293. * 删除公司的vr展厅链接地址
  294. */
  295. public function del_companyvr()
  296. {
  297. $request = request();
  298. $param = $request->only(['id']);
  299. $data = CompanyVrshow::where([['root_id','=',$request->employee->root_id],['type','=',1],['id','=',$param['id']]])->find();
  300. if(empty($data)) return json(['code'=>1,'msg'=>'数据不存在']);
  301. $ms = $data->delete();
  302. if($ms){
  303. return json(['code'=>0,'msg'=>'删除成功']);
  304. }else{
  305. return json(['code'=>1,'msg'=>'删除失败']);
  306. }
  307. }
  308. public function setting()
  309. {
  310. $request = request();
  311. $data = Company::where(['root_id' => $request->employee->root_id])->find();
  312. $param = $request->only(['logo', 'company_name', 'tel', 'logo_file', 'company_introduction' => '', 'company_address' => '', 'vr_address' => '', 'vr_show' => '']);
  313. $url = 'hnweizhihui.xiaohongwu';
  314. $jurl = 'web.xiaohongwu';
  315. if ($param['vr_address']) {
  316. $param['vr_address'] = $this->vrlink_set($param['vr_address']);
  317. }
  318. if ($param['vr_show']) {
  319. $cpvrmod = new CompanyVrshow;
  320. //$param['vr_show'] = $this->vrlink_set($param['vr_show']);
  321. foreach(json_decode($param['vr_show'],true) as $k=>$v){
  322. if($v['id']) $save[] = ['id'=>$v['id'],'name'=>$v['name'],'url'=>$this->vrlink_set($v['url'])];
  323. else $add[] = ['name'=>$v['name'],'url'=>$this->vrlink_set($v['url']),'root_id'=>$request->employee->root_id,'type'=>1];
  324. }
  325. if(!empty($save)) $cpvrmod->saveAll($save);
  326. if(!empty($add)) $cpvrmod->saveAll($add);
  327. $param['vr_show'] = '';
  328. }
  329. if (empty($param['logo']) && empty($param['logo_file'])) return json(['code' => 1, 'msg' => '请上传LOGO']);
  330. if (!empty($param['logo_file'])) $param['logo'] = $param['logo_file'];
  331. $data->save($param);
  332. // 三天未进入小程序 准入小程序锁定
  333. $disable_day = input('disable_day', '', 'intval');
  334. $disable_day_setting = Setting::where([['name', '=', 'disable_day'], ['root_id', '=', $request->employee->root_id]])->findOrEmpty();
  335. if ($disable_day_setting->isEmpty()) {
  336. Setting::create(['name'=> 'disable_day', 'root_id'=> $request->employee->root_id, 'content'=> $disable_day, 'state'=> 1]);
  337. } else {
  338. $disable_day_setting->content = $disable_day;
  339. $disable_day_setting->save();
  340. }
  341. return json(['code' => 0, 'msg' => '保存成功']);
  342. }
  343. /**
  344. * 部门人员树
  345. */
  346. public function tree($data, $pid = 0, $persons)
  347. {
  348. $new_arr = [];
  349. foreach ($data as $k => $v) {
  350. if ($v['pid'] == $pid) {
  351. $persions = isset($persons[$v['id']]) ? $persons[$v['id']] : [];
  352. $children = $this->tree($data, $v['id'], $persons);
  353. $v['children'] = array_merge_recursive($children, $persions);
  354. if (empty($v['children'])) $v['disabled'] = true;
  355. $new_arr[] = $v;
  356. }
  357. }
  358. return $new_arr;
  359. }
  360. /**
  361. * 指派人员
  362. * @param $id
  363. */
  364. public function get_person()
  365. {
  366. $root_id = request()->employee->root_id;
  367. $keyword = input('keyword', '');
  368. //所有员工
  369. $w1[] = ['root_id', '=', $root_id];
  370. $w1[] = ['state', '=', '在职'];
  371. $w1[] = ['org_id', '>', 0];
  372. $w1[] = ['uid', '>', 0];
  373. if ($keyword) {
  374. $w1[] = ['name', 'like', '%' . $keyword . '%'];
  375. }
  376. $employee = Employee::where($w1)->field('id,name title,org_id,is_manager')->order('is_manager desc,id desc')->select()->toArray();
  377. foreach ($employee as $k => &$v) {
  378. $v['selected'] = false;
  379. $v['children'] = [];
  380. $v['all_count'] = 0;
  381. $v['title'] = $v['is_manager'] ? $v['title'] . '(负责人)' : $v['title'];
  382. $v['org_class'] = 'org_' . $v['org_id'];
  383. $v['per_class'] = 'per_' . $v['id'];
  384. $v['type'] = 'per';
  385. }
  386. $persons = [];
  387. foreach ($employee as $k => $v1) {
  388. $persons[$v1['org_id']][] = $v1;
  389. }
  390. $where = [
  391. ['path', 'like', $root_id . '-%'],
  392. ['status', '=', 1]
  393. ];
  394. $count = Employee::where([['root_id', '=', $root_id], ['state', '=', '在职'], ['uid', '>', 0]])->group('org_id')->column('count(*) count', 'org_id');
  395. $allnodes = OrgModel::where($where)->field('id,pid,name title,level,org_type,info,path')->order('level asc, id asc')->select()->toarray();
  396. foreach ($allnodes as $k => $v) {
  397. $allnodes[$k]['count'] = isset($count[$v['id']]) ? $count[$v['id']] : 0; //本部门人数
  398. $allnodes[$k]['all_count'] = 0; //包含子部门总数
  399. $allnodes[$k]['org_class'] = 'org_' . $v['id'];
  400. $allnodes[$k]['per_class'] = 'per_org_' . $v['id'];
  401. $allnodes[$k]['type'] = 'org';
  402. foreach ($allnodes as $k2 => $v2) {
  403. if (strpos($v2['path'], $v['path']) !== false) {
  404. $allnodes[$k]['all_count'] = isset($count[$v2['id']]) ? $count[$v2['id']] + $allnodes[$k]['all_count'] : $allnodes[$k]['all_count'];
  405. }
  406. }
  407. $allnodes[$k]['title'] = $allnodes[$k]['title'] . ' (' . $allnodes[$k]['all_count'] . ')';
  408. }
  409. $tree = $this->tree($allnodes, 0, $persons);
  410. $info = Setting::where(['root_id' => request()->employee->root_id, 'name' => 'disable_day_unlimited'])->value('content');
  411. return json(['code' => 0, 'data' => $tree, 'checkOrg' => $info]);
  412. }
  413. /**
  414. * 设置不受限制人员
  415. */
  416. public function set_unlimited_employee()
  417. {
  418. $setting = Setting::where(['root_id' => request()->employee->root_id, 'name' => 'disable_day_unlimited'])->findOrEmpty();
  419. $assign_employee = $setting->isEmpty() ? '' : $setting['content'];
  420. if (!request()->isAjax()) {
  421. $count = $assign_employee ? count(explode(',', $assign_employee)) : 0;
  422. view::assign('count', $count);
  423. return View::fetch();
  424. }
  425. $pid = input('pid', '', 'trim'); //多选框选中id
  426. $type = input('type', '', 'trim'); //选中类型,人/部门
  427. $res = input('res', '', 'trim'); //选择结果 1选中,0取消
  428. $data = [];
  429. $a = 0;
  430. if ($type == 'per' && $pid) {
  431. $data[] = 'per_' . $pid;
  432. $pid = [$pid];
  433. $a = 1;
  434. } elseif ($type == 'org' && $pid) {
  435. $data[] = 'org_' . $pid;
  436. $org = OrgModel::where([['id', '=', $pid]])->value('path');
  437. $orgs = OrgModel::where([['path', 'like', $org . '%']])->column('id');
  438. $pid = Employee::where([['root_id', '=', request()->employee->root_id], ['org_id', 'in', $orgs], ['state', '=', '在职'], ['uid', '>', 0]])->order('is_manager desc,id desc')->column('id');
  439. $a = 1;
  440. foreach ($pid as $v) {
  441. $data[] = 'per_' . $v;
  442. }
  443. foreach ($orgs as $v2) {
  444. $data[] = 'org_' . $v2;
  445. }
  446. }
  447. $assign_employee = explode(',', $assign_employee);
  448. if ($a) {
  449. $arr = array_filter(array_diff($assign_employee, $pid));
  450. $arr = $res ? array_merge($pid, $arr) : $arr;
  451. $arr = array_unique($arr);
  452. //过滤运营人员,旧bug导致选择根部门时,运营人员也会在内
  453. $arr = Employee::where([['id', 'in', $arr], ['uid', '>', 0], ['state', '=', '在职']])->column('id');
  454. //查询指派人的组织
  455. if ($setting->isEmpty()) {
  456. $add = ['root_id' => request()->employee->root_id, 'name' => 'disable_day_unlimited', 'content' => implode(',', $arr)];
  457. Setting::create($add);
  458. } else {
  459. Setting::where(['root_id' => request()->employee->root_id, 'name' => 'disable_day_unlimited'])->update(['content' => implode(',', $arr)]);
  460. }
  461. }
  462. return json(['code' => 0, 'data' => $data]);
  463. }
  464. /*
  465. * 不受限制员工列表
  466. */
  467. public function get_unlimited_employee()
  468. {
  469. $page = input('page', 0, 'intval');
  470. $limit = input('limit', 0, 'intval');
  471. $keyword = input('keyword', '', 'trim');
  472. if ($keyword) {
  473. $w[] = ['name', 'like', '%' . $keyword . '%'];
  474. }
  475. $setting = Setting::where(['root_id' => request()->employee->root_id, 'name' => 'disable_day_unlimited'])->findOrEmpty();
  476. $arr = $setting->isEmpty() ? '' : $setting['content'];
  477. $arr = $arr ? explode(',', $arr) : [];
  478. $w[] = ['id', 'in', $arr];
  479. $w[] = ['state', '=', '在职'];
  480. $w[] = ['uid', '>', 0];
  481. if ($page && $limit) {
  482. $data = Employee::with('orgName')->where($w)->visible(['name', 'org_name', 'id', 'is_manager'])->page($page, $limit)->select()->toArray();
  483. } else {
  484. $data = Employee::with('orgName')->where($w)->visible(['name', 'org_name', 'id', 'is_manager'])->select()->toArray();
  485. }
  486. $count = Employee::where($w)->count();
  487. foreach ($data as $k => $v) {
  488. $data[$k]['xh'] = $k + 1;
  489. }
  490. return json(['code' => 0, 'data' => $data, 'count' => $count]);
  491. }
  492. /**
  493. * 删除已设置不受限制员工
  494. */
  495. public function delete_unlimited_employee()
  496. {
  497. $eid = input('eid', '', 'intval');
  498. if ($eid) {
  499. if ($eid == -1) {
  500. Setting::where(['root_id' => request()->employee->root_id, 'name' => 'disable_day_unlimited'])->update(['content' => '']);
  501. } else {
  502. $setting = Setting::where(['root_id' => request()->employee->root_id, 'name' => 'disable_day_unlimited'])->findOrEmpty();
  503. $arr = $setting->isEmpty() ? '' : $setting['content'];
  504. $arr = array_filter(array_diff(explode(',', $arr), [$eid]));
  505. if ($setting->isEmpty()) {
  506. Setting::create(['root_id' => request()->employee->root_id, 'name' => 'disable_day_unlimited', 'content'=> implode(',', $arr)]);
  507. } else {
  508. $setting->save(['content' => implode(',', $arr)]);
  509. }
  510. }
  511. }
  512. return json(['code' => 0, 'data' => '取消成功', 'msg' => '取消成功']);
  513. }
  514. //vr链接设置修改
  515. public function vrlink_set($vr_link)
  516. {
  517. //2023-05-04 志远装饰app创建的vr作品
  518. if (strpos($vr_link,'/vr/#')) return $vr_link;
  519. // 旧域名 替换成 新域名
  520. $links = [
  521. 'xiaohongwu' => 'hnweizhihui.xiaohongwu.nczyzs.com',
  522. 'kujiale' => 'pano337.p.kujiale.com',
  523. 'justeasy' => 'vr-17.justeasy.nczyzs.com',
  524. '3d66' => 'vr.3d66.nczyzs.com',
  525. ];
  526. $url = parse_url($vr_link);
  527. if ($url === false || !isset($url['host'])) {
  528. echo json_encode(['code' => 1, 'msg' => '链接格式错误']);
  529. exit;
  530. }
  531. if (strpos($url['host'], 'xiaohongwu') !== false) {
  532. return str_replace($url['host'], $links['xiaohongwu'], $vr_link);
  533. }
  534. if (strpos($url['host'], 'kujiale') !== false) {
  535. return str_replace($url['host'], $links['kujiale'], $vr_link);
  536. }
  537. if (strpos($url['host'], 'justeasy') !== false) {
  538. return str_replace($url['host'], $links['justeasy'], $vr_link);
  539. }
  540. if (strpos($url['host'], '3d66') !== false) {
  541. return str_replace($url['host'], $links['3d66'], $vr_link);
  542. }
  543. echo json_encode(['code' => 1, 'msg' => '无效的VR链接']);
  544. exit;
  545. }
  546. //奖励规则设置
  547. public function reward_rule()
  548. {
  549. $request = request();
  550. $where[] = ['code', '=', 'talkskill_credits'];
  551. $where[] = ['root_id', '=', $request->employee->root_id];
  552. $data['talkskill_credits'] = CreditsSetting::where($where)->value('value') ?: 1;
  553. $where2[] = ['code', '=', 'talkskill_contribution_value'];
  554. $where2[] = ['root_id', '=', $request->employee->root_id];
  555. $data['talkskill_contribution_value'] = CreditsSetting::where($where2)->value('value') ?: 1;
  556. $where3[] = ['code', '=', 'talkskill_person1'];
  557. $where3[] = ['root_id', '=', $request->employee->root_id];
  558. $person1 = CreditsSetting::where($where3)->value('value');
  559. $data['talkskill_person1'] = $person1 ? json_decode($person1, true) : ['person1' => 1, 'credits1' => 1];
  560. $where4[] = ['code', '=', 'talkskill_person2'];
  561. $where4[] = ['root_id', '=', $request->employee->root_id];
  562. $person2 = CreditsSetting::where($where4)->value('value');
  563. $data['talkskill_person2'] = $person2 ? json_decode($person2, true) : ['person2' => 1, 'credits2' => 1];
  564. $where5[] = ['code', '=', 'material_case_value'];
  565. $where5[] = ['root_id', '=', $request->employee->root_id];
  566. $data['material_case_value'] = CreditsSetting::where($where5)->value('value') ?: 1;
  567. $where6[] = ['code', '=', 'material_case_integral'];
  568. $where6[] = ['root_id', '=', $request->employee->root_id];
  569. $material_case_integral = CreditsSetting::where($where6)->value('value');
  570. if ((int)$material_case_integral > 0) $material_case_integral = null;
  571. $data['material_case_integral'] = $material_case_integral ? json_decode($material_case_integral, true) : ['case_num' => 1, 'case_integral' => 2];
  572. View::assign('data', $data);
  573. return View::fetch();
  574. }
  575. //奖励规则设置
  576. public function reward_rule_save()
  577. {
  578. $request = request();
  579. $param = Request::only(['up', 'answer', 'person1', 'credits1', 'person2', 'credits2', 'upcase', 'case_num', 'case_integral']);
  580. if (isset($param['up'])) {
  581. credits($request->employee->root_id, $param['up'], 'talkskill_credits', 0); //积分
  582. }
  583. if (isset($param['answer'])) {
  584. credits($request->employee->root_id, $param['answer'], 'talkskill_contribution_value', 0); //贡献值
  585. }
  586. if (isset($param['person1']) && isset($param['credits1'])) {
  587. $json = json_encode(['person1' => $param['person1'], 'credits1' => $param['credits1']]);
  588. credits($request->employee->root_id, $json, 'talkskill_person1', 0); //贡献值
  589. }
  590. if (isset($param['person2']) && isset($param['credits2'])) {
  591. $json = json_encode(['person2' => $param['person2'], 'credits2' => $param['credits2']]);
  592. credits($request->employee->root_id, $json, 'talkskill_person2', 0); //贡献值
  593. }
  594. if (isset($param['upcase'])) {
  595. credits($request->employee->root_id, $param['upcase'], 'material_case_value', 0); //贡献值
  596. }
  597. if (isset($param['case_num']) && isset($param['case_integral'])) {
  598. $json = json_encode(['case_num' => $param['case_num'], 'case_integral' => $param['case_integral']]);
  599. credits($request->employee->root_id, $json, 'material_case_integral', 0); //案例被使用积分
  600. }
  601. return json(['code' => 0, 'msg' => '保存成功']);
  602. }
  603. //设计师管理
  604. public function designer()
  605. {
  606. $designerOrg = OrgModel::field('id,info as name')->withAttr('name', function($value){
  607. $v = explode('/', $value);
  608. return implode('/', array_slice($v, -2));
  609. })->where([['path', 'like', request()->employee['root_id'].'-%'], ['org_type', '=', 2]])->order('level asc, id asc')->select();
  610. View::assign('designerOrg', $designerOrg);
  611. return View::fetch();
  612. }
  613. //添加设计师
  614. public function add_designer()
  615. {
  616. return View::fetch();
  617. }
  618. //编辑设计师
  619. public function edit_designer()
  620. {
  621. $id = input('id', 0);
  622. View::assign('id', $id);
  623. $token = request()->employee;
  624. $w[] = ['employee_id', '=', $id];
  625. $w[] = ['root_id', '=', $token['root_id']];
  626. $row = Designer::where($w)->findOrEmpty();
  627. if ($row->isEmpty()) {
  628. $row['headimgurl'] = '';
  629. $row['vcr'] = '';
  630. $row['work_years'] = '';
  631. $row['position'] = '';
  632. $row['design_concept'] = '';
  633. $row['good_at'] = '';
  634. $row['good_house'] = '';
  635. $row['headimgurls'] = '';
  636. } else {
  637. $row->headimgurls = $row->getData('headimgurl');
  638. $row->vcrurl = $row->getData('vcr');
  639. $row = $row->toArray();
  640. }
  641. // var_dump($row['headimgurls']);die;
  642. View::assign('data', $row);
  643. $condition = [['root_id', '=', $token['root_id']]];
  644. //风格获取
  645. $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->field('name')->select()->toArray();
  646. $arr = $row['good_at'] ?: [];
  647. foreach ($decostyles as $k => $v) {
  648. $decostyles[$k]['value'] = $v['name'];
  649. $decostyles[$k]['selected'] = in_array($v['name'], $arr);
  650. }
  651. $decostyles = json_encode($decostyles);
  652. // var_dump($decostyles);die;
  653. View::assign('decostyles', $decostyles);
  654. //户型获取
  655. $housetype = Housetype::where($condition)->field('name')->select()->toArray();
  656. $arr = $row['good_house'] ?: [];
  657. foreach ($housetype as $k => $v) {
  658. $housetype[$k]['value'] = $v['name'];
  659. $housetype[$k]['selected'] = in_array($v['name'], $arr);
  660. }
  661. // var_dump($housetype);die;
  662. $housetype = json_encode($housetype);
  663. View::assign('housetype', $housetype);
  664. return View::fetch();
  665. }
  666. /*
  667. * 富文本图片
  668. */
  669. public function imgUpload()
  670. {
  671. $bindUrl = config('app.ali_oss_bindurl');
  672. $data = [
  673. 'src' => 'http://' . $bindUrl . '/' . Request::param('file'),
  674. 'title' => ''
  675. ];
  676. return json(['code' => 0, 'msg' => '', 'data' => $data]);
  677. }
  678. }