Manage.php 37 KB

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