merchant.php 72 KB

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