Customer.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 app\customer\validate\CustomerValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Customer extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new CustomerModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. $param = get_params();
  38. if (request()->isAjax()) {
  39. $where=[];
  40. $whereOr = [];
  41. $uid = $this->uid;
  42. $tab = isset($param['tab']) ? $param['tab'] : 0;
  43. if (!empty($param['keywords'])) {
  44. $where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
  45. }
  46. if (!empty($param['customer_status'])) {
  47. $where[] = ['customer_status', '=', $param['customer_status']];
  48. }
  49. if (!empty($param['industry_id'])) {
  50. $where[] = ['industry_id', '=', $param['industry_id']];
  51. }
  52. if (!empty($param['source_id'])) {
  53. $where[] = ['source_id', '=', $param['source_id']];
  54. }
  55. if (!empty($param['grade_id'])) {
  56. $where[] = ['grade_id', '=', $param['grade_id']];
  57. }
  58. if (!empty($param['intent_status'])) {
  59. $where[] = ['intent_status', '=', $param['intent_status']];
  60. }
  61. if (!empty($param['follow_time'])) {
  62. $follow_time =explode('~', $param['follow_time']);
  63. $where[] = ['follow_time', 'between',[strtotime(urldecode($follow_time[0])),strtotime(urldecode($follow_time[1].' 23:59:59'))]];
  64. }
  65. if (!empty($param['next_time'])) {
  66. $next_time =explode('~', $param['next_time']);
  67. $where[] = ['next_time', 'between',[strtotime(urldecode($next_time[0])),strtotime(urldecode($next_time[1].' 23:59:59'))]];
  68. }
  69. $where[]=['delete_time','=',0];
  70. $where[]=['discard_time','=',0];
  71. if($tab == 0){
  72. if (!empty($param['uid'])) {
  73. $where[] = ['belong_uid', '=', $param['uid']];
  74. }
  75. else{
  76. //是否是客户管理员
  77. $auth = isAuth($uid,'customer_admin','conf_1');
  78. if($auth == 0){
  79. $whereOr[] = ['belong_uid','=',$uid];
  80. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
  81. $dids_a = get_leader_departments($uid);
  82. $dids_b = get_role_departments($uid);
  83. $dids = array_merge($dids_a, $dids_b);
  84. if(!empty($dids)){
  85. $whereOr[] = ['belong_did','in',$dids];
  86. }
  87. }
  88. else{
  89. $where[] = ['belong_did','<>',0];
  90. }
  91. }
  92. }
  93. //我的客户
  94. if($tab == 1){
  95. $where[] = ['belong_uid','=',$uid];
  96. }
  97. //下属客户
  98. if($tab == 2){
  99. $where[] = ['belong_uid','<>',$uid];
  100. $dids_a = get_leader_departments($uid);
  101. if(!empty($dids_a)){
  102. $where[] = ['belong_did','in',$dids_a];
  103. }
  104. }
  105. //分享客户
  106. if($tab == 3){
  107. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
  108. }
  109. $list = $this->model->datalist($param,$where,$whereOr);
  110. return table_assign(0, '', $list);
  111. }
  112. else{
  113. View::assign('is_leader', isLeader($this->uid));
  114. return view();
  115. }
  116. }
  117. /**
  118. * 添加/编辑
  119. */
  120. public function add()
  121. {
  122. $param = get_params();
  123. if (request()->isAjax()) {
  124. try {
  125. validate(CustomerValidate::class)->scene($param['scene'])->check($param);
  126. } catch (ValidateException $e) {
  127. // 验证失败 输出错误信息
  128. return to_assign(1, $e->getError());
  129. }
  130. if (!empty($param['id']) && $param['id'] > 0) {
  131. $param['edit_id'] = $this->uid;
  132. $this->model->edit($param);
  133. } else {
  134. $param['admin_id'] = $this->uid;
  135. $this->model->add($param);
  136. }
  137. }else{
  138. $id = isset($param['id']) ? $param['id'] : 0;
  139. $sea = isset($param['sea']) ? $param['sea'] : 0;
  140. View::assign('sea', $sea);
  141. if ($id>0) {
  142. $detail = $this->model->getById($id);
  143. View::assign('detail', $detail);
  144. return view('edit');
  145. }
  146. if($this->uid>1){
  147. View::assign('userinfo', get_admin($this->uid));
  148. }
  149. if(is_mobile()){
  150. return view('qiye@/customer/add');
  151. }
  152. return view();
  153. }
  154. }
  155. /**
  156. * 查看
  157. */
  158. public function view($id)
  159. {
  160. $detail = $this->model->getById($id);
  161. $detail['admin_name'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('name');
  162. if($detail['customer_status']>0){
  163. $detail['customer_status_name'] = Db::name('BasicCustomer')->where(['id' => $detail['customer_status']])->value('title');
  164. }
  165. else{
  166. $detail['customer_status_name']='-';
  167. }
  168. if($detail['intent_status']>0){
  169. $detail['intent_status_name'] = Db::name('BasicCustomer')->where(['id' => $detail['intent_status']])->value('title');
  170. }
  171. else{
  172. $detail['intent_status_name']='-';
  173. }
  174. $detail['industry'] = Db::name('Industry')->where(['id' => $detail['industry_id']])->value('title');
  175. $detail['source'] = Db::name('CustomerSource')->where(['id' => $detail['source_id']])->value('title');
  176. $detail['grade'] = Db::name('CustomerGrade')->where(['id' => $detail['grade_id']])->value('title');
  177. //附件
  178. $file_array = Db::name('CustomerFile')
  179. ->field('cf.id,f.filepath,f.name,f.filesize,f.fileext,f.create_time,f.admin_id')
  180. ->alias('cf')
  181. ->join('File f', 'f.id = cf.file_id', 'LEFT')
  182. ->order('cf.create_time asc')
  183. ->where(array('cf.customer_id' => $id, 'cf.delete_time' => 0))
  184. ->select()->toArray();
  185. $detail['file_array'] = $file_array;
  186. $role=0;
  187. if($detail['belong_uid'] == $this->uid && $detail['is_lock'] == 0){
  188. $role=1;
  189. }
  190. View::assign('detail', $detail);
  191. View::assign('role', $role);
  192. if(is_mobile()){
  193. return view('qiye@/customer/view');
  194. }
  195. return view();
  196. }
  197. /**
  198. * 删除
  199. */
  200. public function del()
  201. {
  202. $param = get_params();
  203. if (request()->isDelete()) {
  204. $id = get_params("id");
  205. $idArray = explode(',', strval($id));
  206. $list = [];
  207. foreach ($idArray as $key => $val) {
  208. $list[] = [
  209. 'id' => $val,
  210. 'discard_time' => time()
  211. ];
  212. }
  213. foreach ($list as $key => $v) {
  214. if (Db::name('Customer')->update($v) !== false) {
  215. add_log('delete', $param['id']);
  216. }
  217. }
  218. return to_assign(0, '操作成功');
  219. } else {
  220. return to_assign(1, "错误的请求");
  221. }
  222. }
  223. }