account_helper.php 21 KB

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