Manage.php 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  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, $per)
  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. $shop = array();
  665. if ($order) {
  666. foreach($order as $k => $v) {
  667. if (!isset($shop[$v['type_id']])) {
  668. $shop[$v['type_id']] = 0;
  669. }
  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. $price = ($v['price'] - $c_price);
  679. $total += $price;
  680. $shop[$v['type_id']] += round($price * $per, 2);
  681. }
  682. }
  683. return array(round($total, 2), round($total*$per, 2), $shop);
  684. }
  685. # 零售店毛利
  686. public function l_buy($where, $shop_id, $per)
  687. {
  688. $where['shop_id'] = $shop_id;
  689. $data = Dever::db('mail/area_entry')->getBuy($where);
  690. $total = 0;
  691. $shop = array();
  692. if ($data) {
  693. foreach ($data as $k => $v) {
  694. if (!isset($shop[$v['type_id']])) {
  695. $shop[$v['shop_id']] = 0;
  696. }
  697. $price = $v['buy'];
  698. $total += $price;
  699. $shop[$v['shop_id']] += round($price * $per, 2);
  700. }
  701. }
  702. return array(round($total, 2), round($total*$per, 2), $shop);
  703. }
  704. # 区域分润
  705. public function area_api()
  706. {
  707. /*
  708. $month = Dever::input('month', date('Y-m'));
  709. $start_time = $month .'-01 00:00:00';
  710. $where = array();
  711. $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
  712. $where['start'] = Dever::maketime($start_time);
  713. $where['end'] = Dever::maketime($end_time);
  714. */
  715. # 设置利润计算规则:
  716. $config = array
  717. (
  718. 1 => 0.01,
  719. 2 => 0.03,
  720. 3 => 0.05,
  721. );
  722. # 传入day,获取月开始和月结束日期
  723. list($where['start'], $where['end']) = Dever::month();
  724. $month = Dever::maketime(date('Y-m', $where['start']));
  725. # 获取区域
  726. $area = array();
  727. $shop = Dever::db('shop/info')->select();
  728. if ($shop) {
  729. foreach ($shop as $k => $v) {
  730. if ($v['type'] != 10) {
  731. if ($v['city'] > 0) {
  732. $key = $v['province'] . ',' . $v['city'];
  733. $area[$key]['shop_id'][$v['type']][] = $v['id'];
  734. $area[$key]['type'] = 1;
  735. }
  736. if ($v['county'] > 0) {
  737. $key = $v['province'] . ',' . $v['city'] . ',' . $v['county'];
  738. $area[$key]['shop_id'][$v['type']][] = $v['id'];
  739. $area[$key]['type'] = 2;
  740. }
  741. if ($v['town'] > 0) {
  742. $key = $v['province'] . ',' . $v['city'] . ',' . $v['county'] . ',' . $v['town'];
  743. $area[$key]['shop_id'][$v['type']][] = $v['id'];
  744. $area[$key]['type'] = 3;
  745. }
  746. }
  747. }
  748. $area_id = array();
  749. $shop_data = array();
  750. foreach ($area as $k => $v) {
  751. $update = array();
  752. $update['month'] = $month;
  753. $update['name'] = $k;
  754. $info = Dever::db('mail/area_stat')->find($update);
  755. # 设置金额
  756. $update['t_num'] = $update['l_num'] = $update['t_cash'] = $update['l_cash'] = $update['t_buy'] = $update['l_buy'] = 0;
  757. $update['data'] = array();
  758. foreach ($v['shop_id'] as $k1 => $v1) {
  759. if ($k1 == 1) {
  760. # 体验店
  761. $update['t_num'] = count($v1);
  762. list($update['t_buy'], $update['t_cash'], $shop_data) = $this->t_buy($where, $v1, $config[$v['type']]);
  763. if ($shop_data) {
  764. $update['data'] += $shop_data;
  765. }
  766. } elseif ($k1 == 2) {
  767. # 零售店
  768. $update['l_num'] = count($v1);
  769. list($update['l_buy'], $update['l_cash'], $shop_data) = $this->l_buy($where, $v1, $config[$v['type']]);
  770. if ($shop_data) {
  771. $update['data'] += $shop_data;
  772. }
  773. }
  774. }
  775. if ($update['t_buy'] == 0 && $update['l_buy'] == 0) {
  776. continue;
  777. }
  778. # 设置上级id,用来做列表层级展示
  779. if ($v['type'] == 1) {
  780. $update['parent_id'] = -1;
  781. } elseif ($v['type'] == 2) {
  782. $area_value = explode(',', $k);
  783. $k2 = $area_value[0] . ',' . $area_value[1];
  784. $update['parent_id'] = isset($area_id[$k2]) ? $area_id[$k2] : -1;
  785. } elseif ($v['type'] == 3) {
  786. $area_value = explode(',', $k);
  787. $k2 = $area_value[0] . ',' . $area_value[1] . ',' . $area_value[2];
  788. $update['parent_id'] = isset($area_id[$k2]) ? $area_id[$k2] : -1;
  789. }
  790. # 设置收益代理商
  791. $member = Dever::db('agent/member')->getAreaAll(array('area' => $k));
  792. if ($member) {
  793. $update['mid'] = $member['id'];
  794. }
  795. $update['data'] = Dever::json_encode($update['data']);
  796. if (!$info) {
  797. $stat_id = Dever::db('mail/area_stat')->insert($update);
  798. } else {
  799. $stat_id = $update['where_id'] = $info['id'];
  800. Dever::db('mail/area_stat')->update($update);
  801. }
  802. if ($v['type'] == 1) {
  803. $area_id[$k] = $stat_id;
  804. } elseif ($v['type'] == 2) {
  805. $area_id[$k] = $stat_id;
  806. }
  807. }
  808. }
  809. /*
  810. $data = array();
  811. $data = Dever::db('shop/info')->getAreaAll(array('state'=>1));
  812. foreach($data as $k => $v){
  813. $w['month'] = $where['start'];
  814. #城市
  815. if($v['city']>0){
  816. $city_area_stat = -1;
  817. $where['area'] = $v['city'];
  818. $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  819. $where['parent_type'] = '1,3';
  820. // print_R($where);die;
  821. $jia = $this->caigou($where);
  822. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  823. $data[$k]['citys']['price']= $jia['money'] * 0.01;
  824. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  825. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['citys']['area'],'role'=>2));
  826. $w['citys']['area'] = $v['city'];
  827. if($mid && $mid['id']){
  828. $data[$k]['citys']['mid'] = $mid['id'];
  829. }else{
  830. $data[$k]['citys']['mid'] = '-1';
  831. }
  832. $where['city'] = $v['city'];
  833. $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  834. #体验店
  835. $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  836. $data[$k]['citys']['type'] = array_column($t_shop,'id');
  837. $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  838. $data[$k]['citys']['t_num'] = count($t_shop);
  839. if($data[$k]['citys']['t_num']>0){
  840. $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  841. $data[$k]['citys']['t_fprice'] = $data[$k]['citys']['price'];
  842. }else{
  843. $data[$k]['citys']['t_price'] = 0;
  844. $data[$k]['citys']['t_fprice'] = 0;
  845. }
  846. #零售店
  847. $shop_area = $this->ls($where,1);
  848. $data[$k]['citys']['l_price'] =$shop_area['price'];
  849. $data[$k]['citys']['l_fprice'] =$shop_area['price'] * 0.01;
  850. $data[$k]['citys']['l_num'] = $shop_area['num'];
  851. $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_fprice'];
  852. $w['mid'] = $data[$k]['citys']['mid'];
  853. $w['name'] = $data[$k]['citys']['area'];
  854. $w['price'] = $data[$k]['citys']['price'];
  855. $w['c_price'] = $jia['price'];
  856. // $data[$k]['citys']['money']['total'];
  857. $w['num'] = $data[$k]['citys']['num'];
  858. $w['t_num'] = $data[$k]['citys']['t_num'];
  859. $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  860. $w['t_fprice'] = $data[$k]['citys']['t_fprice'];
  861. $w['l_num'] = $data[$k]['citys']['l_num'];
  862. $w['l_price'] = $shop_area['price'];
  863. $w['l_fprice'] = $data[$k]['citys']['l_fprice'];
  864. $w['parent_id'] = -1;
  865. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['citys']['area']));
  866. if(!$shop){
  867. $city_area_stat = Dever::db('mail/area_stat')->insert($w);
  868. }else{
  869. $city_area_stat = $w['where_id'] = $shop['id'];
  870. Dever::db('mail/area_stat')->update($w);
  871. }
  872. }
  873. #区县
  874. if($v['county']>0){
  875. $county_area_stat = -1;
  876. $where['area'] = $v['county'];
  877. $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  878. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  879. $jia = $this->caigou($where);
  880. $data[$k]['countys']['price']= $jia['money'] *0.03;
  881. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  882. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['countys']['area'],'role'=>3));
  883. if($mid && $mid['id']){
  884. $data[$k]['countys']['mid'] = $mid['id'];
  885. }else{
  886. $data[$k]['countys']['mid'] = '-1';
  887. }
  888. $wh['county'] = $v['county'];
  889. $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  890. // #体验店
  891. $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  892. $data[$k]['countys']['type'] = array_column($t_shop,'id');
  893. $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  894. $data[$k]['countys']['t_num'] = count($t_shop);
  895. if($data[$k]['countys']['t_num']>0){
  896. $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  897. $data[$k]['countys']['t_fprice'] = $data[$k]['countys']['price'];
  898. }else{
  899. $data[$k]['countys']['t_price'] = 0;
  900. $data[$k]['countys']['t_fprice'] = 0;
  901. }
  902. #零售店
  903. $where['county'] = $v['county'];
  904. $shop_area = $this->ls($where,2);
  905. $data[$k]['countys']['l_price'] = $shop_area['price'];
  906. $data[$k]['countys']['l_fprice'] = $shop_area['price'] * 0.03;
  907. $data[$k]['countys']['l_num'] = $shop_area['num'];
  908. $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_fprice'];
  909. $w['mid'] = $data[$k]['countys']['mid'];
  910. $w['name'] = $data[$k]['countys']['area'];
  911. $w['price'] = $data[$k]['countys']['price'];
  912. $w['num'] = $data[$k]['countys']['num'];
  913. $w['c_price'] = $jia['price'];
  914. // $data[$k]['countys']['money']['total'];
  915. $w['t_num'] = $data[$k]['countys']['t_num'];
  916. $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  917. $w['t_fprice'] = $data[$k]['countys']['t_fprice'];
  918. $w['l_num'] = $data[$k]['countys']['l_num'];
  919. $w['l_price'] = $shop_area['price'];
  920. $w['l_fprice'] = $data[$k]['countys']['l_fprice'];
  921. $w['parent_id'] = $city_area_stat;
  922. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['countys']['area']));
  923. if(!$shop){
  924. $county_area_stat = Dever::db('mail/area_stat')->insert($w);
  925. }else{
  926. $county_area_stat = $w['where_id'] = $shop['id'];
  927. Dever::db('mail/area_stat')->update($w);
  928. }
  929. }
  930. #街道
  931. if($v['town']>0){
  932. $where['area'] = $v['town'];
  933. $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  934. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  935. $jia = $this->caigou($where);
  936. $data[$k]['towns']['price'] = $jia['money'] * 0.05;
  937. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  938. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['towns']['area'],'role'=>4));
  939. if($mid && $mid['id']){
  940. $data[$k]['towns']['mid'] = $mid['id'];
  941. }else{
  942. $data[$k]['towns']['mid'] = '-1';
  943. }
  944. $whe['town'] = $v['town'];
  945. $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  946. #体验店
  947. $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  948. $data[$k]['towns']['type'] = array_column($t_shop,'id');
  949. $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  950. $data[$k]['towns']['t_num'] = count($t_shop);
  951. if($data[$k]['towns']['t_num']>0){
  952. $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  953. $data[$k]['towns']['t_fprice'] = $data[$k]['towns']['price'];
  954. }else{
  955. $data[$k]['towns']['t_price'] = 0;
  956. $data[$k]['towns']['t_fprice'] = 0;
  957. }
  958. #零售店
  959. $where['town'] = $v['town'];
  960. $shop_area = $this->ls($where,3);
  961. $data[$k]['towns']['l_price'] =$shop_area['price'];
  962. $data[$k]['towns']['l_fprice'] =$shop_area['price'] * 0.05;
  963. $data[$k]['towns']['l_num'] = $shop_area['num'];
  964. $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_fprice'];
  965. $w['mid'] = $data[$k]['towns']['mid'];
  966. $w['name'] = $data[$k]['towns']['area'];
  967. $w['price'] = $data[$k]['towns']['price'];
  968. $w['num'] = $data[$k]['towns']['num'];
  969. $w['c_price'] = $jia['price'];
  970. // $data[$k]['towns']['money']['total'];
  971. $w['t_num'] = $data[$k]['towns']['t_num'];
  972. $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  973. $w['t_fprice'] = $data[$k]['towns']['t_fprice'];
  974. $w['l_num'] = $data[$k]['towns']['l_num'];
  975. $w['l_price'] = $shop_area['price'];
  976. $w['l_fprice'] = $data[$k]['towns']['l_fprice'];
  977. $w['parent_id'] = $county_area_stat;
  978. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['towns']['area']));
  979. if(!$shop){
  980. Dever::db('mail/area_stat')->insert($w);
  981. }else{
  982. $w['where_id'] = $shop['id'];
  983. Dever::db('mail/area_stat')->update($w);
  984. }
  985. }
  986. }
  987. */
  988. return 'ok';
  989. }
  990. /*
  991. #采购价-成本价
  992. public function caigou($where){
  993. $data = Dever::db('shop/buy_order')->getNewAll($where);
  994. $res = array();
  995. $money = 0;
  996. $res['money'] = 0;
  997. if($data && isset($data['price']) && $data['price']){
  998. $res['price'] = $data['price'];
  999. }else{
  1000. $res['price'] = 0;
  1001. }
  1002. foreach($data as $k => $v){
  1003. // $goods_id,$skuid
  1004. $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  1005. $c_price = 0;
  1006. foreach($order_goods as $k1 => $v1){
  1007. $goods = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
  1008. if($goods['c_price'] && $goods['c_price'] >= 0){
  1009. $c_price += $goods['c_price'] * $v1['num'];
  1010. }
  1011. }
  1012. $res['money'] += ($v['price'] - $c_price);
  1013. }
  1014. return $res;
  1015. }
  1016. #零售
  1017. public function ls($where,$type=false){
  1018. $shop = Dever::db('mail/area_entry')->getNewAll($where);
  1019. $data = array();
  1020. $data['price'] = 0;
  1021. foreach($shop as $k => $v){
  1022. if ($type == 1) {
  1023. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('city'=>$where['city'],'id'=>$v['shop_id']));
  1024. } elseif ($type == 2) {
  1025. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('county'=>$where['county'],'id'=>$v['shop_id']));
  1026. } elseif ($type == 3) {
  1027. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('town'=>$where['town'],'id'=>$v['shop_id']));
  1028. }
  1029. }
  1030. foreach($shop as $k => $v){
  1031. if(!$v['shop']){
  1032. unset($shop[$k]);
  1033. }
  1034. }
  1035. foreach($shop as $k=>$v){
  1036. $data['price'] +=$v['cprice'];
  1037. }
  1038. $data['num'] = count($shop);
  1039. return $data;
  1040. }
  1041. */
  1042. // public function area_api(){
  1043. // #零售店的采购金额*0.4
  1044. // $month = Dever::input('month', date('Y-m'));
  1045. // $start_time = $month .'-01 00:00:00';
  1046. // $where = array();
  1047. // $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
  1048. // $where['start'] = Dever::maketime($start_time);
  1049. // $where['end'] = Dever::maketime($end_time);
  1050. // $where['state'] = 1;
  1051. // $data = array();
  1052. // $shop = Dever::db('shop/info')->getAreaAll(array('state'=>1));
  1053. // foreach($shop as $k=>$v){
  1054. // $data[$v['city']]=$v;
  1055. // }
  1056. // $shop_area = Dever::db('mail/area_entry')->getAll($where);
  1057. // $res = array();
  1058. // if($shop_area){
  1059. // foreach($shop_area as $k => $v){
  1060. // if($v['area']){
  1061. // $area = explode(',',$v['area']);
  1062. // if($area && isset($area[0])){
  1063. // $res[$k]['province'] = $area[0];
  1064. // }
  1065. // if ($area && isset($area[1])){
  1066. // $res[$k]['city'] = $area[1];
  1067. // }else{
  1068. // $res[$k]['city'] = 0;
  1069. // }
  1070. // if($area && isset($area[2])){
  1071. // $res[$k]['county'] = $area[2];
  1072. // }else{
  1073. // $res[$k]['county'] = 0;
  1074. // }
  1075. // if($area && isset($area[3])){
  1076. // $res[$k]['town'] = $area[3];
  1077. // }else{
  1078. // $res[$k]['town'] = 0;
  1079. // }
  1080. // }
  1081. // }
  1082. // }
  1083. // $data = array_values($data);
  1084. // $data = array_merge($data,$res);
  1085. // // print_R($data);die;
  1086. // $result=array_unique($data, SORT_REGULAR);
  1087. // $rest=array();
  1088. // foreach($data as $k=>$v){
  1089. // $rest[$v['county']]=$v;
  1090. // }
  1091. // $data=array_values($rest);
  1092. // foreach ($data as $k => $v) {
  1093. // $edition[] = $v['province'];
  1094. // }
  1095. // array_multisort($edition, SORT_ASC, $data);
  1096. // foreach($data as $k => $v){
  1097. // $w['month'] = $where['start'];
  1098. // #城市
  1099. // if($v['city']>0){
  1100. // $where['area'] = $v['city'];
  1101. // $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  1102. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  1103. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  1104. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1105. // $w['citys']['area'] = $v['city'];
  1106. // if($mid && $mid['id']){
  1107. // $data[$k]['citys']['mid'] = $mid['id'];
  1108. // }else{
  1109. // $data[$k]['citys']['mid'] = '';
  1110. // }
  1111. // $where['city'] = $v['city'];
  1112. // $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  1113. // #体验店
  1114. // $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  1115. // $data[$k]['citys']['type'] = array_column($t_shop,'id');
  1116. // $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  1117. // $data[$k]['citys']['t_num'] = count($t_shop);
  1118. // if($data[$k]['citys']['t_num']>0){
  1119. // $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1120. // }else{
  1121. // $data[$k]['citys']['t_price'] = 0;
  1122. // }
  1123. // #零售店
  1124. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1125. // if ($entry && $entry['num']){
  1126. // $data[$k]['citys']['l_num'] = $entry['num'];
  1127. // $data[$k]['citys']['num'] = $data[$k]['citys']['num'] + $data[$k]['citys']['l_num'];
  1128. // }else{
  1129. // $data[$k]['citys']['l_num'] = 0;
  1130. // }
  1131. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1132. // if ($entry_price && $entry_price['cprice'] ){
  1133. // $data[$k]['citys']['l_price'] = $entry_price['cprice'] * 0.4;
  1134. // $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_price'];
  1135. // }else{
  1136. // $data[$k]['citys']['l_price'] = 0;
  1137. // }
  1138. // $w['mid'] = $data[$k]['citys']['mid'];
  1139. // $w['area'] = $data[$k]['citys']['area'];
  1140. // $w['price'] = $data[$k]['citys']['price'];
  1141. // $w['c_price'] = $data[$k]['citys']['money']['total'];
  1142. // $w['num'] = $data[$k]['citys']['num'];
  1143. // $w['t_num'] = $data[$k]['citys']['t_num'];
  1144. // $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  1145. // $w['l_num'] = $data[$k]['citys']['l_num'];
  1146. // $w['l_price'] = $data[$k]['citys']['l_price'];
  1147. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['citys']['area']));
  1148. // if(!$shop){
  1149. // Dever::db('mail/area_stat')->insert($w);
  1150. // }else{
  1151. // $w['where_id'] = $shop['id'];
  1152. // Dever::db('mail/area_stat')->update($w);
  1153. // }
  1154. // }
  1155. // #区县
  1156. // if($v['county']>0){
  1157. // $where['area'] = $v['county'];
  1158. // $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  1159. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  1160. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  1161. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1162. // if($mid && $mid['id']){
  1163. // $data[$k]['countys']['mid'] = $mid['id'];
  1164. // }else{
  1165. // $data[$k]['countys']['mid'] = '';
  1166. // }
  1167. // $wh['county'] = $v['county'];
  1168. // $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  1169. // // #体验店
  1170. // $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  1171. // $data[$k]['countys']['type'] = array_column($t_shop,'id');
  1172. // $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  1173. // $data[$k]['countys']['t_num'] = count($t_shop);
  1174. // if($data[$k]['countys']['t_num']>0){
  1175. // $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1176. // }else{
  1177. // $data[$k]['countys']['t_price'] = 0;
  1178. // }
  1179. // #零售店
  1180. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1181. // if ($entry && $entry['num']){
  1182. // $data[$k]['countys']['l_num'] = $entry['num'];
  1183. // $data[$k]['countys']['num'] = $data[$k]['countys']['num'] + $data[$k]['countys']['l_num'];
  1184. // }else{
  1185. // $data[$k]['countys']['l_num'] = 0;
  1186. // }
  1187. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1188. // if ($entry_price && $entry_price['cprice'] ){
  1189. // $data[$k]['countys']['l_price'] = $entry_price['cprice'] * 0.4;
  1190. // $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_price'];
  1191. // }else{
  1192. // $data[$k]['countys']['l_price'] = 0;
  1193. // }
  1194. // $w['mid'] = $data[$k]['countys']['mid'];
  1195. // $w['area'] = $data[$k]['countys']['area'];
  1196. // $w['price'] = $data[$k]['countys']['price'];
  1197. // $w['num'] = $data[$k]['countys']['num'];
  1198. // $w['c_price'] = $data[$k]['countys']['money']['total'];
  1199. // $w['t_num'] = $data[$k]['countys']['t_num'];
  1200. // $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  1201. // $w['l_num'] = $data[$k]['countys']['l_num'];
  1202. // $w['l_price'] = $data[$k]['countys']['l_price'];
  1203. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['countys']['area']));
  1204. // if(!$shop){
  1205. // Dever::db('mail/area_stat')->insert($w);
  1206. // }else{
  1207. // $w['where_id'] = $shop['id'];
  1208. // Dever::db('mail/area_stat')->update($w);
  1209. // }
  1210. // }
  1211. // #街道
  1212. // if($v['town']>0){
  1213. // $where['area'] = $v['town'];
  1214. // $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  1215. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  1216. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  1217. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1218. // if($mid && $mid['id']){
  1219. // $data[$k]['towns']['mid'] = $mid['id'];
  1220. // }else{
  1221. // $data[$k]['towns']['mid'] = '';
  1222. // }
  1223. // $whe['town'] = $v['town'];
  1224. // $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  1225. // #体验店
  1226. // $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  1227. // $data[$k]['towns']['type'] = array_column($t_shop,'id');
  1228. // $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  1229. // $data[$k]['towns']['t_num'] = count($t_shop);
  1230. // if($data[$k]['towns']['t_num']>0){
  1231. // $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1232. // }else{
  1233. // $data[$k]['towns']['t_price'] = 0;
  1234. // }
  1235. // #零售店
  1236. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1237. // if ($entry && $entry['num']){
  1238. // $data[$k]['towns']['l_num'] = $entry['num'];
  1239. // $data[$k]['towns']['num'] = $data[$k]['towns']['num'] + $data[$k]['towns']['l_num'];
  1240. // }else{
  1241. // $data[$k]['towns']['l_num'] = 0;
  1242. // }
  1243. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1244. // if ($entry_price && $entry_price['cprice'] ){
  1245. // $data[$k]['towns']['l_price'] = $entry_price['cprice'] * 0.4;
  1246. // $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_price'];
  1247. // }else{
  1248. // $data[$k]['towns']['l_price'] = 0;
  1249. // }
  1250. // $w['mid'] = $data[$k]['towns']['mid'];
  1251. // $w['area'] = $data[$k]['towns']['area'];
  1252. // $w['price'] = $data[$k]['towns']['price'];
  1253. // $w['num'] = $data[$k]['towns']['num'];
  1254. // $w['c_price'] = $data[$k]['towns']['money']['total'];
  1255. // $w['t_num'] = $data[$k]['towns']['t_num'];
  1256. // $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  1257. // $w['l_num'] = $data[$k]['towns']['l_num'];
  1258. // $w['l_price'] = $data[$k]['towns']['l_price'];
  1259. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['towns']['area']));
  1260. // if(!$shop){
  1261. // Dever::db('mail/area_stat')->insert($w);
  1262. // }else{
  1263. // $w['where_id'] = $shop['id'];
  1264. // Dever::db('mail/area_stat')->update($w);
  1265. // }
  1266. // }
  1267. // }
  1268. // return 'ok';
  1269. // }
  1270. public function area_member($id){
  1271. $info = Dever::db('mail/area_stat')->find($id);
  1272. $res = '-';
  1273. if($info['mid']){
  1274. $member = Dever::db('agent/member')->find($info['mid']);
  1275. if ($member) {
  1276. $res = $member['name']."<br/>".$member['mobile'];
  1277. }
  1278. }
  1279. return $res;
  1280. }
  1281. public function entry_member($id){
  1282. $info = Dever::db('mail/area_entry')->find($id);
  1283. if($info['shop_id']){
  1284. $member = Dever::db('shop/info')->find($info['shop_id']);
  1285. // print_R($member);die;
  1286. $res = $member['name'].'<br/>'.$member['sid'];
  1287. }else{
  1288. $res = '-';
  1289. }
  1290. return $res;
  1291. }
  1292. public function updateArea_entry($id,$name,$data){
  1293. $sid = Dever::param('sid',$data);
  1294. $month = Dever::param('month',$data);
  1295. if ($id && $sid) {
  1296. $info = Dever::db('mail/area_entry')->find($id);
  1297. $member = Dever::db('shop/info')->find(array('sid'=>$sid));
  1298. // print_R($member);die;
  1299. $where['where_id'] = $id ;
  1300. $where['shop_id'] = $member['id'];
  1301. $where['month'] = strtotime($month);
  1302. Dever::db('mail/area_entry')->update($where);
  1303. }
  1304. }
  1305. }