DpyhApiAction.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. class DpyhApiAction extends CommonAction {
  3. const tableName = 'dpyh_api';
  4. const pkName = 'ID';
  5. function sys_list( ){
  6. $list = new \Jms\Gui\ClGrid();
  7. $list->sql_filter = function($search,&$cond){
  8. $cond['RoleId'] = \Zndp\User\RoleEnum::API_CLIENT;
  9. };
  10. $list->display($this);
  11. }
  12. function sys_addedit( ){
  13. $form = new \Jiaruan\LigerIframeForm();
  14. $form->before_add = function(&$data){
  15. $data['ProjectID'] = C('CC_PROJECT_ID');
  16. $data['RoleId'] = \Zndp\User\RoleEnum::API_CLIENT;
  17. };
  18. $form->before_save = function(&$data){
  19. $id = I('get.id');
  20. //取出原用户名,密码
  21. $userinfo = M('uc_user')->field('UserName,Password')->where(array('ID'=>$id))->find();
  22. $cond = array(
  23. 'ID' => array('neq',$id),
  24. 'UserName' => $data['UserName'],
  25. );
  26. if( M('uc_user')->where($cond)->count() > 0 ){
  27. json_fail('该用户名已存在,请换一个!');
  28. }
  29. if( $data['Password'] != $userinfo['Password'] ) {
  30. $data['Password'] = (new \Zndp\User\Util)->encPwd( $data['Password'] );
  31. }else{
  32. unset($data['Password']);
  33. }
  34. };
  35. $form->display($this);
  36. }
  37. public function sys_delete_api( ){
  38. $id = I('get.id');
  39. if(!$id){
  40. json_fail('ID不存在!');
  41. }
  42. $where =array('ID'=>$id);
  43. $result = M('uc_user')->where($where)->delete();
  44. if(!$result){
  45. json_fail('删除失败!');
  46. }
  47. json_success('删除成功!');
  48. }
  49. function sys_assoc_list( ){
  50. $list = new \Jms\Gui\ClGrid();
  51. $list->sql_filter = function($search,&$cond){
  52. $cond['AssocId'] = I('get.id');
  53. };
  54. $list->row_filter = function(&$row){
  55. $where = array('ID'=>$row['FarmId']);
  56. $row['FarmId_text'] = MM('dpyh_farm')->where($where)->getField('FarmName');
  57. };
  58. $list->toolbar_filter = function(&$toolbar){
  59. if($toolbar['icon'] == 'add'){
  60. $toolbar['url'] .= "&id=".I('get.id');
  61. }
  62. };
  63. $list->display($this);
  64. }
  65. function sys_addedit_assoc( ){
  66. $form = new \Jms\Gui\ClForm();
  67. $form->before_save = function(&$data){
  68. $id = I('get.id');
  69. $where = array('ID'=>$data['ID']);
  70. $res = MM('uc_user')->where($where)->setField('AssocId',$id);
  71. if(!$res){
  72. json_fail('操作失败');
  73. }
  74. json_success('操作成功');
  75. };
  76. $form->form_filter = function(&$form){
  77. $user_list = get_user_option();
  78. $form['fields']['ID']['editor'] = array('options'=>$user_list);
  79. };
  80. $form->display($this);
  81. }
  82. public function sys_disassociation( ){
  83. $id = I('get.id');
  84. if(!$id){
  85. json_fail('缺少ID');
  86. }
  87. $where = array('ID'=>$id);
  88. $res = MM('uc_user')->where($where)->setField('AssocId','');
  89. if(!$res){
  90. json_fail('操作失败');
  91. }
  92. json_success('操作成功');
  93. }
  94. private function get_company_option( ){
  95. //获取已关联的公司id
  96. $where = array('RoleId'=>\Zndp\User\RoleEnum::API_CLIENT);
  97. $assoc_ids = M('uc_user')->field('AssocId')->where($where)->select();
  98. if($assoc_ids){//如果存在已绑定的公司id
  99. $ids = array_column($assoc_ids,'AssocId');
  100. $where = array('ID'=>array('NOT IN',$ids),'Level'=>0);//公司查询条件
  101. }else{
  102. $where = array('Level'=>0);
  103. }
  104. $fields = 'ID as id,DepartName as text';
  105. $comp_list = M('uc_organization')->field($fields)->where($where)->select();
  106. if(empty($comp_list)){
  107. $comp_list = array();
  108. $first_option = array('id'=>'','text'=>'没有可选公司');
  109. array_push($comp_list,$first_option);
  110. }else{
  111. $first_option = array('id'=>'','text'=>'请选择关联公司');
  112. array_unshift($comp_list,$first_option);
  113. }
  114. return $comp_list;
  115. }
  116. }