ProjectDonation.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace app\common\model\project;
  3. use app\common\model\Category;
  4. use liuniu\BaseModel;
  5. use think\Model;
  6. class ProjectDonation extends BaseModel
  7. {
  8. // 表名
  9. protected $name = 'project_donation';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = false;
  15. protected $deleteTime = false;
  16. // 追加属性
  17. protected $append = [
  18. 'start_time_text',
  19. 'end_time_text',
  20. 'verify_time_text',
  21. 'feedback_time_text',
  22. 'status_text'
  23. ];
  24. public function getStatusList()
  25. {
  26. return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
  27. }
  28. public function getStartTimeTextAttr($value, $data)
  29. {
  30. $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
  31. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  32. }
  33. public function getEndTimeTextAttr($value, $data)
  34. {
  35. $value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : '');
  36. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  37. }
  38. public function getVerifyTimeTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['verify_time']) ? $data['verify_time'] : '');
  41. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  42. }
  43. public function getFeedbackTimeTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['feedback_time']) ? $data['feedback_time'] : '');
  46. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  47. }
  48. public function getStatusTextAttr($value, $data)
  49. {
  50. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  51. $list = $this->getStatusList();
  52. return isset($list[$value]) ? $list[$value] : '';
  53. }
  54. protected function setStartTimeAttr($value)
  55. {
  56. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  57. }
  58. protected function setEndTimeAttr($value)
  59. {
  60. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  61. }
  62. protected function setVerifyTimeAttr($value)
  63. {
  64. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  65. }
  66. protected function setFeedbackTimeAttr($value)
  67. {
  68. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  69. }
  70. public static function lst($where)
  71. {
  72. $model = new self;
  73. $where1 = null;
  74. if (isset($where['cid']) && $where['cid']>0) $where1['cid'] = $where['cid'];
  75. if (isset($where['title']) && $where['title'] !== '') $where1['title'] =['LIKE',"%$where[title]%"];
  76. if (isset($where['status']) && $where['status']>-2) $where1['status'] = $where['status'];
  77. if (isset($where['uid']) && $where['uid']>0) $where1['uid'] = $where['uid'];
  78. $list = $model->where($where1)->order('sort desc,id desc')->page($where['page'],$where['limit'])->select();
  79. $count = $model->where($where1)->count();
  80. return compact('count','list');
  81. }
  82. public static function info($id)
  83. {
  84. $info = self::find($id);
  85. if($info) {
  86. $rs = ProjectDonationInfo::where('pro_id', $id)->select();
  87. foreach ($rs as &$v)
  88. {
  89. $v['ify_tile'] = Category::where('id',$v['project_donation_id'])->value('name');
  90. }
  91. $info['project_donation_info'] =$rs;
  92. $sum = ProjectDonationInfo::where('pro_id', $id)->group('pro_id')->field('sum(project_donation_num) as project_donation_num ,sum(received) as received')->find();
  93. $info['project_progress'] = bcdiv($sum['received'],$sum['project_donation_num'],0);
  94. }
  95. return $info;
  96. }
  97. }