Need.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. // 待跟进客户
  34. $where1['relation_type'] = 1;
  35. $customerlist = Record::where($where)->where($where1)->column('relation_id');
  36. $customerlist1 = 0;
  37. if($customerlist){
  38. $whereExit['relation_id'] = array('in',$customerlist);
  39. $whereExit['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  40. $customerlist1 = Record::where($whereExit)->count();
  41. }
  42. $customer = count($customerlist) - $customerlist1;
  43. if($customer <=0){
  44. $customer =0;
  45. }
  46. //待跟进合同
  47. $where2['relation_type'] = 3;
  48. $contractlist = Record::where($where)->where($where2)->column('relation_id');
  49. $contractlist1 = 0;
  50. if($contractlist){
  51. $whereExitC['relation_id'] = array('in',$contractlist);
  52. $whereExitC['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  53. $contractlist1 = Record::where($whereExitC)->count();
  54. }
  55. $contract = count($contractlist)-$contractlist1;
  56. if($contract <=0){
  57. $contract =0;
  58. }
  59. //待跟进线索
  60. $where3['relation_type'] = 4;
  61. $leadlist = Record::where($where)->where($where3)->column('relation_id');
  62. $leadlist1 = 0;
  63. if($leadlist){
  64. $whereExitL['relation_id'] = array('in',$leadlist);
  65. $whereExitL['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  66. $leadlist1 = Record::where($whereExitL)->count();
  67. }
  68. $lead = count($leadlist)-$leadlist1;
  69. if($lead <=0){
  70. $lead =0;
  71. }
  72. //费用审核
  73. $consume = ExamineRecord::where([
  74. 'relation_type' => ExamineRecord::CONSUME_TYPE,
  75. 'status' => 0,
  76. 'check_staff_id' => $this->_staff->id
  77. ])->count();
  78. //待处理日程
  79. $eventOne = Event::where([
  80. 'type' => 1,
  81. 'status' => ['in', [0, 1]],
  82. 'staff_id' => $this->_staff->id,
  83. ])->count();
  84. //待审核合同
  85. $examine = ExamineRecord::where([
  86. 'relation_type' => ExamineRecord::CONTRACT_TYPE,
  87. 'status' => 0,
  88. 'check_staff_id' => $this->_staff->id
  89. ])->count();
  90. //待审核回款
  91. $receivables = ExamineRecord::where([
  92. 'relation_type' => ExamineRecord::RECEIVABLES_TYPE,
  93. 'status' => 0,
  94. 'check_staff_id' => $this->_staff->id,
  95. ])->count();
  96. //待审批办公
  97. $approval = ExamineRecord::where([
  98. 'relation_type' => ExamineRecord::APPROVAL_TYPE,
  99. 'status' => 0,
  100. 'check_staff_id' => $this->_staff->id,
  101. ])->count();
  102. //超时任务
  103. $eventtask = Event::where([
  104. 'type' => 1,
  105. 'status' => ['in', [0, 1]],
  106. 'start_time' => ['lt', date('Y-m-d', strtotime('+1 day'))],
  107. 'staff_id' => $this->_staff->id,
  108. ])->count();
  109. //业绩审核
  110. $achievement = ExamineRecord::where([
  111. 'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE,
  112. 'status' => 0,
  113. 'check_staff_id' => $this->_staff->id
  114. ])->count();
  115. $info = array(
  116. 'customer'=>$customer,
  117. 'contract'=>$contract,
  118. 'lead'=>$lead,
  119. 'consume'=>$consume,
  120. 'eventOne'=>$eventOne,
  121. 'examine'=>$examine,
  122. 'receivables'=>$receivables,
  123. 'approval'=>$approval,
  124. 'eventtask'=>$eventtask,
  125. 'achievement'=>$achievement,
  126. );
  127. $this->view->assign('row',$info);
  128. return $this->view->fetch();
  129. }
  130. /**
  131. * 获取通知数量
  132. */
  133. public function get_need_number(){
  134. $where['create_staff_id'] = $this->_staff->id;
  135. $where['next_time'] = array(array('egt',date('Y-m-d 00:00:00')),array('lt',date('Y-m-d 23:59:59')));
  136. $where['follow_type'] = ['neq', '其它'];
  137. $where['status'] = 0;
  138. // 待跟进客户
  139. $where1['relation_type'] = 1;
  140. $customerlist = Record::where($where)->where($where1)->column('relation_id');
  141. $customerlist1 = 0;
  142. if($customerlist){
  143. $whereExit['relation_id'] = array('in',$customerlist);
  144. $whereExit['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  145. $customerlist1 = Record::where($whereExit)->count();
  146. }
  147. $customer = count($customerlist) - $customerlist1;
  148. if($customer <=0){
  149. $customer =0;
  150. }
  151. //待跟进合同
  152. $where2['relation_type'] = 3;
  153. $contractlist = Record::where($where)->where($where2)->column('relation_id');
  154. $contractlist1 = 0;
  155. if($contractlist){
  156. $whereExitC['relation_id'] = array('in',$contractlist);
  157. $whereExitC['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  158. $contractlist1 = Record::where($whereExitC)->count();
  159. }
  160. $contract = count($contractlist)-$contractlist1;
  161. if($contract <=0){
  162. $contract =0;
  163. }
  164. //待跟进线索
  165. $where3['relation_type'] = 4;
  166. $leadlist = Record::where($where)->where($where3)->column('relation_id');
  167. $leadlist1 = 0;
  168. if($leadlist){
  169. $whereExitL['relation_id'] = array('in',$leadlist);
  170. $whereExitL['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  171. $leadlist1 = Record::where($whereExitL)->count();
  172. }
  173. $lead = count($leadlist)-$leadlist1;
  174. if($lead <=0){
  175. $lead =0;
  176. }
  177. //费用审核
  178. $consume = ExamineRecord::where([
  179. 'relation_type' => ExamineRecord::CONSUME_TYPE,
  180. 'status' => 0,
  181. 'check_staff_id' => $this->_staff->id
  182. ])->count();
  183. //待处理日程
  184. $eventOne = Event::where([
  185. 'type' => 1,
  186. 'status' => ['in', [0, 1]],
  187. 'staff_id' => ['in',$this->_staff->id],
  188. ])->count();
  189. //待审核合同
  190. $examine = ExamineRecord::where([
  191. 'relation_type' => ExamineRecord::CONTRACT_TYPE,
  192. 'status' => 0,
  193. 'check_staff_id' => $this->_staff->id
  194. ])->count();
  195. //待审核回款
  196. $receivables = ExamineRecord::where([
  197. 'relation_type' => ExamineRecord::RECEIVABLES_TYPE,
  198. 'status' => 0,
  199. 'check_staff_id' => $this->_staff->id
  200. ])->count();
  201. //待审批办公
  202. $approval = ExamineRecord::where([
  203. 'relation_type' => ExamineRecord::APPROVAL_TYPE,
  204. 'status' => 0,
  205. 'check_staff_id' => $this->_staff->id
  206. ])->count();
  207. //超时任务
  208. $eventtask = Event::where([
  209. 'type' => 1,
  210. 'status' => ['in', [0, 1]],
  211. 'start_time' => ['lt', date('Y-m-d', strtotime('+1 day'))],
  212. 'staff_id' => $this->_staff->id
  213. ])->count();
  214. //业绩审核
  215. $achievement = ExamineRecord::where([
  216. 'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE,
  217. 'status' => 0,
  218. 'check_staff_id' => $this->_staff->id
  219. ])->count();
  220. $info = array(
  221. 'customer'=>$customer,
  222. 'contract'=>$contract,
  223. 'lead'=>$lead,
  224. 'consume'=>$consume,
  225. 'eventOne'=>$eventOne,
  226. 'examine'=>$examine,
  227. 'receivables'=>$receivables,
  228. 'approval'=>$approval,
  229. 'eventtask'=>$eventtask,
  230. 'achievement'=>$achievement,
  231. );
  232. $number=array_sum(array_values($info));
  233. $info['number']=$number;
  234. $this->success('请求成功','',$info);
  235. }
  236. }