Access.php 115 KB

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