Help.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\common\model;
  3. use liuniu\BaseModel;
  4. use think\Exception;
  5. use traits\model\SoftDelete;
  6. class Help extends BaseModel
  7. {
  8. use SoftDelete;
  9. // 表名
  10. protected $name = 'help';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'int';
  13. // 定义时间戳字段名
  14. protected $createTime = 'createtime';
  15. protected $updateTime = 'updatetime';
  16. protected $deleteTime = 'deletetime';
  17. // 追加属性
  18. protected $append = [
  19. 'isrec_text',
  20. 'status_text'
  21. ];
  22. public function getIsrecList()
  23. {
  24. return ['0' => __('Isrec 0'), '1' => __('Isrec 1')];
  25. }
  26. public function getStatusList()
  27. {
  28. return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4')];
  29. }
  30. public function getIsrecTextAttr($value, $data)
  31. {
  32. $value = $value ? $value : (isset($data['isrec']) ? $data['isrec'] : '');
  33. $list = $this->getIsrecList();
  34. return isset($list[$value]) ? $list[$value] : '';
  35. }
  36. public function getStatusTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  39. $list = $this->getStatusList();
  40. return isset($list[$value]) ? $list[$value] : '';
  41. }
  42. public static function help_create($where)
  43. {
  44. self::beginTrans();
  45. try {
  46. $res = self::create($where);
  47. $where['help_id'] = $res['id'];
  48. $res1 = HelpExt::create($where);
  49. foreach ($where['family'] as $v)
  50. {
  51. $v['cid'] = $where['cid'];
  52. $v['help_id'] = $res['id'];
  53. if(isset($v['full_name']) && isset($v['relation']))
  54. {
  55. HelpFamily::create($v);
  56. }
  57. }
  58. self::commitTrans();
  59. return $res;
  60. }catch (Exception $e)
  61. {
  62. self::setErrorInfo($e->getMessage(),true);
  63. }
  64. }
  65. public static function lst($where)
  66. {
  67. $model = new self;
  68. if(isset($where['cid']) && $where['cid']>0) $model->where('cid',$where['cid']);
  69. if(isset($where['user_id']) && $where['user_id']>0) $model->where('user_id',$where['user_id']);
  70. if(isset($where['category_id']) && $where['category_id']>0) $model->where('category_id',$where['category_id']);
  71. if(isset($where['status']) && $where['status']>-2) $model->where('status',$where['status']);
  72. if(isset($where['is_rec']) && $where['is_rec']==1) $model->where('is_rec',$where['is_rec']);
  73. $data = $model->order('id desc')->page($where['page'],$where['limit'])->select();
  74. return $data;
  75. }
  76. public static function info($cid,$id)
  77. {
  78. $info = self::where('cid',$cid)->where('id',$id)->find();
  79. if(!$info)return self::setErrorInfo('非法数据');
  80. $info['ext'] = HelpExt::where('help_id',$info['id'])->find();
  81. $info['family'] = HelpFamily::where('help_id',$info['id'])->select();
  82. $info['lave'] = Lave::lst(['cid'=>$cid,'paid'=>1,'help_id'=>$info['id']]);
  83. return $info;
  84. }
  85. }