Access.php 114 KB

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