Need.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. namespace app\admin\controller\qingdong\customer;
  3. use addons\qingdong\model\ReceivablesPlan;
  4. use app\admin\controller\qingdong\Base;
  5. use addons\qingdong\model\Staff;
  6. use think\Db;
  7. use think\Exception;
  8. use addons\qingdong\model\Event;
  9. use addons\qingdong\model\ExamineRecord;
  10. use addons\qingdong\model\Record;
  11. /**
  12. * 待办管理
  13. * 操作文档:https://doc.fastadmin.net/qingdong
  14. * 软件介绍:https://www.fastadmin.net/store/qingdong.html
  15. * 售后微信:qingdong_crm
  16. */
  17. class Need extends Base
  18. {
  19. protected $relationSearch = true;
  20. protected $model = null;
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. }
  25. /**
  26. * 待办列表
  27. */
  28. public function index(){
  29. $where['create_staff_id'] = $this->_staff->id;
  30. $where['next_time'] = array(array('egt',date('Y-m-d 00:00:00')),array('lt',date('Y-m-d 23:59:59')));
  31. $where['follow_type'] = ['neq', '其它'];
  32. $where['status'] = 0;
  33. // unset($where['create_staff_id']);
  34. // 待跟进客户
  35. // $where1['relation_type'] = 1;
  36. $customerlist = Record::where($where)->column('relation_id');
  37. $customerlist1 = 0;
  38. if($customerlist){
  39. $whereExit['relation_id'] = array('in',$customerlist);
  40. $whereExit['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  41. $customerlist1 = Record::where($whereExit)->count();
  42. }
  43. $customer = count($customerlist) - $customerlist1;
  44. if($customer <=0){
  45. $customer =0;
  46. }
  47. //待跟进合同
  48. $where2['relation_type'] = 3;
  49. $contractlist = Record::where($where)->where($where2)->column('relation_id');
  50. $contractlist1 = 0;
  51. if($contractlist){
  52. $whereExitC['relation_id'] = array('in',$contractlist);
  53. $whereExitC['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  54. $contractlist1 = Record::where($whereExitC)->count();
  55. }
  56. $contract = count($contractlist)-$contractlist1;
  57. if($contract <=0){
  58. $contract =0;
  59. }
  60. //待跟进线索
  61. $where3['relation_type'] = 4;
  62. $leadlist = Record::where($where)->where($where3)->column('relation_id');
  63. $leadlist1 = 0;
  64. if($leadlist){
  65. $whereExitL['relation_id'] = array('in',$leadlist);
  66. $whereExitL['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  67. $leadlist1 = Record::where($whereExitL)->count();
  68. }
  69. $lead = count($leadlist)-$leadlist1;
  70. if($lead <=0){
  71. $lead =0;
  72. }
  73. //费用审核
  74. $consume = ExamineRecord::where([
  75. 'relation_type' => ExamineRecord::CONSUME_TYPE,
  76. 'status' => 0,
  77. 'check_staff_id' => $this->_staff->id
  78. ])->count();
  79. //待处理日程
  80. $eventOne = Event::where([
  81. 'type' => 1,
  82. 'status' => ['in', [0, 1]],
  83. 'staff_id' => $this->_staff->id,
  84. ])->count();
  85. //待审核合同
  86. $examine = ExamineRecord::where([
  87. 'relation_type' => ExamineRecord::CONTRACT_TYPE,
  88. 'status' => 0,
  89. 'check_staff_id' => $this->_staff->id
  90. ])->count();
  91. //待审核回款
  92. $receivables = ExamineRecord::where([
  93. 'relation_type' => ExamineRecord::RECEIVABLES_TYPE,
  94. 'status' => 0,
  95. 'check_staff_id' => $this->_staff->id,
  96. ])->count();
  97. //待审批办公
  98. $approval = ExamineRecord::where([
  99. 'relation_type' => ExamineRecord::APPROVAL_TYPE,
  100. 'status' => 0,
  101. 'check_staff_id' => $this->_staff->id,
  102. ])->count();
  103. //超时任务
  104. $eventtask = Event::where([
  105. 'type' => 1,
  106. 'status' => ['in', [0, 1]],
  107. 'start_time' => ['lt', date('Y-m-d', strtotime('+1 day'))],
  108. 'staff_id' => $this->_staff->id,
  109. ])->count();
  110. //业绩审核
  111. $achievement = ExamineRecord::where([
  112. 'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE,
  113. 'status' => 0,
  114. 'check_staff_id' => $this->_staff->id
  115. ])->count();
  116. $info = array(
  117. 'customer'=>$customer,
  118. 'contract'=>$contract,
  119. 'lead'=>$lead,
  120. 'consume'=>$consume,
  121. 'eventOne'=>$eventOne,
  122. 'examine'=>$examine,
  123. 'receivables'=>$receivables,
  124. 'approval'=>$approval,
  125. 'eventtask'=>$eventtask,
  126. 'achievement'=>$achievement,
  127. );
  128. $this->view->assign('row',$info);
  129. return $this->view->fetch();
  130. }
  131. /**
  132. * 获取通知数量
  133. */
  134. public function get_need_number(){
  135. $where['create_staff_id'] = $this->_staff->id;
  136. $where['next_time'] = array(array('egt',date('Y-m-d 00:00:00')),array('lt',date('Y-m-d 23:59:59')));
  137. $where['follow_type'] = ['neq', '其它'];
  138. $where['status'] = 0;
  139. // 待跟进客户
  140. $where1['relation_type'] = 1;
  141. $customerlist = Record::where($where)->where($where1)->column('relation_id');
  142. $customerlist1 = 0;
  143. if($customerlist){
  144. $whereExit['relation_id'] = array('in',$customerlist);
  145. $whereExit['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  146. $customerlist1 = Record::where($whereExit)->count();
  147. }
  148. $customer = count($customerlist) - $customerlist1;
  149. if($customer <=0){
  150. $customer =0;
  151. }
  152. //待跟进合同
  153. $where2['relation_type'] = 3;
  154. $contractlist = Record::where($where)->where($where2)->column('relation_id');
  155. $contractlist1 = 0;
  156. if($contractlist){
  157. $whereExitC['relation_id'] = array('in',$contractlist);
  158. $whereExitC['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  159. $contractlist1 = Record::where($whereExitC)->count();
  160. }
  161. $contract = count($contractlist)-$contractlist1;
  162. if($contract <=0){
  163. $contract =0;
  164. }
  165. //待跟进线索
  166. $where3['relation_type'] = 4;
  167. $leadlist = Record::where($where)->where($where3)->column('relation_id');
  168. $leadlist1 = 0;
  169. if($leadlist){
  170. $whereExitL['relation_id'] = array('in',$leadlist);
  171. $whereExitL['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  172. $leadlist1 = Record::where($whereExitL)->count();
  173. }
  174. $lead = count($leadlist)-$leadlist1;
  175. if($lead <=0){
  176. $lead =0;
  177. }
  178. //费用审核
  179. $consume = ExamineRecord::where([
  180. 'relation_type' => ExamineRecord::CONSUME_TYPE,
  181. 'status' => 0,
  182. 'check_staff_id' => $this->_staff->id
  183. ])->count();
  184. //待处理日程
  185. $eventOne = Event::where([
  186. 'type' => 1,
  187. 'status' => ['in', [0, 1]],
  188. 'staff_id' => ['in',$this->_staff->id],
  189. ])->count();
  190. //待审核合同
  191. $examine = ExamineRecord::where([
  192. 'relation_type' => ExamineRecord::CONTRACT_TYPE,
  193. 'status' => 0,
  194. 'check_staff_id' => $this->_staff->id
  195. ])->count();
  196. //待审核回款
  197. $receivables = ExamineRecord::where([
  198. 'relation_type' => ExamineRecord::RECEIVABLES_TYPE,
  199. 'status' => 0,
  200. 'check_staff_id' => $this->_staff->id
  201. ])->count();
  202. //待审批办公
  203. $approval = ExamineRecord::where([
  204. 'relation_type' => ExamineRecord::APPROVAL_TYPE,
  205. 'status' => 0,
  206. 'check_staff_id' => $this->_staff->id
  207. ])->count();
  208. //超时任务
  209. $eventtask = Event::where([
  210. 'type' => 1,
  211. 'status' => ['in', [0, 1]],
  212. 'start_time' => ['lt', date('Y-m-d', strtotime('+1 day'))],
  213. 'staff_id' => $this->_staff->id
  214. ])->count();
  215. //业绩审核
  216. $achievement = ExamineRecord::where([
  217. 'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE,
  218. 'status' => 0,
  219. 'check_staff_id' => $this->_staff->id
  220. ])->count();
  221. $info = array(
  222. 'customer'=>$customer,
  223. 'contract'=>$contract,
  224. 'lead'=>$lead,
  225. 'consume'=>$consume,
  226. 'eventOne'=>$eventOne,
  227. 'examine'=>$examine,
  228. 'receivables'=>$receivables,
  229. 'approval'=>$approval,
  230. 'eventtask'=>$eventtask,
  231. 'achievement'=>$achievement,
  232. );
  233. $number=array_sum(array_values($info));
  234. $info['number']=$number;
  235. $this->success('请求成功','',$info);
  236. }
  237. }