merchant.php 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. <?php
  2. /**
  3. * 机构管理界面
  4. *
  5. **by 好商城V3 www.33hao.com 运营版*/
  6. defined('InShopNC') or exit('Access Invalid!');
  7. include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
  8. require_once(BASE_HELPER_PATH . '/stat_helper.php');
  9. require_once(BASE_ROOT_PATH . '/helper/refill/functional.php');
  10. require_once(BASE_HELPER_PATH . '/task/task_helper.php');
  11. require_once(BASE_HELPER_PATH . '/refill/functional.php');
  12. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  13. use refill\quality_ploy;
  14. class merchantControl extends SystemControl
  15. {
  16. const EXPORT_SIZE = 1000;
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. Language::read('merchant');
  21. }
  22. public function merchantOp()
  23. {
  24. global $config;
  25. $model_merchant = Model('merchant');
  26. $condition = [];
  27. if (trim($_GET['merchant_name']) != '') {
  28. $condition['company_name'] = ['like', '%' . $_GET['merchant_name'] . '%'];
  29. }
  30. $debt_total = 0;
  31. $available_total = 0;
  32. $merchant_list = $model_merchant->getMerchantList($condition, 200, 'available_predeposit desc,merchant_state asc,mchid desc', true);
  33. foreach ($merchant_list as $key => $merchant) {
  34. $mchid = $merchant['mchid'];
  35. $available_predeposit = $merchant['available_predeposit'] - $merchant['credit_bonus'];
  36. $merchant_list[$key]['available_predeposit'] = number_format($available_predeposit,4,'.',',');;
  37. if(!in_array($mchid, $config['test_mchid']) && $merchant['merchant_state'] == 1) {
  38. if($available_predeposit >= 0) {
  39. $available_total += $available_predeposit;
  40. }else{
  41. $debt_total += $available_predeposit;
  42. }
  43. }
  44. }
  45. $stats = ['available_total' => $available_total, 'debt_total' => $debt_total];
  46. Tpl::output('merchant_state_text', self::STATE_TEXT);
  47. Tpl::output('merchant_list', $merchant_list);
  48. Tpl::output('stats', $stats);
  49. Tpl::output('page', $model_merchant->showpage('2'));
  50. Tpl::showpage('merchant.index');
  51. }
  52. public function changeStateOp()
  53. {
  54. $mchid = intval($_GET['mchid']);
  55. $state = intval($_GET['state']);
  56. $model_merchant = Model('merchant');
  57. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  58. if (empty($merchant_info) || !in_array($state, [1, 2])) {
  59. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  60. }
  61. $resp = $model_merchant->editMerchant(['merchant_state' => $state], ['mchid' => $mchid]);
  62. if (!$resp) {
  63. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  64. }
  65. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  66. }
  67. public function AllCloseMerchantOp()
  68. {
  69. $model_merchant = Model('merchant');
  70. $resp = $model_merchant->editMerchant(['merchant_state' => 2], ['mchid' => ['gt',0]]);
  71. showMessage('操作成功');
  72. }
  73. public function merchant_addOp()
  74. {
  75. if (chksubmit())
  76. {
  77. $obj_validate = new Validator();
  78. $obj_validate->validateparam = [
  79. ["input" => $_POST["name"], "require" => "true", "message" => '机构账号不能为空'],
  80. ["input" => $_POST["company_name"], "require" => "true", "message" => '机构公司名称不能为空'],
  81. ["input" => $_POST["password"], "require" => "true", "message" => '密码不能为空']
  82. ];
  83. $error = $obj_validate->validate();
  84. if ($error != '') {
  85. showMessage($error);
  86. }
  87. else
  88. {
  89. $model_merchant = Model('merchant');
  90. $model_member = Model('member');
  91. $trans = new trans_wapper($model_merchant, __METHOD__);
  92. try
  93. {
  94. $name = trim($_POST['name']);
  95. $company_name = trim($_POST['company_name']);
  96. $pwd = trim($_POST['password']);
  97. $alarm_amount = $_POST['alarm_amount'] ?? 0;
  98. $insert_member['member_name'] = md5($name . time());
  99. $insert_member['member_passwd'] = $pwd;
  100. $insert_id = $model_member->addMember($insert_member);
  101. if ($insert_id == false) {
  102. $trans->rollback();
  103. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  104. }
  105. $insert_array['name'] = $name;
  106. $insert_array['company_name'] = $company_name;
  107. $insert_array['org_pwd'] = $pwd;
  108. $insert_array['password'] = md5($pwd);
  109. $insert_array['admin_id'] = trim($insert_id);
  110. $insert_array['alarm_amount'] = $alarm_amount;
  111. $result = $model_merchant->addMerchant($insert_array);
  112. if ($result > 0) {
  113. $helper = new refill\divert_account();
  114. $helper->init_member($insert_id);
  115. $ret = true;
  116. } else {
  117. $ret = false;
  118. }
  119. if($ret)
  120. {
  121. $trans->commit();
  122. $url = [[
  123. 'url' => 'index.php?act=merchant&op=merchant',
  124. 'msg' => '返回机构列表',
  125. ], [
  126. 'url' => 'index.php?act=merchant&op=merchant_add',
  127. 'msg' => '继续新增机构',
  128. ]];
  129. $this->log('添加机构:' . '[ ' . $_POST['name'] . ']', 1);
  130. showMessage('机构添加成功', $url);
  131. } else {
  132. $trans->rollback();
  133. showMessage('机构添加失败');
  134. }
  135. }
  136. catch (Exception $e) {
  137. $trans->rollback();
  138. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  139. }
  140. }
  141. }
  142. Tpl::showpage('merchant.add');
  143. }
  144. public function merchant_editOp()
  145. {
  146. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  147. $model_merchant = Model('merchant');
  148. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
  149. if (empty($merchant)) {
  150. showMessage('机构信息有误');
  151. }
  152. if (chksubmit())
  153. {
  154. $update_credit_bonus = ncPriceFormat($_POST['credit_bonus']);
  155. $operatetype = $_POST['operatetype'];
  156. $credit_bonus_delta = false;
  157. if ($update_credit_bonus > 0)
  158. {
  159. if ($operatetype == 'add')
  160. {
  161. if ($merchant['credit_bonus'] + $update_credit_bonus < 0) {
  162. showMessage('授信金额调整后不能小于0');
  163. }
  164. $credit_bonus_delta = $update_credit_bonus;
  165. }
  166. elseif ($operatetype == 'del')
  167. {
  168. if ($merchant['credit_bonus'] - $update_credit_bonus < 0) {
  169. showMessage('授信金额调整后不能小于0');
  170. }
  171. $credit_bonus_delta = -$update_credit_bonus;
  172. }
  173. }
  174. $update['company_name'] = trim($_POST['company_name']);
  175. $update['org_pwd'] = trim($_POST['password']);
  176. $update['password'] = md5($update['org_pwd']);
  177. $update['alarm_amount'] = $_POST['alarm_amount'] ?? 0;
  178. $update['manual_recharge'] = $_POST['manual_recharge'];
  179. $day_timeout = intval($_POST['day_timeout']);
  180. $night_timeout = intval($_POST['night_timeout']);
  181. if($day_timeout <= 0) {
  182. $day_timeout = 180;
  183. }
  184. if($night_timeout <= 0) {
  185. $day_timeout = 180;
  186. }
  187. $update['day_timeout'] = $day_timeout;
  188. $update['night_timeout'] = $night_timeout;
  189. if(refill\functional::isDay()) {
  190. $update['time_out'] = intval($_POST['day_timeout']);
  191. } else {
  192. $update['time_out'] = intval($_POST['night_timeout']);
  193. }
  194. $member_id = $merchant['admin_id'];
  195. $model_merchant = Model('merchant');
  196. $trans = new trans_wapper($model_merchant, __METHOD__);
  197. try
  198. {
  199. if ($update_credit_bonus > 0 && $member_id > 0)
  200. {
  201. [$succ,$msg] = $this->credit_save_money($update_credit_bonus, $operatetype, $member_id);
  202. if (!$succ) {
  203. throw new Exception('调整预存款失败.');
  204. } else {
  205. $model_merchant->editMerchant(['credit_bonus' => ['exp', "credit_bonus+$credit_bonus_delta"]], ['admin_id' => $member_id]);
  206. }
  207. }
  208. $result = $model_merchant->editMerchant($update, ['mchid' => $mchid]);
  209. if (!$result) {
  210. $trans->rollback();
  211. showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
  212. }
  213. $trans->commit();
  214. $this->log("编辑机构:' . '[{$merchant['name']}]");
  215. showMessage('机构编辑成功', 'index.php?act=merchant&op=merchant');
  216. } catch (Exception $e) {
  217. $trans->rollback();
  218. showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
  219. }
  220. }
  221. Tpl::output('merchant', $merchant);
  222. Tpl::showpage('merchant.edit');
  223. }
  224. public function priceOp()
  225. {
  226. $quality = $_GET['quality'] ?? 1;
  227. if (chksubmit()) {
  228. $mchid = $_POST['mchid'];
  229. //合并表单数据
  230. $card_types = $_POST['cardtype'];
  231. $specs = $_POST['spec'];
  232. $prices = $_POST['price'];
  233. $extra_prices = $_POST['extra_price'];
  234. $max_inprices = $_POST['max_inprice'];
  235. foreach ($card_types as $key => $card_type) {
  236. $data['card_type'] = $card_type;
  237. $data['spec'] = intval($specs[$key]);
  238. $data['price'] = ncPriceFormat($prices[$key]);
  239. $data['extra_price'] = ncPriceFormat($extra_prices[$key]);
  240. $data['max_inprice'] = ncPriceFormat($max_inprices[$key]);
  241. $params[] = $data;
  242. }
  243. foreach ($params as $param) {
  244. if ($param['price'] > 0) {
  245. $insert['mchid'] = $mchid;
  246. $insert['spec'] = $param['spec'];
  247. $insert['price'] = $param['price'];
  248. $insert['extra_price'] = $param['extra_price'];
  249. $insert['max_inprice'] = $param['max_inprice'];
  250. $insert['card_types'] = $param['card_type'];
  251. $insert['quality'] = $quality;
  252. $inserts[] = $insert;
  253. }
  254. }
  255. $model_merchant = Model('merchant');
  256. $trans = new trans_wapper($model_merchant, __METHOD__);
  257. try {
  258. //删除旧费率
  259. $res = $model_merchant->delPrices(['mchid' => $mchid, 'quality' => $quality]);
  260. if(!$res) {
  261. $trans->rollback();
  262. showMessage('删除旧费率失败');
  263. }
  264. $ret = true;
  265. //更新新费率
  266. if (!empty($inserts)) {
  267. $ret = $model_merchant->insertPrices($inserts);
  268. }
  269. if($ret) {
  270. $trans->commit();
  271. showMessage('操作成功');
  272. }else{
  273. $trans->rollback();
  274. showMessage('更新费率失败');
  275. }
  276. } catch (Exception $e) {
  277. $trans->rollback();
  278. Log::record("merchant_price update err: {$e->getMessage()}", Log::ERR);
  279. showMessage('操作失败');
  280. }
  281. }
  282. $mchid = $_GET['mchid'] ?? 0;
  283. $goods = $this->GoodsFormat($mchid, $quality);
  284. Tpl::output('goods', $goods);
  285. Tpl::showpage('merchant.price');
  286. }
  287. public function third_merchant_priceOp()
  288. {
  289. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  290. $mod = Model('thrid_refill');
  291. if (chksubmit()) {
  292. //合并表单数据
  293. $card_types = $_POST['cardtype'];
  294. $specs = $_POST['spec'];
  295. $prices = $_POST['price'];
  296. $pcodes = $_POST['pcode'];
  297. $quality = 1;
  298. $params = [];
  299. foreach ($card_types as $key => $card_type) {
  300. $data['card_type'] = $card_type;
  301. $data['spec'] = intval($specs[$key]);
  302. $data['price'] = ncPriceFormat($prices[$key]);
  303. $data['pcode'] = $pcodes[$key];
  304. $params[] = $data;
  305. }
  306. $model_merchant = Model('merchant');
  307. $trans = new trans_wapper($model_merchant, __METHOD__);
  308. try {
  309. foreach ($params as $param) {
  310. $insert = [];
  311. if ($param['price'] > 0) {
  312. $insert['mchid'] = $mchid;
  313. $insert['spec'] = $param['spec'];
  314. $insert['price'] = $param['price'];
  315. $insert['card_types'] = $param['card_type'];
  316. $insert['quality'] = $quality;
  317. $insert['pcode'] = $param['pcode'];
  318. }
  319. //删除旧费率
  320. $res = $model_merchant->delPrices(['mchid' => $mchid, 'quality' => $quality, 'pcode' => $param['pcode']]);
  321. if(!$res) {
  322. $trans->rollback();
  323. showMessage('删除旧费率失败');
  324. }
  325. $ret = true;
  326. //更新新费率
  327. if (!empty($insert)) {
  328. $ret = $model_merchant->table('merchant_price')->insert($insert);
  329. }
  330. if(!$ret) {
  331. $trans->rollback();
  332. showMessage('更新费率失败');
  333. }
  334. }
  335. $trans->commit();
  336. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  337. } catch (Exception $e) {
  338. $trans->rollback();
  339. Log::record("merchant_price pcode update err: {$e->getMessage()}", Log::ERR);
  340. showMessage('操作失败');
  341. }
  342. } else {
  343. $condition = [];
  344. if (!empty($_GET['system_code'])) {
  345. $condition['system_code'] = $_GET['system_code'];
  346. }
  347. if (!empty($_GET['product_type'])) {
  348. $condition['product_type'] = $_GET['product_type'];
  349. }
  350. if (trim($_GET['product_name']) != '') {
  351. $condition['product_name'] = ['like', '%' . $_GET['product_name'] . '%'];
  352. }
  353. $third_product = $mod->getProductList($condition, 50);
  354. $model_merchant = Model('merchant');
  355. $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid, 'quality' => 1, 'card_types' => mtopcard\ThirdRefillCard])->select();
  356. $goods = [];
  357. foreach ($items as $item) {
  358. $goods[$item['pcode']] = $item['price'];
  359. }
  360. Tpl::output('third_product_type', self::THIRD_PRODUCT_TYPE);
  361. Tpl::output('third_product', $third_product);
  362. Tpl::output('goods', $goods);
  363. Tpl::output('page', $mod->showpage());
  364. Tpl::showpage('third.merchant.price');
  365. }
  366. }
  367. private function GoodsFormat($mchid, $quality)
  368. {
  369. $all_spector = function ($quality) {
  370. global $config;
  371. $refill_specs = $config['refill_specs'];
  372. $all_type_specs = [];
  373. foreach ($refill_specs as $scard_type => $specs) {
  374. $card_type = mtopcard\topcard_type($scard_type);
  375. if (in_array($card_type, [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
  376. if ($quality == refill\Quality::Quick) {
  377. $specs = array_merge($config['refill_phone_small_specs'], $specs);
  378. }
  379. }
  380. $all_type_specs[$card_type] = $specs;
  381. }
  382. $result = [];
  383. foreach ($all_type_specs as $card_type => $specs) {
  384. foreach ($specs as $spec) {
  385. $result["{$card_type}-{$spec}"] = ['card_type' => $card_type, 'spec' => $spec];
  386. }
  387. }
  388. return $result;
  389. };
  390. $merch_spector = function ($mchid, $quality) {
  391. $model_merchant = Model('merchant');
  392. $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid, 'quality' => $quality])->select();
  393. $result = [];
  394. foreach ($items as $item) {
  395. $card_types = explode(',', $item['card_types']);
  396. foreach ($card_types as $card_type) {
  397. $value['spec'] = intval($item['spec']);
  398. $result["{$card_type}-{$value['spec']}"] = ['card_type' => $card_type,
  399. 'spec' => intval($item['spec']),
  400. 'price' => $item['price'],
  401. 'extra_price' => $item['extra_price'],
  402. 'max_inprice' => $item['max_inprice']
  403. ];
  404. }
  405. }
  406. return $result;
  407. };
  408. $all_cardtype_specs = $all_spector($quality);
  409. $merch_cardtype_specs = $merch_spector($mchid, $quality);
  410. $merger = function ($all_specs, $mech_specs) {
  411. $result = [];
  412. foreach ($all_specs as $cardtype_spec => $value) {
  413. $card_name = $this->scard_type($value['card_type']);
  414. $data = [];
  415. $data['goods_name'] = $card_name;
  416. $data['card_type'] = $value['card_type'];
  417. $data['spec'] = $value['spec'];
  418. if (array_key_exists($cardtype_spec, $mech_specs)) {
  419. $data['price'] = $mech_specs[$cardtype_spec]['price'];
  420. $data['extra_price'] = $mech_specs[$cardtype_spec]['extra_price'];
  421. $data['max_inprice'] = $mech_specs[$cardtype_spec]['max_inprice'];
  422. } else {
  423. $data['price'] = 0;
  424. $data['extra_price'] = 0;
  425. $data['max_inprice'] = 0;
  426. }
  427. $result[$value['card_type']][] = $data;
  428. }
  429. return $result;
  430. };
  431. return $merger($all_cardtype_specs, $merch_cardtype_specs);
  432. }
  433. public function check_merchantOp()
  434. {
  435. $mchid = trim($_GET['mchid']);
  436. if (!$mchid) {
  437. echo '';
  438. die;
  439. }
  440. $model_merchant = Model('merchant');
  441. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*');
  442. if (empty($merchant_info)) {
  443. echo '';
  444. die;
  445. }
  446. echo 'true';
  447. }
  448. /**
  449. * ajax操作
  450. */
  451. public function ajaxOp()
  452. {
  453. $model_merchant = Model('merchant');
  454. switch ($_GET['branch']) {
  455. /**
  456. * 验证机构名称是否重复
  457. */
  458. case 'check_mch_name':
  459. $condition['name'] = $_GET['name'];
  460. $list = $model_merchant->getMerchantInfo($condition);
  461. if (empty($list)) {
  462. echo 'true';
  463. } else {
  464. echo 'false';
  465. }
  466. break;
  467. /**
  468. * 验证机构是否存在
  469. */
  470. case 'check_merchant':
  471. $condition['mchid'] = intval($_GET['mchid']);
  472. $list = $model_merchant->getMerchantInfo($condition);
  473. if (!empty($list)) {
  474. echo 'true';
  475. } else {
  476. echo 'false';
  477. }
  478. }
  479. }
  480. public function check_evidenceOp()
  481. {
  482. $status = $_GET['status'];
  483. $apply_id = intval($_GET['apply_id']);
  484. if ($apply_id > 0) {
  485. $model_merchant = Model('merchant');
  486. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true);
  487. if (empty($evidence_info)) {
  488. showMessage('充值申请不存在');
  489. }
  490. if ($status == 'pass') {
  491. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 2, 'check_time' => time()]);
  492. } elseif ($status == 'unpass') {
  493. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 3, 'check_time' => time()]);
  494. } else {
  495. showMessage('审核类型错误');
  496. }
  497. }
  498. showMessage(L('nc_common_save_succ'), urlAdmin('refill_evidence', 'index'));
  499. }
  500. //处理充值申请
  501. public function rechargeOp()
  502. {
  503. if (chksubmit()) {
  504. $mchid = $this->add_money();
  505. $model_merchant = Model('merchant');
  506. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  507. if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
  508. //更新预警短信通知限制
  509. $mch_cache = rcache("merchant-notify", 'refill-');
  510. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  511. $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
  512. wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
  513. }
  514. showMessage('操作成功', 'index.php?act=refill_evidence&op=index');
  515. } else {
  516. $apply_id = $_GET['apply_id'];
  517. if (!empty($apply_id)) {
  518. $model_merchant = Model('merchant');
  519. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*,member.available_predeposit', true);
  520. Tpl::output('apply_id', $apply_id);
  521. Tpl::output('amount', $evidence_info['amount']);
  522. Tpl::output('available_predeposit', $evidence_info['available_predeposit']);
  523. }
  524. global $config;
  525. Tpl::output('receive_bank', $config['receive_bank'][COMPANY_NAME]);
  526. Tpl::showpage('recharge.add');
  527. }
  528. }
  529. public function recharge_manualOp()
  530. {
  531. $type = $_GET['type'] ?? $_POST['type'];
  532. if (chksubmit()) {
  533. $add_type = '';
  534. $obj_validate = new Validator();
  535. if ($type == 'add') {
  536. $add_type = '加款';
  537. $obj_validate->validateparam = [
  538. ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
  539. ["input" => $_POST["bank_username"], "require" => "true", "message" => '开户人姓名不能为空'],
  540. ["input" => $_POST["bank_name"], "require" => "true", "message" => '开户银行不能为空'],
  541. ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空'],
  542. ["input" => $_POST["receive_bank"], "require" => "true", "message" => '请选择收款银行']
  543. ];
  544. } elseif ($type == 'edit') {
  545. $add_type = '调款';
  546. $obj_validate->validateparam = [
  547. ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
  548. ["input" => $_POST["bank_username"], "require" => "true", "message" => '操作人姓名不能为空'],
  549. ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空']
  550. ];
  551. }
  552. $operatetype = $_POST['operatetype'];
  553. $error = $obj_validate->validate();
  554. if ($error != '') {
  555. showMessage($error);
  556. }
  557. $mchid = $_POST["mch_id"];
  558. $model_merchant = Model('merchant');
  559. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  560. if (!$merchant_info) {
  561. showMessage('对应机构不存在');
  562. }
  563. $pointsnum = $_POST['pointsnum'];
  564. $money = abs($pointsnum);
  565. if ($money == 0) {
  566. showMessage('预存金额错误');
  567. }
  568. if (!empty($_FILES['voucher']['name'])) {
  569. $upload = new UploadFile();
  570. $upload->set('default_dir', ATTACH_UPFILE);
  571. $result = $upload->upfile('voucher');
  572. if ($result) {
  573. $_POST['voucher_name'] = $upload->file_name;
  574. } else {
  575. showMessage($upload->error);
  576. }
  577. }
  578. $trans = new trans_wapper($model_merchant, __METHOD__);
  579. try {
  580. $member_id = $merchant_info['admin_id'];
  581. if ($operatetype == 'add') {
  582. $bz = "管理员{$add_type}操作,手动增加预存金额";
  583. $this->credit_save_money($money, 'add', $member_id, $bz);
  584. $_POST['pointsnum'] = $money;
  585. } elseif ($operatetype == 'del') {
  586. $bz = "管理员{$add_type}操作,手动减少预存金额";
  587. $this->credit_save_money($money, 'del', $member_id, $bz);
  588. $_POST['pointsnum'] = -($money);
  589. } else {
  590. showMessage('预存类型错误');
  591. }
  592. $result = $this->ct_refill_evidence($_POST, $merchant_info);
  593. if (!$result) {
  594. $trans->rollback();
  595. showMessage('操作失败', 'index.php?act=merchant&op=merchant');
  596. }
  597. $trans->commit();
  598. if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
  599. //更新预警短信通知限制
  600. $mch_cache = rcache("merchant-notify", 'refill-');
  601. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  602. $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
  603. wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
  604. }
  605. showMessage('操作成功', 'index.php?act=refill_evidence&op=index');
  606. } catch (Exception $e) {
  607. $trans->rollback();
  608. showMessage('操作失败', 'index.php?act=refill_evidence&op=index');
  609. }
  610. } else {
  611. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  612. $model_merchant = Model('merchant');
  613. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  614. if (empty($merchant)) {
  615. showMessage('机构信息有误');
  616. }
  617. Tpl::output('merchant', $merchant);
  618. global $config;
  619. Tpl::output('receive_bank', $config['receive_bank'][COMPANY_NAME]);
  620. $page = "recharge.manual.{$type}";
  621. Tpl::showpage($page);
  622. }
  623. }
  624. private function ct_refill_evidence($params, $merchant_info)
  625. {
  626. $admininfo = $this->getAdminInfo();
  627. $mem_info = Model('member')->getMemberInfo(['member_id' => $merchant_info['admin_id']]);
  628. $input['mchid'] = $merchant_info['mchid'];
  629. $input['mch_name'] = $merchant_info['name'];
  630. $input['member_id'] = $merchant_info['admin_id'];
  631. $input['amount'] = $params['pointsnum'];
  632. $input['bank_username'] = $params['bank_username'];
  633. $input['bank_name'] = $params['bank_name'] ?? '';
  634. $input['bz'] = $params['pointsdesc'];
  635. $input['voucher_name'] = $params['voucher_name'] ?? '/';
  636. $input['status'] = 2;
  637. $input['is_operation'] = 2;
  638. $input['add_time'] = $input['check_time'] = time();
  639. $input['after_available'] = ncPriceFormat($mem_info['available_predeposit'] + $params['pointsnum']);
  640. $input['admin_name'] = $admininfo['name'];
  641. $input['admin_id'] = $admininfo['id'];
  642. $input['add_type'] = $params['add_type'];
  643. $input['receive_bank'] = $params['receive_bank'] ?? 0;
  644. if ($params['type'] == 'add') {
  645. $input['is_bank'] = 1;
  646. }
  647. $model_merchant = Model('merchant');
  648. return $model_merchant->addRefillEvidence($input);
  649. }
  650. public function add_money()
  651. {
  652. $obj_validate = new Validator();
  653. $obj_validate->validateparam = [
  654. ["input" => $_POST["apply_id"], "require" => "true", "message" => Language::get('admin_points_member_error_again')],
  655. ["input" => $_POST["pointsnum"], "require" => "true", 'validator' => 'Compare', 'operator' => ' >= ', 'to' => 1, "message" => Language::get('admin_points_points_min_error')],
  656. ["input" => $_POST["receive_bank"], "require" => "true", "message" => '请选择收款银行']
  657. ];
  658. $error = $obj_validate->validate();
  659. if ($error != '') {
  660. showMessage($error, '', '', 'error');
  661. }
  662. $money = abs(floatval($_POST['pointsnum']));
  663. $memo = trim($_POST['pointsdesc']);
  664. if ($money <= 0) {
  665. showMessage('输入的金额必需大于0', '', 'html', 'error');
  666. }
  667. $apply_id = intval($_POST['apply_id']);
  668. $model_merchant = Model('merchant');
  669. $receive_bank = $_POST['receive_bank'] ?? 0;
  670. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true);
  671. if (!is_array($evidence_info) || count($evidence_info) <= 0) {
  672. showMessage("无效的充值申请信息", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  673. }
  674. if ($evidence_info['status'] != 2) {
  675. showMessage("该充值申请未被审核通过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  676. }
  677. if ($evidence_info['is_operation'] == 2) {
  678. showMessage("该充值申请未已被预存过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  679. }
  680. //查询会员信息
  681. $obj_member = Model('member');
  682. $member_id = intval($evidence_info['member_id']);
  683. $member_info = $obj_member->getMemberInfo(['member_id' => $member_id], '*', true);
  684. $available_predeposit = floatval($member_info['available_predeposit']);
  685. $freeze_predeposit = floatval($member_info['freeze_predeposit']);
  686. if ($_POST['operatetype'] == 3 && $money > $available_predeposit) {
  687. showMessage(('可冻结预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  688. }
  689. if ($_POST['operatetype'] == 4 && $money > $freeze_predeposit) {
  690. showMessage(('可恢复冻结预存款不足,会员当前冻结预存款') . $freeze_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  691. }
  692. $model_pd = Model('predeposit');
  693. $order_sn = $apply_id;
  694. $admininfo = $this->getAdminInfo();
  695. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款,金额为" . $money . ",编号为" . $order_sn;
  696. $admin_act = 'sys_add_money';
  697. switch ($_POST['operatetype']) {
  698. case 1:
  699. $admin_act = "sys_add_money";
  700. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【增加】,金额为" . $money . ",编号为" . $order_sn;
  701. break;
  702. case 2:
  703. $admin_act = "sys_del_money";
  704. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【减少】,金额为" . $money . ",编号为" . $order_sn;
  705. break;
  706. default:
  707. showMessage('操作失败', 'index.php?act=refill_evidence&op=index');
  708. break;
  709. }
  710. $trans = new trans_wapper($model_pd, __METHOD__);
  711. try {
  712. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true,true);
  713. if ($evidence_info['is_operation'] == 2) {
  714. $trans->commit();
  715. showMessage('已经处理', 'index.php?act=refill_evidence&op=index', 'html', 'error');
  716. }
  717. //扣除冻结的预存款
  718. $data = [];
  719. $data['member_id'] = $member_info['member_id'];
  720. $data['member_name'] = $member_info['member_name'];
  721. $data['amount'] = $money;
  722. $data['order_sn'] = $order_sn;
  723. $data['admin_name'] = $admininfo['name'];
  724. $data['pdr_sn'] = $order_sn;
  725. $data['lg_desc'] = $memo;
  726. $isRefill = $model_pd->isRefill($data['member_id']);
  727. $model_pd->changePd($admin_act, $data,$isRefill);
  728. $after_available = ncPriceFormat($available_predeposit + $evidence_info['amount']);
  729. $model_merchant->editRefillEvidence(
  730. ['apply_id' => $apply_id],
  731. [
  732. 'is_operation' => 2, 'after_available' => $after_available,
  733. 'admin_id' => $admininfo['id'], 'admin_name' => $admininfo['name'],
  734. 'receive_bank' => $receive_bank
  735. ]
  736. );
  737. $trans->commit();
  738. $this->log($log_msg, 1);
  739. return $evidence_info['mchid'];
  740. } catch (Exception $e) {
  741. $trans->rollback();
  742. $this->log($log_msg, 0);
  743. showMessage($e->getMessage(), 'index.php?act=refill_evidence&op=index', 'html', 'error');
  744. }
  745. }
  746. public function checkevidenceOp()
  747. {
  748. $apply_id = trim($_GET['apply_id']);
  749. if (!$apply_id) {
  750. echo '';
  751. die;
  752. }
  753. $model_merchant = Model('merchant');
  754. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  755. if (empty($evidence_info)) {
  756. echo '';
  757. die;
  758. }
  759. echo 'true';
  760. }
  761. public function notify_merchantOp()
  762. {
  763. $order_id = $_GET['order_id'];
  764. $mod_order = Model('vr_order');
  765. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  766. $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id, 'inner_status' => 0, 'is_retrying' => 0]);
  767. if (empty($refill_info)) {
  768. showMessage('订单不存在,或不符合条件', '');
  769. }
  770. if ($order_info['order_state'] == ORDER_STATE_SEND) {
  771. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  772. } else {
  773. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  774. }
  775. showMessage('操作成功', '');
  776. }
  777. public function notify_manual_merchantOp()
  778. {
  779. $order_id = $_GET['order_id'];
  780. $type = $_GET['type'];
  781. $mod_order = Model('vr_order');
  782. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id, 'order_state' => ORDER_STATE_SEND]);
  783. $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id, 'inner_status' => 0, 'is_retrying' => 0]);
  784. if (empty($refill_info) || empty($order_info)) {
  785. showMessage('订单不存在,或不符合条件');
  786. }
  787. $fetch_order_ids = $this->check_fetch_order($order_id);
  788. if (in_array($order_id, $fetch_order_ids)) {
  789. showMessage('此订单不可手动操作,请联系抢单人员操作!');
  790. }
  791. if ($type == 'success') {
  792. refill\util::manual_success($order_id);
  793. } elseif ($type == 'cancel') {
  794. refill\util::manual_cancel($order_id);
  795. } else {
  796. showMessage('手动操作类型错误', 'index.php?act=refill_order&op=index');
  797. }
  798. $this->manual_log_record($refill_info, $type);
  799. $this->log("手动处理,订单号:{$order_info['order_sn']}", 1);
  800. showMessage('操作成功');
  801. }
  802. private function manual_log_record($order, $oper_type)
  803. {
  804. $admininfo = $this->getAdminInfo();
  805. $cur_time = time();
  806. $bz = "手动处理订单,操作者:{$admininfo['name']}";
  807. $ins = [
  808. 'order_id' => $order['order_id'], 'order_sn' => $order['order_sn'],'order_time' => $order['order_time'], 'notify_time' => $order['notify_time'],
  809. 'manual_type' => $oper_type, 'admin_id' => $admininfo['id'], 'admin_name' => $admininfo['name'], 'act_time' => $cur_time, 'bz' => $bz
  810. ];
  811. Model('refill_buyback')->insert($ins);
  812. }
  813. public function provider_provinceOp()
  814. {
  815. $provider_model = Model('refill_provider');
  816. $provider_id = $_GET['id'] ?? $_POST['id'];
  817. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  818. if (empty($provider)) {
  819. showMessage('通道信息有误');
  820. }
  821. $operator = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
  822. if (chksubmit()) {
  823. foreach ($operator as $opr) {
  824. $key = $opr . '-province';
  825. $province = $_POST[$key];
  826. if ($province == -1) {
  827. $updata[$opr] = -1;
  828. } else {
  829. $updata[$opr] = implode(',', $province);
  830. }
  831. }
  832. $resp = $provider_model->editProvider(['provinces' => serialize($updata)], ['provider_id' => $provider_id]);
  833. if ($resp) {
  834. showMessage('编辑成功', 'index.php?act=provider&op=index');
  835. } else {
  836. showMessage('编辑失败', "index.php?act=merchant&op=provider_province&id={$provider_id}");
  837. }
  838. } else {
  839. $data = unserialize($provider['provinces']);
  840. $provinces = [];
  841. foreach ($operator as $opr) {
  842. if (empty($data)) {
  843. $provinces[$opr] = [-1];
  844. } else {
  845. $provinces[$opr] = explode(',', $data[$opr]);
  846. }
  847. }
  848. $province_list = mtopcard\ProvinceList;
  849. Tpl::output('province_list', $province_list);
  850. Tpl::output('provider', $provider);
  851. Tpl::output('provinces', $provinces);
  852. Tpl::showpage('provider.province');
  853. }
  854. }
  855. public function changeProviderStateOp()
  856. {
  857. $provider_id = intval($_GET['id']);
  858. $state = intval($_GET['state']);
  859. $provider_model = Model('refill_provider');
  860. $provider_info = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  861. if (empty($provider_info) || !in_array($state, [1, 2])) {
  862. showMessage('操作成功', 'index.php?act=provider&op=index');
  863. }
  864. $resp = $provider_model->editProvider(['opened' => $state], ['provider_id' => $provider_id]);
  865. if (!$resp) {
  866. showMessage('操作失败', 'index.php?act=provider&op=index', 'html', 'error');
  867. }
  868. showMessage('操作成功', 'index.php?act=provider&op=index');
  869. }
  870. /**
  871. * 新增通道
  872. */
  873. public function provider_addOp()
  874. {
  875. $provider_model = Model('refill_provider');
  876. if (chksubmit()) {
  877. $params = $_POST;
  878. unset($params['form_submit']);
  879. $result = $provider_model->addProvider($params);
  880. if ($result) {
  881. $url = [
  882. [
  883. 'url' => 'index.php?act=provider&op=index',
  884. 'msg' => '返回通道列表',
  885. ],
  886. [
  887. 'url' => 'index.php?act=merchant&op=provider_add',
  888. 'msg' => '继续新增通道',
  889. ],
  890. ];
  891. $this->log('添加通道:' . '[ ' . $_POST['name'] . ']', 1);
  892. showMessage('通道添加成功', $url);
  893. } else {
  894. showMessage('通道添加失败');
  895. }
  896. }
  897. Tpl::showpage('provider.add');
  898. }
  899. public function provider_editOp()
  900. {
  901. $provider_model = Model('refill_provider');
  902. if (chksubmit()) {
  903. $provider_id = intval($_POST['provider_id']) ?? '';
  904. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  905. if (empty($provider)) {
  906. showMessage('通道信息有误');
  907. }
  908. $params = $_POST;
  909. unset($params['form_submit']);
  910. if (empty($params)) {
  911. showMessage('通道编辑成功', 'index.php?act=provider&op=index');
  912. }
  913. $result = $provider_model->editProvider($params, ['provider_id' => $provider_id]);
  914. if ($result) {
  915. $this->log('编辑通道:' . '[ ' . $provider['name'] . ']', 1);
  916. showMessage('通道编辑成功', 'index.php?act=provider&op=index');
  917. } else {
  918. showMessage('通道编辑失败', "index.php?act=merchant&op=provider_edit&id={$provider_id}");
  919. }
  920. }
  921. $provider_id = intval($_GET['id']) ?? '';
  922. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  923. if (empty($provider)) {
  924. showMessage('通道信息有误');
  925. }
  926. $type_text = ['油卡', '手机充值卡'];
  927. Tpl::output('type_text', $type_text);
  928. Tpl::output('provider', $provider);
  929. Tpl::showpage('provider.edit');
  930. }
  931. public function provider_delOp()
  932. {
  933. $provider_model = Model('refill_provider');
  934. $provider_id = intval($_GET['id']) ?? '';
  935. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  936. if (empty($provider)) {
  937. showMessage('通道信息有误');
  938. }
  939. $result = $provider_model->delProvider(['provider_id' => $provider_id]);
  940. if ($result) {
  941. $this->log('删除通道:' . '[ ' . $provider['name'] . ']', 1);
  942. showMessage('通道删除成功', 'index.php?act=provider&op=index');
  943. } else {
  944. showMessage('通道删除失败', "index.php?act=provider&op=index");
  945. }
  946. }
  947. public function OrderStatsCheckOp()
  948. {
  949. $stat_id = $_GET['stat_id'] ?? $_POST['stat_id'];
  950. $mod_stat = Model('refill_stats');
  951. $stats_data = $mod_stat->getStatsInfo(['stat_id' => $stat_id]);
  952. if (empty($stats_data)) {
  953. showMessage('对应数据不存在', '');
  954. }
  955. $type = $stats_data['type'];
  956. if (chksubmit()) {
  957. $corder_success_count = $_POST['corder_success_count'] ?? 0;
  958. $corder_success_amounts = $_POST['corder_success_amounts'] ?? 0;
  959. $corder_success_refill_amounts = $_POST['corder_success_refill_amounts'] ?? 0;
  960. $refund = $_POST['refund'] ?? 0;
  961. $remark = $_POST['remark'];
  962. $gap_order_count = $gap_success_amounts = $gap_success_refill_amounts = 0;
  963. if ($type == 'provider') {
  964. if (!empty($corder_success_amounts)) {
  965. $gap_success_amounts = $corder_success_amounts - $stats_data['success_channel_amounts'];
  966. }
  967. if (!empty($corder_success_count)) {
  968. $gap_order_count = $corder_success_count - $stats_data['success_count'];
  969. }
  970. } elseif ($type == 'merchant') {
  971. if (!empty($corder_success_count)) {
  972. $gap_order_count = $stats_data['success_count'] - $corder_success_count;
  973. }
  974. if (!empty($corder_success_amounts)) {
  975. $gap_success_amounts = $stats_data['success_channel_amounts'] - $corder_success_amounts;
  976. }
  977. } else {
  978. showMessage('对账数据类型错误', 'index.php?act=OrderStats&op=index');
  979. }
  980. if (!empty($corder_success_refill_amounts)) {
  981. $gap_success_refill_amounts = $corder_success_refill_amounts - $stats_data['success_refill_amounts'];
  982. }
  983. $updata['corder_success_count'] = $corder_success_count;
  984. $updata['corder_success_amounts'] = $corder_success_amounts;
  985. $updata['corder_success_refill_amounts'] = $corder_success_refill_amounts;
  986. $updata['gap_order_count'] = $gap_order_count;
  987. $updata['gap_success_amounts'] = $gap_success_amounts;
  988. $updata['gap_success_refill_amounts'] = $gap_success_refill_amounts;
  989. $updata['remark'] = $remark;
  990. $updata['refund'] = $refund;
  991. if (!empty($corder_success_count) && !empty($corder_success_amounts) && !empty($corder_success_refill_amounts)) {
  992. if ($gap_order_count == 0 && $gap_success_amounts == 0 && $gap_success_refill_amounts == 0) {
  993. $updata['check_status'] = 1;
  994. } else {
  995. $updata['check_status'] = 2;
  996. }
  997. }
  998. $res = $mod_stat->edit($stat_id, $updata);
  999. if ($res) {
  1000. showMessage('操作成功', "index.php?act=OrderStats&op=index&type={$type}&cid={$stats_data['cid']}&order_time_type={$stats_data['order_time_type']}");
  1001. } else {
  1002. showMessage('操作失败');
  1003. }
  1004. } else {
  1005. $type_text = ['provider' => '上游', 'merchant' => '商户'];
  1006. Tpl::output('stats_type', $type_text[$type]);
  1007. Tpl::output('stats_data', $stats_data);
  1008. Tpl::showpage('order.stats.check');
  1009. }
  1010. }
  1011. public function OrderStatsReloadOp()
  1012. {
  1013. $stat_id = $_GET['stat_id'];
  1014. $mod_stat = Model('refill_stats');
  1015. $stats_data = $mod_stat->getStatsInfo(['stat_id' => $stat_id]);
  1016. if (empty($stats_data)) {
  1017. showMessage('对应数据不存在', '');
  1018. }
  1019. $cond = [
  1020. 'type' => $stats_data['type'],
  1021. 'time_stamp' => $stats_data['time_stamp'],
  1022. 'cid' => $stats_data['cid'],
  1023. 'order_time_type' => $stats_data['order_time_type']
  1024. ];
  1025. $manager = new task\manager();
  1026. $task = $manager->add_task('order_stat_reload',$cond,0,3600);
  1027. if ($task->completed() && $task->success()) {
  1028. showMessage('操作成功');
  1029. } else {
  1030. showMessage("操作成功,后台任务已开始重新统计,请稍后查看新数据");
  1031. }
  1032. }
  1033. public function merchant_ctlOp()
  1034. {
  1035. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  1036. $model_merchant = Model('merchant');
  1037. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
  1038. if (empty($merchant)) {
  1039. showMessage('机构信息有误');
  1040. }
  1041. $qualitys = [
  1042. refill\Quality::Normal, refill\Quality::Quick, refill\Quality::CardKey, refill\Quality::ThirdShop,
  1043. refill\Quality::SlowTwentyFour, refill\Quality::SlowSix, refill\Quality::SlowTwo, refill\Quality::SlowFortyEight,
  1044. refill\Quality::SlowSeventyTwo, refill\Quality::Fastest
  1045. ];
  1046. if(chksubmit())
  1047. {
  1048. if(intval($_POST['transfer_opened']) === 1) {
  1049. if($_POST['transfer_mchid'] == $mchid) {
  1050. showMessage('预回调设置:转发通道不可为自身!');
  1051. }
  1052. $transfer_merchant = $model_merchant->getMerchantInfo(['mchid' => $_POST['transfer_mchid']], '*', true);
  1053. if(empty($transfer_merchant)) {
  1054. showMessage('预回调设置:转发通道不存在!');
  1055. }
  1056. }
  1057. if(!empty($_POST['segment'])) {
  1058. $segment = explode(',', $_POST['segment']);
  1059. foreach ($segment as $str) {
  1060. if (!preg_match('/^\d{3}$/',$str)){
  1061. showMessage('拦截设置:号段拦截有误!');
  1062. }
  1063. }
  1064. }
  1065. $transfer_data = function (){
  1066. $transfer_cfg['transfer_opened'] = intval($_POST['transfer_opened']) ?? 0;
  1067. $transfer_cfg['transfer_mchid'] = intval($_POST['transfer_mchid']) ?? 0;
  1068. $transfer_cfg['transfer_lowertime'] = intval($_POST['transfer_lowertime']) ?? 0;
  1069. $transfer_cfg['transfer_uppertime'] = intval($_POST['transfer_uppertime']) ?? 0;
  1070. return serialize($transfer_cfg);
  1071. };
  1072. $intercept_data = function (){
  1073. $intercept_cfg['is_transfer'] = intval($_POST['is_transfer']) === 1;
  1074. if (!empty($_POST['card_states'])) {
  1075. foreach ($_POST['card_states'] as $card_state)
  1076. {
  1077. $card_states[] = intval($card_state);
  1078. }
  1079. $intercept_cfg['card_states'] = $card_states;
  1080. }
  1081. if (!empty($_POST['card_types'])) {
  1082. foreach ($_POST['card_types'] as $card_type)
  1083. {
  1084. $card_types[] = intval($card_type);
  1085. }
  1086. $intercept_cfg['card_types'] = $card_types;
  1087. }
  1088. if(!empty($_POST['segment'])) {
  1089. $intercept_cfg['segment'] = trim($_POST['segment']);
  1090. }
  1091. return serialize($intercept_cfg);
  1092. };
  1093. $retry_times_data = function ($qualitys){
  1094. $qualities = [];
  1095. foreach ($qualitys as $quality) {
  1096. $quality = intval($quality);
  1097. $day_secs_key = "{$quality}-day_secs";
  1098. $night_secs_key = "{$quality}-night_secs";
  1099. $times_key = "{$quality}-times";
  1100. if(!empty($_POST[$day_secs_key]) && !empty($_POST[$night_secs_key]) && !empty($_POST[$times_key])) {
  1101. $qualities[$quality] = ['day_secs' => intval($_POST[$day_secs_key]), 'night_secs' => intval($_POST[$night_secs_key]), 'times' => intval($_POST[$times_key])];
  1102. }
  1103. }
  1104. $retry_times_cfg['qualities'] = $qualities;
  1105. $ratio = floatval($_POST['ratio']) ?? 0;
  1106. $period = intval($_POST['period']) ?? 0;
  1107. $profit_ratio = floatval($_POST['profit_ratio']) ?? 0;
  1108. $retry_times_cfg['lower_ratio'] = ['ratio' => $ratio, 'period' => $period];
  1109. $retry_times_cfg['profit_ratio'] = $profit_ratio;
  1110. $profit_formula = $_POST['profit_formula'] ?? '';
  1111. $retry_times_cfg['profit_formula'] = $profit_formula;
  1112. return serialize($retry_times_cfg);
  1113. };
  1114. $retry_times_cfg = $retry_times_data($qualitys);
  1115. $update['quality'] = intval($_POST['quality']);
  1116. $update['oil_quality'] = intval($_POST['oil_quality']);
  1117. $update['intercept_cfg'] = $intercept_data();
  1118. $update['retry_times_cfg'] = $retry_times_cfg;
  1119. $update['transfer_cfg'] = $transfer_data();
  1120. $resp = $model_merchant->editMerchant($update, ['mchid' => $mchid]);
  1121. if ($resp) {
  1122. $this->update_time_out($mchid);
  1123. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  1124. } else {
  1125. showMessage('操作失败');
  1126. }
  1127. }
  1128. else
  1129. {
  1130. foreach ($qualitys as $value) {
  1131. $quality[$value] = $this->quality_format($value,mtopcard\ChinaMobileCard);
  1132. }
  1133. Tpl::output('intercept', $this->merchant_intercept($merchant));
  1134. Tpl::output('retry_times', $this->merchant_retry_times($merchant));
  1135. Tpl::output('transfer_cfg', $this->transfer_cfg($merchant));
  1136. Tpl::output('merchant', $merchant);
  1137. Tpl::output('quality', $quality);
  1138. Tpl::output('card_state', mtopcard\CardState);
  1139. Tpl::showpage('merchant.ctl');
  1140. }
  1141. }
  1142. private function update_time_out($mchid)
  1143. {
  1144. $model_merchant = Model('merchant');
  1145. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
  1146. $org_quality = $merchant['quality'];
  1147. $retry_times_cfg = $this->merchant_retry_times($merchant);
  1148. $day_timeout = 0;
  1149. $night_timeout = 0;
  1150. $quality_ploy = new quality_ploy();
  1151. $qualities = $quality_ploy->qualities($org_quality);
  1152. foreach ($qualities as $quality) {
  1153. $day_timeout += $retry_times_cfg['qualities'][$quality]['day_secs'];
  1154. $night_timeout += $retry_times_cfg['qualities'][$quality]['night_secs'];
  1155. }
  1156. if (refill\functional::isDay()) {
  1157. $time_out = $day_timeout;
  1158. } else {
  1159. $time_out = $night_timeout;
  1160. }
  1161. $update['day_timeout'] = $day_timeout;
  1162. $update['night_timeout'] = $night_timeout;
  1163. $update['time_out'] = $time_out;
  1164. $model_merchant->editMerchant($update, ['mchid' => $mchid]);
  1165. }
  1166. private function merchant_intercept($merchant)
  1167. {
  1168. $intercept_cfg = $merchant['intercept_cfg'];
  1169. if (empty($intercept_cfg)) {
  1170. $intercept_cfg = ['card_states' => [], 'is_transfer' => 0, 'segment' => ''];
  1171. } else {
  1172. $intercept_cfg = unserialize($intercept_cfg);
  1173. }
  1174. return $intercept_cfg;
  1175. }
  1176. private function merchant_retry_times($merchant)
  1177. {
  1178. $retry_times_cfg = $merchant['retry_times_cfg'];
  1179. if (empty($retry_times_cfg)) {
  1180. $retry_times_cfg = [];
  1181. } else {
  1182. $retry_times_cfg = unserialize($retry_times_cfg);
  1183. }
  1184. return $retry_times_cfg;
  1185. }
  1186. private function transfer_cfg($merchant)
  1187. {
  1188. $transfer_cfg = $merchant['transfer_cfg'];
  1189. if (empty($transfer_cfg)) {
  1190. $transfer_cfg = ['transfer_opened' => 0, 'transfer_mchid' => 0, 'transfer_lowertime' => 0, 'transfer_uppertime' => 0];
  1191. } else {
  1192. $transfer_cfg = unserialize($transfer_cfg);
  1193. }
  1194. return $transfer_cfg;
  1195. }
  1196. }