VipcardModel.class.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace Home\Model;
  3. use Think\Model;
  4. /**
  5. * 拼团模型模型
  6. * @author fish
  7. *
  8. */
  9. class VipcardModel {
  10. public function update($data)
  11. {
  12. $ins_data = array();
  13. $ins_data['cardname'] = $data['cardname'];
  14. $ins_data['orignprice'] = $data['orignprice'];
  15. $ins_data['price'] = $data['price'];
  16. $ins_data['expire_day'] = $data['expire_day'];
  17. $ins_data['addtime'] = time();
  18. $id = $data['id'];
  19. if( !empty($id) && $id > 0 )
  20. {
  21. unset($ins_data['addtime']);
  22. M('lionfish_comshop_member_card')->where( array('id' => $id) )->save( $ins_data );
  23. $id = $data['id'];
  24. }else{
  25. $id = M('lionfish_comshop_member_card')->add( $ins_data );
  26. }
  27. }
  28. public function updateequity($data)
  29. {
  30. $ins_data = array();
  31. $ins_data['equity_name'] = $data['equity_name'];
  32. $ins_data['image'] = $data['image'];
  33. $ins_data['addtime'] = time();
  34. $id = $data['id'];
  35. if( !empty($id) && $id > 0 )
  36. {
  37. unset($ins_data['addtime']);
  38. M('lionfish_comshop_member_card_equity')->where( array('id' => $id) )->save( $ins_data );
  39. $id = $data['id'];
  40. }else{
  41. $id = M('lionfish_comshop_member_card_equity')->add( $ins_data );
  42. }
  43. }
  44. /**
  45. * 会员卡0元支付订单
  46. * @param $order_id
  47. */
  48. public function member_charge_zero_card($order_id){
  49. //购买会员卡代码
  50. $member_charge_flow_info = M('lionfish_comshop_member_card_order')->where( array('id' => $order_id ) )->find();
  51. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id'] ) )->find();
  52. if(!empty($member_charge_flow_info) && $member_charge_flow_info['state'] == 0)
  53. {
  54. $begin_time = 0;
  55. $end_time = 0;
  56. if($member_charge_flow_info['order_type'] == 1)
  57. {
  58. //首次购买
  59. $begin_time = time();
  60. $end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
  61. }else if($member_charge_flow_info['order_type'] == 2)
  62. {
  63. //有效期内续期
  64. $begin_time = $member_info['card_end_time'];
  65. $end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
  66. }else if($member_charge_flow_info['order_type'] == 3)
  67. {
  68. //过期后续费
  69. $begin_time = time();
  70. $end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
  71. }
  72. $charge_flow_data = array();
  73. $charge_flow_data['trans_id'] = "";
  74. $charge_flow_data['state'] = 1;
  75. $charge_flow_data['pay_time'] = time();
  76. $charge_flow_data['begin_time'] = $begin_time;
  77. $charge_flow_data['end_time'] = $end_time;
  78. $charge_flow_data['state'] = 1;
  79. M('lionfish_comshop_member_card_order')->where( array('id' => $order_id ) )->save( $charge_flow_data );
  80. $mb_up_data = array();
  81. $mb_up_data['card_id'] = $member_charge_flow_info['car_id'];
  82. $mb_up_data['card_begin_time'] = $begin_time;
  83. $mb_up_data['card_end_time'] = $end_time;
  84. M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id'] ) )->save( $mb_up_data );
  85. for($i=0;$i<3;$i++)
  86. {
  87. $member_formid_data = array();
  88. $member_formid_data['member_id'] = $member_charge_flow_info['member_id'];
  89. $member_formid_data['state'] = 0;
  90. $member_formid_data['formid'] = $member_charge_flow_info['formid'];
  91. $member_formid_data['addtime'] = time();
  92. M('lionfish_comshop_member_formid')->add($member_formid_data);
  93. }
  94. }
  95. }
  96. }