merchant.php 59 KB

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