Manage.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. <?php
  2. namespace Stats\Lib;
  3. use Dever;
  4. Class Manage
  5. {
  6. public function index_api()
  7. {
  8. $data = array();
  9. $start = Dever::input('start');
  10. $end = Dever::input('end');
  11. if (!$start && !$end) {
  12. $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  13. $end = strtotime(date('Y-m-d 23:59:59',
  14. strtotime(date('Y-m-01')."+1 month - 1 day")));
  15. $data['start'] = date('Y-m-d',$start);
  16. $data['end'] = date('Y-m-d',$end);
  17. } else {
  18. $data['start'] = date('Y-m-d',$start);
  19. $data['end'] = date('Y-m-d',$end);
  20. }
  21. $fastart = Dever::input('fastart');
  22. $faend = Dever::input('faend');
  23. if (!$fastart && !$faend) {
  24. $fastart=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  25. $faend = strtotime(date('Y-m-d 23:59:59',
  26. strtotime(date('Y-m-01')."+1 month - 1 day")));
  27. $data['fastart'] = date('Y-m-d',$fastart);
  28. $data['faend'] = date('Y-m-d',$faend);
  29. } else {
  30. $data['fastart'] = date('Y-m-d',$fastart);
  31. $data['faend'] = date('Y-m-d',$faend);
  32. }
  33. $fstart = Dever::input('fstart');
  34. $fend = Dever::input('fend');
  35. if (!$fstart && !$fend) {
  36. $fstart=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  37. $fend = strtotime(date('Y-m-d 23:59:59',
  38. strtotime(date('Y-m-01')."+1 month - 1 day")));
  39. $data['fstart'] = date('Y-m-d',$fstart);
  40. $data['fend'] = date('Y-m-d',$fend);
  41. } else {
  42. $data['fstart'] = date('Y-m-d',$fstart);
  43. $data['fend'] = date('Y-m-d',$fend);
  44. }
  45. $data['type'] = array(1 => '体验店',2 => '零售店',10 => '平台商城');
  46. return Dever::render('out', $data);
  47. }
  48. public function list_api()
  49. {
  50. $status = Dever::db('shop/sell_order')->config['status_manage'];
  51. $start = Dever::input('start');
  52. $end = Dever::input('end');
  53. $fastart = Dever::input('fastart');
  54. $faend = Dever::input('faend');
  55. $fstart = Dever::input('fstart');
  56. $fend = Dever::input('fend');
  57. $cate = Dever::input('cate');
  58. $name = Dever::input('goods_name');
  59. $shop_name = Dever::input('shop_name');
  60. $order_num = Dever::input('order_num');
  61. if ($start) {
  62. $where['start'] = strtotime($start);
  63. }
  64. if ($end) {
  65. $where['end'] = strtotime($end)+86399;
  66. }
  67. if ($fastart) {
  68. $where['fastart'] = strtotime($fastart);
  69. }
  70. if ($faend) {
  71. $where['faend'] = strtotime($faend)+86399;
  72. }
  73. if ($fstart) {
  74. $where['fstart'] = strtotime($fstart);
  75. }
  76. if ($fend) {
  77. $where['fend'] = strtotime($fend)+86399;
  78. }
  79. if ($cate && $cate>0) {
  80. $where['shop_type'] = $cate;
  81. }
  82. if ($name) {
  83. $where['name'] = $name;
  84. }
  85. if ($shop_name) {
  86. $shop = Dever::db('shop/info')->find(array('name'=>$shop_name));
  87. if ($shop) {
  88. $where['shop_id'] = $shop['id'];
  89. }
  90. }
  91. if ($order_num) {
  92. $where['order_num'] = $order_num;
  93. }
  94. $where['state'] = 1;
  95. $data = Dever::db('shop/sell_order')->getExcel($where);
  96. // print_R($data);die;
  97. $header = array('门店类型', '门店编号', '门店名称', '订单号', '商品编码', '存货编码', '商品名称', '规格型号', '税率', '商品单价', '购买数量', '商品合计金额', '代理优惠金额', '商品实付金额', '礼品卡金额', '钱包金额','商品支付金额', '礼品卡名称', '礼品卡卡号', '代理商注册时间', '下单时间', '付款时间', '发货时间', '完成时间', '订单总数量', '订单总金额', '订单实付金额', '礼品卡金额', '钱包金额', '优惠券金额', '代理优惠金额', '订单状态', '退款状态', '退款时间', '退款金额','退卡金额','退现金金额', '收件人', '收件人手机', '收件人地址');
  98. $body = array();
  99. if ($data) {
  100. foreach ($data as $k => $v) {
  101. $shop_type = '';
  102. if ($v['shop_type'] == 1) {
  103. $shop_type = '体验店';
  104. } elseif ($v['shop_type'] == 2) {
  105. $shop_type = '平台商城';
  106. }
  107. $shop = Dever::db('shop/info')->find($v['shop_id']);
  108. $sid = '';
  109. $shop_name = '';
  110. if ($shop) {
  111. if (isset($shop['sid']) && $shop['sid'] ) {
  112. $sid = $shop['sid'];
  113. }
  114. if (isset($shop['name']) && $shop['name']) {
  115. $shop_name = $shop['name'];
  116. }
  117. }
  118. $v['card'] = '';
  119. if ($v['card_code_id']) {
  120. $code = Dever::db('card/code')->find($v['card_code_id']);
  121. if ($code) {
  122. $card_info = Dever::db('card/info')->find($code['card_id']);
  123. if ($card_info) {
  124. if (!$code['total_cash']) {
  125. $code['total_cash'] = $card_info['value'];
  126. }
  127. $v['card'] = $card_info['name'];
  128. $v['card_code'] = $code['card'];
  129. }
  130. }
  131. }
  132. $zhuce = '';
  133. $address_contact = '';
  134. $address_mobile = '';
  135. $address_info = '';
  136. if ($v['address_id'] > 0) {
  137. $address = Dever::load('passport/address')->getOne($v['uid'], $v['address_id']);
  138. if($address) {
  139. $address_contact = $address['contact'];
  140. $address_mobile = $address['mobile'];
  141. $address_info = $address['address_info'];
  142. $member = Dever::db('agent/member')->find(array('mobile'=>$address['mobile']));
  143. if ($member) {
  144. $zhuce = date('Y-m-d H:i',$member['cdate']);
  145. }
  146. }
  147. }
  148. $ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
  149. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  150. $paydate = isset($v['paydate']) && $v['paydate'] ? date('Y-m-d H:i', $v['paydate']) : '-';
  151. $operdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
  152. $fdate = '-';
  153. if ($v['fdate']) {
  154. $fdate = date('Y-m-d H:i',$v['fdate']);
  155. }
  156. if($v['status']>=7) {
  157. $v['price'] = 0;
  158. }
  159. $refund_status = '';
  160. $refund_cdate = '';
  161. $refund_cash = '';
  162. $ka = 0;
  163. $money = 0;
  164. $goods = Dever::db('shop/sell_order_goods')->select(Array('order_id'=>$v['id']));
  165. // print_R($goods);die;
  166. foreach($goods as $k1 => $v1) {
  167. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  168. if (isset($goods_info['sku'])) {
  169. $sku = $goods_info['sku']['string'];
  170. } else {
  171. $sku = '';
  172. }
  173. if ($k1 == 0) {
  174. $total_cash = Dever::load("shop/lib/manage.getTotalCash", $v['id']);
  175. } else {
  176. $total_cash = 0;
  177. }
  178. if ($v['status'] == 8 || $v['status'] == 6) {
  179. $refund_status = '已退款';
  180. $refund_cash = $v1['price']*$v1['num'];
  181. if ($v['status'] == 8) {
  182. if ($v['refund_cash'] && $v['refund_cash']>0) {
  183. $money = $v['refund_cash']+$v['wallet_cash'];
  184. }
  185. if ($v['card_code_cash'] && $v['card_code_cash'] >0) {
  186. $ka = $v['card_code_cash'];
  187. }
  188. if ($k1 == 0) {
  189. $ka = $ka;
  190. $money = $money;
  191. } else {
  192. $ka = 0;
  193. $money = 0;
  194. }
  195. } elseif ($v['status'] == 6) {
  196. if ($v1['status'] == 3) {
  197. if ($v['card_code_id'] && $v['card_code_id'] >0) {
  198. $ka = $v['refund_cash'];
  199. } else {
  200. $money = $v['refund_cash'];
  201. }
  202. $refund_status = '已退款';
  203. } else {
  204. $refund_status = '正常';
  205. $refund_cash = 0;
  206. $ka = 0;
  207. $money = 0;
  208. }
  209. }
  210. $refund_cdate = '';
  211. if ($v['shop_type'] == 1) {
  212. $refund = Dever::db('shop/sell_order_refund')->find(array('order_id'=>$v['id']));
  213. if ($refund) {
  214. $refund_cdate = date('Y-m-d H:i',$refund['cdate']);
  215. }
  216. }
  217. } else {
  218. if ($v['refund_status'] == 3 && $v1['status'] == 3) {
  219. $refund_cash = $v1['num']*$v1['price'];
  220. if ($v['card_code_id'] && $v['card_code_id'] >0) {
  221. $ka = $v['refund_cash'];
  222. } else {
  223. $money = $v['refund_cash'];
  224. }
  225. // $refund_status = '已退款';
  226. $refund_status = '有退款';
  227. $refund_cdate = '';
  228. if ($v['shop_type'] == 1) {
  229. $refund = Dever::db('shop/sell_order_refund')->find(array('order_id'=>$v['id']));
  230. if ($refund) {
  231. $refund_cdate = date('Y-m-d H:i',$refund['cdate']);
  232. }
  233. }
  234. } else {
  235. $refund_cdate = '';
  236. $refund_cash = '0';
  237. $refund_status = '未退款';
  238. }
  239. }
  240. // print_R($goods);die;
  241. // print_R($goods_info);die;
  242. if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
  243. $dj = $this->danjia($goods_info['goods']);
  244. $heji = 0;
  245. $heji = $this->total($goods,$v1['num']);
  246. foreach ($goods_info['goods'] as $key => $val) {
  247. $dnum = round($val['num']*$v1['num'],2);
  248. // print_R($dnum);die;
  249. $goods_price = round($val['price']/$dj*$v1['price']*$v1['num'],2);
  250. $danjia = round($goods_price/$dnum,2);
  251. $bili = round($val['price']*$dnum /$heji,2);#比例
  252. // print_R($)
  253. // $goods_price = round($val['price']*$dnum*($v1['price']/$heji),2);
  254. // print_R($bili);die;
  255. $price_money = $val['price']*$dnum*$v['discount_cash'];#支付
  256. if ($v['card_code_cash'] && $v['card_code_cash']>0){
  257. $card_price = round(($v['card_code_cash']/$v['oprice']*$goods_price),2);
  258. } else {
  259. $card_price = 0;
  260. }
  261. $wallet_price = round(($v['wallet_cash']/$v['oprice']*$goods_price),2);
  262. $goodsfu = 0;
  263. if ($v1['discount_id']<=0) {
  264. $youhui = 0;
  265. if ($card_price + $wallet_price >=$goods_price){
  266. $goodsfu = 0;
  267. } elseif ($card_price + $wallet_price ==0) {
  268. $goodsfu = $goods_price;
  269. // round($val['price']*$dnum,2);
  270. } else {
  271. $goodsfu = round($goods_price-($card_price + $wallet_price),2);
  272. }
  273. } else {
  274. $act = Dever::db('act/discount')->find($v['discount_id']);
  275. if ($act && $act['num']) {
  276. $act_num = $act['num']/10;
  277. }
  278. if ($card_price + $wallet_price == 0) {
  279. $goodsfu = round($goods_price*$act_num,2);
  280. $youhui = round($goods_price-$goodsfu);
  281. } elseif ($card_price + $wallet_price >=$goods_price) {
  282. $goodsfu = 0;
  283. $youhui = round($goods_price-$goodsfu-($card_price + $wallet_price),2);
  284. } else {
  285. $goodsfu = round($goods_price-($card_price + $wallet_price),2);
  286. $youhui = round($goods_price-$goodsfu,2);
  287. }
  288. // $youhui = ($val['price']*$dnum-($val['price']*$dnum/$heji)*$v1['price'])*$v1['num'];
  289. }
  290. // $goodsfu = $val['price']*$dnum-$youhui-$card_price-$wallet_price;
  291. if ($key == 0 && $k1 ==0) {
  292. $price = $v['price'];//round($v1['price']*$v1['num']-$v1['discount_cash'],2);
  293. $shifu = round($v['price'],2);//实付金额
  294. $order_num = $v1['num'];#订单总数量
  295. $oprice = $v['oprice'];//round($v1['price']*$v1['num'],2);#订单总金额
  296. $coupon_cash = round($v1['coupon_cash'],2);
  297. $discount_cash = round($v1['discount_cash'],2);
  298. $card_code_cash = round($v['card_code_cash'],2);
  299. $wallet_cash = round($v['wallet_cash'],2);
  300. if ($v['status'] == 8) {
  301. $refund_cash = $refund_cash;
  302. $ka = $ka;
  303. $money = 0;
  304. }
  305. } else {
  306. $price = 0;
  307. $shifu = 0;
  308. $order_num = 0;
  309. $oprice = 0;#订单总金额
  310. $coupon_cash = 0;
  311. $discount_cash = 0;
  312. $card_code_cash = 0;
  313. $wallet_cash = 0;
  314. if ($v['status'] == 8) {
  315. $refund_cash = 0;
  316. $ka = 0;
  317. $money = 0;
  318. }
  319. }
  320. $d = array
  321. (
  322. $shop_type,
  323. $sid,
  324. $shop_name,
  325. $v['order_num'],
  326. $val['code']."\t",
  327. $goods_info['cunhuo_code']."\t",
  328. $val['name'].'('.$goods_info['name'].')',
  329. $sku,
  330. $goods_info['tax'],
  331. $danjia,//round($val['price'],2),
  332. $dnum,
  333. $goods_price,//round(($val['price']*$dnum),2),
  334. round($youhui,2),
  335. $goodsfu,
  336. $card_price,
  337. $wallet_price,
  338. $price,//$price,//$price_money,
  339. $v['card'],
  340. $v['card_code_card']."\t",
  341. $zhuce,
  342. $cdate,
  343. $paydate,
  344. $operdate,
  345. $fdate,
  346. $order_num,
  347. $oprice,
  348. $price,
  349. $card_code_cash,
  350. $wallet_cash,
  351. $coupon_cash,
  352. $discount_cash,
  353. $status[$v['status']],
  354. $refund_status,
  355. $refund_cdate,
  356. round($refund_cash, 2),
  357. round($ka,2),
  358. round($money,2),
  359. $address_contact,
  360. $address_mobile,
  361. $address_info,
  362. );
  363. $body[] = $d;
  364. }
  365. } else {
  366. if ($ka > 0 || $money > 0) {
  367. $st = Dever::db('shop/sell_order_goods')->find(Array('order_id'=>$v['id'],'status'=>3));
  368. if ($v1['goods_id'] == $st['goods_id']) {
  369. $ka = round($ka,2);
  370. $money = round($money,2);
  371. } else {
  372. $ka = 0;
  373. $money = 0;
  374. }
  375. }
  376. if ($k1 == 0 ) {
  377. $discount_cash = round($v['discount_cash'],2);
  378. $card_code_cash = round($v['card_code_cash'],2);
  379. $wallet_cash = round($v['wallet_cash'],2);
  380. $zhifu = $v['price'];
  381. $total = $v['oprice']-($card_code_cash + $wallet_cash + $discount_cash+$zhifu);
  382. $order_num = $v['num'];//订单总数量
  383. $oprice = round($v['oprice'],2);#订单总金额
  384. $coupon_cash = round($v['coupon_cash'],2);
  385. // $ka = round($ka,2);
  386. // $money = round($money,2);
  387. } else {
  388. $discount_cash = 0;
  389. $card_code_cash = 0;
  390. $wallet_cash = 0;
  391. $total = 0;
  392. $zhifu = 0;
  393. $order_num = 0;
  394. $oprice = 0;
  395. $coupon_cash = 0;
  396. // $ka = 0;
  397. // $money = 0;
  398. }
  399. $dyouhui = round($v1['discount_cash'],2);
  400. $dcard_price = $v['card_code_cash']/$v['oprice']*($v1['price']*$v1['num']);
  401. $dwallet_price = $v['wallet_cash']/$v['oprice']*($v1['price']*$v1['num']);
  402. $dgoodsfu = $v1['price']*$v1['num']-$dyouhui-$dcard_price-$dwallet_price;
  403. // print_R($v1);die;
  404. // $dpaymoney = round($v1['price']/$v['oprice']*$v1['price']*$v1['num'],2);
  405. if ($dgoodsfu<0){
  406. $dgoodsfu = 0;
  407. }
  408. // print_R($ka);
  409. $d = array
  410. (
  411. $shop_type,
  412. $sid,
  413. $shop_name,
  414. $v['order_num'],
  415. $goods_info['code']."\t",
  416. $goods_info['cunhuo_code']."\t",
  417. $goods_info['name'],
  418. $sku,
  419. $goods_info['tax'],
  420. round($v1['price'],2),
  421. round($v1['num'],2),
  422. round(($v1['price']*$v1['num']),2),
  423. round($dyouhui,2),
  424. $dgoodsfu,
  425. $dcard_price,
  426. $dwallet_price,
  427. $zhifu,//$dgoodsfu,//
  428. $v['card'],
  429. $v['card_code_card']."\t",
  430. $zhuce,
  431. $cdate,
  432. $paydate,
  433. $operdate,
  434. $fdate,
  435. $order_num,
  436. sprintf('%01.2f',$total_cash),
  437. $zhifu,
  438. $card_code_cash,
  439. $wallet_cash,
  440. $coupon_cash,//优惠券
  441. $discount_cash,//代理优惠
  442. $status[$v['status']],
  443. $refund_status,
  444. $refund_cdate,
  445. round($refund_cash, 2),
  446. $ka,
  447. $money,
  448. $address_contact,
  449. $address_mobile,
  450. $address_info,
  451. );
  452. $body[] = $d;
  453. }
  454. }
  455. }
  456. }
  457. if (!$body) {
  458. Dever::alert('此时段没有数据,请重新选择条件');
  459. }
  460. $file = '商品销售相关数据';
  461. return Dever::excelExport($body, $header, $file);
  462. }
  463. public function danjia($goods) {
  464. $price = 0;
  465. foreach($goods as $k => $v) {
  466. $price+=$v['price'];
  467. }
  468. return $price;
  469. }
  470. public function total($goods,$num){
  471. if ($goods) {
  472. $price = 0;
  473. foreach ($goods as $k => $v) {
  474. $price += $v['price'] * $v['num']*$num;
  475. }
  476. return $price;
  477. }
  478. }
  479. public function duihuan_api()
  480. {
  481. $start = Dever::input('start');
  482. $end = Dever::input('end');
  483. $fastart = Dever::input('fastart');
  484. $faend = Dever::input('faend');
  485. $fstart = Dever::input('fstart');
  486. $fend = Dever::input('fend');
  487. $name = Dever::input('goods_name');
  488. $shop_name = Dever::input('shop_name');
  489. $order_num = Dever::input('order_num');
  490. $parent_type = Dever::input('cate');
  491. if ($start) {
  492. $where['start'] = strtotime($start);
  493. }
  494. if ($end) {
  495. $where['end'] = strtotime($end)+86399;
  496. }
  497. if ($fastart) {
  498. $where['fastart'] = strtotime($fastart);
  499. }
  500. if ($faend) {
  501. $where['faend'] = strtotime($faend)+86399;
  502. }
  503. if ($fstart) {
  504. $where['fstart'] = strtotime($fstart);
  505. }
  506. if ($fend) {
  507. $where['fend'] = strtotime($fend)+86399;
  508. }
  509. if ($parent_type && $parent_type>0) {
  510. if ($parent_type == 2) {
  511. $parent_type = 3;
  512. }
  513. $where['parent_type'] = $parent_type;
  514. } else {
  515. $where['parent_type'] = '1,2,3';
  516. }
  517. if ($name) {
  518. $where['name'] = $name;
  519. }
  520. if ($shop_name) {
  521. $where['type'] = 1;
  522. $shop = Dever::db('shop/info')->find(array('name'=>$shop_name));
  523. if ($shop) {
  524. $where['type_id'] = $shop['id'];
  525. }
  526. }
  527. if ($order_num) {
  528. $where['order_num'] = $order_num;
  529. }
  530. $where['state'] = 1;
  531. $data = Dever::db('shop/buy_order')->getDui($where);
  532. $header = array('门店类型', '门店编号', '门店名称', '订单号', '商品编码', '存货编码', '商品名称', '规格型号', '税率', '商品单价', '购买数量', '商品合计金额', '代理商注册时间', '下单时间', '付款时间', '发货时间', '完成时间', '订单总数量', '订单总金额', '订单实付金额', '资金账户抵扣金额', '订单状态', '退款状态', '退款时间', '退款金额', '收件人', '收件人手机', '收件人地址');
  533. $body = array();
  534. if ($data) {
  535. foreach($data as $k => $v){
  536. $shop = Dever::db('shop/info')->find($v['type_id']);
  537. if ($shop['type'] ==1) {
  538. $shop_type = '体验店';
  539. } elseif ($shop['type'] ==10) {
  540. $shop_type = '平台商城';
  541. }
  542. $zhuce = '';
  543. $address_contact = '';
  544. $address_mobile = '';
  545. $address_info = '';
  546. $shifu = 0;
  547. if ($v['parent_type'] == 3) {
  548. $parent_order = Dever::db('agent/dh_order')->find($v['parent_order_id']);
  549. $shifu = 0;
  550. $record_cash = 0;
  551. } else {
  552. $shifu = round($v['price'],2);
  553. $record_cash = round($v['record_cash'],2);
  554. }
  555. if ($v['type'] == 1) {
  556. $type_info = Dever::db('shop/info')->find($v['type_id']);
  557. } elseif ($info['type'] == 2) {
  558. $type_info = Dever::db('store/info')->find($v['type_id']);
  559. } elseif ($info['type'] == 3) {
  560. $type_info = Dever::db('store/info')->find($v['type_id']);
  561. }
  562. if (isset($parent_order) && $parent_order && isset($parent_order['uid']) && $parent_order['uid']) {
  563. if ($parent_order['address_id']) {
  564. $address = Dever::load('passport/address')->getOne($parent_order['uid'], $parent_order['address_id']);
  565. if($address) {
  566. $address_contact = $address['contact'];
  567. $address_mobile = $address['mobile'];
  568. $address_info = $address['address_info'];
  569. $member = Dever::db('agent/member')->find(array('mobile'=>$address['mobile']));
  570. if ($member) {
  571. $zhuce = date('Y-m-d H:i',$member['cdate']);
  572. }
  573. }
  574. }
  575. } elseif (isset($type_info) && $type_info) {
  576. $address_contact = $type_info['truename'];
  577. $address_mobile = $type_info['mobile'];
  578. $address_info = $type_info['address'];
  579. }
  580. $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  581. $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
  582. foreach ($goods as $k1 => $v1) {
  583. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  584. if (isset($goods_info['sku'])) {
  585. $sku = $goods_info['sku']['string'];
  586. } else {
  587. $sku = '';
  588. }
  589. if ($v['cdate']) {
  590. $cdate = date('Y-m-d H:i',$v['cdate']);
  591. }
  592. $fadate = '';
  593. if ($v['fadate']) {
  594. $fadate = date('Y-m-d H:i',$v['fadate']);
  595. }
  596. $fdate = '';
  597. if ($v['fdate']) {
  598. $fdate = date('Y-m-d H:i',$v['fdate']);
  599. }
  600. if ($v1['status'] == 1) {
  601. $refund_status = '正常';
  602. } elseif ($v1['status'] == 2) {
  603. $refund_status = '已申报';
  604. } elseif ($v1['status'] == 3) {
  605. $refund_status = '已退款';
  606. }
  607. $tk = Dever::db('shop/buy_order_refund')->find(array('order_id'=>$v['id'],'order_goods_id'=>$v1['id']));
  608. $refund_cdate = '-';
  609. if ($tk) {
  610. $refund_cdate = date('Y-m-d H:i',$tk['cdate']);
  611. }
  612. if ($k1 == 0) {
  613. $num = $v['num'];
  614. $order_price = round($v['price'],2);
  615. $shifu = $shifu;
  616. $record_cash = $record_cash;
  617. $refund_cash = round($v['refund_cash'],2);
  618. } else {
  619. $num = 0;
  620. $order_price = 0;
  621. $shifu = 0;
  622. $record_cash = 0;
  623. $refund_cash = 0;
  624. }
  625. $d = array
  626. (
  627. $shop_type,
  628. $shop['sid'],
  629. $shop['name'],
  630. $v['order_num'],
  631. $goods_info['code']."\t",
  632. $goods_info['cunhuo_code']."\t",
  633. $goods_info['name'],
  634. $sku,
  635. $goods_info['tax'],
  636. round($v1['price'],2),
  637. round($v1['num'],2),
  638. round($v1['price']*$v1['num'],2),
  639. $zhuce,
  640. $cdate,
  641. $cdate,
  642. $fadate,
  643. $fdate,
  644. $num,
  645. $order_price,
  646. $shifu,
  647. $record_cash,
  648. $goods_status[$v1['status']],
  649. $refund_status,
  650. $refund_cdate,
  651. $refund_cash,
  652. $address_contact,
  653. $address_mobile,
  654. $address_info,
  655. );
  656. $body[] = $d;
  657. }
  658. }
  659. }
  660. // print_R($body);die;
  661. if (!$body) {
  662. Dever::alert('此时段没有数据,请重新选择条件');
  663. }
  664. $file = '代理商兑换订单';
  665. return Dever::excelExport($body, $header, $file);
  666. }
  667. public function memberGoods_api()
  668. {
  669. $name = Dever::input('name');
  670. $member_name = Dever::input('member_name');
  671. $card_num = Dever::input('card_num');
  672. $mobile = Dever::input('mobile');
  673. $start = Dever::input('start');
  674. $end = Dever::input('end');
  675. $rstart = Dever::input('rstart');
  676. $rend = Dever::input('end');
  677. $cstart = Dever::input('cstart');
  678. $cend = Dever::input('cend');
  679. if ($card_num) {
  680. $code = Dever::db('card/code')->find(array('card'=>$card_num));
  681. if ($code){
  682. $where['sku_id'] = "t_1.sku_id=".$code['id'];
  683. }
  684. }
  685. if ($name) {
  686. $where['name'] = "t_1.name like '%$name%'";
  687. }
  688. if ($cstart) {
  689. $where['cstart'] = 't_1.cdate+(360*86400)>='. strtotime($cstart);
  690. }
  691. if ($cend) {
  692. $where['cend'] = 't_1.cdate+(360*86400)<='.strtotime($cend)+86399;
  693. }
  694. if ($start) {
  695. $where['start'] = 't_1.cdate>='.strtotime($start);
  696. }
  697. if ($end) {
  698. $where['end'] = 't_1.cdate<='.strtotime($end)+86399;
  699. }
  700. if ($member_name) {
  701. $where['member_name'] = "t_2.name like '%$member_name%'";
  702. }
  703. if ($mobile) {
  704. $where['mobile'] = 't_2.mobile='.$mobile;
  705. }
  706. if ($rstart) {
  707. $where['rstart'] = 't_2.cdate>='.strtotime($rstart);
  708. }
  709. if ($rend) {
  710. $where['rend'] = 't_2.cdate<='.strtotime($rend)+86399;
  711. }
  712. $where['t_1.state'] = 't_1.state=1';
  713. $where['t_1.type'] = "t_1.type in (1,2)";
  714. $header = array('权益名称','会员等级','姓名','手机号','卡号','类型','数量','单件价值','总价值','已兑换价值','已使用价值','未兑换价值','未使用价值','备注','获取方式','获取时间','代理商注册时间','礼品卡有效期');
  715. $body = array();
  716. if ($where) {
  717. $where = implode(' and ', $where);
  718. $data = Dever::db('agent/member_goods')->fetchAll("select t_1.*,t_2.id as aid from churen_agent_member_goods as t_1 left join churen_agent_member as t_2 on t_1.mid = t_2.id where " . $where,array(),array(20, 'list'));
  719. if ($data) {
  720. foreach ($data as $k => $v) {
  721. $role_name = '';
  722. $member_name = '';
  723. $member_mobile = '';
  724. $member = Dever::db('agent/member')->find($v['mid']);
  725. if ($member) {
  726. $member_cdate = '-';
  727. if($member['cdate']){
  728. $member_cdate = date('Y-m-d H:i',$member['cdate']);
  729. }
  730. $member_name = $member['name'];
  731. $member_mobile = $member['mobile'];
  732. $role = Dever::db('setting/role')->find($member['role']);
  733. if ($role) {
  734. $role_name = $role['name'];
  735. }
  736. }
  737. $wd = ($v['total_num'] - $v['sell_num'])*$v['price'];
  738. $yd = $v['sell_num']*$v['price'];
  739. $card = '-';
  740. $mianzhi = '0';
  741. $money = '-';
  742. $youxiao = '';
  743. $leitype = '发放权益';
  744. if($v['type'] == 2){
  745. $code = Dever::db('card/code')->find($v['sku_id']);
  746. if($code){
  747. $card_info = Dever::db('card/info')->find($code['card_id']);
  748. if ($card_info && $card_info['end_dh_day']) {
  749. $youxiao = date('Y-m-d H:i',strtotime(+ $card_info['end_dh_day'].'day',$code['bdate']));
  750. }
  751. $card = $code['card']."\t";
  752. $mianzhi = $code['use_cash'];
  753. }
  754. }
  755. $wy = $v['cash'] - $mianzhi;
  756. $desc = '';
  757. $member_goods_log = Dever::db('agent/member_goods_log')->getOne(array('type'=>$v['type'],'type_id'=>$v['type_id'],'sku_id'=>$v['sku_id'],'state'=>1));
  758. if($member_goods_log && $member_goods_log['desc']){
  759. $desc = $member_goods_log['desc'];
  760. }
  761. $d = array
  762. (
  763. $v['name'],
  764. $role_name,
  765. $member_name,
  766. $member_mobile,
  767. $card,
  768. $leitype,
  769. $v['total_num'],
  770. $v['price'],
  771. $v['cash'],
  772. $yd,
  773. $mianzhi,
  774. $wd,
  775. $wy,
  776. $desc,
  777. '',
  778. date('Y-m-d H:i',$v['cdate']),
  779. $member_cdate,
  780. $youxiao,
  781. );
  782. $body[] = $d;
  783. }
  784. }
  785. }
  786. if (!$body) {
  787. Dever::alert('此时段没有数据,请重新选择条件');
  788. }
  789. $file = '代理商权益';
  790. return Dever::excelExport($body, $header, $file);
  791. }
  792. #代理商权益发放使用兑换明细
  793. public function mingxi_api()
  794. {
  795. $name = Dever::input('name');
  796. $mobile = Dever::input('mobile');
  797. $card_num = Dever::input('card_num');
  798. $shop_name = Dever::input('shop_name');
  799. $shop_num = Dever::input('shop_num');
  800. $order_num = Dever::input('order_num');
  801. $start = Dever::input('start');
  802. $end = Dever::input('end');
  803. $type = Dever::input('type');
  804. if ($name) {
  805. $where['name'] = $name;
  806. }
  807. if ($mobile) {
  808. $where['mobile'] = $mobile;
  809. }
  810. if ($card_num) {
  811. $code = Dever::db('card/code')->find(array('card'=>$card_num));
  812. if ($code){
  813. $where['sku_id'] = $code['id'];
  814. }
  815. }
  816. if ($shop_name) {
  817. $shop = Dever::db('shop/info')->find(array('name'=>$shop_name));
  818. $where['shop_id'] = $shop['id'];
  819. }
  820. if ($shop_num) {
  821. $shop = Dever::db('shop/info')->fetch('select * from churen_shop_info where sid = '.$shop_num.' and state = 1');
  822. $where['shop_id'] = $shop['id'];
  823. }
  824. // print_R($where['shop_id']);die;
  825. if ($order_num) {
  826. $sell_order = Dever::db('shop/sell_order')->find(array('order_num'=>$order_num));
  827. $where['sku_id'] = $sell_order['card_code_id'];
  828. }
  829. if ($start) {
  830. $where['start'] = strtotime($start);
  831. }
  832. if ($end) {
  833. $where['end'] = strtotime($end)+86399;
  834. }
  835. if ($type) {
  836. $where['types'] = $type;
  837. }
  838. $header = array('日期','权益名称','会员等级','姓名','手机号','卡号','类型','数量','单件价值','总价值','门店类型','门店编号','门店名称','关联平台商城订单号','备注','获取方式','获取时间','代理商注册时间','礼品卡有效期');
  839. $body = array();
  840. $where['type'] = '1,2';
  841. $data = Dever::db('agent/member_goods')->getMingxi($where);
  842. $res = array('发放权益','兑换权益','使用权益');
  843. // print_R($data);die;
  844. $rest = array();
  845. if ($where['types'] == -1) {
  846. foreach ($res as $a => $b ){
  847. foreach ($data as $k => $v) {
  848. $v['leixing'] = $b;
  849. $rest[] = $v;
  850. }
  851. }
  852. } elseif ($where['types'] == 1) {
  853. foreach ($data as $k => $v) {
  854. $v['leixing'] = '发放权益';
  855. $rest[] = $v;
  856. }
  857. } elseif ($where['types'] == 2) {
  858. foreach ($data as $k => $v) {
  859. $v['leixing'] = '兑换权益';
  860. $rest[] = $v;
  861. }
  862. } elseif ($where['types'] == 3) {
  863. foreach ($data as $k => $v) {
  864. $v['leixing'] = '使用权益';
  865. $rest[] = $v;
  866. }
  867. }
  868. foreach ($rest as $k => $v) {
  869. $data[$k]['cdate'] = date('Y-m-d H:i',$v['cdate']);
  870. // foreach ($res as $a => $b) {
  871. // $data[$k]['leixing'] = $b;
  872. $member_goods_name = '';
  873. if (isset($v['name']) && $v['name']) {
  874. $member_goods_name = $v['name'];
  875. }
  876. $total_num = '';
  877. if(isset($v['total_num']) && $v['total_num']) {
  878. $total_num = $v['total_num'];
  879. }
  880. $price = '';
  881. if (isset($v['price']) && $v['price']) {
  882. $price = $v['price'];
  883. }
  884. $cash = '';
  885. if (isset($v['cash']) && $v['cash']) {
  886. $cash = $v['cash'];
  887. }
  888. $role_name = '';
  889. $member_name = '';
  890. $member_mobile = '';
  891. $member_cdate = '-';
  892. $member = Dever::db('agent/member')->find($v['mid']);
  893. if ($member) {
  894. if($member['cdate']){
  895. $member_cdate = date('Y-m-d H:i',$member['cdate']);
  896. }
  897. $member_name = $member['name'];
  898. $member_mobile = $member['mobile'];
  899. $role = Dever::db('setting/role')->find($member['role']);
  900. if ($role) {
  901. $role_name = $role['name'];
  902. }
  903. }
  904. $card = '';
  905. $youxiao = '';
  906. if ($v['type'] == 2){
  907. $code = Dever::db('card/code')->find($v['sku_id']);
  908. if($code){
  909. $card_info = Dever::db('card/info')->find($code['card_id']);
  910. if ($card_info && $card_info['end_dh_day']) {
  911. $youxiao = date('Y-m-d H:i',strtotime(+ $card_info['end_dh_day'].'day',$code['bdate']));
  912. }
  913. $card = $code['card']."\t";
  914. }
  915. }
  916. $desc = '';
  917. $member_goods_log = Dever::db('agent/member_goods_log')->getOne(array('type'=>$v['type'],'type_id'=>$v['type_id'],'sku_id'=>$v['sku_id'],'state'=>1));
  918. if($member_goods_log && $member_goods_log['desc']){
  919. $desc = $member_goods_log['desc'];
  920. }
  921. $dui['mid'] = $v['mid'];
  922. if (isset($where['start']) && $where['start']) {
  923. $dui['start'] = $where['start'];
  924. }
  925. if (isset($where['end']) && $where['end']) {
  926. $dui['end'] = $where['end'];
  927. }
  928. $dh_order_ps = Dever::db('agent/dh_order_ps')->getDui($dui);
  929. if ($where['types'] == 2 || $where['types'] == -1) {
  930. // $v['leixing'] = ''
  931. if ($dh_order_ps) {
  932. // $data[$k]['leixing'] = '兑换权益';
  933. foreach ($dh_order_ps as $k =>$v) {
  934. $dh_order = Dever::db('agent/dh_order')->find($v['order_id']);
  935. if ($dh_order && isset($dh_order['info']) && $dh_order['info']){
  936. $desc = $dh_order['info'];
  937. }
  938. }
  939. }
  940. }
  941. $shop_name = '';
  942. $shop_type = '';
  943. $shop_sid = '';
  944. $order_num = '';
  945. if (isset($where['shop_id']) && $where['shop_id']) {
  946. $where['types'] = 3;
  947. $w2['shop_id'] = $where['shop_id'];
  948. if (isset($where['start']) && $where['start']) {
  949. $w2['start'] = $where['start'];
  950. }
  951. if (isset($where['end']) && $where['end']) {
  952. $w2['end'] = $where['end'];
  953. }
  954. $sell_order = Dever::db('shop/sell_order')->getOutOne($w2);
  955. if ($sell_order) {
  956. if ($where['types'] == 3 || $where['types'] == -1){
  957. $w = $this->common($sell_order);
  958. if ($w) {
  959. $shop_name = $w['shop_name'];
  960. $shop_type = $w['shop_type'];
  961. $shop_sid = $w['shop_sid'];
  962. $order_num = $w['order_num'];
  963. }
  964. }
  965. }
  966. } else {
  967. if (isset($v['sku_id']) && $v['sku_id']){
  968. $w1['card_code_id'] = $v['sku_id'];
  969. if (isset($where['start']) && $where['start']) {
  970. $w1['start'] = $where['start'];
  971. }
  972. if (isset($where['end']) && $where['end']) {
  973. $w1['end'] = $where['end'];
  974. }
  975. $sell_order = Dever::db('shop/sell_order')->getOutOne($w1);
  976. if ($sell_order) {
  977. if ($where['types'] == 3 || $where['types'] == -1) {
  978. $w = $this->common($sell_order);
  979. if ($w) {
  980. $shop_name = $w['shop_name'];
  981. $shop_type = $w['shop_type'];
  982. $shop_sid = $w['shop_sid'];
  983. $order_num = $w['order_num'];
  984. }
  985. }
  986. }
  987. }
  988. }
  989. $d = array
  990. (
  991. $data[$k]['cdate'],
  992. $member_goods_name,
  993. $role_name,
  994. $member_name,
  995. $member_mobile,
  996. $card,
  997. $v['leixing'],
  998. $total_num,
  999. $price,
  1000. $cash,
  1001. $shop_type,
  1002. $shop_sid,
  1003. $shop_name,
  1004. $order_num,
  1005. $desc,
  1006. '',
  1007. $data[$k]['cdate'],
  1008. $member_cdate,
  1009. $youxiao,
  1010. );
  1011. $body[] = $d;
  1012. }
  1013. if (!$body) {
  1014. Dever::alert('此时段没有数据,请重新选择条件');
  1015. }
  1016. $file = '代理商权益明细';
  1017. return Dever::excelExport($body, $header, $file);
  1018. }
  1019. public function common($sell_order)
  1020. {
  1021. $w = array();
  1022. $w['order_num'] = $sell_order['order_num'];
  1023. $shop = Dever::db('shop/info')->find($sell_order['shop_id']);
  1024. if ($shop) {
  1025. $w['shop_name'] = $shop['name'];
  1026. $w['shop_sid'] = $shop['sid'];
  1027. if ($shop['type'] = 1) {
  1028. $w['shop_type'] = '体验店';
  1029. } elseif ($shop['type'] = 2) {
  1030. $w['shop_type'] = '零售店';
  1031. } elseif ($shop['type'] = 10) {
  1032. $w['shop_type'] = '平台商城';
  1033. }
  1034. }
  1035. return $w;
  1036. }
  1037. }