member_bonus.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  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. require_once(BASE_ROOT_PATH . '/helper/room_helper.php');
  24. require_once(BASE_ROOT_PATH . '/helper/algorithm.php');
  25. require_once(BASE_ROOT_PATH . '/helper/login_helper.php');
  26. require_once(BASE_ROOT_PATH . '/helper/sms_helper.php');
  27. require_once(BASE_ROOT_PATH . '/helper/model_helper.php');
  28. require_once(BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
  29. require_once(BASE_ROOT_PATH . '/helper/user_session/storage.php');
  30. use bonus\activity_bonus;
  31. use room\proto_type;
  32. class member_bonusControl extends mbMemberControl
  33. {
  34. const sampler_goods = 30;
  35. const msg_malice_bonus = '为避免恶意欺诈,只有下单后的用户才能发送红包给好友.';
  36. private $mUserAccount;
  37. public function __construct() {
  38. parent::__construct();
  39. $this->mUserAccount = $this->price_calcer();
  40. }
  41. public function indexOp()
  42. {
  43. $result = [];
  44. $result['bonus_total'] = $this->mUserAccount->total_bonus();
  45. $result['pred_total'] = $this->total_pred();
  46. $result['bonus_rate'] = 30;
  47. $mine_rooms = room_helper::user_rooms(session_helper::memberid(),'shared_bonus desc',4);
  48. if(empty($mine_rooms)) {
  49. $result['show_joinroom'] = true;
  50. $result['mine_room'] = [];
  51. } else {
  52. $result['show_joinroom'] = false;
  53. $result['mine_room'] = $mine_rooms;
  54. }
  55. $result['convert_ratio'] = 1000;
  56. $result['other_room'] = room_helper::page_rooms(['type' => proto_type::room_chat],'steps_count desc,room_id desc');
  57. $result['daliy_bonus'] = schema_helper::openurl("试试手气",activity_bonus::daliy_bonus_url());
  58. $result['invite_friend'] = schema_helper::invite_page();
  59. $result['shake_bonus'] = schema_helper::shake();
  60. $result['donate_steps'] = schema_helper::donate_steps();
  61. return self::outsuccess($result);
  62. }
  63. private function total_pred()
  64. {
  65. $member = Model('member');
  66. $info = $member->getMemberInfoByID(session_helper::memberid());
  67. return (intval($info['available_predeposit'] * 100 + 0.5 )) / 100;
  68. }
  69. public function mine_bonusOp()
  70. {
  71. $result = [];
  72. $result['bonus_total'] = $this->mUserAccount->total_bonus();
  73. $result['usable_bonus'] = $this->mUserAccount->usable_bonus();
  74. return self::outsuccess($result);
  75. }
  76. public function mine_roomsOp()
  77. {
  78. $mod_room = Model('room');
  79. $items = $mod_room->getRoomParts(['member_id' => session_helper::memberid(),'state' => 0],'room_id');
  80. $roomids = [];
  81. foreach ($items as $item) {
  82. $roomids[] = intval($item['room_id']);
  83. }
  84. $result['mine_room'] = room_helper::page_rooms(['type' => proto_type::room_chat,'room_id'=>['in',$roomids]],'steps_count desc,room_id desc',20, 20,$mobile_page);
  85. $result['mobile_page'] = $mobile_page;
  86. return self::outsuccess($result);
  87. }
  88. public function other_roomsOp ()
  89. {
  90. $result['other_room'] = room_helper::page_rooms(['type' => proto_type::room_chat,"steps_count"=>['gt',0]],'steps_count desc,room_id desc',20, 20,$mobile_page);
  91. $result['mobile_page'] = $mobile_page;
  92. return self::outsuccess($result);
  93. }
  94. public function predepositexOp()
  95. {
  96. $result = [];
  97. $result['bonus_total'] = $this->mUserAccount->total_bonus();
  98. $result['pred_total'] = $this->total_pred();
  99. $bonus_state = $this->mUserAccount->bonus_state();
  100. $expiring = $bonus_state['expiring'];
  101. $expiring = intval($expiring * 100 + 0.5);
  102. if($expiring > 0) {
  103. $expiring = $expiring / 100;
  104. $warning = "您有{$expiring}元红包即将过期";
  105. }
  106. $result = array_merge($result,$bonus_state);
  107. $result['bonus_rate'] = $this->format_rates($this->mUserAccount->pay_bonus_rates());
  108. $result['share_bonus_rate'] = $this->format_rates($this->mUserAccount->share_bonus_rates());
  109. $result['room_bonus'] = $this->mUserAccount->room_bonus();
  110. $result['send_bless'] = $this->cur_bless();
  111. $result['avatar'] = session_helper::avatar();
  112. $result['sub_titles'] = ['shake' => '','invite' => '赚百分百红包','friends' => '','bonus_detail' => $warning];
  113. $this->update_available_bonus($result['bonus_total']);
  114. return self::outsuccess($result);
  115. }
  116. private function format_rates($bonus_rate)
  117. {
  118. if ($bonus_rate != null)
  119. {
  120. $rates = $bonus_rate->format();
  121. $rates_money = [];
  122. if(noBonusRate())
  123. {
  124. $amount = 0.0;
  125. foreach ($rates as $rate => $money) {
  126. $amount += $money;
  127. }
  128. $rates_money[] = ['rate' => defaultBonusRate(),'total' => $amount];
  129. }
  130. else
  131. {
  132. foreach ($rates as $rate => $money) {
  133. $item['rate'] = $rate;
  134. $item['total'] = $money;
  135. $rates_money[] = $item;
  136. }
  137. }
  138. }
  139. else {
  140. $rates_money = null;
  141. }
  142. return $rates_money;
  143. }
  144. private function update_available_bonus($amount)
  145. {
  146. if(isset($_SESSION['available_bonus']))
  147. {
  148. $old = intval($_SESSION['available_bonus'] * 100 + 0.5);
  149. $cur_cent = intval($amount * 100 + 0.5);
  150. if($old == $cur_cent) {
  151. $fEdit = false;
  152. } else {
  153. $fEdit = true;
  154. }
  155. } else {
  156. $fEdit = true;
  157. }
  158. if($fEdit)
  159. {
  160. $_SESSION['available_bonus'] = $amount;
  161. $member = Model('member');
  162. $member->editMember(['member_id' => session_helper::memberid()],['available_bonus' => $amount]);
  163. }
  164. }
  165. private function cur_bless()
  166. {
  167. if(isset($_SESSION['cur_share_id']) && $_SESSION['cur_share_id'] > 0) {
  168. $share = bonus_helper::get_share($_SESSION['cur_share_id']);
  169. } else {
  170. $share = bonus_helper::get_share();
  171. $_SESSION['cur_share_id'] = $share['share_id'];
  172. return $share['title'];
  173. }
  174. return $share['title'];
  175. }
  176. private function reset_share()
  177. {
  178. $share = bonus_helper::get_share();
  179. $_SESSION['cur_share_id'] = $share['share_id'];
  180. }
  181. private function fill_param($input,$bonus_rate)
  182. {
  183. $param = $input;
  184. $param['sender_id'] = $_SESSION['member_id'];
  185. $param['sender_mobile'] = $_SESSION['member_mobile'];
  186. $param['sender_name'] = session_helper::nickname();
  187. if($bonus_rate > 0) {
  188. $param['bonus_rate'] = $bonus_rate;
  189. }
  190. $param['share_id'] = $_SESSION['cur_share_id'];
  191. return $param;
  192. }
  193. public function makeOp()
  194. {
  195. if(session_helper::can_send() == false) {
  196. return self::outerr(errcode::ErrBonus,self::msg_malice_bonus);
  197. }
  198. if(usedBonusRate())
  199. {
  200. if (intval($_GET['bonus_rate']) > 0) {
  201. $bonus_rate = intval($_GET['bonus_rate']);
  202. } else {
  203. return self::outerr(errcode::ErrParamter,'红包折扣率错误,客户端需要升级新版本.');
  204. }
  205. }
  206. else {
  207. $bonus_rate = defaultBonusRate();
  208. }
  209. $param = $this->fill_param($_GET,$bonus_rate);
  210. $type = bonus_helper::create_type_input($param);
  211. if(!$this->mUserAccount->share_enough($type->getTotal_amount(),$bonus_rate)) {
  212. return self::outerr(errcode::ErrBonusNotEnough,'余额不够发送红包');
  213. }
  214. $rate_moneys = [];
  215. if($type->isFixedAmount()) {
  216. $item['amount'] = $type->fixed_money();
  217. } else {
  218. $item['amount'] = $type->getTotal_amount();
  219. }
  220. $item['hold_amount'] = $type->getTotal_amount();
  221. $item['num'] = $type->getTotal_num();
  222. $item['rate'] = $bonus_rate;
  223. $rate_moneys[] = $item;
  224. $ret = $this->mUserAccount->make_bonus($type->get_param(),$rate_moneys);
  225. if($ret === false) {
  226. return self::outerr(errcode::ErrBonus,"生成红包失败.");
  227. }
  228. else
  229. {
  230. $type_sn = $ret['type_sn'];
  231. $url = url_helper::bonus_open_url($type_sn);
  232. $this->share_info($type,$title,$sub_title,$img_url);
  233. $this->reset_share();
  234. $strids = $_GET['toids'];
  235. if(!empty($strids))
  236. {
  237. $mids = explode(',',$strids);
  238. $bonusex = bonus_helper::send($type_sn,$mids);
  239. if($bonusex != false) {
  240. push_helper::send_bonus(session_helper::memberid(),$mids,$type_sn);
  241. }
  242. }
  243. return self::outsuccess(['type_sn' => $ret,
  244. 'url' => "{$url}",
  245. 'path' => url_helper::bonus_open_path($type_sn),
  246. 'title' => $title,
  247. 'sub_title' => $sub_title,
  248. 'img_url' => $img_url]);
  249. }
  250. }
  251. private function share_info(bonus\type $type,&$title,&$sub_title,&$img_url)
  252. {
  253. $share = bonus_helper::get_share($type->share_id());
  254. $title = $type->bless();
  255. if(empty($title) || $title == '特权红包,内购正品行货美妆') {
  256. $title = $share['title'];
  257. }
  258. $sub_title = $share['sub_title'] . "\n\n点击领取";
  259. $img_url = $share['img_url'];
  260. }
  261. private function random_cids()
  262. {
  263. $type_sn = "member_bonus";
  264. $time = 0;
  265. $cids = [];
  266. if(array_key_exists('goods_sampler',$_SESSION) && array_key_exists($type_sn,$_SESSION['goods_sampler']))
  267. {
  268. $cids = $_SESSION['goods_sampler'][$type_sn]['cids'];
  269. $time = $_SESSION['goods_sampler'][$type_sn]['time'];
  270. }
  271. if($time < time() - 86400 || empty($cids))
  272. {
  273. if(session_helper::is_man()) {
  274. $cids = activity\goods_sampler::instance()->fetch_male(self::sampler_goods);
  275. } else {
  276. $cids = activity\goods_sampler::instance()->fetch_female(self::sampler_goods);
  277. }
  278. if(!empty($cids)) {
  279. $_SESSION['goods_sampler'][$type_sn]['cids'] = $cids;
  280. $_SESSION['goods_sampler'][$type_sn]['time'] = time();
  281. }
  282. }
  283. return $cids;
  284. }
  285. public function match_goodsexOp()
  286. {
  287. $cids = $this->random_cids();
  288. if(empty($cids))
  289. {
  290. return self::outsuccess(['special_list' => null,
  291. 'summary' => null,
  292. 'groupbuy' => null,
  293. 'limitime' => null,
  294. 'bundling' => null,
  295. 'mobile_page' => mobile_page(0)]);
  296. }
  297. $model_goods = Model('goods');
  298. $items = $model_goods->getGoodsListByColorDistinct(['goods_commonid' => ['in',$cids]],goods_helper::fieldstr,'','');
  299. if(empty($items))
  300. {
  301. return self::outsuccess(['special_list' => null,
  302. 'summary' => null,
  303. 'groupbuy' => null,
  304. 'limitime' => null,
  305. 'bundling' => null,
  306. 'mobile_page' => mobile_page(1)]);
  307. }
  308. else
  309. {
  310. $tmp =[];
  311. foreach ($items as $item) {
  312. $commonid = intval($item['goods_commonid']);
  313. $tmp[$commonid] = $item;
  314. }
  315. $goods_list = [];
  316. foreach ($cids as $cid)
  317. {
  318. if(array_key_exists($cid,$tmp)) {
  319. $goods_list[] = $tmp[$cid];
  320. }
  321. }
  322. foreach ($goods_list as $goods) {
  323. $goods_id = intval($goods['goods_id']);
  324. $goods_ids[] = $goods_id;
  325. }
  326. $helper = new goods_helper($this->mUserAccount);
  327. $ret = $helper->summary($goods_list,$related_goods);
  328. $block = special_formater::format_goods($goods_ids,"",$ret['sort_summary']);
  329. $blocks = [];
  330. if($this->page_no() == 1 && !empty($block) && session_helper::client_type() != session_helper::device_mini) {
  331. global $config;
  332. $guess_like = $config['special_header']['guess_like'];
  333. if($guess_like > 0) {
  334. $specials = special_manager::instance()->blocks($guess_like);
  335. $blocks = $specials;
  336. }
  337. }
  338. $blocks[] = $block;
  339. return self::outsuccess(['special_list' => $blocks,
  340. 'summary' => $ret['summary'],
  341. 'groupbuy' => $ret['groupbuy'],
  342. 'limitime' => $ret['limitime'],
  343. 'bundling' => $ret['bundling'],
  344. 'mobile_page' => mobile_page(1)]);
  345. }
  346. }
  347. public function match_goodsOp()
  348. {
  349. $bonus_rate = $this->mUserAccount->pay_bonus_rates();
  350. $rate_moneys = $bonus_rate->format();
  351. $price = bonus_helper::match_price($rate_moneys);
  352. if($price == false)
  353. {
  354. return self::outsuccess(array('special_list' => null,
  355. 'summary' => null,
  356. 'groupbuy' => null,
  357. 'limitime' => null,
  358. 'bundling' => null,
  359. 'mobile_page' => mobile_page(0)));
  360. }
  361. else
  362. {
  363. $params = ['price' => $price,'page_no' => $this->page_no(),'page_size' => $this->page_size()];
  364. $result = search\search_client::instance()->match_price($params);
  365. if($result == false)
  366. {
  367. return self::outsuccess(array('special_list' => null,
  368. 'summary' => null,
  369. 'groupbuy' => null,
  370. 'limitime' => null,
  371. 'bundling' => null,
  372. 'mobile_page' => mobile_page(0)));
  373. }
  374. $cids = $result['cids'];
  375. $model_goods = Model('goods');
  376. $items = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => array('in',$cids)),goods_helper::fieldstr,'','');
  377. $page_count = intval($result['page_count']);
  378. if(empty($items))
  379. {
  380. return self::outsuccess(array('special_list' => null,
  381. 'summary' => null,
  382. 'groupbuy' => null,
  383. 'limitime' => null,
  384. 'bundling' => null,
  385. 'mobile_page' => mobile_page($page_count)));
  386. }
  387. else
  388. {
  389. $tmp =[];
  390. foreach ($items as $item) {
  391. $commonid = intval($item['goods_commonid']);
  392. $tmp[$commonid] = $item;
  393. }
  394. $goods_list = [];
  395. foreach ($cids as $cid)
  396. {
  397. if(array_key_exists($cid,$tmp)) {
  398. $goods_list[] = $tmp[$cid];
  399. }
  400. }
  401. foreach ($goods_list as $goods) {
  402. $goods_id = intval($goods['goods_id']);
  403. $goods_ids[] = $goods_id;
  404. }
  405. $helper = new goods_helper($this->mUserAccount);
  406. $ret = $helper->summary($goods_list,$related_goods);
  407. $blocks = [];
  408. $block = special_formater::format_goods($goods_ids,"",$ret['sort_summary']);
  409. if($this->page_no() == 1 && !empty($block))
  410. {
  411. global $config;
  412. $spid = $config['goods_sampler']['mbonus_spid'];
  413. $banners = special_manager::instance()->special($spid,$unused_gids);
  414. foreach ($banners as $tmp) {
  415. $blocks[] = $tmp;
  416. }
  417. }
  418. $blocks[] = $block;
  419. return self::outsuccess(array('special_list' => $blocks,
  420. 'summary' => $ret['summary'],
  421. 'groupbuy' => $ret['groupbuy'],
  422. 'limitime' => $ret['limitime'],
  423. 'bundling' => $ret['bundling'],
  424. 'mobile_page' => mobile_page($page_count)));
  425. }
  426. }
  427. }
  428. public function makeby_bonusOp()
  429. {
  430. if(session_helper::can_send() == false) {
  431. return self::outerr(errcode::ErrBonus,self::msg_malice_bonus);
  432. }
  433. if(!isset($_GET['bonus_sn']) || empty($_GET['bonus_sn'])) {
  434. return self::outerr(errcode::ErrParamter,"需要红包序列号.");
  435. }
  436. $bonus = bonus\user_bonus::create_by_sn($_GET['bonus_sn']);
  437. if($bonus->expired()) {
  438. return self::outerr(errcode::ErrBonus,"该红包已经过期,不能再发送.");
  439. }
  440. if(!$bonus->can_share()) {
  441. return self::outerr(errcode::ErrBonus,"该红包只可用于购物,不能分享.");
  442. }
  443. $param = $this->fill_param($_GET,$bonus->bonus_rate());
  444. $type = bonus_helper::create_type_input($param);
  445. $type_amount = intval($type->getTotal_amount() * 100 + 0.5);
  446. $bonus_amount = intval($bonus->remain_amount() * 100 + 0.5);
  447. if($type_amount > $bonus_amount) {
  448. return self::outerr(errcode::ErrBonusNotEnough,'该红包余额不足发送红包');
  449. }
  450. $rate_moneys = [];
  451. if($type->isFixedAmount()) {
  452. $item['amount'] = $type->fixed_money();
  453. } else {
  454. $item['amount'] = $type->getTotal_amount();
  455. }
  456. $item['hold_amount'] = $type->getTotal_amount();
  457. $item['num'] = $type->getTotal_num();
  458. $item['rate'] = $bonus->bonus_rate();
  459. $rate_moneys[] = $item;
  460. $ret = $this->mUserAccount->makeby_bonus($type->get_param(),$rate_moneys,$bonus->bonus_sn());
  461. if($ret === false) {
  462. return self::outerr(errcode::ErrBonus,"生成红包失败.");
  463. }
  464. else
  465. {
  466. $type_sn = $ret['type_sn'];
  467. $url = url_helper::bonus_open_url($type_sn);
  468. $path = url_helper::bonus_open_path($type_sn);
  469. $this->share_info($type,$title,$sub_title,$img_url);
  470. $this->reset_share();
  471. return self::outsuccess(array('type_sn' => $ret,
  472. 'url' => "{$url}",
  473. 'title' => $title,
  474. 'sub_title' => $sub_title,
  475. 'path' => $path,
  476. 'img_url' => $img_url));
  477. }
  478. }
  479. public function inviteOp()
  480. {
  481. $info = invite_helper::share_info(session_helper::share_id());
  482. return self::outsuccess(['type_sn' => "",
  483. 'url' => url_helper::inviter_url(),
  484. 'title' => $info['title'],
  485. 'sub_title' => $info['sub_title'],
  486. 'img_url' => $info['img']]);
  487. }
  488. public function invite_pageOp()
  489. {
  490. return self::outsuccess(['direct_uri' => url_helper::inviter_url()],"redirect");
  491. }
  492. public function shareOp()
  493. {
  494. if(!isset($_GET['type_sn']) || empty($_GET['type_sn'])) {
  495. return self::outerr(errcode::ErrParamter,"需要红包序列号.");
  496. }
  497. $type_sn = $_GET['type_sn'];
  498. $type = bonus\type::create_by_sn($type_sn);
  499. $this->share_info($type,$title,$sub_title,$img_url);
  500. $url = url_helper::bonus_open_url($type_sn);
  501. $path = url_helper::bonus_open_path($type_sn);
  502. return self::outsuccess(array('type_sn' => $type_sn, 'url' => "{$url}",
  503. 'title' => $title,
  504. 'sub_title' => $sub_title,
  505. 'path' => $path,
  506. 'img_url' => $img_url));
  507. }
  508. public function send_listexOp()
  509. {
  510. $type_infos = $this->send_listex($pages);
  511. if($this->page_no() == 1) {
  512. $tip_blocks = $this->tip_block('send',count($type_infos));
  513. } else {
  514. $tip_blocks = false;
  515. }
  516. if($type_infos == null)
  517. {
  518. if($tip_blocks == false) $tip_blocks = null;
  519. return self::outsuccess(array('special_list' => $tip_blocks,
  520. 'summary' => null,
  521. 'groupbuy' => null,
  522. 'limitime' => null,
  523. 'bundling' => null,
  524. 'typeinfos' => $type_infos,
  525. 'mobile_page' => mobile_page($pages)));
  526. }
  527. else
  528. {
  529. $blocks = [];
  530. if($tip_blocks != false)
  531. {
  532. foreach ($tip_blocks as $block) {
  533. $blocks[] = $block;
  534. }
  535. }
  536. $block = special_formater::format_type($type_infos);
  537. $blocks[] = $block;
  538. return self::outsuccess(array('special_list' => $blocks,
  539. 'summary' => null,
  540. 'groupbuy' => null,
  541. 'limitime' => null,
  542. 'bundling' => null,
  543. 'typeinfos' => $type_infos,
  544. 'mobile_page' => mobile_page($pages)));
  545. }
  546. }
  547. private function send_listex(&$pages)
  548. {
  549. $mod_type = Model('bonus_type');
  550. $cond['sender_id|relayer_id'] = array('_multi'=>true,$_SESSION['member_id'],$_SESSION['member_id']);
  551. $cond['make_type'] = array('in',array(bonus\type::MakeSendType,bonus\type::MakeInviteType));
  552. $count = $mod_type->getTypeCount($cond);
  553. if($count == 0) {
  554. $pages = 0;
  555. return null;
  556. }
  557. $items = $mod_type->getTypeList($cond,$this->page_size(),'*','type_id desc');
  558. $type_infos = [];
  559. foreach($items as $val)
  560. {
  561. $type = bonus\type::create_by_paramer($val);
  562. $item["type_sn"] = $type->getType_sn();
  563. $item["type_bless"] = $type->bless();
  564. $item["send_type"] = $type->send_type();
  565. if($type->make_type() == bonus\type::MakeInviteType) {
  566. $item["title"] = "邀请好友红包";
  567. }
  568. else
  569. {
  570. if($type->isFixedAmount()) {
  571. $item["title"] = "普通红包";
  572. } else {
  573. $item["title"] = "拼手气红包";
  574. }
  575. }
  576. $item['sender_name'] = $item['title'];
  577. $item["total_amount"] = $type->getTotal_amount();
  578. $item["total_num"] = $type->getTotal_num();
  579. $item["remain_amount"] = $type->remain_amount();
  580. $item["bonus_rate"] = $type->bonus_rate();
  581. $item["binded_num"] = $type->binded_num();
  582. $item["send_start_date"] = $type->get_start_time();
  583. $item["send_end_date"] = $type->get_end_time();
  584. $item["make_type"] = $type->make_type();
  585. $item["is_end"] = $type->isEnd();
  586. $item["binded_over"] = $type->binded_over();
  587. $item['can_share'] = !$type->isEnd() && !$type->binded_over();
  588. $type_sn = $type->getType_sn();
  589. $open_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}";
  590. $detail_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}";
  591. $item["open_url"] = $open_url;
  592. $item["detail_url"] = $detail_url;
  593. $type_infos[] = $item;
  594. }
  595. $pages = $this->pages($count);
  596. return $type_infos;
  597. }
  598. private function tip_block($state,$count)
  599. {
  600. global $config;
  601. $banners = $config['bonus_detail_banner'];
  602. if($state == 'usable') {
  603. $key = 'usable';
  604. }
  605. elseif($state == 'expiring') {
  606. $key = 'expiring';
  607. }
  608. elseif($state == 'used') {
  609. $key = 'used';
  610. }
  611. elseif($state == 'expired') {
  612. $key = 'expired';
  613. }
  614. elseif($state == 'send') {
  615. $key = 'send';
  616. }
  617. else {
  618. $key = '';
  619. }
  620. if(!empty($key)) {
  621. $special_id = $count <= 0 ? $banners[$key][0] : $banners[$key][1];
  622. } else {
  623. $special_id = 0;
  624. }
  625. if($special_id == 0) return false;
  626. $helper = new special_formater($special_id);
  627. $blocks = $helper->format($goods_ids);
  628. return $blocks;
  629. }
  630. public function topupOp()
  631. {
  632. $items = $this->mUserAccount->topup_bonus($_SESSION['member_mobile']);
  633. if($items === false) {
  634. return self::outsuccess(array("count" => 0,'total_amount' => 0.00));
  635. }
  636. else
  637. {
  638. $total_amount = 0.00;
  639. $max_rate = 0;
  640. $max_share = 0;
  641. $result = [];
  642. foreach ($items as $item)
  643. {
  644. $bonus = bonus\user_bonus::create_by_param($item);
  645. $type = bonus\type::create_by_sn($bonus->type_sn());
  646. $user_id = $type->sender_id();
  647. $member = new member_info($user_id);
  648. $avatar = $member->avatar();
  649. if($type->binded_over() == false && $type->getTotal_num())
  650. {
  651. $share_num = $type->getTotal_num() - $type->binded_num();
  652. if($max_share < $share_num) {
  653. $result['max_share']['avatar'] = $avatar;
  654. $result['max_share']['count'] = $share_num;
  655. $result['max_share']['total_amount'] = $item['bonus_value'];//$type->getTotal_amount();
  656. $result['max_share']['rate'] = $type->bonus_rate();
  657. $result['max_share']['type_sn'] = $type->getType_sn();
  658. $max_share = $share_num;
  659. }
  660. }
  661. $rate = $bonus->bonus_rate();
  662. if ($max_rate < $rate)
  663. {
  664. $result['max_rate']['avatar'] = $avatar;
  665. $result['max_rate']['rate'] = $rate;
  666. $result['max_rate']['type_sn'] = $type->getType_sn();
  667. $max_rate = $rate;
  668. }
  669. $total_amount += doubleval($item['bonus_value']);
  670. }
  671. $result['max_rate']['total_amount'] = $total_amount;
  672. $result['max_rate']['count'] = count($items);
  673. if(!empty($result['max_share'])) {
  674. $info = $result['max_share'];
  675. $count = intval($info['count']);
  676. $title = "您获得{$count}个红包";
  677. $sub_title = "可分享红包";
  678. $btn_type = 'send';
  679. $btn_title = '点击分享';
  680. } else {
  681. $info = $result['max_rate'];
  682. $count = intval($info['count']);
  683. $total_amount = $info['total_amount'];
  684. $title = "您领了{$count}个红包";
  685. $sub_title = "总共{$total_amount}元,已到账";
  686. $btn_type = 'detail';
  687. $btn_title = '点击查看';
  688. }
  689. $detail_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$info['type_sn']}";
  690. return self::outsuccess(array("count" => $count, 'total_amount' => $info['total_amount'],
  691. 'title' => $title,'sub_title' => $sub_title,
  692. 'avatar' => $info['avatar'],
  693. 'rate' => $info['rate'],
  694. 'type_sn' => $info['type_sn'],
  695. 'btn_type' => $btn_type,
  696. 'btn_title' => $btn_title,
  697. 'detail_url' => $detail_url));
  698. }
  699. }
  700. private function async_topup()
  701. {
  702. $last_topup = intval($_SESSION['last_topup_time']);
  703. if(time() - $last_topup > 7 * 86400) {
  704. QueueClient::push('onAsyncTopup',['member_id' => session_helper::memberid()]);
  705. $_SESSION['last_topup_time'] = time();
  706. }
  707. }
  708. public function topupexOp()
  709. {
  710. $items = $this->mUserAccount->topup_bonus($_SESSION['member_mobile']);
  711. // $this->async_topup();
  712. if($items === false) {
  713. return self::outsuccess(array("count" => 0,'total_amount' => 0.00));
  714. }
  715. else
  716. {
  717. $total_amount = 0.00;
  718. $max_rate = 0;
  719. $avatar = RESOURCE_SITE_URL . '/mobile/defimg/female.png';
  720. $type_sn = '';
  721. foreach ($items as $item)
  722. {
  723. $bonus = bonus\user_bonus::create_by_param($item);
  724. $rate = $bonus->bonus_rate();
  725. if ($max_rate < $rate) {
  726. $type = bonus\type::create_by_sn($bonus->type_sn());
  727. $user_id = $type->sender_id();
  728. $member = new member_info($user_id);
  729. $avatar = $member->avatar();
  730. $max_rate = $rate;
  731. $type_sn = $type->getType_sn();
  732. }
  733. $total_amount += doubleval($item['bonus_value']);
  734. }
  735. $count = count($items);
  736. $title = "您新领了{$count}个, 总额价值{$total_amount}元的红包.";
  737. $detail_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}";
  738. return self::outsuccess(array("count" => $count, 'total_amount' => $total_amount,
  739. 'title' => $title, 'avatar' => $avatar, 'rate' => $max_rate,
  740. 'type_sn' => $type_sn, 'detail_url' => $detail_url));
  741. }
  742. }
  743. public function recv_listexOp()
  744. {
  745. $bonus = $this->recv_list($state,$count,$pages);
  746. if($this->page_no() == 1) {
  747. $tip_blocks = $this->tip_block($state,$count);
  748. } else {
  749. $tip_blocks = false;
  750. }
  751. if($bonus == null)
  752. {
  753. if($tip_blocks == false) $tip_blocks = null;
  754. return self::outsuccess(array('special_list' => $tip_blocks,
  755. 'summary' => null,
  756. 'summary' => null,
  757. 'groupbuy' => null,
  758. 'limitime' => null,
  759. 'bundling' => null,
  760. 'bonuses' => $bonus,
  761. 'mobile_page' => mobile_page($pages)));
  762. }
  763. else
  764. {
  765. $blocks = [];
  766. if($tip_blocks != false)
  767. {
  768. foreach ($tip_blocks as $block) {
  769. $blocks[] = $block;
  770. }
  771. }
  772. $block = special_formater::format_bonus($bonus);
  773. $blocks[] = $block;
  774. return self::outsuccess(array('special_list' => $blocks,
  775. 'summary' => null,
  776. 'groupbuy' => null,
  777. 'limitime' => null,
  778. 'bundling' => null,
  779. 'bonuses' => $bonus,
  780. 'mobile_page' => mobile_page($pages)));
  781. }
  782. }
  783. //我收到的红包
  784. public function recv_listOp()
  785. {
  786. $bonus = $this->recv_list($state,$count,$pages);
  787. if($bonus == null) {
  788. return self::outsuccess(array('bonuses' => array(), 'mobile_page' => mobile_page($pages)));
  789. }
  790. return self::outsuccess(array('bonuses' => $bonus,'mobile_page' => mobile_page($pages)));
  791. }
  792. private function recv_cond(&$state,&$order_by)
  793. {
  794. static $stQuerys = array('usable','expiring','used','expired');
  795. static $day_secs = 24 * 3600;
  796. $cond = array('user_id' => $_SESSION['member_id'],'bonus_status' => 3);
  797. $query_state = $_GET['query_state'];
  798. if(!empty($query_state) && in_array($query_state,$stQuerys))
  799. {
  800. $state = $query_state;
  801. if($query_state == 'usable') {
  802. $cond['usable_time'] = ['gt',time()];
  803. $cond['remain_amount'] = array('gt','0.00');
  804. $cond['expired'] = 0;
  805. $order_by = 'grab_time DESC';
  806. } elseif ($query_state == 'expiring') {
  807. $cond['usable_time&usable_time'] = ['_multi'=>true,['gt',time()],['elt',time() + 5 * $day_secs]];
  808. $cond['remain_amount'] = array('gt','0.00');
  809. $cond['expired'] = 0;
  810. $order_by = 'grab_time DESC';
  811. } elseif ($query_state == 'used') {
  812. $cond['remain_amount'] = '0.00';
  813. $cond['expired'] = 0;
  814. $order_by = 'grab_time DESC';
  815. } elseif ($query_state == 'expired') {
  816. $cond['expired'] = 1;
  817. $cond['usable_time'] = ['lt',time()];
  818. $cond['remain_amount'] = ['gt','0.00'];
  819. $order_by = 'bonus_rate DESC,bonus_id DESC';
  820. } else {
  821. return false;
  822. }
  823. }
  824. return $cond;
  825. }
  826. private function recv_list(&$state,&$count,&$pages)
  827. {
  828. $mod_bonus = Model('user_bonus');
  829. $cond = $this->recv_cond($state,$order_by);
  830. $count = $mod_bonus->getBonusCount($cond);
  831. if($count == 0) {
  832. $pages = 0;
  833. return null;
  834. }
  835. $pages = $this->pages($count);
  836. if($this->page_no() > $pages) {
  837. return null;
  838. }
  839. $items = $mod_bonus->getBonusList($cond,'*',$order_by,$this->page_size(),$count);
  840. $type_ids = array();
  841. foreach ($items as $val) {
  842. array_push($type_ids,intval($val['type_id']));
  843. }
  844. $types = array();
  845. $type_items = Model('bonus_type')->getTypeList(array('type_id' => array('in',$type_ids)));
  846. foreach ($type_items as $val) {
  847. $type = bonus\type::create_by_paramer($val);
  848. $types[$type->getType_id()] = $type;
  849. }
  850. $result = [];
  851. foreach($items as $val)
  852. {
  853. $user_bonus = bonus\user_bonus::create_by_param($val);
  854. $item['bonus_sn'] = $user_bonus->bonus_sn();
  855. $item['bonus_value'] = $user_bonus->bonus_value();
  856. $item['remain_amount'] = $user_bonus->remain_amount();
  857. $item['usable_time'] = $user_bonus->usable_time();
  858. $item['expired'] = $user_bonus->expired();
  859. $item['spend_over'] = $user_bonus->spend_over();
  860. $item['get_time'] = $user_bonus->get_time();
  861. $item['can_share'] = $user_bonus->client_can_share();
  862. $bonus_rate = $user_bonus->bonus_rate();
  863. $item['bonus_rate'] = empty($bonus_rate) ? 30 : $bonus_rate;
  864. if(array_key_exists($user_bonus->type_id(),$types) == false) {
  865. continue;
  866. }
  867. $type = $types[$user_bonus->type_id()];
  868. $item['sender_name'] = $this->show_name($type);
  869. $item['title'] = $this->show_name($type);
  870. $item['rand_type'] = $type->isRandomAmount();
  871. $item['total_num'] = $type->getTotal_num();
  872. $item['binded_num'] = $type->binded_num();
  873. $item['share_end'] = $type->isEnd();
  874. $item['show_type'] = self::show_type($type->make_type());
  875. $type_sn = $type->getType_sn();
  876. $item['type_sn'] = $type_sn;
  877. $item['url'] = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}";
  878. $item['detail_url'] = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}";
  879. $result[] = $item;
  880. }
  881. return $result;
  882. }
  883. private function show_type($make_type)
  884. {
  885. switch ($make_type)
  886. {
  887. case bonus\type::MakeSendType: //抢
  888. case bonus\type::MakeInviteType:
  889. case bonus\type::MakeVoteType:
  890. return 1;
  891. case bonus\type::MakeBonusRefundType: //退
  892. case bonus\type::MakePayRefundType:
  893. case bonus\type::MakeOrderCancelType:
  894. return 2;
  895. case bonus\type::MakeShakeGainType: //摇
  896. case bonus\type::MakeShakeLostType:
  897. return 3;
  898. case bonus\type::MakePayType: //赠
  899. case bonus\type::MakeRegisterType:
  900. case bonus\type::MakeEvaluateType:
  901. case bonus\type::MakeInviteRewardType:
  902. case bonus\type::MakePayRewardInviterType:
  903. case bonus\type::MakePayRewardInviteeType:
  904. case bonus\type::MakeAllowanceType:
  905. return 4;
  906. default:
  907. return 0; //什么都不显示
  908. }
  909. }
  910. private function show_name(bonus\type $type)
  911. {
  912. $make_type = $type->make_type();
  913. switch ($make_type) {
  914. case bonus\type::MakeSendType: //抢
  915. case bonus\type::MakeShakeGainType: //摇
  916. return $type->sender_name();
  917. case bonus\type::MakeVoteType:
  918. return "投票或答题红包";
  919. case bonus\type::MakeEvaluateType:
  920. case bonus\type::MakeInviteType:
  921. case bonus\type::MakeBonusRefundType: //退
  922. case bonus\type::MakePayRefundType:
  923. case bonus\type::MakeOrderCancelType:
  924. case bonus\type::MakeShakeLostType:
  925. case bonus\type::MakePayType: //赠
  926. case bonus\type::MakeRegisterType:
  927. case bonus\type::MakeInviteRewardType:
  928. case bonus\type::MakePayRewardInviterType:
  929. case bonus\type::MakePayRewardInviteeType:
  930. case bonus\type::MakeAllowanceType:
  931. return $type->name();
  932. default:
  933. return "熊猫美妆"; //什么都不显示
  934. }
  935. }
  936. //预存款收支记录
  937. public function pdlogOp()
  938. {
  939. $mod_pd = Model('predeposit');
  940. $count = $mod_pd->getPdLogCount(array('lg_member_id' => $_SESSION['member_id']));
  941. $items = $mod_pd->getPdLogList(array('lg_member_id' => $_SESSION['member_id']),$this->page_size(),'*','lg_id desc');
  942. if(empty($items)) {
  943. return self::outsuccess(array('pd_logs' => array(),'mobile_page' => mobile_page(0)));
  944. }
  945. $logger = new bonus\recorder(session_helper::memberid());
  946. $pd_logs = $logger->filter_pd_log($items);
  947. $pages = $this->pages($count);
  948. return self::outsuccess(array('pd_logs' => $pd_logs,'mobile_page' => mobile_page($pages)));
  949. }
  950. public function shakeOp()
  951. {
  952. if(!isset($_POST['strength']) || !empty($_POST['strength'])) {
  953. $strength = intval($_POST['strength']);
  954. } else {
  955. $strength = 3;
  956. }
  957. $shaker = new shaker_helper();
  958. $items = $shaker->shake($strength,$err);
  959. if($items == false) {
  960. return self::outsuccess(array("bonuses" => [],"info" => array('count' => 0, 'money' => 0.0)));
  961. }
  962. else
  963. {
  964. $total_amount = 0;
  965. $bonuses = array();
  966. foreach ($items as $bonus)
  967. {
  968. $user_bonus = bonus\user_bonus::create_by_param($bonus);
  969. $type_info = bonus_helper::get_typeinfo($user_bonus->type_sn());
  970. $type_info = $type_info['type_info'];
  971. $type = bonus\type::create_by_paramer($type_info);
  972. $item = array();
  973. if($_SESSION['member_id'] == $user_bonus->user_id()) {
  974. $item['direction'] = 'gain';
  975. $item['name'] = $type->sender_name();
  976. $item['bonus_value'] = $user_bonus->bonus_value();
  977. $item['url'] = $this->bonus_detailurl($user_bonus->type_sn());
  978. $total_amount += $user_bonus->bonus_value();
  979. $minfo = new member_info($type->sender_id());
  980. } else {
  981. $item['direction'] = 'lost';
  982. $item['name'] = $user_bonus->user_name();
  983. $item['bonus_value'] = $user_bonus->bonus_value();
  984. $item['url'] = $this->bonus_detailurl($user_bonus->type_sn());
  985. $total_amount -= $user_bonus->bonus_value();
  986. $minfo = new member_info($user_bonus->user_id());
  987. }
  988. $item['is_man'] = $minfo->is_man();
  989. $item['avatar'] = $minfo->avatar();
  990. array_push($bonuses,$item);
  991. }
  992. $count = count($bonuses);
  993. return self::outsuccess(array("bonuses" => $bonuses,"info" => array('count' => $count, 'money' => $total_amount)));
  994. }
  995. }
  996. public function thiefOp()
  997. {
  998. $user_id = $_GET['enmember_id'];
  999. if(empty($user_id)) {
  1000. return self::outerr(errcode::ErrParamter,"被偷的用户不存在");
  1001. }
  1002. $user_id = util::decrypt_data(urldecode($user_id));
  1003. if($user_id <= 0) {
  1004. return self::outerr(errcode::ErrParamter,"被偷的用户不存在");
  1005. }
  1006. else
  1007. {
  1008. $amount = session_helper::thief($user_id,$err);
  1009. if($amount == false) {
  1010. return self::outerr($err['code'],$err['msg']);
  1011. }
  1012. else
  1013. {
  1014. $bonuses = account_helper::gain_bonus($user_id, $_SESSION['member_id'], $amount);
  1015. if($bonuses == false || empty($bonuses)) {
  1016. return self::outerr(errcode::ErrBonus,"这次没偷着");
  1017. } else {
  1018. $bonus = $bonuses[0];
  1019. $tips = "您成功偷到{$bonus['bonus_value']}元";
  1020. return self::outsuccess(array("bonuses" => $bonuses,
  1021. "info" => ['count' => 1, 'money' => $bonus['bonus_value'],'tips' => $tips]));
  1022. }
  1023. }
  1024. }
  1025. }
  1026. private function bonus_detailurl($type_sn)
  1027. {
  1028. $url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&type_sn={$type_sn}&client_type=wap";
  1029. return $url;
  1030. }
  1031. public function daily_rankOp()
  1032. {
  1033. $count = ranklist_helper::list_count($_SESSION['member_id']);
  1034. if($count == false) {
  1035. return self::outerr(errcode::ErrBonusDailyRank,"您还没有抢红包记录,明天才能看到榜单~");
  1036. }
  1037. $start_index = ($this->page_no() - 1) * $this->page_size();
  1038. $end = $start_index + $this->page_size();
  1039. $end = $end > $count ? $count : $end;
  1040. $times = array();
  1041. $start_tm = time();
  1042. for ($index = $start_index; $index < $end; ++$index) {
  1043. $date_time = date_helper::sub_days($start_tm,$index + 1);
  1044. array_push($times,$date_time);
  1045. }
  1046. $mids = array();
  1047. array_push($mids,intval($_SESSION['member_id']));
  1048. $top_infos = array();
  1049. $tops = ranklist_helper::ranklists($_SESSION['member_id'],$times);
  1050. foreach ($tops as $key => $top) {
  1051. $item = array();
  1052. $item['list_sn'] = $top->list_sn();
  1053. $item['list_rank'] = $top->get_rank() + 1;
  1054. $item['list_value'] = $top->money();
  1055. $item['list_date'] = $top->list_date();
  1056. $item['top_id'] = $top->top_id();
  1057. $item['top_money'] = $top->top_money();
  1058. if(in_array($top->top_id(),$mids) == false) {
  1059. array_push($mids,$top->top_id());
  1060. }
  1061. array_push($top_infos,$item);
  1062. }
  1063. $mem_desc = array();
  1064. $members = Model('member')->getMemberList(array('member_id' => array('in',$mids)));
  1065. foreach ($members as $val) {
  1066. $info = new member_info($val);
  1067. array_push($mem_desc,$info->filter());
  1068. }
  1069. $pages = intval($count / $this->page_size()) + ( ($count % $this->page_size()) == 0 ? 0 : 1);
  1070. return self::outsuccess(array('top_list' => $top_infos,'mem_desc' => $mem_desc,'mobile_page' => mobile_page($pages)));
  1071. }
  1072. //免费送
  1073. public function free_giftsOp()
  1074. {
  1075. return self::outsuccess(null,"bonus/free_gifts");
  1076. // $user = intval($_GET['curuser']);
  1077. // if(session_helper::need_wechat_author())
  1078. // {
  1079. // $author = new thrid_author\wxauthor();
  1080. // $url = author_url::inviter_url($user);
  1081. // $url = $author->enter($url);
  1082. // return self::outsuccess(['direct_uri' => $url],"redirect");
  1083. // }
  1084. //
  1085. // if($user <= 0)
  1086. // {
  1087. // if(session_helper::logined()) {
  1088. // $user = session_helper::memberid();
  1089. // }
  1090. // }
  1091. //
  1092. // $type_sn = account_helper::invite_bonus(session_helper::share_id());
  1093. // if($user > 0) {
  1094. // return self::outsuccess(['tpl' => new tpl_free_gifts($user,$type_sn)],"bonus/free_gifts",'wap');
  1095. // }
  1096. // else {
  1097. // return self::outerr(errcode::ErrParamter);
  1098. // }
  1099. }
  1100. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1101. public function share_oneOp()
  1102. {
  1103. if(!isset($_GET['bonus_sn']) || empty($_GET['bonus_sn'])) {
  1104. return self::outerr(errcode::ErrParamter,"需要红包序列号.");
  1105. }
  1106. $bonus_sn = $_GET['bonus_sn'];
  1107. $ret = $this->mUserAccount->share_bonus($bonus_sn,$msg);
  1108. if($ret === false) {
  1109. return self::outerr(errcode::ErrBonus,empty($msg) ? "生成红包失败." : $msg);
  1110. } else {
  1111. $type_sn = $ret['type_sn'];
  1112. $url = url_helper::bonus_open_url($type_sn);
  1113. return self::outsuccess(array('type_sn' => $ret,'url' => "{$url}"));
  1114. }
  1115. }
  1116. public function send_listOp()
  1117. {
  1118. $type_infos = $this->send_list($pages);
  1119. return self::outsuccess(array('type_infos' => $type_infos, 'mobile_page' => mobile_page($pages)));
  1120. }
  1121. private function send_list(&$pages)
  1122. {
  1123. $mod_type = Model('bonus_type');
  1124. $cond['sender_id|relayer_id'] = ['_multi'=>true,$_SESSION['member_id'],$_SESSION['member_id']];
  1125. $cond['make_type'] = array('in',array(bonus\type::MakeSendType,bonus\type::MakeInviteType));
  1126. $count = $mod_type->getTypeCount($cond);
  1127. if($count == 0) {
  1128. $pages = 0;
  1129. return null;
  1130. }
  1131. $items = $mod_type->getTypeList($cond,$this->page_size(),'*','type_id desc');
  1132. $type_infos = [];
  1133. foreach($items as $val) {
  1134. $type_info = bonus_helper::filter_type($val);
  1135. $type_infos[] = $type_info;
  1136. }
  1137. $pages = $this->pages($count);
  1138. return $type_infos;
  1139. }
  1140. }
  1141. class tpl_free_gifts
  1142. {
  1143. private $mUser;
  1144. private $mRewardedInvites;
  1145. private $mRewardingInvites;
  1146. private $mUserInfo;
  1147. private $mShareInfo;
  1148. private $mTypesn;
  1149. private $mMineInfo;
  1150. private $mRank;
  1151. private $mMine;
  1152. private $mCaller;
  1153. public function __construct($user,$type_sn)
  1154. {
  1155. $this->mUser = $user;
  1156. $this->mRewardedInvites = [];
  1157. $this->mRewardingInvites = [];
  1158. $this->init($user);
  1159. $this->mShareInfo = invite_helper::share_info(session_helper::share_id());
  1160. $this->mTypesn = $type_sn;
  1161. $this->mMine = (session_helper::memberid() == $user);
  1162. $this->mCaller = new user_session\friend_caller();
  1163. }
  1164. private function init($user)
  1165. {
  1166. if($user <= 0) return false;
  1167. $mod_member = Model('member');
  1168. $items = $mod_member->getMemberList(['member_id|inviter_id' => ['_multi' => true,$user,$user]],'*', 0, 'reward_amount desc');
  1169. $cur_user = session_helper::memberid();
  1170. $index = 0;
  1171. foreach ($items as $item)
  1172. {
  1173. $user_info = new member_info($item);
  1174. $uid = $user_info->member_id();
  1175. if($uid == $user) {
  1176. $this->mUserInfo = $user_info;
  1177. }
  1178. elseif ($uid == $cur_user) {
  1179. $this->mMineInfo = $user_info;
  1180. $this->mRank = $index + 1;
  1181. }
  1182. else
  1183. {
  1184. if($user_info->rewared_inviter()) {
  1185. $this->mRewardedInvites[] = $user_info;
  1186. } else {
  1187. $this->mRewardingInvites[] = $user_info;
  1188. }
  1189. }
  1190. $index++;
  1191. }
  1192. }
  1193. public function show()
  1194. {
  1195. $this->show_relay();
  1196. // if(!empty($this->mTypesn)) {
  1197. // $this->show_bonus();
  1198. // }
  1199. $rewared = $this->show_rewared();
  1200. $rewarding = $this->show_rewarding();
  1201. if($rewared == false && $rewarding == false) {
  1202. $this->show_noinvitee();
  1203. }
  1204. $this->show_prompt();
  1205. }
  1206. private function show_noinvitee()
  1207. {
  1208. echo "<div class=\"bonus_list\">";
  1209. echo "<span class=\"invite_null\">TA尚未邀请好友</span>";
  1210. echo "</div>";
  1211. }
  1212. private function show_relay()
  1213. {
  1214. $minfo = $this->mUserInfo;
  1215. $inviter_id = $minfo->inviter_id();
  1216. $str = "
  1217. <div class=\"profit_box\">
  1218. <div class=\"left_profit\">
  1219. <img class=\"profit_avatar\" src=\"{$minfo->avatar()}\" alt=\"\">
  1220. <p class=\"f14 col333 lineH1\">{$minfo->nickname()}</p>
  1221. ";
  1222. if($inviter_id > 0) {
  1223. $str .= "";
  1224. }
  1225. $str .= "
  1226. </div>
  1227. <div class=\"right_profit\">
  1228. <p class=\"profit_money mb9\">{$minfo->reward_amount()}<span class=\"profit_unit\">元</span></p>
  1229. <p class=\"f14 col666 lineH1\">邀请好友累计获得收益</p>
  1230. </div>
  1231. </div>";
  1232. echo $str;
  1233. }
  1234. // private function show_bonus()
  1235. // {
  1236. // echo "<div class=\"open_bonus_link\">
  1237. // <div class=\"bonus\">
  1238. // <div class=\"bonus_top\"></div>
  1239. // <div class=\"bonus_center\"></div>
  1240. // <div class=\"bonus_bg\">
  1241. // <span id=\"coin\" class=\"open_bonus_btn gold_coin\"></span>
  1242. // </div>
  1243. // </div>
  1244. // </div>";
  1245. // }
  1246. private function show_rewared()
  1247. {
  1248. if(empty($this->mMineInfo) && empty($this->mRewardedInvites)) {
  1249. return false;
  1250. }
  1251. if(!empty($this->mMineInfo) && $this->mMineInfo->rewared_inviter()) {
  1252. $count = count($this->mRewardedInvites) + 1;
  1253. } else {
  1254. $count = count($this->mRewardedInvites);
  1255. }
  1256. echo "<div class=\"bonus_list\">";
  1257. echo "<div class=\"prompt_label\">
  1258. <span class=\"title\">已带来收益的好友<span class=\"invite_num\">({$count})</span></span>
  1259. </div>";
  1260. if(!empty($this->mMineInfo) && $this->mMineInfo->rewared_inviter()) {
  1261. $this->show_invitee($this->mMineInfo);
  1262. }
  1263. foreach ($this->mRewardedInvites as $minfo) {
  1264. $this->show_invitee($minfo);
  1265. }
  1266. echo "</div>";
  1267. return true;
  1268. }
  1269. private function show_rewarding()
  1270. {
  1271. if(empty($this->mMineInfo) && empty($this->mRewardingInvites)) {
  1272. return false;
  1273. }
  1274. if(!empty($this->mMineInfo) && $this->mMineInfo->rewared_inviter() == false) {
  1275. $count = count($this->mRewardingInvites) + 1;
  1276. } else {
  1277. $count = count($this->mRewardingInvites);
  1278. }
  1279. echo "<div class=\"bonus_list\">";
  1280. echo "<div class=\"prompt_label\">
  1281. <span class=\"title\">尚未带来收益的好友<span class=\"invite_num\">({$count})</span></span>
  1282. </div>";
  1283. if(!empty($this->mMineInfo) && $this->mMineInfo->rewared_inviter() == false) {
  1284. $this->show_invitee($this->mMineInfo);
  1285. }
  1286. foreach ($this->mRewardingInvites as $minfo) {
  1287. $this->show_invitee($minfo);
  1288. }
  1289. echo "</div>";
  1290. return true;
  1291. }
  1292. private function show_prompt()
  1293. {
  1294. $str = "<div class=\"prompt\">
  1295. <div class=\"prompt_label\">
  1296. <span class=\"title\">提示</span>
  1297. </div>
  1298. <div class=\"prompt_list\">
  1299. <p>1.由于近期发现恶意刷红包用户,为保障体验,在邀请好友之后,需要好友微信授权、注册、下载APP登录后才发邀请奖励。</p>
  1300. <p>2.邀请前5名新用户可得10元100%红包,邀请好友数量>5后可得10元40%红包,雨露均沾红包为40%红包,为了您的长期收益,我们建议您邀请真实的朋友。</p>
  1301. <p>3.您可以点击\"召唤TA\",邀请好友回来。(同一用户每天只能召唤一次)</p>
  1302. <p>4.熊猫有权解散违规邀请的用户,收回已发红包并关闭相关订单。(具体细节查看规则)</p>
  1303. </div>
  1304. </div>
  1305. <div class=\"briefing_address\"></div>";
  1306. echo $str;
  1307. }
  1308. private function show_invitee($minfo)
  1309. {
  1310. if(empty($minfo)) return;
  1311. $user = $minfo->member_id();
  1312. $called = $this->mCaller->called($user);
  1313. $url = BASE_SITE_URL . "/mobile/index.php?act=invite_friend&op=index&client_type=wap&curuser={$user}";
  1314. $str = "<div class=\"item\">
  1315. <a href=\"{$url}\">
  1316. <div class=\"user_img\">
  1317. <img src=\"{$minfo->avatar()}\">
  1318. </div>
  1319. <div class=\"user_name text-overflow\">
  1320. <p class=\"text-overflow\"> {$minfo->nickname()}</p>
  1321. <p class=\"invite_msg\">邀请{$minfo->invitees()}人,收益<span class=\"price\">{$minfo->reward_amount()}</span>元</p>
  1322. </div>";
  1323. if($this->mMine == false)
  1324. {
  1325. $str .= "<div class=\"look_btn\">
  1326. <span class=\"arrow\"></span>
  1327. </div>";
  1328. }
  1329. $str .= "</a>";
  1330. if($this->mMine)
  1331. {
  1332. if($called) {
  1333. $str .= "<span class=\"call_btn called\" data-user=\"{$user}\">召唤TA</span>";
  1334. } else {
  1335. $str .= "<span class=\"call_btn\" data-user=\"{$user}\">召唤TA</span>";
  1336. }
  1337. }
  1338. $str .= "</div>";
  1339. echo $str;
  1340. }
  1341. public function show_open()
  1342. {
  1343. if(!session_helper::isapp())
  1344. {
  1345. echo "<div class=\"fixed_bottom\">
  1346. <span class=\"logo\"></span>
  1347. <div class=\"label\">
  1348. <p>熊猫美妆</p>
  1349. <p>下载APP即可得更多奖励</p>
  1350. </div>
  1351. <a href=\"#\" class=\"download_app_btn\" id=\"download_app\">打开APP</a>
  1352. </div>";
  1353. }
  1354. }
  1355. public function bonus_url() {
  1356. return url_helper::bonus_open_url($this->mTypesn);
  1357. }
  1358. public function share_url()
  1359. {
  1360. return url_helper::bonus_open_url($this->mTypesn);
  1361. }
  1362. public function share_title()
  1363. {
  1364. return $this->mShareInfo['title'];
  1365. }
  1366. public function share_image()
  1367. {
  1368. return $this->mShareInfo['img'];;
  1369. }
  1370. public function share_subtitle()
  1371. {
  1372. return $this->mShareInfo['sub_title'];;
  1373. }
  1374. }