Manage.php 59 KB

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