OrderPay.php 47 KB

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