Access.php 112 KB

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