OrderV3Model.class.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 Home\Model;
  15. use Think\Model;
  16. /**
  17. * @author yj
  18. * @desc 重构前端订单模型
  19. * Class OrderV3Model
  20. * @package Home\Model
  21. */
  22. class OrderV3Model {
  23. public static $payed_status_ids = '1,2,4,6,11,14,15';//已付款订单状态值
  24. public static $wait_send_status_ids = '1';//待发货订单状态
  25. public static $sending_status_ids = '4,14';//已发货,待收货的订单
  26. public static $wait_refund_status_ids = '12';//待退款订单数 , 申请退款中的数量
  27. public static $wait_pay_status_ids = '3';//待付款订单数量
  28. /**
  29. * @author yj
  30. * @desc 根据时间筛选出销售统计
  31. * @param $begin_time
  32. * @param $end_time
  33. */
  34. public function analySalesByTime( $begin_time , $end_time )
  35. {
  36. //1、支付订单数
  37. $condition_paycount = "order_status_id in (".self::$payed_status_ids.") and pay_time >= {$begin_time} and pay_time <= {$end_time} ";
  38. $pay_order_count = M('lionfish_comshop_order')->where($condition_paycount)->count();
  39. //2、支付订单金额
  40. $sum_exp = "total+packing_fare+shipping_fare-voucher_credit-fullreduction_money-score_for_money+localtown_add_shipping_fare-fare_shipping_free";
  41. $pay_order_money = M('lionfish_comshop_order')->where($condition_paycount)->sum( $sum_exp );
  42. //3、待发货订单数量
  43. $condition_wait_send = "order_status_id = ".self::$wait_send_status_ids." and pay_time >= {$begin_time} and pay_time <= {$end_time} ";
  44. $wait_send_count = M('lionfish_comshop_order')->where($condition_wait_send)->count();
  45. //4、配送中订单数量
  46. $condition_sending = "order_status_id in (".self::$sending_status_ids.") and pay_time >= {$begin_time} and pay_time <= {$end_time} ";
  47. $sending_order_count = M('lionfish_comshop_order')->where($condition_sending)->count();
  48. //5、待退款订单数量
  49. $condition_waitrefund = "order_status_id = ".self::$wait_refund_status_ids." and pay_time >= {$begin_time} and pay_time <= {$end_time} ";
  50. $waitrefund_count = M('lionfish_comshop_order')->where($condition_waitrefund)->count();
  51. $data = [];
  52. $data['pay_order_count'] = $pay_order_count;
  53. $data['pay_order_money'] = round($pay_order_money, 2);
  54. $data['wait_send_count'] = $wait_send_count;
  55. $data['sending_order_count'] = $sending_order_count;
  56. $data['waitrefund_count'] = $waitrefund_count;
  57. return $data;
  58. }
  59. /**
  60. * @author y
  61. * @desc 获取今日平台数据
  62. * @return array
  63. */
  64. public function getTodayOrderData()
  65. {
  66. //1、今日付款订单
  67. $begin_time = strtotime( date('Y-m-d ').' 00:00:00' );
  68. $end_time = $begin_time + 86400;
  69. $condition_paycount = "order_status_id in (".self::$payed_status_ids.") and pay_time >= {$begin_time} and pay_time < {$end_time} ";
  70. $todaypay_order_count = M('lionfish_comshop_order')->where($condition_paycount)->count();
  71. //2、今日付款总金额
  72. $sum_exp = "total+packing_fare+shipping_fare-voucher_credit-fullreduction_money-score_for_money+localtown_add_shipping_fare-fare_shipping_free";
  73. $todaypay_order_money = M('lionfish_comshop_order')->where($condition_paycount)->sum( $sum_exp );
  74. //3、今日待付款订单
  75. $condition_wait_send = "order_status_id = ".self::$wait_pay_status_ids." and date_added >= {$begin_time} and date_added < {$end_time} ";
  76. $todaywait_send_count = M('lionfish_comshop_order')->where($condition_wait_send)->count();
  77. $data = [];
  78. $data['todaypay_order_count'] = $todaypay_order_count;
  79. $data['todaypay_order_money'] = round($todaypay_order_money,2);
  80. $data['todaywait_send_count'] = $todaywait_send_count;
  81. return $data;
  82. }
  83. /**
  84. * @author y
  85. * @desc 获取平台用户数据
  86. *
  87. */
  88. public function getPlatformUserData()
  89. {
  90. $today_begin_time = strtotime( date('Y-m-d').' 00:00:00' );
  91. $today_end_time = $today_begin_time +86400;
  92. $yes_begin_time = $today_begin_time - 86400;
  93. $yes_end_time = $today_begin_time;
  94. //1、今日新增会员
  95. $condition = " create_time >= {$today_begin_time} and create_time < {$today_end_time} ";
  96. $today_user_count = M('lionfish_comshop_member')->where($condition)->count();
  97. //2、昨日新增会员
  98. $yes_condition = " create_time >= {$yes_begin_time} and create_time < {$yes_end_time} ";
  99. $yes_user_count = M('lionfish_comshop_member')->where($yes_condition)->count();
  100. //3、总会员数
  101. $total_user_count = M('lionfish_comshop_member')->count();
  102. //4、今日新增团长
  103. $condition_today_head = " addtime >= {$today_begin_time} and addtime < {$today_end_time} ";
  104. $today_addhead_count = M('lionfish_community_head')->where( $condition_today_head )->count();
  105. //5、昨日新增团长
  106. $condition_yes_head = " addtime >= {$yes_begin_time} and addtime < {$yes_end_time} ";
  107. $yes_addhead_count = M('lionfish_community_head')->where( $condition_yes_head )->count();
  108. //6、总团长数
  109. $total_head_count = M('lionfish_community_head')->count();
  110. $data = [];
  111. $data['today_user_count'] = $today_user_count;
  112. $data['yes_user_count'] = $yes_user_count;
  113. $data['total_user_count'] = $total_user_count;
  114. $data['today_addhead_count'] = $today_addhead_count;
  115. $data['yes_addhead_count'] = $yes_addhead_count;
  116. $data['total_head_count'] = $total_head_count;
  117. return $data;
  118. }
  119. /**
  120. * @author yj
  121. * @desc 获取商品数量数据
  122. * @return array
  123. */
  124. public function getPlatformGoodsData()
  125. {
  126. //1、商品总数
  127. $count = M('lionfish_comshop_goods')->count();
  128. //2、普通商品数量
  129. $normal_count = M('lionfish_comshop_goods')->where( array('type' => 'normal') )->count();
  130. //3、拼团商品
  131. $pingoods_count = M('lionfish_comshop_goods')->where( array('type' => 'pin') )->count();
  132. //4、积分商品
  133. $integral_goods_count = M('lionfish_comshop_goods')->where( array('type' => 'integral') )->count();
  134. $data = [];
  135. $data['count'] = $count;
  136. $data['normal_count'] = $normal_count;
  137. $data['pingoods_count'] = $pingoods_count;
  138. $data['integral_goods_count'] = $integral_goods_count;
  139. return $data;
  140. }
  141. /**
  142. * @author y
  143. * @desc 获取平台营业数据
  144. * @return array
  145. */
  146. public function getBusinessData()
  147. {
  148. //1、团长总佣金
  149. $head_commiss_money = M('lionfish_community_head_commiss_order')->where( array( 'state' => 1 ) )->sum('money');
  150. //2、今日利润 (今日利润:今日商城商品销量的全部金额 - 今日商城商品销量的全部成本金额 = 今日商品利润 )
  151. $begin_time = strtotime( date('Y-m-d ').' 00:00:00' );
  152. $end_time = $begin_time + 86400;
  153. $condition_paycount = "order_status_id in (".self::$payed_status_ids.") and pay_time >= {$begin_time} and pay_time < {$end_time} ";
  154. $sum_exp = "total+packing_fare+shipping_fare-voucher_credit-fullreduction_money-score_for_money+localtown_add_shipping_fare-fare_shipping_free";
  155. $todaypay_order_money = M('lionfish_comshop_order')->where($condition_paycount)->sum( $sum_exp );
  156. $sql = "select sum(og.cost_price) as total_cost_price from ".C('DB_PREFIX')."lionfish_comshop_order_goods as og left join ".C('DB_PREFIX')."lionfish_comshop_order as o
  157. on og.order_id = o.order_id where o.order_status_id in (".self::$payed_status_ids.") and o.pay_time >= {$begin_time} and o.pay_time < {$end_time} ";
  158. $res = M()->query( $sql );
  159. $total_cost_price = $res[0]['total_cost_price'];
  160. $today_win_money = $todaypay_order_money - $total_cost_price;
  161. //3、付款人数
  162. $payed_member_count = M('lionfish_comshop_order')->where("order_status_id in (".self::$payed_status_ids.")")->count('distinct member_id');
  163. //4、下单人数
  164. $addorder_member_count = M('lionfish_comshop_order')->count('distinct member_id');
  165. $need_data = [];
  166. $need_data['head_commiss_money'] = round($head_commiss_money, 2);
  167. $need_data['today_win_money'] = round($today_win_money,2);
  168. $need_data['payed_member_count'] = $payed_member_count;
  169. $need_data['addorder_member_count'] = $addorder_member_count;
  170. return $need_data;
  171. }
  172. public function getOrderTotalMoney( $item )
  173. {
  174. $free_tongji = $item['total'] + $item['packing_fare'] +$item['shipping_fare']-$item['voucher_credit']-$item['fullreduction_money'] - $item['score_for_money'] + $item['localtown_add_shipping_fare']- $item['fare_shipping_free'];
  175. if($free_tongji < 0){
  176. $free_tongji = 0;
  177. }
  178. return round( $free_tongji ,2 );
  179. }
  180. }