Index.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\controller\v1\PayNotify;
  4. use app\service\PayService;
  5. use think\Config;
  6. use think\Console;
  7. use think\console\Input;
  8. use think\console\Output;
  9. use think\Controller;
  10. use think\Db;
  11. use app\common\library\WeixinPay;
  12. class Index extends Controller
  13. {
  14. public function sywpay(){
  15. die;
  16. $wxPay = new WeixinPay();
  17. // $params['appid'] = Config::get('wxpay-h5')['app_id'];
  18. // $params['mch_id'] = Config::get('wxpay-h5')['mch_id'];
  19. $params['appid'] = 'wxf6d1543cec2dfa53';
  20. $params['mch_id'] = '1675127018';
  21. $params['sub_mch_id'] = '1726067763';
  22. $params['nonce_str'] = random(10);
  23. $params['body'] = '测试商品描述';
  24. $params['out_trade_no'] = "DT". time(). mt_rand(10000000,99999999);
  25. $params['total_fee'] = 1; // 支付金额,以分为单位
  26. $params['spbill_create_ip'] = request()->ip();
  27. // $params['spbill_create_ip'] = '115.195.83.99';
  28. $params['notify_url'] = 'http://sdkapi.newsdk.com/pay.php';
  29. $params['trade_type'] = 'MWEB';
  30. // $params['scene_info'] = '{"h5_info":{"type":"Wap","wap_url":"'.$wap_url.'","wap_name":"祈盟"}}';
  31. $params['scene_info'] = '{"h5_info":{"type":"Wap","wap_url":"http://sdkapi.newsdk.com","wap_name":"祈盟"}}';
  32. //获取签名数据
  33. // $params['sign'] = $wxPay->MakeSign($params, Config::get('wxpay-h5')['key']);
  34. $params['sign'] = $wxPay->MakeSign($params, '66052a198653943dbc6c8032f1a40a9c');
  35. $xml = dataToXml($params);
  36. $response = $wxPay->postXmlCurl($xml, 'https://api.mch.weixin.qq.com/v3/pay/partner/transactions/h5');
  37. dump($response);
  38. $result = $wxPay->xmlToArray($response);
  39. }
  40. public function index()
  41. {
  42. // echo phpinfo();
  43. // $return_arr['mweb_url'] = 'http://sdkapi.46yx.com';
  44. // $return_url = 'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx05112758904301e15b6b8e875970b00000&package=2416986125';
  45. // header("location:" . $return_arr['mweb_url'] . "&redirect_url={$return_url}");
  46. // return json_encode(["code" => 200, "message" => "HELLO API!", "data" => ""]);
  47. $gameid = input('gameid');
  48. if(!$gameid){
  49. return json_encode(["code" => 200, "message" => "HELLO API!", "data" => ""]);
  50. }
  51. $userAgent = $_SERVER["HTTP_USER_AGENT"];
  52. if((stripos($userAgent, "iPhone") !== false || stripos($userAgent, "iPad") !== false)){
  53. $gameIds = Config::get('ios_jump_game');
  54. if(array_key_exists($gameid, $gameIds)){
  55. header("location: ". $gameIds[$gameid]);
  56. }
  57. echo "请联系开发配置当前游戏跳转!";
  58. }
  59. }
  60. // TODO:媒体对接测试(可删)
  61. public function mediaTest(){
  62. $input = input();
  63. log_message('input:' . json_encode($input), 'log', LOG_PATH . 'mediaTest/');
  64. $msg = "\n input=". json_encode($input) ." , \n date: ".date('Y-m-d H:i:s', time())." \n";
  65. curlDD($msg,"https://oapi.dingtalk.com/robot/send?access_token=e129a024173c56f193a6343012edd4072cb8f1d1a771a72ca126fcfa4d521ba8");
  66. return "success";
  67. }
  68. public function transpondUrlAction()
  69. {
  70. // $url = $request->get("url"); // 获取接口传入需要转发的url注意需要用url编码。由于基于Symfony框架实现$request可以直接获取url参数,原生可用$_GET['url']代替
  71. $url = 'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx05112758904301e15b6b8e875970b00000&package=2416986125';
  72. $userAgent = $this->getAgent('user-agent');
  73. if (empty($url) or $url == "") return false;
  74. if (empty($userAgent)) $userAgent = $this->getAgent();
  75. $ch = curl_init();
  76. if (preg_match("/^https:\\/\\/.+/", $url)) {
  77. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  78. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  79. }
  80. $cip = '125.77.44.84';
  81. curl_setopt($ch, CURLOPT_URL, $url);
  82. curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
  83. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  84. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  85. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  86. // curl_setopt ($ch, CURLOPT_COOKIEJAR, './cookie.txt'); // cookie日志
  87. // 微信Wap支付需要伪造请求头Referer该参数,该参数需设置与微信支付配置都安全域名一致
  88. curl_setopt($ch, CURLOPT_REFERER, "http://sdkapi.46yx.com");
  89. curl_setopt($ch, CURLOPT_HTTPHEADER, ["CLIENT-IP:$cip"]);// 这里需要设置客户端的Ip地址,用于伪造请求IP地址
  90. curl_setopt($ch, CURLOPT_HEADER, 1); //显示返回的HEAD区域的内容
  91. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  92. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  93. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  94. $result = curl_exec($ch);
  95. curl_close($ch);
  96. var_dump($result);
  97. }
  98. public function getAgent()
  99. {
  100. $agentarry = [
  101. "iPhone11" => "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MicroMessenger/6.5.18 NetType/WIFI Language/en",
  102. "华为P9全网通" => "Mozilla/5.0 (Linux; Android 7.0; EVA-AL00 Build/HUAWEIEVA-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043508 Safari/537.36 MicroMessenger/6.5.13.1100 NetType/WIFI Language/zh_CN",
  103. "小米5X" => "Mozilla/5.0 (Linux; U; Android 7.1.2; zh-cn; MI 5X Build/N2G47H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.146 Mobile Safari/537.36 XiaoMi/MiuiBrowser/9.2.2",
  104. "一加手机3" => "Mozilla/5.0 (Linux; Android 7.1.1; ONEPLUS A3000 Build/NMF26F; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043508 Safari/537.36 MicroMessenger/6.5.13.1100 NetType/WIFI Language/zh_CN",
  105. "努比亚Z11" => "Mozilla/5.0 (Linux; U; Android 6.0.1; zh-cn; NX531J Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 Chrome/37.0.0.0 MQQBrowser/6.8 Mobile Safari/537.36",
  106. "小米5s" => "Mozilla/5.0 (Linux; Android 6.0.1; MI 5s Build/MXB48T; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043508 Safari/537.36 V1_AND_SQ_7.2.0_730_YYB_D QQ/7.2.0.3270 NetType/WIFI WebP/0.3.0 Pixel/1080",
  107. "华为nova" => "Mozilla/5.0 (Linux; Android 7.0; HUAWEI CAZ-AL10 Build/HUAWEICAZ-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043508 Safari/537.36 V1_AND_SQ_7.1.0_692_YYB_D QQ/7.1.0.3175 NetType/WIFI WebP/0.3.0 Pixel/1080",
  108. "联想ZUK Z2 Pro" => "Mozilla/5.0 (Linux; Android 7.0; ZUK Z2121 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043508 Safari/537.36 V1_AND_SQ_7.2.0_730_YYB_D QQ/7.2.0.3270 NetType/4G WebP/0.3.0 Pixel/1080",
  109. "魅蓝note 3" => "Mozilla/5.0 (Linux; Android 5.1; m3 note Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/48.0.2564.116 Mobile Safari/537.36 T7/9.3 baiduboxapp/9.3.0.10 (Baidu; P1 5.1)",
  110. "三星GALAXY S8+" => "Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; SM-G9550 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.7.0.953 Mobile Safari/537.36",
  111. "魅族MX6 " => "Mozilla/5.0 (Linux; Android 6.0; MX6 Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043508 Safari/537.36 MicroMessenger/6.5.13.1100 NetType/4G Language/zh_CN",
  112. "vivo Xplay5A" => "Mozilla/5.0 (Linux; Android 5.1.1; vivo Xplay5A Build/LMY47V; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/48.0.2564.116 Mobile Safari/537.36 T7/9.3 baiduboxapp/9.3.0.10 (Baidu; P1 5.1.1)",
  113. "三星GALAXY C7" => "Mozilla/5.0 (Linux; U; Android 6.0.1; zh-CN; SM-C7000 Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.6.2.948 Mobile Safari/537.36",
  114. "三星GALAXY S8" => "Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; SM-G9500 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.7.0.953 Mobile Safari/537.36",
  115. "荣耀8青春版" => "Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; PRA-AL00 Build/HONORPRA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.7.0.953 Mobile Safari/537.36",
  116. "UCOpenwave" => "Openwave/ UCWEB7.0.2.37/28/999",
  117. "UC Opera" => "Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999",
  118. "小米4S" => "Mozilla/5.0 (Linux; U; Android 5.1.1; zh-cn; MI 4S Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.146 Mobile Safari/537.36 XiaoMi/MiuiBrowser/9.1.3",
  119. "OPPO R12" => "Mozilla/5.0 (Linux; U; Android 7.1.1; zh-CN; OPPO R11 Build/NMF26X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.7.0.953 Mobile Safari/537.36",
  120. "iPhone2" => "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MicroMessenger/6.5.7 NetType/WIFI Language/zh_CN",
  121. ];
  122. return $agentarry[array_rand($agentarry, 1)];
  123. }
  124. // ## 短信验证码
  125. private function encode($str)
  126. {
  127. $res = urlencode($str);
  128. $res = preg_replace("/\+/", "%20", $res);
  129. $res = preg_replace("/\*/", "%2A", $res);
  130. $res = preg_replace("/%7E/", "~", $res);
  131. return $res;
  132. }
  133. private function fetchContent($url, $method, $body)
  134. {
  135. $ch = curl_init();
  136. if ($method == 'POST') {
  137. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  138. curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
  139. } else {
  140. $url .= '?' . $body;
  141. }
  142. curl_setopt($ch, CURLOPT_URL, $url);
  143. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  144. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  145. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  146. "x-sdk-client" => "php/2.0.0"
  147. ));
  148. if (substr($url, 0, 5) == 'https') {
  149. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  150. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  151. }
  152. $rtn = curl_exec($ch);
  153. if ($rtn === false) {
  154. // 大多由设置等原因引起,一般无法保障后续逻辑正常执行,
  155. // 所以这里触发的是E_USER_ERROR,会终止脚本执行,无法被try...catch捕获,需要用户排查环境、网络等故障
  156. trigger_error("[CURL_" . curl_errno($ch) . "]: " . curl_error($ch), E_USER_ERROR);
  157. }
  158. curl_close($ch);
  159. return $rtn;
  160. }
  161. public function senCode(){
  162. $accessKeyId = 'LTAI5tMnwbRaFFNegZABs1i9';
  163. $accessKeySecret = '1AFchDeuPoytXzcCD8HUU4gsMizwn3';
  164. $params = [
  165. 'PhoneNumbers' => '13121776520',
  166. 'SignName' => '祈盟',
  167. 'TemplateCode' => 'SMS_496015161',
  168. 'TemplateParam' => json_encode(['name' => '顾长歌', 'money' => 999], JSON_UNESCAPED_UNICODE),
  169. ];
  170. $params = array_merge($params, [
  171. "RegionId" => "cn-hangzhou",
  172. "Action" => "SendSms",
  173. "Version" => "2017-05-25",
  174. ]);
  175. $apiParams = array_merge([
  176. "SignatureMethod" => "HMAC-SHA1",
  177. "SignatureNonce" => uniqid(mt_rand(0,0xffff), true),
  178. "SignatureVersion" => "1.0",
  179. "AccessKeyId" => $accessKeyId,
  180. "Timestamp" => gmdate("Y-m-d\TH:i:s\Z"),
  181. "Format" => "JSON",
  182. ], $params);
  183. // dump($apiParams);
  184. ksort($apiParams);
  185. $sortedQueryStringTmp = "";
  186. foreach ($apiParams as $key => $value) {
  187. $sortedQueryStringTmp .= "&" . $this->encode($key) . "=" . $this->encode($value);
  188. }
  189. $stringToSign = "POST&%2F&" . $this->encode(substr($sortedQueryStringTmp, 1));
  190. $sign = base64_encode(hash_hmac("sha1", $stringToSign, $accessKeySecret . "&",true));
  191. $signature = $this->encode($sign);
  192. $content = $this->fetchContent("http://dysmsapi.aliyuncs.com/", "POST", "Signature={$signature}{$sortedQueryStringTmp}");
  193. dump($content);
  194. }
  195. public function pay(){
  196. die;
  197. // 根据域名获取发起支付URL
  198. // http://devsdkapi.youxi9.com/test_pay?customMoney=1
  199. // http://devsdkapi.qmgames.cn/test_pay?customMoney=1
  200. // http://sdkapi.newsdk.com/test_pay?customMoney=1
  201. // http://sdkapi.newsdk.com/test_pay
  202. // 根据URL做跳转
  203. // $pay_url = input('pay_url');
  204. // if($pay_url){
  205. // $this->assign('pay_url', $pay_url);
  206. // return $this->fetch();
  207. // }else{
  208. // 直接生成订单,发起支付
  209. $pay = new PayService();
  210. $notify_url = Config::get('wxpay-h5')['notify_url'];
  211. $ip = $_SERVER['REMOTE_ADDR'] ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
  212. $orderid = 'DT'. time(). mt_rand(10000000,99999999);
  213. $payInfoRes = $pay->getWxpayH5Param($orderid, 1, "测试商品", $ip, $notify_url);
  214. $pay_url = "http://devsdkapi.youxi9.com/test_pay?pay_url=".$payInfoRes['data']['mweb_url'];
  215. // header("Location: {$pay_url}");
  216. // }
  217. $this->assign('pay_url', $pay_url);
  218. return $this->fetch();
  219. }
  220. public function notify(){
  221. // 根据域名获取发起支付URL
  222. // http://sdkapi.newsdk.com/notify
  223. // $input = '{"gmt_create":"2026-04-16 20:33:08","charset":"utf-8","seller_email":"coolpads@126.com","notify_time":"2026-04-16 22:30:48","subject":"\u7279\u60e0\u793c\u5305","sign":"YsAqB42sE4rXglnlAo0rls1RaeP8xyznILR55y+IUK8oge2ktIBI+N9YqUu+GzOIomMzO5yhnMWvrdG\/xUa+Usop6gJZOPAYDpUON8pmYWunRoPWr9b1vEh+hVQFMxM4rQePyDx3e7gJ8GlpxEgrGohjJt2XETQyOSxKIXyRkENFKNxW93KwLp4gKNcLvB\/NutK4schqNtBaTuXrWIUX07bMDq7PAlzG7iOnFuNoouLwEAgMKHuzUSawgs7eD40No3FoDRZzJIhehyca9ZNTjGfMU\/dNF\/FOg+QHuyEmK6tvDICRYkwHOIQ0w099W\/1ToXyLp4aoYZMrq5HpQ+Y\/gA==","buyer_id":"2088822405920853","version":"1.0","notify_id":"2026041601222210402020851433505728","notify_type":"trade_status_sync","out_trade_no":"WL17763427819316214057","total_amount":"10.50","refund_fee":"0.00","trade_status":"TRADE_CLOSED","trade_no":"2026041623001420851437484237","auth_app_id":"2021002136682180","buyer_logon_id":"177****2043","gmt_close":"2026-04-16 21:04:02","app_id":"2021002136682180","sign_type":"RSA2","seller_id":"2088141187506144"}';
  224. // $result = json_decode($input, true);
  225. // dump($result);
  226. // $orderid = 'DT'. time(). mt_rand(10000000,99999999);
  227. // $orderid = 'WL17769362780609203154';
  228. $orderid = 'WL17803075011896409072';
  229. $orderid = 'WL17803175979579639315';
  230. $refundData = [
  231. "out_trade_no" => $orderid, // 商户订单号
  232. // "order_no" => $order_no, // 交易流水号
  233. "out_refund_no" => $orderid.'_T', // 商户退款单号
  234. "refund_amount" => "0.01", // 退款金额(元)
  235. "refund_reason" => "订单已取消,系统自动退款处理", // 退款原因
  236. ];
  237. // $refundRsult = \app\common\factory\Pay::makeRefund('ali_pay', $refundData);
  238. // $refundRsult = \app\common\factory\Pay::makeQuery('xty_pay', $refundData);
  239. // $refundRsult = \app\common\factory\Pay::makeRefund('xty_pay', $refundData);
  240. // $refundRsult = \app\common\factory\Pay::makeQuery('qzl_pay', $refundData);
  241. $refundRsult = \app\common\factory\Pay::makeRefund('qzl_pay', $refundData);
  242. dump("notify: ", $refundRsult);
  243. }
  244. // 接口测试专用
  245. public function wen_test()
  246. {
  247. // http://sdkapi.newsdk.com/index/wen_test
  248. // // 调用系统内置命令,例如 optimize:schema
  249. // Console::call('ComplexSummaryGameServer', ['day'=>'2025-12-21']);
  250. // // // 调用自定义命令,并传参
  251. // $input = new Input(['day', '2025-12-17']);
  252. // $output = new Output();
  253. // Console::call('ComplexSummaryComplex', $input->getArguments(), $output);
  254. // // 获取命令输出内容
  255. // echo $output->fetch();
  256. // die;
  257. // dump(strtotime("2025-10-30 23:59:59"));
  258. // dump(date("Y-m-d H:i:s", 1761799926), date("Y-m-d H:i:s", 1761809613));
  259. // ## Hi支付测试
  260. $payData = [
  261. 'productname' => '测试商品',
  262. 'attach' => 'DT'. time(). mt_rand(10000000, 99999999),
  263. 'amount' => 0.01,
  264. 'notify_url' => 'http://devsdkapi.qmgames.cn/payNotify',
  265. ];
  266. $pay = new PayService();
  267. $result = $pay->getSywPayParam($payData, 'wxh5');
  268. // dump($result);
  269. dump("http://qmpay.youxi9.com/?orderid=".$payData['attach']."&payurl=".$result['data']['mweb_url']);
  270. // header("Location: " . $result['data']);
  271. $mweb_url = $result['data'];
  272. // $this->assign('data', $result['data']);
  273. // $this->fetch();
  274. // die;
  275. // $res = (new HandleService())->getCacheGiftNum();
  276. // dump($res);
  277. // ## 短信
  278. // config('ALI_SMS.channelAdvanceMobile')
  279. // $result = (new \app\common\library\Sms)->sendNotify('13121776520', 'SMS_496015161', ['name' => 'xxx', 'money' => 999]);
  280. // dump($result);
  281. // ## 发起支付测试
  282. // $orderid = makeOrderid();
  283. // $notify_url = Config::get('wxpay-h5')['notify_url'];
  284. // $result = (new PayService)->getHipayWxpayH5Param($orderid, 0.01, $notify_url, '测试商品', request()->ip(), 10);
  285. // dump($result);
  286. // ## 旅人三区活动
  287. // $res = (new LvRenSdk())->sendRewards('103523_stable', '10082', '1008200125959', '250225', '1'); // 发放集结礼包
  288. // $res = (new LvRenSdk())->getRoleList('103523_stable', '10082');
  289. // $res = (new LvRenSdk())->getTagAndValByRole('10082', '1008200125959'); // 获取角色活动标签
  290. // $res = (new LvRenSdk())->getRoleList('267973_stable', '10083'); // 账户角色数据
  291. // $res = (new LvRenSdk())->getTagAndValByRole('10083', '1008300003478'); // 获取角色活动标签
  292. // $res = (new LvRenSdk())->getRoleList('213910_stable', '10082');
  293. // $res = (new LvRenSdk())->getTagAndValByRole('10082', '1008100200674'); // 获取角色活动标签
  294. //
  295. // dump($res);
  296. // $res = Db::query("UPDATE `new_sdk`.`cy_members` SET `amount` = 4.5 WHERE `id` = 153196");
  297. // dump($res);
  298. // ## 订单号
  299. // dump(makeOrderid());
  300. // 加密
  301. // $password = auth_code('123456', "ENCODE", Env::get('auth_key'));
  302. //
  303. // dump(urlEncode('J3YrYmrn7cOLBjIubTOz5HavJg39G3C40T/voMiuvR2nSIt5LknEs4r+o+MwVWho57cSBzGjOcF/sTB4HjhF8/W9ol0'));
  304. // // 解密
  305. // $password1 = auth_code('msVNNwhwHMAs8wiDo5Y6p07mK/EGEcrq2iUQX0vfiGxQE7jjkqj/B50uKYQxEhnzPpbUB9Kh7C/j3tOl+n8aoRmOfL1+kDBHOmTs8y7WKnzjPUnCDbu85EJBnf+3l2JlkiByW/JkWkjAMCfZf7YK3ZbzuxE0xJmunQwAIFuP0+Hey9+L84Jz0da9XqQiBX49iJwyYJEed+NYSRL6sejjQTgoYLz1UosR3B2Kwvl+yEbDbpisGfYenT803n0kpkOOd5dgmISVI350kxYSQeu1PsvIwxXzBV+oZ+LCYO99sjiatNI66r+M0KKBQ9SM9/owr/FZEu7XdrbAKmevVlTfag==
  306. // ', "DECODE", Env::get('auth_key'));
  307. // dump($password1);
  308. // 获取支付的配置参数
  309. // $public_key = Config::get('ali_pay_config')['configs'][Config::get('ali_pay_config')['default']['zfb']]['public_key'];
  310. // dump($public_key);
  311. // dump(Config::get('ali_pay_config')['sign_type']);
  312. // 游戏订单回调签名生成 - 订单通知表: cy_paycpinfo
  313. // $str = "orderid=WL17683337938759161607&username=298960_stable&gameid=645&roleid=10924&serverid=4&paytype=xty_wx_h5&amount=98&paytime=1768333793&attach=%7B%22gameOrderId%22%3A7594935792166765171%7D&sign=608a8a8d93ed552406f0550f98a05897"; // 订单数据拿过来的时候,这里记得去除sign参数
  314. // $param = $str . "&appkey=d5bb829af0e9eb3b09f93f207c4a5364";
  315. // $md5params = md5($param);
  316. // $params = $str . "&sign=" . urlencode($md5params);
  317. // dump($params);
  318. // $params = [
  319. // "mer_id" => "55282",
  320. // "notify_url" => "http://xxx.xxx.com",
  321. // "amt_type" => "RMB",
  322. // "goods_inf" => "测试商品",
  323. // "order_id" => rand(0,
  324. // 999999999),
  325. // "mer_date" => date("Ymd"),
  326. // "amount" => "1",
  327. // // "user_ip" => "127.0.0.1",
  328. // "user_ip" => "115.196.65.151", // 要真实IP地址
  329. // "open_id" => "o0jap60RiBbxuKoiM1tWm2oyurxU",
  330. // "app_id" => "wx117849d0c0632d22",
  331. // "scancode_type" => "WECHAT",
  332. // "mer_flag" => "KMER",
  333. // ];
  334. // $service = new UmfService("55282");
  335. // $res = $service->miniProgramPayMap($params); // 小程序
  336. // // $res = $service->H5AutoConnectMap($params); // H5直连-范围URL地址
  337. // // $res = $service->H5ConnectMap($params); // H5直连-返回请求参数
  338. // dump($res);
  339. // $payData = [
  340. // 'productname' => '测试',
  341. // 'order_id' => makeOrderid(),
  342. // 'amount' => '1',
  343. // 'open_id' => $param['open_id'],
  344. // ];
  345. // // $result = (new LdysPay())->getWxmpPay($payData);
  346. // // $result = (new LdysPay())->getWxToekn($payData);
  347. // $result = (new LdysPay())->generateWxmpPayUrl();
  348. // dump($result);
  349. // $res = Db::query("UPDATE `new_sdk`.`cy_memberstwo` SET `realname` = '', `idcard` = '' WHERE `id` = 56557");
  350. // dump($res);
  351. // $jule = new Jule();
  352. // $data = [
  353. // 'account' => '{"user_code":"104471097","user_name":"jolo666","game_code":"3143016315883","session_id":"12842658","id":"1573633923000"}',
  354. // 'accountSign' => '13DersLTir22ofrzbxii4+N44gByUIZi6vg/ulP8ru9vid0GOY3sVvgSoAmBkNezKiUWEqei/gPrPERYUccbpM05yh1I4Bs81nunLx1GrlDl6FU3nPRzC4a8mtDbCcU3aZ+lzSXk/8ieymPXdrOMtq6ncmqgVf/jk2A8K151oXQ='
  355. // ];
  356. // $res = $jule->getSpecialParam($data);
  357. // dump($res);
  358. // ## 统计需要分包的相关游戏
  359. // 订单
  360. // $res = Db::query("select p.channel_id,p.gameid,g.nickname,SUM(p.amount) as sum_amount FROM cy_pay as p LEFT JOIN cy_game as g ON g.id=p.gameid where p.create_time BETWEEN 1704038400 AND 1711962953 GROUP BY p.gameid ORDER BY sum_amount desc");
  361. // 登陆
  362. // $res = Db::query("select * FROM nw_subaccount limit 1");
  363. // dump($res);
  364. // // APP 加固
  365. // $rsa = new RsaSign();
  366. // $str = '6f8ffbbc02059d05be0816953102f6cc425599';
  367. // $jiaMiRes = $rsa->openssl_public_encrypt($str);
  368. // $jieMiRes = $rsa->openssl_private_decrypt($jiaMiRes);
  369. //
  370. // // $jiaMiRes = $rsa->openssl_sign($str);
  371. // // $jieMiRes = $rsa->openssl_verify($str, $jiaMiRes);
  372. // dump($str, $jiaMiRes, $jieMiRes);
  373. // dump(json_encode(input()));
  374. // $sdk = new Yueyou();
  375. // $res = $sdk->getSpecialParam(['channel_token' => 'RT_7D535DFD85F94A2FBB01072C58610E68', 'time' => 1711079997], ['param' => '{"app_id":"1011","server_key":"rqejOC0Jep"}']);
  376. // dump($res);
  377. // 发送分包请求
  378. // $redis = Cache::init()->handler(); // 获取redis句柄
  379. // // $redis_value ='{"filename":"mubaoANDROID","channel_id":"5215","apktype":0,"extend":{"channel_version":13,"pinyin":"mubaoANDROID","channel_id":"5215","admin_id":1,"512pngUrl":"https:\/\/cdn.' . QM_DOMAIN_URL . '\/image\/game\/icons\/2023091416266502c3cc46898.png","bundleID":"com.qimeng.mubao","gameChineseName":"\u6bcd\u5305ANDROID"},"target_filename":"6601454dc8b90.apk","finish_notice_url":"http:\/\/admin.7dgames.cn\/upload_notify\/index\/game_id\/10\/channel_id\/5215\/adminid\/1\/apktype\/0.html"}';
  380. // $redis_value = '{"filename":"aaaaav1anzhuo","channel_id":"5215","apktype":0,"extend":{"channel_version":17,"pinyin":"aaaaav1anzhuo","channel_id":"5215","admin_id":1,"512pngUrl":"http:\/\/cdn.7dgame.cn\/","bundleID":"aaa.xxcc","gameChineseName":"aaaaa_v1(\u5b89\u5353)"},"target_filename":"66b46056b1b1d.apk","finish_notice_url":"http:\/\/admin.7dgames.cn\/upload_notify\/index\/game_id\/271\/channel_id\/5215\/adminid\/1\/apktype\/0.html","sign_ver":1}';
  381. // $res = $redis->lpush('aoyou:apk:subpackage:task', $redis_value);
  382. // dump($res);
  383. // ## 分包通知-ws
  384. // http://admin.7dgames.cn/upload_notify/makeExcelComplete?action=payList&adminid=1&file_path=https://static.7dgames.cn/excel_dev/20240806/充值记录管理导出_20240806144943_1.csv&time=1722926977
  385. // $ws = new Websocket();
  386. // $gamename = 'test'.'-'.'9527';
  387. // $str = '{"error_code":0,"data":{"action":"subpackageFinish","data":{"code":0,"gamename":"'.$gamename.'", "message":"分包完成!"}}}';
  388. // $res = $ws->sayToUid('1', $str);
  389. // dump($res);
  390. // $res = Db::query("SELECT * FROM `new_sdk`.`cy_members` where username='18947335139 '");
  391. // dump($res);
  392. // ## 代金卷使用通知
  393. // $res = (new \app\common\logic\YqlHandle())->notifyCoupon('206'); -- 弃用
  394. // $res = (new \app\api\controller\YqlData())->notifyCoupon('206');
  395. // dump($res);
  396. // 176 解密/加密
  397. // $a = strEncrypt("13","Su)sjKsu23G0slow");
  398. // var_dump('# $a: ', $a);
  399. // $a = 'd7afaff8a880a0fe535318299fdf80b5';
  400. // var_dump('# $b: ', strDecrypt($a,"Su)sjKsu23G0slow"));
  401. // $res = RSACryptUtil::encrypt(['xxx' => 'xxx']);
  402. // dump($res);
  403. // $signStr = sprintf('token=%s&userID=%s&key=%s', 'db733736e9613e42f81f69b4309b9dca', '13028121', '0adc300369494b5f9e195024b2bdefee');
  404. // $res = md5($signStr);
  405. // dump($signStr, $res);
  406. // 支付回调 - 微信H5
  407. // $res = '{"charset":"UTF-8","req_data":"{\"order_no\":\"1010317672024080718032424646\",\"pay_scene\":\"H5\",\"order_desc\":\"\u9053\u5177\",\"order_name\":\"\u9053\u5177\",\"pay_time\":\"20240807180351\",\"ch_order_no\":\"4200002304202408074418206630\",\"payer_account\":\"oAVOM6yBC6zrc8MdVXQAMQ9p4gyE\",\"out_trade_no\":\"WL17230250041470115375\",\"total_amount\":10,\"reserved\":\"\",\"ch_out_trade_no\":\"5150147638240807\",\"trade_status\":\"SUCCESS\",\"pay_channel\":\"WX\",\"payer_id\":\"oAVOM6yBC6zrc8MdVXQAMQ9p4gyE\"}","method":"trade.order.notify","app_id":"A17222309452323464","version":"1.0.1","sign_type":"RSA2","timestamp":"20240807180351"}';
  408. // 支付回调 - 支付宝H5
  409. // $res = '{"charset":"UTF-8","req_data":"{\"order_no\":\"1010317672024080718071324962\",\"pay_scene\":\"H5\",\"order_desc\":\"\u9053\u5177\",\"order_name\":\"\u9053\u5177\",\"pay_time\":\"20240807180752\",\"ch_order_no\":\"2024080722001456531440275398\",\"payer_account\":\"ahj***@163.com\",\"out_trade_no\":\"WL17230252337046293807\",\"total_amount\":10,\"reserved\":\"\",\"ch_out_trade_no\":\"705150165776240807\",\"trade_status\":\"SUCCESS\",\"pay_channel\":\"ALI\",\"payer_id\":\"2088022151356531\"}","method":"trade.order.notify","app_id":"A17222309452323464","version":"1.0.1","sign_type":"RSA2","timestamp":"20240807180753"}';
  410. // dump(json_decode($res));
  411. // ## TC-喜钛游 支付
  412. // $pay = new PayService();
  413. // $data = [
  414. // "orderid" => makeOrderid(),
  415. // "productname" => '道具',
  416. // "real_amount" => '0.01',
  417. // "notify_url" => Config::get('xty_pay')['notify']['notify_url'],
  418. // "ip" => request()->ip(),
  419. // ];
  420. // $payInfoRes = $pay->getXtyPayParam($data, 'payWxH5');
  421. // // $payInfoRes = $pay->getXtyPayParam($data, 'payAliH5');
  422. // dump($payInfoRes);
  423. // $randomList = [
  424. // ['pay_scene' => 'wx_h5', 'game_id' => 10, 'version' => 'v3.4.4'],
  425. // ['pay_scene' => 'wx_h5', 'game_id' => 266, 'version' => 'v3.4.4'],
  426. // ['pay_scene' => 'wx_h5', 'game_id' => 256, 'version' => 'v3.4.4'],
  427. // ['pay_scene' => 'wx_h5', 'game_id' => 20, 'version' => 'v3.4.3'],
  428. // ['pay_scene' => 'wx_h5', 'game_id' => 259, 'version' => 'v3.4.3'],
  429. // ];
  430. // $countNum = ['qzl_wx_h5' => 0, 'ldys_wx_h5' => 0, 'ybzf_wxmp_h5' => 0, 'yyyb_wx_h5' => 0, 'xty_wx_h5' => 0, 'qmf_wxmp_h5' => 0];
  431. // for ($i = 0; $i < 100; $i++) {
  432. // // $info =
  433. // // 随机获取$randomList数据总数中的一条
  434. // $data = $randomList[array_rand($randomList)];
  435. // $newPayType = (new PayHandle())->getPayChannel($data['pay_scene'], $data['game_id'], $data['version']);
  436. // $countNum[$newPayType['data']['paytype']] = $countNum[$newPayType['data']['paytype']] + 1;
  437. // echo "<br />" . $newPayType['data']['paytype'] . ' - ' . $data['game_id'];
  438. // }
  439. // dump($countNum);
  440. }
  441. // shop 测试订单生成
  442. public function wxPay()
  443. {
  444. $money = input('customMoney');
  445. if (!$money) {
  446. return json_encode(['code' => 0, 'msg' => '请输入金额!', 'data' => '']);
  447. }
  448. $title = input('title', '购买商品');
  449. $pay = new PayService();
  450. $notify_url = Config::get('wxpay-h5')['notify_url'];
  451. $ip = $_SERVER['REMOTE_ADDR'] ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
  452. $payInfoRes = $pay->getWxpayH5Param(makeUniqueid('API'), $money, $title, $ip, $notify_url);
  453. if($payInfoRes['error'] == true){
  454. return json_encode(['data' => '', 'code' => 0, 'msg' => $payInfoRes['msg']]);
  455. }
  456. // $payInfoRes['data']['mweb_url'] = 'http://sdkapi.'.QM_DOMAIN_URL.'/jump?key=' . base64_encode($payInfoRes['data']['mweb_url']);
  457. // $payInfoRes['data']['mweb_url'] = 'http://devsdkapi.youxi9.com/jump?key=' . base64_encode($payInfoRes['data']['mweb_url']);
  458. return json_encode(['data' => $payInfoRes['data'], 'code' => 1, 'msg' => '订单生成成功']);
  459. }
  460. // 会长数据迁移
  461. public function migrate_hz(){
  462. $qy_id = input('qy_id', ''); // 迁移的会长
  463. $js_id = input('js_id', ''); // 接收会长
  464. if(!$qy_id || !$js_id){
  465. return json_encode(["code" => 100, "message" => "缺少迁移或接收会长", "data" => ""]);
  466. }
  467. // 迁移会长
  468. $qy_info = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id' => $qy_id, 'level' => 1])->find();
  469. $js_info = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id' => $js_id, 'level' => 1])->find();
  470. // $id_path = $info['id_path'].$info['id'].',';
  471. // ## 数据统计 ##
  472. // 子会长
  473. $qy_child_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $qy_id, 'level' => 2])->count();
  474. $js_child_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $js_id, 'level' => 2])->count();
  475. // dump($qy_child_count, $js_child_count);
  476. $qy_child_id_path = $qy_info['id_path'].$qy_info['id'].',';
  477. $js_child_id_path = $js_info['id_path'].$js_info['id'].',';
  478. // dump($qy_child_id_path, $js_child_id_path);
  479. // 推广员
  480. $qy_promoter_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id_path' => ['like', '%'.$qy_child_id_path.'%'], 'level' => 3])->count();
  481. $js_promoter_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id_path' => ['like', '%'.$js_child_id_path.'%'], 'level' => 3])->count();
  482. // dump($qy_promoter_count, $js_promoter_count);
  483. $statisticsData = [
  484. // 迁移
  485. 'qy' => [
  486. 'child_count' => $qy_child_count,
  487. 'promoter_count' => $qy_promoter_count,
  488. ],
  489. // 接收
  490. 'js' => [
  491. 'child_count' => $js_child_count,
  492. 'promoter_count' => $js_promoter_count,
  493. ],
  494. // 汇总
  495. 'hz' => [
  496. 'child_count' => $qy_child_count+$js_child_count,
  497. 'promoter_count' => $qy_promoter_count+$js_promoter_count,
  498. ],
  499. // 实际数据(处理后)
  500. 'sj' => [
  501. 'child_count' => 0,
  502. 'promoter_count' => 0,
  503. ],
  504. // 程序处理
  505. 'cx' => [
  506. 'child_count' => 0,
  507. 'promoter_count' => 0,
  508. ],
  509. ];
  510. // dump($statisticsData);
  511. // 子会长
  512. $child_list = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $qy_info['id'], 'level' => 2])->select();
  513. $child_list_ids = array_column($child_list, 'id');
  514. $child_sql = [];
  515. $child_count = 0;
  516. $promoter_count = 0;
  517. $id_path = $js_info['id_path'].$js_info['id'].',';
  518. foreach ($child_list as $v){
  519. $child_count++;
  520. $child_sql[] = [
  521. 'id' => $v['id'],
  522. 'parent_id' => $js_info['id'],
  523. 'id_path' => $id_path,
  524. ];
  525. // $v['parent_ids'] = $js_info['id'];
  526. // $v['id_paths'] = $id_path;
  527. // $child_sql[] = $v;
  528. // 推广员
  529. $promoter_list = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => ['in', $child_list_ids], 'level' => 3])->select();
  530. $vp_id_path = $id_path.$v['id'].',';
  531. foreach ($promoter_list as $vp){
  532. $promoter_count++;
  533. $child_sql[] = [
  534. 'id' => $vp['id'],
  535. 'parent_id' => $v['id'],
  536. 'id_path' => $vp_id_path,
  537. ];
  538. }
  539. }
  540. // return (json_encode($child_sql));
  541. // 启动事务
  542. // Db::startTrans();
  543. // try {
  544. // $channel = new Channel();
  545. // if (!$res = $channel->saveAll($child_sql)) {
  546. // // 回滚事务
  547. // Db::rollback();
  548. // throw new \Exception('迁移失败!');
  549. // }
  550. // Cache::clear('channel_cache');
  551. //
  552. // // 提交事务
  553. // Db::commit();
  554. //
  555. // } catch (\Exception $e) {
  556. // // 回滚事务
  557. // Db::rollback();
  558. // return json_encode(['code' => 0, 'msg' => '操作失败:' . $e->getMessage()]);
  559. // }
  560. // ## 数据统计
  561. $js_child_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $js_id, 'level' => 2])->count();
  562. $js_child_id_path = $js_info['id_path'].$js_info['id'].',';
  563. // 推广员
  564. $js_promoter_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id_path' => ['like', '%'.$js_child_id_path.'%'], 'level' => 3])->count();
  565. $statisticsData['sj'] = [
  566. 'child_count' => $js_child_count,
  567. 'promoter_count' => $js_promoter_count,
  568. ];
  569. $statisticsData['cx'] = [
  570. 'count' => count($child_sql),
  571. 'child_count' => $child_count,
  572. 'promoter_count' => $promoter_count,
  573. ];
  574. return json_encode(['code' => 0, 'msg' => '操作成功', 'data' => $statisticsData]);
  575. }
  576. // 商务账号下的会长数据迁移
  577. public function migrate_sw(){
  578. $qy_id = input('qy_id', ''); // 迁移的商务
  579. $js_id = input('js_id', ''); // 接收的商务
  580. if(!$qy_id || !$js_id){
  581. return json_encode(["code" => 100, "message" => "缺少迁移或接收商务", "data" => ""]);
  582. }
  583. // 迁移的商务
  584. $qy_info = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id' => $qy_id, 'level' => 0, 'parent_id' => 0])->find();
  585. $js_info = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id' => $js_id, 'level' => 0, 'parent_id' => 0])->find();
  586. $qy_path = ','.$qy_info['id'].',';
  587. $js_path = ','.$js_info['id'].',';
  588. // dump($qy_path,' - ', $js_path);
  589. // TODO: 以下流程只是复制上边的,还未完善。等韩辉后续需要再说。
  590. // 迁移的会长
  591. $qy_ids = [''];
  592. $qy_info = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $qy_info['id'], 'level' => 1])->find();
  593. $js_info = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $js_info['id'], 'level' => 1])->find();
  594. // $id_path = $info['id_path'].$info['id'].',';
  595. // ## 数据统计 ##
  596. // 子会长
  597. $qy_child_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $qy_id, 'level' => 2])->count();
  598. $js_child_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $js_id, 'level' => 2])->count();
  599. // dump($qy_child_count, $js_child_count);
  600. $qy_child_id_path = $qy_info['id_path'].$qy_info['id'].',';
  601. $js_child_id_path = $js_info['id_path'].$js_info['id'].',';
  602. // dump($qy_child_id_path, $js_child_id_path);
  603. // 推广员
  604. $qy_promoter_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id_path' => ['like', '%'.$qy_child_id_path.'%'], 'level' => 3])->count();
  605. $js_promoter_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id_path' => ['like', '%'.$js_child_id_path.'%'], 'level' => 3])->count();
  606. // dump($qy_promoter_count, $js_promoter_count);
  607. $statisticsData = [
  608. // 迁移
  609. 'qy' => [
  610. 'child_count' => $qy_child_count,
  611. 'promoter_count' => $qy_promoter_count,
  612. ],
  613. // 接收
  614. 'js' => [
  615. 'child_count' => $js_child_count,
  616. 'promoter_count' => $js_promoter_count,
  617. ],
  618. // 汇总
  619. 'hz' => [
  620. 'child_count' => $qy_child_count+$js_child_count,
  621. 'promoter_count' => $qy_promoter_count+$js_promoter_count,
  622. ],
  623. // 实际数据(处理后)
  624. 'sj' => [
  625. 'child_count' => 0,
  626. 'promoter_count' => 0,
  627. ],
  628. // 程序处理
  629. 'cx' => [
  630. 'child_count' => 0,
  631. 'promoter_count' => 0,
  632. ],
  633. ];
  634. // dump($statisticsData);
  635. // 子会长
  636. $child_list = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $qy_info['id'], 'level' => 2])->select();
  637. $child_list_ids = array_column($child_list, 'id');
  638. $child_sql = [];
  639. $child_count = 0;
  640. $promoter_count = 0;
  641. $id_path = $js_info['id_path'].$js_info['id'].',';
  642. foreach ($child_list as $v){
  643. $child_count++;
  644. $child_sql[] = [
  645. 'id' => $v['id'],
  646. 'parent_id' => $js_info['id'],
  647. 'id_path' => $id_path,
  648. ];
  649. // $v['parent_ids'] = $js_info['id'];
  650. // $v['id_paths'] = $id_path;
  651. // $child_sql[] = $v;
  652. // 推广员
  653. $promoter_list = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => ['in', $child_list_ids], 'level' => 3])->select();
  654. $vp_id_path = $id_path.$v['id'].',';
  655. foreach ($promoter_list as $vp){
  656. $promoter_count++;
  657. $child_sql[] = [
  658. 'id' => $vp['id'],
  659. 'parent_id' => $v['id'],
  660. 'id_path' => $vp_id_path,
  661. ];
  662. }
  663. }
  664. // return (json_encode($child_sql));
  665. // 启动事务
  666. // Db::startTrans();
  667. // try {
  668. // $channel = new Channel();
  669. // if (!$res = $channel->saveAll($child_sql)) {
  670. // // 回滚事务
  671. // Db::rollback();
  672. // throw new \Exception('迁移失败!');
  673. // }
  674. // Cache::clear('channel_cache');
  675. //
  676. // // 提交事务
  677. // Db::commit();
  678. //
  679. // } catch (\Exception $e) {
  680. // // 回滚事务
  681. // Db::rollback();
  682. // return json_encode(['code' => 0, 'msg' => '操作失败:' . $e->getMessage()]);
  683. // }
  684. // ## 数据统计
  685. $js_child_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['parent_id' => $js_id, 'level' => 2])->count();
  686. $js_child_id_path = $js_info['id_path'].$js_info['id'].',';
  687. // 推广员
  688. $js_promoter_count = Db::name('nw_channel')->field('id,name,parent_id,level,id_path')->where(['id_path' => ['like', '%'.$js_child_id_path.'%'], 'level' => 3])->count();
  689. $statisticsData['sj'] = [
  690. 'child_count' => $js_child_count,
  691. 'promoter_count' => $js_promoter_count,
  692. ];
  693. $statisticsData['cx'] = [
  694. 'count' => count($child_sql),
  695. 'child_count' => $child_count,
  696. 'promoter_count' => $promoter_count,
  697. ];
  698. return json_encode(['code' => 0, 'msg' => '操作成功', 'data' => $statisticsData]);
  699. }
  700. // 空方法
  701. public function _empty()
  702. {
  703. return "url error!";
  704. }
  705. // 微信小程序跳转
  706. public function wxmp()
  707. {
  708. $url = input('url');
  709. if ($url) {
  710. header("location: " . $url);
  711. }
  712. }
  713. // 魔力宝贝推广页地址 - 2024.05.17
  714. public function mlbbDownload()
  715. {
  716. $code = input('code', '');
  717. $img_status = true;
  718. if (!$code) {
  719. $img_status = false;
  720. }
  721. $code = base64_decode($code);
  722. $code = str_replace('@qm_mlbb', "", $code);
  723. $url_host = QM_DOMAIN_URL;
  724. $file_url = "https://sdkdown.{$url_host}/game_mlbb/app/{$code}.plist";
  725. $this->assign('img_status', $img_status);
  726. $this->assign('file_url', $file_url);
  727. return $this->fetch();
  728. }
  729. // 批量获取推广标识
  730. public function getMlbbCode()
  731. {
  732. $pix = 'mlbb_';
  733. // $arr = [];
  734. // for ($i = 21; $i <= 100; $i++) {
  735. // $paddedNumber = str_pad($i, 4, '0', STR_PAD_LEFT);
  736. //
  737. // // if (intval($i / 10) = 0) {
  738. // //
  739. // // }
  740. // $code = $pix . $paddedNumber;
  741. // // echo $code . ' = https://t.'.QM_DOMAIN_URL.'/mlbb/' . base64_encode($code . '@qm_mlbb') . "<br />";
  742. // echo 'https://t.'.QM_DOMAIN_URL.'/mlbb/' . base64_encode($code . '@qm_mlbb') . "<br />";
  743. // // if (intval($i % 10) === 0) {
  744. // // echo $i . "<br />";
  745. // // }
  746. //
  747. //
  748. // // $arr[$i] = [
  749. // // 'title' => $code,
  750. // // 'code' => base64_encode($code . '@qm_mlbb'),
  751. // // ];
  752. // }
  753. //
  754. // dump($arr);
  755. $name = input('name', '');
  756. $code = $pix . $name;
  757. // 范例文件:public/mubao/mlbb_1001.plist
  758. return 'https://t.'.QM_DOMAIN_URL.'/mlbb/' . base64_encode($code . '@qm_mlbb');
  759. }
  760. }