Access.php 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310
  1. <?php
  2. namespace app\controller\api\merchant\sxy;
  3. use alipay\aop\AopClient;
  4. use alipay\aop\request\AlipaySystemOauthTokenRequest;
  5. use app\common\model\store\order\StoreOrder;
  6. use app\common\model\user\UserCertification;
  7. use app\common\repositories\merchant\order\OrderGzcRepository;
  8. use app\common\repositories\merchant\order\OrderMerchantRepository;
  9. use app\common\repositories\store\order\StoreGroupOrderRepository;
  10. use app\common\repositories\store\order\StoreOrderRepository;
  11. use app\controller\Aes;
  12. use app\model\sxy\DeclareLog;
  13. use app\traits\HuiPay;
  14. use app\traits\ShouxinyiApiRequest;
  15. use crmeb\exceptions\AuthException;
  16. use think\Exception;
  17. use think\facade\Db;
  18. use think\facade\Request;
  19. use think\facade\Log;
  20. class Access
  21. {
  22. use HuiPay;
  23. //入网查询
  24. public function queryMer($m_id){
  25. try {
  26. if($m_id == '')
  27. return app('json')->fail('参数错误');
  28. return app('json')->success('入网完成');
  29. }catch (Exception $exception){
  30. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  31. return app('json')->fail('查询失败');
  32. }
  33. }
  34. //发起支付(微信小程序、公众号预下单返回oid)
  35. public function onlinePay(){
  36. try {
  37. $return = array(
  38. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  39. 'status' => $res['status'],
  40. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  41. 'appParams' => $res['appParams'] ?? '',//App调用码
  42. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  43. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  44. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  45. 'token' => $res['token'] ?? '', //微包支付调用token
  46. );
  47. return app('json')->success($return);
  48. }catch (Exception $exception){
  49. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  50. return app('json')->fail('发起支付失败');
  51. }
  52. }
  53. //回调
  54. public function notify($type){
  55. try {
  56. $data = Request::param('data');
  57. Db::name("log")->insert(array('data'=>"首信易回调data:".json_encode($data)));//日志记录
  58. $header = Request::header();
  59. switch ($type){
  60. case 'createMerchant_5upay':
  61. $request['data'] = $data;
  62. $request['encryptKey'] = $header['encryptkey'];
  63. $request['merchantId'] = $header['merchantid'];
  64. $request['requestId'] = $header['requestid'];
  65. $res = ShouxinyiApiRequest::returnDecode($request);
  66. Db::name("log")->insert(array('data'=>"入网回调data:".json_encode($data)));//日志记录
  67. Db::name("log")->insert(array('data'=>"入网回调header:".json_encode($header)));//日志记录
  68. Db::name("log")->insert(array('data'=>"入网回调res:".json_encode($res)));//日志记录
  69. //入网记录
  70. $log = new DeclareLog();
  71. $log -> updateLog(array(
  72. 'status' => $res['subMerchantReviewStatus'],
  73. 'message' => $res['subMerchantReviewRemarks']??'',
  74. 'requestId'=>$res['requestId']
  75. ));
  76. $mid = $log -> getMidLog($res['requestId']);
  77. if($res['subMerchantReviewStatus'] == 'SUCCESS' || $res['subMerchantReviewStatus'] == 'ESIGN_SUCCESS'){
  78. $mer_id = Db::name('merchant_intention') -> where('mer_intention_id',$mid) -> find();
  79. if($mer_id['hf_status']==2){
  80. Db::name('merchant_intention')->where('mer_intention_id',$mid)->update(['status'=>1]);
  81. }
  82. Db::name('merchant') -> where('mer_id',$mer_id['mer_id']??0) -> update(['sxy_submerchant_id'=>$res['subMerchantId']]);
  83. }else{
  84. Db::name('merchant_intention')->where('mer_intention_id',$mid)->update(['status'=>3]);
  85. }
  86. break;
  87. case 'pay_5upay':
  88. Db::name("log")->insert(array('data'=>"支付回调data:".json_encode($data)));//日志记录
  89. $request['data'] = $data;
  90. $request['encryptKey'] = $header['encryptkey'];
  91. $request['merchantId'] = $header['merchantid'];
  92. $request['requestId'] = $header['requestid'];
  93. $res = ShouxinyiApiRequest::returnDecode($request);
  94. Db::name("log")->insert(array('data'=>"支付回调data:".json_encode($data)));//日志记录
  95. Db::name("log")->insert(array('data'=>"支付回调header:".json_encode($header)));//日志记录
  96. Db::name("log")->insert(array('data'=>"支付回调res:".json_encode($res)));//日志记录
  97. $requestId = [];
  98. if(strpos($res['requestId'],'_') !== false){
  99. $requestId = explode("_",$res['requestId']);
  100. }
  101. if($res['status'] == 'SUCCESS'){
  102. Db::name('store_group_order') -> where('group_order_sn',$requestId[0]) -> update(['rand'=>$requestId[1],'serialNumber'=>$res['serialNumber']]);
  103. $pay_type = $res['paymentModeAlias'] == 'MINIAPPS_WEIXIN_PAY' ? 1 : 4;
  104. event('pay_success_order', ['order_sn' => $requestId[0],'pay_type'=>$pay_type]);
  105. }
  106. break;
  107. case "pay_split_5upay":
  108. $request['data'] = $data;
  109. $request['encryptKey'] = $header['encryptkey'];
  110. $request['merchantId'] = $header['merchantid'];
  111. $request['requestId'] = $header['requestid'];
  112. $res = ShouxinyiApiRequest::returnDecode($request);
  113. Db::name("log")->insert(array('data'=>"分账回调data:".json_encode($data)));//日志记录
  114. Db::name("log")->insert(array('data'=>"分账回调header:".json_encode($header)));//日志记录
  115. Db::name("log")->insert(array('data'=>"分账回调res:".json_encode($res)));//日志记录
  116. if($res['status'] == 'SUCCESS'){
  117. $status = ['status'=>1];
  118. }else{
  119. $status = ['status'=>2];
  120. }
  121. Db::name('store_split_order') -> where("requestId",$res['requestId']) -> update($status);
  122. break;
  123. case "pay_refund_5upay":
  124. $request['data'] = $data;
  125. $request['encryptKey'] = $header['encryptkey'];
  126. $request['merchantId'] = $header['merchantid'];
  127. $request['requestId'] = $header['requestid'];
  128. $res = ShouxinyiApiRequest::returnDecode($request);
  129. Db::name("log")->insert(array('data'=>"退款回调data:".json_encode($data)));//日志记录
  130. Db::name("log")->insert(array('data'=>"退款回调header:".json_encode($header)));//日志记录
  131. Db::name("log")->insert(array('data'=>"退款回调res:".json_encode($res)));//日志记录
  132. break;
  133. case "pay_annual":
  134. Db::name("log")->insert(array('data'=>"支付年费回调data:".json_encode($data)));//日志记录 1
  135. $request['data'] = $data;
  136. $request['encryptKey'] = $header['encryptkey'];
  137. $request['merchantId'] = $header['merchantid'];
  138. $request['requestId'] = $header['requestid'];
  139. $res = ShouxinyiApiRequest::returnDecode($request);
  140. Db::name("log")->insert(array('data'=>"支付年费回调data:".json_encode($data)));//日志记录
  141. Db::name("log")->insert(array('data'=>"支付年费回调header:".json_encode($header)));//日志记录
  142. Db::name("log")->insert(array('data'=>"支付年费回调res:".json_encode($res)));//日志记录
  143. $requestId = [];
  144. if(strpos($res['requestId'],'_') !== false){
  145. $requestId = explode("_",$res['requestId']);
  146. }
  147. if($res['status'] == 'SUCCESS'){
  148. $annual_cost_order=Db::name('merchant_annual_cost_order')-> where('order_no',$requestId[0])->find();
  149. if($annual_cost_order['status'] == 0) {
  150. // Db::name('merchant_annual_cost_order') -> where('order_no',$requestId[0]) -> update(['rand'=>$requestId[1],'serialNumber'=>$res['serialNumber']]);
  151. Db::name('merchant_annual_cost_order')->where('order_no', $requestId[0])->update(['rand' => $requestId[1], 'serialNumber' => $res['serialNumber'], 'status' => 1]);
  152. //如果有商户id就是续费
  153. $mer_id = Db::name('merchant_annual_cost_order')->where('order_no', $requestId[0])->value('mer_id');
  154. if ($mer_id !== 0) {
  155. $expire_time = strtotime(date('Y-m-d')) + 86400 * 365 + 86400 - 1;
  156. Db::name('merchant')->where('mer_id', $mer_id)->update(['expire_time' => $expire_time, 'status' => 1]);
  157. }
  158. $mer = Db::name('user_mer') -> where('uid',$annual_cost_order['uid']) -> find();
  159. if(!$mer){
  160. Db::name('user_mer') -> insert(['uid'=>$annual_cost_order['uid'],'mer'=>2]);
  161. }else{
  162. Db::name('user_mer') -> where('uid',$annual_cost_order['uid'])->inc('mer', 2) ->update();;
  163. }
  164. // $mer_data=Db::name('merchant_annual_cost_order') -> where('order_no',$requestId[0]) ->field('tz_integral,tz_money,mer_id')->find();
  165. // $integral=bcadd(bcdiv(500, '5',2),$mer_data['tz_integral'],2);
  166. // $moneys=bcadd(500,$mer_data['tz_money'],2);
  167. // $updateData=[
  168. // 'tz_integral'=>$integral,
  169. // 'tz_money'=>$moneys,
  170. // 'status'=>1
  171. // ];
  172. // Db::name('merchant')->where('mer_id',$mer_data['mer_id'])->update($updateData);
  173. //佣金跟养老金商户或者用户邀请一个用户成功注册成为平台商家会员(6000元);获得2000元返佣+1000元养老金;商户自己获得1000元养老金;
  174. $this->nianfei_yj($annual_cost_order['id']);
  175. }
  176. }
  177. break;
  178. case "pay_activation":
  179. Db::name("log")->insert(array('data'=>"支付激活码回调data:".json_encode($data)));//日志记录 1
  180. $request['data'] = $data;
  181. $request['encryptKey'] = $header['encryptkey'];
  182. $request['merchantId'] = $header['merchantid'];
  183. $request['requestId'] = $header['requestid'];
  184. $res = ShouxinyiApiRequest::returnDecode($request);
  185. Db::name("log")->insert(array('data'=>"支付激活码回调data:".json_encode($data)));//日志记录
  186. Db::name("log")->insert(array('data'=>"支付激活码回调header:".json_encode($header)));//日志记录
  187. Db::name("log")->insert(array('data'=>"支付激活码回调res:".json_encode($res)));//日志记录
  188. $requestId = [];
  189. if(strpos($res['requestId'],'_') !== false){
  190. $requestId = explode("_",$res['requestId']);
  191. }
  192. if($res['status'] == 'SUCCESS'){
  193. try{
  194. // Db::name('merchant_annual_cost_order') -> where('order_no',$requestId[0]) -> update(['rand'=>$requestId[1],'serialNumber'=>$res['serialNumber']]);
  195. $order_data=Db::name('activation_code_order') -> where('order_no',$requestId[0]) -> find();
  196. Db::name('channel_user')->where('uid',$order_data['uid'])->update(['status'=>1]);
  197. if($order_data['status']==1){
  198. return false;
  199. }
  200. $id=Db::name('activation_code')->insertGetId([
  201. 'uid'=>$order_data['uid'],
  202. 'code'=>$this->randomFromDev(20),
  203. 'ctime'=>time(),
  204. 'status'=>1,
  205. 'utime'=>time(),
  206. 'use_uid'=>0,
  207. 'type'=>1
  208. ]);
  209. // $code_data=Db::name('activation_code')->where('status',0)->where('uid',0)->select();
  210. // if(!$code_data->isEmpty()){
  211. // $data=$code_data->toArray();
  212. // Db::name('activation_code')->where('id',$data[0]['id'])->update(['uid'=>$order_data['uid'],'status'=>1,'utime'=>time()]);
  213. Db::name('activation_code_order') -> where('order_no',$requestId[0]) -> update(['rand'=>$requestId[1],'serialNumber'=>$res['serialNumber'],'status'=>1,'code_id'=>$id]);
  214. // }
  215. }catch (\Exception $e) {
  216. Db::name('log')->insert(['data'=>'支付激活码错误:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  217. }
  218. }
  219. //处理佣金
  220. $num=$this->activation_yj($requestId[0]);
  221. //分账
  222. $this->activation_spilet($requestId[0],$num);
  223. break;
  224. case "pay_channel":
  225. Db::name("log")->insert(array('data'=>"支付渠道商回调data:".json_encode($data)));//日志记录 1
  226. $request['data'] = $data;
  227. $request['encryptKey'] = $header['encryptkey'];
  228. $request['merchantId'] = $header['merchantid'];
  229. $request['requestId'] = $header['requestid'];
  230. $res = ShouxinyiApiRequest::returnDecode($request);
  231. Db::name("log")->insert(array('data'=>"支付渠道商回调data:".json_encode($data)));//日志记录
  232. Db::name("log")->insert(array('data'=>"支付渠道商回调header:".json_encode($header)));//日志记录
  233. Db::name("log")->insert(array('data'=>"支付渠道商回调res:".json_encode($res)));//日志记录
  234. $requestId = [];
  235. if(strpos($res['requestId'],'_') !== false){
  236. $requestId = explode("_",$res['requestId']);
  237. }
  238. if($res['status'] == 'SUCCESS'){
  239. try{
  240. $order_data=Db::name('channel_order') -> where('order_no',$requestId[0]) -> find();
  241. if($order_data['status']==1){
  242. return false;
  243. }
  244. Db::name('channel_user')->where('uid',$order_data['uid'])->update(['status'=>1]);
  245. Db::name('channel_order') -> where('order_no',$requestId[0]) -> update(['rand'=>$requestId[1],'serialNumber'=>$res['serialNumber'],'status'=>1]);
  246. }catch (\Exception $e) {
  247. Db::name('log')->insert(['data'=>'支付渠道商错误:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  248. }
  249. try{
  250. //分账
  251. $this->channel_spilet($requestId[0]);
  252. //分佣
  253. $this->channel_fenyong($requestId[0]);
  254. // //给7个激活码
  255. // for($i=0;$i<=6;$i++){
  256. // Db::name('activation_code')->insertGetId([
  257. // 'uid'=>$order_data['uid'],
  258. // 'code'=>$this->randomFromDev(20),
  259. // 'ctime'=>time(),
  260. // 'status'=>1,
  261. // 'utime'=>time(),
  262. // 'use_uid'=>0,
  263. // 'type'=>2
  264. // ]);
  265. // }
  266. //赠送返本商户
  267. $mer = Db::name('user_mer') -> where('uid',$order_data['uid']) -> find();
  268. if(!$mer){
  269. Db::name('user_mer') -> insert(['uid'=>$order_data['uid'],'mer'=>10]);
  270. }else{
  271. Db::name('user_mer') -> where('uid',$order_data['uid'])->inc('mer', 10) ->update();;
  272. }
  273. //赠送商户
  274. $merchant=Db::name('merchant')->where('uid',$order_data['uid'])->find();
  275. if(!$merchant)
  276. Db::name('merchant_intention')->insert(['uid'=>$order_data['uid'],'activation_code'=>rand('000000000','999999999')]);
  277. //赠送大仓会员资格
  278. $dacang_user = Db::name('da_cang_user')->where('uid', $order_data['uid'])->find();
  279. $time = date('Y-m-d', time());
  280. $time = strtotime($time);
  281. $end_time = $time + 31536000 - 1;
  282. $dc_id = 1;
  283. //如果不是金卡会员,赠送金卡会员一年
  284. if (!$dacang_user) {
  285. Db::name('da_cang_user')->insert(['uid' => $order_data['uid'], 'ctime' => time(), 'end_time' => $end_time, 'dc_id' => $dc_id,'status'=>1,'type'=>1]);
  286. }else{
  287. //如果是银卡会员,变成金卡,一年 || 是否已过期,如果已过期,赠送金卡会员一年
  288. if($dacang_user['type'] == 2 || $dacang_user['end_time'] < $time){
  289. Db::name('da_cang_user')->where('uid', $order_data['uid'])->where('dc_id', $dc_id)->update(['end_time' => $end_time,'status'=>1,'type'=>1]);
  290. }
  291. }
  292. }catch (\Exception $exception){
  293. Db::name('log')->insert(['data'=>'支付渠道商错误:'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
  294. }
  295. }
  296. break;
  297. case "withdrawal_5upay":
  298. $request['data'] = $data;
  299. $request['encryptKey'] = $header['encryptkey'];
  300. $request['merchantId'] = $header['merchantid'];
  301. $request['requestId'] = $header['requestid'];
  302. $res = ShouxinyiApiRequest::returnDecode($request);
  303. Db::name("log")->insert(array('data'=>"提现回调data:".json_encode($data)));//日志记录
  304. Db::name("log")->insert(array('data'=>"提现回调header:".json_encode($header)));//日志记录
  305. Db::name("log")->insert(array('data'=>"提现回调res:".json_encode($res)));//日志记录
  306. if($res["status" ]=="SUCCESS"){
  307. Db::name('business_wthdrawal')
  308. ->where(['requestId'=>$res['requestId']])
  309. ->update(['status'=>2,'success_time'=>time(),'desc'=>'提现成功']);
  310. }
  311. break;
  312. default:
  313. Db::name("log")->insert(array('data'=>$type));//日志记录
  314. }
  315. }catch (Exception $exception){
  316. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  317. }
  318. }
  319. public function add_activation_code($uid,$num){
  320. for($i=1;$i<=$num;$i++){
  321. Db::name('activation_code')->insert([
  322. 'uid'=>$uid,
  323. 'code'=>$this->randomFromDev(20),
  324. 'ctime'=>time(),
  325. 'status'=>1,
  326. 'utime'=>time(),
  327. 'use_uid'=>0,
  328. 'type'=>2
  329. ]);
  330. }
  331. }
  332. public function nianfei_yj($id){
  333. try{
  334. //商户拿5%养老金
  335. $annual=Db::name('merchant_annual_cost_order')-> where('id',$id)->find();
  336. $uid = $annual['uid'];
  337. $mer_id = $annual['mer_id'];
  338. $pay_price = $annual['pay_price'] ?? 0;
  339. if ($pay_price == 0) {
  340. return '';
  341. }
  342. //订单用户
  343. $user = Db::name('user')->where('uid', $uid)->find();
  344. //订单用户直接上级
  345. $top_user = Db::name('user')->where('uid', $user['spread_uid'])->find();
  346. //上级身份是否大仓会员
  347. $is_da_cang_vip=Db::name('da_cang_user')->where('status',1)->where('uid',$user['spread_uid'])->find();
  348. //上级身份是否商户
  349. $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$user['spread_uid'])->find();
  350. $is_shanghu2=Db::name('merchant')->where('uid',$user['spread_uid'])->find();
  351. $is_shanghu3=Db::name('merchant_intention')->where('uid',$user['spread_uid'])->find();
  352. //渠道商
  353. $is_channel = Db::name('channel_user') -> where('uid',$user['spread_uid'])->where('status',1)->find();
  354. $number = bcmul($pay_price, 0.1, 2);//养老金
  355. //购买者本人给10%养老金
  356. if($number > 0){
  357. $data=[
  358. 'link_id' => $annual['id'],
  359. "uid"=>$uid,
  360. "pm"=>1,
  361. "title"=>'商户养老金',
  362. "category"=>"now_money",
  363. "type"=>"commission",
  364. "number"=>$number,
  365. "balance"=>0,
  366. "mark"=>'成为商户获得'.$number.'元养老金',
  367. "status"=>1,
  368. "commission_type"=>5,
  369. "order_sn"=>$annual['order_no'],
  370. "mer_id"=>$mer_id,
  371. "source"=>0,
  372. "type_shop"=>0,
  373. 'gzc'=>0
  374. ];
  375. Db::name("user_bill")->insert($data);
  376. Db::name("user")->where("uid",$uid)->inc('annuity', $number) ->update();
  377. Db::name("user")->where("uid",$uid)->inc('annuity_num', 1) ->update();
  378. }
  379. $top_yongjin = 0;//直接上级佣金
  380. $top_top_yongjin = 0;//间接上级佣金
  381. //直接上级
  382. if ($top_user['uid'] != 0) {
  383. //如果是大仓会员
  384. if($is_da_cang_vip){
  385. //如果上级是金卡会员 15%佣金
  386. if($is_da_cang_vip['type'] == 1){
  387. $top_yongjin = bcmul($pay_price, 0.15, 2);
  388. }elseif ($is_da_cang_vip['type'] == 2){
  389. //如果上级是银卡会员 10%佣金
  390. $top_yongjin = bcmul($pay_price, 0.10, 2);
  391. }
  392. }
  393. //如果是商户 20%佣金
  394. if($is_shanghu1||$is_shanghu2||$is_shanghu3){
  395. $top_yongjin = bcmul($pay_price, 0.20, 2);
  396. }
  397. //如果是渠道商 25% 佣金
  398. if($is_channel){
  399. $top_yongjin = bcmul($pay_price, 0.25, 2);
  400. }
  401. //如果上级有返本商户系统.直接佣金为60%
  402. $mer = Db::name('user_mer') -> where('uid',$user['spread_uid']) -> find();
  403. $mer_num = $mer['mer'] ?? 0;
  404. if($mer_num > 0){
  405. $top_yongjin = bcmul($pay_price, 0.6, 2);
  406. //减掉一次返本商户系统
  407. Db::name('user_mer') -> where('uid',$user['spread_uid']) -> dec('mer',1) ->update();
  408. }
  409. if($top_yongjin > 0){
  410. $bill_data = [
  411. 'uid' => $top_user['uid'],
  412. 'link_id' => $annual['id'],
  413. 'pm' => 1,
  414. 'title' => '佣金',
  415. 'category' => 'now_money',
  416. 'type' => 'commission',
  417. 'number' => $top_yongjin,
  418. 'mark' => '推荐商户获得' . $top_yongjin . '招募奖励',
  419. 'status' => 1,
  420. 'commission_type' => 10,
  421. 'order_sn' => $annual['order_no'],
  422. 'type_shop' => 0,
  423. 'mer_id' => $mer_id,
  424. 'source' => 0,
  425. 'order_type' => 1
  426. ];
  427. Db::name('user_bill')->insert($bill_data);
  428. Db::name('user')->where('uid', $top_user['uid'])->inc('brokerage_price', $top_yongjin)->update();
  429. }
  430. }
  431. //间接上级 如果直接上级是渠道商。间接上级是渠道商推荐人,如果没渠道商推荐人找注册推荐人
  432. if($is_channel){
  433. $top_top_user = Db::name('channel_user') -> where('uid',$top_user['spread_uid'])->where('status',1)->value('recommend_uid');
  434. if($top_top_user == ''){
  435. $top_top_user = Db::name('user')->where('uid', $top_user['spread_uid'])->value('uid');
  436. }
  437. }else{
  438. //直接上级不是渠道商,就找注册推荐人
  439. $top_top_user = Db::name('user')->where('uid', $top_user['spread_uid'])->value('uid');
  440. }
  441. if($top_top_user > 0){
  442. //商户
  443. $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_top_user)->find();
  444. $is_shanghu2=Db::name('merchant')->where('uid',$top_top_user)->find();
  445. $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_top_user)->find();
  446. //大仓会员
  447. $is_da_cang_vip=Db::name('da_cang_user')->where('uid',$top_top_user)->where('status',1)->find();
  448. //渠道商
  449. $is_channel = Db::name('channel_user') -> where('uid',$top_top_user)->where('status',1)->find();
  450. //如果是大仓会员
  451. if($is_da_cang_vip){
  452. //如果间接上级是金卡会员 25%佣金
  453. if($is_da_cang_vip['type'] == 1){
  454. $top_top_yongjin = bcmul($pay_price, 0.25, 2);
  455. }elseif ($is_da_cang_vip['type'] == 2){
  456. //如果上级是银卡会员 20%佣金
  457. $top_top_yongjin = bcmul($pay_price, 0.20, 2);
  458. }
  459. }
  460. //如果是商户 30%佣金
  461. if($is_shanghu1||$is_shanghu2||$is_shanghu3){
  462. $top_top_yongjin = bcmul($pay_price, 0.3, 2);
  463. }
  464. //如果是渠道商 30% 佣金
  465. if($is_channel){
  466. $top_top_yongjin = bcmul($pay_price, 0.3, 2);
  467. }
  468. if($top_top_yongjin > 0){
  469. $bill_data = [
  470. 'uid' => $top_top_user,
  471. 'link_id' => $annual['id'],
  472. 'pm' => 1,
  473. 'title' => '佣金',
  474. 'category' => 'now_money',
  475. 'type' => 'commission',
  476. 'number' => $top_top_yongjin,
  477. 'mark' => '推荐商户获得' . $top_top_yongjin . '培育奖励',
  478. 'status' => 1,
  479. 'commission_type' => 10,
  480. 'order_sn' => $annual['order_no'],
  481. 'type_shop' => 0,
  482. 'mer_id' => $mer_id,
  483. 'source' => 0,
  484. 'order_type' => 1
  485. ];
  486. Db::name('user_bill')->insert($bill_data);
  487. Db::name('user')->where('uid', $top_top_user)->inc('brokerage_price', $top_top_yongjin)->update();
  488. }
  489. }
  490. }catch (Exception $exception){
  491. Db::name("log")->insert(array('data'=>'年费佣金error'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  492. }
  493. return true;
  494. //2022年6月21号之前的版本
  495. try {
  496. //用户注册成为平台商家会员(6000元),商户自己获得666元养老金;商户上级获得666佣金无养老金 ,上上级如果为商户或者大仓会员的话再给666佣金无养老金 上上上级是商户的话再给666佣金无养老金
  497. //商户拿666养老金
  498. $annual=Db::name('merchant_annual_cost_order')-> where('id',$id)->find();
  499. $uid = $annual['uid'];
  500. $mer_id = $annual['mer_id'];
  501. $number = 666;//养老金
  502. $data=[
  503. 'link_id' => $annual['id'],
  504. "uid"=>$uid,
  505. "pm"=>1,
  506. "title"=>'商户养老金',
  507. "category"=>"now_money",
  508. "type"=>"commission",
  509. "number"=>$number,
  510. "balance"=>0,
  511. "mark"=>'成为商户获得'.$number.'元养老金',
  512. "status"=>1,
  513. "commission_type"=>5,
  514. "order_sn"=>$annual['order_no'],
  515. "mer_id"=>$mer_id,
  516. "source"=>0,
  517. "type_shop"=>0,
  518. 'gzc'=>0
  519. ];
  520. Db::name("user_bill")->insert($data);
  521. Db::name("user")->where("uid",$uid)->inc('annuity', $number) ->update();
  522. Db::name("user")->where("uid",$uid)->inc('annuity_num', 1) ->update();
  523. //公证处入账
  524. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  525. // if($certification) {
  526. // $user_data = Db::name('user')->where('uid', $uid)->find();
  527. // $user_data['real_name']=Db::name('user_certification')->where('status',1)->where('uid',$user_data['uid'])->value('user_name');
  528. // $user_data['account']=Db::name('user_certification')->where('status',1)->where('uid',$user_data['uid'])->value('mobile');
  529. // $online = ['uid' => $uid, 'pay_type' => $annual['pay_type'] == 'al' ? 4 : 1, 'order_sn' => $annual['order_no'], 'order_id' => $annual['id']];
  530. // $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  531. // $this->GZC($online, $certification, $number);
  532. // }
  533. //商户上级普通会员获得333佣金无养老金
  534. //商户上级大仓会员获得666佣金无养老金
  535. //商户上级商户获得999佣金无养老金
  536. //商户上级渠道商获得999佣金无养老金
  537. $top_user = Db::name('user') -> where('uid',Db::name('user')->where('uid',$uid)->value('spread_uid')) -> find();
  538. $is_da_cang_vip=Db::name('da_cang_user')->where('status',1)->where('uid',$top_user['uid'])->find();
  539. $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_user['uid'])->find();
  540. $is_shanghu2=Db::name('merchant')->where('uid',$top_user['uid'])->find();
  541. $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_user['uid'])->find();
  542. //渠道商
  543. $is_channel = Db::name('channel_user') -> where('uid',$top_user['uid'])->where('status',1)->find();
  544. $direct_number = 333;
  545. if($is_da_cang_vip){
  546. $direct_number = 666;
  547. }
  548. if($is_shanghu1||$is_shanghu2||$is_shanghu3){
  549. $direct_number = 999;
  550. }
  551. if($is_channel){
  552. $direct_number = 1999;
  553. }
  554. if($top_user){
  555. $spread_data=[
  556. 'link_id' => $annual['id'],
  557. "uid"=>$top_user['uid'],
  558. "pm"=>1,
  559. "title"=>'商户佣金',
  560. "category"=>"now_money",
  561. "type"=>"commission",
  562. "number"=>$direct_number,
  563. "balance"=>0,
  564. "mark"=>'推荐商户获得'.$direct_number.'元佣金',
  565. "status"=>1,
  566. "commission_type"=>10,
  567. "order_sn"=>$annual['order_no'],
  568. "mer_id"=>$mer_id,
  569. "source"=>0,
  570. "type_shop"=>0
  571. ];
  572. Db::name("user_bill")->insert($spread_data);
  573. Db::name("user")->where("uid", $top_user['uid'])->inc('brokerage_price', $direct_number)->update();
  574. }
  575. // $certification = UserCertification::getInstance()->where('uid', $spread_uid)->find();
  576. // if($certification) {
  577. // $user_data = Db::name('user')->where('uid', $spread_uid)->find();
  578. // $user_data['real_name']=Db::name('user_certification')->where('status',1)->where('uid',$user_data['uid'])->value('user_name');
  579. // $user_data['account']=Db::name('user_certification')->where('status',1)->where('uid',$user_data['uid'])->value('mobile');
  580. //
  581. // $online = ['uid' => $uid, 'pay_type' => $annual['pay_type'] == 'al' ? 4 : 1, 'order_sn' => $annual['order_no'], 'order_id' => $annual['id']];
  582. // $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  583. // $this->GZC($online, $certification, $number);
  584. // }
  585. //商户上级普通会员获得0佣金无养老金 间接
  586. //商户上级大仓会员获得666佣金无养老金 间接
  587. //商户上级商户获得999佣金无养老金 间接
  588. //商户上级渠道商获得1999佣金无养老金 间接
  589. $yj = 0;
  590. $is_shanghu=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_user['spread_uid'])->find();
  591. $is_shanghu2=Db::name('merchant')->where('uid',$top_user['spread_uid'])->find();
  592. $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_user['spread_uid'])->find();
  593. $is_daCang=Db::name('da_cang_user')->where('uid',$top_user['spread_uid'])->where('status',1)->find();
  594. //渠道商
  595. $is_channel = Db::name('channel_user') -> where('uid',$top_user['spread_uid'])->where('status',1)->find();
  596. if($is_daCang){
  597. $yj = 666;
  598. }
  599. if($is_shanghu||$is_shanghu2||$is_shanghu3||$is_channel){
  600. $yj = 999;
  601. }
  602. $spread_yh_data = [
  603. 'link_id' => $annual['id'],
  604. "uid" => $top_user['spread_uid'],
  605. "pm" => 1,
  606. "title" => '商户佣金',
  607. "category" => "now_money",
  608. "type" => "commission",
  609. "number" => $yj,
  610. "balance" => 0,
  611. "mark" => '推荐商户获得' . $yj . '元佣金',
  612. "status" => 1,
  613. "commission_type" => 10,
  614. "order_sn" => $annual['order_no'],
  615. "mer_id" => $mer_id,
  616. "source" => 0
  617. ];
  618. if($yj > 0){
  619. Db::name("user_bill")->insert($spread_yh_data);
  620. Db::name("user")->where("uid", $top_user['spread_uid'])->inc('brokerage_price', $yj)->update();
  621. }
  622. // $top_top_data=Db::name('user')->where('uid',Db::name('user')->where('uid',$top_user['spread_uid'])->value('spread_uid'))->find();
  623. // $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_top_data['uid'])->find();
  624. // $is_shanghu2=Db::name('merchant')->where('uid',$top_user['spread_uid'])->find();
  625. // $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_user['spread_uid'])->find();
  626. // if($is_shanghu1||$is_shanghu2||$is_shanghu3){
  627. // $spread_yh_data = [
  628. // 'link_id' => $annual['id'],
  629. // "uid" => $top_top_data['uid'],
  630. // "pm" => 1,
  631. // "title" => '商户佣金',
  632. // "category" => "now_money",
  633. // "type" => "commission",
  634. // "number" => $yj,
  635. // "balance" => 0,
  636. // "mark" => '推荐商户获得' . $yj . '元佣金',
  637. // "status" => 1,
  638. // "commission_type" => 10,
  639. // "order_sn" => $annual['order_no'],
  640. // "mer_id" => $mer_id,
  641. // "source" => 0
  642. // ];
  643. // Db::name("user_bill")->insert($spread_yh_data);
  644. // Db::name("user")->where("uid", $top_top_data['uid'])->inc('brokerage_price', $yj)->update();
  645. // }
  646. }catch (Exception $exception){
  647. Db::name("log")->insert(array('data'=>'年费佣金error'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  648. }
  649. }
  650. public function test1111()
  651. {
  652. // $domain = $this->request->domain();
  653. // if(strpos($domain, 'test.hebeiyhc.com') !== false){
  654. $requestId[0]=input('order_sn');
  655. // $pay_type=5;
  656. Db::name('store_group_order') -> where('group_order_sn',$requestId[0]) -> update(['rand'=>mt_rand(1000,9999)]);
  657. $orderSn = $requestId[0];
  658. $groupOrder = app()->make(StoreGroupOrderRepository::class)->getWhere(['group_order_sn' => $orderSn]);
  659. if (!$groupOrder || $groupOrder->paid == 1) return;
  660. app()->make(StoreOrderRepository::class)->paySuccess($groupOrder);
  661. // event('pay_success_order', ['order_sn' => $requestId[0],'pay_type'=>$pay_type]);
  662. dump('成功');
  663. // dump($this->randomFromDev(20));
  664. // }
  665. }
  666. function randomFromDev($len)
  667. {
  668. $fp = @fopen('/dev/urandom','rb');
  669. $result = '';
  670. if ($fp !== FALSE) {
  671. $result .= @fread($fp, $len);
  672. @fclose($fp);
  673. }
  674. else
  675. {
  676. trigger_error('Can not open /dev/urandom.');
  677. }
  678. // convert from binary to string
  679. $result = base64_encode($result);
  680. // remove none url chars
  681. $result = strtr($result, '+/', '-_');
  682. // Remove = from the end
  683. $result = str_replace('=', 't', $result);
  684. $result=rtrim($result,' ');
  685. return $result;
  686. }
  687. //app小程序话费支付
  688. public function hf_pay_wechat_mp(){
  689. try {
  690. log::info("微信小程序回调");
  691. Db::name('log')->insert(['data'=>'汇付订单支付pay_wechat_mp-66666666---发起支付']);
  692. $oid = Request::param('oid','');
  693. $code = Request::param('code','');
  694. $type = Request::param('type','');
  695. if($oid == '') return app('json')->fail("请检查参数是否正确");
  696. $groupOrder = Db::name('order_huafei_hf')->where('order_id', (int)$oid)->find();
  697. if (!$groupOrder) return app('json')->fail('订单不存在或已支付');
  698. $res = $this->pay_huifu($type,$code,$groupOrder,"储蓄保",env('APP_URL')."/api/hf_notify/huafei",'delay');
  699. Db::name('log')->insert(['data'=>'汇付话费订单支付--- 返回参数'.json_encode($res)]);
  700. if (isset($res['id'])) {
  701. return app('json')->success($res);
  702. }
  703. return app('json')->fail($res);
  704. }catch (Exception $exception){
  705. log::info("支付异常======");
  706. log::info($exception);
  707. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  708. return app('json')->fail("异常");
  709. }
  710. }
  711. //小程序支付
  712. public function pay_wechat_mp(StoreGroupOrderRepository $groupOrderRepository){
  713. $oid = Request::param('oid','');
  714. $store_order_data = Db::name('store_order')->where('group_order_id',$oid)->find();
  715. $array_fzone_paytype = json_decode( $store_order_data['fzone_paytype'],true);
  716. if(!empty($array_fzone_paytype['type'])){
  717. //a3 会员专区的现金+VR支付
  718. if($array_fzone_paytype['type'] == 'a3'){
  719. $userdata = Db::name('user')->where('uid',$store_order_data['uid'])->find();
  720. //查询用户的VR是否足够
  721. $vr_pri = $userdata['vr'] - $array_fzone_paytype['other'];
  722. // return app('json')->fail($oid);
  723. //return app('json')->fail($userdata['vr'] . " pri:" .$array_fzone_paytype['other']);
  724. if($vr_pri < 0){
  725. return app('json')->fail('VR不足,请重试!');
  726. }
  727. //如果VR足够,修改订单的实际价格
  728. $group_order_datas = Db::name('store_group_order')->where('group_order_id',$oid)->find();
  729. if(!empty($group_order_datas)){
  730. Db::name('store_group_order')->where('group_order_id',$oid)->update(['pay_price'=>$array_fzone_paytype['price']]);
  731. }else{
  732. return app('json')->fail('找不到订单,请重试!');
  733. }
  734. }
  735. //b2 精彩生活区的现金+积分支付
  736. if($array_fzone_paytype['type'] == 'b2'){
  737. //查询用户的积分是否足够
  738. $score_pri = $userdata['score'] - $array_fzone_paytype['other'];
  739. if($score_pri < 0){
  740. return app('json')->fail('积分不足,请重试!');
  741. }
  742. //如果积分足够,修改订单的实际价格
  743. $group_order_datas = Db::name('store_group_order')->where('group_order_id',$oid)->find();
  744. if(!empty($group_order_datas)){
  745. Db::name('store_group_order')->where('group_order_id',$oid)->update(['pay_price'=>$array_fzone_paytype['price']]);
  746. }else{
  747. return app('json')->fail('找不到订单,请重试!');
  748. }
  749. }
  750. }else{
  751. return app('json')->fail('数据异常,请重新下单,并选择支付方式!');
  752. }
  753. try {
  754. log::info("微信小程序回调");
  755. Db::name('log')->insert(['data'=>'汇付订单支付pay_wechat_mp-66666666---发起支付']);
  756. $oid = Request::param('oid','');
  757. $code = Request::param('code','');
  758. $type = Request::param('type','');
  759. $pay_open_id = Request::param('pay_open_id','');
  760. if($oid == '')
  761. return app('json')->fail("请检查参数是否正确");
  762. $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  763. if (!$groupOrder)
  764. return app('json')->fail('订单不存在或已支付');
  765. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  766. if($cart){
  767. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  768. $cart = explode(",",$cart);
  769. $cart_id = $cart[0];
  770. $product = Db::name("store_product")
  771. ->alias('sp')
  772. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  773. ->where(["sc.cart_id"=>$cart_id])
  774. ->value('sp.store_name');
  775. }
  776. $res = $this -> pay_huifu($type,$code,$groupOrder,$product ?? "储蓄保",env('APP_URL')."/api/hf_notify/pay",'delay');
  777. Db::name('log')->insert(['data'=>'汇付订单支付--- 返回参数'.json_encode($res)]);
  778. if (isset($res['id'])) {
  779. Db::name('store_group_order')->where('group_order_id', $oid)->update(['hf_pay_id' => $res['id'],'pay_wx'=>systemConfig('pay_wx')]);
  780. if($pay_open_id)
  781. Db::name('store_order')->where('group_order_id', $oid)->update(['pay_open_id' => $pay_open_id]);
  782. return app('json')->success($res);
  783. }
  784. return app('json')->fail($res);
  785. //////////////////////////////////////////////首信易/////////////////////////////////////////////////////////
  786. if($type == 'wx'){
  787. if(!$code || $code == '' || $code =='undefined')
  788. return app('json')->fail("授权失败,code为空");
  789. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=".env('WECHAT_MP.APPID')."&secret=".env('WECHAT_MP.SECRET')."&js_code=".$code."&grant_type=authorization_code";
  790. $get = curlGet($url);
  791. if(!isset($get['openid']) || empty($get['openid'])){
  792. return app('json')->fail('授权失败');
  793. }
  794. $openid = $get['openid'];
  795. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  796. $datas['openId'] = $openid;
  797. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  798. }else{
  799. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  800. }
  801. $datas['requestId'] = $groupOrder['group_order_sn']."_".rand(1000,9999);//订单号
  802. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  803. $datas['callbackUrl'] = 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg4NzQ4NDgzNQ==&scene=124&uin=&key=&devicetype=Windows+10+x64&version=6302019c&lang=zh_CN&a8scene=7&fontgear=2';//同步地址微信公众号
  804. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  805. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  806. $cart = explode(",",$cart);
  807. $cart_id = $cart[0];
  808. $product = Db::name("store_product")
  809. ->alias('sp')
  810. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  811. ->where(["sc.cart_id"=>$cart_id])
  812. ->value('sp.store_name');
  813. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  814. $productDetails = array(
  815. 'name' => $product ?? "储蓄保",//商品名称。需传递真实产品名称。
  816. 'quantity' => 1,//商品数量
  817. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  818. );
  819. $datas['productDetails'] = [$productDetails];//商品信息
  820. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  821. $datas['notifyUrl']='/api/notify/pay_5upay';
  822. $res = ShouxinyiApiRequest::onlinePay($datas);
  823. $return = array(
  824. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  825. 'status' => $res['status'],
  826. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  827. 'appParams' => $res['appParams'] ?? '',//App调用码
  828. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  829. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  830. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  831. 'token' => $res['token'] ?? '', //微包支付调用token
  832. );
  833. Db::name("log")->insert(array('data'=>'支付回调---'.json_encode($return)));//日志记录
  834. return app('json')->success($return);
  835. }catch (Exception $exception){
  836. log::info("支付异常======");
  837. log::info($exception);
  838. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  839. return app('json')->fail("异常");
  840. }
  841. }
  842. //小程序支付
  843. public function pay_wechat_mp_copy(StoreGroupOrderRepository $groupOrderRepository){
  844. try {
  845. Db::name('log')->insert(['data'=>'汇付订单支付pay_wechat_mp6666666---发起支付']);
  846. $oid = Request::param('oid','');
  847. $code = Request::param('code','');
  848. $type = Request::param('type','');
  849. $pay_open_id = Request::param('pay_open_id','');
  850. if($oid == '')
  851. return app('json')->fail("请检查参数是否正确");
  852. $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  853. if (!$groupOrder)
  854. return app('json')->fail('订单不存在或已支付');
  855. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  856. if($cart){
  857. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  858. $cart = explode(",",$cart);
  859. $cart_id = $cart[0];
  860. $product = Db::name("store_product")
  861. ->alias('sp')
  862. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  863. ->where(["sc.cart_id"=>$cart_id])
  864. ->value('sp.store_name');
  865. }
  866. $res = $this -> pay_huifu($type,$code,$groupOrder,$product ?? "储蓄保",env('APP_URL')."/api/hf_notify/pay",'delay');
  867. Db::name('log')->insert(['data'=>'汇付订单支付--- 返回参数'.json_encode($res)]);
  868. if (isset($res['id'])) {
  869. Db::name('store_group_order')->where('group_order_id', $oid)->update(['hf_pay_id' => $res['id'],'pay_wx'=>systemConfig('pay_wx')]);
  870. if($pay_open_id)
  871. Db::name('store_order')->where('group_order_id', $oid)->update(['pay_open_id' => $pay_open_id]);
  872. return app('json')->success($res);
  873. }
  874. return app('json')->fail($res);
  875. //////////////////////////////////////////////首信易/////////////////////////////////////////////////////////
  876. if($type == 'wx'){
  877. if(!$code || $code == '' || $code =='undefined')
  878. return app('json')->fail("授权失败,code为空");
  879. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=".env('WECHAT_MP.APPID')."&secret=".env('WECHAT_MP.SECRET')."&js_code=".$code."&grant_type=authorization_code";
  880. $get = curlGet($url);
  881. if(!isset($get['openid']) || empty($get['openid'])){
  882. return app('json')->fail('授权失败');
  883. }
  884. $openid = $get['openid'];
  885. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  886. $datas['openId'] = $openid;
  887. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  888. }else{
  889. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  890. }
  891. $datas['requestId'] = $groupOrder['group_order_sn']."_".rand(1000,9999);//订单号
  892. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  893. $datas['callbackUrl'] = 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg4NzQ4NDgzNQ==&scene=124&uin=&key=&devicetype=Windows+10+x64&version=6302019c&lang=zh_CN&a8scene=7&fontgear=2';//同步地址微信公众号
  894. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  895. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  896. $cart = explode(",",$cart);
  897. $cart_id = $cart[0];
  898. $product = Db::name("store_product")
  899. ->alias('sp')
  900. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  901. ->where(["sc.cart_id"=>$cart_id])
  902. ->value('sp.store_name');
  903. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  904. $productDetails = array(
  905. 'name' => $product ?? "储蓄保",//商品名称。需传递真实产品名称。
  906. 'quantity' => 1,//商品数量
  907. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  908. );
  909. $datas['productDetails'] = [$productDetails];//商品信息
  910. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  911. $datas['notifyUrl']='/api/notify/pay_5upay';
  912. $res = ShouxinyiApiRequest::onlinePay($datas);
  913. $return = array(
  914. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  915. 'status' => $res['status'],
  916. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  917. 'appParams' => $res['appParams'] ?? '',//App调用码
  918. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  919. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  920. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  921. 'token' => $res['token'] ?? '', //微包支付调用token
  922. );
  923. return app('json')->success($return);
  924. }catch (Exception $exception){
  925. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  926. return app('json')->fail("异常");
  927. }
  928. }
  929. public function pay_demo(StoreGroupOrderRepository $groupOrderRepository){
  930. Db::name("log")->insert(array('data'=>'测试支付---1'));//日志记录
  931. $oid = Request::param('oid','');
  932. $type = Request::param('type','');
  933. $code = Request::param('code','');
  934. if($oid == '')
  935. return app('json')->fail("请检查参数是否正确");
  936. $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  937. if (!$groupOrder)
  938. return app('json')->fail('订单不存在或已支付');
  939. $goods_title=Db::name('merchant')->where('mer_id',$groupOrder['mer_id'])->find();
  940. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  941. Db::name("log")->insert(array('data'=>'测试支付---购物车---'.json_encode($cart)));//日志记录
  942. $cart = explode(",",$cart);
  943. $cart_id = $cart[0];
  944. $product = Db::name("store_product")
  945. ->alias('sp')
  946. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  947. ->where(["sc.cart_id"=>$cart_id])
  948. ->value('sp.store_name');
  949. if($type=='WX'){
  950. if(!$code || $code == '' || $code =='undefined')
  951. return app('json')->fail("授权失败,code为空");
  952. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=".env('WECHAT_MP.APPID')."&secret=".env('WECHAT_MP.SECRET')."&js_code=".$code."&grant_type=authorization_code";
  953. $get = curlGet($url);
  954. if(!isset($get['openid']) || empty($get['openid'])){
  955. return app('json')->fail('授权失败');
  956. }
  957. $openid = $get['openid'];
  958. $member_id=$goods_title['hf_member_id_wx'];
  959. $app_id='app_0827b960-b932-45ec-b800-4e850091b419';
  960. $type='2';
  961. $pay_channel='wx_lite';
  962. $key='api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  963. $expend=[
  964. 'open_id'=>$openid
  965. ];
  966. $params=[
  967. 'order_no'=>$groupOrder['group_order_sn']."_".rand(1000,9999),//订单号
  968. 'app_id'=>$app_id,
  969. 'pay_channel'=>$pay_channel,
  970. 'pay_amt'=>strval($groupOrder['pay_price']),//金额。,
  971. 'goods_title'=>$product ?? "储蓄保",
  972. 'goods_desc'=>$product ?? "储蓄保",
  973. 'device_info'=>[
  974. 'device_ip'=>app('request')->ip()
  975. // 'device_ip'=>'115.171.134.68'
  976. ],
  977. 'expend'=>json_encode($expend),
  978. 'fee_mode'=>'I',
  979. 'notify_url'=>env('APP_URL')."/api/jsapiPay/notify/HF_demo"
  980. ];
  981. }elseif($type=='ALI'){
  982. if(!$code || $code == '' || $code =='undefined')
  983. return app('json')->fail("授权失败,code为空");
  984. $res = $this -> getAliUserId($code);
  985. return app('json')->success($res);
  986. $buyer_id = Request::param('buyer_id','');
  987. $member_id=$goods_title['hf_member_id'];
  988. $app_id='app_44108546-d27a-48ee-88c1-84b45b75114f';
  989. $type='1';
  990. $pay_channel='alipay_pub';
  991. $expend=[
  992. 'buyer_id'=>$buyer_id
  993. ];
  994. $key='api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  995. $params=[
  996. 'order_no'=>$groupOrder['group_order_sn']."_".rand(1000,9999),//订单号
  997. 'app_id'=>$app_id,
  998. 'pay_channel'=>$pay_channel,
  999. 'pay_amt'=>strval($groupOrder['pay_price']),//金额。,
  1000. 'goods_title'=>$product ?? "储蓄保",
  1001. 'goods_desc'=>$product ?? "储蓄保",
  1002. 'device_info'=>[
  1003. 'device_ip'=>app('request')->ip()
  1004. // 'device_ip'=>'115.171.134.68'
  1005. ],
  1006. 'expend'=>json_encode($expend),
  1007. 'fee_mode'=>'I',
  1008. 'notify_url'=>env('APP_URL')."/api/jsapiPay/notify/HF_demo"
  1009. ];
  1010. }
  1011. $res=$this->Payment_create_traits($params,$type,$key);
  1012. $res['code']='1000';
  1013. $res['return_code']='999';
  1014. if(!empty($res['error_code'])){
  1015. $res['code']='1000';
  1016. $res['return_msg']=$res['error_msg'];
  1017. $res['return_code']=1200;
  1018. }
  1019. return app('json')->success($res);
  1020. }
  1021. public function getAliUserId($code){
  1022. $aop = new AopClient();
  1023. $url = "https://openapi.alipay.com/gateway.do";
  1024. // $app_id="2021002194632049";
  1025. // $privateKey="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDGxceDFVT6VTYClinyAdY4PxE6MadNYLZ3sbLOLV14e39kuu1lkKDBZ/KPRNruPlSPGdiRVe+L8v4rsVk6bthsS/vMk5aH1wQyt58/HvHmZ5QVo3U5UD7cgqqefTcRJjKhjjM1rU/OrOkOqyssaLRukW3jeKRlBccUgtaGsXXrbMxWYpzl1OMDhKRRUVxu3LTfqlMpHghOasQrgyD92q9wlUN7U6hBYzGUocO/N3sz97PZwptwWAW0r3CFdlLCpgnMr+xb/Zh8td1OKGl3wEghiGavgDDlc2+w/xtk1SZ3pJbnGAU+D+oyJ6r76po6vkyGIlLrKp/zQ50az7fObzgNAgMBAAECggEBAK60szERlMkaEAih92gQGTsCo5+keMnX0UjO1LvGv7rfwQ7GBVYZklGrjVRDTrHL8wJ70w+amptFDgVVMXncZzh4aG5c4heu8q+pGLyf9DlwnIWQT736O+YQqun2YGogSqwYkgYBuH2NGKKd66pytPPhutYN+WAZfesXPHrSizRJtZMfuZvvGzm6ZJLZ1LmhvkOuLrX4xrJGRs1nAwZOmOfi4MY5VASblfPj59fUim9hErocNaX4uiMVwmhQl2QuOM/EbTd1UkW+dkV/gyQMOFzpcfN+SEi+hdLN+JiR9TVEcwity6ihOG5+3X33GKzfY4WFxeHHUaqA0SQWSkKofMECgYEA5OF5Imtq8/6JjWJ0jvYCpUnj9742McGJZTWBoTn9Hp0d3bwyE3YbH8pBVJyvzlfPKB9TUjE2FzVZvQtxEu+ZxToccp/LPqlgITWNHCmEtzAgXW7ww2PafgDZJ2QRSyjLUeRIWSAkeilj64XMCEC/bEs/nb5nmUb2gnsNTvvpMLUCgYEA3lMMtaIZH1fMI4XMNaPFzeRiKc0FIcLEem/efnPetPuOCujIWQJ/x9cCDCcfqO59I1FXQuiC/E1dFvme2qs/H7h2bFu8RG0M/ZQWd9twg31Sh+R7gCQakFERag8HXc4AWfBGXCvMu1SmSovU49KecSLxYGOAUdp77j1GxtLiePkCgYAQjc45ExPVOd+w/iH4BQsD8Wgvju5Ugu7xBwGtK4iHIk36r5XfmnczwWkgOYTto6Qz/rAEDdMfspge+CjhebrhbOaJ08zbZ1ywijL+inIy3aQ5ncCEIUC4RE9wbehiSz0JWz1wVMbOnxe+/RpYrnYp2vdq7U6I430IyuWXhNjE0QKBgEtJUmd7oghEIgPxfiq37/b+HOPM4q0BGKnhkjW+JS+idAJru9SwjPbub2oQIZ+CS2wXUnZ86EZqKFjsZQflr7WdMLUXB5UgXKLOcCFcdSiB2t3b2JqXH0u5uCzzM+pnJSVPwXPa/TR+wOVDnu8bVr43OAgNCdouI4OUyo/vv/N5AoGATJaIvpsZ9v1zmhbtJbgPBM9dhD2PIp2ufZ7yvhGGzA02FqAbyAeVsI2d+W+uA6jJ1X87x27pQv//mFoFXStxX3/bhdgTWbUYEWobAhw1jBS1rMQfLuBGGI/LsHGhzau3U+59erC5sYhGgZKSdXDyjOduWQlPWAv6ufkNZ+I3FCU=";
  1026. // $aop->alipayrsaPublicKey='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuUb+0sJSNXjWiG0VJIPzn55+18af/fubYMpRLlreu34ewMgLx1zpCNpB3wrA+dylfWPMAm8PzvKnakByB+VJ/LMNhWHmF8Qkdo4astAikjlI4TMQCK/G384NzrtjHR4DGCDM5CMVt1xw5noF7kNBMYIvgDfhMCYmygdlIjuVdIlVEoQKOsT0RaNMleES0aZvbjvBGkGM0dsetqUExSjid9BF1NAO2ET+J3XMxCtMgCUVmFUvxsCKe6Rapa1/Lk3rzIeG6CRpoabuYfPM9E+3y3f3luSOMXLfH9lOSW1RA8qrF+Ms1RZv8gmzUnbyrPLmmZPmmN/Qs6DGzDVg73fpSwIDAQAB';
  1027. $app_id = '2021001197698727';
  1028. $privateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCf1r70C/D+XWtDuuV07/41UnEHRyas0Y92TRS5eI+S4v4r8lDY8aLcWM6ssE/dVaKrGulEqG3jv12WLRP7ZDiHSzlcgrHZLm9sub+rY9r7dPMn69xaVg/wMh7SQ5yduHXr1WtjIlnb4ng29ZoQjzHy9kgQ0i92Vtk1PRsQrlUWeYGXjftBShdHMraP7km8tvA5S+tTalczzkDm5i2lXHeycAkIiTJ1dqebA74ZCe47kyG0AtNbRBOMOB0zOFcHX865Faa1hPPlug98o6D6oyR4M/rkehqtf1Y1AIuBGIDSey4BmOvIqOiu/WbLTSx7TS9OxXBoP3SFMKiVKMqR7yH5AgMBAAECggEAGf3QpVy/vo0wYR4mK+LOwpr6WEWgq1+UZZdZNGO/bRJOZJUNwolgg1ZJnVk6U3KWdh51Kj39SJiYvk/sPOfqLU31MO7rvrZHVjXKTjN5q4Qz+hzngyUViGiODIEEGb2iJ0xYHxG57QChrcY4XFL8u1aDF4EmSKcMwRSDry26FmI/uEfjuF30kl11r24CtifE/NkbnqeWzOvoXteWxb1DbUsiqjRydnqUme5BPNoFhp5maYMZVUyg+I92G39FlQ1xQSJVq68TpL7ePOf8JBrGLqHSqNAiAfFwuvUWpELBstc4GPvQeWAw8142dsQGWz2wHZjUZW9CEyfrPDXZUz2wkQKBgQDdzpWkLNSjqhzdxcWw6z4bTguRVc594s5wbMftrKEybVbutVYjVKYi3rzSRRMcbr7vkkCj7FkQsmjY5l/wrv/CBrN/OPhQ7dDGTdEjtU2pnhDOvLaXIvcinz9YeAVHGePXXyx43wo5LysCqhAIxA5lS+LOuZZxQJzYVOv18uI6NQKBgQC4eqT8DiYb81Ke5l4Q5irOOd9Q/PqtCDJAyOkZVjMKBNOJauHZdx+rFgB2GEB2EdI5rUPDLn4XBkmeHlqk15HjLGA2kl4AojB2eCfD9voYHOTOEiAGpm9AL9Ws8ALFg27W1XKu/Ih1IxHifCAeR86lnIejJCizQ/P2lilWBj9hNQKBgQC8E9cZbhYkbTOq7W9TNDXmi0gNxXehkPdBp0vkAhRxoPss0ECpFrcFLF9p4L5yxolKtXXwSZHAMbfr63SArrMZv/rmLtWIMg9sh0GGiM7Au9I+qxAcmb568hORnbvD7XUgA4i/OUj+8jsDOFb+R9h5Fl7MsduaTpJwcZnfZENl3QKBgEKMq9vp1sGag6GjBSgfgC2pHvB+cofdPxOz5rMnL35bw1v9XMAwgxIa+8uecBKn1yjLYniU2xO/Ruttk9GHmq9TINpO7u5XlBgIvH+rJwlv0vKsAzWi8Ns85l5erwFFqsSBd7+8hhWLszX7BTMnQFrqHtwxfSU+TFIWVY8c7dxJAoGAaXqh1VejqHCPLfQ7Dthx0lEkzXOdUaPVh+LW7F5RPCBBnhsaFGlKVOQYHm6oFtH9qLgZBT1IkA7HTGX9YYTX8jl1zvgUNvxFOprPyYCo5O7vsa7KfkIzZt2FnycI83NAKYDTpA8q28YI81rcHcRLRbmun2drEPyj9dG79uy6Xg8=';
  1029. $aop->alipayrsaPublicKey='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArHwMZtNYBkK5q2jQ0Ml18H8MhQX9Bpuz/ignvuJC47K7LHY+F6/U/+o/nYeDhqHzUajMAAyM06N3r2qBnWQRjC4JKFMO4i5xIDVycuumzcsWz3LwAkHOFG/S1pGXFWh74zdQDNednhvnNOiTDwjefZRnf5HUqEZK/7tRSaZvzSUIAwHG2zj0C6AYkhg5wr6ZJxgRDjPjqbs6ZMqLT+pITsnCcc6IgIisZbPTdtw1U2FKmQm5n228drI3XKYbE3UVT2y6R0mZNmqmiHDszmYSKOjDrpgtMExWpee8kUFn7J800HIyYtq0nRv1ypdWngUZtkm+szVWOTDGgN4eHQW3FwIDAQAB';
  1030. $aop->gatewayUrl = $url;
  1031. $aop->appId = $app_id;
  1032. $aop->rsaPrivateKey = $privateKey;
  1033. $aop->apiVersion = '1.0';
  1034. $aop->signType = 'RSA2';
  1035. $aop->postCharset='GBK';
  1036. $aop->format='json';
  1037. $request = new AlipaySystemOauthTokenRequest ();
  1038. $request->setGrantType("authorization_code");
  1039. $request->setCode($code);
  1040. // $request->setRefreshToken("201208134b203fe6c11548bcabd8da5bb087a83b");
  1041. $result = $aop->execute ( $request);
  1042. $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  1043. $resultCode = $result->$responseNode->code;
  1044. if(!empty($resultCode)&&$resultCode == 10000){
  1045. return $result;
  1046. } else {
  1047. return false;
  1048. }
  1049. }
  1050. /**
  1051. * @remarks 小程序支付年费
  1052. * @author Tang
  1053. * @created 2021/8/27 9:18
  1054. */
  1055. public function pay_annual_cost(){
  1056. try {
  1057. $oid = Request::param('oid','');
  1058. $code = Request::param('code','');
  1059. $payType = Request::param('type','');
  1060. $appid = Request::param('appid','');
  1061. if($oid == '')
  1062. return app('json')->fail("请检查参数是否正确");
  1063. // $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  1064. $groupOrder=Db::name('merchant_annual_cost_order')->where('id',$oid)->where('status',0)->find();
  1065. if (!$groupOrder)
  1066. return app('json')->fail('订单不存在或已支付');
  1067. Db::name('log')->insert(['data'=>'汇付商户支付---groupOrder'.json_encode($groupOrder)]);
  1068. $res = $this -> pay_huifu($payType,$code,$groupOrder,'商户',env('APP_URL')."/api/hf_notify/pay_annual",null,$appid);
  1069. // Db::name('log')->insert(['data'=>'汇付商户支付---'.json_encode($res)]);
  1070. Db::name('merchant_annual_cost_order')->where('id',$oid) ->update(['hf_pay_id'=>$res['id']]);
  1071. return app('json')->success($res);
  1072. ///////////////////////////////年费/////////////////////////////////////////////
  1073. if($payType == 'wx'){
  1074. if(!$code || $code == '' || $code =='undefined')
  1075. return app('json')->fail("授权失败,code为空");
  1076. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=".env('WECHAT_MP.APPID')."&secret=".env('WECHAT_MP.SECRET')."&js_code=".$code."&grant_type=authorization_code";
  1077. $get = curlGet($url);
  1078. if(!isset($get['openid']) || empty($get['openid'])){
  1079. return app('json')->fail('授权失败');
  1080. }
  1081. $openid = $get['openid'];
  1082. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  1083. $datas['openId'] = $openid;
  1084. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  1085. Db::name('merchant_annual_cost_order')->where('id',$oid)->update(['pay_type'=>'wx']);
  1086. }else{
  1087. Db::name('merchant_annual_cost_order')->where('id',$oid)->update(['pay_type'=>'al']);
  1088. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  1089. }
  1090. $datas['requestId'] = $groupOrder['order_no']."_".rand(1000,9999);//订单号
  1091. $datas['splitMark'] = 'NOT_DO_SPLIT';//不分账
  1092. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  1093. $datas['callbackUrl'] = 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg4NzQ4NDgzNQ==&scene=124&uin=&key=&devicetype=Windows+10+x64&version=6302019c&lang=zh_CN&a8scene=7&fontgear=2';//同步地址微信公众号
  1094. $cart = Db::name('merchant_annual_cost_order')->where('id',$oid)->where('status',0)-> value("id");//日志记录
  1095. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  1096. $product = '商家年费';
  1097. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  1098. $productDetails = array(
  1099. 'name' => $product ?? "储蓄保年费",//商品名称。需传递真实产品名称。
  1100. 'quantity' => 1,//商品数量
  1101. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  1102. );
  1103. $datas['productDetails'] = [$productDetails];//商品信息
  1104. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  1105. $datas['notifyUrl']='/api/notify/pay_annual';
  1106. $res = ShouxinyiApiRequest::onlinePay($datas);
  1107. $return = array(
  1108. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  1109. 'status' => $res['status'],
  1110. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  1111. 'appParams' => $res['appParams'] ?? '',//App调用码
  1112. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  1113. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  1114. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  1115. 'token' => $res['token'] ?? '', //微包支付调用token
  1116. );
  1117. return app('json')->success($return);
  1118. }catch (Exception $exception){
  1119. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  1120. return app('json')->fail("异常");
  1121. }
  1122. }
  1123. /**
  1124. * @remarks 小程序支付激活码
  1125. * @author Tang
  1126. * @created 2021/8/27 9:18
  1127. */
  1128. public function pay_activation_code(){
  1129. try {
  1130. $oid = Request::param('oid','');
  1131. $code = Request::param('code','');
  1132. $payType = Request::param('type','');
  1133. if($oid == '')
  1134. return app('json')->fail("请检查参数是否正确");
  1135. // $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  1136. $groupOrder=Db::name('activation_code_order')->where('id',$oid)->where('status',0)->find();
  1137. // $group_type=Db::name('activation_code_order')->where('id',$oid)->where('status',0)->update(['pay_type'=>$type]);
  1138. if (!$groupOrder)
  1139. return app('json')->fail('订单不存在或已支付');
  1140. $res = $this -> pay_huifu($payType,$code,$groupOrder,"商户激活码",env('APP_URL')."/api/hf_notify/pay_activation",'delay');
  1141. Db::name('log')->insert(['data'=>'汇付激活码支付---'.json_encode($res)]);
  1142. Db::name('activation_code_order')->where('group_order_id',$oid) ->update(['hf_pay_id'=>$res['id']]);
  1143. return app('json')->success($res);
  1144. //////////////////////////////////////首信易/////////////////////////////////////////////
  1145. if($payType == 'wx'){
  1146. Db::name('log')->insert(['data'=>'code---'.$code]);
  1147. if(!$code || $code == '' || $code =='undefined')
  1148. return app('json')->fail("授权失败,code为空");
  1149. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=".env('WECHAT_MP.APPID')."&secret=".env('WECHAT_MP.SECRET')."&js_code=".$code."&grant_type=authorization_code";
  1150. $get = curlGet($url);
  1151. Db::name('log')->insert(['data'=>'open_id---'.json_encode($get)]);
  1152. if(!isset($get['openid']) || empty($get['openid'])){
  1153. return app('json')->fail('授权失败');
  1154. }
  1155. $openid = $get['openid'];
  1156. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  1157. $datas['openId'] = $openid;
  1158. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  1159. Db::name('activation_code_order')->where('id',$oid)->update(['pay_type'=>'al']);
  1160. }else{
  1161. Db::name('activation_code_order')->where('id',$oid)->update(['pay_type'=>'al']);
  1162. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  1163. }
  1164. $datas['requestId'] = $groupOrder['order_no']."_".rand(1000,9999);//订单号
  1165. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  1166. $datas['callbackUrl'] = 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg4NzQ4NDgzNQ==&scene=124&uin=&key=&devicetype=Windows+10+x64&version=6302019c&lang=zh_CN&a8scene=7&fontgear=2';//同步地址微信公众号
  1167. $cart = Db::name('activation_code_order')->where('id',$oid)->where('status',0)-> value("id");//日志记录
  1168. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  1169. $product = '商家激活码';
  1170. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  1171. $productDetails = array(
  1172. 'name' => $product ?? "激活码",//商品名称。需传递真实产品名称。
  1173. 'quantity' => 1,//商品数量
  1174. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  1175. );
  1176. $datas['productDetails'] = [$productDetails];//商品信息
  1177. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  1178. $datas['notifyUrl']='/api/notify/pay_activation';
  1179. Db::name('log')->insert(['data'=>'请求数据--'.json_encode($datas)]);
  1180. $res = ShouxinyiApiRequest::onlinePay($datas);
  1181. $return = array(
  1182. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  1183. 'status' => $res['status'],
  1184. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  1185. 'appParams' => $res['appParams'] ?? '',//App调用码
  1186. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  1187. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  1188. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  1189. 'token' => $res['token'] ?? '', //微包支付调用token
  1190. );
  1191. return app('json')->success($return);
  1192. }catch (Exception $exception){
  1193. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  1194. return app('json')->fail("异常");
  1195. }
  1196. }
  1197. /**
  1198. * @remarks 小程序支付渠道商
  1199. * @author Tang
  1200. * @created 2021/8/27 9:18
  1201. */
  1202. public function pay_channel(){
  1203. try {
  1204. $oid = Request::param('oid','');
  1205. $code = Request::param('code','');
  1206. $payType = Request::param('type','');
  1207. if($oid == '')
  1208. return app('json')->fail("请检查参数是否正确");
  1209. // $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  1210. $groupOrder=Db::name('channel_order')->where('id',$oid)->where('status',0)->find();
  1211. // $group_type=Db::name('channel_order')->where('id',$oid)->where('status',0)->update(['pay_type'=>$type]);
  1212. if (!$groupOrder)
  1213. return app('json')->fail('订单不存在或已支付');
  1214. $res = $this -> pay_huifu($payType,$code,$groupOrder,'渠道商',env('APP_URL')."/api/hf_notify/pay_channel");
  1215. Db::name('log')->insert(['data'=>'汇付渠道商支付---'.json_encode($res)]);
  1216. Db::name('channel_order')->where('id',$oid) ->update(['hf_pay_id'=>$res['id']]);
  1217. return app('json')->success($res);
  1218. /////////////////////////////首信易/////////////////////////////////////////////////
  1219. if($payType == 'wx'){
  1220. Db::name('log')->insert(['data'=>'code---'.$code]);
  1221. if(!$code || $code == '' || $code =='undefined')
  1222. return app('json')->fail("授权失败,code为空");
  1223. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=".env('WECHAT_MP.APPID')."&secret=".env('WECHAT_MP.SECRET')."&js_code=".$code."&grant_type=authorization_code";
  1224. $get = curlGet($url);
  1225. Db::name('log')->insert(['data'=>'open_id---'.json_encode($get)]);
  1226. if(!isset($get['openid']) || empty($get['openid'])){
  1227. return app('json')->fail('授权失败');
  1228. }
  1229. $openid = $get['openid'];
  1230. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  1231. $datas['openId'] = $openid;
  1232. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  1233. Db::name('channel_order')->where('id',$oid)->update(['pay_type'=>'wx']);
  1234. }else{
  1235. Db::name('channel_order')->where('id',$oid)->update(['pay_type'=>'al']);
  1236. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  1237. }
  1238. $datas['requestId'] = $groupOrder['order_no']."_".rand(1000,9999);//订单号
  1239. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  1240. $datas['callbackUrl'] = 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg4NzQ4NDgzNQ==&scene=124&uin=&key=&devicetype=Windows+10+x64&version=6302019c&lang=zh_CN&a8scene=7&fontgear=2';//同步地址微信公众号
  1241. $product = '渠道商';
  1242. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  1243. $productDetails = array(
  1244. 'name' => $product ?? "渠道商",//商品名称。需传递真实产品名称。
  1245. 'quantity' => 1,//商品数量
  1246. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  1247. );
  1248. $datas['productDetails'] = [$productDetails];//商品信息
  1249. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  1250. $datas['notifyUrl']='/api/notify/pay_channel';
  1251. Db::name('log')->insert(['data'=>'请求数据--'.json_encode($datas)]);
  1252. $res = ShouxinyiApiRequest::onlinePay($datas);
  1253. $return = array(
  1254. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  1255. 'status' => $res['status'],
  1256. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  1257. 'appParams' => $res['appParams'] ?? '',//App调用码
  1258. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  1259. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  1260. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  1261. 'token' => $res['token'] ?? '', //微包支付调用token
  1262. );
  1263. return app('json')->success($return);
  1264. }catch (Exception $exception){
  1265. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  1266. return app('json')->fail("异常");
  1267. }
  1268. }
  1269. //退款
  1270. public function refund(){
  1271. $data['requestId'] = ShouxinyiApiRequest::getOrderNumber('refund'); //订单号
  1272. $data['orderId'] = '4bd333679fc94d61b88b7e758a71e8bc';//交易订单的流水号
  1273. $data['isCollect'] = '1';
  1274. $data['amount'] = 7900;//退款金额
  1275. $data['remark'] = '备注';
  1276. $refundCollectDetail = array(
  1277. 'collectAccType' => 'WAIT_ACC',//归集类型
  1278. 'collectAmount' => 7900,//归集金额
  1279. );
  1280. $data['refundCollectDetail'] = [$refundCollectDetail];//商品信息
  1281. $res = ShouxinyiApiRequest::refund($data);
  1282. return app('json')->success($res);
  1283. }
  1284. //客户端IP
  1285. public function getRealIP()
  1286. {
  1287. $forwarded = request()->header("x-forwarded-for");
  1288. if ($forwarded) {
  1289. $ip = explode(',', $forwarded)[0];
  1290. } else {
  1291. $ip = request()->ip();
  1292. }
  1293. return $ip;
  1294. }
  1295. //修改首信易商户银行信息
  1296. public function save_bank(){
  1297. $data['merchantId'] = '899104033';
  1298. $data['subMerchantId'] = '897401634';
  1299. $data['requestId'] = ShouxinyiApiRequest::getOrderNumber('modifyBankCard'); //订单号;
  1300. $data['bankCode'] = 'ICBC';
  1301. $data['bankBranchName'] = '中国工商银行股份有限公司北京万年花城支行';
  1302. $data['bankCardNo'] = '0200244909200054497';
  1303. $data['cityCode'] = '110100';
  1304. $data['provinceCode'] = '110000';
  1305. $save = ShouxinyiApiRequest::modifyBankCard($data);
  1306. dump($save);
  1307. }
  1308. //佣金处理
  1309. public function activation_yj($order_no)
  1310. {
  1311. $num=0.3;
  1312. $order_data=Db::name('activation_code_order')->where('order_no',$order_no)->where('status',1)->find();
  1313. // $order_data['pay_price']=6000;//测试养老金佣金改为6000
  1314. if(empty($order_data)){
  1315. return $num;
  1316. }
  1317. $eb_data=Db::name('entropy_barter_user_276')->where('uid',$order_data['uid'])->find();
  1318. $jifen=$order_data['pay_price'];
  1319. $uid=$order_data['uid'];
  1320. $bill=[
  1321. 'from_id'=>'0',
  1322. 'number'=>$jifen,
  1323. 'to_id'=>$eb_data['eb_id'],
  1324. 'type'=>'1',
  1325. 'order_no'=>$order_no,
  1326. 'remarks'=>'购买激活码得积分',
  1327. 'pm'=>1,
  1328. 'status'=>2,
  1329. 'on_line'=>1,
  1330. 'mer_id'=>276
  1331. ];
  1332. $this->eb_user_bill($bill);
  1333. Db::name('entropy_barter_user_276')->where('eb_id',$eb_data['eb_id'])->inc('integral',$jifen)->update();
  1334. $mer_id = 276;
  1335. $number = bcmul($order_data['pay_price'],'0.01',2);//养老金
  1336. $data=[
  1337. 'link_id' => $order_data['id'],
  1338. "uid"=>$uid,
  1339. "pm"=>1,
  1340. "title"=>'激活码养老金',
  1341. "category"=>"now_money",
  1342. "type"=>"commission",
  1343. "number"=>$number,
  1344. "balance"=>0,
  1345. "mark"=>'购买激活码获得'.$number.'元养老金',
  1346. "status"=>1,
  1347. "commission_type"=>5,
  1348. "order_sn"=>$order_data['order_no'],
  1349. "mer_id"=>$mer_id,
  1350. "source"=>0,
  1351. "type_shop"=>0,
  1352. 'gzc'=>0
  1353. ];
  1354. Db::name("user_bill")->insert($data);
  1355. Db::name("user")->where("uid",$uid)->inc('annuity', $number) ->update();
  1356. Db::name("user")->where("uid",$uid)->inc('annuity_num', 1) ->update();
  1357. //公证处入账
  1358. // $certification = UserCertification::getInstance()->where('uid', $order_data['uid'])->find();
  1359. // if($certification) {
  1360. // $user_data = Db::name('user')->where('uid', $uid)->find();
  1361. // $user_data['real_name']=Db::name('user_certification')->where('status',1)->where('uid',$user_data['uid'])->value('user_name');
  1362. // $user_data['account']=Db::name('user_certification')->where('status',1)->where('uid',$user_data['uid'])->value('mobile');
  1363. // $online = ['uid' => $uid, 'pay_type' => $order_data['pay_type'] == 'alpay' ? 4 : 1, 'order_sn' => $order_data['order_no'], 'order_id' => $order_data['id']];
  1364. // $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  1365. // $this->GZC($online, $certification, $number);
  1366. // }
  1367. //上级数据
  1368. $top_eb_data=Db::name('entropy_barter_user_276')->where('eb_id',$eb_data['top_eb_id'])->find();
  1369. $top_eb_id=$top_eb_data['eb_id']??0;
  1370. //上级上级数据
  1371. $top_top_eb_data=Db::name('entropy_barter_user_276')->where('eb_id',$top_eb_data['top_eb_id'])->find();
  1372. $top_top_eb_id=$top_top_eb_data['eb_id']??0;
  1373. //一级奖励
  1374. $one_yj=bcmul($order_data['pay_price'],'0.1',2);
  1375. if($top_eb_id==0){//为0 不执行直接返回
  1376. return $num;
  1377. }
  1378. if($top_eb_data['type']!=1) {
  1379. $bill = [
  1380. 'from_id' => '0',
  1381. 'number' => $one_yj,
  1382. 'to_id' => $top_eb_id,
  1383. 'type' => '2',
  1384. 'order_no' => $order_no,
  1385. 'remarks' => '易熵易物直推佣金',
  1386. 'pm' => 1,
  1387. 'status' => 2,
  1388. 'on_line' => 1,
  1389. 'mer_id' => 276
  1390. ];
  1391. $this->eb_user_bill($bill);
  1392. Db::name('entropy_barter_user_276')->where('eb_id', $top_eb_id)->inc('wallet', $one_yj)->update();
  1393. $num=$num - 0.1;
  1394. }
  1395. if($top_top_eb_id==0){//为0 不执行直接返回
  1396. return $num;
  1397. }
  1398. if($top_top_eb_data['type']!=1) {
  1399. if($top_top_eb_data['type']==2){
  1400. $bl=0.15;
  1401. }elseif ($top_top_eb_data['type']==3){
  1402. $bl=0.20;
  1403. }
  1404. //二级奖励
  1405. $two_yj=bcmul($order_data['pay_price'],$bl,2);
  1406. $bill = [
  1407. 'from_id' => '0',
  1408. 'number' => $two_yj,
  1409. 'to_id' => $top_top_eb_id,
  1410. 'type' => '1',
  1411. 'order_no' => $order_no,
  1412. 'remarks' => '易熵易物间推佣金',
  1413. 'pm' => 1,
  1414. 'status' => 2,
  1415. 'on_line' => 1,
  1416. 'mer_id' => 276
  1417. ];
  1418. $this->eb_user_bill($bill);
  1419. Db::name('entropy_barter_user_276')->where('eb_id', $top_top_eb_id)->inc('wallet', $two_yj)->update();
  1420. $num = $num-$bl;
  1421. }
  1422. //公证处入账
  1423. return $num;
  1424. }
  1425. public function GZC($online,$certification,$pension)
  1426. {
  1427. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1428. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1429. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1430. $create = [
  1431. 'uid' => $online['uid'],
  1432. 'platform_no' => $orderId,
  1433. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  1434. 'user_name' => $certification['user_name'],
  1435. 'mobile' => $certification['mobile'],
  1436. 'user_card' => $certification['user_card'],
  1437. 'pension' => $pension,
  1438. 'order_type' => 2,
  1439. 'out_trade_no' => $online['order_sn']
  1440. ];
  1441. $OrderGzcRepository->create($create);
  1442. }
  1443. //账单记录
  1444. public function eb_user_bill($bill)
  1445. {
  1446. $insert=[
  1447. 'from_id'=>$bill['from_id'],
  1448. 'number'=>$bill['number'],
  1449. 'to_id'=>$bill['to_id'],
  1450. 'type'=>$bill['type'],
  1451. 'order_no'=>$bill['order_no'],
  1452. 'remarks'=>$bill['remarks'],
  1453. 'pm'=>$bill['pm'],
  1454. 'ctime'=>time(),
  1455. 'on_line'=>$bill['on_line'],
  1456. 'status'=>$bill['status'],
  1457. 'pm2_msg'=>$bill['pm2_msg']??'',
  1458. 'mer_id'=>$bill['mer_id'],
  1459. 'commission_scale'=>$bill['commission_scale']??0,
  1460. 'commission_type'=>$bill['commission_type']??0,
  1461. 'to_user_type'=>$bill['to_user_type']??'',
  1462. 'to_user_type_1'=>$bill['to_user_type_1']??'',
  1463. ];
  1464. Db::name('log')->insert(['data'=>json_encode($insert)]);
  1465. Db::name('entropy_barter_bill')->insert($insert);
  1466. }
  1467. //分账
  1468. public function activation_spilet($order_no,$num)
  1469. {
  1470. Db::name('log')->insert(['data'=>'分账比例'.$num]);
  1471. $bili=0.33;
  1472. $bili=bcadd($bili,$num,2);
  1473. Db::name('log')->insert(['data'=>'分账比例'.$bili]);
  1474. $order_data=Db::name('activation_code_order')->where('order_no',$order_no)->where('status',1)->find();
  1475. if(empty($order_data)){
  1476. return '';
  1477. }
  1478. $goods_title=Db::name('merchant')->where('mer_id',276)->find();
  1479. $mer_price=bcmul($order_data['pay_price'],$bili,2);
  1480. $yongjin=bcmul($order_data['pay_price'],'0.37',2);
  1481. $shouxufei=bcmul($order_data['pay_price'],'0.006',3);
  1482. $yongjin=bcadd($yongjin,round($shouxufei,2));
  1483. $mer_price=bcsub($mer_price,round($shouxufei,2),2);
  1484. $payment_id = ShouxinyiApiRequest::getOrderNumber('split');
  1485. $div_members=[
  1486. [
  1487. 'member_id'=>$goods_title['hf_member_id_wx'],
  1488. 'amount'=>$mer_price,
  1489. 'fee_flag'=>'Y'
  1490. ],
  1491. [
  1492. 'member_id'=>0,
  1493. 'amount'=>$yongjin,
  1494. 'fee_flag'=>'N'
  1495. ]
  1496. ];
  1497. $params = [
  1498. 'payment_id'=>$order_data['hf_pay_id'],
  1499. 'order_no'=>$payment_id,
  1500. 'confirm_amt' => $order_data['pay_price'],
  1501. 'div_members'=>json_encode($div_members)
  1502. ];
  1503. $res = $this -> payment_confirm_create_traits($params);
  1504. Db::name("log")->insert(array('data'=>'汇付延时分账-----'.json_encode($res)));//日志记录
  1505. ////////////////////////////////首信易///////////////////////////////////////////
  1506. $sxy_submerchant_id=Db::name('Merchant')->where('mer_id',276)->value('sxy_submerchant_id');
  1507. $splitDetails = array(
  1508. array(
  1509. 'subSplitRequestId' => $data['requestId'] . '_1',
  1510. 'splitAccType' => 'MERCHANT_ACC',
  1511. 'splitAccId' => $sxy_submerchant_id,
  1512. 'splitAmount' => $mer_price
  1513. ),
  1514. array(
  1515. 'subSplitRequestId' => $data['requestId'] . '_2',
  1516. 'splitAccType' => 'MERCHANT_ACC',
  1517. 'splitAccId' => '895961180',
  1518. 'splitAmount' => $yongjin
  1519. )
  1520. );
  1521. $insertData=[
  1522. [
  1523. 'mid' => $order['mer_id']??0,
  1524. 'requestId' => $data['requestId'],
  1525. 'group_order_id' => $data['orderId'],
  1526. 'subSplitRequestId' => $data['requestId'].'_1',
  1527. 'splitAccId' => $sxy_submerchant_id,
  1528. 'splitAmount' => $splitDetails[0]['splitAmount'],
  1529. 'totalSplitAmount' => $data['totalSplitAmount'],
  1530. 'status' => 0
  1531. ],
  1532. [
  1533. 'mid' => $order['mer_id']??0,
  1534. 'requestId' => $data['requestId'],
  1535. 'group_order_id' => $data['orderId'],
  1536. 'subSplitRequestId' => $data['requestId'].'_2',
  1537. 'splitAccId' => 895961180,
  1538. 'splitAmount' => $splitDetails[1]['splitAmount'],
  1539. 'totalSplitAmount' => $data['totalSplitAmount'],
  1540. 'status' => 0
  1541. ]
  1542. ];
  1543. $data['splitDetails'] = $splitDetails;
  1544. Db::name("store_split_order") -> insertAll($insertData);
  1545. return ShouxinyiApiRequest::split($data);
  1546. }
  1547. //渠道商分佣
  1548. public function channel_fenyong($order_sn)
  1549. {
  1550. try{
  1551. $order_data=Db::name('channel_order')->where('order_no',$order_sn)->find();//订单数据
  1552. $channelrecommend=Db::name('channel_user')->where('uid',$order_data['uid'])->find();
  1553. //渠道商表中查无此人
  1554. if(!$channelrecommend){
  1555. return false;
  1556. }
  1557. $user_data=Db::name('user')->where('uid',$order_data['uid'])->find();//渠道商用户信息
  1558. $top_user_data=Db::name('user')->where('uid',$user_data['spread_uid'])->find();//用户的推荐人(邀请注册的人)
  1559. $top_uid = $top_user_data['uid'];
  1560. if($channelrecommend['recommend_uid'] != '' || $channelrecommend['recommend_uid'] != 0){
  1561. $top_uid=$channelrecommend['recommend_uid'];
  1562. }
  1563. //渠道商本人给养老金10%
  1564. $ylj=bcmul($order_data['pay_price'],'0.1',5);//10%的养老金
  1565. $ylj=round($ylj,2);
  1566. $top_yongjin = 0;//直接上级佣金
  1567. $top_top_yongjin = 0;//间接上级佣金
  1568. $title='养老金';
  1569. $mark = '成为渠道商获得' . $ylj . '养老金';
  1570. $billData=[
  1571. 'uid'=>$order_data['uid'],
  1572. 'link_id'=>$order_data['id'],
  1573. 'pm'=>1,
  1574. 'title'=>$title,
  1575. 'category'=>'now_money',
  1576. 'type'=>'commission',
  1577. 'number'=>$ylj,
  1578. 'balance'=>0,
  1579. 'mark'=>$mark,
  1580. 'create_time'=>date("Y-m-d H:i:s",time()),
  1581. 'status'=>1,
  1582. 'order_sn'=>$order_sn,
  1583. 'type_shop'=>0,
  1584. 'commission_type'=>5,
  1585. 'order_type'=>1,
  1586. 'gzc'=>0
  1587. ];
  1588. Db::name('user_bill')->insert($billData);
  1589. Db::name("user")->where("uid",$order_data['uid'])->inc('annuity', $ylj) ->update();
  1590. Db::name("user")->where("uid",$order_data['uid'])->inc('annuity_num', 1) ->update();
  1591. //如果存在上级
  1592. if($top_uid > 0){
  1593. //上级身份是否大仓会员
  1594. $is_da_cang_vip=Db::name('da_cang_user')->where('status',1)->where('uid',$top_uid)->find();
  1595. //上级身份是否商户
  1596. $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_uid)->find();
  1597. $is_shanghu2=Db::name('merchant')->where('uid',$top_uid)->find();
  1598. $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_uid)->find();
  1599. //渠道商
  1600. $is_channel = Db::name('channel_user') -> where('uid',$top_uid)->where('status',1)->find();
  1601. Db::name('log')->insert(['data'=>'会员状态'.json_encode($is_da_cang_vip)]);
  1602. Db::name('log')->insert(['data'=>'商户支付订单'.json_encode($is_shanghu1)]);
  1603. Db::name('log')->insert(['data'=>'商户'.json_encode($is_shanghu2)]);
  1604. Db::name('log')->insert(['data'=>'商户入驻表'.json_encode($is_shanghu3)]);
  1605. Db::name('log')->insert(['data'=>'渠道商'.json_encode($is_channel)]);
  1606. //如果是大仓会员
  1607. if($is_da_cang_vip){
  1608. //如果上级是金卡会员 20%佣金
  1609. if($is_da_cang_vip['type'] == 1){
  1610. $top_yongjin = bcmul($order_data['pay_price'], 0.12, 5);
  1611. }elseif ($is_da_cang_vip['type'] == 2){
  1612. //如果上级是银卡会员 15%佣金
  1613. $top_yongjin = bcmul($order_data['pay_price'], 0.1, 5);
  1614. }
  1615. }
  1616. //如果是商户 22%佣金
  1617. if($is_shanghu1||$is_shanghu2||$is_shanghu3){
  1618. $top_yongjin = bcmul($order_data['pay_price'], 0.15, 5);
  1619. }
  1620. //如果是渠道商 20% 佣金
  1621. if($is_channel){
  1622. $top_yongjin = bcmul($order_data['pay_price'], 0.20, 5);
  1623. }
  1624. $top_yongjin=round($top_yongjin,2);
  1625. if($top_yongjin > 0){
  1626. $title='佣金';
  1627. $mark = '邀请渠道商获得' . $top_yongjin . '招募奖励';
  1628. $billData=[
  1629. 'uid'=>$top_uid,
  1630. 'link_id'=>$order_data['id'],
  1631. 'pm'=>1,
  1632. 'title'=>$title,
  1633. 'category'=>'now_money',
  1634. 'type'=>'commission',
  1635. 'number'=>$top_yongjin,
  1636. 'balance'=>0,
  1637. 'mark'=>$mark,
  1638. 'create_time'=>date("Y-m-d H:i:s",time()),
  1639. 'status'=>1,
  1640. 'order_sn'=>$order_sn,
  1641. 'type_shop'=>0,
  1642. 'commission_type'=>9,
  1643. 'order_type'=>1
  1644. ];
  1645. Db::name('user_bill')->insert($billData);
  1646. Db::name('user')->where('uid',$top_uid)->inc('brokerage_price',$top_yongjin)->update();
  1647. }
  1648. }
  1649. //间接上级
  1650. $top_top_uid =Db::name('user')->where('uid',$top_uid)->value('spread_uid');//推荐人的推荐人(邀请注册的人)
  1651. $top_channelrecommend=Db::name('channel_user')->where('uid',$top_uid)->find();//推荐人的推荐人(渠道商推荐人)
  1652. if($top_channelrecommend && ($top_channelrecommend['recommend_uid'] != '' || $top_channelrecommend['recommend_uid'] != 0)){
  1653. $top_top_uid = $top_channelrecommend['recommend_uid'];
  1654. }
  1655. if($top_top_uid > 0){
  1656. //商户
  1657. $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_top_uid)->find();
  1658. $is_shanghu2=Db::name('merchant')->where('uid',$top_top_uid)->find();
  1659. $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_top_uid)->find();
  1660. //大仓会员
  1661. $is_da_cang_vip=Db::name('da_cang_user')->where('uid',$top_top_uid)->where('status',1)->find();
  1662. //渠道商
  1663. $is_channel = Db::name('channel_user') -> where('uid',$top_top_uid)->where('status',1)->find();
  1664. Db::name('log')->insert(['data'=>'会员状态'.json_encode($is_da_cang_vip)]);
  1665. Db::name('log')->insert(['data'=>'商户支付订单'.json_encode($is_shanghu1)]);
  1666. Db::name('log')->insert(['data'=>'商户'.json_encode($is_shanghu2)]);
  1667. Db::name('log')->insert(['data'=>'商户入驻表'.json_encode($is_shanghu3)]);
  1668. Db::name('log')->insert(['data'=>'渠道商'.json_encode($is_channel)]);
  1669. //如果是大仓会员
  1670. if($is_da_cang_vip){
  1671. //如果间接上级是金卡会员 8%佣金
  1672. if($is_da_cang_vip['type'] == 1){
  1673. $top_top_yongjin = bcmul($order_data['pay_price'], 0.08, 5);
  1674. }elseif ($is_da_cang_vip['type'] == 2){
  1675. //如果上级是银卡会员 5%佣金
  1676. $top_top_yongjin = bcmul($order_data['pay_price'], 0.05, 5);
  1677. }
  1678. }
  1679. //如果是商户 10%佣金
  1680. if($is_shanghu1||$is_shanghu2||$is_shanghu3){
  1681. $top_top_yongjin = bcmul($order_data['pay_price'], 0.1, 5);
  1682. }
  1683. //如果是渠道商 15% 佣金
  1684. if($is_channel){
  1685. $top_top_yongjin = bcmul($order_data['pay_price'], 0.15, 5);
  1686. }
  1687. $top_top_yongjin=round($top_top_yongjin,2);
  1688. $title='佣金';
  1689. $mark = '下级邀请渠道商获得' . $top_top_yongjin . '培育奖励';
  1690. $billData=[
  1691. 'uid'=>$top_top_uid,
  1692. 'link_id'=>$order_data['id'],
  1693. 'pm'=>1,
  1694. 'title'=>$title,
  1695. 'category'=>'now_money',
  1696. 'type'=>'commission',
  1697. 'number'=>$top_top_yongjin,
  1698. 'balance'=>0,
  1699. 'mark'=>$mark,
  1700. 'create_time'=>date("Y-m-d H:i:s",time()),
  1701. 'status'=>1,
  1702. 'order_sn'=>$order_sn,
  1703. 'type_shop'=>0,
  1704. 'commission_type'=>9,
  1705. 'order_type'=>1
  1706. ];
  1707. Db::name('user_bill')->insert($billData);
  1708. Db::name('user')->where('uid',$top_top_uid)->inc('brokerage_price',$top_top_yongjin)->update();
  1709. }
  1710. }catch (Exception $exception){
  1711. Db::name("log")->insert(array('data'=>'渠道商佣金error'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  1712. }
  1713. return true;
  1714. //2022年6月22号前版本
  1715. $order_data=Db::name('channel_order')->where('order_no',$order_sn)->find();//订单数据
  1716. $channelrecommend=Db::name('channel_user')->where('uid',$order_data['uid'])->find();
  1717. //渠道商表中查无此人
  1718. if(!$channelrecommend){
  1719. return false;
  1720. }
  1721. $user_data=Db::name('user')->where('uid',$order_data['uid'])->find();//渠道商用户信息
  1722. $top_user_data=Db::name('user')->where('uid',$user_data['spread_uid'])->find();//用户的推荐人(邀请注册的人)
  1723. $top_uid = $top_user_data['uid'];
  1724. if($channelrecommend['recommend_uid'] != '' || $channelrecommend['recommend_uid'] != 0){
  1725. $top_uid=$channelrecommend['recommend_uid'];
  1726. }
  1727. //渠道商本人给养老金5%
  1728. $ylj=bcmul($order_data['pay_price'],'0.05',5);//5%的养老金
  1729. $ylj=round($ylj,2);
  1730. $title='养老金';
  1731. $mark = '成为渠道商获得' . $ylj . '养老金';
  1732. $billData=[
  1733. 'uid'=>$order_data['uid'],
  1734. 'link_id'=>$order_data['id'],
  1735. 'pm'=>1,
  1736. 'title'=>$title,
  1737. 'category'=>'now_money',
  1738. 'type'=>'commission',
  1739. 'number'=>$ylj,
  1740. 'balance'=>0,
  1741. 'mark'=>$mark,
  1742. 'create_time'=>date("Y-m-d H:i:s",time()),
  1743. 'status'=>1,
  1744. 'order_sn'=>$order_sn,
  1745. 'type_shop'=>0,
  1746. 'commission_type'=>5,
  1747. 'order_type'=>1,
  1748. 'gzc'=>0
  1749. ];
  1750. Db::name('user_bill')->insert($billData);
  1751. Db::name("user")->where("uid",$order_data['uid'])->inc('annuity', $ylj) ->update();
  1752. Db::name("user")->where("uid",$order_data['uid'])->inc('annuity_num', 1) ->update();
  1753. //如果有直接上级,给佣金10%
  1754. if($top_uid > 0){
  1755. $price=bcmul($order_data['pay_price'],'0.1',5);//10%的推荐佣金
  1756. $price=round($price,2);
  1757. $title='佣金';
  1758. $mark = '邀请渠道商获得' . $price . '佣金';
  1759. $billData=[
  1760. 'uid'=>$top_uid,
  1761. 'link_id'=>$order_data['id'],
  1762. 'pm'=>1,
  1763. 'title'=>$title,
  1764. 'category'=>'now_money',
  1765. 'type'=>'commission',
  1766. 'number'=>$price,
  1767. 'balance'=>0,
  1768. 'mark'=>$mark,
  1769. 'create_time'=>date("Y-m-d H:i:s",time()),
  1770. 'status'=>1,
  1771. 'order_sn'=>$order_sn,
  1772. 'type_shop'=>0,
  1773. 'commission_type'=>9,
  1774. 'order_type'=>1
  1775. ];
  1776. Db::name('user_bill')->insert($billData);
  1777. Db::name('user')->where('uid',$top_uid)->inc('brokerage_price',$price)->update();
  1778. $top_top_uid =Db::name('user')->where('uid',$top_uid)->value('spread_uid');//推荐人的推荐人(邀请注册的人)
  1779. $top_channelrecommend=Db::name('channel_user')->where('uid',$top_uid)->find();//推荐人的推荐人(渠道商推荐人)
  1780. if($top_channelrecommend && ($top_channelrecommend['recommend_uid'] != '' || $top_channelrecommend['recommend_uid'] != 0)){
  1781. $top_top_uid = $top_channelrecommend['recommend_uid'];
  1782. }
  1783. //如果有间接上级,给佣金5%
  1784. if($top_top_uid > 0){
  1785. //大仓会员
  1786. $is_da_cang_vip=Db::name('da_cang_user')->where('status',1)->where('uid',$top_top_uid)->find();
  1787. //商户
  1788. $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_top_uid)->find();
  1789. $is_shanghu2=Db::name('merchant')->where('uid',$top_top_uid)->find();
  1790. $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_top_uid)->find();
  1791. //渠道商
  1792. $is_channel = Db::name('channel_user') -> where('uid',$top_top_uid)->where('status',1)->find();
  1793. //第二级 必需是会员或者商户 或者渠道商
  1794. if($is_da_cang_vip || $is_shanghu1 || $is_shanghu2 || $is_shanghu3 || $is_channel){
  1795. $price=bcmul($order_data['pay_price'],'0.05',5);//5%的推荐佣金
  1796. $price=round($price,2);
  1797. $title='佣金';
  1798. $mark = '下级邀请渠道商获得' . $price . '佣金';
  1799. $billData=[
  1800. 'uid'=>$top_top_uid,
  1801. 'link_id'=>$order_data['id'],
  1802. 'pm'=>1,
  1803. 'title'=>$title,
  1804. 'category'=>'now_money',
  1805. 'type'=>'commission',
  1806. 'number'=>$price,
  1807. 'balance'=>0,
  1808. 'mark'=>$mark,
  1809. 'create_time'=>date("Y-m-d H:i:s",time()),
  1810. 'status'=>1,
  1811. 'order_sn'=>$order_sn,
  1812. 'type_shop'=>0,
  1813. 'commission_type'=>9,
  1814. 'order_type'=>1
  1815. ];
  1816. Db::name('user_bill')->insert($billData);
  1817. Db::name('user')->where('uid',$top_top_uid)->inc('brokerage_price',$price)->update();
  1818. }
  1819. }
  1820. }
  1821. return true;
  1822. //以下为原逻辑。2022.05.30更改
  1823. //消费者上级奖励
  1824. if($top_user_data){//上级用户信息是否存在
  1825. $uid=$top_user_data['uid'];
  1826. $price=bcmul($order_data['pay_price'],'0.05',3);//5%的推荐佣金
  1827. $price=round($price,2);
  1828. $title='养老金';
  1829. $mark='下级成为渠道商获得'.$price.'养老金';
  1830. $billData=[
  1831. 'uid'=>$uid,
  1832. 'link_id'=>$order_data['id'],
  1833. 'pm'=>1,
  1834. 'title'=>$title,
  1835. 'category'=>'now_money',
  1836. 'type'=>'commission',
  1837. 'number'=>$price,
  1838. 'balance'=>0,
  1839. 'mark'=>$mark,
  1840. 'create_time'=>date("Y-m-d H:i:s",time()),
  1841. 'status'=>1,
  1842. 'order_sn'=>$order_sn,
  1843. 'type_shop'=>0,
  1844. 'commission_type'=>5,
  1845. 'order_type'=>1,
  1846. 'gzc'=>0
  1847. ];
  1848. Db::name('user_bill')->insert($billData);
  1849. Db::name("user")->where("uid",$uid)->inc('annuity', $price) ->update();
  1850. Db::name("user")->where("uid",$uid)->inc('annuity_num', 1) ->update();
  1851. }
  1852. //上级奖励
  1853. //备注同上
  1854. $channelrecommend=Db::name('channel_user')->where('uid',$order_data['uid'])->find();
  1855. if(!$channelrecommend){
  1856. return false;
  1857. }
  1858. $uid=$channelrecommend['recommend_uid'];
  1859. $price=bcmul($order_data['pay_price'],'0.1',3);
  1860. $price=round($price,2);
  1861. $mark = '邀请渠道商获得' . $price . '佣金';
  1862. $commission_type=9;
  1863. $is_implement=1;
  1864. if($uid==0){
  1865. $uid=$top_user_data['uid'];
  1866. $commission_type=3;
  1867. $is_implement=0;
  1868. }
  1869. $title='佣金';
  1870. $billData=[
  1871. 'uid'=>$uid,
  1872. 'link_id'=>$order_data['id'],
  1873. 'pm'=>1,
  1874. 'title'=>$title,
  1875. 'category'=>'now_money',
  1876. 'type'=>'commission',
  1877. 'number'=>$price,
  1878. 'balance'=>0,
  1879. 'mark'=>$mark,
  1880. 'create_time'=>date("Y-m-d H:i:s",time()),
  1881. 'status'=>1,
  1882. 'order_sn'=>$order_sn,
  1883. 'type_shop'=>0,
  1884. 'commission_type'=>$commission_type,
  1885. 'order_type'=>1
  1886. ];
  1887. Db::name('user_bill')->insert($billData);
  1888. Db::name('user')->where('uid',$uid)->inc('brokerage_price',$price)->update();
  1889. if($is_implement){
  1890. if($channelrecommend['recommend_uid']!=0){
  1891. $price=bcmul($order_data['pay_price'],'0.05',3);
  1892. $price=round($price,2);
  1893. $mark = '邀请渠道商获得' . $price . '佣金';
  1894. $title='佣金';
  1895. $tuijian=Db::name('channel_user')->where('uid',Db::name('channel_user')->where('uid',$channelrecommend['recommend_uid'])->value('recommend_uid'))->find();
  1896. if($tuijian){
  1897. $billData=[
  1898. 'uid'=>$tuijian['uid'],
  1899. 'link_id'=>$order_data['id'],
  1900. 'pm'=>1,
  1901. 'title'=>$title,
  1902. 'category'=>'now_money',
  1903. 'type'=>'commission',
  1904. 'number'=>$price,
  1905. 'balance'=>0,
  1906. 'mark'=>$mark,
  1907. 'create_time'=>date("Y-m-d H:i:s",time()),
  1908. 'status'=>1,
  1909. 'order_sn'=>$order_sn,
  1910. 'type_shop'=>0,
  1911. 'commission_type'=>9,
  1912. 'order_type'=>1
  1913. ];
  1914. Db::name('user_bill')->insert($billData);
  1915. Db::name('user')->where('uid',$tuijian['uid'])->inc('brokerage_price',$price)->update();
  1916. }
  1917. }
  1918. }
  1919. }
  1920. //渠道商分账
  1921. public function channel_spilet($order_no)
  1922. {
  1923. $order_data=Db::name('channel_order')->where('order_no',$order_no)->where('status',1)->find();
  1924. if(empty($order_data)){
  1925. return '';
  1926. }
  1927. $data['requestId'] = ShouxinyiApiRequest::getOrderNumber('split');
  1928. $data['orderId'] = $order_no.'_'.$order_data['rand'];
  1929. $data['totalSplitAmount'] = bcmul($order_data['pay_price'],'100');
  1930. $monent=bcmul($order_data['pay_price'],'100');
  1931. $splitDetails = array(
  1932. array(
  1933. 'subSplitRequestId' => $data['requestId'] . '_1',
  1934. 'splitAccType' => 'MERCHANT_ACC',
  1935. 'splitAccId' => '895152791',
  1936. 'splitAmount' => $monent
  1937. )
  1938. );
  1939. $insertData=[
  1940. [
  1941. 'mid' => $order['mer_id']??0,
  1942. 'requestId' => $data['requestId'],
  1943. 'group_order_id' => $data['orderId'],
  1944. 'subSplitRequestId' => $data['requestId'].'_1',
  1945. 'splitAccId' => '895152791',
  1946. 'splitAmount' => $splitDetails[0]['splitAmount'],
  1947. 'totalSplitAmount' => $data['totalSplitAmount'],
  1948. 'status' => 0
  1949. ]
  1950. ];
  1951. $data['splitDetails'] = $splitDetails;
  1952. Db::name("store_split_order") -> insertAll($insertData);
  1953. return ShouxinyiApiRequest::split($data);
  1954. }
  1955. public function marketing_spilet($order_id){
  1956. }
  1957. public function pay_huifu($payType,$code,$groupOrder,$title,$notify_url,$pay_mode=null,$appid=''){
  1958. $order_no = $groupOrder['group_order_sn'] ?? $groupOrder['order_no'];
  1959. if($payType == 'wx'){
  1960. if(!$code || $code == '' || $code =='undefined')
  1961. return "授权失败,code为空";
  1962. if($appid == '') {
  1963. $pay_wx = systemConfig('pay_wx');
  1964. if ($pay_wx == 2){
  1965. $appid = env('WECHAT_MP.APPID');
  1966. $new_secret = env('WECHAT_MP.SECRET');
  1967. $app_id='app_0827b960-b932-45ec-b800-4e850091b419';
  1968. $key='api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  1969. }elseif ($pay_wx == 3){
  1970. $appid = env('WECHAT_TDYL.APPID');
  1971. $new_secret = env('WECHAT_TDYL.SECRET');
  1972. Db::name('log')->insert(['data'=>'appid---'.$appid]);
  1973. Db::name('log')->insert(['data'=>'new_secret---'.$new_secret]);
  1974. $app_id='app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  1975. $key='api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  1976. }
  1977. }else{
  1978. $app_id='app_0827b960-b932-45ec-b800-4e850091b419';
  1979. $key='api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  1980. $new_secret = "c8cbe24fa3b83f77a88b79554b3aeab4";
  1981. }
  1982. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$new_secret."&js_code=".$code."&grant_type=authorization_code";
  1983. $get = curlGet($url);
  1984. Db::name('log')->insert(['data'=>'pay_wx---'.$pay_wx]);
  1985. Db::name('log')->insert(['data'=>'code---'.$code]);
  1986. Db::name('log')->insert(['data'=>'url---'.$url]);
  1987. Db::name('log')->insert(['data'=>'open_id---'.json_encode($get)]);
  1988. if(!isset($get['openid']) || empty($get['openid'])){
  1989. return '授权失败';
  1990. }
  1991. $openid = $get['openid'];
  1992. $member_id=0;
  1993. $type='2';
  1994. $pay_channel='wx_lite';
  1995. $expend=[
  1996. 'open_id'=>$openid,
  1997. 'wx_app_id'=> $appid
  1998. ];
  1999. if ($groupOrder['order_type'] = "marketing"){
  2000. // 创富宝 分账
  2001. //创富宝
  2002. $cfb = sprintf("%01.2f",round(bcmul($groupOrder['pay_price'],'0.094',5),2));//9.4%的分账
  2003. $cfb_member = "jsdk_member_1680162243019";
  2004. // 平台
  2005. $cxb = sprintf("%01.2f",round(bcsub($groupOrder['pay_price'],$cfb,5),2));//剩下的归平台
  2006. $div_members=[
  2007. [
  2008. 'member_id'=>$member_id,
  2009. 'amount'=>$cxb,
  2010. 'fee_flag'=>'Y'
  2011. ],
  2012. [
  2013. 'member_id'=>$cfb_member,
  2014. 'amount'=>$cfb,
  2015. 'fee_flag'=>'N'
  2016. ]
  2017. ];
  2018. }else{
  2019. $div_members=[
  2020. [
  2021. 'member_id'=>$member_id,
  2022. 'amount'=>$groupOrder['pay_price'],
  2023. 'fee_flag'=>'Y'
  2024. ]
  2025. ];
  2026. }
  2027. $params=[
  2028. 'order_no'=>$order_no."_".rand(1000,9999),
  2029. 'app_id'=>$app_id,
  2030. 'pay_channel'=>$pay_channel,
  2031. 'pay_amt'=>(string)$groupOrder['pay_price'],
  2032. 'goods_title'=> strlen($title) > 64 ? mb_substr($title, 0, 64,'utf-8') : $title,// 解决因为太长不能支付问题
  2033. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127,'utf-8') : $title,// 解决因为太长不能支付问题
  2034. 'device_info'=>[
  2035. 'device_ip'=>app('request')->ip()
  2036. // 'device_ip'=>'115.171.134.68'
  2037. ],
  2038. 'expend'=>json_encode($expend),
  2039. 'div_members'=>json_encode($div_members),
  2040. 'fee_mode'=>'I',
  2041. 'notify_url'=>$notify_url
  2042. ];
  2043. if($pay_mode == 'delay'){
  2044. $params['pay_mode'] = 'delay';
  2045. unset($params['div_members']);
  2046. unset($params['fee_mode']);
  2047. }
  2048. return $this->Payment_create_traits_b($params,$type,$key);
  2049. }elseif($payType=='ALI'){
  2050. // throw new AuthException('支付宝正在升级,请使用微信支付');
  2051. $member_id=0;
  2052. $type='1';
  2053. $pay_channel='alipay_qr';
  2054. // 天地博爱科技通道
  2055. $app_id='app_44108546-d27a-48ee-88c1-84b45b75114f';
  2056. $key='api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  2057. // 天地博爱通道
  2058. // $app_id='app_0827b960-b932-45ec-b800-4e850091b419';
  2059. // $key='api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  2060. $div_members=[
  2061. [
  2062. 'member_id'=>$member_id,
  2063. 'amount'=>$groupOrder['pay_price'],
  2064. 'fee_flag'=>'Y'
  2065. ]
  2066. ];
  2067. $params=[
  2068. 'order_no'=>$order_no."_".rand(1000,9999),
  2069. 'app_id'=>$app_id,
  2070. 'pay_channel'=>$pay_channel,
  2071. 'pay_amt'=>(string)$groupOrder['pay_price'],
  2072. 'goods_title'=> strlen($title) > 64 ? mb_substr($title, 0, 64,'utf-8') : $title,// 解决因为太长不能支付问题
  2073. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127,'utf-8') : $title,// 解决因为太长不能支付问题
  2074. 'device_info'=>[
  2075. 'device_ip'=>app('request')->ip()
  2076. // 'device_ip'=>'115.171.134.68'
  2077. ],
  2078. // 'expend'=>json_encode($expend),
  2079. 'div_members'=>json_encode($div_members),
  2080. 'fee_mode'=>'I',
  2081. 'notify_url'=>$notify_url
  2082. ];
  2083. if($pay_mode == 'delay'){
  2084. $params['pay_mode'] = 'delay';
  2085. unset($params['div_members']);
  2086. unset($params['fee_mode']);
  2087. }
  2088. return $this->Payment_create_traits_a($params,$type,$key);
  2089. }
  2090. }
  2091. }