OrderV3Model.class.php 8.9 KB

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