cart.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. //用户可删除已用余额支付的订单,并将余额退回帐户
  10. define("PAYMENT_NOT_EXIST",0); //支付单被删除(提示联系管理员)
  11. define("PAY_SUCCESS",1); //充值成功(充值到相应的会员帐户中,并生成日志)或者订单支付成功
  12. define("ORDER_REPAY",2); //订单重复支付(即付款单所属的订单已支付,将支付的金额转存到会员帐户,并生成日志)
  13. define("ORDER_EXPIRED",3); //订单支付失败(限时已到,无法完成订单支付,退款到会员帐户,并生成日志)
  14. define("ORDER_SOLDOUT",4); //订单支付失败(即库存已满,无法完成订单支付,退款到会员帐户,并生成日志)
  15. //付款记录支付
  16. //返回
  17. function payment_paid($notice_sn,$outer_sn)
  18. {
  19. $payment_notice = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."payment_notice where notice_sn = '".$notice_sn."'");
  20. if($payment_notice)
  21. {
  22. $pInTrans = $GLOBALS['db']->StartTrans();
  23. try
  24. {
  25. $total_diamonds = 0;
  26. //充值单
  27. $sql = "update ".DB_PREFIX."payment_notice set pay_time = '".get_gmtime()."',is_paid = 1,outer_notice_sn = '".$outer_sn."' , pay_date = '".to_date(get_gmtime(), 'Y-m-d')."' where id = ".$payment_notice['id']." and is_paid = 0";
  28. $GLOBALS['db']->query($sql);
  29. if($GLOBALS['db']->affected_rows())
  30. {
  31. $GLOBALS['db']->query("update ".DB_PREFIX."payment set total_amount = total_amount + ".$payment_notice['money']." where id = ".$payment_notice['payment_id']);
  32. if ($payment_notice['order_id']>0) {
  33. //判断是否为鲜肉
  34. if($payment_notice['type']==11){
  35. $weibo_id = $payment_notice['order_id'];
  36. $weibo = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."weibo where id = ".$weibo_id);
  37. $money = $payment_notice['money'];
  38. if($weibo){
  39. // 更新状态
  40. $GLOBALS['db']->query("UPDATE ".DB_PREFIX."weibo set red_count = red_count+1 where id = ".$weibo_id);
  41. $GLOBALS['db']->query("UPDATE ".DB_PREFIX."user set weibo_money = weibo_money+$money where id = ".$weibo['user_id']);
  42. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  43. fanwe_require(APP_ROOT_PATH.'mapi/xr/redis/WeiboContributionRedisService.php');
  44. $weiboCont_redis = new WeiboContributionRedisService();
  45. $weiboCont_redis->insert_db($payment_notice['user_id'], $weibo['user_id'], $money);
  46. //进行分销
  47. $weiboCont_redis->distribution_calculate($payment_notice['user_id'], $money,$payment_notice['recharge_name']);
  48. }else{
  49. //增加到付款人的金额中
  50. $GLOBALS['db']->query("UPDATE ".DB_PREFIX."user set weibo_money = weibo_money+$money where id = ".$payment_notice['user_id']);
  51. $GLOBALS['db']->query("UPDATE ".DB_PREFIX."payment_notice set is_paid= 3 where id = ".$payment_notice['id']);//退款到余额中
  52. }
  53. }else{
  54. $is_p = $GLOBALS['db']->getOne("select is_p from ".DB_PREFIX."goods_order where id = ".$payment_notice['order_id']);
  55. if(intval($is_p) == 0){
  56. //购买
  57. $goods_order = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."goods_order where id = ".$payment_notice['order_id']);
  58. if($goods_order){
  59. // 更新订单状态
  60. $pay_time = date("Y-m-d H:i:s",time());
  61. $goods_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."goods where id = ".$goods_order['goods_id']);
  62. $video_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "video where user_id=" . $goods_order['podcast_id'] . " and live_in =1");
  63. if($goods_order['buy_type'] == 0){
  64. $table = DB_PREFIX . "goods_order";
  65. $sql = "UPDATE $table SET order_status = '2',pay_time='".$pay_time."',pay_diamonds='".$goods_order['total_diamonds']."' WHERE `id`=".$payment_notice['order_id'];
  66. $GLOBALS['db']->query($sql);
  67. // $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$goods_order['podcast_ticket']." where id = ".$goods_order['podcast_id'];
  68. // $GLOBALS['db']->query($sql);//主播增加佣金
  69. // user_deal_to_reids(array(intval($goods_order['podcast_id'])));
  70. if($goods_info){
  71. $root['quantity'] = intval($goods_order['number']);
  72. $root['goods_logo'] = json_decode(get_spec_image($goods_info['imgs']),true)[0];
  73. $root['goods_name'] = $goods_info['name'];
  74. $root['order_sn'] = $goods_order['order_sn'];
  75. $root['empirivalue'] = $goods_info['score'];
  76. }
  77. $ext = array();
  78. $ext['goods'] = $root;
  79. $root['roomId'] = intval($video_info['id']);
  80. $root['groupId'] = $video_info['group_id'];
  81. $root['createrId'] = $video_info['user_id'];
  82. $root['loadingVideoImageUrl'] = get_spec_image($video_info['head_image']);
  83. $root['video_type'] = $video_info['video_type'];
  84. $ext['type'] = 37;
  85. $ext['room_id'] = intval($video_info['id']);
  86. $ext['post_id'] = $goods_order['viewer_id'];
  87. $ext['desc'] = "我购买“" .$root['goods_name']. "”";
  88. $ext['is_self'] = 1;
  89. $ext['score'] = $root['empirivalue'];
  90. }else{
  91. $order_info=array();
  92. $order_info['order_status']=4;
  93. $order_info['order_status_time']=NOW_TIME;
  94. $order_info['pay_time']=$pay_time;
  95. $order_info['pay_diamonds'] = $goods_order['total_diamonds'];
  96. $GLOBALS['db']->autoExecute(DB_PREFIX."goods_order", $order_info, $mode = 'UPDATE', "order_sn='".$goods_order['order_sn']."'");
  97. $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$goods_order['podcast_ticket']." where id = ".$goods_order['podcast_id'];
  98. $GLOBALS['db']->query($sql);//主播增加佣金
  99. user_deal_to_reids(array(intval($goods_order['podcast_id'])));
  100. if($goods_info){
  101. $root['quantity'] = intval($goods_order['number']);
  102. $root['goods_logo'] = json_decode(get_spec_image($goods_info['imgs']),true)[0];
  103. $root['goods_name'] = $goods_info['name'];
  104. $root['order_sn'] = $goods_order['order_sn'];
  105. $root['empirivalue'] = $goods_info['score'];
  106. }
  107. $ext = array();
  108. $ext['goods'] = $root;
  109. $root['roomId'] = intval($video_info['id']);
  110. $root['groupId'] = $video_info['group_id'];
  111. $root['createrId'] = $video_info['user_id'];
  112. $root['loadingVideoImageUrl'] = get_spec_image($video_info['head_image']);
  113. $root['video_type'] = $video_info['video_type'];
  114. $ext['type'] = 37;
  115. $ext['room_id'] = intval($video_info['id']);
  116. $ext['post_id'] = $goods_order['viewer_id'];
  117. $ext['desc'] = "我购买“" .$root['goods_name']. "”赠送主播";
  118. $ext['is_self'] = 0;
  119. $ext['score'] = $root['empirivalue'];
  120. }
  121. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  122. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserFollwRedisService.php');
  123. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
  124. $user_redis = new UserRedisService();
  125. $fields = array('head_image', 'user_level', 'v_type', 'v_icon', 'nick_name');
  126. $ext['user'] = $user_redis->getRow_db($goods_order['viewer_id'], $fields);
  127. $ext['user']['user_id'] = $goods_order['viewer_id'];
  128. $ext['user']['head_image'] = get_spec_image($ext['user']['head_image']);
  129. $ext['user']['nick_name'] = emoji_decode($ext['user']['nick_name']);
  130. $user_score = $GLOBALS['db']->query("update ".DB_PREFIX."user set score=score+".intval($root['empirivalue'])." where id = ".$goods_order['viewer_id']);
  131. $podcast_score = $GLOBALS['db']->query("update ".DB_PREFIX."user set score=score+".intval($root['empirivalue'])." where id = ".$goods_order['podcast_id']);
  132. if($user_score && $podcast_score){
  133. //更新经验
  134. $user_redis->inc_score($goods_order['viewer_id'],intval($root['empirivalue']));
  135. $user_redis->inc_score($goods_order['podcast_id'],intval($root['empirivalue']));
  136. }
  137. // $sql = "update ".DB_PREFIX."goods set inventory=inventory-".$goods_order['number']." where id = ".$goods_order['goods_id'];
  138. // $GLOBALS['db']->query($sql);//商品库存减少
  139. #构造高级接口所需参数
  140. $tim_data = array();
  141. $tim_data['ext'] = $ext;
  142. $tim_data['podcast_id'] = strim($goods_order['viewer_id']);
  143. $tim_data['group_id'] = strim($video_info['group_id']);
  144. $tim_data['score'] = intval($root['empirivalue']);
  145. get_tim_api($tim_data);
  146. }
  147. }else{
  148. $goods_order = $GLOBALS['db']->getAll("select * from ".DB_PREFIX."goods_order where pid= ".$payment_notice['order_id']);
  149. if($goods_order){
  150. $pay_time = date("Y-m-d H:i:s",time());
  151. $sql = "UPDATE ".DB_PREFIX."goods_order SET order_status = '2',pay_time='".$pay_time."' WHERE `id`=".$payment_notice['order_id'];
  152. $GLOBALS['db']->query($sql);
  153. foreach($goods_order as $key =>$value){
  154. $goods_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."goods where id = ".$value['goods_id']);
  155. $video_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "video where user_id=" . $value['podcast_id'] . " and live_in =1");
  156. if($value['buy_type'] == 0){
  157. $table = DB_PREFIX . "goods_order";
  158. $sql = "UPDATE $table SET order_status = '2',pay_time='".$pay_time."',pay_diamonds='".$goods_order['total_diamonds']."' WHERE `id`=".$value['id'];
  159. $GLOBALS['db']->query($sql);
  160. // $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$value['podcast_ticket']." where id = ".$value['podcast_id'];
  161. // $GLOBALS['db']->query($sql);//主播增加佣金
  162. // user_deal_to_reids(array(intval($value['podcast_id'])));
  163. if($goods_info){
  164. $root['quantity'] = intval($value['number']);
  165. $root['goods_logo'] = json_decode(get_spec_image($goods_info['imgs']),true)[0];
  166. $root['goods_name'] = $goods_info['name'];
  167. $root['order_sn'] = $value['order_sn'];
  168. $root['empirivalue'] = $goods_info['score'];
  169. }
  170. $ext = array();
  171. $ext['goods'] = $root;
  172. $root['roomId'] = intval($video_info['id']);
  173. $root['groupId'] = $video_info['group_id'];
  174. $root['createrId'] = $video_info['user_id'];
  175. $root['loadingVideoImageUrl'] = get_spec_image($video_info['head_image']);
  176. $root['video_type'] = $video_info['video_type'];
  177. $ext['type'] = 37;
  178. $ext['room_id'] = intval($video_info['id']);
  179. $ext['post_id'] = $value['viewer_id'];
  180. $ext['desc'] = "我购买“" .$root['goods_name']. "”";
  181. $ext['is_self'] = 1;
  182. $ext['score'] = $root['empirivalue'];
  183. }else{
  184. $order_info=array();
  185. $order_info['order_status']=4;
  186. $order_info['order_status_time']=NOW_TIME;
  187. $order_info['pay_time']=$pay_time;
  188. $order_info['pay_diamonds'] = $goods_order['total_diamonds'];
  189. $GLOBALS['db']->autoExecute(DB_PREFIX."goods_order", $order_info, $mode = 'UPDATE', "order_sn='".$value['order_sn']."'");
  190. $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$value['podcast_ticket']." where id = ".$value['podcast_id'];
  191. $GLOBALS['db']->query($sql);//主播增加佣金
  192. user_deal_to_reids(array(intval($value['podcast_id'])));
  193. if($goods_info){
  194. $root['quantity'] = intval($value['number']);
  195. $root['goods_logo'] = json_decode(get_spec_image($goods_info['imgs']),true)[0];
  196. $root['goods_name'] = $goods_info['name'];
  197. $root['order_sn'] = $value['order_sn'];
  198. $root['empirivalue'] = $goods_info['score'];
  199. }
  200. $ext = array();
  201. $ext['goods'] = $root;
  202. $root['roomId'] = intval($video_info['id']);
  203. $root['groupId'] = $video_info['group_id'];
  204. $root['createrId'] = $video_info['user_id'];
  205. $root['loadingVideoImageUrl'] = get_spec_image($video_info['head_image']);
  206. $root['video_type'] = $video_info['video_type'];
  207. $ext['type'] = 37;
  208. $ext['room_id'] = intval($video_info['id']);
  209. $ext['post_id'] = $value['viewer_id'];
  210. $ext['desc'] = "我购买“" .$root['goods_name']. "”赠送主播";
  211. $ext['is_self'] = 0;
  212. $ext['score'] = $root['empirivalue'];
  213. }
  214. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  215. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserFollwRedisService.php');
  216. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
  217. $user_redis = new UserRedisService();
  218. $fields = array('head_image', 'user_level', 'v_type', 'v_icon', 'nick_name');
  219. $ext['user'] = $user_redis->getRow_db($value['viewer_id'], $fields);
  220. $ext['user']['user_id'] = $value['viewer_id'];
  221. $ext['user']['head_image'] = get_spec_image($ext['user']['head_image']);
  222. $ext['user']['nick_name'] = emoji_decode($ext['user']['nick_name']);
  223. $user_score = $GLOBALS['db']->query("update ".DB_PREFIX."user set score=score+".intval($root['empirivalue'])." where id = ".$value['viewer_id']);
  224. $podcast_score = $GLOBALS['db']->query("update ".DB_PREFIX."user set score=score+".intval($root['empirivalue'])." where id = ".$value['podcast_id']);
  225. if($user_score && $podcast_score){
  226. //更新经验
  227. $user_redis->inc_score($value['viewer_id'],intval($root['empirivalue']));
  228. $user_redis->inc_score($value['podcast_id'],intval($root['empirivalue']));
  229. }
  230. // $sql = "update ".DB_PREFIX."goods set inventory=inventory-".$value['number']." where id = ".$value['goods_id'];
  231. // $GLOBALS['db']->query($sql);//商品库存减少
  232. #构造高级接口所需参数
  233. $tim_data = array();
  234. $tim_data['ext'] = $ext;
  235. $tim_data['podcast_id'] = strim($value['viewer_id']);
  236. $tim_data['group_id'] = strim($video_info['group_id']);
  237. $tim_data['score'] = intval($root['empirivalue']);
  238. get_tim_api($tim_data);
  239. }
  240. }
  241. }
  242. }
  243. }else{
  244. $user_id = intval($payment_notice['user_id']);
  245. if(intval($payment_notice['type'])==1){
  246. $day_num = intval($payment_notice['diamonds']);
  247. if($day_num>0){
  248. $vip_time = $day_num * 24 * 3600;//购买的会员时长
  249. $sql = "select id,is_vip,vip_expire_time from ".DB_PREFIX."user where id = ".$user_id;
  250. $user = $GLOBALS['db']->getRow($sql,true,true);
  251. if(intval($user['is_vip'])==1){
  252. $vip_expire_time = intval($user['vip_expire_time']) + $vip_time; //已经是会员,会员到期时间 = 当前会员到期时间 + 购买的会员时长
  253. }else{
  254. $vip_expire_time = NOW_TIME + $vip_time;//非会员 会员到期时间 = 当前时间 + 购买的会员时长
  255. }
  256. $sql = "update ".DB_PREFIX."user set is_vip = 1,vip_expire_time = ".$vip_expire_time." where id = ".$user_id;
  257. $GLOBALS['db']->query($sql);
  258. }
  259. }elseif(intval($payment_notice['type'])==11){
  260. // 'weixin'=>'购买微信号',
  261. //'reward'=>'打赏',
  262. // 'chat'=>'聊天付费',
  263. // $weibo_id = $payment_notice['order_id'];
  264. // $weibo = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."weibo where id = ".$weibo_id);
  265. if($payment_notice['type_cate']=='weixin'||$payment_notice['type_cate']=='reward'||$payment_notice['type_cate']=='chat'){
  266. $money = $payment_notice['money'];
  267. $GLOBALS['db']->query("UPDATE ".DB_PREFIX."user set weibo_money = weibo_money+$money where id = ".$payment_notice['to_user_id']);
  268. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  269. fanwe_require(APP_ROOT_PATH.'mapi/xr/redis/WeiboContributionRedisService.php');
  270. $weiboCont_redis = new WeiboContributionRedisService();
  271. $weiboCont_redis->insert_db($payment_notice['user_id'], $payment_notice['to_user_id'], $money);
  272. //进行分销
  273. $weiboCont_redis->distribution_calculate($payment_notice['user_id'], $money,$payment_notice['recharge_name']);
  274. }
  275. }
  276. else{
  277. $diamonds = intval($payment_notice['diamonds']);
  278. if ($diamonds == 0){
  279. $payment_info = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."payment where class_name='Iappay'");
  280. if(intval($payment_info['id'])==intval($payment_notice['payment_id'])){
  281. $sql = "select (iap_diamonds+gift_diamonds) as num from ".DB_PREFIX."recharge_rule where id = ".$payment_notice['recharge_id'];
  282. }else{
  283. $sql = "select (diamonds+gift_diamonds) as num from ".DB_PREFIX."recharge_rule where id = ".$payment_notice['recharge_id'];
  284. }
  285. $diamonds = $GLOBALS['db']->getOne($sql,true,true);
  286. }
  287. if ($diamonds > 0){
  288. $sql = "update ".DB_PREFIX."user set diamonds = diamonds + ".$diamonds." where id = ".$user_id;
  289. $GLOBALS['db']->query($sql);
  290. }
  291. //赠送游戏币
  292. if (OPEN_GAME_MODULE==1) {
  293. $sql = "select gift_coins from ".DB_PREFIX."recharge_rule where id = ".$payment_notice['recharge_id'];
  294. $coins = $GLOBALS['db']->getOne($sql,true,true);
  295. if ($coins > 0){
  296. $sql = "update ".DB_PREFIX."user set coins = coins + ".$coins." where id = ".$user_id;
  297. $GLOBALS['db']->query($sql);
  298. }
  299. }
  300. if ((defined('DISTRIBUTION_SCAN')&&DISTRIBUTION_SCAN==1)) //二级分销_充值后的印票抽成
  301. {
  302. $sql = "select p_user_id from ".DB_PREFIX."user where id = ".$user_id;
  303. $p_user_id = $GLOBALS['db']->getOne($sql,true,true); //获取分销上级ID
  304. if ($p_user_id!=0) //确定为分销下级用户
  305. {
  306. //钻石-印票兑换比例
  307. $sql1 = "select val from ".DB_PREFIX."m_config where code = 'diamond_to_ticket_rate'";
  308. $diamond_to_ticket_rate = $GLOBALS['db']->getOne($sql1,true,true);
  309. //分销下级充值-上级抽成比例
  310. $sql2 = "select val from ".DB_PREFIX."m_config where code = 'distribution_recharge_rate'";
  311. $distribution_recharge_rate = $GLOBALS['db']->getOne($sql2,true,true);
  312. //上级成员印票抽成总额计算
  313. $diamonds = intval($payment_notice['diamonds']);
  314. $tickets_add = intval($diamonds*$diamond_to_ticket_rate*$distribution_recharge_rate);
  315. $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$tickets_add." where id = ".$p_user_id;
  316. $GLOBALS['db']->query($sql);
  317. //写入用户操作日志
  318. fanwe_require(APP_ROOT_PATH.'system/common.php');
  319. $data = array();
  320. $data['ticket'] = $tickets_add;
  321. $data['log_admin_id'] = 0;
  322. $param['type'] = 9;//类型 9表示分销上级抽成
  323. $log_msg ='由于下级分销成员'.$user_id.'充值,用户'.$p_user_id.'获取'.$tickets_add.'印票抽成';
  324. account_log_com($data,$p_user_id,$log_msg,$param);
  325. }
  326. }
  327. }
  328. }
  329. $GLOBALS['db']->Commit($pInTrans);
  330. $pInTrans = false;
  331. if (!function_exists("fanwe_require")) {
  332. require APP_ROOT_PATH."system/common.php";
  333. }
  334. user_deal_to_reids(array($user_id));
  335. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  336. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  337. $user_redis = new UserRedisService();
  338. $total_diamonds = $user_redis->getOne_db($user_id, 'diamonds');
  339. }else{
  340. $data= array();
  341. $data['error'] = '更新订单失败';
  342. $data['payment_info'] = $payment_notice;
  343. log_err_file(array(__FILE__,__LINE__,__METHOD__,$data));
  344. $GLOBALS['db']->Rollback($pInTrans);
  345. }
  346. //get_mortgate();
  347. return array("error"=>"恭喜您,成功","status"=>1, "total_diamonds"=>$total_diamonds,'url'=>$url); //已充值
  348. }catch(Exception $e){
  349. //异常回滚
  350. $GLOBALS['db']->Rollback($pInTrans);
  351. log_err_file(array(__FILE__,__LINE__,__METHOD__,$e->getMessage()));
  352. file_put_contents(APP_ROOT_PATH."public/alipaylog/exc_msg.txt",$e->getMessage());
  353. }
  354. }
  355. else
  356. {
  357. return array("error"=>"无效的支付单号(".$notice_sn."),请联系管理员","status"=>0);
  358. }
  359. }
  360. ?>