Manage.php 36 KB

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