OrderPay.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use app\admin\model\ReportCode;use think\App;
  5. use think\facade\Db;use think\queue\command\Retry;
  6. class OrderPay extends BaseController{
  7. public function __construct(App $app) {parent::__construct($app);}
  8. //新建资金认领数据
  9. public function create(){
  10. $tradNo = isset($this->post['tradNo'])&&$this->post['tradNo']!=""?trim($this->post['tradNo']):"";
  11. if($tradNo==""){
  12. return error_show(1004,"参数 tradNo 不能为空");
  13. }
  14. $orderArr = isset($this->post['orderArr'])&&!empty($this->post['orderArr'])?$this->post['orderArr']:[];
  15. if(empty($orderArr)){
  16. return error_show(1004,"参数 orderArr 不能为空");
  17. }
  18. Db::startTrans();
  19. try{
  20. $logNo=makeNo("TRC");
  21. $trade =Db::name("trade")->where(["tradNo"=>$tradNo,"is_del"=>0])->lock(true)->findOrEmpty();
  22. if(empty($trade)){
  23. Db::rollback();
  24. return error_show(1004,"未找到资金信息");
  25. }
  26. $total_fee =array_sum(array_column($orderArr,"trad_fee"));
  27. if ($trade['balance']<$total_fee){
  28. Db::rollback();
  29. return error_show(1004,"资金余额不足核销");
  30. }
  31. $assoc=[];
  32. foreach ($orderArr as $value){
  33. if(!isset($value['sequenceNo'])||$value['sequenceNo']==""){
  34. Db::rollback();
  35. return error_show(1004,"销售单编号不能为空");
  36. }
  37. if(!isset($value['trad_fee'])||$value['trad_fee']==""){
  38. Db::rollback();
  39. return error_show(1004,"销售单核销金额不能为空");
  40. }
  41. $qrd =Db::name("qrd_info")->where("sequenceNo","=",$value['sequenceNo'])->field("id,customerNo,status,pay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty();
  42. if(empty($qrd)){
  43. Db::rollback();
  44. return error_show(1004,"销售单信息未找到");
  45. }
  46. if($qrd['wpay_fee']<$value['trad_fee']){
  47. Db::rollback();
  48. return error_show(1004,"销售单未付款金额不足核销金额");
  49. }
  50. $updt=[
  51. "pay_fee"=>$qrd['pay_fee']+$value['trad_fee'],
  52. "wpay_fee"=>$qrd['wpay_fee']-$value['trad_fee'],
  53. "pay_status"=>2,
  54. "status"=>1,
  55. "updatetime"=>date("Y-m-d H:i:s")
  56. ];
  57. $qrdup = Db::name("qrd_info")->where($qrd)->update($updt);
  58. if($qrdup==false){
  59. Db::rollback();
  60. return error_show(1004,"销售单核销金额失败");
  61. }
  62. $temp=[
  63. "assocNo"=>makeNo("AS"),
  64. "apply_id"=>$this->uid,
  65. "apply_name"=>$this->uname,
  66. "type"=>2,
  67. "orderCode"=>$value['sequenceNo'],
  68. "customerNo"=>$qrd['customerNo'],
  69. "viceCode"=>$logNo,
  70. "order_total"=>$qrd['totalPrice'],
  71. "vice_total"=>$total_fee,
  72. "cancel_fee"=>$value['trad_fee'],
  73. "status"=>1,
  74. "addtime"=>date("Y-m-d H:i:s"),
  75. "updatetime"=>date("Y-m-d H:i:s")
  76. ];
  77. $assoc[]=$temp;
  78. $report=ReportCode::where(["qrdNo"=>$value['sequenceNo']])->find();
  79. if($report)$report->setField("logNo",$logNo);
  80. if($report)$report->setField("tradNo",$tradNo);
  81. }
  82. $asscin= Db::name("assoc")->insertAll($assoc);
  83. if($asscin!=count($assoc)){
  84. Db::rollback();
  85. return error_show(1004,"销售单核销金额关联失败");
  86. }
  87. $update=[
  88. "balance"=>$trade['balance']-$total_fee,
  89. "used_fee"=>$trade['used_fee']+$total_fee,
  90. "status"=>($trade['balance']-$total_fee)==0 ? 3:2,
  91. "updatetime"=>date("Y-m-d H:i:s"),
  92. ];
  93. $tradup=Db::name("trade")->where($trade)->update($update);
  94. if($tradup){
  95. $create = [
  96. "logNo"=>$logNo,
  97. "tradNo"=>$tradNo,
  98. "companyNo"=>$trade['companyNo'],
  99. "apply_id"=>$this->uid,
  100. "apply_name"=>$this->uname,
  101. "trade_time"=>$trade['trade_time'],
  102. "total_fee"=>$total_fee,
  103. "status"=>1,
  104. "addtime"=>date("Y-m-d H:i:s"),
  105. "updatetime"=>date("Y-m-d H:i:s")
  106. ];
  107. $tradchild =Db::name("trade_pool")->insert($create);
  108. if($tradchild){
  109. Db::commit();
  110. return app_show(0,"资金认领成功",["logNo"=>$logNo]);
  111. }
  112. }
  113. Db::rollback();
  114. return error_show(1004,"资金认领失败");
  115. }catch (\Exception $e){
  116. Db::rollback();
  117. return error_show(1004,$e->getMessage());
  118. }
  119. }
  120. // 1待审批2审批通过3审批驳回4退款5解除认领
  121. public function status(){
  122. $logNo = isset($this->post['logNo'])&&$this->post['logNo']!=""?trim($this->post['logNo']):"";
  123. if($logNo==""){
  124. return error_show(1004,"参数logNo不能为空");
  125. }
  126. $logingo= Db::name("trade_pool")->where(["logNo"=>$logNo,"is_del"=>0])->find();
  127. if($logingo==false){
  128. return error_show(1004,"资金认领信息未找到");
  129. }
  130. $status=isset($this->post['status'])&&$this->post['status']!=""?intval($this->post['status']):"";
  131. if($status==""){
  132. return error_show(1004,"参数 status 不能为空");
  133. }
  134. $remark=isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  135. $trade =Db::name("trade")->where(["tradNo"=>$logingo['tradNo'],"is_del"=>0])->findOrEmpty();
  136. if(empty($trade)){
  137. return error_show(1005,"资金信息未找到");
  138. }
  139. // if($remark==""){
  140. // return error_show(1004,"参数 remark 不能为空");
  141. // }
  142. Db::startTrans();
  143. try {
  144. $up=["status"=>$status,"updatetime"=>date("Y-m-d H:i:s"),"remark"=>$remark];
  145. $logup = Db::name("trade_pool")->where($logingo)->update($up);
  146. if($logup){
  147. if($status==2){
  148. $qrdArr=Db::name("assoc")->where(["viceCode"=>$logNo,"status"=>1,"is_del"=>0])->select()->toArray();
  149. if(!empty($qrdArr)){
  150. foreach ($qrdArr as $value){
  151. $qrd =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->field("id,status,pay_fee,apay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty();
  152. if(empty($qrd)){
  153. Db::rollback();
  154. return error_show(1005,"未找到销售单数据");
  155. }
  156. if($qrd['pay_fee']<$value['cancel_fee']){
  157. Db::rollback();
  158. return error_show(1005,"销售单待付金额不足");
  159. }
  160. $update =[
  161. "apay_fee"=>$qrd['apay_fee']+$value['cancel_fee'],
  162. "pay_fee"=>$qrd['pay_fee']-$value['cancel_fee'],
  163. "paytime"=>date("Y-m-d H:i:s"),
  164. "pay_status"=>$qrd['wpay_fee']==0 && ($qrd['pay_fee']-$value['cancel_fee'])==0 ? 3:2,
  165. "updatetime"=>date("Y-m-d H:i:s")
  166. ];
  167. $qrdup =Db::name("qrd_info")->where($qrd)->update($update);
  168. if($qrdup==false){
  169. Db::rollback();
  170. return error_show(1005,"销售单更新失败");
  171. }
  172. $asscup =[
  173. "status"=>2,
  174. "assoc_time"=>date("Y-m-d H:i:s"),
  175. "updatetime"=>date("Y-m-d H:i:s")
  176. ];
  177. $assc=Db::name("assoc")->where($value)->update($asscup);
  178. if($assc==false){
  179. Db::rollback();
  180. return error_show(1005,"销售单更新失败");
  181. }
  182. }
  183. }
  184. }
  185. if($status==3){
  186. $qrdArr=Db::name("assoc")->where(["viceCode"=>$logNo,"status"=>1,"is_del"=>0])->select()->toArray();
  187. if(!empty($qrdArr)){
  188. foreach ($qrdArr as $value){
  189. $qrd =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->field("id,status,pay_fee,apay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty();
  190. if(empty($qrd)){
  191. Db::rollback();
  192. return error_show(1005,"未找到销售单数据");
  193. }
  194. if($qrd['pay_fee']<$value['cancel_fee']){
  195. Db::rollback();
  196. return error_show(1005,"销售单待付金额不足");
  197. }
  198. $update =[
  199. "wpay_fee"=>$qrd['wpay_fee']+$value['cancel_fee'],
  200. "pay_fee"=>$qrd['pay_fee']-$value['cancel_fee'],
  201. "pay_status"=>$qrd['apay_fee']==0 && ($qrd['pay_fee']-$value['cancel_fee'])==0 ? 1:2,
  202. "status"=>$qrd['apay_fee']==0 && ($qrd['pay_fee']-$value['cancel_fee'])==0 ?0:1,
  203. "updatetime"=>date("Y-m-d H:i:s")
  204. ];
  205. $qrdup =Db::name("qrd_info")->where($qrd)->update($update);
  206. if($qrdup==false){
  207. Db::rollback();
  208. return error_show(1005,"销售单更新失败");
  209. }
  210. $asscup =[
  211. "status"=>3,
  212. "updatetime"=>date("Y-m-d H:i:s")
  213. ];
  214. $assc=Db::name("assoc")->where($value)->update($asscup);
  215. if($assc==false){
  216. Db::rollback();
  217. return error_show(1005,"销售单更新失败");
  218. }
  219. $report=ReportCode::where(["qrdNo"=>$value['orderCode']])->find();
  220. if($report)$report->rmField("logNo",$logNo);
  221. }
  222. }
  223. if($trade['used_fee']<$logingo['total_fee']){
  224. Db::rollback();
  225. return error_show(1005,"资金信息已认领金额不足");
  226. }
  227. $tradup =[
  228. "used_fee"=>$trade['used_fee']-$logingo['total_fee'],
  229. "balance"=>$trade['balance']+$logingo['total_fee'],
  230. "status"=>($trade['used_fee']-$logingo['total_fee'])==0 ? 1 :2,
  231. "updatetime"=>date("Y-m-d H:i:s")
  232. ];
  233. $updaT=Db::name("trade")->where($trade)->update($tradup);
  234. if($updaT==false){
  235. Db::rollback();
  236. return error_show(1005,"资金信息更新失败");
  237. }
  238. }
  239. Db::commit();
  240. return app_show(0,"审核成功");
  241. }
  242. Db::rollback();
  243. return error_show(1004,"审核失败");
  244. }catch (\Exception $e){
  245. Db::rollback();
  246. return error_show(1004,$e->getMessage());
  247. }
  248. }
  249. //资金信息列表
  250. public function list(){
  251. $condition=[];
  252. $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1;
  253. $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15;
  254. $name =isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
  255. $bank =isset($this->post['bank'])&&$this->post['bank']!=""? trim($this->post['bank']):"";
  256. $start =isset($this->post['start'])&&$this->post['start']!=""? trim($this->post['start']):"";
  257. $end =isset($this->post['end'])&&$this->post['end']!=""? trim($this->post['end']):"";
  258. $status =isset($this->post['status'])&&$this->post['status']!==""? intval($this->post['status']):"";
  259. $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):"";
  260. $companyNo =isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']):"";
  261. $used_lower =isset($this->post['userd_lower'])&&$this->post['userd_lower']!==""? floor($this->post['userd_lower']) :"0";
  262. $used_upper =isset($this->post['used_upper'])&&$this->post['used_upper']!==""? floor($this->post['used_upper']):"";
  263. if($used_lower!=="")$condition[]=["used_fee",">=",$used_lower];
  264. if($used_upper!=="")$condition[]=["used_fee","<=",$used_upper];
  265. if($companyNo!==""){
  266. $condition[]=["companyNo","=",$companyNo];
  267. }
  268. $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
  269. if($relaComNo!=""){
  270. $condition[]=["companyNo","=",$relaComNo];
  271. }
  272. if($tradNo!==""){
  273. $condition[]=["tradNo","like","%$tradNo%"];
  274. }
  275. if($bank!=""){
  276. $condition[]=["trade_bank","like","%$bank%"];
  277. }
  278. if($name!=""){
  279. $condition[]=["trade_out","like","%$name%"];
  280. }
  281. if($start!=""){
  282. $condition[]=["trade_time",">=",$start." 00:00:00"];
  283. }
  284. if($end!=""){
  285. $condition[]=["trade_time","<=",$end." 23:59:59"];
  286. }
  287. if($status!==""){
  288. $condition[]=["status","=",$status];
  289. }
  290. $count=Db::name("trade")->where($condition)->count();
  291. $total=ceil($count/$size);
  292. $page=$page>$total? intval($total):$page;
  293. $list =Db::name("trade")->where($condition)->page($page,$size)->order("addtime desc")->select()->toArray();
  294. foreach ($list as &$value){
  295. $data = Db::name("trade_pool")->alias("a")
  296. ->leftJoin("assoc b","a.logNo=b.viceCode")
  297. ->leftJoin("qrd_info c","b.orderCode=c.sequenceNo")
  298. ->where(["a.tradNo"=>$value['tradNo'],"a.is_del"=>0])
  299. ->order("a.addtime desc")
  300. ->field("a.*,b.orderCode,c.qrdSource,goodNo,goodName,qrdType,c.ownerName,c.ownerid,c.department,c.poCode")
  301. ->select()->toArray();
  302. $value['child']=$data;
  303. }
  304. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  305. }
  306. // 认领资金列表明细
  307. public function tradeList(){
  308. $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1;
  309. $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15;
  310. $condition =[["a.is_del","=",0],["b.is_del","=",0]];
  311. $name =isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
  312. $bank =isset($this->post['bank'])&&$this->post['bank']!=""? trim($this->post['bank']):"";
  313. $start =isset($this->post['start'])&&$this->post['start']!=""? trim($this->post['start']):"";
  314. $end =isset($this->post['end'])&&$this->post['end']!=""? trim($this->post['end']):"";
  315. $status =isset($this->post['status'])&&$this->post['status']!==""? intval($this->post['status']):"";
  316. $apply_id =isset($this->post['apply_id'])&&$this->post['apply_id']!=""? intval($this->post['apply_id']):"";
  317. $apply_name =isset($this->post['apply_name'])&&$this->post['apply_name']!=""? trim($this->post['apply_name']):"";
  318. $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):"";
  319. $orderCode =isset($this->post['orderCode'])&&$this->post['orderCode']!=''?trim($this->post['orderCode']):"";
  320. $companyNo =isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']):"";
  321. if($companyNo!==""){
  322. $condition[]=["a.companyNo","=",$companyNo];
  323. }
  324. $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
  325. if($relaComNo!=""){
  326. $condition[]=["companyNo","=",$relaComNo];
  327. }
  328. if($tradNo!==""){
  329. $condition[]=["a.tradNo","like","%$tradNo%"];
  330. }
  331. if($orderCode!==""){
  332. $condition[]=["d.orderCode","like","%$orderCode%"];
  333. }
  334. $logNo =isset($this->post['logNo'])&&$this->post['logNo']!=""? trim($this->post['logNo']):"";
  335. if($logNo!==""){
  336. $condition[]=["a.logNo","like","%$logNo%"];
  337. }
  338. if($bank!=""){
  339. $condition[]=["b.trade_bank","like","%$bank%"];
  340. }
  341. if($name!=""){
  342. $condition[]=["b.trade_out","like","%$name%"];
  343. }
  344. if($start!=""){
  345. $condition[]=["a.add_time",">=",$start." 00:00:00"];
  346. }
  347. if($end!=""){
  348. $condition[]=["a.add_time","<=",$end." 23:59:59"];
  349. }
  350. if($status!==""){
  351. $condition[]=["a.status","=",$status];
  352. }
  353. if($apply_id!==""){
  354. $condition[]=["a.apply_id","=",$apply_id];
  355. }
  356. if($apply_name!==""){
  357. $condition[]=["a.apply_name","like","%$apply_name%"];
  358. }
  359. $count=Db::name("trade_pool")->alias("a")
  360. ->leftJoin("trade b","a.tradNo=b.tradNo")
  361. ->leftJoin("assoc d","a.logNo=d.viceCode")
  362. ->leftJoin("qrd_info c","d.orderCode=c.sequenceNo")
  363. ->where($condition)->count();
  364. $total=ceil($count/$size);
  365. $page=$page>$total? intval($total):$page;
  366. $list =Db::name("trade_pool")->alias("a")
  367. ->leftJoin("trade b","a.tradNo=b.tradNo")
  368. ->leftJoin("assoc d","a.logNo=d.viceCode")
  369. ->leftJoin("qrd_info c","d.orderCode=c.sequenceNo")
  370. ->where($condition)
  371. ->page($page,$size)
  372. ->field("a.*,b.trade_bank,b.trade_account,b.trade_out,b.total_fee as btotal_fee,b.used_fee,b.balance,
  373. d.orderCode,c.qrdSource,c.goodNo,c.goodName,c.qrdType,c.ownerName,c.ownerid,c.department,c.poCode,c.platName,c.totalPrice,d.cancel_fee")
  374. ->order("a.addtime desc")->select();
  375. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  376. }
  377. // 获取资金下面的认领信息
  378. public function tradeQuery(){
  379. $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):"";
  380. $status =isset($this->post['status'])&&$this->post['status']!=""? intval($this->post['status']):"";
  381. $apply_id =isset($this->post['apply_id'])&&$this->post['apply_id']!=""? intval($this->post['apply_id']):"";
  382. $apply_name =isset($this->post['apply_name'])&&$this->post['apply_name']!=""? trim($this->post['apply_name']):"";
  383. $companyNo =isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']):"";
  384. if($companyNo!==""){
  385. $condition[]=["companyNo","=",$companyNo];
  386. }
  387. $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
  388. if($relaComNo!=""){
  389. $condition[]=["companyNo","=",$relaComNo];
  390. }
  391. $condition=[["is_del","=",0]];
  392. if($apply_id!==""){
  393. $condition[]=["apply_id","=",$apply_id];
  394. }
  395. if($apply_name!==""){
  396. $condition[]=["apply_name","like","%$apply_name%"];
  397. }
  398. if($status!==""){
  399. $condition[]=["status","=",$status];
  400. }
  401. if($tradNo!==""){
  402. $condition[]=["tradNo","like","%$tradNo%"];
  403. }
  404. $list =Db::name("trade_pool")->where($condition)->order("addtime desc")->select();
  405. return app_show(0,"获取成功",$list);
  406. }
  407. //资金详情
  408. public function tradeInfo(){
  409. $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):"";
  410. if($tradNo==""){
  411. return error_show(1004,"参数 tradNo 不能为空");
  412. }
  413. $tradinfo = Db::name("trade")->where(["tradNo"=>$tradNo,"is_del"=>0])->find();
  414. if($tradinfo==false){
  415. return error_show(1004,"资金信息未找到");
  416. }
  417. return app_show(0,"获取成功",$tradinfo);
  418. }
  419. //资金认领详情
  420. public function logInfo(){
  421. $logNo =isset($this->post['logNo'])&&$this->post['logNo']!=""? trim($this->post['logNo']):"";
  422. if($logNo==""){
  423. return error_show(1004,"参数 logNo 不能为空");
  424. }
  425. $tradinfo = Db::name("trade_pool")->where(["logNo"=>$logNo,"is_del"=>0])->find();
  426. if($tradinfo==false){
  427. return error_show(1004,"资金信息未找到");
  428. }
  429. $trade = Db::name("trade")->where(["tradNo"=>$tradinfo['tradNo'],"is_del"=>0])->find();
  430. $tradinfo['trade_out']= $trade['trade_out']??"";
  431. $tradinfo['trade_in']= $trade['trade_in']??"";
  432. $tradinfo['trade_bank']= $trade['trade_bank']??"";
  433. $tradinfo['customerNo']= $trade['customerNo']??"";
  434. $tradinfo['companyNo']= $trade['companyNo']??"";
  435. $tradinfo['total_fee']= $trade['total_fee']??"";
  436. $tradinfo['balance']= $trade['balance']??"";
  437. $tradinfo['used_fee']= $trade['used_fee']??"";
  438. $orderinfo = Db::name("assoc")->alias("a")->leftJoin("qrd_info c","a.orderCode=c.sequenceNo")
  439. ->where(["a.viceCode"=>$logNo,"a.is_del"=>0,"a.status"=>[1,2,3]])
  440. ->order("a.addtime desc")
  441. ->field("c.*,a.cancel_fee")
  442. ->findOrEmpty();
  443. $tradinfo['orderinfo']=$orderinfo;
  444. return app_show(0,"获取成功",$tradinfo);
  445. }
  446. //认领资金退回或退款 type 1 退款 2 解除资金认领
  447. public function ReturnPay(){
  448. $logNo = isset($this->post['logNo'])&&$this->post['logNo']!="" ? trim($this->post['logNo']):"";
  449. if($logNo==''){
  450. return error_show(1004,"参数 logNo 不能为空");
  451. }
  452. $type = isset($this->post['type'])&&$this->post['type']!="" ? intval($this->post['type']):"";
  453. if($type==""){
  454. return error_show(1004,"参数 type 不能为空");
  455. }
  456. $loginfo = Db::name("trade_pool")->where(["logNo"=>$logNo,"is_del"=>0])->find();
  457. if($loginfo==false){
  458. return error_show(1004,"认领资金信息未找到");
  459. }
  460. if($loginfo['status']!=2)return error_show(1004,"认领资金信息审核未通过");
  461. $tradinfo = Db::name("trade")->where(["tradNo"=>$loginfo['tradNo'],"is_del"=>0])->find();
  462. if($tradinfo==false){
  463. return error_show(1004,"资金信息未找到");
  464. }
  465. $reason = isset($this->post['return_reason'])&&$this->post['return_reason']!="" ? trim($this->post['return_reason']):"";
  466. $remark = isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']):"";
  467. $returnCode =makeNo("RTA");
  468. $data=[
  469. "returnCode"=>$returnCode,
  470. "logNo"=>$logNo,
  471. "companyNo"=>$tradinfo['companyNo'],
  472. "tradNo"=>$loginfo['tradNo'],
  473. "type"=>$type,
  474. "apply_id"=>$this->uid,
  475. "apply_name"=>$this->uname,
  476. "return_reason"=>$reason,
  477. "remark"=>$remark,
  478. "addtime"=>date("Y-m-d H:i:s"),
  479. "updatetime"=>date("Y-m-d H:i:s")
  480. ];
  481. $in = Db::name("trade_return")->insert($data);
  482. if($in){
  483. return app_show(0,"申请新建成功");
  484. }else{
  485. return error_show(1004,"申请新建失败");
  486. }
  487. }
  488. /**退款列表
  489. * //page size tradNo logNo apply_id apply_name type status returnCode
  490. * @return \think\response\Json|void
  491. * @throws \think\db\exception\DataNotFoundException
  492. * @throws \think\db\exception\DbException
  493. * @throws \think\db\exception\ModelNotFoundException
  494. */
  495. public function returnList(){
  496. $page=isset($this->post['page'])&&$this->post['page']!='' ? intval($this->post['page']):1;
  497. $size=isset($this->post['size'])&&$this->post['size']!='' ? intval($this->post['size']):15;
  498. $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=''?trim($this->post['tradNo']):"";
  499. $logNo =isset($this->post['logNo'])&&$this->post['logNo']!=''?trim($this->post['logNo']):"";
  500. $apply_id =isset($this->post['apply_id'])&&$this->post['apply_id']!=''?intval($this->post['apply_id']):"";
  501. $apply_name =isset($this->post['apply_name'])&&$this->post['apply_name']!=''?trim($this->post['apply_name']):"";
  502. $type =isset($this->post['type'])&&$this->post['type']!=''?intval($this->post['type']):"";
  503. $status =isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):"";
  504. $returnCode =isset($this->post['returnCode'])&&$this->post['returnCode']!=''?trim($this->post['returnCode']):"";
  505. $orderCode =isset($this->post['orderCode'])&&$this->post['orderCode']!=''?trim($this->post['orderCode']):"";
  506. $companyNo =isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']):"";
  507. if($companyNo!==""){
  508. $condition[]=["a.companyNo","=",$companyNo];
  509. }
  510. $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
  511. if($relaComNo!=""){
  512. $condition[]=["a.companyNo","=",$relaComNo];
  513. }
  514. $condition=[["a.is_del","=",0]];
  515. if($tradNo!=''){
  516. $condition[]=["a.tradNo","like","%$tradNo%"];
  517. }
  518. if($orderCode!=''){
  519. $condition[]=["b.orderCode","like","%$orderCode%"];
  520. }
  521. if($logNo!=''){
  522. $condition[]=["a.logNo","like","%$logNo%"];
  523. }
  524. if($apply_id!=''){
  525. $condition[]=["a.apply_id","=",$apply_id];
  526. }
  527. if($apply_name!=''){
  528. $condition[]=["a.apply_name","like","%$apply_name%"];
  529. }
  530. if($returnCode!=''){
  531. $condition[]=["a.returnCode","like","%$returnCode%"];
  532. }
  533. if($type!=''){
  534. $condition[]=["a.type","=",$type];
  535. }
  536. if($status!==''){
  537. $condition[]=["a.status","=",$status];
  538. }
  539. $count =Db::name("trade_return")->alias("a")
  540. ->leftJoin("assoc b","a.logNo=b.viceCode")
  541. ->leftJoin("qrd_info c","c.sequenceNo=b.orderCode")
  542. ->where($condition)->count();
  543. $total=ceil($count/$size);
  544. $page = $page>$total ? intval($total):$page;
  545. $list=Db::name("trade_return")->alias("a")->leftJoin("assoc b","a.logNo=b.viceCode")
  546. ->leftJoin("qrd_info c","c.sequenceNo=b.orderCode")
  547. ->field("a.*,b.orderCode,c.qrdSource,goodNo,goodName,qrdType,c.ownerName,c.ownerid,c.department,c.poCode,c.platName,b.cancel_fee,c.customerName")
  548. ->where($condition)->page($page,$size)->order("a.addtime desc")->select();
  549. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  550. }
  551. //退款状态审核 0 待审核 1 财务审核 2 财务驳回
  552. public function returnStatus(){
  553. $returnCode=isset($this->post['returnCode'])&&$this->post['returnCode']!=''?trim($this->post['returnCode']):"";
  554. if($returnCode==''){
  555. return error_show(1004,"参数 returnCode 不能为空");
  556. }
  557. $returninfo =Db::name("trade_return")->where(["returnCode"=>$returnCode,"is_del"=>0])->find();
  558. if($returninfo==false){
  559. return error_show(1004,"退款申请数据未找到");
  560. }
  561. $status=isset($this->post['status']) &&$this->post['status']!=''?intval($this->post['status']) : '';
  562. if($status==''){
  563. return error_show(1004,"参数 status 不能为空");
  564. }
  565. $return_img = isset($this->post['return_img'])&&$this->post['return_img']!=''?trim($this->post['return_img']):"";
  566. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  567. $loginfo = Db::name("trade_pool")->where(["logNo"=>$returninfo['logNo'],"is_del"=>0])->find();
  568. if($loginfo==false){
  569. return error_show(1004,"认领资金信息未找到");
  570. }
  571. if($loginfo['status']!=2)return error_show(1004,"认领资金信息审核未通过");
  572. Db::startTrans();
  573. try{
  574. $update=["status"=>$status,"return_img"=>$return_img,"remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")];
  575. $up =Db::name("trade_return")->where($returninfo)->update($update);
  576. if($up){
  577. if($status==1){
  578. $qrdArr=Db::name("assoc")->where(["viceCode"=>$returninfo['logNo'],"status"=>2,"is_del"=>0])->select()
  579. ->toArray();
  580. if(!empty($qrdArr)){
  581. foreach ($qrdArr as $value){
  582. $qrd =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->field("id,status,pay_fee,apay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty();
  583. if(empty($qrd)){
  584. Db::rollback();
  585. return error_show(1005,"未找到销售单数据");
  586. }
  587. if($qrd['apay_fee']<$value['cancel_fee']){
  588. Db::rollback();
  589. return error_show(1005,"销售单待付金额不足");
  590. }
  591. $update =[
  592. "wpay_fee"=>$qrd['wpay_fee']+$value['cancel_fee'],
  593. "apay_fee"=>$qrd['apay_fee']-$value['cancel_fee'],
  594. "pay_status"=>($qrd['apay_fee']-$value['cancel_fee'])==0 && $qrd['pay_fee']==0 ? 1:2,
  595. "status"=>$qrd['pay_fee']==0 && ($qrd['apay_fee']-$value['cancel_fee'])==0 ?0:1,
  596. "updatetime"=>date("Y-m-d H:i:s")
  597. ];
  598. $qrdup =Db::name("qrd_info")->where($qrd)->update($update);
  599. if($qrdup==false){
  600. Db::rollback();
  601. return error_show(1005,"销售单更新失败");
  602. }
  603. $asscup =[
  604. "status"=>3,
  605. "updatetime"=>date("Y-m-d H:i:s")
  606. ];
  607. $assc=Db::name("assoc")->where($value)->update($asscup);
  608. if($assc==false){
  609. Db::rollback();
  610. return error_show(1005,"销售单更新失败");
  611. }
  612. $report=ReportCode::where(["qrdNo"=>$value['orderCode']])->find();
  613. if($report)$report->setField("returnTrad",$returnCode);
  614. }
  615. }
  616. $logup =["status"=>$returninfo['type']==1?5:4,"updatetime"=>date("Y-m-d H:i:s")];
  617. $upde =Db::name("trade_pool")->where($loginfo)->update($logup);
  618. if($upde==false){
  619. Db::rollback();
  620. return error_show(1005,"资金认领信息更新失败");
  621. }
  622. // if($returninfo['type']==1){
  623. $trade =Db::name("trade")->where(["tradNo"=>$returninfo['tradNo'],"is_del"=>0])->find();
  624. if($trade==false){
  625. Db::rollback();
  626. return error_show(1005,"资金信息未找到");
  627. }
  628. if($trade['used_fee']<$loginfo['total_fee']){
  629. Db::rollback();
  630. return error_show(1005,"资金信息已认领金额不足");
  631. }
  632. $tradup =[
  633. "used_fee"=>$trade['used_fee']-$loginfo['total_fee'],
  634. "balance"=>$trade['balance']+$loginfo['total_fee'],
  635. "status"=>($trade['used_fee']-$loginfo['total_fee'])==0 ?1 :2,
  636. "updatetime"=>date("Y-m-d H:i:s")
  637. ];
  638. $updaT=Db::name("trade")->where($trade)->update($tradup);
  639. if($updaT==false){
  640. Db::rollback();
  641. return error_show(1005,"资金信息更新失败");
  642. }
  643. // }
  644. }
  645. Db::commit();
  646. return app_show(0,"退款申请审核成功");
  647. }
  648. Db::rollback();
  649. return error_show(1004,'审核状态失败');
  650. }catch (\Exception $e){
  651. Db::rollback();
  652. return error_show(1004,$e->getMessage());
  653. }
  654. }
  655. //退款申请详情
  656. public function returnInfo(){
  657. $returnCode=isset($this->post['returnCode'])&&$this->post['returnCode']!=''?trim($this->post['returnCode']):"";
  658. if($returnCode==''){
  659. return error_show(1004,"参数 returnCode 不能为空");
  660. }
  661. $returninfo =Db::name("trade_return")->where(["returnCode"=>$returnCode,"is_del"=>0])->find();
  662. if($returninfo==false){
  663. return error_show(1004,"退款申请数据未找到");
  664. }
  665. $trade = Db::name("trade")->where(["tradNo"=>$returninfo['tradNo'],"is_del"=>0])->find();
  666. $returninfo['trade_out']= $trade['trade_out']??"";
  667. $returninfo['trade_in']= $trade['trade_in']??"";
  668. $returninfo['trade_bank']= $trade['trade_bank']??"";
  669. $returninfo['trade_time']= $trade['trade_time']??"";
  670. $returninfo['customerNo']= $trade['customerNo']??"";
  671. $returninfo['companyNo']= $trade['companyNo']??"";
  672. $returninfo['total_fee']= $trade['total_fee']??"";
  673. $returninfo['balance']= $trade['balance']??"";
  674. $returninfo['used_fee']= $trade['used_fee']??"";
  675. $pool =Db::name("trade_pool")->where(["logNo"=>$returninfo['logNo'],"is_del"=>0])->find();
  676. $returninfo['log_total_fee']= $pool['total_fee']??"";
  677. $returninfo['log_apply_id']= $pool['apply_id']??"";
  678. $returninfo['log_apply_name']= $pool['apply_name']??"";
  679. $orderinfo = Db::name("assoc")->alias("a")->leftJoin("qrd_info c","a.orderCode=c.sequenceNo")
  680. ->where(["a.viceCode"=>$returninfo['logNo'],"a.is_del"=>0,"a.status"=>[1,2]])
  681. ->order("a.addtime desc")
  682. ->field("c.*")
  683. ->findOrEmpty();
  684. $returninfo['orderinfo'] = $orderinfo;
  685. return app_show(0,"获取成功",$returninfo);
  686. }
  687. /**
  688. * 显示创建资源表单页.
  689. *
  690. * @return \think\Response
  691. */
  692. public function importTrade()
  693. {
  694. $files = $this->request->file("excel");
  695. $data = upload($files,$files->getOriginalExtension());
  696. if($data['code']!=0){
  697. return error_show(1004,$data['msg']);
  698. }
  699. $trade = $data['data'];
  700. $list = [];
  701. foreach ( $trade as $key => $value) {
  702. if (!isset($value[0]) || $value[0] == '') {
  703. //return ['code' => 1003, "msg" => '交易时间不能为空'];
  704. return error_show( 1003, '第'.($key+1).'行收款方公司编号不能为空!');
  705. }
  706. if (!isset($value[4]) || $value[4] == '') {
  707. // return ['code' => 1003, "msg" => '交易行名不能为空'];
  708. return error_show( 1003, '第'.($key+1).'行收入金额不能为空!');
  709. }
  710. if (!isset($value[8]) || $value[8] == '') {
  711. // return ['code' => 1003, "msg" => '对方账户不能为空'];
  712. return error_show( 1003, '第'.($key+1).'行对方账户不能为空!');
  713. }
  714. if (!isset($value[9]) || $value[9] == '') {
  715. // return ['code' => 1003, "msg" => '对方户名不能为空'];
  716. return error_show( 1003, '第'.($key+1).'行对方户名不能为空!');
  717. }
  718. if ($key == 0) {
  719. if ($value[0] != '收款方公司编号') {
  720. // return ['code' => 1003, "msg" => '模板第一列为必须为交易时间!'];
  721. return error_show( 1003, '模板第一列为必须为收款方公司编号!');
  722. }
  723. if ($value[4] != '收入金额') {
  724. // return ['code' => 1003, "msg" => '模板第二列为必须为收入金额!'];
  725. return error_show( 1003, '模板第五列为必须为收入金额!');
  726. }
  727. if ($value[6] != '交易行名') {
  728. //return ['code' => 1003, "msg" => '模板第五列为必须为交易行名!'];
  729. return error_show( 1003, '模板第七列为必须为交易行名!');
  730. }
  731. if ($value[8] != '对方账号') {
  732. // return ['code' => 1003, "msg" => '模板第七列为必须为对方账号!'];
  733. return error_show( 1003, '模板第九列为必须为对方账号!');
  734. }
  735. if ($value[9] != '对方户名') {
  736. // return ['code' => 1003, "msg" => '模板第八列为必须为对方户名!'];
  737. return error_show( 1003, '模板第十列为必须为对方户名!');
  738. }
  739. continue;
  740. }
  741. $company =Db::name("company_info")->where(["companyNo"=>$value[0]])->findOrEmpty();
  742. if(empty($company)){
  743. return error_show( 1003, "业务公司编号不存在{$value[0]}");
  744. }
  745. $total_fee = $value[4];
  746. $type = 0;
  747. $time = explode(" ", $value[3]);
  748. $list[$key]["tradeTime"] = date("Y-m-d", strtotime($time[0])) . " " . (isset($time[1]) ? $time[1] : "00:00:00");
  749. $list[$key]["trade_fee"] = str_replace(",","",$total_fee);
  750. $list[$key]["trade_bank"] = $value[6];
  751. $list[$key]["trade_account"] = $value[8];
  752. $list[$key]["trade_out"] = $value[9];
  753. $list[$key]["trade_in"] = $value[1]??$company['company_name'];
  754. $list[$key]["trade_type"] = $type;
  755. $list[$key]["trade_used"] = isset($value[10]) ? $value[10] : "";
  756. $list[$key]["trade_remark"] = '';
  757. $list[$key]["companyNo"] = $value[0];
  758. $list[$key]["trade_in_account"] = $value[2]??"";
  759. }
  760. if(empty($list)){
  761. return error_show( 1003, '导入数据不能为空!');
  762. }
  763. Db::startTrans();
  764. try{
  765. $tra=[];
  766. foreach ($list as $value) {
  767. $temp = [];
  768. $temp["tradNo"] = makeStr('S');
  769. $temp['trade_time'] = $value['tradeTime'];
  770. $temp['total_fee'] = $value['trade_fee'];
  771. $temp['trade_bank'] = $value['trade_bank'];
  772. $temp['trade_account'] = $value['trade_account'];
  773. $temp['trade_type'] =$value['trade_type'];
  774. $temp['trade_out'] = $value['trade_out'];
  775. $temp['trade_in'] = $value['trade_in'];
  776. $temp['trade_in_account'] = $value['trade_in_account'];
  777. $temp['companyNo'] = $value['companyNo'];
  778. $temp['trade_used'] = $value['trade_used'];
  779. $temp['trade_remark'] = $value['trade_remark'];
  780. $temp['balance'] =$value['trade_fee'];
  781. $temp['addtime'] = date("Y-m-d H:i:s");
  782. $temp['updatetime'] = date("Y-m-d H:i:s");
  783. $tra[]=$temp;
  784. }
  785. $list = Db::name('trade')->insertAll($tra);
  786. if($list==count($tra)){
  787. Db::commit();
  788. return app_show(0, "资金导入成功");
  789. }else{
  790. Db::rollback();
  791. return app_show(1004, "资金导入失败");
  792. }
  793. }catch (\Exception $e){
  794. Db::rollback();
  795. return app_show(1004, $e->getMessage());
  796. }
  797. }
  798. /**
  799. * @return \think\response\Json|void
  800. */
  801. public function importTradeByArr()
  802. {
  803. $trade =isset($this->post['data']) &&!empty($this->post['data'])? $this->post['data']:[];
  804. if(!is_array($trade) || empty($trade) ) return error_show( 1003,"参数 data 不能为空");
  805. $list = [];
  806. foreach ( $trade as $key => $value) {
  807. if (!isset($value[0]) || $value[0] == '') {
  808. //return ['code' => 1003, "msg" => '交易时间不能为空'];
  809. return error_show( 1003, '第'.($key+1).'行收款方公司编号不能为空!');
  810. }
  811. if (!isset($value[2]) || $value[2] == '') {
  812. //return ['code' => 1003, "msg" => '交易时间不能为空'];
  813. return error_show( 1003, '第'.($key+1).'行收款账户不能为空!');
  814. }
  815. if (!isset($value[3]) || $value[3] == '') {
  816. //return ['code' => 1003, "msg" => '交易时间不能为空'];
  817. return error_show( 1003, '第'.($key+1).'行交易时间不能为空!');
  818. }
  819. if (!isset($value[4]) || $value[4] == '') {
  820. // return ['code' => 1003, "msg" => '交易行名不能为空'];
  821. return error_show( 1003, '第'.($key+1).'行收入金额不能为空!');
  822. }
  823. if (!isset($value[6]) || $value[6] == '') {
  824. // return ['code' => 1003, "msg" => '交易行名不能为空'];
  825. return error_show( 1003, '第'.($key+1).'行交易银行名称不能为空!');
  826. }
  827. if (!isset($value[8]) || $value[8] == '') {
  828. // return ['code' => 1003, "msg" => '对方账户不能为空'];
  829. return error_show( 1003, '第'.($key+1).'行对方账户不能为空!');
  830. }
  831. if (!isset($value[9]) || $value[9] == '') {
  832. // return ['code' => 1003, "msg" => '对方户名不能为空'];
  833. return error_show( 1003, '第'.($key+1).'行对方户名不能为空!');
  834. }
  835. // if ($key == 0) {
  836. // if ($value[0] != '收款方公司编号') {
  837. // // return ['code' => 1003, "msg" => '模板第一列为必须为交易时间!'];
  838. // return error_show( 1003, '模板第一列为必须为收款方公司编号!');
  839. // }
  840. // if ($value[4] != '收入金额') {
  841. // // return ['code' => 1003, "msg" => '模板第二列为必须为收入金额!'];
  842. // return error_show( 1003, '模板第五列为必须为收入金额!');
  843. // }
  844. //
  845. // if ($value[6] != '交易行名') {
  846. // //return ['code' => 1003, "msg" => '模板第五列为必须为交易行名!'];
  847. // return error_show( 1003, '模板第七列为必须为交易行名!');
  848. // }
  849. // if ($value[8] != '对方账号') {
  850. // // return ['code' => 1003, "msg" => '模板第七列为必须为对方账号!'];
  851. // return error_show( 1003, '模板第九列为必须为对方账号!');
  852. // }
  853. // if ($value[9] != '对方户名') {
  854. // // return ['code' => 1003, "msg" => '模板第八列为必须为对方户名!'];
  855. // return error_show( 1003, '模板第十列为必须为对方户名!');
  856. // }
  857. // continue;
  858. // }
  859. $company =Db::name("company_info")->where(["companyNo"=>$value[0]])->findOrEmpty();
  860. if(empty($company)){
  861. return error_show( 1003, "业务公司编号不存在{$value[0]}");
  862. }
  863. $total_fee = $value[4];
  864. $type = 0;
  865. $time = explode(" ", $value[3]);
  866. $list[$key]["tradeTime"] = date("Y-m-d", strtotime($time[0])) . " " . (isset($time[1]) ? $time[1] : "00:00:00");
  867. $list[$key]["trade_fee"] = str_replace(",","",$total_fee);
  868. $list[$key]["trade_bank"] = $value[6];
  869. $list[$key]["trade_account"] = $value[8];
  870. $list[$key]["trade_out"] = $value[9];
  871. $list[$key]["trade_in"] = $value[1]??$company['company_name'];
  872. $list[$key]["trade_type"] = $type;
  873. $list[$key]["trade_used"] = isset($value[10]) ? $value[10] : "";
  874. $list[$key]["trade_remark"] = '';
  875. $list[$key]["companyNo"] = $value[0];
  876. $list[$key]["trade_in_account"] = $value[2]??"";
  877. }
  878. if(empty($list)){
  879. return error_show( 1003, '导入数据不能为空!');
  880. }
  881. Db::startTrans();
  882. try{
  883. $tra=[];
  884. foreach ($list as $value) {
  885. $temp = [];
  886. $temp["tradNo"] = makeStr('S');
  887. $temp['trade_time'] = $value['tradeTime'];
  888. $temp['total_fee'] = $value['trade_fee'];
  889. $temp['trade_bank'] = $value['trade_bank'];
  890. $temp['trade_account'] = $value['trade_account'];
  891. $temp['trade_type'] =$value['trade_type'];
  892. $temp['trade_out'] = $value['trade_out'];
  893. $temp['trade_in'] = $value['trade_in'];
  894. $temp['trade_in_account'] = $value['trade_in_account'];
  895. $temp['companyNo'] = $value['companyNo'];
  896. $temp['trade_used'] = $value['trade_used'];
  897. $temp['trade_remark'] = $value['trade_remark'];
  898. $temp['balance'] =$value['trade_fee'];
  899. $temp['addtime'] = date("Y-m-d H:i:s");
  900. $temp['updatetime'] = date("Y-m-d H:i:s");
  901. $tra[]=$temp;
  902. }
  903. $list = Db::name('trade')->insertAll($tra);
  904. if($list==count($tra)){
  905. Db::commit();
  906. return app_show(0, "资金导入成功");
  907. }else{
  908. Db::rollback();
  909. return app_show(1004, "资金导入失败");
  910. }
  911. }catch (\Exception $e){
  912. Db::rollback();
  913. return app_show(1004, $e->getMessage());
  914. }
  915. }
  916. }