Manage.php 52 KB

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