UserBl.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 UserBl extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'p_bl' => input('pBl/f',0),
  13. 'c_bl' => input('cBl/f',0),
  14. 'p_bl_type' => input('pBlType/d',0),
  15. 'c_bl_type' => input('cBlType/d',0),
  16. 'p_bl_extra' => input('pBlExtra/f',0),
  17. 'c_bl_extra' => input('cBlExtra/f',0),
  18. 'p_free_bl' => input('pFreeBl/f',0),
  19. 'c_free_bl' => input('cFreeBl/f',0),
  20. ];
  21. if($data['id'] <= 0){
  22. HelpHander::error('参数错误');
  23. }
  24. $id = $data['id'];
  25. unset($data['id']);
  26. $data['update_time'] = date('Y-m-d H:i:s');
  27. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  28. if(!$ret){
  29. HelpHander::error('操作失败');
  30. }
  31. return true;
  32. }
  33. public function info($id){
  34. $info = $this->where('id',$id)->find();
  35. if(!$info){
  36. HelpHander::error('数据不存在');
  37. }
  38. $data = $info->toArray();
  39. return $data;
  40. }
  41. public function lists($page,$size,$companyId,$orgId){
  42. if($companyId > 0){
  43. $map[] = ['ur.company_id','=',$companyId];
  44. }
  45. $map = empty($map)?true:$map;
  46. $lists = Db::name('user_bl')
  47. ->alias('ur')
  48. ->join('company c','c.id = ur.company_id')
  49. ->where($map)
  50. ->field('ur.*,c.title as company')
  51. ->page($page,$size)
  52. ->order('ur.id asc')
  53. ->select();
  54. $total = Db::name('user_bl')
  55. ->alias('ur')
  56. ->join('company c','c.id = ur.company_id')
  57. ->where($map)->count();
  58. $data = [
  59. 'total' => $total,
  60. 'list' => $lists?$lists:[]
  61. ];
  62. return $data;
  63. }
  64. }