Project.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\project\ProjectDonation;
  5. use app\common\model\project\ProjectDonationOrder;
  6. use app\common\model\project\ProjectDonationRocord;
  7. use app\common\model\project\ProjectDonationUser;
  8. use think\Request;
  9. use liuniu\UtilService;
  10. class Project extends Api
  11. {
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 获取捐赠列表
  15. * @param Request $request
  16. */
  17. public function lst(Request $request)
  18. {
  19. $where = UtilService::getMore([
  20. ['status',-2],
  21. ['page',1],
  22. ['limit',10],
  23. ['cid',$this->cid],
  24. ],$request);
  25. $this->success('获取成功',ProjectDonation::lst($where));
  26. }
  27. /**
  28. * 获取捐赠详情
  29. * @param Request $request
  30. */
  31. public function info(Request $request)
  32. {
  33. $id = input('id',0);
  34. $info = ProjectDonation::info($id)->toArray();
  35. if(!$info) return $this->error('此捐赠不存在!');
  36. $this->success('获取成功',$info);
  37. }
  38. /**
  39. * 获取我的捐赠
  40. * @param $where
  41. */
  42. public function myorder(Request $request)
  43. {
  44. $where = UtilService::postMore([
  45. ['status',-2],
  46. ['page',1],
  47. ['limit',10],
  48. ['all',0],
  49. ],$request);
  50. $where['uid'] = $this->auth->getUserinfo()['id'];
  51. $this->success('获取成功',ProjectDonationOrder::lst($where));
  52. }
  53. /**
  54. * 获取所有状态
  55. * @param Request $request
  56. */
  57. public function bill(Request $request)
  58. {
  59. list($project_id,$page,$limit,$type) = UtilService::postMore([
  60. ['project_id',0],
  61. ['page',1],
  62. ['limit',10],
  63. ['type',''],
  64. ],$request,true);
  65. $this->success('获取成功',ProjectDonationRocord::getbill($project_id,$type,$page,$limit));
  66. }
  67. /**
  68. * 活动捐赠
  69. * @param Request $request
  70. * @return mixed
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\DbException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. */
  75. public function all_order(Request $request)
  76. {
  77. $where = UtilService::postMore([
  78. ['status',-2],
  79. ['page',1],
  80. ['limit',10],
  81. ['all',1],
  82. ['project_id',0],
  83. ],$request);
  84. $where['uid'] = $this->auth->getUserinfo()['id'];
  85. $where['cid'] = $this->cid;
  86. $this->success('获取成功',ProjectDonationOrder::lst($where));
  87. }
  88. /**
  89. * 创建捐赠
  90. * @param Request $request
  91. */
  92. public function order_create(Request $request)
  93. {
  94. $where = UtilService::postMore([
  95. ['name',''],
  96. ['project_id',0],
  97. ['project_user_id',0],
  98. ['matter',''],
  99. ['qc',''],
  100. ['worth',''],
  101. ['item',[]],
  102. ['logistics',''],
  103. ],$request);
  104. if(empty($where['name'])) $this->error('名称不能为空!');
  105. if($where['project_user_id']<1) $this->error('用户不能为空!');
  106. if(sizeof($where['item'])==0) $this->error('捐赠物资不能为空!');
  107. $where['uid'] = $this->auth->getUserinfo()['id'];
  108. $where['cid'] = $this->cid;
  109. $order = ProjectDonationOrder::create_order($where);
  110. if ($order === false) return $this->error(ProjectDonationOrder::getErrorInfo('订单生成失败'));
  111. return app('json')->successful($order);
  112. }
  113. /**
  114. * 获取订单详情
  115. * @param Request $request
  116. */
  117. public function order_info(Request $request)
  118. {
  119. $id = input('id',0);
  120. $this->success('获取成功',ProjectDonationOrder::info($id));
  121. }
  122. /**
  123. * 创建用户
  124. * @param Request $request
  125. */
  126. public function create_user(Request $request)
  127. {
  128. $where = UtilService::postMore([
  129. ['name',''],
  130. ['card_id',''],
  131. ['phone',''],
  132. ['tel',''],
  133. ['contacts',''],
  134. ['anonymous',0],
  135. ['invoice',0],
  136. ['user_type',0],
  137. ['logistics',''],
  138. ],$request);
  139. $where['uid'] = $this->auth->getUserinfo()['id'];
  140. $id = input('id',0);
  141. if($where['user_type']==0)
  142. {
  143. if(empty($where['name'])) $this->error('姓名不能为空!');
  144. if(empty($where['phone'])) $this->error('联系方式不能为空!');
  145. }
  146. else
  147. {
  148. if(empty($where['name'])) $this->error('单位不能为空!');
  149. if(empty($where['contacts'])) $this->error('联系人不能为空!');
  150. if(empty($where['tel'])) $this->error('单位电话不能为空!');
  151. }
  152. if(empty($where['logistics'])) $this->error('物流类型不能为空!');
  153. if($id==0)
  154. {
  155. $rs = ProjectDonationUser::create($where);
  156. }
  157. else
  158. {
  159. $rs = ProjectDonationUser::where('id')->update($where);
  160. }
  161. $this->success('获取成功',$rs);
  162. }
  163. /**
  164. * 获取用户列表
  165. * @param Request $request
  166. */
  167. public function user_list(Request $request)
  168. {
  169. $where = UtilService::getMore([
  170. ['type',0],
  171. ],$request);
  172. $where['uid'] = $this->auth->getUserinfo()['id'];
  173. return $this->success('获取成功',ProjectDonationUser::where($where)->select());
  174. }
  175. }