account_helper.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/6/27
  6. * Time: 下午2:46
  7. */
  8. require_once(BASE_HELPER_PATH . '/bonus_helper.php');
  9. require_once(BASE_HELPER_PATH . '/model_helper.php');
  10. require_once(BASE_HELPER_PATH . '/push_helper.php');
  11. require_once(BASE_HELPER_PATH . '/sms_helper.php');
  12. require_once(BASE_HELPER_PATH . '/bonus/parameters.php');
  13. require_once(BASE_HELPER_PATH . '/user_session/favorite.php');
  14. require_once(BASE_HELPER_PATH . '/user_session/anotice.php');
  15. require_once(BASE_HELPER_PATH . '/fcode/mfcode.php');
  16. require_once(BASE_HELPER_PATH . '/fcode/operator.php');
  17. require_once(BASE_HELPER_PATH . '/user_session/fcode.php');
  18. require_once(BASE_HELPER_PATH . '/search/tcp_client.php');
  19. require_once(BASE_HELPER_PATH . '/message/publisher.php');
  20. require_once(BASE_HELPER_PATH . '/async/IAsync.php');
  21. require_once(BASE_HELPER_PATH . '/async/status.php');
  22. require_once(BASE_HELPER_PATH . '/async/register.php');
  23. require_once(BASE_HELPER_PATH . '/async/order.php');
  24. require_once(BASE_HELPER_PATH . '/async/qugc.php');
  25. require_once(BASE_HELPER_PATH . '/async/bargain.php');
  26. require_once(BASE_HELPER_PATH . '/room_helper.php');
  27. require_once(BASE_HELPER_PATH . '/async/broadcast_order.php');
  28. require_once(BASE_HELPER_PATH . '/async/broadcast.php');
  29. require_once(BASE_HELPER_PATH . '/async/broadcast/filter.php');
  30. require_once(BASE_HELPER_PATH . '/async/broadcast/operator.php');
  31. require_once(BASE_HELPER_PATH . '/async/broadcast/sender.php');
  32. require_once(BASE_HELPER_PATH . '/async/broadcast/params_table.php');
  33. require_once(BASE_HELPER_PATH . '/order_helper.php');
  34. require_once(BASE_HELPER_PATH . '/fcode/present_manager.php');
  35. require_once(BASE_HELPER_PATH . '/schema_helper.php');
  36. require_once(BASE_HELPER_PATH . '/url_helper.php');
  37. require_once(BASE_HELPER_PATH . '/mcard/mcard.php');
  38. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  39. class account_helper
  40. {
  41. ///
  42. public static function invite_bonus($relay_id)
  43. {
  44. $last_type = bonus_helper::last_invite_type($relay_id);
  45. if (is_null($last_type) == false) {
  46. $type = bonus_helper::create_by_paramer($last_type);
  47. if ($type->binded_over() == false && $type->isEnd() == false) {
  48. return $type->getType_sn();
  49. }
  50. }
  51. $param = bonus\parameters::invite($relay_id);
  52. $ret = bonus_helper::make_bonus($param, $param['rate_money']);
  53. if ($ret != false) {
  54. $type_sn = $ret['type_sn'];
  55. push_helper::invite_bonus($relay_id,$param['rate_money']['amount'],$type_sn);
  56. return $type_sn;
  57. } else {
  58. return false;
  59. }
  60. }
  61. static private $stSysBonus = null;
  62. public static function gain_system($to_id, $amount)
  63. {
  64. if (account_helper::$stSysBonus == null) {
  65. account_helper::$stSysBonus = new bonus\sys_bonus();
  66. }
  67. if (account_helper::$stSysBonus->bind_over()) {
  68. $param = account_helper::$stSysBonus->gen_param($rates);
  69. $ret = bonus_helper::make_bonus($param, $rates);
  70. if ($ret != false) {
  71. $type_sn = $ret['type_sn'];
  72. account_helper::$stSysBonus->reset($type_sn);
  73. } else {
  74. return false;
  75. }
  76. }
  77. $bonus = bonus_helper::send(account_helper::$stSysBonus->type_sn(), [$to_id]);
  78. return $bonus;
  79. }
  80. public static function gain_bonus($from_id,$to_id,$amount)
  81. {
  82. $pred_from = new bonus\account($from_id);
  83. $bonus_rate = $pred_from->find_share_bonus($amount);
  84. if($bonus_rate == false || $bonus_rate['rate'] > 30) {
  85. return false;
  86. }
  87. $minfo = new member_info($from_id);
  88. $param = bonus\parameters::shake_gain($minfo->member_id(),$minfo->mobile(),$minfo->nickname(),$bonus_rate['rate'],$bonus_rate['amount']);
  89. $ret = bonus_helper::make_bonus($param,$param['rate_money']);
  90. if($ret != false)
  91. {
  92. $to_minfo = new member_info($to_id);
  93. $thief = $to_minfo->nickname();
  94. $amount = $bonus_rate['amount'];
  95. bonus_helper::withold_money($from_id,$bonus_rate['rate'],$amount,bonus_helper::send_bonus_withold);
  96. $logger = new bonus\recorder($from_id);
  97. $logger->handout_bonus($amount,$ret['type_sn'],$thief,"{$thief}摇走了您{$amount}元的红包.",\bonus\type::MakeShakeGainType);
  98. $bonusex = bonus_helper::send($ret['type_sn'],[$to_id]);
  99. push_helper::stolen_bonus($minfo,$to_minfo,$amount);
  100. return $bonusex;
  101. } else {
  102. return false;
  103. }
  104. }
  105. public static function lost_bonus($from_id,$to_id,$amount)
  106. {
  107. $pred_from = new bonus\account($from_id);
  108. $bonus_rate = $pred_from->find_share_bonus($amount);
  109. if($bonus_rate == false) {
  110. return false;
  111. }
  112. $rate = $bonus_rate['rate'];
  113. $amount = $bonus_rate['amount'];
  114. $minfo = new member_info($from_id);
  115. $param = \bonus\parameters::shake_lost($minfo->member_id(),$minfo->mobile(),$minfo->nickname(),$bonus_rate['rate'],$bonus_rate['amount']);
  116. $ret = bonus_helper::make_bonus($param,$param['rate_money']);
  117. if($ret != false)
  118. {
  119. $to_info = new member_info($to_id);
  120. $logger = new bonus\recorder($from_id);
  121. $logger->handout_bonus($amount,$ret['type_sn'],$to_info->nickname(),"您摇丢了{$amount}的红包.",\bonus\type::MakeShakeLostType);
  122. bonus_helper::withold_money($from_id,$rate,$amount,bonus_helper::send_bonus_withold);
  123. $bonusex = bonus_helper::send($ret['type_sn'],[$to_id]);
  124. push_helper::fly_bonus($minfo,$to_info,$amount,$ret['type_sn']);
  125. return $bonusex;
  126. } else {
  127. return false;
  128. }
  129. }
  130. // private static function pay_refund($member_id,$amount,$bonus_name)
  131. // {
  132. // $param = self::base_param($amount,1);
  133. // self::admin_param($param);
  134. // $param['make_type'] = \bonus\type::MakePayRefundType;
  135. // $param['type_name'] = $bonus_name;
  136. //
  137. // $ret = bonus_helper::make_bonus($param);
  138. // if($ret != false)
  139. // {
  140. // bonus_helper::send($ret['type_sn'],array($member_id));
  141. // push_helper::order_refund_bonus($member_id,$amount);
  142. // } else {
  143. // Log::record("给用户 {$member_id} 退款{$amount}失败.");
  144. // }
  145. // }
  146. //
  147. // private static function use_bonus($order_sn, $member_id)
  148. // {
  149. // $mod_order = Model('order');
  150. // $order = $mod_order->getOrderInfo(['order_sn' => $order_sn]);
  151. //
  152. // $pd_amount = $order['pd_amount'];
  153. // $bonus_rate = $order['bonus_rate'];
  154. // if(empty($bonus_rate)) {
  155. // $bonus_rate = [30 => $pd_amount];
  156. // } else {
  157. // $bonus_rate = unserialize($bonus_rate);
  158. // }
  159. //
  160. // $pred = new bonus\account($member_id);
  161. // $pred->pay_bonus($bonus_rate);
  162. // }
  163. public static function bonus_refund($type_sn,$member_id)
  164. {
  165. $type = bonus\type::create_by_sn($type_sn);
  166. $amount = $type->remain_amount();
  167. $rate = $type->bonus_rate();
  168. if(empty($rate)) $rate = 30;
  169. $param = \bonus\parameters::bonus_refund($rate,$amount);
  170. $ret = bonus_helper::make_bonus($param,$param['rate_money']);
  171. if($ret != false)
  172. {
  173. $bonus = bonus_helper::send($ret['type_sn'],[$member_id]);
  174. if($bonus != false) {
  175. push_helper::bonus_refund($member_id,$amount,$ret['type_sn']);
  176. }
  177. }
  178. else {
  179. Log::record("给用户 {$member_id} 红包退款{$amount}失败.");
  180. }
  181. }
  182. private static function send_bonus($param,$rates,array $member_ids)
  183. {
  184. $ret = bonus_helper::make_bonus($param,$rates);
  185. if($ret != false)
  186. {
  187. $type_sn = $ret['type_sn'];
  188. $items = bonus_helper::send($type_sn,$member_ids);
  189. if($items != false)
  190. {
  191. $result = [];
  192. foreach ($items as $bonus_param) {
  193. $bonus = bonus\user_bonus::create_by_param($bonus_param);
  194. $user_id = $bonus->user_id();
  195. $result[$user_id] = $bonus;
  196. }
  197. return $result;
  198. }
  199. else {
  200. return false;
  201. }
  202. }
  203. else {
  204. return false;
  205. }
  206. }
  207. public static function add_bonus($rate,$amount,$member_ids,$type_name,$can_share,$usable_days = bonus\parameters::usable_days)
  208. {
  209. $param = bonus\parameters::admin_fixed(intval($rate),doubleval($amount),count($member_ids),$type_name,$can_share,$usable_days);
  210. $fix_bonus = self::send_bonus($param,$param['rate_money'],$member_ids);
  211. if($fix_bonus != false) {
  212. return true;
  213. } else {
  214. return false;
  215. }
  216. }
  217. public static function appreciate($sender_id,$rate,$amount,$toid,$bless)
  218. {
  219. $param = bonus\parameters::appreciate($sender_id,intval($rate),$amount,$bless);
  220. $pred = new bonus\account($sender_id);
  221. $rate_moneys[] = ['rate' => $rate,'num' => 1,'amount' => $amount,'hold_amount' => $amount];
  222. $ret = $pred->make_bonus($param,$rate_moneys);
  223. if($ret == false) return false;
  224. $type_sn = $ret['type_sn'];
  225. $ret = bonus_helper::send($type_sn,[$toid]);
  226. return ($ret != false);
  227. }
  228. public static function withhold_bonus($rate,$amount,$member_id)
  229. {
  230. $rates = [intval($rate) => doubleval($amount)];
  231. $ret = bonus_helper::withold($member_id,$rates,bonus_helper::pay_order_withold);
  232. if($ret) {
  233. $logger = new bonus\recorder($member_id);
  234. $logger->reduce_pred($amount);
  235. } else {
  236. Log::record('扣除预存款失败',Log::ERR);
  237. }
  238. return $ret;
  239. }
  240. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  241. public static function onPredRefund($change_type,$member_id,$sn,$refund_id)
  242. {
  243. // $order_sn = $sn;
  244. // $order = order::create_by_sn($order_sn);
  245. // if($order == false) {
  246. // self::pay_refund($member_id,$pd_amount,"退款红包");
  247. // } else {
  248. // self::pay_refund($member_id,$order->pd_amount(),"退款红包");
  249. // }
  250. }
  251. public static function onPredeposit($change_type,$member_id,$sn)
  252. {
  253. if($change_type == 'order_cancel')
  254. {
  255. //发送给该用户一个同等额度的红包
  256. $mod_order = Model('order');
  257. $order = $mod_order->getOrderInfo(['order_sn' => $sn,'buyer_id' => $member_id]);
  258. if(!empty($order)) {
  259. $pay_sn = $order['pay_sn'];
  260. $order_sn = $order['order_sn'];
  261. QueueClient::push('onAsyncOrderCancel',['pay_sn' => $pay_sn,'order_sn' => $order_sn]);
  262. }
  263. }
  264. elseif($change_type == 'refund') { //发送给该用户一个同等额度的红包
  265. }
  266. elseif($change_type == 'bonus_refund') { // 发送给该用户一个同等额度的红包
  267. self::bonus_refund($sn,$member_id);
  268. }
  269. }
  270. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  271. public static function onLogin($member_id)
  272. {
  273. if(session_helper::isapp()) {
  274. $updata['client_type'] = session_helper::client_type();
  275. $updata['client_version'] = session_helper::version_code();
  276. Model('member')->editMember(['member_id' => $member_id], $updata);
  277. }
  278. relation_helper::onLogin($member_id);
  279. $anotice = new user_session\anotice();
  280. $anotice->onStatus();
  281. $favorate = new user_session\favorite();
  282. $favorate->onLogin();
  283. $fcode = new user_session\fcode();
  284. $fcode->onStatus();
  285. QueueClient::push('onAsyncStatus',['member_id' => $member_id]);
  286. $member_info = Model('member')->getMemberInfoByID($member_id);
  287. if(intval($member_info['member_mobile_bind']) == 1) {
  288. $user_cards = new mtopcard\user_topcards($member_id);
  289. $user_cards->addPhone($member_info['member_mobile']);
  290. }
  291. $rewared_inviter = intval($member_info['rewared_inviter']);
  292. $inviter_id = intval($member_info['inviter_id']);
  293. if(session_helper::isapp() && session_helper::logined() && $rewared_inviter == 0) {
  294. QueueClient::push('onAsyncRegister',['user' => $member_id,'inviter' => $inviter_id]);
  295. }
  296. }
  297. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  298. public static function onStatus($member_id)
  299. {
  300. relation_helper::onLogin($member_id);
  301. $member_info = Model('member')->getMemberInfoByID($member_id);
  302. $updata['member_login_num'] = $member_info['member_login_num'] + 1;
  303. $updata['member_login_time'] = time();
  304. $updata['member_old_login_time'] = $member_info['member_login_time'];
  305. $updata['member_login_ip'] = getIp();
  306. $updata['member_old_login_ip'] = $member_info['member_login_ip'];
  307. if(session_helper::isapp()) {
  308. $updata['client_type'] = session_helper::client_type();
  309. $updata['client_version'] = session_helper::version_code();
  310. }
  311. Model('member')->editMember(['member_id' => $member_id], $updata);
  312. $anotice = new user_session\anotice();
  313. $anotice->onStatus();
  314. $favorate = new user_session\favorite();
  315. $favorate->onLogin();
  316. $fcode = new user_session\fcode();
  317. $fcode->onStatus();
  318. $rewared_inviter = intval($member_info['rewared_inviter']);
  319. $inviter_id = intval($member_info['inviter_id']);
  320. if(session_helper::isapp() && session_helper::logined() && $rewared_inviter == 0) {
  321. QueueClient::async_push('onAsyncRegister',['user' => $member_id,'inviter' => $inviter_id],5);
  322. }
  323. QueueClient::async_push('onAsyncStatus',['member_id' => $member_id],10);
  324. }
  325. public static function onAsyncStatus($member_id)
  326. {
  327. try
  328. {
  329. $iPusher = new async\status($member_id);
  330. $iPusher->run();
  331. } catch (Exception $ex) {
  332. Log::record($ex->getMessage(),Log::ERR);
  333. }
  334. }
  335. public static function onAsyncTopup($member_id)
  336. {
  337. try
  338. {
  339. $iPusher = new async\status($member_id);
  340. $iPusher->topup();
  341. } catch (Exception $ex) {
  342. Log::record($ex->getMessage(),Log::ERR);
  343. }
  344. }
  345. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  346. public static function onRegister($member_id,$relay_id,$channel = 0)
  347. {
  348. QueueClient::push('makeMemberMiniQrCode',['member_id' => $member_id]);
  349. QueueClient::push('sendInviterSubMsg', ['inviter_id' => $relay_id,'invitee_id' => $member_id]);
  350. if(session_helper::isapp()) {
  351. $updata['client_type'] = session_helper::client_type();
  352. $updata['client_version'] = session_helper::version_code();
  353. Model('member')->editMember(['member_id' => $member_id], $updata);
  354. }
  355. if($relay_id > 0) {
  356. relation_helper::onSubscribe($member_id,$relay_id);
  357. relation_helper::onInvite($relay_id,$member_id);
  358. }
  359. relation_helper::onRegister($member_id);
  360. $publisher = new message\publisher();
  361. if($relay_id > 0) {
  362. $publisher->add_follow($relay_id,[$member_id]);
  363. }
  364. $publisher->add_inviter($member_id,$relay_id);
  365. if(session_helper::logined() && session_helper::isapp()) {
  366. QueueClient::async_push('onAsyncRegister',['user' => $member_id,'inviter' => $relay_id],5);
  367. }
  368. }
  369. public static function onAsyncRegister($user,$inviter)
  370. {
  371. try
  372. {
  373. $iPusher = new async\register($user,$inviter);
  374. $iPusher->run();
  375. } catch (Exception $ex) {
  376. Log::record($ex->getMessage(),Log::ERR);
  377. }
  378. }
  379. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  380. public static function onAsyncOrderPaied($pay_sn)
  381. {
  382. try
  383. {
  384. $iPusher = new async\order($pay_sn);
  385. $iPusher->onPaied();
  386. } catch (Exception $ex) {
  387. Log::record($ex->getMessage(),Log::ERR);
  388. }
  389. }
  390. public static function onAsyncOrderSended($pay_sn,$logistics_no,$logistics_company)
  391. {
  392. try
  393. {
  394. $iPusher = new async\order($pay_sn);
  395. $iPusher->onSended($logistics_no,$logistics_company);
  396. } catch (Exception $ex) {
  397. Log::record($ex->getMessage(),Log::ERR);
  398. }
  399. }
  400. public static function onAsyncOrderComplete($pay_sn)
  401. {
  402. try
  403. {
  404. $iPusher = new async\order($pay_sn);
  405. $iPusher->onComplete();
  406. } catch (Exception $ex) {
  407. Log::record($ex->getMessage(),Log::ERR);
  408. }
  409. }
  410. public static function onAsyncBroadcastOrder($pay_sn,$amount,$days)
  411. {
  412. try
  413. {
  414. $iPusher = new async\broadcast_order($pay_sn);
  415. $iPusher->order_bonus($amount,$days);
  416. } catch (Exception $ex) {
  417. Log::record($ex->getMessage(),Log::ERR);
  418. }
  419. }
  420. public static function onAsyncBroadcastNormal($filters,$oper_param,$send_params)
  421. {
  422. try
  423. {
  424. $sms_type = $send_params['type'];
  425. $memf_params = $filters['member_filters'];
  426. $mem_filters = async\filter::create($memf_params);
  427. $oper = async\operator::create($oper_param);
  428. $smsf_params = $filters['sms_filters'];
  429. $sms_filters = async\filter::create($smsf_params);
  430. $sender = async\sender::create($sms_filters,$send_params);
  431. $broad = new async\broadcast($mem_filters,$oper,$sender,$sms_type);
  432. $broad->run();
  433. } catch (Exception $ex) {
  434. Log::record($ex->getMessage(),Log::ERR);
  435. }
  436. }
  437. public static function onAsyncOrderCancel($pay_sn,$order_sn)
  438. {
  439. try
  440. {
  441. $iPusher = new async\order($pay_sn);
  442. $iPusher->onCancel($order_sn);
  443. } catch (Exception $ex) {
  444. Log::record($ex->getMessage(),Log::ERR);
  445. }
  446. }
  447. public static function onAsyncOrderEvaluate($pay_sn)
  448. {
  449. try
  450. {
  451. $iPusher = new async\order($pay_sn);
  452. $iPusher->onEvaluate();
  453. } catch (Exception $ex) {
  454. Log::record($ex->getMessage(),Log::ERR);
  455. }
  456. }
  457. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  458. public static function onAsyncUgcPublish($spid)
  459. {
  460. try
  461. {
  462. $iPusher = new async\qugc($spid);
  463. $iPusher->onPublish();
  464. } catch (Exception $ex) {
  465. Log::record($ex->getMessage(),Log::ERR);
  466. }
  467. }
  468. public static function onAsyncUgcDel($spid)
  469. {
  470. try
  471. {
  472. $iPusher = new async\qugc($spid);
  473. $iPusher->onDel();
  474. } catch (Exception $ex) {
  475. Log::record($ex->getMessage(),Log::ERR);
  476. }
  477. }
  478. public static function onAsyncUgcSubmit($spid,$user)
  479. {
  480. try
  481. {
  482. $iPusher = new async\qugc($spid);
  483. $iPusher->onSubmit($user);
  484. } catch (Exception $ex) {
  485. Log::record($ex->getMessage(),Log::ERR);
  486. }
  487. }
  488. public static function onAsyncUgcSupport($spid,$comment_id,$user)
  489. {
  490. try
  491. {
  492. $iPusher = new async\qugc($spid);
  493. $iPusher->onSupport($comment_id,$user);
  494. } catch (Exception $ex) {
  495. Log::record($ex->getMessage(),Log::ERR);
  496. }
  497. }
  498. public static function onAsyncUgcComment($spid,$commentid,$userid)
  499. {
  500. try
  501. {
  502. $iPusher = new async\qugc($spid);
  503. $iPusher->onComment($commentid,$userid);
  504. } catch (Exception $ex) {
  505. Log::record($ex->getMessage(),Log::ERR);
  506. }
  507. }
  508. public static function onAsyncUgcAppreciate($spid,$user,$rate,$amount)
  509. {
  510. try
  511. {
  512. $iPusher = new async\qugc($spid);
  513. $iPusher->onAppreciate($user,$rate,$amount);
  514. } catch (Exception $ex) {
  515. Log::record($ex->getMessage(),Log::ERR);
  516. }
  517. }
  518. ////////////////////////////////////////Bargain/////////////////////////////////////////////////////////////////////
  519. public static function onAsyncBargain($type,$bargain_id)
  520. {
  521. try
  522. {
  523. $bargain = new async\bargain($bargain_id);
  524. if($type == "close") {
  525. $bargain->onClose();
  526. }
  527. } catch (Exception $ex) {
  528. Log::record($ex->getMessage(),Log::ERR);
  529. }
  530. }
  531. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  532. public static function onAsyncFollow($user,$follow)
  533. {
  534. }
  535. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  536. public static function onAsyncGoodsDiscount($gid)
  537. {
  538. }
  539. }