Manage.php 58 KB

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