Access.php 116 KB

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