Api.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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\api\BaseController;
  16. use app\customer\model\Customer;
  17. use app\customer\model\CustomerTrace;
  18. use app\customer\model\CustomerContact;
  19. use app\customer\model\CustomerChance;
  20. use think\facade\Db;
  21. use think\facade\View;
  22. class Api extends BaseController
  23. {
  24. //获取客户列表
  25. public function get_customer()
  26. {
  27. $param = get_params();
  28. $uid = $this->uid;
  29. $where = array();
  30. $whereOr = array();
  31. if (!empty($param['keywords'])) {
  32. $where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
  33. }
  34. $where[]=['delete_time','=',0];
  35. $where[]=['discard_time','=',0];
  36. if (!empty($param['uid'])) {
  37. $where[] = ['belong_uid', '=', $param['uid']];
  38. }
  39. else{
  40. //是否是客户管理员
  41. $auth = isAuth($uid,'customer_admin','conf_1');
  42. if($auth == 0){
  43. $whereOr[] = ['belong_uid','=',$uid];
  44. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
  45. $dids_a = get_leader_departments($uid);
  46. $dids_b = get_role_departments($uid);
  47. $dids = array_merge($dids_a, $dids_b);
  48. if(!empty($dids)){
  49. $whereOr[] = ['belong_did','in',$dids];
  50. }
  51. }
  52. }
  53. $model = new Customer();
  54. $list = $model->datalist($param,$where,$whereOr);
  55. table_assign(0, '', $list);
  56. }
  57. //分配客户
  58. public function distribute()
  59. {
  60. if (request()->isAjax()) {
  61. $params = get_params();
  62. //是否是客户管理员
  63. $auth = isAuth($this->uid,'customer_admin','conf_1');
  64. if($auth==0){
  65. return to_assign(1, "只有客户管理员才有权限操作");
  66. }
  67. $data['id'] = $params['id'];
  68. $data['belong_uid'] = $params['uid'];
  69. $data['belong_did'] = $params['did'];
  70. $data['distribute_time'] = time();
  71. if (Db::name('Customer')->update($data) !== false) {
  72. add_log('allot', $data['id'],[],'客户');
  73. return to_assign(0, "操作成功");
  74. } else {
  75. return to_assign(1, "操作失败");
  76. }
  77. } else {
  78. return to_assign(1, "错误的请求");
  79. }
  80. }
  81. //锁住、解锁客户
  82. public function customer_lock()
  83. {
  84. if (request()->isAjax()) {
  85. $params = get_params();
  86. //是否是客户管理员
  87. $auth = isAuth($this->uid,'customer_admin','conf_1');
  88. if($auth==0){
  89. return to_assign(1, "只有客户管理员才有权限操作");
  90. }
  91. $data['id'] = $params['id'];
  92. $data['is_lock'] = $params['is_lock'];
  93. if (Db::name('Customer')->update($data) !== false) {
  94. if($data['is_lock']==1){
  95. add_log('lock', $data['id'],[],'客户');
  96. }
  97. else{
  98. add_log('unlock', $data['id'],[],'客户');
  99. }
  100. return to_assign(0, "操作成功");
  101. } else {
  102. return to_assign(1, "操作失败");
  103. }
  104. } else {
  105. return to_assign(1, "错误的请求");
  106. }
  107. }
  108. //彻底删除客户
  109. public function delete()
  110. {
  111. if (request()->isDelete()) {
  112. $params = get_params();
  113. //是否是客户管理员
  114. $auth = isAuth($this->uid,'customer_admin','conf_1');
  115. if($auth==0){
  116. return to_assign(1, "只有客户管理员才有权限操作");
  117. }
  118. $data['id'] = $params['id'];
  119. $data['delete_time'] = -1;
  120. if (Db::name('Customer')->update($data) !== false) {
  121. //删除客户联系人
  122. Db::name('CustomerContact')->where(['cid' => $params['id']])->update(['delete_time'=>time()]);
  123. //删除客户机会
  124. Db::name('CustomerChance')->where(['cid' => $params['id']])->update(['delete_time'=>time()]);
  125. add_log('delete', $params['id']);
  126. return to_assign();
  127. } else {
  128. return to_assign(1, "操作失败");
  129. }
  130. } else {
  131. return to_assign(1, "错误的请求");
  132. }
  133. }
  134. //跟进记录列表
  135. public function get_trace()
  136. {
  137. $param = get_params();
  138. $where = array();
  139. $where[] = ['a.delete_time', '=', 0];
  140. $where[] = ['a.cid', '=', $param['cid']];
  141. $model = new CustomerTrace();
  142. $list = $model->datalist($param,$where);
  143. return table_assign(0, '', $list);
  144. }
  145. //销售机会列表
  146. public function get_chance()
  147. {
  148. $param = get_params();
  149. $where = array();
  150. $where[] = ['a.delete_time', '=', 0];
  151. $where[] = ['a.cid', '=', $param['cid']];
  152. if (!empty($param['keywords'])) {
  153. $where[] = ['a.title|a.content', 'like', '%' . $param['keywords'] . '%'];
  154. }
  155. $model = new CustomerChance();
  156. $list = $model->datalist($param,$where);
  157. return table_assign(0, '', $list);
  158. }
  159. //获取联系人数据
  160. public function get_contact()
  161. {
  162. $param = get_params();
  163. $where = array();
  164. $where[] = ['delete_time', '=', 0];
  165. $where[] = ['cid', '=', $param['cid']];
  166. $model = new CustomerContact();
  167. $list = $model->datalist($param,$where);
  168. return table_assign(0, '', $list);
  169. }
  170. //设置联系人
  171. public function set_contact()
  172. {
  173. if (request()->isAjax()) {
  174. $param = get_params();
  175. $detail= Db::name('CustomerContact')->where(['id' => $param['id']])->find();
  176. CustomerContact::where(['cid' => $detail['cid']])->update(['is_default'=>0]);
  177. $res = CustomerContact::where(['id' => $param['id']])->update(['is_default'=>1]);
  178. if ($res) {
  179. add_log('edit', $param['id'], $param,'客户联系人');
  180. return to_assign();
  181. } else {
  182. return to_assign(1, '操作失败');
  183. }
  184. } else {
  185. return to_assign(1, '参数错误');
  186. }
  187. }
  188. //添加附件
  189. public function add_file()
  190. {
  191. $param = get_params();
  192. $param['create_time'] = time();
  193. $param['admin_id'] = $this->uid;
  194. $fid = Db::name('CustomerFile')->strict(false)->field(true)->insertGetId($param);
  195. if ($fid) {
  196. return to_assign(0, '上传成功', $fid);
  197. }
  198. }
  199. //删除附件
  200. public function delete_file()
  201. {
  202. if (request()->isDelete()) {
  203. $id = get_params("id");
  204. $data['id'] = $id;
  205. $data['delete_time'] = time();
  206. if (Db::name('CustomerFile')->update($data) !== false) {
  207. $detail = Db::name('CustomerFile')->where('id', $id)->find();
  208. $file_name = Db::name('File')->where('id', $detail['file_id'])->value('name');
  209. return to_assign(0, "删除成功");
  210. } else {
  211. return to_assign(1, "删除失败");
  212. }
  213. } else {
  214. return to_assign(1, "错误的请求");
  215. }
  216. }
  217. //获取客户等级
  218. public function get_customer_grade()
  219. {
  220. $list = get_base_data('customer_grade');
  221. return to_assign(0, '', $list);
  222. }
  223. //获取客户状态
  224. public function get_customer_status()
  225. {
  226. $list = get_base_type_data('basic_customer',1);
  227. return to_assign(0, '', $list);
  228. }
  229. //获取客户意向
  230. public function get_intent_status()
  231. {
  232. $list = get_base_type_data('basic_customer',2);
  233. return to_assign(0, '', $list);
  234. }
  235. }