merchant.php 51 KB

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