Access.php 105 KB

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