predeposit_helper.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/4/12
  6. * Time: 下午4:57
  7. */
  8. require_once(BASE_ROOT_PATH . '/helper/model_helper.php');
  9. require_once(BASE_ROOT_PATH . '/helper/bonus_helper.php');
  10. require_once(BASE_ROOT_PATH . '/helper/account_helper.php');
  11. class RateMoney
  12. {
  13. const ASC = 1;
  14. const DESC = 2;
  15. const PRED_RATE = 30;
  16. private $mRates;
  17. private $mDirty;
  18. public function __construct($rates)
  19. {
  20. $this->mDirty = false;
  21. $this->mRates = [];
  22. foreach ($rates as $key => $val)
  23. {
  24. $val = intval(100 * $val + 0.5);
  25. if($val > 0) {
  26. $this->mRates[$key] = $val / 100;
  27. }
  28. }
  29. krsort($this->mRates);
  30. }
  31. public function add_bonuses($items)
  32. {
  33. foreach ($items as $item)
  34. {
  35. $bonus = \bonus\user_bonus::create_by_param($item);
  36. $rate = $bonus->bonus_rate();
  37. $amount = intval($bonus->remain_amount() * 100 + 0.5);
  38. if($amount <= 0) continue;
  39. $this->mDirty = true;
  40. if(isset($this->mRates[$rate]) == false) {
  41. $this->mRates[$rate] = 0.00;
  42. }
  43. $this->mRates[$rate] += $bonus->remain_amount();
  44. }
  45. krsort($this->mRates);
  46. }
  47. public function balance($money)
  48. {
  49. $money = intval($money * 100 + 0.5);
  50. $total = intval($this->total() * 100 + 0.5);
  51. if($money > $total)
  52. {
  53. if(isset($this->mRates[self::PRED_RATE]) == false) {
  54. $this->mRates[self::PRED_RATE] = 0.00;
  55. }
  56. $this->mRates[self::PRED_RATE] += ($money - $total) / 100;
  57. }
  58. }
  59. public function resort()
  60. {
  61. krsort($this->mRates);
  62. }
  63. public function is_enough(&$rate,$amount)
  64. {
  65. $amount = intval($amount * 100 + 0.5);
  66. foreach ($this->mRates as $key => $val)
  67. {
  68. $val = intval($val * 100 + 0.5);
  69. if($rate == -1)
  70. {
  71. if($val >= $amount) {
  72. $rate = $key;
  73. return true;
  74. }
  75. }
  76. else
  77. {
  78. if($rate == $key)
  79. {
  80. $rate = $key;
  81. if($val >= $amount) {
  82. return true;
  83. } else {
  84. return false;
  85. }
  86. }
  87. }
  88. }
  89. return false;
  90. }
  91. public function with_hold($rate,$amount)
  92. {
  93. if(isset($this->mRates[$rate])) {
  94. $this->mDirty = true;
  95. $this->mRates[$rate] = $this->mRates[$rate] - $amount;
  96. }
  97. }
  98. public function find_rate($amount)
  99. {
  100. if(empty($this->mRates)) return false;
  101. $rates = $this->mRates;
  102. ksort($rates);
  103. foreach ($rates as $rate => $money)
  104. {
  105. $money = intval($money * 100 + 0.5);
  106. $amount = intval($amount * 100 + 0.5);
  107. if($amount >= $money) {
  108. return array('rate' => $rate,'amount' => $money / 100);
  109. } else {
  110. return array('rate' => $rate,'amount' => $amount / 100);
  111. }
  112. }
  113. return false;
  114. }
  115. public function format()
  116. {
  117. $result = [];
  118. foreach ($this->mRates as $key => $val)
  119. {
  120. $val = intval($val * 100 + 0.5);
  121. if($val > 0) {
  122. $result[$key] = $val / 100;
  123. }
  124. }
  125. return $result;
  126. }
  127. public function total()
  128. {
  129. $total = 0.00;
  130. foreach ($this->mRates as $key => $amount) {
  131. $total += $amount;
  132. }
  133. return $total;
  134. }
  135. public function dirty() {
  136. return $this->mDirty;
  137. }
  138. public function clean() {
  139. $this->mDirty = false;
  140. }
  141. public function calc_money($price,&$rates)
  142. {
  143. $rates = [];
  144. $disc = 0;
  145. $left = intval($price * 100 + 0.5);
  146. foreach ($this->mRates as $rate => $total)
  147. {
  148. if($left <= 0) break;
  149. if($rate > 100) continue;
  150. $total = intval($total * 100 + 0.5);
  151. if($total <= 0) {
  152. continue;
  153. }
  154. else
  155. {
  156. $max_rate = intval($left * $rate / 100 + 0.5);
  157. if($total >= $max_rate) {
  158. $disc += $max_rate;
  159. $left = 0;
  160. $rates[$rate] = $max_rate / 100;
  161. } else {
  162. $disc += $total;
  163. $left -= intval($total * 100 / $rate + 0.5);
  164. $rates[$rate] = $total / 100;
  165. }
  166. }
  167. }
  168. $cur_price = intval($price * 100 + 0.5) - $disc;
  169. return $cur_price / 100;
  170. }
  171. public function calc_price($price,&$rates)
  172. {
  173. $cur_price = intval($this->calc_money($price,$rates) * 100 + 0.5);
  174. return $cur_price / 100;
  175. }
  176. static function scale() {
  177. return (100 - self::PRED_RATE) / 100;
  178. }
  179. }
  180. class predeposit_helper
  181. {
  182. private $model_pd;
  183. private $member_id;
  184. private $mTotalPred;
  185. private $mFreezePred;
  186. private $mRates;
  187. private $mBonusState;
  188. private $mRateVersion; //用来记录,红包过期带来的红包变化
  189. public function __construct($member_id)
  190. {
  191. $this->model_pd = Model('predeposit');
  192. $this->member_id = $member_id;
  193. $pd_array = Model('member')->getMemberPdInfo($this->member_id);
  194. $this->mTotalPred = $pd_array['available_predeposit']; // 当前预存款
  195. $this->mFreezePred = $pd_array['freeze_predeposit']; // 当前预存款冻结
  196. $this->mRateVersion = intval($pd_array['rate_version']);
  197. $this->init_rate();
  198. }
  199. private function init_rate()
  200. {
  201. $fUpdate = false;
  202. if(isset($_SESSION['bonus_rate_version']) == false) {
  203. $fUpdate = true;
  204. }
  205. else
  206. {
  207. $version = $_SESSION['bonus_rate_version'];
  208. if($version != $this->mRateVersion) {
  209. $fUpdate = true;
  210. }
  211. else
  212. {
  213. if(isset($_SESSION['bonus_rate']) && isset($_SESSION['bonus_state'])) {
  214. $this->mRates = new RateMoney($_SESSION['bonus_rate']);
  215. $this->mBonusState = $_SESSION['bonus_state'];
  216. } else {
  217. $fUpdate = true;
  218. }
  219. }
  220. }
  221. if($fUpdate)
  222. {
  223. $mod_bonus = Model('user_bonus');
  224. $this->mRates = new RateMoney(array());
  225. $items = $mod_bonus->getUsableBonus($this->member_id);
  226. $this->mRates->add_bonuses($items);
  227. $this->mRates->balance($this->mTotalPred);
  228. $bonus_rate = $this->mRates->format();
  229. $this->mBonusState = [];
  230. $querys = array('usable','expiring','used','expired');
  231. foreach ($querys as $state) {
  232. $cond = $this->query_cond($state);
  233. if($state == 'used') {
  234. $sum = $mod_bonus->getSum($cond,'bonus_value');
  235. } else {
  236. $sum = $mod_bonus->getSum($cond);
  237. }
  238. $this->mBonusState[$state] = doubleval($sum);
  239. }
  240. $this->write_rates($this->mBonusState,$bonus_rate);
  241. $this->mRates->clean();
  242. }
  243. }
  244. public function __destruct()
  245. {
  246. if($this->mRates != null && $this->mRates->dirty()) {
  247. $this->del_rates();
  248. }
  249. }
  250. public function bonus_rate() {
  251. return $this->mRates;
  252. }
  253. static public function order_cash($goods_amount, &$rates)
  254. {
  255. if(isset($_SESSION['bonus_rate']) == false) {
  256. $pred = new predeposit_helper($_SESSION['member_id']);
  257. $bonus_rate = $pred->bonus_rate();
  258. } else {
  259. $bonus_rate = new RateMoney($_SESSION['bonus_rate']);
  260. }
  261. return $bonus_rate->calc_money($goods_amount,$rates);
  262. }
  263. static public function login_bonus_price($goods_price, &$rates)
  264. {
  265. if(session_helper::isLogin())
  266. {
  267. if(isset($_SESSION['bonus_rate']) == false) {
  268. $pred = new predeposit_helper($_SESSION['member_id']);
  269. $bonus_rate = $pred->bonus_rate();
  270. } else {
  271. $bonus_rate = new RateMoney($_SESSION['bonus_rate']);
  272. }
  273. return $bonus_rate->calc_price($goods_price,$rates);
  274. }
  275. else
  276. {
  277. return $goods_price;
  278. }
  279. }
  280. static public function unlogin_bonus_price($goods_price,$rate_moneys,&$rates)
  281. {
  282. if(!empty($rate_moneys)) {
  283. $bonus_rate = new RateMoney($rate_moneys);
  284. return $bonus_rate->calc_price($goods_price,$rates);
  285. } else {
  286. return $goods_price;
  287. }
  288. }
  289. static public function discount_gap($bonus_price,$goods_price)
  290. {
  291. $bonus_price = intval($bonus_price* 100 + 0.5);
  292. $discount = intval($goods_price * 70 + 0.5);
  293. if($bonus_price <= $discount) {
  294. return 0;
  295. } else {
  296. return ($bonus_price - $discount) / 100;
  297. }
  298. }
  299. public function bonus_state() {
  300. return $this->mBonusState;
  301. }
  302. private function query_cond($query_state)
  303. {
  304. static $stQuerys = array('usable','expiring','used','expired');
  305. static $day_secs = 24 * 3600;
  306. $cond = array('user_id' => $_SESSION['member_id'],'bonus_status' => 3);
  307. if(!empty($query_state) && in_array($query_state,$stQuerys))
  308. {
  309. if($query_state == 'usable') {
  310. $cond['remain_amount'] = array('gt','0.00');
  311. $cond['expired'] = 0;
  312. } elseif ($query_state == 'expiring') {
  313. $cond['usable_time'] = array('elt',time() + 5 * $day_secs);
  314. $cond['remain_amount'] = array('gt','0.00');
  315. $cond['expired'] = 0;
  316. } elseif ($query_state == 'used') {
  317. $cond['remain_amount'] = '0.00';
  318. $cond['expired'] = 0;
  319. } elseif ($query_state == 'expired') {
  320. $cond['expired'] = 1;
  321. } else {
  322. }
  323. }
  324. return $cond;
  325. }
  326. private function write_rates($bonus_state,$bonus_rate)
  327. {
  328. $_SESSION['bonus_state'] = $bonus_state;
  329. $_SESSION['bonus_rate'] = $bonus_rate;
  330. $_SESSION['bonus_rate_version'] = $this->mRateVersion;
  331. }
  332. private function del_rates()
  333. {
  334. if(isset($_SESSION['bonus_state'])) {
  335. unset($_SESSION['bonus_state']);
  336. }
  337. if(isset($_SESSION['bonus_rate'])) {
  338. unset($_SESSION['bonus_rate']);
  339. }
  340. if(isset($_SESSION['bonus_rate_version'])) {
  341. unset($_SESSION['bonus_rate_version']);
  342. }
  343. }
  344. public function topup_bonus($mobile)
  345. {
  346. $bonuses = bonus_helper::topup_bonus($this,$mobile);
  347. if($bonuses != false) {
  348. $this->del_rates();
  349. }
  350. return $bonuses;
  351. }
  352. public function total_pred() {
  353. return $this->mTotalPred;
  354. }
  355. public function freeze_pred() {
  356. return $this->mFreezePred;
  357. }
  358. public function is_enough($money) {
  359. return intval($this->total_pred() * 100) >= intval($money * 100);
  360. }
  361. public function person_enough($money,&$bonus_rate)
  362. {
  363. if($this->mRates == null) return false;
  364. return $this->mRates->is_enough($bonus_rate,$money);
  365. }
  366. public function rates() {
  367. return $this->mRates == null ? false : $this->mRates;
  368. }
  369. public function makeby_bonus($param, $rate_moneys, $bonus_sn)
  370. {
  371. $result = bonus_helper::make_bonus($param,$rate_moneys);
  372. if($result == false) return false;
  373. foreach ($rate_moneys as $item) {
  374. $rate = intval($item['rate']);
  375. $val = $item['hold_amount'];
  376. bonus_helper::withold_bonus($this->member_id,$bonus_sn,$rate,$val,bonus_helper::send_bonus_withold);
  377. }
  378. $type_sn = $result['type_sn'];
  379. $money = $result['money'];
  380. $this->handout_bonus($money,$type_sn,session_helper::nickname(),"发送了{$money}元的红包.",\bonus\type::MakeSendType);
  381. foreach ($rate_moneys as $item) {
  382. $this->mRates->with_hold($item['rate'],$item['amount']);
  383. }
  384. return $result;
  385. }
  386. public function make_bonus($param,$rate_moneys)
  387. {
  388. $result = bonus_helper::make_bonus($param,$rate_moneys);
  389. if($result == false) return false;
  390. $rates = [];
  391. foreach ($rate_moneys as $item) {
  392. $rate = intval($item['rate']);
  393. $val = $item['hold_amount'];
  394. $rates[$rate] = $val;
  395. }
  396. bonus_helper::withold($this->member_id,$rates,bonus_helper::send_bonus_withold);
  397. $type_sn = $result['type_sn'];
  398. $money = $result['money'];
  399. $this->handout_bonus($money,$type_sn,session_helper::nickname(),"发送了{$money}元的红包.",\bonus\type::MakeSendType);
  400. foreach ($rate_moneys as $item) {
  401. $this->mRates->with_hold($item['rate'],$item['amount']);
  402. }
  403. return $result;
  404. }
  405. private function base_param($amount,$total_num)
  406. {
  407. $param = array();
  408. $param['total_amount'] = $amount;
  409. $param['total_num'] = $total_num;
  410. $param['send_type'] = 1;
  411. return $param;
  412. }
  413. public function share_bonus($bonus_sn,&$msg)
  414. {
  415. $bonus = bonus\user_bonus::create_by_sn($bonus_sn);
  416. if($bonus->spend_over()) {
  417. $msg = "该红包现金已经花光了~";
  418. return false;
  419. }
  420. $amount = $bonus->remain_amount();
  421. $param = $this->base_param($amount,1);
  422. $minfo = new member_info($this->member_id);
  423. $param['sender_id'] = $this->member_id;
  424. $param['sender_mobile'] = $minfo->mobile();
  425. $param['sender_name'] = $minfo->nickname();
  426. $param['make_type'] = \bonus\type::MakeSendType;
  427. $name = $minfo->nickname();
  428. $param['type_name'] = "{$name}";
  429. $type = \bonus\type::crate_by_input($param);
  430. $rate_moneys = [];
  431. $item['amount'] = $type->getTotal_amount();
  432. $item['num'] = $type->getTotal_num();
  433. $item['rate'] = $bonus->bonus_rate();
  434. $rate_moneys[] = $item;
  435. $result = bonus_helper::make_bonus($param,$rate_moneys);
  436. if($result == false) {
  437. return false;
  438. }
  439. else
  440. {
  441. if(bonus_helper::withold_bonus($this->member_id,$bonus->bonus_rate(),
  442. $bonus_sn,$type->getTotal_amount(),bonus_helper::send_bonus_withold))
  443. {
  444. $type_sn = $result['type_sn'];
  445. $money = $result['money'];
  446. $this->handout_bonus($money,$type_sn,session_helper::nickname(),"发送了{$money}元的红包.",\bonus\type::MakeSendType);
  447. }
  448. return $result;
  449. }
  450. }
  451. public function admin_make_bonus($param,$rate_moneys)
  452. {
  453. return bonus_helper::make_bonus($param,$rate_moneys);
  454. }
  455. public function bonus_expire($bouns)
  456. {
  457. try
  458. {
  459. $bonus_obj = bonus\user_bonus::create_by_param($bouns);
  460. if($bonus_obj->spend_over()) {
  461. return false;
  462. }
  463. $this->inc_rate_version();
  464. $minfo = new member_info($this->member_id);
  465. $data = array();
  466. $data['member_id'] = $this->member_id;
  467. $data['member_name'] = $minfo->nickname();
  468. $data['amount'] = $bonus_obj->remain_amount();
  469. $data['order_sn'] = $bonus_obj->bonus_sn();
  470. $data['admin_name'] = "熊猫美妆";
  471. $data['pdr_sn'] = $bonus_obj->bonus_sn();
  472. $data['lg_desc'] = "红包过期扣款";
  473. $this->model_pd->changePd("bonus_expire", $data);
  474. return true;
  475. } catch (Exception $ex) {
  476. return false;
  477. }
  478. }
  479. public function bonus_refund($bonus_type)
  480. {
  481. $types = bonus\type::create_by_paramer($bonus_type);
  482. QueueClient::push('onPredeposit',
  483. array('change_type' => 'bonus_refund','buyer_id'=>$types->sender_id(),'order_sn'=>$types->getType_sn()));
  484. }
  485. public function transform_money($member_id,$name,$amount)
  486. {
  487. $data = array();
  488. $data['member_id'] = $member_id;
  489. $data['member_name'] = is_null($name) ? '' : $name;
  490. $data['amount'] = $amount;
  491. $order_sn = $this->model_pd->makeSn();
  492. $data['order_sn'] = $order_sn;
  493. $data['admin_name'] = '平台管理员';
  494. $data['pdr_sn'] = $order_sn;
  495. $data['lg_desc'] = '版本升级,余额迁移.';
  496. $this->model_pd->changePd("sys_add_money",$data);
  497. }
  498. public function bonus_add_money($amount,$bonus_sn,$sender_name,$info,$make_type = 0)
  499. {
  500. $minfo = new member_info($this->member_id);
  501. $data = array();
  502. $data['member_id'] = $this->member_id;
  503. $data['member_name'] = $minfo->nickname();
  504. $data['amount'] = $amount;
  505. $data['order_sn'] = $bonus_sn;
  506. $data['admin_name'] = $sender_name;
  507. $data['pdr_sn'] = $bonus_sn;
  508. $data['lg_desc'] = $info;
  509. $this->model_pd->changePd("bonus_add_money", $data);
  510. }
  511. private function send_name($sender_name,$relay_id)
  512. {
  513. if($relay_id > 0) {
  514. $info = new member_info($relay_id);
  515. $nick = $info->nickname();
  516. if(!empty($nick)) return $nick;
  517. }
  518. return $sender_name;
  519. }
  520. public function add_bonus(bonus\user_bonus $bonus,bonus\type $type)
  521. {
  522. $this->inc_rate_version();
  523. $minfo = new member_info($this->member_id);
  524. $data = array();
  525. $data['member_id'] = $this->member_id;
  526. $data['member_name'] = $minfo->nickname();
  527. $data['amount'] = $bonus->bonus_value();
  528. $data['order_sn'] = $bonus->bonus_sn();
  529. $data['admin_name'] = $this->send_name($type->sender_name(),$type->relayer_id());
  530. $data['pdr_sn'] = $bonus->bonus_sn();
  531. $data['lg_desc'] = "";
  532. $data['make_type'] = $type->make_type();
  533. $this->model_pd->changePd("bonus_add_money", $data);
  534. }
  535. public function reduce_pred($amount)
  536. {
  537. $minfo = new member_info($this->member_id);
  538. $data = array();
  539. $data['member_id'] = $this->member_id;
  540. $data['member_name'] = $minfo->nickname();
  541. $data['amount'] = $amount;
  542. $data['pdr_sn'] = '';
  543. $data['lg_desc'] = "";
  544. $this->model_pd->changePd("sys_del_money", $data);
  545. $this->inc_rate_version();
  546. }
  547. public function handout_bonus($amount, $type_sn, $sender_name, $info,$make_type = 0)
  548. {
  549. $this->inc_rate_version();
  550. $minfo = new member_info($this->member_id);
  551. $data = array();
  552. $data['member_id'] = $this->member_id;
  553. $data['member_name'] = $minfo->nickname();
  554. $data['amount'] = $amount;
  555. $data['order_sn'] = $type_sn;
  556. $data['admin_name'] = $sender_name;
  557. $data['pdr_sn'] = $type_sn;
  558. $data['lg_desc'] = $info;
  559. $data['make_type'] = $make_type;
  560. $this->model_pd->changePd("hand_out_bonus", $data);
  561. }
  562. private function filter_sn($lg_desc)
  563. {
  564. $pos = mb_strpos($lg_desc,':');
  565. if($pos != false) {
  566. return mb_substr($lg_desc,$pos + 1);
  567. }
  568. return '';
  569. }
  570. private function filter_make_type($lg_desc)
  571. {
  572. $reg = '/make_type=(\d+)/i';
  573. $ret = preg_match($reg, $lg_desc, $arr);
  574. if($ret > 0) {
  575. return intval($arr[1]);
  576. } else {
  577. return 0;
  578. }
  579. }
  580. private function gen_send_title($sender_name,$make_type)
  581. {
  582. switch ($make_type) {
  583. case bonus\type::MakeSendType:
  584. return "发出红包";
  585. case bonus\type::MakeShakeGainType:
  586. return "被{$sender_name}摇走的红包";
  587. case bonus\type::MakeShakeLostType:
  588. return "摇飞红包到{$sender_name}";
  589. default:
  590. return "";
  591. }
  592. }
  593. private function gen_gain_title($sender_name,$make_type)
  594. {
  595. switch ($make_type) {
  596. case bonus\type::MakeSendType:
  597. return "{$sender_name}的红包";
  598. case bonus\type::MakeInviteType:
  599. return "{$sender_name}发出的邀请红包";
  600. case bonus\type::MakeBonusRefundType:
  601. return "未领红包退款";
  602. case bonus\type::MakeShakeGainType:
  603. return "摇到{$sender_name}的红包";
  604. case bonus\type::MakeShakeLostType:
  605. return "{$sender_name}摇到你这儿的红包";
  606. case bonus\type::MakePayRefundType:
  607. return "购物退款红包";
  608. case bonus\type::MakePayType:
  609. return "购物分享红包";
  610. case bonus\type::MakeOrderCancelType:
  611. return "订单取消退款";
  612. case bonus\type::MakeRegisterType:
  613. return "新人福利";
  614. case bonus\type::MakeEvaluateType:
  615. return "评论奖励红包";
  616. case bonus\type::MakeInviteRewardType:
  617. return "邀请好友,奖励红包";
  618. default:
  619. return "";
  620. }
  621. }
  622. public function filter_pd_log($items)
  623. {
  624. $pdlogs = array();
  625. foreach($items as $val)
  626. {
  627. $item = array();
  628. $av_amount = $val['lg_av_amount'];
  629. $freeze_amount = $val['lg_freeze_amount'];
  630. $admin_name = $val['lg_admin_name'];
  631. $add_time = $val['lg_add_time'];
  632. $type = $val['lg_type'];
  633. $sn = $this->filter_sn($val['lg_desc']);
  634. $item['av_amount'] = $av_amount;
  635. $item['freeze_amount'] = $freeze_amount;
  636. $item['add_time'] = $add_time;
  637. $fAdd = true;
  638. if($type == 'order_pay') {
  639. $item['title'] = "支付订单";
  640. $item['sn'] = "订单号:{$sn}";
  641. }
  642. else if($type == 'order_freeze') {
  643. $item['title'] = "下单扣除红包";
  644. $item['sn'] = "订单号:{$sn}";
  645. }
  646. else if($type == 'order_cancel') {
  647. $item['title'] = "取消订单,解冻红包";
  648. $item['sn'] = "订单号:{$sn}";
  649. }
  650. else if($type == 'order_comb_pay') {
  651. $item['title'] = "下单,支付被冻结的红包";
  652. $item['sn'] = "订单号:{$sn}";
  653. $item['av_amount'] = $freeze_amount;
  654. }
  655. else if($type == 'recharge') {
  656. $item['title'] = "充值";
  657. $item['sn'] = "充值单号:{$sn}";
  658. }
  659. else if($type == 'refund') {
  660. $item['title'] = "确认退款";
  661. }
  662. else if($type == 'vr_refund') {
  663. $item['title'] = "虚拟兑码退款成功";
  664. }
  665. else if($type == 'hand_out_bonus') {
  666. $make_type = $this->filter_make_type($val['lg_desc']);
  667. $item['title'] = $this->gen_send_title($admin_name,$make_type);
  668. $item['sn'] = '';
  669. }
  670. else if($type == 'bonus_refund') {
  671. $item['title'] = "红包退款";
  672. $item['sn'] = '';
  673. }
  674. else if($type == 'bonus_add_money') {
  675. $make_type = $this->filter_make_type($val['lg_desc']);
  676. $item['title'] = $this->gen_gain_title($admin_name,$make_type);
  677. $item['sn'] = '';
  678. }
  679. else if($type == 'bonus_expire') {
  680. $item['title'] = "红包过期扣款";
  681. $item['sn'] = '';
  682. }
  683. else if($type == 'sys_add_money') {
  684. $item['title'] = "管理员调节预存款";
  685. $item['sn'] = '';
  686. }
  687. else if($type == 'sys_del_money') {
  688. $item['title'] = "管理员调节预存款";
  689. $item['sn'] = '';
  690. }
  691. else if($type == 'sys_freeze_money') {
  692. $item['title'] = "管理员冻结预存款";
  693. $item['sn'] = "充值单号:{$sn}";
  694. }
  695. else if($type == 'sys_unfreeze_money') {
  696. $item['title'] = "管理员解冻预存款";
  697. $item['sn'] = "充值单号:{$sn}";
  698. }
  699. else {
  700. $fAdd = false;
  701. }
  702. if($fAdd) {
  703. array_push($pdlogs,$item);
  704. }
  705. }
  706. return $pdlogs;
  707. }
  708. public function calc_pred($order_info,$pd_amount,&$no_cash,&$rates)
  709. {
  710. $order_id = intval($order_info['order_id']);
  711. $mod_order = Model('order');
  712. $pred_amount = 0.00;
  713. $goods_list = $mod_order->getOrderGoodsList(array('order_id' => $order_id));
  714. foreach ($goods_list as $goods)
  715. {
  716. $goods_type = intval($goods['goods_type']);
  717. if($goods_type == 1) {
  718. $pred_amount += doubleval($goods['goods_pay_price']);
  719. }
  720. }
  721. $pred_amount = $pred_amount - $this->mRates->calc_money($pred_amount,$rates);
  722. $cur_used = intval($pred_amount * 100 + 0.5);
  723. $cur_used = $cur_used > $pd_amount ? $pd_amount : $cur_used;
  724. $order_amount = intval($order_info['order_amount'] * 100 + 0.5);
  725. $order_pd_amount = intval($order_info['pd_amount'] * 100 + 0.5);
  726. if($order_amount == $cur_used) {
  727. $no_cash = true;
  728. } else {
  729. $no_cash = false;
  730. }
  731. return $cur_used - $order_pd_amount;
  732. }
  733. public function pay_bonus($rates)
  734. {
  735. $ret = bonus_helper::withold($this->member_id,$rates,bonus_helper::pay_order_withold);
  736. if($ret == true) {
  737. $this->inc_rate_version();
  738. $this->del_rates();
  739. }
  740. else
  741. {
  742. $cent = intval($ret * 100 + 0.5);
  743. if($cent > 0) {
  744. $this->inc_rate_version();
  745. $this->del_rates();
  746. }
  747. }
  748. return $ret;
  749. }
  750. public function find_bonus($amount)
  751. {
  752. $bonus_rate = $this->bonus_rate();
  753. return $bonus_rate->find_rate($amount);
  754. }
  755. private function inc_rate_version()
  756. {
  757. Model('member')->inc_rate_version($this->member_id);
  758. }
  759. }