Help.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. list($help['cid'],$help['category_id'],$help['user_id'],$help['full_name'],$help['contact'],$help['id_card'],$help['title'],$help['info'],$help['userimage'],$help['userimages'],$help['status']) =
  47. [$where['cid'],$where['category_id'],$where['user_id'],$where['full_name'],$where['contact'],$where['id_card'],$where['title'],$where['info'],$where['userimage'],$where['userimages'],0];
  48. $res = self::create($help);
  49. list($HelpExt['cid'],$HelpExt['help_id'],$HelpExt['sex'],$HelpExt['politics'],$HelpExt['birthday'],$HelpExt['address'],$HelpExt['company'],$HelpExt['unit_nature'],$HelpExt['monthly_income'],$HelpExt['annual_household_income'],$HelpExt['annual_household_income_average'],$HelpExt['identity'],$HelpExt['marriage'],$HelpExt['medical_insurance'],$HelpExt['object_features'],$HelpExt['reason']) =
  50. [$where['cid'],$res['id'],$where['sex'],$where['politics'],$where['birthday'],$where['address'],$where['company'],$where['unit_nature'],$where['monthly_income'],$where['annual_household_income'],$where['annual_household_income_average'],$where['identity'],$where['marriage'],$where['medical_insurance'],$where['object_features'],$where['reason']];
  51. $res1 = HelpExt::create($HelpExt);
  52. foreach ($where['family'] as $v)
  53. {
  54. $v['cid'] = $where['cid'];
  55. $v['help_id'] = $res['id'];
  56. if(isset($v['full_name']) && isset($v['relation']))
  57. {
  58. HelpFamily::create($v);
  59. }
  60. }
  61. self::commitTrans();
  62. return $res;
  63. }catch (Exception $e)
  64. {
  65. self::setErrorInfo($e->getLine().'--'.$e->getMessage(),true);
  66. }
  67. }
  68. public static function lst($where)
  69. {
  70. $model = new self;
  71. if(isset($where['cid']) && $where['cid']>0) $model->where('cid',$where['cid']);
  72. if(isset($where['user_id']) && $where['user_id']>0) $model->where('user_id',$where['user_id']);
  73. if(isset($where['category_id']) && $where['category_id']>0) $model->where('category_id',$where['category_id']);
  74. if(isset($where['status']) && $where['status']>-2) $model->where('status',$where['status']);
  75. if(isset($where['is_rec']) && $where['is_rec']==1) $model->where('is_rec',$where['is_rec']);
  76. $data = $model->order('id desc')->page($where['page'],$where['limit'])->select();
  77. foreach ($data as &$v)
  78. {
  79. $v['is_apply'] = HelpApply::where('help_id',$v['id'])->where('user_id',$where['user_id_1'])->find();
  80. $v['apply_sum'] = HelpApply::where('help_id',$v['id'])->value('count(id)')?:0;
  81. $v['category'] = Category::where('id',$v['category_id'])->value('name');
  82. if($v['apply_user_id']>0)
  83. {
  84. $v['apply_user'] = HelpApply::where('help_id',$v['id'])->where('user_id',$v['apply_user_id'])->find();
  85. }
  86. else
  87. {
  88. $v['apply_user'] = null;
  89. }
  90. }
  91. return $data;
  92. }
  93. public static function info($cid,$id,$user_id=0)
  94. {
  95. $info = self::where('cid',$cid)->where('id',$id)->find();
  96. if(!$info)return self::setErrorInfo('非法数据');
  97. $info['ext'] = HelpExt::where('help_id',$info['id'])->find();
  98. $info['family'] = HelpFamily::where('help_id',$info['id'])->select();
  99. $info['lave'] = Lave::lst(['cid'=>$cid,'paid'=>1,'help_id'=>$info['id'],'page'=>1,'limit'=>99999]);
  100. $info['sum_lave'] = Lave::where(['cid'=>$cid,'paid'=>1,'help_id'=>$id])->sum('amount');
  101. $info['is_apply'] = HelpApply::where('help_id',$info['id'])->where('user_id',$user_id)->find();
  102. $info['apply_sum'] = HelpApply::where('help_id',$info['id'])->value('count(id)')?:0;
  103. $info['category'] = Category::where('id',$info['category_id'])->value('name');
  104. return $info;
  105. }
  106. }