ReportsController.class.php 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class ReportsController extends CommonController{
  11. protected function _initialize(){
  12. parent::_initialize();
  13. }
  14. public function index()
  15. {
  16. $_GPC = I('request.');
  17. $condition = " and type != 'integral' ";
  18. $cur_controller = 'reports/index';
  19. //今天开始时间
  20. $today = array();
  21. $today['egt'] = strtotime(date('Y-m-d 00:00:00'));
  22. $today['lt'] = strtotime(date('Y-m-d 23:59:59'));
  23. //本周时间
  24. $arr=array();
  25. $thisweek = array();
  26. $arr=getdate();
  27. $num=$arr['wday'];
  28. if(empty($num)){
  29. $num =7;
  30. }
  31. $thisweek['egt'] = $today['egt']-($num-1)*24*60*60;
  32. //$thisweek['lt'] = $today['lt']+(7-$num)*24*60*60;
  33. $thisweek['lt'] = strtotime(date('Y-m-d H:i:s'));
  34. if (empty($_GPC['reports_index']) || $_GPC['reports_index']=='0'){
  35. //每天所有订单
  36. $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 , sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare 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");
  37. for($i=0;$i<$num;$i++){
  38. $day_start = date("Y-m-d" , $today['egt']-($num-1-$i)*24*60*60);
  39. $isin = $this->deep_in_array($day_start,$day_info);
  40. if($isin){
  41. }else{
  42. $day_info[] =array(
  43. 'date' => $day_start,
  44. 'count' => 0,
  45. 'total' => 0,
  46. 'shipping_fare' => 0,
  47. 'voucher_credit' => 0,
  48. 'fullreduction_money' => 0,
  49. 'score_for_money' => 0,
  50. 'fare_shipping_free' => 0,
  51. 'packing_fare' => 0,
  52. );
  53. }
  54. }
  55. foreach($day_info as $val){
  56. $key_arrays[]=$val['date'];
  57. }
  58. array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$day_info);
  59. //总单数和下单金额
  60. $zongdanshu = 0;
  61. $zongxiadan = 0;
  62. foreach($day_info as $val1) {
  63. $zongdanshu += $val1['count'];
  64. $zongxiadan += $val1['total']+$val1['shipping_fare']+$val1['packing_fare']-$val1['voucher_credit']-$val1['fullreduction_money'] - $val1['score_for_money'] - $val1['fare_shipping_free'];
  65. }
  66. //有订单的所有日期
  67. //$day_info2 = M()->query("select from_unixtime( pay_time, '%Y-%m-%d' ) as date from ".C('DB_PREFIX')."lionfish_comshop_order where pay_time > ".$thisweek['egt']." and pay_time < ".$thisweek['lt']." ".$condition." group by date order by date asc");
  68. for($i=0;$i<=$num;$i++){
  69. $day_info2[$i] = array(
  70. "date" => date("Y-m-d" , $today['egt']-($num-1-$i)*24*60*60 ),
  71. );
  72. }
  73. foreach($day_info2 as $key =>$day) {
  74. $day["egt"]=strtotime(date($day["date"],time()));
  75. $day["lt"]=$day["egt"]+(60*60*24)-1;
  76. //每天退款单数
  77. $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))");
  78. if($day_info3){
  79. $daytui = 0;
  80. $daytuikuan =0;
  81. }
  82. //每天取消单数
  83. $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 , sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare from ".C('DB_PREFIX')."lionfish_comshop_order
  84. where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id = 5)");
  85. if($day_info4){
  86. $dayqu = 0;
  87. $dayquxiao =0;
  88. }
  89. //取消单数
  90. $dayqu = $day_info4[0]['count'];
  91. //取消金额
  92. $dayquxiao = $day_info4[0]['total']+$day_info4[0]['shipping_fare']+$day_info4[0]['packing_fare']-$day_info4[0]['voucher_credit']-$day_info4[0]['fullreduction_money']-$day_info4[0]['score_for_money']-$day_info4[0]['fare_shipping_free'];
  93. //退款中 金额
  94. $daywait_refund_money_arr = M()->query("select sum(ref_money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_refund
  95. where state =0 and addtime >= ".$day['egt']." and addtime < ".$day['lt']." ");
  96. $daywait_refund_money = $daywait_refund_money_arr[0]['total_money'];
  97. //退款中 订单数量
  98. $daywait_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_refund where state =0 and addtime >= ".$day['egt']."
  99. and addtime < ".$day['lt']." ");
  100. $daywait_refund_count = count($daywait_refund_arr);
  101. //已退款 金额
  102. $dayhas_refund_money_arr = M()->query("select sum(money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime >= ".$day['egt']."
  103. and addtime < ".$day['lt']." ");
  104. $dayhas_refund_money = $dayhas_refund_money_arr[0]['total_money'];
  105. //已退款 订单数量
  106. $dayhas_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime >= ".$day['egt']."
  107. and addtime < ".$day['lt']." group by order_id ");
  108. $dayhas_refund_count = count($dayhas_refund_arr);
  109. $daylist[$key] = array(
  110. 'daywait_refund_money' => $daywait_refund_money,
  111. 'daywait_refund_count' => $daywait_refund_count,
  112. 'dayhas_refund_money' => $dayhas_refund_money,
  113. 'dayhas_refund_count' => $dayhas_refund_count,
  114. 'dayqu' => $dayqu,
  115. 'dayquxiao' => $dayquxiao,
  116. );
  117. }
  118. $list = array();
  119. $list['day_info'] = $day_info;
  120. //合并两个数组
  121. $list2 = array();
  122. foreach($list['day_info'] as $k=>$v){
  123. $list2[] = array_merge($v,$daylist[$k]);
  124. }
  125. //退款中 金额
  126. $wait_refund_money_arr = M()->query("select sum(ref_money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_refund
  127. where state =0 and addtime > ".$thisweek['egt']." and addtime < ".$thisweek['lt']." ");
  128. $wait_refund_money = $wait_refund_money_arr[0]['total_money'];
  129. //退款中 订单数量
  130. $wait_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_refund where state =0 and addtime > ".$thisweek['egt']."
  131. and addtime < ".$thisweek['lt']." ");
  132. $wait_refund_count = count($wait_refund_arr);
  133. //已退款 金额
  134. $has_refund_money_arr = M()->query("select sum(money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime > ".$thisweek['egt']."
  135. and addtime < ".$thisweek['lt']." ");
  136. $has_refund_money = $has_refund_money_arr[0]['total_money'];
  137. //已退款 订单数量
  138. $has_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime > ".$thisweek['egt']."
  139. and addtime < ".$thisweek['lt']." group by order_id ");
  140. $has_refund_count = count($has_refund_arr);
  141. $this->wait_refund_money = $wait_refund_money;
  142. $this->wait_refund_count = $wait_refund_count;
  143. $this->has_refund_money = $has_refund_money;
  144. $this->has_refund_count = $has_refund_count;
  145. //小计
  146. /*$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 pay_time > ".$thisweek['egt']." and pay_time < ".$thisweek['lt']." ".$condition." and (order_status_id in (1,2,3,4,6,11,14)) group by date order by date asc" );
  147. $xaiojishu =0;
  148. $xaioji =0;
  149. foreach($subtotal_info as $val3) {
  150. $xaiojishu += $val3['count'];
  151. $xaioji += $val3['total']+$val3['shipping_fare']-$val3['voucher_credit']-$val3['fullreduction_money']- $val3['score_for_money'];
  152. }*/
  153. //取消订单
  154. $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 , sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare 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");
  155. $quxiaoshu =0;
  156. $quxiao =0;
  157. foreach($quxiao_info as $val4) {
  158. $quxiaoshu += $val4['count'];
  159. $quxiao += $val4['total']+$val4['shipping_fare']+$val4['packing_fare']-$val4['voucher_credit']-$val4['fullreduction_money']- $val4['score_for_money']- $val4['fare_shipping_free'];
  160. }
  161. //小计 = 下单金额-取消金额
  162. $xaiojishu = $zongdanshu - $quxiaoshu;
  163. $xaioji = $zongxiadan - $quxiao;
  164. $tabid = 0;
  165. }
  166. //上周时间
  167. if($_GPC['reports_index'] == 1){
  168. $lastweek['egt'] = $thisweek['egt']-7*24*60*60;
  169. $lastweek['lt'] = $thisweek['egt']-1;
  170. //每天所有订单
  171. $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 , sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare 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");
  172. for($i=0;$i<7;$i++){
  173. $day_start = date("Y-m-d" , $thisweek['egt']-(7-$i)*24*60*60);
  174. $isin = $this->deep_in_array($day_start,$day_info);
  175. if($isin){
  176. }else{
  177. $day_info[] =array(
  178. 'date' => $day_start,
  179. 'count' => 0,
  180. 'total' => 0,
  181. 'shipping_fare' => 0,
  182. 'voucher_credit' => 0,
  183. 'fullreduction_money' => 0,
  184. 'score_for_money' => 0,
  185. 'fare_shipping_free' => 0,
  186. 'packing_fare' => 0,
  187. );
  188. }
  189. }
  190. foreach($day_info as $val){
  191. $key_arrays[]=$val['date'];
  192. }
  193. array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$day_info);
  194. //总单数和下单金额
  195. $zongdanshu = 0;
  196. $zongxiadan = 0;
  197. foreach($day_info as $val1) {
  198. $zongdanshu += $val1['count'];
  199. $zongxiadan += $val1['total']+$val1['shipping_fare']+$val1['packing_fare']-$val1['voucher_credit']-$val1['fullreduction_money'] - $val1['score_for_money']- $val1['fare_shipping_free'];
  200. }
  201. //有订单的所有日期
  202. //$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" );
  203. // date("Y-m-d H:i",$todaytime)
  204. for($i=0;$i<7;$i++){
  205. $day_info2[$i] = array(
  206. "date" => date("Y-m-d" , $thisweek['egt']-(7-$i)*24*60*60 ),
  207. );
  208. }
  209. foreach($day_info2 as $key =>$day) {
  210. $day["egt"]=strtotime(date($day["date"],time()));
  211. $day["lt"]=$day["egt"]+(60*60*24)-1;
  212. //每天退款单数
  213. $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))" );
  214. if($day_info3){
  215. $daytui = 0;
  216. $daytuikuan =0;
  217. }
  218. //每天取消单数
  219. $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 , sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id = 5)" );
  220. if($day_info4){
  221. $dayqu = 0;
  222. $dayquxiao =0;
  223. }
  224. //取消单数
  225. $dayqu = $day_info4[0]['count'];
  226. //取消金额
  227. $dayquxiao = $day_info4[0]['total']+$day_info4[0]['shipping_fare']+$day_info4[0]['packing_fare']-$day_info4[0]['voucher_credit']-$day_info4[0]['fullreduction_money']-$day_info4[0]['score_for_money']-$day_info4[0]['fare_shipping_free'];
  228. //退款中 金额
  229. $daywait_refund_money_arr = M()->query("select sum(ref_money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_refund
  230. where state =0 and addtime >= ".$day['egt']." and addtime < ".$day['lt']." ");
  231. $daywait_refund_money = $daywait_refund_money_arr[0]['total_money'];
  232. //退款中 订单数量
  233. $daywait_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_refund where state =0 and addtime >= ".$day['egt']."
  234. and addtime < ".$day['lt']." ");
  235. $daywait_refund_count = count($daywait_refund_arr);
  236. //已退款 金额
  237. $dayhas_refund_money_arr = M()->query("select sum(money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime >= ".$day['egt']."
  238. and addtime < ".$day['lt']." ");
  239. $dayhas_refund_money = $dayhas_refund_money_arr[0]['total_money'];
  240. //已退款 订单数量
  241. $dayhas_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime >= ".$day['egt']."
  242. and addtime < ".$day['lt']." group by order_id ");
  243. $dayhas_refund_count = count($dayhas_refund_arr);
  244. $daylist[$key] = array(
  245. 'daywait_refund_money' => $daywait_refund_money,
  246. 'daywait_refund_count' => $daywait_refund_count,
  247. 'dayhas_refund_money' => $dayhas_refund_money,
  248. 'dayhas_refund_count' => $dayhas_refund_count,
  249. 'dayqu' => $dayqu,
  250. 'dayquxiao' => $dayquxiao,
  251. );
  252. }
  253. $list = array();
  254. $list['day_info'] = $day_info;
  255. //合并两个数组
  256. $list2 = array();
  257. foreach($list['day_info'] as $k=>$v){
  258. $list2[] = array_merge($v,$daylist[$k]);
  259. }
  260. //退款中 金额
  261. $wait_refund_money_arr = M()->query("select sum(ref_money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_refund
  262. where state =0 and addtime > ".$lastweek['egt']." and addtime < ".$lastweek['lt']." ");
  263. $wait_refund_money = $wait_refund_money_arr[0]['total_money'];
  264. //退款中 订单数量
  265. $wait_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_refund where state =0 and addtime > ".$lastweek['egt']."
  266. and addtime < ".$lastweek['lt']." ");
  267. $wait_refund_count = count($wait_refund_arr);
  268. //已退款 金额
  269. $has_refund_money_arr = M()->query("select sum(money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime > ".$lastweek['egt']."
  270. and addtime < ".$lastweek['lt']." ");
  271. $has_refund_money = $has_refund_money_arr[0]['total_money'];
  272. //已退款 订单数量
  273. $has_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime > ".$lastweek['egt']."
  274. and addtime < ".$lastweek['lt']." group by order_id ");
  275. $has_refund_count = count($has_refund_arr);
  276. $this->wait_refund_money = $wait_refund_money;
  277. $this->wait_refund_count = $wait_refund_count;
  278. $this->has_refund_money = $has_refund_money;
  279. $this->has_refund_count = $has_refund_count;
  280. //退款
  281. $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 , sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare from ".C('DB_PREFIX')."lionfish_comshop_order
  282. 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");
  283. $zongtuishu =0;
  284. $tuikuan =0;
  285. foreach($cancel_info as $val2) {
  286. $zongtuishu += $val2['count'];
  287. $tuikuan += $val2['total']+$val2['shipping_fare']+$val2['packing_fare']-$val2['voucher_credit']-$val2['fullreduction_money']-$val2['score_for_money']-$val2['fare_shipping_free'];
  288. }
  289. //小计
  290. /*$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");
  291. $xaiojishu =0;
  292. $xaioji =0;
  293. foreach($subtotal_info as $val3) {
  294. $xaiojishu += $val3['count'];
  295. $xaioji += $val3['total']+$val3['shipping_fare']-$val3['voucher_credit']-$val3['fullreduction_money']- $val3['score_for_money'];
  296. }*/
  297. //取消订单
  298. $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 , sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare 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");
  299. $quxiaoshu =0;
  300. $quxiao =0;
  301. foreach($quxiao_info as $val4) {
  302. $quxiaoshu += $val4['count'];
  303. $quxiao += $val4['total']+$val4['shipping_fare']+$val4['packing_fare']-$val4['voucher_credit']-$val4['fullreduction_money']- $val4['score_for_money']- $val4['fare_shipping_free'];
  304. }
  305. //小计 = 下单金额-取消金额
  306. $xaiojishu = $zongdanshu - $quxiaoshu;
  307. $xaioji = $zongxiadan - $quxiao;
  308. $tabid = 1;
  309. }
  310. //本月时间
  311. if($_GPC['reports_index'] == 2){
  312. $thismonth = array();
  313. $thismonth['egt']=strtotime(date('Y-m-01 00:00:00'));
  314. $thismonth['lt'] = strtotime(date('Y-m-d H:i:s'));
  315. //每天所有订单
  316. $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 , sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare 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");
  317. $j = date("d");
  318. for($i=0;$i<$j;$i++){
  319. $day_start = date("Y-m-d" , strtotime(date('Y-m-d 00:00:00'))-($j-$i-1)*24*60*60);
  320. $isin = $this->deep_in_array($day_start,$day_info);
  321. if($isin){
  322. }else{
  323. $day_info[] =array(
  324. 'date' => $day_start,
  325. 'count' => 0,
  326. 'total' => 0,
  327. 'shipping_fare' => 0,
  328. 'voucher_credit' => 0,
  329. 'fullreduction_money' => 0,
  330. 'score_for_money' => 0,
  331. 'fare_shipping_free' => 0,
  332. 'packing_fare' => 0,
  333. );
  334. }
  335. }
  336. foreach($day_info as $val){
  337. $key_arrays[]=$val['date'];
  338. }
  339. array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$day_info);
  340. //总单数和下单金额
  341. $zongdanshu = 0;
  342. $zongxiadan = 0;
  343. foreach($day_info as $val1) {
  344. $zongdanshu += $val1['count'];
  345. $zongxiadan += $val1['total']+$val1['shipping_fare']+$val1['packing_fare']-$val1['voucher_credit']-$val1['fullreduction_money'] - $val1['score_for_money']- $val1['fare_shipping_free'];
  346. }
  347. //有订单的所有日期
  348. //$day_info2 = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date from ".C('DB_PREFIX')."lionfish_comshop_order where pay_time > ".$thismonth['egt']." and pay_time < ".$thismonth['lt']." ".$condition." group by date order by date asc");
  349. for($i=0;$i<$j;$i++){
  350. $day_info2[$i] = array(
  351. "date" => date("Y-m-d" , strtotime(date('Y-m-d 00:00:00'))-($j-$i-1)*24*60*60),
  352. );
  353. }
  354. foreach($day_info2 as $key =>$day) {
  355. $day["egt"]=strtotime(date($day["date"],time()));
  356. $day["lt"]=$day["egt"]+(60*60*24)-1;
  357. //每天退款单数
  358. $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))");
  359. if($day_info3){
  360. $daytui = 0;
  361. $daytuikuan =0;
  362. }
  363. //每天取消单数
  364. $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, sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id = 5)");
  365. if($day_info4){
  366. $dayqu = 0;
  367. $dayquxiao =0;
  368. }
  369. //取消单数
  370. $dayqu = $day_info4[0]['count'];
  371. //取消金额
  372. $dayquxiao = $day_info4[0]['total']+$day_info4[0]['shipping_fare']+$day_info4[0]['packing_fare']-$day_info4[0]['voucher_credit']-$day_info4[0]['fullreduction_money']-$day_info4[0]['score_for_money']-$day_info4[0]['fare_shipping_free'];
  373. //退款中 金额
  374. $daywait_refund_money_arr = M()->query("select sum(ref_money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_refund
  375. where state =0 and addtime >= ".$day['egt']." and addtime < ".$day['lt']." ");
  376. $daywait_refund_money = $daywait_refund_money_arr[0]['total_money'];
  377. //退款中 订单数量
  378. $daywait_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_refund where state =0 and addtime >= ".$day['egt']."
  379. and addtime < ".$day['lt']." ");
  380. $daywait_refund_count = count($daywait_refund_arr);
  381. //已退款 金额
  382. $dayhas_refund_money_arr = M()->query("select sum(money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime >= ".$day['egt']."
  383. and addtime < ".$day['lt']." ");
  384. $dayhas_refund_money = $dayhas_refund_money_arr[0]['total_money'];
  385. //已退款 订单数量
  386. $dayhas_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime >= ".$day['egt']."
  387. and addtime < ".$day['lt']." group by order_id ");
  388. $dayhas_refund_count = count($dayhas_refund_arr);
  389. $daylist[$key] = array(
  390. 'daywait_refund_money' => $daywait_refund_money,
  391. 'daywait_refund_count' => $daywait_refund_count,
  392. 'dayhas_refund_money' => $dayhas_refund_money,
  393. 'dayhas_refund_count' => $dayhas_refund_count,
  394. 'dayqu' => $dayqu,
  395. 'dayquxiao' => $dayquxiao,
  396. );
  397. }
  398. $list = array();
  399. $list['day_info'] = $day_info;
  400. //合并两个数组
  401. $list2 = array();
  402. foreach($list['day_info'] as $k=>$v){
  403. $list2[] = array_merge($v,$daylist[$k]);
  404. }
  405. //退款中 金额
  406. $wait_refund_money_arr = M()->query("select sum(ref_money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_refund
  407. where state =0 and addtime > ".$thismonth['egt']." and addtime < ".$thismonth['lt']." ");
  408. $wait_refund_money = $wait_refund_money_arr[0]['total_money'];
  409. //退款中 订单数量
  410. $wait_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_refund where state =0 and addtime > ".$thismonth['egt']."
  411. and addtime < ".$thismonth['lt']." ");
  412. $wait_refund_count = count($wait_refund_arr);
  413. //已退款 金额
  414. $has_refund_money_arr = M()->query("select sum(money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime > ".$thismonth['egt']."
  415. and addtime < ".$thismonth['lt']." ");
  416. $has_refund_money = $has_refund_money_arr[0]['total_money'];
  417. //已退款 订单数量
  418. $has_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime > ".$thismonth['egt']."
  419. and addtime < ".$thismonth['lt']." group by order_id ");
  420. $has_refund_count = count($has_refund_arr);
  421. $this->wait_refund_money = $wait_refund_money;
  422. $this->wait_refund_count = $wait_refund_count;
  423. $this->has_refund_money = $has_refund_money;
  424. $this->has_refund_count = $has_refund_count;
  425. //退款
  426. $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, sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare from
  427. ".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");
  428. $zongtuishu =0;
  429. $tuikuan =0;
  430. foreach($cancel_info as $val2) {
  431. $zongtuishu += $val2['count'];
  432. $tuikuan += $val2['total']+$val2['shipping_fare']+$val2['packing_fare']-$val2['voucher_credit']-$val2['fullreduction_money']-$val2['score_for_money']-$val2['fare_shipping_free'];
  433. }
  434. //小计
  435. /*$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");
  436. $xaiojishu =0;
  437. $xaioji =0;
  438. foreach($subtotal_info as $val3) {
  439. $xaiojishu += $val3['count'];
  440. $xaioji += $val3['total']+$val3['shipping_fare']-$val3['voucher_credit']-$val3['fullreduction_money']- $val3['score_for_money'];
  441. }*/
  442. //取消订单
  443. $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, sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare 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");
  444. $quxiaoshu =0;
  445. $quxiao =0;
  446. foreach($quxiao_info as $val4) {
  447. $quxiaoshu += $val4['count'];
  448. $quxiao += $val4['total']+$val4['shipping_fare']+$val4['packing_fare']-$val4['voucher_credit']-$val4['fullreduction_money']- $val4['score_for_money']- $val4['fare_shipping_free'];
  449. }
  450. //小计 = 下单金额-取消金额
  451. $xaiojishu = $zongdanshu - $quxiaoshu;
  452. $xaioji = $zongxiadan - $quxiao;
  453. $tabid = 2;
  454. }
  455. //上月时间
  456. if($_GPC['reports_index'] == 3){
  457. $lastmonth['lt'] = strtotime(date('Y-m-01 00:00:00')) - 1;
  458. $month=date('m') - 1;
  459. $year=date('Y');
  460. if($month==1 || $month==3 || $month==5|| $month==7 ||$month==8 || $month==10 ||$month==12 ){
  461. //31天
  462. $lastmonth['egt'] = strtotime(date('Y-m-01 00:00:00')) - 31*24*60*60;
  463. $j = 31;
  464. }elseif($month==4 || $month==6 ||$month==9 ||$month==11){
  465. //30天
  466. $lastmonth['egt'] = strtotime(date('Y-m-01 00:00:00')) - 30*24*60*60;
  467. $j = 30;
  468. }else{
  469. if($year%4 == 0){
  470. //29天
  471. $lastmonth['egt'] = strtotime(date('Y-m-01 00:00:00')) - 29*24*60*60;
  472. $j = 29;
  473. }else{
  474. //28天
  475. $lastmonth['egt'] = strtotime(date('Y-m-01 00:00:00')) - 28*24*60*60;
  476. $j = 28;
  477. }
  478. }
  479. //每天所有订单
  480. $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, sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare 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");
  481. for($i=0;$i<$j;$i++){
  482. $day_start = date("Y-m-d" , strtotime(date('Y-m-01 00:00:00')) - ($j-$i)*24*60*60 );
  483. $isin = $this->deep_in_array($day_start,$day_info);
  484. if($isin){
  485. }else{
  486. $day_info[] =array(
  487. 'date' => $day_start,
  488. 'count' => 0,
  489. 'total' => 0,
  490. 'shipping_fare' => 0,
  491. 'voucher_credit' => 0,
  492. 'fullreduction_money' => 0,
  493. 'score_for_money' => 0,
  494. 'fare_shipping_free' => 0,
  495. 'packing_fare' => 0,
  496. );
  497. }
  498. }
  499. foreach($day_info as $val){
  500. $key_arrays[]=$val['date'];
  501. }
  502. array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$day_info);
  503. //总单数和下单金额
  504. $zongdanshu = 0;
  505. $zongxiadan = 0;
  506. foreach($day_info as $val1) {
  507. $zongdanshu += $val1['count'];
  508. $zongxiadan += $val1['total']+$val1['shipping_fare']+$val1['packing_fare']-$val1['voucher_credit']-$val1['fullreduction_money'] - $val1['score_for_money']- $val1['fare_shipping_free'];
  509. }
  510. //有订单的所有日期
  511. $day_info2 = M()->query("select from_unixtime( date_added, '%Y-%m-%d' ) as date from ".C('DB_PREFIX')."lionfish_comshop_order where pay_time > ".$lastmonth['egt']." and pay_time < ".$lastmonth['lt']." ".$condition." group by date order by date asc");
  512. for($i=0;$i<$j;$i++){
  513. $day_info2[$i] = array(
  514. "date" => date("Y-m-d" , strtotime(date('Y-m-01 00:00:00')) - ($j-$i)*24*60*60 ),
  515. );
  516. }
  517. foreach($day_info2 as $key =>$day) {
  518. $day["egt"]=strtotime(date($day["date"],time()));
  519. $day["lt"]=$day["egt"]+(60*60*24)-1;
  520. //每天退款单数
  521. $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, sum(fare_shipping_free) as fare_shipping_free 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))");
  522. if($day_info3){
  523. $daytui = 0;
  524. $daytuikuan =0;
  525. }
  526. //退款单数
  527. $daytui = $day_info3[0]['count'];
  528. //退款金额
  529. $daytuikuan = $day_info3[0]['total']+$day_info3[0]['shipping_fare']-$day_info3[0]['voucher_credit']-$day_info3[0]['fullreduction_money']-$day_info3[0]['score_for_money']-$day_info3[0]['fare_shipping_free'];
  530. //每天取消单数
  531. $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, sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$day['egt']." and date_added < ".$day['lt']." ".$condition." and (order_status_id = 5)");
  532. if(empty($day_info4)){
  533. $dayqu = 0;
  534. $dayquxiao =0;
  535. }else{
  536. $dayqu = $day_info4[0]['count'];
  537. $dayquxiao =$day_info4[0]['total']+$day_info4[0]['shipping_fare']+$day_info4[0]['packing_fare']-$day_info4[0]['voucher_credit']-$day_info4[0]['fullreduction_money']-$day_info4[0]['score_for_money']-$day_info4[0]['fare_shipping_free'];
  538. }
  539. //退款中 金额
  540. $daywait_refund_money_arr = M()->query("select sum(ref_money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_refund
  541. where state =0 and addtime >= ".$day['egt']." and addtime < ".$day['lt']." ");
  542. $daywait_refund_money = $daywait_refund_money_arr[0]['total_money'];
  543. //退款中 订单数量
  544. $daywait_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_refund where state =0 and addtime >= ".$day['egt']."
  545. and addtime < ".$day['lt']." ");
  546. $daywait_refund_count = count($daywait_refund_arr);
  547. //已退款 金额
  548. $dayhas_refund_money_arr = M()->query("select sum(money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime >= ".$day['egt']."
  549. and addtime < ".$day['lt']." ");
  550. $dayhas_refund_money = $dayhas_refund_money_arr[0]['total_money'];
  551. //已退款 订单数量
  552. $dayhas_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime >= ".$day['egt']."
  553. and addtime < ".$day['lt']." group by order_id ");
  554. $dayhas_refund_count = count($dayhas_refund_arr);
  555. $daylist[$key] = array(
  556. 'daywait_refund_money' => $daywait_refund_money,
  557. 'daywait_refund_count' => $daywait_refund_count,
  558. 'dayhas_refund_money' => $dayhas_refund_money,
  559. 'dayhas_refund_count' => $dayhas_refund_count,
  560. 'dayqu' => $dayqu,
  561. 'dayquxiao' => $dayquxiao,
  562. );
  563. }
  564. $list = array();
  565. $list['day_info'] = $day_info;
  566. //合并两个数组
  567. $list2 = array();
  568. foreach($list['day_info'] as $k=>$v){
  569. $list2[] = array_merge($v,$daylist[$k]);
  570. }
  571. //退款中 金额
  572. $wait_refund_money_arr = M()->query("select sum(ref_money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_refund
  573. where state =0 and addtime > ".$lastmonth['egt']." and addtime < ".$lastmonth['lt']." ");
  574. $wait_refund_money = $wait_refund_money_arr[0]['total_money'];
  575. //退款中 订单数量
  576. $wait_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_refund where state =0 and addtime > ".$lastmonth['egt']."
  577. and addtime < ".$lastmonth['lt']." ");
  578. $wait_refund_count = count($wait_refund_arr);
  579. //已退款 金额
  580. $has_refund_money_arr = M()->query("select sum(money) as total_money from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime > ".$lastmonth['egt']."
  581. and addtime < ".$lastmonth['lt']." ");
  582. $has_refund_money = $has_refund_money_arr[0]['total_money'];
  583. //已退款 订单数量
  584. $has_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where addtime > ".$lastmonth['egt']."
  585. and addtime < ".$lastmonth['lt']." group by order_id ");
  586. $has_refund_count = count($has_refund_arr);
  587. $this->wait_refund_money = $wait_refund_money;
  588. $this->wait_refund_count = $wait_refund_count;
  589. $this->has_refund_money = $has_refund_money;
  590. $this->has_refund_count = $has_refund_count;
  591. //退款
  592. $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, sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare from ".C('DB_PREFIX')."lionfish_comshop_order
  593. 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");
  594. $zongtuishu =0;
  595. $tuikuan =0;
  596. foreach($cancel_info as $val2) {
  597. $zongtuishu += $val2['count'];
  598. $tuikuan += $val2['total']+$val2['shipping_fare']+$val2['packing_fare']-$val2['voucher_credit']-$val2['fullreduction_money']-$val2['score_for_money']-$val2['fare_shipping_free'];
  599. }
  600. /*//小计
  601. $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");
  602. $xaiojishu =0;
  603. $xaioji =0;
  604. foreach($subtotal_info as $val3) {
  605. $xaiojishu += $val3['count'];
  606. $xaioji += $val3['total']+$val3['shipping_fare']-$val3['voucher_credit']-$val3['fullreduction_money']- $val3['score_for_money'];
  607. }*/
  608. //取消订单
  609. $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, sum(fare_shipping_free) as fare_shipping_free, sum(packing_fare) as packing_fare 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");
  610. $quxiaoshu =0;
  611. $quxiao =0;
  612. foreach($quxiao_info as $val4) {
  613. $quxiaoshu += $val4['count'];
  614. $quxiao += $val4['total']+$val4['shipping_fare']+$val4['packing_fare']-$val4['voucher_credit']-$val4['fullreduction_money']- $val4['score_for_money']- $val4['fare_shipping_free'];
  615. }
  616. //小计 = 下单金额-取消金额
  617. $xaiojishu = $zongdanshu - $quxiaoshu;
  618. $xaioji = $zongxiadan - $quxiao;
  619. $tabid = 3;
  620. }
  621. if( isset($_GPC['is_export']) && $_GPC['is_export'] == 1 )
  622. {
  623. $columns = array(
  624. array('title' => '下单日期', 'field' => 'date', 'width' => 32),
  625. array('title' => '订单数', 'field' => 'count', 'width' => 32),
  626. array('title' => '下单金额', 'field' => 'order_amount', 'width' => 32),
  627. array('title' => '等待退款笔数', 'field' => 'daywait_refund_count', 'width' => 32),
  628. array('title' => '等待退款金额', 'field' => 'daywait_refund_money', 'width' => 32),
  629. array('title' => '已退款笔数', 'field' => 'dayhas_refund_count', 'width' => 32),
  630. array('title' => '已退款金额', 'field' => 'dayhas_refund_money', 'width' => 32),
  631. array('title' => '取消笔数', 'field' => 'dayqu', 'width' => 32),
  632. array('title' => '取消金额', 'field' => 'dayquxiao', 'width' => 32),
  633. array('title' => '小计', 'field' => 'order_ji', 'width' => 32),
  634. );
  635. $exportlist = array();
  636. foreach($list2 as $k => $w){
  637. $tmp_exval = array();
  638. $tmp_exval['date'] = $w['date'];
  639. $tmp_exval['count'] = $w["count"];
  640. $order_amount = $w['total']+$w['shipping_fare']-$w['voucher_credit']-$w['fullreduction_money']-$W['score_for_money']-$w['fare_shipping_free'];
  641. $order_amount = sprintf("%.2f",$order_amount);
  642. $tmp_exval['order_amount'] = $order_amount;
  643. $tmp_exval['daywait_refund_count'] = $w['daywait_refund_count'];
  644. $tmp_exval['daywait_refund_money'] = $w['daywait_refund_money'];
  645. $tmp_exval['dayhas_refund_count'] = $w['dayhas_refund_count'];
  646. $tmp_exval['dayhas_refund_money'] = $w['dayhas_refund_money'];
  647. $tmp_exval['dayqu'] = $w['dayqu'];
  648. $w["dayquxiao"] = sprintf("%.2f",$w["dayquxiao"]);
  649. $tmp_exval['dayquxiao'] = $w['dayquxiao'];
  650. $order_ji = $order_amount - $w["daytuikuan"]-$w["dayquxiao"];
  651. $order_ji = sprintf("%.2f",$order_ji);
  652. $tmp_exval['order_ji'] = $order_ji;
  653. $exportlist[] = $tmp_exval;
  654. }
  655. $title = '本周营业数据';
  656. if( isset($_GPC['reports_index']) && $_GPC['reports_index'] == 0)
  657. {
  658. $title = '本周营业数据';
  659. }else if( isset($_GPC['reports_index']) && $_GPC['reports_index'] == 1 ){
  660. $title = '上周营业数据';
  661. }else if( isset($_GPC['reports_index']) && $_GPC['reports_index'] == 2 ){
  662. $title = '本月营业数据';
  663. }else if( isset($_GPC['reports_index']) && $_GPC['reports_index'] == 3 ){
  664. $title = '上月营业数据';
  665. }
  666. D('Seller/Excel')->export($exportlist, array('title' => $title, 'columns' => $columns));
  667. }
  668. $this->lastmonth = $lastmonth;
  669. $this->zongdanshu = $zongdanshu;
  670. $this->zongxiadan = $zongxiadan;
  671. $this->day_info = $day_info;
  672. $this->day_info2 = $day_info2;
  673. $this->list = $list;
  674. $this->list2 = $list2;
  675. $this->zongtuishu = $zongtuishu;
  676. $this->tuikuan = $tuikuan;
  677. $this->cancel_info = $cancel_info;
  678. $this->subtotal_info = $subtotal_info;
  679. $this->xaiojishu = $xaiojishu;
  680. $this->xaioji = $xaioji;
  681. $this->quxiao_info = $quxiao_info;
  682. $this->quxiaoshu = $quxiaoshu;
  683. $this->quxiao = $quxiao;
  684. $this->tabid = $tabid;
  685. $this->_GPC = $_GPC;
  686. $this->display();
  687. }
  688. public function datastatics()
  689. {
  690. $_GPC = I('request.');
  691. $condition = ' 1 ';
  692. //$pindex = max(1, intval($_GPC['page']));
  693. //$psize = 10;
  694. //下单金额(元) sum_money
  695. //下单会员数 sum_member
  696. //下单量 sum_order
  697. //下单商品数 sum_goods
  698. //平均价格 ave_money
  699. //新增会员 add_member
  700. //会员数量 member_num
  701. //新增供货商 add_supplier
  702. //新增团长 add_head
  703. //新增商品 add_goods
  704. //今天开始时间
  705. $today = array();
  706. $today['egt'] = strtotime(date('Y-m-d 00:00:00'));
  707. $today['lt'] = strtotime(date('Y-m-d 23:59:59'));
  708. //今天所有订单
  709. $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 type != 'integral' and ".$condition );
  710. $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,packing_fare,fare_shipping_free from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$today['egt']." and date_added < ".$today['lt']." and type != 'integral' and ".$condition);
  711. $list = array();
  712. $sum_money = 0;
  713. foreach($day_info2 as $key =>$val1) {
  714. //下单金额(元)sum_money
  715. $sum_money += $val1['total']+$val1['shipping_fare']+$val1['packing_fare']-$val1['fare_shipping_free']-$val1['voucher_credit']-$val1['fullreduction_money'];
  716. $list[$key] = array(
  717. 'member_id' => $val1['member_id'],
  718. );
  719. }
  720. //下单量sum_order
  721. $sum_order = $day_info[0]['count'];
  722. //下单会员数sum_member
  723. $result = array_unique($list, SORT_REGULAR);
  724. $sum_member = sizeof($result,0);
  725. //下单商品数sum_goods
  726. $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);
  727. $list1 = array_unique($goods, SORT_REGULAR);
  728. $sum_goods = sizeof($list1,0);
  729. //平均价格 ave_money 下单金额/下单量
  730. if(empty($sum_order)){
  731. $ave_money = 0;
  732. }else{
  733. $ave_money =($sum_money)/($sum_order);
  734. $ave_money = sprintf("%.3f",$ave_money);
  735. }
  736. //新增会员add_member
  737. $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);
  738. $add_member = $add_member[0]['count'];
  739. //会员数量member_num
  740. $member_num = M()->query("select count( * ) as count from ".C('DB_PREFIX')."lionfish_comshop_member where ".$condition,
  741. array(':uniacid' => $_W['uniacid'] ));
  742. $member_num = $member_num[0]['count'];
  743. //新增供货商add_supplier
  744. $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 );
  745. $add_supplier = $add_supplier[0]['count'];
  746. //新增团长add_head
  747. $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 );
  748. $add_head = $add_head[0]['count'];
  749. //新增商品add_goods
  750. $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 );
  751. $add_goods = $add_goods[0]['count'];
  752. //今日销售走势
  753. $todaytime = array();
  754. $todaytime['egt'] = strtotime(date('Y-m-d 00:00:00'));
  755. $todaytime['lt'] = strtotime(date('Y-m-d 23:59:59'));
  756. $today_sales = array();
  757. //当前小时
  758. $h = date("H");
  759. for($i = 0;$i <= $h; $i++){
  760. $todaytime['egt'] = strtotime(date('Y-m-d 00:00:00'));
  761. $todaytime['egt'] = $todaytime['egt']+$i*60*60;
  762. $todaytime['lt'] = $todaytime['egt']+60*60-1;
  763. //有效销售额
  764. $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,sum(packing_fare) as packing_fare,sum(fare_shipping_free) as fare_shipping_free from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$todaytime['egt']." and date_added < ".$todaytime['lt']." and type != 'integral' and ".$condition." and (order_status_id in (1,2,3,4,6,11,14))" );
  765. if(empty($list[0]['total'])){
  766. $val = 0;
  767. }else{
  768. $val = $list[0]['total']+$list[0]['shipping_fare']+$list[0]['packing_fare']-$list[0]['fare_shipping_free']-$list[0]['voucher_credit']-$list[0]['fullreduction_money'];
  769. }
  770. $today_sales[$i] = $val;
  771. }
  772. //昨日销售走势
  773. $yestertime = array();
  774. $yestertime['egt'] = strtotime(date('Y-m-d 00:00:00')) - 24*60*60;
  775. $yestertime['lt'] = strtotime(date('Y-m-d 00:00:00')) - 1;
  776. $yesterday_sales = array();
  777. for($i = 0;$i <= 23; $i++){
  778. $yestertime['egt'] = strtotime(date('Y-m-d 00:00:00')) - 24*60*60;
  779. $yestertime['egt'] = $yestertime['egt']+$i*60*60;
  780. $yestertime['lt'] = $yestertime['egt']+60*60-1;
  781. //有效销售额
  782. $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,sum(packing_fare) as packing_fare,sum(fare_shipping_free) as fare_shipping_free from ".C('DB_PREFIX')."lionfish_comshop_order where date_added > ".$yestertime['egt']." and date_added < ".$yestertime['lt']." and ".$condition." and type != 'integral' and (order_status_id in (1,2,3,4,6,11,14))" );
  783. if(empty($list1[0]['total'])){
  784. $val1 = 0;
  785. }else{
  786. $val1 = $list1[0]['total']+$list1[0]['shipping_fare']+$list1[0]['packing_fare']-$list1[0]['fare_shipping_free']-$list1[0]['voucher_credit']-$list1[0]['fullreduction_money'];
  787. }
  788. $yesterday_sales[$i] = $val1;
  789. }
  790. //七天的时间
  791. $sevenday = array();
  792. $sevenday['egt'] = strtotime(date('Y-m-d 00:00:00'))-6*24*60*60;
  793. $sevenday['lt'] = strtotime(date('Y-m-d 23:59:59'));
  794. //7日内团长销量top10
  795. $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 type != 'integral' and ".$condition);
  796. //所有团长id
  797. $sale = array();
  798. foreach($sevenday_sale as $key =>$v) {
  799. $sale[$key] = array(
  800. 'head_id' => $v['head_id'],
  801. );
  802. }
  803. //合并数据,唯一团长id
  804. $sale = array_unique($sale, SORT_REGULAR);
  805. //var_dump($sale);
  806. //var_dump($sale);
  807. //获取供应信息
  808. $sale_list = array();
  809. foreach($sale as $key =>$v) {
  810. //社区店名称
  811. $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);
  812. //var_dump($sale1);
  813. //团长
  814. //订单数量
  815. $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 type != 'integral' and ".$condition);
  816. //var_dump($sale2);
  817. //有效订单金额(元)
  818. $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,sum(packing_fare) as packing_fare,sum(fare_shipping_free) as fare_shipping_free from ".C('DB_PREFIX')."lionfish_comshop_order where (head_id = ".$v['head_id'].") and date_added > ".$sevenday['egt']." and date_added < ".$sevenday['lt']." and type != 'integral' and ".$condition );
  819. //有效订单金额(元)sum_money
  820. $sale_money = $sale3[0]['total']+$sale3[0]['shipping_fare']+$sale3[0]['packing_fare']-$sale3[0]['fare_shipping_free']-$sale3[0]['voucher_credit']-$sale3[0]['fullreduction_money'];
  821. $sale_list[$key] = array(
  822. 'community_name' => $sale1[0]['community_name'],
  823. 'head_name' => $sale1[0]['head_name'],
  824. 'count' => $sale2[0]['count'],
  825. 'sale_money' => $sale_money,
  826. );
  827. }
  828. //数组重新排序
  829. $count = array_column($sale_list,'count');
  830. array_multisort($count,SORT_DESC,$sale_list);
  831. $this->sale_list = $sale_list;
  832. //7日内商品销量top10
  833. $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 ");
  834. //所有商品id
  835. $info = array();
  836. foreach($sevenday_info as $key =>$v) {
  837. $info[$key] = array(
  838. 'goods_id' => $v['goods_id'],
  839. //'quantity' => $v['quantity'],
  840. );
  841. }
  842. //合并数据,唯一商品id
  843. $info = array_unique($info, SORT_REGULAR);
  844. //唯一商品id获取对应信息
  845. $goods_statistic = array();
  846. foreach($info as $key =>$v) {
  847. $g_sql = "select sum(og.quantity) as quantity ,og.name as name from ".C('DB_PREFIX')."lionfish_comshop_order_goods og,".C('DB_PREFIX')."lionfish_comshop_order o where( og.goods_id = ".$v['goods_id'].") "
  848. ." and og.addtime > ".$sevenday['egt']." and og.addtime < ".$sevenday['lt']." and ".$condition." and og.order_id=o.order_id and o.type != 'integral' and o.order_status_id in(6,11)";
  849. $info2 = M()->query($g_sql);
  850. if( empty($info2[0]['name']) && empty($info2[0]['quantity'])){
  851. }else{
  852. $goods_statistic[$key]=array(
  853. 'goods_id' => $v['goods_id'],
  854. 'name' => $info2[0]['name'],
  855. 'quantity' => $info2[0]['quantity'],
  856. );
  857. }
  858. }
  859. //序号
  860. $gid = 0;
  861. //数组重新排序
  862. $quantity = array_column($goods_statistic,'quantity');
  863. array_multisort($quantity,SORT_DESC,$goods_statistic);
  864. $this->day_info = $day_info;
  865. $this->day_info2 = $day_info2;
  866. $this->sum_money = $sum_money;
  867. $this->sum_order = $sum_order;
  868. $this->sum_member = $sum_member;
  869. $this->list1 = $list1;
  870. $this->sum_goods = $sum_goods;
  871. $this->ave_money = $ave_money;
  872. $this->add_member = $add_member;
  873. $this->member_num = $member_num;
  874. $this->add_supplier = $add_supplier;
  875. $this->add_head = $add_head;
  876. $this->add_goods = $add_goods;
  877. $this->todaytime = $todaytime;
  878. $this->today_sales = $today_sales;
  879. $this->yestertime = $yestertime;
  880. $this->yesterday_sales = $yesterday_sales;
  881. $this->sevenday = $sevenday;
  882. $this->sevenday_sale = $sevenday_sale;
  883. $this->sale = $sale;
  884. $this->count = $count;
  885. $this->sevenday_info = $sevenday_info;
  886. $this->info = $info;
  887. $this->goods_statistic = $goods_statistic;
  888. $this->_GPC = $_GPC;
  889. include $this->display();
  890. }
  891. public function communitystatics()
  892. {
  893. $_GPC = I('request.');
  894. $starttime = strtotime( date('Y-m-d').' 00:00:00' );
  895. $endtime = $starttime + 86400;
  896. $pindex = I('request.page', 1);
  897. $psize = 20;
  898. $searchtime = $_GPC['searchtime'];
  899. $keyword = I('get.keyword','','addslashes');
  900. $keyword2 = stripslashes($keyword);
  901. $this->keyword = $keyword2;
  902. if( !empty($searchtime) )
  903. {
  904. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  905. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  906. }
  907. $this->starttime = $starttime;
  908. $this->endtime = $endtime;
  909. $this->searchtime = $searchtime;
  910. //0 3
  911. $type = isset($_GPC['type']) ? $_GPC['type'] : 0;
  912. $data = array();
  913. $data = $this->head_sale_analys($keyword, $searchtime , $starttime , $endtime, $pindex , $psize);
  914. $this->pager = $data['pager'];
  915. unset($data['pager']);
  916. $this->type = $type;
  917. $this->data = $data;
  918. $this->_GPC = $_GPC;
  919. $this->display();
  920. }
  921. public function communitystatics_commiss()
  922. {
  923. $_GPC = I('request.');
  924. $pindex = I('request.page', 1);
  925. $psize = 20;
  926. $starttime = strtotime( date('Y-m-d').' 00:00:00' );
  927. $endtime = $starttime + 86400;
  928. $searchtime = $_GPC['searchtime'];
  929. $keyword = $_GPC['keyword'];
  930. if( !empty($searchtime) )
  931. {
  932. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  933. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  934. }
  935. //0 3
  936. $type = isset($_GPC['type']) ? $_GPC['type'] : 0;
  937. $data = array();
  938. $data = $this->head_commiss_analys($keyword,$searchtime , $starttime , $endtime , $pindex , $psize);
  939. $this->starttime = $starttime;
  940. $this->endtime = $endtime;
  941. $this->searchtime = $searchtime;
  942. $this->keyword = $keyword;
  943. $this->pager = $data['pager'];
  944. unset($data['pager']);
  945. $this->type = $type;
  946. $this->data = $data;
  947. $this->_GPC = $_GPC;
  948. include $this->display();
  949. }
  950. public function communitystatics_order()
  951. {
  952. $_GPC = I('request.');
  953. $starttime = strtotime( date('Y-m-d').' 00:00:00' );
  954. $endtime = $starttime + 86400;
  955. $searchtime = $_GPC['searchtime'];
  956. $keyword = $_GPC['keyword'];
  957. if( !empty($searchtime) )
  958. {
  959. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  960. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  961. }
  962. //0 3
  963. $type = isset($_GPC['type']) ? $_GPC['type'] : 0;
  964. $data = array();
  965. $pindex = I('request.page', 1);
  966. $psize = 20;
  967. $data = $this->head_order_analys($keyword,$searchtime , $starttime , $endtime , $pindex , $psize);
  968. $this->starttime = $starttime;
  969. $this->endtime = $endtime;
  970. $this->searchtime = $searchtime;
  971. $this->keyword = $keyword;
  972. $this->pager = $data['pager'];
  973. unset($data['pager']);
  974. $this->type = $type;
  975. $this->data = $data;
  976. $this->_GPC = $_GPC;
  977. include $this->display();
  978. }
  979. private function head_order_analys($keyword,$searchtime , $starttime , $endtime, $pindex , $psize)
  980. {
  981. $_GPC = I('request.');
  982. $data = array();
  983. //1、寻找团长
  984. $where = " and type != 'integral' ";
  985. if( !empty($searchtime) )
  986. {
  987. $where .= " and date_added >= {$starttime} and date_added <= {$endtime} ";
  988. }
  989. /*$sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order where 1 {$where} group by head_id ";
  990. $order_ids_all = M()->query($sql);
  991. $head_ids_arr = array();
  992. if( !empty($order_ids_all) )
  993. {
  994. foreach( $order_ids_all as $val )
  995. {
  996. $head_ids_arr[] = $val['head_id'];
  997. }
  998. }
  999. $search_head_list = array();
  1000. if( !empty($keyword) )
  1001. {
  1002. $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
  1003. WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  1004. $community_head_list = M()->query( $sql );
  1005. if( !empty($community_head_list) )
  1006. {
  1007. foreach( $community_head_list as $val )
  1008. {
  1009. $search_head_list[] = $val['id'];
  1010. }
  1011. }
  1012. //交集
  1013. $head_ids_arr = array_intersect($head_ids_arr, $search_head_list);
  1014. }*/
  1015. //进行分页操作
  1016. /*$sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order co left join " . C('DB_PREFIX'). "lionfish_community_head as ch on co.head_id=ch.id left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id where 1 {$where} and ch.member_id > 0 group by head_id ";
  1017. if( !empty($keyword) ){
  1018. $sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order co left join " . C('DB_PREFIX'). "lionfish_community_head as ch on co.head_id=ch.id left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id"
  1019. ." WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%') {$where} group by head_id ";
  1020. }
  1021. $sql2 = "";
  1022. if( !empty($keyword) ){
  1023. $sql = " SELECT DISTINCT(ch.id) as head_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
  1024. WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  1025. }
  1026. if(!empty($sql2)){
  1027. $sql = $sql . " union all ".$sql2;
  1028. }
  1029. $sql = 'select distinct(head_id) as head_id from ('.$sql . ') t where head_id > 0';*/
  1030. $sql = " SELECT ch.id as head_id,ch.level_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 where 1=1 ";
  1031. if( !empty($keyword) ){
  1032. $sql = $sql." and (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  1033. }
  1034. if( isset($_GPC['export']) && $_GPC['export'] == 1 ) {
  1035. $sql_list = 'select distinct(head_id) as head_id from (' . $sql . ') t where head_id > 0 ';
  1036. }else{
  1037. $sql_list = 'select distinct(head_id) as head_id from (' . $sql . ') t where head_id > 0 order by head_id asc limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  1038. $total_list = M()->query("select count(1) as count from ($sql) t where head_id > 0");
  1039. $total = 0;
  1040. if(!empty($total_list) && count($total_list) > 0){
  1041. $total = $total_list[0]['count'];
  1042. }
  1043. $pager = pagination2($total, $pindex, $psize);
  1044. $data['pager'] = $pager;
  1045. }
  1046. $order_ids_all = M()->query($sql_list);
  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. //----------------以上是搜索团长的代码
  1056. //---------------团长等级begin-------------
  1057. $level_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_commission_level where 1 ";
  1058. $level_list = M()->query($level_sql);
  1059. $level_arr = array(0 => '默认等级');
  1060. foreach( $level_list as $vv )
  1061. {
  1062. $level_arr[ $v['id'] ] = $vv['levelname'];
  1063. }
  1064. //---------------团长等级end---------------
  1065. if( empty($head_ids_arr) )
  1066. {
  1067. return $data;
  1068. }else{
  1069. foreach($head_ids_arr as $head_id)
  1070. {
  1071. $tmp = array();
  1072. $head_info = M('lionfish_community_head')->where( array('id' => $head_id ) )->find();
  1073. if( empty($head_info['member_id']) )
  1074. {
  1075. continue;
  1076. }
  1077. $mb_info = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $head_info['member_id'] ) )->find();
  1078. $tmp['head_id'] = $head_id;
  1079. $tmp['username'] = $mb_info['username'];
  1080. $tmp['community_name'] = $head_info['community_name'];
  1081. $tmp['head_name'] = $head_info['head_name'];
  1082. $tmp['head_mobile'] = $head_info['head_mobile'];
  1083. $tmp['head_levelname'] = $level_arr[ $head_info['level_id'] ];
  1084. //总订单量 in(1,4,6,11,14) 退款: 7,
  1085. $all_order_count = M('lionfish_comshop_order')->where( "head_id = {$head_id} {$where}" )->count();
  1086. $tmp['all_order_count'] = $all_order_count;
  1087. //有效订单量
  1088. $effect_order_count = M('lionfish_comshop_order')->where( " head_id = {$head_id} and order_status_id in (1,4,6,11,12,14) {$where}" )->count();
  1089. $tmp['effect_order_count'] = $effect_order_count;
  1090. //已关闭订单量
  1091. $close_order_count = M('lionfish_comshop_order')->where( " head_id = {$head_id} and order_status_id =5 {$where} " )->count();
  1092. $tmp['close_order_count'] = $close_order_count;
  1093. //订单总金额(元)
  1094. $all_order_paymoney = M('lionfish_comshop_order')->where("head_id = {$head_id} {$where}")->sum("total+shipping_fare-voucher_credit-fullreduction_money+packing_fare");
  1095. $all_order_paymoney = sprintf('%.2f',$all_order_paymoney);
  1096. $tmp['all_order_paymoney'] = $all_order_paymoney;
  1097. //有效订单金额(元)
  1098. $effect_order_paymoney = M('lionfish_comshop_order')->where("head_id = {$head_id} and order_status_id in(1,4,6,11,12,14) {$where}")->sum("total+shipping_fare-voucher_credit-fullreduction_money+packing_fare");
  1099. $effect_order_paymoney = sprintf('%.2f',$effect_order_paymoney);
  1100. $tmp['effect_order_paymoney'] = $effect_order_paymoney;
  1101. //待付款量
  1102. $pending_order_count = M('lionfish_comshop_order')->where( " head_id = {$head_id} and order_status_id =3 {$where} " )->count();
  1103. $tmp['pending_order_count'] = $pending_order_count;
  1104. //退款量
  1105. $refund_order_count = M('lionfish_comshop_order')->where(" head_id = {$head_id} and order_status_id =7 {$where} ")->count();
  1106. $tmp['refund_order_count'] = $refund_order_count;
  1107. //退款总金额(元)
  1108. $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+packing_fare");
  1109. $refund_order_paymoney = sprintf('%.2f',$refund_order_paymoney);
  1110. $tmp['refund_order_paymoney'] = $refund_order_paymoney;
  1111. $data[] = $tmp;
  1112. }
  1113. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  1114. {
  1115. $columns = array(
  1116. array('title' => 'ID', 'field' => 'head_id', 'width' => 32),
  1117. array('title' => '团长昵称', 'field' => 'username', 'width' => 32),
  1118. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 32),
  1119. array('title' => '团长手机号', 'field' => 'head_mobile', 'width' => 32),
  1120. array('title' => '小区信息', 'field' => 'community_name', 'width' => 32),
  1121. array('title' => '总订单量', 'field' => 'all_order_count', 'width' => 32),
  1122. array('title' => '有效订单量', 'field' => 'effect_order_count', 'width' => 32),
  1123. array('title' => '已关闭订单量', 'field' => 'close_order_count', 'width' => 32),
  1124. array('title' => '订单总金额(元)', 'field' => 'all_order_paymoney', 'width' => 32),
  1125. array('title' => '有效订单金额(元)', 'field' => 'effect_order_paymoney', 'width' => 32),
  1126. array('title' => '待付款量', 'field' => 'pending_order_count', 'width' => 32),
  1127. array('title' => '退款量', 'field' => 'refund_order_count', 'width' => 32),
  1128. array('title' => '退款总金额(元)', 'field' => 'refund_order_paymoney', 'width' => 32),
  1129. );
  1130. $title = '团长销售额统计';
  1131. D('Seller/Excel')->export($data, array('title' => $title, 'columns' => $columns));
  1132. }
  1133. }
  1134. return $data;
  1135. }
  1136. private function head_commiss_analys( $keyword,$searchtime , $starttime , $endtime , $pindex , $psize )
  1137. {
  1138. $_GPC = I('request.');
  1139. $data = array();
  1140. //1、寻找团长
  1141. $where = " 1 ";
  1142. $tj_where = " ";
  1143. if( !empty($searchtime) )
  1144. {
  1145. $where .= " and date_added >= {$starttime} and date_added <= {$endtime} ";
  1146. $tj_where .= " and addtime >= {$starttime} and addtime <= {$endtime} ";
  1147. }
  1148. //原先获取数据
  1149. /*$sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order where {$where} group by head_id ";
  1150. $order_ids_all = M()->query($sql);
  1151. $head_ids_arr = array();
  1152. if( !empty($order_ids_all) )
  1153. {
  1154. foreach( $order_ids_all as $val )
  1155. {
  1156. $head_ids_arr[] = $val['head_id'];
  1157. }
  1158. }
  1159. $search_head_list = array();
  1160. if( !empty($keyword) )
  1161. {
  1162. $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
  1163. WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  1164. $community_head_list = M()->query( $sql );
  1165. //var_dump($community_head_list,$sql);die();
  1166. if( !empty($community_head_list) )
  1167. {
  1168. foreach( $community_head_list as $val )
  1169. {
  1170. $search_head_list[] = $val['id'];
  1171. }
  1172. }
  1173. //交集
  1174. $head_ids_arr = array_intersect($head_ids_arr, $search_head_list);
  1175. }*/
  1176. //进行分页操作
  1177. /*$sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order co left join " . C('DB_PREFIX'). "lionfish_community_head as ch on co.head_id=ch.id left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id where {$where} and ch.member_id > 0 group by head_id ";
  1178. if( !empty($keyword) ){
  1179. $sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order co left join " . C('DB_PREFIX'). "lionfish_community_head as ch on co.head_id=ch.id left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id"
  1180. ." WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%') {$where} group by head_id ";
  1181. }
  1182. $sql2 = "";
  1183. if( !empty($keyword) ){
  1184. $sql = " SELECT DISTINCT(ch.id) as head_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
  1185. WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  1186. }
  1187. if(!empty($sql2)){
  1188. $sql = $sql . " union all ".$sql2;
  1189. }
  1190. $sql = 'select distinct(head_id) as head_id from ('.$sql . ') t where head_id > 0';*/
  1191. $sql = " SELECT ch.id as head_id,ch.level_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 where 1=1 ";
  1192. if( !empty($keyword) ){
  1193. $sql = $sql." and (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  1194. }
  1195. if( isset($_GPC['export']) && $_GPC['export'] == 1 ) {
  1196. $sql_list = 'select distinct(head_id) as head_id from (' . $sql . ') t where head_id > 0 ';
  1197. }else{
  1198. $sql_list = 'select distinct(head_id) as head_id from (' . $sql . ') t where head_id > 0 order by head_id asc limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  1199. $total_list = M()->query("select count(1) as count from (" . $sql . ") ct where head_id > 0");
  1200. $total = 0;
  1201. if(!empty($total_list) && count($total_list) > 0){
  1202. $total = $total_list[0]['count'];
  1203. }
  1204. $pager = pagination2($total, $pindex, $psize);
  1205. $data['pager'] = $pager;
  1206. }
  1207. $order_ids_all = M()->query($sql_list);
  1208. $head_ids_arr = array();
  1209. if( !empty($order_ids_all) )
  1210. {
  1211. foreach( $order_ids_all as $val )
  1212. {
  1213. $head_ids_arr[] = $val['head_id'];
  1214. }
  1215. }
  1216. //----------------以上是搜索团长的代码
  1217. //---------------团长等级begin-------------
  1218. /*$level_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_commission_level ";
  1219. $level_list = M()->query($level_sql);
  1220. $level_arr = array(0 => '默认等级');
  1221. foreach( $level_list as $vv )
  1222. {
  1223. $level_arr[ $v['id'] ] = $vv['levelname'];
  1224. }*/
  1225. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  1226. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1227. $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
  1228. $list_default = array(
  1229. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  1230. );
  1231. if(empty($community_head_level)){
  1232. $community_head_level = array();
  1233. }
  1234. $community_head_level = array_merge($list_default, $community_head_level);
  1235. $level_arr = array();
  1236. foreach($community_head_level as $kk => $vv)
  1237. {
  1238. $level_arr[$vv['id']] = $vv['levelname'];
  1239. }
  1240. //---------------团长等级end---------------
  1241. if( empty($head_ids_arr) )
  1242. {
  1243. return $data;
  1244. }else{
  1245. foreach($head_ids_arr as $head_id)
  1246. {
  1247. $tmp = array();
  1248. $head_info = M('lionfish_community_head')->where( array('id' => $head_id ) )->find();
  1249. if( empty($head_info['member_id']) )
  1250. {
  1251. continue;
  1252. }
  1253. //ims_lionfish_comshop_member
  1254. $mb_info = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $head_info['member_id'] ) )->find();
  1255. $tmp['head_id'] = $head_id;
  1256. $tmp['username'] = $mb_info['username'];
  1257. $tmp['community_name'] = $head_info['community_name'];
  1258. $tmp['head_name'] = $head_info['head_name'];
  1259. $tmp['head_mobile'] = $head_info['head_mobile'];
  1260. $tmp['head_levelname'] = $level_arr[ $head_info['level_id'] ];
  1261. $head_commiss = M('lionfish_community_head_commiss')->where( array('head_id' =>$head_id ) )->find();
  1262. //下单佣金(元) orderbuy (1,2)
  1263. $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');
  1264. $tmp['sum_order_commiss'] = $sum_order_commiss;
  1265. //退款佣金(元) orderbuy(2)
  1266. $sum_order_refundcommiss = M('lionfish_community_head_commiss_order')->where(" head_id = {$head_id} and state = 2 and type = 'orderbuy' {$tj_where} ")->sum('money');
  1267. $tmp['sum_order_refundcommiss'] = $sum_order_refundcommiss;
  1268. //下级下单佣金(元) commiss tuijian (1,2)
  1269. $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');
  1270. $tmp['childsum_order_commiss'] = $childsum_order_commiss;
  1271. //下级退款佣金(元) commiss tuijian (2)
  1272. $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');
  1273. $tmp['childsum_order_refundcommiss'] = $childsum_order_refundcommiss;
  1274. //净佣金(元)
  1275. $real_commiss_money = $sum_order_commiss + $childsum_order_commiss - $sum_order_refundcommiss - $childsum_order_refundcommiss;
  1276. $tmp['real_commiss_money'] = $real_commiss_money;
  1277. //申请提现佣金(元)
  1278. $tmp['dongmoney'] = $head_commiss['dongmoney'];
  1279. //提现到帐佣金(元)
  1280. $tmp['getmoney'] = $head_commiss['getmoney'];
  1281. $data[] = $tmp;
  1282. }
  1283. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  1284. {
  1285. $columns = array(
  1286. array('title' => 'ID', 'field' => 'head_id', 'width' => 32),
  1287. array('title' => '团长昵称', 'field' => 'username', 'width' => 32),
  1288. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 32),
  1289. array('title' => '团长手机号', 'field' => 'head_mobile', 'width' => 32),
  1290. array('title' => '小区信息', 'field' => 'community_name', 'width' => 32),
  1291. array('title' => '团长等级', 'field' => 'head_levelname', 'width' => 32),
  1292. array('title' => '下单佣金(元)', 'field' => 'sum_order_commiss', 'width' => 32),
  1293. array('title' => '退款佣金(元)', 'field' => 'sum_order_refundcommiss', 'width' => 32),
  1294. array('title' => '下级下单佣金(元)', 'field' => 'childsum_order_commiss', 'width' => 32),
  1295. array('title' => '下级退款佣金(元)', 'field' => 'childsum_order_refundcommiss', 'width' => 32),
  1296. array('title' => '净佣金(元)', 'field' => 'real_commiss_money', 'width' => 32),
  1297. array('title' => '申请提现佣金(元)', 'field' => 'dongmoney', 'width' => 32),
  1298. array('title' => '提现到帐佣金(元)', 'field' => 'getmoney', 'width' => 32),
  1299. );
  1300. $title = '团长佣金金额统计';
  1301. D('Seller/Excel')->export($data, array('title' => $title, 'columns' => $columns));
  1302. }
  1303. return $data;
  1304. }
  1305. }
  1306. //团长销售额统计
  1307. private function head_sale_analys( $keyword,$searchtime , $starttime , $endtime , $pindex , $psize)
  1308. {
  1309. $_GPC = I('request.');
  1310. $data = array();
  1311. //1、寻找团长
  1312. $where = " and type != 'integral' ";
  1313. $refund_where = " ";
  1314. if( !empty($searchtime) )
  1315. {
  1316. $where .= " and date_added >= {$starttime} and date_added <= {$endtime} ";
  1317. $refund_where .= " and addtime >= {$starttime} and addtime <= {$endtime} ";
  1318. }
  1319. /*$sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order where 1 {$where} group by head_id ";
  1320. $order_ids_all = M()->query($sql);
  1321. $head_ids_arr = array();
  1322. if( !empty($order_ids_all) )
  1323. {
  1324. foreach( $order_ids_all as $val )
  1325. {
  1326. $head_ids_arr[] = $val['head_id'];
  1327. }
  1328. }
  1329. $search_head_list = array();
  1330. if( !empty($keyword) )
  1331. {
  1332. $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
  1333. WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  1334. $community_head_list = M()->query( $sql );
  1335. if( !empty($community_head_list) )
  1336. {
  1337. foreach( $community_head_list as $val )
  1338. {
  1339. $search_head_list[] = $val['id'];
  1340. }
  1341. }
  1342. //交集
  1343. $head_ids_arr = array_intersect($head_ids_arr, $search_head_list);
  1344. }*/
  1345. //进行分页操作
  1346. /*$sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order co left join " . C('DB_PREFIX'). "lionfish_community_head as ch on co.head_id=ch.id left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id where 1 {$where} and ch.member_id > 0 group by head_id ";
  1347. if( !empty($keyword) ){
  1348. $sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order co left join " . C('DB_PREFIX'). "lionfish_community_head as ch on co.head_id=ch.id left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id"
  1349. ." WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%') {$where} group by head_id ";
  1350. }
  1351. $sql2 = "";
  1352. if( !empty($keyword) ){
  1353. $sql2 = " SELECT DISTINCT (ch.id) as head_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
  1354. WHERE (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  1355. }
  1356. if(!empty($sql2)){
  1357. $sql = $sql . " union all ".$sql2;
  1358. }*/
  1359. $sql = " SELECT ch.id as head_id,ch.level_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 where 1=1 ";
  1360. if( !empty($keyword) ){
  1361. $sql = $sql." and (m.username like '%{$keyword}%' or ch.head_name like '%{$keyword}%' or ch.community_name like '%{$keyword}%' ) ";
  1362. }
  1363. //$sql = 'select distinct(head_id) as head_id from ('.$sql . ') t where head_id > 0';
  1364. if( isset($_GPC['export']) && $_GPC['export'] == 1 ) {
  1365. $sql_list = 'select distinct(head_id) as head_id from (' . $sql . ') t where head_id > 0 ';
  1366. }else{
  1367. $sql_list = 'select distinct(head_id) as head_id from (' . $sql . ') t where head_id > 0 order by head_id asc limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  1368. $total_list = M()->query("select count(1) as count from ($sql) t where head_id > 0");
  1369. $total = 0;
  1370. if(!empty($total_list) && count($total_list) > 0){
  1371. $total = $total_list[0]['count'];
  1372. }
  1373. $pager = pagination2($total, $pindex, $psize);
  1374. $data['pager'] = $pager;
  1375. }
  1376. $order_ids_all = M()->query($sql_list);
  1377. $head_ids_arr = array();
  1378. if( !empty($order_ids_all) )
  1379. {
  1380. foreach( $order_ids_all as $val )
  1381. {
  1382. $head_ids_arr[] = $val['head_id'];
  1383. }
  1384. }
  1385. //----------------以上是搜索团长的代码
  1386. //---------------团长等级begin-------------
  1387. /*$level_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_commission_level ";
  1388. $level_list = M()->query($level_sql );
  1389. $level_arr = array(0 => '默认等级');
  1390. foreach( $level_list as $vv )
  1391. {
  1392. $level_arr[ $v['id'] ] = $vv['levelname'];
  1393. }*/
  1394. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  1395. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1396. $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
  1397. $list_default = array(
  1398. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  1399. );
  1400. if(empty($community_head_level)){
  1401. $community_head_level = array();
  1402. }
  1403. $community_head_level = array_merge($list_default, $community_head_level);
  1404. $level_arr = array();
  1405. foreach($community_head_level as $kk => $vv)
  1406. {
  1407. $level_arr[$vv['id']] = $vv['levelname'];
  1408. }
  1409. //---------------团长等级end---------------
  1410. if( empty($head_ids_arr) )
  1411. {
  1412. return $data;
  1413. }else{
  1414. foreach($head_ids_arr as $head_id)
  1415. {
  1416. $tmp = array();
  1417. $head_info = M('lionfish_community_head')->where( array('id' => $head_id ) )->find();
  1418. if( empty($head_info['member_id']) )
  1419. {
  1420. continue;
  1421. }
  1422. $mb_info = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $head_info['member_id'] ) )->find();
  1423. $tmp['head_id'] = $head_id;
  1424. $tmp['username'] = $mb_info['username'];
  1425. $tmp['community_name'] = $head_info['community_name'];
  1426. $tmp['head_name'] = $head_info['head_name'];
  1427. $tmp['head_mobile'] = $head_info['head_mobile'];
  1428. $tmp['head_levelname'] = $level_arr[ $head_info['level_id'] ];
  1429. //下单会员数(支付的+退款的)
  1430. $buy_mb_count_arr = M()->query("SELECT count( DISTINCT(member_id) ) as count FROM ".C('DB_PREFIX').
  1431. "lionfish_comshop_order WHERE 1 and head_id = {$head_id} and order_status_id in(1,4,5,6,7,11,12,14) {$where} ");
  1432. $buy_mb_count = $buy_mb_count_arr[0]['count'];
  1433. $tmp['buy_mb_count'] = $buy_mb_count;
  1434. //下单数量(支付的+退款的)
  1435. $buy_order_count = M('lionfish_comshop_order')->where(" head_id = {$head_id} and order_status_id in(1,4,5,6,7,11,12,14) {$where} ")->count();
  1436. $tmp['buy_order_count'] = $buy_order_count;
  1437. //销售额(支付的+退款的)
  1438. $sum_order_paymoney = M('lionfish_comshop_order')->where("head_id = {$head_id} and order_status_id in(1,4,5,6,7,11,12,14) {$where}")->sum('total+shipping_fare-fare_shipping_free-voucher_credit-fullreduction_money+packing_fare');
  1439. $sum_order_paymoney = sprintf('%.2f',$sum_order_paymoney);
  1440. $tmp['sum_order_paymoney'] = $sum_order_paymoney;
  1441. $tp_od_list = M('lionfish_comshop_order')->field('order_id')->where(" head_id = {$head_id} {$where} ")->select();
  1442. if( !empty($tp_od_list) )
  1443. {
  1444. $tp_od_arr = array();
  1445. foreach( $tp_od_list as $tp_val )
  1446. {
  1447. $tp_od_arr[] = $tp_val['order_id'];
  1448. }
  1449. $has_refund_arr = M()->query("select order_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund where order_id in( ".implode(',', $tp_od_arr )." ) group by order_id ");
  1450. $refund_order_count = count($has_refund_arr);
  1451. //退款额(元)
  1452. $refund_order_money = M('lionfish_comshop_order_goods_refund')->where(array('order_id' => array('in', $tp_od_arr) ))->sum('money+refund_shipping_fare');
  1453. }else{
  1454. $refund_order_count = 0;
  1455. $refund_order_money = 0;
  1456. }
  1457. //$where .= " and date_added >= {$starttime} and date_added <= {$endtime} ";
  1458. $tmp['refund_order_count'] = $refund_order_count;
  1459. $tmp['refund_order_money'] = $refund_order_money;
  1460. //净销售额(元) 销售额 - 退款额 = 净销售额
  1461. $real_sale_money = round(($sum_order_paymoney - $refund_order_money) ,2);
  1462. $tmp['real_sale_money'] = $real_sale_money;
  1463. $data[] = $tmp;
  1464. }
  1465. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  1466. {
  1467. $columns = array(
  1468. array('title' => 'ID', 'field' => 'head_id', 'width' => 32),
  1469. array('title' => '团长昵称', 'field' => 'username', 'width' => 32),
  1470. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 32),
  1471. array('title' => '团长手机号', 'field' => 'head_mobile', 'width' => 32),
  1472. array('title' => '小区信息', 'field' => 'community_name', 'width' => 32),
  1473. array('title' => '团长等级', 'field' => 'head_levelname', 'width' => 32),
  1474. array('title' => '下单会员数', 'field' => 'buy_mb_count', 'width' => 32),
  1475. array('title' => '下单数量', 'field' => 'buy_order_count', 'width' => 32),
  1476. array('title' => '销售额(元)', 'field' => 'sum_order_paymoney', 'width' => 32),
  1477. array('title' => '退款量', 'field' => 'refund_order_count', 'width' => 32),
  1478. array('title' => '退款额(元)', 'field' => 'refund_order_money', 'width' => 32),
  1479. array('title' => '净销售额(元)', 'field' => 'real_sale_money', 'width' => 32),
  1480. );
  1481. $title = '团长销售额统计';
  1482. D('Seller/Excel')->export($data, array('title' => $title, 'columns' => $columns));
  1483. }
  1484. }
  1485. return $data;
  1486. }
  1487. //找出这段时间团长的方法
  1488. private function head_sale_analys_back( $keyword,$searchtime , $starttime , $endtime )
  1489. {
  1490. $_GPC = I('request.');
  1491. $data = array();
  1492. //1、寻找团长
  1493. $where = " ";
  1494. if( !empty($searchtime) )
  1495. {
  1496. $where .= " and date_added >= {$starttime} and date_added <= {$endtime} ";
  1497. }
  1498. $sql = "select head_id from ".C('DB_PREFIX')."lionfish_comshop_order where 1 {$where} group by head_id ";
  1499. $order_ids_all = M()->query($sql );
  1500. $head_ids_arr = array();
  1501. if( !empty($order_ids_all) )
  1502. {
  1503. foreach( $order_ids_all as $val )
  1504. {
  1505. $head_ids_arr[] = $val['head_id'];
  1506. }
  1507. }
  1508. $search_head_list = array();
  1509. if( !empty($keyword) )
  1510. {
  1511. $sql = "select id from ".C('DB_PREFIX').
  1512. "lionfish_community_head where (head_name like '%{$keyword}%' or community_name like '%{$keyword}%' ) ";
  1513. $community_head_list = M()->query( $sql );
  1514. if( !empty($community_head_list) )
  1515. {
  1516. foreach( $community_head_list as $val )
  1517. {
  1518. $search_head_list[] = $val['id'];
  1519. }
  1520. }
  1521. //交集
  1522. $head_ids_arr = array_intersect($head_ids_arr, $search_head_list);
  1523. }
  1524. //----------------以上是搜索团长的代码
  1525. //---------------团长等级begin-------------
  1526. $level_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_commission_level ";
  1527. $level_list = M()->query($level_sql);
  1528. $level_arr = array(0 => '默认等级');
  1529. foreach( $level_list as $vv )
  1530. {
  1531. $level_arr[ $v['id'] ] = $vv['levelname'];
  1532. }
  1533. //---------------团长等级end---------------
  1534. if( empty($head_ids_arr) )
  1535. {
  1536. return $data;
  1537. }else{
  1538. foreach($head_ids_arr as $head_id)
  1539. {
  1540. $tmp = array();
  1541. $head_info = M('lionfish_community_head')->where( array('id' => $head_id ) )->find();
  1542. $tmp['community_name'] = $head_info['community_name'];
  1543. $tmp['head_name'] = $head_info['head_name'];
  1544. $tmp['head_mobile'] = $head_info['head_mobile'];
  1545. $tmp['head_levelname'] = $level_arr[ $head_info['level_id'] ];
  1546. //下单会员数
  1547. //下单数量
  1548. //销售额
  1549. //level_id
  1550. $data[] = $tmp;
  1551. }
  1552. }
  1553. return $data;
  1554. }
  1555. private function deep_in_array($value, $array) {
  1556. foreach($array as $item) {
  1557. if(!is_array($item)) {
  1558. if ($item == $value) {
  1559. return true;
  1560. } else {
  1561. continue;
  1562. }
  1563. }
  1564. if(in_array($value, $item)) {
  1565. return true;
  1566. } else if($this->deep_in_array($value, $item)) {
  1567. return true;
  1568. }
  1569. }
  1570. return false;
  1571. }
  1572. /**
  1573. * 毛利统计
  1574. */
  1575. public function goodstatics(){
  1576. $_GPC = I('request.');
  1577. $pindex = I('request.page', 1);
  1578. $psize = 20;
  1579. //商品名称
  1580. $keyword = I('get.keyword','','addslashes');
  1581. $keyword2 = stripslashes($keyword);
  1582. $this->keyword = $keyword2;
  1583. $condition = " and og.cost_price is not NULL ";
  1584. if (!empty($keyword)) {
  1585. $condition .= " and og.name like '%".$keyword."%' ";
  1586. }
  1587. $starttime = strtotime( date('Y-m-d').' 00:00:00' );
  1588. $endtime = $starttime + 86400;
  1589. $searchtime = $_GPC['searchtime'];
  1590. if( !empty($searchtime) )
  1591. {
  1592. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  1593. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  1594. $condition .= " and og.addtime >= {$starttime} and og.addtime <= {$endtime} ";
  1595. }
  1596. $this->starttime = $starttime;
  1597. $this->endtime = $endtime;
  1598. $this->searchtime = $searchtime;
  1599. $sql = " SELECT og.goods_id,og.name,og.rela_goodsoption_valueid,og.price,og.cost_price,SUM( og.quantity ) as quantity, "
  1600. . " SUM( og.quantity * og.price ) as total_price,SUM( og.quantity * og.cost_price ) as cost_total_price,sum(og.profit_total) as profit_total "
  1601. . " FROM ". C('DB_PREFIX'). "lionfish_comshop_order_goods as og "
  1602. . " left join ". C('DB_PREFIX'). "lionfish_comshop_order as o on og.order_id=o.order_id "
  1603. . " left join ". C('DB_PREFIX'). "lionfish_comshop_goods as g on g.id=og.goods_id "
  1604. . " WHERE 1=1 and o.order_status_id in (6,11) and g.type != 'integral' "
  1605. . $condition . " group by og.goods_id, og.name, og.rela_goodsoption_valueid,og.price,og.cost_price ";
  1606. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  1607. {
  1608. $t_sql = " select * from ( " .$sql. " ) t "
  1609. . " order by profit_total desc ";
  1610. $list = M()->query($t_sql);
  1611. $i = 1;
  1612. foreach ($list as $k=>$v) {
  1613. $list[$k]['rank'] = $i;
  1614. $list[$k]['profit_fee'] = round($v['profit_total']/$v['total_price']*100,2);
  1615. $order_goods_info = M('lionfish_comshop_order_goods')->where(array('goods_id'=>$v['goods_id'],'rela_goodsoption_valueid'=>$v['rela_goodsoption_valueid']))->find();
  1616. $list[$k]['option_sku'] = D('Seller/Order')->get_order_option_sku($order_goods_info['order_id'], $order_goods_info['order_goods_id']);
  1617. //商品名称
  1618. /*$goods_info = M('lionfish_comshop_goods')->where(array('id'=>$v['goods_id']))->field('goodsname')->find();
  1619. if(!empty($goods_info)){
  1620. $list[$k]['name'] = $goods_info['goodsname'];
  1621. }*/
  1622. $i++;
  1623. }
  1624. $columns = array(
  1625. array('title' => '排名', 'field' => 'rank', 'width' => 32),
  1626. array('title' => '商品名称', 'field' => 'name', 'width' => 32),
  1627. array('title' => '规格', 'field' => 'option_sku', 'width' => 32),
  1628. array('title' => '商城售价(元)', 'field' => 'price', 'width' => 32),
  1629. array('title' => '成本价(元)', 'field' => 'cost_price', 'width' => 32),
  1630. array('title' => '商品销量', 'field' => 'quantity', 'width' => 32),
  1631. array('title' => '商品销量总价(元) ', 'field' => 'total_price', 'width' => 32),
  1632. array('title' => '商品销量成本总价(元)', 'field' => 'cost_total_price', 'width' => 32),
  1633. array('title' => '毛利额', 'field' => 'profit_total', 'width' => 32),
  1634. array('title' => '毛利率(%)', 'field' => 'profit_fee', 'width' => 32),
  1635. );
  1636. $data = array();
  1637. foreach($list as $k=>$v){
  1638. $tmp = array();
  1639. $tmp['rank'] = $v['rank'];
  1640. $tmp['name'] = $v['name'];
  1641. $tmp['option_sku'] = $v['option_sku'];
  1642. $tmp['price'] = $v['price'];
  1643. $tmp['cost_price'] = $v['cost_price'];
  1644. $tmp['quantity'] = $v['quantity'];
  1645. $tmp['total_price'] = $v['total_price'];
  1646. $tmp['cost_total_price'] = $v['cost_total_price'];
  1647. $tmp['profit_total'] = $v['profit_total'];
  1648. $tmp['profit_fee'] = $v['profit_fee'];
  1649. $data[] = $tmp;
  1650. }
  1651. $title = '商品毛利统计';
  1652. D('Seller/Excel')->export($data, array('title' => $title, 'columns' => $columns));
  1653. }else{
  1654. $t_sql = " select * from ( " .$sql. " ) t "
  1655. . " order by profit_total desc limit " . (($pindex - 1) * $psize) . "," . $psize;
  1656. $list = M()->query($t_sql);
  1657. $i = ($pindex-1)*$psize + 1;
  1658. foreach ($list as $k=>$v) {
  1659. $list[$k]['rank'] = $i;
  1660. $list[$k]['profit_fee'] = round($v['profit_total']/$v['total_price']*100,2);
  1661. $order_goods_info = M('lionfish_comshop_order_goods')->where(array('goods_id'=>$v['goods_id'],'rela_goodsoption_valueid'=>$v['rela_goodsoption_valueid']))->find();
  1662. $list[$k]['option_sku'] = D('Seller/Order')->get_order_option_sku($order_goods_info['order_id'], $order_goods_info['order_goods_id']);
  1663. //商品名称
  1664. /*$goods_info = M('lionfish_comshop_goods')->where(array('id'=>$v['goods_id']))->field('goodsname')->find();
  1665. if(!empty($goods_info)){
  1666. $list[$k]['name'] = $goods_info['goodsname'];
  1667. }*/
  1668. $i++;
  1669. }
  1670. $total_list = M()->query("select count(1) as count from (".$sql.") as t");
  1671. $total = $total_list[0]['count'];
  1672. $pager = pagination2($total, $pindex, $psize);
  1673. //商品总销量,商品总销售额
  1674. $all_sql = "select sum(og.quantity) as quantity,sum(og.quantity * og.price) as total_price "
  1675. . " from ". C('DB_PREFIX'). "lionfish_comshop_order_goods as og "
  1676. . " left join ". C('DB_PREFIX'). "lionfish_comshop_order as o on og.order_id=o.order_id "
  1677. . " left join ". C('DB_PREFIX'). "lionfish_comshop_goods as g on g.id=og.goods_id "
  1678. . " WHERE 1=1 and o.order_status_id in (6,11) and g.type != 'integral' "
  1679. . $condition;
  1680. $all_list = M()->query($all_sql);
  1681. $this->all_quantity = !empty($all_list[0]['quantity']) ? $all_list[0]['quantity'] : 0;
  1682. $this->all_total = !empty($all_list[0]['total_price']) ? $all_list[0]['total_price'] : 0;
  1683. $this->list = $list;
  1684. $this->pager = $pager;
  1685. $this->gpc = $_GPC;
  1686. $this->display();
  1687. }
  1688. }
  1689. }
  1690. ?>