123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\NoteLog;
- use app\BaseController;
- use think\App;
- use think\facade\Config;
- use think\facade\Db;
- class Manange extends BaseController
- {
- public $post = "";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post = $this->request->post();
- }
- public function create()
- {
- $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? $this->post['id'] : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- $company_id = isset($this->post['company_id']) && $this->post['company_id'] !== "" ? $this->post['company_id'] : "";
- if ($company_id == "") {
- return error_show(1002, "参数company_id不能为空");
- }
- $var = Db::name('manange')->where(['company_id' => $company_id,'is_del' => 0])->column("manange_id");
- //var_dump( Db::name('manange')->getLastSql());
- $str = array_diff($id, $var);
- $datain=[];
- if (!empty($str)) {
- foreach ($str as $value){
- $to = GetInfoById($token, ['id' => $value]);
- if ((!empty($to) && $to['code'] != 0) || empty($to)) {
- return error_show($to['code'], $to['message']);
- }
- $datai = [];
- $info = $to['data'];
- $datai['manange_name'] = $info['nickname'];
- $datai['manange_id'] = $info['id'];
- $datai['phone'] = $info['mobile'];
- $datai['company_id'] = $company_id;
- $datai['is_del'] = 0;
- $datai['addtime'] = date("Y-m-d H:i:s");
- $datai['updatetime'] = date("Y-m-d H:i:s");
- $datain[]=$datai;
- }
- }
- $st = array_diff($var,$id);
- $itep = Db::name('deal')->where(['deal_id'=>$st,'is_del'=>0])->select();
- if(!empty($itep)){
- $uin = array_unique(array_column($itep->toArray(),'deal_id'));
- $infe=Db::name('manange')->where(['manange_id'=>$uin,"is_del"=>0,'company_id'=>$company_id])->column('manange_id,manange_name');
- if(!empty($infe)){
- return app_show(10002,"处理人已绑定任务无法删除",$infe);
- }
- }
- Db::startTrans();
- try{
- if(!empty($st)){
- $it['is_del']=1;
- $it['updatetime'] = date("Y-m-d H:i:s");
- $inf=Db::name('manange')->where(['manange_id'=>$st,"is_del"=>0,'company_id'=>$company_id])->save($it);
- //var_dump(Db::name('manange')->getLastSql());
- if(!$inf){
- Db::rollback();
- return error_show(1003, "更新失败");
- }
- }
- if(!empty($datai)){
- $datainfo = Db::name('manange')->insertAll($datain);
- //var_dump(Db::name('manange')->getLastSql());
- if (!$datainfo) {
- Db::rollback();
- return error_show(1002, "新建失败");
- }
- }
- Db::commit();
- return error_show(0, "新建成功");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function del(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数不能为空");
- }
- $info=Db::name('manange')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($info)){
- return error_show(1002,"未找到数据");
- }
- $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"0";
- if ($status==""){
- return error_show(1002,"参数status不能为空");
- }
- $str['is_del']=1;
- $str['status']=$status;
- $str['updatetime']=date("Y-m-d H:i:s");
- $info=Db::name('manange')->where($info)->save($str);
- return $info ? app_show(0,"删除成功") :error_show(1002,"删除失败");
- }
- public function list(){
- $where =[['is_del','=',0]];
- $manange_name = isset($this->post['manange_name']) && $this->post['manange_name'] !== "" ? trim($this->post['manange_name']) : "";
- if ($manange_name !== "") {
- $where[]= ['manange_name',"like","%$manange_name%"];
- }
- $manange_id = isset($this->post['manange_id']) && $this->post['manange_id'] !== "" ? trim($this->post['manange_id']) : "";
- if ($manange_id !== "") {
- $where[]= ['manange_id',"like","%$manange_id%"];
- }
- $company_id = isset($this->post['company_id']) && $this->post['company_id'] !== "" ? $this->post['company_id'] : "";
- if ($company_id !== "") {
- $where[]= ['company_id',"=",$company_id];
- }
- $phone= isset($this->post['phone']) && $this->post['phone'] !== "" ? intval($this->post['phone']) : "";
- if ($phone !== "") {
- $where[]= ['phone',"like","%$phone%"];
- }
- $status= isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status !== "") {
- $where[]= ['status',"=",$status];
- }
- $list=Db::name('manange')->where($where)->order("addtime desc")->select();
- return app_show(0,"获取成功",$list);
- }
- public function loglist(){
- $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
- $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
- $where=[];
- $bugNo= isset($this->post['bugNo']) && $this->post['bugNo']!="" ? trim($this->post['bugNo']):"";
- if($bugNo!=""){
- $where[]=['bugNo',"like","%$bugNo%"];
- }
- $conf=Config::get('note');
- $count = Db::name('note_log')->where($where)->count();
- $total = ceil($count/$size);
- $page = $total>=$page ? $page :$total;
- $list = Db::name('note_log')->where($where)->page($page,$size)->order("addtime desc")
- ->select();
- $data=[];
- foreach ($list as $value){
- $value['type_cn'] = $value['type']==2?'编辑':'新建';
- if(array_key_exists($value['handle_name'],$conf['field_value'])){
- $field_value=$conf['field_value'][$value['handle_name']];
- $value['action_item'] = isset($field_value[$value['action_item']]) ?$field_value[$value['action_item']]:$value['action_item'];
- $value['action_after'] = isset($field_value[$value['action_after']]) ?$field_value[$value['action_after']]:$value['action_after'];
- }else{
- if($value['handle_name']=='model_id'){
- $model1 = made($value['action_item']);
- $model2 = made($value['action_after']);
- $value['action_item'] = empty($model1)?'': implode("/",array_column($model1,'rename'));
- $value['action_after'] = empty($model2)?'': implode("/",array_column($model2,'rename'));
- }
- }
- $value['handle_name'] = $conf['field'][$value['handle_name']];
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- }
|