merchant.php 52 KB

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