Project.php 5.3 KB

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