account_helper.php 17 KB

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