123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- <?php
- namespace app\admin\controller\qingdongams\customer;
- use addons\qingdongams\model\Message;
- use addons\qingdongams\model\Notice as NoticeModel;
- use addons\qingdongams\model\NoticeRead;
- use addons\qingdongams\model\ReceivablesPlan;
- use addons\qingdongams\model\Record as RecordModel;
- use addons\qingdongams\model\Workorder;
- use app\admin\controller\qingdongams\Base;
- use addons\qingdongams\model\Staff;
- use think\Db;
- use think\Exception;
- use addons\qingdongams\model\Event;
- use addons\qingdongams\model\ExamineRecord;
- use addons\qingdongams\model\Record;
- /**
- * 待办管理
- * @desc 操作文档:https://doc.fastadmin.net/qingdongams
- * @desc 软件介绍:https://www.fastadmin.net/store/qingdongams.html
- * @desc 售后微信:qingdong_crm
- */
- class Need extends Base
- {
- protected $relationSearch = true;
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->type = array(
- array(
- 'id'=>1,
- 'pid'=>0,
- 'name'=>'消息提醒',
- 'text'=>'消息提醒',
- ),
- array(
- 'id'=>1,
- 'pid'=>0,
- 'name'=>'公告',
- 'text'=>'消息提醒',
- ),
- array(
- 'id'=>1,
- 'pid'=>0,
- 'name'=>'今日需联系客户',
- 'text'=>'消息提醒',
- ),
- );
- $this->assignconfig('typeList', $this->type);
- }
- /**
- * 待办列表
- */
- public function index(){
- //消息提醒
- $whereNew = [
- 'status'=>0,
- 'to_staff_id' => $this->_staff->id ,
- 'relation_type'=>['not in','examine,discuss,sign']
- ];
- $news = Message::where($whereNew)->count();
- //公告
- $noticeid = NoticeModel::where([])->column('id');
- foreach($noticeid as $k=>$v){
- $read = NoticeRead::where(['notice_id'=>$v,'staff_id'=>$this->_staff->id])->find();
- if($read){
- unset($noticeid[$k]);
- continue;
- }
- }
- $notice = count($noticeid);
- $start = date('Y-m-d 00:00:00');
- $end = date('Y-m-d 23:59:59');
- $where['createtime'] = array(array('egt',strtotime($start)),array('elt',strtotime($end)));
- $whereR['next_time'] = array(array('egt',$start),array('elt',$end));
- //待线索跟进
- $whereLead['create_staff_id'] = $this->_staff->id;
- $whereLead['relation_type'] = 4;
- $whereLead['status'] = 0;
- $lead = Record::where($whereLead)->where($whereR)->count();
- $whereCustomer['create_staff_id'] = $this->_staff->id;
- $whereCustomer['relation_type'] = 1;
- $whereCustomer['status'] = 0;
- $customer = Record::where($whereCustomer)->where($whereR)->count();
- $whereBusiness['create_staff_id'] = $this->_staff->id;
- $whereBusiness['relation_type'] = 5;
- $whereBusiness['status'] = 0;
- $business = Record::where($whereBusiness)->where($whereR)->count();
- $whereContract['create_staff_id'] = $this->_staff->id;
- $whereContract['relation_type'] = 3;
- $whereContract['status'] = 0;
- $contract = Record::where($whereContract)->where($whereR)->count();
- //费用审核
- $consume = ExamineRecord::where([
- 'relation_type' => ExamineRecord::CONSUME_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待审核合同
- $examine = ExamineRecord::where([
- 'relation_type' => ExamineRecord::CONTRACT_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待审核回款
- $receivables = ExamineRecord::where([
- 'relation_type' => ExamineRecord::RECEIVABLES_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id,
- ])->count();
- //待审批办公
- $approval = ExamineRecord::where([
- 'relation_type' => ExamineRecord::APPROVAL_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id,
- ])->count();
- //业绩审核
- $achievement = ExamineRecord::where([
- 'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待入库审批
- $partin = ExamineRecord::where([
- 'relation_type' => ExamineRecord::PARTS_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待报价审批
- $quote = ExamineRecord::where([
- 'relation_type' => ExamineRecord::QUOTE_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待处理工单
- $whereStaff = function ($query) {
- $query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
- ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
- };
- $wheres['status']=array('in','0,1');
- $workorder = Workorder::where($whereStaff)->where($wheres)->where($where)->count();
- $wheres['status']=array('in','0,1');
- $workorder_7 = Workorder::where($whereStaff)->where($wheres)->where($where)->count();
- //待发票审批
- $invoice = ExamineRecord::where([
- 'relation_type' => ExamineRecord::INVOICE_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- $info = array(
- 'customer'=>$customer,
- 'contract'=>$contract,
- 'lead'=>$lead,
- 'consume'=>$consume,
- 'news'=>$news,
- 'examine'=>$examine,
- 'receivables'=>$receivables,
- 'approval'=>$approval,
- 'notice'=>$notice,
- 'achievement'=>$achievement,
- 'business'=>$business,
- 'partin'=>$partin,
- 'quote'=>$quote,
- 'workorder'=>$workorder,
- 'workorder_7'=>$workorder_7,
- 'invoice'=>$invoice,
- );
- $this->view->assign('row',$info);
- $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'))]);
- // $this->assignconfig("dinfo", ['dtime' => date('Y-m-d 00:00:00').' - '.date('Y-m-d 23:59:59', strtotime('+7 days'))]);
-
- return $this->view->fetch();
- }
- /**
- * 获取通知数量
- */
- public function get_need_number(){
- //消息提醒
- $whereNew = ['status'=>0,'to_staff_id' => $this->_staff->id ,'relation_type'=>['not in','examine,discuss,sign,work_report']];
- $news = Message::where($whereNew)->count();
- //公告
- $noticeid = NoticeModel::where([])->column('id');
- foreach($noticeid as $k=>$v){
- $read = NoticeRead::where(['notice_id'=>$v,'staff_id'=>$this->_staff->id])->find();
- if($read){
- unset($noticeid[$k]);
- continue;
- }
- }
- $notice = count($noticeid);
- $start = date('Y-m-d 00:00:00');
- $end = date('Y-m-d 23:59:59');
- $where['createtime'] = array(array('egt',strtotime($start)),array('elt',strtotime($end)));
- $whereR['next_time'] = array(array('egt',$start),array('elt',$end));
- //待线索跟进
- $whereLead['create_staff_id'] = $this->_staff->id;
- $whereLead['relation_type'] = 4;
- $whereLead['status'] = 0;
- $lead = Record::where($whereLead)->where($whereR)->count();
- $whereCustomer['create_staff_id'] = $this->_staff->id;
- $whereCustomer['relation_type'] = 1;
- $whereCustomer['status'] = 0;
- $customer = Record::where($whereCustomer)->where($whereR)->count();
- $whereBusiness['create_staff_id'] = $this->_staff->id;
- $whereBusiness['relation_type'] = 5;
- $whereBusiness['status'] = 0;
- $business = Record::where($whereBusiness)->where($whereR)->count();
- $whereContract['create_staff_id'] = $this->_staff->id;
- $whereContract['relation_type'] = 3;
- $whereContract['status'] = 0;
- $contract = Record::where($whereContract)->where($whereR)->count();
- //费用审核
- $consume = ExamineRecord::where([
- 'relation_type' => ExamineRecord::CONSUME_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待审核合同
- $examine = ExamineRecord::where([
- 'relation_type' => ExamineRecord::CONTRACT_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待审核回款
- $receivables = ExamineRecord::where([
- 'relation_type' => ExamineRecord::RECEIVABLES_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id,
- ])->count();
- //待审批办公
- $approval = ExamineRecord::where([
- 'relation_type' => ExamineRecord::APPROVAL_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id,
- ])->count();
- //业绩审核
- $achievement = ExamineRecord::where([
- 'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待入库审批
- $partin = ExamineRecord::where([
- 'relation_type' => ExamineRecord::PARTS_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待报价审批
- $quote = ExamineRecord::where([
- 'relation_type' => ExamineRecord::QUOTE_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- //待处理工单
- $whereStaff = function ($query) {
- $query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
- ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
- };
- $wheres['status']=array('in','0,1');
- $workorder = Workorder::where($whereStaff)->where($wheres)->where($where)->count();
- //待发票审批
- $invoice = ExamineRecord::where([
- 'relation_type' => ExamineRecord::INVOICE_TYPE,
- 'status' => 0,
- 'check_staff_id' => $this->_staff->id
- ])->count();
- $info = array(
- 'customer'=>$customer,
- 'contract'=>$contract,
- 'lead'=>$lead,
- 'consume'=>$consume,
- 'news'=>$news,
- 'examine'=>$examine,
- 'receivables'=>$receivables,
- 'approval'=>$approval,
- 'notice'=>$notice,
- 'achievement'=>$achievement,
- 'business'=>$business,
- 'partin'=>$partin,
- 'quote'=>$quote,
- 'workorder'=>$workorder,
- 'invoice'=>$invoice,
- );
- $number=array_sum(array_values($info));
- $info['number']=$number;
- $this->success('请求成功','',$info);
- }
- /**
- * 提醒消息
- */
- public function news()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $wheres = ['to_staff_id' => $this->_staff->id,'relation_type'=>['not in','examine,discuss,sign,work_report']];
- $list = Message::where($where)->where($wheres)->with(['fromStaff', 'examine'])->order('status asc,id desc')->paginate($limit);
- foreach($list as $k=>$v){
- $list[$k]['relation_name'] = Message::messageType($v['relation_type'],$v['relation_id']);
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 公告
- */
- public function notice()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $staff = Staff::info();
- $list = NoticeModel::where($where)->order('id desc')->paginate($limit);
- foreach ($list as $k => $v) {
- $read = NoticeRead::where(['notice_id'=>$v['id'],'staff_id'=>$staff->id])->find();
- if($read){
- unset($list[$k]);
- continue;
- }
- $read_staff_ids = explode(',', $v['read_staff_ids']);
- $list[$k]['is_read'] = in_array($staff->id, $read_staff_ids)?0:1;
- $list[$k]['content'] = strip_tags(htmlspecialchars_decode($v['content']));
- }
- $arr = $list->items();
- array_multisort($arr,SORT_DESC);
- $result = array("total" => $list->total(), "rows" => $arr);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 待线索跟进记录列表
- */
- public function leads() {
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $staff = Staff::info();
- //0:全部 1:我负责的 2:下属负责的
- $type = input('type',1);
- switch($type){
- case 1:
- $wheres['create_staff_id'] = $staff->id;
- break;
- case 2:
- $wheres['create_staff_id'] = array('in',Staff::getLowerStaffId());
- break;
- default:
- $wheres['create_staff_id'] = array('in',Staff::getMyStaffIds());
- break;
- }
- $wheres['relation_type'] = 4;
- $wheres['status'] = 0;
- $list = Record::where($where)->where($wheres)->with(['staff','leads'])->order($sort, $order)->paginate($limit);
- $row = $list->items();
- $result = array("total" => $list->total(), "rows" => $row);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 待客户跟进记录列表
- */
- public function customer() {
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $staff = Staff::info();
- //0:全部 1:我负责的 2:下属负责的
- $type = input('type',1);
- switch($type){
- case 1:
- $wheres['create_staff_id'] = $staff->id;
- break;
- case 2:
- $wheres['create_staff_id'] = array('in',Staff::getLowerStaffId());
- break;
- default:
- $wheres['create_staff_id'] = array('in',Staff::getMyStaffIds());
- break;
- }
- $wheres['relation_type'] = 1;
- $wheres['status'] = 0;
- $list = Record::where($where)->where($wheres)->with(['staff','customer'])->order($sort, $order)->paginate($limit);
- $row = $list->items();
- $result = array("total" => $list->total(), "rows" => $row);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 待商机跟进记录列表
- */
- public function business() {
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $staff = Staff::info();
- //0:全部 1:我负责的 2:下属负责的
- $type = input('type',1);
- switch($type){
- case 1:
- $wheres['create_staff_id'] = $staff->id;
- break;
- case 2:
- $wheres['create_staff_id'] = array('in',Staff::getLowerStaffId());
- break;
- default:
- $wheres['create_staff_id'] = array('in',Staff::getMyStaffIds());
- break;
- }
- $wheres['relation_type'] = 5;
- $wheres['status'] = 0;
- $list = Record::where($where)->where($wheres)->with(['staff','business'])->order($sort, $order)->paginate($limit);
- $row = $list->items();
- $result = array("total" => $list->total(), "rows" => $row);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 待合同跟进记录列表
- */
- public function contract() {
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- //0:全部 1:我负责的 2:下属负责的
- $type = input('type',1);
- switch($type){
- case 1:
- $wheres['create_staff_id'] = $this->_staff->id;
- break;
- case 2:
- $wheres['create_staff_id'] = array('in',Staff::getLowerStaffId());
- break;
- default:
- $wheres['create_staff_id'] = array('in',Staff::getMyStaffIds());
- break;
- }
- $wheres['relation_type'] = 3;
- $wheres['status'] = 0;
- $list = Record::where($where)->where($wheres)->with(['staff','contract'])->order($sort, $order)->paginate($limit);
- $row = $list->items();
- $result = array("total" => $list->total(), "rows" => $row);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 待工单处理列表
- */
- public function workorder() {
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $whereStaff = function ($query) {
- $query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
- ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
- };
- $wheres['status']=array('in','0,1');
- $list = Workorder::where($where)->where($whereStaff)->where($wheres)->order($sort, $order)->paginate($limit);
- $row = $list->items();
- $result = array("total" => $list->total(), "rows" => $row);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 待工单处理列表
- */
- public function workorder_7() {
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $whereStaff = function ($query) {
- $query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
- ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
- };
- $wheres['status']=array('in','0,1');
- $list = Workorder::where($where)->where($whereStaff)->where($wheres)->order($sort, $order)->paginate($limit);
- $row = $list->items();
- $result = array("total" => $list->total(), "rows" => $row);
- return json($result);
- }
- return $this->view->fetch();
- }
-
- }
|