Details.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Details extends Model
  5. {
  6. // 表名
  7. protected $name = 'details';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'fluctuate_type_text',
  17. 'assets_type_text',
  18. 'source_type_text'
  19. ];
  20. public function getFluctuateTypeList()
  21. {
  22. return ['1' => __('Fluctuate_type 1')];
  23. }
  24. public function getAssetsTypeList()
  25. {
  26. return ['1' => __('Assets_type 1'), '2' => __('Assets_type 2')];
  27. }
  28. public function getSourceTypeList()
  29. {
  30. return ['1' => __('Source_type 1'), '2' => __('Source_type 2')];
  31. }
  32. public function getFluctuateTypeTextAttr($value, $data)
  33. {
  34. $value = $value ? $value : (isset($data['fluctuate_type']) ? $data['fluctuate_type'] : '');
  35. $list = $this->getFluctuateTypeList();
  36. return isset($list[$value]) ? $list[$value] : '';
  37. }
  38. public function getAssetsTypeTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['assets_type']) ? $data['assets_type'] : '');
  41. $list = $this->getAssetsTypeList();
  42. return isset($list[$value]) ? $list[$value] : '';
  43. }
  44. public function getSourceTypeTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['source_type']) ? $data['source_type'] : '');
  47. $list = $this->getSourceTypeList();
  48. return isset($list[$value]) ? $list[$value] : '';
  49. }
  50. public function addDetail($user_id,$fluctuate_type,$msg,$money,$assets_type,$source_type,$form_id=0){
  51. $data = [
  52. 'user_id' => $user_id,
  53. 'fluctuate_type' => $fluctuate_type,
  54. 'msg' => $msg,
  55. 'amount' => $money,
  56. 'assets_type' => $assets_type,
  57. 'source_type' => $source_type,
  58. 'createtime' => time(),
  59. 'form_id'=> $form_id
  60. ];
  61. $this->save($data);
  62. }
  63. }