Manage.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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. $where['area'] = $v['city'];
  714. $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  715. $where['parent_type'] = '1,3';
  716. // print_R($where);die;
  717. $jia = $this->caigou($where);
  718. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  719. $data[$k]['citys']['price']= $jia['money'] * 0.01;
  720. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  721. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['citys']['area'],'role'=>2));
  722. $w['citys']['area'] = $v['city'];
  723. if($mid && $mid['id']){
  724. $data[$k]['citys']['mid'] = $mid['id'];
  725. }else{
  726. $data[$k]['citys']['mid'] = '-1';
  727. }
  728. $where['city'] = $v['city'];
  729. $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  730. #体验店
  731. $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  732. $data[$k]['citys']['type'] = array_column($t_shop,'id');
  733. $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  734. $data[$k]['citys']['t_num'] = count($t_shop);
  735. if($data[$k]['citys']['t_num']>0){
  736. $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  737. $data[$k]['citys']['t_fprice'] = $data[$k]['citys']['price'];
  738. }else{
  739. $data[$k]['citys']['t_price'] = 0;
  740. $data[$k]['citys']['t_fprice'] = 0;
  741. }
  742. #零售店
  743. $shop_area = $this->ls($where,1);
  744. $data[$k]['citys']['l_price'] =$shop_area['price'];
  745. $data[$k]['citys']['l_fprice'] =$shop_area['price'] * 0.01;
  746. $data[$k]['citys']['l_num'] = $shop_area['num'];
  747. $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_fprice'];
  748. $w['mid'] = $data[$k]['citys']['mid'];
  749. $w['area'] = $data[$k]['citys']['area'];
  750. $w['price'] = $data[$k]['citys']['price'];
  751. $w['c_price'] = $jia['price'];
  752. // $data[$k]['citys']['money']['total'];
  753. $w['num'] = $data[$k]['citys']['num'];
  754. $w['t_num'] = $data[$k]['citys']['t_num'];
  755. $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  756. $w['t_fprice'] = $data[$k]['citys']['t_fprice'];
  757. $w['l_num'] = $data[$k]['citys']['l_num'];
  758. $w['l_price'] = $shop_area['price'];
  759. $w['l_fprice'] = $data[$k]['citys']['l_fprice'];
  760. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['citys']['area']));
  761. if(!$shop){
  762. Dever::db('mail/area_stat')->insert($w);
  763. }else{
  764. $w['where_id'] = $shop['id'];
  765. Dever::db('mail/area_stat')->update($w);
  766. }
  767. }
  768. #区县
  769. if($v['county']>0){
  770. $where['area'] = $v['county'];
  771. $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  772. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  773. $jia = $this->caigou($where);
  774. $data[$k]['countys']['price']= $jia['money'] *0.03;
  775. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  776. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['countys']['area'],'role'=>3));
  777. if($mid && $mid['id']){
  778. $data[$k]['countys']['mid'] = $mid['id'];
  779. }else{
  780. $data[$k]['countys']['mid'] = '-1';
  781. }
  782. $wh['county'] = $v['county'];
  783. $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  784. // #体验店
  785. $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  786. $data[$k]['countys']['type'] = array_column($t_shop,'id');
  787. $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  788. $data[$k]['countys']['t_num'] = count($t_shop);
  789. if($data[$k]['countys']['t_num']>0){
  790. $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  791. $data[$k]['countys']['t_fprice'] = $data[$k]['countys']['price'];
  792. }else{
  793. $data[$k]['countys']['t_price'] = 0;
  794. $data[$k]['countys']['t_fprice'] = 0;
  795. }
  796. #零售店
  797. $where['county'] = $v['county'];
  798. $shop_area = $this->ls($where,2);
  799. $data[$k]['countys']['l_price'] = $shop_area['price'];
  800. $data[$k]['countys']['l_fprice'] = $shop_area['price'] * 0.03;
  801. $data[$k]['countys']['l_num'] = $shop_area['num'];
  802. $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_fprice'];
  803. $w['mid'] = $data[$k]['countys']['mid'];
  804. $w['area'] = $data[$k]['countys']['area'];
  805. $w['price'] = $data[$k]['countys']['price'];
  806. $w['num'] = $data[$k]['countys']['num'];
  807. $w['c_price'] = $jia['price'];
  808. // $data[$k]['countys']['money']['total'];
  809. $w['t_num'] = $data[$k]['countys']['t_num'];
  810. $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  811. $w['t_fprice'] = $data[$k]['countys']['t_fprice'];
  812. $w['l_num'] = $data[$k]['countys']['l_num'];
  813. $w['l_price'] = $shop_area['price'];
  814. $w['l_fprice'] = $data[$k]['countys']['l_fprice'];
  815. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['countys']['area']));
  816. if(!$shop){
  817. Dever::db('mail/area_stat')->insert($w);
  818. }else{
  819. $w['where_id'] = $shop['id'];
  820. Dever::db('mail/area_stat')->update($w);
  821. }
  822. }
  823. #街道
  824. if($v['town']>0){
  825. $where['area'] = $v['town'];
  826. $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  827. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  828. $jia = $this->caigou($where);
  829. $data[$k]['towns']['price'] = $jia['money'] * 0.05;
  830. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  831. $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['towns']['area'],'role'=>4));
  832. if($mid && $mid['id']){
  833. $data[$k]['towns']['mid'] = $mid['id'];
  834. }else{
  835. $data[$k]['towns']['mid'] = '-1';
  836. }
  837. $whe['town'] = $v['town'];
  838. $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  839. #体验店
  840. $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  841. $data[$k]['towns']['type'] = array_column($t_shop,'id');
  842. $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  843. $data[$k]['towns']['t_num'] = count($t_shop);
  844. if($data[$k]['towns']['t_num']>0){
  845. $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  846. $data[$k]['towns']['t_fprice'] = $data[$k]['towns']['price'];
  847. }else{
  848. $data[$k]['towns']['t_price'] = 0;
  849. $data[$k]['towns']['t_fprice'] = 0;
  850. }
  851. #零售店
  852. $where['town'] = $v['town'];
  853. $shop_area = $this->ls($where,3);
  854. $data[$k]['towns']['l_price'] =$shop_area['price'];
  855. $data[$k]['towns']['l_fprice'] =$shop_area['price'] * 0.05;
  856. $data[$k]['towns']['l_num'] = $shop_area['num'];
  857. $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_fprice'];
  858. $w['mid'] = $data[$k]['towns']['mid'];
  859. $w['area'] = $data[$k]['towns']['area'];
  860. $w['price'] = $data[$k]['towns']['price'];
  861. $w['num'] = $data[$k]['towns']['num'];
  862. $w['c_price'] = $jia['price'];
  863. // $data[$k]['towns']['money']['total'];
  864. $w['t_num'] = $data[$k]['towns']['t_num'];
  865. $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  866. $w['t_fprice'] = $data[$k]['towns']['t_fprice'];
  867. $w['l_num'] = $data[$k]['towns']['l_num'];
  868. $w['l_price'] = $shop_area['price'];
  869. $w['l_fprice'] = $data[$k]['towns']['l_fprice'];
  870. $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['towns']['area']));
  871. if(!$shop){
  872. Dever::db('mail/area_stat')->insert($w);
  873. }else{
  874. $w['where_id'] = $shop['id'];
  875. Dever::db('mail/area_stat')->update($w);
  876. }
  877. }
  878. }
  879. return 'ok';
  880. }
  881. // public function area_api(){
  882. // #零售店的采购金额*0.4
  883. // $month = Dever::input('month', date('Y-m'));
  884. // $start_time = $month .'-01 00:00:00';
  885. // $where = array();
  886. // $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
  887. // $where['start'] = Dever::maketime($start_time);
  888. // $where['end'] = Dever::maketime($end_time);
  889. // $where['state'] = 1;
  890. // $data = array();
  891. // $shop = Dever::db('shop/info')->getAreaAll(array('state'=>1));
  892. // foreach($shop as $k=>$v){
  893. // $data[$v['city']]=$v;
  894. // }
  895. // $shop_area = Dever::db('mail/area_entry')->getAll($where);
  896. // $res = array();
  897. // if($shop_area){
  898. // foreach($shop_area as $k => $v){
  899. // if($v['area']){
  900. // $area = explode(',',$v['area']);
  901. // if($area && isset($area[0])){
  902. // $res[$k]['province'] = $area[0];
  903. // }
  904. // if ($area && isset($area[1])){
  905. // $res[$k]['city'] = $area[1];
  906. // }else{
  907. // $res[$k]['city'] = 0;
  908. // }
  909. // if($area && isset($area[2])){
  910. // $res[$k]['county'] = $area[2];
  911. // }else{
  912. // $res[$k]['county'] = 0;
  913. // }
  914. // if($area && isset($area[3])){
  915. // $res[$k]['town'] = $area[3];
  916. // }else{
  917. // $res[$k]['town'] = 0;
  918. // }
  919. // }
  920. // }
  921. // }
  922. // $data = array_values($data);
  923. // $data = array_merge($data,$res);
  924. // // print_R($data);die;
  925. // $result=array_unique($data, SORT_REGULAR);
  926. // $rest=array();
  927. // foreach($data as $k=>$v){
  928. // $rest[$v['county']]=$v;
  929. // }
  930. // $data=array_values($rest);
  931. // foreach ($data as $k => $v) {
  932. // $edition[] = $v['province'];
  933. // }
  934. // array_multisort($edition, SORT_ASC, $data);
  935. // foreach($data as $k => $v){
  936. // $w['month'] = $where['start'];
  937. // #城市
  938. // if($v['city']>0){
  939. // $where['area'] = $v['city'];
  940. // $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
  941. // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  942. // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
  943. // $mid = Dever::db('agent/member')->getAreaAll($where);
  944. // $w['citys']['area'] = $v['city'];
  945. // if($mid && $mid['id']){
  946. // $data[$k]['citys']['mid'] = $mid['id'];
  947. // }else{
  948. // $data[$k]['citys']['mid'] = '';
  949. // }
  950. // $where['city'] = $v['city'];
  951. // $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
  952. // #体验店
  953. // $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
  954. // $data[$k]['citys']['type'] = array_column($t_shop,'id');
  955. // $where['type_id'] = implode(',',$data[$k]['citys']['type']);
  956. // $data[$k]['citys']['t_num'] = count($t_shop);
  957. // if($data[$k]['citys']['t_num']>0){
  958. // $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  959. // }else{
  960. // $data[$k]['citys']['t_price'] = 0;
  961. // }
  962. // #零售店
  963. // $entry = Dever::db('mail/area_entry')->getNum($where);
  964. // if ($entry && $entry['num']){
  965. // $data[$k]['citys']['l_num'] = $entry['num'];
  966. // $data[$k]['citys']['num'] = $data[$k]['citys']['num'] + $data[$k]['citys']['l_num'];
  967. // }else{
  968. // $data[$k]['citys']['l_num'] = 0;
  969. // }
  970. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  971. // if ($entry_price && $entry_price['cprice'] ){
  972. // $data[$k]['citys']['l_price'] = $entry_price['cprice'] * 0.4;
  973. // $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_price'];
  974. // }else{
  975. // $data[$k]['citys']['l_price'] = 0;
  976. // }
  977. // $w['mid'] = $data[$k]['citys']['mid'];
  978. // $w['area'] = $data[$k]['citys']['area'];
  979. // $w['price'] = $data[$k]['citys']['price'];
  980. // $w['c_price'] = $data[$k]['citys']['money']['total'];
  981. // $w['num'] = $data[$k]['citys']['num'];
  982. // $w['t_num'] = $data[$k]['citys']['t_num'];
  983. // $w['t_price'] = $data[$k]['citys']['t_price']['total'];
  984. // $w['l_num'] = $data[$k]['citys']['l_num'];
  985. // $w['l_price'] = $data[$k]['citys']['l_price'];
  986. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['citys']['area']));
  987. // if(!$shop){
  988. // Dever::db('mail/area_stat')->insert($w);
  989. // }else{
  990. // $w['where_id'] = $shop['id'];
  991. // Dever::db('mail/area_stat')->update($w);
  992. // }
  993. // }
  994. // #区县
  995. // if($v['county']>0){
  996. // $where['area'] = $v['county'];
  997. // $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
  998. // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  999. // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
  1000. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1001. // if($mid && $mid['id']){
  1002. // $data[$k]['countys']['mid'] = $mid['id'];
  1003. // }else{
  1004. // $data[$k]['countys']['mid'] = '';
  1005. // }
  1006. // $wh['county'] = $v['county'];
  1007. // $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
  1008. // // #体验店
  1009. // $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
  1010. // $data[$k]['countys']['type'] = array_column($t_shop,'id');
  1011. // $where['type_id'] = implode(',',$data[$k]['countys']['type']);
  1012. // $data[$k]['countys']['t_num'] = count($t_shop);
  1013. // if($data[$k]['countys']['t_num']>0){
  1014. // $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1015. // }else{
  1016. // $data[$k]['countys']['t_price'] = 0;
  1017. // }
  1018. // #零售店
  1019. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1020. // if ($entry && $entry['num']){
  1021. // $data[$k]['countys']['l_num'] = $entry['num'];
  1022. // $data[$k]['countys']['num'] = $data[$k]['countys']['num'] + $data[$k]['countys']['l_num'];
  1023. // }else{
  1024. // $data[$k]['countys']['l_num'] = 0;
  1025. // }
  1026. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1027. // if ($entry_price && $entry_price['cprice'] ){
  1028. // $data[$k]['countys']['l_price'] = $entry_price['cprice'] * 0.4;
  1029. // $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_price'];
  1030. // }else{
  1031. // $data[$k]['countys']['l_price'] = 0;
  1032. // }
  1033. // $w['mid'] = $data[$k]['countys']['mid'];
  1034. // $w['area'] = $data[$k]['countys']['area'];
  1035. // $w['price'] = $data[$k]['countys']['price'];
  1036. // $w['num'] = $data[$k]['countys']['num'];
  1037. // $w['c_price'] = $data[$k]['countys']['money']['total'];
  1038. // $w['t_num'] = $data[$k]['countys']['t_num'];
  1039. // $w['t_price'] = $data[$k]['countys']['t_price']['total'];
  1040. // $w['l_num'] = $data[$k]['countys']['l_num'];
  1041. // $w['l_price'] = $data[$k]['countys']['l_price'];
  1042. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['countys']['area']));
  1043. // if(!$shop){
  1044. // Dever::db('mail/area_stat')->insert($w);
  1045. // }else{
  1046. // $w['where_id'] = $shop['id'];
  1047. // Dever::db('mail/area_stat')->update($w);
  1048. // }
  1049. // }
  1050. // #街道
  1051. // if($v['town']>0){
  1052. // $where['area'] = $v['town'];
  1053. // $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
  1054. // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
  1055. // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
  1056. // $mid = Dever::db('agent/member')->getAreaAll($where);
  1057. // if($mid && $mid['id']){
  1058. // $data[$k]['towns']['mid'] = $mid['id'];
  1059. // }else{
  1060. // $data[$k]['towns']['mid'] = '';
  1061. // }
  1062. // $whe['town'] = $v['town'];
  1063. // $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
  1064. // #体验店
  1065. // $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
  1066. // $data[$k]['towns']['type'] = array_column($t_shop,'id');
  1067. // $where['type_id'] = implode(',',$data[$k]['towns']['type']);
  1068. // $data[$k]['towns']['t_num'] = count($t_shop);
  1069. // if($data[$k]['towns']['t_num']>0){
  1070. // $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
  1071. // }else{
  1072. // $data[$k]['towns']['t_price'] = 0;
  1073. // }
  1074. // #零售店
  1075. // $entry = Dever::db('mail/area_entry')->getNum($where);
  1076. // if ($entry && $entry['num']){
  1077. // $data[$k]['towns']['l_num'] = $entry['num'];
  1078. // $data[$k]['towns']['num'] = $data[$k]['towns']['num'] + $data[$k]['towns']['l_num'];
  1079. // }else{
  1080. // $data[$k]['towns']['l_num'] = 0;
  1081. // }
  1082. // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
  1083. // if ($entry_price && $entry_price['cprice'] ){
  1084. // $data[$k]['towns']['l_price'] = $entry_price['cprice'] * 0.4;
  1085. // $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_price'];
  1086. // }else{
  1087. // $data[$k]['towns']['l_price'] = 0;
  1088. // }
  1089. // $w['mid'] = $data[$k]['towns']['mid'];
  1090. // $w['area'] = $data[$k]['towns']['area'];
  1091. // $w['price'] = $data[$k]['towns']['price'];
  1092. // $w['num'] = $data[$k]['towns']['num'];
  1093. // $w['c_price'] = $data[$k]['towns']['money']['total'];
  1094. // $w['t_num'] = $data[$k]['towns']['t_num'];
  1095. // $w['t_price'] = $data[$k]['towns']['t_price']['total'];
  1096. // $w['l_num'] = $data[$k]['towns']['l_num'];
  1097. // $w['l_price'] = $data[$k]['towns']['l_price'];
  1098. // $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['towns']['area']));
  1099. // if(!$shop){
  1100. // Dever::db('mail/area_stat')->insert($w);
  1101. // }else{
  1102. // $w['where_id'] = $shop['id'];
  1103. // Dever::db('mail/area_stat')->update($w);
  1104. // }
  1105. // }
  1106. // }
  1107. // return 'ok';
  1108. // }
  1109. public function area_member($id){
  1110. $info = Dever::db('mail/area_stat')->find($id);
  1111. $res = '-';
  1112. if($info['mid']){
  1113. $member = Dever::db('agent/member')->find($info['mid']);
  1114. if ($member) {
  1115. $res = $member['name']."<br/>".$member['mobile'];
  1116. }
  1117. }
  1118. return $res;
  1119. }
  1120. public function entry_member($id){
  1121. $info = Dever::db('mail/area_entry')->find($id);
  1122. if($info['shop_id']){
  1123. $member = Dever::db('shop/info')->find($info['shop_id']);
  1124. // print_R($member);die;
  1125. $res = $member['name'].'<br/>'.$member['sid'];
  1126. }else{
  1127. $res = '-';
  1128. }
  1129. return $res;
  1130. }
  1131. public function updateArea_entry($id,$name,$data){
  1132. $sid = Dever::param('sid',$data);
  1133. $month = Dever::param('month',$data);
  1134. if ($id && $sid) {
  1135. $info = Dever::db('mail/area_entry')->find($id);
  1136. $member = Dever::db('shop/info')->find(array('sid'=>$sid));
  1137. // print_R($member);die;
  1138. $where['where_id'] = $id ;
  1139. $where['shop_id'] = $member['id'];
  1140. $where['month'] = strtotime($month);
  1141. Dever::db('mail/area_entry')->update($where);
  1142. }
  1143. }
  1144. }