member_bonus.php 55 KB

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