ReportsController.class.php 91 KB

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