merchant.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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. class merchantControl extends SystemControl
  9. {
  10. const EXPORT_SIZE = 1000;
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. Language::read('merchant');
  15. }
  16. /**
  17. * 机构列表
  18. */
  19. public function merchantOp()
  20. {
  21. $model_merchant = Model('merchant');
  22. if (trim($_GET['merchant_name']) != '') {
  23. $condition['name'] = ['like', '%' . $_GET['merchant_name'] . '%'];
  24. Tpl::output('merchant_name', $_GET['merchant_name']);
  25. }
  26. $merchant_list = $model_merchant->getMerchantList($condition, 25, 'mchid desc');
  27. $merchant_state_text = ['使用中', '已禁用'];
  28. Tpl::output('merchant_state_text', $merchant_state_text);
  29. Tpl::output('merchant_list', $merchant_list);
  30. Tpl::output('page', $model_merchant->showpage('2'));
  31. Tpl::showpage('merchant.index');
  32. }
  33. public function changeStateOp()
  34. {
  35. $mchid = intval($_GET['mchid']);
  36. $state = intval($_GET['state']);
  37. $model_merchant = Model('merchant');
  38. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  39. if (empty($merchant_info) || !in_array($state, [1, 2])) {
  40. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  41. }
  42. $resp = $model_merchant->editMerchant(['merchant_state' => $state], ['mchid' => $mchid]);
  43. if (!$resp) {
  44. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  45. }
  46. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  47. }
  48. /**
  49. * 新增机构
  50. */
  51. public function merchant_addOp()
  52. {
  53. if (chksubmit()) {
  54. /**
  55. * 验证
  56. */
  57. $obj_validate = new Validator();
  58. $obj_validate->validateparam = [
  59. ["input" => $_POST["name"], "require" => "true", "message" => '机构账号不能为空'],
  60. ["input" => $_POST["company_name"], "require" => "true", "message" => '机构公司名称不能为空'],
  61. ["input" => $_POST["password"], "require" => "true", "message" => '密码不能为空']
  62. ];
  63. $error = $obj_validate->validate();
  64. if ($error != '') {
  65. showMessage($error);
  66. } else {
  67. $name = trim($_POST['name']);
  68. $company_name = trim($_POST['company_name']);
  69. $pwd = trim($_POST['password']);
  70. $alarm_amount = $_POST['alarm_amount'] ?? 0;
  71. $model_merchant = Model('merchant');
  72. $model_member = Model('member');
  73. try {
  74. $trans = new trans_wapper($model_merchant, __METHOD__);
  75. $insert_member['member_name'] = md5($name . time());
  76. $insert_member['member_passwd'] = $pwd;
  77. $insert_id = $model_member->addMember($insert_member);
  78. if ($insert_id == false) {
  79. $trans->rollback();
  80. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  81. }
  82. $insert_array['name'] = $name;
  83. $insert_array['company_name'] = $company_name;
  84. $insert_array['org_pwd'] = $pwd;
  85. $insert_array['password'] = md5($pwd);
  86. $insert_array['admin_id'] = trim($insert_id);
  87. $insert_array['alarm_amount'] = $alarm_amount;
  88. $result = $model_merchant->addMerchant($insert_array);
  89. if ($result) {
  90. $url = [
  91. [
  92. 'url' => 'index.php?act=merchant&op=merchant',
  93. 'msg' => '返回机构列表',
  94. ],
  95. [
  96. 'url' => 'index.php?act=merchant&op=merchant_add',
  97. 'msg' => '继续新增机构',
  98. ],
  99. ];
  100. $this->log('添加机构:' . '[ ' . $_POST['name'] . ']', 1);
  101. showMessage('机构添加成功', $url);
  102. } else {
  103. showMessage('机构添加失败');
  104. }
  105. $trans->commit();
  106. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  107. } catch (Exception $e) {
  108. $trans->rollback();
  109. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  110. }
  111. }
  112. }
  113. Tpl::showpage('merchant.add');
  114. }
  115. public function merchant_editOp()
  116. {
  117. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  118. $model_merchant = Model('merchant');
  119. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  120. if(empty($merchant)){
  121. showMessage('机构信息有误');
  122. }
  123. if (chksubmit()) {
  124. $update['company_name'] = trim($_POST['company_name']);
  125. $update['org_pwd'] = trim($_POST['password']);
  126. $update['password'] = md5($update['org_pwd']);
  127. $update['alarm_amount'] = $_POST['alarm_amount'] ?? 0;
  128. $result = $model_merchant->editMerchant($update,['mchid' => $mchid]);
  129. if ($result) {
  130. $this->log('编辑机构:' . '[ ' . $merchant['name'] . ']', 1);
  131. showMessage('机构编辑成功', 'index.php?act=merchant&op=merchant');
  132. } else {
  133. showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
  134. }
  135. }
  136. Tpl::output('merchant', $merchant);
  137. Tpl::showpage('merchant.edit');
  138. }
  139. public function orderStorgeOp()
  140. {
  141. if (chksubmit())
  142. {
  143. $mchids = $_POST['mchid'];
  144. $petrochinas = $_POST['petrochina'];
  145. $sinopecs = $_POST['sinopec'];
  146. foreach ($mchids as $pos => $mchid) {
  147. $mchid = intval($mchid);
  148. $data['mchid'] = $mchid;
  149. $data['petrochina'] = ['100' => intval($petrochinas[100][$pos]) , '200' => intval($petrochinas[200][$pos]) , '500' => intval($petrochinas[500][$pos]) , '1000' => intval($petrochinas[1000][$pos])];
  150. $data['sinopec'] = ['100' => intval($sinopecs[100][$pos]) , '200' => intval($sinopecs[200][$pos]) , '500' => intval($sinopecs[500][$pos]) , '1000' => intval($sinopecs[1000][$pos])];
  151. $data['time'] = time();
  152. $result[$mchid] = $data;
  153. }
  154. $this->cache_storge_limit($result);
  155. showMessage('编辑成功', 'index.php?act=merchant&op=merchant');
  156. }
  157. else
  158. {
  159. $order_limit = rcache('storge_limit' , 'merchant-');
  160. if(empty($order_limit)){
  161. $order_limit = [];
  162. }else{
  163. $order_limit = unserialize($order_limit['data']);
  164. }
  165. $initialiser = function ($merchant) {
  166. $amount = [
  167. '100' => -1,
  168. '200' => -1,
  169. '500' => -1,
  170. '1000' => -1
  171. ];
  172. $data['mchid'] = $merchant['mchid'];
  173. $data['petrochina'] = $data['sinopec'] = $amount;
  174. $data['time'] = time();
  175. return $data;
  176. };
  177. $reader = function ($mchid,$time)
  178. {
  179. $cond['mchid'] = $mchid;
  180. $cond['inner_status'] = 0;
  181. $cond['order_state'] = ORDER_STATE_SUCCESS;
  182. $cond['refill_order.order_time'] = ['egt', $time];
  183. $items = Model('')->table('refill_order,vr_order')->join('inner')
  184. ->on('refill_order.order_id=vr_order.order_id')
  185. ->field('refill_order.mchid,refill_order.card_type,refill_order.refill_amount,count(*) as num')
  186. ->group('refill_order.card_type,refill_order.refill_amount')
  187. ->where($cond)->select();
  188. return $items;
  189. };
  190. $type_map = [1 => 'petrochina' , 2 => 'sinopec'];
  191. $cur_limits = [];
  192. $model_merchant = model('merchant');
  193. $merchant_list = $model_merchant->getMerchantList([], 1000, 'mchid asc' , 'mchid,company_name');
  194. foreach ($merchant_list as $merchant)
  195. {
  196. $mchid = intval($merchant['mchid']);
  197. if(array_key_exists($mchid , $order_limit)) {
  198. $result[$mchid] = $order_limit[$mchid];
  199. }else{
  200. $result[$mchid] = $initialiser($merchant);
  201. }
  202. $start = $result[$mchid]['time'];
  203. $items = $reader($mchid,$start);
  204. $cur_limits[$mchid] = $result[$mchid];
  205. foreach ($items as $item) {
  206. $refill_amount = intval($item['refill_amount'] + 0.005);
  207. $card_type = $type_map[$item['card_type']];
  208. $cache_num = $result[$mchid][$card_type][$refill_amount];
  209. if ($cache_num == -1) {
  210. $new_num = -1;
  211. }else{
  212. $new_num = ($cache_num - $item['num']) >= 0 ? $cache_num - $item['num'] : 0;
  213. }
  214. $cur_limits[$mchid][$card_type][$refill_amount] = $new_num;
  215. }
  216. $cur_limits[$mchid]['company_name'] = $merchant['company_name'];
  217. }
  218. Tpl::output('data', $cur_limits);
  219. Tpl::showpage('merchant.orderlimit');
  220. }
  221. }
  222. private function cache_storge_limit($data)
  223. {
  224. Model('')->table('setting')->where(['name'=>'storge_limit'])->delete();
  225. Model('')->table('setting')->insert(['name'=>'storge_limit','value'=>serialize($data)]);
  226. wcache('storge_limit' , ['data' => serialize($data)] , 'merchant-');
  227. }
  228. public function priceOp()
  229. {
  230. $quality = $_GET['quality'] ? $_GET['quality'] : 1;
  231. if (chksubmit())
  232. {
  233. $mchid = $_POST['mchid'];
  234. //合并表单数据
  235. $card_types = $_POST['cardtype'];
  236. $specs = $_POST['spec'];
  237. $prices = $_POST['price'];
  238. foreach ($card_types as $key => $card_type) {
  239. $data['card_type'] = $card_type;
  240. $data['spec'] = intval($specs[$key]);
  241. $data['price'] = ncPriceFormat($prices[$key]);
  242. $params[] = $data;
  243. }
  244. foreach ($params as $param)
  245. {
  246. if($param['price'] > 0) {
  247. $insert['mchid'] = $mchid;
  248. $insert['spec'] = $param['spec'];
  249. $insert['price'] = $param['price'];
  250. $insert['card_types'] = $param['card_type'];
  251. $insert['quality'] = $quality;
  252. $inserts[] = $insert;
  253. }
  254. }
  255. if(empty($inserts)) {
  256. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  257. }
  258. try {
  259. $model_merchant = Model('merchant');
  260. $trans = new trans_wapper($model_merchant, __METHOD__);
  261. //删除旧费率
  262. $model_merchant->delPrices($mchid,$quality);
  263. //更新新费率
  264. $model_merchant->insertPrices($inserts);
  265. $trans->commit();
  266. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  267. } catch (Exception $e) {
  268. $trans->rollback();
  269. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  270. }
  271. }
  272. $mchid = $_GET['mchid'] ?? 0;
  273. $goods = $this->GoodsFormat($mchid,$quality);
  274. Tpl::output('goods', $goods);
  275. Tpl::showpage('merchant.price');
  276. }
  277. private function GoodsFormat($mchid,$quality)
  278. {
  279. $all_spector = function ()
  280. {
  281. global $config;
  282. $refill_specs = $config['refill_specs'];
  283. $all_type_specs = [];
  284. foreach ($refill_specs as $scard_type => $specs)
  285. {
  286. if ($scard_type == 'petrochina') { //中石油
  287. $card_type = 1;
  288. } elseif ($scard_type == 'sinopec') { //中石化
  289. $card_type = 2;
  290. } elseif ($scard_type == 'chinamobile') { //中国移动
  291. $card_type = 4;
  292. } elseif ($scard_type == 'chinaunicom') { //中国联通
  293. $card_type = 5;
  294. } elseif ($scard_type == 'chinatelecom') { //中国电信
  295. $card_type = 6;
  296. } else {
  297. continue;
  298. }
  299. $all_type_specs[$card_type] = $specs;
  300. }
  301. $result =[];
  302. foreach ($all_type_specs as $card_type => $specs) {
  303. foreach ($specs as $spec){
  304. $result["{$card_type}-{$spec}"] = ['card_type' => $card_type , 'spec' => $spec];
  305. }
  306. }
  307. return $result;
  308. };
  309. $merch_spector = function ($mchid , $quality)
  310. {
  311. $model_merchant = Model('merchant');
  312. $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid , 'quality' => $quality])->select();
  313. $result = [];
  314. foreach ($items as $item)
  315. {
  316. $card_types = explode(',' , $item['card_types']);
  317. foreach ($card_types as $card_type) {
  318. $value['spec'] = intval($item['spec']);
  319. $result["{$card_type}-{$value['spec']}"] = ['card_type'=>$card_type,
  320. 'spec' => intval($item['spec']),
  321. 'price' => $item['price']];
  322. }
  323. }
  324. return $result;
  325. };
  326. $all_cardtype_specs = $all_spector();
  327. $merch_cardtype_specs = $merch_spector($mchid,$quality);
  328. $merger = function ($all_specs,$mech_specs)
  329. {
  330. $result = [];
  331. foreach ($all_specs as $cardtype_spec => $value)
  332. {
  333. $card_name = $this->scard_type($value['card_type']);
  334. $data = [];
  335. $data['goods_name'] = $card_name;
  336. $data['card_type'] = $value['card_type'];
  337. $data['spec'] = $value['spec'];
  338. if(array_key_exists($cardtype_spec , $mech_specs)) {
  339. $data['price'] = $mech_specs[$cardtype_spec]['price'];
  340. } else {
  341. $data['price'] = 0;
  342. }
  343. $result[$value['card_type']][] = $data;
  344. }
  345. return $result;
  346. };
  347. $result = $merger($all_cardtype_specs,$merch_cardtype_specs);
  348. return $result;
  349. }
  350. public function check_merchantOp()
  351. {
  352. $mchid = trim($_GET['mchid']);
  353. if (!$mchid) {
  354. echo '';
  355. die;
  356. }
  357. $model_merchant = Model('merchant');
  358. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*');
  359. if (empty($merchant_info)) {
  360. echo '';
  361. die;
  362. }
  363. echo 'true';
  364. }
  365. /**
  366. * ajax操作
  367. */
  368. public function ajaxOp()
  369. {
  370. $model_merchant = Model('merchant');
  371. switch ($_GET['branch']) {
  372. /**
  373. * 验证机构名称是否重复
  374. */
  375. case 'check_mch_name':
  376. $condition['name'] = $_GET['name'];
  377. $list = $model_merchant->getMerchantInfo($condition);
  378. if (empty($list)) {
  379. echo 'true';
  380. } else {
  381. echo 'false';
  382. }
  383. exit;
  384. /**
  385. * 验证机构是否存在
  386. */
  387. case 'check_merchant':
  388. $condition['mchid'] = intval($_GET['mchid']);
  389. $list = $model_merchant->getMerchantInfo($condition);
  390. if (!empty($list)) {
  391. echo 'true';
  392. } else {
  393. echo 'false';
  394. }
  395. exit;
  396. }
  397. }
  398. /**
  399. * 充值申请列表
  400. */
  401. public function refill_evidenceOp()
  402. {
  403. $model_merchant = Model('merchant');
  404. $condition = [];
  405. if (trim($_GET['mch_name']) != '') {
  406. $condition['mch_name'] = array('like', '%' . $_GET['mch_name'] . '%');
  407. Tpl::output('mch_name', $_GET['mch_name']);
  408. }
  409. $state_sel = intval($_REQUEST['state_sel']);
  410. if ($state_sel == 1) {
  411. $condition['check_time'] = 0;
  412. $condition['status'] = 1;
  413. } elseif ($state_sel == 2) {
  414. $condition['check_time'] = ['gt', 0];
  415. $condition['status'] = 2;
  416. } elseif ($state_sel == 3) {
  417. $condition['check_time'] = ['gt', 0];
  418. $condition['status'] = 3;
  419. } else {
  420. }
  421. //充值申请列表
  422. $evidence_list = $model_merchant->getRefillEvidence($condition, 20, '*,member.available_predeposit', 'refill_evidence.add_time desc');
  423. $status_text = ['申请中', '已通过', '已驳回'];
  424. $operation_text = ['未预存', '已预存'];
  425. Tpl::output('evidence_list', $evidence_list);
  426. Tpl::output('status_text', $status_text);
  427. Tpl::output('operation_text', $operation_text);
  428. Tpl::output('page', $model_merchant->showpage('2'));
  429. Tpl::showpage('merchant.refill.evidence_list');
  430. }
  431. public function check_evidenceOp()
  432. {
  433. $status = $_GET['status'];
  434. $apply_id = intval($_GET['apply_id']);
  435. if ($apply_id > 0) {
  436. $model_merchant = Model('merchant');
  437. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  438. if (empty($evidence_info)) {
  439. showMessage('充值申请不存在');
  440. }
  441. if ($status == 'pass') {
  442. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 2, 'check_time' => time()]);
  443. } elseif ($status == 'unpass') {
  444. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 3, 'check_time' => time()]);
  445. } else {
  446. }
  447. }
  448. showMessage(L('nc_common_save_succ'), urlAdmin('merchant', 'refill_evidence'));
  449. }
  450. public function rechargeOp()
  451. {
  452. if (chksubmit()) {
  453. $mchid = $this->add_money();
  454. $model_merchant = Model('merchant');
  455. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  456. if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit'])
  457. {
  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=merchant&op=refill_evidence');
  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 add_money()
  478. {
  479. $obj_validate = new Validator();
  480. $obj_validate->validateparam = array(
  481. array("input" => $_POST["apply_id"], "require" => "true", "message" => Language::get('admin_points_member_error_again')),
  482. array("input" => $_POST["pointsnum"], "require" => "true", 'validator' => 'Compare', 'operator' => ' >= ', 'to' => 1, "message" => Language::get('admin_points_points_min_error'))
  483. );
  484. $error = $obj_validate->validate();
  485. if ($error != '') {
  486. showMessage($error, '', '', 'error');
  487. }
  488. $money = abs(floatval($_POST['pointsnum']));
  489. $memo = trim($_POST['pointsdesc']);
  490. if ($money <= 0) {
  491. showMessage('输入的金额必需大于0', '', 'html', 'error');
  492. }
  493. $apply_id = intval($_POST['apply_id']);
  494. $model_merchant = Model('merchant');
  495. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  496. if (!is_array($evidence_info) || count($evidence_info) <= 0) {
  497. showMessage("无效的充值申请信息", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  498. }
  499. if ($evidence_info['status'] != 2) {
  500. showMessage("该充值申请未被审核通过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  501. }
  502. if ($evidence_info['is_operation'] == 2) {
  503. showMessage("该充值申请未已被预存过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  504. }
  505. //查询会员信息
  506. $obj_member = Model('member');
  507. $member_id = intval($evidence_info['member_id']);
  508. $member_info = $obj_member->getMemberInfo(array('member_id' => $member_id));
  509. $available_predeposit = floatval($member_info['available_predeposit']);
  510. $freeze_predeposit = floatval($member_info['freeze_predeposit']);
  511. if ($_POST['operatetype'] == 2 && $money > $available_predeposit) {
  512. showMessage(('预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  513. }
  514. if ($_POST['operatetype'] == 3 && $money > $available_predeposit) {
  515. showMessage(('可冻结预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  516. }
  517. if ($_POST['operatetype'] == 4 && $money > $freeze_predeposit) {
  518. showMessage(('可恢复冻结预存款不足,会员当前冻结预存款') . $freeze_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  519. }
  520. $model_pd = Model('predeposit');
  521. $order_sn = $apply_id;
  522. $admininfo = $this->getAdminInfo();
  523. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款,金额为" . $money . ",编号为" . $order_sn;
  524. $admin_act = 'sys_add_money';
  525. switch ($_POST['operatetype']) {
  526. case 1:
  527. $admin_act = "sys_add_money";
  528. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【增加】,金额为" . $money . ",编号为" . $order_sn;
  529. break;
  530. case 2:
  531. $admin_act = "sys_del_money";
  532. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【减少】,金额为" . $money . ",编号为" . $order_sn;
  533. break;
  534. default:
  535. showMessage('操作失败', 'index.php?act=merchant&op=refill_evidence');
  536. break;
  537. }
  538. try {
  539. $trans = new trans_wapper($model_pd, __METHOD__);
  540. //扣除冻结的预存款
  541. $data = array();
  542. $data['member_id'] = $member_info['member_id'];
  543. $data['member_name'] = $member_info['member_name'];
  544. $data['amount'] = $money;
  545. $data['order_sn'] = $order_sn;
  546. $data['admin_name'] = $admininfo['name'];
  547. $data['pdr_sn'] = $order_sn;
  548. $data['lg_desc'] = $memo;
  549. $model_pd->changePd($admin_act, $data);
  550. $after_available = ncPriceFormat($available_predeposit + $evidence_info['amount']);
  551. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['is_operation' => 2 , 'after_available' => $after_available]);
  552. $trans->commit();
  553. $this->log($log_msg, 1);
  554. return $evidence_info['mchid'];
  555. } catch (Exception $e) {
  556. $trans->rollback();
  557. $this->log($log_msg, 0);
  558. showMessage($e->getMessage(), 'index.php?act=merchant&op=refill_evidence', 'html', 'error');
  559. exit;
  560. }
  561. }
  562. public function checkevidenceOp()
  563. {
  564. $apply_id = trim($_GET['apply_id']);
  565. if (!$apply_id) {
  566. echo '';
  567. die;
  568. }
  569. $model_merchant = Model('merchant');
  570. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  571. if (empty($evidence_info)) {
  572. echo '';
  573. die;
  574. }
  575. echo 'true';
  576. }
  577. public function refill_orderOp()
  578. {
  579. $model_refill_order = Model('refill_order');
  580. $condition['refill_order.inner_status'] = 0;
  581. $condition['refill_order.order_time'] = ['time', [strtotime(date("Y-m-d")), strtotime(date("Y-m-d"))]];
  582. if($_GET['order_state'] == ORDER_STATE_SEND) {
  583. unset($condition['refill_order.order_time']);
  584. }
  585. if (!empty($_GET['order_sn'])) {
  586. $condition['refill_order.order_sn'] = $_GET['order_sn'];
  587. unset($condition['refill_order.order_time']);
  588. }
  589. if (!empty($_GET['mch_order'])) {
  590. $condition['refill_order.mch_order'] = $_GET['mch_order'];
  591. unset($condition['refill_order.order_time']);
  592. }
  593. if (!empty($_GET['mchid'])) {
  594. $condition['refill_order.mchid'] = $_GET['mchid'];
  595. unset($condition['refill_order.order_time']);
  596. }
  597. if (!empty($_GET['channel_name'])) {
  598. $condition['refill_order.channel_name'] = $_GET['channel_name'];
  599. unset($condition['refill_order.order_time']);
  600. }
  601. if (!empty($_GET['store_id'])) {
  602. $condition['vr_order.store_id'] = $_GET['store_id'];
  603. unset($condition['refill_order.order_time']);
  604. }
  605. if (!empty($_GET['card_type'])) {
  606. if(in_array($_GET['card_type'] , ['1' , '2' , '4' , '5' , '6'])) {
  607. $condition['refill_order.card_type'] = $_GET['card_type'];
  608. }
  609. if($_GET['card_type'] == 'oil') {
  610. $condition['refill_order.card_type'] = ['in' , ['1' , '2']];
  611. }
  612. if($_GET['card_type'] == 'phone') {
  613. $condition['refill_order.card_type'] = ['in' , ['4' , '5' , '6']];
  614. }
  615. }
  616. if (!empty($_GET['ch_trade_no'])) {
  617. $condition['refill_order.ch_trade_no'] = $_GET['ch_trade_no'];
  618. unset($condition['refill_order.order_time']);
  619. }
  620. if (!empty($_GET['card_no'])) {
  621. $condition['refill_order.card_no'] = $_GET['card_no'];
  622. unset($condition['refill_order.order_time']);
  623. }
  624. if (in_array($_GET['refill_amount'], ['10', '20', '30', '50' , '100', '200', '300', '500' , '1000', '20000'])) {
  625. $condition['refill_order.refill_amount'] = $_GET['refill_amount'];
  626. }
  627. $start_unixtime = strtotime($_GET['query_start_time']);
  628. $end_unixtime = strtotime($_GET['query_end_time']);
  629. if ($start_unixtime >0 && $end_unixtime >0) {
  630. $condition['refill_order.order_time'] = ['time', [$start_unixtime, $end_unixtime]];
  631. }
  632. if (in_array($_GET['order_state'], ['0', '10', '20', '30', '40'])) {
  633. $condition['vr_order.order_state'] = $_GET['order_state'];
  634. if($_GET['order_state'] == ORDER_STATE_SEND) {
  635. if($_GET['time'] == 1){
  636. $condition['refill_order.order_time'] = ['between', [(time() - 3600) , (time() - 1800)]];
  637. }
  638. if($_GET['time'] == 2){
  639. $condition['refill_order.order_time'] = ['lt', (time() - 3600)];
  640. }
  641. }
  642. }
  643. $merchant_list = Model('')->table('merchant')->limit(100)->select();
  644. foreach ($merchant_list as $key =>$value) {
  645. $merchants[$value['mchid']] = $value;
  646. }
  647. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  648. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  649. ->on('refill_order.order_id=vr_order.order_id')
  650. ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
  651. ->where($condition)->select();
  652. $count = $this->refill_stat($condition);
  653. foreach ($order_list as $order_id => $order_info) {
  654. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  655. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  656. if($order_info['notify_time'] > 0)
  657. {
  658. $order_list[$order_id]['diff_time_text'] = $this->elapse_time($order_info['notify_time'] - $order_info['order_time']);
  659. $order_list[$order_id]['diff_time'] = $order_info['notify_time'] - $order_info['order_time'];
  660. }
  661. else
  662. {
  663. $order_list[$order_id]['diff_time_text'] = $this->elapse_time(time() - $order_info['order_time']);
  664. $order_list[$order_id]['diff_time'] = time() - $order_info['order_time'];
  665. }
  666. }
  667. $provider_list = Model('')->table('refill_provider')->limit(100)->select();
  668. Tpl::output('stat', $stat[0]);
  669. Tpl::output('count', $count);
  670. Tpl::output('order_list', $order_list);
  671. Tpl::output('provider_list', $provider_list);
  672. Tpl::output('show_page', $model_refill_order->showpage());
  673. Tpl::showpage('refill.order.index');
  674. }
  675. public function notify_merchantOp()
  676. {
  677. $order_id = $_GET['order_id'];
  678. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => true]);
  679. showMessage('操作成功', 'index.php?act=merchant&op=refill_order');
  680. }
  681. public function notify_manual_merchantOp()
  682. {
  683. $order_id = $_GET['order_id'];
  684. $type = $_GET['type'];
  685. $mod_order = Model('vr_order');
  686. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  687. if((time() - $order_info['order_time']) < 3600)
  688. {
  689. showMessage('订单时间未超过1小时', 'index.php?act=merchant&op=refill_order');
  690. }
  691. $logic_vr_order = Logic("vr_order");
  692. if($type == 'success') {
  693. $logic_vr_order->changeOrderStateSuccess($order_id);
  694. }elseif ($type == 'cancel') {
  695. $logic_vr_order->changeOrderStateCancel($order_info, '', "后台手动回调通知失败.");
  696. }else {
  697. showMessage('手动操作类型错误', 'index.php?act=merchant&op=refill_order');
  698. }
  699. $mod_refill = Model('refill_order');
  700. $mod_refill->edit($order_id, ['notify_time' => time(), 'notify_state' => 1]);
  701. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
  702. showMessage('操作成功', 'index.php?act=merchant&op=refill_order');
  703. }
  704. public function providerStatsOp()
  705. {
  706. $provider_model = Model('refill_provider');
  707. $condition = [];
  708. $provider_list = $provider_model->getProviderList($condition, 100);
  709. $opened_text = ['使用中', '已禁用'];
  710. $type_text = ['油卡', '手机充值卡'];
  711. Tpl::output('opened_text', $opened_text);
  712. Tpl::output('type_text', $type_text);
  713. Tpl::output('provider_list', $provider_list);
  714. Tpl::output('show_page', $provider_model->showpage());
  715. Tpl::showpage('provider.stats');
  716. }
  717. public function providerOp()
  718. {
  719. $this->sync_cfgs();
  720. $provider_model = Model('refill_provider');
  721. $condition = [];
  722. if (trim($_GET['name']) != '') {
  723. $condition['name'] = ['like', '%' . $_GET['name'] . '%'];
  724. Tpl::output('name', $_GET['name']);
  725. }
  726. if (in_array($_GET['type'], [1, 2])) {
  727. $condition['type'] = $_GET['type'];
  728. }
  729. $provider_list = $provider_model->getProviderList($condition, 100);
  730. foreach ($provider_list as $key => $provider) {
  731. if(!empty($provider['start_period']) && !empty($provider['end_period'])){
  732. $provider_list[$key]['period'] = $provider['start_period'] . '~' . $provider['end_period'];
  733. }else{
  734. $provider_list[$key]['period'] = '全时间段';
  735. }
  736. }
  737. $opened_text = ['使用中', '已禁用'];
  738. $type_text = ['油卡', '手机充值卡'];
  739. Tpl::output('opened_text', $opened_text);
  740. Tpl::output('type_text', $type_text);
  741. Tpl::output('provider_list', $provider_list);
  742. Tpl::output('show_page', $provider_model->showpage());
  743. Tpl::showpage('provider.index');
  744. }
  745. public function sync_cfgs()
  746. {
  747. $name_val = function ($items) {
  748. $result = [];
  749. foreach ($items as $item) {
  750. $name = $item['name'];
  751. $result[$name] = $item;
  752. }
  753. return $result;
  754. };
  755. $match = function ($all,$cur)
  756. {
  757. $inserts = [];
  758. foreach ($all as $key => $value)
  759. {
  760. if(!array_key_exists($key,$cur)) {
  761. $insert['name'] = $key;
  762. $insert['store_id'] = $value['cfg']['store_id'];
  763. $inserts[] = $insert;
  764. }
  765. }
  766. return $inserts;
  767. };
  768. $inserter = function ($mod,$type,$names)
  769. {
  770. foreach ($names as $name) {
  771. $data = ['name' => $name['name'],'type' => $type,'store_id' => $name['store_id']];
  772. $mod->insert($data);
  773. }
  774. };
  775. global $config;
  776. $oil_configs = $config['oil_providers'];
  777. $pho_configs = $config['phone_providers'];
  778. $oils = $name_val($oil_configs);
  779. $phones = $name_val($pho_configs);
  780. $mod_prov = Model('refill_provider');
  781. $oil_items = $mod_prov->getProviderList(['type' => 1]);
  782. $oil_items = $name_val($oil_items);
  783. $oil_inserts = $match($oils,$oil_items);
  784. $phone_items = $mod_prov->getProviderList(['type' => 2]);
  785. $phone_items = $name_val($phone_items);
  786. $phone_inserts = $match($phones,$phone_items);
  787. $inserter($mod_prov,1,$oil_inserts);
  788. $inserter($mod_prov,2,$phone_inserts);
  789. }
  790. public function changeProviderStateOp()
  791. {
  792. $provider_id = intval($_GET['id']);
  793. $state = intval($_GET['state']);
  794. $provider_model = Model('refill_provider');
  795. $provider_info = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  796. if (empty($provider_info) || !in_array($state, [1, 2])) {
  797. showMessage('操作成功', 'index.php?act=merchant&op=provider');
  798. }
  799. $resp = $provider_model->editProvider(['opened' => $state], ['provider_id' => $provider_id]);
  800. if (!$resp) {
  801. showMessage('操作失败', 'index.php?act=merchant&op=provider', 'html', 'error');
  802. }
  803. showMessage('操作成功', 'index.php?act=merchant&op=provider');
  804. }
  805. /**
  806. * 新增通道
  807. */
  808. public function provider_addOp()
  809. {
  810. $provider_model = Model('refill_provider');
  811. if (chksubmit()) {
  812. $params = $_POST;
  813. unset($params['form_submit']);
  814. $result = $provider_model->addProvider($params);
  815. if ($result) {
  816. $url = [
  817. [
  818. 'url' => 'index.php?act=merchant&op=provider',
  819. 'msg' => '返回通道列表',
  820. ],
  821. [
  822. 'url' => 'index.php?act=merchant&op=provider_add',
  823. 'msg' => '继续新增通道',
  824. ],
  825. ];
  826. $this->log('添加通道:' . '[ ' . $_POST['name'] . ']', 1);
  827. showMessage('通道添加成功', $url);
  828. } else {
  829. showMessage('通道添加失败');
  830. }
  831. }
  832. Tpl::showpage('provider.add');
  833. }
  834. public function provider_editOp()
  835. {
  836. $provider_model = Model('refill_provider');
  837. if (chksubmit()) {
  838. $provider_id = intval($_POST['provider_id']) ?? '';
  839. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  840. if (empty($provider)) {
  841. showMessage('通道信息有误');
  842. }
  843. $params = $_POST;
  844. unset($params['form_submit']);
  845. if (empty($params)) {
  846. showMessage('通道编辑成功', 'index.php?act=merchant&op=provider');
  847. }
  848. $result = $provider_model->editProvider($params, ['provider_id' => $provider_id]);
  849. if ($result) {
  850. $this->log('编辑通道:' . '[ ' . $provider['name'] . ']', 1);
  851. showMessage('通道编辑成功', 'index.php?act=merchant&op=provider');
  852. } else {
  853. showMessage('通道编辑失败', "index.php?act=merchant&op=provider_edit&id={$provider_id}");
  854. }
  855. }
  856. $provider_id = intval($_GET['id']) ?? '';
  857. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  858. if (empty($provider)) {
  859. showMessage('通道信息有误');
  860. }
  861. $type_text = ['油卡', '手机充值卡'];
  862. Tpl::output('type_text', $type_text);
  863. Tpl::output('provider', $provider);
  864. Tpl::showpage('provider.edit');
  865. }
  866. public function provider_delOp()
  867. {
  868. $provider_model = Model('refill_provider');
  869. $provider_id = intval($_GET['id']) ?? '';
  870. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  871. if (empty($provider)) {
  872. showMessage('通道信息有误');
  873. }
  874. $result = $provider_model->delProvider(['provider_id' => $provider_id]);
  875. if ($result) {
  876. $this->log('删除通道:' . '[ ' . $provider['name'] . ']', 1);
  877. showMessage('通道删除成功', 'index.php?act=merchant&op=provider');
  878. } else {
  879. showMessage('通道删除失败', "index.php?act=merchant&op=provider");
  880. }
  881. }
  882. public function provider_amount_controlOp()
  883. {
  884. global $config;
  885. $type = $_GET['type'] ?? $_POST['type'];
  886. $form = $_GET['form'] ?? $_POST['form'];
  887. $rkey = $this->speed_key($type , $form);
  888. if (chksubmit())
  889. {
  890. $pids = $_POST['pid'];
  891. $names = $_POST['name'];
  892. $types = $_POST['types'];
  893. $amounts = $_POST['amount'];
  894. $speeds = $_POST['speed'];
  895. $sorts = $_POST['sort'];
  896. $openeds = $_POST['opened'];
  897. $hass = $_POST['has'];
  898. foreach ($pids as $key => $pid) {
  899. if($hass[$key] == 0) {
  900. continue;
  901. }
  902. $data['pid'] = intval($pid);
  903. $data['name'] = $names[$key];
  904. $data['type'] = intval($types[$key]);
  905. $data['amount'] = intval($amounts[$key]);
  906. $data['speed'] = intval($speeds[$key]);
  907. $data['sort'] = intval($sorts[$key]);
  908. $data['opened'] = intval($openeds[$key]);
  909. $index = "{$data['type']}-{$data['amount']}";
  910. $result[$index][] = $data;
  911. }
  912. wcache($rkey , ['data' => serialize($result)] , 'provider-');
  913. showMessage('编辑成功', 'index.php?act=merchant&op=provider');
  914. }
  915. else
  916. {
  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. $provider_model = Model('refill_provider');
  932. $providers = $provider_model->getProviderList(['type' => $type] , '1000' , 'provider_id,name' , 'provider_id asc');
  933. if(empty($providers)) {
  934. showMessage('暂无相关通道', 'index.php?act=merchant&op=provider');
  935. }
  936. $formData = $this->formData($type , $form);
  937. $amounts = $formData['amounts'];
  938. $cfgs = $formData['cfgs'];
  939. $types = $formData['types'];
  940. foreach ($speed_limit as $key => $speed) {
  941. foreach ($speed as $value) {
  942. $speed_limit[$key][$value['pid']] = $value;
  943. }
  944. }
  945. $ProviderManager = new \refill\ProviderManager();
  946. $ProviderManager->load();
  947. $QPTA = $ProviderManager->getQPTA();
  948. if($form == 'common') {
  949. $QPTA = $QPTA[1];
  950. }
  951. if($form == 'fast') {
  952. $QPTA = $QPTA[2];
  953. }
  954. foreach ($providers as $key => $provider)
  955. {
  956. $result = [];
  957. $pid = $provider['provider_id'];
  958. $name = $provider['name'];
  959. if(empty($cfgs) || !array_key_exists($name , $cfgs)) {
  960. unset($providers[$key]);
  961. continue;
  962. }
  963. foreach ($types as $type)
  964. {
  965. foreach ($amounts as $k => $amount)
  966. {
  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(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=merchant&op=provider');
  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=merchant&op=provider");
  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. {
  1024. foreach ($amounts as $amount)
  1025. {
  1026. $data['text'] = $value . '-' . $amount . '元';
  1027. $data['type'] = $type_data[$key];
  1028. $data['amount'] = $amount;
  1029. $amountData[] = $data;
  1030. }
  1031. }
  1032. foreach ($cfgs as $cfg) {
  1033. $pcfgs[$cfg['name']] = $cfg;
  1034. }
  1035. return [ 'amountData' => $amountData , 'form' => $form , 'amounts' => $amounts , 'types' => $type_data , 'cfgs' => $pcfgs];
  1036. }
  1037. private function scard_type(int $card_type)
  1038. {
  1039. if ($card_type == 1) { //中石油
  1040. return '中石油';
  1041. } elseif ($card_type == 2) { //中石化
  1042. return '中石化';
  1043. } elseif ($card_type == 4) { //中国移动
  1044. return '中国移动';
  1045. } elseif ($card_type == 5) { //中国联通
  1046. return '中国联通';
  1047. } elseif ($card_type == 6) { //中国电信
  1048. return '中国电信';
  1049. } else {
  1050. return 'unknown';
  1051. }
  1052. }
  1053. private function elapse_time($seconds)
  1054. {
  1055. $minutes = intval($seconds / 60);
  1056. $second = intval($seconds % 60);
  1057. if($minutes >= 60) {
  1058. $minute = $minutes % 60;
  1059. $hours = intval($minutes / 60);
  1060. $result = "{$minute}m{$second}s";
  1061. }
  1062. elseif($minutes > 0) {
  1063. $result = "{$minutes}m{$second}s";
  1064. } else {
  1065. $result = "{$second}s";
  1066. }
  1067. if(isset($hours))
  1068. {
  1069. $result = "{$hours}h{$minute}m";
  1070. }
  1071. return $result;
  1072. }
  1073. private function refill_stat($condition)
  1074. {
  1075. $model_refill_order = Model('refill_order');
  1076. $i = $half_count = $hour_count = 0;
  1077. while (true)
  1078. {
  1079. $start = $i * 100000;
  1080. $orders = $model_refill_order->getMerchantOrderList($condition, '', 'refill_order.*,vr_order.order_state','order_time desc' ,"{$start},100000");
  1081. $i++;
  1082. if (empty($orders)) {
  1083. break;
  1084. }
  1085. foreach ($orders as $order)
  1086. {
  1087. if($order['notify_time'] == 0 || $order['notify_time'] == null)
  1088. {
  1089. $order['diff_time'] = time() - $order['order_time'];
  1090. if($order['order_state'] == ORDER_STATE_SEND) {
  1091. if($order['diff_time'] > 1800 && $order['diff_time'] < 3600) {
  1092. $half_count++;
  1093. }
  1094. if($order['diff_time'] > 3600) {
  1095. $hour_count++;
  1096. }
  1097. }
  1098. }
  1099. }
  1100. if (count($orders) < 100000) {
  1101. break;
  1102. }
  1103. }
  1104. return ['half_count' => $half_count , 'hour_count' => $hour_count];
  1105. }
  1106. }