merchant.php 55 KB

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