MessageLogic.php 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. namespace app\crm\logic;
  3. use app\admin\model\Common;
  4. use app\crm\model\Customer;
  5. use think\Db;
  6. use function foo\func;
  7. class MessageLogic extends Common
  8. {
  9. /**
  10. *
  11. * 今日续联系线索列表
  12. * @param $param
  13. *
  14. * @author alvin guogaobo
  15. * @version 1.0 版本号
  16. * @since 2021/5/24 0024 11:43
  17. */
  18. public function todayLeads($param)
  19. {
  20. $type = !empty($param['type']) ? $param['type'] : 1;
  21. $isSub = !empty($param['isSub']) ? $param['isSub'] : 0;
  22. $todayTime = getTimeByType('today');
  23. unset($param['type']);
  24. unset($param['isSub']);
  25. $request = $this->where($param, $type, $isSub, $todayTime);
  26. $leadsModel = new \app\crm\model\Leads();
  27. $data = $leadsModel->getDataList($request);
  28. return $data;
  29. }
  30. /**
  31. * 客户
  32. * @param $request
  33. *
  34. * @author alvin guogaobo
  35. * @version 1.0 版本号
  36. * @since 2021/5/25 0025 09:17
  37. */
  38. public function remindCustomer($param)
  39. {
  40. $type = $param['type'] ?: 1;
  41. $isSub = $param['isSub'] ?: '';
  42. $todayTime = getTimeByType('today');
  43. unset($param['type']);
  44. unset($param['isSub']);
  45. $request = $this->where($param, $type, $isSub, $todayTime);
  46. $customerModel = model('Customer');
  47. $data = $customerModel->getDataList($request);
  48. return $data;
  49. }
  50. /**
  51. *
  52. * @param $param
  53. *
  54. * @author alvin guogaobo
  55. * @version 1.0 版本号
  56. * @since 2021/5/26 0026 10:13
  57. */
  58. public function todayBusiness($param)
  59. {
  60. $type = !empty($param['type']) ? $param['type'] : 1;
  61. $isSub = !empty($param['isSub']) ? $param['isSub'] : 0;
  62. $todayTime = getTimeByType('today');
  63. unset($param['type']);
  64. unset($param['isSub']);
  65. $request = $this->where($param, $type, $isSub, $todayTime);
  66. $businessModel = new \app\crm\model\Business();
  67. $data = $businessModel->getDataList($request);
  68. return $data;
  69. }
  70. /**
  71. * 分配给我的线索
  72. * @param $param
  73. *
  74. * @author alvin guogaobo
  75. * @version 1.0 版本号
  76. * @since 2021/5/26 0026 10:32
  77. */
  78. public function followLeads($param)
  79. {
  80. $type = $param['type'] ?: 1;
  81. unset($param['type']);
  82. $request = $this->where($param, $type, '', '');
  83. $leadsModel = model('Leads');
  84. $data = $leadsModel->getDataList($request);
  85. return $data;
  86. }
  87. /**
  88. * 分配给我的客户
  89. * @param $param
  90. *
  91. * @author alvin guogaobo
  92. * @version 1.0 版本号
  93. * @since 2021/5/26 0026 10:36
  94. */
  95. public function followCustomer($param)
  96. {
  97. $type = $param['type'] ?: 1;
  98. $isSub = $param['isSub'] ?: '';
  99. unset($param['type']);
  100. unset($param['isSub']);
  101. $request = $this->where($param, $type, $isSub, '');
  102. unset($param['user_id']);
  103. $customerModel = model('Customer');
  104. $data = $customerModel->getDataList($request);
  105. return $data;
  106. }
  107. /**
  108. * @param $param
  109. *
  110. * @author alvin guogaobo
  111. * @version 1.0 版本号
  112. * @since 2021/5/26 0026 11:42
  113. */
  114. public function checkContract($param)
  115. {
  116. $type = $param['type'] ?: 1;
  117. unset($param['type']);
  118. $contractModel = model('Contract');
  119. $request = $this->whereCheck($param, $type);
  120. $request['isMessage'] = true;
  121. $data = $contractModel->getDataList($request);
  122. return $data;
  123. }
  124. /**
  125. * 待审核回款
  126. * @param $param
  127. *
  128. * @author alvin guogaobo
  129. * @version 1.0 版本号
  130. * @since 2021/5/26 0026 11:48
  131. */
  132. public function checkReceivables($param){
  133. $type = $param['type'] ? : 1;
  134. $isSub = 1;
  135. unset($param['type']);
  136. $receivablesModel = model('Receivables');
  137. $request = $this->whereCheck($param, $type,$isSub);
  138. $request['isMessage'] = true;
  139. $data = $receivablesModel->getDataList($request);
  140. return $data;
  141. }
  142. /**
  143. *待审核发票
  144. *
  145. * @author alvin guogaobo
  146. * @version 1.0 版本号
  147. * @since 2021/5/26 0026 13:35
  148. */
  149. public function checkInvoice($param){
  150. $type = !empty($param['type']) ? $param['type'] : 1;
  151. $isSub = 2;
  152. # 清除与模型无关的数据
  153. unset($param['type']);
  154. $request = $this->whereCheck($param, $type,$isSub);
  155. $request['isMessage'] = true;
  156. $data = (new InvoiceLogic())->index($request);
  157. return $data;
  158. }
  159. /**
  160. * 审批查询条件
  161. * @param $param
  162. * @param $type
  163. *
  164. * @author alvin guogaobo
  165. * @version 1.0 版本号
  166. * @since 2021/5/26 0026 11:43
  167. */
  168. public function whereCheck($param, $type,$isSub='')
  169. {
  170. if(empty($isSub)){
  171. switch ($type) {
  172. case '1' :
  173. $param['check_status'] = ['lt', '2'];
  174. $param['check_user_id'] = ['like', '%,' . $param['user_id'] . ',%'];
  175. # 要提醒的合同ID
  176. $contractIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_contract'], 'user_id' => ['eq', $param['user_id']]])->column('types_id');
  177. $param['contractIdArray'] = !empty($contractIdArray) ? $contractIdArray : -1;
  178. break;
  179. case '2' :
  180. $param['flow_user_id'] = ['like', '%,' . $param['user_id'] . ',%'];
  181. break;
  182. }
  183. }else if($isSub==1){
  184. switch ($type) {
  185. case '1' :
  186. # 待审核、审核中
  187. $param['check_status'] = ['lt','2'];
  188. $param['check_user_id'] = ['like','%,'.$param['user_id'].',%'];
  189. # 要提醒的回款ID
  190. $receivablesIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_receivables'], 'user_id' => ['eq', $param['user_id']]])->column('types_id');
  191. $param['receivablesIdArray'] = !empty($receivablesIdArray) ? $receivablesIdArray : -1;
  192. break;
  193. case '2' :
  194. # 全部
  195. $param['flow_user_id'] = ['like','%,'.$param['user_id'].',%'];
  196. break;
  197. }
  198. }elseif($isSub==2){
  199. switch ($type) {
  200. case '1' :
  201. # 待审核、审核中
  202. $param['check_status'] = ['lt', 2];
  203. $param['check_user_id'] = ['like', '%,'. $param['user_id'] .',%'];
  204. # 要提醒的发票ID
  205. $invoiceIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_invoice'], 'user_id' => ['eq', $param['user_id']]])->column('types_id');
  206. $param['invoiceIdArray'] = !empty($invoiceIdArray) ? $invoiceIdArray : -1;
  207. $param['dealt'] = 1;
  208. break;
  209. case '2' :
  210. # 全部
  211. $param['flow_user_id'] = ['like', '%,'. $param['user_id'] .',%'];
  212. $param['dealt'] = 1;
  213. break;
  214. }
  215. }
  216. return $param;
  217. }
  218. /**
  219. * 负责人查询条件
  220. * @param $param
  221. *
  222. * @author alvin guogaobo
  223. * @version 1.0 版本号
  224. * @since 2021/5/24 0024 09:46
  225. */
  226. public function where($param, $type, $isSub, $todayTime)
  227. {
  228. # 负责人
  229. $param['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false, 0, $param['user_id'])] : ['eq', $param['user_id']];
  230. # 类型:1今日需联系;2已逾期;3已联系
  231. if (empty($isSub) && empty($todayTime)) {
  232. switch ($type) {
  233. case '1' :
  234. $param['follow'] = [['neq', '已跟进'], null, 'or'];
  235. $param['is_allocation'] = 1;
  236. break;
  237. case '2' :
  238. $param['follow'] = ['eq', '已跟进'];
  239. $param['is_allocation'] = 1;
  240. break;
  241. }
  242. } else {
  243. switch ($type) {
  244. case '1' :
  245. $param['next_time'] = ['between', [$todayTime[0], $todayTime[1]]];
  246. $param['is_dealt'] = ['neq', 1];
  247. break;
  248. case '2' :
  249. $param['next_time'] = ['between', [1, time()]];
  250. $param['overdue'] = true;
  251. $param['is_dealt'] = ['neq', 1];
  252. break;
  253. case '3' :
  254. $param['last_time'] = ['between', [$todayTime[0], $todayTime[1]]];
  255. break;
  256. }
  257. }
  258. return $param;
  259. }
  260. }