Donate.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\common\model;
  3. use liuniu\BaseModel;
  4. class Donate extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'donate';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'sex_text',
  17. 'education_text',
  18. 'status_text'
  19. ];
  20. public function getSexList()
  21. {
  22. return ['0' => __('Sex 0'), '1' => __('Sex 1')];
  23. }
  24. public function getEducationList()
  25. {
  26. return ['0' => __('Education 0'), '1' => __('Education 1'), '2' => __('Education 2'), '3' => __('Education 3'), '4' => __('Education 4'), '5' => __('Education 5'), '6' => __('Education 6'), '7' => __('Education 7'), '8' => __('Education 8'), '9' => __('Education 9')];
  27. }
  28. public function getStatusList()
  29. {
  30. return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1')];
  31. }
  32. public function getSexTextAttr($value, $data)
  33. {
  34. $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
  35. $list = $this->getSexList();
  36. return isset($list[$value]) ? $list[$value] : '';
  37. }
  38. public function getEducationTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['education']) ? $data['education'] : '');
  41. $list = $this->getEducationList();
  42. return isset($list[$value]) ? $list[$value] : '';
  43. }
  44. public function getStatusTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  47. $list = $this->getStatusList();
  48. return isset($list[$value]) ? $list[$value] : '';
  49. }
  50. public static function lst($where)
  51. {
  52. $model = new self;
  53. if(isset($where['cid']) && $where['cid']>0) $model->where('cid',$where['cid']);
  54. if(isset($where['user_id']) && $where['user_id']>0) $model->where('user_id',$where['user_id']);
  55. if(isset($where['category_ids']) && $where['category_ids']>0) $model = $model->where("CONCAT(',',category_ids,',') LIKE '%,$where[category_ids],%'");
  56. if(isset($where['status']) && $where['status']>-2) $model->where('status',$where['status']);
  57. $data = $model->order('id desc')->page($where['page'],$where['limit'])->select();
  58. return $data;
  59. }
  60. }