Donate.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\{Category,Donate as DonateModel};
  5. use liuniu\IdentityCard;
  6. use liuniu\UtilService;
  7. use think\Request;
  8. class Donate extends Api
  9. {
  10. public function apply(Request $request)
  11. {
  12. $where = UtilService::postMore(
  13. [
  14. ['cid',$this->cid],
  15. ['user_id',$this->auth->getUserinfo()['id']],
  16. ['full_name',''],
  17. ['sex',0],
  18. ['birthday',date("Y-m-d")],
  19. ['id_card',''],
  20. ['vocation',''],
  21. ['education',0],
  22. ['category_ids',0],
  23. ['tel',''],
  24. ['mobile',''],
  25. ['executor',''],
  26. ['executor_id_card',''],
  27. ['executor_tel',''],
  28. ['executor_mobile',''],
  29. ],$request
  30. );
  31. if($where['full_name']=='')$this->error('姓名不能为空');
  32. if(IdentityCard::isValid($where['id_card']))$this->error('身份证号不正确!');
  33. if($where['vocation']=='')$this->error('职业不能为空');
  34. if($where['category_ids']=='')$this->error('捐献类型不能空');
  35. if(!preg_match("/^1\d{10}$/", $where['mobile'])) $this->error('手机号不对');
  36. if(!preg_match("/^1\d{10}$/", $where['executor_mobile'])) $this->error('执行人移动电话不对');
  37. if(IdentityCard::isValid($where['executor_id_card']))$this->error('执行人身份证号不正确!');
  38. $this->success(DonateModel::create($where));
  39. }
  40. public function ify(Request $request)
  41. {
  42. $this->success('获取成功',Category::getCategoryArray('donate'));
  43. }
  44. public function lst(Request $request)
  45. {
  46. $where = UtilService::getMore(
  47. [
  48. ['cid',$this->cid],
  49. ['user_id',$this->auth->getUserinfo()['id']],
  50. ['page',1],
  51. ['limit',10],
  52. ['status',-2],
  53. ]
  54. );
  55. return $this->success('获取成功',DonateModel::lst($where));
  56. }
  57. public function view()
  58. {
  59. $id = input('id',0);
  60. if($id==0) $this->error('参数错误!');
  61. $rs = DonateModel::info($id);
  62. if(!$rs)$this->error(HelpModel::getErrorInfo());
  63. return $this->success('获取成功',$rs);
  64. }
  65. }