ThirdPayServices.php 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223
  1. <?php
  2. /**
  3. * 支付宝支付
  4. */
  5. namespace app\api\services;
  6. use app\common\model\PaymentModel;
  7. use app\common\model\ServicesOrderModel;
  8. use app\common\model\ShopGoodsModel;
  9. use app\common\model\ShopOrderGoodsModel as OrderGoods;
  10. use app\common\model\ShopOrderModel;
  11. use app\common\model\ShopOrderModel as Order;
  12. use app\common\model\UserBankSignModel;
  13. use app\common\model\UserModel;
  14. use app\common\model\WithDrawLogModel;
  15. use app\common\service\PaymentService;
  16. use app\common\service\UserBankSignService;
  17. use app\common\service\UserService;
  18. use think\Exception;
  19. use think\facade\Db;
  20. use utils\RedisCache;
  21. class ThirdPayServices extends BasePayServices
  22. {
  23. /**
  24. * 多乐宝支付宝支付
  25. * @param $uid
  26. * @param $params
  27. * @return \think\Response
  28. * @throws Exception
  29. */
  30. public function getPayInfo($uid, $params)
  31. {
  32. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  33. $out_trade_no1 = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  34. $params = [
  35. 'appid' => '9d5e3cb9a4946cf28a42b99f4f8bf978',
  36. 'method' => 'payment.wxjsapp',
  37. 'merchant' => '220951176399985946',
  38. 'body' => '购买商品',
  39. 'external_order_no' => $out_trade_no1, // 我们自己的订单号
  40. 'total_amount' => $total_amount,
  41. // 'notify_url'=>'http://api.meikangjw.com/api/aliResult'
  42. 'notify_url' => 'http://zy.suncorex.com:2080/api/aliResultDLB'
  43. ];
  44. $sign = thirdPayGetSign($params, '897d9ea909093173b24dd89c772181e4');
  45. $params['sign'] = $sign;
  46. $res = _curlrequest('http://openpay.duolaibei.com/api/gateway', $params, 'post');
  47. $res = json_decode($res);
  48. if ($res && isset($res->code) && $res->code == 200) {
  49. $out_trade_no = $res->content->order_no;
  50. $this->setPaymentOrder(compact('body', 'out_trade_no', 'out_trade_no1', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 5);
  51. // return api_succ_return(['msg'=>'请求成功', 'data'=>['thirdpaydlbalipay'=>['url'=>$res->content->url]]]);
  52. return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpaydlbwx' => ['url' => $res->content->url, 'jsappid' => $res->content->JSAPPID]]]);
  53. } else {
  54. return api_error_return('获取失败');
  55. }
  56. }
  57. /**
  58. * 多乐宝微信支付
  59. * @param $uid
  60. * @param $params
  61. * @return \think\Response
  62. * @throws Exception
  63. */
  64. public function getWxPayInfo($uid, $params)
  65. {
  66. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  67. $out_trade_no1 = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  68. $params = [
  69. 'appid' => '9d5e3cb9a4946cf28a42b99f4f8bf978',
  70. 'method' => 'payment.wxjsapp',
  71. 'merchant' => '220951176399985946',
  72. 'body' => '购买商品',
  73. 'external_order_no' => $out_trade_no1, // 我们自己的订单号
  74. 'total_amount' => $total_amount,
  75. // 'notify_url'=>'http://api.meikangjw.com/api/aliResult'
  76. 'notify_url' => 'http://zy.suncorex.com:2080/api/wechatResultDLB'
  77. ];
  78. $sign = thirdPayGetSign($params, '897d9ea909093173b24dd89c772181e4');
  79. $params['sign'] = $sign;
  80. // return $params;
  81. $res = _curlrequest('http://openpay.duolaibei.com/api/gateway', $params, 'post');
  82. // sr_log(sr_getcurtime(time()).$res);
  83. // {"code":200,"msg":"success","content":{"order_no":"DLB1649853909589099089998901OP","external_order_no":"12365847092204130845091649853909","total_amount":11970,"body":"\u8d2d\u4e70\u5546\u54c1","trans_type":"AL_JSAPP","JSAPPID":"2021002148663267","url":"alipays:\/\/platformapi\/startapp?appId=2021002148663267&page=pages\/open-pay\/open-pay&query=order_no%3DDLB1649853909589099089998901OP","sign":"FA06F884C143DA40E505950918D4AD45"}}
  84. $res = json_decode($res);
  85. if ($res && isset($res->code) && $res->code == 200) {
  86. $out_trade_no = $res->content->order_no;
  87. $this->setPaymentOrder(compact('body', 'out_trade_no', 'out_trade_no1', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 5);
  88. // return api_succ_return(['msg'=>'请求成功', 'data'=>['thirdpaydlbalipay'=>['url'=>$res->content->url]]]);
  89. return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpaydlbwx' => ['url' => $res->content->url, 'jsappid' => $res->content->JSAPPID]]]);
  90. } else {
  91. return api_error_return('获取失败');
  92. }
  93. }
  94. /**
  95. * 畅联微信支付
  96. * @param $uid
  97. * @param $params
  98. * @return \think\Response
  99. * @throws Exception
  100. */
  101. public function getWxPayInfoCL($uid, $params)
  102. {
  103. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  104. $out_trade_no = 'CL' . rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  105. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  106. $error_url = getWebUrl() . '/api/thirdPayClError';
  107. $params = [
  108. 'appid' => '1059174',
  109. 'pay_type' => 'partnerJs',
  110. 'amount' => sprintf("%.2f", $total_amount),
  111. 'callback_url' => getWebUrl() . '/api/wechatResultCL',
  112. 'success_url' => $success_url,
  113. 'error_url' => $error_url,
  114. 'extend' => '{"body":"购买商品"}',
  115. 'out_trade_no' => $out_trade_no
  116. ];
  117. // sr_log(json_encode($params));
  118. $sign = thirdPayGetSignCL('XMLfjHMPOGexsSaadIWSVCNG0XJBClZZ', $params);
  119. $params['sign'] = $sign;
  120. // sr_log(json_encode($params));
  121. // return $params;
  122. $res = _curlrequest('https://api.payunk.com/index/unifiedorder?format=json', $params, 'post');
  123. sr_log(sr_getcurtime(time()) . $res);
  124. $res = json_decode($res);
  125. if ($res && isset($res->code) && $res->code == 200) {
  126. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 7);
  127. return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpayclwx' => ['url' => $res->url, 'success_url' => $success_url, 'error_url' => $error_url]]]);
  128. } else {
  129. return api_error_return('获取失败');
  130. }
  131. }
  132. /**
  133. * 畅联支付宝支付 type aban(A版本) h5ban(h5版本) dban(D版本)
  134. * @param $uid
  135. * @param $params
  136. * @param $type
  137. * @return \think\Response
  138. * @throws Exception
  139. */
  140. public function getAliPayInfoCL($uid, $params, $type)
  141. {
  142. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  143. // 这是测试 线要干掉
  144. // $total_amount = floatval('0.'.mt_rand(1, 3).mt_rand(1, 9));
  145. // $total_amount = 0.01;
  146. $out_trade_no = 'CL' . rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  147. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  148. $error_url = getWebUrl() . '/api/thirdPayClError';
  149. $type_arr = [
  150. 'aban' => 'alipayApp',
  151. 'h5ban' => 'adapayH5',
  152. 'dban' => 'alipayPrecreate'
  153. ];
  154. $params = [
  155. 'appid' => '1059174',
  156. 'pay_type' => $type_arr[$type],
  157. 'amount' => sprintf("%.2f", $total_amount),
  158. 'callback_url' => getWebUrl() . '/api/AliResultCL',
  159. 'success_url' => $success_url,
  160. 'error_url' => $error_url,
  161. 'extend' => '{"body":"购买商品","subject":"购买商品"}',
  162. 'out_trade_no' => $out_trade_no
  163. ];
  164. // sr_log(json_encode($params));
  165. $sign = thirdPayGetSignCL('XMLfjHMPOGexsSaadIWSVCNG0XJBClZZ', $params);
  166. $params['sign'] = $sign;
  167. // sr_log(json_encode($params));
  168. // return $params;
  169. $res = _curlrequest('https://api2.payunk.com/index/unifiedorder?format=json', $params, 'post');
  170. // sr_log(sr_getcurtime(time()).$res);
  171. $res = json_decode($res);
  172. if ($res && isset($res->code) && $res->code == 200) {
  173. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), ($type == 'aban' ? 10 : 8));
  174. return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpayclali' => ['url' => $res->url, 'success_url' => $success_url, 'error_url' => $error_url]]]);
  175. } else {
  176. return api_error_return('获取失败');
  177. }
  178. }
  179. /**
  180. * mo宝 富有 银联支付
  181. * @param $uid
  182. * @param $paramscon
  183. * @return \think\Response
  184. * @throws Exception
  185. */
  186. public function getBankPayInfoFY($uid, $paramscon)
  187. {
  188. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $paramscon);
  189. // 商户号
  190. $mchnt_cd = env('api.PAY_FUYOU_MCHNT_id');
  191. $time = time();
  192. $time_end = time() + 2 * 60 * 60;
  193. $order_date = sr_getcurtime($time, 'Ymd');
  194. $order_timestart = sr_getcurtime($time, 'YmdHis');
  195. $order_timeend = sr_getcurtime($time_end, 'YmdHis');
  196. $order_id = $paramscon['order_id'];
  197. $out_trade_no = 'FYYL' . $order_id;
  198. $mess_arr = ['mchnt_cd' => $mchnt_cd, 'order_date' => $order_date, 'order_id' => $paramscon['order_id'], 'ver' => '1.0.0'];
  199. // sr_log('message_json'.json_encode($mess_arr));
  200. $params = ['mchnt_cd' => $mchnt_cd, 'message' => RSA_openssl(json_encode($mess_arr))];
  201. // 测试
  202. // $url = 'https://aggapp-test.fuioupay.com/token.fuiou';
  203. // 正式
  204. $url = 'https://aggapp.fuioupay.com/token.fuiou';
  205. $ch = curl_init();
  206. curl_setopt($ch, CURLOPT_URL, $url);
  207. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  208. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  209. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  210. $headers = ['Content-type: application/json'];
  211. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  212. // POST数据
  213. curl_setopt($ch, CURLOPT_POST, 1);
  214. // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  215. // 把post的变量加上
  216. $data = json_encode($params);
  217. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  218. $output = curl_exec($ch);
  219. curl_close($ch);
  220. // sr_log('ccc'.$output);
  221. $rsares = json_decode($output);
  222. $res_decode = json_decode(RSA_openssl($rsares->message, 'decode'));
  223. sr_log('ccc' . json_encode($res_decode));
  224. if (isset($res_decode->order_date) && isset($res_decode->order_token) && isset($res_decode->mchnt_cd) && isset($res_decode->order_id)) {
  225. if ($res_decode->mchnt_cd == $mchnt_cd && $res_decode->order_id == $order_id) {
  226. $bank_params = [
  227. 'mchnt_cd' => $mchnt_cd,
  228. 'order_date' => $order_date,
  229. 'order_amt' => bcmul($total_amount, 100, 0),
  230. 'order_id' => $order_id,
  231. 'page_notifyurl' => ($paramscon['app_sources'] == 'ios' ? getWebUrl() . '/api/thirdPayClSuccess' : AESjiami(getWebUrl() . '/api/thirdPayClSuccess')),
  232. 'back_notifyurl' => ($paramscon['app_sources'] == 'ios' ? getWebUrl() . '/api/BankResultFY' : AESjiami(getWebUrl() . '/api/BankResultFY')),
  233. 'order_timestart' => $order_timestart,
  234. 'order_timeend' => $order_timeend,
  235. 'order_token' => $res_decode->order_token
  236. ];
  237. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 9);
  238. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayflyl' => $bank_params]]);
  239. } else {
  240. return api_error_return('获取失败,订单校验失败1');
  241. }
  242. } else {
  243. return api_error_return('获取失败,订单校验失败');
  244. }
  245. return api_error_return('获取失败');
  246. }
  247. /**
  248. * 易票联 支付宝支付
  249. * @param $uid
  250. * @param $params
  251. * @return \think\Response
  252. * @throws Exception
  253. */
  254. public function getZfbPayInfoYPL($uid, $params)
  255. {
  256. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  257. $order_id = $params['order_id'];
  258. $out_trade_no = 'YPL' . $order_id . mt_rand(1, 10000);
  259. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  260. $error_url = getWebUrl() . '/api/thirdPayClError';
  261. $notify_url = getWebUrl() . '/api/ZfbResultYPL';
  262. $orderInfo = array();
  263. $orderInfo['Id'] = 'id34535';
  264. $orderInfo['businessType'] = '130001';
  265. $orderInfo['goodsList'] = array(array('name' => 'pay', 'number' => 'one', 'amount' => 1));
  266. $params = [
  267. 'areaInfo' => '440106',
  268. 'attachData' => 'attachData',
  269. 'clientIp' => request()->ip(),
  270. 'customerCode' => '562012003860535',
  271. 'nonceStr' => nonce_str(32),
  272. 'notifyUrl' => $notify_url,
  273. 'orderInfo' => $orderInfo,
  274. 'outTradeNo' => $out_trade_no,
  275. 'payAmount' => bcmul($total_amount, 100, 0),
  276. 'payCurrency' => 'CNY',
  277. 'payMethod' => '7',
  278. 'redirectUrl' => $success_url,
  279. 'transactionStartTime' => date('YmdHis'),
  280. 'version' => '3.0'
  281. ];
  282. sr_log(json_encode($params));
  283. // 测试
  284. // $url = 'http://test-efps.epaylinks.cn';
  285. // 正式
  286. $url = 'https://efps.epaylinks.cn';
  287. $url = $url . '/api/txs/pay/NativePayment';
  288. $sign = $this->YPLsign(json_encode($params));
  289. $headers = [
  290. // 'Content-type: application/json',
  291. 'x-efps-sign-no' => '562012003860535001',
  292. 'x-efps-sign-type' => 'SHA256withRSA',
  293. 'x-efps-sign' => $sign,
  294. 'x-efps-timestamp' => date('YmdHis')
  295. ];
  296. sr_log(json_encode('header' . json_encode($headers)));
  297. // J+08ZMVCkZnMq0roi3JikP//ODGsy9UvYBM09b921RvU0/3Z+4opOwAFQGPBLrKRGhkZzVhHRJwVDZHA9Iu/wWX13SJyowRYkr8zVsYivNQhYKyt3uPScdN/BVfLM3d5OuA9o2ypIqVuoinorYDsrqXixyYg7LEA4pWTDZc9dtuSRWFF+DFvLTW4UODyiwhBCq7bFaa+MOVmWuiahZMM79MhKxiTqsfFQLptsnlc2crlYuok2Bp2TAbEDM7FZhlLIGiidux0kaLhC3dK31tRc6Y72NlukXJc3sN4HVLqj0GAiw+9jzmGf0NwhvxdHvBC6/7uOp2ShCMxSXUA/qPbLmA7Vh/Zv0njHbxJ0j3oylrhjCjUKGPTKf//GD/vgnVQz2m3KXW6+60PBfWRYwQYkSPFRHj2lRALBYe97q4w0kWa9xO/2yRrIW2lNBqt7ZKSmSstsA+NgiOU4u/LCBmIoxMqk9HzygfDPLhQ9oimOuM/7d//qjP0z6mPD4SbhdVKjfgsp9yqN7h9jR3BJJxDGRAtzJJpDA6/YIcTbkDnJIvHwIx4Fkcf22tBYW436W7f +0GeMLxBp5mAr8qlDJt0R3GoPD4hZ5Omh/FxYhOjN9RKG8QcqSykZSQgYgVAKsGeFWVeXes2XNo2AB1F7MlGuZSypOTv73BL5iE75xJVjRupk6qplmOo2YHLKs8USDSX3Y+QprbAC8irxQ5QtK4ayGbLZ8BDHuKnGLLA1/ID++2ccYJsnfA+9cqvSTm8lo19W1btBl9iZQC8Wfv94rfDsIAe2pc3Gd+LJv47i1mwzK03SQ5c6W8LBxgtStinz/f8Rm5oVn6hTgoRfV93F8ZGRVj5K+KYva5qIjBSyweYToPoXCirUO0UdA96PmU7+oVVOVu4pDcqBJjuSxPXIzRLXbSQUlFHecKjedx2DuOlHPdVMhn2XRjpdd+Ka70Grbw0dro76EvaBzHC2x/rN7g8nIe7ReG4LS2ya07bIXrbHyk6b45XfrneBGHnKDpIX6ymlDKZ2NAWyfXkBEPhiQrsT3AVGrokFjMTRVqubXqRW29Q8if2C5MYduen34s3QtmVHaVUZ24N6cX5FIvCwZYIyBvpFrTCfQZztRz3QngjhclbngGGyBv040WFfQ/sqzkWgdO8XP7cIUWlKmD0xANVq9dQqQiwwcvYpWFzMTpQcw9daGYWltwfzKfRveVnXHyfxaq6XVeHlZCboTDv4Fg5/nVW+s4JCmTXNPedU53ZYcDkrrZcHbygFXgPPOM8KMlowq8KnA9lXUYunHATpa2Q9vKnTED8Ro9gn6IGFpGRdZIeuYOJ+vKMA9sy55AIQiJVUMit7iw2M0ZehPwm4k5Dpi6RMzgC/5+OZc1u+Rt13Borvd3/7EuyqaNwhUkITp7Kl0dv75PQkK0Btcsg+PLVs+2h+GadNurWhl3Bvo6y++5HbkcEfymSFV/phDaAZBTYQFyzjAJhwJizMUBp1HFOetOiLEZSs4iMPj/gwps0BSwqCCRFZXJj3ifLo+fi/bE3rU+/nHcTBo9Dhzw/EVE2KLF1QbZw3fGLnhHqCK+PyOv4i7NwEQKqsA==
  298. $response = $this->http_post_json($url, json_encode($params), $sign);
  299. sr_log($response);
  300. if ($response && $response[0] == 200) {
  301. $re_data = json_decode($response[1], true);
  302. if ($re_data['returnCode'] == '0000') {
  303. $payurl = $re_data['codeUrl'];
  304. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 12);
  305. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYPL' => ['pay_url' => $payurl]]]);
  306. // return api_succ_return(['msg'=>'成功', 'data'=>['thirdpay'=>['url'=>$payurl]]]);
  307. //
  308. }
  309. } else {
  310. return api_error_return('获取失败,请联系客服');
  311. }
  312. return api_error_return('获取失败,请联系客服');
  313. }
  314. /**
  315. * 易票联云闪付
  316. * @param $uid
  317. * @param $params
  318. * @return \think\Response
  319. * @throws Exception
  320. */
  321. public function getYsfPayInfoYPL($uid, $params)
  322. {
  323. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  324. // 商户号
  325. $mchnt_cd = env('api.PAY_FUYOU_MCHNT_id');
  326. $order_id = $params['order_id'];
  327. $out_trade_no = 'YPL' . $order_id . mt_rand(1, 10000);
  328. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  329. $error_url = getWebUrl() . '/api/thirdPayClError';
  330. $notify_url = getWebUrl() . '/api/ZfbResultYPL';
  331. $orderInfo = array();
  332. $orderInfo['Id'] = 'id34535';
  333. $orderInfo['businessType'] = '130001';
  334. $orderInfo['goodsList'] = array(array('name' => 'pay', 'number' => 'one', 'amount' => 1));
  335. // $order_timestart = sr_getcurtime($time, 'YmdHis');
  336. $params = [
  337. 'areaInfo' => '440106',
  338. 'attachData' => 'attachData',
  339. 'clientIp' => request()->ip(),
  340. 'customerCode' => '562012003860535',
  341. 'nonceStr' => nonce_str(32),
  342. 'notifyUrl' => $notify_url,
  343. 'orderInfo' => $orderInfo,
  344. 'outTradeNo' => $out_trade_no,
  345. 'payAmount' => bcmul($total_amount, 100, 0),
  346. 'payCurrency' => 'CNY',
  347. 'redirectUrl' => $success_url,
  348. 'transactionStartTime' => date('YmdHis'),
  349. 'version' => '3.0'
  350. ];
  351. sr_log('ypl' . json_encode($params));
  352. // 测试
  353. // $url = 'http://test-efps.epaylinks.cn';
  354. // 正式
  355. $url = 'https://efps.epaylinks.cn';
  356. $url = $url . '/api/txs/pay/UnionAppPayment';
  357. sr_log('yplurl:' . $url);
  358. $sign = $this->YPLsign(json_encode($params));
  359. $headers = [
  360. // 'Content-type: application/json',
  361. 'x-efps-sign-no' => '562012003860535001',
  362. 'x-efps-sign-type' => 'SHA256withRSA',
  363. 'x-efps-sign' => $sign,
  364. 'x-efps-timestamp' => date('YmdHis')
  365. ];
  366. sr_log('yplheader' . json_encode($headers));
  367. $response = $this->http_post_json($url, json_encode($params), $sign);
  368. sr_log('yplresponse' . json_encode($response));
  369. if ($response && $response[0] == 200) {
  370. $re_data = json_decode($response[1], true);
  371. if ($re_data['returnCode'] == '0000') {
  372. $tn = $re_data['tn'];
  373. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 13);
  374. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYPLYsf' => ['tn' => $tn]]]);
  375. //
  376. }
  377. } else {
  378. return api_error_return('获取失败,请联系客服');
  379. }
  380. return api_error_return('获取失败,请联系客服');
  381. }
  382. /**
  383. * 汇付支付宝支付
  384. * @param $uid
  385. * @param $params
  386. * @return \think\Response
  387. * @throws Exception
  388. */
  389. public function getHfPayInfoHF($uid, $params)
  390. {
  391. // 加载基础 adapay 基础类
  392. // SDK 初始化文件加载
  393. include_once "../extend/thirdpay/AdapaySdk/init.php";
  394. // 在文件中设置 DEBUG 为 true 时, 则可以打印日志到指定的日志目录下 LOG_DIR
  395. include_once "../extend/thirdpay/config.php";
  396. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  397. // 这是测试 线要干掉
  398. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  399. // 这是测试 线要干掉
  400. $total_amount = floatval('1.' . mt_rand(1, 3) . mt_rand(1, 9));
  401. }
  402. $time_end = time() + 2 * 60 * 60;
  403. $order_timeend = sr_getcurtime($time_end, 'YmdHis');
  404. $order_id = $params['order_id'];
  405. $out_trade_no = 'HFPAY' . $order_id . mt_rand(1, 10000);
  406. # 初始化支付类
  407. $payment = new \AdaPaySdk\Payment();
  408. # 支付设置
  409. $payment_params = array(
  410. "app_id" => "app_3906a188-adf7-4776-a126-fd1996b178d3",
  411. "order_no" => $out_trade_no,
  412. "pay_channel" => "alipay",
  413. "time_expire" => $order_timeend,
  414. "pay_amt" => strval(intval($total_amount)) . '.00',
  415. "goods_title" => "日用生活用品",
  416. "goods_desc" => "多宝购买商品",
  417. "description" => "购买商品",
  418. "notify_url" => getWebUrl() . '/api/ZfbResultHF'
  419. );
  420. sr_log('汇付支付请求参数:' . json_encode($payment_params));
  421. # 发起支付
  422. $payment->create($payment_params);
  423. # 对支付结果进行处理
  424. if ($payment->isError()) {
  425. //失败处理
  426. $response = $payment->result;
  427. sr_log('hfresponseerror' . json_encode($response));
  428. return api_error_return('获取失败,请联系客服');
  429. } else {
  430. //成功处理
  431. $response = $payment->result;
  432. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 14);
  433. $bank_params = [
  434. 'url' => $response['expend']['pay_info']
  435. ];
  436. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayhf' => $bank_params]]);
  437. }
  438. return api_error_return('获取失败,请联系客服');
  439. }
  440. /**
  441. * 易票联统一支付
  442. * @param $uid
  443. * @param $params
  444. * @return \think\Response
  445. * @throws Exception
  446. */
  447. public function getYsfPayInfoTY($uid, $params)
  448. {
  449. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  450. // 商户号
  451. $order_id = $params['order_id'];
  452. $out_trade_no = 'YPL' . $order_id . mt_rand(1, 10000);
  453. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  454. $error_url = getWebUrl() . '/api/thirdPayClError';
  455. $notify_url = getWebUrl() . '/api/ZfbResultYPL';
  456. // 商品订单信息
  457. $orderInfo = array();
  458. $orderInfo['Id'] = 'id34535';
  459. $orderInfo['businessType'] = '130001';
  460. $orderInfo['goodsList'] = array(array('name' => 'pay', 'number' => 'one', 'amount' => 1));
  461. $params = [
  462. 'areaInfo' => '440106',
  463. 'attachData' => 'attachData',
  464. 'clientIp' => request()->ip(),
  465. 'customerCode' => '562012003860535',
  466. 'nonceStr' => nonce_str(32),
  467. 'notifyUrl' => $notify_url,
  468. 'orderInfo' => $orderInfo,
  469. 'outTradeNo' => $out_trade_no,
  470. 'payAmount' => bcmul($total_amount, 100, 0),
  471. 'payCurrency' => 'CNY',
  472. 'redirectUrl' => $success_url,
  473. 'transactionStartTime' => date('YmdHis'),
  474. 'version' => '3.0'
  475. ];
  476. sr_log('ypl' . json_encode($params));
  477. // 测试
  478. // $url = 'http://test-efps.epaylinks.cn';
  479. // 正式
  480. $url = 'https://efps.epaylinks.cn';
  481. $url = $url . '/api/txs/pay/UnifiedPayment';
  482. sr_log('yplurl:' . $url);
  483. $sign = '333';
  484. $headers = [
  485. 'x-efps-sign-no' => '562012003860535001',
  486. 'x-efps-sign-type' => 'SHA256withRSA',
  487. 'x-efps-sign' => $sign,
  488. 'x-efps-timestamp' => date('YmdHis')
  489. ];
  490. sr_log('yplheader' . json_encode($headers));
  491. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 13);
  492. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYPLYsf' => ['tn' => $out_trade_no]]]);
  493. }
  494. /**
  495. * 易票联进件申请
  496. * @param $uid
  497. * @param $params
  498. * @return \think\Response
  499. */
  500. public function getYsfPayJJSubmit($uid, $params)
  501. {
  502. $time = time();
  503. $time_end = time() + 2 * 60 * 60;
  504. $order_date = sr_getcurtime($time, 'Ymd');
  505. $order_timestart = sr_getcurtime($time, 'YmdHis');
  506. $order_timeend = sr_getcurtime($time_end, 'YmdHis');
  507. $success_url = 'https://api.meikangjw.com/api/yplApplyResult';
  508. $error_url = getWebUrl() . '/api/thirdPayClError';
  509. $notify_url = getWebUrl() . '/api/ZfbResultYPL';
  510. $paper = array();
  511. //-------------------------------------------------------
  512. // 经营地址
  513. $paper['businessAddress'] = '重庆市渝北区回兴街道宝圣大道209号西政国际学术交流中心1幢';
  514. // 证件人姓名
  515. $paper['certificateName'] = '胡明冬';
  516. // 证件效期(截止) 无限期填写“长期”
  517. $paper['certificateTo'] = '20270104';
  518. // 省
  519. $paper['province'] = '500000';
  520. // 市
  521. $paper['city'] = '500100';
  522. // 区
  523. $paper['area'] = '500112';
  524. // MCC 码 参考附件商户类别 MCC 码
  525. $paper['mcc'] = '5399';
  526. // 联系人姓名
  527. $paper['contactPerson'] = '胡明冬';
  528. // 联系人手机号码
  529. $paper['contactPhone'] = '13330218461';
  530. // 邮箱地址
  531. $paper['email'] = '845313908@qq.com';
  532. // $paper['isCc']='1';
  533. // 证件号码
  534. $paper['lawyerCertNo'] = '513002199602181213';
  535. //// 证件背面
  536. $paper['lawyerCertPhotoBack'] = 'https://api.meikangjw.com/upload/20220707/42b46e4e6b82c81b9bb3c72d1c630c80.jpg';
  537. /// // 证件正面照
  538. $paper['lawyerCertPhotoFront'] = 'https://api.meikangjw.com/upload/20220707/5fa0ff6cc891e545c1aa423db7613f63.jpg';
  539. // 0:身份证;1:居住证;2:签证;3:护照;4:户口本;5:军人证;6:团员证;7:党员证;8:港澳通行证;9:台胞证;11:临时身份证;12:回乡证;13:营业执照:14:组织机构代码证;15:驾驶证;99:其他目前仅支持 0:身份证
  540. $paper['lawyerCertType'] = '0';
  541. // 开户银行 填写银行名称,参见附件银行
  542. $paper['openBank'] = '中国工商银行';
  543. // 开户行联行号 settleAccountType 为“1:对公账户”时必填,参见附件支行及联行号 查询不到 看链接查询 https://www.lianhanghao.com/
  544. $paper['openBankCode'] = '102290010045';
  545. // 开户支行 settleAccountType 为“1:对公账户”时必填
  546. $paper['openSubBank'] = '中国工商银行股份有限公司上海市闵行支行';
  547. // 客服电话
  548. $paper['serviceTel'] = '13330218461';
  549. // 结算账户名 ①merchantType=1、2 且 settleAccountType=1 时,需与merchantName 一致; ②merchantType=1、2 且 settleAccountType=2 时,需与lawyerName 一致; ③merchantType=3 时,需与 certificateName 一致。
  550. $paper['settleAccount'] = '胡明冬';
  551. // 1:个体工商户;2:企业;3:个人(小微);4:政府 事业单位;9:其他组织
  552. $paper['merchantType'] = '3';
  553. // 结算账户类型 1:对公账户 2:法人账户 3:授权对公 4:授权对私 merchantType=3 时必填 2。
  554. $paper['settleAccountType'] = '2';
  555. // 银行卡正面照
  556. $paper['bankCardPhotoFront'] = 'https://api.meikangjw.com/upload/20220707/1d80b9edb7773c0d1313270a9b39da6c.jpeg';
  557. // 银行卡背面照
  558. $paper['bankCardPhotoBack'] = 'https://api.meikangjw.com/upload/20220707/aff7377fff22225bff320a51cddaa75d.jpeg';
  559. // 结算账户号
  560. $paper['settleAccountNo'] = '6222031001022713072';
  561. // 提现方式 1:自动提现;2:手动提现
  562. $paper['settleTarget'] = '2';
  563. // 商户简称
  564. $paper['shortName'] = 'hmd_xiaowei';
  565. // 门店内景照
  566. $paper['storeHallPhoto'] = 'https://api.meikangjw.com/upload/20220711/a9ed2ef249e919c8432f756bd4b29a0a.jpg';
  567. // 门店门头照
  568. $paper['storeHeadPhoto'] = 'https://api.meikangjw.com/upload/20220711/e3491c28c5096fc20b6c84efff3b003e.jpg';
  569. // 门店外景照
  570. $paper['storeShopPhoto'] = 'https://api.meikangjw.com/upload/20220711/e3491c28c5096fc20b6c84efff3b003e.jpg';
  571. // $paper['unionShortName']='蜀盛锦蓉店铺';
  572. // refundFeeRate 退款手续费费率
  573. // settleCycle 结算周期
  574. // stage 手续费费率
  575. // stage.amountFrom 阶梯起始交易金额
  576. // stage.feePer 单笔收费
  577. // stage.feeRate 按比例收费
  578. // 代付带储蓄卡
  579. $b_withdraw = array('bankStage' => [], 'businessCode' => 'WITHDRAW', 'creditcardsEnabled' => 0, 'refundEnabled' => 1, 'refundFeePer' => 0, 'refundFeeRate' => 0, 'settleCycle' => 'D+0', 'stage' => array(array('amountFrom' => 0, 'feePer' => 200)));
  580. // 支付宝 主扫支付
  581. $b_alinav = array('bankStage' => [], 'businessCode' => 'ALI_NATIVE_PAY', 'creditcardsEnabled' => 0, 'refundEnabled' => 1, 'refundFeePer' => 0, 'refundFeeRate' => 0, 'settleCycle' => 'D+1', 'stage' => array(array('amountFrom' => 0, 'feeRate' => 60)));
  582. // 支付宝生活号支付
  583. $b_alinav1 = array('bankStage' => [], 'businessCode' => 'ALI_JSAPI_PAY', 'creditcardsEnabled' => 0, 'refundEnabled' => 1, 'refundFeePer' => 0, 'refundFeeRate' => 0, 'settleCycle' => 'D+1', 'stage' => array(array('amountFrom' => 0, 'feeRate' => 60)));
  584. $business = array($b_withdraw, $b_alinav, $b_alinav1);
  585. $params = [
  586. // 是否收单 1 是,0 否
  587. 'acceptOrder' => '1',
  588. // 平台商户编号
  589. 'acqSpId' => '562012003860535',
  590. // 审核回调地址
  591. 'backUrl' => $success_url,
  592. 'business' => $business,
  593. // 填写进件的小微名字
  594. 'merchantName' => '重庆闲食有趣',
  595. // 是否开户
  596. 'openAccount' => '1',
  597. 'paper' => json_encode($paper),
  598. // 更换子商户信息必传
  599. 'acqMerId' => 562227003867484
  600. ];
  601. sr_log('yplpaper' . json_encode($paper));
  602. sr_log('ypl' . json_encode($params));
  603. // 正式
  604. $url = 'https://efps.epaylinks.cn';
  605. // 商户进件或者补件
  606. $url = $url . '/api/cust/SP/Merchant/apply';
  607. sr_log('yplurl:' . $url);
  608. $sign = $this->YPLsign(json_encode($params));
  609. $headers = [
  610. 'x-efps-sign-no' => '562012003860535001',
  611. 'x-efps-sign-type' => 'SHA256withRSA',
  612. 'x-efps-sign' => $sign,
  613. 'x-efps-timestamp' => date('YmdHis')
  614. ];
  615. sr_log('yplheader' . json_encode($headers));
  616. $response = $this->http_post_json($url, json_encode($params), $sign);
  617. sr_log('yplresponse' . json_encode($response));
  618. if ($response && $response[0] == 200) {
  619. $re_data = json_decode($response[1], true);
  620. if ($re_data['respCode'] == '0000') {
  621. return api_succ_return('成功');
  622. } else {
  623. return api_error_return($re_data['respMsg']);
  624. }
  625. } else {
  626. return api_error_return('获取失败,请联系客服');
  627. }
  628. return api_error_return('获取失败,请联系客服');
  629. return api_error_return('获取失败');
  630. }
  631. /**
  632. * http请求
  633. * @param $url
  634. * @param $jsonStr
  635. * @param $sign
  636. * @return array
  637. */
  638. protected function http_post_json($url, $jsonStr, $sign)
  639. {
  640. $ch = curl_init();
  641. $headers = array(
  642. 'Content-Type: application/json; charset=utf-8',
  643. 'Content-Length: ' . strlen($jsonStr),
  644. 'x-efps-sign-no:' . '562012003860535001',
  645. 'x-efps-sign-type:SHA256withRSA',
  646. 'x-efps-sign:' . $sign,
  647. 'x-efps-timestamp:' . date('YmdHis'),
  648. );
  649. curl_setopt($ch, CURLOPT_POST, 1);
  650. curl_setopt($ch, CURLOPT_URL, $url);
  651. curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
  652. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  653. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过检查
  654. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 跳过检查
  655. //curl_setopt($ch, CURLOPT_HEADER, true);
  656. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  657. $response = curl_exec($ch);
  658. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  659. return array($httpCode, $response);
  660. }
  661. /**
  662. * 签名
  663. * @param $data
  664. * @return string
  665. */
  666. protected function YPLsign($data)
  667. {
  668. $certs = array();
  669. if (env("app.CUR_SYS_PARAMS") == 1) {
  670. //其中password为你的证书密码
  671. openssl_pkcs12_read(file_get_contents('/Users/sunriseos/Documents/www/wwwroot/cert/ypl/user-rsa.pfx'), $certs, 'zy2033.');
  672. } else {
  673. openssl_pkcs12_read(file_get_contents('/www/wwwroot/cert/ypl/user-rsa.pfx'), $certs, 'zy2033.'); //其中password为你的证书密码
  674. }
  675. ($certs) or die('您使用的私钥格式错误,请检查RSA私钥配置');
  676. openssl_sign($data, $sign, $certs['pkey'], OPENSSL_ALGO_SHA256);
  677. $sign = base64_encode($sign);
  678. return $sign;
  679. }
  680. /**
  681. * 费用配置
  682. * @param int $uid
  683. * @param array $data
  684. * @param int $type
  685. * @return array
  686. */
  687. public function _payConf(int $uid, array $data, int $type = 1)
  688. {
  689. $body = $total_amount = $remarks = '';
  690. switch ($data['order_type']) {
  691. case 1: // 充值
  692. $body = '充值';
  693. $total_amount = $data['money'];
  694. break;
  695. case 2: // 实名认证
  696. $total_amount = Db::name('user_data')->where('uid', $uid)->value('rz_money');
  697. $body = '实名认证费用';
  698. break;
  699. case 3: // 开通会员
  700. $vip_money = env('app.VIP_MONEY', 38);
  701. if (!$vip_money > 0) {
  702. throw new Exception('会员配置不存在');
  703. }
  704. $body = '开通会员';
  705. $total_amount = $vip_money;
  706. $remarks = $data['order_id'];
  707. break;
  708. case 4: //购买商品
  709. $order_sn = $data['order_id'];
  710. $checkingOrder = Order::checkingOrder($order_sn, 0, $uid);
  711. if (!$checkingOrder) {
  712. throw new Exception('校验订单失败');
  713. }
  714. if ($checkingOrder['flag'] !== 200) {
  715. throw new Exception($checkingOrder['msg']);
  716. }
  717. $body = '购买商品';
  718. $total_amount = $checkingOrder['orderPayment'];
  719. $remarks = $order_sn;
  720. //更改订单支付状态为线下支付待审核状态
  721. if ($data['channel'] == 4 && $data['order_type'] == 4) {
  722. Order::where('order_sn', 'in', $order_sn)->save(['pay_type' => 4, 'status' => 4]);
  723. }
  724. break;
  725. case 5: //余额充值
  726. {
  727. if (intval($data['money']) < 0) {
  728. sr_throw('金额填写错误,请填写整数');
  729. }
  730. if (!str_is_int($data['money'])) {
  731. sr_throw('充值金额有误,请输入正整数');
  732. }
  733. if ($data['money'] > 10000 || $data['money'] < 20) {
  734. sr_throw('请输入20到10000之间金额充值');
  735. }
  736. if ($data['channel'] == 19) {
  737. $usdt_price = Db::name('system_config')->where('name', 'usdt_price')->where('group', 'usdt_price')->value('value');
  738. }
  739. $charge_sn = createdRechargeOrderSn();
  740. Db::name('recharge_order')->insertGetId([
  741. 'recharge_sn' => $charge_sn,
  742. 'payment' => $data['money'],
  743. 'total_price' => $data['money'],
  744. 'usdt_money' => ($data['channel'] == 19 ? ceil($data['money'] / $usdt_price * 100) / 100 : 0),
  745. 'user_id' => $uid,
  746. 'pay_type' => $data['channel'],
  747. 'status' => 1,
  748. 'expires_time' => sr_getcurtime(time() + 0.5 * 3600),
  749. 'created_time' => sr_getcurtime(time())
  750. ]);
  751. $count = Db::name('recharge_order')->where('user_id', $uid)->where('pay_type', $data['channel'])->where('status', 1)->whereTime('created_time', '-2 hours')->count('order_id');
  752. if ($count > 20) {
  753. sr_throw('未支付订单过多请2小时后在试');
  754. }
  755. $body = '用户充值';
  756. $total_amount = $data['money'];
  757. $remarks = $charge_sn;
  758. }
  759. break;
  760. case 6:
  761. {
  762. $money = env('boxsetting.SERVICES_STORE_OPEN_PRICE');
  763. $charge_sn = createdRechargeOrderSn();
  764. Db::name('services_order')->insertGetId([
  765. 'recharge_sn' => $charge_sn,
  766. 'payment' => $money,
  767. 'total_price' => $money,
  768. 'usdt_money' => 0,
  769. 'user_id' => $uid,
  770. 'pay_type' => $data['channel'],
  771. 'status' => 1,
  772. 'expires_time' => sr_getcurtime(time() + 0.5 * 3600),
  773. 'created_time' => sr_getcurtime(time())
  774. ]);
  775. $count = Db::name('services_order')->where('user_id', $uid)->where('pay_type', $data['channel'])->where('status', 1)->whereTime('created_time', '-2 hours')->count('order_id');
  776. if ($count > 20) {
  777. sr_throw('未支付订单过多请稍后在试');
  778. }
  779. $body = '用户购买服务商服务';
  780. $total_amount = $money;
  781. $remarks = $charge_sn;
  782. }
  783. break;
  784. }
  785. if (!$body || !$total_amount || $total_amount <= 0){
  786. throw new Exception('配置错误');
  787. }
  788. return [$body, $type == 1 ? $total_amount : bcmul($total_amount, 100, 2), $data['order_type'], $remarks, $data['trade_type'], $data['channel'], isset($data['voucher_img']) ? $data['voucher_img'] : ''];
  789. }
  790. /**
  791. * @param $uid
  792. * @param $params
  793. * @return \think\Response
  794. * @throws Exception
  795. * @throws \think\db\exception\DataNotFoundException
  796. * @throws \think\db\exception\DbException
  797. * @throws \think\db\exception\ModelNotFoundException
  798. */
  799. public function getPayInfoSQZ($uid, $params)
  800. {
  801. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  802. $nowTime = date('Y-m-d H:i:s');
  803. $signId = isset($params['sign_id'])? $params['sign_id'] : 0;
  804. $payCode = PaymentService::make()->getPayCode($pay_way);
  805. $cacheKey = "caches:payment:{$payCode}:signid_{$signId}:";
  806. $signInfo = UserBankSignService::make()->getCacheInfo($signId,$uid);
  807. RedisCache::set($cacheKey.'catch',['params'=> $params, 'sign'=> $signInfo,'date'=> $nowTime], 7200);
  808. if (!$signInfo) {
  809. sr_throw('参数错误');
  810. }
  811. $order_id = '';
  812. if ($order_type == 4) {
  813. $order_id = $params['order_id'];
  814. }
  815. if ($order_type == 5) {
  816. $order_id = $remarks;
  817. }
  818. if ($order_type == 6) {
  819. // 如果是购买服务商订单 order_id 就是 services_order 里面的order_id
  820. $order_id = $remarks;
  821. }
  822. $out_trade_no = 'SY' . $order_id . mt_rand(1, 10000);
  823. // PAYBACK_URL
  824. $pay_success_backurl = env('PAYSQZ.PAYBACK_URL');
  825. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  826. // 这是测试 线要干掉
  827. $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9));
  828. }
  829. $parterid = env('PAYSQZ.PARTER');
  830. $apiData = [
  831. 'parter' => $parterid,
  832. 'type' => 1000,
  833. 'value' => $total_amount,
  834. 'orderid' => $out_trade_no,
  835. // 'hy_auth_uid' => env('PAYSQZ.SXY_PARTER'),
  836. 'callbackurl' => $pay_success_backurl,
  837. 'payerIp' => get_client_ip(),
  838. 'userno' => $signInfo['userno']
  839. ];
  840. $apiUrl = 'http://pay.xindonglife.com/chargebank.aspx';
  841. $apiData['sign'] = md5('parter=' . $parterid . '&type=' . '1000' . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SIGNKEY'));
  842. RedisCache::set($cacheKey.'request',['url'=>urldecode($apiUrl),'params'=> $params,'apiData'=>$apiData, 'sign'=> $signInfo,'date'=> $nowTime], 7200);
  843. $result = _curlrequest($apiUrl, $apiData, 'post');
  844. $res = $result? json_decode($result, true) : [];
  845. RedisCache::set($cacheKey.'request',['url'=>$apiUrl,'params'=> $params,'apiData'=>$apiData, 'result'=>$result, 'sign'=> $signInfo,'date'=> $nowTime], 7200);
  846. if (isset($res->code) && $res->code == 'SUCCESS') {
  847. $insert = [
  848. 'total_fee' => $total_amount,
  849. 'trade_type' => $trade_type,
  850. 'body' => $body,
  851. 'state' => 7,
  852. 'out_trade_no' => $out_trade_no,
  853. 'pay_way' => $pay_way,
  854. 'remarks' => $remarks,
  855. 'order_type' => $order_type,
  856. 'uid' => $uid,
  857. 'voucher_img' => $voucher_img,
  858. 'out_trade_no1' => $res->orderid,
  859. 'hy_token_id' => $res->hy_token_id
  860. ];
  861. if(!PaymentModel::insert($insert)){
  862. sr_throw('调用处理失败');
  863. }
  864. RedisCache::set($cacheKey.'request',['url'=>$apiUrl,'params'=> $params,'apiData'=>$apiData,'result'=>$res,'payment'=>$insert,'sign'=> $signInfo,'date'=> $nowTime], 7200);
  865. return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySYL' => ['orderid' => $res->orderid, 'mobile' => $signInfo['phone']]]]);
  866. }
  867. return api_error_return('调用失败,请确定账号无误后联系客服');
  868. }
  869. /**
  870. * 石区长-支付宝
  871. * @param $uid
  872. * @param $params
  873. * @return \think\Response
  874. * @throws Exception
  875. */
  876. public function getPayInfoSQZAlipay($uid, $params)
  877. {
  878. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  879. $order_id = '';
  880. if ($order_type == 4) {
  881. $order_id = $params['order_id'];
  882. }
  883. if ($order_type == 5) {
  884. $order_id = $remarks;
  885. }
  886. $out_trade_no = 'SA' . $order_id . mt_rand(1, 10000);
  887. // PAYBACK_URL
  888. $pay_success_backurl = env('PAYSQZ.PAYAliBACK_URL');
  889. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  890. // 这是测试 线要干掉
  891. $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9));
  892. }
  893. $parterid = env('PAYSQZ.PARTER');
  894. $params = [
  895. 'parter' => $parterid,
  896. 'type' => 1010,
  897. 'value' => $total_amount,
  898. 'orderid' => $out_trade_no,
  899. 'callbackurl' => $pay_success_backurl,
  900. 'payerIp' => request()->ip()
  901. ];
  902. // 提交确定支付
  903. sr_log('确认支付支付宝:' . json_encode($params));
  904. $params['sign'] = md5('parter=' . $parterid . '&type=' . '1010' . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SIGNKEY'));
  905. $url = 'http://pay.xindonglife.com/chargebank.aspx';
  906. $insert = [
  907. 'total_fee' => $total_amount,
  908. 'trade_type' => $trade_type,
  909. 'body' => $body,
  910. 'state' => 7,
  911. 'out_trade_no' => $out_trade_no,
  912. 'pay_way' => $pay_way,
  913. 'remarks' => $remarks,
  914. 'order_type' => $order_type,
  915. 'uid' => $uid,
  916. 'voucher_img' => $voucher_img,
  917. 'out_trade_no1' => '',
  918. 'hy_token_id' => ''
  919. ];
  920. Db::name('payment')->insert($insert);
  921. $pay_url = $url . '?' . http_build_query($params);
  922. sr_log('支付宝支付链接:' . $pay_url);
  923. return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySQZAlipay' => ['pay_url' => $pay_url]]]);
  924. }
  925. /**
  926. * 石区长-微信支付
  927. * @param $uid
  928. * @param $params
  929. * @return \think\Response
  930. * @throws Exception
  931. */
  932. public function getPayInfoSQZWechat($uid, $params)
  933. {
  934. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  935. $order_id = '';
  936. if ($order_type == 4) {
  937. $order_id = $params['order_id'];
  938. }
  939. if ($order_type == 5) {
  940. $order_id = $remarks;
  941. }
  942. $out_trade_no = 'Sw' . $order_id . mt_rand(1, 10000);
  943. $pay_success_backurl = env('PAYSQZ.PAYWeixinBACK_URL');
  944. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  945. // 这是测试 线要干掉
  946. $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9));
  947. }
  948. $parterid = env('PAYSQZ.PARTER');
  949. $type = 1004;
  950. $params = [
  951. 'parter' => $parterid,
  952. 'type' => $type,
  953. 'value' => $total_amount,
  954. 'orderid' => $out_trade_no,
  955. 'callbackurl' => $pay_success_backurl,
  956. 'payerIp' => request()->ip()
  957. ];
  958. // 提交确定支付
  959. sr_log('确认支付:' . json_encode($params));
  960. $params['sign'] = md5('parter=' . $parterid . '&type=' . $type . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SIGNKEY'));
  961. $url = 'http://pay.xindonglife.com/chargebank.aspx';
  962. $insert = [
  963. 'total_fee' => $total_amount,
  964. 'trade_type' => $trade_type,
  965. 'body' => $body,
  966. 'state' => 7,
  967. 'out_trade_no' => $out_trade_no,
  968. 'pay_way' => $pay_way,
  969. 'remarks' => $remarks,
  970. 'order_type' => $order_type,
  971. 'uid' => $uid,
  972. 'voucher_img' => $voucher_img,
  973. 'out_trade_no1' => '',
  974. 'hy_token_id' => ''
  975. ];
  976. Db::name('payment')->insert($insert);
  977. return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySQZ' => ['pay_url' => $url . '?' . http_build_query($params)]]]);
  978. }
  979. /**
  980. * @param $uid
  981. * @param $params
  982. * @return \think\Response
  983. * @throws Exception
  984. */
  985. public function getPayInfoSQZBankkuai($uid, $params)
  986. {
  987. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  988. $order_id = '';
  989. if ($order_type == 4) {
  990. $order_id = $params['order_id'];
  991. }
  992. if ($order_type == 5) {
  993. $order_id = $remarks;
  994. }
  995. $out_trade_no = 'SK' . $order_id . mt_rand(1, 10000);
  996. $pay_success_backurl = env('PAYSQZ.PAYKUAIJIEBACK_URL');
  997. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  998. // 这是测试 线要干掉
  999. $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9));
  1000. }
  1001. $parterid = env('PAYSQZ.SXY_PARTER');
  1002. $type = 967;
  1003. $params = [
  1004. 'parter' => $parterid,
  1005. 'type' => $type,
  1006. 'value' => $total_amount,
  1007. 'orderid' => $out_trade_no,
  1008. 'callbackurl' => $pay_success_backurl,
  1009. 'payerIp' => request()->ip()
  1010. ];
  1011. // 提交确定支付
  1012. sr_log('确认支付:' . json_encode($params));
  1013. $params['sign'] = md5('parter=' . $parterid . '&type=' . $type . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SXY_SIGNKEY'));
  1014. $url = 'http://pay.xindonglife.com/chargebank.aspx';
  1015. $insert = [
  1016. 'total_fee' => $total_amount,
  1017. 'trade_type' => $trade_type,
  1018. 'body' => $body,
  1019. 'state' => 7,
  1020. 'out_trade_no' => $out_trade_no,
  1021. 'pay_way' => $pay_way,
  1022. 'remarks' => $remarks,
  1023. 'order_type' => $order_type,
  1024. 'uid' => $uid,
  1025. 'voucher_img' => $voucher_img,
  1026. 'out_trade_no1' => '',
  1027. 'hy_token_id' => ''
  1028. ];
  1029. Db::name('payment')->insert($insert);
  1030. return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySQZ' => ['pay_url' => $url . '?' . http_build_query($params)]]]);
  1031. }
  1032. /**
  1033. * 银盛快捷无卡
  1034. * @param $uid
  1035. * @param $params
  1036. * @return \think\Response
  1037. * @throws Exception
  1038. * @throws \think\db\exception\DataNotFoundException
  1039. * @throws \think\db\exception\DbException
  1040. * @throws \think\db\exception\ModelNotFoundException
  1041. */
  1042. public function getPayInfoYSwk($uid, $params)
  1043. {
  1044. if (empty($params['cer_no']) || empty($params['cer_name'] || empty($params['bank_id']) || empty($params['bank_type']) || empty($params['bank_no']) || empty($params['mobile']))) {
  1045. return api_error_return("参数错误");
  1046. }
  1047. if ($params['bank_type'] == 2) {
  1048. if (empty($params['card_expr_time']) || empty($params['security_code'])) {
  1049. return api_error_return('信用卡类型必须填写信用卡上面的三位安全码跟过期时间');
  1050. }
  1051. }
  1052. $bank_info = Db::name('ys_banklist')->where('id', $params['bank_id'])->find();
  1053. if (!$bank_info) {
  1054. return api_error_return('参数错误');
  1055. }
  1056. $buy_mobilee = $params['mobile'];
  1057. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  1058. $interface_url = 'https://openapi.ysepay.com/gateway.do'; //正式
  1059. $order_id = '';
  1060. if ($order_type == 4) {
  1061. $order_id = $params['order_id'];
  1062. }
  1063. if ($order_type == 5) {
  1064. $order_id = $remarks;
  1065. }
  1066. $out_trade_no = $order_id . '_yswk' . mt_rand(1, 10000);
  1067. // PAYBACK_URL
  1068. $pay_success_backurl = env('PAYSQZ.PAYKUAIJIEBACK_URL');
  1069. // $total_amount = 1;
  1070. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  1071. // 这是测试 线要干掉
  1072. $total_amount = floatval('0' . '.' . mt_rand(1, 2) . mt_rand(1, 9));
  1073. }
  1074. $parterid = env('ZLYS.PARTER_ID');
  1075. $cur_time = sr_getcurtime(time());
  1076. $biz_content = array();
  1077. $biz_content['out_trade_no'] = $out_trade_no;
  1078. $biz_content['shopdate'] = sr_getcurtime(time(), 'Ymd');
  1079. $biz_content['subject'] = '购买商品';
  1080. // $biz_content['total_amount'] = $total_amount;
  1081. $biz_content['total_amount'] = $total_amount;
  1082. $biz_content['timeout_express'] = '1h';
  1083. $biz_content['currency'] = 'CNY';
  1084. $biz_content['business_code'] = '3010002';
  1085. $biz_content['seller_id'] = $parterid;
  1086. $biz_content['bank_type'] = $bank_info['bank_value'];
  1087. $biz_content['buyer_name'] = $params['cer_name'];
  1088. $biz_content['buyer_card_number'] = $params['bank_no'];
  1089. $biz_content['buyer_mobile'] = $params['mobile'];
  1090. $number = trim($this->ECBEncrypt($params['cer_no'], 'Scf10981'));
  1091. // 银行卡类型 debit 借记卡 credit信用卡
  1092. $biz_content['support_card_type'] = intval($params['bank_type']) == 1 ? 'debit' : 'credit';
  1093. if ($params['bank_type'] == 2) {
  1094. $biz_content['cardCvn2'] = $this->ECBEncrypt($params['security_code'], 'Scf10981');
  1095. $biz_content['cardExprDt'] = $this->ECBEncrypt($params['card_expr_time'], 'Scf10981');
  1096. }
  1097. $biz_content['bank_name'] = $bank_info['bank_name'];
  1098. $biz_content['pyerIDNo'] = $number;
  1099. $biz_content['pyerIDTp'] = $this->ECBEncrypt('01', 'Scf10981');;
  1100. $biz_content['bank_account_type'] = 'personal';
  1101. $params = [
  1102. 'method' => 'ysepay.online.fastpay',
  1103. 'partner_id' => $parterid,
  1104. 'timestamp' => $cur_time,
  1105. 'charset' => 'UTF-8',
  1106. 'sign_type' => 'RSA',
  1107. 'notify_url' => env('ZLYS.PAYBACK_URL'),
  1108. 'version' => '3.4',
  1109. 'biz_content' => json_encode($biz_content, JSON_UNESCAPED_UNICODE)
  1110. ];
  1111. ksort($params);
  1112. $params['sign'] = $this->sign($params);
  1113. // 提交确定支付
  1114. sr_log('确认支付:' . json_encode($params));
  1115. $result = curlPost($interface_url, $params);
  1116. sr_log('result:' . $result);
  1117. $res = json_decode($result);
  1118. if (isset($res->ysepay_online_fastpay_response->code) && intval($res->ysepay_online_fastpay_response->code) == 10000 && isset($res->ysepay_online_fastpay_response->msg) && intval($res->ysepay_online_fastpay_response->msg) == 'Success') {
  1119. $trade_no = $res->ysepay_online_fastpay_response->trade_no;
  1120. $insert = [
  1121. 'total_fee' => $total_amount,
  1122. 'trade_type' => $trade_type,
  1123. 'body' => $body,
  1124. 'state' => 7,
  1125. 'out_trade_no' => $out_trade_no,
  1126. 'pay_way' => $pay_way,
  1127. 'remarks' => $remarks,
  1128. 'order_type' => $order_type,
  1129. 'uid' => $uid,
  1130. 'voucher_img' => $voucher_img,
  1131. 'out_trade_no1' => '',
  1132. 'hy_token_id' => '',
  1133. 'buyer_mobile' => $buy_mobilee,
  1134. 'trade_no' => $trade_no
  1135. ];
  1136. Db::name('payment')->insert($insert);
  1137. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYS' => ['trade_no' => $trade_no]]]);
  1138. } else {
  1139. if (isset($res->ysepay_online_fastpay_response->sub_msg)) {
  1140. return api_error_return($res->ysepay_online_fastpay_response->sub_msg);
  1141. } else {
  1142. return api_error_return('支付错误,请联系客服');
  1143. }
  1144. }
  1145. return api_error_return('支付错误,请联系客服1');
  1146. }
  1147. /**
  1148. * 电科支付宝支付信息
  1149. * @param $uid
  1150. * @param $params
  1151. * @return \think\Response
  1152. * @throws Exception
  1153. */
  1154. public function getPayInfoDiankeZfb($uid, $payData)
  1155. {
  1156. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $payData);
  1157. // 接口地址
  1158. $apiUrl = env('PAYDK.DKPAY_API_URL','http://1.14.197.47/proxy/pay/unifiedorder');
  1159. $date = date('Y-m-d H:i:s');
  1160. $out_trade_no = createdOrderSn();
  1161. $cacheKey = "caches:payment:dkpay:otn_{$out_trade_no}:{$uid}_{$remarks}_";
  1162. RedisCache::set($cacheKey.'payData', ['payData'=> $payData, 'date'=>$date], 2*86400);
  1163. // 测试金额
  1164. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  1165. $total_amount = floatval('0' . '.' . mt_rand(1, 2) . mt_rand(1, 9));
  1166. }
  1167. if ($total_amount > 15000) {
  1168. $loData = ['payData'=> $payData,'error'=>'大额不能使用支付宝支付', 'date'=>$date];
  1169. RedisCache::set($cacheKey.'error', $loData, 2*86400);
  1170. sr_throw('大额不能使用支付宝支付');
  1171. }
  1172. $params = [
  1173. 'appId' => 'dianke',
  1174. 'version' => '1.0',
  1175. 'nonceStr' => nonce_str(15),
  1176. 'orderId' => $out_trade_no,
  1177. 'amount' => intval($total_amount * 100),
  1178. 'payChannel' => 'ALP',
  1179. 'goodsName' => $body? $body : '牛仔裤',
  1180. 'goodsDesc' => $body? $body : '牛仔裤',
  1181. 'clientIp' => get_client_ip(),
  1182. 'asyncNotifyUrl' => env('PAYSQZ.PAYBACK_ZFB_NEWURL'),
  1183. 'tradeType' => 'QRCODE'
  1184. ];
  1185. ksort($params);
  1186. $params['sign'] = $this->diankesign($params);
  1187. // 提交确定支付请求接口
  1188. $loData = ['url'=>$apiUrl,'payData'=> $payData,'params'=> $params, 'date'=>$date];
  1189. RedisCache::set($cacheKey.'request', $loData, 2*86400);
  1190. $result = curlPost($apiUrl, $params);
  1191. $result = $result? json_decode($result, true) : [];
  1192. $payUrl = isset($result['data'])? $result['data'] : '';
  1193. $loData['result'] = $result;
  1194. RedisCache::set($cacheKey.'result', $loData, 2*86400);
  1195. if ($payUrl) {
  1196. $payment = [
  1197. 'total_fee' => $total_amount,
  1198. 'trade_type' => $trade_type,
  1199. 'body' => $body,
  1200. 'state' => 7,
  1201. 'out_trade_no' => $out_trade_no,
  1202. 'pay_way' => $pay_way,
  1203. 'remarks' => $remarks,
  1204. 'order_type' => $order_type,
  1205. 'uid' => $uid,
  1206. 'voucher_img' => $voucher_img,
  1207. 'out_trade_no1' => '',
  1208. 'hy_token_id' => ''
  1209. ];
  1210. Db::name('payment')->insert($payment);
  1211. return api_succ_return(['msg' => '成功', 'data' => ['pay_url' => $payUrl]]);
  1212. } else {
  1213. return api_error_return('支付错误,请联系客服');
  1214. }
  1215. }
  1216. /**
  1217. * 电科云闪付
  1218. * @param $uid
  1219. * @param $params
  1220. * @return \think\Response
  1221. * @throws Exception
  1222. */
  1223. public function getPayInfoDiankeYsf($uid, $payData)
  1224. {
  1225. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $payData);
  1226. // 接口地址
  1227. $apiUrl = env('PAYDK.DKPAY_API_URL','http://1.14.197.47/proxy/pay/unifiedorder');
  1228. $date = date('Y-m-d H:i:s');
  1229. $out_trade_no = createdOrderSn();
  1230. $cacheKey = "caches:payment:dkpay:otn_{$out_trade_no}:{$uid}_{$remarks}_";
  1231. RedisCache::set($cacheKey.'payData', ['payData'=> $payData, 'date'=>$date], 2*86400);
  1232. // 测试金额
  1233. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  1234. $total_amount = floatval('0' . '.' . mt_rand(1, 2) . mt_rand(1, 9));
  1235. }
  1236. if ($total_amount > 15000) {
  1237. $loData = ['payData'=> $payData,'error'=>'大额不能使用支付宝支付', 'date'=>$date];
  1238. RedisCache::set($cacheKey.'error', $loData, 2*86400);
  1239. sr_throw('大额不能使用支付宝支付');
  1240. }
  1241. $params = [
  1242. 'appId' => 'dianke',
  1243. 'version' => '1.0',
  1244. 'nonceStr' => nonce_str(15),
  1245. 'orderId' => $out_trade_no,
  1246. 'amount' => intval($total_amount * 100),
  1247. 'payChannel' => 'ALP',
  1248. 'goodsName' => $body? $body : '牛仔裤',
  1249. 'goodsDesc' => $body? $body : '牛仔裤',
  1250. 'clientIp' => get_client_ip(),
  1251. 'asyncNotifyUrl' => env('PAYSQZ.PAYBACK_ZFB_NEWURL'),
  1252. 'tradeType' => 'QRCODE'
  1253. ];
  1254. ksort($params);
  1255. $params['sign'] = $this->diankesign($params);
  1256. // 提交确定支付请求接口
  1257. $loData = ['url'=>$apiUrl,'payData'=> $payData,'params'=> $params, 'date'=>$date];
  1258. RedisCache::set($cacheKey.'request', $loData, 2*86400);
  1259. $result = curlPost($apiUrl, $params);
  1260. $result = $result? json_decode($result, true) : [];
  1261. $payUrl = isset($result['data'])? $result['data'] : '';
  1262. $loData['result'] = $result;
  1263. RedisCache::set($cacheKey.'result', $loData, 2*86400);
  1264. if ($payUrl) {
  1265. $payment = [
  1266. 'total_fee' => $total_amount,
  1267. 'trade_type' => $trade_type,
  1268. 'body' => $body,
  1269. 'state' => 7,
  1270. 'out_trade_no' => $out_trade_no,
  1271. 'pay_way' => $pay_way,
  1272. 'remarks' => $remarks,
  1273. 'order_type' => $order_type,
  1274. 'uid' => $uid,
  1275. 'voucher_img' => $voucher_img,
  1276. 'out_trade_no1' => '',
  1277. 'hy_token_id' => ''
  1278. ];
  1279. Db::name('payment')->insert($payment);
  1280. return api_succ_return(['msg' => '成功', 'data' => ['pay_url' => $payUrl]]);
  1281. } else {
  1282. return api_error_return('支付错误,请联系客服');
  1283. }
  1284. }
  1285. /**
  1286. * 银盛-第三方快捷支付
  1287. * @param $trade_no
  1288. * @param $sms_code
  1289. * @return \think\Response
  1290. * @throws Exception
  1291. * @throws \think\db\exception\DataNotFoundException
  1292. * @throws \think\db\exception\DbException
  1293. * @throws \think\db\exception\ModelNotFoundException
  1294. */
  1295. public function kjPayWithCode($trade_no, $sms_code)
  1296. {
  1297. $field = 'id,out_trade_no,total_fee,user_id,buyer_mobile';
  1298. $paymentInfo = PaymentService::make()->getCacheInfo($trade_no, 0, $field,false);
  1299. if (!$paymentInfo) {
  1300. sr_throw('支付订单错误');
  1301. }
  1302. $out_trade_no = isset($paymentInfo['out_trade_no'])? $paymentInfo['out_trade_no'] : '';
  1303. $interface_url = 'https://openapi.ysepay.com/gateway.do'; //正式
  1304. $parterid = env('ZLYS.PARTER_ID');
  1305. $cur_time = sr_getcurtime(time());
  1306. $biz_content = array();
  1307. $biz_content['out_trade_no'] = $out_trade_no;
  1308. $biz_content['buyer_mobile'] = isset($paymentInfo['buyer_mobile'])? $paymentInfo['buyer_mobile'] : '';
  1309. $biz_content['mobile_verify_code'] = $sms_code;
  1310. $params = [
  1311. 'method' => 'ysepay.online.fastpay.authorize',
  1312. 'partner_id' => $parterid,
  1313. 'timestamp' => $cur_time,
  1314. 'charset' => 'UTF-8',
  1315. 'sign_type' => 'RSA',
  1316. 'notify_url' => env('ZLYS.PAYBACK_URL'),
  1317. 'version' => '3.0',
  1318. 'biz_content' => json_encode($biz_content, JSON_UNESCAPED_UNICODE)
  1319. ];
  1320. ksort($params);
  1321. $params['sign'] = $this->sign($params);
  1322. // 提交确定支付
  1323. $cacheKey = "caches:payment:yskjPay:otn_{$out_trade_no}:";
  1324. RedisCache::set($cacheKey.'params', $params, 3600);
  1325. $result = curlPost($interface_url, $params);
  1326. RedisCache::set($cacheKey.'result', ['params'=> $params,'result'=> $result], 3600);
  1327. $res = json_decode($result);
  1328. $code = isset($res->ysepay_online_fastpay_authorize_response->code)? intval($res->ysepay_online_fastpay_authorize_response->code) : 0;
  1329. $msg = isset($res->ysepay_online_fastpay_authorize_response->msg)? trim($res->ysepay_online_fastpay_authorize_response->msg) : '';
  1330. $sub_msg = isset($res->ysepay_online_fastpay_authorize_response->sub_msg)? trim($res->ysepay_online_fastpay_authorize_response->sub_msg) : '';
  1331. if ($code == 10000 && $msg == 'Success') {
  1332. return api_succ_return('成功');
  1333. } else {
  1334. if ($sub_msg) {
  1335. return api_error_return($sub_msg);
  1336. } else {
  1337. return api_error_return('支付错误,请联系客服');
  1338. }
  1339. }
  1340. }
  1341. /**
  1342. * DES加密方法
  1343. * @param $data 传入需要加密的证件号码
  1344. * @param $key key为商户号前八位.不足八位的需在商户号前补空格
  1345. * @return string 返回加密后的字符串
  1346. */
  1347. function ECBEncrypt($data, $key)
  1348. {
  1349. $encrypted = openssl_encrypt($data, 'DES-ECB', $key, 1);
  1350. return base64_encode($encrypted);
  1351. }
  1352. /**
  1353. * DES解密方法
  1354. * @param $data 传入需要解密的字符串
  1355. * @param $key key为商户号前八位.不足八位的需在商户号前补空格
  1356. * @return string 返回解密后的证件号码
  1357. */
  1358. function doECBDecrypt($data, $key)
  1359. {
  1360. $encrypted = base64_decode($data);
  1361. $decrypted = openssl_decrypt($encrypted, 'DES-ECB', $key, 1);
  1362. return $decrypted;
  1363. }
  1364. /**
  1365. * 签名加密
  1366. * @param input data
  1367. * @return success
  1368. * @return check
  1369. * @return msg
  1370. */
  1371. public function sign_encrypt($input)
  1372. {
  1373. $return = [
  1374. 'success' => 0,
  1375. 'msg' => '',
  1376. 'check' => ''
  1377. ];
  1378. $pkcs12 = file_get_contents(env('ZLYS.PFX_PATH')); //私钥
  1379. if (openssl_pkcs12_read($pkcs12, $certs, env('ZLYS.PSSSWORD'))) {
  1380. $privateKey = $certs['pkey'];
  1381. $publicKey = $certs['cert'];
  1382. $signedMsg = "";
  1383. if (openssl_sign($input['data'], $signedMsg, $privateKey, OPENSSL_ALGO_SHA1)) {
  1384. $return['success'] = 1;
  1385. $return['check'] = base64_encode($signedMsg);
  1386. $return['msg'] = base64_encode($input['data']);
  1387. }
  1388. }
  1389. return $return;
  1390. }
  1391. /**
  1392. * 签名
  1393. * @param $data
  1394. * @return string
  1395. */
  1396. public function sign($data)
  1397. {
  1398. ksort($data);
  1399. $signStr = "";
  1400. foreach ($data as $key => $val) {
  1401. $signStr .= $key . '=' . $val . '&';
  1402. }
  1403. $signStr = trim($signStr, '&');
  1404. $sign = $this->sign_encrypt(array('data' => $signStr));
  1405. return trim($sign['check']);
  1406. }
  1407. /**
  1408. * 签名
  1409. * @param $data
  1410. * @return string
  1411. */
  1412. public function diankesign($data)
  1413. {
  1414. ksort($data);
  1415. $signStr = "";
  1416. foreach ($data as $key => $val) {
  1417. $signStr .= $key . '=' . $val . '&';
  1418. }
  1419. $stringSignTemp = $signStr . 'key=a05fd6fc1f924b74b83dfd519ce93c28';
  1420. $signtemp = \md5($stringSignTemp);
  1421. return strtoupper($signtemp);
  1422. }
  1423. /**
  1424. * thirdPaySqzBack支付三方sqz签名
  1425. * @param $params
  1426. * @return string
  1427. */
  1428. public function sqzSign($params){
  1429. $orderId = isset($params['orderid'])? $params['orderid'] : '';
  1430. return md5('orderid=' . $orderId . '&opstate=' . $params['opstate'] . '&ovalue=' . $params['ovalue'] . env('PAYSQZ.SIGNKEY'));
  1431. }
  1432. /**
  1433. * 签名
  1434. * @param $data
  1435. * @return string
  1436. */
  1437. public function diankesigndf($data)
  1438. {
  1439. ksort($data);
  1440. $signStr = "";
  1441. foreach ($data as $key => $val) {
  1442. $signStr .= $key . '=' . $val . '&';
  1443. }
  1444. $stringSignTemp = $signStr . 'key=b91f3a72fe074e39a6add7382de813bc';
  1445. $signtemp = \md5($stringSignTemp);
  1446. return strtoupper($signtemp);
  1447. }
  1448. /**
  1449. * USDT
  1450. * @param $uid
  1451. * @param $params
  1452. * @return \think\Response
  1453. * @throws Exception
  1454. */
  1455. public function getPayInfoUsdt($uid, $params)
  1456. {
  1457. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  1458. return api_succ_return('成功');
  1459. }
  1460. /**
  1461. * 签约银行卡
  1462. * @param $uid
  1463. * @param $post
  1464. * @return mixed
  1465. * @throws Exception
  1466. * @throws \think\db\exception\DataNotFoundException
  1467. * @throws \think\db\exception\DbException
  1468. * @throws \think\db\exception\ModelNotFoundException
  1469. */
  1470. public function userBankSign($uid, $post)
  1471. {
  1472. $pay_success_backurl = env('PAYSQZ.USER_SIGN_BANK');
  1473. $parterid = env('PAYSQZ.PARTER');
  1474. $phone = $post['phone'];
  1475. $bankCard = $post['bank_card'];
  1476. $name = $post['name'];
  1477. $idCard = $post['id_card'];
  1478. $orderId = creatBankSignOrderSn($uid);
  1479. if ($info = UserBankSignService::make()->checkHasSign($uid, $bankCard, 4)) {
  1480. UserBankSignModel::where('id', $info['id'])->save([
  1481. 'status' => 1,
  1482. 'signorder_id' => $orderId
  1483. ]);
  1484. } else {
  1485. UserBankSignModel::insert([
  1486. 'uid' => $uid,
  1487. 'phone' => $phone,
  1488. 'bank_card' => $bankCard,
  1489. 'name' => $name,
  1490. 'id_card' => $idCard,
  1491. 'create_time' => sr_getcurtime(time()),
  1492. 'signorder_id' => $orderId
  1493. ]);
  1494. }
  1495. // 签约参数
  1496. $param = [
  1497. 'parter' => $parterid,
  1498. 'userid' => $uid,
  1499. 'phone' => $phone,
  1500. 'bankCard' => $bankCard,
  1501. 'name' => $name,
  1502. 'idCard' => $idCard,
  1503. 'orderid' => $orderId,
  1504. 'callBack' => $pay_success_backurl
  1505. ];
  1506. $keystring = 'parter=' . $parterid . '&userid=' . $uid . '&phone=' . $phone . '&bankCard=' . $bankCard . '&name=' . $name . '&idCard=' . $idCard . '&orderid=' . $orderId . env('PAYSQZ.SIGNKEY');
  1507. $param['sign'] = md5($keystring);
  1508. $cacheKey = "caches:userBankSign:user_{$uid}:{$bankCard}_";
  1509. RedisCache::set($cacheKey.'param', $param, 7200);
  1510. $res = _curlrequest('http://pay.xindonglife.com/PageSign.aspx', $param, 'post');
  1511. RedisCache::set($cacheKey.'result', ['param'=> $param,'result'=>$res,'date'=>date('Y-m-d H:i:s')], 7200);
  1512. $result = json_decode($res);
  1513. if (isset($result->code) && $result->code == 'SUCCESS') {
  1514. return $result->sign_url;
  1515. } else {
  1516. if (is_string($res)) {
  1517. sr_throw($res);
  1518. } else {
  1519. sr_throw('请求失败,请稍后再试');
  1520. }
  1521. }
  1522. }
  1523. /**
  1524. * 解绑银行卡
  1525. * @param $uid
  1526. * @param $post
  1527. * @throws Exception
  1528. * @throws \think\db\exception\DataNotFoundException
  1529. * @throws \think\db\exception\DbException
  1530. * @throws \think\db\exception\ModelNotFoundException
  1531. */
  1532. public function userUnBankSign($uid, $post)
  1533. {
  1534. $parterid = env('PAYSQZ.PARTER');
  1535. $orderId = creatBankSignOrderSn($uid);
  1536. $recordId = isset($post['record_id'])? intval($post['record_id']) : 0;
  1537. if (!$recordId || !$bankInfo = UserBankSignService::make()->getCacheInfo($recordId, $uid)) {
  1538. sr_throw('参数错误');
  1539. }
  1540. $param = [
  1541. 'parter' => $parterid,
  1542. 'hy_auth_uid' => $bankInfo['userno'],
  1543. 'orderId' => $orderId
  1544. ];
  1545. $keystring = 'parter=' . $parterid . '&hy_auth_uid=' . $bankInfo['userno'] . env('PAYSQZ.SIGNKEY');
  1546. $param['sign'] = md5($keystring);
  1547. $cacheKey = "caches:userBankSign:{$uid}_{$recordId}_{$parterid}:";
  1548. RedisCache::set($cacheKey.'param', $param, 7200);
  1549. $res = _curlrequest('http://pay.xindonglife.com/CardUnbinding.aspx', $param, 'post');
  1550. RedisCache::set($cacheKey.'result', ['param'=> $param,'result'=> $res,'date'=>date('Y-m-d H:i:s')], 7200);
  1551. $res = json_decode($res);
  1552. if (isset($res->code) && $res->code == 'SUCCESS') {
  1553. RedisCache::keyDel("caches:userBankSign*");
  1554. UserBankSignModel::where('id', $post['record_id'])->save(['signorder_u_id' => $orderId, 'status' => 4]);
  1555. } else {
  1556. RedisCache::set($cacheKey.'back', ['error'=>'解绑失败','param'=> $param,'result'=> $res,'date'=>date('Y-m-d H:i:s')], 7200);
  1557. sr_throw('解绑失败');
  1558. }
  1559. }
  1560. /**
  1561. * 石学长 银联支付
  1562. * @param $uid
  1563. * @param $params
  1564. * @throws Exception
  1565. * @throws \think\db\exception\DataNotFoundException
  1566. * @throws \think\db\exception\DbException
  1567. * @throws \think\db\exception\ModelNotFoundException
  1568. */
  1569. public function sylSurePay($uid, $params)
  1570. {
  1571. if (empty($params['sms_code'])) {
  1572. sr_throw('参数错误');
  1573. }
  1574. $payment_info = Db::name('payment')->where('out_trade_no1', $params['order_id'])->where('state', 7)->where('uid', $uid)->find();
  1575. if (!$payment_info) {
  1576. sr_throw('参数错误或者订单错误');
  1577. }
  1578. $parterid = env('PAYSQZ.PARTER');
  1579. $order_id = creatBankSignOrderSn($uid);
  1580. $out_trade_no1 = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  1581. $param = [
  1582. 'parter' => $parterid,
  1583. 'hy_token_id' => $payment_info['hy_token_id'],
  1584. 'verify_code' => $params['sms_code'],
  1585. 'orderId' => $out_trade_no1
  1586. ];
  1587. $keystring = 'parter=' . $parterid . '&hy_token_id=' . $payment_info['hy_token_id'] . '&verify_code=' . $params['sms_code'] . env('PAYSQZ.SIGNKEY');
  1588. $param['sign'] = md5($keystring);
  1589. $res = _curlrequest('http://pay.xindonglife.com/payMentConfirm.aspx', $param, 'post');
  1590. $res = json_decode($res);
  1591. if (isset($res->code) && $res->code == 'SUCCESS') {
  1592. Db::name('payment')->where('id', $payment_info['id'])->save(['hy_bill_no' => $res->hy_bill_no, 'syl_sureorderid' => $out_trade_no1]);
  1593. } else {
  1594. if (isset($res->message)) {
  1595. sr_throw($res->message);
  1596. }
  1597. // {"id":1,"code":"Fail","message":"\u77ed\u4fe1\u9a8c\u8bc1\u7801\u5df2\u8fc7\u671f"}
  1598. // sr_log('确认失败:'.json_encode($res));
  1599. }
  1600. }
  1601. /**
  1602. * pay_money 支付订单的金额
  1603. * @param $out_trade_no
  1604. * @param $pay_money
  1605. * @param $pay_type
  1606. * @param $content
  1607. * @throws Exception
  1608. * @throws \think\db\exception\DataNotFoundException
  1609. * @throws \think\db\exception\DbException
  1610. * @throws \think\db\exception\ModelNotFoundException
  1611. */
  1612. public function payBack($out_trade_no, $pay_money, $pay_type, $content, $cacheKey='')
  1613. {
  1614. $date = date('Y-m-d H:i:s');
  1615. $shopordermodel = new ShopOrderModel();
  1616. $services_ordermodel = new ServicesOrderModel();
  1617. $params = $content? json_encode($content, true):[];
  1618. $cacheKey = $cacheKey? $cacheKey : "caches:payment:callBack:{$out_trade_no}";
  1619. RedisCache::set($cacheKey.'_catch', ['params'=>$params,'date'=> $date], 7200);
  1620. // 验证支付请求信息
  1621. $payInfo = PaymentModel::where('out_trade_no', $out_trade_no)->where('state', 7)->find();
  1622. $payUid = isset($payInfo['uid'])? $payInfo['uid']:0;
  1623. if (!$payInfo || $payUid<=0) {
  1624. $logData = ['params'=>$params,'msg'=>"单号{$out_trade_no}已经回调支付,或支付信息不存在",'date'=> $date];
  1625. RedisCache::set($cacheKey.'_error', $logData, 7200);
  1626. sr_throw('outtradeno已经回调支付:' . $out_trade_no);
  1627. }
  1628. $nowTime = date('Y-m-d H:i:s', time());
  1629. $userInfo = UserService::make()->getCacheInfo($payUid);
  1630. if ($payInfo['order_type'] == 6) {
  1631. $date = sr_getcurtime(time(), 'Y-m-d');
  1632. $expire_day = date('Y-m-d', strtotime("$date +1 month"));
  1633. $payInfo->save(['state' => 6, 'pay_at' => $nowTime]);
  1634. $services_orderinfo = $services_ordermodel->where('recharge_sn', $payInfo['remarks'])->find();
  1635. if ($services_orderinfo) {
  1636. $services_orderinfo->save(['status' => 2, 'pay_type' => $pay_type, 'updated_time' => $nowTime]);
  1637. }
  1638. Db::name('user')->where('id', $services_orderinfo['user_id'])->save([
  1639. 'store_type' => 1,
  1640. 'store_expire_time' => $expire_day
  1641. ]);
  1642. } elseif ($payInfo['order_type'] == 4) {
  1643. $nowTime = date('Y-m-d H:i:s', time());
  1644. $payInfo->save(['state' => 6, 'pay_at' => $nowTime]);
  1645. $order_info = $shopordermodel->where('order_sn', $payInfo['remarks'])->find();
  1646. Db::name('user')->whereIn('id', $userInfo['path'])->inc('total_team_income', $payInfo['total_fee'])->update();
  1647. Db::name('user')->whereIn('id', $userInfo['id'])->inc('total_team_income', $payInfo['total_fee'])->update();
  1648. Db::name('user')->where('id', $userInfo['id'])->inc('total_income', $payInfo['total_fee'])->update();
  1649. $order_info->save(['status' => 1, 'pay_type' => $pay_type, 'updated_time' => $nowTime]);
  1650. // 增加销量
  1651. $orderGoods = OrderGoods::where(['order_id' => $order_info['order_id']])->select()->toArray();
  1652. foreach ($orderGoods as $k => $v) {
  1653. ShopGoodsModel::where(['goods_id' => $v['goods_id']])->inc('sales_volume', $v['num'])->inc('real_sales_volume', $v['num'])->update();
  1654. }
  1655. $uid = $payInfo['uid'];
  1656. Db::name('thirdpay_back')->insert([
  1657. 'out_order_no' => $out_trade_no,
  1658. 'content' => $content,
  1659. 'create_time' => sr_getcurtime(time()),
  1660. 'type' => $pay_type,
  1661. 'uid' => $uid,
  1662. 'money' => $pay_money
  1663. ]);
  1664. // 赠送积分
  1665. edit_user_score(3, $uid, $order_info['rebate_score'], 0, $payInfo['id']);
  1666. }
  1667. }
  1668. /**
  1669. * ay_money 代付回调金额
  1670. * @param $out_trade_no
  1671. * @param $pay_money
  1672. * @param $params
  1673. * @param $content
  1674. * @throws \think\db\exception\DataNotFoundException
  1675. * @throws \think\db\exception\DbException
  1676. * @throws \think\db\exception\ModelNotFoundException
  1677. */
  1678. public function payDfBack($out_trade_no, $pay_money, $params, $content)
  1679. {
  1680. if (isset($params['status'])) {
  1681. $model = new WithDrawLogModel();
  1682. $info = $model->where('out_biz_no', $out_trade_no)->find();
  1683. if (!$info) {
  1684. return;
  1685. }
  1686. if ($info && $info['status'] == 4) {
  1687. if ($params['status'] == 1) {
  1688. // 代付成功
  1689. $info->save(['status' => 1]);
  1690. } else {
  1691. Db::startTrans();
  1692. try {
  1693. Db::startTrans();//开启事务
  1694. $info = $model->where('out_biz_no', $out_trade_no)->find();
  1695. $user_info = Db::name('user')->where('id', $info['uid'])->lock(true)->find();
  1696. $res = edit_user_money(10, $info['uid'], $info['apply_money']);
  1697. Db::name('action_liangb')->insert([
  1698. 'create_time' => sr_getcurtime(time()),
  1699. 'wd_id' => $out_trade_no
  1700. ]);
  1701. // 代付失败
  1702. $info->save(['zfb_error' => $content, 'status' => 3]);
  1703. Db::commit();
  1704. } catch (\Exception $e) {
  1705. Db::rollback();
  1706. sr_log('代付回调报错');
  1707. }
  1708. }
  1709. }
  1710. }
  1711. }
  1712. /**
  1713. * @param $uid
  1714. * @param $pay_info
  1715. * @param $yeji
  1716. * @throws \think\db\exception\DataNotFoundException
  1717. * @throws \think\db\exception\DbException
  1718. * @throws \think\db\exception\ModelNotFoundException
  1719. */
  1720. public function scaleAgentMoney($uid, $pay_info, $yeji)
  1721. {
  1722. $is_privince_get = false;
  1723. $is_city_get = false;
  1724. $money = intval($pay_info['total_fee'] / 100) * 100;
  1725. $user_info = Db::name('user')->where('id', $uid)->find();
  1726. $path = $user_info['path'];
  1727. // sr_log('path:'.$path);
  1728. $arr = explode(',', $path);
  1729. $arr = array_reverse($arr);
  1730. $ids = $arr;
  1731. $ids = implode(',', $ids);
  1732. $order = 'field(id,' . $ids . ')';
  1733. $users = Db::name('user')->where('id', 'in', $arr)->field('id,level,agent_type')->order(Db::raw($order))->select()->toArray();
  1734. foreach ($users as $key => $val) {
  1735. if ($val['agent_type'] == 1) {
  1736. if (!$is_privince_get) {
  1737. if ($is_city_get) {
  1738. edit_user_money(17, $val['id'], $money * 0.5 / 100, 0, $pay_info['remarks']);
  1739. } else {
  1740. edit_user_money(17, $val['id'], $money / 100, 0, $pay_info['remarks']);
  1741. }
  1742. $is_privince_get = true;
  1743. }
  1744. }
  1745. if ($val['agent_type'] == 2) {
  1746. if (!$is_privince_get) {
  1747. edit_user_money(18, $val['id'], $money * 0.5 / 100, 0, $pay_info['remarks']);
  1748. }
  1749. $is_city_get = true;
  1750. }
  1751. }
  1752. }
  1753. /**
  1754. * pay_money 余额支付订单的金额
  1755. * @param $order_sn
  1756. * @param $pay_type
  1757. * @param $content
  1758. * @throws \think\db\exception\DataNotFoundException
  1759. * @throws \think\db\exception\DbException
  1760. * @throws \think\db\exception\ModelNotFoundException
  1761. */
  1762. public function payBalanceDown($order_sn, $pay_type, $content)
  1763. {
  1764. $paymodel = new PaymentModel();
  1765. $shopordermodel = new ShopOrderModel();
  1766. $usermodel = new UserModel();
  1767. $order_info = $shopordermodel->where('order_sn', $order_sn)->find();
  1768. $nowTime = date('Y-m-d H:i:s', time());
  1769. $user_info = $usermodel->where('id', $order_info['user_id'])->find();
  1770. $order_info->save(['status' => 1, 'pay_type' => $pay_type, 'updated_time' => $nowTime]);
  1771. // 增加销量
  1772. $orderGoods = OrderGoods::where(['order_id' => $order_info['order_id']])->select()->toArray();
  1773. foreach ($orderGoods as $k => $v) {
  1774. ShopGoodsModel::where(['goods_id' => $v['goods_id']])->inc('sales_volume', $v['num'])->inc('real_sales_volume', $v['num'])->update();
  1775. }
  1776. $uid = $order_info['user_id'];
  1777. Db::name('thirdpay_back')->insert([
  1778. 'out_order_no' => '',
  1779. 'content' => $content,
  1780. 'create_time' => sr_getcurtime(time()),
  1781. 'type' => $pay_type,
  1782. 'uid' => $uid,
  1783. 'money' => $order_info['payment']
  1784. ]);
  1785. // 给用户添加业绩
  1786. $pay_info = $paymodel->where('remarks', $order_sn)->where('state', 6)->find();
  1787. // 赠送积分
  1788. edit_user_score(1, $uid, $order_info['rebate_score']);
  1789. $this->update_user_yeji($uid, $user_info, $order_info, $pay_info);
  1790. }
  1791. /**
  1792. * @param $uid
  1793. * @param $user_info
  1794. * @param $order_info
  1795. * @param $pay_info
  1796. * @throws \think\db\exception\DataNotFoundException
  1797. * @throws \think\db\exception\DbException
  1798. * @throws \think\db\exception\ModelNotFoundException
  1799. */
  1800. public function update_user_yeji($uid, $user_info, $order_info, $pay_info)
  1801. {
  1802. // 计算用户的yeji
  1803. $yeji = 0;
  1804. // 根据所送的积分算业绩
  1805. if ($user_info['performance_me'] < 10000) {
  1806. if (($user_info['performance_me'] + $order_info['rebate_score']) > 10000) {
  1807. $yeji = 10000 - $user_info['performance_me'];
  1808. incUserPerformance($uid, $yeji);
  1809. } else {
  1810. $yeji = $order_info['rebate_score'];
  1811. incUserPerformance($uid, $yeji);
  1812. }
  1813. }
  1814. if ($yeji > 0) {
  1815. // 如果增加的业绩大于0 计算省代跟市代
  1816. //
  1817. $this->scaleAgentMoney($order_info['user_id'], $pay_info, $yeji);
  1818. }
  1819. }
  1820. /**
  1821. * 手续费
  1822. * @param $uid
  1823. * @param $pay_info
  1824. * @param $nowTime
  1825. * @param int $type
  1826. * @return false
  1827. */
  1828. public function update_user_free($uid, $pay_info, $nowTime, $type = 1){
  1829. // return false;
  1830. }
  1831. }