UserBase.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class UserBase extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'user_id' => input('uid/d',0),
  12. 'qynj' => input('qynj/f',0),
  13. 'gjj' => input('gjj/f',0),
  14. 'sb' => input('sb/f',0),
  15. 'syyl' => input('syyl/f',0),
  16. 'gssy' => input('gssy/f',0),
  17. 'ylnj' => input('ylnj/f',0),
  18. ];
  19. $result = validate('UserBase')->check($data,[],'');
  20. if(true !== $result){
  21. HelpHander::error(validate('UserBase')->getError());
  22. }
  23. $ubase = Db::name('user_base')->where('user_id',$data['user_id'])->find();
  24. if($ubase){ // 修改
  25. $data['update_time'] = date('Y-m-d H:i:s');
  26. $res = Db::name('user_base')->where('id',$ubase['id'])->update($data);
  27. } else {// 新增
  28. $data['create_time'] = date('Y-m-d H:i:s');
  29. $data['update_time'] = date('Y-m-d H:i:s');
  30. $res = Db::name('user_base')->insert($data);
  31. }
  32. if(!$res){
  33. HelpHander::error('操作失败');
  34. }
  35. return true;
  36. }
  37. public function info($id){
  38. $info = $this->where('id',$id)->find();
  39. if(!$info){
  40. HelpHander::error('数据不存在');
  41. }
  42. $data = $info->toArray();
  43. $data['userName'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name');
  44. return $data;
  45. }
  46. public function lists($page,$size,$name,$phone,$companyId,$orgId){
  47. if($name != ''){
  48. $map[] = ['ui.name','like','%'.$name.'%'];
  49. }
  50. if($phone != ''){
  51. $map[] = ['u.phone','like','%'.$phone.'%'];
  52. }
  53. if($companyId > 0){
  54. $map[] = ['ui.company_id','=',$companyId];
  55. }
  56. $uids = model('User')->getAdminUsers();
  57. if($uids){
  58. $map[] = ['u.id','not in',$uids];
  59. }
  60. $map[] = ['u.del','=',0];
  61. $map[] = ['r.type','=',3];
  62. $map[] = ['r.org_id','=',$orgId];
  63. $lists = Db::name('user_info')
  64. ->alias('ui')
  65. ->join('user u','ui.user_id = u.id')
  66. ->join('user_roles ur','ur.user_id = u.id')
  67. ->join('roles r','ur.roles_id = r.id')
  68. ->join('user_base ub','ub.user_id = u.id','left')
  69. ->where($map)
  70. ->field('ub.*,u.phone,ui.name,ui.gender,ui.user_id as uid')
  71. ->page($page,$size)
  72. ->order('u.id desc')
  73. ->select();
  74. $lists = $lists?$lists:[];
  75. /*$lists = Db::name('user_base')
  76. ->alias('ur')
  77. ->join('user u','u.id = ur.user_id')
  78. ->join('user_info ui','ui.user_id = ur.user_id')
  79. ->where($map)
  80. ->field('ur.*,u.phone,ui.name,ui.gender')
  81. ->page($page,$size)
  82. ->order('id desc')
  83. ->select();
  84. $bls = Db::name('user_bl')->select();
  85. foreach ($lists as $k=>$v){
  86. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  87. $lists[$k]['gjjp'] = $lists[$k]['gjjc'] = 0;
  88. $lists[$k]['qynjp'] = $lists[$k]['qynjc'] = 0;
  89. $lists[$k]['sbylap'] = $lists[$k]['sbylac'] = 0;
  90. $lists[$k]['sbsyep'] = $lists[$k]['sbsyep'] = 0;
  91. $lists[$k]['sbylip'] = $lists[$k]['sbylic'] = 0;
  92. $lists[$k]['sbgsc'] = $lists[$k]['sbsyuc'] = 0;
  93. $sbhj = $gjjhj = $qynjhj = 0;
  94. // 计算各项扣除
  95. foreach ($bls as $key=>$val){
  96. if($val['company_id'] == $v['company_id']){
  97. switch ($val['name']){
  98. case 'gjj':
  99. $lists[$k]['gjjp'] = calculate_money($v['gjj'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']);
  100. $lists[$k]['gjjc'] = calculate_money($v['gjj'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  101. $gjjhj = round($lists[$k]['gjjp'] + $lists[$k]['gjjc'],2);
  102. break;
  103. case 'qynj':
  104. if($val['company_id'] == 1){
  105. $lists[$k]['qynjp'] = calculate_money($v['ylnj'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']);
  106. $lists[$k]['qynjc'] = calculate_money($v['ylnj'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  107. } else {
  108. $lists[$k]['qynjp'] = calculate_money($v['qynj'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']);
  109. $lists[$k]['qynjc'] = calculate_money($v['qynj'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  110. }
  111. $qynjhj = round($lists[$k]['qynjp'] + $lists[$k]['qynjc'],2);
  112. break;
  113. case 'yla':
  114. if($val['company_id'] == 1){
  115. $lists[$k]['sbylap'] = calculate_money($v['ylnj'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']);
  116. $lists[$k]['sbylac'] = calculate_money($v['ylnj'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  117. } else {
  118. $lists[$k]['sbylap'] = calculate_money($v['sb'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']);
  119. $lists[$k]['sbylac'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  120. }
  121. $sbhj += $lists[$k]['sbylap'];
  122. $sbhj += $lists[$k]['sbylac'];
  123. break;
  124. case 'sye':
  125. if($val['company_id'] == 1){
  126. $lists[$k]['sbsyep'] = calculate_money($v['gssy'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']);
  127. $lists[$k]['sbsyec'] = calculate_money($v['gssy'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  128. } else {
  129. $lists[$k]['sbsyep'] = calculate_money($v['sb'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']);
  130. $lists[$k]['sbsyec'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  131. }
  132. $sbhj += $lists[$k]['sbsyep'];
  133. $sbhj += $lists[$k]['sbsyec'];
  134. break;
  135. case 'yli':
  136. if($val['company_id'] == 1){
  137. $lists[$k]['sbylip'] = calculate_money($v['syyl'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']);
  138. $lists[$k]['sbylic'] = calculate_money($v['syyl'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  139. } else {
  140. $lists[$k]['sbylip'] = calculate_money($v['sb'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']);
  141. $lists[$k]['sbylic'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  142. }
  143. $sbhj += $lists[$k]['sbylip'];
  144. $sbhj += $lists[$k]['sbylic'];
  145. break;
  146. case 'gs':
  147. if($val['company_id'] == 1){
  148. $lists[$k]['sbgsc'] = calculate_money($v['gssy'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  149. } else {
  150. $lists[$k]['sbgsc'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  151. }
  152. $sbhj += $lists[$k]['sbgsc'];
  153. break;
  154. case 'syu':
  155. if($val['company_id'] == 1){
  156. $lists[$k]['sbsyuc'] = calculate_money($v['gssy'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  157. } else {
  158. $lists[$k]['sbsyuc'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']);
  159. }
  160. $sbhj += $lists[$k]['sbsyuc'];
  161. break;
  162. }
  163. }
  164. }
  165. $lists[$k]['sbhj'] = round($sbhj,2);
  166. $lists[$k]['gjjhj'] = round($sbhj,2);
  167. $lists[$k]['qynjhj'] = round($qynjhj,2);
  168. }*/
  169. $total = Db::name('user_info')
  170. ->alias('ui')
  171. ->join('user u','ui.user_id = u.id')
  172. ->join('user_roles ur','ur.user_id = u.id')
  173. ->join('roles r','ur.roles_id = r.id')
  174. ->join('user_base ub','ub.user_id = u.id','left')
  175. ->where($map)->count();
  176. $data = [
  177. 'total' => $total,
  178. 'list' => $lists?$lists:[]
  179. ];
  180. return $data;
  181. }
  182. public function del($id){
  183. $ret = $this->where('id',$id)->delete();
  184. if(!$ret){
  185. HelpHander::error('删除失败');
  186. }
  187. return true;
  188. }
  189. }