Donate.php 2.4 KB

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