Withdraw.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\common\model;
  3. use think\Config;
  4. use think\Model;
  5. class Withdraw extends Model
  6. {
  7. // 表名
  8. protected $table = 'withdraw';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. // 追加属性
  15. protected $append = [
  16. 'state_text',
  17. 'finishtime_text'
  18. ];
  19. public function getStateList()
  20. {
  21. return ['1' => __('提现中'),'2' => __('打款中'),'3' => __('已打款')];
  22. }
  23. public function getStateTextAttr($value, $data)
  24. {
  25. $value = $value ? $value : $data['state'];
  26. $list = $this->getStateList();
  27. return isset($list[$value]) ? $list[$value] : '';
  28. }
  29. public function getFinishtimeTextAttr($value, $data)
  30. {
  31. $value = $value ? $value : $data['finishtime'];
  32. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  33. }
  34. protected function setFinishtimeAttr($value)
  35. {
  36. return $value && !is_numeric($value) ? strtotime($value) : $value;
  37. }
  38. /**
  39. * 连接主库
  40. * @return $this
  41. */
  42. public function setConnect()
  43. {
  44. $config = Config::get('database');
  45. $config['admin_rw_separate'] = false;
  46. $this->connect($config);
  47. return $this;
  48. }
  49. }