display(); } public function Mcouponlist() { $userinfo = session("ls_userinfo"); $merchantid = $userinfo['merchantid']; $type = I('get.type'); $time = time(); if (empty($type)) { $w['status'] = array('in', array(1, 2)); // 正常 ,下架优惠券 } else { if ($type == 1) { // 未进行的优惠券 $w['coupontype'] = 1; $w['starttime'] = array('gt', $time); $w['coupon_num'] = array('gt', 0); $w['status'] = 1; // 正常 ,下架优惠券 } else if ($type == 2) { $w['status'] = 1; $w['coupon_num'] = array('gt', 0); $w['_string'] = "(coupontype = 1 AND starttime < {$time} AND endtime > {$time}) OR (coupontype = 2)"; } else if ($type == 3) { $w['_string'] = "(coupontype = 1 AND coupon_num > 0 AND endtime < {$time}) OR (coupon_num <= 0) OR (status = 2)"; } } $page = I('get.page'); $limit = I('get.limit'); $w['merchantid'] = $merchantid; $count = M('retail_mcoupon')->where($w)->count(); $list = M('retail_mcoupon')->where($w) ->page($page, $limit) ->order('addtime desc') ->select(); // 查询出所有可用门店 $storelist = M('retail_store') ->where(array('merchantid' => $merchantid, 'store_status' => 0, 'state' => 0)) ->field('id,storetag') ->select(); $gradeall = M('retail_vip_integral') ->where(array('merchantid' => $merchantid)) ->field('id,cardname') ->select(); foreach ($list as $k => &$v) { $v['type'] = 2; $v['typename'] = '进行中'; $v['addtime'] = date('Y-m-d H:i:s', $v['addtime']); if ($v['coupontype'] == 1) { $v['usetime'] = date('Y-m-d H:i:s', $v['starttime']) . '到' . date('Y-m-d H:i:s', $v['endtime']); if ($v['starttime'] > $time) { $v['type'] = 1; // 未开始 $v['typename'] = '未开始'; } if ($v['endtime'] < $time || $v['coupon_num'] <= 0) { $v['type'] = 3; // 已结束 $v['typename'] = '已结束'; } } else if ($v['coupontype'] == 2) { $v['usetime'] = "会员领取当日起" . $v['daynum'] . '天内有效'; if ($v['coupon_num'] > 0) { $v['type'] = 2; $v['typename'] = '进行中'; } else { $v['type'] = 3; $v['typename'] = '已结束'; } } else if ($v['coupontype'] == 3) { $v['usetime'] = "会员领取次日日起" . $v['daynum'] . '天内有效'; if ($v['coupon_num'] > 0) { $v['type'] = 2; $v['typename'] = '进行中'; } else { $v['type'] = 3; $v['typename'] = '已结束'; } } else { $v['usetime'] = "错误的优惠券,建议删除"; $v['type'] = 3; $v['typename'] = '已结束'; } if ($v['status'] == 2) { $v['type'] = 3; $v['typename'] = '已结束'; } // 可用门店 if ($v['storeids'] == 0) { $v['storelist'] = array(array('id' => 0, 'storetag' => '所有门店')); } else { $v['storelist'] = array(); $v['storeids'] = trim($v['storeids'], ','); $storeids = explode(',', $v['storeids']); foreach ($storelist as $key => $val) { if (in_array($val['id'], $storeids)) { $v['storelist'][] = $val; } } $v['data'] = $storeids; } // 可用会员等级 if ($v['coupon_gradeid'] == 0) { $v['gradelist'] = array(array('id' => 0, 'cardname' => '所有会员')); } else { $v['gradelist'] = array(); $v['coupon_gradeid'] = trim($v['coupon_gradeid'], ','); $gradeids = explode(',', $v['coupon_gradeid']); foreach ($gradeall as $key => $val) { if (in_array($val['id'], $gradeids)) { $v['gradelist'][] = $val; } } } } $rt['code'] = 0; $rt['msg'] = ''; $rt['count'] = $count; $rt['data'] = $list; $this->ajaxReturn($rt); } // 创建优惠券 public function addMcoupon() { $userinfo = session("ls_userinfo"); $merchantid = $userinfo['merchantid']; // 查询出所有可用会员等级 $gradeall = M('retail_vip_integral') ->where(array('merchantid' => $merchantid)) ->field('id,cardname') ->select(); $this->assign('gradeall', $gradeall); $this->assign('gradejson', json_encode($gradeall)); $time = date('Y-m-d H:i:s'); // 查询出所有可用门店 $storelist = M('retail_store') ->where(array('merchantid' => $merchantid, 'store_status' => 0, 'state' => 0)) ->field('id,storetag') ->select(); $this->assign('storelist', $storelist); $this->assign('storejson', json_encode($storelist)); $this->assign('time', $time); $this->display(); } // 投放优惠券 public function launchcoupon() { if (IS_POST) { $post = I('post.'); $grade = $post['grade']; if (!$grade) { $rt['status'] = 0; $rt['msg'] = '请选择会员等级'; $this->ajaxReturn($rt); } $id = $post['id']; $userinfo = session("ls_userinfo"); $merchantid = $userinfo['merchantid']; $w['merchantid'] = $merchantid; $w['status'] = 1; // 正常 ,下架优惠券 $w['id'] = $id; $coupon = M('retail_mcoupon')->where($w)->find(); $gradeall = M('retail_vip_integral') ->where(array('merchantid' => $merchantid)) ->field('id,cardname,min_integral') ->order('min_integral asc') ->select(); // 循环生成可用的等级积分区间 $integralarr = array(); $len = count($gradeall); if ($grade[0] == 0) { $defaultgrade = true; unset($grade[0]); } else { $defaultgrade = false; } foreach ($gradeall as $key => $val) { foreach ($grade as $k => $v) { if ($v == $val['id']) { if ($len == $key + 1) { $max = -1; } else { $max = $gradeall[$key + 1]['min_integral'] * 1; } $integralarr[$val['min_integral']] = array('min' => $val['min_integral'] * 1, 'max' => $max); } } } array_multisort(array_columns($integralarr, 'min'), SORT_DESC, $integralarr); // 按会员积分区间 查询符合的会员。 $allvipid = array(); foreach ($integralarr as $k => $v) { $where = array(); $where['status'] = 1; // 会员状态正常 $where['merchantid'] = $merchantid; if ($v['max'] == -1) { $where['grade_integral'] = array('egt', $v['min']); } else { // $where['grade_integral'] = array('egt',$v[0]); // $where['grade_integral'] = array('lt',$v[1]); $where['grade_integral'] = array(array('egt', $v['min']), array('lt', $v['max']), "AND"); } $vids = M('retail_vip')->where($where)->field('id,grade_integral')->order('grade_integral desc,addtime asc')->select(); $allvipid = array_merge($allvipid, $vids); } if ($defaultgrade) { $where = array(); $where['status'] = 1; // 会员状态正常 $where['merchantid'] = $merchantid; $where['grade_integral'] = array(array('egt', 0), array('lt', $gradeall[0]['min_integral']), "AND"); $vids = M('retail_vip')->where($where)->field('id,grade_integral')->order('grade_integral desc,addtime asc')->select(); $allvipid = array_merge($allvipid, $vids); } $time = time(); $Ad['mcouponid'] = $id; $Ad['needmoney'] = $coupon['needmoney']; $Ad['reducemoney'] = $coupon['reducemoney']; $Ad['merchantid'] = $merchantid; $Ad['canusestoreids'] = $coupon['storeids']; $Ad['addtime'] = $time; if ($coupon['coupontype'] == 1) { $Ad['starttime'] = $coupon['starttime']; $Ad['endtime'] = $coupon['endtime']; } else if ($coupon['coupontype'] == 2) { $Ad['starttime'] = time(); $Ad['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + $coupon['daynum'] * 86400; } else if ($coupon['coupontype'] == 3) { $Ad['starttime'] = strtotime(date('Y-m-d') . ' 23:59:59') + 1; $Ad['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + ($coupon['daynum'] + 1) * 86400; } $num = 0; $coupon_num = $coupon['coupon_num']; // 剩余数量 $fisrt = "尊敬的会员用户,赠送您一张" . $coupon['coupon_name']; $Ad['coupon_name'] = $coupon['coupon_name']; $merchanname = M('retail_merchant')->where(array('id' => $merchantid))->getField('name'); $remark = $merchanname . '提示:优惠券在' . date('Y-m-d', $Ad['starttime']) . '到' . date('Y-m-d', $Ad['endtime']) . '有效期内可以使用'; foreach ($allvipid as $k => $v) { if ($k < $coupon_num && $coupon_num > 0) { $Ad['vid'] = $v['id']; M('retail_vipmcoupon')->add($Ad); $num++; A('Vip/Mark')->launchcoupon($v['id'], $fisrt, $remark, $Ad); } else { break; } } $ret = M('retail_mcoupon')->where(array('id' => $id))->setDec('coupon_num', $num); $rt['data2'] = $num; $rt['vipids'] = $allvipid; if ($ret) { $rt['status'] = 1; $rt['msg'] = "投放成功"; } else { $rt['status'] = 2; $rt['msg'] = "投放失败"; // $rt['data'] = M()->_sql(); $rt['data2'] = $num; $rt['vipids'] = $allvipid; } $this->ajaxReturn($rt); } else { $id = I('get.id'); $userinfo = session("ls_userinfo"); $merchantid = $userinfo['merchantid']; $w['merchantid'] = $merchantid; $w['status'] = array('in', array(1, 2)); // 正常 ,下架优惠券 $w['id'] = $id; $v = M('retail_mcoupon')->where($w) ->find(); // 查询出所有可用门店 $storelist = M('retail_store') ->where(array('merchantid' => $merchantid, 'store_status' => 0, 'state' => 0)) ->field('id,storetag') ->select(); $gradeall = M('retail_vip_integral') ->where(array('merchantid' => $merchantid)) ->order('min_integral asc') ->field('id,cardname,min_integral') ->select(); $v['addtime'] = date('Y-m-d H:i:s', $v['addtime']); if ($v['coupontype'] == 1) { $v['usetime'] = date('Y-m-d H:i:s', $v['starttime']) . '到' . date('Y-m-d H:i:s', $v['endtime']); } else if ($v['coupontype'] == 2) { $v['usetime'] = "会员领取当日起" . $v['daynum'] . '天内有效'; } else if ($v['coupontype'] == 3) { $v['usetime'] = "会员领取次日日起" . $v['daynum'] . '天内有效'; } else { $v['usetime'] = "错误的优惠券,建议删除"; } // 可用门店 if ($v['storeids'] == 0) { $v['storelist'] = array(array('id' => 0, 'storetag' => '所有门店')); } else { $v['storelist'] = array(); $v['storeids'] = trim($v['storeids'], ','); $storeids = explode(',', $v['storeids']); foreach ($storelist as $key => $val) { if (in_array($val['id'], $storeids)) { $v['storelist'][] = $val; } } $v['data'] = $storeids; } // 可用会员等级 if ($v['coupon_gradeid'] == 0) { if (empty($gradeall) || $gradeall[0]['min_integral'] > 0) { $defaultgrade = array( 'id' => 0, 'cardname' => '默认等级' ); $this->assign('defaultgrade', $defaultgrade); } $v['gradelist'] = $gradeall; } else { $v['gradelist'] = array(); $v['coupon_gradeid'] = trim($v['coupon_gradeid'], ','); $gradeids = explode(',', $v['coupon_gradeid']); foreach ($gradeall as $key => $val) { if (in_array($val['id'], $gradeids)) { $v['gradelist'][] = $val; } } } $this->assign('coupon', $v); $this->display(); } } //失效优惠券 public function makeend() { if (IS_POST) { $id = I('post.id'); $userinfo = session("ls_userinfo"); $merchantid = $userinfo['merchantid']; $w['id'] = $id; $w['merchantid'] = $merchantid; $savedata['status'] = 2; $ret = M('retail_mcoupon')->where($w)->save($savedata); if ($ret) { $rt['status'] = 1; $rt['msg'] = '失效成功'; } else { $rt['status'] = 0; $rt['msg'] = '失效失败'; } $this->ajaxReturn($rt); } } // 优惠券记录 public function couponrecord() { $id = I('get.id'); $this->assign('id', $id); $this->display(); } // 优惠券记录列表数据 public function recordlist() { $userinfo = session("ls_userinfo"); $merchantid = $userinfo['merchantid']; $id = I('get.id'); $page = I('get.page'); $limit = I('get.limit'); $type = I('get.type'); $time = time(); $coupon = M('retail_mcoupon')->where(array('id' => $id))->find(); // 将未使用的过期的优惠券 该未过期 M('retail_vipmcoupon') ->where(array('mcouponid' => $id, 'endtime' => array('lt', $time), 'isuse' => 1)) ->save(array('isuse' => 3)); $order = 'addtime desc'; if ($type == 2) { $w['isuse'] = 2; // 使用记录 $order = 'usetime desc'; } else if ($type == 3) { // $w['isuse'] = 3; // 已过期 $w['_string'] = "(isuse =3 ) OR (mcouponid = {$id} AND endtime <{$time} AND isuse = 1)"; } $w['mcouponid'] = $id; $list = M('retail_vipmcoupon') ->where($w)->page($page, $limit) ->order($order) ->select(); $count = M('retail_vipmcoupon')->where($w)->count(); if ($list) { foreach ($list as $k => &$v) { $v['coupon_name'] = $coupon['coupon_name']; $v['addtime'] = date('Y-m-d H:i:s', $v['addtime']); $v['canusetime'] = date('Y-m-d H:i:s', $v['starttime']) . ' 到 ' . date('Y-m-d H:i:s', $v['endtime']); if ($v['isuse'] == 1) { if ($v['endtime'] < $time) { $v['isuse'] = '已过期'; $v['usetime'] = '已过期'; $v['usestore'] = '已过期'; } else { $v['isuse'] = '未使用'; $v['usetime'] = '未使用'; $v['usestore'] = '未使用'; } } else if ($v['isuse'] == 2) { $v['isuse'] = '已使用'; $v['usetime'] = date('Y-m-d H:i:s', $v['usetime']); $v['usestore'] = M('retail_store')->where(array('id' => $v['storeid']))->getField('storetag'); } else if ($v['isuse'] == 3) { $v['isuse'] = '已过期'; $v['usetime'] = '已过期'; $v['usestore'] = '已过期'; } else { $v['isuse'] = '错误了'; $v['usetime'] = '错误了'; $v['usestore'] = '错误了'; } $vip = M('retail_vip')->where(array('id' => $v['vid']))->field('name,nickname,mobile_phone')->find(); $v['vip'] = $vip['name'] ? $vip['name'] : ($vip['nickname'] ? $vip['nickname'] : '未设置名称'); $v['mobile_phone'] = $vip['mobile_phone']; } } $rt['code'] = 0; $rt['msg'] = ""; $rt['data'] = $list; $rt['count'] = $count; $this->ajaxReturn($rt); } public function index2() { if (IS_POST) { //获取用户storeid ; $userinfo = cookie("ls_userinfo"); if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') { $where['merchantid'] = $userinfo['merchantid']; $where['store_type'] = 0; $one = M("store")->where($where)->find(); if ($one) { $storeid = $one['id']; } } else { $storeid = $userinfo['storeid']; } $w['storeid'] = $storeid; $id = I("post.id"); $w['id'] = $id; $data['status'] = 2;// 下架 $ret = M('coupon')->where($w)->save($data); if ($ret) { $rt['status'] = 1; $rt['msg'] = "下架成功"; } else { $rt['status'] = 1; $rt['msg'] = "下架失败"; } $this->ajaxReturn($rt); } else { //获取用户storeid ; $userinfo = session("ls_userinfo"); // 查找未过期 未下架的优惠券 $w['deadtime'] = array('gt', time()); $w['status'] = 1;// 未下架 $p = I("p/d") ? I("p/d") : 1; $count = M("coupon")->where($w)->count(); $Page = new \Common\Model\Pages ($count, 12); $show = $Page->show(); // 分页显示输出 $this->assign('page', $show); // 赋值分页输出 $rows = M("coupon")->where($w)->page($p, 12)->order('addtime desc')->select(); // retail_mcoupon // 查找已投放信息 foreach ($rows as $k => $v) { $ww['status'] = 2; $ww['type'] = 3; // $ww['storeid'] = $storeid; $ww['exchangeid'] = $v['id']; $rows[$k]['usenum'] = M('integral_exchange')->where($ww)->count() ? M('integral_exchange')->where($ww)->count() : 0; } $this->assign('empty', '没有优惠券信息哦'); $this->assign("couponlist", $rows); $this->display(); } } // 下架优惠券 public function soldout() { if (IS_POST) { //获取用户storeid ; $userinfo = cookie("ls_userinfo"); if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') { $where['merchantid'] = $userinfo['merchantid']; $where['store_type'] = 0; $one = M("store")->where($where)->find(); if ($one) { $storeid = $one['id']; } } else { $storeid = $userinfo['storeid']; } $w['storeid'] = $storeid; $id = I("post.id"); $w['id'] = $id; $data['status'] = 1;// 上架 $ret = M('coupon')->where($w)->save($data); if ($ret) { $rt['status'] = 1; $rt['msg'] = "上架成功"; } else { $rt['status'] = 1; $rt['msg'] = "上架失败"; } $this->ajaxReturn($rt); } else { //获取用户storeid ; $userinfo = cookie("ls_userinfo"); if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') { $where['merchantid'] = $userinfo['merchantid']; $where['store_type'] = 0; $one = M("store")->where($where)->find(); if ($one) { $storeid = $one['id']; } } else { $storeid = $userinfo['storeid']; } // 查找未过期 已下架的优惠券 $w['deadtime'] = array('gt', time()); $w['status'] = 2;// 已下架 $w['storeid'] = $storeid; $p = I("p/d") ? I("p/d") : 1; $count = M("coupon")->where($w)->count(); $Page = new \Common\Model\Pages ($count, 12); $show = $Page->show(); // 分页显示输出 $this->assign('page', $show); // 赋值分页输出 $rows = M("coupon")->where($w)->page($p, 12)->select(); // 查找已投放信息 foreach ($rows as $k => $v) { $ww['status'] = 2; $ww['type'] = 3; $ww['storeid'] = $storeid; $ww['exchangeid'] = $v['id']; $rows[$k]['usenum'] = M('integral_exchange')->where($ww)->count() ? M('integral_exchange')->where($ww)->count() : 0; } $this->assign('empty', '没有优惠券信息哦'); $this->assign("couponlist", $rows); $this->display(); } } // 已过期的优惠券 public function overdue() { if (IS_POST) { //获取用户storeid ; $userinfo = cookie("ls_userinfo"); if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') { $where['merchantid'] = $userinfo['merchantid']; $where['store_type'] = 0; $one = M("store")->where($where)->find(); if ($one) { $storeid = $one['id']; } } else { $storeid = $userinfo['storeid']; } $w['storeid'] = $storeid; $id = I("post.id"); $w['id'] = $id; $ret = M('coupon')->where($w)->delete(); if ($ret) { $rt['status'] = 1; $rt['msg'] = "销毁成功"; } else { $rt['status'] = 1; $rt['msg'] = "销毁失败"; } $this->ajaxReturn($rt); } else { //获取用户storeid ; $userinfo = cookie("ls_userinfo"); if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') { $where['merchantid'] = $userinfo['merchantid']; $where['store_type'] = 0; $one = M("store")->where($where)->find(); if ($one) { $storeid = $one['id']; } } else { $storeid = $userinfo['storeid']; } // 查找未过期 已下架的优惠券 $w['deadtime'] = array('lt', time()); $w['storeid'] = $storeid; $p = I("p/d") ? I("p/d") : 1; $count = M("coupon")->where($w)->count(); $Page = new \Common\Model\Pages ($count, 12); $show = $Page->show(); // 分页显示输出 $this->assign('page', $show); // 赋值分页输出 $rows = M("coupon")->where($w)->page($p, 12)->select(); // 查找已投放信息 foreach ($rows as $k => $v) { $ww['status'] = 2; $ww['type'] = 3; $ww['storeid'] = $storeid; $ww['exchangeid'] = $v['id']; $rows[$k]['usenum'] = M('integral_exchange')->where($ww)->count() ? M('integral_exchange')->where($ww)->count() : 0; } $this->assign('empty', '没有优惠券信息哦'); $this->assign("couponlist", $rows); $this->display(); } } // 添加优惠券 public function addcoupon() { if (IS_POST) { //获取用户storeid ; $userinfo = cookie("ls_userinfo"); if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') { $where['merchantid'] = $userinfo['merchantid']; $where['store_type'] = 0; $one = M("store")->where($where)->find(); if ($one) { $storeid = $one['id']; } } else { $storeid = $userinfo['storeid']; } $str = I("post.deadtime"); $deadtimearr = explode("-", $str); $deadtime = mktime(23, 59, 59, $deadtimearr[1], $deadtimearr[2], $deadtimearr[0]); $Ad['storeid'] = $storeid; $Ad['deadtime'] = $deadtime; // 有效期 // echo date("Y-m-d h-i-sa",$deadtime); $Ad['needmoney'] = I("post.needmoney"); // 满 $Ad['reducemoney'] = I("post.reducemoney"); //减 $Ad['coupon_allnum'] = I("post.coupon_allnum"); // 数量 $Ad['coupon_num'] = I("post.coupon_allnum"); // 数量 $Ad['coupon_name'] = I("post.coupon_name"); // 名字 $Ad['coupon_type'] = 1;// 代金券 $Ad['addtime'] = time(); // 添加时间 $Ad['status'] = 1; // 上架 $Ad['usenum'] = I("post.usenum"); $ret = M("coupon")->add($Ad); if ($ret) { $rt['status'] = 1; $rt['msg'] = "添加优惠券成功"; } else { $rt['status'] = 2; $rt['msg'] = "添加优惠券失败"; } $this->ajaxReturn($rt); } else { $this->display(); } } // 发放记录 public function usedata() { //获取用户storeid ; $userinfo = cookie("ls_userinfo"); if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') { $where['merchantid'] = $userinfo['merchantid']; $where['store_type'] = 0; $one = M("store")->where($where)->find(); if ($one) { $storeid = $one['id']; } } else { $storeid = $userinfo['storeid']; } $id = I("get.id"); $m['storeid'] = $storeid; $m['exchangeid'] = $id; $m['type'] = 3; $p = I("p/d") ? I("p/d") : 1; $count = M("integral_exchange")->where($m)->count(); $Page = new \Common\Model\Pages ($count, 12); $show = $Page->show(); // 分页显示输出 $this->assign('page', $show); // 赋值分页输出 $rows = M("integral_exchange")->where($m)->page($p, 12)->order('usetime')->select(); // 查找用户信息 foreach ($rows as $k => $v) { $vipid = $v['vid']; $vipmsg = M("vip")->find($vipid); $vipmsg['grade'] = $this->getgrade($storeid, $vipmsg['grade_integral']); $rows[$k]['vipmsg'] = $vipmsg;// vip用户信息 } $msg = M("coupon")->find($id); $this->assign('couponmsg', $msg);// 优惠券信息 $this->assign("couponlist", $rows); $this->display(); } // 使用记录。 public function usedata2() { //获取用户storeid ; $userinfo = cookie("ls_userinfo"); if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') { $where['merchantid'] = $userinfo['merchantid']; $where['store_type'] = 0; $one = M("store")->where($where)->find(); if ($one) { $storeid = $one['id']; } } else { $storeid = $userinfo['storeid']; } $id = I("get.id"); $ww['status'] = 2; $ww['type'] = 3; $ww['storeid'] = $storeid; $ww['exchangeid'] = I('get.id'); $p = I("p/d") ? I("p/d") : 1; $count = M("integral_exchange")->where($ww)->count(); $Page = new \Common\Model\Pages ($count, 12); $show = $Page->show(); // 分页显示输出 $this->assign('page', $show); // 赋值分页输出 $rows = M("integral_exchange")->where($ww)->page($p, 12)->select(); // 查找用户信息 foreach ($rows as $k => $v) { $vipid = $v['vid']; $vipmsg = M("vip")->find($vipid); $vipmsg['grade'] = $this->getgrade($storeid, $vipmsg['grade_integral']); $rows[$k]['vipmsg'] = $vipmsg;// vip用户信息 } $msg = M("coupon")->find($id); $this->assign('couponmsg', $msg);// 优惠券信息 $this->assign("couponlist", $rows); $this->display(); } // 获取用户等级 function getgrade($storeid, $integral) { $wgrade['min_integral'] = array("elt", $integral); $wgrade['storeid'] = $storeid; $integrallist = M('vip_integral')->where($wgrade)->order("min_integral")->select(); if ($integrallist) { $grade = $integrallist[count($integrallist) - 1]['cardname']; } else { $grade = "普通会员"; } return $grade; } //充值送积分 public function give() { $id = I('get.id'); $mcoupon = M('retail_mcoupon')->where(array('id' => $id))->find(); $this->assign('mcoupon', $mcoupon); $this->display(); } //充值送积分提交按钮 public function submitgive() { $post = I('post.'); if (empty($post['give_status']) || empty($post['money']) || empty($post['id'])) { $res['status'] = 0; $res['msg'] = '参数错误'; $this->ajaxReturn($res); exit; } else { $data['give_status'] = $post['give_status']; $data['money'] = $post['money']; $save = M('retail_mcoupon')->where(array('id' => $post['id']))->save($data); if ($save) { $res['status'] = 1; $res['msg'] = '操作成功'; } else { $res['status'] = 0; $res['msg'] = '操作失败'; } $this->ajaxReturn($res); } } // 投放优惠券 // 投放优惠券 public function appointlaunchcoupon() { if (IS_POST) { $post = I('post.'); $allvipid = $post['ids']; if (!$allvipid) { $rt['status'] = 0; $rt['msg'] = '请选择会员'; $this->ajaxReturn($rt); } $allvipid = explode(',', $allvipid); $id = $post['id']; $userinfo = session("ls_userinfo"); $merchantid = $userinfo['merchantid']; $w['merchantid'] = $merchantid; $w['status'] = 1; // 正常 ,下架优惠券 $w['id'] = $id; $coupon = M('retail_mcoupon')->where($w)->find(); $time = time(); $Ad['mcouponid'] = $id; $Ad['needmoney'] = $coupon['needmoney']; $Ad['reducemoney'] = $coupon['reducemoney']; $Ad['merchantid'] = $merchantid; $Ad['canusestoreids'] = $coupon['storeids']; $Ad['addtime'] = $time; if ($coupon['coupontype'] == 1) { $Ad['starttime'] = $coupon['starttime']; $Ad['endtime'] = $coupon['endtime']; } else if ($coupon['coupontype'] == 2) { $Ad['starttime'] = time(); $Ad['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + $coupon['daynum'] * 86400; } else if ($coupon['coupontype'] == 3) { $Ad['starttime'] = strtotime(date('Y-m-d') . ' 23:59:59') + 1; $Ad['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + ($coupon['daynum'] + 1) * 86400; } $num = 0; $coupon_num = $coupon['coupon_num']; // 剩余数量 $fisrt = "尊敬的会员用户,赠送您一张" . $coupon['coupon_name']; $Ad['coupon_name'] = $coupon['coupon_name']; $merchanname = M('retail_merchant')->where(array('id' => $merchantid))->getField('name'); $remark = $merchanname . '提示:优惠券在' . date('Y-m-d', $Ad['starttime']) . '到' . date('Y-m-d', $Ad['endtime']) . '有效期内可以使用'; foreach ($allvipid as $k => $v) { if ($k < $coupon_num && $coupon_num > 0) { $Ad['vid'] = $v; M('retail_vipmcoupon')->add($Ad); $num++; A('Vip/Mark')->launchcoupon($v, $fisrt, $remark, $Ad); } else { break; } } $ret = M('retail_mcoupon')->where(array('id' => $id))->setDec('coupon_num', $num); $rt['data2'] = $num; $rt['vipids'] = $allvipid; if ($ret) { $rt['status'] = 1; $rt['msg'] = "投放成功"; } else { $rt['status'] = 2; $rt['msg'] = "投放失败"; $rt['data2'] = $num; $rt['vipids'] = $allvipid; } $this->ajaxReturn($rt); } else { $id = I('get.id'); $userinfo = session("ls_userinfo"); $merchantid = $userinfo['merchantid']; $w['merchantid'] = $merchantid; $w['status'] = array('in', array(1, 2)); // 正常 ,下架优惠券 $w['id'] = $id; $v = M('retail_mcoupon')->where($w) ->find(); // 查询出所有可用门店 $storelist = M('retail_store') ->where(array('merchantid' => $merchantid, 'store_status' => 0, 'state' => 0)) ->field('id,storetag') ->select(); $v['addtime'] = date('Y-m-d H:i:s', $v['addtime']); if ($v['coupontype'] == 1) { $v['usetime'] = date('Y-m-d H:i:s', $v['starttime']) . '到' . date('Y-m-d H:i:s', $v['endtime']); } else if ($v['coupontype'] == 2) { $v['usetime'] = "会员领取当日起" . $v['daynum'] . '天内有效'; } else if ($v['coupontype'] == 3) { $v['usetime'] = "会员领取次日日起" . $v['daynum'] . '天内有效'; } else { $v['usetime'] = "错误的优惠券,建议删除"; } // 可用门店 if ($v['storeids'] == 0) { $v['storelist'] = array(array('id' => 0, 'storetag' => '所有门店')); } else { $v['storelist'] = array(); $v['storeids'] = trim($v['storeids'], ','); $storeids = explode(',', $v['storeids']); foreach ($storelist as $key => $val) { if (in_array($val['id'], $storeids)) { $v['storelist'][] = $val; } } $v['data'] = $storeids; } $this->assign('coupon', $v); $userinfo = session("ls_userinfo"); $machantid = $userinfo['merchantid']; $info = M("retail_store") ->where(array('merchantid' => $machantid, 'store_status' => 0)) ->field("id,storetag") ->select(); $this->assign("list", $info); $one = M('retail_vip_integral') ->where(array('merchantid' => $userinfo['merchantid'])) ->order('min_integral asc') ->field('id,min_integral,cardname') ->select(); if ($one && $one[0]['min_integral'] > 0) { $arr = array( 'id' => 0, 'min_integral' => 0, 'cardname' => '默认会员' ); $one = array_merge(array($arr), $one); } array_values($one); $gradeArr = array(); $count = count($one); foreach ($one as $k => $v) { if ($k < $count - 1) { $item = array( 'id' => $v['id'], 'cardname' => $v['cardname'], 'min' => $v['min_integral'], 'max' => $one[$k + 1]['min_integral'] ); } else { $item = array( 'id' => $v['id'], 'cardname' => $v['cardname'], 'min' => $v['min_integral'], 'max' => -1 ); } $gradeArr[] = $item; } $this->assign('gradeArr', $gradeArr); $this->display(); } } /** * 批量发放优惠券 * @param $id 优惠券id * @return array */ public function batchPutInCoupon() { $merchantid = I('session.merchant_userinfo')['merchantid']; $id = I('post.id'); $vips = I('post.vips'); if (!$id || !$vips) { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } $map['merchantid'] = $merchantid; $map['status'] = 1; // 正常优惠券 $map['id'] = $id; $map['coupon_num'] = array('gt', 0); $coupon = M('retail_mcoupon')->where($map)->find(); if (!$coupon) { $res['status'] = 0; $res['msg'] = '该优惠券无法发放'; $this->ajaxReturn($res); } $cr['mcouponid'] = $coupon['id']; $cr['needmoney'] = $coupon['needmoney']; $cr['reducemoney'] = $coupon['reducemoney']; $cr['merchantid'] = $coupon['merchantid']; $cr['canusestoreids'] = $coupon['storeids']; $cr['coupon_name'] = $coupon['coupon_name']; $cr['addtime'] = time(); if ($coupon['coupontype'] == 1) { $cr['starttime'] = $coupon['starttime']; $cr['endtime'] = $coupon['endtime']; } else if ($coupon['coupontype'] == 2) { $cr['starttime'] = time(); $cr['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + $coupon['daynum'] * 86400; } else if ($coupon['coupontype'] == 3) { $cr['starttime'] = strtotime(date('Y-m-d') . ' 23:59:59') + 1; $cr['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + ($coupon['daynum'] + 1) * 86400; } else { $res['status'] = 0; $res['msg'] = '无效的优惠券,建议失效'; $this->ajaxReturn($res); } $fisrt = "尊敬的用户,赠送您一张" . $coupon['coupon_name']; $merchanname = M('retail_merchant')->where(array('id' => $coupon['merchantid']))->getField('name'); $remark = $merchanname . '提示:优惠券在' . date('Y-m-d', $cr['starttime']) . '到' . date('Y-m-d', $cr['endtime']) . '有效期内可以使用'; foreach ($vips as $key => &$val) { if (($key + 1) > $coupon['coupon_num']) { $res['status'] = 2; $res['msg'] = '优惠券发放完毕'; $this->ajaxReturn($res); } else { // 发放 $cr['vid'] = $val['id']; $add = M('retail_vipmcoupon')->add($cr); // 添加优惠券 if ($add) { $set_dec = M('retail_mcoupon')->where(array('id' => $coupon['id']))->setDec('coupon_num', 1); if ($set_dec) { A('Vip/Mark')->launchcoupon($val['id'], $fisrt, $remark, $cr); } else { $res['status'] = 0; $res['msg'] = '发放失败,请刷新重试'; $this->ajaxReturn($res); } } else { continue; // 发放失败,继续下一个发放 } } unset($cr['vid']); unset($add); unset($set_dec); } $res['status'] = 1; $res['msg'] = '发放成功'; $this->ajaxReturn($res); } /** * 批量发放券包 * @param $id 券包id * @return $res */ public function batchPutInCouponGroup() { $merchantid = I('session.merchant_userinfo')['merchantid']; $id = I('post.id'); $vips = I('post.vips'); if (!$id || !$vips) { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } // 查询券包 $map['merchantid'] = $merchantid; $map['status'] = 1; // 正常券包 $map['id'] = $id; $map['coupon_group_num'] = array('gt', 0); $coupon_group = M('retail_mcoupon_group')->where($map)->find(); if (!$coupon_group) { $res['status'] = 0; $res['msg'] = '该券包状态异常无法发放'; $this->ajaxReturn($res); } // 查询优惠券 $time = time(); $map2['type'] = 2; $map2['mcoupon_group_id'] = $coupon_group['id']; $map2['merchantid'] = $merchantid; $map2['_string'] = "(coupontype = 1 AND endtime > {$time}) OR (coupontype = 2) OR (coupontype = 3)"; $coupons = M('retail_mcoupon')->where($map2)->order('id asc')->select(); if (!$coupons) { $res['status'] = 0; $res['msg'] = '该券包暂无可以使用的优惠券,无法发放'; $this->ajaxReturn($res); } $create['mcoupon_group_id'] = $coupon_group['id']; $create['canusestoreids'] = $coupon_group['storeids']; $create['type'] = 2; foreach ($vips as $key => &$val) { if (($key + 1) > $coupon_group['coupon_group_num']) { $res['status'] = 2; $res['msg'] = '券包发放完毕'; //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-指定投放券包';//操作行为描述 action_log($source, $type, $request_data, $desc); //end $this->ajaxReturn($res); } else { // 发放 $num = 0; foreach ($coupons as &$value) { $cr = $create; $cr['mcouponid'] = $value['id']; $cr['needmoney'] = $value['needmoney']; $cr['reducemoney'] = $value['reducemoney']; $cr['merchantid'] = $value['merchantid']; $cr['coupon_name'] = $value['coupon_name']; $cr['addtime'] = time(); $cr['vid'] = $val['id']; if ($value['coupontype'] == 1) { $cr['starttime'] = $value['starttime']; $cr['endtime'] = $value['endtime']; } else if ($value['coupontype'] == 2) { $cr['starttime'] = time(); $cr['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + $value['daynum'] * 86400; } else if ($value['coupontype'] == 3) { $cr['starttime'] = strtotime(date('Y-m-d') . ' 23:59:59') + 1; $cr['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + ($value['daynum'] + 1) * 86400; } else { continue; // 无效优惠券,继续下一个发放 } $fisrt = "尊敬的用户,赠送您一张" . $value['coupon_name']; $merchanname = M('retail_merchant')->where(array('id' => $value['merchantid']))->getField('name'); $remark = $merchanname . '提示:优惠券在' . date('Y-m-d', $cr['starttime']) . '到' . date('Y-m-d', $cr['endtime']) . '有效期内可以使用'; $add = M('retail_vipmcoupon')->add($cr); if ($add) { $num++; M('retail_mcoupon')->where(array('id' => $value['id']))->setDec('coupon_num', 1); // 优惠券减数量 A('Vip/Mark')->launchcoupon($val['id'], $fisrt, $remark, $cr); } else { continue; // 发放失败,继续下一个发放 } } if ($num > 0) { $set_dec = M('retail_mcoupon_group')->where(array('id' => $coupon_group['id']))->setDec('coupon_group_num', 1); if (!$set_dec) { $res['status'] = 0; $res['msg'] = '发放失败,请刷新重试'; $this->ajaxReturn($res); } } else { continue; // 发放失败,继续下一个发放 } } } $res['status'] = 1; $res['msg'] = '发放成功'; $this->ajaxReturn($res); } /** * 优惠券记录列表数据 * @param $map 查询条件 * @param $page * @param $limit * @param $time * @return $res */ public function getRecordList($map, $page, $limit, $time) { $record_list = M('retail_vipmcoupon')->where($map)->page($page, $limit)->order('usetime desc,addtime desc')->select(); if (!$record_list) { $res['status'] = 0; $res['msg'] = '暂无记录'; return $res; } $total = M('retail_vipmcoupon')->where($map)->count(); foreach ($record_list as &$val) { switch ($val['isuse']) { case 1: if ($time > $val['endtime']) { // 过期 $val['isuse_name'] = '已过期'; $val['use_time'] = '已过期'; $val['use_store'] = '已过期'; } else { $val['isuse_name'] = '未使用'; $val['use_time'] = '未使用'; $val['use_store'] = '未使用'; } break; case 2: $val['isuse_name'] = '已使用'; $val['use_time'] = date('Y-m-d H:i:s', $val['usetime']); $val['use_store'] = M('retail_store')->where(array('id' => $val['storeid']))->getField('storetag'); break; case 3: $val['isuse_name'] = '已过期'; $val['use_time'] = '已过期'; $val['use_store'] = '已过期'; break; default: $val['isuse_name'] = '未知优惠券'; $val['use_time'] = '未知优惠券'; $val['use_store'] = '未知优惠券'; } $vip = M('retail_vip')->where(array('id' => $val['vid']))->field('name,nickname,mobile_phone')->find(); $val['vip_name'] = $vip['name'] ? $vip['name'] : ($vip['nickname'] ? $vip['nickname'] : '未设置名称'); $val['vip_phone'] = $vip['mobile_phone']; $val['coupon_name'] = M('retail_mcoupon')->where(array('id' => $val['mcouponid']))->getField('coupon_name'); $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']); $starttime = date('Y-m-d H:i:s', $val['starttime']); $endtime = date('Y-m-d H:i:s', $val['endtime']); $val['canusetime'] = $starttime . '至' . $endtime; } $res['status'] = 1; $res['record_list'] = $record_list; $res['total'] = (int)$total; return $res; } /** * 查询优惠券充值赠送设置 * @return [array] $res */ public function getRechargeState() { $merchantid = I('session.merchant_userinfo')['merchantid']; $id = I('post.id'); if (!$id) { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } $map['id'] = $id; $map['merchantid'] = $merchantid; $map['type'] = 1; $map['status'] = 1; $recharge = M('retail_mcoupon')->field('id,recharge_state,money')->where($map)->find(); if ($recharge) { $recharge['money'] = floatval($recharge['money']); $res['status'] = 1; $res['recharge'] = $recharge; } else { $res['status'] = 0; $res['msg'] = '查询失败'; } $this->ajaxReturn($res); } /** * 查询优惠券支付赠送设置 * @return [array] $res */ public function getPayState() { $RetailMCouponModel = D("RetailMCoupon"); $merchantid = I('session.merchant_userinfo')['merchantid']; $id = I('post.id'); if (!$id) { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } $map['id'] = $id; $map['merchantid'] = $merchantid; $map['type'] = 1; $map['status'] = 1; $map['give_status'] = 3; $payment = $RetailMCouponModel->getOrderFind($map, "id,payment_money,payment_state"); if ($payment) { $payment['payment_money'] = floatval($payment['payment_money']); $res['status'] = 1; $res['payment'] = $payment; } else { $res['status'] = 0; $res['msg'] = '查询失败'; } $this->ajaxReturn($res); } /** * *****************************2020-12-12新版优惠券*********************** */ //获取所有门店和会员等级列表(该方法更新会员积分时请删除) public function getStoreListAndVipGrade() { $StoreClass = new Store(); $store_list = $StoreClass->storeListInfo([ 'merchant_id' => $this->merchant_id, 'fields' => [ 'id', 'storetag as store_name' ] ]); $VipInfoClass = new VipInfo(); $vip_grade_list = $VipInfoClass->getGradeList([ 'merchant_id' => $this->merchant_id, 'fields' => [ 'id', 'cardname as grade_name' ] ]); $res['status'] = 1; $res['store_list'] = $store_list ? $store_list : []; $res['vip_grade_list'] = $vip_grade_list ? $vip_grade_list : []; $this->ajaxReturn($res); } //保存充值赠设置 public function setRechargeState() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $CouponClass = new CouponOperation(); $result = $CouponClass->rechargeSet($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-优惠券充值设置';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //保存支付赠优惠券设置 public function setPaymentState() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $CouponClass = new CouponOperation(); $result = $CouponClass->paySet($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-优惠券支付设置';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //指定会员列表的门店与等级列表 public function getAppointList() { $data = I('post.'); $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $CouponListClass = new CouponList(); $result = $CouponListClass->getAppointList($data); $this->ajaxReturn($result); } //获取指定的会员列表 public function getStoreGradeVipInfo() { $data = I('post.'); $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $CouponListClass = new CouponList(); $result = $CouponListClass->getAppointVipList($data); $this->ajaxReturn($result); } //优惠券或券包使失效 public function couponFailure() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $CouponClass = new CouponOperation(); $result = $CouponClass->couponInvalid($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 if ($data['coupon_type'] == 1) { $desc = '插件-使失效优惠券';//操作行为描述 } else if ($data['coupon_type'] == 2) { $desc = '插件-使失效券包';//操作行为描述 } action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //批量发放优惠券或券包 public function batchGrantCoupon() { $data = I('post.'); $data['operator_type'] = 1; $data['operator_id'] = session('jurisdiction_user')['id']; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $CouponClass = new CouponOperation(); $result = $CouponClass->batchGrantCoupon($data); if (C('IS_SET_REDIS')) { if ($data['batch_type'] == 1) { //优惠券 $redis_key = 'retail_merchant_id_' . $data['merchant_id'] . '_coupon_type_2_coupon_id_' . $data['id']; } else if ($data['batch_type'] == 2) { //券包 $redis_key = 'retail_merchant_id_' . $data['merchant_id'] . '_coupon_package_id_' . $data['id']; } $CacheClass = new CacheHandle(); $CacheClass->eliminateCache($redis_key); $CacheClass->submitAffair(); } if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 if ($data['batch_type'] == 1) { $desc = '插件-发放优惠券';//操作行为描述 } else if ($data['batch_type'] == 2) { $desc = '插件-发放券包';//操作行为描述 } action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //创建券包createCouponGroup public function createCouponGroup() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 3; $data['type'] = 2; $data['merchant_id'] = $this->merchant_id; $data['operator_id'] = session('jurisdiction_user')['id']; $CouponClass = new CouponOperation(); $result = $CouponClass->createCouponPackage($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-新增券包';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //券包编辑接口editPackage public function editPackage() { $data = I('post.'); $data['user_type'] = 3; $data['operator_type'] = 1; $data['merchant_id'] = $this->merchant_id; $data['operator_id'] = session('jurisdiction_user')['id']; $CouponClass = new CouponOperation(); $result = $CouponClass->editPackage($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-编辑券包';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //券包详情couponGroupDetails public function couponGroupDetails() { $data = I('post.'); $data['merchant_id'] = $this->merchant_id; $CouponClass = new CouponList(); $result = $CouponClass->couponPackageInfo($data); $this->ajaxReturn($result); } //券包发放记录couponGroupRecordList public function couponGroupRecordList() { $data = I('post.'); $data['user_type'] = 3; $data['type'] = 2; $data['merchant_id'] = $this->merchant_id; $CouponClass = new CouponList(); $result = $CouponClass->couponGrantRecord($data); $this->ajaxReturn($result); } //券包列表 public function getCouponGroupList() { $data = I('post.'); $data['merchant_id'] = $this->merchant_id; $data['user_type'] = 3; $CouponClass = new CouponList(); $result = $CouponClass->couponPackageList($data); $this->ajaxReturn($result); } //创建优惠券createCoupon public function createCoupon() { $data = I('post.'); $data['operator_type'] = 1; $data['type'] = 1; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $data['operator_id'] = session('jurisdiction_user')['id']; $CouponClass = new CouponOperation(); $result = $CouponClass->createCoupon($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-新增优惠券';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //编辑优惠券editCoupon public function editCoupon() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $data['operator_id'] = session('jurisdiction_user')['id']; $CouponClass = new CouponOperation(); $result = $CouponClass->editCoupon($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-编辑优惠券';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //优惠券详情couponInfo public function couponInfo() { $data = I('post.'); $CouponClass = new CouponList(); $result = $CouponClass->couponInfo($data); $this->ajaxReturn($result); } //优惠券发放记录couponRecordList public function couponRecordList() { $data = I('post.'); $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $data['type'] = 1; $CouponClass = new CouponList(); $result = $CouponClass->couponGrantRecord($data); $this->ajaxReturn($result); } //优惠券列表 public function getCouponList() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $CouponClass = new CouponList(); $result = $CouponClass->couponList($data); $this->ajaxReturn($result); } //指定分类查看商品详情basisClassGetGoods public function basisClassGetGoods() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $SaleClass = new SaleGoods(); $result = $SaleClass->basisClassIdGetGoods($data); $this->ajaxReturn($result); } //指定的分类列表 public function appointGoodsClass() { $data = I('post.'); $data['operator_type'] = 1; $data['merchant_id'] = $this->merchant_id; $data['user_type'] = 3; $GoodsClassify = new GoodsClassify(); $result = $GoodsClassify->classList($data); $this->ajaxReturn($result); } //指定商品appointGoods public function appointGoods() { $data = I('post.'); $data['operator_type'] = 1; $data['merchant_id'] = $this->merchant_id; $data['user_type'] = 4; $SaleClass = new SaleGoods(); $result = $SaleClass->getGoodsList($data); $this->ajaxReturn($result); } }