Manage.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  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 caigou($where){
  659. $data = Dever::db('shop/buy_order')->getNewAll($where);
  660. $res = array();
  661. $money = 0;
  662. $res['money'] = 0;
  663. if($data && isset($data['price']) && $data['price']){
  664. $res['price'] = $data['price'];
  665. }else{
  666. $res['price'] = 0;
  667. }
  668. foreach($data as $k => $v){
  669. // $goods_id,$skuid
  670. $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  671. $c_price = 0;
  672. foreach($order_goods as $k1 => $v1){
  673. $goods = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
  674. if($goods['c_price'] && $goods['c_price'] >= 0){
  675. $c_price += $goods['c_price'] * $v1['num'];
  676. }
  677. }
  678. $res['money'] += ($v['price'] - $c_price);
  679. }
  680. return $res;
  681. }
  682. #零售
  683. public function ls($where,$type=false){
  684. $shop = Dever::db('mail/area_entry')->getNewAll($where);
  685. $data = array();
  686. $data['price'] = 0;
  687. foreach($shop as $k => $v){
  688. if ($type == 1) {
  689. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('city'=>$where['city'],'id'=>$v['shop_id']));
  690. } elseif ($type == 2) {
  691. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('county'=>$where['county'],'id'=>$v['shop_id']));
  692. } elseif ($type == 3) {
  693. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('town'=>$where['town'],'id'=>$v['shop_id']));
  694. }
  695. }
  696. foreach($shop as $k => $v){
  697. if(!$v['shop']){
  698. unset($shop[$k]);
  699. }
  700. }
  701. foreach($shop as $k=>$v){
  702. $data['price'] +=$v['cprice'];
  703. }
  704. $data['num'] = count($shop);
  705. return $data;
  706. }
  707. #区域分润
  708. public function area_api(){
  709. $month = Dever::input('month', date('Y-m'));
  710. $start_time = $month .'-01 00:00:00';
  711. $where = array();
  712. $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
  713. $where['start'] = Dever::maketime($start_time);
  714. $where['end'] = Dever::maketime($end_time);
  715. $where['state'] = 1;
  716. $data = array();
  717. $data = Dever::db('shop/info')->getAreaAll(array('state'=>1));
  718. foreach($data as $k => $v){
  719. $w['month'] = $where['start'];
  720. #城市
  721. if($v['city']>0){
  722. $city_area_stat = -1;
  723. $where['area'] = $v['city'];
  724. $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  725. $where['parent_type'] = '1,3';
  726. // print_R($where);die;
  727. $jia = $this->caigou($where);
  728. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  729. $data[$k]['citys']['price']= $jia['money'] * 0.01;
  730. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  731. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['citys']['area'],'role'=>2));
  732. $w['citys']['area'] = $v['city'];
  733. if($mid && $mid['id']){
  734. $data[$k]['citys']['mid'] = $mid['id'];
  735. }else{
  736. $data[$k]['citys']['mid'] = '-1';
  737. }
  738. $where['city'] = $v['city'];
  739. $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  740. #体验店
  741. $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  742. $data[$k]['citys']['type'] = array_column($t_shop,'id');
  743. $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  744. $data[$k]['citys']['t_num'] = count($t_shop);
  745. if($data[$k]['citys']['t_num']>0){
  746. $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  747. $data[$k]['citys']['t_fprice'] = $data[$k]['citys']['price'];
  748. }else{
  749. $data[$k]['citys']['t_price'] = 0;
  750. $data[$k]['citys']['t_fprice'] = 0;
  751. }
  752. #零售店
  753. $shop_area = $this->ls($where,1);
  754. $data[$k]['citys']['l_price'] =$shop_area['price'];
  755. $data[$k]['citys']['l_fprice'] =$shop_area['price'] * 0.01;
  756. $data[$k]['citys']['l_num'] = $shop_area['num'];
  757. $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_fprice'];
  758. $w['mid'] = $data[$k]['citys']['mid'];
  759. $w['name'] = $data[$k]['citys']['area'];
  760. $w['price'] = $data[$k]['citys']['price'];
  761. $w['c_price'] = $jia['price'];
  762. // $data[$k]['citys']['money']['total'];
  763. $w['num'] = $data[$k]['citys']['num'];
  764. $w['t_num'] = $data[$k]['citys']['t_num'];
  765. $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  766. $w['t_fprice'] = $data[$k]['citys']['t_fprice'];
  767. $w['l_num'] = $data[$k]['citys']['l_num'];
  768. $w['l_price'] = $shop_area['price'];
  769. $w['l_fprice'] = $data[$k]['citys']['l_fprice'];
  770. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['citys']['area']));
  771. if(!$shop){
  772. $city_area_stat = Dever::db('mail/area_stat')->insert($w);
  773. }else{
  774. $city_area_stat = $w['where_id'] = $shop['id'];
  775. Dever::db('mail/area_stat')->update($w);
  776. }
  777. }
  778. #区县
  779. if($v['county']>0){
  780. $county_area_stat = -1;
  781. $where['area'] = $v['county'];
  782. $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  783. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  784. $jia = $this->caigou($where);
  785. $data[$k]['countys']['price']= $jia['money'] *0.03;
  786. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  787. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['countys']['area'],'role'=>3));
  788. if($mid && $mid['id']){
  789. $data[$k]['countys']['mid'] = $mid['id'];
  790. }else{
  791. $data[$k]['countys']['mid'] = '-1';
  792. }
  793. $wh['county'] = $v['county'];
  794. $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  795. // #体验店
  796. $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  797. $data[$k]['countys']['type'] = array_column($t_shop,'id');
  798. $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  799. $data[$k]['countys']['t_num'] = count($t_shop);
  800. if($data[$k]['countys']['t_num']>0){
  801. $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  802. $data[$k]['countys']['t_fprice'] = $data[$k]['countys']['price'];
  803. }else{
  804. $data[$k]['countys']['t_price'] = 0;
  805. $data[$k]['countys']['t_fprice'] = 0;
  806. }
  807. #零售店
  808. $where['county'] = $v['county'];
  809. $shop_area = $this->ls($where,2);
  810. $data[$k]['countys']['l_price'] = $shop_area['price'];
  811. $data[$k]['countys']['l_fprice'] = $shop_area['price'] * 0.03;
  812. $data[$k]['countys']['l_num'] = $shop_area['num'];
  813. $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_fprice'];
  814. $w['mid'] = $data[$k]['countys']['mid'];
  815. $w['name'] = $data[$k]['countys']['area'];
  816. $w['price'] = $data[$k]['countys']['price'];
  817. $w['num'] = $data[$k]['countys']['num'];
  818. $w['c_price'] = $jia['price'];
  819. // $data[$k]['countys']['money']['total'];
  820. $w['t_num'] = $data[$k]['countys']['t_num'];
  821. $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  822. $w['t_fprice'] = $data[$k]['countys']['t_fprice'];
  823. $w['l_num'] = $data[$k]['countys']['l_num'];
  824. $w['l_price'] = $shop_area['price'];
  825. $w['l_fprice'] = $data[$k]['countys']['l_fprice'];
  826. $w['parent_id'] = $city_area_stat;
  827. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['countys']['area']));
  828. if(!$shop){
  829. $county_area_stat = Dever::db('mail/area_stat')->insert($w);
  830. }else{
  831. $county_area_stat = $w['where_id'] = $shop['id'];
  832. Dever::db('mail/area_stat')->update($w);
  833. }
  834. }
  835. #街道
  836. if($v['town']>0){
  837. $where['area'] = $v['town'];
  838. $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  839. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  840. $jia = $this->caigou($where);
  841. $data[$k]['towns']['price'] = $jia['money'] * 0.05;
  842. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  843. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['towns']['area'],'role'=>4));
  844. if($mid && $mid['id']){
  845. $data[$k]['towns']['mid'] = $mid['id'];
  846. }else{
  847. $data[$k]['towns']['mid'] = '-1';
  848. }
  849. $whe['town'] = $v['town'];
  850. $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  851. #体验店
  852. $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  853. $data[$k]['towns']['type'] = array_column($t_shop,'id');
  854. $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  855. $data[$k]['towns']['t_num'] = count($t_shop);
  856. if($data[$k]['towns']['t_num']>0){
  857. $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  858. $data[$k]['towns']['t_fprice'] = $data[$k]['towns']['price'];
  859. }else{
  860. $data[$k]['towns']['t_price'] = 0;
  861. $data[$k]['towns']['t_fprice'] = 0;
  862. }
  863. #零售店
  864. $where['town'] = $v['town'];
  865. $shop_area = $this->ls($where,3);
  866. $data[$k]['towns']['l_price'] =$shop_area['price'];
  867. $data[$k]['towns']['l_fprice'] =$shop_area['price'] * 0.05;
  868. $data[$k]['towns']['l_num'] = $shop_area['num'];
  869. $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_fprice'];
  870. $w['mid'] = $data[$k]['towns']['mid'];
  871. $w['name'] = $data[$k]['towns']['area'];
  872. $w['price'] = $data[$k]['towns']['price'];
  873. $w['num'] = $data[$k]['towns']['num'];
  874. $w['c_price'] = $jia['price'];
  875. // $data[$k]['towns']['money']['total'];
  876. $w['t_num'] = $data[$k]['towns']['t_num'];
  877. $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  878. $w['t_fprice'] = $data[$k]['towns']['t_fprice'];
  879. $w['l_num'] = $data[$k]['towns']['l_num'];
  880. $w['l_price'] = $shop_area['price'];
  881. $w['l_fprice'] = $data[$k]['towns']['l_fprice'];
  882. $w['parent_id'] = $county_area_stat;
  883. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['towns']['area']));
  884. if(!$shop){
  885. Dever::db('mail/area_stat')->insert($w);
  886. }else{
  887. $w['where_id'] = $shop['id'];
  888. Dever::db('mail/area_stat')->update($w);
  889. }
  890. }
  891. }
  892. return 'ok';
  893. }
  894. // public function area_api(){
  895. // #零售店的采购金额*0.4
  896. // $month = Dever::input('month', date('Y-m'));
  897. // $start_time = $month .'-01 00:00:00';
  898. // $where = array();
  899. // $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
  900. // $where['start'] = Dever::maketime($start_time);
  901. // $where['end'] = Dever::maketime($end_time);
  902. // $where['state'] = 1;
  903. // $data = array();
  904. // $shop = Dever::db('shop/info')->getAreaAll(array('state'=>1));
  905. // foreach($shop as $k=>$v){
  906. // $data[$v['city']]=$v;
  907. // }
  908. // $shop_area = Dever::db('mail/area_entry')->getAll($where);
  909. // $res = array();
  910. // if($shop_area){
  911. // foreach($shop_area as $k => $v){
  912. // if($v['area']){
  913. // $area = explode(',',$v['area']);
  914. // if($area && isset($area[0])){
  915. // $res[$k]['province'] = $area[0];
  916. // }
  917. // if ($area && isset($area[1])){
  918. // $res[$k]['city'] = $area[1];
  919. // }else{
  920. // $res[$k]['city'] = 0;
  921. // }
  922. // if($area && isset($area[2])){
  923. // $res[$k]['county'] = $area[2];
  924. // }else{
  925. // $res[$k]['county'] = 0;
  926. // }
  927. // if($area && isset($area[3])){
  928. // $res[$k]['town'] = $area[3];
  929. // }else{
  930. // $res[$k]['town'] = 0;
  931. // }
  932. // }
  933. // }
  934. // }
  935. // $data = array_values($data);
  936. // $data = array_merge($data,$res);
  937. // // print_R($data);die;
  938. // $result=array_unique($data, SORT_REGULAR);
  939. // $rest=array();
  940. // foreach($data as $k=>$v){
  941. // $rest[$v['county']]=$v;
  942. // }
  943. // $data=array_values($rest);
  944. // foreach ($data as $k => $v) {
  945. // $edition[] = $v['province'];
  946. // }
  947. // array_multisort($edition, SORT_ASC, $data);
  948. // foreach($data as $k => $v){
  949. // $w['month'] = $where['start'];
  950. // #城市
  951. // if($v['city']>0){
  952. // $where['area'] = $v['city'];
  953. // $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  954. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  955. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  956. // $mid = Dever::db('agent/member')->getAreaAll($where);
  957. // $w['citys']['area'] = $v['city'];
  958. // if($mid && $mid['id']){
  959. // $data[$k]['citys']['mid'] = $mid['id'];
  960. // }else{
  961. // $data[$k]['citys']['mid'] = '';
  962. // }
  963. // $where['city'] = $v['city'];
  964. // $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  965. // #体验店
  966. // $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  967. // $data[$k]['citys']['type'] = array_column($t_shop,'id');
  968. // $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  969. // $data[$k]['citys']['t_num'] = count($t_shop);
  970. // if($data[$k]['citys']['t_num']>0){
  971. // $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  972. // }else{
  973. // $data[$k]['citys']['t_price'] = 0;
  974. // }
  975. // #零售店
  976. // $entry = Dever::db('mail/area_entry')->getNum($where);
  977. // if ($entry && $entry['num']){
  978. // $data[$k]['citys']['l_num'] = $entry['num'];
  979. // $data[$k]['citys']['num'] = $data[$k]['citys']['num'] + $data[$k]['citys']['l_num'];
  980. // }else{
  981. // $data[$k]['citys']['l_num'] = 0;
  982. // }
  983. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  984. // if ($entry_price && $entry_price['cprice'] ){
  985. // $data[$k]['citys']['l_price'] = $entry_price['cprice'] * 0.4;
  986. // $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_price'];
  987. // }else{
  988. // $data[$k]['citys']['l_price'] = 0;
  989. // }
  990. // $w['mid'] = $data[$k]['citys']['mid'];
  991. // $w['area'] = $data[$k]['citys']['area'];
  992. // $w['price'] = $data[$k]['citys']['price'];
  993. // $w['c_price'] = $data[$k]['citys']['money']['total'];
  994. // $w['num'] = $data[$k]['citys']['num'];
  995. // $w['t_num'] = $data[$k]['citys']['t_num'];
  996. // $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  997. // $w['l_num'] = $data[$k]['citys']['l_num'];
  998. // $w['l_price'] = $data[$k]['citys']['l_price'];
  999. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['citys']['area']));
  1000. // if(!$shop){
  1001. // Dever::db('mail/area_stat')->insert($w);
  1002. // }else{
  1003. // $w['where_id'] = $shop['id'];
  1004. // Dever::db('mail/area_stat')->update($w);
  1005. // }
  1006. // }
  1007. // #区县
  1008. // if($v['county']>0){
  1009. // $where['area'] = $v['county'];
  1010. // $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  1011. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  1012. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  1013. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1014. // if($mid && $mid['id']){
  1015. // $data[$k]['countys']['mid'] = $mid['id'];
  1016. // }else{
  1017. // $data[$k]['countys']['mid'] = '';
  1018. // }
  1019. // $wh['county'] = $v['county'];
  1020. // $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  1021. // // #体验店
  1022. // $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  1023. // $data[$k]['countys']['type'] = array_column($t_shop,'id');
  1024. // $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  1025. // $data[$k]['countys']['t_num'] = count($t_shop);
  1026. // if($data[$k]['countys']['t_num']>0){
  1027. // $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1028. // }else{
  1029. // $data[$k]['countys']['t_price'] = 0;
  1030. // }
  1031. // #零售店
  1032. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1033. // if ($entry && $entry['num']){
  1034. // $data[$k]['countys']['l_num'] = $entry['num'];
  1035. // $data[$k]['countys']['num'] = $data[$k]['countys']['num'] + $data[$k]['countys']['l_num'];
  1036. // }else{
  1037. // $data[$k]['countys']['l_num'] = 0;
  1038. // }
  1039. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1040. // if ($entry_price && $entry_price['cprice'] ){
  1041. // $data[$k]['countys']['l_price'] = $entry_price['cprice'] * 0.4;
  1042. // $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_price'];
  1043. // }else{
  1044. // $data[$k]['countys']['l_price'] = 0;
  1045. // }
  1046. // $w['mid'] = $data[$k]['countys']['mid'];
  1047. // $w['area'] = $data[$k]['countys']['area'];
  1048. // $w['price'] = $data[$k]['countys']['price'];
  1049. // $w['num'] = $data[$k]['countys']['num'];
  1050. // $w['c_price'] = $data[$k]['countys']['money']['total'];
  1051. // $w['t_num'] = $data[$k]['countys']['t_num'];
  1052. // $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  1053. // $w['l_num'] = $data[$k]['countys']['l_num'];
  1054. // $w['l_price'] = $data[$k]['countys']['l_price'];
  1055. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['countys']['area']));
  1056. // if(!$shop){
  1057. // Dever::db('mail/area_stat')->insert($w);
  1058. // }else{
  1059. // $w['where_id'] = $shop['id'];
  1060. // Dever::db('mail/area_stat')->update($w);
  1061. // }
  1062. // }
  1063. // #街道
  1064. // if($v['town']>0){
  1065. // $where['area'] = $v['town'];
  1066. // $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  1067. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  1068. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  1069. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1070. // if($mid && $mid['id']){
  1071. // $data[$k]['towns']['mid'] = $mid['id'];
  1072. // }else{
  1073. // $data[$k]['towns']['mid'] = '';
  1074. // }
  1075. // $whe['town'] = $v['town'];
  1076. // $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  1077. // #体验店
  1078. // $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  1079. // $data[$k]['towns']['type'] = array_column($t_shop,'id');
  1080. // $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  1081. // $data[$k]['towns']['t_num'] = count($t_shop);
  1082. // if($data[$k]['towns']['t_num']>0){
  1083. // $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1084. // }else{
  1085. // $data[$k]['towns']['t_price'] = 0;
  1086. // }
  1087. // #零售店
  1088. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1089. // if ($entry && $entry['num']){
  1090. // $data[$k]['towns']['l_num'] = $entry['num'];
  1091. // $data[$k]['towns']['num'] = $data[$k]['towns']['num'] + $data[$k]['towns']['l_num'];
  1092. // }else{
  1093. // $data[$k]['towns']['l_num'] = 0;
  1094. // }
  1095. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1096. // if ($entry_price && $entry_price['cprice'] ){
  1097. // $data[$k]['towns']['l_price'] = $entry_price['cprice'] * 0.4;
  1098. // $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_price'];
  1099. // }else{
  1100. // $data[$k]['towns']['l_price'] = 0;
  1101. // }
  1102. // $w['mid'] = $data[$k]['towns']['mid'];
  1103. // $w['area'] = $data[$k]['towns']['area'];
  1104. // $w['price'] = $data[$k]['towns']['price'];
  1105. // $w['num'] = $data[$k]['towns']['num'];
  1106. // $w['c_price'] = $data[$k]['towns']['money']['total'];
  1107. // $w['t_num'] = $data[$k]['towns']['t_num'];
  1108. // $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  1109. // $w['l_num'] = $data[$k]['towns']['l_num'];
  1110. // $w['l_price'] = $data[$k]['towns']['l_price'];
  1111. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['towns']['area']));
  1112. // if(!$shop){
  1113. // Dever::db('mail/area_stat')->insert($w);
  1114. // }else{
  1115. // $w['where_id'] = $shop['id'];
  1116. // Dever::db('mail/area_stat')->update($w);
  1117. // }
  1118. // }
  1119. // }
  1120. // return 'ok';
  1121. // }
  1122. public function area_member($id){
  1123. $info = Dever::db('mail/area_stat')->find($id);
  1124. $res = '-';
  1125. if($info['mid']){
  1126. $member = Dever::db('agent/member')->find($info['mid']);
  1127. if ($member) {
  1128. $res = $member['name']."<br/>".$member['mobile'];
  1129. }
  1130. }
  1131. return $res;
  1132. }
  1133. public function entry_member($id){
  1134. $info = Dever::db('mail/area_entry')->find($id);
  1135. if($info['shop_id']){
  1136. $member = Dever::db('shop/info')->find($info['shop_id']);
  1137. // print_R($member);die;
  1138. $res = $member['name'].'<br/>'.$member['sid'];
  1139. }else{
  1140. $res = '-';
  1141. }
  1142. return $res;
  1143. }
  1144. public function updateArea_entry($id,$name,$data){
  1145. $sid = Dever::param('sid',$data);
  1146. $month = Dever::param('month',$data);
  1147. if ($id && $sid) {
  1148. $info = Dever::db('mail/area_entry')->find($id);
  1149. $member = Dever::db('shop/info')->find(array('sid'=>$sid));
  1150. // print_R($member);die;
  1151. $where['where_id'] = $id ;
  1152. $where['shop_id'] = $member['id'];
  1153. $where['month'] = strtotime($month);
  1154. Dever::db('mail/area_entry')->update($where);
  1155. }
  1156. }
  1157. }