member_bonus.php 56 KB

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