merchant.php 51 KB

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