Manage.php 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. <?php
  2. namespace Mail\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function getArea($name)
  7. {
  8. if (strstr($name, '|—')) {
  9. $temp = explode('|—', $name);
  10. return $temp[0] . '|—' . Dever::load("area/api.string", $temp[1]);
  11. } else {
  12. return Dever::load("area/api.string", $name);
  13. }
  14. }
  15. #代理商日数据统计
  16. public function day_api(){
  17. $day = Dever::input('day');
  18. if($day){
  19. $start = strtotime($day);
  20. $end = $start+86400-1;
  21. }else{
  22. $start=mktime(0,0,0,date('m'),date('d'),date('Y'));
  23. $end = $start+86400-1;
  24. }
  25. $time = Dever::maketime(date('Y-m-d'),'00:00:00');
  26. $where = array();
  27. $where['fstart'] = $start;
  28. $where['fend'] = $end;
  29. $w = array();
  30. $fstart = Dever::input('start', date('Y-m-01', $start));
  31. $w['fstart'] = Dever::maketime($fstart . ' 00:00:00');
  32. $w['fend'] = strtotime(date('Y-m-d 23:59:59',
  33. strtotime($fstart."+1 month - 1 day")));;
  34. $data = array();
  35. $data['start'] = date('Y-m-d',$start);
  36. $data['day'] = $this->content_api($where,1);
  37. $data['money'] = $this->c_api($where);
  38. $data['week'] = $this->zhou_api($start);
  39. $data['all'] = $this->content_api($w,2);
  40. $data['all_money'] = $this->c_api($w);
  41. $data['time'] = $this->day_time_api($w);
  42. $data['data'] = Dever::json_encode($data['time']);
  43. $data['money_time'] = $this->money_time_api($w);
  44. $data['qu_money'] = Dever::json_encode($data['money_time']);
  45. $data['xzhou'] = $this->button_day_api($w,1);
  46. $data['zhou'] = Dever::json_encode($data['xzhou']);
  47. return Dever::render('census', $data);
  48. }
  49. public function zhou_api($time='',$format="Y-m-d"){
  50. $time = $time != '' ? $time : time();
  51. $week = date('w', $time);
  52. $date = [];
  53. if($week == 0){
  54. $week = 7;
  55. }
  56. for ($i=1; $i<=7; $i++){
  57. $date[$i] = date($format ,strtotime( '+' . $i-$week .' days', $time));
  58. }
  59. $start = strtotime($date[1]);
  60. $end = strtotime($date[7])+86400-1;
  61. $where = array();
  62. $where['fstart'] = $start;
  63. $where['fend'] = $end;
  64. $data = array();
  65. $data['week'] = date('Y.m.d',$start).' - '.date('Y.m.d',$end);
  66. $data['all'] = $this->content_api($where,2);
  67. $data['all_money'] = $this->c_api($where);
  68. return $data;
  69. }
  70. #按时间统计
  71. public function content_api($where,$type){
  72. $data = array();
  73. if($type == 2){
  74. $data['time'] = date('Y.m',$where['fstart']);
  75. }elseif($type == 1){
  76. $data['time'] = date('Y.m.d',$where['fstart']);
  77. }
  78. #确认代理商订单数
  79. $where['status'] = 4;
  80. $data['num'] = Dever::db('agent/order')->getNum($where);
  81. #确认订单总费用
  82. $money = Dever::db('agent/order')->getCash($where);
  83. if($money['total']){
  84. $data['money'] = $money['total'];
  85. }else{
  86. $data['money'] = 0;
  87. }
  88. #确认代理费
  89. $dl_money = Dever::db('agent/order')->getDailiCash($where);
  90. if($dl_money['total']){
  91. $data['dl_money'] = $dl_money['total'];
  92. }else{
  93. $data['dl_money'] = 0;
  94. }
  95. #确认软件服务费
  96. $soft_money = Dever::db('agent/order')->getSoftCash($where);
  97. if($soft_money['total']){
  98. $data['soft_money'] = $soft_money['total'];
  99. }else{
  100. $data['soft_money'] = 0;
  101. }
  102. $wh['status'] = 3;
  103. $wh['fstart'] = $where['fstart'];
  104. $wh['fend'] = $where['fend'];
  105. $cash = Dever::db('agent/soft_cash')->getTotal($wh);
  106. if($cash['total']){
  107. $data['cash'] = $cash['total'];
  108. }else{
  109. $data['cash'] = 0;
  110. }
  111. $data['soft_cash'] = $data['soft_money'] + $data['cash'];
  112. #期权价值
  113. $option_money = Dever::db('agent/order')->getOptionPrice($where);
  114. if($option_money['total']){
  115. $data['option_money'] = $option_money['total'];
  116. }else{
  117. $data['option_money'] = 0;
  118. }
  119. return $data;
  120. }
  121. #各角色的金额,数量,原始期权价值,软件服务费
  122. public function c_api($where){
  123. $role = Dever::db('setting/role')->getAll(array('id'=>1,'state'=>1));
  124. foreach($role as $k => $v){
  125. $where['role'] = $v['id'];
  126. $data[$k]['name'] = $v['name'];
  127. $where['status'] = 4;
  128. $data[$k]['num'] = Dever::db('agent/order')->getNum($where);
  129. // $where['status'] = 4;
  130. $dl = Dever::db('agent/order')->getSum($where);
  131. if($dl['total']){
  132. $data[$k]['money'] = $dl['total'];
  133. }else{
  134. $data[$k]['money'] = 0;
  135. }
  136. #期权价值:
  137. $option_money = Dever::db('agent/order')->getOptionPrice($where);
  138. if($option_money['total']){
  139. $data[$k]['option_money'] = $option_money['total'];
  140. }else{
  141. $data[$k]['option_money'] = 0;
  142. }
  143. #软件服务费
  144. $soft_money = Dever::db('agent/order')->getSoftCash($where);
  145. if($soft_money['total']){
  146. $data[$k]['soft_money'] = $soft_money['total'];
  147. }else{
  148. $data[$k]['soft_money'] = 0;
  149. }
  150. $wh['role'] = $v['id'];
  151. $wh['status'] = 3;
  152. $wh['fstart'] = $where['fstart'];
  153. $wh['fend'] = $where['fend'];
  154. $cash = Dever::db('agent/soft_cash')->getTotal($wh);
  155. if($cash['total']){
  156. $data[$k]['cash'] = $cash['total'];
  157. }else{
  158. $data[$k]['cash'] = 0;
  159. }
  160. }
  161. return $data;
  162. }
  163. #数据趋势
  164. public function day_time_api($w){
  165. $time = date('m',time()) - date('m',$w['fstart']);
  166. $start = date('Y-m-01',$w['fstart']);
  167. if($time<=0){
  168. $w['fend'] = time();
  169. }elseif($time>0){
  170. $w['fend'] = strtotime(date('Y-m-d 23:59:59',
  171. strtotime($start."+1 month - 1 day")));
  172. }
  173. $days = ($w['fend']-$w['fstart'])/86400+1;
  174. // 保存每天日期
  175. $day = array();
  176. $data = array();
  177. for($i=0; $i<$days; $i++){
  178. $day[] = array($w['fstart']+(86400*$i),$w['fstart']+(86400*$i)+86400);
  179. }
  180. $res = array();
  181. $res['num'] = array();
  182. foreach($day as $k => $v){
  183. $where['fstart'] = $v[0];
  184. $where['fend'] =$v[1]-1;
  185. $data[$k]['time'] = date('m.d',$v[0]);
  186. #确认代理商订单数
  187. $where['status'] = 4;
  188. $res['num'][] = Dever::db('agent/order')->getNum($where);
  189. }
  190. // print_R($where);die;
  191. $data = array();
  192. $data['name'] = '数量';
  193. $data['type'] = 'line';
  194. // $data['stack'] = 'Total';
  195. $data['data'] = $res['num'];
  196. return $data;
  197. }
  198. #金额趋势
  199. public function money_time_api($w){
  200. $time = date('m',time()) - date('m',$w['fstart']);
  201. $start = date('Y-m-01',$w['fstart']);
  202. if($time<=0){
  203. $w['fend'] = time();
  204. }elseif($time>0){
  205. $w['fend'] = strtotime(date('Y-m-d 23:59:59',
  206. strtotime($start."+1 month - 1 day")));
  207. }
  208. $days = ($w['fend']-$w['fstart'])/86400+1;
  209. // 保存每天日期
  210. $day = array();
  211. $data = array();
  212. for($i=0; $i<$days; $i++){
  213. $day[] = array($w['fstart']+(86400*$i),$w['fstart']+(86400*$i)+86400);
  214. }
  215. $res = array();
  216. $res['money'] = array();
  217. foreach($day as $k => $v){
  218. $where['fstart'] = $v[0];
  219. $where['fend'] =$v[1]-1;
  220. $data[$k]['time'] = date('m.d',$v[0]);
  221. #确认订单总费用
  222. $money = Dever::db('agent/order')->getCash($where);
  223. if($money['total']){
  224. $res['money'][] = $money['total'];
  225. }else{
  226. $res['money'][] = 0;
  227. }
  228. }
  229. $money = array();
  230. $money['name'] = '金额';
  231. $money['type'] = 'line';
  232. $money['data'] = $res['money'];
  233. return $money;
  234. }
  235. #趋势底部日期
  236. public function button_day_api($w,$type){
  237. $time = date('m',time()) - date('m',$w['fstart']);
  238. $start = date('Y-m-01',$w['fstart']);
  239. if($time<=0){
  240. $w['fend'] = time();
  241. }elseif($time>0){
  242. $w['fend'] = strtotime(date('Y-m-d 23:59:59',
  243. strtotime($start."+1 month - 1 day")));
  244. }
  245. $days = ($w['fend']-$w['fstart'])/86400+1;
  246. if($type ==1){
  247. $daysd = $days-1;
  248. }else{
  249. $daysd = $days;
  250. }
  251. // 保存每天日期
  252. $day = array();
  253. $data = array();
  254. for($i=0; $i<$daysd; $i++){
  255. $day[] = date('m.d',$w['fstart']+(86400*$i));
  256. }
  257. $data['type'] = 'category';
  258. $data['boundaryGap'] = false;
  259. $data['date'] = $day;
  260. return $day;
  261. }
  262. #代理商日统计
  263. public function index_api(){
  264. $title = '代理商日数据统计';
  265. $data = Dever::db('mail/feature')->find(array('key'=>'lib/cron.day'));
  266. $email = explode(',',$data['email_id']);
  267. foreach($email as $k => $v){
  268. $res[] = Dever::db('mail/email')->find(array('id'=>$v));
  269. }
  270. $content = $this->index_api();
  271. foreach($res as $key => $val){
  272. $this->send($val['email'], $val['name'], $title, $content);
  273. }
  274. }
  275. #代理商统计发送邮件
  276. public function send($email, $username, $title, $content)
  277. {
  278. $config = Dever::config('base', 'project')->email;
  279. Dever::apply('src/PHPMailer', 'email');
  280. Dever::apply('src/Exception', 'email');
  281. Dever::apply('src/SMTP', 'email');
  282. $mail = new \PHPMailer\PHPMailer\PHPMailer();
  283. $mail->isSMTP();
  284. //$mail->SMTPDebug = 2;
  285. $mail->CharSet = 'UTF-8';
  286. $mail->Host = $config['smtp'];
  287. $mail->Port = 465;
  288. $mail->SMTPSecure = 'ssl';
  289. $mail->SMTPAuth = true;
  290. $mail->Username = $config['username'];
  291. $mail->Password = $config['password'];
  292. $mail->setFrom($config['from'][0], '统计');
  293. $mail->addAddress($email, $username);
  294. $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?=";
  295. $mail->Body = $content;
  296. $mail->isHTML(true);
  297. //$mail->addAttachment($file);
  298. if (!$mail->send()) {
  299. Dever::alert("Mailer Error: " . $mail->ErrorInfo);
  300. } else {
  301. return 'ok';
  302. }
  303. }
  304. #期权统计
  305. public function option_api(){
  306. #主账户数量
  307. $data['account'] = Dever::db('option/account')->getCount(array('state'=>1));
  308. #所有数量
  309. $data['member'] = Dever::db('option/member')->getCount(array('state'=>1));
  310. #已认证完成
  311. $data['y_num'] = Dever::db('option/account')->getCount(array('audit'=>3,'state'=>1));
  312. #尚未任何交付的
  313. $data['no_num'] = Dever::db('option/bill_jiaofu')->getCount(array('status'=>2,'state'=>1));
  314. #原始期权待交付
  315. $yq_nonum = Dever::db('option/bill_jiaofu')->getCash(array('status'=>2,'type'=>2,'state'=>1));
  316. if($yq_nonum['total']){
  317. $data['yq_nonum'] = $yq_nonum['total'];
  318. }else{
  319. $data['yq_nonum'] = 0;
  320. }
  321. #原始期权已交付未发放
  322. $yq_nof = Dever::db('option/bill_jiaofu')->getCash(array('status'=>1,'type'=>2,'state'=>1));
  323. if($yq_nof['total']){
  324. $data['yq_nof'] = $yq_nof['total'];
  325. }else{
  326. $data['yq_nof'] = 0;
  327. }
  328. #原始期权已发放
  329. $yq_fnum = Dever::db('option/bill_fafang')->getCash(array('status'=>1,'type'=>2,'state'=>1));
  330. if($yq_fnum['total']){
  331. $data['yq_fnum'] = $yq_fnum['total'];
  332. }else{
  333. $data['yq_fnum'] = 0;
  334. }
  335. #期权待交付
  336. $q_nonum = Dever::db('option/bill_jiaofu')->getCash(array('status'=>2,'type'=>1,'state'=>1));
  337. if($q_nonum['total']){
  338. $data['q_nonum'] = $q_nonum['total'];
  339. }else{
  340. $data['q_nonum'] = 0;
  341. }
  342. #期权已交付未发放
  343. $q_nof = Dever::db('option/bill_jiaofu')->getCash(array('status'=>1,'type'=>1,'state'=>1));
  344. if($q_nof['total']){
  345. $data['q_nof'] = $q_nof['total'];
  346. }else{
  347. $data['q_nof'] = 0;
  348. }
  349. #期权已发放
  350. $q_fnum = Dever::db('option/bill_fafang')->getCash(array('status'=>1,'type'=>1,'state'=>1));
  351. if($q_fnum['total']){
  352. $data['q_fnum'] = $q_fnum['total'];
  353. }else{
  354. $data['q_fnum'] = 0;
  355. }
  356. return Dever::render('qiquan', $data);
  357. }
  358. #代理商期权待交付
  359. public function option_nopay_api($start,$end,$type=false){
  360. $start = Dever::input('start',$start);
  361. $end = Dever::input('end',$end);
  362. if($start && $end){
  363. $start = strtotime($start);
  364. $end = strtotime($end);
  365. }else{
  366. $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  367. $end = strtotime(date('Y-m-d 23:59:59',
  368. strtotime(date('Y-m-01')."+1 month - 1 day")));
  369. }
  370. $where['start'] = $start;
  371. $where['end'] = $end;
  372. $where['state'] = 1;
  373. $rest = array();
  374. $rest['start'] = date('Y-m-d',$start);
  375. $rest['end'] = date('Y-m-d',$end);
  376. $rest['data'] = array();
  377. $data = Dever::db('agent/order')->getAll($where);
  378. if($data){
  379. foreach($data as $k => $v){
  380. #单独购买的软件服务费
  381. $cash = Dever::db('agent/soft_cash')->getTotal(array('fstart'=>$start,'fend'=>$end,'mid'=>$v['mid']));
  382. $data[$k]['buy_cash'] = $cash['total'];
  383. $option = Dever::db('agent/soft_cash')->getPrice(array('fstart'=>$start,'fend'=>$end,'mid'=>$v['mid']));
  384. $data[$k]['y_price'] = $option['total'];
  385. }
  386. $rest['page'] = Dever::page("current");
  387. $rest['data'] = $data;
  388. if($type == 1){
  389. return $rest['data'];
  390. }else{
  391. return Dever::render('option_nopay', $rest);
  392. }
  393. }else{
  394. return Dever::render('option_nopay', $rest);
  395. }
  396. }
  397. #代理商期权待交付导出
  398. public function out_option_nopay_api(){
  399. $start = Dever::input('start');
  400. $end = Dever::input('end');
  401. if($start && $end){
  402. $start = strtotime($start);
  403. $end = strtotime($end);
  404. }else{
  405. $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  406. $end = strtotime(date('Y-m-d 23:59:59',
  407. strtotime(date('Y-m-01')."+1 month - 1 day")));
  408. }
  409. $data = $this->option_nopay_api($start,$end,1);
  410. $header = array('用户姓名', '手机号', '身份证号', '软件服务费(订单)', '软件服务费(购买)', '原始期权', '期权赠送');
  411. if($data){
  412. $body = array();
  413. foreach($data as $k => $v){
  414. $d = array
  415. (
  416. $v['name'],
  417. $v['mobile'],
  418. $v['idcard'],
  419. $v['soft_cash'],
  420. $v['buy_cash'],
  421. $v['y_price'],
  422. $v['option_price'],
  423. );
  424. $body[] = $d;
  425. }
  426. $file = '代理商期权待交付';
  427. Dever::excelExport($body, $header, $file);
  428. }
  429. }
  430. #代理商期权发放统计
  431. public function option_grant_api($start,$end,$type=false){
  432. $start = Dever::input('start',$start);
  433. $end = Dever::input('end',$end);
  434. if($start && $end){
  435. $start = strtotime($start);
  436. $end = strtotime($end);
  437. }else{
  438. $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  439. $end = strtotime(date('Y-m-d 23:59:59',
  440. strtotime(date('Y-m-01')."+1 month - 1 day")));
  441. }
  442. $data = array();
  443. $data['start'] = date('Y-m-d',$start);
  444. $data['end'] = date('Y-m-d',$end);
  445. $res = Dever::db('agent/member')->getAll(array('start'=>$start,'end'=>$end,'state'=>1));
  446. foreach($res as $k=>$v){
  447. $role = Dever::db('setting/role')->find($v['role']);
  448. $res[$k]['role_name'] = $role['name'];
  449. $res[$k]['cv_num'] = Dever::db('agent/member')->getNum(array('parent_mid'=>$v['id'],'fstart'=>$start,'fend'=>$end,'role'=>8,'state'=>1));
  450. $res[$k]['ck_num'] = Dever::db('agent/member')->getNum(array('parent_mid'=>$v['id'],'fstart'=>$start,'fend'=>$end,'role'=>6,'state'=>1));
  451. $res[$k]['cash'] = Dever::db('bill/cash')->getCash(array('mid'=>$v['id'],'type'=>'1,2','state'=>1));
  452. }
  453. $data['page'] = Dever::page("current");
  454. $data['data'] = $res;
  455. if($type == 1){
  456. return $res;
  457. }else{
  458. return Dever::render('option_grant', $data);
  459. }
  460. }
  461. #期权发放导出
  462. public function out_option_grant_api(){
  463. $start = Dever::input('start');
  464. $end = Dever::input('end');
  465. if($start && $end){
  466. $start = strtotime($start);
  467. $end = strtotime($end);
  468. }else{
  469. $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  470. $end = strtotime(date('Y-m-d 23:59:59',
  471. strtotime(date('Y-m-01')."+1 month - 1 day")));
  472. }
  473. $data = $this->option_grant_api($start,$end,1);
  474. $header = array('用户姓名', '手机号', '身份证号', '角色', '完成团队业绩', '完成直推创v', '完成直推创客');
  475. if($data){
  476. $body = array();
  477. foreach($data as $k => $v){
  478. $d = array
  479. (
  480. $v['name'],
  481. $v['mobile'],
  482. $v['idcard'],
  483. $v['role_name'],
  484. $v['group_sell'],
  485. $v['cv_num'],
  486. $v['ck_num'],
  487. );
  488. $body[] = $d;
  489. }
  490. $file = '代理商期权发放';
  491. Dever::excelExport($body, $header, $file);
  492. }
  493. }
  494. #软件服务费数据统计
  495. public function soft_cash_api(){
  496. $start = Dever::input('start');
  497. $end = Dever::input('end');
  498. $where = array();
  499. if($start && $end){
  500. $where['fstart'] = strtotime($start.'00:00:00');
  501. $where['fend'] = strtotime($end.'23:59:59');
  502. }else{
  503. $where['fstart']=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  504. $where['fend'] = strtotime(date('Y-m-d 23:59:59',
  505. strtotime(date('Y-m-01')."+1 month - 1 day")));
  506. }
  507. $where['state'] = 1;
  508. $data = array();
  509. $data['start'] = date('Y-m-d',$where['fstart']);
  510. $data['end'] = date('Y-m-d',$where['fend']);
  511. #软件服务费的已确认数量
  512. $where['soft_cash']=1;
  513. $where['status'] = 4;
  514. $order = Dever::db('agent/order')->getSoftNum($where);
  515. $where['status'] = 3;
  516. $soft_cash = Dever::db('agent/soft_cash')->getSoftNum($where);
  517. $data['num'] = $order + $soft_cash;
  518. #软件服务费未确认的数量
  519. $where['status'] = '-2,-1,1,2,3';
  520. $order = Dever::db('agent/order')->getSoftNoNum($where);
  521. $where['status'] = '1,2';
  522. $soft_cash = Dever::db('agent/soft_cash')->getSoftNoNum($where);
  523. $data['no_num'] = $order + $soft_cash;
  524. #总数量
  525. $data['total_num'] = $data['num'] + $data['no_num'];
  526. #已确认软件服务费
  527. $where['status'] = 4;
  528. $order = Dever::db('agent/order')->getSoftCash($where);
  529. $where['status'] = 3;
  530. $soft_cash = Dever::db('agent/soft_cash')->getSoftCash($where);
  531. $data['money'] = $order['total'] + $soft_cash['total'];
  532. #未确认软件服务费
  533. $where['status'] = '-2,-1,1,2,3';
  534. $order = Dever::db('agent/order')->getSoftNoCash($where);
  535. $where['status'] = '1,2';
  536. $soft_cash = Dever::db('agent/soft_cash')->getSoftNoCash($where);
  537. $data['no_money'] = $order['total'] + $soft_cash['total'];
  538. #总钱数
  539. $data['total_money'] = $data['money'] + $data['no_money'];
  540. #合同已确认数量:
  541. $where['status'] = 2;
  542. $data['a_num'] = Dever::db('agent/member_agreement')->getNum($where);
  543. #合同未确认数量:
  544. $where['status'] = 1;
  545. $data['a_nonum'] = Dever::db('agent/member_agreement')->getNoNum($where);
  546. $data['a_totalnum'] = $data['a_num'] + $data['a_nonum'];
  547. #合同已确认软件服务费
  548. $where['status'] = 2;
  549. $price = Dever::db('agent/member_agreement')->getPrice($where);
  550. if($price['total']){
  551. $data['a_price'] = $price['total'];
  552. }else{
  553. $data['a_price'] = 0;
  554. }
  555. #合同未确认软件服务费
  556. $where['status'] = 1;
  557. $noprice = Dever::db('agent/member_agreement')->getNoPrice($where);
  558. if($noprice['total']){
  559. $data['a_noprice'] = $noprice['total'];
  560. }else{
  561. $data['a_noprice'] = 0;
  562. }
  563. #总钱数
  564. $data['total_price'] = $data['a_price'] + $data['a_noprice'];
  565. return Dever::render('soft_cash', $data);
  566. }
  567. public function out_option_qiquan_api($data)
  568. {
  569. // print_R($data);die;
  570. $header = array('索引', '账户名称', '账户类型', '手机号', '邮箱', '邮箱认证', '账户认证', '合同审核状态','待交付期权', '待交付原始期权', '已交付期权', '已交付原始期权');
  571. // $data = Dever::db('option/member')->state();
  572. $body = array();
  573. $main = '';
  574. $f_money = 0;
  575. $j_money = 0;
  576. $dj_money = 0;
  577. $d_money = 0;
  578. $status = array();
  579. $set = Dever::db('option/account')->config['set'];
  580. $ag_audit = Dever::db('option/agreement')->config['audit'];
  581. foreach ($data as $k1 => $v1) {
  582. $member[$v1['id']] = Dever::db('option/member')->select(array('aid' => $v1['id']));
  583. $agreement = Dever::db('option/agreement')->find(array('aid' => $v1['id']));
  584. $status[$v1['id']] = array
  585. (
  586. 'email' => $v1['email'],
  587. 'is_email' => $v1['is_email'] == 1 ? '已验证' : '未验证',
  588. 'audit' => $set['audit'][$v1['audit']],
  589. 'agreement' => $agreement ? $ag_audit[$agreement['audit']] : '未签署',
  590. );
  591. }
  592. foreach ($member as $k => $v1) {
  593. foreach ($v1 as $v) {
  594. $daijiaofu_qiquan = $daijiaofu_yuanshiqiquan = $jiaofu_qiquan = $jiaofu_yaunshiqiquan = 0;
  595. if ($v['main'] == 1) {
  596. $main = '主账户';
  597. } else {
  598. $main = '子账户';
  599. }
  600. $where = array();
  601. $where['mid'] = $v['id'];
  602. /*
  603. $ff = Dever::db('option/bill_fafang')->getSearch($where);
  604. if ($ff && $ff['total']) {
  605. $f_money = $ff['total'];
  606. }
  607. $duifu = Dever::db('option/bill_duifu')->getSearch($where);
  608. if ($duifu && $duifu['total']){
  609. $d_money = $duifu['total'];
  610. }
  611. */
  612. $where['status'] = 2;
  613. $where['type'] = 1;
  614. $jiaofu = Dever::db('option/bill_jiaofu')->getSearch($where);
  615. if ($jiaofu && $jiaofu['total']){
  616. $daijiaofu_qiquan = $jiaofu['total'];
  617. }
  618. $where['status'] = 2;
  619. $where['type'] = 2;
  620. $jiaofu = Dever::db('option/bill_jiaofu')->getSearch($where);
  621. if ($jiaofu && $jiaofu['total']){
  622. $daijiaofu_yuanshiqiquan = $jiaofu['total'];
  623. }
  624. $where['status'] = 1;
  625. $where['type'] = 1;
  626. $jiaofu = Dever::db('option/bill_jiaofu')->getSearch($where);
  627. if ($jiaofu && $jiaofu['total']){
  628. $jiaofu_qiquan = $jiaofu['total'];
  629. }
  630. $where['status'] = 1;
  631. $where['type'] = 2;
  632. $jiaofu = Dever::db('option/bill_jiaofu')->getSearch($where);
  633. if ($jiaofu && $jiaofu['total']){
  634. $jiaofu_yaunshiqiquan = $jiaofu['total'];
  635. }
  636. $d =array
  637. (
  638. $v['key'],
  639. $v['name'],
  640. $main,
  641. $v['mobile'],
  642. $status[$v['aid']]['email'],
  643. $status[$v['aid']]['is_email'],
  644. $status[$v['aid']]['audit'],
  645. $status[$v['aid']]['agreement'],
  646. $daijiaofu_qiquan,
  647. $daijiaofu_yuanshiqiquan,
  648. $jiaofu_qiquan,
  649. $jiaofu_yaunshiqiquan,
  650. );
  651. $body[] = $d;
  652. }
  653. }
  654. $file = '期权导出';
  655. return Dever::excelExport($body, $header, $file);
  656. }
  657. # 体验店毛利:采购价-成本价
  658. public function t_buy($where, $shop_id)
  659. {
  660. $where['type_id'] = $shop_id;
  661. $where['status'] = '5,6';
  662. $order = Dever::db('shop/buy_order')->getNewAll($where);
  663. $total = 0;
  664. if ($order) {
  665. foreach($order as $k => $v) {
  666. $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  667. $c_price = 0;
  668. foreach($order_goods as $k1 => $v1){
  669. $goods = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
  670. if($goods['c_price'] && $goods['c_price'] >= 0){
  671. $c_price += $goods['c_price'] * $v1['num'];
  672. }
  673. }
  674. $total += ($v['price'] - $c_price);
  675. }
  676. }
  677. return $total;
  678. }
  679. # 零售店毛利
  680. public function l_buy($where, $shop_id)
  681. {
  682. $where['shop_id'] = $shop_id;
  683. $data = Dever::db('mail/area_entry')->getBuy($where);
  684. if ($data && $data['total']) {
  685. return $data['total'];
  686. }
  687. return 0;
  688. }
  689. # 区域分润
  690. public function area_api()
  691. {
  692. /*
  693. $month = Dever::input('month', date('Y-m'));
  694. $start_time = $month .'-01 00:00:00';
  695. $where = array();
  696. $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
  697. $where['start'] = Dever::maketime($start_time);
  698. $where['end'] = Dever::maketime($end_time);
  699. */
  700. # 设置利润计算规则:
  701. $config = array
  702. (
  703. 1 => 0.01,
  704. 2 => 0.03,
  705. 3 => 0.05,
  706. );
  707. # 传入day,获取月开始和月结束日期
  708. list($where['start'], $where['end']) = Dever::month();
  709. # 获取区域
  710. $area = array();
  711. $shop = Dever::db('shop/info')->select();
  712. if ($shop) {
  713. foreach ($shop as $k => $v) {
  714. if ($v['type'] != 10) {
  715. if ($v['city'] > 0) {
  716. $key = $v['province'] . ',' . $v['city'];
  717. $area[$key]['shop_id'][$v['type']][] = $v['id'];
  718. $area[$key]['type'] = 1;
  719. }
  720. if ($v['county'] > 0) {
  721. $key = $v['province'] . ',' . $v['city'] . ',' . $v['county'];
  722. $area[$key]['shop_id'][$v['type']][] = $v['id'];
  723. $area[$key]['type'] = 2;
  724. }
  725. if ($v['town'] > 0) {
  726. $key = $v['province'] . ',' . $v['city'] . ',' . $v['county'] . ',' . $v['town'];
  727. $area[$key]['shop_id'][$v['type']][] = $v['id'];
  728. $area[$key]['type'] = 3;
  729. }
  730. }
  731. }
  732. foreach ($area as $k => $v) {
  733. $update = array();
  734. $update['month'] = $where['start'];
  735. $update['name'] = $k;
  736. $info = Dever::db('mail/area_stat')->find($update);
  737. # 设置金额
  738. $update['t_num'] = $update['l_num'] = $update['t_cash'] = $update['l_cash'] = $update['t_buy'] = $update['l_buy'] = 0;
  739. foreach ($v['shop_id'] as $k1 => $v1) {
  740. if ($k1 == 1) {
  741. # 体验店
  742. $update['t_num'] = count($v1);
  743. $update['t_buy'] = $this->t_buy($where, $v1);
  744. if ($update['t_buy'] > 0) {
  745. $update['t_cash'] = $update['t_buy'] * $config[$v['type']];
  746. }
  747. } elseif ($k1 == 2) {
  748. # 零售店
  749. $update['l_num'] = count($v1);
  750. $update['l_buy'] = $this->l_buy($where, $v1);
  751. if ($update['l_buy'] > 0) {
  752. $update['l_cash'] = $update['l_buy'] * $config[$v['type']];
  753. }
  754. }
  755. }
  756. if ($update['t_buy'] == 0 && $update['l_buy'] == 0) {
  757. continue;
  758. }
  759. # 设置上级id,用来做列表层级展示
  760. if ($v['type'] == 1) {
  761. $update['parent_id'] = -1;
  762. } elseif ($v['type'] == 2) {
  763. $update['parent_id'] = $city_id;
  764. } elseif ($v['type'] == 3) {
  765. $update['parent_id'] = $county_id;
  766. }
  767. # 设置收益代理商
  768. $member = Dever::db('agent/member')->getAreaAll(array('area' => $k));
  769. if ($member) {
  770. $update['mid'] = $member['id'];
  771. }
  772. if (!$info) {
  773. $stat_id = Dever::db('mail/area_stat')->insert($update);
  774. if ($v['type'] == 1) {
  775. $city_id = $stat_id;
  776. } elseif ($v['type'] == 2) {
  777. $county_id = $stat_id;
  778. }
  779. } else {
  780. $update['where_id'] = $info['id'];
  781. Dever::db('mail/area_stat')->update($w);
  782. }
  783. }
  784. }
  785. /*
  786. $data = array();
  787. $data = Dever::db('shop/info')->getAreaAll(array('state'=>1));
  788. foreach($data as $k => $v){
  789. $w['month'] = $where['start'];
  790. #城市
  791. if($v['city']>0){
  792. $city_area_stat = -1;
  793. $where['area'] = $v['city'];
  794. $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  795. $where['parent_type'] = '1,3';
  796. // print_R($where);die;
  797. $jia = $this->caigou($where);
  798. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  799. $data[$k]['citys']['price']= $jia['money'] * 0.01;
  800. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  801. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['citys']['area'],'role'=>2));
  802. $w['citys']['area'] = $v['city'];
  803. if($mid && $mid['id']){
  804. $data[$k]['citys']['mid'] = $mid['id'];
  805. }else{
  806. $data[$k]['citys']['mid'] = '-1';
  807. }
  808. $where['city'] = $v['city'];
  809. $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  810. #体验店
  811. $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  812. $data[$k]['citys']['type'] = array_column($t_shop,'id');
  813. $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  814. $data[$k]['citys']['t_num'] = count($t_shop);
  815. if($data[$k]['citys']['t_num']>0){
  816. $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  817. $data[$k]['citys']['t_fprice'] = $data[$k]['citys']['price'];
  818. }else{
  819. $data[$k]['citys']['t_price'] = 0;
  820. $data[$k]['citys']['t_fprice'] = 0;
  821. }
  822. #零售店
  823. $shop_area = $this->ls($where,1);
  824. $data[$k]['citys']['l_price'] =$shop_area['price'];
  825. $data[$k]['citys']['l_fprice'] =$shop_area['price'] * 0.01;
  826. $data[$k]['citys']['l_num'] = $shop_area['num'];
  827. $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_fprice'];
  828. $w['mid'] = $data[$k]['citys']['mid'];
  829. $w['name'] = $data[$k]['citys']['area'];
  830. $w['price'] = $data[$k]['citys']['price'];
  831. $w['c_price'] = $jia['price'];
  832. // $data[$k]['citys']['money']['total'];
  833. $w['num'] = $data[$k]['citys']['num'];
  834. $w['t_num'] = $data[$k]['citys']['t_num'];
  835. $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  836. $w['t_fprice'] = $data[$k]['citys']['t_fprice'];
  837. $w['l_num'] = $data[$k]['citys']['l_num'];
  838. $w['l_price'] = $shop_area['price'];
  839. $w['l_fprice'] = $data[$k]['citys']['l_fprice'];
  840. $w['parent_id'] = -1;
  841. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['citys']['area']));
  842. if(!$shop){
  843. $city_area_stat = Dever::db('mail/area_stat')->insert($w);
  844. }else{
  845. $city_area_stat = $w['where_id'] = $shop['id'];
  846. Dever::db('mail/area_stat')->update($w);
  847. }
  848. }
  849. #区县
  850. if($v['county']>0){
  851. $county_area_stat = -1;
  852. $where['area'] = $v['county'];
  853. $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  854. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  855. $jia = $this->caigou($where);
  856. $data[$k]['countys']['price']= $jia['money'] *0.03;
  857. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  858. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['countys']['area'],'role'=>3));
  859. if($mid && $mid['id']){
  860. $data[$k]['countys']['mid'] = $mid['id'];
  861. }else{
  862. $data[$k]['countys']['mid'] = '-1';
  863. }
  864. $wh['county'] = $v['county'];
  865. $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  866. // #体验店
  867. $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  868. $data[$k]['countys']['type'] = array_column($t_shop,'id');
  869. $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  870. $data[$k]['countys']['t_num'] = count($t_shop);
  871. if($data[$k]['countys']['t_num']>0){
  872. $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  873. $data[$k]['countys']['t_fprice'] = $data[$k]['countys']['price'];
  874. }else{
  875. $data[$k]['countys']['t_price'] = 0;
  876. $data[$k]['countys']['t_fprice'] = 0;
  877. }
  878. #零售店
  879. $where['county'] = $v['county'];
  880. $shop_area = $this->ls($where,2);
  881. $data[$k]['countys']['l_price'] = $shop_area['price'];
  882. $data[$k]['countys']['l_fprice'] = $shop_area['price'] * 0.03;
  883. $data[$k]['countys']['l_num'] = $shop_area['num'];
  884. $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_fprice'];
  885. $w['mid'] = $data[$k]['countys']['mid'];
  886. $w['name'] = $data[$k]['countys']['area'];
  887. $w['price'] = $data[$k]['countys']['price'];
  888. $w['num'] = $data[$k]['countys']['num'];
  889. $w['c_price'] = $jia['price'];
  890. // $data[$k]['countys']['money']['total'];
  891. $w['t_num'] = $data[$k]['countys']['t_num'];
  892. $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  893. $w['t_fprice'] = $data[$k]['countys']['t_fprice'];
  894. $w['l_num'] = $data[$k]['countys']['l_num'];
  895. $w['l_price'] = $shop_area['price'];
  896. $w['l_fprice'] = $data[$k]['countys']['l_fprice'];
  897. $w['parent_id'] = $city_area_stat;
  898. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['countys']['area']));
  899. if(!$shop){
  900. $county_area_stat = Dever::db('mail/area_stat')->insert($w);
  901. }else{
  902. $county_area_stat = $w['where_id'] = $shop['id'];
  903. Dever::db('mail/area_stat')->update($w);
  904. }
  905. }
  906. #街道
  907. if($v['town']>0){
  908. $where['area'] = $v['town'];
  909. $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  910. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  911. $jia = $this->caigou($where);
  912. $data[$k]['towns']['price'] = $jia['money'] * 0.05;
  913. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  914. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['towns']['area'],'role'=>4));
  915. if($mid && $mid['id']){
  916. $data[$k]['towns']['mid'] = $mid['id'];
  917. }else{
  918. $data[$k]['towns']['mid'] = '-1';
  919. }
  920. $whe['town'] = $v['town'];
  921. $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  922. #体验店
  923. $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  924. $data[$k]['towns']['type'] = array_column($t_shop,'id');
  925. $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  926. $data[$k]['towns']['t_num'] = count($t_shop);
  927. if($data[$k]['towns']['t_num']>0){
  928. $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  929. $data[$k]['towns']['t_fprice'] = $data[$k]['towns']['price'];
  930. }else{
  931. $data[$k]['towns']['t_price'] = 0;
  932. $data[$k]['towns']['t_fprice'] = 0;
  933. }
  934. #零售店
  935. $where['town'] = $v['town'];
  936. $shop_area = $this->ls($where,3);
  937. $data[$k]['towns']['l_price'] =$shop_area['price'];
  938. $data[$k]['towns']['l_fprice'] =$shop_area['price'] * 0.05;
  939. $data[$k]['towns']['l_num'] = $shop_area['num'];
  940. $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_fprice'];
  941. $w['mid'] = $data[$k]['towns']['mid'];
  942. $w['name'] = $data[$k]['towns']['area'];
  943. $w['price'] = $data[$k]['towns']['price'];
  944. $w['num'] = $data[$k]['towns']['num'];
  945. $w['c_price'] = $jia['price'];
  946. // $data[$k]['towns']['money']['total'];
  947. $w['t_num'] = $data[$k]['towns']['t_num'];
  948. $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  949. $w['t_fprice'] = $data[$k]['towns']['t_fprice'];
  950. $w['l_num'] = $data[$k]['towns']['l_num'];
  951. $w['l_price'] = $shop_area['price'];
  952. $w['l_fprice'] = $data[$k]['towns']['l_fprice'];
  953. $w['parent_id'] = $county_area_stat;
  954. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['towns']['area']));
  955. if(!$shop){
  956. Dever::db('mail/area_stat')->insert($w);
  957. }else{
  958. $w['where_id'] = $shop['id'];
  959. Dever::db('mail/area_stat')->update($w);
  960. }
  961. }
  962. }
  963. */
  964. return 'ok';
  965. }
  966. /*
  967. #采购价-成本价
  968. public function caigou($where){
  969. $data = Dever::db('shop/buy_order')->getNewAll($where);
  970. $res = array();
  971. $money = 0;
  972. $res['money'] = 0;
  973. if($data && isset($data['price']) && $data['price']){
  974. $res['price'] = $data['price'];
  975. }else{
  976. $res['price'] = 0;
  977. }
  978. foreach($data as $k => $v){
  979. // $goods_id,$skuid
  980. $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  981. $c_price = 0;
  982. foreach($order_goods as $k1 => $v1){
  983. $goods = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
  984. if($goods['c_price'] && $goods['c_price'] >= 0){
  985. $c_price += $goods['c_price'] * $v1['num'];
  986. }
  987. }
  988. $res['money'] += ($v['price'] - $c_price);
  989. }
  990. return $res;
  991. }
  992. #零售
  993. public function ls($where,$type=false){
  994. $shop = Dever::db('mail/area_entry')->getNewAll($where);
  995. $data = array();
  996. $data['price'] = 0;
  997. foreach($shop as $k => $v){
  998. if ($type == 1) {
  999. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('city'=>$where['city'],'id'=>$v['shop_id']));
  1000. } elseif ($type == 2) {
  1001. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('county'=>$where['county'],'id'=>$v['shop_id']));
  1002. } elseif ($type == 3) {
  1003. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('town'=>$where['town'],'id'=>$v['shop_id']));
  1004. }
  1005. }
  1006. foreach($shop as $k => $v){
  1007. if(!$v['shop']){
  1008. unset($shop[$k]);
  1009. }
  1010. }
  1011. foreach($shop as $k=>$v){
  1012. $data['price'] +=$v['cprice'];
  1013. }
  1014. $data['num'] = count($shop);
  1015. return $data;
  1016. }
  1017. */
  1018. // public function area_api(){
  1019. // #零售店的采购金额*0.4
  1020. // $month = Dever::input('month', date('Y-m'));
  1021. // $start_time = $month .'-01 00:00:00';
  1022. // $where = array();
  1023. // $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
  1024. // $where['start'] = Dever::maketime($start_time);
  1025. // $where['end'] = Dever::maketime($end_time);
  1026. // $where['state'] = 1;
  1027. // $data = array();
  1028. // $shop = Dever::db('shop/info')->getAreaAll(array('state'=>1));
  1029. // foreach($shop as $k=>$v){
  1030. // $data[$v['city']]=$v;
  1031. // }
  1032. // $shop_area = Dever::db('mail/area_entry')->getAll($where);
  1033. // $res = array();
  1034. // if($shop_area){
  1035. // foreach($shop_area as $k => $v){
  1036. // if($v['area']){
  1037. // $area = explode(',',$v['area']);
  1038. // if($area && isset($area[0])){
  1039. // $res[$k]['province'] = $area[0];
  1040. // }
  1041. // if ($area && isset($area[1])){
  1042. // $res[$k]['city'] = $area[1];
  1043. // }else{
  1044. // $res[$k]['city'] = 0;
  1045. // }
  1046. // if($area && isset($area[2])){
  1047. // $res[$k]['county'] = $area[2];
  1048. // }else{
  1049. // $res[$k]['county'] = 0;
  1050. // }
  1051. // if($area && isset($area[3])){
  1052. // $res[$k]['town'] = $area[3];
  1053. // }else{
  1054. // $res[$k]['town'] = 0;
  1055. // }
  1056. // }
  1057. // }
  1058. // }
  1059. // $data = array_values($data);
  1060. // $data = array_merge($data,$res);
  1061. // // print_R($data);die;
  1062. // $result=array_unique($data, SORT_REGULAR);
  1063. // $rest=array();
  1064. // foreach($data as $k=>$v){
  1065. // $rest[$v['county']]=$v;
  1066. // }
  1067. // $data=array_values($rest);
  1068. // foreach ($data as $k => $v) {
  1069. // $edition[] = $v['province'];
  1070. // }
  1071. // array_multisort($edition, SORT_ASC, $data);
  1072. // foreach($data as $k => $v){
  1073. // $w['month'] = $where['start'];
  1074. // #城市
  1075. // if($v['city']>0){
  1076. // $where['area'] = $v['city'];
  1077. // $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  1078. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  1079. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  1080. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1081. // $w['citys']['area'] = $v['city'];
  1082. // if($mid && $mid['id']){
  1083. // $data[$k]['citys']['mid'] = $mid['id'];
  1084. // }else{
  1085. // $data[$k]['citys']['mid'] = '';
  1086. // }
  1087. // $where['city'] = $v['city'];
  1088. // $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  1089. // #体验店
  1090. // $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  1091. // $data[$k]['citys']['type'] = array_column($t_shop,'id');
  1092. // $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  1093. // $data[$k]['citys']['t_num'] = count($t_shop);
  1094. // if($data[$k]['citys']['t_num']>0){
  1095. // $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1096. // }else{
  1097. // $data[$k]['citys']['t_price'] = 0;
  1098. // }
  1099. // #零售店
  1100. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1101. // if ($entry && $entry['num']){
  1102. // $data[$k]['citys']['l_num'] = $entry['num'];
  1103. // $data[$k]['citys']['num'] = $data[$k]['citys']['num'] + $data[$k]['citys']['l_num'];
  1104. // }else{
  1105. // $data[$k]['citys']['l_num'] = 0;
  1106. // }
  1107. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1108. // if ($entry_price && $entry_price['cprice'] ){
  1109. // $data[$k]['citys']['l_price'] = $entry_price['cprice'] * 0.4;
  1110. // $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_price'];
  1111. // }else{
  1112. // $data[$k]['citys']['l_price'] = 0;
  1113. // }
  1114. // $w['mid'] = $data[$k]['citys']['mid'];
  1115. // $w['area'] = $data[$k]['citys']['area'];
  1116. // $w['price'] = $data[$k]['citys']['price'];
  1117. // $w['c_price'] = $data[$k]['citys']['money']['total'];
  1118. // $w['num'] = $data[$k]['citys']['num'];
  1119. // $w['t_num'] = $data[$k]['citys']['t_num'];
  1120. // $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  1121. // $w['l_num'] = $data[$k]['citys']['l_num'];
  1122. // $w['l_price'] = $data[$k]['citys']['l_price'];
  1123. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['citys']['area']));
  1124. // if(!$shop){
  1125. // Dever::db('mail/area_stat')->insert($w);
  1126. // }else{
  1127. // $w['where_id'] = $shop['id'];
  1128. // Dever::db('mail/area_stat')->update($w);
  1129. // }
  1130. // }
  1131. // #区县
  1132. // if($v['county']>0){
  1133. // $where['area'] = $v['county'];
  1134. // $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  1135. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  1136. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  1137. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1138. // if($mid && $mid['id']){
  1139. // $data[$k]['countys']['mid'] = $mid['id'];
  1140. // }else{
  1141. // $data[$k]['countys']['mid'] = '';
  1142. // }
  1143. // $wh['county'] = $v['county'];
  1144. // $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  1145. // // #体验店
  1146. // $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  1147. // $data[$k]['countys']['type'] = array_column($t_shop,'id');
  1148. // $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  1149. // $data[$k]['countys']['t_num'] = count($t_shop);
  1150. // if($data[$k]['countys']['t_num']>0){
  1151. // $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1152. // }else{
  1153. // $data[$k]['countys']['t_price'] = 0;
  1154. // }
  1155. // #零售店
  1156. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1157. // if ($entry && $entry['num']){
  1158. // $data[$k]['countys']['l_num'] = $entry['num'];
  1159. // $data[$k]['countys']['num'] = $data[$k]['countys']['num'] + $data[$k]['countys']['l_num'];
  1160. // }else{
  1161. // $data[$k]['countys']['l_num'] = 0;
  1162. // }
  1163. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1164. // if ($entry_price && $entry_price['cprice'] ){
  1165. // $data[$k]['countys']['l_price'] = $entry_price['cprice'] * 0.4;
  1166. // $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_price'];
  1167. // }else{
  1168. // $data[$k]['countys']['l_price'] = 0;
  1169. // }
  1170. // $w['mid'] = $data[$k]['countys']['mid'];
  1171. // $w['area'] = $data[$k]['countys']['area'];
  1172. // $w['price'] = $data[$k]['countys']['price'];
  1173. // $w['num'] = $data[$k]['countys']['num'];
  1174. // $w['c_price'] = $data[$k]['countys']['money']['total'];
  1175. // $w['t_num'] = $data[$k]['countys']['t_num'];
  1176. // $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  1177. // $w['l_num'] = $data[$k]['countys']['l_num'];
  1178. // $w['l_price'] = $data[$k]['countys']['l_price'];
  1179. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['countys']['area']));
  1180. // if(!$shop){
  1181. // Dever::db('mail/area_stat')->insert($w);
  1182. // }else{
  1183. // $w['where_id'] = $shop['id'];
  1184. // Dever::db('mail/area_stat')->update($w);
  1185. // }
  1186. // }
  1187. // #街道
  1188. // if($v['town']>0){
  1189. // $where['area'] = $v['town'];
  1190. // $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  1191. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  1192. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  1193. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1194. // if($mid && $mid['id']){
  1195. // $data[$k]['towns']['mid'] = $mid['id'];
  1196. // }else{
  1197. // $data[$k]['towns']['mid'] = '';
  1198. // }
  1199. // $whe['town'] = $v['town'];
  1200. // $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  1201. // #体验店
  1202. // $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  1203. // $data[$k]['towns']['type'] = array_column($t_shop,'id');
  1204. // $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  1205. // $data[$k]['towns']['t_num'] = count($t_shop);
  1206. // if($data[$k]['towns']['t_num']>0){
  1207. // $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1208. // }else{
  1209. // $data[$k]['towns']['t_price'] = 0;
  1210. // }
  1211. // #零售店
  1212. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1213. // if ($entry && $entry['num']){
  1214. // $data[$k]['towns']['l_num'] = $entry['num'];
  1215. // $data[$k]['towns']['num'] = $data[$k]['towns']['num'] + $data[$k]['towns']['l_num'];
  1216. // }else{
  1217. // $data[$k]['towns']['l_num'] = 0;
  1218. // }
  1219. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1220. // if ($entry_price && $entry_price['cprice'] ){
  1221. // $data[$k]['towns']['l_price'] = $entry_price['cprice'] * 0.4;
  1222. // $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_price'];
  1223. // }else{
  1224. // $data[$k]['towns']['l_price'] = 0;
  1225. // }
  1226. // $w['mid'] = $data[$k]['towns']['mid'];
  1227. // $w['area'] = $data[$k]['towns']['area'];
  1228. // $w['price'] = $data[$k]['towns']['price'];
  1229. // $w['num'] = $data[$k]['towns']['num'];
  1230. // $w['c_price'] = $data[$k]['towns']['money']['total'];
  1231. // $w['t_num'] = $data[$k]['towns']['t_num'];
  1232. // $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  1233. // $w['l_num'] = $data[$k]['towns']['l_num'];
  1234. // $w['l_price'] = $data[$k]['towns']['l_price'];
  1235. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['towns']['area']));
  1236. // if(!$shop){
  1237. // Dever::db('mail/area_stat')->insert($w);
  1238. // }else{
  1239. // $w['where_id'] = $shop['id'];
  1240. // Dever::db('mail/area_stat')->update($w);
  1241. // }
  1242. // }
  1243. // }
  1244. // return 'ok';
  1245. // }
  1246. public function area_member($id){
  1247. $info = Dever::db('mail/area_stat')->find($id);
  1248. $res = '-';
  1249. if($info['mid']){
  1250. $member = Dever::db('agent/member')->find($info['mid']);
  1251. if ($member) {
  1252. $res = $member['name']."<br/>".$member['mobile'];
  1253. }
  1254. }
  1255. return $res;
  1256. }
  1257. public function entry_member($id){
  1258. $info = Dever::db('mail/area_entry')->find($id);
  1259. if($info['shop_id']){
  1260. $member = Dever::db('shop/info')->find($info['shop_id']);
  1261. // print_R($member);die;
  1262. $res = $member['name'].'<br/>'.$member['sid'];
  1263. }else{
  1264. $res = '-';
  1265. }
  1266. return $res;
  1267. }
  1268. public function updateArea_entry($id,$name,$data){
  1269. $sid = Dever::param('sid',$data);
  1270. $month = Dever::param('month',$data);
  1271. if ($id && $sid) {
  1272. $info = Dever::db('mail/area_entry')->find($id);
  1273. $member = Dever::db('shop/info')->find(array('sid'=>$sid));
  1274. // print_R($member);die;
  1275. $where['where_id'] = $id ;
  1276. $where['shop_id'] = $member['id'];
  1277. $where['month'] = strtotime($month);
  1278. Dever::db('mail/area_entry')->update($where);
  1279. }
  1280. }
  1281. }