merchant.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  1. <?php
  2. /**
  3. * 机构管理界面
  4. *
  5. **by 好商城V3 www.33hao.com 运营版*/
  6. defined('InShopNC') or exit('Access Invalid!');
  7. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  8. require_once(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
  9. require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
  10. class merchantControl extends SystemControl
  11. {
  12. const EXPORT_SIZE = 1000;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. Language::read('merchant');
  17. }
  18. /**
  19. * 机构列表
  20. */
  21. public function merchantOp()
  22. {
  23. $model_merchant = Model('merchant');
  24. if (trim($_GET['merchant_name']) != '') {
  25. $condition['name'] = ['like', '%' . $_GET['merchant_name'] . '%'];
  26. Tpl::output('merchant_name', $_GET['merchant_name']);
  27. }
  28. $merchant_list = $model_merchant->getMerchantList($condition, 25, 'available_predeposit desc');
  29. $merchant_state_text = ['使用中', '已禁用'];
  30. Tpl::output('merchant_state_text', $merchant_state_text);
  31. Tpl::output('merchant_list', $merchant_list);
  32. Tpl::output('page', $model_merchant->showpage('2'));
  33. Tpl::showpage('merchant.index');
  34. }
  35. public function changeStateOp()
  36. {
  37. $mchid = intval($_GET['mchid']);
  38. $state = intval($_GET['state']);
  39. $model_merchant = Model('merchant');
  40. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  41. if (empty($merchant_info) || !in_array($state, [1, 2])) {
  42. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  43. }
  44. $resp = $model_merchant->editMerchant(['merchant_state' => $state], ['mchid' => $mchid]);
  45. if (!$resp) {
  46. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  47. }
  48. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  49. }
  50. /**
  51. * 新增机构
  52. */
  53. public function merchant_addOp()
  54. {
  55. if (chksubmit()) {
  56. /**
  57. * 验证
  58. */
  59. $obj_validate = new Validator();
  60. $obj_validate->validateparam = [
  61. ["input" => $_POST["name"], "require" => "true", "message" => '机构账号不能为空'],
  62. ["input" => $_POST["company_name"], "require" => "true", "message" => '机构公司名称不能为空'],
  63. ["input" => $_POST["password"], "require" => "true", "message" => '密码不能为空']
  64. ];
  65. $error = $obj_validate->validate();
  66. if ($error != '') {
  67. showMessage($error);
  68. } else {
  69. $name = trim($_POST['name']);
  70. $company_name = trim($_POST['company_name']);
  71. $pwd = trim($_POST['password']);
  72. $alarm_amount = $_POST['alarm_amount'] ?? 0;
  73. $model_merchant = Model('merchant');
  74. $model_member = Model('member');
  75. try {
  76. $trans = new trans_wapper($model_merchant, __METHOD__);
  77. $insert_member['member_name'] = md5($name . time());
  78. $insert_member['member_passwd'] = $pwd;
  79. $insert_id = $model_member->addMember($insert_member);
  80. if ($insert_id == false) {
  81. $trans->rollback();
  82. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  83. }
  84. $insert_array['name'] = $name;
  85. $insert_array['company_name'] = $company_name;
  86. $insert_array['org_pwd'] = $pwd;
  87. $insert_array['password'] = md5($pwd);
  88. $insert_array['admin_id'] = trim($insert_id);
  89. $insert_array['alarm_amount'] = $alarm_amount;
  90. $result = $model_merchant->addMerchant($insert_array);
  91. if ($result) {
  92. $url = [
  93. [
  94. 'url' => 'index.php?act=merchant&op=merchant',
  95. 'msg' => '返回机构列表',
  96. ],
  97. [
  98. 'url' => 'index.php?act=merchant&op=merchant_add',
  99. 'msg' => '继续新增机构',
  100. ],
  101. ];
  102. $this->log('添加机构:' . '[ ' . $_POST['name'] . ']', 1);
  103. showMessage('机构添加成功', $url);
  104. } else {
  105. showMessage('机构添加失败');
  106. }
  107. $trans->commit();
  108. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  109. } catch (Exception $e) {
  110. $trans->rollback();
  111. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  112. }
  113. }
  114. }
  115. Tpl::showpage('merchant.add');
  116. }
  117. public function merchant_editOp()
  118. {
  119. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  120. $model_merchant = Model('merchant');
  121. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  122. if (empty($merchant)) {
  123. showMessage('机构信息有误');
  124. }
  125. if (chksubmit()) {
  126. $update['company_name'] = trim($_POST['company_name']);
  127. $update['org_pwd'] = trim($_POST['password']);
  128. $update['password'] = md5($update['org_pwd']);
  129. $update['alarm_amount'] = $_POST['alarm_amount'] ?? 0;
  130. $update['credit_bonus'] = ncPriceFormat($_POST['credit_bonus']);
  131. $update['time_out'] = intval($_POST['time_out']);
  132. $update['quality'] = intval($_POST['quality']);
  133. $member_id = $merchant['admin_id'];
  134. try {
  135. $model_merchant = Model('merchant');
  136. $trans = new trans_wapper($model_merchant, __METHOD__);
  137. if ($merchant['credit_bonus'] == $update['credit_bonus']) {
  138. unset($update['credit_bonus']);
  139. } elseif ($merchant['credit_bonus'] > $update['credit_bonus']) {
  140. $credit_bonus = ncPriceFormat($merchant['credit_bonus'] - $update['credit_bonus']);
  141. $this->credit_save_money($credit_bonus, 2, $member_id);
  142. } elseif ($merchant['credit_bonus'] < $update['credit_bonus']) {
  143. $credit_bonus = ncPriceFormat($update['credit_bonus'] - $merchant['credit_bonus']);
  144. $this->credit_save_money($credit_bonus, 1, $member_id);
  145. }
  146. $result = $model_merchant->editMerchant($update, ['mchid' => $mchid]);
  147. if (!$result) {
  148. $trans->rollback();
  149. showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
  150. }
  151. $this->log('编辑机构:' . '[ ' . $merchant['name'] . ']', 1);
  152. $trans->commit();
  153. showMessage('机构编辑成功', 'index.php?act=merchant&op=merchant');
  154. } catch (Exception $e) {
  155. $trans->rollback();
  156. showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
  157. }
  158. }
  159. Tpl::output('merchant', $merchant);
  160. Tpl::showpage('merchant.edit');
  161. }
  162. private function credit_save_money($money, $operatetype, $member_id, $bz = '')
  163. {
  164. $obj_member = Model('member');
  165. $member_id = intval($member_id);
  166. $member_info = $obj_member->getMemberInfo(['member_id' => $member_id]);
  167. $admininfo = $this->getAdminInfo();
  168. switch ($operatetype) {
  169. case 1:
  170. $admin_act = "sys_add_money";
  171. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】,预存款【增加】,金额为" . $money;
  172. break;
  173. case 2:
  174. $admin_act = "sys_del_money";
  175. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】,预存款【减少】,金额为" . $money;
  176. break;
  177. default:
  178. return [false, '调节类型错误'];
  179. break;
  180. }
  181. $model_pd = Model('predeposit');
  182. //调节预存款
  183. $data = [];
  184. $data['member_id'] = $member_info['member_id'];
  185. $data['member_name'] = $member_info['member_name'];
  186. $data['amount'] = $money;
  187. $data['order_sn'] = '';
  188. $data['admin_name'] = $admininfo['name'];
  189. $data['pdr_sn'] = '';
  190. $data['lg_desc'] = $bz ? $bz : '管理员操作客户授信,更改会员余额。';
  191. $model_pd->changePd($admin_act, $data);
  192. $this->log($log_msg, 1);
  193. return [true, 'success'];
  194. }
  195. public function priceOp()
  196. {
  197. $quality = $_GET['quality'] ? $_GET['quality'] : 1;
  198. if (chksubmit()) {
  199. $mchid = $_POST['mchid'];
  200. //合并表单数据
  201. $card_types = $_POST['cardtype'];
  202. $specs = $_POST['spec'];
  203. $prices = $_POST['price'];
  204. foreach ($card_types as $key => $card_type) {
  205. $data['card_type'] = $card_type;
  206. $data['spec'] = intval($specs[$key]);
  207. $data['price'] = ncPriceFormat($prices[$key]);
  208. $params[] = $data;
  209. }
  210. foreach ($params as $param) {
  211. if ($param['price'] > 0) {
  212. $insert['mchid'] = $mchid;
  213. $insert['spec'] = $param['spec'];
  214. $insert['price'] = $param['price'];
  215. $insert['card_types'] = $param['card_type'];
  216. $insert['quality'] = $quality;
  217. $inserts[] = $insert;
  218. }
  219. }
  220. try {
  221. $model_merchant = Model('merchant');
  222. $trans = new trans_wapper($model_merchant, __METHOD__);
  223. //删除旧费率
  224. $model_merchant->delPrices($mchid, $quality);
  225. //更新新费率
  226. if (!empty($inserts)) {
  227. $model_merchant->insertPrices($inserts);
  228. }
  229. $trans->commit();
  230. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  231. } catch (Exception $e) {
  232. $trans->rollback();
  233. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  234. }
  235. }
  236. $mchid = $_GET['mchid'] ?? 0;
  237. $goods = $this->GoodsFormat($mchid, $quality);
  238. Tpl::output('goods', $goods);
  239. Tpl::showpage('merchant.price');
  240. }
  241. private function GoodsFormat($mchid, $quality)
  242. {
  243. $all_spector = function () {
  244. global $config;
  245. $refill_specs = $config['refill_specs'];
  246. $all_type_specs = [];
  247. foreach ($refill_specs as $scard_type => $specs) {
  248. if ($scard_type == 'petrochina') { //中石油
  249. $card_type = 1;
  250. } elseif ($scard_type == 'sinopec') { //中石化
  251. $card_type = 2;
  252. } elseif ($scard_type == 'chinamobile') { //中国移动
  253. $card_type = 4;
  254. } elseif ($scard_type == 'chinaunicom') { //中国联通
  255. $card_type = 5;
  256. } elseif ($scard_type == 'chinatelecom') { //中国电信
  257. $card_type = 6;
  258. } else {
  259. continue;
  260. }
  261. $all_type_specs[$card_type] = $specs;
  262. }
  263. $result = [];
  264. foreach ($all_type_specs as $card_type => $specs) {
  265. foreach ($specs as $spec) {
  266. $result["{$card_type}-{$spec}"] = ['card_type' => $card_type, 'spec' => $spec];
  267. }
  268. }
  269. return $result;
  270. };
  271. $merch_spector = function ($mchid, $quality) {
  272. $model_merchant = Model('merchant');
  273. $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid, 'quality' => $quality])->select();
  274. $result = [];
  275. foreach ($items as $item) {
  276. $card_types = explode(',', $item['card_types']);
  277. foreach ($card_types as $card_type) {
  278. $value['spec'] = intval($item['spec']);
  279. $result["{$card_type}-{$value['spec']}"] = ['card_type' => $card_type,
  280. 'spec' => intval($item['spec']),
  281. 'price' => $item['price']];
  282. }
  283. }
  284. return $result;
  285. };
  286. $all_cardtype_specs = $all_spector();
  287. $merch_cardtype_specs = $merch_spector($mchid, $quality);
  288. $merger = function ($all_specs, $mech_specs) {
  289. $result = [];
  290. foreach ($all_specs as $cardtype_spec => $value) {
  291. $card_name = $this->scard_type($value['card_type']);
  292. $data = [];
  293. $data['goods_name'] = $card_name;
  294. $data['card_type'] = $value['card_type'];
  295. $data['spec'] = $value['spec'];
  296. if (array_key_exists($cardtype_spec, $mech_specs)) {
  297. $data['price'] = $mech_specs[$cardtype_spec]['price'];
  298. } else {
  299. $data['price'] = 0;
  300. }
  301. $result[$value['card_type']][] = $data;
  302. }
  303. return $result;
  304. };
  305. $result = $merger($all_cardtype_specs, $merch_cardtype_specs);
  306. return $result;
  307. }
  308. public function check_merchantOp()
  309. {
  310. $mchid = trim($_GET['mchid']);
  311. if (!$mchid) {
  312. echo '';
  313. die;
  314. }
  315. $model_merchant = Model('merchant');
  316. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*');
  317. if (empty($merchant_info)) {
  318. echo '';
  319. die;
  320. }
  321. echo 'true';
  322. }
  323. /**
  324. * ajax操作
  325. */
  326. public function ajaxOp()
  327. {
  328. $model_merchant = Model('merchant');
  329. switch ($_GET['branch']) {
  330. /**
  331. * 验证机构名称是否重复
  332. */
  333. case 'check_mch_name':
  334. $condition['name'] = $_GET['name'];
  335. $list = $model_merchant->getMerchantInfo($condition);
  336. if (empty($list)) {
  337. echo 'true';
  338. } else {
  339. echo 'false';
  340. }
  341. exit;
  342. /**
  343. * 验证机构是否存在
  344. */
  345. case 'check_merchant':
  346. $condition['mchid'] = intval($_GET['mchid']);
  347. $list = $model_merchant->getMerchantInfo($condition);
  348. if (!empty($list)) {
  349. echo 'true';
  350. } else {
  351. echo 'false';
  352. }
  353. exit;
  354. }
  355. }
  356. /**
  357. * 充值申请列表
  358. */
  359. public function refill_evidenceOp()
  360. {
  361. $model_merchant = Model('merchant');
  362. $condition = [];
  363. if (trim($_GET['mch_name']) != '') {
  364. $condition['mch_name'] = ['like', '%' . $_GET['mch_name'] . '%'];
  365. Tpl::output('mch_name', $_GET['mch_name']);
  366. }
  367. $state_sel = intval($_REQUEST['state_sel']);
  368. if ($state_sel == 1) {
  369. $condition['check_time'] = 0;
  370. $condition['status'] = 1;
  371. } elseif ($state_sel == 2) {
  372. $condition['check_time'] = ['gt', 0];
  373. $condition['status'] = 2;
  374. } elseif ($state_sel == 3) {
  375. $condition['check_time'] = ['gt', 0];
  376. $condition['status'] = 3;
  377. } else {
  378. }
  379. //充值申请列表
  380. $evidence_list = $model_merchant->getRefillEvidence($condition, 20, '*,member.available_predeposit', 'refill_evidence.add_time desc');
  381. $status_text = ['申请中', '已通过', '已驳回'];
  382. $operation_text = ['未预存', '已预存'];
  383. Tpl::output('evidence_list', $evidence_list);
  384. Tpl::output('status_text', $status_text);
  385. Tpl::output('operation_text', $operation_text);
  386. Tpl::output('page', $model_merchant->showpage('2'));
  387. Tpl::showpage('merchant.refill.evidence_list');
  388. }
  389. public function check_evidenceOp()
  390. {
  391. $status = $_GET['status'];
  392. $apply_id = intval($_GET['apply_id']);
  393. if ($apply_id > 0) {
  394. $model_merchant = Model('merchant');
  395. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  396. if (empty($evidence_info)) {
  397. showMessage('充值申请不存在');
  398. }
  399. if ($status == 'pass') {
  400. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 2, 'check_time' => time()]);
  401. } elseif ($status == 'unpass') {
  402. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 3, 'check_time' => time()]);
  403. } else {
  404. }
  405. }
  406. showMessage(L('nc_common_save_succ'), urlAdmin('merchant', 'refill_evidence'));
  407. }
  408. public function rechargeOp()
  409. {
  410. if (chksubmit()) {
  411. $mchid = $this->add_money();
  412. $model_merchant = Model('merchant');
  413. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  414. if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
  415. //更新预警短信通知限制
  416. $mch_cache = rcache("merchant-notify", 'refill-');
  417. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  418. $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
  419. wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
  420. }
  421. showMessage('操作成功', 'index.php?act=merchant&op=refill_evidence');
  422. } else {
  423. $apply_id = $_GET['apply_id'];
  424. if (!empty($apply_id)) {
  425. $model_merchant = Model('merchant');
  426. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*,member.available_predeposit');
  427. Tpl::output('apply_id', $apply_id);
  428. Tpl::output('amount', $evidence_info['amount']);
  429. Tpl::output('available_predeposit', $evidence_info['available_predeposit']);
  430. }
  431. Tpl::showpage('recharge.add');
  432. }
  433. }
  434. public function recharge_manualOp()
  435. {
  436. $type = $_GET['type'] ?? $_POST['type'];
  437. if (chksubmit()) {
  438. $obj_validate = new Validator();
  439. if($type == 'add') {
  440. $obj_validate->validateparam = [
  441. ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
  442. ["input" => $_POST["bank_username"], "require" => "true", "message" => '开户人姓名不能为空'],
  443. ["input" => $_POST["bank_name"], "require" => "true", "message" => '开户银行不能为空'],
  444. ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空']
  445. ];
  446. } elseif ($type == 'edit') {
  447. $obj_validate->validateparam = [
  448. ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
  449. ["input" => $_POST["bank_username"], "require" => "true", "message" => '操作人姓名不能为空'],
  450. ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空']
  451. ];
  452. }
  453. $error = $obj_validate->validate();
  454. if ($error != '') {
  455. showMessage($error);
  456. }
  457. $mchid = $_POST["mch_id"];
  458. $model_merchant = Model('merchant');
  459. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  460. if (!$merchant_info) {
  461. showMessage('对应机构不存在');
  462. }
  463. $pointsnum = $_POST['pointsnum'];
  464. $money = abs($pointsnum);
  465. if ($money == 0) {
  466. showMessage('预存金额错误');
  467. }
  468. if(!empty($_FILES['voucher']['name'])) {
  469. $upload = new UploadFile();
  470. $upload->set('default_dir',ATTACH_UPFILE);
  471. $result = $upload->upfile('voucher');
  472. if ($result){
  473. $_POST['voucher_name'] = $upload->file_name;
  474. }else {
  475. showMessage($upload->error);
  476. }
  477. }
  478. try {
  479. $model_merchant = Model('merchant');
  480. $trans = new trans_wapper($model_merchant, __METHOD__);
  481. $member_id = $merchant_info['admin_id'];
  482. if ($pointsnum > 0) {
  483. $bz = '管理员操作手动预存金额增加';
  484. $this->credit_save_money($money, 1, $member_id, $bz);
  485. } elseif ($pointsnum < 0) {
  486. $bz = '管理员操作手动预存金额减少';
  487. $this->credit_save_money($money, 2, $member_id, $bz);
  488. } else {
  489. showMessage('预存金额错误');
  490. }
  491. $result = $this->ct_refill_evidence($_POST, $merchant_info);
  492. if (!$result) {
  493. $trans->rollback();
  494. showMessage('操作失败', 'index.php?act=merchant&op=merchant');
  495. }
  496. $trans->commit();
  497. if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
  498. //更新预警短信通知限制
  499. $mch_cache = rcache("merchant-notify", 'refill-');
  500. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  501. $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
  502. wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
  503. }
  504. showMessage('操作成功', 'index.php?act=merchant&op=refill_evidence');
  505. } catch (Exception $e) {
  506. $trans->rollback();
  507. showMessage('操作失败', 'index.php?act=merchant&op=refill_evidence');
  508. }
  509. } else {
  510. $page = "recharge.manual.{$type}";
  511. Tpl::showpage($page);
  512. }
  513. }
  514. private function ct_refill_evidence($params, $merchant_info)
  515. {
  516. $admininfo = $this->getAdminInfo();
  517. $mem_info = Model('member')->getMemberInfo(['member_id' => $merchant_info['admin_id']]);
  518. $input['mchid'] = $merchant_info['mchid'];
  519. $input['mch_name'] = $merchant_info['name'];
  520. $input['member_id'] = $merchant_info['admin_id'];
  521. $input['amount'] = $params['pointsnum'];
  522. $input['bank_username'] = $params['bank_username'];
  523. $input['bank_name'] = $params['bank_name'] ?? '';
  524. $input['bz'] = $params['pointsdesc'];
  525. $input['voucher_name'] = $params['voucher_name'] ?? '/';
  526. $input['status'] = 2;
  527. $input['is_operation'] = 2;
  528. $input['add_time'] = $input['check_time'] = time();
  529. $input['after_available'] = ncPriceFormat($mem_info['available_predeposit'] + $params['pointsnum']);
  530. $input['admin_name'] = $admininfo['name'];
  531. $input['admin_id'] = $admininfo['id'];
  532. $model_merchant = Model('merchant');
  533. return $model_merchant->addRefillEvidence($input);
  534. }
  535. public function add_money()
  536. {
  537. $obj_validate = new Validator();
  538. $obj_validate->validateparam = [
  539. ["input" => $_POST["apply_id"], "require" => "true", "message" => Language::get('admin_points_member_error_again')],
  540. ["input" => $_POST["pointsnum"], "require" => "true", 'validator' => 'Compare', 'operator' => ' >= ', 'to' => 1, "message" => Language::get('admin_points_points_min_error')]
  541. ];
  542. $error = $obj_validate->validate();
  543. if ($error != '') {
  544. showMessage($error, '', '', 'error');
  545. }
  546. $money = abs(floatval($_POST['pointsnum']));
  547. $memo = trim($_POST['pointsdesc']);
  548. if ($money <= 0) {
  549. showMessage('输入的金额必需大于0', '', 'html', 'error');
  550. }
  551. $apply_id = intval($_POST['apply_id']);
  552. $model_merchant = Model('merchant');
  553. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  554. if (!is_array($evidence_info) || count($evidence_info) <= 0) {
  555. showMessage("无效的充值申请信息", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  556. }
  557. if ($evidence_info['status'] != 2) {
  558. showMessage("该充值申请未被审核通过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  559. }
  560. if ($evidence_info['is_operation'] == 2) {
  561. showMessage("该充值申请未已被预存过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  562. }
  563. //查询会员信息
  564. $obj_member = Model('member');
  565. $member_id = intval($evidence_info['member_id']);
  566. $member_info = $obj_member->getMemberInfo(['member_id' => $member_id]);
  567. $available_predeposit = floatval($member_info['available_predeposit']);
  568. $freeze_predeposit = floatval($member_info['freeze_predeposit']);
  569. if ($_POST['operatetype'] == 2 && $money > $available_predeposit) {
  570. showMessage(('预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  571. }
  572. if ($_POST['operatetype'] == 3 && $money > $available_predeposit) {
  573. showMessage(('可冻结预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  574. }
  575. if ($_POST['operatetype'] == 4 && $money > $freeze_predeposit) {
  576. showMessage(('可恢复冻结预存款不足,会员当前冻结预存款') . $freeze_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  577. }
  578. $model_pd = Model('predeposit');
  579. $order_sn = $apply_id;
  580. $admininfo = $this->getAdminInfo();
  581. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款,金额为" . $money . ",编号为" . $order_sn;
  582. $admin_act = 'sys_add_money';
  583. switch ($_POST['operatetype']) {
  584. case 1:
  585. $admin_act = "sys_add_money";
  586. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【增加】,金额为" . $money . ",编号为" . $order_sn;
  587. break;
  588. case 2:
  589. $admin_act = "sys_del_money";
  590. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【减少】,金额为" . $money . ",编号为" . $order_sn;
  591. break;
  592. default:
  593. showMessage('操作失败', 'index.php?act=merchant&op=refill_evidence');
  594. break;
  595. }
  596. try {
  597. $trans = new trans_wapper($model_pd, __METHOD__);
  598. //扣除冻结的预存款
  599. $data = [];
  600. $data['member_id'] = $member_info['member_id'];
  601. $data['member_name'] = $member_info['member_name'];
  602. $data['amount'] = $money;
  603. $data['order_sn'] = $order_sn;
  604. $data['admin_name'] = $admininfo['name'];
  605. $data['pdr_sn'] = $order_sn;
  606. $data['lg_desc'] = $memo;
  607. $model_pd->changePd($admin_act, $data);
  608. $after_available = ncPriceFormat($available_predeposit + $evidence_info['amount']);
  609. $model_merchant->editRefillEvidence(
  610. ['apply_id' => $apply_id],
  611. ['is_operation' => 2, 'after_available' => $after_available, 'admin_id' => $admininfo['id'], 'admin_name' => $admininfo['name']]
  612. );
  613. $trans->commit();
  614. $this->log($log_msg, 1);
  615. return $evidence_info['mchid'];
  616. } catch (Exception $e) {
  617. $trans->rollback();
  618. $this->log($log_msg, 0);
  619. showMessage($e->getMessage(), 'index.php?act=merchant&op=refill_evidence', 'html', 'error');
  620. exit;
  621. }
  622. }
  623. public function checkevidenceOp()
  624. {
  625. $apply_id = trim($_GET['apply_id']);
  626. if (!$apply_id) {
  627. echo '';
  628. die;
  629. }
  630. $model_merchant = Model('merchant');
  631. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  632. if (empty($evidence_info)) {
  633. echo '';
  634. die;
  635. }
  636. echo 'true';
  637. }
  638. public function OrderQueryOp()
  639. {
  640. $model_vr_order = Model('vr_order');
  641. $condition['order_state'] = ORDER_STATE_SEND;
  642. $orders = $model_vr_order->getOrderList($condition);
  643. if (!empty($orders)) {
  644. foreach ($orders as $order) {
  645. $order_id = $order['order_id'];
  646. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  647. }
  648. }
  649. showMessage('操作成功', 'index.php?act=merchant&op=refill_order');
  650. }
  651. public function mch_notifyOp()
  652. {
  653. $model_refill_order = Model('refill_order');
  654. $condition['mch_notify_state'] = 0;
  655. $condition['inner_status'] = 0;
  656. $orders = $model_refill_order->getMerchantOrderList($condition, 1000, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  657. if (!empty($orders)) {
  658. foreach ($orders as $order) {
  659. $order_id = $order['order_id'];
  660. if ($order['order_state'] == ORDER_STATE_SEND) {
  661. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  662. } else {
  663. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  664. }
  665. }
  666. }
  667. showMessage('操作成功', 'index.php?act=merchant&op=refill_order');
  668. }
  669. public function refill_orderOp()
  670. {
  671. $model_refill_order = Model('refill_order');
  672. $condition['inner_status'] = 0;
  673. $fSingle = false;
  674. if (!empty($_GET['order_sn'])) {
  675. $condition['refill_order.order_sn'] = $_GET['order_sn'];
  676. $fSingle = true;
  677. }
  678. if (!empty($_GET['mch_order'])) {
  679. $condition['refill_order.mch_order'] = $_GET['mch_order'];
  680. $fSingle = true;
  681. }
  682. if (!empty($_GET['ch_trade_no'])) {
  683. $condition['refill_order.ch_trade_no'] = $_GET['ch_trade_no'];
  684. $fSingle = true;
  685. }
  686. if (!empty($_GET['card_no'])) {
  687. $condition['refill_order.card_no'] = $_GET['card_no'];
  688. $fSingle = true;
  689. }
  690. if (!empty($_GET['mchid'])) {
  691. $condition['refill_order.mchid'] = $_GET['mchid'];
  692. }
  693. if (!empty($_GET['channel_name'])) {
  694. $condition['refill_order.channel_name'] = $_GET['channel_name'];
  695. }
  696. if (!empty($_GET['store_id'])) {
  697. $condition['vr_order.store_id'] = $_GET['store_id'];
  698. }
  699. if (!empty($_GET['refill_amount'])) {
  700. $condition['refill_order.refill_amount'] = $_GET['refill_amount'];
  701. }
  702. if (!empty($_GET['card_type'])) {
  703. if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6'])) {
  704. $condition['refill_order.card_type'] = $_GET['card_type'];
  705. }
  706. if ($_GET['card_type'] == 'oil') {
  707. $condition['refill_order.card_type'] = ['in', ['1', '2']];
  708. }
  709. if ($_GET['card_type'] == 'phone') {
  710. $condition['refill_order.card_type'] = ['in', ['4', '5', '6']];
  711. }
  712. }
  713. $fToday = false;
  714. if (!$fSingle)
  715. {
  716. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  717. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  718. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  719. $condition['refill_order.order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  720. } elseif ($start_unixtime > 0) {
  721. $condition['refill_order.order_time'] = ['egt', $start_unixtime];
  722. } elseif ($end_unixtime > 0) {
  723. $condition['refill_order.order_time'] = ['lt', $end_unixtime];
  724. } else {
  725. $start = strtotime(date('Y-m-d', time()));
  726. $condition['refill_order.order_time'] = ['egt', $start];
  727. $fToday = true;
  728. }
  729. if (in_array($_GET['order_state'], ['0', '10', '20', '30', '40'])) {
  730. $condition['vr_order.order_state'] = $_GET['order_state'];
  731. if ($_GET['order_state'] == ORDER_STATE_SEND) {
  732. if ($_GET['time'] == 1) {
  733. $condition['refill_order.order_time'] = ['between', [(time() - 3600), (time() - 1800)]];
  734. }
  735. if ($_GET['time'] == 2) {
  736. $condition['refill_order.order_time'] = ['lt', (time() - 3600)];
  737. }
  738. }
  739. }
  740. }
  741. $merchants = [];
  742. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  743. foreach ($merchant_list as $key => $value) {
  744. $merchants[$value['mchid']] = $value;
  745. }
  746. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  747. $stat = $this->all_order_state_stat($condition);
  748. foreach ($order_list as $order_id => $order_info) {
  749. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  750. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  751. if ($order_info['notify_time'] > 0) {
  752. $diff_time = $order_info['notify_time'] - $order_info['order_time'];
  753. } else {
  754. $diff_time = time() - $order_info['order_time'];
  755. }
  756. $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
  757. $order_list[$order_id]['diff_time'] = $diff_time;
  758. }
  759. $provider_list = Model('')->table('refill_provider,store')
  760. ->field('refill_provider.*,store.store_name')
  761. ->join('inner')
  762. ->on('store.store_id=refill_provider.store_id')
  763. ->order('opened asc, provider_id desc')
  764. ->limit(1000)
  765. ->select();
  766. Tpl::output('stat', $stat);
  767. Tpl::output('ftoday', $fToday);
  768. Tpl::output('order_list', $order_list);
  769. Tpl::output('provider_list', $provider_list);
  770. Tpl::output('merchant_list', $merchant_list);
  771. Tpl::output('show_page', $model_refill_order->showpage());
  772. Tpl::showpage('refill.order.index');
  773. }
  774. public function notify_merchantOp()
  775. {
  776. $order_id = $_GET['order_id'];
  777. $mod_order = Model('vr_order');
  778. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  779. if ($order_info['order_state'] == ORDER_STATE_SEND) {
  780. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  781. } else {
  782. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  783. }
  784. showMessage('操作成功', '');
  785. }
  786. public function notify_manual_merchantOp()
  787. {
  788. $order_id = $_GET['order_id'];
  789. $type = $_GET['type'];
  790. $mod_order = Model('vr_order');
  791. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  792. if ((time() - $order_info['order_time']) < 3600) {
  793. showMessage('订单时间未超过1小时', 'index.php?act=merchant&op=refill_order');
  794. }
  795. if ($type == 'success') {
  796. refill\util::manual_success($order_id);
  797. } elseif ($type == 'cancel') {
  798. refill\util::manual_cancel($order_id);
  799. } else {
  800. showMessage('手动操作类型错误', 'index.php?act=merchant&op=refill_order');
  801. }
  802. showMessage('操作成功', '');
  803. }
  804. public function providerStatsOp()
  805. {
  806. $provider_model = Model('refill_provider');
  807. $condition = [];
  808. $provider_list = $provider_model->getProviderList($condition, 1000);
  809. $opened_text = ['使用中', '已禁用'];
  810. $type_text = ['油卡', '手机充值卡'];
  811. Tpl::output('opened_text', $opened_text);
  812. Tpl::output('type_text', $type_text);
  813. Tpl::output('provider_list', $provider_list);
  814. Tpl::output('show_page', $provider_model->showpage());
  815. Tpl::showpage('provider.stats');
  816. }
  817. public function providerOp()
  818. {
  819. $this->sync_cfgs();
  820. $provider_model = Model('refill_provider');
  821. $condition = [];
  822. if (trim($_GET['name']) != '') {
  823. $condition['name'] = ['like', '%' . $_GET['name'] . '%'];
  824. Tpl::output('name', $_GET['name']);
  825. }
  826. if (in_array($_GET['type'], [1, 2])) {
  827. $condition['type'] = $_GET['type'];
  828. }
  829. $store_list = Model('store')->getStoreList(['store_id' => ['gt',0]], '', '', 'store_id,store_name');
  830. foreach ($store_list as $store) {
  831. $stores[$store['store_id']] = $store['store_name'];
  832. }
  833. $provider_list = $provider_model->getProviderList($condition, 20);
  834. foreach ($provider_list as $key => $provider) {
  835. if (!empty($provider['start_period']) && !empty($provider['end_period'])) {
  836. $provider_list[$key]['period'] = $provider['start_period'] . '~' . $provider['end_period'];
  837. } else {
  838. $provider_list[$key]['period'] = '全时间段';
  839. }
  840. $provider_list[$key]['store_name'] = $stores[$provider['store_id']];
  841. }
  842. $opened_text = ['使用中', '已禁用'];
  843. $type_text = ['油卡', '手机充值卡'];
  844. Tpl::output('opened_text', $opened_text);
  845. Tpl::output('type_text', $type_text);
  846. Tpl::output('provider_list', $provider_list);
  847. Tpl::output('show_page', $provider_model->showpage());
  848. Tpl::showpage('provider.index');
  849. }
  850. public function provider_provinceOp()
  851. {
  852. $provider_model = Model('refill_provider');
  853. $provider_id = $_GET['id'] ?? $_POST['id'];
  854. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  855. if (empty($provider)) {
  856. showMessage('通道信息有误');
  857. }
  858. $operator = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
  859. if(chksubmit()) {
  860. foreach ($operator as $opr) {
  861. $key = $opr . '-province';
  862. $province = $_POST[$key];
  863. if($province == -1) {
  864. $updata[$opr] = -1;
  865. }else{
  866. $updata[$opr] = implode(',',$province);
  867. }
  868. }
  869. $resp = $provider_model->editProvider(['provinces' => serialize($updata)], ['provider_id' => $provider_id]);
  870. if ($resp) {
  871. showMessage('编辑成功', 'index.php?act=merchant&op=provider');
  872. } else {
  873. showMessage('编辑失败', "index.php?act=merchant&op=provider_province&id={$provider_id}");
  874. }
  875. } else {
  876. $data = unserialize($provider['provinces']);
  877. $provinces = [];
  878. $province = $provinces;
  879. foreach ($operator as $opr) {
  880. if(empty($data)) {
  881. $provinces[$opr] = [-1];
  882. } else {
  883. $provinces[$opr] = explode(',', $data[$opr]);
  884. }
  885. }
  886. $province_list = mtopcard\ProvinceList;
  887. Tpl::output('province_list', $province_list);
  888. Tpl::output('provider', $provider);
  889. Tpl::output('provinces', $provinces);
  890. Tpl::showpage('provider.province');
  891. }
  892. }
  893. public function sync_cfgs()
  894. {
  895. $name_val = function ($items) {
  896. $result = [];
  897. foreach ($items as $item) {
  898. $name = $item['name'];
  899. $result[$name] = $item;
  900. }
  901. return $result;
  902. };
  903. $match = function ($all, $cur) {
  904. $inserts = $updates = [];
  905. foreach ($all as $key => $value) {
  906. if (!array_key_exists($key, $cur)) {
  907. $insert['name'] = $key;
  908. $insert['store_id'] = $value['cfg']['store_id'];
  909. $insert['qualitys'] = $value['cfg']['qualitys'];
  910. $inserts[] = $insert;
  911. } elseif ($value['cfg']['qualitys'] != $cur[$key]['qualitys']) {
  912. $update['provider_id'] = $cur[$key]['provider_id'];
  913. $update['qualitys'] = $value['cfg']['qualitys'];
  914. $updates[] = $update;
  915. }
  916. }
  917. return [$inserts, $updates];
  918. };
  919. $updater = function ($mod, $updates) {
  920. if (empty($updates)) return;
  921. foreach ($updates as $update) {
  922. $provider_id = $update['provider_id'];
  923. $data = ['qualitys' => $update['qualitys']];
  924. $mod->editProvider($data, ['provider_id' => $provider_id]);
  925. }
  926. };
  927. $inserter = function ($mod, $type, $names) {
  928. foreach ($names as $name) {
  929. $data = ['name' => $name['name'], 'type' => $type, 'store_id' => $name['store_id'], 'qualitys' => $name['qualitys'], 'opened' => 2];
  930. $mod->insert($data);
  931. }
  932. };
  933. global $config;
  934. $oil_configs = $config['oil_providers'];
  935. $pho_configs = $config['phone_providers'];
  936. $oils = $name_val($oil_configs);
  937. $phones = $name_val($pho_configs);
  938. $mod_prov = Model('refill_provider');
  939. $oil_items = $mod_prov->getProviderList(['type' => 1]);
  940. $oil_items = $name_val($oil_items);
  941. [$oil_inserts, $oil_updates] = $match($oils, $oil_items);
  942. $phone_items = $mod_prov->getProviderList(['type' => 2]);
  943. $phone_items = $name_val($phone_items);
  944. [$phone_inserts, $phone_updates] = $match($phones, $phone_items);
  945. $inserter($mod_prov, 1, $oil_inserts);
  946. $inserter($mod_prov, 2, $phone_inserts);
  947. $updater($mod_prov, $oil_updates);
  948. $updater($mod_prov, $phone_updates);
  949. }
  950. public function changeProviderStateOp()
  951. {
  952. $provider_id = intval($_GET['id']);
  953. $state = intval($_GET['state']);
  954. $provider_model = Model('refill_provider');
  955. $provider_info = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  956. if (empty($provider_info) || !in_array($state, [1, 2])) {
  957. showMessage('操作成功', 'index.php?act=merchant&op=provider');
  958. }
  959. $resp = $provider_model->editProvider(['opened' => $state], ['provider_id' => $provider_id]);
  960. if (!$resp) {
  961. showMessage('操作失败', 'index.php?act=merchant&op=provider', 'html', 'error');
  962. }
  963. showMessage('操作成功', 'index.php?act=merchant&op=provider');
  964. }
  965. /**
  966. * 新增通道
  967. */
  968. public function provider_addOp()
  969. {
  970. $provider_model = Model('refill_provider');
  971. if (chksubmit()) {
  972. $params = $_POST;
  973. unset($params['form_submit']);
  974. $result = $provider_model->addProvider($params);
  975. if ($result) {
  976. $url = [
  977. [
  978. 'url' => 'index.php?act=merchant&op=provider',
  979. 'msg' => '返回通道列表',
  980. ],
  981. [
  982. 'url' => 'index.php?act=merchant&op=provider_add',
  983. 'msg' => '继续新增通道',
  984. ],
  985. ];
  986. $this->log('添加通道:' . '[ ' . $_POST['name'] . ']', 1);
  987. showMessage('通道添加成功', $url);
  988. } else {
  989. showMessage('通道添加失败');
  990. }
  991. }
  992. Tpl::showpage('provider.add');
  993. }
  994. public function provider_editOp()
  995. {
  996. $provider_model = Model('refill_provider');
  997. if (chksubmit()) {
  998. $provider_id = intval($_POST['provider_id']) ?? '';
  999. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  1000. if (empty($provider)) {
  1001. showMessage('通道信息有误');
  1002. }
  1003. $params = $_POST;
  1004. unset($params['form_submit']);
  1005. if (empty($params)) {
  1006. showMessage('通道编辑成功', 'index.php?act=merchant&op=provider');
  1007. }
  1008. $result = $provider_model->editProvider($params, ['provider_id' => $provider_id]);
  1009. if ($result) {
  1010. $this->log('编辑通道:' . '[ ' . $provider['name'] . ']', 1);
  1011. showMessage('通道编辑成功', 'index.php?act=merchant&op=provider');
  1012. } else {
  1013. showMessage('通道编辑失败', "index.php?act=merchant&op=provider_edit&id={$provider_id}");
  1014. }
  1015. }
  1016. $provider_id = intval($_GET['id']) ?? '';
  1017. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  1018. if (empty($provider)) {
  1019. showMessage('通道信息有误');
  1020. }
  1021. $type_text = ['油卡', '手机充值卡'];
  1022. Tpl::output('type_text', $type_text);
  1023. Tpl::output('provider', $provider);
  1024. Tpl::showpage('provider.edit');
  1025. }
  1026. public function provider_delOp()
  1027. {
  1028. $provider_model = Model('refill_provider');
  1029. $provider_id = intval($_GET['id']) ?? '';
  1030. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  1031. if (empty($provider)) {
  1032. showMessage('通道信息有误');
  1033. }
  1034. $result = $provider_model->delProvider(['provider_id' => $provider_id]);
  1035. if ($result) {
  1036. $this->log('删除通道:' . '[ ' . $provider['name'] . ']', 1);
  1037. showMessage('通道删除成功', 'index.php?act=merchant&op=provider');
  1038. } else {
  1039. showMessage('通道删除失败', "index.php?act=merchant&op=provider");
  1040. }
  1041. }
  1042. public function provider_amount_controlOp()
  1043. {
  1044. global $config;
  1045. $type = $_GET['type'] ?? $_POST['type'];
  1046. $form = $_GET['form'] ?? $_POST['form'];
  1047. $rkey = $this->speed_key($type, $form);
  1048. $quality = ['common' => 1, 'fast' => 2, 'card' => 3, 'third' => 4, 'slow' => 5];
  1049. if (chksubmit()) {
  1050. $pids = $_POST['pid'];
  1051. $names = $_POST['name'];
  1052. $types = $_POST['types'];
  1053. $amounts = $_POST['amount'];
  1054. $speeds = $_POST['speed'];
  1055. $sorts = $_POST['sort'];
  1056. $openeds = $_POST['opened'];
  1057. $hass = $_POST['has'];
  1058. foreach ($pids as $key => $pid) {
  1059. if ($hass[$key] == 0) {
  1060. continue;
  1061. }
  1062. $data['pid'] = intval($pid);
  1063. $data['name'] = $names[$key];
  1064. $data['type'] = intval($types[$key]);
  1065. $data['amount'] = intval($amounts[$key]);
  1066. $data['speed'] = intval($speeds[$key]);
  1067. $data['sort'] = intval($sorts[$key]);
  1068. $data['opened'] = intval($openeds[$key]);
  1069. $index = "{$data['type']}-{$data['amount']}";
  1070. $result[$index][] = $data;
  1071. }
  1072. wcache($rkey, ['data' => serialize($result)], 'provider-');
  1073. showMessage('编辑成功', 'index.php?act=merchant&op=provider');
  1074. } else {
  1075. $speed_limit = rcache($rkey, 'provider-');
  1076. if (empty($speed_limit)) {
  1077. $speed_limit = [];
  1078. } else {
  1079. $speed_limit = unserialize($speed_limit['data']);
  1080. }
  1081. $initialiser = function ($provider) {
  1082. $data['pid'] = $provider['provider_id'];
  1083. $data['name'] = $provider['name'];
  1084. $data['speed'] = -1;
  1085. $data['sort'] = 1;
  1086. $data['opened'] = 1;
  1087. return $data;
  1088. };
  1089. $providers = Model('')->table('refill_provider,store')
  1090. ->field('refill_provider.*,store.store_name')
  1091. ->join('inner')
  1092. ->on('store.store_id=refill_provider.store_id')
  1093. ->where(['type' => $type, 'qualitys' => ['like', '%' . $quality[$form] . '%']])
  1094. ->limit(1000)
  1095. ->order('opened asc , provider_id desc')
  1096. ->select();
  1097. if (empty($providers)) {
  1098. showMessage('暂无相关通道', 'index.php?act=merchant&op=provider');
  1099. }
  1100. $formData = $this->formData($type, $form);
  1101. $amounts = $formData['amounts'];
  1102. $cfgs = $formData['cfgs'];
  1103. $types = $formData['types'];
  1104. foreach ($speed_limit as $key => $speed) {
  1105. foreach ($speed as $value) {
  1106. $speed_limit[$key][$value['pid']] = $value;
  1107. }
  1108. }
  1109. $ProviderManager = new \refill\ProviderManager();
  1110. $ProviderManager->load();
  1111. $QPTA = $ProviderManager->getQPTA();
  1112. $QPTA = $QPTA[$quality[$form]];
  1113. foreach ($providers as $key => $provider) {
  1114. $result = [];
  1115. $pid = $provider['provider_id'];
  1116. $name = $provider['name'];
  1117. if (empty($cfgs) || !array_key_exists($name, $cfgs)) {
  1118. unset($providers[$key]);
  1119. continue;
  1120. }
  1121. foreach ($types as $type) {
  1122. foreach ($amounts as $k => $amount) {
  1123. $key = $type . '-' . $amount;
  1124. if (is_array($speed_limit[$key]) && array_key_exists($pid, $speed_limit[$key])) {
  1125. $speed = $speed_limit[$key][$pid];
  1126. } else {
  1127. $speed = $initialiser($provider);
  1128. }
  1129. if (is_array($QPTA["{$name}-{$type}-{$amount}"]) && array_key_exists("{$name}-{$type}-{$amount}", $QPTA)) {
  1130. $speed['has'] = 1;
  1131. } else {
  1132. $speed['has'] = 0;
  1133. }
  1134. $result[] = $speed;
  1135. }
  1136. }
  1137. $datas[$pid] = $result;
  1138. }
  1139. if (empty($datas)) {
  1140. showMessage('暂无相关通道配置', 'index.php?act=merchant&op=provider');
  1141. }
  1142. Tpl::output('form', $formData);
  1143. Tpl::output('datas', $datas);
  1144. Tpl::output('providers', $providers);
  1145. Tpl::showpage('provider.amount.control');
  1146. }
  1147. }
  1148. private function speed_key($type, $form)
  1149. {
  1150. if ($type == 1) {
  1151. $rkey = "channel-ctl-oil-{$form}-limit";
  1152. } elseif ($type == 2) {
  1153. $rkey = "channel-ctl-phone-{$form}-limit";
  1154. } else {
  1155. showMessage('类型有误', "index.php?act=merchant&op=provider");
  1156. }
  1157. Log::record($rkey, Log::DEBUG);
  1158. return $rkey;
  1159. }
  1160. private function formData($type, $form)
  1161. {
  1162. global $config;
  1163. $texts = [
  1164. ["中石油", '中石化'], ['移动', '联通', '电信']
  1165. ];
  1166. $type_data = [[1, 2], [4, 5, 6]];
  1167. $type_text = $texts[$type - 1];
  1168. $type_data = $type_data[$type - 1];
  1169. $amounts = [];
  1170. if ($type == 1) {
  1171. $amounts = $config['refill_oil_specs'];
  1172. $cfgs = $config['oil_providers'];
  1173. }
  1174. if ($type == 2) {
  1175. $amounts = $config['refill_phone_specs'];
  1176. $cfgs = $config['phone_providers'];
  1177. }
  1178. foreach ($type_text as $key => $value) {
  1179. foreach ($amounts as $amount) {
  1180. $data['text'] = $value . '-' . $amount . '元';
  1181. $data['type'] = $type_data[$key];
  1182. $data['amount'] = $amount;
  1183. $amountData[] = $data;
  1184. }
  1185. }
  1186. foreach ($cfgs as $cfg) {
  1187. $pcfgs[$cfg['name']] = $cfg;
  1188. }
  1189. return ['amountData' => $amountData, 'form' => $form, 'amounts' => $amounts, 'types' => $type_data, 'cfgs' => $pcfgs];
  1190. }
  1191. private function scard_type(int $card_type)
  1192. {
  1193. if ($card_type == 1) { //中石油
  1194. return '中石油';
  1195. } elseif ($card_type == 2) { //中石化
  1196. return '中石化';
  1197. } elseif ($card_type == 4) { //中国移动
  1198. return '中国移动';
  1199. } elseif ($card_type == 5) { //中国联通
  1200. return '中国联通';
  1201. } elseif ($card_type == 6) { //中国电信
  1202. return '中国电信';
  1203. } else {
  1204. return 'unknown';
  1205. }
  1206. }
  1207. private function elapse_time($seconds)
  1208. {
  1209. $minutes = intval($seconds / 60);
  1210. $second = intval($seconds % 60);
  1211. if ($minutes >= 60) {
  1212. $minute = $minutes % 60;
  1213. $hours = intval($minutes / 60);
  1214. $result = "{$minute}m{$second}s";
  1215. } elseif ($minutes > 0) {
  1216. $result = "{$minutes}m{$second}s";
  1217. } else {
  1218. $result = "{$second}s";
  1219. }
  1220. if (isset($hours)) {
  1221. $result = "{$hours}h{$minute}m";
  1222. }
  1223. return $result;
  1224. }
  1225. private function refill_stat($condition, $times)
  1226. {
  1227. $stat_order = function ($condition) {
  1228. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  1229. ->on('refill_order.order_id=vr_order.order_id')
  1230. ->field('count(*) as order_count ')
  1231. ->where($condition)->find();
  1232. return $stat['order_count'];
  1233. };
  1234. $result = [];
  1235. $condition['order_state'] = ORDER_STATE_SEND;
  1236. foreach ($times as $time) {
  1237. $condition['refill_order.order_time'] = $time;
  1238. $result[] = $stat_order($condition);
  1239. }
  1240. return $result;
  1241. }
  1242. private function all_order_state_stat($condition)
  1243. {
  1244. $counts = Model('')->table('refill_order,vr_order')->join('inner')
  1245. ->on('refill_order.order_id=vr_order.order_id')
  1246. ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts, order_state')
  1247. ->where($condition)
  1248. ->group('order_state')
  1249. ->select();
  1250. $all = [];
  1251. $data['order_count'] = $data['refill_amounts'] = $data['channel_amounts'] = $data['mch_amounts'] = 0;
  1252. $sending = $success = $cancel = $data;
  1253. foreach ($counts as $count) {
  1254. if ($count['order_state'] == ORDER_STATE_SEND) {
  1255. $sending = $count;
  1256. } elseif ($count['order_state'] == ORDER_STATE_SUCCESS) {
  1257. $success = $count;
  1258. } elseif ($count['order_state'] == ORDER_STATE_CANCEL) {
  1259. $cancel = $count;
  1260. }
  1261. $all['order_count'] += $count['order_count'];
  1262. $all['refill_amounts'] += ncPriceFormat($count['refill_amounts']);
  1263. $all['channel_amounts'] += ncPriceFormat($count['channel_amounts']);
  1264. $all['mch_amounts'] += ncPriceFormat($count['mch_amounts']);
  1265. }
  1266. return ['all' => $all, 'sending' => $sending, 'success' => $success, 'cancel' => $cancel];
  1267. }
  1268. public function OrderSendListOp()
  1269. {
  1270. $model_refill_order = Model('refill_order');
  1271. $condition['refill_order.inner_status'] = 0;
  1272. $condition['vr_order.order_state'] = ORDER_STATE_SEND;
  1273. $condition['refill_order.order_time'] = ['lt', (time() - 1800)];
  1274. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  1275. foreach ($merchant_list as $key => $value) {
  1276. $merchants[$value['mchid']] = $value;
  1277. }
  1278. if ($_GET['time'] == 1) {
  1279. $condition['refill_order.order_time'] = ['between', [(time() - 3600), (time() - 1800)]];
  1280. }
  1281. if ($_GET['time'] == 2) {
  1282. $condition['refill_order.order_time'] = ['lt', (time() - 3600)];
  1283. }
  1284. if ($_GET['card_type'] == 'oil') {
  1285. $condition['refill_order.card_type'] = ['in', ['1', '2']];
  1286. }
  1287. if ($_GET['card_type'] == 'phone') {
  1288. $condition['refill_order.card_type'] = ['in', ['4', '5', '6']];
  1289. }
  1290. if (!empty($_GET['card_type'])) {
  1291. if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6'])) {
  1292. $condition['refill_order.card_type'] = $_GET['card_type'];
  1293. }
  1294. if ($_GET['card_type'] == 'oil') {
  1295. $condition['refill_order.card_type'] = ['in', ['1', '2']];
  1296. }
  1297. if ($_GET['card_type'] == 'phone') {
  1298. $condition['refill_order.card_type'] = ['in', ['4', '5', '6']];
  1299. }
  1300. }
  1301. $order_list = $model_refill_order->getMerchantOrderList($condition, 100, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  1302. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  1303. ->on('refill_order.order_id=vr_order.order_id')
  1304. ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
  1305. ->where($condition)->find();
  1306. $count = $this->refill_stat($condition,
  1307. [['between', [(time() - 3600), (time() - 1800)]],
  1308. ['lt', (time() - 3600)]]
  1309. );
  1310. foreach ($order_list as $order_id => $order_info) {
  1311. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  1312. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  1313. $order_list[$order_id]['diff_time_text'] = $this->elapse_time(time() - $order_info['order_time']);
  1314. $order_list[$order_id]['diff_time'] = time() - $order_info['order_time'];
  1315. }
  1316. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  1317. $provider_list = Model('')->table('refill_provider,store')
  1318. ->field('refill_provider.*,store.store_name')
  1319. ->join('inner')
  1320. ->on('store.store_id=refill_provider.store_id')
  1321. ->order('opened asc, provider_id desc')
  1322. ->limit(1000)
  1323. ->select();
  1324. Tpl::output('stat', $stat);
  1325. Tpl::output('count', $count);
  1326. Tpl::output('order_list', $order_list);
  1327. Tpl::output('merchant_list', $merchant_list);
  1328. Tpl::output('provider_list', $provider_list);
  1329. Tpl::output('show_page', $model_refill_order->showpage());
  1330. Tpl::showpage('refill.order.send.index');
  1331. }
  1332. public function OrderStatsOp()
  1333. {
  1334. $type = $_GET['type'] ? $_GET['type'] : 'system';
  1335. $page = "{$type}.order.stats";
  1336. $model_refill_order = Model('refill_order');
  1337. $condition['type'] = $type;
  1338. if (!empty($_GET['cid'])) {
  1339. $condition['cid'] = $_GET['cid'];
  1340. }
  1341. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  1342. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  1343. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  1344. $condition['time_stamp'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  1345. } elseif ($start_unixtime > 0) {
  1346. $condition['time_stamp'] = ['egt', $start_unixtime];
  1347. } elseif ($end_unixtime > 0) {
  1348. $condition['time_stamp'] = ['lt', $end_unixtime];
  1349. }
  1350. $stats_list = $model_refill_order->getOrderStatsList($condition);
  1351. if ($type == 'provider') {
  1352. $provider_list = Model('')->table('refill_provider,store')->field('refill_provider.store_id,store.store_name')->join('inner')
  1353. ->on('store.store_id=refill_provider.store_id')->limit(1000)->select();
  1354. Tpl::output('provider_list', $provider_list);
  1355. } elseif ($type == 'merchant') {
  1356. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  1357. Tpl::output('merchant_list', $merchant_list);
  1358. }
  1359. $check_text = ['未编辑', '匹配', '不匹配'];
  1360. Tpl::output('stats_list', $stats_list);
  1361. Tpl::output('check_text', $check_text);
  1362. Tpl::output('show_page', $model_refill_order->showpage());
  1363. Tpl::showpage($page);
  1364. }
  1365. public function OrderStatsCheckOp()
  1366. {
  1367. $stat_id = $_GET['stat_id'] ?? $_POST['stat_id'];
  1368. $mod_stat = Model('refill_stats');
  1369. $stats_data = $mod_stat->getStatsInfo(['stat_id' => $stat_id]);
  1370. if (empty($stats_data)) {
  1371. showMessage('对应数据不存在', '');
  1372. }
  1373. $type = $stats_data['type'];
  1374. if (chksubmit()) {
  1375. $corder_success_count = $_POST['corder_success_count'];
  1376. $corder_success_amounts = $_POST['corder_success_amounts'];
  1377. $remark = $_POST['remark'];
  1378. $gap_order_count = $gap_success_amounts = 0;
  1379. if($type == 'provider') {
  1380. $gap_order_count = $corder_success_count - $stats_data['success_count'];
  1381. $gap_success_amounts = $corder_success_amounts - $stats_data['success_channel_amounts'];
  1382. }elseif ($type == 'merchant') {
  1383. $gap_order_count = $stats_data['success_count'] - $corder_success_count;
  1384. $gap_success_amounts = $stats_data['success_channel_amounts'] - $corder_success_amounts;
  1385. }else{
  1386. showMessage('对账数据类型错误', 'index.php?act=merchant&op=OrderStats');
  1387. }
  1388. $updata['corder_success_count'] = $corder_success_count;
  1389. $updata['corder_success_amounts'] = $corder_success_amounts;
  1390. $updata['gap_order_count'] = $gap_order_count;
  1391. $updata['gap_success_amounts'] = $gap_success_amounts;
  1392. $updata['remark'] = $remark;
  1393. if($gap_order_count == 0 && $gap_success_amounts == 0) {
  1394. $updata['check_status'] = 1;
  1395. }else{
  1396. $updata['check_status'] = 2;
  1397. }
  1398. $res = $mod_stat->edit($stat_id, $updata);
  1399. if ($res) {
  1400. showMessage('操作成功',"index.php?act=merchant&op=OrderStats&type={$type}");
  1401. } else {
  1402. showMessage('操作失败');
  1403. }
  1404. } else {
  1405. $type_text = ['provider' => '上游', 'merchant' => '商户'];
  1406. Tpl::output('stats_type', $type_text[$type]);
  1407. Tpl::showpage('order.stats.check');
  1408. }
  1409. }
  1410. public function provider_evidenceOp()
  1411. {
  1412. $mod = Model('provider_evidence');
  1413. $condition = [];
  1414. if (trim($_GET['store_name']) != '') {
  1415. $condition['store_name'] = ['like', '%' . $_GET['store_name'] . '%'];
  1416. }
  1417. //上游充值申请列表
  1418. $evidence_list = $mod->getProviderEvidence($condition, 30);
  1419. Tpl::output('evidence_list', $evidence_list);
  1420. Tpl::output('page', $mod->showpage());
  1421. Tpl::showpage('merchant.provider.evidence_list');
  1422. }
  1423. public function provider_evidence_addOp()
  1424. {
  1425. $provider_model = Model('refill_provider');
  1426. if (chksubmit()) {
  1427. $obj_validate = new Validator();
  1428. $obj_validate->validateparam = [
  1429. ["input" => $_POST["provider_id"], "require" => "true", "message" => '上游通道不能为空'],
  1430. ["input" => $_POST["bank_username"], "require" => "true", "message" => '开户人姓名不能为空'],
  1431. ["input" => $_POST["bank_name"], "require" => "true", "message" => '开户银行不能为空'],
  1432. ["input" => $_POST["to_bank_username"], "require" => "true", "message" => '上游开户人姓名不能为空'],
  1433. ["input" => $_POST["to_bank_name"], "require" => "true", "message" => '上游开户银行不能为空'],
  1434. ["input" => $_POST["amount"], "require" => "true", "message" => '预存金额不能为空']
  1435. ];
  1436. $error = $obj_validate->validate();
  1437. if ($error != '') {
  1438. showMessage($error);
  1439. }
  1440. $provider_id = $_POST["provider_id"];
  1441. $provider_info = $provider_model->table('refill_provider,store')
  1442. ->where((['provider_id' => $provider_id]))
  1443. ->field('refill_provider.*,store.store_name')
  1444. ->join('inner')
  1445. ->on('store.store_id=refill_provider.store_id')
  1446. ->find();
  1447. if (!$provider_info) {
  1448. showMessage('对应店铺不存在');
  1449. }
  1450. $amount = $_POST['amount'];
  1451. $money = abs($amount);
  1452. if ($money == 0) {
  1453. showMessage('申请金额错误');
  1454. }
  1455. if(!empty($_FILES['voucher']['name'])) {
  1456. $upload = new UploadFile();
  1457. $upload->set('default_dir',ATTACH_UPFILE.'/provider');
  1458. $result = $upload->upfile('voucher');
  1459. if ($result){
  1460. $_POST['voucher'] = $upload->file_name;
  1461. $input['voucher_name'] = $_POST['voucher'];
  1462. }else {
  1463. showMessage($upload->error);
  1464. }
  1465. }
  1466. $input['store_name'] = $provider_info['store_name'];
  1467. $input['store_id'] = $provider_info['store_id'];
  1468. $input['amount'] = $amount;
  1469. $input['bank_username'] = $_POST['bank_username'];
  1470. $input['bank_name'] = $_POST['bank_name'];
  1471. $input['to_bank_username'] = $_POST['to_bank_username'];
  1472. $input['to_bank_name'] = $_POST['to_bank_name'];
  1473. $input['add_time'] = time();
  1474. $mod = Model('provider_evidence');
  1475. $res = $mod->addProviderEvidence($input);
  1476. if ($res) {
  1477. showMessage('操作成功',"index.php?act=merchant&op=provider_evidence");
  1478. } else {
  1479. showMessage('操作失败');
  1480. }
  1481. } else {
  1482. $provider_list = Model('')->table('refill_provider,store')
  1483. ->field('refill_provider.*,store.store_name')
  1484. ->join('inner')
  1485. ->on('store.store_id=refill_provider.store_id')
  1486. ->limit(1000)
  1487. ->select();
  1488. Tpl::output('provider_list', $provider_list);
  1489. Tpl::showpage('provider.evidence.add');
  1490. }
  1491. }
  1492. public function provider_successfulOp()
  1493. {
  1494. $days = $this->successful_where();
  1495. Tpl::output('days', $days);
  1496. Tpl::showpage('provider.successful');
  1497. }
  1498. private function successful_where() {
  1499. if(defined('COMPANY_NAME') && COMPANY_NAME === 'LZKJ_COMPANY') {
  1500. $url = 'https://www.lzkj168.cn/plot/days';
  1501. }
  1502. else {
  1503. $url = 'https://www.xyzshops.cn/plot/days';
  1504. }
  1505. Log::record("successful get timestamp url : {$url}", Log::DEBUG);
  1506. $data = http_request($url);
  1507. if(empty($data)) return [];
  1508. preg_match_all('/\d{10}/', $data, $matches);
  1509. $days = $matches[0];
  1510. if(empty($days)) return [];
  1511. $result = [];
  1512. foreach ($days as $day) {
  1513. $result[$day] = date("Y-m-d",$day);
  1514. }
  1515. return $result;
  1516. }
  1517. public function successful_time_get_whereOp(){
  1518. if(defined('COMPANY_NAME') && COMPANY_NAME === 'LZKJ_COMPANY') {
  1519. $url = 'https://www.lzkj168.cn/plot/paths?time_stamp='.$_GET['timestamp'];
  1520. }
  1521. else {
  1522. $url = 'https://www.xyzshops.cn/plot/paths?time_stamp='.$_GET['timestamp'];
  1523. }
  1524. Log::record("successful get where url : {$url}", Log::DEBUG);
  1525. $data = http_request($url);
  1526. preg_match_all('/\d{10}\/[a-z]+\/\d{1,2}\/\d\/\d{2,4}/', $data, $matches);
  1527. $conds = $matches[0];
  1528. if(empty($conds)) return [];
  1529. foreach ($conds as $cond) {
  1530. $arr = explode('/',$cond);
  1531. $chname[] = $arr[1];
  1532. $qualitys[] = $arr[2];
  1533. $card_types[] = $arr[3];
  1534. $amount[] = intval($arr[4]);
  1535. }
  1536. $chnameData = array_unique($chname);
  1537. sort($chnameData);
  1538. $result['chname'] = $chnameData;
  1539. $amountData = array_unique($amount);
  1540. sort($amountData);
  1541. $result['amount'] = $amountData;
  1542. foreach (array_unique($card_types) as $card_type) {
  1543. $card_typeData[$card_type] = $this->scard_type($card_type);
  1544. }
  1545. ksort($card_typeData);
  1546. $result['card_type'] = $card_typeData;
  1547. $quality_txt = [1=>'普充', 2=>'快充', 3=>'卡密', 4=>'三方', 5=>'慢充'];
  1548. foreach (array_unique($qualitys) as $quality) {
  1549. $qualityData[$quality] = $quality_txt[$quality];
  1550. }
  1551. ksort($qualityData);
  1552. $result['quality'] = $qualityData;
  1553. echo(json_encode($result));
  1554. exit;
  1555. }
  1556. }