Contact.php 4.7 KB

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