Manage.php 36 KB

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