merchant.php 57 KB

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