Manage.php 46 KB

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