account_helper.php 17 KB

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