BalanceModel.class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Model;
  15. use Think\Model;
  16. class BalanceModel extends Model{
  17. public function show_balance_order_page($bid)
  18. {
  19. $sql='SELECT * FROM '.C('DB_PREFIX').'balance_order where bid='.$bid;
  20. $count=count(M()->query($sql));
  21. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  22. $show = $Page->show();// 分页显示输出
  23. $sql.=' order by boid asc LIMIT '.$Page->firstRow.','.$Page->listRows;
  24. $list=M()->query($sql);
  25. foreach($list as $key => $val)
  26. {
  27. $seller_info = M('seller')->where( array('s_id' =>$val['seller_id']) )->find();
  28. $val['seller'] = $seller_info;
  29. $order_info = M('order')->field('order_num_alias')->where( array('order_id' => $val['order_id']) )->find();
  30. //order_id
  31. $order_goods = M('order_goods')->field('goods_id')->where(array('order_id' => $val['order_id']) )->find();
  32. $goods_to_category = M('goods_to_category')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  33. $store_bind_class = M('store_bind_class')->where( array('seller_id' => $val['seller_id'],
  34. 'class_1' =>$goods_to_category['class_id1'],'class_2' => 0,
  35. 'class_3' => 0
  36. ) )->find();
  37. $val['order_sn'] = $order_info['order_num_alias'];
  38. $val['store_bind_class'] = $store_bind_class;
  39. $member_commiss_order = M('member_commiss_order')->where( array('order_id' => $val['order_id']) )->find();
  40. $val['commiss_money'] = 0;
  41. if( !empty($member_commiss_order) )
  42. {
  43. $val['commiss_money'] = $member_commiss_order['money'];
  44. }
  45. $list[$key] = $val;
  46. }
  47. return array(
  48. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  49. 'list'=>$list,
  50. 'page'=>$show
  51. );
  52. }
  53. /**
  54. 商家等待提现金额
  55. **/
  56. public function wait_balance_order($seller_id)
  57. {
  58. $sql = "select o.order_id,o.total,gtc.class_id1,gtc.class_id2,gtc.class_id3 from ".C('DB_PREFIX')."order as o,".C('DB_PREFIX')."order_goods as og,
  59. ".C('DB_PREFIX')."goods_to_category as gtc
  60. where o.order_id = og.order_id and gtc.goods_id = og.goods_id and og.store_id = ".$seller_id."
  61. and o.is_balance = 0 and o.order_status_id in (1,4,6,11) ";
  62. $order_list = M()->query($sql);
  63. $seller = M('seller')->where(array('s_id' =>$seller_id) )->select();
  64. //获取商家所有绑定类目
  65. $store_bind_class = M('store_bind_class')->where( array('seller_id' => $seller['s_id']) )->select();
  66. $class_rate_arr = array();
  67. foreach($store_bind_class as $bind_class)
  68. {
  69. $key = $bind_class['class_1'].'_'.$bind_class['class_2'].'_'.$bind_class['class_3'];
  70. $class_rate_arr[$key] = $bind_class['commis_rate'];
  71. }
  72. $tongji_money = 0;
  73. $total_reduce_money = 0;
  74. foreach($order_list as $order)
  75. {
  76. $reduce_money = 0;
  77. $del_moeny = 0;
  78. //只按照一级的类目进行计算
  79. $fkey = $order['class_id1'].'_0_0';
  80. $reduce_money = $order['total'] * $class_rate_arr[$fkey] * 0.01;
  81. $del_moeny = $order['total'] - $reduce_money;
  82. $tongji_money += $del_moeny;
  83. $total_reduce_money += $reduce_money;
  84. }
  85. return $tongji_money;
  86. }
  87. /**
  88. * 获取提现记录
  89. */
  90. public function show_balance_assets_page($search='')
  91. {
  92. $where =' where st.seller_id=s.s_id ';
  93. if(!empty($search)) {
  94. $where .= $search;
  95. }
  96. $sql='SELECT st.* FROM '.C('DB_PREFIX').'seller_tixian as st,'.C('DB_PREFIX').'seller as s '.$where;
  97. $count=count(M()->query($sql));
  98. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  99. $show = $Page->show();// 分页显示输出
  100. $sql.=' order by st.state asc ,st.addtime desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  101. $list=M()->query($sql);
  102. foreach($list as $key => $val)
  103. {
  104. $seller_info = M('seller')->where( array('s_id' =>$val['seller_id']) )->find();
  105. $val['seller'] = $seller_info;
  106. $list[$key] = $val;
  107. }
  108. return array(
  109. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  110. 'list'=>$list,
  111. 'page'=>$show
  112. );
  113. }
  114. public function show_balance_page($search=''){
  115. $where ='';
  116. if(!empty($search)) {
  117. $where = 'where '.$search;
  118. }
  119. $sql='SELECT * FROM '.C('DB_PREFIX').'balance '.$where;
  120. $count=count(M()->query($sql));
  121. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  122. $show = $Page->show();// 分页显示输出
  123. $sql.=' order by state asc ,addtime desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  124. $list=M()->query($sql);
  125. foreach($list as $key => $val)
  126. {
  127. $seller_info = M('seller')->where( array('s_id' =>$val['seller_id']) )->find();
  128. $val['seller'] = $seller_info;
  129. $list[$key] = $val;
  130. }
  131. return array(
  132. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  133. 'list'=>$list,
  134. 'page'=>$show
  135. );
  136. }
  137. }
  138. ?>