Project.php 5.5 KB

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