ProjectDonationRocord.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\common\model\project;
  3. use app\common\model\project\ProjectDonationOrder;
  4. use liuniu\BaseModel;
  5. use think\Model;
  6. class ProjectDonationRocord extends BaseModel
  7. {
  8. // 表名
  9. protected $name = 'project_donation_rocord';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = false;
  12. // 定义时间戳字段名
  13. protected $createTime = false;
  14. protected $updateTime = false;
  15. protected $deleteTime = false;
  16. // 追加属性
  17. protected $append = [
  18. 'add_time_text'
  19. ];
  20. public function getAddTimeTextAttr($value, $data)
  21. {
  22. $value = $value ? $value : (isset($data['add_time']) ? $data['add_time'] : '');
  23. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  24. }
  25. protected function setAddTimeAttr($value)
  26. {
  27. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  28. }
  29. public static function bill($cid=0,$type,$admin_id=0,$project_id=0,$order_id=0,$remark='')
  30. {
  31. $add_time = time();
  32. return self::create(compact('type', 'admin_id', 'order_id', 'remark', 'type', 'add_time','project_id','cid'));
  33. }
  34. public static function getbill($project_id,$type,$page=1,$limit=20,$cid=0)
  35. {
  36. $model = new self;
  37. if ($cid>0) $model = $model->where('cid',$cid);
  38. $where['project_id'] = $project_id;
  39. $where['type'] = $type;
  40. $model = $model->where($where);
  41. $count = $model->count();
  42. $data = $model->page($page,$limit)->select()->toarray();
  43. foreach ($data as &$v)
  44. {
  45. $v['name'] = ProjectDonationOrder::where('id',$v['order_id'])->value('name');
  46. }
  47. return compact('count','data');
  48. }
  49. }