Index.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\customer\controller;
  15. use app\base\BaseController;
  16. use app\customer\model\Customer as CustomerModel;
  17. use think\facade\Db;
  18. use think\facade\View;
  19. class Index extends BaseController
  20. {
  21. /**
  22. * 构造函数
  23. */
  24. protected $model;
  25. public function __construct()
  26. {
  27. parent::__construct(); // 调用父类构造函数
  28. $this->model = new CustomerModel();
  29. }
  30. //抢客宝
  31. public function rush()
  32. {
  33. if (request()->isAjax()) {
  34. $param = get_params();
  35. $param['order'] = 'rand()';
  36. $where = array();
  37. $where[] = ['delete_time', '=', 0];
  38. $where[] = ['discard_time', '=', 0];
  39. $where[] = ['belong_uid', '=', 0];
  40. $list = $this->model->datalist($param,$where);
  41. return table_assign(0, '', $list);
  42. } else {
  43. $time = strtotime(date('Y-m-d')." 00:00:00");
  44. $max_num = Db::name('DataAuth')->where('name','customer_admin')->value('conf_2');
  45. $count = Db::name('Customer')->where([['belong_time','>',$time],['belong_uid','=',$this->uid]])->count();
  46. View::assign('max_num', $max_num);
  47. View::assign('count', $count);
  48. return view();
  49. }
  50. }
  51. //公海客户
  52. public function sea()
  53. {
  54. if (request()->isAjax()) {
  55. $param = get_params();
  56. $where = array();
  57. if (!empty($param['keywords'])) {
  58. $where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
  59. }
  60. if (!empty($param['industry_id'])) {
  61. $where[] = ['industry_id', '=', $param['industry_id']];
  62. }
  63. if (!empty($param['source_id'])) {
  64. $where[] = ['source_id', '=', $param['source_id']];
  65. }
  66. if (!empty($param['grade_id'])) {
  67. $where[] = ['grade_id', '=', $param['grade_id']];
  68. }
  69. if (!empty($param['follow_time'])) {
  70. $follow_time =explode('~', $param['follow_time']);
  71. $where[] = ['follow_time', 'between',[strtotime(urldecode($follow_time[0])),strtotime(urldecode($follow_time[1].' 23:59:59'))]];
  72. }
  73. $where[] = ['delete_time', '=', 0];
  74. $where[] = ['discard_time', '=', 0];
  75. $where[] = ['belong_uid', '=', 0];
  76. $list = $this->model->datalist($param,$where);
  77. return table_assign(0, '', $list);
  78. } else {
  79. return view();
  80. }
  81. }
  82. //废池客户
  83. public function trash()
  84. {
  85. if (request()->isAjax()) {
  86. $param = get_params();
  87. $where = array();
  88. if (!empty($param['keywords'])) {
  89. $where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
  90. }
  91. if (!empty($param['industry_id'])) {
  92. $where[] = ['industry_id', '=', $param['industry_id']];
  93. }
  94. if (!empty($param['source_id'])) {
  95. $where[] = ['source_id', '=', $param['source_id']];
  96. }
  97. if (!empty($param['grade_id'])) {
  98. $where[] = ['grade_id', '=', $param['grade_id']];
  99. }
  100. $where[] = ['delete_time', '>', 0];
  101. $where[] = ['discard_time', '=', 0];
  102. $where[] = ['belong_uid', '=', 0];
  103. $list = $this->model->datalist($param,$where);
  104. return table_assign(0, '', $list);
  105. } else {
  106. return view();
  107. }
  108. }
  109. //移入公海
  110. public function to_sea()
  111. {
  112. if (request()->isAjax()) {
  113. $id = get_params("id");
  114. $idArray = explode(',', strval($id));
  115. $list = [];
  116. foreach ($idArray as $key => $val) {
  117. $list[] = [
  118. 'id' => $val,
  119. 'belong_uid' => 0,
  120. 'belong_did' => 0,
  121. 'belong_time' => 0
  122. ];
  123. }
  124. foreach ($list as $key => $v) {
  125. if (Db::name('Customer')->update($v) !== false) {
  126. add_log('tosea', $v['id']);
  127. }
  128. }
  129. return to_assign(0, '操作成功');
  130. } else {
  131. return to_assign(1, "错误的请求");
  132. }
  133. }
  134. //获取客户
  135. public function to_get()
  136. {
  137. if (request()->isAjax()) {
  138. $id = get_params("id");
  139. $time = strtotime(date('Y-m-d')." 00:00:00");
  140. $max_num_day = Db::name('DataAuth')->where('name','customer_admin')->value('conf_2');
  141. $count_day = Db::name('Customer')->where([['belong_time','between',[$time,time()]],['belong_uid','=',$this->uid]])->count();
  142. if($count_day>=$max_num_day){
  143. return to_assign(1, "今日领取客户数已到达上限,请明天再来领取");
  144. }
  145. $max_num = Db::name('DataAuth')->where('name','customer_admin')->value('conf_3');
  146. $count = Db::name('Customer')->where([['belong_uid','=',$this->uid]])->count();
  147. if($count>=$max_num){
  148. return to_assign(1, "领取客户数已到达上限,请把部分客户移到公海里再来领取");
  149. }
  150. $data['id'] = $id;
  151. $data['belong_uid'] = $this->uid;
  152. $data['belong_did'] = $this->did;
  153. $data['belong_time'] = time();
  154. if (Db::name('Customer')->update($data) !== false) {
  155. add_log('tosea', $id);
  156. return to_assign(0, "操作成功");
  157. } else {
  158. return to_assign(1, "操作失败");
  159. }
  160. } else {
  161. return to_assign(1, "错误的请求");
  162. }
  163. }
  164. //客户移入废弃池
  165. public function to_trash()
  166. {
  167. if (request()->isAjax()) {
  168. $params = get_params();
  169. $id = get_params("id");
  170. $idArray = explode(',', strval($id));
  171. $list = [];
  172. foreach ($idArray as $key => $val) {
  173. $list[] = [
  174. 'id' => $val,
  175. 'delete_time' => time()
  176. ];
  177. }
  178. foreach ($list as $key => $v) {
  179. if (Db::name('Customer')->update($v) !== false) {
  180. add_log('totrash', $params['id']);
  181. }
  182. }
  183. return to_assign(0, '操作成功');
  184. } else {
  185. return to_assign(1, "错误的请求");
  186. }
  187. }
  188. //还原客户
  189. public function to_revert()
  190. {
  191. if (request()->isAjax()) {
  192. $params = get_params();
  193. $id = get_params("id");
  194. $idArray = explode(',', strval($id));
  195. $list = [];
  196. foreach ($idArray as $key => $val) {
  197. $list[] = [
  198. 'id' => $val,
  199. 'delete_time' => 0
  200. ];
  201. }
  202. foreach ($list as $key => $v) {
  203. if (Db::name('Customer')->update($v) !== false) {
  204. add_log('recovery', $params['id']);
  205. }
  206. }
  207. return to_assign(0, '操作成功');
  208. } else {
  209. return to_assign(1, "错误的请求");
  210. }
  211. }
  212. }