account_helper.php 21 KB

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