SalaryApply.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class SalaryApply extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'title' => input('title','','trim'),
  12. 'type' => input('type/d',0),
  13. 'sort' => input('sort/d',0),
  14. 'cate' => input('cate/d',0),
  15. 'sign' => input('sign/d',0),
  16. 'userids' => input('userids','','trim')
  17. ];
  18. $result = validate('SalaryApply')->check($data,[],'');
  19. if(true !== $result){
  20. HelpHander::error(validate('SalaryApply')->getError());
  21. }
  22. $users = explode(',',$data['userids']);
  23. $arr = [];
  24. foreach ($users as $v){
  25. if($v){
  26. $arr[] = $v;
  27. }
  28. }
  29. $data['userids'] = implode(',',$arr);
  30. $id = $data['id'];
  31. unset($data['id']);
  32. if($id > 0){
  33. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  34. }else{
  35. $ret = $this->allowField(true)->save($data);
  36. }
  37. if(!$ret){
  38. HelpHander::error('操作失败');
  39. }
  40. return true;
  41. }
  42. public function all($type){
  43. $map[] = ['type','=',$type];
  44. $lists = $this
  45. ->where($map)
  46. ->order('sort asc,id asc')
  47. ->select();
  48. $lists = $lists?$lists->toArray():[];
  49. foreach ($lists as $k=>$v){
  50. $uids = explode(',',$v['userids']);
  51. $users = Db::name('user_info')->where('user_id','in',$uids)->column('name');
  52. $lists[$k]['users'] = $users?implode(',',$users):'';
  53. }
  54. return $lists;
  55. }
  56. public function all2($type){
  57. $map[] = ['type','=',$type];
  58. $lists = $this
  59. ->where($map)
  60. // ->field('id,title,userids,sign')
  61. ->order('sort asc,id asc')
  62. ->select();
  63. $lists = $lists?$lists->toArray():[];
  64. return $lists;
  65. }
  66. public function del($id){
  67. $ret = Db::name('salary_apply')->delete($id);
  68. if(!$ret){
  69. HelpHander::error('删除失败');
  70. }
  71. return true;
  72. }
  73. }