Statistics.php 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: my
  5. * Date: 2021/4/12
  6. * Time: 16:04
  7. */
  8. namespace app\admin\controller;
  9. use app\common\util\ExcelUtil;
  10. use think\App;
  11. use think\Db;
  12. class Statistics extends Auth{
  13. public function __construct(App $app) {
  14. parent::__construct($app);
  15. }
  16. /**
  17. * 订单统计
  18. *
  19. * @author wst
  20. * @date 2021/4/12 16:05
  21. */
  22. public function OrderTotal(){
  23. $data = (new Wyorders())->OrderTotal(cur_org_id());
  24. $this->assign('data',$data);
  25. $this->assign('meta_title','订单统计');
  26. return $this->fetch();
  27. }
  28. /**
  29. * 完成工时统计
  30. *
  31. * @author wst
  32. * @date 2021/4/12 16:05
  33. */
  34. public function duration(){
  35. $month = request()->get('month')?request()->get('month'):date('Y-m');
  36. $data = (new \app\model\Todo())->duration(cur_org_id(),$month);
  37. $this->assign('data',$data);
  38. $this->assign('month',$month);
  39. $this->assign('meta_title','完成工时统计');
  40. return $this->fetch();
  41. }
  42. /**
  43. * 巡更工作量统计
  44. *
  45. * @author wst
  46. * @date 2021/4/12 18:13
  47. */
  48. public function PatrolWork(){
  49. $data = (new \app\model\PatrolAddr())->PatrolWork(cur_org_id(),1);
  50. $this->assign('data',$data);
  51. $this->assign('meta_title','巡检巡查工作量统计');
  52. return $this->fetch();
  53. }
  54. /**
  55. * 设备台账工作量统计
  56. *
  57. * @author wst
  58. * @date 2021/4/12 18:13
  59. */
  60. public function DeviceWork(){
  61. $data = (new \app\common\model\Device())->DeviceWork(cur_org_id());
  62. $this->assign('data',$data);
  63. $this->assign('meta_title','设备维保工作量统计');
  64. return $this->fetch();
  65. }
  66. /**
  67. * 日常工作工作量统计
  68. *
  69. * @author wst
  70. * @date 2021/4/12 18:13
  71. */
  72. public function DailyWork(){
  73. $data = (new \app\common\model\Daily())->DailyWork(cur_org_id());
  74. $this->assign('data',$data);
  75. $this->assign('meta_title','日常工作量统计');
  76. return $this->fetch();
  77. }
  78. /**
  79. * 巡更人员工作量统计
  80. *
  81. * @author wst
  82. * @date 2021/4/12 18:13
  83. */
  84. public function WorkerPatrol(){
  85. $search['start'] = request()->get('start');
  86. $search['end'] = request()->get('end');
  87. if(empty($search['start'])){ // 未传时间默认近7天的
  88. $search['start'] = date('Y-m-d',time()-(6*24*60*60));
  89. $search['end'] = date('Y-m-d');
  90. }
  91. $data = (new \app\model\PatrolTask())->WorkerPatrol(cur_org_id(),$search,1);
  92. $this->assign('data',$data);
  93. $this->assign('month',$search);
  94. $this->assign('meta_title','巡检巡查人员工作量统计');
  95. return $this->fetch();
  96. }
  97. //预约统计
  98. public function ServiceCount(){
  99. $type=input('type');
  100. $start=input('start');
  101. $end=input('end');
  102. if($type == 1){
  103. $meta_title = '餐饮预约统计';
  104. }elseif ($type == 2){
  105. $meta_title = '美发预约统计';
  106. }elseif ($type == 3){
  107. $meta_title = '洗衣预约统计';
  108. }elseif ($type == 4){
  109. $meta_title = '医疗预约统计';
  110. }elseif ($type == 5){
  111. $meta_title = '活动室预约统计';
  112. }
  113. //获取服务id
  114. $serviceId = Db::name('service')->where('org_id',$this->org_id)->where('type',$type)->value('id');
  115. if(!$serviceId){
  116. $data = [];
  117. $this->assign('data',$data);
  118. }
  119. if(!$start && !$end){
  120. $end = date('Y-m-d H:i:s');
  121. $start = date('Y-m-d H:i:s',strtotime("$start -1 month"));
  122. }
  123. if($start >= $end){
  124. $this->error('开始时间不能大于结束时间');
  125. }
  126. if($type == 1 || $type == 2){
  127. $map[] = ['service_id','=',$serviceId];
  128. $cateList = Db::name('service_cate')->where($map)->order('id asc')->select()->toArray();
  129. $map[] = ['del','=',0];
  130. $itemList = Db::name('service_item')->where($map)->order('id asc')->select()->toArray();
  131. $this->assign('itemList',$itemList);
  132. $this->assign('cateList',$cateList);
  133. if($start && $end){
  134. $where[] = ['sb.create_time','>=',$start];
  135. $where[] = ['sb.create_time','<=',$end];
  136. }
  137. $where[] = ['sb.service_id','=',$serviceId];
  138. $where[] = ['sb.org_id','=',$this->org_id];
  139. $data = [];
  140. foreach ($itemList as $k=>$v){
  141. $data[$k]['title']= $v['title'];
  142. foreach ($cateList as $kk=>$vv){
  143. $bookList = Db::name('service_book')
  144. ->alias('sb')
  145. ->field('sb.*')
  146. ->join('service_book_cate sbc','sbc.service_book_id=sb.id')
  147. ->where('sb.service_item_id',$v['id'])
  148. ->where('sbc.service_cate_id',$vv['id'])
  149. ->where($where)
  150. ->select()
  151. ->toArray();
  152. $total = 0;
  153. foreach ($bookList as $kay=>$val){
  154. $total +=$val['nums'];
  155. }
  156. $data[$k]['list'][$kk] = $total;
  157. }
  158. }
  159. $count = [];
  160. foreach ($cateList as $k=>$v){
  161. $bookList = Db::name('service_book')
  162. ->alias('sb')
  163. ->field('sb.*')
  164. ->join('service_book_cate sbc','sbc.service_book_id=sb.id')
  165. ->where('sbc.service_cate_id',$v['id'])
  166. ->where($where)
  167. ->select()
  168. ->toArray();
  169. $countNum = 0;
  170. foreach ($bookList as $kk=>$vv){
  171. $countNum +=$vv['nums'];
  172. }
  173. $count[$k]['count'] = $countNum;
  174. }
  175. $this->assign('count',$count);
  176. }
  177. if($type == 3){
  178. $where[] = ['service_id','=',$serviceId];
  179. $where[] = ['org_id','=',$this->org_id];
  180. if($start && $end){
  181. $where[] = ['create_time','>=',$start];
  182. $where[] = ['create_time','<=',$end];
  183. }
  184. $data = [];
  185. $bookList = Db::name('service_book')->where($where)->select()->toArray();
  186. $total = 0;
  187. foreach ($bookList as $k=>$v){
  188. $total +=$v['nums'];
  189. }
  190. $data['k'] = 1;
  191. $data['count'] = $total;
  192. }
  193. if($type == 4 || $type == 5){
  194. $map[] = ['service_id','=',$serviceId];
  195. $map[] = ['del','=',0];
  196. $itemList = Db::name('service_item')->where($map)->order('id asc')->select()->toArray();
  197. $this->assign('itemList',$itemList);
  198. $where[] = ['create_time','>=',$start];
  199. $where[] = ['create_time','<=',$end];
  200. $where[] = ['service_id','=',$serviceId];
  201. $where[] = ['org_id','=',$this->org_id];
  202. $data = [];
  203. foreach ($itemList as $k=>$v){
  204. $data[$k]['id']= $v['id'];
  205. $data[$k]['title']= $v['title'];
  206. $bookList = Db::name('service_book')
  207. ->where('service_item_id',$v['id'])
  208. ->where($where)
  209. ->select()
  210. ->toArray();
  211. $total = 0;
  212. foreach ($bookList as $kay=>$val){
  213. $total +=$val['nums'];
  214. }
  215. $data[$k]['count'] = $total;
  216. }
  217. $countNum = 0;
  218. foreach ($data as $kay =>$val){
  219. $countNum += $val['count'];
  220. }
  221. $this->assign('countNum',$countNum);
  222. }
  223. $this->assign('start',$start);
  224. $this->assign('end',$end);
  225. $this->assign('data',$data);
  226. $this->assign('type',$type);
  227. $this->assign('meta_title',$meta_title);
  228. return $this->fetch();
  229. }
  230. public function serviceCountDetails(){
  231. $month = input('month');
  232. $itemId = input('itemId',0);
  233. $serviceId = input('serviceId',0);
  234. if(!$month && !$itemId){
  235. $this->error('参数错误');
  236. }
  237. $startMonth = $month.'-1 00:00:00';
  238. $endMonth = $month.'-31 23:59:59';
  239. $sWeek = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
  240. $eWeek = date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600));
  241. $startWeek = $sWeek.' 00:00:00';
  242. $endWeek = $eWeek.' 23:59:59';
  243. $day = date('Y-m-d');
  244. $startDay= $day.' 00:00:00';
  245. $endDay= $day.' 23:59:59';
  246. $cateList = Db::name('service_cate')->where('service_id',$serviceId)->where('enable',1)->select()->toArray();
  247. foreach ($cateList as $k=>$v){
  248. $bookCate = Db::name('service_book_cate')
  249. ->where('service_book_cate_id',$v['id'])
  250. ->select()
  251. ->toArray();
  252. $ids = [];
  253. foreach ($bookCate as $kay=>$val){
  254. $ids[] = $val['service_book_id'];
  255. }
  256. $newIds = array_unique($ids);
  257. $bookList = Db::name('service_book')
  258. ->whereIn('id',$newIds)
  259. ->where('service_item_id',$itemId)
  260. ->where('service_id',$serviceId)
  261. ->where('org_id',$this->org_id)
  262. ->whereTime('create_time', 'between', [$startMonth, $endMonth])
  263. ->select()->toArray();
  264. $nums = 0;
  265. foreach ($bookList as $kk=>$vv){
  266. $nums +=$vv['nums'];
  267. }
  268. $bookList1 = Db::name('service_book')
  269. ->whereIn('id',$newIds)
  270. ->where('service_item_id',$itemId)
  271. ->where('service_id',$serviceId)
  272. ->where('org_id',$this->org_id)
  273. ->whereTime('create_time', 'between', [$startWeek, $endWeek])
  274. ->select()->toArray();
  275. $nums1 = 0;
  276. foreach ($bookList1 as $kk=>$vv){
  277. $nums1 +=$vv['nums'];
  278. }
  279. $bookList2 = Db::name('service_book')
  280. ->whereIn('id',$newIds)
  281. ->where('service_item_id',$itemId)
  282. ->where('service_id',$serviceId)
  283. ->where('org_id',$this->org_id)
  284. ->whereTime('create_time', 'between', [$startDay, $endDay])
  285. ->select()->toArray();
  286. $nums2 = 0;
  287. foreach ($bookList2 as $kk=>$vv){
  288. $nums2 +=$vv['nums'];
  289. }
  290. $cateList[$k]['count'] = $nums;
  291. $cateList[$k]['week'] = $nums1;
  292. $cateList[$k]['day'] = $nums2;
  293. }
  294. $this->assign('meta_title','餐厅统计');
  295. $this->assign('data',$cateList);
  296. return $this->fetch();
  297. }
  298. public function userWork()
  299. {
  300. if(request()->isAjax()){
  301. //分页参数
  302. $length = input('rows',10,'intval'); //每页条数
  303. $page = input('page',1,'intval'); //第几页
  304. $start = ($page - 1) * $length; //分页开始位置
  305. //排序
  306. $sortRow = input('sidx','id','trim'); //排序列
  307. $sort = input('sord','desc','trim'); //排序方式
  308. $order = $sortRow.' '.$sort;
  309. $title = input('title','','trim');
  310. if($title){
  311. $map[] = ['u.nickname','like','%'.$title.'%'];
  312. }
  313. $map= empty($map) ? true: $map;
  314. $ret = Db::name('user')
  315. ->alias('u')
  316. ->field('u.id,u.nickname')
  317. ->join('user_org uo', 'uo.user_id=u.id')
  318. ->where('uo.org_id', $this->org_id)
  319. ->where('u.enable', 1)
  320. ->where('u.del', 0)
  321. ->where($map)
  322. ->limit($start,$length)
  323. ->order($order)
  324. ->select()
  325. ->toArray();
  326. foreach ($ret as $k => $v) {
  327. //获取本月开始时间结束时间
  328. $smonth = date('Y-m') . '-1 00:00:00';
  329. $emonth = date('Y-m') . '-31 23:59:59';
  330. $where[] = ['update_time','>=',$smonth];
  331. $where[] = ['update_time','<=',$emonth];
  332. $userWork = Db::name('user_work')
  333. ->where('user_id', $v['id'])
  334. ->where($where)
  335. ->whereNotNull('start_time')
  336. ->whereNotNull('end_time')
  337. ->select()
  338. ->toArray();
  339. $num = 0;
  340. foreach ($userWork as $kk => $vv) {
  341. $stime = strtotime($vv['start_time']);
  342. $etime = strtotime($vv['end_time']);
  343. $newTime = $etime - $stime;
  344. $num += $newTime;
  345. }
  346. $ret[$k]['month'] = $num;
  347. //获取本周开始时间 结束时间
  348. $sweek = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)) . ' 00:00:00';
  349. $eweek = date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)) . ' 23:59:59';
  350. $where2[] = ['update_time','>=',$sweek];
  351. $where2[] = ['update_time','<=',$eweek];
  352. $userWork2 = Db::name('user_work')
  353. ->where('user_id', $v['id'])
  354. ->where($where2)
  355. ->whereNotNull('start_time')
  356. ->whereNotNull('end_time')
  357. ->select()->toArray();
  358. $num2 = 0;
  359. foreach ($userWork2 as $kk => $vv) {
  360. $stime = strtotime($vv['start_time']);
  361. $etime = strtotime($vv['end_time']);
  362. $newTime = $etime - $stime;
  363. $num2 += $newTime;
  364. }
  365. $ret[$k]['week'] = $num2;
  366. //获取今天开始时间 结束时间
  367. $sday = date('Y-m-d') . ' 00:00:00';
  368. $eday = date('Y-m-d') . ' 23:59:59';
  369. $where3[] = ['update_time','>=',$sday];
  370. $where3[] = ['update_time','<=',$eday];
  371. $userWork3 = Db::name('user_work')
  372. ->where('user_id', $v['id'])
  373. ->where($where3)
  374. ->whereNotNull('start_time')
  375. ->whereNotNull('end_time')
  376. ->select()->toArray();
  377. $num3 = 0;
  378. foreach ($userWork3 as $kk => $vv) {
  379. $stime = strtotime($vv['start_time']);
  380. $etime = strtotime($vv['end_time']);
  381. $newTime = $etime - $stime;
  382. $num3 += $newTime;
  383. }
  384. $ret[$k]['day'] = $num3;
  385. }
  386. //数据返回
  387. $totalCount = Db::name('user')
  388. ->alias('u')
  389. ->field('u.id,u.nickname')
  390. ->join('user_org uo', 'uo.user_id=u.id')
  391. ->where('uo.org_id', $this->org_id)
  392. ->where('u.enable', 1)
  393. ->where('u.del', 0)
  394. ->where($map)
  395. ->count();;
  396. $totalPage = ceil($totalCount/$length);
  397. $result['page'] = $page;
  398. $result['total'] = $totalPage;
  399. $result['records'] = $totalCount;
  400. $result['rows'] = $ret;
  401. return json($result);
  402. }else{
  403. $this->assign('meta_title','用户工作时长统计');
  404. return $this->fetch();
  405. }
  406. }
  407. //耗材统计
  408. public function mateItems(){
  409. $month = input('month','','trim');
  410. if($month){
  411. $smonth = $month.'-01 :00:00:00';
  412. $emonth = $month.'-31 :23:59:59';
  413. $where[] = ['t.done_time','>=',$smonth];
  414. $where[] = ['t.done_time','<=',$emonth];
  415. }else{
  416. //本月
  417. $month = date('Y-m');
  418. $sdate = date('Y-m').'-01 :00:00:00';
  419. $edate = date('Y-m').'-31 :23:59:59';
  420. $where[] = ['t.done_time','>=',$sdate];
  421. $where[] = ['t.done_time','<=',$edate];
  422. //本周
  423. $sweek = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)) . ' 00:00:00';
  424. $eweek = date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)) . ' 23:59:59';
  425. $where2[] = ['t.done_time','>=',$sweek];
  426. $where2[] = ['t.done_time','<=',$eweek];
  427. //当天
  428. $sday = date('Y-m-d') . ' 00:00:00';
  429. $eday = date('Y-m-d') . ' 23:59:59';
  430. $where3[] = ['t.done_time','>=',$sday];
  431. $where3[] = ['t.done_time','<=',$eday];
  432. }
  433. $map[] = ['enable','=',1];
  434. $map[] = ['org_id','=',$this->org_id];
  435. $map= empty($map) ? true: $map;
  436. $ret = Db::name('dep')->where($map)->select()->toArray();
  437. foreach ($ret as $k=>$v){
  438. //本月
  439. $todo = Db::name('todo')
  440. ->alias('t')
  441. ->field('t.id,t.to_user_id,t.mate_price')
  442. ->join('user_dep ud','ud.user_id=t.to_user_id')
  443. ->where('ud.dep_id',$v['id'])
  444. ->where('t.todo_mode',3)
  445. ->where('t.del',0)
  446. ->where('t.org_id',$this->org_id)
  447. ->where($where)
  448. ->select()
  449. ->toArray();
  450. $total = 0;
  451. foreach ($todo as $kk=>$vv){
  452. $total +=$vv['mate_price'];
  453. }
  454. $ret[$k]['month'] = $total;
  455. //本周
  456. $ret[$k]['week'] = 0;
  457. if(!empty($where2)){
  458. $todo = Db::name('todo')
  459. ->alias('t')
  460. ->field('t.id,t.to_user_id,t.mate_price')
  461. ->join('user_dep ud','ud.user_id=t.to_user_id')
  462. ->where('ud.dep_id',$v['id'])
  463. ->where('t.todo_mode',3)
  464. ->where('t.del',0)
  465. ->where('t.org_id',$this->org_id)
  466. ->where($where2)
  467. ->select()
  468. ->toArray();
  469. $total2 = 0;
  470. foreach ($todo as $kk=>$vv){
  471. $total2 +=$vv['mate_price'];
  472. }
  473. $ret[$k]['week'] = $total2;
  474. }
  475. $ret[$k]['day'] = 0;
  476. if(!empty($where3)){
  477. //当天
  478. $todo = Db::name('todo')
  479. ->alias('t')
  480. ->field('t.id,t.to_user_id,t.mate_price')
  481. ->join('user_dep ud','ud.user_id=t.to_user_id')
  482. ->where('ud.dep_id',$v['id'])
  483. ->where('t.todo_mode',3)
  484. ->where('t.del',0)
  485. ->where('t.org_id',$this->org_id)
  486. ->where($where3)
  487. ->select()
  488. ->toArray();
  489. $total3 = 0;
  490. foreach ($todo as $kk=>$vv){
  491. $total3 +=$vv['mate_price'];
  492. }
  493. $ret[$k]['day'] = $total3;
  494. }
  495. }
  496. $this->assign('data',$ret);
  497. $this->assign('month',$month);
  498. $this->assign('meta_title','耗材统计列表');
  499. return $this->fetch();
  500. }
  501. public function mateItemsDetails($id,$month){
  502. $sdate = $month.'-1 00:00:00';
  503. $edate = $month.'-31 23:59:59';
  504. $map[] = ['t.done_time','>=',$sdate];
  505. $map[] = ['t.done_time','<=',$edate];
  506. if(request()->isAjax()){
  507. //分页参数
  508. $length = input('rows',10,'intval'); //每页条数
  509. $page = input('page',1,'intval'); //第几页
  510. $start = ($page - 1) * $length; //分页开始位置
  511. //排序
  512. $sortRow = input('sidx','id','trim'); //排序列
  513. $sort = input('sord','desc','trim'); //排序方式
  514. $order = $sortRow.' '.$sort;
  515. $ret = Db::name('todo')
  516. ->alias('t')
  517. ->field('t.to_user_id,tmi.*')
  518. ->join('user_dep ud','ud.user_id=t.to_user_id')
  519. ->join('todo_mate_item tmi','tmi.todo_id=t.id')
  520. ->where('ud.dep_id',$id)
  521. ->where('t.todo_mode',3)
  522. ->where('t.del',0)
  523. ->where('t.org_id',$this->org_id)
  524. ->where($map)
  525. ->limit($start,$length)
  526. ->order($order)
  527. ->select()
  528. ->toArray();
  529. foreach ($ret as $k=>$v){
  530. $ret[$k]['title']=Db::name('mate_items')
  531. ->where('id',$v['items_id'])
  532. ->value('title');
  533. $ret[$k]['nickname']=Db::name('user')
  534. ->where('id',$v['to_user_id'])
  535. ->value('nickname');
  536. }
  537. //数据返回
  538. $totalCount = Db::name('todo')
  539. ->alias('t')
  540. ->field('tmi.*')
  541. ->join('user_dep ud','ud.user_id=t.to_user_id')
  542. ->join('todo_mate_item tmi','tmi.todo_id=t.id')
  543. ->where('ud.dep_id',$id)
  544. ->where('t.todo_mode',3)
  545. ->where('t.del',0)
  546. ->where('t.org_id',$this->org_id)
  547. ->where($map)
  548. ->count();
  549. $totalPage = ceil($totalCount/$length);
  550. $result['page'] = $page;
  551. $result['total'] = $totalPage;
  552. $result['records'] = $totalCount;
  553. $result['rows'] = $ret;
  554. return json($result);
  555. }else{
  556. $this->assign('meta_title','部门使用耗材列表');
  557. $this->assign('id',$id);
  558. $this->assign('month',$month);
  559. return $this->fetch();
  560. }
  561. }
  562. //报修科室使用材料统计
  563. public function cltj(){
  564. $cur = date('Y-m-d');
  565. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  566. $end = input('end', date('Y-m-d'));
  567. $start1 = $start . ' 00:00:00';
  568. $end1 = $end . ' 23:59:59';
  569. $data = $this->cltjData($start1,$end1);
  570. $this->assign('data', $data);
  571. $this->assign('start', $start);
  572. $this->assign('end', $end);
  573. return $this->fetch();
  574. }
  575. public function cltjData($start,$end){
  576. $orgId = $this->orgId;
  577. $ret = Db::name('order_repair')
  578. ->alias('a')
  579. ->join('orders b','a.order_id=b.id')
  580. ->where('b.org_id',$orgId)
  581. ->where('a.address_id','>',0)
  582. ->field('a.address_id')
  583. ->distinct(true)
  584. ->select();
  585. $map = [];
  586. if(!empty($start)){
  587. $map[] = ['t.done_time','>=',$start];
  588. }
  589. if(!empty($end)){
  590. $map[] = ['t.done_time','<',$end];
  591. }
  592. $map[] = ['t.del','=',0];
  593. $map[] = ['t.org_id','=',$orgId];
  594. foreach ($ret as $k=>$v){
  595. $map1 = [];
  596. $todo = Db::name('todo_mate_item')
  597. ->alias('tmi')
  598. ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
  599. ->join('todo t','tm.todo_id = t.id')
  600. ->join('orders o','o.id = t.order_id')
  601. ->join('order_repair r','o.id = r.order_id')
  602. ->where('r.address_id',$v['address_id'])
  603. ->where($map)
  604. ->sum('tmi.total_money');
  605. $num =$todo?round($todo,2):0;
  606. if($num<=0){
  607. unset($ret[$k]);
  608. }else{
  609. $ret[$k]['month'] = $num;
  610. if(!empty($start)){
  611. $map1[] = ['t.done_time','>=',$start];
  612. }
  613. if(!empty($end)){
  614. $map1[] = ['t.done_time','<',$end];
  615. }
  616. $map1[] = ['t.del','=',0];
  617. $map1[] = ['t.org_id','=',$orgId];
  618. $map1[] = ['r.address_id','=',$v['address_id']];
  619. $lists =Db::name('todo_mate_item')
  620. ->alias('tmi')
  621. ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
  622. ->join('todo t','tm.todo_id = t.id')
  623. ->join('orders o','o.id = t.order_id')
  624. ->join('user u','u.id = t.to_user_id')
  625. ->join('order_repair r','o.id = r.order_id')
  626. ->join('mate_goods ma','ma.id = tmi.items_id')
  627. ->field('tmi.*,u.real_name,ma.title')
  628. ->where($map1)
  629. ->select();
  630. if(empty($lists)){
  631. unset($ret[$k]);
  632. continue;
  633. }
  634. $ret[$k]['rows'] = count($lists);
  635. $ret[$k]['items'] = $lists;
  636. $ret[$k]['title'] =Db::name('address')
  637. ->where('id',$v['address_id'])
  638. ->value('title');
  639. }
  640. }
  641. return $ret;
  642. }
  643. //耗材统计导出
  644. public function cltjExport()
  645. {
  646. set_time_limit(0);
  647. ini_set("memory_limit", "1024M");
  648. $cur = date('Y-m-d');
  649. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  650. $end = input('end', date('Y-m-d'));
  651. $start1 = $start . ' 00:00:00';
  652. $end1 = $end . ' 23:59:59';
  653. $data = $this->cltjData($start1,$end1);
  654. $title = '报修科室使用材料统计报表';
  655. header("Content-type: application/vnd.ms-excel");
  656. header("Content-Type: application/force-download");
  657. header("Content-Disposition: attachment; filename=".$title.".xls");
  658. header('Expires:0');
  659. header('Pragma:public');
  660. $res = '';
  661. $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
  662. $res.='<tr style="background: #ffffff;">';
  663. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">科室名称</th>';
  664. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">材料名称</th>';
  665. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">数量</th>';
  666. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">单价</th>';
  667. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总价</th>';
  668. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">小计</th>';
  669. $res.='</tr>';
  670. foreach ($data as $k=>$v){
  671. $res.='<tr style="background: #ffffff;">';
  672. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['title'].'</td>';
  673. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['title'].'</td>';
  674. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total'].'</td>';
  675. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['money'].'</td>';
  676. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total_money'].'</td>';
  677. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['month'].'</td>';
  678. $res.='</tr>';
  679. if(count($v['items']) >=2){
  680. foreach ($v['items'] as $k1=>$v1){
  681. if($k1>0){
  682. $res.='<tr style="background: #ffffff;">';
  683. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['title'].'</td>';
  684. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total'].'</td>';
  685. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['money'].'</td>';
  686. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total_money'].'</td>';
  687. $res.='</tr>';
  688. }
  689. }
  690. }
  691. }
  692. echo $res;
  693. }
  694. //员工维修工作量
  695. public function finishTime(){
  696. $cur = date('Y-m-d');
  697. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  698. $end = input('end', date('Y-m-d'));
  699. $start1 = $start . ' 00:00:00';
  700. $end1 = $end . ' 23:59:59';
  701. $data = $this->finishTimeData($start1,$end1);
  702. $this->assign('data', $data);
  703. $this->assign('start', $start);
  704. $this->assign('end', $end);
  705. return $this->fetch();
  706. }
  707. public function finishTimeData($start,$end) {
  708. $org_id = $this->orgId;
  709. $list = (new \app\common\model\WorkTypeMode())->getRolesUser(1,$this->orgId);
  710. $a = [];
  711. foreach ($list as $k=>$v){
  712. if($v['user']){
  713. foreach ($v['user'] as $k1=>$v1){
  714. $a[] = $v1;
  715. }
  716. }
  717. }
  718. $accepted = $nFinish=0;
  719. $list = $a;
  720. $map = [];
  721. if(!empty($start)){
  722. $map[] = ['todo.create_yyyymmdd','>=',date('Ymd',strtotime($start))];
  723. }
  724. if(!empty($end)){
  725. $map[] = ['todo.create_yyyymmdd','<=',date('Ymd',strtotime($end))];
  726. }
  727. foreach ($list as $k=>$v){
  728. $hs = 0;
  729. $orderList = Db::name('todo')
  730. ->alias('todo')
  731. ->where('todo.org_id',$org_id)
  732. ->where('todo.todo_mode',3)
  733. ->where('todo.to_user_id',$v['id'])
  734. ->where('todo.work_type_mode',1)
  735. ->where($map)
  736. ->select();
  737. foreach ($orderList as $k1=>$v1){
  738. $hs += strtotime($v1['done_time'])-strtotime($v1['create_time']);
  739. }
  740. $hszj = $hs >0?round($hs/3600,2):0;
  741. $list[$k]['hszj'] = $hszj;
  742. $wc_time = Db::name('todo')
  743. ->alias('todo')
  744. ->where('todo.org_id',$org_id)
  745. ->where('todo.todo_mode',3)
  746. ->where('todo.to_user_id',$v['id'])
  747. ->where('todo.work_type_mode',1)
  748. ->where($map)
  749. ->sum('todo.wc_time');
  750. $total = $wc_time?round($wc_time/3600,2):0;
  751. $list[$k]['total'] = $total;
  752. $nums = Db::name('todo')
  753. ->alias('todo')
  754. ->where('todo.org_id',$org_id)
  755. ->where('todo.todo_mode',3)
  756. ->where('todo.to_user_id',$v['id'])
  757. ->where('todo.work_type_mode',1)
  758. ->where($map)
  759. ->count();
  760. $list[$k]['num'] =$nums;
  761. if($nums>0){
  762. $avg = round($total/$nums,2);
  763. }else{
  764. $avg = 0;
  765. }
  766. $list[$k]['avg'] = $avg;
  767. $dep = Db::name('user_dep')
  768. ->alias('a')
  769. ->join('dep o','a.dep_id=o.id')
  770. ->where('a.user_id',$v['id'])
  771. ->field('o.title')
  772. ->find();
  773. $list[$k]['dep'] = $dep?$dep['title']:'';
  774. // 已接工
  775. $list[$k]['accepted'] = Db::name('todo')
  776. ->alias('todo')
  777. ->where('todo.org_id',$org_id)
  778. ->where('todo.todo_mode','>',1)
  779. ->where('todo.to_user_id',$v['id'])
  780. ->where('todo.work_type_mode',1)
  781. ->where($map)
  782. ->count();
  783. $accepted += $list[$k]['accepted'];
  784. // 未完工
  785. $list[$k]['nFinish'] = Db::name('todo')
  786. ->alias('todo')
  787. ->where('todo.org_id',$org_id)
  788. ->where('todo.todo_mode','in',[2,4,5,6,7,8])
  789. ->where('todo.to_user_id',$v['id'])
  790. ->where('todo.work_type_mode',1)
  791. ->where($map)
  792. ->count();
  793. $nFinish += $list[$k]['nFinish'];
  794. }
  795. return $list;
  796. }
  797. //excel导出
  798. public function finishTimeExport() {
  799. $meta_title = '维修人员工作时长';
  800. $cur = date('Y-m-d');
  801. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  802. $end = input('end', date('Y-m-d'));
  803. $start1 = $start . ' 00:00:00';
  804. $end1 = $end . ' 23:59:59';
  805. $ret = $this->finishTimeData($start1,$end1);
  806. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  807. //实例化PHPExcel类
  808. $objPHPExcel = new \PHPExcel();
  809. //激活当前的sheet表
  810. $objPHPExcel->setActiveSheetIndex(0);
  811. //设置表格头(即excel表格的第一行)
  812. $objPHPExcel->setActiveSheetIndex(0)
  813. ->setCellValue('A1', '姓名')
  814. ->setCellValue('B1', '班组名称')
  815. ->setCellValue('C1', '接工量')
  816. ->setCellValue('D1', '完工量')
  817. ->setCellValue('E1', '未完工量')
  818. ->setCellValue('F1', '维修耗时')
  819. ->setCellValue('G1', '工时总计');
  820. // 设置表格头水平居中
  821. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  822. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  823. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  824. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  825. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  826. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  827. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  828. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  829. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  830. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  831. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  832. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  833. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  834. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  835. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  836. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  837. //设置列水平居中
  838. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  839. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  840. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  841. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  842. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  843. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  844. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  845. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  846. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  847. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  848. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  849. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  850. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  851. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  852. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  853. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  854. //设置单元格宽度
  855. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  856. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  857. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  858. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  859. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  860. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
  861. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  862. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  863. //循环刚取出来的数组,将数据逐一添加到excel表格。
  864. for ($i = 0; $i < count($ret); $i++) {
  865. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['real_name']);
  866. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['dep']);
  867. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['accepted']);
  868. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $ret[$i]['num']);
  869. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $ret[$i]['nFinish']);
  870. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $ret[$i]['hszj']);
  871. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $ret[$i]['total']);
  872. }
  873. //设置保存的Excel表格名称
  874. $filename = '维修人员工作时长' . date('YmdHis', time()) . '.xls';
  875. //设置当前激活的sheet表格名称
  876. $objPHPExcel->getActiveSheet()->setTitle('维修人员工作时长');
  877. //设置浏览器窗口下载表格
  878. ob_end_clean();
  879. header("Content-Type: application/force-download");
  880. header("Content-Type: application/octet-stream");
  881. header("Content-Type: application/download");
  882. header('Content-Disposition:inline;filename="' . $filename);
  883. //生成excel文件
  884. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  885. //下载文件在浏览器窗口
  886. return $objWriter->save('php://output');
  887. }
  888. //班组维修工作量
  889. public function bzwx(){
  890. $cur = date('Y-m-d');
  891. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  892. $end = input('end', date('Y-m-d'));
  893. $title = input('title','');
  894. $start1 = $start . ' 00:00:00';
  895. $end1 = $end . ' 23:59:59';
  896. $data = $this->bzwxData($start1,$end1,$title);
  897. $this->assign('data', $data);
  898. $this->assign('start', $start);
  899. $this->assign('end', $end);
  900. $this->assign('title', $title);
  901. return $this->fetch();
  902. }
  903. public function bzwxData($start,$end,$title){
  904. $org_id = $this->orgId;
  905. $m = [];
  906. if(!empty($title)){
  907. $m[] =['title','like','%'.$title.'%'];
  908. }
  909. $list = Db::name('dep')
  910. ->where('del',0)
  911. ->where('enable',1)
  912. ->where('org_id',$org_id)
  913. ->select();
  914. $map = [];
  915. if(!empty($start)){
  916. $map[] = ['create_yyyymmdd','>=',date('Ymd',strtotime($start))];
  917. }
  918. if(!empty($end)){
  919. $map[] = ['create_yyyymmdd','<=',date('Ymd',strtotime($end))];
  920. }
  921. $accepted = $nFinish=0;
  922. foreach ($list as $k=>$v){
  923. $user = Db::name('user_dep')
  924. ->alias('b')
  925. ->join('user a','b.user_id=a.id')
  926. ->where('a.del',0)
  927. ->where('a.enable',1)
  928. ->where('b.dep_id',$v['id'])
  929. ->field('b.user_id')
  930. ->select();
  931. $ids = $user?array_column($user,'user_id'):[];
  932. $list[$k]['num'] =0;
  933. $list[$k]['accepted'] =0;
  934. $list[$k]['nFinish'] =0;
  935. if(!empty($ids)){
  936. $nums =Db::name('todo')
  937. ->where('org_id',$org_id)
  938. ->where('to_user_id','in',$ids)
  939. ->where('work_type_mode',1)
  940. ->where('todo_mode','in',[2,3,9])
  941. ->where($map)
  942. ->count();
  943. $list[$k]['num'] =$nums;
  944. // 已接工
  945. $list[$k]['accepted'] = Db::name('todo')
  946. ->where('org_id',$org_id)
  947. ->where('to_user_id','in',$ids)
  948. ->where('work_type_mode',1)
  949. ->where('todo_mode','>',1)
  950. ->where($map)
  951. ->count();
  952. $accepted += $list[$k]['accepted'];
  953. // 未完工
  954. $list[$k]['nFinish'] = Db::name('todo')
  955. ->where('org_id',$org_id)
  956. ->where('to_user_id','in',$ids)
  957. ->where('work_type_mode',1)
  958. ->where('todo_mode','in',[2,4,5,6,7])
  959. ->where($map)
  960. ->count();
  961. $nFinish += $list[$k]['nFinish'];
  962. if($nums==0 && $list[$k]['accepted']==0 && $list[$k]['nFinish']==0){
  963. unset($list[$k]);
  964. }
  965. }else{
  966. unset($list[$k]);
  967. }
  968. }
  969. return $list;
  970. }
  971. //excel导出
  972. public function bzwxExport() {
  973. $meta_title = '班组维修工作量统计表';
  974. $cur = date('Y-m-d');
  975. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  976. $end = input('end', date('Y-m-d'));
  977. $start1 = $start . ' 00:00:00';
  978. $end1 = $end . ' 23:59:59';
  979. $title = input('title','');
  980. $ret = $this->bzwxData($start1,$end1,$title);
  981. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  982. //实例化PHPExcel类
  983. $objPHPExcel = new \PHPExcel();
  984. //激活当前的sheet表
  985. $objPHPExcel->setActiveSheetIndex(0);
  986. //设置表格头(即excel表格的第一行)
  987. $objPHPExcel->setActiveSheetIndex(0)
  988. ->setCellValue('A1', '班组名称')
  989. ->setCellValue('B1', '接工量')
  990. ->setCellValue('C1', '完工量')
  991. ->setCellValue('D1', '未完工量');
  992. // 设置表格头水平居中
  993. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  994. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  995. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  996. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  997. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  998. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  999. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  1000. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1001. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  1002. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1003. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  1004. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1005. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  1006. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1007. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  1008. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1009. //设置列水平居中
  1010. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  1011. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1012. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  1013. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1014. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  1015. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1016. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  1017. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1018. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  1019. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1020. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  1021. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1022. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  1023. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1024. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  1025. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1026. //设置单元格宽度
  1027. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  1028. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  1029. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  1030. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  1031. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  1032. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
  1033. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  1034. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  1035. //循环刚取出来的数组,将数据逐一添加到excel表格。
  1036. for ($i = 0; $i < count($ret); $i++) {
  1037. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['title']);
  1038. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['accepted']);
  1039. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['num']);
  1040. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $ret[$i]['nFinish']);
  1041. }
  1042. //设置保存的Excel表格名称
  1043. $filename = '班组维修工作量统计表' . date('YmdHis', time()) . '.xls';
  1044. //设置当前激活的sheet表格名称
  1045. $objPHPExcel->getActiveSheet()->setTitle('班组维修工作量统计表');
  1046. //设置浏览器窗口下载表格
  1047. ob_end_clean();
  1048. header("Content-Type: application/force-download");
  1049. header("Content-Type: application/octet-stream");
  1050. header("Content-Type: application/download");
  1051. header('Content-Disposition:inline;filename="' . $filename);
  1052. //生成excel文件
  1053. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1054. //下载文件在浏览器窗口
  1055. return $objWriter->save('php://output');
  1056. }
  1057. public function bxks(){
  1058. $cur = date('Y-m-d');
  1059. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1060. $end = input('end', date('Y-m-d'));
  1061. $title = input('title','');
  1062. $start1 = $start . ' 00:00:00';
  1063. $end1 = $end . ' 23:59:59';
  1064. $data = $this->bxksData($start1,$end1,$title);
  1065. $this->assign('data', $data);
  1066. $this->assign('start', $start);
  1067. $this->assign('end', $end);
  1068. $this->assign('title', $title);
  1069. return $this->fetch();
  1070. }
  1071. public function bxksData($start,$end,$title){
  1072. $org_id = $this->orgId;
  1073. $map = [];
  1074. if(!empty($title)){
  1075. $ks = Db::name('address')
  1076. ->where('org_id',$org_id)
  1077. ->where('del',0)
  1078. ->where('enable',1)
  1079. ->where('title','like','%'.$title.'%')
  1080. ->select();
  1081. if(empty($ks)){
  1082. $map[] = ['a.address_id','=',-1];
  1083. }else{
  1084. $map[] = ['a.address_id','in',array_column($ks,'id')];
  1085. }
  1086. }
  1087. $ret =Db::name('order_repair')
  1088. ->alias('a')
  1089. ->join('orders b','a.order_id=b.id')
  1090. ->where('b.org_id',$org_id)
  1091. ->where('a.address_id','>',0)
  1092. ->where($map)
  1093. ->field('a.address_id')
  1094. ->distinct(true)
  1095. ->select();
  1096. if(!empty($start)){
  1097. $map1[] = ['t.create_yyyymmdd','>=',date('Ymd',strtotime($start))];
  1098. }
  1099. if(!empty($end)){
  1100. $map1[] = ['t.create_yyyymmdd','<=',date('Ymd',strtotime($end))];
  1101. }
  1102. $map1[] = ['t.del','=',0];
  1103. $map1[] = ['t.org_id','=',$org_id];
  1104. foreach ($ret as $k=>$v){
  1105. $num = Db::name('order_repair')
  1106. ->alias('a')
  1107. ->join('orders t','a.order_id = t.id')
  1108. ->where('a.address_id',$v['address_id'])
  1109. ->where($map1)
  1110. ->count();
  1111. $ret[$k]['num'] = $num;
  1112. $ret[$k]['title'] = Db::name('address')
  1113. ->where('id',$v['address_id'])
  1114. ->value('title');
  1115. }
  1116. return $ret;
  1117. }
  1118. //excel导出
  1119. public function bxksExport() {
  1120. $meta_title = '报修科室统计';
  1121. $cur = date('Y-m-d');
  1122. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1123. $end = input('end', date('Y-m-d'));
  1124. $start1 = $start . ' 00:00:00';
  1125. $end1 = $end . ' 23:59:59';
  1126. $title = input('title','');
  1127. $ret = $this->bxksData($start1,$end1,$title);
  1128. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  1129. //实例化PHPExcel类
  1130. $objPHPExcel = new \PHPExcel();
  1131. //激活当前的sheet表
  1132. $objPHPExcel->setActiveSheetIndex(0);
  1133. //设置表格头(即excel表格的第一行)
  1134. $objPHPExcel->setActiveSheetIndex(0)
  1135. ->setCellValue('A1', '科室名称')
  1136. ->setCellValue('B1', '报修订单数量');
  1137. // 设置表格头水平居中
  1138. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  1139. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1140. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  1141. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1142. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  1143. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1144. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  1145. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1146. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  1147. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1148. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  1149. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1150. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  1151. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1152. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  1153. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1154. //设置列水平居中
  1155. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  1156. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1157. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  1158. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1159. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  1160. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1161. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  1162. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1163. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  1164. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1165. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  1166. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1167. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  1168. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1169. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  1170. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1171. //设置单元格宽度
  1172. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  1173. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  1174. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  1175. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  1176. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  1177. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
  1178. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  1179. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  1180. //循环刚取出来的数组,将数据逐一添加到excel表格。
  1181. for ($i = 0; $i < count($ret); $i++) {
  1182. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['title']);
  1183. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['num']);
  1184. }
  1185. //设置保存的Excel表格名称
  1186. $filename = '报修科室统计' . date('YmdHis', time()) . '.xls';
  1187. //设置当前激活的sheet表格名称
  1188. $objPHPExcel->getActiveSheet()->setTitle('报修科室统计');
  1189. //设置浏览器窗口下载表格
  1190. ob_end_clean();
  1191. header("Content-Type: application/force-download");
  1192. header("Content-Type: application/octet-stream");
  1193. header("Content-Type: application/download");
  1194. header('Content-Disposition:inline;filename="' . $filename);
  1195. //生成excel文件
  1196. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1197. //下载文件在浏览器窗口
  1198. return $objWriter->save('php://output');
  1199. }
  1200. public function grcltj(){
  1201. $cur = date('Y-m-d');
  1202. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1203. $end = input('end', date('Y-m-d'));
  1204. $start1 = $start . ' 00:00:00';
  1205. $end1 = $end . ' 23:59:59';
  1206. $data = $this->grcltjData($start1,$end1);
  1207. $this->assign('data', $data);
  1208. $this->assign('start', $start);
  1209. $this->assign('end', $end);
  1210. return $this->fetch();
  1211. }
  1212. public function grcltjData($start,$end){
  1213. $orgId = $this->orgId;
  1214. $ret = Db::name('todo_mate')
  1215. ->alias('a')
  1216. ->join('todo b','a.todo_id=b.id')
  1217. ->field('a.*')
  1218. ->where('a.org_id',$orgId)
  1219. ->where('a.type',0)
  1220. ->where('b.del',0)
  1221. ->group('a.user_id')
  1222. ->select();
  1223. $map = [];
  1224. if(!empty($start)){
  1225. $map[] = ['tmi.create_time','>=',$start];
  1226. }
  1227. if(!empty($end)){
  1228. $map[] = ['tmi.create_time','<',$end];
  1229. }
  1230. $map[] = ['t.del','=',0];
  1231. $map[] = ['tm.org_id','=',$orgId];
  1232. foreach ($ret as $k=>$v){
  1233. $map1 = [];
  1234. $todo = Db::name('todo_mate_item')
  1235. ->alias('tmi')
  1236. ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
  1237. ->join('todo t','tm.todo_id = t.id')
  1238. ->join('orders o','o.id = t.order_id')
  1239. ->where('tmi.user_id',$v['user_id'])
  1240. ->where($map)
  1241. ->sum('tmi.total_money');
  1242. $num =$todo?round($todo,2):0;
  1243. if($num<=0){
  1244. unset($ret[$k]);
  1245. }else{
  1246. $ret[$k]['month'] = $num;
  1247. if(!empty($start)){
  1248. $map1[] = ['t.create_time','>=',$start];
  1249. }
  1250. if(!empty($end)){
  1251. $map1[] = ['t.create_time','<',$end];
  1252. }
  1253. $map1[] = ['t.del','=',0];
  1254. $map1[] = ['t.org_id','=',$orgId];
  1255. $map1[] = ['tm.user_id','=',$v['user_id']];
  1256. $lists =Db::name('todo_mate_item')
  1257. ->alias('tmi')
  1258. ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
  1259. ->join('todo t','tm.todo_id = t.id')
  1260. ->join('orders o','o.id = t.order_id')
  1261. ->join('user u','u.id = t.to_user_id')
  1262. ->join('mate_goods ma','ma.id = tmi.items_id')
  1263. ->field('tmi.*,u.real_name,ma.title')
  1264. ->where($map1)
  1265. ->select();
  1266. if(empty($lists)){
  1267. unset($ret[$k]);
  1268. continue;
  1269. }
  1270. $ret[$k]['rows'] = count($lists);
  1271. $ret[$k]['items'] = $lists;
  1272. $ret[$k]['real_name'] = Db::name('user')
  1273. ->where('id',$v['user_id'])
  1274. ->value('real_name');
  1275. }
  1276. }
  1277. return $ret;
  1278. }
  1279. public function grcltjExport()
  1280. {
  1281. set_time_limit(0);
  1282. ini_set("memory_limit", "1024M");
  1283. $cur = date('Y-m-d');
  1284. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1285. $end = input('end', date('Y-m-d'));
  1286. $start1 = $start . ' 00:00:00';
  1287. $end1 = $end . ' 23:59:59';
  1288. $data = $this->grcltjData($start1,$end1);
  1289. $title = '工人耗材用量统计';
  1290. header("Content-type: application/vnd.ms-excel");
  1291. header("Content-Type: application/force-download");
  1292. header("Content-Disposition: attachment; filename=".$title.".xls");
  1293. header('Expires:0');
  1294. header('Pragma:public');
  1295. $res = '';
  1296. $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
  1297. $res.='<tr style="background: #ffffff;">';
  1298. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">工人名称</th>';
  1299. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">材料名称</th>';
  1300. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">数量</th>';
  1301. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">单价</th>';
  1302. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总价</th>';
  1303. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用时间</th>';
  1304. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">小计</th>';
  1305. $res.='</tr>';
  1306. foreach ($data as $k=>$v){
  1307. $res.='<tr style="background: #ffffff;">';
  1308. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['real_name'].'</td>';
  1309. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['title'].'</td>';
  1310. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total'].'</td>';
  1311. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['money'].'</td>';
  1312. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total_money'].'</td>';
  1313. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['create_time'].'</td>';
  1314. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['month'].'</td>';
  1315. $res.='</tr>';
  1316. if(count($v['items']) >=2){
  1317. foreach ($v['items'] as $k1=>$v1){
  1318. if($k1>0){
  1319. $res.='<tr style="background: #ffffff;">';
  1320. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['title'].'</td>';
  1321. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total'].'</td>';
  1322. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['money'].'</td>';
  1323. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total_money'].'</td>';
  1324. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['create_time'].'</td>';
  1325. $res.='</tr>';
  1326. }
  1327. }
  1328. }
  1329. }
  1330. echo $res;
  1331. }
  1332. public function bxrcltj(){
  1333. $cur = date('Y-m-d');
  1334. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1335. $end = input('end', date('Y-m-d'));
  1336. $start1 = $start . ' 00:00:00';
  1337. $end1 = $end . ' 23:59:59';
  1338. $data = $this->bxrcltjData($start1,$end1);
  1339. $this->assign('data', $data);
  1340. $this->assign('start', $start);
  1341. $this->assign('end', $end);
  1342. return $this->fetch();
  1343. }
  1344. public function bxrcltjData($start,$end){
  1345. $orgId = $this->orgId;
  1346. $ret = Db::name('orders')
  1347. ->alias('a')
  1348. ->where('org_id',$orgId)
  1349. ->where('del',0)
  1350. ->where('finish_time','>=',$start)
  1351. ->where('finish_time','<',$end)
  1352. ->group('user_id')
  1353. ->select();
  1354. $map = [];
  1355. if(!empty($start)){
  1356. $map[] = ['t.done_time','>=',$start];
  1357. }
  1358. if(!empty($end)){
  1359. $map[] = ['t.done_time','<',$end];
  1360. }
  1361. $map[] = ['t.del','=',0];
  1362. $map[] = ['t.org_id','=',$orgId];
  1363. foreach ($ret as $k=>$v){
  1364. $map1 = [];
  1365. $todo = Db::name('todo_mate_item')
  1366. ->alias('tmi')
  1367. ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
  1368. ->join('todo t','tm.todo_id = t.id')
  1369. ->join('orders o','o.id = t.order_id')
  1370. ->where('o.user_id',$v['user_id'])
  1371. ->where($map)
  1372. ->sum('tmi.total_money');
  1373. $num =$todo?round($todo,2):0;
  1374. if($num<=0){
  1375. unset($ret[$k]);
  1376. }else{
  1377. $ret[$k]['month'] = $num;
  1378. if(!empty($start)){
  1379. $map1[] = ['t.done_time','>=',$start];
  1380. }
  1381. if(!empty($end)){
  1382. $map1[] = ['t.done_time','<',$end];
  1383. }
  1384. $map1[] = ['t.del','=',0];
  1385. $map1[] = ['t.org_id','=',$orgId];
  1386. $map1[] = ['o.user_id','=',$v['user_id']];
  1387. $lists =Db::name('todo_mate_item')
  1388. ->alias('tmi')
  1389. ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
  1390. ->join('todo t','tm.todo_id = t.id')
  1391. ->join('orders o','o.id = t.order_id')
  1392. ->join('user u','u.id = t.to_user_id')
  1393. ->join('mate_goods ma','ma.id = tmi.items_id')
  1394. ->field('tmi.*,u.real_name,ma.title')
  1395. ->where($map1)
  1396. ->select();
  1397. if(empty($lists)){
  1398. unset($ret[$k]);
  1399. continue;
  1400. }
  1401. $ret[$k]['rows'] = count($lists);
  1402. $ret[$k]['items'] = $lists;
  1403. $ret[$k]['title'] =Db::name('user')
  1404. ->where('id',$v['user_id'])
  1405. ->value('real_name');
  1406. }
  1407. }
  1408. return $ret;
  1409. }
  1410. //耗材统计导出
  1411. public function bxrcltjExport()
  1412. {
  1413. set_time_limit(0);
  1414. ini_set("memory_limit", "1024M");
  1415. $cur = date('Y-m-d');
  1416. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1417. $end = input('end', date('Y-m-d'));
  1418. $start1 = $start . ' 00:00:00';
  1419. $end1 = $end . ' 23:59:59';
  1420. $data = $this->bxrcltjData($start1,$end1);
  1421. $title = '报修人耗材统计报表';
  1422. header("Content-type: application/vnd.ms-excel");
  1423. header("Content-Type: application/force-download");
  1424. header("Content-Disposition: attachment; filename=".$title.".xls");
  1425. header('Expires:0');
  1426. header('Pragma:public');
  1427. $res = '';
  1428. $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
  1429. $res.='<tr style="background: #ffffff;">';
  1430. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">报修人</th>';
  1431. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">材料名称</th>';
  1432. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">数量</th>';
  1433. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">单价</th>';
  1434. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用人</th>';
  1435. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用时间</th>';
  1436. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总价</th>';
  1437. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">小计</th>';
  1438. $res.='</tr>';
  1439. foreach ($data as $k=>$v){
  1440. $res.='<tr style="background: #ffffff;">';
  1441. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['title'].'</td>';
  1442. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['title'].'</td>';
  1443. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total'].'</td>';
  1444. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['money'].'</td>';
  1445. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['real_name'].'</td>';
  1446. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['create_time'].'</td>';
  1447. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total_money'].'</td>';
  1448. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['month'].'</td>';
  1449. $res.='</tr>';
  1450. if(count($v['items']) >=2){
  1451. foreach ($v['items'] as $k1=>$v1){
  1452. if($k1>0){
  1453. $res.='<tr style="background: #ffffff;">';
  1454. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['title'].'</td>';
  1455. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total'].'</td>';
  1456. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['money'].'</td>';
  1457. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['real_name'].'</td>';
  1458. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['create_time'].'</td>';
  1459. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total_money'].'</td>';
  1460. $res.='</tr>';
  1461. }
  1462. }
  1463. }
  1464. }
  1465. echo $res;
  1466. }
  1467. public function wlflcltj(){
  1468. $cur = date('Y-m-d');
  1469. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1470. $end = input('end', date('Y-m-d'));
  1471. $start1 = $start . ' 00:00:00';
  1472. $end1 = $end . ' 23:59:59';
  1473. $data = $this->wlflcltjData($start1,$end1);
  1474. $this->assign('data', $data);
  1475. $this->assign('start', $start);
  1476. $this->assign('end', $end);
  1477. return $this->fetch();
  1478. }
  1479. public function wlflcltjData($start,$end){
  1480. $orgId = $this->orgId;
  1481. $ret = Db::name('mate_cate')
  1482. ->where('org_id',$orgId)
  1483. ->where('del',0)
  1484. ->where('enable',1)
  1485. ->select();
  1486. $map = [];
  1487. if(!empty($start)){
  1488. $map[] = ['t.done_time','>=',$start];
  1489. }
  1490. if(!empty($end)){
  1491. $map[] = ['t.done_time','<',$end];
  1492. }
  1493. $map[] = ['t.del','=',0];
  1494. $map[] = ['t.org_id','=',$orgId];
  1495. foreach ($ret as $k=>$v){
  1496. $map1 = [];
  1497. $todo = Db::name('todo_mate_item')
  1498. ->alias('tmi')
  1499. ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
  1500. ->join('mate_goods mg','tmi.items_id=mg.id')
  1501. ->join('mate_cate mc','mg.cate_id = mc.id')
  1502. ->join('todo t','tm.todo_id = t.id')
  1503. ->join('orders o','o.id = t.order_id')
  1504. ->where('mc.id',$v['id'])
  1505. ->where($map)
  1506. ->sum('tmi.total_money');
  1507. $num =$todo?round($todo,2):0;
  1508. if($num<=0){
  1509. unset($ret[$k]);
  1510. }else{
  1511. $ret[$k]['month'] = $num;
  1512. if(!empty($start)){
  1513. $map1[] = ['t.done_time','>=',$start];
  1514. }
  1515. if(!empty($end)){
  1516. $map1[] = ['t.done_time','<',$end];
  1517. }
  1518. $map1[] = ['t.del','=',0];
  1519. $map1[] = ['t.org_id','=',$orgId];
  1520. $map1[] = ['mc.id','=',$v['id']];
  1521. $lists =Db::name('todo_mate_item')
  1522. ->alias('tmi')
  1523. ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
  1524. ->join('mate_goods mg','tmi.items_id=mg.id')
  1525. ->join('mate_cate mc','mg.cate_id = mc.id')
  1526. ->join('todo t','tm.todo_id = t.id')
  1527. ->join('orders o','o.id = t.order_id')
  1528. ->join('user u','u.id = t.to_user_id')
  1529. ->join('mate_goods ma','ma.id = tmi.items_id')
  1530. ->field('tmi.*,u.real_name,ma.title')
  1531. ->where($map1)
  1532. ->select();
  1533. if(empty($lists)){
  1534. unset($ret[$k]);
  1535. continue;
  1536. }
  1537. $ret[$k]['rows'] = count($lists);
  1538. $ret[$k]['items'] = $lists;
  1539. }
  1540. }
  1541. return $ret;
  1542. }
  1543. //耗材统计导出
  1544. public function wlflcltjExport()
  1545. {
  1546. set_time_limit(0);
  1547. ini_set("memory_limit", "1024M");
  1548. $cur = date('Y-m-d');
  1549. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1550. $end = input('end', date('Y-m-d'));
  1551. $start1 = $start . ' 00:00:00';
  1552. $end1 = $end . ' 23:59:59';
  1553. $data = $this->wlflcltjData($start1,$end1);
  1554. $title = '物料分类统计报表';
  1555. header("Content-type: application/vnd.ms-excel");
  1556. header("Content-Type: application/force-download");
  1557. header("Content-Disposition: attachment; filename=".$title.".xls");
  1558. header('Expires:0');
  1559. header('Pragma:public');
  1560. $res = '';
  1561. $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
  1562. $res.='<tr style="background: #ffffff;">';
  1563. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">分类名称</th>';
  1564. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">材料名称</th>';
  1565. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">数量</th>';
  1566. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">单价</th>';
  1567. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用人</th>';
  1568. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用时间</th>';
  1569. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总价</th>';
  1570. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">小计</th>';
  1571. $res.='</tr>';
  1572. foreach ($data as $k=>$v){
  1573. $res.='<tr style="background: #ffffff;">';
  1574. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['title'].'</td>';
  1575. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['title'].'</td>';
  1576. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total'].'</td>';
  1577. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['money'].'</td>';
  1578. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['real_name'].'</td>';
  1579. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['create_time'].'</td>';
  1580. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total_money'].'</td>';
  1581. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['month'].'</td>';
  1582. $res.='</tr>';
  1583. if(count($v['items']) >=2){
  1584. foreach ($v['items'] as $k1=>$v1){
  1585. if($k1>0){
  1586. $res.='<tr style="background: #ffffff;">';
  1587. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['title'].'</td>';
  1588. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total'].'</td>';
  1589. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['money'].'</td>';
  1590. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['real_name'].'</td>';
  1591. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['create_time'].'</td>';
  1592. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total_money'].'</td>';
  1593. $res.='</tr>';
  1594. }
  1595. }
  1596. }
  1597. }
  1598. echo $res;
  1599. }
  1600. public function wxOrderTj(){
  1601. $cur = date('Y-m-d');
  1602. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1603. $end = input('end', date('Y-m-d'));
  1604. $title = input('title','');
  1605. $cateId = input('cateId','');
  1606. $goodsId = input('goodsId','');
  1607. $start1 = $start . ' 00:00:00';
  1608. $end1 = $end . ' 23:59:59';
  1609. $data = $this->wxOrderTjData($start1,$end1,$title,$cateId);
  1610. $cateList = model('WxGoodsCate')->lists($this->orgId);
  1611. $this->assign('cateList', $cateList);
  1612. $this->assign('data', $data);
  1613. $this->assign('start', $start);
  1614. $this->assign('end', $end);
  1615. $this->assign('title', $title);
  1616. $this->assign('cateId', $cateId?explode(',',$cateId):"");
  1617. $this->assign('goodsId', $goodsId?explode(',',$goodsId):"");
  1618. $glist = Db::name('wx_goods')->where('org_id',$this->orgId)->where('enable',1)->where('del',0)->select();
  1619. $this->assign('glist', $glist);
  1620. return $this->fetch();
  1621. }
  1622. public function wxOrderTjData($start,$end,$title,$cateId){
  1623. $org_id = $this->orgId;
  1624. $map = [];
  1625. $goodsId = input('goodsId','');
  1626. if(!empty($title)){
  1627. $map[] = ['g.title','like','%'.$title.'%'];
  1628. }
  1629. if(!empty($cateId)){
  1630. $map[] = ['g.cate_id','in',explode(',',$cateId)];
  1631. }
  1632. if(!empty($goodsId)){
  1633. $map[] = ['g.id','in',explode(',',$goodsId)];
  1634. }
  1635. if(!empty($start)){
  1636. $map[] = ['a.create_time','>=',$start];
  1637. }
  1638. if(!empty($end)){
  1639. $map[] = ['a.create_time','<=',$end];
  1640. }
  1641. $map[] = ['a.status','in',[1,2,3,5]];
  1642. $map[] = ['a.del','=',0];
  1643. $map[] = ['a.org_id','=',$org_id];
  1644. $ret =Db::name('wx_orders')
  1645. ->alias('a')
  1646. ->join('wx_orders_goods b','a.id=b.order_id')
  1647. ->join('wx_goods g','b.goods_id=g.id')
  1648. ->join('wx_goods_cate ca','g.cate_id=ca.id')
  1649. ->where($map)
  1650. ->field('b.goods_id,a.id,sum(b.nums) as num,b.price,g.title,ca.title as cateName')
  1651. ->group('b.goods_id')
  1652. ->select();
  1653. $total = 0;
  1654. foreach ($ret as $k=>$v){
  1655. $refund = Db::name('wx_orders_refund')
  1656. ->where('order_id',$v['id'])
  1657. ->where('goods_id',$v['goods_id'])
  1658. ->where('del',0)
  1659. ->where('status','in',[0,1])
  1660. ->find();
  1661. $num = $v['num'];
  1662. if($refund){
  1663. $num = $v['num']-$refund['num'];
  1664. }
  1665. if($num==0){
  1666. unset($ret[$k]);
  1667. }else{
  1668. $t = $num*$v['price'];
  1669. $total+=$t;
  1670. $ret[$k]['total'] = $num*$v['price'];
  1671. $ret[$k]['num'] = $num;
  1672. }
  1673. }
  1674. array_push($ret,[
  1675. 'title'=>'合计:',
  1676. 'cateName'=>'',
  1677. 'num'=>'',
  1678. 'price'=>'',
  1679. 'total'=>$total,
  1680. ]);
  1681. return $ret;
  1682. }
  1683. public function wxOrderTjExport(){
  1684. $cur = date('Y-m-d');
  1685. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  1686. $end = input('end', date('Y-m-d'));
  1687. $title = input('title','');
  1688. $cateId = input('cateId','');
  1689. $start1 = $start . ' 00:00:00';
  1690. $end1 = $end . ' 23:59:59';
  1691. $data = $this->wxOrderTjData($start1,$end1,$title,$cateId);
  1692. $header = [
  1693. ['title' => '商品名称', 'name' => 'title','width'=>'30'],
  1694. ['title' => '分类', 'name' => 'cateName','width'=>'30'],
  1695. ['title' => '数量', 'name' => 'num','width'=>'30'],
  1696. ['title' => '单价', 'name' => 'price','width'=>'80'],
  1697. ['title' => '总金额', 'name' => 'total','width'=>'30'],
  1698. ];
  1699. $filename = '销售统计';
  1700. ExcelUtil::export($filename,$header,$data);
  1701. }
  1702. public function wxOrderView(){
  1703. $startY = beginYear();
  1704. $zjygy = date('Y-m-d 00:00:00',time()-(30*86400));
  1705. $type = input('type/d',0);
  1706. if(request()->isPost()){
  1707. $dataTitle = [];
  1708. $dataValue = [];
  1709. $dataValue1 = [];
  1710. $map[] = ['org_id','=',$this->orgId];
  1711. $map[] = ['del','=',0];
  1712. $map[] = ['status','in',[1,2,3,5]];
  1713. $ddzs = 0;
  1714. $ddbl=0;
  1715. $ddzt=0;//0持平1上升2下降
  1716. $yzfdd=0;
  1717. $yzfbl=0;
  1718. $yzfzt=0;//0持平1上升2下降
  1719. $ddze=0;
  1720. $ddzebl=0;
  1721. $ddzezt=0;//0持平1上升2下降
  1722. $map1[] = ['org_id','=',$this->orgId];
  1723. $map1[] = ['del','=',0];
  1724. $cateList = model('WxGoodsCate')->lists($this->orgId);
  1725. $refund = Db::name('wx_orders_refund')
  1726. ->where('org_id','=',$this->orgId)
  1727. ->where('del',0)
  1728. ->where('status','in',[0,1])
  1729. ->column('goods_id');
  1730. $rMap = [];
  1731. if($refund){
  1732. $rMap[] = ['b.goods_id','not in',$refund];
  1733. }
  1734. if($type==0){
  1735. $title = getMinFromRange(date('Y-m-d 00:00:00'),date('Y-m-d H:i:s'));
  1736. foreach ($title as $k=>$v){
  1737. $dataTitle[] = date('H点',strtotime($v));
  1738. $dataValue[] = Db::name('wx_orders')
  1739. ->where($map)
  1740. ->where('create_yyyymmddhh','=',date('YmdH',strtotime($v)))
  1741. ->count();
  1742. $dataValue1[] = Db::name('wx_orders')
  1743. ->where($map)
  1744. ->where('create_yyyymmddhh','=',date('YmdH',strtotime($v)))
  1745. ->sum('amount');
  1746. }
  1747. $zt = date("Ymd",strtotime("-1 day"));
  1748. $ddzs =Db::name('wx_orders')
  1749. ->where($map1)
  1750. ->where('create_yyyymmdd','=',date('Ymd'))
  1751. ->count();
  1752. $ztzs = Db::name('wx_orders')
  1753. ->where($map1)
  1754. ->where('create_yyyymmdd','=',$zt)
  1755. ->count();
  1756. if($ztzs==$ddzs){
  1757. $ddzt = 0;
  1758. }elseif ($ztzs>$ddzs){
  1759. $ddzt = 2;
  1760. $ddbl = $ztzs>0?round((($ztzs-$ddzs)/$ztzs),2)*100:0;
  1761. }elseif ($ztzs<$ddzs){
  1762. $ddzt = 1;
  1763. $ddbl = $ddzs>0?round((($ddzs-$ztzs))/$ddzs,2)*100:0;
  1764. }
  1765. $yzfdd =Db::name('wx_orders')
  1766. ->where($map1)
  1767. ->where('status','in',[1,2,3,5])
  1768. ->where('create_yyyymmdd','=',date('Ymd'))
  1769. ->count();
  1770. $ztyzfdd = Db::name('wx_orders')
  1771. ->where($map1)
  1772. ->where('status','in',[1,2,3,5])
  1773. ->where('create_yyyymmdd','=',$zt)
  1774. ->count();
  1775. if($ztyzfdd==$yzfdd){
  1776. $yzfzt = 0;
  1777. }elseif ($ztyzfdd>$yzfdd){
  1778. $yzfzt = 2;
  1779. $yzfbl = $ztyzfdd>0?round((($ztyzfdd-$yzfdd)/$ztyzfdd),2)*100:0;
  1780. }elseif ($ztyzfdd<$yzfdd){
  1781. $yzfzt = 1;
  1782. $yzfbl = $yzfdd>0?round((($yzfdd-$ztyzfdd))/$yzfdd,2)*100:0;
  1783. }
  1784. $ddze =Db::name('wx_orders')
  1785. ->where($map1)
  1786. ->where('status','in',[1,2,3,5])
  1787. ->where('create_yyyymmdd','=',date('Ymd'))
  1788. ->sum('amount');
  1789. $ztddze = Db::name('wx_orders')
  1790. ->where($map1)
  1791. ->where('status','in',[1,2,3,5])
  1792. ->where('create_yyyymmdd','=',$zt)
  1793. ->sum('amount');
  1794. if($ztddze==$ddze){
  1795. $ddzezt = 0;
  1796. }elseif ($ztddze>$ddze){
  1797. $ddzezt = 2;
  1798. $ddzebl = $ztddze>0?round((($ztddze-$ddze)/$ztddze),2)*100:0;
  1799. }elseif ($ztddze<$ddze){
  1800. $ddzezt = 1;
  1801. $ddzebl = $ddze>0?round((($ddze-$ztddze))/$ddze,2)*100:0;
  1802. }
  1803. foreach ($cateList as $k=>$v){
  1804. $a = Db::name('wx_orders')
  1805. ->alias('a')
  1806. ->join('wx_orders_goods b','a.id=b.order_id')
  1807. ->join('wx_goods c','b.goods_id=c.id')
  1808. ->where('a.del','=',0)
  1809. ->where('a.org_id','=',$this->orgId)
  1810. ->where('c.cate_id','=',$v['id'])
  1811. ->where('a.status','in',[1,2,3,5])
  1812. ->where($rMap)
  1813. ->where('a.create_yyyymmdd','=',date('Ymd'))
  1814. ->sum('b.nums*b.price');
  1815. $cateList[$k]['total'] = $a?$a:0;
  1816. }
  1817. }elseif ($type==1){
  1818. $title = getDateFromRange(date('Y-m-01'),date('Y-m-d'));
  1819. foreach ($title as $k=>$v){
  1820. $dataTitle[] = date('Y-m-d',strtotime($v));
  1821. $dataValue[] = Db::name('wx_orders')
  1822. ->where($map)
  1823. ->where('create_yyyymmdd','=', date('Ymd',strtotime($v)))
  1824. ->count();
  1825. $dataValue1[] = Db::name('wx_orders')
  1826. ->where($map)
  1827. ->where('create_yyyymmdd','=', date('Ymd',strtotime($v)))
  1828. ->sum('amount');
  1829. }
  1830. $zt = date("Ym",strtotime("-1 month"));
  1831. $ddzs =Db::name('wx_orders')
  1832. ->where($map1)
  1833. ->where('create_yyyymm','=',date('Ym'))
  1834. ->count();
  1835. $ztzs = Db::name('wx_orders')
  1836. ->where($map1)
  1837. ->where('create_yyyymm','=',$zt)
  1838. ->count();
  1839. if($ztzs==$ddzs){
  1840. $ddzt = 0;
  1841. }elseif ($ztzs>$ddzs){
  1842. $ddzt = 2;
  1843. $ddbl = $ztzs>0?round((($ztzs-$ddzs)/$ztzs),2)*100:0;
  1844. }elseif ($ztzs<$ddzs){
  1845. $ddzt = 1;
  1846. $ddbl = $ddzs>0?round((($ddzs-$ztzs))/$ddzs,2)*100:0;
  1847. }
  1848. $yzfdd =Db::name('wx_orders')
  1849. ->where($map1)
  1850. ->where('status','in',[1,2,3,5])
  1851. ->where('create_yyyymm','=',date('Ym'))
  1852. ->count();
  1853. $ztyzfdd = Db::name('wx_orders')
  1854. ->where($map1)
  1855. ->where('status','in',[1,2,3,5])
  1856. ->where('create_yyyymm','=',$zt)
  1857. ->count();
  1858. if($ztyzfdd==$yzfdd){
  1859. $yzfzt = 0;
  1860. }elseif ($ztyzfdd>$yzfdd){
  1861. $yzfzt = 2;
  1862. $yzfbl = $ztyzfdd>0?round((($ztyzfdd-$yzfdd)/$ztyzfdd),2)*100:0;
  1863. }elseif ($ztyzfdd<$yzfdd){
  1864. $yzfzt = 1;
  1865. $yzfbl = $yzfdd>0?round((($yzfdd-$ztyzfdd))/$yzfdd,2)*100:0;
  1866. }
  1867. $ddze =Db::name('wx_orders')
  1868. ->where($map1)
  1869. ->where('status','in',[1,2,3,5])
  1870. ->where('create_yyyymm','=',date('Ym'))
  1871. ->sum('amount');
  1872. $ztddze = Db::name('wx_orders')
  1873. ->where($map1)
  1874. ->where('status','in',[1,2,3,5])
  1875. ->where('create_yyyymm','=',$zt)
  1876. ->sum('amount');
  1877. if($ztddze==$ddze){
  1878. $ddzezt = 0;
  1879. }elseif ($ztddze>$ddze){
  1880. $ddzezt = 2;
  1881. $ddzebl = $ztddze>0?round((($ztddze-$ddze)/$ztddze),2)*100:0;
  1882. }elseif ($ztddze<$ddze){
  1883. $ddzezt = 1;
  1884. $ddzebl = $ddze>0?round((($ddze-$ztddze))/$ddze,2)*100:0;
  1885. }
  1886. foreach ($cateList as $k=>$v){
  1887. $a = Db::name('wx_orders')
  1888. ->alias('a')
  1889. ->join('wx_orders_goods b','a.id=b.order_id')
  1890. ->join('wx_goods c','b.goods_id=c.id')
  1891. ->where('a.del','=',0)
  1892. ->where('a.org_id','=',$this->orgId)
  1893. ->where('c.cate_id','=',$v['id'])
  1894. ->where($rMap)
  1895. ->where('a.status','in',[1,2,3,5])
  1896. ->where('a.create_yyyymm','=',date('Ym'))
  1897. ->sum('b.nums*b.price');
  1898. $cateList[$k]['total'] = $a?$a:0;
  1899. }
  1900. }elseif ($type==2){
  1901. $title = getMonthFromRange($startY,date('Y-m-d H:i:s'));
  1902. foreach ($title as $k=>$v){
  1903. $dataTitle[] = date('Y-m',strtotime($v));
  1904. $dataValue[] = Db::name('wx_orders')
  1905. ->where($map)
  1906. ->where('create_yyyymm','=', date('Ym',strtotime($v)))
  1907. ->count();
  1908. $dataValue1[] = Db::name('wx_orders')
  1909. ->where($map)
  1910. ->where('create_yyyymm','=', date('Ym',strtotime($v)))
  1911. ->sum('amount');
  1912. }
  1913. $zt = date ( "Y" , strtotime ( "-1 year" ));
  1914. $ddzs =Db::name('wx_orders')
  1915. ->where($map1)
  1916. ->where('create_yyyy','=',date('Y'))
  1917. ->count();
  1918. $ztzs = Db::name('wx_orders')
  1919. ->where($map1)
  1920. ->where('create_yyyy','=',$zt)
  1921. ->count();
  1922. if($ztzs==$ddzs){
  1923. $ddzt = 0;
  1924. }elseif ($ztzs>$ddzs){
  1925. $ddzt = 2;
  1926. $ddbl = $ztzs>0?round((($ztzs-$ddzs)/$ztzs),2)*100:0;
  1927. }elseif ($ztzs<$ddzs){
  1928. $ddzt = 1;
  1929. $ddbl = $ddzs>0?round((($ddzs-$ztzs))/$ddzs,2)*100:0;
  1930. }
  1931. $yzfdd =Db::name('wx_orders')
  1932. ->where($map1)
  1933. ->where('status','in',[1,2,3,5])
  1934. ->where('create_yyyy','=',date('Y'))
  1935. ->count();
  1936. $ztyzfdd = Db::name('wx_orders')
  1937. ->where($map1)
  1938. ->where('status','in',[1,2,3,5])
  1939. ->where('create_yyyy','=',$zt)
  1940. ->count();
  1941. if($ztyzfdd==$yzfdd){
  1942. $yzfzt = 0;
  1943. }elseif ($ztyzfdd>$yzfdd){
  1944. $yzfzt = 2;
  1945. $yzfbl = $ztyzfdd>0?round((($ztyzfdd-$yzfdd)/$ztyzfdd),2)*100:0;
  1946. }elseif ($ztyzfdd<$yzfdd){
  1947. $yzfzt = 1;
  1948. $yzfbl = $yzfdd>0?round((($yzfdd-$ztyzfdd))/$yzfdd,2)*100:0;
  1949. }
  1950. $ddze =Db::name('wx_orders')
  1951. ->where($map1)
  1952. ->where('status','in',[1,2,3,5])
  1953. ->where('create_yyyy','=',date('Y'))
  1954. ->sum('amount');
  1955. $ztddze = Db::name('wx_orders')
  1956. ->where($map1)
  1957. ->where('status','in',[1,2,3,5])
  1958. ->where('create_yyyy','=',$zt)
  1959. ->sum('amount');
  1960. if($ztddze==$ddze){
  1961. $ddzezt = 0;
  1962. }elseif ($ztddze>$ddze){
  1963. $ddzezt = 2;
  1964. $ddzebl = $ztddze>0?round((($ztddze-$ddze)/$ztddze),2)*100:0;
  1965. }elseif ($ztddze<$ddze){
  1966. $ddzezt = 1;
  1967. $ddzebl = $ddze>0?round((($ddze-$ztddze))/$ddze,2)*100:0;
  1968. }
  1969. foreach ($cateList as $k=>$v){
  1970. $a = Db::name('wx_orders')
  1971. ->alias('a')
  1972. ->join('wx_orders_goods b','a.id=b.order_id')
  1973. ->join('wx_goods c','b.goods_id=c.id')
  1974. ->where('a.del','=',0)
  1975. ->where('a.org_id','=',$this->orgId)
  1976. ->where('c.cate_id','=',$v['id'])
  1977. ->where($rMap)
  1978. ->where('a.status','in',[1,2,3,5])
  1979. ->where('a.create_yyyy','=',date('Y'))
  1980. ->sum('b.nums*b.price');
  1981. $cateList[$k]['total'] = $a?$a:0;
  1982. }
  1983. }
  1984. if($cateList){
  1985. $vol = array_column($cateList,'total');
  1986. array_multisort($vol,SORT_DESC,$cateList);
  1987. }
  1988. $p = [
  1989. 'title'=>$dataTitle,
  1990. 'value'=>$dataValue,
  1991. 'value1'=>$dataValue1,
  1992. 'ddzs' => $ddzs,
  1993. 'ddbl' => $ddbl,
  1994. 'ddzt' => $ddzt,
  1995. 'yzfdd' => $yzfdd,
  1996. 'yzfbl' => $yzfbl,
  1997. 'yzfzt' => $yzfzt,
  1998. 'ddze' => $ddze,
  1999. 'ddzebl' => $ddzebl,
  2000. 'ddzezt' => $ddzezt,
  2001. 'cateList' => $cateList,
  2002. ];
  2003. $this->success('操作成功','',$p);
  2004. }else{
  2005. $map[] = ['org_id','=',$this->orgId];
  2006. $map[] = ['del','=',0];
  2007. $data['orderAmount'] = Db::name('wx_orders')
  2008. ->where($map)
  2009. ->where('status','in',[1,2,3,5])
  2010. ->where('create_yyyymm','=',date('Ym'))
  2011. ->sum('amount');
  2012. $data['orderCount'] = Db::name('wx_orders')
  2013. ->where($map)
  2014. ->where('status','in',[1,2,3,5])
  2015. ->where('create_yyyy','=',date('Y'))
  2016. ->count();
  2017. $data['orderUser'] = Db::name('wx_orders')
  2018. ->where($map)
  2019. ->where('status','in',[1,2,3,5])
  2020. ->where('create_yyyymmdd','=',date('Ymd'))
  2021. ->group('user_id')
  2022. ->count();
  2023. $beginMonth = beginMonth();
  2024. $data['refundCount'] = Db::name('wx_orders_refund')
  2025. ->where('org_id',$this->orgId)
  2026. ->where('status',1)
  2027. ->where('del',0)
  2028. ->where('create_time','>=',$beginMonth)
  2029. ->where('create_time','<=',getTime())
  2030. ->sum('money');
  2031. $this->assign('data',$data);
  2032. return $this->fetch();
  2033. }
  2034. }
  2035. }