Manage.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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. #采购价-成本价
  559. public function caigou($where){
  560. $data = Dever::db('shop/buy_order')->getNewAll($where);
  561. $res = array();
  562. $money = 0;
  563. $res['money'] = 0;
  564. if($data && isset($data['price']) && $data['price']){
  565. $res['price'] = $data['price'];
  566. }else{
  567. $res['price'] = 0;
  568. }
  569. foreach($data as $k => $v){
  570. // $goods_id,$skuid
  571. $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  572. $c_price = 0;
  573. foreach($order_goods as $k1 => $v1){
  574. $goods = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
  575. if($goods['c_price'] && $goods['c_price'] >= 0){
  576. $c_price += $goods['c_price'] * $v1['num'];
  577. }
  578. }
  579. $res['money'] += ($v['price'] - $c_price);
  580. }
  581. return $res;
  582. }
  583. #零售
  584. public function ls($where,$type=false){
  585. $shop = Dever::db('mail/area_entry')->getNewAll($where);
  586. $data = array();
  587. $data['price'] = 0;
  588. foreach($shop as $k => $v){
  589. if ($type == 1) {
  590. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('city'=>$where['city'],'id'=>$v['shop_id']));
  591. } elseif ($type == 2) {
  592. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('county'=>$where['county'],'id'=>$v['shop_id']));
  593. } elseif ($type == 3) {
  594. $shop[$k]['shop'] = Dever::db('shop/info')->find(array('town'=>$where['town'],'id'=>$v['shop_id']));
  595. }
  596. }
  597. foreach($shop as $k => $v){
  598. if(!$v['shop']){
  599. unset($shop[$k]);
  600. }
  601. }
  602. foreach($shop as $k=>$v){
  603. $data['price'] +=$v['cprice'];
  604. }
  605. $data['num'] = count($shop);
  606. return $data;
  607. }
  608. #区域分润
  609. public function area_api(){
  610. $month = Dever::input('month', date('Y-m'));
  611. $start_time = $month .'-01 00:00:00';
  612. $where = array();
  613. $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
  614. $where['start'] = Dever::maketime($start_time);
  615. $where['end'] = Dever::maketime($end_time);
  616. $where['state'] = 1;
  617. $data = array();
  618. $data = Dever::db('shop/info')->getAreaAll(array('state'=>1));
  619. foreach($data as $k => $v){
  620. $w['month'] = $where['start'];
  621. #城市
  622. if($v['city']>0){
  623. $where['area'] = $v['city'];
  624. $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  625. $jia = $this->caigou($where);
  626. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  627. $data[$k]['citys']['price']= $jia['money'] * 0.01;
  628. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  629. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['citys']['area'],'role'=>2));
  630. $w['citys']['area'] = $v['city'];
  631. if($mid && $mid['id']){
  632. $data[$k]['citys']['mid'] = $mid['id'];
  633. }else{
  634. $data[$k]['citys']['mid'] = '-1';
  635. }
  636. $where['city'] = $v['city'];
  637. $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  638. #体验店
  639. $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  640. $data[$k]['citys']['type'] = array_column($t_shop,'id');
  641. $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  642. $data[$k]['citys']['t_num'] = count($t_shop);
  643. if($data[$k]['citys']['t_num']>0){
  644. $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  645. $data[$k]['citys']['t_fprice'] = $data[$k]['citys']['price'];
  646. }else{
  647. $data[$k]['citys']['t_price'] = 0;
  648. $data[$k]['citys']['t_fprice'] = 0;
  649. }
  650. #零售店
  651. $shop_area = $this->ls($where,1);
  652. $data[$k]['citys']['l_price'] =$shop_area['price'];
  653. $data[$k]['citys']['l_fprice'] =$shop_area['price'] * 0.01;
  654. $data[$k]['citys']['l_num'] = $shop_area['num'];
  655. $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_fprice'];
  656. $w['mid'] = $data[$k]['citys']['mid'];
  657. $w['area'] = $data[$k]['citys']['area'];
  658. $w['price'] = $data[$k]['citys']['price'];
  659. $w['c_price'] = $jia['price'];
  660. // $data[$k]['citys']['money']['total'];
  661. $w['num'] = $data[$k]['citys']['num'];
  662. $w['t_num'] = $data[$k]['citys']['t_num'];
  663. $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  664. $w['t_fprice'] = $data[$k]['citys']['t_fprice'];
  665. $w['l_num'] = $data[$k]['citys']['l_num'];
  666. $w['l_price'] = $shop_area['price'];
  667. $w['l_fprice'] = $data[$k]['citys']['l_fprice'];
  668. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['citys']['area']));
  669. if(!$shop){
  670. Dever::db('mail/area_stat')->insert($w);
  671. }else{
  672. $w['where_id'] = $shop['id'];
  673. Dever::db('mail/area_stat')->update($w);
  674. }
  675. }
  676. #区县
  677. if($v['county']>0){
  678. $where['area'] = $v['county'];
  679. $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  680. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  681. $jia = $this->caigou($where);
  682. $data[$k]['countys']['price']= $jia['money'] *0.03;
  683. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  684. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['countys']['area'],'role'=>3));
  685. if($mid && $mid['id']){
  686. $data[$k]['countys']['mid'] = $mid['id'];
  687. }else{
  688. $data[$k]['countys']['mid'] = '-1';
  689. }
  690. $wh['county'] = $v['county'];
  691. $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  692. // #体验店
  693. $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  694. $data[$k]['countys']['type'] = array_column($t_shop,'id');
  695. $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  696. $data[$k]['countys']['t_num'] = count($t_shop);
  697. if($data[$k]['countys']['t_num']>0){
  698. $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  699. $data[$k]['countys']['t_fprice'] = $data[$k]['countys']['price'];
  700. }else{
  701. $data[$k]['countys']['t_price'] = 0;
  702. $data[$k]['countys']['t_fprice'] = 0;
  703. }
  704. #零售店
  705. $where['county'] = $v['county'];
  706. $shop_area = $this->ls($where,2);
  707. $data[$k]['countys']['l_price'] = $shop_area['price'];
  708. $data[$k]['countys']['l_fprice'] = $shop_area['price'] * 0.03;
  709. $data[$k]['countys']['l_num'] = $shop_area['num'];
  710. $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_fprice'];
  711. $w['mid'] = $data[$k]['countys']['mid'];
  712. $w['area'] = $data[$k]['countys']['area'];
  713. $w['price'] = $data[$k]['countys']['price'];
  714. $w['num'] = $data[$k]['countys']['num'];
  715. $w['c_price'] = $jia['price'];
  716. // $data[$k]['countys']['money']['total'];
  717. $w['t_num'] = $data[$k]['countys']['t_num'];
  718. $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  719. $w['t_fprice'] = $data[$k]['countys']['t_fprice'];
  720. $w['l_num'] = $data[$k]['countys']['l_num'];
  721. $w['l_price'] = $shop_area['price'];
  722. $w['l_fprice'] = $data[$k]['countys']['l_fprice'];
  723. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['countys']['area']));
  724. if(!$shop){
  725. Dever::db('mail/area_stat')->insert($w);
  726. }else{
  727. $w['where_id'] = $shop['id'];
  728. Dever::db('mail/area_stat')->update($w);
  729. }
  730. }
  731. #街道
  732. if($v['town']>0){
  733. $where['area'] = $v['town'];
  734. $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  735. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  736. $jia = $this->caigou($where);
  737. $data[$k]['towns']['price'] = $jia['money'] * 0.05;
  738. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  739. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['towns']['area'],'role'=>4));
  740. if($mid && $mid['id']){
  741. $data[$k]['towns']['mid'] = $mid['id'];
  742. }else{
  743. $data[$k]['towns']['mid'] = '-1';
  744. }
  745. $whe['town'] = $v['town'];
  746. $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  747. #体验店
  748. $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  749. $data[$k]['towns']['type'] = array_column($t_shop,'id');
  750. $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  751. $data[$k]['towns']['t_num'] = count($t_shop);
  752. if($data[$k]['towns']['t_num']>0){
  753. $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  754. $data[$k]['towns']['t_fprice'] = $data[$k]['towns']['price'];
  755. }else{
  756. $data[$k]['towns']['t_price'] = 0;
  757. $data[$k]['towns']['t_fprice'] = 0;
  758. }
  759. #零售店
  760. $where['town'] = $v['town'];
  761. $shop_area = $this->ls($where,3);
  762. $data[$k]['towns']['l_price'] =$shop_area['price'];
  763. $data[$k]['towns']['l_fprice'] =$shop_area['price'] * 0.05;
  764. $data[$k]['towns']['l_num'] = $shop_area['num'];
  765. $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_fprice'];
  766. $w['mid'] = $data[$k]['towns']['mid'];
  767. $w['area'] = $data[$k]['towns']['area'];
  768. $w['price'] = $data[$k]['towns']['price'];
  769. $w['num'] = $data[$k]['towns']['num'];
  770. $w['c_price'] = $jia['price'];
  771. // $data[$k]['towns']['money']['total'];
  772. $w['t_num'] = $data[$k]['towns']['t_num'];
  773. $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  774. $w['t_fprice'] = $data[$k]['towns']['t_fprice'];
  775. $w['l_num'] = $data[$k]['towns']['l_num'];
  776. $w['l_price'] = $shop_area['price'];
  777. $w['l_fprice'] = $data[$k]['towns']['l_fprice'];
  778. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['towns']['area']));
  779. if(!$shop){
  780. Dever::db('mail/area_stat')->insert($w);
  781. }else{
  782. $w['where_id'] = $shop['id'];
  783. Dever::db('mail/area_stat')->update($w);
  784. }
  785. }
  786. }
  787. return 'ok';
  788. }
  789. // public function area_api(){
  790. // #零售店的采购金额*0.4
  791. // $month = Dever::input('month', date('Y-m'));
  792. // $start_time = $month .'-01 00:00:00';
  793. // $where = array();
  794. // $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
  795. // $where['start'] = Dever::maketime($start_time);
  796. // $where['end'] = Dever::maketime($end_time);
  797. // $where['state'] = 1;
  798. // $data = array();
  799. // $shop = Dever::db('shop/info')->getAreaAll(array('state'=>1));
  800. // foreach($shop as $k=>$v){
  801. // $data[$v['city']]=$v;
  802. // }
  803. // $shop_area = Dever::db('mail/area_entry')->getAll($where);
  804. // $res = array();
  805. // if($shop_area){
  806. // foreach($shop_area as $k => $v){
  807. // if($v['area']){
  808. // $area = explode(',',$v['area']);
  809. // if($area && isset($area[0])){
  810. // $res[$k]['province'] = $area[0];
  811. // }
  812. // if ($area && isset($area[1])){
  813. // $res[$k]['city'] = $area[1];
  814. // }else{
  815. // $res[$k]['city'] = 0;
  816. // }
  817. // if($area && isset($area[2])){
  818. // $res[$k]['county'] = $area[2];
  819. // }else{
  820. // $res[$k]['county'] = 0;
  821. // }
  822. // if($area && isset($area[3])){
  823. // $res[$k]['town'] = $area[3];
  824. // }else{
  825. // $res[$k]['town'] = 0;
  826. // }
  827. // }
  828. // }
  829. // }
  830. // $data = array_values($data);
  831. // $data = array_merge($data,$res);
  832. // // print_R($data);die;
  833. // $result=array_unique($data, SORT_REGULAR);
  834. // $rest=array();
  835. // foreach($data as $k=>$v){
  836. // $rest[$v['county']]=$v;
  837. // }
  838. // $data=array_values($rest);
  839. // foreach ($data as $k => $v) {
  840. // $edition[] = $v['province'];
  841. // }
  842. // array_multisort($edition, SORT_ASC, $data);
  843. // foreach($data as $k => $v){
  844. // $w['month'] = $where['start'];
  845. // #城市
  846. // if($v['city']>0){
  847. // $where['area'] = $v['city'];
  848. // $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  849. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  850. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  851. // $mid = Dever::db('agent/member')->getAreaAll($where);
  852. // $w['citys']['area'] = $v['city'];
  853. // if($mid && $mid['id']){
  854. // $data[$k]['citys']['mid'] = $mid['id'];
  855. // }else{
  856. // $data[$k]['citys']['mid'] = '';
  857. // }
  858. // $where['city'] = $v['city'];
  859. // $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  860. // #体验店
  861. // $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  862. // $data[$k]['citys']['type'] = array_column($t_shop,'id');
  863. // $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  864. // $data[$k]['citys']['t_num'] = count($t_shop);
  865. // if($data[$k]['citys']['t_num']>0){
  866. // $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  867. // }else{
  868. // $data[$k]['citys']['t_price'] = 0;
  869. // }
  870. // #零售店
  871. // $entry = Dever::db('mail/area_entry')->getNum($where);
  872. // if ($entry && $entry['num']){
  873. // $data[$k]['citys']['l_num'] = $entry['num'];
  874. // $data[$k]['citys']['num'] = $data[$k]['citys']['num'] + $data[$k]['citys']['l_num'];
  875. // }else{
  876. // $data[$k]['citys']['l_num'] = 0;
  877. // }
  878. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  879. // if ($entry_price && $entry_price['cprice'] ){
  880. // $data[$k]['citys']['l_price'] = $entry_price['cprice'] * 0.4;
  881. // $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_price'];
  882. // }else{
  883. // $data[$k]['citys']['l_price'] = 0;
  884. // }
  885. // $w['mid'] = $data[$k]['citys']['mid'];
  886. // $w['area'] = $data[$k]['citys']['area'];
  887. // $w['price'] = $data[$k]['citys']['price'];
  888. // $w['c_price'] = $data[$k]['citys']['money']['total'];
  889. // $w['num'] = $data[$k]['citys']['num'];
  890. // $w['t_num'] = $data[$k]['citys']['t_num'];
  891. // $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  892. // $w['l_num'] = $data[$k]['citys']['l_num'];
  893. // $w['l_price'] = $data[$k]['citys']['l_price'];
  894. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['citys']['area']));
  895. // if(!$shop){
  896. // Dever::db('mail/area_stat')->insert($w);
  897. // }else{
  898. // $w['where_id'] = $shop['id'];
  899. // Dever::db('mail/area_stat')->update($w);
  900. // }
  901. // }
  902. // #区县
  903. // if($v['county']>0){
  904. // $where['area'] = $v['county'];
  905. // $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  906. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  907. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  908. // $mid = Dever::db('agent/member')->getAreaAll($where);
  909. // if($mid && $mid['id']){
  910. // $data[$k]['countys']['mid'] = $mid['id'];
  911. // }else{
  912. // $data[$k]['countys']['mid'] = '';
  913. // }
  914. // $wh['county'] = $v['county'];
  915. // $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  916. // // #体验店
  917. // $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  918. // $data[$k]['countys']['type'] = array_column($t_shop,'id');
  919. // $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  920. // $data[$k]['countys']['t_num'] = count($t_shop);
  921. // if($data[$k]['countys']['t_num']>0){
  922. // $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  923. // }else{
  924. // $data[$k]['countys']['t_price'] = 0;
  925. // }
  926. // #零售店
  927. // $entry = Dever::db('mail/area_entry')->getNum($where);
  928. // if ($entry && $entry['num']){
  929. // $data[$k]['countys']['l_num'] = $entry['num'];
  930. // $data[$k]['countys']['num'] = $data[$k]['countys']['num'] + $data[$k]['countys']['l_num'];
  931. // }else{
  932. // $data[$k]['countys']['l_num'] = 0;
  933. // }
  934. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  935. // if ($entry_price && $entry_price['cprice'] ){
  936. // $data[$k]['countys']['l_price'] = $entry_price['cprice'] * 0.4;
  937. // $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_price'];
  938. // }else{
  939. // $data[$k]['countys']['l_price'] = 0;
  940. // }
  941. // $w['mid'] = $data[$k]['countys']['mid'];
  942. // $w['area'] = $data[$k]['countys']['area'];
  943. // $w['price'] = $data[$k]['countys']['price'];
  944. // $w['num'] = $data[$k]['countys']['num'];
  945. // $w['c_price'] = $data[$k]['countys']['money']['total'];
  946. // $w['t_num'] = $data[$k]['countys']['t_num'];
  947. // $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  948. // $w['l_num'] = $data[$k]['countys']['l_num'];
  949. // $w['l_price'] = $data[$k]['countys']['l_price'];
  950. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['countys']['area']));
  951. // if(!$shop){
  952. // Dever::db('mail/area_stat')->insert($w);
  953. // }else{
  954. // $w['where_id'] = $shop['id'];
  955. // Dever::db('mail/area_stat')->update($w);
  956. // }
  957. // }
  958. // #街道
  959. // if($v['town']>0){
  960. // $where['area'] = $v['town'];
  961. // $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  962. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  963. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  964. // $mid = Dever::db('agent/member')->getAreaAll($where);
  965. // if($mid && $mid['id']){
  966. // $data[$k]['towns']['mid'] = $mid['id'];
  967. // }else{
  968. // $data[$k]['towns']['mid'] = '';
  969. // }
  970. // $whe['town'] = $v['town'];
  971. // $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  972. // #体验店
  973. // $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  974. // $data[$k]['towns']['type'] = array_column($t_shop,'id');
  975. // $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  976. // $data[$k]['towns']['t_num'] = count($t_shop);
  977. // if($data[$k]['towns']['t_num']>0){
  978. // $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  979. // }else{
  980. // $data[$k]['towns']['t_price'] = 0;
  981. // }
  982. // #零售店
  983. // $entry = Dever::db('mail/area_entry')->getNum($where);
  984. // if ($entry && $entry['num']){
  985. // $data[$k]['towns']['l_num'] = $entry['num'];
  986. // $data[$k]['towns']['num'] = $data[$k]['towns']['num'] + $data[$k]['towns']['l_num'];
  987. // }else{
  988. // $data[$k]['towns']['l_num'] = 0;
  989. // }
  990. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  991. // if ($entry_price && $entry_price['cprice'] ){
  992. // $data[$k]['towns']['l_price'] = $entry_price['cprice'] * 0.4;
  993. // $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_price'];
  994. // }else{
  995. // $data[$k]['towns']['l_price'] = 0;
  996. // }
  997. // $w['mid'] = $data[$k]['towns']['mid'];
  998. // $w['area'] = $data[$k]['towns']['area'];
  999. // $w['price'] = $data[$k]['towns']['price'];
  1000. // $w['num'] = $data[$k]['towns']['num'];
  1001. // $w['c_price'] = $data[$k]['towns']['money']['total'];
  1002. // $w['t_num'] = $data[$k]['towns']['t_num'];
  1003. // $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  1004. // $w['l_num'] = $data[$k]['towns']['l_num'];
  1005. // $w['l_price'] = $data[$k]['towns']['l_price'];
  1006. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['towns']['area']));
  1007. // if(!$shop){
  1008. // Dever::db('mail/area_stat')->insert($w);
  1009. // }else{
  1010. // $w['where_id'] = $shop['id'];
  1011. // Dever::db('mail/area_stat')->update($w);
  1012. // }
  1013. // }
  1014. // }
  1015. // return 'ok';
  1016. // }
  1017. public function area_member($id){
  1018. $info = Dever::db('mail/area_stat')->find($id);
  1019. $res = '-';
  1020. if($info['mid']){
  1021. $member = Dever::db('agent/member')->find($info['mid']);
  1022. if ($member) {
  1023. $res = $member['name']."<br/>".$member['mobile'];
  1024. }
  1025. }
  1026. return $res;
  1027. }
  1028. public function entry_member($id){
  1029. $info = Dever::db('mail/area_entry')->find($id);
  1030. if($info['shop_id']){
  1031. $member = Dever::db('shop/info')->find($info['shop_id']);
  1032. // print_R($member);die;
  1033. $res = $member['name'].'<br/>'.$member['sid'];
  1034. }else{
  1035. $res = '-';
  1036. }
  1037. return $res;
  1038. }
  1039. public function updateArea_entry($id,$name,$data){
  1040. $sid = Dever::param('sid',$data);
  1041. $month = Dever::param('month',$data);
  1042. if ($id && $sid) {
  1043. $info = Dever::db('mail/area_entry')->find($id);
  1044. $member = Dever::db('shop/info')->find(array('sid'=>$sid));
  1045. // print_R($member);die;
  1046. $where['where_id'] = $id ;
  1047. $where['shop_id'] = $member['id'];
  1048. $where['month'] = strtotime($month);
  1049. Dever::db('mail/area_entry')->update($where);
  1050. }
  1051. }
  1052. }