Manange.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\NoteLog;
  4. use app\BaseController;
  5. use think\App;
  6. use think\facade\Config;
  7. use think\facade\Db;
  8. class Manange extends BaseController
  9. {
  10. public $post = "";
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. $this->post = $this->request->post();
  15. }
  16. public function create()
  17. {
  18. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  19. $id = isset($this->post['id']) && $this->post['id'] !== "" ? $this->post['id'] : "";
  20. if ($id == "") {
  21. return error_show(1002, "参数id不能为空");
  22. }
  23. $company_id = isset($this->post['company_id']) && $this->post['company_id'] !== "" ? $this->post['company_id'] : "";
  24. if ($company_id == "") {
  25. return error_show(1002, "参数company_id不能为空");
  26. }
  27. $var = Db::name('manange')->where(['company_id' => $company_id,'is_del' => 0])->column("manange_id");
  28. //var_dump( Db::name('manange')->getLastSql());
  29. $str = array_diff($id, $var);
  30. $datain=[];
  31. if (!empty($str)) {
  32. foreach ($str as $value){
  33. $to = GetInfoById($token, ['id' => $value]);
  34. if ((!empty($to) && $to['code'] != 0) || empty($to)) {
  35. return error_show($to['code'], $to['message']);
  36. }
  37. $datai = [];
  38. $info = $to['data'];
  39. $datai['manange_name'] = $info['nickname'];
  40. $datai['manange_id'] = $info['id'];
  41. $datai['phone'] = $info['mobile'];
  42. $datai['company_id'] = $company_id;
  43. $datai['is_del'] = 0;
  44. $datai['addtime'] = date("Y-m-d H:i:s");
  45. $datai['updatetime'] = date("Y-m-d H:i:s");
  46. $datain[]=$datai;
  47. }
  48. }
  49. $st = array_diff($var,$id);
  50. $itep = Db::name('deal')->where(['deal_id'=>$st,'is_del'=>0])->select();
  51. if(!empty($itep)){
  52. $uin = array_unique(array_column($itep->toArray(),'deal_id'));
  53. $infe=Db::name('manange')->where(['manange_id'=>$uin,"is_del"=>0,'company_id'=>$company_id])->column('manange_id,manange_name');
  54. if(!empty($infe)){
  55. return app_show(10002,"处理人已绑定任务无法删除",$infe);
  56. }
  57. }
  58. Db::startTrans();
  59. try{
  60. if(!empty($st)){
  61. $it['is_del']=1;
  62. $it['updatetime'] = date("Y-m-d H:i:s");
  63. $inf=Db::name('manange')->where(['manange_id'=>$st,"is_del"=>0,'company_id'=>$company_id])->save($it);
  64. //var_dump(Db::name('manange')->getLastSql());
  65. if(!$inf){
  66. Db::rollback();
  67. return error_show(1003, "更新失败");
  68. }
  69. }
  70. if(!empty($datai)){
  71. $datainfo = Db::name('manange')->insertAll($datain);
  72. //var_dump(Db::name('manange')->getLastSql());
  73. if (!$datainfo) {
  74. Db::rollback();
  75. return error_show(1002, "新建失败");
  76. }
  77. }
  78. Db::commit();
  79. return error_show(0, "新建成功");
  80. }catch (\Exception $e){
  81. Db::rollback();
  82. return error_show(1004,$e->getMessage());
  83. }
  84. }
  85. public function del(){
  86. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  87. if($id==""){
  88. return error_show(1002,"参数不能为空");
  89. }
  90. $info=Db::name('manange')->where(['id'=>$id,'is_del'=>0])->find();
  91. if(empty($info)){
  92. return error_show(1002,"未找到数据");
  93. }
  94. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"0";
  95. if ($status==""){
  96. return error_show(1002,"参数status不能为空");
  97. }
  98. $str['is_del']=1;
  99. $str['status']=$status;
  100. $str['updatetime']=date("Y-m-d H:i:s");
  101. $info=Db::name('manange')->where($info)->save($str);
  102. return $info ? app_show(0,"删除成功") :error_show(1002,"删除失败");
  103. }
  104. public function list(){
  105. $where =[['is_del','=',0]];
  106. $manange_name = isset($this->post['manange_name']) && $this->post['manange_name'] !== "" ? trim($this->post['manange_name']) : "";
  107. if ($manange_name !== "") {
  108. $where[]= ['manange_name',"like","%$manange_name%"];
  109. }
  110. $manange_id = isset($this->post['manange_id']) && $this->post['manange_id'] !== "" ? trim($this->post['manange_id']) : "";
  111. if ($manange_id !== "") {
  112. $where[]= ['manange_id',"like","%$manange_id%"];
  113. }
  114. $company_id = isset($this->post['company_id']) && $this->post['company_id'] !== "" ? $this->post['company_id'] : "";
  115. if ($company_id !== "") {
  116. $where[]= ['company_id',"=",$company_id];
  117. }
  118. $phone= isset($this->post['phone']) && $this->post['phone'] !== "" ? intval($this->post['phone']) : "";
  119. if ($phone !== "") {
  120. $where[]= ['phone',"like","%$phone%"];
  121. }
  122. $status= isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  123. if ($status !== "") {
  124. $where[]= ['status',"=",$status];
  125. }
  126. $list=Db::name('manange')->where($where)->order("addtime desc")->select();
  127. return app_show(0,"获取成功",$list);
  128. }
  129. public function loglist(){
  130. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  131. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  132. $where=[];
  133. $bugNo= isset($this->post['bugNo']) && $this->post['bugNo']!="" ? trim($this->post['bugNo']):"";
  134. if($bugNo!=""){
  135. $where[]=['bugNo',"like","%$bugNo%"];
  136. }
  137. $conf=Config::get('note');
  138. $count = Db::name('note_log')->where($where)->count();
  139. $total = ceil($count/$size);
  140. $page = $total>=$page ? $page :$total;
  141. $list = Db::name('note_log')->where($where)->page($page,$size)->order("addtime desc")
  142. ->select();
  143. $data=[];
  144. foreach ($list as $value){
  145. $value['type_cn'] = $value['type']==2?'编辑':'新建';
  146. if(array_key_exists($value['handle_name'],$conf['field_value'])){
  147. $field_value=$conf['field_value'][$value['handle_name']];
  148. $value['action_item'] = isset($field_value[$value['action_item']]) ?$field_value[$value['action_item']]:$value['action_item'];
  149. $value['action_after'] = isset($field_value[$value['action_after']]) ?$field_value[$value['action_after']]:$value['action_after'];
  150. }else{
  151. if($value['handle_name']=='model_id'){
  152. $model1 = made($value['action_item']);
  153. $model2 = made($value['action_after']);
  154. $value['action_item'] = empty($model1)?'': implode("/",array_column($model1,'rename'));
  155. $value['action_after'] = empty($model2)?'': implode("/",array_column($model2,'rename'));
  156. }
  157. }
  158. $value['handle_name'] = $conf['field'][$value['handle_name']];
  159. $data[]=$value;
  160. }
  161. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  162. }
  163. }