Member.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018-2020 rights reserved.
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // | Date: 2020-08-31 20:43
  10. // +----------------------------------------------------------------------
  11. namespace app\system\controller;
  12. use app\BaseController;
  13. use app\lib\OrderLib;
  14. use app\model\api\PayTrade;
  15. use library\utils\WxpayV2 as wxpayApi;
  16. use app\model\api\User as UserModel;
  17. use app\model\api\UserDetail as UserDetailModel;
  18. use app\model\api\UserScoreDetail as UserScoreDetailModel;
  19. use library\services\UtilService;
  20. use app\Request;
  21. use think\facade\Db;
  22. class Member extends BaseController
  23. {
  24. /**
  25. * 会员列表
  26. * @param Request $request
  27. * @return mixed
  28. */
  29. public function list(Request $request)
  30. {
  31. $pageSize = 50;
  32. $post = UtilService::getMore([
  33. ['page',1],
  34. ['nickname',''],
  35. ['uid',''],
  36. ['parent_uid',''],
  37. ['mobile',''],
  38. ['status',''],
  39. ['time',[]],
  40. ],$request);
  41. $where = [];
  42. //创建时间
  43. $startTime="";
  44. $endTime="";
  45. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  46. $startTime = strtotime($post['time'][0]);
  47. $endTime = strtotime($post['time'][1]);
  48. $where[]=["u.regtime","between","{$startTime},{$endTime}"];
  49. }
  50. if(!empty($post['nickname'])){
  51. $where[]=["u.nickname","like","%{$post['nickname']}%"];
  52. }
  53. if(!empty($post['uid'])){
  54. $where[]=["u.uid","=",$post['uid']];
  55. }
  56. if(!empty($post['mobile'])){
  57. $where[]=["u.mobile","=",$post['mobile']];
  58. }
  59. if(!empty($post['parent_uid'])){
  60. $where[]=["u.parent_uid","=",$post['parent_uid']];
  61. }
  62. if(in_array((string)$post["status"],['1','0','-1'])){
  63. $where[]=["u.status","=",(int)$post["status"]];
  64. }
  65. $data = (new UserModel)
  66. ->field("u.uid,u.nickname,u.name,u.regtime,u.score,u.money,u.status,u.avatar,u.mobile,u.parent_uid"
  67. . ",p.nickname as p_nickname,p.mobile as p_mobile"
  68. . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount")
  69. ->alias("u")
  70. ->leftJoin("user p","p.uid = u.parent_uid")
  71. ->where($where)
  72. ->page((int)$post["page"], (int)$pageSize)
  73. ->order("u.uid","desc")
  74. ->select()
  75. ->toArray();
  76. $pageCount = (new UserModel)->alias("u")->where($where)->count();
  77. $data = empty($data)?[]:$data;
  78. foreach($data as $k=>$v){
  79. $data[$k]["regtime"] = date("Y-m-d H:i:s",$v["regtime"]);
  80. $data[$k]["mobile"] = empty($v["mobile"])?"未绑定":$v["mobile"];
  81. $data[$k]["p_mobile"] = empty($v["mobile"])?"未绑定":$v["p_mobile"];
  82. }
  83. return app('json')->success([
  84. 'list' => $data,
  85. 'pageCount' => $pageCount,
  86. 'pageSize' => $pageSize,
  87. 'page' => $post["page"],
  88. ]);
  89. }
  90. /**
  91. * 编辑
  92. */
  93. public function save(Request $request){
  94. $post = UtilService::getMore([
  95. ['uid','0'],
  96. ['status',''],
  97. ['name',''],
  98. ['nickname',''],
  99. ],$request);
  100. $uid = (int)$post["uid"];
  101. if(empty($uid)){
  102. return app('json')->fail("参数错误");
  103. }
  104. unset($post["uid"]);
  105. $r=0;
  106. if(!in_array((string)$post["status"],['1','-1'])){
  107. return app('json')->success("状态错误");
  108. }
  109. //用户信息
  110. $save=[];
  111. $save["status"] = $post["status"];
  112. if(!empty($post["name"])){
  113. $save["name"] = $post["name"];
  114. }
  115. if(!empty($post["nickname"])){
  116. $save["nickname"] = $post["nickname"];
  117. }
  118. $r = (new UserModel)->where("uid",$uid)->update($save);
  119. return app('json')->success("数据保存成功");
  120. }
  121. /**
  122. * 会员收益明细列表
  123. * @param Request $request
  124. * @return mixed
  125. */
  126. public function moneyDetail (Request $request)
  127. {
  128. $pageSize = 50;
  129. $post = UtilService::getMore(
  130. [
  131. ['page', '1'],
  132. ['uid', '0'],
  133. ['mobile', ''],
  134. ['time', []],
  135. ['type', ''],
  136. ['code', ''],
  137. ], $request
  138. );
  139. $where = [];
  140. if (!empty($post['uid'])){
  141. $where[]=["d.uid","=",$post['uid']];
  142. }
  143. if (!empty($post['mobile'])) {
  144. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  145. if(!empty($m)) {
  146. $where[]=["d.uid","=",$m['uid']];
  147. }
  148. }
  149. $startTime = "";
  150. $endTime = "";
  151. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  152. $startTime = strtotime($post['time'][0]);
  153. $endTime = strtotime($post['time'][1]);
  154. $where[]=["d.time","between","{$startTime},{$endTime}"];
  155. }
  156. if (!empty($post['type']) && in_array(strval($post['type']), ["1","-1"])) {
  157. $where[]=["d.type","=",$post['type']];
  158. }
  159. if(!empty($post['code']) && $post['code']!="all"){
  160. $where[]=["d.code","=",$post['code']];
  161. }
  162. $data = (new UserDetailModel)
  163. ->alias("d")
  164. ->field("d.*,u.mobile")
  165. ->leftJoin("user u", "u.uid = d.uid")
  166. ->where($where)
  167. ->page((int)$post["page"], $pageSize)
  168. ->order("d.id","desc")
  169. ->select()
  170. ->toArray();
  171. $pageCount = (new UserDetailModel)->alias("d")->where($where)->count();
  172. foreach($where as $k=>$v){
  173. if($v[0]=="d.type"){
  174. array_splice($where,$k,1);
  175. }
  176. }
  177. //收入
  178. $inWhere = $where;
  179. $inWhere[]=["d.type","=",1];
  180. $inTotal = (new UserDetailModel)->alias("d")->where($inWhere)->sum("d.into");
  181. //支出
  182. $outWhere = $where;
  183. $outWhere[]=["d.type","=",-1];
  184. $outTotal = (new UserDetailModel)->alias("d")->where($outWhere)->sum("d.into");
  185. $result = UtilService::getParam(
  186. [
  187. 'id',
  188. 'uid',
  189. 'mobile',
  190. 'title',
  191. 'content',
  192. 'type',
  193. 'into',
  194. 'money',
  195. ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
  196. ], $data);
  197. return app('json')->success([
  198. 'list' => $result,
  199. 'pageCount' => $pageCount,
  200. 'pageSize' => $pageSize,
  201. 'page' => $post['page'],
  202. 'inTotal' => empty($inTotal) ? 0 : floatval($inTotal),
  203. 'outTotal' => empty($outTotal)? 0 : floatval($outTotal),
  204. ]);
  205. }
  206. /**
  207. * 收益增/减
  208. * @param Request $request
  209. */
  210. public function moneyDetailSave(Request $request)
  211. {
  212. $post = UtilService::getMore([
  213. ['uid', '', 'empty', '参数错误'],
  214. ['type', '1'],
  215. ['into', '0', 'gt|0', '输入值错误'],
  216. ['othen', ''],
  217. ], $request);
  218. $userData = (new UserModel)->where("uid",$post["uid"])->find();
  219. if(empty($userData)){
  220. return app('json')->fail('用户不存在,请输入正确的用户uid');
  221. }
  222. if(!in_array((string)$post["type"],["1","-1"])){
  223. return app('json')->fail('请选择增减');
  224. }
  225. $post["into"] = bcadd("0",$post["into"],2);
  226. if(!is_numeric($post["into"]) || $post["into"]<=0){
  227. return app('json')->fail('请输入正确的金额');
  228. }
  229. if ($post['type'] == 1)
  230. $bool = (new UserDetailModel)->adminAddMoney($userData['uid'], $post['into'], $request->adminInfo['id'],$post['othen']);
  231. if ($post['type'] == -1){
  232. if($userData["money"]-$post['into']<0){
  233. return app('json')->fail('余额不足');
  234. }
  235. $bool = (new UserDetailModel)->adminCutMoney($userData['uid'], $post['into'], $request->adminInfo['id'],$post['othen']);
  236. }
  237. if ($bool)
  238. return app('json')->success('操作成功');
  239. else
  240. return app('json')->fail('操作失败');
  241. }
  242. /**
  243. * 钻石收益明细列表
  244. * @param Request $request
  245. * @return mixed
  246. */
  247. public function scoreDetail (Request $request)
  248. {
  249. $pageSize = 50;
  250. $post = UtilService::getMore(
  251. [
  252. ['page', '1'],
  253. ['uid', '0'],
  254. ['mobile', ''],
  255. ['type', ''],
  256. ['code', ''],
  257. ['time', []],
  258. ], $request
  259. );
  260. $where = [];
  261. if (!empty($post['uid'])){
  262. $where[]=["d.uid","=",$post['uid']];
  263. }else if (!empty($post['mobile'])) {
  264. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  265. if(!empty($m)) {
  266. $where[]=["d.uid","=",$m['uid']];
  267. }
  268. }
  269. $startTime = "";
  270. $endTime = "";
  271. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  272. $startTime = strtotime($post['time'][0]);
  273. $endTime = strtotime($post['time'][1]);
  274. $where[]=["d.time","between","{$startTime},{$endTime}"];
  275. }
  276. if (!empty($post['type']) && in_array(strval($post['type']), ["1","-1"])) {
  277. $where[]=["d.type","=",$post['type']];
  278. }
  279. if (!empty($post['code'])) {
  280. $where[]=["d.code","=",$post['code']];
  281. }
  282. $data = (new UserScoreDetailModel)
  283. ->alias("d")
  284. ->field("d.*,u.mobile")
  285. ->leftJoin("user u", "u.uid = d.uid")
  286. ->where($where)
  287. ->page((int)$post["page"], $pageSize)
  288. ->order("d.id","desc")
  289. ->select()
  290. ->toArray();
  291. $pageCount = (new UserScoreDetailModel)->alias("d")->where($where)->count();
  292. foreach($where as $k=>$v){
  293. if($v[0]=="d.type"){
  294. array_splice($where,$k,1);
  295. }
  296. }
  297. //收入
  298. $inWhere = $where;
  299. $inWhere[]=["d.type","=",1];
  300. $inTotal = (new UserScoreDetailModel)->alias("d")->where($inWhere)->sum("d.v");
  301. //支出
  302. $outWhere = $where;
  303. $outWhere[]=["d.type","=",-1];
  304. $outTotal = (new UserScoreDetailModel)->alias("d")->where($outWhere)->sum("d.v");
  305. $result = UtilService::getParam(
  306. [
  307. 'id',
  308. 'uid',
  309. 'mobile',
  310. 'title',
  311. 'content',
  312. 'type',
  313. ['into','v'],
  314. 'money',
  315. ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
  316. ], $data);
  317. return app('json')->success([
  318. 'list' => $result,
  319. 'pageCount' => $pageCount,
  320. 'pageSize' => $pageSize,
  321. 'page' => $post['page'],
  322. 'inTotal' => empty($inTotal) ? 0 : floatval($inTotal),
  323. 'outTotal' => empty($outTotal)? 0 : floatval($outTotal),
  324. ]);
  325. }
  326. /**
  327. * 积分增/减
  328. * @param Request $request
  329. */
  330. public function scoreDetailSave(Request $request)
  331. {
  332. $post = UtilService::getMore([
  333. ['uid', '', 'empty', '参数错误'],
  334. ['type', '1'],
  335. ['into', '0', 'gt|0', '输入值错误'],
  336. ['othen', ''],
  337. ], $request);
  338. $userData = (new UserModel)->where("uid",$post["uid"])->find();
  339. if(empty($userData)){
  340. return app('json')->fail('用户不存在,请输入正确的用户uid');
  341. }
  342. if ($post['type'] == 1)
  343. $bool = (new UserScoreDetailModel)->adminAddMoney($userData['uid'], intval($post['into']), $request->adminInfo['id'],$post['othen']);
  344. if ($post['type'] == -1){
  345. if($userData["score"]-$post['into']<0){
  346. return app('json')->fail('剩余积分不足');
  347. }
  348. $bool = (new UserScoreDetailModel)->adminCutMoney($userData['uid'], intval($post['into']), $request->adminInfo['id'],$post['othen']);
  349. }
  350. if ($bool)
  351. return app('json')->success('操作成功');
  352. else
  353. return app('json')->fail('操作失败');
  354. }
  355. /**
  356. * 获取会员数据
  357. * @param Request $request
  358. * @return mixed
  359. */
  360. public function getItem(Request $request)
  361. {
  362. $post = UtilService::getMore([
  363. ['uid', 1],
  364. ]);
  365. $data = (new UserModel)
  366. ->alias("u")
  367. ->field("u.uid,u.mobile,u.nickname,u.avatar,u.status,u.regtime,u.lasttime,u.parent_uid.p.nickname as parent_nickname")
  368. ->leftJoin("user p","p.uid = u.parent_uid")
  369. ->where("u.uid",$post["uid"])
  370. ->find()
  371. ->toArray();
  372. if(!empty($data)){
  373. $data["regtime"] = date("Y-m-d H:i:s",$data["regtime"]);
  374. $data["lasttime"] = date("Y-m-d H:i:s",$data["lasttime"]);
  375. }
  376. return app('json')->success(empty($data) ? [] : $data);
  377. }
  378. public function shopSave(Request $request){
  379. $post = UtilService::getMore([
  380. ['id','','empty','参数错误'],
  381. ['name','','empty','请输入名称'],
  382. ['tel','','empty','请输入联系电话'],
  383. ['lx_name','','empty','请输入联系人'],
  384. ['address','','empty','请输入门店地址'],
  385. ['longitude',''],
  386. ['latitude',''],
  387. ['is_show',''],
  388. ],$request);
  389. $id = (int)$post["id"];
  390. if(empty($id)){
  391. return app('json')->fail("参数错误");
  392. }
  393. unset($post["id"]);
  394. $shopSave=[
  395. "name" => $post["name"],
  396. "tel" => $post["tel"],
  397. "address" => $post["address"],
  398. "lx_name" => $post["lx_name"],
  399. "longitude" => $post["longitude"],
  400. "latitude" => $post["latitude"],
  401. "is_show" => $post["is_show"]==1?1:0,
  402. ];
  403. if(empty($shopSave["name"])){
  404. return app('json')->fail("请输入门店名称");
  405. }
  406. if(empty($shopSave["tel"])){
  407. return app('json')->fail("请输入门店联系电话");
  408. }
  409. if(empty($shopSave["address"])){
  410. return app('json')->fail("请输入门店地址");
  411. }
  412. if(empty($shopSave["lx_name"])){
  413. return app('json')->fail("请输入门店联系人");
  414. }
  415. (new UserShopModel)->where("id",$id)->update($shopSave);
  416. return app('json')->success("数据保存成功");
  417. }
  418. public function shopList(Request $request){
  419. $pageSize = 50;
  420. $post = UtilService::getMore(
  421. [
  422. ['page', '1'],
  423. ['uid', ''],
  424. ['is_show', ''],
  425. ['mobile', ''],
  426. ['name', ''],
  427. ['pageSize', ''],
  428. ], $request);
  429. $where = [];
  430. if(!empty($post["pageSize"]) && $post["pageSize"]>50){
  431. $pageSize = (int)$post["pageSize"];
  432. }
  433. //用户
  434. if (!empty($post['uid'])){
  435. $where[]=["t.uid","=",$post['uid']];
  436. }else if (!empty($post['mobile'])) {
  437. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  438. if(!empty($m)) {
  439. $where[]=["t.uid","=",$m['uid']];
  440. }
  441. }
  442. if(is_numeric($post['is_show']) && in_array((string)$post['is_show'],['0','1'])) {
  443. $where[]=["t.is_show","=",(int)$post['is_show']];
  444. }
  445. if(!empty($post['name'])){
  446. $where[]=["t.name","like","%{$post['name']}%"];
  447. }
  448. $data = (new UserShopModel)
  449. ->alias("t")
  450. ->field("t.*,u.nickname as nickname")
  451. ->leftJoin("user u" , "u.uid = t.uid")
  452. ->where($where)
  453. ->page((int)$post["page"], $pageSize)
  454. ->order("t.id","desc")
  455. ->select()
  456. ->toArray();
  457. $pageCount = (new UserShopModel)->alias("t")->where($where)->count();
  458. $result = UtilService::getParam(
  459. [
  460. 'id',
  461. 'uid',
  462. 'nickname',
  463. 'name',
  464. 'area',
  465. 'address',
  466. 'tel',
  467. 'lx_name',
  468. 'longitude',
  469. "latitude",
  470. 'is_show',
  471. ['time', 'time', function($item){
  472. return empty($item) ? "--" : date("Y-m-d H:i:s",$item);
  473. }],
  474. ], $data);
  475. return app('json')->success([
  476. 'list' => $result,
  477. 'pageCount' => $pageCount,
  478. 'pageSize' => $pageSize,
  479. 'page' => $post['page'],
  480. ]);
  481. }
  482. /**
  483. * 支付任务列表
  484. * @param \app\model\api\Request $request
  485. */
  486. public function payTradeList(Request $request){
  487. $pageSize = 50;
  488. $post = UtilService::getMore(
  489. [
  490. ['page', '1'],
  491. ['uid', ''],
  492. ['status', ''],
  493. ['mobile', ''],
  494. ['type', ''],
  495. ['pay_no', ''],
  496. ['order_id', ''],
  497. ['time', []],
  498. ], $request);
  499. $where = [];
  500. //用户
  501. if (!empty($post['uid'])){
  502. $where[]=["t.uid","=",$post['uid']];
  503. }else if (!empty($post['mobile'])) {
  504. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  505. if(!empty($m)) {
  506. $where[]=["t.uid","=",$m['uid']];
  507. }
  508. }
  509. if(is_numeric($post['status']) && in_array((string)$post['status'],['0','1'])) {
  510. $where[]=["t.status","=",(int)$post['status']];
  511. }
  512. if(!empty($post['pay_type']) && in_array($post['pay_type'],['wxpay','system'])) {
  513. $where[]=["t.pay_type","=",$post['pay_type']];
  514. }
  515. if(!empty($post['type']) && in_array($post['type'],['pro','temp','activity'])) {
  516. $where[]=["t.type","=",$post['type']];
  517. }
  518. if(!empty($post['pay_no'])){
  519. $where[]=["t.pay_no","=",$post['pay_no']];
  520. }
  521. if(!empty($post['order_id'])){
  522. $where[]=["t.order_id","=",$post['order_id']];
  523. }
  524. $startTime = "";
  525. $endTime = "";
  526. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  527. $startTime = strtotime($post['time'][0]);
  528. $endTime = strtotime($post['time'][1]);
  529. $where[]=["t.time","between","{$startTime},{$endTime}"];
  530. }
  531. $data = (new PayTrade)
  532. ->alias("t")
  533. ->field("t.*,u.nickname as nickname,a.username as admin_name")
  534. ->leftJoin("user u" , "u.uid = t.uid")
  535. ->leftJoin("admin a", "a.id = t.admin_id")
  536. ->where($where)
  537. ->page((int)$post["page"], $pageSize)
  538. ->order("t.id","desc")
  539. ->select()
  540. ->toArray();
  541. $pageCount = (new PayTrade)->alias("t")->where($where)->count();
  542. $result = UtilService::getParam(
  543. [
  544. 'id',
  545. 'uid',
  546. 'nickname',
  547. "admin_id",
  548. "admin_name",
  549. 'pay_no',
  550. 'out_trade_no',
  551. 'pay_no',
  552. 'order_id',
  553. 'pay_type',
  554. 'type',
  555. 'money',
  556. 'content',
  557. "d_json",
  558. 'status',
  559. 'mono',
  560. ['time', 'time', function($item){
  561. return empty($item) ? "--" : date("Y-m-d H:i:s",$item);
  562. }],
  563. ['pay_time' , 'pay_time', function($item){
  564. return empty($item) ? "--" : date("Y-m-d H:i:s",$item);
  565. }],
  566. ['pay_json', 'pay_json', function($item){
  567. if(empty($item)){
  568. return "";
  569. }
  570. $payData = json_decode($item,true);
  571. return $payData;
  572. }],
  573. ], $data);
  574. return app('json')->success([
  575. 'list' => $result,
  576. 'pageCount' => $pageCount,
  577. 'pageSize' => $pageSize,
  578. 'page' => $post['page'],
  579. ]);
  580. }
  581. /**
  582. * 搜索交易数据
  583. * @param Request $request
  584. */
  585. public function searchPayTrade(Request $request){
  586. $post = UtilService::getMore(
  587. [
  588. ['id', '','empty',''],
  589. ], $request);
  590. $data = (new PayTrade)->where("id",$post["id"])->find();
  591. if(empty($data)){
  592. return app("json")->fail("数据不存在");
  593. }
  594. if($data["status"]==1 && !empty($data["pay_json"])){
  595. return app("json")->success("交易支付成功", json_decode($data["pay_json"],true));
  596. }
  597. $out_trade_no = $data["out_trade_no"];
  598. //微信支付
  599. if($data["pay_type"]=="wxpay"){
  600. $wxpay = new wxpayApi();
  601. $resAr = $wxpay->searchOrderQuery($out_trade_no);
  602. if(empty($resAr) || !is_array($resAr)){
  603. return app("json")->fail("查询失败");
  604. }
  605. if(empty($resAr["trade_state"])){
  606. return app("json")->fail("查询状态错误");
  607. }
  608. if($resAr["trade_state"]=="NOTPAY"){
  609. return app("json")->fail("未支付");
  610. }
  611. if($resAr["trade_state"]=="REFUND"){
  612. return app("json")->fail("转入退款");
  613. }
  614. if($resAr["trade_state"]=="CLOSED"){
  615. return app("json")->fail("已关闭");
  616. }
  617. if($resAr["trade_state"]=="REVOKED"){
  618. return app("json")->fail("已撤销(付款码支付)");
  619. }
  620. if($resAr["trade_state"]=="USERPAYING"){
  621. return app("json")->fail("用户支付中(付款码支付)");
  622. }
  623. if($resAr["trade_state"]=="PAYERROR"){
  624. return app("json")->fail("支付失败(其他原因,如银行返回失败)");
  625. }
  626. if($resAr["trade_state"]=="ACCEPT"){
  627. return app("json")->fail("已接收,等待扣款");
  628. }
  629. if($resAr["trade_state"]=="SUCCESS"){
  630. if(empty($resAr["payMoney"])){
  631. return app("json")->fail("交易支付成功,但是查询不到金额信息");
  632. }
  633. $payDataInfo = [
  634. 'totalMoney' =>empty($resAr["total_fee"]) ? "未返回" : $resAr["total_fee"]/100,
  635. 'payMoney' =>empty($resAr["cash_fee"]) ? "未返回" : $resAr["cash_fee"]/100,
  636. 'payTradeNo' =>empty($resAr["transaction_id"]) ? "未返回" : $resAr["transaction_id"],
  637. 'outTradeNo' =>empty($resAr["out_trade_no"]) ? "未返回" : $resAr["out_trade_no"],
  638. "tradeStatus"=>empty($resAr["trade_state"]) ? "未返回" : $resAr["trade_state"],
  639. "payTime" =>empty($resAr["time_end"]) ? "未返回" : $resAr["time_end"],
  640. "attach" =>empty($resAr["attach"]) ? "未返回" : $resAr["attach"],
  641. ];
  642. //重新调用支付处理
  643. if(!empty($data["o_id"]) && $data["status"]==0){
  644. $pay_json = json_encode($payDataInfo);
  645. (new OrderLib)->orderPay($payDataInfo["outTradeNo"], $pay_json);
  646. }
  647. return app("json")->success("交易支付成功",$payDataInfo);
  648. }
  649. return app("json")->fail("支付状态未知");
  650. }
  651. return app("json")->fail("查询失败");
  652. }
  653. }