Access.php 110 KB

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