PostSalary.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class PostSalary extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'title' => input('title','','trim'),
  12. 'job' => input('job','','trim'),
  13. 'type' => input('type/d',0),
  14. 'money' => input('money/f',0),
  15. 'company_id' => input('companyId/d',0),
  16. 'fixed_performance' => input('fixedPerformance/f',0),
  17. 'month_performance' => input('monthPerformance/f',0),
  18. 'year_performance' => input('yearPerformance/f',0),
  19. 'fixed_performance2' => input('fixedPerformance2/f',0),
  20. 'month_performance2' => input('monthPerformance2/f',0),
  21. 'year_performance2' => input('yearPerformance2/f',0),
  22. ];
  23. $logdata = json_encode($data);
  24. $result = validate('PostSalary')->check($data,[],'');
  25. if(true !== $result){
  26. HelpHander::error(validate('PostSalary')->getError());
  27. }
  28. $id = $data['id'];
  29. unset($data['id']);
  30. if($id > 0){
  31. $data['update_time'] = date('Y-m-d H:i:s');
  32. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  33. }else{
  34. $data['create_time'] = date('Y-m-d H:i:s');
  35. $ret = $this->allowField(true)->save($data);
  36. }
  37. if(!$ret){
  38. HelpHander::error('操作失败');
  39. }
  40. if($id > 0){
  41. $content = '修改岗位等级';
  42. }else{
  43. $content = '添加岗位等级';
  44. }
  45. model('ActionLog')->add(6,$content,0,$logdata);
  46. return true;
  47. }
  48. public function info($id){
  49. $info = $this->where('id',$id)->find();
  50. if(!$info){
  51. HelpHander::error('数据不存在');
  52. }
  53. return $info->toArray();
  54. }
  55. public function lists($page,$size,$type,$companyId){
  56. $map[] = ['del','=',0];
  57. if($companyId > 0){
  58. $map[] = ['company_id','=',$companyId];
  59. }
  60. if(in_array($type,[1,2,3])){
  61. $map[] = ['type','=',$type];
  62. }
  63. $lists = $this
  64. ->where($map)
  65. ->page($page,$size)
  66. ->order('id desc')
  67. ->select();
  68. $lists = $lists?$lists->toArray():[];
  69. foreach ($lists as $k=>$v){
  70. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  71. }
  72. $total = $this->where($map)->count();
  73. $data = [
  74. 'total' => $total,
  75. 'list' => $lists
  76. ];
  77. return $data;
  78. }
  79. public function del($id){
  80. $ret = $this->where('id',$id)->setField('del',1);
  81. if(!$ret){
  82. HelpHander::error('删除失败');
  83. }
  84. $logdata = json_encode(['id' => $id]);
  85. model('ActionLog')->add(6,'删除岗位等级',0,$logdata);
  86. return true;
  87. }
  88. public function all(){
  89. $map[] = ['del','=',0];
  90. $lists = $this
  91. ->where($map)
  92. ->field('id,title,type,company_id')
  93. ->order('id desc')
  94. ->select();
  95. return $lists?$lists->toArray():[];
  96. }
  97. public function center(){
  98. $map[] = ['del','=',0];
  99. $map[] = ['company_id','=',1];
  100. $lists = $this
  101. ->where($map)
  102. ->field('id,title,job,type')
  103. ->order('type asc,id asc')
  104. ->select();
  105. return $lists?$lists->toArray():[];
  106. }
  107. }