Trace.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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\CustomerTrace as CustomerTraceModel;
  17. use think\facade\Db;
  18. use think\facade\View;
  19. class Trace extends BaseController
  20. {
  21. /**
  22. * 构造函数
  23. */
  24. protected $model;
  25. public function __construct()
  26. {
  27. parent::__construct(); // 调用父类构造函数
  28. $this->model = new CustomerTraceModel();
  29. }
  30. /**
  31. * 数据列表
  32. */
  33. public function datalist()
  34. {
  35. $param = get_params();
  36. $uid=$this->uid;
  37. if (request()->isAjax()) {
  38. $where=[];
  39. $where[]=['a.delete_time','=',0];
  40. if (!empty($param['keywords'])) {
  41. $where[] = ['a.content|c.name|cc.title', 'like', '%' . $param['keywords'] . '%'];
  42. }
  43. if (!empty($param['follow_time'])) {
  44. $follow_time =explode('~', $param['follow_time']);
  45. $where[] = ['a.follow_time', 'between',[strtotime(urldecode($follow_time[0])),strtotime(urldecode($follow_time[1].' 23:59:59'))]];
  46. }
  47. if (!empty($param['uid'])) {
  48. $where[] = ['a.admin_id','=',$param['uid']];
  49. }
  50. $map=[];
  51. $mapOr=[];
  52. $map[]=['delete_time','=',0];
  53. $map[]=['discard_time','=',0];
  54. $mapOr[] = ['belong_uid','=',$uid];
  55. $mapOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
  56. $dids_a = get_leader_departments($uid);
  57. //是否是客户管理员
  58. $auth = isAuth($uid,'customer_admin','conf_1');
  59. if($auth == 0){
  60. if(!empty($dids_a)){
  61. $mapOr[] = ['belong_did','in',$dids_a];
  62. }
  63. $cids = Db::name('Customer')
  64. ->where($map)
  65. ->where(function ($query) use($mapOr) {
  66. if (!empty($mapOr)){
  67. $query->whereOr($mapOr);
  68. }
  69. })->column('id');
  70. $where[] = ['a.cid', 'in',$cids];
  71. }
  72. $list = $this->model->datalist($param,$where);
  73. return table_assign(0, '', $list);
  74. }
  75. else{
  76. View::assign('is_auth', isAuth($uid,'customer_admin','conf_1'));
  77. return view();
  78. }
  79. }
  80. /**
  81. * 添加/编辑
  82. */
  83. public function add()
  84. {
  85. $param = get_params();
  86. if (request()->isAjax()) {
  87. if(isset($param['follow_time'])){
  88. $param['follow_time'] = strtotime($param['follow_time']);
  89. }
  90. if(isset($param['next_time'])){
  91. $param['next_time'] = strtotime($param['next_time']);
  92. }
  93. $param['update_time'] = time();
  94. if (!empty($param['id']) && $param['id'] > 0) {
  95. $this->model->edit($param);
  96. } else {
  97. $param['create_time'] = time();
  98. $param['admin_id'] = $this->uid;
  99. $this->model->add($param);
  100. }
  101. }else{
  102. $id = isset($param['id']) ? $param['id'] : 0;
  103. if ($id > 0) {
  104. View::assign('detail', $this->model->getById($id));
  105. return view('edit');
  106. }
  107. $customer_id = isset($param['cid']) ? $param['cid'] : 0;
  108. $customer_name = Db::name('Customer')->where('id',$customer_id)->value('name');
  109. View::assign('customer_id', $customer_id);
  110. View::assign('customer_name', $customer_name);
  111. if(is_mobile()){
  112. return view('qiye@/customer/trace_add');
  113. }
  114. return view();
  115. }
  116. }
  117. /**
  118. * 查看
  119. */
  120. public function view($id)
  121. {
  122. $detail = $this->model->getById($id);
  123. if (!empty($detail)) {
  124. $detail['contact'] = Db::name('CustomerContact')->where('id',$detail['contact_id'])->value('name');
  125. $detail['types_name'] = Db::name('BasicCustomer')->where('id',$detail['types'])->value('title');
  126. $detail['stage_name'] = Db::name('BasicCustomer')->where('id',$detail['stage'])->value('title');
  127. if($detail['chance_id']>0){
  128. $detail['chance'] = Db::name('CustomerChance')->where(['id' => $detail['chance_id']])->value('title');
  129. }
  130. else{
  131. $detail['chance']='-';
  132. }
  133. View::assign('detail', $detail);
  134. if(is_mobile()){
  135. return view('qiye@/customer/trace_view');
  136. }
  137. return view();
  138. }
  139. else{
  140. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  141. }
  142. }
  143. /**
  144. * 删除
  145. */
  146. public function del()
  147. {
  148. $param = get_params();
  149. $id = isset($param['id']) ? $param['id'] : 0;
  150. if (request()->isDelete()) {
  151. $this->model->delById($id);
  152. } else {
  153. return to_assign(1, "错误的请求");
  154. }
  155. }
  156. }