Join.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\Fishery;
  4. use app\admin\model\Third;
  5. use app\admin\model\User;
  6. use app\admin\model\UserMoneyRecharge;
  7. use app\common\controller\Api;
  8. use think\Db;
  9. use think\Exception;
  10. use think\exception\ErrorException;
  11. /**
  12. * 加盟-塘主-渔场主
  13. * @ApiWeigh (5)
  14. * @package app\api\controller
  15. */
  16. class Join extends Api
  17. {
  18. protected $noNeedLogin = [];
  19. protected $noNeedRight = ['*'];
  20. /**
  21. * 申请入驻塘主or渔场主
  22. * @ApiMethod (POST)
  23. * @ApiParams (name=type, type="int", required=true,description="类型:1=塘主,2=渔场主")
  24. * @ApiParams (name=certificates_type, type="string", required=true,description="证件类型:营业执照/租赁资格证")
  25. * @ApiParams (name=certificates_image,type="string", required=true,,description="证件图片")
  26. * @ApiParams (name=cover_image,type="string", required=true,description="封面图")
  27. * @ApiParams (name=video,type="string", required=true,description="视频")
  28. * @ApiParams (name=province_id,type="int", required=true,description="省")
  29. * @ApiParams (name=city_id,type="int", required=true,description="市")
  30. * @ApiParams (name=area_id,type="int", required=true,description="区")
  31. * @ApiParams (name=address,type="string", required=true,description="详细地址")
  32. * @ApiParams (name=lng,type="string", required=true,description="经度")
  33. * @ApiParams (name=lat,type="string", required=true,description="纬度")
  34. * @ApiParams (name=fish_name,type="string", required=true,description="鱼塘名称")
  35. * @ApiParams (name=name,type="string", required=true,description="姓名")
  36. * @ApiParams (name=phone,type="string", required=true,description="联系方式")
  37. */
  38. public function apply()
  39. {
  40. $user_id = $this->auth->id;
  41. $input = input();
  42. if (empty($input['type']) || empty($input['certificates_type']) || empty($input['certificates_image']) || empty($input['province_id']) || empty($input['city_id']) || empty($input['area_id']) || empty($input['address']) || empty($input['lng']) || empty($input['lat']) || empty($input['name']) || empty($input['phone'])) {
  43. $this->error('请完善信息');
  44. }
  45. if ($input['type'] != 1 && $input['type'] != 2) {
  46. $this->error('参数错误');
  47. }
  48. // 申请塘主时
  49. if ($input['type'] == 1 && (empty($input['cover_image']) || empty($input['video']) || empty($input['fish_name']))) {
  50. $this->error('请完善信息');
  51. }
  52. $suppliers_model = new Fishery();
  53. // 检查是否申请过
  54. $info = $suppliers_model::get(['user_id' => $user_id, 'type' => $input['type']]);
  55. if ($info) {
  56. $this->error('已提交过申请,不能重复提交');
  57. }
  58. $data = [
  59. 'user_id' => $user_id,
  60. 'type' => $input['type'],
  61. 'certificates_type' => $input['certificates_type'],
  62. 'certificates_image' => $input['certificates_image'],
  63. 'cover_image' => array_key_exists('cover_image', $input) ? $input['cover_image'] : '',
  64. 'video' => array_key_exists('video', $input) ? $input['video'] : '',
  65. 'province_id' => $input['province_id'],
  66. 'city_id' => $input['city_id'],
  67. 'area_id' => $input['area_id'],
  68. 'city' => city_name($input['province_id']) . city_name($input['city_id']) . city_name($input['area_id']),
  69. 'address' => $input['address'],
  70. 'lng' => $input['lng'],
  71. 'lat' => $input['lat'],
  72. 'fish_name' => array_key_exists('fish_name', $input) ? $input['fish_name'] : '',
  73. 'name' => $input['name'],
  74. 'phone' => $input['phone'],
  75. 'pay_money' => config('site.fishery_pond')
  76. ];
  77. Db::startTrans();
  78. try {
  79. $suppliers_model->save($data);
  80. //更新用户表
  81. if ($input['type'] == 1) {
  82. $user_data['is_pond'] = 1;
  83. } else {
  84. $user_data['is_fishery'] = 1;
  85. }
  86. $user_model = new User();
  87. $user_model->save($user_data, ['id' => $user_id]);
  88. Db::commit();
  89. $this->success('申请成功,请耐心等待审核');
  90. } catch (ErrorException $e) {
  91. Db::rollback();
  92. $this->error('申请失败,请稍后重试');
  93. }
  94. }
  95. /**
  96. * 申请入驻-查看
  97. * @ApiMethod (POST)
  98. * @ApiParams (name=type, type="int", required=true,description="类型:1=塘主,2=渔场主")
  99. * @ApiReturnParams (name=has_apply, type="bool", required=true,description="true=有申请信息,false=没有申请信息")
  100. * @ApiReturnParams (name=detail, type="object", required=true,description="详细信息,参数见apply接口")
  101. * @ApiReturnParams (name=detail.status, type="int", required=true,description="状态:1=审核中,2=审核通过,3=审核失败,4缴费成功")
  102. * @ApiReturnParams (name=detail.refusal_reason, type="string", required=true,description="审核失败理由")
  103. * @ApiReturn ({"code":1,"msg":"ok","time":"1672390281","data":{"has_apply":true,"detail":{"id":3,"type":1,"user_id":3,"certificates_type":"营业执照","certificates_image":"11","cover_image":"1","video":"111","province_id":1,"city_id":2,"area_id":4,"city":"北京市北京市北京市","address":"address","lng":"123.1","lat":"40.5","fish_name":"余名","name":"佚名","phone":"13161001120","status":1,"refusal_reason":null,"createtime":1672387969,"updatetime":1672387969,"deletetime":null,"logout":0,"logout_reason":null,"pay_time":0,"pay_no":"","pay_money":"0.00","type_text":"Type 1","status_text":"Status 1","logout_text":""}}})
  104. */
  105. public function apply_detail()
  106. {
  107. $user_id = $this->auth->id;
  108. $input = input();
  109. if (empty($input['type'])) {
  110. $this->error('请完善信息');
  111. }
  112. if ($input['type'] != 1 && $input['type'] != 2) {
  113. $this->error('参数错误');
  114. }
  115. $fishery_model = new Fishery();
  116. // 申请的信息
  117. $info = $fishery_model::get(['user_id' => $user_id, 'type' => $input['type']]);
  118. $this->success('ok', ['has_apply' => !empty($info), 'detail' => $info]);
  119. }
  120. /**
  121. * 重新申请入驻塘主or渔场主
  122. * @ApiMethod (POST)
  123. * @ApiParams (name=id, type="int", required=true,description="申请id")
  124. * @ApiParams (name=type, type="int", required=true,description="类型:1=塘主,2=渔场主")
  125. * @ApiParams (name=certificates_type, type="string", required=true,description="证件类型:营业执照/租赁资格证")
  126. * @ApiParams (name=certificates_image,type="string", required=true,,description="证件图片")
  127. * @ApiParams (name=cover_image,type="string", required=true,description="封面图")
  128. * @ApiParams (name=video,type="string", required=true,description="视频")
  129. * @ApiParams (name=province_id,type="int", required=true,description="省")
  130. * @ApiParams (name=city_id,type="int", required=true,description="市")
  131. * @ApiParams (name=area_id,type="int", required=true,description="区")
  132. * @ApiParams (name=address,type="string", required=true,description="详细地址")
  133. * @ApiParams (name=lng,type="string", required=true,description="经度")
  134. * @ApiParams (name=lat,type="string", required=true,description="纬度")
  135. * @ApiParams (name=fish_name,type="string", required=true,description="鱼塘名称")
  136. * @ApiParams (name=name,type="string", required=true,description="姓名")
  137. * @ApiParams (name=phone,type="string", required=true,description="联系方式")
  138. */
  139. public function re_apply()
  140. {
  141. $user_id = $this->auth->id;
  142. $input = input();
  143. if (empty($input['type']) || empty($input['certificates_type']) || empty($input['certificates_image']) || empty($input['province_id']) || empty($input['city_id']) || empty($input['area_id']) || empty($input['address']) || empty($input['lng']) || empty($input['lat']) || empty($input['name']) || empty($input['phone'])) {
  144. $this->error('请完善信息');
  145. }
  146. if ($input['type'] != 1 && $input['type'] != 2) {
  147. $this->error('参数错误');
  148. }
  149. // 申请塘主时
  150. if ($input['type'] == 1 && (empty($input['cover_image']) || empty($input['video']) || empty($input['fish_name']))) {
  151. $this->error('请完善信息');
  152. }
  153. $suppliers_model = new Fishery();
  154. // 检查申请信息
  155. $info = $suppliers_model::get(['id' => $input['id'], 'user_id' => $user_id, 'type' => $input['type']]);
  156. if (!$info) {
  157. $this->error('信息不存在,不能重新申请');
  158. }
  159. $data = [
  160. 'certificates_type' => $input['certificates_type'],
  161. 'certificates_image' => $input['certificates_image'],
  162. 'cover_image' => array_key_exists('cover_image', $input) ? $input['cover_image'] : '',
  163. 'video' => array_key_exists('video', $input) ? $input['video'] : '',
  164. 'province_id' => $input['province_id'],
  165. 'city_id' => $input['city_id'],
  166. 'area_id' => $input['area_id'],
  167. 'city' => city_name($input['province_id']) . city_name($input['city_id']) . city_name($input['area_id']),
  168. 'address' => $input['address'],
  169. 'lng' => $input['lng'],
  170. 'lat' => $input['lat'],
  171. 'fish_name' => array_key_exists('fish_name', $input) ? $input['fish_name'] : '',
  172. 'name' => $input['name'],
  173. 'phone' => $input['phone'],
  174. 'status' => 1,
  175. 'logout_status'=>1,
  176. 'refusal_reason' => "",
  177. ];
  178. Db::startTrans();
  179. try {
  180. $suppliers_model->save($data, ['id' => $input['id']]);
  181. //更新用户表
  182. if ($input['type'] == 1) {
  183. $user_data['is_pond'] = 1;
  184. } else {
  185. $user_data['is_fishery'] = 1;
  186. }
  187. $user_model = new User();
  188. $user_model->save($user_data, ['id' => $user_id]);
  189. Db::commit();
  190. $this->success('申请成功,请耐心等待审核');
  191. } catch (ErrorException $e) {
  192. Db::rollback();
  193. $this->error('申请失败,请稍后重试');
  194. }
  195. }
  196. /**
  197. * 缴费
  198. * @ApiMethod (POST)
  199. * @ApiParams (name="type",type="string", required=true,description="充值类型:wechat=微信,alipay=支付宝")
  200. * @ApiParams (name="mod",type="string", required=true,description="支付方法:web、wap、app、scan、pos、mp、miniapp")
  201. */
  202. public function payment()
  203. {
  204. $money = config('site.fishery_pond');
  205. if ($money <= 0) {
  206. $this->error('请联系平台设置缴费金额');
  207. }
  208. $type = $this->request->post('type');
  209. if ($type != 'wechat' && $type != 'alipay') {
  210. $this->error('请选择支付类型');
  211. }
  212. $method = $this->request->post('mod');
  213. $fishery_model = new Fishery();
  214. $fishery_info = $fishery_model->where('user_id', $this->auth->id)
  215. ->where('type', 1)
  216. ->whereIn('status', [2, 5])
  217. ->find();
  218. if (!$fishery_info) {
  219. $this->error('提交的申请不存在');
  220. }
  221. // 订单号
  222. $orderid = 'RZ' . order_no_s($this->auth->id);
  223. Db::startTrans();
  224. try {
  225. $data = [
  226. 'pay_money' => $money,//更新缴费金额
  227. 'pay_no' => $orderid,
  228. 'status' => 5
  229. ];
  230. $fishery_info->save($data);
  231. Db::commit();
  232. } catch (Exception $e) {
  233. Db::rollback();
  234. $this->error($e);
  235. }
  236. $openID = '';
  237. if ($type == 'wechat'&&$method!='app') {
  238. $third_model = new Third();
  239. $openID = $third_model->where('user_id', $this->auth->id)->where('platform', 'xcc')->value('openid');
  240. if ($openID == '') {
  241. $this->error("openid");
  242. }
  243. }
  244. $params = [
  245. 'amount' => $money,
  246. 'orderid' => $orderid,
  247. 'type' => $type,
  248. 'title' => "塘主(" . $fishery_info->id . ")支付入驻资金",
  249. 'notifyurl' => common_url() . '/index.php/api/Notify/fishery_notify/type/' . $type,
  250. 'returnurl' => common_url() . '/index.php/api/Notify/fishery_notify/type/' . $type . '/out_trade_no/' . $orderid,
  251. 'method' => $method,
  252. 'openid' => $openID,
  253. ];
  254. $pay = \addons\epay\library\Service::submitOrder($params);
  255. $this->success('ok', $pay);
  256. }
  257. /**
  258. * 账户注销-提交
  259. * @ApiMethod (POST)
  260. * @ApiParams (name=logout_reason,type="string", required=true,description="账户注销理由")
  261. * @ApiParams (name=logout_type,type="string", required=true,description="类型:1=塘主,2=渔场主")
  262. */
  263. public function user_logout()
  264. {
  265. $logout_reason = $this->request->post('logout_reason');
  266. $logout_type = $this->request->post('logout_type');
  267. if ($logout_reason == "" || $logout_type == '') {
  268. $this->error(__('Invalid parameters'));
  269. }
  270. $suppliers_model = new Fishery();
  271. // 检查申请信息
  272. if($logout_type==1){
  273. $status = 4;
  274. }
  275. else{
  276. $status=2;
  277. }
  278. $info = $suppliers_model::get(['user_id' => $this->auth->id, 'type' => $logout_type, 'status' => $status]);
  279. if (!$info) {
  280. $this->error('申请信息不存在');
  281. }
  282. $info->logout = 1;
  283. $info->logout_reason = $logout_reason;
  284. $info->logout_status = 1;
  285. $info->save();
  286. $this->success('成功');
  287. }
  288. }