Member.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. if ($post['type'] == 1)
  226. $bool = (new UserDetailModel)->adminAddMoney($userData['uid'], $post['into'], $request->adminInfo['id'],$post['othen']);
  227. if ($post['type'] == -1){
  228. if($userData["money"]-$post['into']<0){
  229. return app('json')->fail('余额不足');
  230. }
  231. $bool = (new UserDetailModel)->adminCutMoney($userData['uid'], $post['into'], $request->adminInfo['id'],$post['othen']);
  232. }
  233. if ($bool)
  234. return app('json')->success('操作成功');
  235. else
  236. return app('json')->fail('操作失败');
  237. }
  238. /**
  239. * 钻石收益明细列表
  240. * @param Request $request
  241. * @return mixed
  242. */
  243. public function scoreDetail (Request $request)
  244. {
  245. $pageSize = 50;
  246. $post = UtilService::getMore(
  247. [
  248. ['page', '1'],
  249. ['uid', '0'],
  250. ['mobile', ''],
  251. ['type', ''],
  252. ['code', ''],
  253. ['time', []],
  254. ], $request
  255. );
  256. $where = [];
  257. if (!empty($post['uid'])){
  258. $where[]=["d.uid","=",$post['uid']];
  259. }else if (!empty($post['mobile'])) {
  260. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  261. if(!empty($m)) {
  262. $where[]=["d.uid","=",$m['uid']];
  263. }
  264. }
  265. $startTime = "";
  266. $endTime = "";
  267. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  268. $startTime = strtotime($post['time'][0]);
  269. $endTime = strtotime($post['time'][1]);
  270. $where[]=["d.time","between","{$startTime},{$endTime}"];
  271. }
  272. if (!empty($post['type']) && in_array(strval($post['type']), ["1","-1"])) {
  273. $where[]=["d.type","=",$post['type']];
  274. }
  275. if (!empty($post['code'])) {
  276. $where[]=["d.code","=",$post['code']];
  277. }
  278. $data = (new UserScoreDetailModel)
  279. ->alias("d")
  280. ->field("d.*,u.mobile")
  281. ->leftJoin("user u", "u.uid = d.uid")
  282. ->where($where)
  283. ->page((int)$post["page"], $pageSize)
  284. ->order("d.id","desc")
  285. ->select()
  286. ->toArray();
  287. $pageCount = (new UserScoreDetailModel)->alias("d")->where($where)->count();
  288. foreach($where as $k=>$v){
  289. if($v[0]=="d.type"){
  290. array_splice($where,$k,1);
  291. }
  292. }
  293. //收入
  294. $inWhere = $where;
  295. $inWhere[]=["d.type","=",1];
  296. $inTotal = (new UserScoreDetailModel)->alias("d")->where($inWhere)->sum("d.v");
  297. //支出
  298. $outWhere = $where;
  299. $outWhere[]=["d.type","=",-1];
  300. $outTotal = (new UserScoreDetailModel)->alias("d")->where($outWhere)->sum("d.v");
  301. $result = UtilService::getParam(
  302. [
  303. 'id',
  304. 'uid',
  305. 'mobile',
  306. 'title',
  307. 'content',
  308. 'type',
  309. ['into','v'],
  310. 'money',
  311. ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
  312. ], $data);
  313. return app('json')->success([
  314. 'list' => $result,
  315. 'pageCount' => $pageCount,
  316. 'pageSize' => $pageSize,
  317. 'page' => $post['page'],
  318. 'inTotal' => empty($inTotal) ? 0 : floatval($inTotal),
  319. 'outTotal' => empty($outTotal)? 0 : floatval($outTotal),
  320. ]);
  321. }
  322. /**
  323. * 积分增/减
  324. * @param Request $request
  325. */
  326. public function scoreDetailSave(Request $request)
  327. {
  328. $post = UtilService::getMore([
  329. ['uid', '', 'empty', '参数错误'],
  330. ['type', '1'],
  331. ['into', '0', 'gt|0', '输入值错误'],
  332. ['othen', ''],
  333. ], $request);
  334. $userData = (new UserModel)->where("uid",$post["uid"])->find();
  335. if(empty($userData)){
  336. return app('json')->fail('用户不存在,请输入正确的用户uid');
  337. }
  338. if ($post['type'] == 1)
  339. $bool = (new UserScoreDetailModel)->adminAddMoney($userData['uid'], intval($post['into']), $request->adminInfo['id'],$post['othen']);
  340. if ($post['type'] == -1){
  341. if($userData["score"]-$post['into']<0){
  342. return app('json')->fail('剩余积分不足');
  343. }
  344. $bool = (new UserScoreDetailModel)->adminCutMoney($userData['uid'], intval($post['into']), $request->adminInfo['id'],$post['othen']);
  345. }
  346. if ($bool)
  347. return app('json')->success('操作成功');
  348. else
  349. return app('json')->fail('操作失败');
  350. }
  351. /**
  352. * 获取会员数据
  353. * @param Request $request
  354. * @return mixed
  355. */
  356. public function getItem(Request $request)
  357. {
  358. $post = UtilService::getMore([
  359. ['uid', 1],
  360. ]);
  361. $data = (new UserModel)
  362. ->alias("u")
  363. ->field("u.uid,u.mobile,u.nickname,u.avatar,u.status,u.regtime,u.lasttime,u.parent_uid.p.nickname as parent_nickname")
  364. ->leftJoin("user p","p.uid = u.parent_uid")
  365. ->where("u.uid",$post["uid"])
  366. ->find()
  367. ->toArray();
  368. if(!empty($data)){
  369. $data["regtime"] = date("Y-m-d H:i:s",$data["regtime"]);
  370. $data["lasttime"] = date("Y-m-d H:i:s",$data["lasttime"]);
  371. }
  372. return app('json')->success(empty($data) ? [] : $data);
  373. }
  374. public function shopSave(Request $request){
  375. $post = UtilService::getMore([
  376. ['id','','empty','参数错误'],
  377. ['name','','empty','请输入名称'],
  378. ['tel','','empty','请输入联系电话'],
  379. ['lx_name','','empty','请输入联系人'],
  380. ['address','','empty','请输入门店地址'],
  381. ['longitude',''],
  382. ['latitude',''],
  383. ['is_show',''],
  384. ],$request);
  385. $id = (int)$post["id"];
  386. if(empty($id)){
  387. return app('json')->fail("参数错误");
  388. }
  389. unset($post["id"]);
  390. $shopSave=[
  391. "name" => $post["name"],
  392. "tel" => $post["tel"],
  393. "address" => $post["address"],
  394. "lx_name" => $post["lx_name"],
  395. "longitude" => $post["longitude"],
  396. "latitude" => $post["latitude"],
  397. "is_show" => $post["is_show"]==1?1:0,
  398. ];
  399. if(empty($shopSave["name"])){
  400. return app('json')->fail("请输入门店名称");
  401. }
  402. if(empty($shopSave["tel"])){
  403. return app('json')->fail("请输入门店联系电话");
  404. }
  405. if(empty($shopSave["address"])){
  406. return app('json')->fail("请输入门店地址");
  407. }
  408. if(empty($shopSave["lx_name"])){
  409. return app('json')->fail("请输入门店联系人");
  410. }
  411. (new UserShopModel)->where("id",$id)->update($shopSave);
  412. return app('json')->success("数据保存成功");
  413. }
  414. public function shopList(Request $request){
  415. $pageSize = 50;
  416. $post = UtilService::getMore(
  417. [
  418. ['page', '1'],
  419. ['uid', ''],
  420. ['is_show', ''],
  421. ['mobile', ''],
  422. ['name', ''],
  423. ['pageSize', ''],
  424. ], $request);
  425. $where = [];
  426. if(!empty($post["pageSize"]) && $post["pageSize"]>50){
  427. $pageSize = (int)$post["pageSize"];
  428. }
  429. //用户
  430. if (!empty($post['uid'])){
  431. $where[]=["t.uid","=",$post['uid']];
  432. }else if (!empty($post['mobile'])) {
  433. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  434. if(!empty($m)) {
  435. $where[]=["t.uid","=",$m['uid']];
  436. }
  437. }
  438. if(is_numeric($post['is_show']) && in_array((string)$post['is_show'],['0','1'])) {
  439. $where[]=["t.is_show","=",(int)$post['is_show']];
  440. }
  441. if(!empty($post['name'])){
  442. $where[]=["t.name","like","%{$post['name']}%"];
  443. }
  444. $data = (new UserShopModel)
  445. ->alias("t")
  446. ->field("t.*,u.nickname as nickname")
  447. ->leftJoin("user u" , "u.uid = t.uid")
  448. ->where($where)
  449. ->page((int)$post["page"], $pageSize)
  450. ->order("t.id","desc")
  451. ->select()
  452. ->toArray();
  453. $pageCount = (new UserShopModel)->alias("t")->where($where)->count();
  454. $result = UtilService::getParam(
  455. [
  456. 'id',
  457. 'uid',
  458. 'nickname',
  459. 'name',
  460. 'area',
  461. 'address',
  462. 'tel',
  463. 'lx_name',
  464. 'longitude',
  465. "latitude",
  466. 'is_show',
  467. ['time', 'time', function($item){
  468. return empty($item) ? "--" : date("Y-m-d H:i:s",$item);
  469. }],
  470. ], $data);
  471. return app('json')->success([
  472. 'list' => $result,
  473. 'pageCount' => $pageCount,
  474. 'pageSize' => $pageSize,
  475. 'page' => $post['page'],
  476. ]);
  477. }
  478. /**
  479. * 支付任务列表
  480. * @param \app\model\api\Request $request
  481. */
  482. public function payTradeList(Request $request){
  483. $pageSize = 50;
  484. $post = UtilService::getMore(
  485. [
  486. ['page', '1'],
  487. ['uid', ''],
  488. ['status', ''],
  489. ['mobile', ''],
  490. ['type', ''],
  491. ['pay_no', ''],
  492. ['order_id', ''],
  493. ['time', []],
  494. ], $request);
  495. $where = [];
  496. //用户
  497. if (!empty($post['uid'])){
  498. $where[]=["t.uid","=",$post['uid']];
  499. }else if (!empty($post['mobile'])) {
  500. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  501. if(!empty($m)) {
  502. $where[]=["t.uid","=",$m['uid']];
  503. }
  504. }
  505. if(is_numeric($post['status']) && in_array((string)$post['status'],['0','1'])) {
  506. $where[]=["t.status","=",(int)$post['status']];
  507. }
  508. if(!empty($post['pay_type']) && in_array($post['pay_type'],['wxpay','system'])) {
  509. $where[]=["t.pay_type","=",$post['pay_type']];
  510. }
  511. if(!empty($post['type']) && in_array($post['type'],['pro','temp','activity'])) {
  512. $where[]=["t.type","=",$post['type']];
  513. }
  514. if(!empty($post['pay_no'])){
  515. $where[]=["t.pay_no","=",$post['pay_no']];
  516. }
  517. if(!empty($post['order_id'])){
  518. $where[]=["t.order_id","=",$post['order_id']];
  519. }
  520. $startTime = "";
  521. $endTime = "";
  522. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  523. $startTime = strtotime($post['time'][0]);
  524. $endTime = strtotime($post['time'][1]);
  525. $where[]=["t.time","between","{$startTime},{$endTime}"];
  526. }
  527. $data = (new PayTrade)
  528. ->alias("t")
  529. ->field("t.*,u.nickname as nickname,a.username as admin_name")
  530. ->leftJoin("user u" , "u.uid = t.uid")
  531. ->leftJoin("admin a", "a.id = t.admin_id")
  532. ->where($where)
  533. ->page((int)$post["page"], $pageSize)
  534. ->order("t.id","desc")
  535. ->select()
  536. ->toArray();
  537. $pageCount = (new PayTrade)->alias("t")->where($where)->count();
  538. $result = UtilService::getParam(
  539. [
  540. 'id',
  541. 'uid',
  542. 'nickname',
  543. "admin_id",
  544. "admin_name",
  545. 'pay_no',
  546. 'out_trade_no',
  547. 'pay_no',
  548. 'order_id',
  549. 'pay_type',
  550. 'type',
  551. 'money',
  552. 'content',
  553. "d_json",
  554. 'status',
  555. 'mono',
  556. ['time', 'time', function($item){
  557. return empty($item) ? "--" : date("Y-m-d H:i:s",$item);
  558. }],
  559. ['pay_time' , 'pay_time', function($item){
  560. return empty($item) ? "--" : date("Y-m-d H:i:s",$item);
  561. }],
  562. ['pay_json', 'pay_json', function($item){
  563. if(empty($item)){
  564. return "";
  565. }
  566. $payData = json_decode($item,true);
  567. return $payData;
  568. }],
  569. ], $data);
  570. return app('json')->success([
  571. 'list' => $result,
  572. 'pageCount' => $pageCount,
  573. 'pageSize' => $pageSize,
  574. 'page' => $post['page'],
  575. ]);
  576. }
  577. /**
  578. * 搜索交易数据
  579. * @param Request $request
  580. */
  581. public function searchPayTrade(Request $request){
  582. $post = UtilService::getMore(
  583. [
  584. ['id', '','empty',''],
  585. ], $request);
  586. $data = (new PayTrade)->where("id",$post["id"])->find();
  587. if(empty($data)){
  588. return app("json")->fail("数据不存在");
  589. }
  590. if($data["status"]==1 && !empty($data["pay_json"])){
  591. return app("json")->success("交易支付成功", json_decode($data["pay_json"],true));
  592. }
  593. $out_trade_no = $data["out_trade_no"];
  594. //微信支付
  595. if($data["pay_type"]=="wxpay"){
  596. $wxpay = new wxpayApi();
  597. $resAr = $wxpay->searchOrderQuery($out_trade_no);
  598. if(empty($resAr) || !is_array($resAr)){
  599. return app("json")->fail("查询失败");
  600. }
  601. if(empty($resAr["trade_state"])){
  602. return app("json")->fail("查询状态错误");
  603. }
  604. if($resAr["trade_state"]=="NOTPAY"){
  605. return app("json")->fail("未支付");
  606. }
  607. if($resAr["trade_state"]=="REFUND"){
  608. return app("json")->fail("转入退款");
  609. }
  610. if($resAr["trade_state"]=="CLOSED"){
  611. return app("json")->fail("已关闭");
  612. }
  613. if($resAr["trade_state"]=="REVOKED"){
  614. return app("json")->fail("已撤销(付款码支付)");
  615. }
  616. if($resAr["trade_state"]=="USERPAYING"){
  617. return app("json")->fail("用户支付中(付款码支付)");
  618. }
  619. if($resAr["trade_state"]=="PAYERROR"){
  620. return app("json")->fail("支付失败(其他原因,如银行返回失败)");
  621. }
  622. if($resAr["trade_state"]=="ACCEPT"){
  623. return app("json")->fail("已接收,等待扣款");
  624. }
  625. if($resAr["trade_state"]=="SUCCESS"){
  626. if(empty($resAr["payMoney"])){
  627. return app("json")->fail("交易支付成功,但是查询不到金额信息");
  628. }
  629. $payDataInfo = [
  630. 'totalMoney' =>empty($resAr["total_fee"]) ? "未返回" : $resAr["total_fee"]/100,
  631. 'payMoney' =>empty($resAr["cash_fee"]) ? "未返回" : $resAr["cash_fee"]/100,
  632. 'payTradeNo' =>empty($resAr["transaction_id"]) ? "未返回" : $resAr["transaction_id"],
  633. 'outTradeNo' =>empty($resAr["out_trade_no"]) ? "未返回" : $resAr["out_trade_no"],
  634. "tradeStatus"=>empty($resAr["trade_state"]) ? "未返回" : $resAr["trade_state"],
  635. "payTime" =>empty($resAr["time_end"]) ? "未返回" : $resAr["time_end"],
  636. "attach" =>empty($resAr["attach"]) ? "未返回" : $resAr["attach"],
  637. ];
  638. //重新调用支付处理
  639. if(!empty($data["o_id"]) && $data["status"]==0){
  640. $pay_json = json_encode($payDataInfo);
  641. (new OrderLib)->orderPay($payDataInfo["outTradeNo"], $pay_json);
  642. }
  643. return app("json")->success("交易支付成功",$payDataInfo);
  644. }
  645. return app("json")->fail("支付状态未知");
  646. }
  647. return app("json")->fail("查询失败");
  648. }
  649. }