Donate.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_relation',''],
  28. ['executor_id_card',''],
  29. ['executor_tel',''],
  30. ['executor_mobile',''],
  31. ],$request
  32. );
  33. if($where['full_name']=='')$this->error('姓名不能为空');
  34. if(IdentityCard::isValid($where['id_card']))$this->error('身份证号不正确!');
  35. if($where['vocation']=='')$this->error('职业不能为空');
  36. if($where['category_ids']=='')$this->error('捐献类型不能空');
  37. if($where['executor_relation']=='')$this->error('执行人关系');
  38. if(!preg_match("/^1\d{10}$/", $where['mobile'])) $this->error('手机号不对');
  39. if(!preg_match("/^1\d{10}$/", $where['executor_mobile'])) $this->error('执行人移动电话不对');
  40. if(IdentityCard::isValid($where['executor_id_card']))$this->error('执行人身份证号不正确!');
  41. $this->success(DonateModel::create($where));
  42. }
  43. public function ify(Request $request)
  44. {
  45. $this->success('获取成功',Category::getCategoryArray('donate'));
  46. }
  47. public function lst(Request $request)
  48. {
  49. $where = UtilService::getMore(
  50. [
  51. ['cid',$this->cid],
  52. ['user_id',$this->auth->getUserinfo()['id']],
  53. ['page',1],
  54. ['limit',10],
  55. ['status',-2],
  56. ]
  57. );
  58. return $this->success('获取成功',DonateModel::lst($where));
  59. }
  60. public function view()
  61. {
  62. $id = input('id',0);
  63. if($id==0) $this->error('参数错误!');
  64. $rs = DonateModel::info($id);
  65. if(!$rs)$this->error(HelpModel::getErrorInfo());
  66. return $this->success('获取成功',$rs);
  67. }
  68. }