Access.php 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289
  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. if($vr_pri < 0){
  723. return app('json')->fail('VR不足,请重试!');
  724. }
  725. }
  726. //b2 精彩生活区的现金+积分支付
  727. if($array_fzone_paytype['type'] == 'b2'){
  728. //查询用户的积分是否足够
  729. $score_pri = $userdata['score'] - $array_fzone_paytype['other'];
  730. if($score_pri < 0){
  731. return app('json')->fail('积分不足,请重试!');
  732. }
  733. }
  734. }else{
  735. return app('json')->fail('数据异常,请重新下单,并选择支付方式!');
  736. }
  737. try {
  738. log::info("微信小程序回调");
  739. Db::name('log')->insert(['data'=>'汇付订单支付pay_wechat_mp-66666666---发起支付']);
  740. $oid = Request::param('oid','');
  741. $code = Request::param('code','');
  742. $type = Request::param('type','');
  743. $pay_open_id = Request::param('pay_open_id','');
  744. if($oid == '')
  745. return app('json')->fail("请检查参数是否正确");
  746. $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  747. if (!$groupOrder)
  748. return app('json')->fail('订单不存在或已支付');
  749. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  750. if($cart){
  751. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  752. $cart = explode(",",$cart);
  753. $cart_id = $cart[0];
  754. $product = Db::name("store_product")
  755. ->alias('sp')
  756. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  757. ->where(["sc.cart_id"=>$cart_id])
  758. ->value('sp.store_name');
  759. }
  760. $res = $this -> pay_huifu($type,$code,$groupOrder,$product ?? "储蓄保",env('APP_URL')."/api/hf_notify/pay",'delay');
  761. Db::name('log')->insert(['data'=>'汇付订单支付--- 返回参数'.json_encode($res)]);
  762. if (isset($res['id'])) {
  763. Db::name('store_group_order')->where('group_order_id', $oid)->update(['hf_pay_id' => $res['id'],'pay_wx'=>systemConfig('pay_wx')]);
  764. if($pay_open_id)
  765. Db::name('store_order')->where('group_order_id', $oid)->update(['pay_open_id' => $pay_open_id]);
  766. return app('json')->success($res);
  767. }
  768. return app('json')->fail($res);
  769. //////////////////////////////////////////////首信易/////////////////////////////////////////////////////////
  770. if($type == 'wx'){
  771. if(!$code || $code == '' || $code =='undefined')
  772. return app('json')->fail("授权失败,code为空");
  773. $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";
  774. $get = curlGet($url);
  775. if(!isset($get['openid']) || empty($get['openid'])){
  776. return app('json')->fail('授权失败');
  777. }
  778. $openid = $get['openid'];
  779. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  780. $datas['openId'] = $openid;
  781. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  782. }else{
  783. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  784. }
  785. $datas['requestId'] = $groupOrder['group_order_sn']."_".rand(1000,9999);//订单号
  786. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  787. $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';//同步地址微信公众号
  788. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  789. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  790. $cart = explode(",",$cart);
  791. $cart_id = $cart[0];
  792. $product = Db::name("store_product")
  793. ->alias('sp')
  794. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  795. ->where(["sc.cart_id"=>$cart_id])
  796. ->value('sp.store_name');
  797. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  798. $productDetails = array(
  799. 'name' => $product ?? "储蓄保",//商品名称。需传递真实产品名称。
  800. 'quantity' => 1,//商品数量
  801. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  802. );
  803. $datas['productDetails'] = [$productDetails];//商品信息
  804. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  805. $datas['notifyUrl']='/api/notify/pay_5upay';
  806. $res = ShouxinyiApiRequest::onlinePay($datas);
  807. $return = array(
  808. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  809. 'status' => $res['status'],
  810. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  811. 'appParams' => $res['appParams'] ?? '',//App调用码
  812. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  813. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  814. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  815. 'token' => $res['token'] ?? '', //微包支付调用token
  816. );
  817. Db::name("log")->insert(array('data'=>'支付回调---'.json_encode($return)));//日志记录
  818. return app('json')->success($return);
  819. }catch (Exception $exception){
  820. log::info("支付异常======");
  821. log::info($exception);
  822. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  823. return app('json')->fail("异常");
  824. }
  825. }
  826. //小程序支付
  827. public function pay_wechat_mp_copy(StoreGroupOrderRepository $groupOrderRepository){
  828. try {
  829. Db::name('log')->insert(['data'=>'汇付订单支付pay_wechat_mp6666666---发起支付']);
  830. $oid = Request::param('oid','');
  831. $code = Request::param('code','');
  832. $type = Request::param('type','');
  833. $pay_open_id = Request::param('pay_open_id','');
  834. if($oid == '')
  835. return app('json')->fail("请检查参数是否正确");
  836. $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  837. if (!$groupOrder)
  838. return app('json')->fail('订单不存在或已支付');
  839. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  840. if($cart){
  841. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  842. $cart = explode(",",$cart);
  843. $cart_id = $cart[0];
  844. $product = Db::name("store_product")
  845. ->alias('sp')
  846. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  847. ->where(["sc.cart_id"=>$cart_id])
  848. ->value('sp.store_name');
  849. }
  850. $res = $this -> pay_huifu($type,$code,$groupOrder,$product ?? "储蓄保",env('APP_URL')."/api/hf_notify/pay",'delay');
  851. Db::name('log')->insert(['data'=>'汇付订单支付--- 返回参数'.json_encode($res)]);
  852. if (isset($res['id'])) {
  853. Db::name('store_group_order')->where('group_order_id', $oid)->update(['hf_pay_id' => $res['id'],'pay_wx'=>systemConfig('pay_wx')]);
  854. if($pay_open_id)
  855. Db::name('store_order')->where('group_order_id', $oid)->update(['pay_open_id' => $pay_open_id]);
  856. return app('json')->success($res);
  857. }
  858. return app('json')->fail($res);
  859. //////////////////////////////////////////////首信易/////////////////////////////////////////////////////////
  860. if($type == 'wx'){
  861. if(!$code || $code == '' || $code =='undefined')
  862. return app('json')->fail("授权失败,code为空");
  863. $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";
  864. $get = curlGet($url);
  865. if(!isset($get['openid']) || empty($get['openid'])){
  866. return app('json')->fail('授权失败');
  867. }
  868. $openid = $get['openid'];
  869. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  870. $datas['openId'] = $openid;
  871. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  872. }else{
  873. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  874. }
  875. $datas['requestId'] = $groupOrder['group_order_sn']."_".rand(1000,9999);//订单号
  876. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  877. $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';//同步地址微信公众号
  878. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  879. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  880. $cart = explode(",",$cart);
  881. $cart_id = $cart[0];
  882. $product = Db::name("store_product")
  883. ->alias('sp')
  884. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  885. ->where(["sc.cart_id"=>$cart_id])
  886. ->value('sp.store_name');
  887. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  888. $productDetails = array(
  889. 'name' => $product ?? "储蓄保",//商品名称。需传递真实产品名称。
  890. 'quantity' => 1,//商品数量
  891. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  892. );
  893. $datas['productDetails'] = [$productDetails];//商品信息
  894. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  895. $datas['notifyUrl']='/api/notify/pay_5upay';
  896. $res = ShouxinyiApiRequest::onlinePay($datas);
  897. $return = array(
  898. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  899. 'status' => $res['status'],
  900. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  901. 'appParams' => $res['appParams'] ?? '',//App调用码
  902. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  903. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  904. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  905. 'token' => $res['token'] ?? '', //微包支付调用token
  906. );
  907. return app('json')->success($return);
  908. }catch (Exception $exception){
  909. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  910. return app('json')->fail("异常");
  911. }
  912. }
  913. public function pay_demo(StoreGroupOrderRepository $groupOrderRepository){
  914. Db::name("log")->insert(array('data'=>'测试支付---1'));//日志记录
  915. $oid = Request::param('oid','');
  916. $type = Request::param('type','');
  917. $code = Request::param('code','');
  918. if($oid == '')
  919. return app('json')->fail("请检查参数是否正确");
  920. $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  921. if (!$groupOrder)
  922. return app('json')->fail('订单不存在或已支付');
  923. $goods_title=Db::name('merchant')->where('mer_id',$groupOrder['mer_id'])->find();
  924. $cart = Db::name("store_order")->where(['group_order_id'=>$oid]) -> value("cart_id");//日志记录
  925. Db::name("log")->insert(array('data'=>'测试支付---购物车---'.json_encode($cart)));//日志记录
  926. $cart = explode(",",$cart);
  927. $cart_id = $cart[0];
  928. $product = Db::name("store_product")
  929. ->alias('sp')
  930. ->join('store_cart sc', 'sp.product_id = sc.product_id')
  931. ->where(["sc.cart_id"=>$cart_id])
  932. ->value('sp.store_name');
  933. if($type=='WX'){
  934. if(!$code || $code == '' || $code =='undefined')
  935. return app('json')->fail("授权失败,code为空");
  936. $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";
  937. $get = curlGet($url);
  938. if(!isset($get['openid']) || empty($get['openid'])){
  939. return app('json')->fail('授权失败');
  940. }
  941. $openid = $get['openid'];
  942. $member_id=$goods_title['hf_member_id_wx'];
  943. $app_id='app_0827b960-b932-45ec-b800-4e850091b419';
  944. $type='2';
  945. $pay_channel='wx_lite';
  946. $key='api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  947. $expend=[
  948. 'open_id'=>$openid
  949. ];
  950. $params=[
  951. 'order_no'=>$groupOrder['group_order_sn']."_".rand(1000,9999),//订单号
  952. 'app_id'=>$app_id,
  953. 'pay_channel'=>$pay_channel,
  954. 'pay_amt'=>strval($groupOrder['pay_price']),//金额。,
  955. 'goods_title'=>$product ?? "储蓄保",
  956. 'goods_desc'=>$product ?? "储蓄保",
  957. 'device_info'=>[
  958. 'device_ip'=>app('request')->ip()
  959. // 'device_ip'=>'115.171.134.68'
  960. ],
  961. 'expend'=>json_encode($expend),
  962. 'fee_mode'=>'I',
  963. 'notify_url'=>env('APP_URL')."/api/jsapiPay/notify/HF_demo"
  964. ];
  965. }elseif($type=='ALI'){
  966. if(!$code || $code == '' || $code =='undefined')
  967. return app('json')->fail("授权失败,code为空");
  968. $res = $this -> getAliUserId($code);
  969. return app('json')->success($res);
  970. $buyer_id = Request::param('buyer_id','');
  971. $member_id=$goods_title['hf_member_id'];
  972. $app_id='app_44108546-d27a-48ee-88c1-84b45b75114f';
  973. $type='1';
  974. $pay_channel='alipay_pub';
  975. $expend=[
  976. 'buyer_id'=>$buyer_id
  977. ];
  978. $key='api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  979. $params=[
  980. 'order_no'=>$groupOrder['group_order_sn']."_".rand(1000,9999),//订单号
  981. 'app_id'=>$app_id,
  982. 'pay_channel'=>$pay_channel,
  983. 'pay_amt'=>strval($groupOrder['pay_price']),//金额。,
  984. 'goods_title'=>$product ?? "储蓄保",
  985. 'goods_desc'=>$product ?? "储蓄保",
  986. 'device_info'=>[
  987. 'device_ip'=>app('request')->ip()
  988. // 'device_ip'=>'115.171.134.68'
  989. ],
  990. 'expend'=>json_encode($expend),
  991. 'fee_mode'=>'I',
  992. 'notify_url'=>env('APP_URL')."/api/jsapiPay/notify/HF_demo"
  993. ];
  994. }
  995. $res=$this->Payment_create_traits($params,$type,$key);
  996. $res['code']='1000';
  997. $res['return_code']='999';
  998. if(!empty($res['error_code'])){
  999. $res['code']='1000';
  1000. $res['return_msg']=$res['error_msg'];
  1001. $res['return_code']=1200;
  1002. }
  1003. return app('json')->success($res);
  1004. }
  1005. public function getAliUserId($code){
  1006. $aop = new AopClient();
  1007. $url = "https://openapi.alipay.com/gateway.do";
  1008. // $app_id="2021002194632049";
  1009. // $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=";
  1010. // $aop->alipayrsaPublicKey='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuUb+0sJSNXjWiG0VJIPzn55+18af/fubYMpRLlreu34ewMgLx1zpCNpB3wrA+dylfWPMAm8PzvKnakByB+VJ/LMNhWHmF8Qkdo4astAikjlI4TMQCK/G384NzrtjHR4DGCDM5CMVt1xw5noF7kNBMYIvgDfhMCYmygdlIjuVdIlVEoQKOsT0RaNMleES0aZvbjvBGkGM0dsetqUExSjid9BF1NAO2ET+J3XMxCtMgCUVmFUvxsCKe6Rapa1/Lk3rzIeG6CRpoabuYfPM9E+3y3f3luSOMXLfH9lOSW1RA8qrF+Ms1RZv8gmzUnbyrPLmmZPmmN/Qs6DGzDVg73fpSwIDAQAB';
  1011. $app_id = '2021001197698727';
  1012. $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=';
  1013. $aop->alipayrsaPublicKey='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArHwMZtNYBkK5q2jQ0Ml18H8MhQX9Bpuz/ignvuJC47K7LHY+F6/U/+o/nYeDhqHzUajMAAyM06N3r2qBnWQRjC4JKFMO4i5xIDVycuumzcsWz3LwAkHOFG/S1pGXFWh74zdQDNednhvnNOiTDwjefZRnf5HUqEZK/7tRSaZvzSUIAwHG2zj0C6AYkhg5wr6ZJxgRDjPjqbs6ZMqLT+pITsnCcc6IgIisZbPTdtw1U2FKmQm5n228drI3XKYbE3UVT2y6R0mZNmqmiHDszmYSKOjDrpgtMExWpee8kUFn7J800HIyYtq0nRv1ypdWngUZtkm+szVWOTDGgN4eHQW3FwIDAQAB';
  1014. $aop->gatewayUrl = $url;
  1015. $aop->appId = $app_id;
  1016. $aop->rsaPrivateKey = $privateKey;
  1017. $aop->apiVersion = '1.0';
  1018. $aop->signType = 'RSA2';
  1019. $aop->postCharset='GBK';
  1020. $aop->format='json';
  1021. $request = new AlipaySystemOauthTokenRequest ();
  1022. $request->setGrantType("authorization_code");
  1023. $request->setCode($code);
  1024. // $request->setRefreshToken("201208134b203fe6c11548bcabd8da5bb087a83b");
  1025. $result = $aop->execute ( $request);
  1026. $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  1027. $resultCode = $result->$responseNode->code;
  1028. if(!empty($resultCode)&&$resultCode == 10000){
  1029. return $result;
  1030. } else {
  1031. return false;
  1032. }
  1033. }
  1034. /**
  1035. * @remarks 小程序支付年费
  1036. * @author Tang
  1037. * @created 2021/8/27 9:18
  1038. */
  1039. public function pay_annual_cost(){
  1040. try {
  1041. $oid = Request::param('oid','');
  1042. $code = Request::param('code','');
  1043. $payType = Request::param('type','');
  1044. $appid = Request::param('appid','');
  1045. if($oid == '')
  1046. return app('json')->fail("请检查参数是否正确");
  1047. // $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  1048. $groupOrder=Db::name('merchant_annual_cost_order')->where('id',$oid)->where('status',0)->find();
  1049. if (!$groupOrder)
  1050. return app('json')->fail('订单不存在或已支付');
  1051. Db::name('log')->insert(['data'=>'汇付商户支付---groupOrder'.json_encode($groupOrder)]);
  1052. $res = $this -> pay_huifu($payType,$code,$groupOrder,'商户',env('APP_URL')."/api/hf_notify/pay_annual",null,$appid);
  1053. // Db::name('log')->insert(['data'=>'汇付商户支付---'.json_encode($res)]);
  1054. Db::name('merchant_annual_cost_order')->where('id',$oid) ->update(['hf_pay_id'=>$res['id']]);
  1055. return app('json')->success($res);
  1056. ///////////////////////////////年费/////////////////////////////////////////////
  1057. if($payType == 'wx'){
  1058. if(!$code || $code == '' || $code =='undefined')
  1059. return app('json')->fail("授权失败,code为空");
  1060. $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";
  1061. $get = curlGet($url);
  1062. if(!isset($get['openid']) || empty($get['openid'])){
  1063. return app('json')->fail('授权失败');
  1064. }
  1065. $openid = $get['openid'];
  1066. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  1067. $datas['openId'] = $openid;
  1068. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  1069. Db::name('merchant_annual_cost_order')->where('id',$oid)->update(['pay_type'=>'wx']);
  1070. }else{
  1071. Db::name('merchant_annual_cost_order')->where('id',$oid)->update(['pay_type'=>'al']);
  1072. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  1073. }
  1074. $datas['requestId'] = $groupOrder['order_no']."_".rand(1000,9999);//订单号
  1075. $datas['splitMark'] = 'NOT_DO_SPLIT';//不分账
  1076. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  1077. $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';//同步地址微信公众号
  1078. $cart = Db::name('merchant_annual_cost_order')->where('id',$oid)->where('status',0)-> value("id");//日志记录
  1079. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  1080. $product = '商家年费';
  1081. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  1082. $productDetails = array(
  1083. 'name' => $product ?? "储蓄保年费",//商品名称。需传递真实产品名称。
  1084. 'quantity' => 1,//商品数量
  1085. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  1086. );
  1087. $datas['productDetails'] = [$productDetails];//商品信息
  1088. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  1089. $datas['notifyUrl']='/api/notify/pay_annual';
  1090. $res = ShouxinyiApiRequest::onlinePay($datas);
  1091. $return = array(
  1092. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  1093. 'status' => $res['status'],
  1094. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  1095. 'appParams' => $res['appParams'] ?? '',//App调用码
  1096. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  1097. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  1098. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  1099. 'token' => $res['token'] ?? '', //微包支付调用token
  1100. );
  1101. return app('json')->success($return);
  1102. }catch (Exception $exception){
  1103. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  1104. return app('json')->fail("异常");
  1105. }
  1106. }
  1107. /**
  1108. * @remarks 小程序支付激活码
  1109. * @author Tang
  1110. * @created 2021/8/27 9:18
  1111. */
  1112. public function pay_activation_code(){
  1113. try {
  1114. $oid = Request::param('oid','');
  1115. $code = Request::param('code','');
  1116. $payType = Request::param('type','');
  1117. if($oid == '')
  1118. return app('json')->fail("请检查参数是否正确");
  1119. // $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  1120. $groupOrder=Db::name('activation_code_order')->where('id',$oid)->where('status',0)->find();
  1121. // $group_type=Db::name('activation_code_order')->where('id',$oid)->where('status',0)->update(['pay_type'=>$type]);
  1122. if (!$groupOrder)
  1123. return app('json')->fail('订单不存在或已支付');
  1124. $res = $this -> pay_huifu($payType,$code,$groupOrder,"商户激活码",env('APP_URL')."/api/hf_notify/pay_activation",'delay');
  1125. Db::name('log')->insert(['data'=>'汇付激活码支付---'.json_encode($res)]);
  1126. Db::name('activation_code_order')->where('group_order_id',$oid) ->update(['hf_pay_id'=>$res['id']]);
  1127. return app('json')->success($res);
  1128. //////////////////////////////////////首信易/////////////////////////////////////////////
  1129. if($payType == 'wx'){
  1130. Db::name('log')->insert(['data'=>'code---'.$code]);
  1131. if(!$code || $code == '' || $code =='undefined')
  1132. return app('json')->fail("授权失败,code为空");
  1133. $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";
  1134. $get = curlGet($url);
  1135. Db::name('log')->insert(['data'=>'open_id---'.json_encode($get)]);
  1136. if(!isset($get['openid']) || empty($get['openid'])){
  1137. return app('json')->fail('授权失败');
  1138. }
  1139. $openid = $get['openid'];
  1140. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  1141. $datas['openId'] = $openid;
  1142. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  1143. Db::name('activation_code_order')->where('id',$oid)->update(['pay_type'=>'al']);
  1144. }else{
  1145. Db::name('activation_code_order')->where('id',$oid)->update(['pay_type'=>'al']);
  1146. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  1147. }
  1148. $datas['requestId'] = $groupOrder['order_no']."_".rand(1000,9999);//订单号
  1149. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  1150. $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';//同步地址微信公众号
  1151. $cart = Db::name('activation_code_order')->where('id',$oid)->where('status',0)-> value("id");//日志记录
  1152. Db::name("log")->insert(array('data'=>json_encode($cart)));//日志记录
  1153. $product = '商家激活码';
  1154. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  1155. $productDetails = array(
  1156. 'name' => $product ?? "激活码",//商品名称。需传递真实产品名称。
  1157. 'quantity' => 1,//商品数量
  1158. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  1159. );
  1160. $datas['productDetails'] = [$productDetails];//商品信息
  1161. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  1162. $datas['notifyUrl']='/api/notify/pay_activation';
  1163. Db::name('log')->insert(['data'=>'请求数据--'.json_encode($datas)]);
  1164. $res = ShouxinyiApiRequest::onlinePay($datas);
  1165. $return = array(
  1166. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  1167. 'status' => $res['status'],
  1168. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  1169. 'appParams' => $res['appParams'] ?? '',//App调用码
  1170. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  1171. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  1172. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  1173. 'token' => $res['token'] ?? '', //微包支付调用token
  1174. );
  1175. return app('json')->success($return);
  1176. }catch (Exception $exception){
  1177. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  1178. return app('json')->fail("异常");
  1179. }
  1180. }
  1181. /**
  1182. * @remarks 小程序支付渠道商
  1183. * @author Tang
  1184. * @created 2021/8/27 9:18
  1185. */
  1186. public function pay_channel(){
  1187. try {
  1188. $oid = Request::param('oid','');
  1189. $code = Request::param('code','');
  1190. $payType = Request::param('type','');
  1191. if($oid == '')
  1192. return app('json')->fail("请检查参数是否正确");
  1193. // $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
  1194. $groupOrder=Db::name('channel_order')->where('id',$oid)->where('status',0)->find();
  1195. // $group_type=Db::name('channel_order')->where('id',$oid)->where('status',0)->update(['pay_type'=>$type]);
  1196. if (!$groupOrder)
  1197. return app('json')->fail('订单不存在或已支付');
  1198. $res = $this -> pay_huifu($payType,$code,$groupOrder,'渠道商',env('APP_URL')."/api/hf_notify/pay_channel");
  1199. Db::name('log')->insert(['data'=>'汇付渠道商支付---'.json_encode($res)]);
  1200. Db::name('channel_order')->where('id',$oid) ->update(['hf_pay_id'=>$res['id']]);
  1201. return app('json')->success($res);
  1202. /////////////////////////////首信易/////////////////////////////////////////////////
  1203. if($payType == 'wx'){
  1204. Db::name('log')->insert(['data'=>'code---'.$code]);
  1205. if(!$code || $code == '' || $code =='undefined')
  1206. return app('json')->fail("授权失败,code为空");
  1207. $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";
  1208. $get = curlGet($url);
  1209. Db::name('log')->insert(['data'=>'open_id---'.json_encode($get)]);
  1210. if(!isset($get['openid']) || empty($get['openid'])){
  1211. return app('json')->fail('授权失败');
  1212. }
  1213. $openid = $get['openid'];
  1214. // $openid = 'ow5su5GbH-RhPFfJv0JUPrMfvPfE';
  1215. $datas['openId'] = $openid;
  1216. $datas['paymentModeCode'] = "MINIAPPS-WEIXIN_PAY-P2P";
  1217. Db::name('channel_order')->where('id',$oid)->update(['pay_type'=>'wx']);
  1218. }else{
  1219. Db::name('channel_order')->where('id',$oid)->update(['pay_type'=>'al']);
  1220. $datas['paymentModeCode'] = "ALIPAY-OFFICIAL";
  1221. }
  1222. $datas['requestId'] = $groupOrder['order_no']."_".rand(1000,9999);//订单号
  1223. $datas['orderAmount'] = strval($groupOrder['pay_price'] * 100);//金额。单位分
  1224. $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';//同步地址微信公众号
  1225. $product = '渠道商';
  1226. Db::name("log")->insert(array('data'=>Db::name("store_product")->getLastSql()));//日志记录
  1227. $productDetails = array(
  1228. 'name' => $product ?? "渠道商",//商品名称。需传递真实产品名称。
  1229. 'quantity' => 1,//商品数量
  1230. 'amount' => strval($groupOrder['pay_price'] * 100),//商品单价
  1231. );
  1232. $datas['productDetails'] = [$productDetails];//商品信息
  1233. $datas['clientIp'] = $this -> getRealIP();//客户端外网IP
  1234. $datas['notifyUrl']='/api/notify/pay_channel';
  1235. Db::name('log')->insert(['data'=>'请求数据--'.json_encode($datas)]);
  1236. $res = ShouxinyiApiRequest::onlinePay($datas);
  1237. $return = array(
  1238. 'redirectUrl' => $res['redirectUrl'] ?? '',//重定向地址
  1239. 'status' => $res['status'],
  1240. 'scanCode' => $res['scanCode'] ?? '',//Base64二维码
  1241. 'appParams' => $res['appParams'] ?? '',//App调用码
  1242. 'jsString' => $res['jsString'] ?? '',//微信小程序及公众号支付调用串
  1243. 'wechatId' => $res['wechatId'] ?? '',//微信原始ID串
  1244. 'tradeNo' => $res['tradeNo'] ?? '',//支付宝生活号调用id
  1245. 'token' => $res['token'] ?? '', //微包支付调用token
  1246. );
  1247. return app('json')->success($return);
  1248. }catch (Exception $exception){
  1249. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  1250. return app('json')->fail("异常");
  1251. }
  1252. }
  1253. //退款
  1254. public function refund(){
  1255. $data['requestId'] = ShouxinyiApiRequest::getOrderNumber('refund'); //订单号
  1256. $data['orderId'] = '4bd333679fc94d61b88b7e758a71e8bc';//交易订单的流水号
  1257. $data['isCollect'] = '1';
  1258. $data['amount'] = 7900;//退款金额
  1259. $data['remark'] = '备注';
  1260. $refundCollectDetail = array(
  1261. 'collectAccType' => 'WAIT_ACC',//归集类型
  1262. 'collectAmount' => 7900,//归集金额
  1263. );
  1264. $data['refundCollectDetail'] = [$refundCollectDetail];//商品信息
  1265. $res = ShouxinyiApiRequest::refund($data);
  1266. return app('json')->success($res);
  1267. }
  1268. //客户端IP
  1269. public function getRealIP()
  1270. {
  1271. $forwarded = request()->header("x-forwarded-for");
  1272. if ($forwarded) {
  1273. $ip = explode(',', $forwarded)[0];
  1274. } else {
  1275. $ip = request()->ip();
  1276. }
  1277. return $ip;
  1278. }
  1279. //修改首信易商户银行信息
  1280. public function save_bank(){
  1281. $data['merchantId'] = '899104033';
  1282. $data['subMerchantId'] = '897401634';
  1283. $data['requestId'] = ShouxinyiApiRequest::getOrderNumber('modifyBankCard'); //订单号;
  1284. $data['bankCode'] = 'ICBC';
  1285. $data['bankBranchName'] = '中国工商银行股份有限公司北京万年花城支行';
  1286. $data['bankCardNo'] = '0200244909200054497';
  1287. $data['cityCode'] = '110100';
  1288. $data['provinceCode'] = '110000';
  1289. $save = ShouxinyiApiRequest::modifyBankCard($data);
  1290. dump($save);
  1291. }
  1292. //佣金处理
  1293. public function activation_yj($order_no)
  1294. {
  1295. $num=0.3;
  1296. $order_data=Db::name('activation_code_order')->where('order_no',$order_no)->where('status',1)->find();
  1297. // $order_data['pay_price']=6000;//测试养老金佣金改为6000
  1298. if(empty($order_data)){
  1299. return $num;
  1300. }
  1301. $eb_data=Db::name('entropy_barter_user_276')->where('uid',$order_data['uid'])->find();
  1302. $jifen=$order_data['pay_price'];
  1303. $uid=$order_data['uid'];
  1304. $bill=[
  1305. 'from_id'=>'0',
  1306. 'number'=>$jifen,
  1307. 'to_id'=>$eb_data['eb_id'],
  1308. 'type'=>'1',
  1309. 'order_no'=>$order_no,
  1310. 'remarks'=>'购买激活码得积分',
  1311. 'pm'=>1,
  1312. 'status'=>2,
  1313. 'on_line'=>1,
  1314. 'mer_id'=>276
  1315. ];
  1316. $this->eb_user_bill($bill);
  1317. Db::name('entropy_barter_user_276')->where('eb_id',$eb_data['eb_id'])->inc('integral',$jifen)->update();
  1318. $mer_id = 276;
  1319. $number = bcmul($order_data['pay_price'],'0.01',2);//养老金
  1320. $data=[
  1321. 'link_id' => $order_data['id'],
  1322. "uid"=>$uid,
  1323. "pm"=>1,
  1324. "title"=>'激活码养老金',
  1325. "category"=>"now_money",
  1326. "type"=>"commission",
  1327. "number"=>$number,
  1328. "balance"=>0,
  1329. "mark"=>'购买激活码获得'.$number.'元养老金',
  1330. "status"=>1,
  1331. "commission_type"=>5,
  1332. "order_sn"=>$order_data['order_no'],
  1333. "mer_id"=>$mer_id,
  1334. "source"=>0,
  1335. "type_shop"=>0,
  1336. 'gzc'=>0
  1337. ];
  1338. Db::name("user_bill")->insert($data);
  1339. Db::name("user")->where("uid",$uid)->inc('annuity', $number) ->update();
  1340. Db::name("user")->where("uid",$uid)->inc('annuity_num', 1) ->update();
  1341. //公证处入账
  1342. // $certification = UserCertification::getInstance()->where('uid', $order_data['uid'])->find();
  1343. // if($certification) {
  1344. // $user_data = Db::name('user')->where('uid', $uid)->find();
  1345. // $user_data['real_name']=Db::name('user_certification')->where('status',1)->where('uid',$user_data['uid'])->value('user_name');
  1346. // $user_data['account']=Db::name('user_certification')->where('status',1)->where('uid',$user_data['uid'])->value('mobile');
  1347. // $online = ['uid' => $uid, 'pay_type' => $order_data['pay_type'] == 'alpay' ? 4 : 1, 'order_sn' => $order_data['order_no'], 'order_id' => $order_data['id']];
  1348. // $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  1349. // $this->GZC($online, $certification, $number);
  1350. // }
  1351. //上级数据
  1352. $top_eb_data=Db::name('entropy_barter_user_276')->where('eb_id',$eb_data['top_eb_id'])->find();
  1353. $top_eb_id=$top_eb_data['eb_id']??0;
  1354. //上级上级数据
  1355. $top_top_eb_data=Db::name('entropy_barter_user_276')->where('eb_id',$top_eb_data['top_eb_id'])->find();
  1356. $top_top_eb_id=$top_top_eb_data['eb_id']??0;
  1357. //一级奖励
  1358. $one_yj=bcmul($order_data['pay_price'],'0.1',2);
  1359. if($top_eb_id==0){//为0 不执行直接返回
  1360. return $num;
  1361. }
  1362. if($top_eb_data['type']!=1) {
  1363. $bill = [
  1364. 'from_id' => '0',
  1365. 'number' => $one_yj,
  1366. 'to_id' => $top_eb_id,
  1367. 'type' => '2',
  1368. 'order_no' => $order_no,
  1369. 'remarks' => '易熵易物直推佣金',
  1370. 'pm' => 1,
  1371. 'status' => 2,
  1372. 'on_line' => 1,
  1373. 'mer_id' => 276
  1374. ];
  1375. $this->eb_user_bill($bill);
  1376. Db::name('entropy_barter_user_276')->where('eb_id', $top_eb_id)->inc('wallet', $one_yj)->update();
  1377. $num=$num - 0.1;
  1378. }
  1379. if($top_top_eb_id==0){//为0 不执行直接返回
  1380. return $num;
  1381. }
  1382. if($top_top_eb_data['type']!=1) {
  1383. if($top_top_eb_data['type']==2){
  1384. $bl=0.15;
  1385. }elseif ($top_top_eb_data['type']==3){
  1386. $bl=0.20;
  1387. }
  1388. //二级奖励
  1389. $two_yj=bcmul($order_data['pay_price'],$bl,2);
  1390. $bill = [
  1391. 'from_id' => '0',
  1392. 'number' => $two_yj,
  1393. 'to_id' => $top_top_eb_id,
  1394. 'type' => '1',
  1395. 'order_no' => $order_no,
  1396. 'remarks' => '易熵易物间推佣金',
  1397. 'pm' => 1,
  1398. 'status' => 2,
  1399. 'on_line' => 1,
  1400. 'mer_id' => 276
  1401. ];
  1402. $this->eb_user_bill($bill);
  1403. Db::name('entropy_barter_user_276')->where('eb_id', $top_top_eb_id)->inc('wallet', $two_yj)->update();
  1404. $num = $num-$bl;
  1405. }
  1406. //公证处入账
  1407. return $num;
  1408. }
  1409. public function GZC($online,$certification,$pension)
  1410. {
  1411. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1412. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1413. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1414. $create = [
  1415. 'uid' => $online['uid'],
  1416. 'platform_no' => $orderId,
  1417. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  1418. 'user_name' => $certification['user_name'],
  1419. 'mobile' => $certification['mobile'],
  1420. 'user_card' => $certification['user_card'],
  1421. 'pension' => $pension,
  1422. 'order_type' => 2,
  1423. 'out_trade_no' => $online['order_sn']
  1424. ];
  1425. $OrderGzcRepository->create($create);
  1426. }
  1427. //账单记录
  1428. public function eb_user_bill($bill)
  1429. {
  1430. $insert=[
  1431. 'from_id'=>$bill['from_id'],
  1432. 'number'=>$bill['number'],
  1433. 'to_id'=>$bill['to_id'],
  1434. 'type'=>$bill['type'],
  1435. 'order_no'=>$bill['order_no'],
  1436. 'remarks'=>$bill['remarks'],
  1437. 'pm'=>$bill['pm'],
  1438. 'ctime'=>time(),
  1439. 'on_line'=>$bill['on_line'],
  1440. 'status'=>$bill['status'],
  1441. 'pm2_msg'=>$bill['pm2_msg']??'',
  1442. 'mer_id'=>$bill['mer_id'],
  1443. 'commission_scale'=>$bill['commission_scale']??0,
  1444. 'commission_type'=>$bill['commission_type']??0,
  1445. 'to_user_type'=>$bill['to_user_type']??'',
  1446. 'to_user_type_1'=>$bill['to_user_type_1']??'',
  1447. ];
  1448. Db::name('log')->insert(['data'=>json_encode($insert)]);
  1449. Db::name('entropy_barter_bill')->insert($insert);
  1450. }
  1451. //分账
  1452. public function activation_spilet($order_no,$num)
  1453. {
  1454. Db::name('log')->insert(['data'=>'分账比例'.$num]);
  1455. $bili=0.33;
  1456. $bili=bcadd($bili,$num,2);
  1457. Db::name('log')->insert(['data'=>'分账比例'.$bili]);
  1458. $order_data=Db::name('activation_code_order')->where('order_no',$order_no)->where('status',1)->find();
  1459. if(empty($order_data)){
  1460. return '';
  1461. }
  1462. $goods_title=Db::name('merchant')->where('mer_id',276)->find();
  1463. $mer_price=bcmul($order_data['pay_price'],$bili,2);
  1464. $yongjin=bcmul($order_data['pay_price'],'0.37',2);
  1465. $shouxufei=bcmul($order_data['pay_price'],'0.006',3);
  1466. $yongjin=bcadd($yongjin,round($shouxufei,2));
  1467. $mer_price=bcsub($mer_price,round($shouxufei,2),2);
  1468. $payment_id = ShouxinyiApiRequest::getOrderNumber('split');
  1469. $div_members=[
  1470. [
  1471. 'member_id'=>$goods_title['hf_member_id_wx'],
  1472. 'amount'=>$mer_price,
  1473. 'fee_flag'=>'Y'
  1474. ],
  1475. [
  1476. 'member_id'=>0,
  1477. 'amount'=>$yongjin,
  1478. 'fee_flag'=>'N'
  1479. ]
  1480. ];
  1481. $params = [
  1482. 'payment_id'=>$order_data['hf_pay_id'],
  1483. 'order_no'=>$payment_id,
  1484. 'confirm_amt' => $order_data['pay_price'],
  1485. 'div_members'=>json_encode($div_members)
  1486. ];
  1487. $res = $this -> payment_confirm_create_traits($params);
  1488. Db::name("log")->insert(array('data'=>'汇付延时分账-----'.json_encode($res)));//日志记录
  1489. ////////////////////////////////首信易///////////////////////////////////////////
  1490. $sxy_submerchant_id=Db::name('Merchant')->where('mer_id',276)->value('sxy_submerchant_id');
  1491. $splitDetails = array(
  1492. array(
  1493. 'subSplitRequestId' => $data['requestId'] . '_1',
  1494. 'splitAccType' => 'MERCHANT_ACC',
  1495. 'splitAccId' => $sxy_submerchant_id,
  1496. 'splitAmount' => $mer_price
  1497. ),
  1498. array(
  1499. 'subSplitRequestId' => $data['requestId'] . '_2',
  1500. 'splitAccType' => 'MERCHANT_ACC',
  1501. 'splitAccId' => '895961180',
  1502. 'splitAmount' => $yongjin
  1503. )
  1504. );
  1505. $insertData=[
  1506. [
  1507. 'mid' => $order['mer_id']??0,
  1508. 'requestId' => $data['requestId'],
  1509. 'group_order_id' => $data['orderId'],
  1510. 'subSplitRequestId' => $data['requestId'].'_1',
  1511. 'splitAccId' => $sxy_submerchant_id,
  1512. 'splitAmount' => $splitDetails[0]['splitAmount'],
  1513. 'totalSplitAmount' => $data['totalSplitAmount'],
  1514. 'status' => 0
  1515. ],
  1516. [
  1517. 'mid' => $order['mer_id']??0,
  1518. 'requestId' => $data['requestId'],
  1519. 'group_order_id' => $data['orderId'],
  1520. 'subSplitRequestId' => $data['requestId'].'_2',
  1521. 'splitAccId' => 895961180,
  1522. 'splitAmount' => $splitDetails[1]['splitAmount'],
  1523. 'totalSplitAmount' => $data['totalSplitAmount'],
  1524. 'status' => 0
  1525. ]
  1526. ];
  1527. $data['splitDetails'] = $splitDetails;
  1528. Db::name("store_split_order") -> insertAll($insertData);
  1529. return ShouxinyiApiRequest::split($data);
  1530. }
  1531. //渠道商分佣
  1532. public function channel_fenyong($order_sn)
  1533. {
  1534. try{
  1535. $order_data=Db::name('channel_order')->where('order_no',$order_sn)->find();//订单数据
  1536. $channelrecommend=Db::name('channel_user')->where('uid',$order_data['uid'])->find();
  1537. //渠道商表中查无此人
  1538. if(!$channelrecommend){
  1539. return false;
  1540. }
  1541. $user_data=Db::name('user')->where('uid',$order_data['uid'])->find();//渠道商用户信息
  1542. $top_user_data=Db::name('user')->where('uid',$user_data['spread_uid'])->find();//用户的推荐人(邀请注册的人)
  1543. $top_uid = $top_user_data['uid'];
  1544. if($channelrecommend['recommend_uid'] != '' || $channelrecommend['recommend_uid'] != 0){
  1545. $top_uid=$channelrecommend['recommend_uid'];
  1546. }
  1547. //渠道商本人给养老金10%
  1548. $ylj=bcmul($order_data['pay_price'],'0.1',5);//10%的养老金
  1549. $ylj=round($ylj,2);
  1550. $top_yongjin = 0;//直接上级佣金
  1551. $top_top_yongjin = 0;//间接上级佣金
  1552. $title='养老金';
  1553. $mark = '成为渠道商获得' . $ylj . '养老金';
  1554. $billData=[
  1555. 'uid'=>$order_data['uid'],
  1556. 'link_id'=>$order_data['id'],
  1557. 'pm'=>1,
  1558. 'title'=>$title,
  1559. 'category'=>'now_money',
  1560. 'type'=>'commission',
  1561. 'number'=>$ylj,
  1562. 'balance'=>0,
  1563. 'mark'=>$mark,
  1564. 'create_time'=>date("Y-m-d H:i:s",time()),
  1565. 'status'=>1,
  1566. 'order_sn'=>$order_sn,
  1567. 'type_shop'=>0,
  1568. 'commission_type'=>5,
  1569. 'order_type'=>1,
  1570. 'gzc'=>0
  1571. ];
  1572. Db::name('user_bill')->insert($billData);
  1573. Db::name("user")->where("uid",$order_data['uid'])->inc('annuity', $ylj) ->update();
  1574. Db::name("user")->where("uid",$order_data['uid'])->inc('annuity_num', 1) ->update();
  1575. //如果存在上级
  1576. if($top_uid > 0){
  1577. //上级身份是否大仓会员
  1578. $is_da_cang_vip=Db::name('da_cang_user')->where('status',1)->where('uid',$top_uid)->find();
  1579. //上级身份是否商户
  1580. $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_uid)->find();
  1581. $is_shanghu2=Db::name('merchant')->where('uid',$top_uid)->find();
  1582. $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_uid)->find();
  1583. //渠道商
  1584. $is_channel = Db::name('channel_user') -> where('uid',$top_uid)->where('status',1)->find();
  1585. Db::name('log')->insert(['data'=>'会员状态'.json_encode($is_da_cang_vip)]);
  1586. Db::name('log')->insert(['data'=>'商户支付订单'.json_encode($is_shanghu1)]);
  1587. Db::name('log')->insert(['data'=>'商户'.json_encode($is_shanghu2)]);
  1588. Db::name('log')->insert(['data'=>'商户入驻表'.json_encode($is_shanghu3)]);
  1589. Db::name('log')->insert(['data'=>'渠道商'.json_encode($is_channel)]);
  1590. //如果是大仓会员
  1591. if($is_da_cang_vip){
  1592. //如果上级是金卡会员 20%佣金
  1593. if($is_da_cang_vip['type'] == 1){
  1594. $top_yongjin = bcmul($order_data['pay_price'], 0.12, 5);
  1595. }elseif ($is_da_cang_vip['type'] == 2){
  1596. //如果上级是银卡会员 15%佣金
  1597. $top_yongjin = bcmul($order_data['pay_price'], 0.1, 5);
  1598. }
  1599. }
  1600. //如果是商户 22%佣金
  1601. if($is_shanghu1||$is_shanghu2||$is_shanghu3){
  1602. $top_yongjin = bcmul($order_data['pay_price'], 0.15, 5);
  1603. }
  1604. //如果是渠道商 20% 佣金
  1605. if($is_channel){
  1606. $top_yongjin = bcmul($order_data['pay_price'], 0.20, 5);
  1607. }
  1608. $top_yongjin=round($top_yongjin,2);
  1609. if($top_yongjin > 0){
  1610. $title='佣金';
  1611. $mark = '邀请渠道商获得' . $top_yongjin . '招募奖励';
  1612. $billData=[
  1613. 'uid'=>$top_uid,
  1614. 'link_id'=>$order_data['id'],
  1615. 'pm'=>1,
  1616. 'title'=>$title,
  1617. 'category'=>'now_money',
  1618. 'type'=>'commission',
  1619. 'number'=>$top_yongjin,
  1620. 'balance'=>0,
  1621. 'mark'=>$mark,
  1622. 'create_time'=>date("Y-m-d H:i:s",time()),
  1623. 'status'=>1,
  1624. 'order_sn'=>$order_sn,
  1625. 'type_shop'=>0,
  1626. 'commission_type'=>9,
  1627. 'order_type'=>1
  1628. ];
  1629. Db::name('user_bill')->insert($billData);
  1630. Db::name('user')->where('uid',$top_uid)->inc('brokerage_price',$top_yongjin)->update();
  1631. }
  1632. }
  1633. //间接上级
  1634. $top_top_uid =Db::name('user')->where('uid',$top_uid)->value('spread_uid');//推荐人的推荐人(邀请注册的人)
  1635. $top_channelrecommend=Db::name('channel_user')->where('uid',$top_uid)->find();//推荐人的推荐人(渠道商推荐人)
  1636. if($top_channelrecommend && ($top_channelrecommend['recommend_uid'] != '' || $top_channelrecommend['recommend_uid'] != 0)){
  1637. $top_top_uid = $top_channelrecommend['recommend_uid'];
  1638. }
  1639. if($top_top_uid > 0){
  1640. //商户
  1641. $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_top_uid)->find();
  1642. $is_shanghu2=Db::name('merchant')->where('uid',$top_top_uid)->find();
  1643. $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_top_uid)->find();
  1644. //大仓会员
  1645. $is_da_cang_vip=Db::name('da_cang_user')->where('uid',$top_top_uid)->where('status',1)->find();
  1646. //渠道商
  1647. $is_channel = Db::name('channel_user') -> where('uid',$top_top_uid)->where('status',1)->find();
  1648. Db::name('log')->insert(['data'=>'会员状态'.json_encode($is_da_cang_vip)]);
  1649. Db::name('log')->insert(['data'=>'商户支付订单'.json_encode($is_shanghu1)]);
  1650. Db::name('log')->insert(['data'=>'商户'.json_encode($is_shanghu2)]);
  1651. Db::name('log')->insert(['data'=>'商户入驻表'.json_encode($is_shanghu3)]);
  1652. Db::name('log')->insert(['data'=>'渠道商'.json_encode($is_channel)]);
  1653. //如果是大仓会员
  1654. if($is_da_cang_vip){
  1655. //如果间接上级是金卡会员 8%佣金
  1656. if($is_da_cang_vip['type'] == 1){
  1657. $top_top_yongjin = bcmul($order_data['pay_price'], 0.08, 5);
  1658. }elseif ($is_da_cang_vip['type'] == 2){
  1659. //如果上级是银卡会员 5%佣金
  1660. $top_top_yongjin = bcmul($order_data['pay_price'], 0.05, 5);
  1661. }
  1662. }
  1663. //如果是商户 10%佣金
  1664. if($is_shanghu1||$is_shanghu2||$is_shanghu3){
  1665. $top_top_yongjin = bcmul($order_data['pay_price'], 0.1, 5);
  1666. }
  1667. //如果是渠道商 15% 佣金
  1668. if($is_channel){
  1669. $top_top_yongjin = bcmul($order_data['pay_price'], 0.15, 5);
  1670. }
  1671. $top_top_yongjin=round($top_top_yongjin,2);
  1672. $title='佣金';
  1673. $mark = '下级邀请渠道商获得' . $top_top_yongjin . '培育奖励';
  1674. $billData=[
  1675. 'uid'=>$top_top_uid,
  1676. 'link_id'=>$order_data['id'],
  1677. 'pm'=>1,
  1678. 'title'=>$title,
  1679. 'category'=>'now_money',
  1680. 'type'=>'commission',
  1681. 'number'=>$top_top_yongjin,
  1682. 'balance'=>0,
  1683. 'mark'=>$mark,
  1684. 'create_time'=>date("Y-m-d H:i:s",time()),
  1685. 'status'=>1,
  1686. 'order_sn'=>$order_sn,
  1687. 'type_shop'=>0,
  1688. 'commission_type'=>9,
  1689. 'order_type'=>1
  1690. ];
  1691. Db::name('user_bill')->insert($billData);
  1692. Db::name('user')->where('uid',$top_top_uid)->inc('brokerage_price',$top_top_yongjin)->update();
  1693. }
  1694. }catch (Exception $exception){
  1695. Db::name("log")->insert(array('data'=>'渠道商佣金error'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  1696. }
  1697. return true;
  1698. //2022年6月22号前版本
  1699. $order_data=Db::name('channel_order')->where('order_no',$order_sn)->find();//订单数据
  1700. $channelrecommend=Db::name('channel_user')->where('uid',$order_data['uid'])->find();
  1701. //渠道商表中查无此人
  1702. if(!$channelrecommend){
  1703. return false;
  1704. }
  1705. $user_data=Db::name('user')->where('uid',$order_data['uid'])->find();//渠道商用户信息
  1706. $top_user_data=Db::name('user')->where('uid',$user_data['spread_uid'])->find();//用户的推荐人(邀请注册的人)
  1707. $top_uid = $top_user_data['uid'];
  1708. if($channelrecommend['recommend_uid'] != '' || $channelrecommend['recommend_uid'] != 0){
  1709. $top_uid=$channelrecommend['recommend_uid'];
  1710. }
  1711. //渠道商本人给养老金5%
  1712. $ylj=bcmul($order_data['pay_price'],'0.05',5);//5%的养老金
  1713. $ylj=round($ylj,2);
  1714. $title='养老金';
  1715. $mark = '成为渠道商获得' . $ylj . '养老金';
  1716. $billData=[
  1717. 'uid'=>$order_data['uid'],
  1718. 'link_id'=>$order_data['id'],
  1719. 'pm'=>1,
  1720. 'title'=>$title,
  1721. 'category'=>'now_money',
  1722. 'type'=>'commission',
  1723. 'number'=>$ylj,
  1724. 'balance'=>0,
  1725. 'mark'=>$mark,
  1726. 'create_time'=>date("Y-m-d H:i:s",time()),
  1727. 'status'=>1,
  1728. 'order_sn'=>$order_sn,
  1729. 'type_shop'=>0,
  1730. 'commission_type'=>5,
  1731. 'order_type'=>1,
  1732. 'gzc'=>0
  1733. ];
  1734. Db::name('user_bill')->insert($billData);
  1735. Db::name("user")->where("uid",$order_data['uid'])->inc('annuity', $ylj) ->update();
  1736. Db::name("user")->where("uid",$order_data['uid'])->inc('annuity_num', 1) ->update();
  1737. //如果有直接上级,给佣金10%
  1738. if($top_uid > 0){
  1739. $price=bcmul($order_data['pay_price'],'0.1',5);//10%的推荐佣金
  1740. $price=round($price,2);
  1741. $title='佣金';
  1742. $mark = '邀请渠道商获得' . $price . '佣金';
  1743. $billData=[
  1744. 'uid'=>$top_uid,
  1745. 'link_id'=>$order_data['id'],
  1746. 'pm'=>1,
  1747. 'title'=>$title,
  1748. 'category'=>'now_money',
  1749. 'type'=>'commission',
  1750. 'number'=>$price,
  1751. 'balance'=>0,
  1752. 'mark'=>$mark,
  1753. 'create_time'=>date("Y-m-d H:i:s",time()),
  1754. 'status'=>1,
  1755. 'order_sn'=>$order_sn,
  1756. 'type_shop'=>0,
  1757. 'commission_type'=>9,
  1758. 'order_type'=>1
  1759. ];
  1760. Db::name('user_bill')->insert($billData);
  1761. Db::name('user')->where('uid',$top_uid)->inc('brokerage_price',$price)->update();
  1762. $top_top_uid =Db::name('user')->where('uid',$top_uid)->value('spread_uid');//推荐人的推荐人(邀请注册的人)
  1763. $top_channelrecommend=Db::name('channel_user')->where('uid',$top_uid)->find();//推荐人的推荐人(渠道商推荐人)
  1764. if($top_channelrecommend && ($top_channelrecommend['recommend_uid'] != '' || $top_channelrecommend['recommend_uid'] != 0)){
  1765. $top_top_uid = $top_channelrecommend['recommend_uid'];
  1766. }
  1767. //如果有间接上级,给佣金5%
  1768. if($top_top_uid > 0){
  1769. //大仓会员
  1770. $is_da_cang_vip=Db::name('da_cang_user')->where('status',1)->where('uid',$top_top_uid)->find();
  1771. //商户
  1772. $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$top_top_uid)->find();
  1773. $is_shanghu2=Db::name('merchant')->where('uid',$top_top_uid)->find();
  1774. $is_shanghu3=Db::name('merchant_intention')->where('uid',$top_top_uid)->find();
  1775. //渠道商
  1776. $is_channel = Db::name('channel_user') -> where('uid',$top_top_uid)->where('status',1)->find();
  1777. //第二级 必需是会员或者商户 或者渠道商
  1778. if($is_da_cang_vip || $is_shanghu1 || $is_shanghu2 || $is_shanghu3 || $is_channel){
  1779. $price=bcmul($order_data['pay_price'],'0.05',5);//5%的推荐佣金
  1780. $price=round($price,2);
  1781. $title='佣金';
  1782. $mark = '下级邀请渠道商获得' . $price . '佣金';
  1783. $billData=[
  1784. 'uid'=>$top_top_uid,
  1785. 'link_id'=>$order_data['id'],
  1786. 'pm'=>1,
  1787. 'title'=>$title,
  1788. 'category'=>'now_money',
  1789. 'type'=>'commission',
  1790. 'number'=>$price,
  1791. 'balance'=>0,
  1792. 'mark'=>$mark,
  1793. 'create_time'=>date("Y-m-d H:i:s",time()),
  1794. 'status'=>1,
  1795. 'order_sn'=>$order_sn,
  1796. 'type_shop'=>0,
  1797. 'commission_type'=>9,
  1798. 'order_type'=>1
  1799. ];
  1800. Db::name('user_bill')->insert($billData);
  1801. Db::name('user')->where('uid',$top_top_uid)->inc('brokerage_price',$price)->update();
  1802. }
  1803. }
  1804. }
  1805. return true;
  1806. //以下为原逻辑。2022.05.30更改
  1807. //消费者上级奖励
  1808. if($top_user_data){//上级用户信息是否存在
  1809. $uid=$top_user_data['uid'];
  1810. $price=bcmul($order_data['pay_price'],'0.05',3);//5%的推荐佣金
  1811. $price=round($price,2);
  1812. $title='养老金';
  1813. $mark='下级成为渠道商获得'.$price.'养老金';
  1814. $billData=[
  1815. 'uid'=>$uid,
  1816. 'link_id'=>$order_data['id'],
  1817. 'pm'=>1,
  1818. 'title'=>$title,
  1819. 'category'=>'now_money',
  1820. 'type'=>'commission',
  1821. 'number'=>$price,
  1822. 'balance'=>0,
  1823. 'mark'=>$mark,
  1824. 'create_time'=>date("Y-m-d H:i:s",time()),
  1825. 'status'=>1,
  1826. 'order_sn'=>$order_sn,
  1827. 'type_shop'=>0,
  1828. 'commission_type'=>5,
  1829. 'order_type'=>1,
  1830. 'gzc'=>0
  1831. ];
  1832. Db::name('user_bill')->insert($billData);
  1833. Db::name("user")->where("uid",$uid)->inc('annuity', $price) ->update();
  1834. Db::name("user")->where("uid",$uid)->inc('annuity_num', 1) ->update();
  1835. }
  1836. //上级奖励
  1837. //备注同上
  1838. $channelrecommend=Db::name('channel_user')->where('uid',$order_data['uid'])->find();
  1839. if(!$channelrecommend){
  1840. return false;
  1841. }
  1842. $uid=$channelrecommend['recommend_uid'];
  1843. $price=bcmul($order_data['pay_price'],'0.1',3);
  1844. $price=round($price,2);
  1845. $mark = '邀请渠道商获得' . $price . '佣金';
  1846. $commission_type=9;
  1847. $is_implement=1;
  1848. if($uid==0){
  1849. $uid=$top_user_data['uid'];
  1850. $commission_type=3;
  1851. $is_implement=0;
  1852. }
  1853. $title='佣金';
  1854. $billData=[
  1855. 'uid'=>$uid,
  1856. 'link_id'=>$order_data['id'],
  1857. 'pm'=>1,
  1858. 'title'=>$title,
  1859. 'category'=>'now_money',
  1860. 'type'=>'commission',
  1861. 'number'=>$price,
  1862. 'balance'=>0,
  1863. 'mark'=>$mark,
  1864. 'create_time'=>date("Y-m-d H:i:s",time()),
  1865. 'status'=>1,
  1866. 'order_sn'=>$order_sn,
  1867. 'type_shop'=>0,
  1868. 'commission_type'=>$commission_type,
  1869. 'order_type'=>1
  1870. ];
  1871. Db::name('user_bill')->insert($billData);
  1872. Db::name('user')->where('uid',$uid)->inc('brokerage_price',$price)->update();
  1873. if($is_implement){
  1874. if($channelrecommend['recommend_uid']!=0){
  1875. $price=bcmul($order_data['pay_price'],'0.05',3);
  1876. $price=round($price,2);
  1877. $mark = '邀请渠道商获得' . $price . '佣金';
  1878. $title='佣金';
  1879. $tuijian=Db::name('channel_user')->where('uid',Db::name('channel_user')->where('uid',$channelrecommend['recommend_uid'])->value('recommend_uid'))->find();
  1880. if($tuijian){
  1881. $billData=[
  1882. 'uid'=>$tuijian['uid'],
  1883. 'link_id'=>$order_data['id'],
  1884. 'pm'=>1,
  1885. 'title'=>$title,
  1886. 'category'=>'now_money',
  1887. 'type'=>'commission',
  1888. 'number'=>$price,
  1889. 'balance'=>0,
  1890. 'mark'=>$mark,
  1891. 'create_time'=>date("Y-m-d H:i:s",time()),
  1892. 'status'=>1,
  1893. 'order_sn'=>$order_sn,
  1894. 'type_shop'=>0,
  1895. 'commission_type'=>9,
  1896. 'order_type'=>1
  1897. ];
  1898. Db::name('user_bill')->insert($billData);
  1899. Db::name('user')->where('uid',$tuijian['uid'])->inc('brokerage_price',$price)->update();
  1900. }
  1901. }
  1902. }
  1903. }
  1904. //渠道商分账
  1905. public function channel_spilet($order_no)
  1906. {
  1907. $order_data=Db::name('channel_order')->where('order_no',$order_no)->where('status',1)->find();
  1908. if(empty($order_data)){
  1909. return '';
  1910. }
  1911. $data['requestId'] = ShouxinyiApiRequest::getOrderNumber('split');
  1912. $data['orderId'] = $order_no.'_'.$order_data['rand'];
  1913. $data['totalSplitAmount'] = bcmul($order_data['pay_price'],'100');
  1914. $monent=bcmul($order_data['pay_price'],'100');
  1915. $splitDetails = array(
  1916. array(
  1917. 'subSplitRequestId' => $data['requestId'] . '_1',
  1918. 'splitAccType' => 'MERCHANT_ACC',
  1919. 'splitAccId' => '895152791',
  1920. 'splitAmount' => $monent
  1921. )
  1922. );
  1923. $insertData=[
  1924. [
  1925. 'mid' => $order['mer_id']??0,
  1926. 'requestId' => $data['requestId'],
  1927. 'group_order_id' => $data['orderId'],
  1928. 'subSplitRequestId' => $data['requestId'].'_1',
  1929. 'splitAccId' => '895152791',
  1930. 'splitAmount' => $splitDetails[0]['splitAmount'],
  1931. 'totalSplitAmount' => $data['totalSplitAmount'],
  1932. 'status' => 0
  1933. ]
  1934. ];
  1935. $data['splitDetails'] = $splitDetails;
  1936. Db::name("store_split_order") -> insertAll($insertData);
  1937. return ShouxinyiApiRequest::split($data);
  1938. }
  1939. public function marketing_spilet($order_id){
  1940. }
  1941. public function pay_huifu($payType,$code,$groupOrder,$title,$notify_url,$pay_mode=null,$appid=''){
  1942. $order_no = $groupOrder['group_order_sn'] ?? $groupOrder['order_no'];
  1943. if($payType == 'wx'){
  1944. if(!$code || $code == '' || $code =='undefined')
  1945. return "授权失败,code为空";
  1946. if($appid == '') {
  1947. $pay_wx = systemConfig('pay_wx');
  1948. if ($pay_wx == 2){
  1949. $appid = env('WECHAT_MP.APPID');
  1950. $new_secret = env('WECHAT_MP.SECRET');
  1951. $app_id='app_0827b960-b932-45ec-b800-4e850091b419';
  1952. $key='api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  1953. }elseif ($pay_wx == 3){
  1954. $appid = env('WECHAT_TDYL.APPID');
  1955. $new_secret = env('WECHAT_TDYL.SECRET');
  1956. Db::name('log')->insert(['data'=>'appid---'.$appid]);
  1957. Db::name('log')->insert(['data'=>'new_secret---'.$new_secret]);
  1958. $app_id='app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  1959. $key='api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  1960. }
  1961. }else{
  1962. $app_id='app_0827b960-b932-45ec-b800-4e850091b419';
  1963. $key='api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  1964. $new_secret = "c8cbe24fa3b83f77a88b79554b3aeab4";
  1965. }
  1966. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$new_secret."&js_code=".$code."&grant_type=authorization_code";
  1967. $get = curlGet($url);
  1968. Db::name('log')->insert(['data'=>'pay_wx---'.$pay_wx]);
  1969. Db::name('log')->insert(['data'=>'code---'.$code]);
  1970. Db::name('log')->insert(['data'=>'url---'.$url]);
  1971. Db::name('log')->insert(['data'=>'open_id---'.json_encode($get)]);
  1972. if(!isset($get['openid']) || empty($get['openid'])){
  1973. return '授权失败';
  1974. }
  1975. $openid = $get['openid'];
  1976. $member_id=0;
  1977. $type='2';
  1978. $pay_channel='wx_lite';
  1979. $expend=[
  1980. 'open_id'=>$openid,
  1981. 'wx_app_id'=> $appid
  1982. ];
  1983. if ($groupOrder['order_type'] = "marketing"){
  1984. // 创富宝 分账
  1985. //创富宝
  1986. $cfb = sprintf("%01.2f",round(bcmul($groupOrder['pay_price'],'0.094',5),2));//9.4%的分账
  1987. $cfb_member = "jsdk_member_1680162243019";
  1988. // 平台
  1989. $cxb = sprintf("%01.2f",round(bcsub($groupOrder['pay_price'],$cfb,5),2));//剩下的归平台
  1990. $div_members=[
  1991. [
  1992. 'member_id'=>$member_id,
  1993. 'amount'=>$cxb,
  1994. 'fee_flag'=>'Y'
  1995. ],
  1996. [
  1997. 'member_id'=>$cfb_member,
  1998. 'amount'=>$cfb,
  1999. 'fee_flag'=>'N'
  2000. ]
  2001. ];
  2002. }else{
  2003. $div_members=[
  2004. [
  2005. 'member_id'=>$member_id,
  2006. 'amount'=>$groupOrder['pay_price'],
  2007. 'fee_flag'=>'Y'
  2008. ]
  2009. ];
  2010. }
  2011. $params=[
  2012. 'order_no'=>$order_no."_".rand(1000,9999),
  2013. 'app_id'=>$app_id,
  2014. 'pay_channel'=>$pay_channel,
  2015. 'pay_amt'=>(string)$groupOrder['pay_price'],
  2016. 'goods_title'=> strlen($title) > 64 ? mb_substr($title, 0, 64,'utf-8') : $title,// 解决因为太长不能支付问题
  2017. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127,'utf-8') : $title,// 解决因为太长不能支付问题
  2018. 'device_info'=>[
  2019. 'device_ip'=>app('request')->ip()
  2020. // 'device_ip'=>'115.171.134.68'
  2021. ],
  2022. 'expend'=>json_encode($expend),
  2023. 'div_members'=>json_encode($div_members),
  2024. 'fee_mode'=>'I',
  2025. 'notify_url'=>$notify_url
  2026. ];
  2027. if($pay_mode == 'delay'){
  2028. $params['pay_mode'] = 'delay';
  2029. unset($params['div_members']);
  2030. unset($params['fee_mode']);
  2031. }
  2032. return $this->Payment_create_traits_b($params,$type,$key);
  2033. }elseif($payType=='ALI'){
  2034. // throw new AuthException('支付宝正在升级,请使用微信支付');
  2035. $member_id=0;
  2036. $type='1';
  2037. $pay_channel='alipay_qr';
  2038. // 天地博爱科技通道
  2039. $app_id='app_44108546-d27a-48ee-88c1-84b45b75114f';
  2040. $key='api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  2041. // 天地博爱通道
  2042. // $app_id='app_0827b960-b932-45ec-b800-4e850091b419';
  2043. // $key='api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  2044. $div_members=[
  2045. [
  2046. 'member_id'=>$member_id,
  2047. 'amount'=>$groupOrder['pay_price'],
  2048. 'fee_flag'=>'Y'
  2049. ]
  2050. ];
  2051. $params=[
  2052. 'order_no'=>$order_no."_".rand(1000,9999),
  2053. 'app_id'=>$app_id,
  2054. 'pay_channel'=>$pay_channel,
  2055. 'pay_amt'=>(string)$groupOrder['pay_price'],
  2056. 'goods_title'=> strlen($title) > 64 ? mb_substr($title, 0, 64,'utf-8') : $title,// 解决因为太长不能支付问题
  2057. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127,'utf-8') : $title,// 解决因为太长不能支付问题
  2058. 'device_info'=>[
  2059. 'device_ip'=>app('request')->ip()
  2060. // 'device_ip'=>'115.171.134.68'
  2061. ],
  2062. // 'expend'=>json_encode($expend),
  2063. 'div_members'=>json_encode($div_members),
  2064. 'fee_mode'=>'I',
  2065. 'notify_url'=>$notify_url
  2066. ];
  2067. if($pay_mode == 'delay'){
  2068. $params['pay_mode'] = 'delay';
  2069. unset($params['div_members']);
  2070. unset($params['fee_mode']);
  2071. }
  2072. return $this->Payment_create_traits_a($params,$type,$key);
  2073. }
  2074. }
  2075. }