store_id; $StoreModel = new RetailStoreModel(); $store = $StoreModel->getFind(['id' => $store_id], 'openstate as open_state,guide_online_state'); $this->ajaxReturn([ 'status' => 1, 'message' => '获取成功', 'data' => $store, ]); } else { $this->display(); } } /* 获取所有导购员 */ public function get_guide_list() { $param['store_id'] = $this->store_id; $param['merchant_id'] = $this->merchant_id; $param['guide_name'] = I('post.guide_name'); $param['add_time'] = I('post.add_time'); $GuideClass = new Guide(); $result = $GuideClass->getGuideList($param); $this->ajaxReturn($result); } /* 添加导购员 加载模板 添加操作 */ public function create() { if (IS_POST) { $GuideClass = new Guide(); $param = I('post.'); $param['store_id'] = $this->store_id; $param['merchant_id'] = $this->merchant_id; $param['operate_id'] = $this->login_user['id']; $this->ajaxReturn($GuideClass->addGuideUser($param)); } } /* 编辑 */ public function edit() { if (IS_POST) { $data = I('post.'); $data['store_id'] = $this->store_id; $GuideClass = new Guide(); $result = $GuideClass->editGuideUser($data); if ($result['status'] == 1) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '导购员-编辑'; //操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } } /* 销售数据 */ public function details() { $arr = array( 'sell_list_export' => '/index.php/Retail/Guide/sell_list_export', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } /* 获取销售数据 */ public function get_sell_list() { $id = (int)I('get.id'); if (!$id) { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } $moneystate = I('get.moneystate'); /* 状态搜索 */ if ($moneystate) { $map['moneystate'] = $moneystate; } /* 时间搜索 */ $start = I('get.startdate'); $end = I('get.enddate'); if (!empty($start) && !empty($end)) { $startdate = strtotime(I('get.startdate')); $enddate = strtotime(I('get.enddate') . '23:59:59'); $map['paytime'] = array("between", "$startdate,$enddate"); } else if (!empty($start) && empty($end)) { $startdate = strtotime(I('get.startdate')); $map['paytime'] = array('gt', $startdate); } else if (empty($start) && !empty($end)) { $enddate = strtotime(I('get.enddate') . '23:59:59'); $map['paytime'] = array('lt', $enddate); } $map['storeid'] = $this->store_id; $map['guideid'] = $id; $map['paytype'] = array('in', array('1', '2', '3', '4', '5', '6', '7')); $sell_list = M('retail_guideincome')->where($map)->page((int)$_GET['page'], (int)$_GET['limit'])->order('paytime desc')->select(); $count = M('retail_guideincome')->where($map)->count(); $res = $this->statistics_money($map); foreach ($sell_list as $key => &$val) { $val['index'] = $key + 1; $val['guide_name'] = M('retail_guide')->where(array('id' => $id))->getField('guidename'); $val['paytime'] = date("Y-m-d H:i:s", $val['paytime']); if ($val['vipid']) { $vip = M('retail_vip')->field('name,nickname')->where(array('id' => $val['vipid']))->find(); if ($vip['name']) { $val['vip_name'] = $vip['name']; } else if ($vip['nickname']) { $val['vip_name'] = $vip['nickname']; } else { $val['vip_name'] = '未设置'; } } else { $val['vip_name'] = '散客'; } switch ($val['paytype']) { case 1: $val['pay_name'] = '现金支付'; break; case 2: $val['pay_name'] = '银行卡支付'; break; case 3: $val['pay_name'] = '微信支付'; break; case 4: $val['pay_name'] = '支付宝支付'; break; case 5: $val['pay_name'] = '余额支付'; break; case 6: $val['pay_name'] = '微信支付'; break; case 7: $val['pay_name'] = '其他支付'; break; default: $val['pay_name'] = '其他支付'; } if ($val['moneystate'] == 1) { $val['money_state'] = '未提现'; } else if ($val['moneystate'] == 2) { $val['money_state'] = '提现中'; } else { $val['money_state'] = '已结算'; } } $res['code'] = 0; $res['data'] = $sell_list; $res['count'] = $count; $this->ajaxReturn($res); } /* 统计金额 */ public function statistics_money($map) { $sell_money = M('retail_guideincome')->where($map)->sum('allmoney'); $get_money = M('retail_guideincome')->where($map)->sum('income'); unset($map['paytype']); /* 现金支付 */ $map['paytype'] = 1; $xj = M('retail_guideincome')->where($map)->sum('allmoney'); /* 银行卡支付 */ $map['paytype'] = 2; $yhk = M('retail_guideincome')->where($map)->sum('allmoney'); /* 微信支付 */ $map['paytype'] = array('in', '3,6'); $wx = M('retail_guideincome')->where($map)->sum('allmoney'); /* 支付宝卡支付 */ $map['paytype'] = 4; $zfb = M('retail_guideincome')->where($map)->sum('allmoney'); /* 余额支付 */ $map['paytype'] = 5; $hyk = M('retail_guideincome')->where($map)->sum('allmoney'); /* 其他支付 */ $map['paytype'] = 7; $qt = M('retail_guideincome')->where($map)->sum('allmoney'); $res['sell_money'] = $sell_money ? round($sell_money, 2) . '(元)' : '0(元)'; $res['get_money'] = $get_money ? round($get_money, 2) . '(元)' : '0(元)'; $res['xj'] = $xj ? round($xj, 2) . '(元)' : '0(元)'; $res['yhk'] = $yhk ? round($yhk, 2) . '(元)' : '0(元)'; $res['wx'] = $wx ? round($wx, 2) . '(元)' : '0(元)'; $res['zfb'] = $zfb ? round($zfb, 2) . '(元)' : '0(元)'; $res['hyk'] = $hyk ? round($hyk, 2) . '(元)' : '0(元)'; $res['qt'] = $qt ? round($qt, 2) . '(元)' : '0(元)'; return $res; } /* 设置佣金 */ public function setCommission() { $id = I('post.id'); $commission = I('post.commission'); if (!$id || !$commission) { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } $guide = M('retail_guide')->where(array('id' => $id, 'status' => $this->store_id, 'status' => 1))->find(); if (!$guide) { $res['status'] = 0; $res['msg'] = '未查询到该导购员'; $this->ajaxReturn($res); } if ($guide['commission'] == $commission) { $res['status'] = 0; $res['msg'] = '清闲完善提交信息'; $this->ajaxReturn($res); } $up = M('retail_guide')->where(array('id' => $id))->setField('commission', $commission); if ($up) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '导购员-佣金修改'; //操作行为描述 action_log($source, $type, $request_data, $desc); $res['status'] = 1; $res['msg'] = '修改成功'; } else { $res['status'] = 0; $res['msg'] = '修改失败'; } $this->ajaxReturn($res); } /* 删除 */ public function delete() { $store_id = $this->store_id; $id = I('post.id'); if (!$id) { $this->ajaxReturn(['status' => 0, 'msg' => '参数缺失']); } $GuideClass = new Guide(); $result = $GuideClass->delGuideUser([ 'id'=> $id, 'store_id'=> $store_id, ]); if ($result['status'] == 1) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '导购员-删除'; //操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } /* 开启导购模块 */ public function setLineOpenState() { $openState = I('post.openState'); $StoreModel = new RetailStoreModel(); $map = array( 'id' => $this->store_id, ); $save = array( 'openstate' => $openState ? $openState : 2, ); $up = $StoreModel->updateOrder($map, $save); if ($up) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 if ($openState == 1) { $desc = '导购员-开启导购员'; //操作行为描述 } elseif ($openState == 2) { $desc = '导购员-关闭导购员'; //操作行为描述 } action_log($source, $type, $request_data, $desc); $res['status'] = 1; $res['msg'] = '操作成功'; } else { $res['status'] = 0; $res['msg'] = '操作失败'; } $this->ajaxReturn($res); } /* 开启线上导购模块 */ public function changeOnlineStatus() { $guide_online_state = I('post.guide_online_state'); $StoreModel = new RetailStoreModel(); $map = array( 'id' => $this->store_id, ); $save = array( 'guide_online_state' => $guide_online_state ? $guide_online_state : 2, ); $up = $StoreModel->updateOrder($map, $save); if ($up) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 if ($guide_online_state == 1) { $desc = '导购员-开启线上导购员'; //操作行为描述 } elseif ($guide_online_state == 2) { $desc = '导购员-关闭线上导购员'; //操作行为描述 } action_log($source, $type, $request_data, $desc); $res['status'] = 1; $res['msg'] = '操作成功'; } else { $res['status'] = 0; $res['msg'] = '操作失败'; } $this->ajaxReturn($res); } public function takeindex() { $jur = M('retail_store_jurisdiction')->where(array('storeid' => $this->store_id))->field('data_export')->find(); //判断是否有导出权限 $arr = array( 'all_sell_list_export' => '/index.php/Retail/Guide/all_sell_list_export', 'get_audit_list' => '/index.php/Retail/Guide/get_audit_list', 'audit' => '/index.php/Retail/Guide/audit', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->assign('data_export', $jur['data_export']); $this->display(); } /* 获取所有导购销售数据 */ public function get_all_sell_list() { $map['i.storeid'] = $this->store_id; $map['i.paytype'] = array('in', array('1', '2', '3', '4', '5', '6', '7')); $map['g.status'] = 1; /* 状态搜索 */ $moneystate = I('post.moneystate'); if ($moneystate) { $map['moneystate'] = $moneystate; } /* 手机名称搜索 */ $keyword = trim(I('post.keyword'), ''); if ($keyword) { $map['g.phone|g.guidename'] = array('like', '%' . $keyword . '%'); } /* 时间搜索条件 */ $start = I('post.startdate'); $end = I('post.enddate'); if (!empty($start) && !empty($end)) { $startdate = strtotime($start); $enddate = strtotime($end); $map['i.paytime'] = array("between", "$startdate,$enddate"); } else if (!empty($start) && empty($end)) { $startdate = strtotime($start); $map['i.paytime'] = array('gt', $startdate); } else if (empty($start) && !empty($end)) { $enddate = strtotime($end); $map['i.paytime'] = array('lt', $enddate); } $sell_list = M('retail_guideincome as i') ->join('ls_retail_guide as g on i.guideid=g.id') ->field('i.*,g.guidename,g.paynumber,g.chatnumber,g.cardnumber,g.phone') ->where($map) ->page((int)$_POST['page'], (int)$_POST['limit']) ->order('paytime desc') ->select(); $count = M('retail_guideincome as i')->join('ls_retail_guide as g on i.guideid=g.id')->where($map)->count(); $res = $this->statistics_all_money($map); foreach ($sell_list as $key => &$val) { $val['index'] = $key + 1; $val['paytime'] = date("Y-m-d H:i:s", $val['paytime']); $val['moneytime'] = $val['moneytime'] ? date('Y-m-d H:i:s', $val['moneytime']) : '未结算'; $val['auditname'] = $val['auditname'] ? $val['auditname'] : '未结算'; $val['auditnotes'] = $val['auditnotes'] ? $val['auditnotes'] : '-- --'; switch ($val['paytype']) { case 1: $val['pay_name'] = '现金支付'; break; case 2: $val['pay_name'] = '银行卡支付'; break; case 3: $val['pay_name'] = '微信支付'; break; case 4: $val['pay_name'] = '支付宝支付'; break; case 5: $val['pay_name'] = '余额支付'; break; case 6: $val['pay_name'] = '微信支付'; break; case 7: $val['pay_name'] = '其他支付'; break; default: $val['pay_name'] = '其他支付'; } if ($val['vipid']) { $vip = M('retail_vip')->field('name,nickname')->where(array('id' => $val['vipid']))->find(); if ($vip['name']) { $val['vip_name'] = $vip['name']; } else if ($vip['nickname']) { $val['vip_name'] = $vip['nickname']; } else { $val['vip_name'] = '未设置'; } } else { $val['vip_name'] = '散客'; } if ($val['moneystate'] == 1) { $val['money_state'] = '未提现'; } else if ($val['moneystate'] == 2) { $val['money_state'] = '提现中'; } else { $val['money_state'] = '已结算'; } if ($val['guidetype'] == 1) { $val['guide_type'] = '支付宝'; // 显示打款账号 $val['number'] = $val['paynumber']; } else if ($val['guidetype'] == 2) { $val['guide_type'] = '微信'; // 显示打款账号 $val['number'] = $val['chatnumber']; } else if ($val['guidetype'] == 3) { $val['guide_type'] = '银行卡'; $val['number'] = $val['cardnumber']; } else { $val['guide_type'] = '未结算'; $val['number'] = '未结算'; } } $res['code'] = 0; $res['data'] = $sell_list; $res['count'] = $count; $this->ajaxReturn($res); } /* 统计金额 门店所有 */ protected function statistics_all_money($map) { $all_money = M('retail_guideincome as i')->join('ls_retail_guide as g on i.guideid=g.id')->where($map)->sum('allmoney'); $income = M('retail_guideincome as i')->join('ls_retail_guide as g on i.guideid=g.id')->where($map)->sum('income'); /* 未提现 */ $map['moneystate'] = 1; $not_money = M('retail_guideincome as i')->join('ls_retail_guide as g on i.guideid=g.id')->where($map)->sum('income'); /* 待审核 */ $map['moneystate'] = 2; $audit_money = M('retail_guideincome as i')->join('ls_retail_guide as g on i.guideid=g.id')->where($map)->sum('income'); /* 已结算 */ $map['moneystate'] = 3; $do_money = M('retail_guideincome as i')->join('ls_retail_guide as g on i.guideid=g.id')->where($map)->sum('income'); $res['all_money'] = $all_money ? round($all_money, 2) . '(元)' : '0(元)'; $res['income'] = $income ? round($income, 2) . '(元)' : '0(元)'; $res['not_money'] = $not_money ? round($not_money, 2) . '(元)' : '0(元)'; $res['audit_money'] = $audit_money ? round($audit_money, 2) . '(元)' : '0(元)'; $res['do_money'] = $do_money ? round($do_money, 2) . '(元)' : '0(元)'; return $res; } // 查看所属会员名称 public function vip($id) { $vips = M('retail_vip')->field('name,nickname,mobile_phone,cardnum,addtime')->where(array('guideid' => $id, 'status' => 1))->select(); foreach ($vips as $key => &$val) { $val['index'] = $key + 1; if ($val['name']) { $val['vip_name'] = $val['name']; } else if ($val['nickname']) { $val['vip_name'] = $val['nickname']; } else { $val['vip_name'] = '未设置'; } $val['addtime'] = date("Y-m-d H:i:s"); } $this->assign('vips', $vips); $this->display(); } // 结算审核 public function audit($id) { if (IS_POST) { $data = I('post.'); $data['moneystate'] = 3; $data['moneytime'] = time(); $bill = M('retail_guideincome'); $save = $bill->where(array('id' => $id, 'moneystate' => 2))->save($data); if (!empty($save)) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '导购结算-审核结算'; //操作行为描述 action_log($source, $type, $request_data, $desc); $res['status'] = 1; $res['msg'] = '审核成功'; } else { $res['status'] = 0; $res['msg'] = '审核失败'; } $this->ajaxReturn($res); } else if (IS_GET) { // 从支付记录表中获取导购员id $income_res = M('retail_guideincome')->where(array('id' => $id))->find(); // 实例化导购员数据表 $data = M('retail_guide')->where(array('id' => $income_res['guideid']))->find(); // 显示提现类型与提现账号 if ($income_res['guidetype'] == 1) { $data['guidetype'] = '支付宝'; $data['number'] = $data['paynumber']; } else if ($income_res['guidetype'] == 2) { $data['guidetype'] = '微信'; $data['number'] = $data['chatnumber']; } else if ($income_res['guidetype'] == 3) { $data['guidetype'] = '银行卡'; $data['number'] = $data['cardnumber']; } $data['income'] = $income_res['income']; $this->assign('data', $data); $this->display(); } } /* 导购员销售统计报表统计 */ public function guide_statistics() { $guide = M('retail_guide')->where(array('merchantid' => $this->merchant_id, 'storeid' => $this->store_id, 'status' => 1))->getField('id,guidename,addtime', true); $this->assign('guide', $guide); $this->display(); } public function get_guide_statistics() { $map['status'] = 1; $map['storeid'] = $this->store_id; $map['merchantid'] = $this->merchant_id; $guide_ids = M('retail_guide')->where($map)->getField('id', true); /* 导购搜索 */ $guideid = I('get.guideid'); if (!empty($guideid)) { $where['b.guideid'] = $guideid; } else { $where['b.guideid'] = array('in', $guide_ids); } // 时间搜索 $start_time = I('get.start_time'); $end_time = I('get.end_time'); if (!empty($start_time) && !empty($end_time)) { $start_time = strtotime($start_time); $end_time = strtotime($end_time . '23:59:59'); $where['b.addtime'] = array('between', array($start_time, $end_time)); } if (!empty($start_time) && empty($end_time)) { $start_time = strtotime($start_time); $where['b.addtime'] = array('egt', $start_time); } if (empty($start_time) && !empty($end_time)) { $end_time = strtotime(($end_time . '23:59:59')); $where['b.addtime'] = array('elt', $end_time); } $where['b.pay_state'] = 1; $where['b.paytype'] = array('neq', '0'); $where['b.storeid'] = $this->store_id; $where['b.merchantid'] = $this->merchant_id; $where['b.order_type'] = 1; $where['g.status'] = 1; $bill_list = M('retail_bill as b') ->join('ls_retail_guideincome as i on i.billid=b.id') ->join('ls_retail_guide as g on b.guideid=g.id') ->field('b.id,b.order_id,b.paytype,b.vipid,b.refund_status,b.vipid,b.guideid,b.addtime,i.allmoney,i.moneystate,i.commission,g.guidename') ->where($where) ->order('id desc') ->select(); $count = M('retail_bill as b') ->join('ls_retail_guideincome as i on i.billid=b.id') ->join('ls_retail_guide as g on b.guideid=g.id') ->where($where) ->count(); if ($bill_list) { $all_money = 0; // 总金额 $all_get_money = 0; // 总佣金 foreach ($bill_list as $key => &$val) { $val['index'] = ++$key; $all_money += round($val['allmoney'], 2); $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']); $val['vip'] = $val['vipid'] ? '会员' : '散客'; // 消费对象 if ($val['moneystate'] == 1) { $val['money_state'] = '未提现'; } else if ($val['moneystate'] == 2) { $val['money_state'] = '申请中'; } else { $val['money_state'] = '已打款'; } $val['commissions'] = $val['commission'] ? $val['commission'] . '%' : 0; $val['get_money'] = round(($val['allmoney'] * $val['commission']) / 100, 2); // 所得金额 $all_get_money += round($val['get_money'], 2); if ($val['refund_status'] == 0) { $val['refundStatus'] = '正常订单'; } else if ($val['refund_status'] == 1) { $val['refundStatus'] = '申请退款'; } else if ($val['refund_status'] == 2) { $val['refundStatus'] = '退款成功'; } else { $val['refundStatus'] = '有退款'; } switch ($val['paytype']) { case 1: $val['pay_type'] = '现金'; break; case 2: $val['pay_type'] = '银行卡'; break; case 3: $val['pay_type'] = '微信'; break; case 4: $val['pay_type'] = '支付宝'; break; case 5: $val['pay_type'] = '余额'; break; case 6: $val['pay_type'] = '微信'; break; case 7: $val['pay_type'] = '其他'; break; default: $val['pay_type'] = '其他'; } } } $res['code'] = 0; $res['data'] = $bill_list; $res['count'] = $count; $res['all_money'] = $all_money ? $all_money : 0; $res['all_get_money'] = $all_get_money ? $all_get_money : 0; $this->ajaxReturn($res); } /* 销售列表导出 */ public function sell_list_export() { $id = I('get.id'); // 导购员idt_date = I('get.start_date'); // 起始日期 $end_date = I('get.end_date'); // 截止日期 $moneystate = I('get.moneystate'); if (!empty($start_date) && !empty($end_date)) { $start_date = strtotime($start_date); $end_date = strtotime($end_date . '23:59:59'); $map['paytime'] = array("between", "$start_date,$end_date"); } else if (!empty($start_date) && empty($end_date)) { $start_date = strtotime($start_date); $map['paytime'] = array('gt', $start_date); } else if (empty($start_date) && !empty($end_date)) { $end_date = strtotime($end_date . '23:59:59'); $map['paytime'] = array('lt', $end_date); } /* 状态搜索 */ if ($moneystate) { $map['moneystate'] = $moneystate; } $map['guideid'] = $id; $map['storeid'] = $this->store_id; $map['merchantid'] = $this->merchant_id; $map['income'] = array('gt', 0); $sell_list = M('retail_guideincome')->where($map)->order('paytime desc')->select(); foreach ($sell_list as $key => &$val) { $val['index'] = $key + 1; $val['guide_name'] = M('retail_guide')->where(array('id' => $id))->getField('guidename'); $val['paytime'] = date("Y-m-d H:i:s", $val['paytime']); if ($val['vipid']) { $vip = M('retail_vip')->field('name,nickname')->where(array('id' => $val['vipid']))->find(); if ($vip['name']) { $val['vip_name'] = $vip['name']; } else if ($vip['nickname']) { $val['vip_name'] = $vip['nickname']; } else { $val['vip_name'] = '未设置'; } } else { $val['vip_name'] = '散客'; } switch ($val['paytype']) { case 1: $val['pay_name'] = '现金支付'; break; case 2: $val['pay_name'] = '银行卡支付'; break; case 3: $val['pay_name'] = '微信支付'; break; case 4: $val['pay_name'] = '支付宝支付'; break; case 5: $val['pay_name'] = '余额支付'; break; case 6: $val['pay_name'] = '微信支付'; break; case 7: $val['pay_name'] = '其他支付'; break; default: $val['pay_name'] = '其他支付'; } if ($val['moneystate'] == 1) { $val['money_state'] = '未提现'; } else if ($val['moneystate'] == 2) { $val['money_state'] = '提现中'; } else { $val['money_state'] = '已打款'; } } $name = '销售数据'; $headArr = array( array('index', '序号'), array('guide_name', '导购'), array('vip_name', '消费对象'), array('allmoney', '支付金额'), array('pay_name', '支付方式'), array('paytime', '消费时间'), array('income', '所得佣金'), array('money_state', '状态') ); $str = $name . '导出时间' . date('Y-m-d H:i:s', time()); getExcel($name, $headArr, $sell_list, $str); } /* 所有导购销售数据 */ public function all_sell_list_export() { $map['i.storeid'] = $this->store_id; $map['i.paytype'] = array('in', array('1', '2', '3', '4', '5', '6', '7')); $map['g.status'] = 1; /* 状态搜索 */ $moneystate = I('get.moneystate'); if ($moneystate) { $map['moneystate'] = $moneystate; } /* 手机名称搜索 */ $keyword = trim(I('get.keyword'), ''); if ($keyword) { $map['g.phone|g.guidename'] = array('like', '%' . $keyword . '%'); } /* 时间搜索条件 */ $start = I('get.start_date'); $end = I('get.end_date'); if (!empty($start) && !empty($end)) { $startdate = strtotime($start); $enddate = strtotime($end . '23:59:59'); $map['i.paytime'] = array("between", "$startdate,$enddate"); } else if (!empty($start) && empty($end)) { $startdate = strtotime($start); $map['i.paytime'] = array('gt', $startdate); } else if (empty($start) && !empty($end)) { $enddate = strtotime($end . '23:59:59'); $map['i.paytime'] = array('lt', $enddate); } $sell_list = M('retail_guideincome as i') ->join('ls_retail_guide as g on i.guideid=g.id') ->field('i.*,g.guidename,g.paynumber,g.chatnumber,g.cardnumber,g.phone') ->where($map) ->order('paytime desc') ->select(); foreach ($sell_list as $key => &$val) { $val['index'] = $key + 1; $val['paytime'] = date("Y-m-d H:i:s", $val['paytime']); $val['moneytime'] = $val['moneytime'] ? date('Y-m-d H:i:s', $val['moneytime']) : '未结算'; $val['auditname'] = $val['auditname'] ? $val['auditname'] : '未结算'; $val['auditnotes'] = $val['auditnotes'] ? $val['auditnotes'] : '-- --'; switch ($val['paytype']) { case 1: $val['pay_name'] = '现金支付'; break; case 2: $val['pay_name'] = '银行卡支付'; break; case 3: $val['pay_name'] = '微信支付'; break; case 4: $val['pay_name'] = '支付宝支付'; break; case 5: $val['pay_name'] = '余额支付'; break; case 6: $val['pay_name'] = '微信支付'; break; case 7: $val['pay_name'] = '其他支付'; break; default: $val['pay_name'] = '其他支付'; } if ($val['vipid']) { $vip = M('retail_vip')->field('name,nickname')->where(array('id' => $val['vipid']))->find(); if ($vip['name']) { $val['vip_name'] = $vip['name']; } else if ($vip['nickname']) { $val['vip_name'] = $vip['nickname']; } else { $val['vip_name'] = '未设置'; } } else { $val['vip_name'] = '散客'; } if ($val['moneystate'] == 1) { $val['money_state'] = '未提现'; } else if ($val['moneystate'] == 2) { $val['money_state'] = '提现中'; } else { $val['money_state'] = '已结算'; } if ($val['guidetype'] == 1) { $val['guide_type'] = '支付宝'; // 显示打款账号 $val['number'] = $val['paynumber']; } else if ($val['guidetype'] == 2) { $val['guide_type'] = '微信'; // 显示打款账号 $val['number'] = $val['chatnumber']; } else if ($val['guidetype'] == 3) { $val['guide_type'] = '银行卡'; $val['number'] = $val['cardnumber']; } else { $val['guide_type'] = '未结算'; $val['number'] = '未结算'; } } $name = '销售数据'; $headArr = array( array('index', '序号'), array('guidename', '导购'), array('vip_name', '消费对象'), array('allmoney', '支付金额'), array('pay_name', '支付方式'), array('paytime', '消费时间'), array('income', '所得佣金'), array('guide_type', '打款类型'), array('number', '打款账号'), array('moneytime', '提现时间'), array('auditname', '审核人'), array('auditnotes', '审核备注'), array('money_state', '状态') ); $str = $name . '导出时间' . date('Y-m-d H:i:s', time()); getExcel($name, $headArr, $sell_list, $str); } public function batchAudit() { $this->display(); } /* 获取待审核 */ public function get_audit_list() { $map['i.storeid'] = $this->store_id; $map['i.paytype'] = array('neq', 0); $map['i.moneystate'] = 2; $map['g.status'] = 1; /* 手机号 名称搜索 */ $keyword = I('post.keyword2'); if ($keyword) { $map['g.phone|g.guidename'] = array('like', '%' . $keyword . '%'); } $sell_list = M('retail_guideincome as i') ->join('ls_retail_guide as g on i.guideid=g.id') ->field('i.*,g.guidename,g.paynumber,g.chatnumber,g.cardnumber') ->where($map) ->order('paytime desc') ->select(); foreach ($sell_list as $key => &$val) { $val['index'] = $key + 1; $val['paytime'] = date("Y-m-d H:i:s", $val['paytime']); switch ($val['paytype']) { case 1: $val['pay_name'] = '现金支付'; break; case 2: $val['pay_name'] = '银行卡支付'; break; case 3: $val['pay_name'] = '微信支付'; break; case 4: $val['pay_name'] = '支付宝支付'; break; case 5: $val['pay_name'] = '余额支付'; break; case 6: $val['pay_name'] = '微信支付'; break; case 7: $val['pay_name'] = '其他支付'; break; default: $val['pay_name'] = '其他支付'; } if ($val['vipid']) { $vip = M('retail_vip')->field('name,nickname')->where(array('id' => $val['vipid']))->find(); if ($vip['name']) { $val['vip_name'] = $vip['name']; } else if ($vip['nickname']) { $val['vip_name'] = $vip['nickname']; } else { $val['vip_name'] = '未设置'; } } else { $val['vip_name'] = '散客'; } if ($val['moneystate'] == 1) { $val['money_state'] = '未提现'; } else if ($val['moneystate'] == 2) { $val['money_state'] = '提现中'; } else { $val['money_state'] = '已结算'; } if ($val['guidetype'] == 1) { $val['guide_type'] = '支付宝'; // 显示打款账号 $val['number'] = $val['paynumber']; } else if ($val['guidetype'] == 2) { $val['guide_type'] = '微信'; // 显示打款账号 $val['number'] = $val['chatnumber']; } else if ($val['guidetype'] == 3) { $val['guide_type'] = '银行卡'; $val['number'] = $val['cardnumber']; } else { $val['guide_type'] = '未结算'; $val['number'] = '未结算'; } } $res['status'] = 1; $res['list'] = $sell_list; $this->ajaxReturn($res); } /* 批量结算 */ public function batch_settlement() { $audit_list = I('post.audit_list'); $auditname = I('post.auditname'); $auditnotes = I('post.auditnotes'); if (!$audit_list || !$auditname) { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } $save['auditname'] = $auditname; $save['auditnotes'] = $auditnotes; $save['moneystate'] = 3; $save['moneytime'] = time(); foreach ($audit_list as &$value) { $find = M('retail_guideincome')->where(array('id' => $value['id'], 'moneystate' => 2))->find(); if (!$find) { $res['status'] = 0; $res['msg'] = '第' . $value['index'] . '条已结算,请勿重复结算'; $this->ajaxReturn($res); } $up = M('retail_guideincome')->where(array('id' => $value['id']))->save($save); if (!$up) { $res['status'] = 0; $res['msg'] = '第' . $value['index'] . '条结算失败'; $this->ajaxReturn($res); } //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '导购员-批量审核'; //操作行为描述 action_log($source, $type, $request_data, $desc); unset($find); unset($up); } $res['status'] = 1; $res['msg'] = '结算成功'; $this->ajaxReturn($res); } //获取小程序用户 public function getOnlineUserList() { $online_name = I('post.online_name'); $guide_id = I('post.guide_id'); $page = I('post.page'); $limit = I('post.limit'); $merchant_id = $this->merchant_id; $SPUModel = new RetailSmallProgramUserModel(); $map = array( 'merchant_id' => $merchant_id, 'guide_id' => $guide_id, ); if (!empty($online_name)) { $map['nickname'] = array('like', '%' . $online_name . '%'); } $fields = array( 'id', 'avatar', 'nickname', 'guide_id', ); $list = $SPUModel->getSelect($map, $fields); $count = 1; if (empty($list)) { unset($map['guide_id']); $map['login_state'] = 1; $list = $SPUModel->getSelect($map, $fields, 'id' . ' desc', $page . ',' . $limit); $count = $SPUModel->getCount($map); } $res = array( 'status' => 1, 'msg' => '查询成功', 'data' => $list, 'count' => $count ); $this->ajaxReturn($res); } //绑定小程序用户 public function bindOnlineUser() { $user_id = I('post.user_id'); $guide_id = I('post.guide_id'); if (empty($guide_id) || empty($user_id)) { $res = array( 'status' => 0, 'msg' => '缺少参数', ); $this->ajaxReturn($res); } $store_id = $this->store_id; $GuideModel = new RetailGuideModel(); $gMap = array( 'storeid' => $store_id, 'status' => 1, 'id' => $guide_id, ); $guide = $GuideModel->getCount($gMap); if (empty($guide)) { $res = array( 'status' => 0, 'msg' => '您请求的导购员不存在或已离职', ); $this->ajaxReturn($res); } $merchant_id = $this->merchant_id; $SPUModel = new RetailSmallProgramUserModel(); $oMap = array( 'guide_id' => $guide_id, ); $old = $SPUModel->getFind($oMap); if (!empty($old)) { $res = array( 'status' => 0, 'msg' => '操作有误,该导购员已绑定其他用户', ); $this->ajaxReturn($res); } $sMap = array( 'id' => $user_id, 'merchant_id' => $merchant_id, ); $sUser = $SPUModel->getFind($sMap); if (empty($sUser)) { $res = array( 'status' => 0, 'msg' => '您请求的线上用户不存在', ); $this->ajaxReturn($res); } if (!empty($sUser['guide_id'])) { $res = array( 'status' => 0, 'msg' => '该线上用户已绑定导购员,请先解绑', ); $this->ajaxReturn($res); } $save = array( 'guide_id' => $guide_id ); $update = $SPUModel->updateOrder($sMap, $save); if ($update) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '导购员-线上导购-选择'; //操作行为描述 action_log($source, $type, $request_data, $desc); $res = array( 'status' => 1, 'msg' => '绑定成功', ); } else { $res = array( 'status' => 0, 'msg' => '绑定失败', ); } $this->ajaxReturn($res); } //解绑小程序用户 public function unBundlingOnlineUser() { $user_id = I('post.user_id'); if (empty($user_id)) { $res = array( 'status' => 0, 'msg' => '缺少参数', ); $this->ajaxReturn($res); } $merchant_id = $this->merchant_id; $SPUModel = new RetailSmallProgramUserModel(); $sMap = array( 'id' => $user_id, 'merchant_id' => $merchant_id, ); $sUser = $SPUModel->getFind($sMap); if (empty($sUser)) { $res = array( 'status' => 0, 'msg' => '您请求的线上用户不存在', ); $this->ajaxReturn($res); } if (empty($sUser['guide_id'])) { $res = array( 'status' => 0, 'msg' => '该线上用户未绑定导购员,不需要解绑', ); $this->ajaxReturn($res); } $store_id = $this->store_id; $GuideModel = new RetailGuideModel(); $gMap = array( 'status' => 1, 'id' => $sUser['guide_id'], ); $guide = $GuideModel->getFind($gMap); if (!empty($guide) && $guide['storeid'] != $store_id) { $res = array( 'status' => 0, 'msg' => '该导购员不属于您的门店,您无权解绑', ); $this->ajaxReturn($res); } $save = array( 'guide_id' => 0 ); $update = $SPUModel->updateOrder($sMap, $save); if ($update) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '导购员-线上导购-解绑'; //操作行为描述 action_log($source, $type, $request_data, $desc); $res = array( 'status' => 1, 'msg' => '解绑成功', ); } else { $res = array( 'status' => 0, 'msg' => '解绑失败', ); } $this->ajaxReturn($res); } //查看已绑定导购员详情 public function getBindGuide() { $guide_id = I('post.guide_id'); $GuideModel = new RetailGuideModel(); $gMap = array( 'id' => $guide_id, ); $fields = array( 'id', 'jobnum', 'guidename', 'status', 'storeid', ); $guide = $GuideModel->getFind($gMap, $fields); if (empty($guide)) { $res = array( 'status' => 0, 'msg' => '该导购员不存在', ); } else { if ($guide['status'] == 1) { $guide['state_name'] = '在职'; } else { $guide['state_name'] = '已离职'; } $StoreModel = new RetailStoreModel(); $sMap = array( 'id' => $guide['storeid'] ); $guide['store_name'] = $StoreModel->getFindField($sMap, 'storetag'); $res['status'] = 1; $res['msg'] = '查询成功'; $res['data'] = $guide; } $this->ajaxReturn($res); } }