|
@@ -14,333 +14,392 @@ class Customer extends Base
|
|
|
{
|
|
|
parent::__construct($app);
|
|
|
}
|
|
|
- /*列表*/
|
|
|
- public function list(){
|
|
|
- $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";
|
|
|
- $pid = isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
|
|
|
- $where =[];
|
|
|
- $where []= ['ci.is_del',"=",0];
|
|
|
- $condition = [['co.is_del',"=",0]];
|
|
|
- if($pid!==""){
|
|
|
- $condition[]=["co.pid","=",$pid];
|
|
|
- }
|
|
|
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
|
|
|
- if($companyNo !==""){
|
|
|
- $where[] = ['ci.companyNo',"like","%$companyNo%"];
|
|
|
- }
|
|
|
- $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
|
|
|
- if($creater !==""){
|
|
|
- $where[] = ['ci.creater',"like","%$creater%"];
|
|
|
- }
|
|
|
- $name= isset($this->post['name'])&&$this->post['name']!=="" ? trim($this->post['name']):"";
|
|
|
- if($name!=""){
|
|
|
- $condition[]=["co.name","like","%{$this->post['name']}%"];
|
|
|
- }
|
|
|
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
|
|
|
- if ($start != "") {
|
|
|
- $where[] = ["ci.addtime", '>=', $start];
|
|
|
- }
|
|
|
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
|
|
|
- if ($end != "") {
|
|
|
- $where[] = ["ci.addtime", '<=', $end];
|
|
|
- }
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
|
|
|
- if($status!==""){
|
|
|
- $where[] = ['ci.status',"=",$status];
|
|
|
- }
|
|
|
-// $count = Db::name('customer_org1')->where($condition)->count();
|
|
|
-// $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
|
|
|
- $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
|
|
|
- if($creater !==""){
|
|
|
- $condition[] = ['co.creater',"like","%$creater%"];
|
|
|
- }
|
|
|
- $name= isset($this->post['name'])&&$this->post['name']!=="" ? trim($this->post['name']):"";
|
|
|
- if($name!=""){
|
|
|
- $condition[]=["co.name","like","%{$this->post['name']}%"];
|
|
|
- }
|
|
|
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
|
|
|
- if ($start != "") {
|
|
|
- $condition[] = ["co.addtime", '>=', $start];
|
|
|
- }
|
|
|
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
|
|
|
- if ($end != "") {
|
|
|
- $condition[] = ["co.addtime", '<=', $end];
|
|
|
- }
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
|
|
|
- if($status!==""){
|
|
|
- $condition[] = ['co.status',"=",$status];
|
|
|
- }
|
|
|
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
|
|
|
- if ($company_name !== "") {
|
|
|
- $company_ids = get_company_item_user_by_name($company_name);
|
|
|
- $where[] = ["u.uid", 'in', $company_ids];
|
|
|
- $condition[] = ['u.uid',"in",$company_ids];
|
|
|
- }
|
|
|
|
|
|
- $pidlist = Db::name("customer_org1")
|
|
|
- ->alias('co')
|
|
|
- ->leftJoin("depart_user u", "u.uid=co.createrid AND u.is_del=0")
|
|
|
- ->where($condition)
|
|
|
- ->order("co.addtime desc")->column("co.pid");
|
|
|
- if(!empty($pidlist)){
|
|
|
- $where[]=[["ci.itemid","in",$pidlist]];
|
|
|
-
|
|
|
- }else{
|
|
|
- if($pid===""){
|
|
|
- $where[]=['ci.itemid','=',0];
|
|
|
- }else{
|
|
|
- $where[]=['ci.itemid','=',$pid];
|
|
|
- }
|
|
|
- }
|
|
|
- $list = Db::name('customer_org1')
|
|
|
- ->alias('co')
|
|
|
- ->where($condition)
|
|
|
- ->order("co.addtime",'desc')
|
|
|
- ->column("co.id,co.pid,co.name,co.level,co.depart_link,co.creater,co.createrid,co.addtime,co.status");
|
|
|
-
|
|
|
- $all_createrid = array_column($list,'createrid');
|
|
|
- $all_item = get_company_name_by_uid($all_createrid);
|
|
|
-
|
|
|
- $var=[];
|
|
|
- foreach ($list as $item) {
|
|
|
- $iten=[];
|
|
|
- $iten['name']=$item['name'];
|
|
|
-// $iten['code']="";
|
|
|
- $iten['id']=$item['id'];
|
|
|
- $iten['creater']=$item['creater'];
|
|
|
- $iten['status']=$item['status'];
|
|
|
- $iten['addtime']=$item['addtime'];
|
|
|
- $iten['kh']=0;//组织架构
|
|
|
- $iten['company_name'] = $all_item[$item['createrid']]??'';
|
|
|
+ /*列表*/
|
|
|
+ public function list()
|
|
|
+ {
|
|
|
|
|
|
- $var[]=$iten;
|
|
|
- }
|
|
|
- $itm = Db::connect('mysql_sys')
|
|
|
- ->name('customer_info')
|
|
|
- ->alias('ci')
|
|
|
-// ->leftJoin("depart_user u", "u.nickname=ci.creater AND u.is_del=0")
|
|
|
- ->where($where)
|
|
|
- ->order("ci.addtime desc")
|
|
|
- ->select()
|
|
|
- ->toArray();
|
|
|
+ $param = $this->request->filter('trim')->post();
|
|
|
|
|
|
- //同理,这个表里只存了创建人名称,没有id
|
|
|
+ $userCommon = new \app\admin\common\User();
|
|
|
+ $rs = $userCommon->handle('customer_org_list', $param);
|
|
|
|
|
|
- foreach ($itm as $vat){
|
|
|
- $inm=[];
|
|
|
- $inm['name']=$vat['companyName'];
|
|
|
- $inm['id']=$vat['id'];
|
|
|
- $inm['code']=$vat['companyNo'];
|
|
|
-// $inm['companyName']=$vat['companyName'];
|
|
|
-// $inm['invoice_bank']=$vat['invoice_bank'];
|
|
|
-// $inm['invoice_bankNo']=$vat['invoice_bankNo'];
|
|
|
-// $inm['invoice_code']=$vat['invoice_code'];
|
|
|
-// $inm['invoice_people']=$vat['invoice_people'];
|
|
|
-// $inm['invoice_mobile']=$vat['invoice_mobile'];
|
|
|
-// $inm['invoice_addr']=$vat['invoice_addr'];
|
|
|
-// $inm['parent']=$vat['parent'];
|
|
|
-// $inm['branch']=$vat['branch'];
|
|
|
-// $inm['middle']=$vat['middle'];
|
|
|
-// $inm['country']=$vat['country'];
|
|
|
- $inm['status']=$vat['status'];
|
|
|
- $inm['creater']=$vat['creater'];
|
|
|
- $inm['addtime']=$vat['addtime'];
|
|
|
- $inm['kh']=1;//客户
|
|
|
- $inm['company_name'] = '待处理';
|
|
|
- $var[]=$inm;
|
|
|
- }
|
|
|
- return app_show(0,"获取成功",$var);
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
+// $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";
|
|
|
+// $pid = isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
|
|
|
+// $where =[];
|
|
|
+// $where []= ['ci.is_del',"=",0];
|
|
|
+// $condition = [['co.is_del',"=",0]];
|
|
|
+// if($pid!==""){
|
|
|
+// $condition[]=["co.pid","=",$pid];
|
|
|
+// }
|
|
|
+// $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
|
|
|
+// if($companyNo !==""){
|
|
|
+// $where[] = ['ci.companyNo',"like","%$companyNo%"];
|
|
|
+// }
|
|
|
+// $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
|
|
|
+// if($creater !==""){
|
|
|
+// $where[] = ['ci.creater',"like","%$creater%"];
|
|
|
+// }
|
|
|
+// $name= isset($this->post['name'])&&$this->post['name']!=="" ? trim($this->post['name']):"";
|
|
|
+// if($name!=""){
|
|
|
+// $condition[]=["co.name","like","%{$this->post['name']}%"];
|
|
|
+// }
|
|
|
+// $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
|
|
|
+// if ($start != "") {
|
|
|
+// $where[] = ["ci.addtime", '>=', $start];
|
|
|
+// }
|
|
|
+// $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
|
|
|
+// if ($end != "") {
|
|
|
+// $where[] = ["ci.addtime", '<=', $end];
|
|
|
+// }
|
|
|
+// $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
|
|
|
+// if($status!==""){
|
|
|
+// $where[] = ['ci.status',"=",$status];
|
|
|
+// }
|
|
|
+//// $count = Db::name('customer_org1')->where($condition)->count();
|
|
|
+//// $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
|
|
|
+// $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
|
|
|
+// if($creater !==""){
|
|
|
+// $condition[] = ['co.creater',"like","%$creater%"];
|
|
|
+// }
|
|
|
+// $name= isset($this->post['name'])&&$this->post['name']!=="" ? trim($this->post['name']):"";
|
|
|
+// if($name!=""){
|
|
|
+// $condition[]=["co.name","like","%{$this->post['name']}%"];
|
|
|
+// }
|
|
|
+// $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
|
|
|
+// if ($start != "") {
|
|
|
+// $condition[] = ["co.addtime", '>=', $start];
|
|
|
+// }
|
|
|
+// $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
|
|
|
+// if ($end != "") {
|
|
|
+// $condition[] = ["co.addtime", '<=', $end];
|
|
|
+// }
|
|
|
+// $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
|
|
|
+// if($status!==""){
|
|
|
+// $condition[] = ['co.status',"=",$status];
|
|
|
+// }
|
|
|
+// $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
|
|
|
+// if ($company_name !== "") {
|
|
|
+// $company_ids = get_company_item_user_by_name($company_name);
|
|
|
+// $where[] = ["u.uid", 'in', $company_ids];
|
|
|
+// $condition[] = ['u.uid',"in",$company_ids];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $pidlist = Db::name("customer_org1")
|
|
|
+// ->alias('co')
|
|
|
+// ->leftJoin("depart_user u", "u.uid=co.createrid AND u.is_del=0")
|
|
|
+// ->where($condition)
|
|
|
+// ->order("co.addtime desc")->column("co.pid");
|
|
|
+// if(!empty($pidlist)){
|
|
|
+// $where[]=[["ci.itemid","in",$pidlist]];
|
|
|
+//
|
|
|
+// }else{
|
|
|
+// if($pid===""){
|
|
|
+// $where[]=['ci.itemid','=',0];
|
|
|
+// }else{
|
|
|
+// $where[]=['ci.itemid','=',$pid];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $list = Db::name('customer_org1')
|
|
|
+// ->alias('co')
|
|
|
+// ->where($condition)
|
|
|
+// ->order("co.addtime",'desc')
|
|
|
+// ->column("co.id,co.pid,co.name,co.level,co.depart_link,co.creater,co.createrid,co.addtime,co.status");
|
|
|
+//
|
|
|
+// $all_createrid = array_column($list,'createrid');
|
|
|
+// $all_item = get_company_name_by_uid($all_createrid);
|
|
|
+//
|
|
|
+// $var=[];
|
|
|
+// foreach ($list as $item) {
|
|
|
+// $iten=[];
|
|
|
+// $iten['name']=$item['name'];
|
|
|
+//// $iten['code']="";
|
|
|
+// $iten['id']=$item['id'];
|
|
|
+// $iten['creater']=$item['creater'];
|
|
|
+// $iten['status']=$item['status'];
|
|
|
+// $iten['addtime']=$item['addtime'];
|
|
|
+// $iten['kh']=0;//组织架构
|
|
|
+// $iten['company_name'] = $all_item[$item['createrid']]??'';
|
|
|
+//
|
|
|
+// $var[]=$iten;
|
|
|
+// }
|
|
|
+// $itm = Db::connect('mysql_sys')
|
|
|
+// ->name('customer_info')
|
|
|
+// ->alias('ci')
|
|
|
+//// ->leftJoin("depart_user u", "u.nickname=ci.creater AND u.is_del=0")
|
|
|
+// ->where($where)
|
|
|
+// ->order("ci.addtime desc")
|
|
|
+// ->select()
|
|
|
+// ->toArray();
|
|
|
+//
|
|
|
+// //同理,这个表里只存了创建人名称,没有id
|
|
|
+//
|
|
|
+// foreach ($itm as $vat){
|
|
|
+// $inm=[];
|
|
|
+// $inm['name']=$vat['companyName'];
|
|
|
+// $inm['id']=$vat['id'];
|
|
|
+// $inm['code']=$vat['companyNo'];
|
|
|
+//// $inm['companyName']=$vat['companyName'];
|
|
|
+//// $inm['invoice_bank']=$vat['invoice_bank'];
|
|
|
+//// $inm['invoice_bankNo']=$vat['invoice_bankNo'];
|
|
|
+//// $inm['invoice_code']=$vat['invoice_code'];
|
|
|
+//// $inm['invoice_people']=$vat['invoice_people'];
|
|
|
+//// $inm['invoice_mobile']=$vat['invoice_mobile'];
|
|
|
+//// $inm['invoice_addr']=$vat['invoice_addr'];
|
|
|
+//// $inm['parent']=$vat['parent'];
|
|
|
+//// $inm['branch']=$vat['branch'];
|
|
|
+//// $inm['middle']=$vat['middle'];
|
|
|
+//// $inm['country']=$vat['country'];
|
|
|
+// $inm['status']=$vat['status'];
|
|
|
+// $inm['creater']=$vat['creater'];
|
|
|
+// $inm['addtime']=$vat['addtime'];
|
|
|
+// $inm['kh']=1;//客户
|
|
|
+// $inm['company_name'] = '待处理';
|
|
|
+// $var[]=$inm;
|
|
|
+// }
|
|
|
+// return app_show(0,"获取成功",$var);
|
|
|
}
|
|
|
+
|
|
|
/*新建*/
|
|
|
public function create()
|
|
|
{
|
|
|
- $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
|
|
|
- if ($name == "") {
|
|
|
- return error_show(1003, "公司名称不能为空");
|
|
|
- }
|
|
|
- $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "0";
|
|
|
- $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "0";
|
|
|
-// if ($pid === "") {
|
|
|
-// return error_show(1002, "父级id不能为空");
|
|
|
-// }
|
|
|
- if($pid!=0){
|
|
|
- $spid = Db::name('customer_org1')->where(['id'=>$pid, 'is_del'=>0])->find();
|
|
|
- //var_dump( Db::name('customer_org1')->getLastSql());
|
|
|
- if(empty($spid)){
|
|
|
- return error_show(1004,"父级不能为空");
|
|
|
- }
|
|
|
- }
|
|
|
- $rename = Db::name('customer_org1')->where(['is_del' => 0, 'name' => $name,'pid'=>$pid])->find();
|
|
|
- if (!empty($rename)) {
|
|
|
- return error_show(1002, "组织名称已存在");
|
|
|
- }
|
|
|
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
|
|
|
- if($token==''){
|
|
|
- return error_show(105,"参数token不能为空");
|
|
|
- }
|
|
|
- $user =GetUserInfo($token);
|
|
|
- if(empty($user)||$user['code']!=0){
|
|
|
- return error_show(1002,"创建人数据不存在");
|
|
|
- }
|
|
|
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
|
|
|
- $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "1";
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- $tada = [
|
|
|
- "name" => $name,
|
|
|
- "weight" => $weight,
|
|
|
- "pid" => $pid,
|
|
|
- "level" => $level,
|
|
|
- "updatetime" => date("Y-m-d H:i:s"),
|
|
|
- "addtime" => date("Y-m-d H:i:s"),
|
|
|
- "depart_link" => "",
|
|
|
- "is_del" => 0,
|
|
|
- "pname"=>isset($spid['name']) ? $spid['name']:"",
|
|
|
- "creater"=>$creater,
|
|
|
- "createrid"=>$createrid
|
|
|
- ];
|
|
|
- $t = Db::name('customer_org1')->insert($tada, true);
|
|
|
- //var_dump(Db::name('customer_org1')->getLastSql());
|
|
|
- if ($t > 0) {
|
|
|
- if(isset($spid)){
|
|
|
- // var_dump($spid);
|
|
|
- $depart_link = $spid['depart_link']."{$t}-";
|
|
|
- }else{
|
|
|
- $depart_link="{$t}-";
|
|
|
- }
|
|
|
- $level = explode('-', $depart_link);
|
|
|
- // var_dump($level);
|
|
|
- $level = array_filter($level);
|
|
|
- $level = count($level);
|
|
|
- $k = ['depart_link' => $depart_link, 'level' => $level];
|
|
|
- $u = Db::name('customer_org1')->where(['id' => $t])->save($k);
|
|
|
- // var_dump( Db::name('customer_org1')->getLastSql());
|
|
|
- if ($u) {
|
|
|
- Db::commit();
|
|
|
- return error_show(0, "新建成功");
|
|
|
- }
|
|
|
- }
|
|
|
- Db::rollback();
|
|
|
- } catch (\Exception $e) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1003, $e->getMessage());
|
|
|
- }
|
|
|
+ $param = $this->request->filter('trim')->post();
|
|
|
+
|
|
|
+ $param['uid'] = $this->uid;
|
|
|
+ $param['uname'] = $this->uname;
|
|
|
+
|
|
|
+ $userCommon = new \app\admin\common\User();
|
|
|
+ $rs = $userCommon->handle('customer_org_create', $param);
|
|
|
+
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
+// $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
|
|
|
+// if ($name == "") {
|
|
|
+// return error_show(1003, "公司名称不能为空");
|
|
|
+// }
|
|
|
+// $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "0";
|
|
|
+// $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "0";
|
|
|
+//// if ($pid === "") {
|
|
|
+//// return error_show(1002, "父级id不能为空");
|
|
|
+//// }
|
|
|
+// if($pid!=0){
|
|
|
+// $spid = Db::name('customer_org1')->where(['id'=>$pid, 'is_del'=>0])->find();
|
|
|
+// //var_dump( Db::name('customer_org1')->getLastSql());
|
|
|
+// if(empty($spid)){
|
|
|
+// return error_show(1004,"父级不能为空");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $rename = Db::name('customer_org1')->where(['is_del' => 0, 'name' => $name,'pid'=>$pid])->find();
|
|
|
+// if (!empty($rename)) {
|
|
|
+// return error_show(1002, "组织名称已存在");
|
|
|
+// }
|
|
|
+// $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
|
|
|
+// if($token==''){
|
|
|
+// return error_show(105,"参数token不能为空");
|
|
|
+// }
|
|
|
+// $user =GetUserInfo($token);
|
|
|
+// if(empty($user)||$user['code']!=0){
|
|
|
+// return error_show(1002,"创建人数据不存在");
|
|
|
+// }
|
|
|
+// $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
+// $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
|
|
|
+// $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "1";
|
|
|
+// Db::startTrans();
|
|
|
+// try {
|
|
|
+// $tada = [
|
|
|
+// "name" => $name,
|
|
|
+// "weight" => $weight,
|
|
|
+// "pid" => $pid,
|
|
|
+// "level" => $level,
|
|
|
+// "updatetime" => date("Y-m-d H:i:s"),
|
|
|
+// "addtime" => date("Y-m-d H:i:s"),
|
|
|
+// "depart_link" => "",
|
|
|
+// "is_del" => 0,
|
|
|
+// "pname"=>isset($spid['name']) ? $spid['name']:"",
|
|
|
+// "creater"=>$creater,
|
|
|
+// "createrid"=>$createrid
|
|
|
+// ];
|
|
|
+// $t = Db::name('customer_org1')->insert($tada, true);
|
|
|
+// //var_dump(Db::name('customer_org1')->getLastSql());
|
|
|
+// if ($t > 0) {
|
|
|
+// if(isset($spid)){
|
|
|
+// // var_dump($spid);
|
|
|
+// $depart_link = $spid['depart_link']."{$t}-";
|
|
|
+// }else{
|
|
|
+// $depart_link="{$t}-";
|
|
|
+// }
|
|
|
+// $level = explode('-', $depart_link);
|
|
|
+// // var_dump($level);
|
|
|
+// $level = array_filter($level);
|
|
|
+// $level = count($level);
|
|
|
+// $k = ['depart_link' => $depart_link, 'level' => $level];
|
|
|
+// $u = Db::name('customer_org1')->where(['id' => $t])->save($k);
|
|
|
+// // var_dump( Db::name('customer_org1')->getLastSql());
|
|
|
+// if ($u) {
|
|
|
+// Db::commit();
|
|
|
+// return error_show(0, "新建成功");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// Db::rollback();
|
|
|
+// } catch (\Exception $e) {
|
|
|
+// Db::rollback();
|
|
|
+// return error_show(1003, $e->getMessage());
|
|
|
+// }
|
|
|
}
|
|
|
+
|
|
|
/*更新*/
|
|
|
- public function updat(){
|
|
|
- $id = isset($this->post['id'])?intval($this->post['id']):"";
|
|
|
- if($id===""){
|
|
|
- return error_show(1004,"参数id不能为空");
|
|
|
- }
|
|
|
- $sid = Db::name('customer_org1')->where("id","=","$id")->find();
|
|
|
- // var_dump(Db::name('customer_org1')->getLastSql());
|
|
|
- if($sid==false){
|
|
|
- return error_show(1004,"公司不存在");
|
|
|
- }
|
|
|
- if($sid['status']==1){
|
|
|
- return error_show(1002,"状态是启用状态,无法编辑");
|
|
|
- }
|
|
|
- $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? intval($this->post['pid']):"";
|
|
|
- if($pid===""){
|
|
|
- return error_show(1004,"父级id不能为空");
|
|
|
- }
|
|
|
+ public function update()
|
|
|
+ {
|
|
|
|
|
|
- if($pid!=0){
|
|
|
- $fpid = Db::name('customer_org1')->where(['id'=>"$pid",'is_del'=>0])->find();
|
|
|
- if(empty($fpid)){
|
|
|
- return error_show(1004,"父级不能为空");
|
|
|
- }
|
|
|
- }
|
|
|
+ $param = $this->request->filter('trim')->post();
|
|
|
|
|
|
- $weight = isset($this->post['weight']) && $this->post['weight'] !==""? intval($this->post['weight']):"0";
|
|
|
+ $param['uid'] = $this->uid;
|
|
|
+ $param['uname'] = $this->uname;
|
|
|
|
|
|
-// $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
|
|
|
- $name = isset($this->post['name'])? trim($this->post['name']):"";
|
|
|
- if($name==""){
|
|
|
- return error_show(1004,"公司名称不能为空");
|
|
|
- }
|
|
|
- $repeat_name = Db::name('customer_org1')->where(["is_del"=>0,"name"=>$name,'pid'=>$pid])->where("id","<>","$id")->find();
|
|
|
- // echo Db::name('customer_org1')->getLastSql();
|
|
|
- if(!empty($repeat_name)){
|
|
|
- return error_show(1004,"部门名称已存在");
|
|
|
- }
|
|
|
- if(isset($fpid)){
|
|
|
- $depart_link=$fpid['depart_link']."{$id}-";
|
|
|
- }else{
|
|
|
- $depart_link= "{$id}-";
|
|
|
- }
|
|
|
- $level =explode('-',$depart_link);
|
|
|
- $level = array_filter($level);
|
|
|
- $level= count($level);
|
|
|
- $vir=[
|
|
|
- "id"=>$id,
|
|
|
- "name"=>$name,"pid"=>$pid,
|
|
|
- "weight"=>$weight,"depart_link"=>$depart_link,
|
|
|
- "level"=>$level,"is_del"=>0,"addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
- $org = Db::name('customer_org1')->save($vir);
|
|
|
- if($org){
|
|
|
- return error_show(0,"更新成功");
|
|
|
- }else{
|
|
|
- return error_show(1004,"更新失败");
|
|
|
- }
|
|
|
+ $userCommon = new \app\admin\common\User();
|
|
|
+ $rs = $userCommon->handle('customer_org_update', $param);
|
|
|
+
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
+
|
|
|
+// $id = isset($this->post['id'])?intval($this->post['id']):"";
|
|
|
+// if($id===""){
|
|
|
+// return error_show(1004,"参数id不能为空");
|
|
|
+// }
|
|
|
+// $sid = Db::name('customer_org1')->where("id","=","$id")->find();
|
|
|
+// // var_dump(Db::name('customer_org1')->getLastSql());
|
|
|
+// if($sid==false){
|
|
|
+// return error_show(1004,"公司不存在");
|
|
|
+// }
|
|
|
+// if($sid['status']==1){
|
|
|
+// return error_show(1002,"状态是启用状态,无法编辑");
|
|
|
+// }
|
|
|
+// $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? intval($this->post['pid']):"";
|
|
|
+// if($pid===""){
|
|
|
+// return error_show(1004,"父级id不能为空");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if($pid!=0){
|
|
|
+// $fpid = Db::name('customer_org1')->where(['id'=>"$pid",'is_del'=>0])->find();
|
|
|
+// if(empty($fpid)){
|
|
|
+// return error_show(1004,"父级不能为空");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// $weight = isset($this->post['weight']) && $this->post['weight'] !==""? intval($this->post['weight']):"0";
|
|
|
+//
|
|
|
+//// $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
|
|
|
+// $name = isset($this->post['name'])? trim($this->post['name']):"";
|
|
|
+// if($name==""){
|
|
|
+// return error_show(1004,"公司名称不能为空");
|
|
|
+// }
|
|
|
+// $repeat_name = Db::name('customer_org1')->where(["is_del"=>0,"name"=>$name,'pid'=>$pid])->where("id","<>","$id")->find();
|
|
|
+// // echo Db::name('customer_org1')->getLastSql();
|
|
|
+// if(!empty($repeat_name)){
|
|
|
+// return error_show(1004,"部门名称已存在");
|
|
|
+// }
|
|
|
+// if(isset($fpid)){
|
|
|
+// $depart_link=$fpid['depart_link']."{$id}-";
|
|
|
+// }else{
|
|
|
+// $depart_link= "{$id}-";
|
|
|
+// }
|
|
|
+// $level =explode('-',$depart_link);
|
|
|
+// $level = array_filter($level);
|
|
|
+// $level= count($level);
|
|
|
+// $vir=[
|
|
|
+// "id"=>$id,
|
|
|
+// "name"=>$name,"pid"=>$pid,
|
|
|
+// "weight"=>$weight,"depart_link"=>$depart_link,
|
|
|
+// "level"=>$level,"is_del"=>0,"addtime"=>date("Y-m-d H:i:s"),
|
|
|
+// "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
+// ];
|
|
|
+// $org = Db::name('customer_org1')->save($vir);
|
|
|
+// if($org){
|
|
|
+// return error_show(0,"更新成功");
|
|
|
+// }else{
|
|
|
+// return error_show(1004,"更新失败");
|
|
|
+// }
|
|
|
}
|
|
|
+
|
|
|
/*查询*/
|
|
|
- public function selec(){
|
|
|
- $id =isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
|
|
|
- if($id==""){
|
|
|
- return error_show(1004,"公司客户不存在");
|
|
|
+ public function info()
|
|
|
+ {
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
|
|
|
+ if ($id == "") {
|
|
|
+ return error_show(1004, "公司客户不存在");
|
|
|
}
|
|
|
- $tod=Db::name('customer_org1')->where(['id'=>$id,'is_del'=>0])->find();
|
|
|
- //var_dump(Db::name('customer_org1')->getLastSql());
|
|
|
- return app_show(0,"获取成功",$tod);
|
|
|
+
|
|
|
+ $userCommon = new \app\admin\common\User();
|
|
|
+ $rs = $userCommon->handle('customer_org_info', ['id' => $id]);
|
|
|
+
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
+// $tod=Db::name('customer_org1')->where(['id'=>$id,'is_del'=>0])->find();
|
|
|
+// //var_dump(Db::name('customer_org1')->getLastSql());
|
|
|
+// return app_show(0,"获取成功",$tod);
|
|
|
}
|
|
|
+
|
|
|
/*删除*/
|
|
|
- public function dell(){
|
|
|
- $id=isset($this->post['id']) ?intval($this->post['id']):"";
|
|
|
- $custy = Db::name('customer_org1')->where(["is_del"=>0,'id'=>$id])->find();
|
|
|
- if($custy==false){
|
|
|
- return error_show(1004,"公司不存在");
|
|
|
- }
|
|
|
- //$var= Db::name('customer_info')->where(['itemid'=>$id,'is_del'=>0])->find();
|
|
|
- $db= Db::name('customer_org1')->where(['pid'=>$custy['id'],'is_del'=>0])->count();
|
|
|
- if($db>0){
|
|
|
- return error_show(1004,"下一级还有组织,不允许删除");
|
|
|
- }
|
|
|
- $var= Db::connect('mysql_sys')
|
|
|
- ->name('customer_info')->where(['itemid'=>$id,'is_del'=>0])->count();
|
|
|
- if($var>0){
|
|
|
- return error_show(1004,"下一级还有分公司,不允许删除");
|
|
|
- }
|
|
|
- $custy['is_del']=1;
|
|
|
- $custy['updatetime']=date("Y-m-d H:i:s");
|
|
|
- $compy = Db::name('customer_org1')->save($custy);
|
|
|
- return $compy ? error_show(0,"删除成功"):error_show(1004,"删除失败");
|
|
|
+ public function delete()
|
|
|
+ {
|
|
|
+
|
|
|
+ $id = $this->request->post('id/d', 0, 'trim');
|
|
|
+
|
|
|
+ if ($id === 0) return json_show(1004, 'id不能为空');
|
|
|
+
|
|
|
+ $userCommon = new \app\admin\common\User();
|
|
|
+ $rs = $userCommon->handle('customer_org_delete', ['id' => $id]);
|
|
|
+
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
+// $id=isset($this->post['id']) ?intval($this->post['id']):"";
|
|
|
+// $custy = Db::name('customer_org1')->where(["is_del"=>0,'id'=>$id])->find();
|
|
|
+// if($custy==false){
|
|
|
+// return error_show(1004,"公司不存在");
|
|
|
+// }
|
|
|
+// //$var= Db::name('customer_info')->where(['itemid'=>$id,'is_del'=>0])->find();
|
|
|
+// $db= Db::name('customer_org1')->where(['pid'=>$custy['id'],'is_del'=>0])->count();
|
|
|
+// if($db>0){
|
|
|
+// return error_show(1004,"下一级还有组织,不允许删除");
|
|
|
+// }
|
|
|
+// $var= Db::connect('mysql_sys')
|
|
|
+// ->name('customer_info')->where(['itemid'=>$id,'is_del'=>0])->count();
|
|
|
+// if($var>0){
|
|
|
+// return error_show(1004,"下一级还有分公司,不允许删除");
|
|
|
+// }
|
|
|
+// $custy['is_del']=1;
|
|
|
+// $custy['updatetime']=date("Y-m-d H:i:s");
|
|
|
+// $compy = Db::name('customer_org1')->save($custy);
|
|
|
+// return $compy ? error_show(0,"删除成功"):error_show(1004,"删除失败");
|
|
|
}
|
|
|
- public function status(){
|
|
|
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
|
|
|
- if($id==""){
|
|
|
- return error_show(1002,"参数id不能为空");
|
|
|
- }
|
|
|
- $info = Db::name("customer_org1")->where([["id","=",$id]])->find();
|
|
|
- if(!$info){
|
|
|
- return error_show(1002,"未找到对应数据");
|
|
|
- }
|
|
|
- $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
|
|
|
- if($status===""){
|
|
|
- return error_show(1002,"参数status不能为空");
|
|
|
- }
|
|
|
- if(!in_array($status,[0,1])){
|
|
|
- return error_show(1002,"参数status无效");
|
|
|
- }
|
|
|
- $info['status']=$status;
|
|
|
- $info['updatetime']=date("Y-m-d H:i:s");
|
|
|
- $msg = $status==1?"启用":"禁用";
|
|
|
- $update = Db::name("customer_org1")->save($info);
|
|
|
- return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
|
|
|
+
|
|
|
+ public function status()
|
|
|
+ {
|
|
|
+
|
|
|
+ $param = $this->request->filter('trim')->post();
|
|
|
+
|
|
|
+ $userCommon = new \app\admin\common\User();
|
|
|
+ $rs = $userCommon->handle('customer_org_status', $param);
|
|
|
+
|
|
|
+ return json_show($rs['code'], $rs['message'], $rs['data']);
|
|
|
+// $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
|
|
|
+// if($id==""){
|
|
|
+// return error_show(1002,"参数id不能为空");
|
|
|
+// }
|
|
|
+// $info = Db::name("customer_org1")->where([["id","=",$id]])->find();
|
|
|
+// if(!$info){
|
|
|
+// return error_show(1002,"未找到对应数据");
|
|
|
+// }
|
|
|
+// $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
|
|
|
+// if($status===""){
|
|
|
+// return error_show(1002,"参数status不能为空");
|
|
|
+// }
|
|
|
+// if(!in_array($status,[0,1])){
|
|
|
+// return error_show(1002,"参数status无效");
|
|
|
+// }
|
|
|
+// $info['status']=$status;
|
|
|
+// $info['updatetime']=date("Y-m-d H:i:s");
|
|
|
+// $msg = $status==1?"启用":"禁用";
|
|
|
+// $update = Db::name("customer_org1")->save($info);
|
|
|
+// return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
|
|
|
}
|
|
|
|
|
|
}
|