predeposit_helper.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. if(intval($this->mTotalPred * 100 + 0.5) < intval($this->mRates->total() * 100 + 0.5)) {
  244. $this->mTotalPred = $this->mRates->total();
  245. Model('member')->editMember(array('member_id' => $this->member_id),array('available_predeposit' => $this->mTotalPred));
  246. }
  247. }
  248. public function __destruct()
  249. {
  250. if($this->mRates != null && $this->mRates->dirty()) {
  251. $this->del_rates();
  252. }
  253. }
  254. public function bonus_rate() {
  255. return $this->mRates;
  256. }
  257. static public function order_cash($goods_amount, &$rates)
  258. {
  259. if(isset($_SESSION['bonus_rate']) == false) {
  260. $pred = new predeposit_helper($_SESSION['member_id']);
  261. $bonus_rate = $pred->bonus_rate();
  262. } else {
  263. $bonus_rate = new RateMoney($_SESSION['bonus_rate']);
  264. }
  265. return $bonus_rate->calc_money($goods_amount,$rates);
  266. }
  267. static public function bonus_price($goods_price,&$rates)
  268. {
  269. if(session_helper::isLogin())
  270. {
  271. if(isset($_SESSION['bonus_rate']) == false) {
  272. $pred = new predeposit_helper($_SESSION['member_id']);
  273. $bonus_rate = $pred->bonus_rate();
  274. } else {
  275. $bonus_rate = new RateMoney($_SESSION['bonus_rate']);
  276. }
  277. return $bonus_rate->calc_price($goods_price,$rates);
  278. }
  279. else
  280. {
  281. return $goods_price;
  282. }
  283. }
  284. static public function discount_gap($bonus_price,$goods_price)
  285. {
  286. $bonus_price = intval($bonus_price* 100 + 0.5);
  287. $discount = intval($goods_price * 70 + 0.5);
  288. if($bonus_price <= $discount) {
  289. return 0;
  290. } else {
  291. return ($bonus_price - $discount) / 100;
  292. }
  293. }
  294. public function bonus_state() {
  295. return $this->mBonusState;
  296. }
  297. private function query_cond($query_state)
  298. {
  299. static $stQuerys = array('usable','expiring','used','expired');
  300. static $day_secs = 24 * 3600;
  301. $cond = array('user_id' => $_SESSION['member_id'],'bonus_status' => 3);
  302. if(!empty($query_state) && in_array($query_state,$stQuerys))
  303. {
  304. if($query_state == 'usable') {
  305. $cond['remain_amount'] = array('gt','0.00');
  306. $cond['expired'] = 0;
  307. } elseif ($query_state == 'expiring') {
  308. $cond['usable_time'] = array('elt',time() + 5 * $day_secs);
  309. $cond['remain_amount'] = array('gt','0.00');
  310. $cond['expired'] = 0;
  311. } elseif ($query_state == 'used') {
  312. $cond['remain_amount'] = '0.00';
  313. $cond['expired'] = 0;
  314. } elseif ($query_state == 'expired') {
  315. $cond['expired'] = 1;
  316. } else {
  317. }
  318. }
  319. return $cond;
  320. }
  321. private function write_rates($bonus_state,$bonus_rate)
  322. {
  323. $_SESSION['bonus_state'] = $bonus_state;
  324. $_SESSION['bonus_rate'] = $bonus_rate;
  325. $_SESSION['bonus_rate_version'] = $this->mRateVersion;
  326. }
  327. private function del_rates()
  328. {
  329. if(isset($_SESSION['bonus_state'])) {
  330. unset($_SESSION['bonus_state']);
  331. }
  332. if(isset($_SESSION['bonus_rate'])) {
  333. unset($_SESSION['bonus_rate']);
  334. }
  335. if(isset($_SESSION['bonus_rate_version'])) {
  336. unset($_SESSION['bonus_rate_version']);
  337. }
  338. }
  339. public function topup_bonus($mobile)
  340. {
  341. $bonuses = bonus_helper::topup_bonus($this,$mobile);
  342. if($bonuses != false) {
  343. $this->del_rates();
  344. }
  345. return $bonuses;
  346. }
  347. public function total_pred() {
  348. return $this->mTotalPred;
  349. }
  350. public function freeze_pred() {
  351. return $this->mFreezePred;
  352. }
  353. public function is_enough($money) {
  354. return intval($this->total_pred() * 100) >= intval($money * 100);
  355. }
  356. public function person_enough($money,&$bonus_rate)
  357. {
  358. if($this->mRates == null) return false;
  359. return $this->mRates->is_enough($bonus_rate,$money);
  360. }
  361. public function rates() {
  362. return $this->mRates == null ? false : $this->mRates;
  363. }
  364. public function makeby_bonus($param, $rate_moneys, $bonus_sn)
  365. {
  366. $result = bonus_helper::make_bonus($param,$rate_moneys);
  367. if($result == false) return false;
  368. foreach ($rate_moneys as $item) {
  369. $rate = intval($item['rate']);
  370. $val = $item['hold_amount'];
  371. bonus_helper::withold_bonus($this->member_id,$bonus_sn,$rate,$val);
  372. }
  373. $type_sn = $result['type_sn'];
  374. $money = $result['money'];
  375. $this->handout_bonus($money,$type_sn,session_helper::nickname(),"发送了{$money}元的红包.",\bonus\type::MakeSendType);
  376. foreach ($rate_moneys as $item) {
  377. $this->mRates->with_hold($item['rate'],$item['amount']);
  378. }
  379. return $result;
  380. }
  381. public function make_bonus($param,$rate_moneys)
  382. {
  383. $result = bonus_helper::make_bonus($param,$rate_moneys);
  384. if($result == false) return false;
  385. $rates = [];
  386. foreach ($rate_moneys as $item) {
  387. $rate = intval($item['rate']);
  388. $val = $item['hold_amount'];
  389. $rates[$rate] = $val;
  390. }
  391. bonus_helper::withold($this->member_id,$rates);
  392. $type_sn = $result['type_sn'];
  393. $money = $result['money'];
  394. $this->handout_bonus($money,$type_sn,session_helper::nickname(),"发送了{$money}元的红包.",\bonus\type::MakeSendType);
  395. foreach ($rate_moneys as $item) {
  396. $this->mRates->with_hold($item['rate'],$item['amount']);
  397. }
  398. return $result;
  399. }
  400. private function base_param($amount,$total_num)
  401. {
  402. $param = array();
  403. $param['total_amount'] = $amount;
  404. $param['total_num'] = $total_num;
  405. $param['send_type'] = 1;
  406. return $param;
  407. }
  408. public function share_bonus($bonus_sn,&$msg)
  409. {
  410. $bonus = bonus\user_bonus::create_by_sn($bonus_sn);
  411. if($bonus->spend_over()) {
  412. $msg = "该红包现金已经花光了~";
  413. return false;
  414. }
  415. $amount = $bonus->remain_amount();
  416. $param = $this->base_param($amount,1);
  417. $minfo = new member_info($this->member_id);
  418. $param['sender_id'] = $this->member_id;
  419. $param['sender_mobile'] = $minfo->mobile();
  420. $param['sender_name'] = $minfo->nickname();
  421. $param['make_type'] = \bonus\type::MakeSendType;
  422. $name = $minfo->nickname();
  423. $param['type_name'] = "{$name}";
  424. $type = \bonus\type::crate_by_input($param);
  425. $rate_moneys = [];
  426. $item['amount'] = $type->getTotal_amount();
  427. $item['num'] = $type->getTotal_num();
  428. $item['rate'] = $bonus->bonus_rate();
  429. $rate_moneys[] = $item;
  430. $result = bonus_helper::make_bonus($param,$rate_moneys);
  431. if($result == false) {
  432. return false;
  433. }
  434. else
  435. {
  436. if(bonus_helper::withold_bonus($this->member_id,$bonus->bonus_rate(),$bonus_sn,$type->getTotal_amount())) {
  437. $type_sn = $result['type_sn'];
  438. $money = $result['money'];
  439. $this->handout_bonus($money,$type_sn,session_helper::nickname(),"发送了{$money}元的红包.",\bonus\type::MakeSendType);
  440. }
  441. return $result;
  442. }
  443. }
  444. public function admin_make_bonus($param,$rate_moneys)
  445. {
  446. return bonus_helper::make_bonus($param,$rate_moneys);
  447. }
  448. public function bonus_expire($bouns)
  449. {
  450. try
  451. {
  452. $bonus_obj = bonus\user_bonus::create_by_param($bouns);
  453. if($bonus_obj->spend_over()) {
  454. return false;
  455. }
  456. $this->inc_rate_version();
  457. $minfo = new member_info($this->member_id);
  458. $data = array();
  459. $data['member_id'] = $this->member_id;
  460. $data['member_name'] = $minfo->nickname();
  461. $data['amount'] = $bonus_obj->remain_amount();
  462. $data['order_sn'] = $bonus_obj->bonus_sn();
  463. $data['admin_name'] = "熊猫美妆";
  464. $data['pdr_sn'] = $bonus_obj->bonus_sn();
  465. $data['lg_desc'] = "红包过期扣款";
  466. $this->model_pd->changePd("bonus_expire", $data);
  467. return true;
  468. } catch (Exception $ex) {
  469. return false;
  470. }
  471. }
  472. public function bonus_refund($bonus_type)
  473. {
  474. $types = bonus\type::create_by_paramer($bonus_type);
  475. account_helper::onPredeposit('bonus_refund',$types->sender_id(),$types->getType_sn());
  476. }
  477. public function transform_money($member_id,$name,$amount)
  478. {
  479. $data = array();
  480. $data['member_id'] = $member_id;
  481. $data['member_name'] = is_null($name) ? '' : $name;
  482. $data['amount'] = $amount;
  483. $order_sn = $this->model_pd->makeSn();
  484. $data['order_sn'] = $order_sn;
  485. $data['admin_name'] = '平台管理员';
  486. $data['pdr_sn'] = $order_sn;
  487. $data['lg_desc'] = '版本升级,余额迁移.';
  488. $this->model_pd->changePd("sys_add_money",$data);
  489. }
  490. public function bonus_add_money($amount,$bonus_sn,$sender_name,$info,$make_type = 0)
  491. {
  492. $minfo = new member_info($this->member_id);
  493. $data = array();
  494. $data['member_id'] = $this->member_id;
  495. $data['member_name'] = $minfo->nickname();
  496. $data['amount'] = $amount;
  497. $data['order_sn'] = $bonus_sn;
  498. $data['admin_name'] = $sender_name;
  499. $data['pdr_sn'] = $bonus_sn;
  500. $data['lg_desc'] = $info;
  501. $this->model_pd->changePd("bonus_add_money", $data);
  502. }
  503. private function send_name($sender_name,$relay_id)
  504. {
  505. if($relay_id > 0) {
  506. $info = new member_info($relay_id);
  507. $nick = $info->nickname();
  508. if(!empty($nick)) return $nick;
  509. }
  510. return $sender_name;
  511. }
  512. public function add_bonus(bonus\user_bonus $bonus,bonus\type $type)
  513. {
  514. $this->inc_rate_version();
  515. $minfo = new member_info($this->member_id);
  516. $data = array();
  517. $data['member_id'] = $this->member_id;
  518. $data['member_name'] = $minfo->nickname();
  519. $data['amount'] = $bonus->bonus_value();
  520. $data['order_sn'] = $bonus->bonus_sn();
  521. $data['admin_name'] = $this->send_name($type->sender_name(),$type->relayer_id());
  522. $data['pdr_sn'] = $bonus->bonus_sn();
  523. $data['lg_desc'] = "";
  524. $data['make_type'] = $type->make_type();
  525. $this->model_pd->changePd("bonus_add_money", $data);
  526. }
  527. public function reduce_pred($amount)
  528. {
  529. $minfo = new member_info($this->member_id);
  530. $data = array();
  531. $data['member_id'] = $this->member_id;
  532. $data['member_name'] = $minfo->nickname();
  533. $data['amount'] = $amount;
  534. $data['pdr_sn'] = '';
  535. $data['lg_desc'] = "";
  536. $this->model_pd->changePd("sys_del_money", $data);
  537. $this->inc_rate_version();
  538. }
  539. public function handout_bonus($amount, $type_sn, $sender_name, $info,$make_type = 0)
  540. {
  541. $this->inc_rate_version();
  542. $minfo = new member_info($this->member_id);
  543. $data = array();
  544. $data['member_id'] = $this->member_id;
  545. $data['member_name'] = $minfo->nickname();
  546. $data['amount'] = $amount;
  547. $data['order_sn'] = $type_sn;
  548. $data['admin_name'] = $sender_name;
  549. $data['pdr_sn'] = $type_sn;
  550. $data['lg_desc'] = $info;
  551. $data['make_type'] = $make_type;
  552. $this->model_pd->changePd("hand_out_bonus", $data);
  553. }
  554. private function filter_sn($lg_desc)
  555. {
  556. $pos = mb_strpos($lg_desc,':');
  557. if($pos != false) {
  558. return mb_substr($lg_desc,$pos + 1);
  559. }
  560. return '';
  561. }
  562. private function filter_make_type($lg_desc)
  563. {
  564. $reg = '/make_type=(\d+)/i';
  565. $ret = preg_match($reg, $lg_desc, $arr);
  566. if($ret > 0) {
  567. return intval($arr[1]);
  568. } else {
  569. return 0;
  570. }
  571. }
  572. private function gen_send_title($sender_name,$make_type)
  573. {
  574. switch ($make_type) {
  575. case bonus\type::MakeSendType:
  576. return "发出红包";
  577. case bonus\type::MakeShakeGainType:
  578. return "被{$sender_name}摇走的红包";
  579. case bonus\type::MakeShakeLostType:
  580. return "摇飞红包到{$sender_name}";
  581. default:
  582. return "";
  583. }
  584. }
  585. private function gen_gain_title($sender_name,$make_type)
  586. {
  587. switch ($make_type) {
  588. case bonus\type::MakeSendType:
  589. return "{$sender_name}的红包";
  590. case bonus\type::MakeInviteType:
  591. return "{$sender_name}发出的邀请红包";
  592. case bonus\type::MakeBonusRefundType:
  593. return "未领红包退款";
  594. case bonus\type::MakeShakeGainType:
  595. return "摇到{$sender_name}的红包";
  596. case bonus\type::MakeShakeLostType:
  597. return "{$sender_name}摇到你这儿的红包";
  598. case bonus\type::MakePayRefundType:
  599. return "购物退款红包";
  600. case bonus\type::MakePayType:
  601. return "购物分享红包";
  602. case bonus\type::MakeOrderCancelType:
  603. return "订单取消退款";
  604. case bonus\type::MakeRegisterType:
  605. return "新人福利";
  606. case bonus\type::MakeEvaluateType:
  607. return "评论奖励红包";
  608. case bonus\type::MakeInviteRewardType:
  609. return "邀请好友,奖励红包";
  610. default:
  611. return "";
  612. }
  613. }
  614. public function filter_pd_log($items)
  615. {
  616. $pdlogs = array();
  617. foreach($items as $val)
  618. {
  619. $item = array();
  620. $av_amount = $val['lg_av_amount'];
  621. $freeze_amount = $val['lg_freeze_amount'];
  622. $admin_name = $val['lg_admin_name'];
  623. $add_time = $val['lg_add_time'];
  624. $type = $val['lg_type'];
  625. $sn = $this->filter_sn($val['lg_desc']);
  626. $item['av_amount'] = $av_amount;
  627. $item['freeze_amount'] = $freeze_amount;
  628. $item['add_time'] = $add_time;
  629. $fAdd = true;
  630. if($type == 'order_pay') {
  631. $item['title'] = "支付订单";
  632. $item['sn'] = "订单号:{$sn}";
  633. }
  634. else if($type == 'order_freeze') {
  635. $item['title'] = "下单扣除红包";
  636. $item['sn'] = "订单号:{$sn}";
  637. }
  638. else if($type == 'order_cancel') {
  639. $item['title'] = "取消订单,解冻红包";
  640. $item['sn'] = "订单号:{$sn}";
  641. }
  642. else if($type == 'order_comb_pay') {
  643. $item['title'] = "下单,支付被冻结的红包";
  644. $item['sn'] = "订单号:{$sn}";
  645. $item['av_amount'] = $freeze_amount;
  646. }
  647. else if($type == 'recharge') {
  648. $item['title'] = "充值";
  649. $item['sn'] = "充值单号:{$sn}";
  650. }
  651. else if($type == 'refund') {
  652. $item['title'] = "确认退款";
  653. }
  654. else if($type == 'vr_refund') {
  655. $item['title'] = "虚拟兑码退款成功";
  656. }
  657. else if($type == 'hand_out_bonus') {
  658. $make_type = $this->filter_make_type($val['lg_desc']);
  659. $item['title'] = $this->gen_send_title($admin_name,$make_type);
  660. $item['sn'] = '';
  661. }
  662. else if($type == 'bonus_refund') {
  663. $item['title'] = "红包退款";
  664. $item['sn'] = '';
  665. }
  666. else if($type == 'bonus_add_money') {
  667. $make_type = $this->filter_make_type($val['lg_desc']);
  668. $item['title'] = $this->gen_gain_title($admin_name,$make_type);
  669. $item['sn'] = '';
  670. }
  671. else if($type == 'bonus_expire') {
  672. $item['title'] = "红包过期扣款";
  673. $item['sn'] = '';
  674. }
  675. else if($type == 'sys_add_money') {
  676. $item['title'] = "管理员调节预存款";
  677. $item['sn'] = '';
  678. }
  679. else if($type == 'sys_del_money') {
  680. $item['title'] = "管理员调节预存款";
  681. $item['sn'] = '';
  682. }
  683. else if($type == 'sys_freeze_money') {
  684. $item['title'] = "管理员冻结预存款";
  685. $item['sn'] = "充值单号:{$sn}";
  686. }
  687. else if($type == 'sys_unfreeze_money') {
  688. $item['title'] = "管理员解冻预存款";
  689. $item['sn'] = "充值单号:{$sn}";
  690. }
  691. else {
  692. $fAdd = false;
  693. }
  694. if($fAdd) {
  695. array_push($pdlogs,$item);
  696. }
  697. }
  698. return $pdlogs;
  699. }
  700. public function calc_pred($order_info,$pd_amount,&$no_cash,&$rates)
  701. {
  702. $order_id = intval($order_info['order_id']);
  703. $mod_order = Model('order');
  704. $pred_amount = 0.00;
  705. $goods_list = $mod_order->getOrderGoodsList(array('order_id' => $order_id));
  706. foreach ($goods_list as $goods)
  707. {
  708. $goods_type = intval($goods['goods_type']);
  709. if($goods_type == 1) {
  710. $pred_amount += doubleval($goods['goods_pay_price']);
  711. }
  712. }
  713. $pred_amount = $pred_amount - $this->mRates->calc_money($pred_amount,$rates);
  714. $cur_used = intval($pred_amount * 100 + 0.5);
  715. $cur_used = $cur_used > $pd_amount ? $pd_amount : $cur_used;
  716. $order_amount = intval($order_info['order_amount'] * 100 + 0.5);
  717. $order_pd_amount = intval($order_info['pd_amount'] * 100 + 0.5);
  718. if($order_amount == $cur_used) {
  719. $no_cash = true;
  720. } else {
  721. $no_cash = false;
  722. }
  723. return $cur_used - $order_pd_amount;
  724. }
  725. public function pay_bonus($rates)
  726. {
  727. $ret = bonus_helper::withold($this->member_id,$rates);
  728. if($ret == true) {
  729. $this->inc_rate_version();
  730. $this->del_rates();
  731. }
  732. else
  733. {
  734. $cent = intval($ret * 100 + 0.5);
  735. if($cent > 0) {
  736. $this->inc_rate_version();
  737. $this->del_rates();
  738. }
  739. }
  740. return $ret;
  741. }
  742. public function find_bonus($amount)
  743. {
  744. $bonus_rate = $this->bonus_rate();
  745. return $bonus_rate->find_rate($amount);
  746. }
  747. private function inc_rate_version()
  748. {
  749. Model('member')->inc_rate_version($this->member_id);
  750. }
  751. }