Chance.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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\CustomerChance as CustomerChanceModel;
  17. use think\facade\Db;
  18. use think\facade\View;
  19. class Chance extends BaseController
  20. {
  21. /**
  22. * 构造函数
  23. */
  24. protected $model;
  25. public function __construct()
  26. {
  27. parent::__construct(); // 调用父类构造函数
  28. $this->model = new CustomerChanceModel();
  29. }
  30. /**
  31. * 数据列表
  32. */
  33. public function datalist()
  34. {
  35. $param = get_params();
  36. $uid=$this->uid;
  37. if (request()->isAjax()) {
  38. $where=[];
  39. $whereOr=[];
  40. $where[]=['a.delete_time','=',0];
  41. if (!empty($param['keywords'])) {
  42. $where[] = ['a.title|a.content|c.name', 'like', '%' . $param['keywords'] . '%'];
  43. }
  44. if (!empty($param['stage'])) {
  45. $where[] = ['a.stage','=',$param['stage']];
  46. }
  47. if (!empty($param['uid'])) {
  48. $where[] = ['a.belong_uid','=',$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['discovery_time'])){
  88. $param['discovery_time'] = strtotime($param['discovery_time']);
  89. }
  90. if(isset($param['expected_time'])){
  91. $param['expected_time'] = strtotime($param['expected_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. $detail = $this->model->getById($id);
  105. View::assign('detail', $detail);
  106. return view('edit');
  107. }
  108. $customer_id = isset($param['cid']) ? $param['cid'] : 0;
  109. $customer_name = Db::name('Customer')->where('id',$customer_id)->value('name');
  110. View::assign('customer_id', $customer_id);
  111. View::assign('customer_name', $customer_name);
  112. if(is_mobile()){
  113. return view('qiye@/customer/chance_add');
  114. }
  115. return view();
  116. }
  117. }
  118. /**
  119. * 查看
  120. */
  121. public function view($id)
  122. {
  123. $detail = $this->model->getById($id);
  124. if (!empty($detail)) {
  125. $detail['contact'] = Db::name('CustomerContact')->where('id',$detail['contact_id'])->value('name');
  126. $detail['stage_name'] =Db::name('BasicCustomer')->where('id',$detail['stage'])->value('title');
  127. View::assign('detail', $detail);
  128. if(is_mobile()){
  129. return view('qiye@/customer/chance_view');
  130. }
  131. return view();
  132. }
  133. else{
  134. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  135. }
  136. }
  137. /**
  138. * 删除
  139. */
  140. public function del()
  141. {
  142. $param = get_params();
  143. $id = isset($param['id']) ? $param['id'] : 0;
  144. if (request()->isDelete()) {
  145. $this->model->delById($id);
  146. } else {
  147. return to_assign(1, "错误的请求");
  148. }
  149. }
  150. }