123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815 |
- <?php
- namespace Stats\Lib;
- use Dever;
- Class Manage
- {
- public function index_api()
- {
- $data = array();
- $start = Dever::input('start');
- $end = Dever::input('end');
- if (!$start && !$end) {
- $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
- $end = strtotime(date('Y-m-d 23:59:59',
- strtotime(date('Y-m-01')."+1 month - 1 day")));
- $data['start'] = date('Y-m-d',$start);
- $data['end'] = date('Y-m-d',$end);
- } else {
- $data['start'] = date('Y-m-d',$start);
- $data['end'] = date('Y-m-d',$end);
- }
- $fastart = Dever::input('fastart');
- $faend = Dever::input('faend');
- if (!$fastart && !$faend) {
- $fastart=Dever::maketime(date('Y-m-01') . ' 00:00:00');
- $faend = strtotime(date('Y-m-d 23:59:59',
- strtotime(date('Y-m-01')."+1 month - 1 day")));
- $data['fastart'] = date('Y-m-d',$fastart);
- $data['faend'] = date('Y-m-d',$faend);
- } else {
- $data['fastart'] = date('Y-m-d',$fastart);
- $data['faend'] = date('Y-m-d',$faend);
- }
- $fstart = Dever::input('fstart');
- $fend = Dever::input('fend');
- if (!$fstart && !$fend) {
- $fstart=Dever::maketime(date('Y-m-01') . ' 00:00:00');
- $fend = strtotime(date('Y-m-d 23:59:59',
- strtotime(date('Y-m-01')."+1 month - 1 day")));
- $data['fstart'] = date('Y-m-d',$fstart);
- $data['fend'] = date('Y-m-d',$fend);
- } else {
- $data['fstart'] = date('Y-m-d',$fstart);
- $data['fend'] = date('Y-m-d',$fend);
- }
- $data['type'] = array(1 => '体验店',2 => '零售店',10 => '平台商城');
- return Dever::render('out', $data);
- }
- public function list_api()
- {
- $status = Dever::db('shop/sell_order')->config['status_manage'];
- $start = Dever::input('start');
- $end = Dever::input('end');
- $fastart = Dever::input('fastart');
- $faend = Dever::input('faend');
- $fstart = Dever::input('fstart');
- $fend = Dever::input('fend');
- $cate = Dever::input('cate');
- $name = Dever::input('goods_name');
- $shop_name = Dever::input('shop_name');
- $order_num = Dever::input('order_num');
- if ($start) {
- $where['start'] = strtotime($start);
- }
- if ($end) {
- $where['end'] = strtotime($end);
- }
- if ($fastart) {
- $where['fastart'] = strtotime($fastart);
- }
- if ($faend) {
- $where['faend'] = strtotime($faend);
- }
- if ($fstart) {
- $where['fstart'] = strtotime($fstart);
- }
- if ($fend) {
- $where['fend'] = strtotime($fend);
- }
- if ($cate && $cate>0) {
- $where['shop_type'] = $cate;
- }
- if ($name) {
- $where['name'] = $name;
- }
- if ($shop_name) {
- $shop = Dever::db('shop/info')->find(array('name'=>$name));
- if ($shop) {
- $where['shop_id'] = $shop['id'];
- }
- }
- if ($order_num) {
- $where['order_num'] = $order_num;
- }
- $where['state'] = 1;
- $data = Dever::db('shop/sell_order')->getExcel($where);
- $header = array('门店类型', '门店编号', '门店名称', '订单号', '商品编码', '存货编码', '商品名称', '规格型号', '税率', '商品单价', '购买数量', '商品合计金额', '代理优惠金额', '商品实付金额', '礼品卡金额', '钱包金额','商品支付金额', '礼品卡名称', '礼品卡卡号', '代理商注册时间', '下单时间', '付款时间', '发货时间', '完成时间', '订单总数量', '订单总金额', '订单实付金额', '礼品卡金额', '钱包金额', '优惠券金额', '代理优惠金额', '订单状态', '退款状态', '退款时间', '退款金额','退卡金额','退现金金额', '收件人', '收件人手机', '收件人地址');
- $body = array();
- if ($data) {
- foreach ($data as $k => $v) {
- $shop_type = '';
- if ($v['shop_type'] == 1) {
- $shop_type = '体验店';
- } elseif ($v['shop_type'] == 2) {
- $shop_type = '平台商城';
- }
- $shop = Dever::db('shop/info')->find($v['shop_id']);
- $sid = '';
- $shop_name = '';
- if ($shop) {
- if (isset($shop['sid']) && $shop['sid'] ) {
- $sid = $shop['sid'];
- }
- if (isset($shop['name']) && $shop['name']) {
- $shop_name = $shop['name'];
- }
- }
- $v['card'] = '';
- if ($v['card_code_id']) {
- $code = Dever::db('card/code')->find($v['card_code_id']);
- if ($code) {
- $card_info = Dever::db('card/info')->find($code['card_id']);
- if ($card_info) {
- if (!$code['total_cash']) {
- $code['total_cash'] = $card_info['value'];
- }
- $v['card'] = $card_info['name'];
- $v['card_code'] = $code['card'];
- }
- }
- }
- $zhuce = '';
- $address_contact = '';
- $address_mobile = '';
- $address_info = '';
- if ($v['address_id'] > 0) {
- $address = Dever::load('passport/address')->getOne($v['uid'], $v['address_id']);
- if($address) {
- $address_contact = $address['contact'];
- $address_mobile = $address['mobile'];
- $address_info = $address['address_info'];
- $member = Dever::db('agent/member')->find(array('mobile'=>$address['mobile']));
- if ($member) {
- $zhuce = date('Y-m-d H:i',$member['cdate']);
- }
- }
- }
- $ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
- $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
- $paydate = isset($v['paydate']) && $v['paydate'] ? date('Y-m-d H:i', $v['paydate']) : '-';
- $operdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
- $fdate = '-';
- if ($v['fdate']) {
- $fdate = date('Y-m-d H:i',$v['fdate']);
- }
- $refund_status = '';
- $refund_cdate = '';
- $refund_cash = '';
- $ka = 0;
- $money = 0;
-
- $goods = Dever::db('shop/sell_order_goods')->select(Array('order_id'=>$v['id']));
- foreach($goods as $k1 => $v1) {
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
- if (isset($goods_info['sku'])) {
- $sku = $goods_info['sku']['string'];
- } else {
- $sku = '';
- }
- if ($k1 == 0) {
- $total_cash = Dever::load("shop/lib/manage.getTotalCash", $v['id']);
- } else {
- $total_cash = 0;
- }
- if ($v['status'] == 8 || $v['status'] == 6) {
- $refund_status = '已退款';
- $refund_cash = $v1['price']*$v1['num'];
- if ($v['status'] == 8) {
- if ($v['refund_cash'] && $v['refund_cash']>0) {
- $money = $v['refund_cash']+$v['wallet_cash'];
- }
- if ($v['card_code_cash'] && $v['card_code_cash'] >0) {
- $ka = $v['card_code_cash'];
- }
- if ($k1 == 0) {
- $ka = $ka;
- $money = $money;
- } else {
- $ka = 0;
- $money = 0;
- }
- } elseif ($v['status'] == 6) {
- if ($v1['status'] == 3) {
- if ($v['card_code_id'] && $v['card_code_id'] >0) {
-
- $ka = $v['refund_cash'];
- } else {
- $money = $v['refund_cash'];
- }
- $refund_status = '已退款';
- } else {
- $refund_status = '正常';
- $refund_cash = 0;
- $ka = 0;
- $money = 0;
- }
-
- }
-
- // print_R($ka);die;
-
- $refund_cdate = '';
- if ($v['shop_type'] == 1) {
- $refund = Dever::db('shop/sell_order_refund')->find(array('order_id'=>$v['id']));
- if ($refund) {
- $refund_cdate = date('Y-m-d H:i',$refund['cdate']);
- }
- }
- } else {
- if ($v['refund_status'] == 3 && $v1['status'] == 3) {
- $refund_cash = $v1['num']*$v1['price'];
- if ($v['card_code_id'] && $v['card_code_id'] >0) {
- $ka = $v['refund_cash'];
- } else {
- $money = $v['refund_cash'];
- }
- // $refund_status = '已退款';
- $refund_status = '有退款';
- $refund_cdate = '';
- if ($v['shop_type'] == 1) {
- $refund = Dever::db('shop/sell_order_refund')->find(array('order_id'=>$v['id']));
- if ($refund) {
- $refund_cdate = date('Y-m-d H:i',$refund['cdate']);
- }
- }
- } else {
- $refund_cdate = '';
- $refund_cash = '0';
- $refund_status = '未退款';
- }
- }
- // print_R($goods);die;
- // print_R($goods_info);
- if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
- $heji = 0;
- $heji = $this->total($goods);
- // print_R($heji);die;
- foreach ($goods_info['goods'] as $key => $val) {
- // $val['price']-($val['price']*)
- $youhui = ($val['price']*($val['num']+$v1['num'])-($val['price']*($val['num']+$v1['num'])/$heji)*$v['price'])*$v1['num'];
- $card_price = ($v['card_code_cash']/$heji*($val['price']*($val['num']+$v1['num'])))*$v1['num'];
- $wallet_price = ($v['wallet_cash']/$heji*($val['price']*($val['num']+$v1['num'])))*$v1['num'];
- $goodsfu = $val['price']*($val['num']+$v1['num'])-$youhui-$card_price-$wallet_price;
- if ($key == 0) {
- $price = round($v1['price']*$v1['num']-$v1['discount_cash'],2);
- $shifu = round($v['price'],2);//实付金额
- $order_num = $v1['num'];#订单总数量
- $oprice = round($v1['price']*$v1['num'],2);#订单总金额
- $coupon_cash = round($v1['coupon_cash'],2);
- $discount_cash = round($v1['discount_cash'],2);
- $card_code_cash = round($v['card_code_cash'],2);
- $wallet_cash = round($v['wallet_cash'],2);
- } else {
- $price = 0;
- $shifu = 0;
- $order_num = 0;
- $oprice = 0;#订单总金额
- $coupon_cash = 0;
- $discount_cash = 0;
- $card_code_cash = 0;
- $wallet_cash = 0;
- }
- if($v1['num']>1) {
- $dnum = round($val['num']+$v1['num'],2);
- } else {
- $dnum = round($val['num'],2);
- }
- $d = array
- (
- $shop_type,
- $sid,
- $shop_name,
- $v['order_num'],
- $val['code']."\t",
- $goods_info['cunhuo_code']."\t",
- $val['name'].'('.$goods_info['name'].')',
- $sku,
- $goods_info['tax'],
- round($val['price'],2),
- $dnum,
- round(($val['price']*($val['num']+$v1['num'])),2),
- round($youhui,2),
- $goodsfu,
- $card_price,
- $wallet_price,
- $price,
- $v['card'],
- $v['card_code_card']."\t",
- $zhuce,
- $cdate,
- $paydate,
- $operdate,
- $fdate,
- $order_num,
- $oprice,
- $price,
- $card_code_cash,
- $wallet_cash,
- $coupon_cash,
- $discount_cash,
- $status[$v['status']],
- $refund_status,
- $refund_cdate,
- round($refund_cash, 2),
- round($ka,2),
- round($money,2),
- $address_contact,
- $address_mobile,
- $address_info,
- );
- $body[] = $d;
- }
- } else {
- if ($k1 == 0) {
- $discount_cash = round($v['discount_cash'],2);
- $card_code_cash = round($v['card_code_cash'],2);
- $wallet_cash = round($v['wallet_cash'],2);
- $zhifu = $v['price'];
- $total = $v['oprice']-($card_code_cash + $wallet_cash + $discount_cash+$zhifu);
- $order_num = $v['num'];//订单总数量
- $oprice = round($v['oprice'],2);#订单总金额
- $coupon_cash = round($v['coupon_cash'],2);
- } else {
- $discount_cash = 0;
- $card_code_cash = 0;
- $wallet_cash = 0;
- $total = 0;
- $zhifu = 0;
- $order_num = 0;
- $oprice = 0;
- $coupon_cash = 0;
- }
- // print_R($v1['price']*$v1['num']/$v['oprice']*$v['price']);die;
- $dyouhui = round($v1['discount_cash'],2);
- // ($v1['price']*$v1['num']/$v['oprice']*$v['price']);
- // print_R($dyouhui);die;
- $dcard_price = $v['card_code_cash']/$v['oprice']*($v1['price']*$v1['num']);
- $dwallet_price = $v['wallet_cash']/$v['oprice']*($v1['price']*$v1['num']);
- $dgoodsfu = $v1['price']*$v1['num']-$dyouhui-$dcard_price-$dwallet_price;
- if ($dgoodsfu<0){
- $dgoodsfu = 0;
- }
- $d = array
- (
- $shop_type,
- $sid,
- $shop_name,
- $v['order_num'],
- $goods_info['code']."\t",
- $goods_info['cunhuo_code']."\t",
- $goods_info['name'],
- $sku,
- $goods_info['tax'],
- round($v1['price'],2),
- round($v1['num'],2),
- round(($v1['price']*$v1['num']),2),
- round($dyouhui,2),
- $dgoodsfu,
- $dcard_price,
- $dwallet_price,
- $zhifu,
- $v['card'],
- $v['card_code_card']."\t",
- $zhuce,
- $cdate,
- $paydate,
- $operdate,
- $fdate,
- $order_num,
- sprintf('%01.2f',$total_cash),
- $zhifu,
- $card_code_cash,
- $wallet_cash,
- $coupon_cash,//优惠券
- $discount_cash,//代理优惠
- $status[$v['status']],
- $refund_status,
- $refund_cdate,
- round($refund_cash, 2),
- round($ka,2),
- round($money,2),
- $address_contact,
- $address_mobile,
- $address_info,
- );
- $body[] = $d;
- }
- }
-
- }
- }
- if (!$body) {
- Dever::alert('此时段没有数据,请重新选择条件');
- }
- $file = '商品销售相关数据';
- return Dever::excelExport($body, $header, $file);
- }
- public function total($goods){
- // print_R($goods);die;
- if ($goods) {
- $price = 0;
- foreach ($goods as $k => $v) {
- $price += $v['price'] * $v['num'];
- }
- return $price;
- }
- }
- public function memberGoods_api()
- {
- $name = Dever::input('name');
- $member_name = Dever::input('member_name');
- $card_num = Dever::input('card_num');
- $mobile = Dever::input('mobile');
- $start = Dever::input('start');
- $end = Dever::input('end');
- $rstart = Dever::input('rstart');
- $rend = Dever::input('end');
- $cstart = Dever::input('cstart');
- $cend = Dever::input('cend');
- if ($card_num) {
- $code = Dever::db('card/code')->find(array('card'=>$card_num));
- if ($code){
- $where['sku_id'] = "t_1.sku_id=".$code['id'];
- }
- }
- if ($name) {
- $where['name'] = "t_1.name like '%$name%'";
- }
- if ($cstart) {
- $where['cstart'] = 't_1.cdate+(360*86400)>='. strtotime($cstart);
- }
- if ($cend) {
- $where['cend'] = 't_1.cdate+(360*86400)<='.strtotime($cend);
- }
- if ($start) {
- $where['start'] = 't_1.cdate>='.strtotime($start);
- }
- if ($end) {
- $where['end'] = 't_1.cdate<='.strtotime($end);
- }
-
- if ($member_name) {
- $where['member_name'] = "t_2.name like '%$member_name%'";
- }
- if ($mobile) {
- $where['mobile'] = 't_2.mobile='.$mobile;
- }
- if ($rstart) {
- $where['rstart'] = 't_2.cdate>='.strtotime($rstart);
- }
- if ($rend) {
- $where['rend'] = 't_2.cdate<='.strtotime($rend);
- }
- $where['t_1.state'] = 't_1.state=1';
- $where['t_1.type'] = "t_1.type in (1,2)";
- $header = array('权益名称','会员等级','姓名','手机号','卡号','类型','数量','单件价值','总价值','已兑换价值','已使用价值','未兑换价值','未使用价值','备注','获取方式','获取时间','代理商注册时间','礼品卡有效期');
- $body = array();
- if ($where) {
- $where = implode(' and ', $where);
- $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'));
-
- if ($data) {
- foreach ($data as $k => $v) {
- $role_name = '';
- $member_name = '';
- $member_mobile = '';
- $member = Dever::db('agent/member')->find($v['mid']);
- if ($member) {
- $member_cdate = '-';
- if($member['cdate']){
- $member_cdate = date('Y-m-d H:i',$member['cdate']);
- }
- $member_name = $member['name'];
- $member_mobile = $member['mobile'];
- $role = Dever::db('setting/role')->find($member['role']);
- if ($role) {
- $role_name = $role['name'];
- }
- }
- $wd = ($v['total_num'] - $v['sell_num'])*$v['price'];
- $yd = $v['sell_num']*$v['price'];
- $card = '-';
- $mianzhi = '0';
- $money = '-';
- $youxiao = '';
- $leitype = '发放权益';
- if($v['type'] == 2){
- $code = Dever::db('card/code')->find($v['sku_id']);
- if($code){
- $card_info = Dever::db('card/info')->find($code['card_id']);
- if ($card_info && $card_info['end_dh_day']) {
- $youxiao = date('Y-m-d H:i',strtotime(+ $card_info['end_dh_day'].'day',$code['bdate']));
- }
- $card = $code['card']."\t";
- $mianzhi = $code['use_cash'];
- }
- }
- $wy = $v['cash'] - $mianzhi;
- $desc = '';
- $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));
- if($member_goods_log && $member_goods_log['desc']){
- $desc = $member_goods_log['desc'];
- }
- $d = array
- (
- $v['name'],
- $role_name,
- $member_name,
- $member_mobile,
- $card,
- $leitype,
- $v['total_num'],
- $v['price'],
- $v['cash'],
- $yd,
- $mianzhi,
- $wd,
- $wy,
- $desc,
- '',
- date('Y-m-d H:i',$v['cdate']),
- $member_cdate,
- $youxiao,
- );
- $body[] = $d;
- }
-
- }
- }
- if (!$body) {
- Dever::alert('此时段没有数据,请重新选择条件');
- }
- $file = '代理商权益';
- return Dever::excelExport($body, $header, $file);
- }
- #代理商权益发放使用兑换明细
- public function mingxi_api()
- {
- $name = Dever::input('name');
- $mobile = Dever::input('mobile');
- $card_num = Dever::input('card_num');
- $shop_name = Dever::input('shop_name');
- $shop_num = Dever::input('shop_num');
- $order_num = Dever::input('order_num');
- $start = Dever::input('start');
- $end = Dever::input('end');
- $type = Dever::input('type');
- if ($name) {
- $where['name'] = $name;
- }
- if ($mobile) {
- $where['mobile'] = $mobile;
- }
- if ($card_num) {
- $code = Dever::db('card/code')->find(array('card'=>$card_num));
- if ($code){
- $where['sku_id'] = $code['id'];
- }
- }
- if ($shop_name) {
- $shop = Dever::db('shop/info')->find(array('name'=>$shop_name));
- $where['shop_id'] = $shop['id'];
- }
- if ($shop_num) {
- $shop = Dever::db('shop/info')->fetch('select * from churen_shop_info where sid = '.$shop_num.' and state = 1');
- $where['shop_id'] = $shop['id'];
- }
- // print_R($where['shop_id']);die;
- if ($order_num) {
- $sell_order = Dever::db('shop/sell_order')->find(array('order_num'=>$order_num));
- $where['sku_id'] = $sell_order['card_code_id'];
- }
- if ($start) {
- $where['start'] = strtotime($start);
- }
- if ($end) {
- $where['end'] = strtotime($end);
- }
- if ($type) {
- $where['types'] = $type;
- }
- $header = array('日期','权益名称','会员等级','姓名','手机号','卡号','类型','数量','单件价值','总价值','门店类型','门店编号','门店名称','关联平台商城订单号','备注','获取方式','获取时间','代理商注册时间','礼品卡有效期');
- $body = array();
- $where['type'] = '1,2';
- $data = Dever::db('agent/member_goods')->getMingxi($where);
- $res = array('发放权益','兑换权益','使用权益');
- // print_R($data);die;
- $rest = array();
- if ($where['types'] == -1) {
- foreach ($res as $a => $b ){
- foreach ($data as $k => $v) {
- $v['leixing'] = $b;
- $rest[] = $v;
- }
- }
- } elseif ($where['types'] == 1) {
- foreach ($data as $k => $v) {
- $v['leixing'] = '发放权益';
- $rest[] = $v;
- }
- } elseif ($where['types'] == 2) {
- foreach ($data as $k => $v) {
- $v['leixing'] = '兑换权益';
- $rest[] = $v;
- }
- } elseif ($where['types'] == 3) {
- foreach ($data as $k => $v) {
- $v['leixing'] = '使用权益';
- $rest[] = $v;
- }
- }
-
- foreach ($rest as $k => $v) {
- $data[$k]['cdate'] = date('Y-m-d H:i',$v['cdate']);
- // foreach ($res as $a => $b) {
- // $data[$k]['leixing'] = $b;
- $member_goods_name = '';
- if (isset($v['name']) && $v['name']) {
- $member_goods_name = $v['name'];
- }
- $total_num = '';
- if(isset($v['total_num']) && $v['total_num']) {
- $total_num = $v['total_num'];
- }
- $price = '';
- if (isset($v['price']) && $v['price']) {
- $price = $v['price'];
- }
- $cash = '';
- if (isset($v['cash']) && $v['cash']) {
- $cash = $v['cash'];
- }
- $role_name = '';
- $member_name = '';
- $member_mobile = '';
- $member_cdate = '-';
- $member = Dever::db('agent/member')->find($v['mid']);
- if ($member) {
- if($member['cdate']){
- $member_cdate = date('Y-m-d H:i',$member['cdate']);
- }
- $member_name = $member['name'];
- $member_mobile = $member['mobile'];
- $role = Dever::db('setting/role')->find($member['role']);
- if ($role) {
- $role_name = $role['name'];
- }
- }
- $card = '';
- $youxiao = '';
- if ($v['type'] == 2){
- $code = Dever::db('card/code')->find($v['sku_id']);
- if($code){
- $card_info = Dever::db('card/info')->find($code['card_id']);
- if ($card_info && $card_info['end_dh_day']) {
- $youxiao = date('Y-m-d H:i',strtotime(+ $card_info['end_dh_day'].'day',$code['bdate']));
- }
- $card = $code['card']."\t";
- }
- }
- $desc = '';
- $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));
- if($member_goods_log && $member_goods_log['desc']){
- $desc = $member_goods_log['desc'];
- }
- $dui['mid'] = $v['mid'];
- if (isset($where['start']) && $where['start']) {
- $dui['start'] = $where['start'];
- }
- if (isset($where['end']) && $where['end']) {
- $dui['end'] = $where['end'];
- }
- $dh_order_ps = Dever::db('agent/dh_order_ps')->getDui($dui);
- if ($where['types'] == 2 || $where['types'] == -1) {
- // $v['leixing'] = ''
- if ($dh_order_ps) {
- // $data[$k]['leixing'] = '兑换权益';
- foreach ($dh_order_ps as $k =>$v) {
- $dh_order = Dever::db('agent/dh_order')->find($v['order_id']);
- if ($dh_order && isset($dh_order['info']) && $dh_order['info']){
- $desc = $dh_order['info'];
- }
- }
- }
- }
-
- $shop_name = '';
- $shop_type = '';
- $shop_sid = '';
- $order_num = '';
- if (isset($where['shop_id']) && $where['shop_id']) {
- $where['types'] = 3;
- $w2['shop_id'] = $where['shop_id'];
- if (isset($where['start']) && $where['start']) {
- $w2['start'] = $where['start'];
- }
- if (isset($where['end']) && $where['end']) {
- $w2['end'] = $where['end'];
- }
- $sell_order = Dever::db('shop/sell_order')->getOutOne($w2);
- if ($sell_order) {
- if ($where['types'] == 3 || $where['types'] == -1){
- $w = $this->common($sell_order);
- if ($w) {
- $shop_name = $w['shop_name'];
- $shop_type = $w['shop_type'];
- $shop_sid = $w['shop_sid'];
- $order_num = $w['order_num'];
-
- }
- }
-
- }
- } else {
- if (isset($v['sku_id']) && $v['sku_id']){
- $w1['card_code_id'] = $v['sku_id'];
- if (isset($where['start']) && $where['start']) {
- $w1['start'] = $where['start'];
- }
- if (isset($where['end']) && $where['end']) {
- $w1['end'] = $where['end'];
- }
- $sell_order = Dever::db('shop/sell_order')->getOutOne($w1);
- if ($sell_order) {
- if ($where['types'] == 3 || $where['types'] == -1) {
- $w = $this->common($sell_order);
- if ($w) {
- $shop_name = $w['shop_name'];
- $shop_type = $w['shop_type'];
- $shop_sid = $w['shop_sid'];
- $order_num = $w['order_num'];
- }
- }
- }
- }
- }
- $d = array
- (
- $data[$k]['cdate'],
- $member_goods_name,
- $role_name,
- $member_name,
- $member_mobile,
- $card,
- $v['leixing'],
- $total_num,
- $price,
- $cash,
- $shop_type,
- $shop_sid,
- $shop_name,
- $order_num,
- $desc,
- '',
- $data[$k]['cdate'],
- $member_cdate,
- $youxiao,
- );
- $body[] = $d;
- }
- if (!$body) {
- Dever::alert('此时段没有数据,请重新选择条件');
- }
- $file = '代理商权益明细';
- return Dever::excelExport($body, $header, $file);
- }
- public function common($sell_order)
- {
- $w = array();
- $w['order_num'] = $sell_order['order_num'];
- $shop = Dever::db('shop/info')->find($sell_order['shop_id']);
- if ($shop) {
- $w['shop_name'] = $shop['name'];
- $w['shop_sid'] = $shop['sid'];
- if ($shop['type'] = 1) {
- $w['shop_type'] = '体验店';
- } elseif ($shop['type'] = 2) {
- $w['shop_type'] = '零售店';
- } elseif ($shop['type'] = 10) {
- $w['shop_type'] = '平台商城';
- }
- }
- return $w;
- }
- }
|