Need.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <?php
  2. namespace app\admin\controller\qingdongams\customer;
  3. use addons\qingdongams\model\Message;
  4. use addons\qingdongams\model\Notice as NoticeModel;
  5. use addons\qingdongams\model\NoticeRead;
  6. use addons\qingdongams\model\ReceivablesPlan;
  7. use addons\qingdongams\model\Record as RecordModel;
  8. use addons\qingdongams\model\Workorder;
  9. use app\admin\controller\qingdongams\Base;
  10. use addons\qingdongams\model\Staff;
  11. use think\Db;
  12. use think\Exception;
  13. use addons\qingdongams\model\Event;
  14. use addons\qingdongams\model\ExamineRecord;
  15. use addons\qingdongams\model\Record;
  16. /**
  17. * 待办管理
  18. * @desc 操作文档:https://doc.fastadmin.net/qingdongams
  19. * @desc 软件介绍:https://www.fastadmin.net/store/qingdongams.html
  20. * @desc 售后微信:qingdong_crm
  21. */
  22. class Need extends Base
  23. {
  24. protected $relationSearch = true;
  25. protected $model = null;
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->type = array(
  30. array(
  31. 'id'=>1,
  32. 'pid'=>0,
  33. 'name'=>'消息提醒',
  34. 'text'=>'消息提醒',
  35. ),
  36. array(
  37. 'id'=>1,
  38. 'pid'=>0,
  39. 'name'=>'公告',
  40. 'text'=>'消息提醒',
  41. ),
  42. array(
  43. 'id'=>1,
  44. 'pid'=>0,
  45. 'name'=>'今日需联系客户',
  46. 'text'=>'消息提醒',
  47. ),
  48. );
  49. $this->assignconfig('typeList', $this->type);
  50. }
  51. /**
  52. * 待办列表
  53. */
  54. public function index(){
  55. //消息提醒
  56. $whereNew = [
  57. 'status'=>0,
  58. 'to_staff_id' => $this->_staff->id ,
  59. 'relation_type'=>['not in','examine,discuss,sign']
  60. ];
  61. $news = Message::where($whereNew)->count();
  62. //公告
  63. $noticeid = NoticeModel::where([])->column('id');
  64. foreach($noticeid as $k=>$v){
  65. $read = NoticeRead::where(['notice_id'=>$v,'staff_id'=>$this->_staff->id])->find();
  66. if($read){
  67. unset($noticeid[$k]);
  68. continue;
  69. }
  70. }
  71. $notice = count($noticeid);
  72. $start = date('Y-m-d 00:00:00');
  73. $end = date('Y-m-d 23:59:59');
  74. $where['createtime'] = array(array('egt',strtotime($start)),array('elt',strtotime($end)));
  75. $whereR['next_time'] = array(array('egt',$start),array('elt',$end));
  76. //待线索跟进
  77. $whereLead['create_staff_id'] = $this->_staff->id;
  78. $whereLead['relation_type'] = 4;
  79. $whereLead['status'] = 0;
  80. $lead = Record::where($whereLead)->where($whereR)->count();
  81. $whereCustomer['create_staff_id'] = $this->_staff->id;
  82. $whereCustomer['relation_type'] = 1;
  83. $whereCustomer['status'] = 0;
  84. $customer = Record::where($whereCustomer)->where($whereR)->count();
  85. $whereBusiness['create_staff_id'] = $this->_staff->id;
  86. $whereBusiness['relation_type'] = 5;
  87. $whereBusiness['status'] = 0;
  88. $business = Record::where($whereBusiness)->where($whereR)->count();
  89. $whereContract['create_staff_id'] = $this->_staff->id;
  90. $whereContract['relation_type'] = 3;
  91. $whereContract['status'] = 0;
  92. $contract = Record::where($whereContract)->where($whereR)->count();
  93. //费用审核
  94. $consume = ExamineRecord::where([
  95. 'relation_type' => ExamineRecord::CONSUME_TYPE,
  96. 'status' => 0,
  97. 'check_staff_id' => $this->_staff->id
  98. ])->count();
  99. //待审核合同
  100. $examine = ExamineRecord::where([
  101. 'relation_type' => ExamineRecord::CONTRACT_TYPE,
  102. 'status' => 0,
  103. 'check_staff_id' => $this->_staff->id
  104. ])->count();
  105. //待审核回款
  106. $receivables = ExamineRecord::where([
  107. 'relation_type' => ExamineRecord::RECEIVABLES_TYPE,
  108. 'status' => 0,
  109. 'check_staff_id' => $this->_staff->id,
  110. ])->count();
  111. //待审批办公
  112. $approval = ExamineRecord::where([
  113. 'relation_type' => ExamineRecord::APPROVAL_TYPE,
  114. 'status' => 0,
  115. 'check_staff_id' => $this->_staff->id,
  116. ])->count();
  117. //业绩审核
  118. $achievement = ExamineRecord::where([
  119. 'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE,
  120. 'status' => 0,
  121. 'check_staff_id' => $this->_staff->id
  122. ])->count();
  123. //待入库审批
  124. $partin = ExamineRecord::where([
  125. 'relation_type' => ExamineRecord::PARTS_TYPE,
  126. 'status' => 0,
  127. 'check_staff_id' => $this->_staff->id
  128. ])->count();
  129. //待报价审批
  130. $quote = ExamineRecord::where([
  131. 'relation_type' => ExamineRecord::QUOTE_TYPE,
  132. 'status' => 0,
  133. 'check_staff_id' => $this->_staff->id
  134. ])->count();
  135. //待处理工单
  136. $whereStaff = function ($query) {
  137. $query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
  138. ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
  139. };
  140. $wheres['status']=array('in','0,1');
  141. $workorder = Workorder::where($whereStaff)->where($wheres)->where($where)->count();
  142. $wheres['status']=array('in','0,1');
  143. $workorder_7 = Workorder::where($whereStaff)->where($wheres)->where($where)->count();
  144. //待发票审批
  145. $invoice = ExamineRecord::where([
  146. 'relation_type' => ExamineRecord::INVOICE_TYPE,
  147. 'status' => 0,
  148. 'check_staff_id' => $this->_staff->id
  149. ])->count();
  150. $info = array(
  151. 'customer'=>$customer,
  152. 'contract'=>$contract,
  153. 'lead'=>$lead,
  154. 'consume'=>$consume,
  155. 'news'=>$news,
  156. 'examine'=>$examine,
  157. 'receivables'=>$receivables,
  158. 'approval'=>$approval,
  159. 'notice'=>$notice,
  160. 'achievement'=>$achievement,
  161. 'business'=>$business,
  162. 'partin'=>$partin,
  163. 'quote'=>$quote,
  164. 'workorder'=>$workorder,
  165. 'workorder_7'=>$workorder_7,
  166. 'invoice'=>$invoice,
  167. );
  168. $this->view->assign('row',$info);
  169. $this->assignconfig("info", ['time' => date('Y-m-d 00:00:00').' - '.date('Y-m-d 23:59:59'),'dtime' => date('Y-m-d 00:00:00').' - '.date('Y-m-d 23:59:59', strtotime('+7 days'))]);
  170. // $this->assignconfig("dinfo", ['dtime' => date('Y-m-d 00:00:00').' - '.date('Y-m-d 23:59:59', strtotime('+7 days'))]);
  171. return $this->view->fetch();
  172. }
  173. /**
  174. * 获取通知数量
  175. */
  176. public function get_need_number(){
  177. //消息提醒
  178. $whereNew = ['status'=>0,'to_staff_id' => $this->_staff->id ,'relation_type'=>['not in','examine,discuss,sign,work_report']];
  179. $news = Message::where($whereNew)->count();
  180. //公告
  181. $noticeid = NoticeModel::where([])->column('id');
  182. foreach($noticeid as $k=>$v){
  183. $read = NoticeRead::where(['notice_id'=>$v,'staff_id'=>$this->_staff->id])->find();
  184. if($read){
  185. unset($noticeid[$k]);
  186. continue;
  187. }
  188. }
  189. $notice = count($noticeid);
  190. $start = date('Y-m-d 00:00:00');
  191. $end = date('Y-m-d 23:59:59');
  192. $where['createtime'] = array(array('egt',strtotime($start)),array('elt',strtotime($end)));
  193. $whereR['next_time'] = array(array('egt',$start),array('elt',$end));
  194. //待线索跟进
  195. $whereLead['create_staff_id'] = $this->_staff->id;
  196. $whereLead['relation_type'] = 4;
  197. $whereLead['status'] = 0;
  198. $lead = Record::where($whereLead)->where($whereR)->count();
  199. $whereCustomer['create_staff_id'] = $this->_staff->id;
  200. $whereCustomer['relation_type'] = 1;
  201. $whereCustomer['status'] = 0;
  202. $customer = Record::where($whereCustomer)->where($whereR)->count();
  203. $whereBusiness['create_staff_id'] = $this->_staff->id;
  204. $whereBusiness['relation_type'] = 5;
  205. $whereBusiness['status'] = 0;
  206. $business = Record::where($whereBusiness)->where($whereR)->count();
  207. $whereContract['create_staff_id'] = $this->_staff->id;
  208. $whereContract['relation_type'] = 3;
  209. $whereContract['status'] = 0;
  210. $contract = Record::where($whereContract)->where($whereR)->count();
  211. //费用审核
  212. $consume = ExamineRecord::where([
  213. 'relation_type' => ExamineRecord::CONSUME_TYPE,
  214. 'status' => 0,
  215. 'check_staff_id' => $this->_staff->id
  216. ])->count();
  217. //待审核合同
  218. $examine = ExamineRecord::where([
  219. 'relation_type' => ExamineRecord::CONTRACT_TYPE,
  220. 'status' => 0,
  221. 'check_staff_id' => $this->_staff->id
  222. ])->count();
  223. //待审核回款
  224. $receivables = ExamineRecord::where([
  225. 'relation_type' => ExamineRecord::RECEIVABLES_TYPE,
  226. 'status' => 0,
  227. 'check_staff_id' => $this->_staff->id,
  228. ])->count();
  229. //待审批办公
  230. $approval = ExamineRecord::where([
  231. 'relation_type' => ExamineRecord::APPROVAL_TYPE,
  232. 'status' => 0,
  233. 'check_staff_id' => $this->_staff->id,
  234. ])->count();
  235. //业绩审核
  236. $achievement = ExamineRecord::where([
  237. 'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE,
  238. 'status' => 0,
  239. 'check_staff_id' => $this->_staff->id
  240. ])->count();
  241. //待入库审批
  242. $partin = ExamineRecord::where([
  243. 'relation_type' => ExamineRecord::PARTS_TYPE,
  244. 'status' => 0,
  245. 'check_staff_id' => $this->_staff->id
  246. ])->count();
  247. //待报价审批
  248. $quote = ExamineRecord::where([
  249. 'relation_type' => ExamineRecord::QUOTE_TYPE,
  250. 'status' => 0,
  251. 'check_staff_id' => $this->_staff->id
  252. ])->count();
  253. //待处理工单
  254. $whereStaff = function ($query) {
  255. $query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
  256. ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
  257. };
  258. $wheres['status']=array('in','0,1');
  259. $workorder = Workorder::where($whereStaff)->where($wheres)->where($where)->count();
  260. //待发票审批
  261. $invoice = ExamineRecord::where([
  262. 'relation_type' => ExamineRecord::INVOICE_TYPE,
  263. 'status' => 0,
  264. 'check_staff_id' => $this->_staff->id
  265. ])->count();
  266. $info = array(
  267. 'customer'=>$customer,
  268. 'contract'=>$contract,
  269. 'lead'=>$lead,
  270. 'consume'=>$consume,
  271. 'news'=>$news,
  272. 'examine'=>$examine,
  273. 'receivables'=>$receivables,
  274. 'approval'=>$approval,
  275. 'notice'=>$notice,
  276. 'achievement'=>$achievement,
  277. 'business'=>$business,
  278. 'partin'=>$partin,
  279. 'quote'=>$quote,
  280. 'workorder'=>$workorder,
  281. 'invoice'=>$invoice,
  282. );
  283. $number=array_sum(array_values($info));
  284. $info['number']=$number;
  285. $this->success('请求成功','',$info);
  286. }
  287. /**
  288. * 提醒消息
  289. */
  290. public function news()
  291. {
  292. //设置过滤方法
  293. $this->request->filter(['strip_tags', 'trim']);
  294. if ($this->request->isAjax()) {
  295. if ($this->request->request('keyField')) {
  296. return $this->selectpage();
  297. }
  298. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  299. $wheres = ['to_staff_id' => $this->_staff->id,'relation_type'=>['not in','examine,discuss,sign,work_report']];
  300. $list = Message::where($where)->where($wheres)->with(['fromStaff', 'examine'])->order('status asc,id desc')->paginate($limit);
  301. foreach($list as $k=>$v){
  302. $list[$k]['relation_name'] = Message::messageType($v['relation_type'],$v['relation_id']);
  303. }
  304. $result = array("total" => $list->total(), "rows" => $list->items());
  305. return json($result);
  306. }
  307. return $this->view->fetch();
  308. }
  309. /**
  310. * 公告
  311. */
  312. public function notice()
  313. {
  314. //设置过滤方法
  315. $this->request->filter(['strip_tags', 'trim']);
  316. if ($this->request->isAjax()) {
  317. if ($this->request->request('keyField')) {
  318. return $this->selectpage();
  319. }
  320. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  321. $staff = Staff::info();
  322. $list = NoticeModel::where($where)->order('id desc')->paginate($limit);
  323. foreach ($list as $k => $v) {
  324. $read = NoticeRead::where(['notice_id'=>$v['id'],'staff_id'=>$staff->id])->find();
  325. if($read){
  326. unset($list[$k]);
  327. continue;
  328. }
  329. $read_staff_ids = explode(',', $v['read_staff_ids']);
  330. $list[$k]['is_read'] = in_array($staff->id, $read_staff_ids)?0:1;
  331. $list[$k]['content'] = strip_tags(htmlspecialchars_decode($v['content']));
  332. }
  333. $arr = $list->items();
  334. array_multisort($arr,SORT_DESC);
  335. $result = array("total" => $list->total(), "rows" => $arr);
  336. return json($result);
  337. }
  338. return $this->view->fetch();
  339. }
  340. /**
  341. * 待线索跟进记录列表
  342. */
  343. public function leads() {
  344. $this->request->filter(['strip_tags']);
  345. if ($this->request->isAjax()) {
  346. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  347. $staff = Staff::info();
  348. //0:全部 1:我负责的 2:下属负责的
  349. $type = input('type',1);
  350. switch($type){
  351. case 1:
  352. $wheres['create_staff_id'] = $staff->id;
  353. break;
  354. case 2:
  355. $wheres['create_staff_id'] = array('in',Staff::getLowerStaffId());
  356. break;
  357. default:
  358. $wheres['create_staff_id'] = array('in',Staff::getMyStaffIds());
  359. break;
  360. }
  361. $wheres['relation_type'] = 4;
  362. $wheres['status'] = 0;
  363. $list = Record::where($where)->where($wheres)->with(['staff','leads'])->order($sort, $order)->paginate($limit);
  364. $row = $list->items();
  365. $result = array("total" => $list->total(), "rows" => $row);
  366. return json($result);
  367. }
  368. return $this->view->fetch();
  369. }
  370. /**
  371. * 待客户跟进记录列表
  372. */
  373. public function customer() {
  374. $this->request->filter(['strip_tags']);
  375. if ($this->request->isAjax()) {
  376. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  377. $staff = Staff::info();
  378. //0:全部 1:我负责的 2:下属负责的
  379. $type = input('type',1);
  380. switch($type){
  381. case 1:
  382. $wheres['create_staff_id'] = $staff->id;
  383. break;
  384. case 2:
  385. $wheres['create_staff_id'] = array('in',Staff::getLowerStaffId());
  386. break;
  387. default:
  388. $wheres['create_staff_id'] = array('in',Staff::getMyStaffIds());
  389. break;
  390. }
  391. $wheres['relation_type'] = 1;
  392. $wheres['status'] = 0;
  393. $list = Record::where($where)->where($wheres)->with(['staff','customer'])->order($sort, $order)->paginate($limit);
  394. $row = $list->items();
  395. $result = array("total" => $list->total(), "rows" => $row);
  396. return json($result);
  397. }
  398. return $this->view->fetch();
  399. }
  400. /**
  401. * 待商机跟进记录列表
  402. */
  403. public function business() {
  404. $this->request->filter(['strip_tags']);
  405. if ($this->request->isAjax()) {
  406. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  407. $staff = Staff::info();
  408. //0:全部 1:我负责的 2:下属负责的
  409. $type = input('type',1);
  410. switch($type){
  411. case 1:
  412. $wheres['create_staff_id'] = $staff->id;
  413. break;
  414. case 2:
  415. $wheres['create_staff_id'] = array('in',Staff::getLowerStaffId());
  416. break;
  417. default:
  418. $wheres['create_staff_id'] = array('in',Staff::getMyStaffIds());
  419. break;
  420. }
  421. $wheres['relation_type'] = 5;
  422. $wheres['status'] = 0;
  423. $list = Record::where($where)->where($wheres)->with(['staff','business'])->order($sort, $order)->paginate($limit);
  424. $row = $list->items();
  425. $result = array("total" => $list->total(), "rows" => $row);
  426. return json($result);
  427. }
  428. return $this->view->fetch();
  429. }
  430. /**
  431. * 待合同跟进记录列表
  432. */
  433. public function contract() {
  434. $this->request->filter(['strip_tags']);
  435. if ($this->request->isAjax()) {
  436. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  437. //0:全部 1:我负责的 2:下属负责的
  438. $type = input('type',1);
  439. switch($type){
  440. case 1:
  441. $wheres['create_staff_id'] = $this->_staff->id;
  442. break;
  443. case 2:
  444. $wheres['create_staff_id'] = array('in',Staff::getLowerStaffId());
  445. break;
  446. default:
  447. $wheres['create_staff_id'] = array('in',Staff::getMyStaffIds());
  448. break;
  449. }
  450. $wheres['relation_type'] = 3;
  451. $wheres['status'] = 0;
  452. $list = Record::where($where)->where($wheres)->with(['staff','contract'])->order($sort, $order)->paginate($limit);
  453. $row = $list->items();
  454. $result = array("total" => $list->total(), "rows" => $row);
  455. return json($result);
  456. }
  457. return $this->view->fetch();
  458. }
  459. /**
  460. * 待工单处理列表
  461. */
  462. public function workorder() {
  463. $this->request->filter(['strip_tags']);
  464. if ($this->request->isAjax()) {
  465. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  466. $whereStaff = function ($query) {
  467. $query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
  468. ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
  469. };
  470. $wheres['status']=array('in','0,1');
  471. $list = Workorder::where($where)->where($whereStaff)->where($wheres)->order($sort, $order)->paginate($limit);
  472. $row = $list->items();
  473. $result = array("total" => $list->total(), "rows" => $row);
  474. return json($result);
  475. }
  476. return $this->view->fetch();
  477. }
  478. /**
  479. * 待工单处理列表
  480. */
  481. public function workorder_7() {
  482. $this->request->filter(['strip_tags']);
  483. if ($this->request->isAjax()) {
  484. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  485. $whereStaff = function ($query) {
  486. $query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
  487. ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
  488. };
  489. $wheres['status']=array('in','0,1');
  490. $list = Workorder::where($where)->where($whereStaff)->where($wheres)->order($sort, $order)->paginate($limit);
  491. $row = $list->items();
  492. $result = array("total" => $list->total(), "rows" => $row);
  493. return json($result);
  494. }
  495. return $this->view->fetch();
  496. }
  497. }