ReportsController.class.php 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  1. <?php
  2. /**
  3. * 本破解程序由三岁半资源网提供
  4. * 三岁半资源网www.sansuib.com
  5. * QQ:89171639 承接网站建设、公众号搭建、小程序建设、企业网站
  6. */
  7. namespace Seller\Controller;
  8. class ReportsController extends CommonController{
  9. protected function _initialize(){
  10. parent::_initialize();
  11. }
  12. public function index()
  13. {
  14. $_GPC = I('request.');
  15. $condition = ' ';
  16. $cur_controller = 'reports/index';
  17. //今天开始时间
  18. $today = array();
  19. $today['egt'] = strtotime(date('Y-m-d 00:00:00'));
  20. $today['lt'] = strtotime(date('Y-m-d 23:59:59'));
  21. //本周时间
  22. $arr=array();
  23. $thisweek = array();
  24. $arr=getdate();
  25. $num=$arr['wday'];
  26. if(empty($num)){
  27. $num =7;
  28. }
  29. $thisweek['egt'] = $today['egt']-($num-1)*24*60*60;
  30. //$thisweek['lt'] = $today['lt']+(7-$num)*24*60*60;
  31. $thisweek['lt'] = strtotime(date('Y-m-d H:i:s'));
  32. if (empty($_GPC['reports_index']) || $_GPC['reports_index']=='0'){
  33. //每天所有订单
  34. $day_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thisweek['egt']." and date_added < ".$thisweek['lt']." ".$condition." group by date order by date asc");
  35. //总单数和下单金额
  36. $zongdanshu = 0;
  37. $zongxiadan = 0;
  38. foreach($day_info as $val1) {
  39. $zongdanshu += $val1['count'];
  40. $zongxiadan += $val1['total']+$val1['shipping_fare']-$val1['voucher_credit']-$val1['fullreduction_money'];
  41. }
  42. //有订单的所有日期
  43. $day_info2 = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thisweek['egt']." and date_added < ".$thisweek['lt']." ".$condition." group by date order by date asc");
  44. foreach($day_info2 as $key =>$day) {
  45. $day["egt"]=strtotime(date($day["date"],time()));
  46. $day["lt"]=$day["egt"]+(60*60*24)-1;
  47. //每天退款单数
  48. $day_info3 = M()->query("select count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id in (7,8,9,10,12,13))");
  49. if($day_info3){
  50. $daytui = 0;
  51. $daytuikuan =0;
  52. }
  53. //退款单数
  54. $daytui = $day_info3[0]['count'];
  55. //退款金额
  56. $daytuikuan = $day_info3[0]['total']+$day_info3[0]['shipping_fare']-$day_info3[0]['voucher_credit']-$day_info3[0]['fullreduction_money'];
  57. //每天取消单数
  58. $day_info4 = M()->query("select count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id = 5)");
  59. if($day_info4){
  60. $dayqu = 0;
  61. $dayquxiao =0;
  62. }
  63. //取消单数
  64. $dayqu = $day_info4[0]['count'];
  65. //取消金额
  66. $dayquxiao = $day_info4[0]['total']+$day_info4[0]['shipping_fare']-$day_info4[0]['voucher_credit']-$day_info4[0]['fullreduction_money'];
  67. $daylist[$key] = array(
  68. 'daytui' => $daytui,
  69. 'daytuikuan' => $daytuikuan,
  70. 'dayqu' => $dayqu,
  71. 'dayquxiao' => $dayquxiao,
  72. );
  73. }
  74. $list = array();
  75. $list['day_info'] = $day_info;
  76. //合并两个数组
  77. $list2 = array();
  78. foreach($list['day_info'] as $k=>$v){
  79. $list2[] = array_merge($v,$daylist[$k]);
  80. }
  81. //退款
  82. $cancel_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thisweek['egt']." and date_added < ".$thisweek['lt']." ".$condition." and (order_status_id in (7,8,9,10,12,13)) group by date order by date asc");
  83. $zongtuishu =0;
  84. $tuikuan =0;
  85. foreach($cancel_info as $val2) {
  86. $zongtuishu += $val2['count'];
  87. $tuikuan += $val2['total']+$val2['shipping_fare']-$val2['voucher_credit']-$val2['fullreduction_money'];
  88. }
  89. //小计
  90. $subtotal_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thisweek['egt']." and date_added < ".$thisweek['lt']." ".$condition." and (order_status_id in (1,2,3,4,6,11,14)) group by date order by date asc" );
  91. $xaiojishu =0;
  92. $xaioji =0;
  93. foreach($subtotal_info as $val3) {
  94. $xaiojishu += $val3['count'];
  95. $xaioji += $val3['total']+$val3['shipping_fare']-$val3['voucher_credit']-$val3['fullreduction_money'];
  96. }
  97. //取消订单
  98. $quxiao_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thisweek['egt']." and date_added < ".$thisweek['lt']." ".$condition." and (order_status_id = 5) group by date order by date asc");
  99. $quxiaoshu =0;
  100. $quxiao =0;
  101. foreach($quxiao_info as $val4) {
  102. $quxiaoshu += $val4['count'];
  103. $quxiao += $val4['total']+$val4['shipping_fare']-$val4['voucher_credit']-$val4['fullreduction_money'];
  104. }
  105. $tabid = 0;
  106. }
  107. //上周时间
  108. if($_GPC['reports_index'] == 1){
  109. $lastweek['egt'] = $thisweek['egt']-7*24*60*60;
  110. $lastweek['lt'] = $thisweek['egt']-1;
  111. //每天所以订单
  112. $day_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastweek['egt']." and date_added < ".$lastweek['lt']." ".$condition." group by date order by date asc");
  113. //总单数和下单金额
  114. $zongdanshu = 0;
  115. $zongxiadan = 0;
  116. foreach($day_info as $val1) {
  117. $zongdanshu += $val1['count'];
  118. $zongxiadan += $val1['total']+$val1['shipping_fare']-$val1['voucher_credit']-$val1['fullreduction_money'];
  119. }
  120. //有订单的所有日期
  121. $day_info2 = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastweek['egt']." and date_added < ".$lastweek['lt']." ".$condition." group by date order by date asc" );
  122. foreach($day_info2 as $key =>$day) {
  123. $day["egt"]=strtotime(date($day["date"],time()));
  124. $day["lt"]=$day["egt"]+(60*60*24)-1;
  125. //每天退款单数
  126. $day_info3 = M()->query("select count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id in (7,8,9,10,12,13))" );
  127. if($day_info3){
  128. $daytui = 0;
  129. $daytuikuan =0;
  130. }
  131. //退款单数
  132. $daytui = $day_info3[0]['count'];
  133. //退款金额
  134. $daytuikuan = $day_info3[0]['total']+$day_info3[0]['shipping_fare']-$day_info3[0]['voucher_credit']-$day_info3[0]['fullreduction_money'];
  135. //每天取消单数
  136. $day_info4 = M()->query("select count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id = 5)" );
  137. if($day_info4){
  138. $dayqu = 0;
  139. $dayquxiao =0;
  140. }
  141. //取消单数
  142. $dayqu = $day_info4[0]['count'];
  143. //取消金额
  144. $dayquxiao = $day_info4[0]['total']+$day_info4[0]['shipping_fare']-$day_info4[0]['voucher_credit']-$day_info4[0]['fullreduction_money'];
  145. $daylist[$key] = array(
  146. 'daytui' => $daytui,
  147. 'daytuikuan' => $daytuikuan,
  148. 'dayqu' => $dayqu,
  149. 'dayquxiao' => $dayquxiao,
  150. );
  151. }
  152. $list = array();
  153. $list['day_info'] = $day_info;
  154. //合并两个数组
  155. $list2 = array();
  156. foreach($list['day_info'] as $k=>$v){
  157. $list2[] = array_merge($v,$daylist[$k]);
  158. }
  159. //退款
  160. $cancel_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastweek['egt']." and date_added < ".$lastweek['lt']." ".$condition." and (order_status_id in (7,8,9,10,12,13)) group by date order by date asc");
  161. $zongtuishu =0;
  162. $tuikuan =0;
  163. foreach($cancel_info as $val2) {
  164. $zongtuishu += $val2['count'];
  165. $tuikuan += $val2['total']+$val2['shipping_fare']-$val2['voucher_credit']-$val2['fullreduction_money'];
  166. }
  167. //小计
  168. $subtotal_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastweek['egt']." and date_added < ".$lastweek['lt']." ".$condition." and (order_status_id in (1,2,3,4,6,11,14)) group by date order by date asc");
  169. $xaiojishu =0;
  170. $xaioji =0;
  171. foreach($subtotal_info as $val3) {
  172. $xaiojishu += $val3['count'];
  173. $xaioji += $val3['total']+$val3['shipping_fare']-$val3['voucher_credit']-$val3['fullreduction_money'];
  174. }
  175. //取消订单
  176. $quxiao_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastweek['egt']." and date_added < ".$lastweek['lt']." ".$condition." and (order_status_id = 5) group by date order by date asc");
  177. $quxiaoshu =0;
  178. $quxiao =0;
  179. foreach($quxiao_info as $val4) {
  180. $quxiaoshu += $val4['count'];
  181. $quxiao += $val4['total']+$val4['shipping_fare']-$val4['voucher_credit']-$val4['fullreduction_money'];
  182. }
  183. $tabid = 1;
  184. }
  185. //本月时间
  186. if($_GPC['reports_index'] == 2){
  187. $thismonth = array();
  188. $thismonth['egt']=strtotime(date('Y-m-01 00:00:00'));
  189. $thismonth['lt'] = strtotime(date('Y-m-d H:i:s'));
  190. //每天所以订单
  191. $day_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thismonth['egt']." and date_added < ".$thismonth['lt']." ".$condition." group by date order by date asc");
  192. //总单数和下单金额
  193. $zongdanshu = 0;
  194. $zongxiadan = 0;
  195. foreach($day_info as $val1) {
  196. $zongdanshu += $val1['count'];
  197. $zongxiadan += $val1['total']+$val1['shipping_fare']-$val1['voucher_credit']-$val1['fullreduction_money'];
  198. }
  199. //有订单的所有日期
  200. $day_info2 = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thismonth['egt']." and date_added < ".$thismonth['lt']." ".$condition." group by date order by date asc");
  201. foreach($day_info2 as $key =>$day) {
  202. $day["egt"]=strtotime(date($day["date"],time()));
  203. $day["lt"]=$day["egt"]+(60*60*24)-1;
  204. //每天退款单数
  205. $day_info3 = M()->query("select count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id in (7,8,9,10,12,13))");
  206. if($day_info3){
  207. $daytui = 0;
  208. $daytuikuan =0;
  209. }
  210. //退款单数
  211. $daytui = $day_info3[0]['count'];
  212. //退款金额
  213. $daytuikuan = $day_info3[0]['total']+$day_info3[0]['shipping_fare']-$day_info3[0]['voucher_credit']-$day_info3[0]['fullreduction_money'];
  214. //每天取消单数
  215. $day_info4 = M()->query("select count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id = 5)");
  216. if($day_info4){
  217. $dayqu = 0;
  218. $dayquxiao =0;
  219. }
  220. //取消单数
  221. $dayqu = $day_info4[0]['count'];
  222. //取消金额
  223. $dayquxiao = $day_info4[0]['total']+$day_info4[0]['shipping_fare']-$day_info4[0]['voucher_credit']-$day_info4[0]['fullreduction_money'];
  224. $daylist[$key] = array(
  225. 'daytui' => $daytui,
  226. 'daytuikuan' => $daytuikuan,
  227. 'dayqu' => $dayqu,
  228. 'dayquxiao' => $dayquxiao,
  229. );
  230. }
  231. $list = array();
  232. $list['day_info'] = $day_info;
  233. //合并两个数组
  234. $list2 = array();
  235. foreach($list['day_info'] as $k=>$v){
  236. $list2[] = array_merge($v,$daylist[$k]);
  237. }
  238. //退款
  239. $cancel_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thismonth['egt']." and date_added < ".$thismonth['lt']." ".$condition." and (order_status_id in (7,8,9,10,12,13)) group by date order by date asc");
  240. $zongtuishu =0;
  241. $tuikuan =0;
  242. foreach($cancel_info as $val2) {
  243. $zongtuishu += $val2['count'];
  244. $tuikuan += $val2['total']+$val2['shipping_fare']-$val2['voucher_credit']-$val2['fullreduction_money'];
  245. }
  246. //小计
  247. $subtotal_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thismonth['egt']." and date_added < ".$thismonth['lt']." ".$condition." and (order_status_id in (1,2,3,4,6,11,14)) group by date order by date asc");
  248. $xaiojishu =0;
  249. $xaioji =0;
  250. foreach($subtotal_info as $val3) {
  251. $xaiojishu += $val3['count'];
  252. $xaioji += $val3['total']+$val3['shipping_fare']-$val3['voucher_credit']-$val3['fullreduction_money'];
  253. }
  254. //取消订单
  255. $quxiao_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$thismonth['egt']." and date_added < ".$thismonth['lt']." ".$condition." and (order_status_id = 5) group by date order by date asc");
  256. $quxiaoshu =0;
  257. $quxiao =0;
  258. foreach($quxiao_info as $val4) {
  259. $quxiaoshu += $val4['count'];
  260. $quxiao += $val4['total']+$val4['shipping_fare']-$val4['voucher_credit']-$val4['fullreduction_money'];
  261. }
  262. $tabid = 2;
  263. }
  264. //上月时间
  265. if($_GPC['reports_index'] == 3){
  266. $lastmonth['lt'] = strtotime(date('Y-m-01 00:00:00')) - 1;
  267. $month=date('m') - 1;
  268. $year=date('Y');
  269. if($month==1 || $month==3 || $month==5|| $month==7 ||$month==8 || $month==10 ||$month==12 ){
  270. //31天
  271. $lastmonth['egt'] = strtotime(date('Y-m-01 00:00:00')) - 31*24*60*60;
  272. }elseif($month==4 || $month==6 ||$month==9 ||$month==11){
  273. //30天
  274. $lastmonth['egt'] = strtotime(date('Y-m-01 00:00:00')) - 30*24*60*60;
  275. }else{
  276. if($year % 4){
  277. //29天
  278. $lastmonth['egt'] = strtotime(date('Y-m-01 00:00:00')) - 29*24*60*60;
  279. }else{
  280. //28天
  281. $lastmonth['egt'] = strtotime(date('Y-m-01 00:00:00')) - 28*24*60*60;
  282. }
  283. }
  284. //每天所以订单
  285. $day_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastmonth['egt']." and date_added < ".$lastmonth['lt']." ".$condition." group by date order by date asc");
  286. //总单数和下单金额
  287. $zongdanshu = 0;
  288. $zongxiadan = 0;
  289. foreach($day_info as $val1) {
  290. $zongdanshu += $val1['count'];
  291. $zongxiadan += $val1['total']+$val1['shipping_fare']-$val1['voucher_credit']-$val1['fullreduction_money'];
  292. }
  293. //有订单的所有日期
  294. $day_info2 = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastmonth['egt']." and date_added < ".$lastmonth['lt']." ".$condition." group by date order by date asc");
  295. foreach($day_info2 as $key =>$day) {
  296. $day["egt"]=strtotime(date($day["date"],time()));
  297. $day["lt"]=$day["egt"]+(60*60*24)-1;
  298. //每天退款单数
  299. $day_info3 = M()->query("select count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id in (7,8,9,10,12,13))");
  300. if($day_info3){
  301. $daytui = 0;
  302. $daytuikuan =0;
  303. }
  304. //退款单数
  305. $daytui = $day_info3[0]['count'];
  306. //退款金额
  307. $daytuikuan = $day_info3[0]['total']+$day_info3[0]['shipping_fare']-$day_info3[0]['voucher_credit']-$day_info3[0]['fullreduction_money'];
  308. //每天取消单数
  309. $day_info4 = M()->query("select count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id = 5)");
  310. if($day_info4){
  311. $dayqu = 0;
  312. $dayquxiao =0;
  313. }
  314. //取消单数
  315. $dayqu = $day_info4[0]['count'];
  316. //取消金额
  317. $dayquxiao = $day_info4[0]['total']+$day_info4[0]['shipping_fare']-$day_info4[0]['voucher_credit']-$day_info4[0]['fullreduction_money'];
  318. $daylist[$key] = array(
  319. 'daytui' => $daytui,
  320. 'daytuikuan' => $daytuikuan,
  321. 'dayqu' => $dayqu,
  322. 'dayquxiao' => $dayquxiao,
  323. );
  324. }
  325. $list = array();
  326. $list['day_info'] = $day_info;
  327. //合并两个数组
  328. $list2 = array();
  329. foreach($list['day_info'] as $k=>$v){
  330. $list2[] = array_merge($v,$daylist[$k]);
  331. }
  332. //退款
  333. $cancel_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastmonth['egt']." and date_added < ".$lastmonth['lt']." ".$condition." and (order_status_id in (7,8,9,10,12,13)) group by date order by date asc");
  334. $zongtuishu =0;
  335. $tuikuan =0;
  336. foreach($cancel_info as $val2) {
  337. $zongtuishu += $val2['count'];
  338. $tuikuan += $val2['total']+$val2['shipping_fare']-$val2['voucher_credit']-$val2['fullreduction_money'];
  339. }
  340. //小计
  341. $subtotal_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastmonth['egt']." and date_added < ".$lastmonth['lt']." ".$condition." and (order_status_id in (1,2,3,4,6,11,14)) group by date order by date asc");
  342. $xaiojishu =0;
  343. $xaioji =0;
  344. foreach($subtotal_info as $val3) {
  345. $xaiojishu += $val3['count'];
  346. $xaioji += $val3['total']+$val3['shipping_fare']-$val3['voucher_credit']-$val3['fullreduction_money'];
  347. }
  348. //取消订单
  349. $quxiao_info = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date, count( * ) as count,sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money,sum(score_for_money) as score_for_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$lastmonth['egt']." and date_added < ".$lastmonth['lt']." ".$condition." and (order_status_id = 5) group by date order by date asc");
  350. $quxiaoshu =0;
  351. $quxiao =0;
  352. foreach($quxiao_info as $val4) {
  353. $quxiaoshu += $val4['count'];
  354. $quxiao += $val4['total']+$val4['shipping_fare']-$val4['voucher_credit']-$val4['fullreduction_money'];
  355. }
  356. $tabid = 3;
  357. }
  358. if( isset($_GPC['is_export']) && $_GPC['is_export'] == 1 )
  359. {
  360. $columns = array(
  361. array('title' => '下单日期', 'field' => 'date', 'width' => 32),
  362. array('title' => '订单数', 'field' => 'count', 'width' => 32),
  363. array('title' => '下单金额', 'field' => 'order_amount', 'width' => 32),
  364. array('title' => '退款笔数', 'field' => 'daytui', 'width' => 32),
  365. array('title' => '退款金额', 'field' => 'daytuikuan', 'width' => 32),
  366. array('title' => '取消笔数', 'field' => 'dayqu', 'width' => 32),
  367. array('title' => '取消金额', 'field' => 'dayquxiao', 'width' => 32),
  368. array('title' => '小计', 'field' => 'order_ji', 'width' => 32),
  369. );
  370. $exportlist = array();
  371. foreach($list2 as $k => $w){
  372. $tmp_exval = array();
  373. $tmp_exval['date'] = $w['date'];
  374. $tmp_exval['count'] = $w["count"];
  375. $order_amount = $w['total']+$w['shipping_fare']-$w['voucher_credit']-$w['fullreduction_money']-$W['score_for_money'];
  376. $order_amount = sprintf("%.2f",$order_amount);
  377. $tmp_exval['order_amount'] = $order_amount;
  378. $tmp_exval['daytui'] = $w['daytui'];
  379. $tmp_exval['daytuikuan'] = $w['daytuikuan'];
  380. $tmp_exval['dayqu'] = $w['dayqu'];
  381. $w["dayquxiao"] = sprintf("%.2f",$w["dayquxiao"]);
  382. $tmp_exval['dayquxiao'] = $w['dayquxiao'];
  383. $order_ji = $order_amount - $w["daytuikuan"]-$w["dayquxiao"];
  384. $order_ji = sprintf("%.2f",$order_ji);
  385. $tmp_exval['order_ji'] = $order_ji;
  386. $exportlist[] = $tmp_exval;
  387. }
  388. $title = '本周营业数据';
  389. if( isset($_GPC['reports_index']) && $_GPC['reports_index'] == 0)
  390. {
  391. $title = '本周营业数据';
  392. }else if( isset($_GPC['reports_index']) && $_GPC['reports_index'] == 1 ){
  393. $title = '上周营业数据';
  394. }else if( isset($_GPC['reports_index']) && $_GPC['reports_index'] == 2 ){
  395. $title = '本月营业数据';
  396. }else if( isset($_GPC['reports_index']) && $_GPC['reports_index'] == 3 ){
  397. $title = '上月营业数据';
  398. }
  399. D('Seller/Excel')->export($exportlist, array('title' => $title, 'columns' => $columns));
  400. }
  401. $this->lastmonth = $lastmonth;
  402. $this->zongdanshu = $zongdanshu;
  403. $this->zongxiadan = $zongxiadan;
  404. $this->day_info = $day_info;
  405. $this->day_info2 = $day_info2;
  406. $this->list = $list;
  407. $this->list2 = $list2;
  408. $this->zongtuishu = $zongtuishu;
  409. $this->tuikuan = $tuikuan;
  410. $this->cancel_info = $cancel_info;
  411. $this->subtotal_info = $subtotal_info;
  412. $this->xaiojishu = $xaiojishu;
  413. $this->xaioji = $xaioji;
  414. $this->quxiao_info = $quxiao_info;
  415. $this->quxiaoshu = $quxiaoshu;
  416. $this->quxiao = $quxiao;
  417. $this->tabid = $tabid;
  418. $this->_GPC = $_GPC;
  419. $this->display();
  420. }
  421. public function datastatics()
  422. {
  423. $_GPC = I('request.');
  424. $condition = ' 1 ';
  425. //$pindex = max(1, intval($_GPC['page']));
  426. //$psize = 10;
  427. //下单金额(元) sum_money
  428. //下单会员数 sum_member
  429. //下单量 sum_order
  430. //下单商品数 sum_goods
  431. //平均价格 ave_money
  432. //新增会员 add_member
  433. //会员数量 member_num
  434. //新增供货商 add_supplier
  435. //新增团长 add_head
  436. //新增商品 add_goods
  437. //今天开始时间
  438. $today = array();
  439. $today['egt'] = strtotime(date('Y-m-d 00:00:00'));
  440. $today['lt'] = strtotime(date('Y-m-d 23:59:59'));
  441. //今天所以订单
  442. $day_info = M()->query("select count( * ) as count from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$today['egt']." and date_added < ".$today['lt']." and ".$condition );
  443. $day_info2 = M()->query("select total as total,member_id as member_id,shipping_fare as shipping_fare,voucher_credit as voucher_credit,fullreduction_money as fullreduction_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$today['egt']." and date_added < ".$today['lt']." and ".$condition);
  444. $list = array();
  445. $sum_money = 0;
  446. foreach($day_info2 as $key =>$val1) {
  447. //下单金额(元)sum_money
  448. $sum_money += $val1['total']+$val1['shipping_fare']-$val1['voucher_credit']-$val1['fullreduction_money'];
  449. $list[$key] = array(
  450. 'member_id' => $val1['member_id'],
  451. );
  452. }
  453. //下单量sum_order
  454. $sum_order = $day_info[0]['count'];
  455. //下单会员数sum_member
  456. $result = array_unique($list, SORT_REGULAR);
  457. $sum_member = sizeof($result,0);
  458. //下单商品数sum_goods
  459. $goods = M()->query("select goods_id as goods_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods where addtime > ".$today['egt']." and addtime < ".$today['lt']." and ".$condition);
  460. $list1 = array_unique($goods, SORT_REGULAR);
  461. $sum_goods = sizeof($list1,0);
  462. //平均价格 ave_money 下单金额/下单量
  463. if(empty($sum_order)){
  464. $ave_money = 0;
  465. }else{
  466. $ave_money =($sum_money)/($sum_order);
  467. $ave_money = sprintf("%.3f",$ave_money);
  468. }
  469. //新增会员add_member
  470. $add_member = M()->query("select count( * ) as count from ".C('DB_PREFIX')."lionfish_comshop_member where create_time > ".$today['egt']." and create_time < ".$today['lt']." and ".$condition);
  471. $add_member = $add_member[0]['count'];
  472. //会员数量member_num
  473. $member_num = M()->query("select count( * ) as count from ".C('DB_PREFIX')."lionfish_comshop_member where ".$condition,
  474. array(':uniacid' => $_W['uniacid'] ));
  475. $member_num = $member_num[0]['count'];
  476. //新增供货商add_supplier
  477. $add_supplier = M()->query("select count( * ) as count from ".C('DB_PREFIX')."lionfish_comshop_supply where addtime > ".$today['egt']." and addtime < ".$today['lt']." and ".$condition );
  478. $add_supplier = $add_supplier[0]['count'];
  479. //新增团长add_head
  480. $add_head = M()->query("select count( * ) as count from ".C('DB_PREFIX')."lionfish_community_head where addtime > ".$today['egt']." and addtime < ".$today['lt']." and ".$condition );
  481. $add_head = $add_head[0]['count'];
  482. //新增商品add_goods
  483. $add_goods = M()->query("select count( * ) as count from ".C('DB_PREFIX')."lionfish_comshop_goods where addtime > ".$today['egt']." and addtime < ".$today['lt']." and ".$condition );
  484. $add_goods = $add_goods[0]['count'];
  485. //今日销售走势
  486. $todaytime = array();
  487. $todaytime['egt'] = strtotime(date('Y-m-d 00:00:00'));
  488. $todaytime['lt'] = strtotime(date('Y-m-d 23:59:59'));
  489. $today_sales = array();
  490. for($i = 0;$i <= 23; $i++){
  491. $todaytime['egt'] = strtotime(date('Y-m-d 00:00:00'));
  492. $todaytime['egt'] = $todaytime['egt']+$i*60*60;
  493. $todaytime['lt'] = $todaytime['egt']+60*60-1;
  494. //有效销售额
  495. $list = M()->query("select sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$todaytime['egt']." and date_added < ".$todaytime['lt']." and ".$condition." and (order_status_id in (1,2,3,4,6,11,14))" );
  496. if(empty($list[0]['total'])){
  497. $val = 0;
  498. }else{
  499. $val = $list[0]['total']+$list[0]['shipping_fare']-$list[0]['voucher_credit']-$list[0]['fullreduction_money'];
  500. }
  501. $today_sales[$i] = $val;
  502. }
  503. //昨日销售走势
  504. $yestertime = array();
  505. $yestertime['egt'] = strtotime(date('Y-m-d 00:00:00')) - 24*60*60;
  506. $yestertime['lt'] = strtotime(date('Y-m-d 00:00:00')) - 1;
  507. $yesterday_sales = array();
  508. for($i = 0;$i <= 23; $i++){
  509. $yestertime['egt'] = strtotime(date('Y-m-d 00:00:00')) - 24*60*60;
  510. $yestertime['egt'] = $yestertime['egt']+$i*60*60;
  511. $yestertime['lt'] = $yestertime['egt']+60*60-1;
  512. //有效销售额
  513. $list1 = M()->query("select sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$yestertime['egt']." and date_added < ".$yestertime['lt']." and ".$condition." and (order_status_id in (1,2,3,4,6,11,14))" );
  514. if(empty($list1[0]['total'])){
  515. $val1 = 0;
  516. }else{
  517. $val1 = $list1[0]['total']+$list1[0]['shipping_fare']-$list1[0]['voucher_credit']-$list1[0]['fullreduction_money'];
  518. }
  519. $yesterday_sales[$i] = $val1;
  520. }
  521. //七天的时间
  522. $sevenday = array();
  523. $sevenday['egt'] = strtotime(date('Y-m-d 00:00:00'))-6*24*60*60;
  524. $sevenday['lt'] = strtotime(date('Y-m-d 23:59:59'));
  525. //7日内团长销量top10
  526. $sevenday_sale = M()->query("select head_id as head_id from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$sevenday['egt']." and date_added < ".$sevenday['lt']." and ".$condition);
  527. //所有团长id
  528. $sale = array();
  529. foreach($sevenday_sale as $key =>$v) {
  530. $sale[$key] = array(
  531. 'head_id' => $v['head_id'],
  532. );
  533. }
  534. //合并数据,唯一团长id
  535. $sale = array_unique($sale, SORT_REGULAR);
  536. //var_dump($sale);
  537. //var_dump($sale);
  538. //获取供应信息
  539. $sale_list = array();
  540. foreach($sale as $key =>$v) {
  541. //社区店名称
  542. $sale1 = M()->query("select community_name as community_name ,head_name as head_name from ".C('DB_PREFIX')."lionfish_community_head where id = ".$v['head_id']." and ".$condition);
  543. //var_dump($sale1);
  544. //团长
  545. //订单数量
  546. $sale2 = M()->query("select count( * ) as count from ".C('DB_PREFIX')."lionfish_comshop_order where(head_id = ".$v['head_id'].") and date_added > ".$sevenday['egt']." and date_added < ".$sevenday['lt']." and ".$condition);
  547. //var_dump($sale2);
  548. //有效订单金额(元)
  549. $sale3 = M()->query("select sum(total) as total,sum(shipping_fare) as shipping_fare,sum(voucher_credit) as voucher_credit,sum(fullreduction_money) as fullreduction_money from ".C('DB_PREFIX')."lionfish_comshop_order where (head_id = ".$v['head_id'].") and date_added > ".$sevenday['egt']." and date_added < ".$sevenday['lt']." and ".$condition );
  550. //有效订单金额(元)sum_money
  551. $sale_money = $sale3[0]['total']+$sale3[0]['shipping_fare']-$sale3[0]['voucher_credit']-$sale3[0]['fullreduction_money'];
  552. $sale_list[$key] = array(
  553. 'community_name' => $sale1[0]['community_name'],
  554. 'head_name' => $sale1[0]['head_name'],
  555. 'count' => $sale2[0]['count'],
  556. 'sale_money' => $sale_money,
  557. );
  558. }
  559. //数组重新排序
  560. $count = array_column($sale_list,'count');
  561. array_multisort($count,SORT_DESC,$sale_list);
  562. $this->sale_list = $sale_list;
  563. //7日内商品销量top10
  564. $sevenday_info = M()->query("select goods_id as goods_id,name as name,quantity as quantity from ".C('DB_PREFIX')."lionfish_comshop_order_goods where addtime > ".$sevenday['egt']." and addtime < ".$sevenday['lt']." and ".$condition." order by quantity desc ");
  565. //所有商品id
  566. $info = array();
  567. foreach($sevenday_info as $key =>$v) {
  568. $info[$key] = array(
  569. 'goods_id' => $v['goods_id'],
  570. //'quantity' => $v['quantity'],
  571. );
  572. }
  573. //合并数据,唯一商品id
  574. $info = array_unique($info, SORT_REGULAR);
  575. //唯一商品id获取对应信息
  576. $goods_statistic = array();
  577. foreach($info as $key =>$v) {
  578. $info2 = M()->query("select sum(quantity) as quantity ,name as name from ".C('DB_PREFIX')."lionfish_comshop_order_goods where( goods_id = ".$v['goods_id'].") and addtime > ".$sevenday['egt']." and addtime < ".$sevenday['lt']." and ".$condition);
  579. $goods_statistic[$key]=array(
  580. 'goods_id' => $v['goods_id'],
  581. 'name' => $info2[0]['name'],
  582. 'quantity' => $info2[0]['quantity'],
  583. );
  584. }
  585. //序号
  586. $gid = 0;
  587. //数组重新排序
  588. $quantity = array_column($goods_statistic,'quantity');
  589. array_multisort($quantity,SORT_DESC,$goods_statistic);
  590. $this->day_info = $day_info;
  591. $this->day_info2 = $day_info2;
  592. $this->sum_money = $sum_money;
  593. $this->sum_order = $sum_order;
  594. $this->sum_member = $sum_member;
  595. $this->list1 = $list1;
  596. $this->sum_goods = $sum_goods;
  597. $this->ave_money = $ave_money;
  598. $this->add_member = $add_member;
  599. $this->member_num = $member_num;
  600. $this->add_supplier = $add_supplier;
  601. $this->add_head = $add_head;
  602. $this->add_goods = $add_goods;
  603. $this->todaytime = $todaytime;
  604. $this->today_sales = $today_sales;
  605. $this->yestertime = $yestertime;
  606. $this->yesterday_sales = $yesterday_sales;
  607. $this->sevenday = $sevenday;
  608. $this->sevenday_sale = $sevenday_sale;
  609. $this->sale = $sale;
  610. $this->count = $count;
  611. $this->sevenday_info = $sevenday_info;
  612. $this->info = $info;
  613. $this->goods_statistic = $goods_statistic;
  614. $this->_GPC = $_GPC;
  615. include $this->display();
  616. }
  617. public function communitystatics()
  618. {
  619. $_GPC = I('request.');
  620. $starttime = strtotime( date('Y-m-d').' 00:00:00' );
  621. $endtime = $starttime + 86400;
  622. $searchtime = $_GPC['searchtime'];
  623. $keyword = $_GPC['keyword'];
  624. if( !empty($searchtime) )
  625. {
  626. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  627. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  628. }
  629. $this->starttime = $starttime;
  630. $this->endtime = $endtime;
  631. $this->searchtime = $searchtime;
  632. $this->keyword = $keyword;
  633. //0 3
  634. $type = isset($_GPC['type']) ? $_GPC['type'] : 0;
  635. $data = array();
  636. $data = $this->head_sale_analys($keyword,$searchtime , $starttime , $endtime );
  637. $this->type = $type;
  638. $this->data = $data;
  639. $this->_GPC = $_GPC;
  640. $this->display();
  641. }
  642. public function communitystatics_commiss()
  643. {
  644. $_GPC = I('request.');
  645. $starttime = strtotime( date('Y-m-d').' 00:00:00' );
  646. $endtime = $starttime + 86400;
  647. $searchtime = $_GPC['searchtime'];
  648. $keyword = $_GPC['keyword'];
  649. if( !empty($searchtime) )
  650. {
  651. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  652. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  653. }
  654. //0 3
  655. $type = isset($_GPC['type']) ? $_GPC['type'] : 0;
  656. $data = array();
  657. $data = $this->head_commiss_analys($keyword,$searchtime , $starttime , $endtime );
  658. $this->starttime = $starttime;
  659. $this->endtime = $endtime;
  660. $this->searchtime = $searchtime;
  661. $this->keyword = $keyword;
  662. $this->type = $type;
  663. $this->data = $data;
  664. $this->_GPC = $_GPC;
  665. include $this->display();
  666. }
  667. public function communitystatics_order()
  668. {
  669. $_GPC = I('request.');
  670. $starttime = strtotime( date('Y-m-d').' 00:00:00' );
  671. $endtime = $starttime + 86400;
  672. $searchtime = $_GPC['searchtime'];
  673. $keyword = $_GPC['keyword'];
  674. if( !empty($searchtime) )
  675. {
  676. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  677. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  678. }
  679. //0 3
  680. $type = isset($_GPC['type']) ? $_GPC['type'] : 0;
  681. $data = array();
  682. $data = $this->head_order_analys($keyword,$searchtime , $starttime , $endtime );
  683. $this->starttime = $starttime;
  684. $this->endtime = $endtime;
  685. $this->searchtime = $searchtime;
  686. $this->keyword = $keyword;
  687. $this->type = $type;
  688. $this->data = $data;
  689. $this->_GPC = $_GPC;
  690. include $this->display();
  691. }
  692. private function head_order_analys()
  693. {
  694. $_GPC = I('request.');
  695. $data = array();
  696. //1、寻找团长
  697. $where = " ";
  698. if( !empty($searchtime) )
  699. {
  700. $where .= " and date_added >= {$starttime} and date_added <= {$endtime} ";
  701. }
  702. $sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order where 1 {$where} group by head_id ";
  703. $order_ids_all = M()->query($sql);
  704. $head_ids_arr = array();
  705. if( !empty($order_ids_all) )
  706. {
  707. foreach( $order_ids_all as $val )
  708. {
  709. $head_ids_arr[] = $val['head_id'];
  710. }
  711. }
  712. $search_head_list = array();
  713. if( !empty($keyword) )
  714. {
  715. $sql = " SELECT ch.id FROM " . C('DB_PREFIX') . "lionfish_community_head as ch left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id
  716. WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  717. $community_head_list = M()->query( $sql );
  718. if( !empty($community_head_list) )
  719. {
  720. foreach( $community_head_list as $val )
  721. {
  722. $search_head_list[] = $val['id'];
  723. }
  724. }
  725. //交集
  726. $head_ids_arr = array_intersect($head_ids_arr, $search_head_list);
  727. }
  728. //----------------以上是搜索团长的代码
  729. //---------------团长等级begin-------------
  730. $level_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_commission_level where 1 ";
  731. $level_list = M()->query($level_sql);
  732. $level_arr = array(0 => '默认等级');
  733. foreach( $level_list as $vv )
  734. {
  735. $level_arr[ $v['id'] ] = $vv['levelname'];
  736. }
  737. //---------------团长等级end---------------
  738. if( empty($head_ids_arr) )
  739. {
  740. return $data;
  741. }else{
  742. foreach($head_ids_arr as $head_id)
  743. {
  744. $tmp = array();
  745. $head_info = M('lionfish_community_head')->where( array('id' => $head_id ) )->find();
  746. if( empty($head_info['member_id']) )
  747. {
  748. continue;
  749. }
  750. $mb_info = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $head_info['member_id'] ) )->find();
  751. $tmp['head_id'] = $head_id;
  752. $tmp['username'] = $mb_info['username'];
  753. $tmp['community_name'] = $head_info['community_name'];
  754. $tmp['head_name'] = $head_info['head_name'];
  755. $tmp['head_mobile'] = $head_info['head_mobile'];
  756. $tmp['head_levelname'] = $level_arr[ $head_info['level_id'] ];
  757. //总订单量 in(1,4,6,11,14) 退款: 7,
  758. $all_order_count = M('lionfish_comshop_order')->where( "head_id = {$head_id} {$where}" )->count();
  759. $tmp['all_order_count'] = $all_order_count;
  760. //有效订单量
  761. $effect_order_count = M('lionfish_comshop_order')->where( " head_id = {$head_id} and order_status_id in (1,4,6,11,14) {$where}" )->count();
  762. $tmp['effect_order_count'] = $effect_order_count;
  763. //已关闭订单量
  764. $close_order_count = M('lionfish_comshop_order')->where( " head_id = {$head_id} and order_status_id =5 {$where} " )->count();
  765. $tmp['close_order_count'] = $close_order_count;
  766. //订单总金额(元)
  767. $all_order_paymoney = M('lionfish_comshop_order')->where("head_id = {$head_id} {$where}")->sum("total+shipping_fare-voucher_credit-fullreduction_money");
  768. $tmp['all_order_paymoney'] = $all_order_paymoney;
  769. //有效订单金额(元)
  770. $effect_order_paymoney = M('lionfish_comshop_order')->where("head_id = {$head_id} and order_status_id in(1,4,6,11,14) {$where}")->sum("total+shipping_fare-voucher_credit-fullreduction_money");
  771. $tmp['effect_order_paymoney'] = $effect_order_paymoney;
  772. //待付款量
  773. $pending_order_count = M('lionfish_comshop_order')->where( " head_id = {$head_id} and order_status_id =3 {$where} " )->count();
  774. $tmp['pending_order_count'] = $pending_order_count;
  775. //退款量
  776. $refund_order_count = M('lionfish_comshop_order')->where(" head_id = {$head_id} and order_status_id =7 {$where} ")->count();
  777. $tmp['refund_order_count'] = $refund_order_count;
  778. //退款总金额(元)
  779. $refund_order_paymoney = M('lionfish_comshop_order')->where(" head_id = {$head_id} and order_status_id =7 {$where} ")->sum("total+shipping_fare-voucher_credit-fullreduction_money");
  780. $tmp['refund_order_paymoney'] = $refund_order_paymoney;
  781. $data[] = $tmp;
  782. }
  783. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  784. {
  785. $columns = array(
  786. array('title' => 'ID', 'field' => 'head_id', 'width' => 32),
  787. array('title' => '团长昵称', 'field' => 'username', 'width' => 32),
  788. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 32),
  789. array('title' => '团长手机号', 'field' => 'head_mobile', 'width' => 32),
  790. array('title' => '小区信息', 'field' => 'community_name', 'width' => 32),
  791. array('title' => '总订单量', 'field' => 'all_order_count', 'width' => 32),
  792. array('title' => '有效订单量', 'field' => 'effect_order_count', 'width' => 32),
  793. array('title' => '已关闭订单量', 'field' => 'close_order_count', 'width' => 32),
  794. array('title' => '订单总金额(元)', 'field' => 'all_order_paymoney', 'width' => 32),
  795. array('title' => '有效订单金额(元)', 'field' => 'effect_order_paymoney', 'width' => 32),
  796. array('title' => '待付款量', 'field' => 'pending_order_count', 'width' => 32),
  797. array('title' => '退款量', 'field' => 'refund_order_count', 'width' => 32),
  798. array('title' => '退款总金额(元)', 'field' => 'refund_order_paymoney', 'width' => 32),
  799. );
  800. $title = '团长销售额统计';
  801. D('Seller/Excel')->export($data, array('title' => $title, 'columns' => $columns));
  802. }
  803. }
  804. return $data;
  805. }
  806. private function head_commiss_analys( $keyword,$searchtime , $starttime , $endtime )
  807. {
  808. $_GPC = I('request.');
  809. $data = array();
  810. //1、寻找团长
  811. $where = " 1 ";
  812. $tj_where = " ";
  813. if( !empty($searchtime) )
  814. {
  815. $where .= " and date_added >= {$starttime} and date_added <= {$endtime} ";
  816. $tj_where .= " and addtime >= {$starttime} and addtime <= {$endtime} ";
  817. }
  818. $sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order where {$where} group by head_id ";
  819. $order_ids_all = M()->query($sql);
  820. $head_ids_arr = array();
  821. if( !empty($order_ids_all) )
  822. {
  823. foreach( $order_ids_all as $val )
  824. {
  825. $head_ids_arr[] = $val['head_id'];
  826. }
  827. }
  828. $search_head_list = array();
  829. if( !empty($keyword) )
  830. {
  831. $sql = " SELECT ch.id FROM " . C('DB_PREFIX'). "lionfish_community_head as ch left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id
  832. WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  833. $community_head_list = M()->query( $sql );
  834. //var_dump($community_head_list,$sql);die();
  835. if( !empty($community_head_list) )
  836. {
  837. foreach( $community_head_list as $val )
  838. {
  839. $search_head_list[] = $val['id'];
  840. }
  841. }
  842. //交集
  843. $head_ids_arr = array_intersect($head_ids_arr, $search_head_list);
  844. }
  845. //----------------以上是搜索团长的代码
  846. //---------------团长等级begin-------------
  847. $level_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_commission_level ";
  848. $level_list = M()->query($level_sql);
  849. $level_arr = array(0 => '默认等级');
  850. foreach( $level_list as $vv )
  851. {
  852. $level_arr[ $v['id'] ] = $vv['levelname'];
  853. }
  854. //---------------团长等级end---------------
  855. if( empty($head_ids_arr) )
  856. {
  857. return $data;
  858. }else{
  859. foreach($head_ids_arr as $head_id)
  860. {
  861. $tmp = array();
  862. $head_info = M('lionfish_community_head')->where( array('id' => $head_id ) )->find();
  863. if( empty($head_info['member_id']) )
  864. {
  865. continue;
  866. }
  867. //ims_lionfish_comshop_member
  868. $mb_info = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $head_info['member_id'] ) )->find();
  869. $tmp['head_id'] = $head_id;
  870. $tmp['username'] = $mb_info['username'];
  871. $tmp['community_name'] = $head_info['community_name'];
  872. $tmp['head_name'] = $head_info['head_name'];
  873. $tmp['head_mobile'] = $head_info['head_mobile'];
  874. $tmp['head_levelname'] = $level_arr[ $head_info['level_id'] ];
  875. $head_commiss = M('lionfish_community_head_commiss')->where( array('head_id' =>$head_id ) )->find();
  876. //下单佣金(元) orderbuy (1,2)
  877. $sum_order_commiss = M('lionfish_community_head_commiss_order')->where("head_id = {$head_id} and state in (1,2) and type = 'orderbuy' {$tj_where}")->sum('money');
  878. $tmp['sum_order_commiss'] = $sum_order_commiss;
  879. //退款佣金(元) orderbuy(2)
  880. $sum_order_refundcommiss = M('lionfish_community_head_commiss_order')->where(" head_id = {$head_id} and state = 2 and type = 'orderbuy' {$tj_where} ")->sum('money');
  881. $tmp['sum_order_refundcommiss'] = $sum_order_refundcommiss;
  882. //下级下单佣金(元) commiss tuijian (1,2)
  883. $childsum_order_commiss = M('lionfish_community_head_commiss_order')->where(" head_id = {$head_id} and state in (1,2) and type in('commiss', 'tuijian') {$tj_where} ")->sum('money');
  884. $tmp['childsum_order_commiss'] = $childsum_order_commiss;
  885. //下级退款佣金(元) commiss tuijian (2)
  886. $childsum_order_refundcommiss = M('lionfish_community_head_commiss_order')->where("head_id = {$head_id} and state = 2 and type in('commiss', 'tuijian') {$tj_where}")->sum('money');
  887. $tmp['childsum_order_refundcommiss'] = $childsum_order_refundcommiss;
  888. //净佣金(元)
  889. $real_commiss_money = $sum_order_commiss + $childsum_order_commiss - $sum_order_refundcommiss - $childsum_order_refundcommiss;
  890. $tmp['real_commiss_money'] = $real_commiss_money;
  891. //申请提现佣金(元)
  892. $tmp['dongmoney'] = $head_commiss['dongmoney'];
  893. //提现到帐佣金(元)
  894. $tmp['getmoney'] = $head_commiss['getmoney'];
  895. $data[] = $tmp;
  896. }
  897. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  898. {
  899. $columns = array(
  900. array('title' => 'ID', 'field' => 'head_id', 'width' => 32),
  901. array('title' => '团长昵称', 'field' => 'username', 'width' => 32),
  902. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 32),
  903. array('title' => '团长手机号', 'field' => 'head_mobile', 'width' => 32),
  904. array('title' => '小区信息', 'field' => 'community_name', 'width' => 32),
  905. array('title' => '团长等级', 'field' => 'head_levelname', 'width' => 32),
  906. array('title' => '下单佣金(元)', 'field' => 'sum_order_commiss', 'width' => 32),
  907. array('title' => '退款佣金(元)', 'field' => 'sum_order_refundcommiss', 'width' => 32),
  908. array('title' => '下级下单佣金(元)', 'field' => 'childsum_order_commiss', 'width' => 32),
  909. array('title' => '下级退款佣金(元)', 'field' => 'childsum_order_refundcommiss', 'width' => 32),
  910. array('title' => '净佣金(元)', 'field' => 'real_commiss_money', 'width' => 32),
  911. array('title' => '申请提现佣金(元)', 'field' => 'dongmoney', 'width' => 32),
  912. array('title' => '提现到帐佣金(元)', 'field' => 'getmoney', 'width' => 32),
  913. );
  914. $title = '团长佣金金额统计';
  915. D('Seller/Excel')->export($data, array('title' => $title, 'columns' => $columns));
  916. }
  917. return $data;
  918. }
  919. }
  920. //团长销售额统计
  921. private function head_sale_analys( $keyword,$searchtime , $starttime , $endtime )
  922. {
  923. $_GPC = I('request.');
  924. $data = array();
  925. //1、寻找团长
  926. $where = " ";
  927. $refund_where = " ";
  928. if( !empty($searchtime) )
  929. {
  930. $where .= " and date_added >= {$starttime} and date_added <= {$endtime} ";
  931. $refund_where .= " and addtime >= {$starttime} and addtime <= {$endtime} ";
  932. }
  933. $sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order where 1 {$where} group by head_id ";
  934. $order_ids_all = M()->query($sql);
  935. $head_ids_arr = array();
  936. if( !empty($order_ids_all) )
  937. {
  938. foreach( $order_ids_all as $val )
  939. {
  940. $head_ids_arr[] = $val['head_id'];
  941. }
  942. }
  943. $search_head_list = array();
  944. if( !empty($keyword) )
  945. {
  946. $sql = " SELECT ch.id FROM " . C('DB_PREFIX'). "lionfish_community_head as ch left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id
  947. WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  948. $community_head_list = M()->query( $sql );
  949. if( !empty($community_head_list) )
  950. {
  951. foreach( $community_head_list as $val )
  952. {
  953. $search_head_list[] = $val['id'];
  954. }
  955. }
  956. //交集
  957. $head_ids_arr = array_intersect($head_ids_arr, $search_head_list);
  958. }
  959. //----------------以上是搜索团长的代码
  960. //---------------团长等级begin-------------
  961. $level_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_commission_level ";
  962. $level_list = M()->query($level_sql );
  963. $level_arr = array(0 => '默认等级');
  964. foreach( $level_list as $vv )
  965. {
  966. $level_arr[ $v['id'] ] = $vv['levelname'];
  967. }
  968. //---------------团长等级end---------------
  969. if( empty($head_ids_arr) )
  970. {
  971. return $data;
  972. }else{
  973. foreach($head_ids_arr as $head_id)
  974. {
  975. $tmp = array();
  976. $head_info = M('lionfish_community_head')->where( array('id' => $head_id ) )->find();
  977. if( empty($head_info['member_id']) )
  978. {
  979. continue;
  980. }
  981. $mb_info = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $head_info['member_id'] ) )->find();
  982. $tmp['head_id'] = $head_id;
  983. $tmp['username'] = $mb_info['username'];
  984. $tmp['community_name'] = $head_info['community_name'];
  985. $tmp['head_name'] = $head_info['head_name'];
  986. $tmp['head_mobile'] = $head_info['head_mobile'];
  987. $tmp['head_levelname'] = $level_arr[ $head_info['level_id'] ];
  988. //下单会员数(支付的+退款的)
  989. $buy_mb_count_arr = M()->query("SELECT count( DISTINCT(member_id) ) as count FROM ".C('DB_PREFIX').
  990. "lionfish_comshop_order WHERE 1 and head_id = {$head_id} and order_status_id in(1,4,6,7,11,14) {$where} ");
  991. $buy_mb_count = $buy_mb_count_arr[0]['count'];
  992. $tmp['buy_mb_count'] = $buy_mb_count;
  993. //下单数量(支付的+退款的)
  994. $buy_order_count = M('lionfish_comshop_order')->where(" head_id = {$head_id} and order_status_id in(1,4,6,7,11,14) {$where} ")->count();
  995. $tmp['buy_order_count'] = $buy_order_count;
  996. //销售额(支付的+退款的)
  997. $sum_order_paymoney = M('lionfish_comshop_order')->where("head_id = {$head_id} and order_status_id in(1,4,6,7,11,14) {$where}")->sum('total+shipping_fare-voucher_credit-fullreduction_money');
  998. $tmp['sum_order_paymoney'] = $sum_order_paymoney;
  999. //退款量(退款成功的)
  1000. $refund_order_count_arr = M()->query("SELECT count( DISTINCT(ref_id) ) as count FROM ".C('DB_PREFIX').
  1001. "lionfish_comshop_order_refund WHERE head_id = {$head_id} and state = 3 {$refund_where} ");
  1002. $refund_order_count = $refund_order_count_arr[0]['count'];
  1003. $tmp['refund_order_count'] = $refund_order_count;
  1004. //退款额(元)
  1005. $refund_order_money = M('lionfish_comshop_order_refund')->where("head_id = {$head_id} and state = 3 {$refund_where}")->sum('ref_money');
  1006. $tmp['refund_order_money'] = $refund_order_money;
  1007. //净销售额(元) 销售额 - 退款额 = 净销售额
  1008. $real_sale_money = round($sum_order_paymoney - $refund_order_money,2);
  1009. $tmp['real_sale_money'] = $real_sale_money;
  1010. $data[] = $tmp;
  1011. }
  1012. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  1013. {
  1014. $columns = array(
  1015. array('title' => 'ID', 'field' => 'head_id', 'width' => 32),
  1016. array('title' => '团长昵称', 'field' => 'username', 'width' => 32),
  1017. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 32),
  1018. array('title' => '团长手机号', 'field' => 'head_mobile', 'width' => 32),
  1019. array('title' => '小区信息', 'field' => 'community_name', 'width' => 32),
  1020. array('title' => '团长等级', 'field' => 'head_levelname', 'width' => 32),
  1021. array('title' => '下单会员数', 'field' => 'buy_mb_count', 'width' => 32),
  1022. array('title' => '下单数量', 'field' => 'buy_order_count', 'width' => 32),
  1023. array('title' => '销售额(元)', 'field' => 'sum_order_paymoney', 'width' => 32),
  1024. array('title' => '退款量', 'field' => 'refund_order_count', 'width' => 32),
  1025. array('title' => '退款额(元)', 'field' => 'refund_order_money', 'width' => 32),
  1026. array('title' => '净销售额(元)', 'field' => 'real_sale_money', 'width' => 32),
  1027. );
  1028. $title = '团长销售额统计';
  1029. D('Seller/Excel')->export($data, array('title' => $title, 'columns' => $columns));
  1030. }
  1031. }
  1032. return $data;
  1033. }
  1034. //找出这段时间团长的方法
  1035. private function head_sale_analys_back( $keyword,$searchtime , $starttime , $endtime )
  1036. {
  1037. $_GPC = I('request.');
  1038. $data = array();
  1039. //1、寻找团长
  1040. $where = " ";
  1041. if( !empty($searchtime) )
  1042. {
  1043. $where .= " and date_added >= {$starttime} and date_added <= {$endtime} ";
  1044. }
  1045. $sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order where 1 {$where} group by head_id ";
  1046. $order_ids_all = M()->query($sql );
  1047. $head_ids_arr = array();
  1048. if( !empty($order_ids_all) )
  1049. {
  1050. foreach( $order_ids_all as $val )
  1051. {
  1052. $head_ids_arr[] = $val['head_id'];
  1053. }
  1054. }
  1055. $search_head_list = array();
  1056. if( !empty($keyword) )
  1057. {
  1058. $sql = "select id from ".C('DB_PREFIX').
  1059. "lionfish_community_head where (head_name like '%{$keyword}%' or community_name like '%{$keyword}%' ) ";
  1060. $community_head_list = M()->query( $sql );
  1061. if( !empty($community_head_list) )
  1062. {
  1063. foreach( $community_head_list as $val )
  1064. {
  1065. $search_head_list[] = $val['id'];
  1066. }
  1067. }
  1068. //交集
  1069. $head_ids_arr = array_intersect($head_ids_arr, $search_head_list);
  1070. }
  1071. //----------------以上是搜索团长的代码
  1072. //---------------团长等级begin-------------
  1073. $level_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_commission_level ";
  1074. $level_list = M()->query($level_sql);
  1075. $level_arr = array(0 => '默认等级');
  1076. foreach( $level_list as $vv )
  1077. {
  1078. $level_arr[ $v['id'] ] = $vv['levelname'];
  1079. }
  1080. //---------------团长等级end---------------
  1081. if( empty($head_ids_arr) )
  1082. {
  1083. return $data;
  1084. }else{
  1085. foreach($head_ids_arr as $head_id)
  1086. {
  1087. $tmp = array();
  1088. $head_info = M('lionfish_community_head')->where( array('id' => $head_id ) )->find();
  1089. $tmp['community_name'] = $head_info['community_name'];
  1090. $tmp['head_name'] = $head_info['head_name'];
  1091. $tmp['head_mobile'] = $head_info['head_mobile'];
  1092. $tmp['head_levelname'] = $level_arr[ $head_info['level_id'] ];
  1093. //下单会员数
  1094. //下单数量
  1095. //销售额
  1096. //level_id
  1097. $data[] = $tmp;
  1098. }
  1099. }
  1100. return $data;
  1101. }
  1102. }
  1103. ?>