account_helper.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. $updata['member_login_num'] = $member_info['member_login_num'] + 1;
  275. $updata['member_login_time'] = time();
  276. $updata['member_old_login_time'] = $member_info['member_login_time'];
  277. $updata['member_login_ip'] = getIp();
  278. $updata['member_old_login_ip'] = $member_info['member_login_ip'];
  279. if(session_helper::isapp()) {
  280. $updata['client_type'] = session_helper::client_type();
  281. $updata['client_version'] = session_helper::version_code();
  282. }
  283. Model('member')->editMember(['member_id' => $member_id], $updata);
  284. $anotice = new user_session\anotice();
  285. $anotice->onStatus();
  286. $favorate = new user_session\favorite();
  287. $favorate->onLogin();
  288. $fcode = new user_session\fcode();
  289. $fcode->onStatus();
  290. QueueClient::push('onAsyncStatus',['member_id' => $member_id]);
  291. }
  292. public static function onAsyncStatus($member_id)
  293. {
  294. try
  295. {
  296. $iPusher = new async\status($member_id);
  297. $iPusher->run();
  298. } catch (Exception $ex) {
  299. Log::record($ex->getMessage(),Log::ERR);
  300. }
  301. }
  302. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  303. public static function onRegister($member_id,$relay_id)
  304. {
  305. if($relay_id > 0) {
  306. relation_helper::onSubscribe($member_id,$relay_id);
  307. relation_helper::onInvite($relay_id,$member_id);
  308. }
  309. relation_helper::onRegister($member_id);
  310. $publisher = new message\publisher();
  311. if($relay_id > 0) {
  312. $publisher->add_follow($relay_id,[$member_id]);
  313. }
  314. $publisher->add_inviter($member_id,$relay_id);
  315. QueueClient::push('onAsyncRegister',['user' => $member_id,'inviter' => $relay_id]);
  316. }
  317. public static function onAsyncRegister($user,$inviter)
  318. {
  319. try
  320. {
  321. $iPusher = new async\register($user,$inviter);
  322. $iPusher->run();
  323. } catch (Exception $ex) {
  324. Log::record($ex->getMessage(),Log::ERR);
  325. }
  326. }
  327. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  328. public static function onAsyncOrderPaied($pay_sn)
  329. {
  330. try
  331. {
  332. $iPusher = new async\order($pay_sn);
  333. $iPusher->onPaied();
  334. } catch (Exception $ex) {
  335. Log::record($ex->getMessage(),Log::ERR);
  336. }
  337. }
  338. public static function onAsyncOrderSended($pay_sn,$logistics_no,$logistics_company)
  339. {
  340. try
  341. {
  342. $iPusher = new async\order($pay_sn);
  343. $iPusher->onSended($logistics_no,$logistics_company);
  344. } catch (Exception $ex) {
  345. Log::record($ex->getMessage(),Log::ERR);
  346. }
  347. }
  348. public static function onAsyncOrderComplete($pay_sn)
  349. {
  350. try
  351. {
  352. $iPusher = new async\order($pay_sn);
  353. $iPusher->onComplete();
  354. } catch (Exception $ex) {
  355. Log::record($ex->getMessage(),Log::ERR);
  356. }
  357. }
  358. public static function onAsyncOrderCancel($pay_sn)
  359. {
  360. try
  361. {
  362. $iPusher = new async\order($pay_sn);
  363. $iPusher->onCancel();
  364. } catch (Exception $ex) {
  365. Log::record($ex->getMessage(),Log::ERR);
  366. }
  367. }
  368. public static function onAsyncOrderEvaluate($pay_sn)
  369. {
  370. try
  371. {
  372. $iPusher = new async\order($pay_sn);
  373. $iPusher->onEvaluate();
  374. } catch (Exception $ex) {
  375. Log::record($ex->getMessage(),Log::ERR);
  376. }
  377. }
  378. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  379. public static function onAsyncUgcPublish($spid)
  380. {
  381. try
  382. {
  383. $iPusher = new async\qugc($spid);
  384. $iPusher->onPublish();
  385. } catch (Exception $ex) {
  386. Log::record($ex->getMessage(),Log::ERR);
  387. }
  388. }
  389. public static function onAsyncUgcDel($spid)
  390. {
  391. try
  392. {
  393. $iPusher = new async\qugc($spid);
  394. $iPusher->onDel();
  395. } catch (Exception $ex) {
  396. Log::record($ex->getMessage(),Log::ERR);
  397. }
  398. }
  399. public static function onAsyncUgcSubmit($spid,$user)
  400. {
  401. try
  402. {
  403. $iPusher = new async\qugc($spid);
  404. $iPusher->onSubmit($user);
  405. } catch (Exception $ex) {
  406. Log::record($ex->getMessage(),Log::ERR);
  407. }
  408. }
  409. public static function onAsyncUgcSupport($spid,$comment_id,$user)
  410. {
  411. try
  412. {
  413. $iPusher = new async\qugc($spid);
  414. $iPusher->onSupport($comment_id,$user);
  415. } catch (Exception $ex) {
  416. Log::record($ex->getMessage(),Log::ERR);
  417. }
  418. }
  419. public static function onAsyncUgcComment($spid,$commentid,$userid)
  420. {
  421. try
  422. {
  423. $iPusher = new async\qugc($spid);
  424. $iPusher->onComment($commentid,$userid);
  425. } catch (Exception $ex) {
  426. Log::record($ex->getMessage(),Log::ERR);
  427. }
  428. }
  429. public static function onAsyncUgcAppreciate($spid,$user,$rate,$amount)
  430. {
  431. try
  432. {
  433. $iPusher = new async\qugc($spid);
  434. $iPusher->onAppreciate($user,$rate,$amount);
  435. } catch (Exception $ex) {
  436. Log::record($ex->getMessage(),Log::ERR);
  437. }
  438. }
  439. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  440. public static function onAsyncFollow($user,$follow)
  441. {
  442. }
  443. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  444. public static function onAsyncGoodsDiscount($gid)
  445. {
  446. }
  447. }