member_bonus.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/4/16
  6. * Time: 下午6:08
  7. */
  8. require_once(BASE_ROOT_PATH . '/helper/bonus_helper.php');
  9. require_once(BASE_ROOT_PATH . '/helper/session_helper.php');
  10. require_once(BASE_ROOT_PATH . '/helper/text_filter.php');
  11. require_once(BASE_ROOT_PATH . '/helper/shaker_helper.php');
  12. require_once(BASE_ROOT_PATH . '/helper/ranklist_helper.php');
  13. require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
  14. require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
  15. require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
  16. require_once(BASE_ROOT_PATH . '/helper/search/util.php');
  17. require_once(BASE_ROOT_PATH . '/helper/search_param.php');
  18. require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
  19. require_once(BASE_ROOT_PATH . '/helper/push_helper.php');
  20. require_once(BASE_ROOT_PATH . '/helper/url_helper.php');
  21. require_once(BASE_ROOT_PATH . '/helper/invite_helper.php');
  22. require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
  23. class member_bonusControl extends mbMemberControl
  24. {
  25. const sampler_goods = 30;
  26. const msg_malice_bonus = '为避免恶意欺诈,只有下单后的用户才能发送红包给好友.';
  27. private $mPred;
  28. public function __construct() {
  29. parent::__construct();
  30. $this->mPred = new predeposit_helper($_SESSION['member_id'],true);
  31. }
  32. public function predepositexOp()
  33. {
  34. $result = [];
  35. $result['bonus_total'] = $this->mPred->total_bonus();
  36. $bonus_state = $this->mPred->bonus_state();
  37. $expiring = $bonus_state['expiring'];
  38. $warning = "";
  39. if(!empty($expiring))
  40. {
  41. $expiring = intval($expiring * 100 + 0.5);
  42. if($expiring > 0) {
  43. $expiring = $expiring / 100;
  44. $warning = "您有{$expiring}元红包即将过期";
  45. }
  46. }
  47. $result = array_merge($result,$bonus_state);
  48. $result['bonus_rate'] = $this->format_rates($this->mPred->pay_bonus_rates());
  49. $result['share_bonus_rate'] = $this->format_rates($this->mPred->share_bonus_rates());
  50. $result['send_bless'] = $this->cur_bless();
  51. $result['avatar'] = session_helper::avatar();
  52. $result['sub_titles'] = ['shake' => '','invite' => '赚百分百红包','friends' => '','bonus_detail' => $warning];
  53. $this->update_available_bonus($result['bonus_total']);
  54. return self::outsuccess($result);
  55. }
  56. private function format_rates($bonus_rate)
  57. {
  58. if ($bonus_rate != null)
  59. {
  60. $rates = $bonus_rate->format();
  61. $rates_money = [];
  62. foreach ($rates as $rate => $money) {
  63. $item['rate'] = $rate;
  64. $item['total'] = $money;
  65. $rates_money[] = $item;
  66. }
  67. }
  68. else {
  69. $rates_money = null;
  70. }
  71. return $rates_money;
  72. }
  73. private function update_available_bonus($amount)
  74. {
  75. if(isset($_SESSION['available_bonus']))
  76. {
  77. $old = intval($_SESSION['available_bonus'] * 100 + 0.5);
  78. $cur_cent = intval($amount * 100 + 0.5);
  79. if($old == $cur_cent) {
  80. $fEdit = false;
  81. } else {
  82. $fEdit = true;
  83. }
  84. } else {
  85. $fEdit = true;
  86. }
  87. if($fEdit)
  88. {
  89. $_SESSION['available_bonus'] = $amount;
  90. $member = Model('member');
  91. $member->editMember(['member_id' => session_helper::memberid()],['available_bonus' => $amount]);
  92. }
  93. }
  94. private function cur_bless()
  95. {
  96. if(isset($_SESSION['cur_share_id']) && $_SESSION['cur_share_id'] > 0) {
  97. $share = bonus_helper::get_share($_SESSION['cur_share_id']);
  98. } else {
  99. $share = bonus_helper::get_share();
  100. $_SESSION['cur_share_id'] = $share['share_id'];
  101. return $share['title'];
  102. }
  103. return $share['title'];
  104. }
  105. private function reset_share()
  106. {
  107. $share = bonus_helper::get_share();
  108. $_SESSION['cur_share_id'] = $share['share_id'];
  109. }
  110. public function predepositOp()
  111. {
  112. $result = [];
  113. $result['predeposit_total'] = $this->mPred->total_bonus();
  114. $result['predeposit_freeze'] = 0;
  115. $bonus_state = $this->mPred->bonus_state();
  116. $result = array_merge($result,$bonus_state);
  117. $result['bonus_rate'] = $this->format_rates($this->mPred->pay_bonus_rates());
  118. $result['share_bonus_rate'] = $this->format_rates($this->mPred->share_bonus_rates());
  119. $result['avatar'] = session_helper::avatar();
  120. $result['sub_titles'] = ['shake' => '偷点地主家的余粮','invite' => '赚百分百红包','friends' => ''];
  121. $result['shake_sub'] = "偷点地主家的余粮";
  122. $result['invite_sub'] = "赚百分百红包";
  123. $result['friends_sub'] = "";
  124. return self::outsuccess($result);
  125. }
  126. private function fill_param($input,$bonus_rate)
  127. {
  128. $param = $input;
  129. $param['sender_id'] = $_SESSION['member_id'];
  130. $param['sender_mobile'] = $_SESSION['member_mobile'];
  131. $param['sender_name'] = session_helper::nickname();
  132. if($bonus_rate > 0) {
  133. $param['bonus_rate'] = $bonus_rate;
  134. }
  135. $param['share_id'] = $_SESSION['cur_share_id'];
  136. return $param;
  137. }
  138. public function makeOp()
  139. {
  140. if(session_helper::can_send() == false) {
  141. return self::outerr(errcode::ErrBonus,self::msg_malice_bonus);
  142. }
  143. if (intval($_GET['bonus_rate']) > 0) {
  144. $bonus_rate = intval($_GET['bonus_rate']);
  145. } else {
  146. return self::outerr(errcode::ErrParamter,'红包折扣率错误,客户端需要升级新版本.');
  147. }
  148. $param = $this->fill_param($_GET,$bonus_rate);
  149. $type = bonus_helper::create_type_input($param);
  150. if(!$this->mPred->share_enough($type->getTotal_amount(),$bonus_rate)) {
  151. return self::outerr(errcode::ErrBonusNotEnough,'余额不够发送红包');
  152. }
  153. $rate_moneys = [];
  154. if($type->isFixedAmount()) {
  155. $item['amount'] = $type->fixed_money();
  156. } else {
  157. $item['amount'] = $type->getTotal_amount();
  158. }
  159. $item['hold_amount'] = $type->getTotal_amount();
  160. $item['num'] = $type->getTotal_num();
  161. $item['rate'] = $bonus_rate;
  162. $rate_moneys[] = $item;
  163. $ret = $this->mPred->make_bonus($type->get_param(),$rate_moneys);
  164. if($ret === false) {
  165. return self::outerr(errcode::ErrBonus,"生成红包失败.");
  166. }
  167. else
  168. {
  169. $type_sn = $ret['type_sn'];
  170. $url = url_helper::bonus_open_url($type_sn);
  171. $this->share_info($type,$title,$sub_title,$img_url);
  172. $this->reset_share();
  173. $strids = $_GET['toids'];
  174. if(!empty($strids))
  175. {
  176. $mids = explode(',',$strids);
  177. $bonusex = bonus_helper::send($type_sn,$mids);
  178. if($bonusex != false) {
  179. push_helper::send_bonus(session_helper::memberid(),$mids);
  180. }
  181. }
  182. return self::outsuccess(array('type_sn' => $ret,
  183. 'url' => "{$url}",
  184. 'title' => $title,
  185. 'sub_title' => $sub_title,
  186. 'img_url' => $img_url));
  187. }
  188. }
  189. private function share_info(bonus\type $type,&$title,&$sub_title,&$img_url)
  190. {
  191. $share = bonus_helper::get_share($type->share_id());
  192. $title = $type->bless();
  193. if(empty($title) || $title == '特权红包,内购正品行货美妆') {
  194. $title = $share['title'];
  195. }
  196. $sub_title = $share['sub_title'] . "\n\n点击领取";
  197. $img_url = $share['img_url'];
  198. }
  199. private function random_cids()
  200. {
  201. $type_sn = "member_bonus";
  202. $time = 0;
  203. $cids = [];
  204. if(array_key_exists('goods_sampler',$_SESSION) && array_key_exists($type_sn,$_SESSION['goods_sampler']))
  205. {
  206. $cids = $_SESSION['goods_sampler'][$type_sn]['cids'];
  207. $time = $_SESSION['goods_sampler'][$type_sn]['time'];
  208. }
  209. if($time < time() - 86400 || empty($cids))
  210. {
  211. if(session_helper::is_man()) {
  212. $cids = activity\goods_sampler::instance()->fetch_male(self::sampler_goods);
  213. } else {
  214. $cids = activity\goods_sampler::instance()->fetch_female(self::sampler_goods);
  215. }
  216. if(!empty($cids)) {
  217. $_SESSION['goods_sampler'][$type_sn]['cids'] = $cids;
  218. $_SESSION['goods_sampler'][$type_sn]['time'] = time();
  219. }
  220. }
  221. return $cids;
  222. }
  223. public function match_goodsexOp()
  224. {
  225. $cids = $this->random_cids();
  226. if(empty($cids))
  227. {
  228. return self::outsuccess(['special_list' => null,
  229. 'summary' => null,
  230. 'groupbuy' => null,
  231. 'limitime' => null,
  232. 'bundling' => null,
  233. 'mobile_page' => mobile_page(0)]);
  234. }
  235. $model_goods = Model('goods');
  236. $items = $model_goods->getGoodsListByColorDistinct(['goods_commonid' => ['in',$cids]],goods_helper::fieldstr,'','');
  237. if(empty($items))
  238. {
  239. return self::outsuccess(['special_list' => null,
  240. 'summary' => null,
  241. 'groupbuy' => null,
  242. 'limitime' => null,
  243. 'bundling' => null,
  244. 'mobile_page' => mobile_page(1)]);
  245. }
  246. else
  247. {
  248. $tmp =[];
  249. foreach ($items as $item) {
  250. $commonid = intval($item['goods_commonid']);
  251. $tmp[$commonid] = $item;
  252. }
  253. $goods_list = [];
  254. foreach ($cids as $cid)
  255. {
  256. if(array_key_exists($cid,$tmp)) {
  257. $goods_list[] = $tmp[$cid];
  258. }
  259. }
  260. foreach ($goods_list as $goods) {
  261. $goods_id = intval($goods['goods_id']);
  262. $goods_ids[] = $goods_id;
  263. }
  264. $helper = new goods_helper();
  265. $ret = $helper->summary($goods_list,$related_goods);
  266. $block = special_formater::format_goods($goods_ids,"",$ret['sort_summary']);
  267. $blocks = [];
  268. if($this->page_no() == 1 && !empty($block)) {
  269. $divider = special_formater::def_divider();
  270. $blocks[] = $divider;
  271. }
  272. $blocks[] = $block;
  273. return self::outsuccess(['special_list' => $blocks,
  274. 'summary' => $ret['summary'],
  275. 'groupbuy' => $ret['groupbuy'],
  276. 'limitime' => $ret['limitime'],
  277. 'bundling' => $ret['bundling'],
  278. 'mobile_page' => mobile_page(1)]);
  279. }
  280. }
  281. public function match_goodsOp()
  282. {
  283. $bonus_rate = $this->mPred->pay_bonus_rates();
  284. $rate_moneys = $bonus_rate->format();
  285. $price = bonus_helper::match_price($rate_moneys);
  286. if($price == false)
  287. {
  288. return self::outsuccess(array('special_list' => null,
  289. 'summary' => null,
  290. 'groupbuy' => null,
  291. 'limitime' => null,
  292. 'bundling' => null,
  293. 'mobile_page' => mobile_page(0)));
  294. }
  295. else
  296. {
  297. $params = ['price' => $price,'page_no' => $this->page_no(),'page_size' => $this->page_size()];
  298. $result = search\search_client::instance()->match_price($params);
  299. if($result == false)
  300. {
  301. return self::outsuccess(array('special_list' => null,
  302. 'summary' => null,
  303. 'groupbuy' => null,
  304. 'limitime' => null,
  305. 'bundling' => null,
  306. 'mobile_page' => mobile_page(0)));
  307. }
  308. $cids = $result['cids'];
  309. $model_goods = Model('goods');
  310. $items = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => array('in',$cids)),goods_helper::fieldstr,'','');
  311. $page_count = intval($result['page_count']);
  312. if(empty($items))
  313. {
  314. return self::outsuccess(array('special_list' => null,
  315. 'summary' => null,
  316. 'groupbuy' => null,
  317. 'limitime' => null,
  318. 'bundling' => null,
  319. 'mobile_page' => mobile_page($page_count)));
  320. }
  321. else
  322. {
  323. $tmp =[];
  324. foreach ($items as $item) {
  325. $commonid = intval($item['goods_commonid']);
  326. $tmp[$commonid] = $item;
  327. }
  328. $goods_list = [];
  329. foreach ($cids as $cid)
  330. {
  331. if(array_key_exists($cid,$tmp)) {
  332. $goods_list[] = $tmp[$cid];
  333. }
  334. }
  335. foreach ($goods_list as $goods) {
  336. $goods_id = intval($goods['goods_id']);
  337. $goods_ids[] = $goods_id;
  338. }
  339. $helper = new goods_helper();
  340. $ret = $helper->summary($goods_list,$related_goods);
  341. $blocks = [];
  342. $block = special_formater::format_goods($goods_ids,"",$ret['sort_summary']);
  343. if($this->page_no() == 1 && !empty($block))
  344. {
  345. global $config;
  346. $spid = $config['goods_sampler']['mbonus_spid'];
  347. $banners = special_manager::instance()->special($spid,$unused_gids);
  348. foreach ($banners as $tmp) {
  349. $blocks[] = $tmp;
  350. }
  351. }
  352. $blocks[] = $block;
  353. return self::outsuccess(array('special_list' => $blocks,
  354. 'summary' => $ret['summary'],
  355. 'groupbuy' => $ret['groupbuy'],
  356. 'limitime' => $ret['limitime'],
  357. 'bundling' => $ret['bundling'],
  358. 'mobile_page' => mobile_page($page_count)));
  359. }
  360. }
  361. }
  362. public function makeby_bonusOp()
  363. {
  364. if(session_helper::can_send() == false) {
  365. return self::outerr(errcode::ErrBonus,self::msg_malice_bonus);
  366. }
  367. if(!isset($_GET['bonus_sn']) || empty($_GET['bonus_sn'])) {
  368. return self::outerr(errcode::ErrParamter,"需要红包序列号.");
  369. }
  370. $bonus = bonus\user_bonus::create_by_sn($_GET['bonus_sn']);
  371. if($bonus->expired()) {
  372. return self::outerr(errcode::ErrBonus,"该红包已经过期,不能再发送.");
  373. }
  374. if(!$bonus->can_share()) {
  375. return self::outerr(errcode::ErrBonus,"该红包只可用于购物,不能分享.");
  376. }
  377. $param = $this->fill_param($_GET,$bonus->bonus_rate());
  378. $type = bonus_helper::create_type_input($param);
  379. $type_amount = intval($type->getTotal_amount() * 100 + 0.5);
  380. $bonus_amount = intval($bonus->remain_amount() * 100 + 0.5);
  381. if($type_amount > $bonus_amount) {
  382. return self::outerr(errcode::ErrBonusNotEnough,'该红包余额不足发送红包');
  383. }
  384. $rate_moneys = [];
  385. if($type->isFixedAmount()) {
  386. $item['amount'] = $type->fixed_money();
  387. } else {
  388. $item['amount'] = $type->getTotal_amount();
  389. }
  390. $item['hold_amount'] = $type->getTotal_amount();
  391. $item['num'] = $type->getTotal_num();
  392. $item['rate'] = $bonus->bonus_rate();
  393. $rate_moneys[] = $item;
  394. $ret = $this->mPred->makeby_bonus($type->get_param(),$rate_moneys,$bonus->bonus_sn());
  395. if($ret === false) {
  396. return self::outerr(errcode::ErrBonus,"生成红包失败.");
  397. }
  398. else
  399. {
  400. $type_sn = $ret['type_sn'];
  401. $url = url_helper::bonus_open_url($type_sn);
  402. $this->share_info($type,$title,$sub_title,$img_url);
  403. $this->reset_share();
  404. return self::outsuccess(array('type_sn' => $ret,
  405. 'url' => "{$url}",
  406. 'title' => $title,
  407. 'sub_title' => $sub_title,
  408. 'img_url' => $img_url));
  409. }
  410. }
  411. public function inviteOp()
  412. {
  413. $info = invite_helper::share_info(session_helper::share_id());
  414. return self::outsuccess(['type_sn' => "",
  415. 'url' => url_helper::inviter_url(),
  416. 'title' => $info['title'],
  417. 'sub_title' => $info['sub_title'],
  418. 'img_url' => $info['img']]);
  419. }
  420. public function invite_pageOp()
  421. {
  422. return self::outsuccess(['direct_uri' => url_helper::inviter_url()],"redirect");
  423. }
  424. public function shareOp()
  425. {
  426. if(!isset($_GET['type_sn']) || empty($_GET['type_sn'])) {
  427. return self::outerr(errcode::ErrParamter,"需要红包序列号.");
  428. }
  429. $type_sn = $_GET['type_sn'];
  430. $type = bonus\type::create_by_sn($type_sn);
  431. $this->share_info($type,$title,$sub_title,$img_url);
  432. $url = url_helper::bonus_open_url($type_sn);
  433. return self::outsuccess(array('type_sn' => $type_sn, 'url' => "{$url}",
  434. 'title' => $title,
  435. 'sub_title' => $sub_title,
  436. 'img_url' => $img_url));
  437. }
  438. public function send_listexOp()
  439. {
  440. $type_infos = $this->send_listex($pages);
  441. if($this->page_no() == 1) {
  442. $tip_blocks = $this->tip_block('send',count($type_infos));
  443. } else {
  444. $tip_blocks = false;
  445. }
  446. if($type_infos == null)
  447. {
  448. if($tip_blocks == false) $tip_blocks = null;
  449. return self::outsuccess(array('special_list' => $tip_blocks,
  450. 'summary' => null,
  451. 'groupbuy' => null,
  452. 'limitime' => null,
  453. 'bundling' => null,
  454. 'typeinfos' => $type_infos,
  455. 'mobile_page' => mobile_page($pages)));
  456. }
  457. else
  458. {
  459. $blocks = [];
  460. if($tip_blocks != false)
  461. {
  462. foreach ($tip_blocks as $block) {
  463. $blocks[] = $block;
  464. }
  465. }
  466. $block = special_formater::format_type($type_infos);
  467. $blocks[] = $block;
  468. return self::outsuccess(array('special_list' => $blocks,
  469. 'summary' => null,
  470. 'groupbuy' => null,
  471. 'limitime' => null,
  472. 'bundling' => null,
  473. 'typeinfos' => $type_infos,
  474. 'mobile_page' => mobile_page($pages)));
  475. }
  476. }
  477. private function send_listex(&$pages)
  478. {
  479. $mod_type = Model('bonus_type');
  480. $cond['sender_id|relayer_id'] = array('_multi'=>true,$_SESSION['member_id'],$_SESSION['member_id']);
  481. $cond['make_type'] = array('in',array(bonus\type::MakeSendType,bonus\type::MakeInviteType));
  482. $count = $mod_type->getTypeCount($cond);
  483. if($count == 0) {
  484. $pages = 0;
  485. return null;
  486. }
  487. $items = $mod_type->getTypeList($cond,$this->page_size(),'*','type_id desc');
  488. $type_infos = [];
  489. foreach($items as $val)
  490. {
  491. $type = bonus\type::create_by_paramer($val);
  492. $item["type_sn"] = $type->getType_sn();
  493. $item["type_bless"] = $type->bless();
  494. $item["send_type"] = $type->send_type();
  495. if($type->make_type() == bonus\type::MakeInviteType) {
  496. $item["title"] = "邀请好友红包";
  497. }
  498. else
  499. {
  500. if($type->isFixedAmount()) {
  501. $item["title"] = "普通红包";
  502. } else {
  503. $item["title"] = "拼手气红包";
  504. }
  505. }
  506. $item['sender_name'] = $item['title'];
  507. $item["total_amount"] = $type->getTotal_amount();
  508. $item["total_num"] = $type->getTotal_num();
  509. $item["remain_amount"] = $type->remain_amount();
  510. $item["bonus_rate"] = $type->bonus_rate();
  511. $item["binded_num"] = $type->binded_num();
  512. $item["send_start_date"] = $type->get_start_time();
  513. $item["send_end_date"] = $type->get_end_time();
  514. $item["make_type"] = $type->make_type();
  515. $item["is_end"] = $type->isEnd();
  516. $item["binded_over"] = $type->binded_over();
  517. $item['can_share'] = !$type->isEnd() && !$type->binded_over();
  518. $type_sn = $type->getType_sn();
  519. $open_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}";
  520. $detail_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}";
  521. $item["open_url"] = $open_url;
  522. $item["detail_url"] = $detail_url;
  523. $type_infos[] = $item;
  524. }
  525. $pages = $this->pages($count);
  526. return $type_infos;
  527. }
  528. private function tip_block($state,$count)
  529. {
  530. global $config;
  531. $banners = $config['bonus_detail_banner'];
  532. if($state == 'usable') {
  533. $key = 'usable';
  534. }
  535. elseif($state == 'expiring') {
  536. $key = 'expiring';
  537. }
  538. elseif($state == 'used') {
  539. $key = 'used';
  540. }
  541. elseif($state == 'expired') {
  542. $key = 'expired';
  543. }
  544. elseif($state == 'send') {
  545. $key = 'send';
  546. }
  547. else {
  548. $key = '';
  549. }
  550. if(!empty($key)) {
  551. $special_id = $count <= 0 ? $banners[$key][0] : $banners[$key][1];
  552. } else {
  553. $special_id = 0;
  554. }
  555. if($special_id == 0) return false;
  556. $helper = new special_formater($special_id);
  557. $blocks = $helper->format($goods_ids);
  558. return $blocks;
  559. }
  560. public function topupOp()
  561. {
  562. $items = $this->mPred->topup_bonus($_SESSION['member_mobile']);
  563. $this->async_topup();
  564. if($items === false) {
  565. return self::outsuccess(array("count" => 0,'total_amount' => 0.00));
  566. }
  567. else
  568. {
  569. $total_amount = 0.00;
  570. $max_rate = 0;
  571. $max_share = 0;
  572. $result = [];
  573. foreach ($items as $item)
  574. {
  575. $bonus = bonus\user_bonus::create_by_param($item);
  576. $type = bonus\type::create_by_sn($bonus->type_sn());
  577. $user_id = $type->sender_id();
  578. $member = new member_info($user_id);
  579. $avatar = $member->avatar();
  580. if($type->binded_over() == false && $type->getTotal_num())
  581. {
  582. $share_num = $type->getTotal_num() - $type->binded_num();
  583. if($max_share < $share_num) {
  584. $result['max_share']['avatar'] = $avatar;
  585. $result['max_share']['count'] = $share_num;
  586. $result['max_share']['total_amount'] = $item['bonus_value'];//$type->getTotal_amount();
  587. $result['max_share']['rate'] = $type->bonus_rate();
  588. $result['max_share']['type_sn'] = $type->getType_sn();
  589. $max_share = $share_num;
  590. }
  591. }
  592. $rate = $bonus->bonus_rate();
  593. if ($max_rate < $rate)
  594. {
  595. $result['max_rate']['avatar'] = $avatar;
  596. $result['max_rate']['rate'] = $rate;
  597. $result['max_rate']['type_sn'] = $type->getType_sn();
  598. $max_rate = $rate;
  599. }
  600. $total_amount += doubleval($item['bonus_value']);
  601. }
  602. $result['max_rate']['total_amount'] = $total_amount;
  603. $result['max_rate']['count'] = count($items);
  604. if(!empty($result['max_share'])) {
  605. $info = $result['max_share'];
  606. $count = intval($info['count']);
  607. $title = "恭喜获得{$count}个可分享红包";
  608. $sub_title = "分享给小伙伴,大家一起抢。";
  609. $btn_type = 'send';
  610. $btn_title = '发红包';
  611. }
  612. else
  613. {
  614. $info = $result['max_rate'];
  615. $count = intval($info['count']);
  616. $total_amount = $info['total_amount'];
  617. $title = "您领了{$count}个红包";
  618. $sub_title = "总共{$total_amount}元,已到账";
  619. $btn_type = 'detail';
  620. $btn_title = '查看红包';
  621. }
  622. $detail_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$info['type_sn']}";
  623. return self::outsuccess(array("count" => $count, 'total_amount' => $info['total_amount'],
  624. 'title' => $title,'sub_title' => $sub_title,
  625. 'avatar' => $info['avatar'],
  626. 'rate' => $info['rate'],
  627. 'type_sn' => $info['type_sn'],
  628. 'btn_type' => $btn_type,
  629. 'btn_title' => $btn_title,
  630. 'detail_url' => $detail_url));
  631. }
  632. }
  633. private function async_topup()
  634. {
  635. $last_topup = intval($_SESSION['last_topup_time']);
  636. if(time() - $last_topup > 7 * 86400) {
  637. QueueClient::push('onAsyncTopup',['member_id' => session_helper::memberid()]);
  638. $_SESSION['last_topup_time'] = time();
  639. }
  640. }
  641. public function topupexOp()
  642. {
  643. $items = $this->mPred->topup_bonus($_SESSION['member_mobile']);
  644. $this->async_topup();
  645. if($items === false) {
  646. return self::outsuccess(array("count" => 0,'total_amount' => 0.00));
  647. }
  648. else
  649. {
  650. $total_amount = 0.00;
  651. $max_rate = 0;
  652. $avatar = RESOURCE_SITE_URL . '/mobile/defimg/female.png';
  653. $type_sn = '';
  654. foreach ($items as $item)
  655. {
  656. $bonus = bonus\user_bonus::create_by_param($item);
  657. $rate = $bonus->bonus_rate();
  658. if ($max_rate < $rate) {
  659. $type = bonus\type::create_by_sn($bonus->type_sn());
  660. $user_id = $type->sender_id();
  661. $member = new member_info($user_id);
  662. $avatar = $member->avatar();
  663. $max_rate = $rate;
  664. $type_sn = $type->getType_sn();
  665. }
  666. $total_amount += doubleval($item['bonus_value']);
  667. }
  668. $count = count($items);
  669. $title = "您新领了{$count}个, 总额价值{$total_amount}元的红包.";
  670. $detail_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}";
  671. return self::outsuccess(array("count" => $count, 'total_amount' => $total_amount,
  672. 'title' => $title, 'avatar' => $avatar, 'rate' => $max_rate,
  673. 'type_sn' => $type_sn, 'detail_url' => $detail_url));
  674. }
  675. }
  676. public function recv_listexOp()
  677. {
  678. $bonus = $this->recv_list($state,$count,$pages);
  679. if($this->page_no() == 1) {
  680. $tip_blocks = $this->tip_block($state,$count);
  681. } else {
  682. $tip_blocks = false;
  683. }
  684. if($bonus == null)
  685. {
  686. if($tip_blocks == false) $tip_blocks = null;
  687. return self::outsuccess(array('special_list' => $tip_blocks,
  688. 'summary' => null,
  689. 'summary' => null,
  690. 'groupbuy' => null,
  691. 'limitime' => null,
  692. 'bundling' => null,
  693. 'bonuses' => $bonus,
  694. 'mobile_page' => mobile_page($pages)));
  695. }
  696. else
  697. {
  698. $blocks = [];
  699. if($tip_blocks != false)
  700. {
  701. foreach ($tip_blocks as $block) {
  702. $blocks[] = $block;
  703. }
  704. }
  705. $block = special_formater::format_bonus($bonus);
  706. $blocks[] = $block;
  707. return self::outsuccess(array('special_list' => $blocks,
  708. 'summary' => null,
  709. 'groupbuy' => null,
  710. 'limitime' => null,
  711. 'bundling' => null,
  712. 'bonuses' => $bonus,
  713. 'mobile_page' => mobile_page($pages)));
  714. }
  715. }
  716. //我收到的红包
  717. public function recv_listOp()
  718. {
  719. $bonus = $this->recv_list($state,$count,$pages);
  720. if($bonus == null) {
  721. return self::outsuccess(array('bonuses' => array(), 'mobile_page' => mobile_page($pages)));
  722. }
  723. return self::outsuccess(array('bonuses' => $bonus,'mobile_page' => mobile_page($pages)));
  724. }
  725. private function recv_cond(&$state,&$order_by)
  726. {
  727. static $stQuerys = array('usable','expiring','used','expired');
  728. static $day_secs = 24 * 3600;
  729. $cond = array('user_id' => $_SESSION['member_id'],'bonus_status' => 3);
  730. $query_state = $_GET['query_state'];
  731. if(!empty($query_state) && in_array($query_state,$stQuerys))
  732. {
  733. $state = $query_state;
  734. if($query_state == 'usable') {
  735. $cond['usable_time'] = ['gt',time()];
  736. $cond['remain_amount'] = array('gt','0.00');
  737. $cond['expired'] = 0;
  738. $order_by = 'grab_time DESC';
  739. } elseif ($query_state == 'expiring') {
  740. $cond['usable_time&usable_time'] = ['_multi'=>true,['gt',time()],['elt',time() + 5 * $day_secs]];
  741. $cond['remain_amount'] = array('gt','0.00');
  742. $cond['expired'] = 0;
  743. $order_by = 'grab_time DESC';
  744. } elseif ($query_state == 'used') {
  745. $cond['remain_amount'] = '0.00';
  746. $cond['expired'] = 0;
  747. $order_by = 'grab_time DESC';
  748. } elseif ($query_state == 'expired') {
  749. $cond['expired'] = 1;
  750. $cond['usable_time'] = ['lt',time()];
  751. $cond['remain_amount'] = ['gt','0.00'];
  752. $order_by = 'bonus_rate DESC,bonus_id DESC';
  753. } else {
  754. return false;
  755. }
  756. }
  757. return $cond;
  758. }
  759. private function recv_list(&$state,&$count,&$pages)
  760. {
  761. $mod_bonus = Model('user_bonus');
  762. $cond = $this->recv_cond($state,$order_by);
  763. $count = $mod_bonus->getBonusCount($cond);
  764. if($count == 0) {
  765. $pages = 0;
  766. return null;
  767. }
  768. $pages = $this->pages($count);
  769. if($this->page_no() > $pages) {
  770. return null;
  771. }
  772. $items = $mod_bonus->getBonusList($cond,'*',$order_by,$this->page_size(),$count);
  773. $type_ids = array();
  774. foreach ($items as $val) {
  775. array_push($type_ids,intval($val['type_id']));
  776. }
  777. $types = array();
  778. $type_items = Model('bonus_type')->getTypeList(array('type_id' => array('in',$type_ids)));
  779. foreach ($type_items as $val) {
  780. $type = bonus\type::create_by_paramer($val);
  781. $types[$type->getType_id()] = $type;
  782. }
  783. $result = [];
  784. foreach($items as $val)
  785. {
  786. $user_bonus = bonus\user_bonus::create_by_param($val);
  787. $item['bonus_sn'] = $user_bonus->bonus_sn();
  788. $item['bonus_value'] = $user_bonus->bonus_value();
  789. $item['remain_amount'] = $user_bonus->remain_amount();
  790. $item['usable_time'] = $user_bonus->usable_time();
  791. $item['expired'] = $user_bonus->expired();
  792. $item['spend_over'] = $user_bonus->spend_over();
  793. $item['get_time'] = $user_bonus->get_time();
  794. $item['can_share'] = $user_bonus->client_can_share();
  795. $bonus_rate = $user_bonus->bonus_rate();
  796. $item['bonus_rate'] = empty($bonus_rate) ? 30 : $bonus_rate;
  797. if(array_key_exists($user_bonus->type_id(),$types) == false) {
  798. continue;
  799. }
  800. $type = $types[$user_bonus->type_id()];
  801. $item['sender_name'] = $this->show_name($type);
  802. $item['title'] = $this->show_name($type);
  803. $item['rand_type'] = $type->isRandomAmount();
  804. $item['total_num'] = $type->getTotal_num();
  805. $item['binded_num'] = $type->binded_num();
  806. $item['share_end'] = $type->isEnd();
  807. $item['show_type'] = self::show_type($type->make_type());
  808. $type_sn = $type->getType_sn();
  809. $item['type_sn'] = $type_sn;
  810. $item['url'] = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}";
  811. $item['detail_url'] = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}";
  812. $result[] = $item;
  813. }
  814. return $result;
  815. }
  816. private function show_type($make_type)
  817. {
  818. switch ($make_type)
  819. {
  820. case bonus\type::MakeSendType: //抢
  821. case bonus\type::MakeInviteType:
  822. case bonus\type::MakeVoteType:
  823. return 1;
  824. case bonus\type::MakeBonusRefundType: //退
  825. case bonus\type::MakePayRefundType:
  826. case bonus\type::MakeOrderCancelType:
  827. return 2;
  828. case bonus\type::MakeShakeGainType: //摇
  829. case bonus\type::MakeShakeLostType:
  830. return 3;
  831. case bonus\type::MakePayType: //赠
  832. case bonus\type::MakeRegisterType:
  833. case bonus\type::MakeEvaluateType:
  834. case bonus\type::MakeInviteRewardType:
  835. case bonus\type::MakePayRewardInviterType:
  836. case bonus\type::MakePayRewardInviteeType:
  837. case bonus\type::MakeAllowanceType:
  838. return 4;
  839. default:
  840. return 0; //什么都不显示
  841. }
  842. }
  843. private function show_name(bonus\type $type)
  844. {
  845. $make_type = $type->make_type();
  846. switch ($make_type) {
  847. case bonus\type::MakeSendType: //抢
  848. case bonus\type::MakeShakeGainType: //摇
  849. return $type->sender_name();
  850. case bonus\type::MakeVoteType:
  851. return "投票或答题红包";
  852. case bonus\type::MakeEvaluateType:
  853. case bonus\type::MakeInviteType:
  854. case bonus\type::MakeBonusRefundType: //退
  855. case bonus\type::MakePayRefundType:
  856. case bonus\type::MakeOrderCancelType:
  857. case bonus\type::MakeShakeLostType:
  858. case bonus\type::MakePayType: //赠
  859. case bonus\type::MakeRegisterType:
  860. case bonus\type::MakeInviteRewardType:
  861. case bonus\type::MakePayRewardInviterType:
  862. case bonus\type::MakePayRewardInviteeType:
  863. case bonus\type::MakeAllowanceType:
  864. return $type->name();
  865. default:
  866. return "熊猫美妆"; //什么都不显示
  867. }
  868. }
  869. //预存款收支记录
  870. public function pdlogOp()
  871. {
  872. $mod_pd = Model('predeposit');
  873. $count = $mod_pd->getPdLogCount(array('lg_member_id' => $_SESSION['member_id']));
  874. $items = $mod_pd->getPdLogList(array('lg_member_id' => $_SESSION['member_id']),$this->page_size(),'*','lg_id desc');
  875. if(empty($items)) {
  876. return self::outsuccess(array('pd_logs' => array(),'mobile_page' => mobile_page(0)));
  877. }
  878. $pd_logs = $this->mPred->filter_pd_log($items);
  879. $pages = $this->pages($count);
  880. return self::outsuccess(array('pd_logs' => $pd_logs,'mobile_page' => mobile_page($pages)));
  881. }
  882. public function shakeOp()
  883. {
  884. if(!isset($_POST['strength']) || empty($_POST['strength'])) {
  885. $strength = intval($_POST['strength']);
  886. } else {
  887. $strength = 3;
  888. }
  889. $shaker = new shaker_helper();
  890. $items = $shaker->shake($strength,$err);
  891. if($items == false) {
  892. return self::outsuccess(array("bonuses" => [],"info" => array('count' => 0, 'money' => 0.0)));
  893. }
  894. else
  895. {
  896. $total_amount = 0;
  897. $bonuses = array();
  898. foreach ($items as $bonus)
  899. {
  900. $user_bonus = bonus\user_bonus::create_by_param($bonus);
  901. $type_info = bonus_helper::get_typeinfo($user_bonus->type_sn());
  902. $type_info = $type_info['type_info'];
  903. $type = bonus\type::create_by_paramer($type_info);
  904. $item = array();
  905. if($_SESSION['member_id'] == $user_bonus->user_id()) {
  906. $item['direction'] = 'gain';
  907. $item['name'] = $type->sender_name();
  908. $item['bonus_value'] = $user_bonus->bonus_value();
  909. $item['url'] = $this->bonus_detailurl($user_bonus->type_sn());
  910. $total_amount += $user_bonus->bonus_value();
  911. $minfo = new member_info($type->sender_id());
  912. } else {
  913. $item['direction'] = 'lost';
  914. $item['name'] = $user_bonus->user_name();
  915. $item['bonus_value'] = $user_bonus->bonus_value();
  916. $item['url'] = $this->bonus_detailurl($user_bonus->type_sn());
  917. $total_amount -= $user_bonus->bonus_value();
  918. $minfo = new member_info($user_bonus->user_id());
  919. }
  920. $item['is_man'] = $minfo->is_man();
  921. $item['avatar'] = $minfo->avatar();
  922. array_push($bonuses,$item);
  923. }
  924. $count = count($bonuses);
  925. return self::outsuccess(array("bonuses" => $bonuses,"info" => array('count' => $count, 'money' => $total_amount)));
  926. }
  927. }
  928. public function thiefOp()
  929. {
  930. $user_id = $_GET['enmember_id'];
  931. if(empty($user_id)) {
  932. return self::outerr(errcode::ErrParamter,"被偷的用户不存在");
  933. }
  934. $user_id = util::decrypt_data(urldecode($user_id));
  935. if($user_id <= 0) {
  936. return self::outerr(errcode::ErrParamter,"被偷的用户不存在");
  937. }
  938. else
  939. {
  940. $amount = session_helper::thief($user_id,$err);
  941. if($amount == false) {
  942. return self::outerr($err['code'],$err['msg']);
  943. }
  944. else
  945. {
  946. $bonuses = account_helper::gain_bonus($user_id, $_SESSION['member_id'], $amount);
  947. if($bonuses == false || empty($bonuses)) {
  948. return self::outerr(errcode::ErrBonus,"这次没偷着");
  949. } else {
  950. $bonus = $bonuses[0];
  951. $tips = "您成功偷到{$bonus['bonus_value']}元";
  952. return self::outsuccess(array("bonuses" => $bonuses,
  953. "info" => ['count' => 1, 'money' => $bonus['bonus_value'],'tips' => $tips]));
  954. }
  955. }
  956. }
  957. }
  958. private function bonus_detailurl($type_sn)
  959. {
  960. $url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&type_sn={$type_sn}&client_type=wap";
  961. return $url;
  962. }
  963. public function daily_rankOp()
  964. {
  965. $count = ranklist_helper::list_count($_SESSION['member_id']);
  966. if($count == false) {
  967. return self::outerr(errcode::ErrBonusDailyRank,"您还没有抢红包记录,明天才能看到榜单~");
  968. }
  969. $start_index = ($this->page_no() - 1) * $this->page_size();
  970. $end = $start_index + $this->page_size();
  971. $end = $end > $count ? $count : $end;
  972. $times = array();
  973. $start_tm = time();
  974. for ($index = $start_index; $index < $end; ++$index) {
  975. $date_time = date_helper::sub_days($start_tm,$index + 1);
  976. array_push($times,$date_time);
  977. }
  978. $mids = array();
  979. array_push($mids,intval($_SESSION['member_id']));
  980. $top_infos = array();
  981. $tops = ranklist_helper::ranklists($_SESSION['member_id'],$times);
  982. foreach ($tops as $key => $top) {
  983. $item = array();
  984. $item['list_sn'] = $top->list_sn();
  985. $item['list_rank'] = $top->get_rank() + 1;
  986. $item['list_value'] = $top->money();
  987. $item['list_date'] = $top->list_date();
  988. $item['top_id'] = $top->top_id();
  989. $item['top_money'] = $top->top_money();
  990. if(in_array($top->top_id(),$mids) == false) {
  991. array_push($mids,$top->top_id());
  992. }
  993. array_push($top_infos,$item);
  994. }
  995. $mem_desc = array();
  996. $members = Model('member')->getMemberList(array('member_id' => array('in',$mids)));
  997. foreach ($members as $val) {
  998. $info = new member_info($val);
  999. array_push($mem_desc,$info->filter());
  1000. }
  1001. $pages = intval($count / $this->page_size()) + ( ($count % $this->page_size()) == 0 ? 0 : 1);
  1002. return self::outsuccess(array('top_list' => $top_infos,'mem_desc' => $mem_desc,'mobile_page' => mobile_page($pages)));
  1003. }
  1004. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1005. public function share_oneOp()
  1006. {
  1007. if(!isset($_GET['bonus_sn']) || empty($_GET['bonus_sn'])) {
  1008. return self::outerr(errcode::ErrParamter,"需要红包序列号.");
  1009. }
  1010. $bonus_sn = $_GET['bonus_sn'];
  1011. $ret = $this->mPred->share_bonus($bonus_sn,$msg);
  1012. if($ret === false) {
  1013. return self::outerr(errcode::ErrBonus,empty($msg) ? "生成红包失败." : $msg);
  1014. } else {
  1015. $type_sn = $ret['type_sn'];
  1016. $url = url_helper::bonus_open_url($type_sn);
  1017. return self::outsuccess(array('type_sn' => $ret,'url' => "{$url}"));
  1018. }
  1019. }
  1020. public function send_listOp()
  1021. {
  1022. $type_infos = $this->send_list($pages);
  1023. return self::outsuccess(array('type_infos' => $type_infos, 'mobile_page' => mobile_page($pages)));
  1024. }
  1025. private function send_list(&$pages)
  1026. {
  1027. $mod_type = Model('bonus_type');
  1028. $cond['sender_id|relayer_id'] = array('_multi'=>true,$_SESSION['member_id'],$_SESSION['member_id']);
  1029. $cond['make_type'] = array('in',array(bonus\type::MakeSendType,bonus\type::MakeInviteType));
  1030. $count = $mod_type->getTypeCount($cond);
  1031. if($count == 0) {
  1032. $pages = 0;
  1033. return null;
  1034. }
  1035. $items = $mod_type->getTypeList($cond,$this->page_size(),'*','type_id desc');
  1036. $type_infos = [];
  1037. foreach($items as $val) {
  1038. $type_info = bonus_helper::filter_type($val);
  1039. $type_infos[] = $type_info;
  1040. }
  1041. $pages = $this->pages($count);
  1042. return $type_infos;
  1043. }
  1044. }