find(); $config = getManagerConf(); $this->assign('basiclist', $config); $timeconf = get_config(ROOT_PATH . '/application/timer/timeconfig.php', 'handshoptime', 'int'); $this->assign('timeconf', $timeconf); return $this->fetch(); } //保存 public function handle() { $data = I('post.'); //$r = M('manager_config')->where('id',1)->save($data); $r = getManagerConf($data); if ($r) { $this->success('操作成功', U('Manager/System/basic')); } else { $this->error("操作失败", U('Manager/System/basic')); } } public function otherset() { return $this->fetch(); } public function otherset_hand() { $info_role = M('role')->where('role_id', 190)->find(); if ($info_role) { $sql = "update wxd_role set act_list='" . $info_role['act_list'] . "' WHERE (`role_name` IN ('超级用户','管理员') )"; Db::execute($sql); $this->success('操作成功', U('Manager/System/otherset')); } } public function weappbasic() { $config = getManagerConf(); $this->assign('basiclist', $config); return $this->fetch(); } public function weappbasic_hand() { $data = I('post.'); $r = getManagerConf($data); if ($r) { $this->success('操作成功', U('Manager/System/weappbasic')); } else { $this->error("操作失败", U('Manager/System/weappbasic')); } } public function settimeconfig() { $state = I("status"); if ($state == 1) { update_config(ROOT_PATH . '/application/timer/timeconfig.php', 'handshoptime', 1, 'int'); //$mytask = new mytask(); //$mytask->start(); } else { update_config(ROOT_PATH . '/application/timer/timeconfig.php', 'handshoptime', 0, 'int'); } return json(['code' => 1, 'msg' => '修改成功']); } public function unbinduser() { $isajax = I('isajax'); $getstoid = I('stoid'); $storelist = M('store')->where('is_audit', 1)->field('store_id,ERPId,store_name')->order('ERPId')->select(); if ($isajax) { $stoid = I('store_id'); $mobile = I('mobile'); $mobarr = explode(",", $mobile); foreach ($mobarr as $k => $v) { $mobarr[$k] = trim($v); } $saved = [ 'mobile' => NULL, 'erpvipid' => NULL, 'erpvipno' => NULL, 'first_leader' => 0, 'second_leader' => 0, 'third_leader' => 0, 'is_distribut' => 0, 'underling_number' => 0, 'is_mzvip' => 0, 'mzvip_remark' => NULL ]; $ud = M("users")->where('store_id', $stoid)->where('mobile', 'in', $mobarr)->field('user_id')->select(); $rs = M("users")->where('store_id', $stoid)->where('mobile', 'in', $mobarr)->save($saved); if ($rs) { $idarr = []; foreach ($ud as $k1 => $v1) { $idarr[] = $v1['user_id']; } M("users")->where('store_id', $stoid)->where('first_leader', 'in', $idarr)->save(['first_leader' => 0]); M("users")->where('store_id', $stoid)->where('second_leader', 'in', $idarr)->save(['second_leader' => 0]); M("users")->where('store_id', $stoid)->where('third_leader', 'in', $idarr)->save(['third_leader' => 0]); $this->success('操作成功', U('System/unbinduser', array('stoid' => $stoid))); } else $this->success('操作失败', U('System/unbinduser', array('stoid' => $stoid))); } $this->assign('storelist', $storelist); $this->assign('getstoid', $getstoid); return $this->fetch(); } public function store_newsale() { $isajax = I('isajax'); $getstoid = I('stoid'); $storelist = M('store')->where('is_audit', 1)->field('store_id,ERPId,store_name')->order('ERPId')->select(); if ($isajax) { $stoid = I('store_id'); $is_newsales_rules = I('is_newsales_rules/d', 0); $store_config = M('store_config')->where(array('store_id' => $stoid))->find(); if (empty($store_config)) { $this->error("操作失败", U('Manager/System/store_newsale')); } $switch_list = $store_config["switch_list"]; $switch_list = json_decode($switch_list, true); foreach ($switch_list as $k => $v) { $newArr[$k] = trim($v); } $newArr["is_newsales_rules"] = $is_newsales_rules; $updatadata['switch_list'] = json_encode($newArr); M('store_config')->where(array('store_id' => $stoid))->save($updatadata); ClearALLCache(); delFile(TEMP_PATH . "/" . getAdmStoId()); $this->success('操作成功', U('Manager/System/store_newsale')); } $this->assign('storelist', $storelist); $this->assign('getstoid', $getstoid); return $this->fetch(); } //----解绑等级会员---- public function unbind_dengji() { $isajax = I('is_ajax'); if ($isajax) { $erpid = I("erpid"); $moblie = I("mobile"); $store = M("store")->where('ERPId', $erpid)->field('store_id')->find(); if (empty($store)) { $this->error('未找到门店', U('System/unbind_dengji')); exit; } $user = M("users")->where('mobile', $moblie)->where('store_id', $store['store_id'])->find(); if (empty($user)) { $this->error('未找到会员', U('System/unbind_dengji')); exit; } if (empty($user['card_field'])) { $this->error('该会员不是等级会员', U('System/unbind_dengji')); exit; } $sconfig = M("store_config")->where('store_id', $store['store_id'])->field('dj_num')->find(); if (empty($sconfig['dj_num'])) { $this->error('等级会员数量已经为0', U('System/unbind_dengji')); exit; } $data['VIPId'] = urlencode($user['erpvipid']); $rr = getApiData_java_p("/api/erp/vip/mem/referee/remove", $erpid, $data, null, null, null, "GET"); $rr = json_decode($rr, true); if ($rr['code'] === 0) { M('users')->where('user_id', $user['user_id'])->where('store_id', $store['store_id']) ->save(['card_field' => '', 'card_expiredate' => '']); //M("store_config")->where('store_id',$store['store_id'])->setDec('dj_num'); //默认初始话那里也有要清理掉 if ($sconfig['fir_yaoqing_no'] == $moblie) { M("store_config")->where('store_id', $store['store_id'])->save(['fir_yaoqing_no' => '']); } //调用接口 $this->success('操作成功', U('System/unbind_dengji')); exit; } $this->error('操作失败', U('System/unbind_dengji')); exit; } return $this->fetch(); } public function show_redis() { return $this->fetch(); } public function re_orderpt() { $isajax = I('is_ajax'); if ($isajax) { $erpid = I("erpid"); $ordersn = I("ordersn"); $store = M("store")->where('ERPId', $erpid)->field('store_id')->find(); if (empty($store)) { $this->error('未找到门店', U('System/re_orderpt')); exit; } $order = M("order")->where('order_sn', $ordersn)->where('store_id', $store['store_id'])->find(); if (empty($order)) { $this->error('未找到订单', U('System/re_orderpt')); exit; } disoucponpt($order); $this->success('操作成功', U('System/re_orderpt')); exit; } return $this->fetch(); } //显示商家的redis public function ajax_show_redis() { $erpid = I("erpid"); $sear_type = I("sear_type"); $now = time(); $redis = get_redis_handle(); //获取门店 $sto = M("store")->where("ERPId", $erpid)->field("store_id")->find(); $flash_list = M("flash_sale")->where("store_id", $sto['store_id']) ->where("is_end", 0) ->where("end_time>" . $now) ->select(); $group_list = M("group_buy")->where("store_id", $sto['store_id']) ->where("is_end", 0) ->where("end_time>" . $now) ->select(); $pt_list = M("teamlist")->where("store_id", $sto['store_id']) ->where("is_end", 0) ->where("end_time>" . $now) ->select(); $zl_list = M("marketing_help_form")->where("store_id", $sto['store_id']) ->where("isdel", 0) ->where("enddate>" . $now) ->select(); //更换换后 if ($sear_type == 1) { $this->set_change_after($flash_list, $group_list, $pt_list,$zl_list,$redis); } else { $this->set_change_before($flash_list, $group_list, $pt_list, $redis); } return $this->fetch(); } //映射设置之后的redis数量 public function set_change_after($flash_list, $group_list, $pt_list,$zl_list, $redis) { if ($flash_list) { foreach ($flash_list as $k => $v) { $name = get_redis_name($v['id'], 1, $v['store_id']); $len = $redis->lLen($name); $flash_list[$k]['redis_len'] = $len; } $this->assign("flash_list", $flash_list); } if ($group_list) { foreach ($group_list as $kk => $vk) { $name = get_redis_name($vk['id'], 2, $vk['store_id']); $len = $redis->lLen($name); $group_list[$kk]['redis_len'] = $len; } $this->assign("group_list", $group_list); } if ($pt_list) { foreach ($pt_list as $kl => $vl) { $name = get_redis_name($vl['id'], 6, $vl['store_id']); $len = $redis->lLen($name); $pt_list[$kl]['redis_len'] = $len; if ($vl['kttype'] == 2) { //正在进行中的团 $teamg = M("teamgroup")->where("team_id", $vl['id']) ->where("state", 2) ->select(); if ($teamg) { //把团的组织一下 foreach ($teamg as $km => $vm) { $name_t = $name . ":" . $vm['listno']; $len = $redis->lLen($name_t); $teamg[$km]['redis_len'] = $len; } $pt_list[$kl]['teamgroup'] = $teamg; } } } $this->assign("pt_list", $pt_list); } if($zl_list){ foreach ($zl_list as $kh => $vh) { $h_list=M("marketing_help_list")->where("help_id",$vh['id'])->select(); foreach ($h_list as $ku=>$vu){ $name = get_redis_name($vu['id'], 7, $vu['store_id']); $len = $redis->lLen($name); $h_list[$ku]['redis_len']=$len; } $zl_list[$kh]['list']=$h_list; } $this->assign("zl_list", $zl_list); } } //映射设置之钱的redis数量 public function set_change_before($flash_list, $group_list, $pt_list, $redis) { if ($flash_list) { foreach ($flash_list as $k => $v) { $name = 'ms' . $v['id'] . '-' . $v['store_id']; $len = $redis->lLen($name); $flash_list[$k]['redis_len'] = $len; } $this->assign("flash_list", $flash_list); } if ($group_list) { foreach ($group_list as $kk => $vk) { $name = 'grb' . $vk['id'] . '-' . $vk['store_id']; $len = $redis->lLen($name); $group_list[$kk]['redis_len'] = $len; } $this->assign("group_list", $group_list); } if ($pt_list) { foreach ($pt_list as $kl => $vl) { $name = 'pind' . $vl['id'] . '-' . $vl['store_id']; $len = $redis->lLen($name); $pt_list[$kl]['redis_len'] = $len; if ($vl['kttype'] == 2) { //正在进行中的团 $teamg = M("teamgroup")->where("team_id", $vl['id']) ->where("state", 2) ->select(); if ($teamg) { //把团的组织一下 foreach ($teamg as $km => $vm) { $name2 = 'pind' . $vl['id'] . '-' . $vm['listno'] . $vl['store_id']; $len = $redis->lLen($name2); $teamg[$km]['redis_len'] = $len; } $pt_list[$kl]['teamgroup'] = $teamg; } } } $this->assign("pt_list", $pt_list); } } //--处理api,列表-- public function re_deal_api() { $pagenum = I("pagenum", 10); $where = "1=1"; $erpid = I("erpid"); $keywords = I("keywords"); if ($erpid) $where .= " and erpid='" . $erpid . "'"; if ($keywords) $where .= " and api like %'" . $erpid . "'%'"; $store = M("store")->where('is_audit', 1)->select(); $this->assign('storelist', $store); $count = M("api_err")->where($where)->count(); $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数 $rs = M("api_err")->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select(); $show = $Page->show();// 分页显示输出 $this->assign('list', $rs);// 赋值数据集 $this->assign('page', $show);// 赋值分页输出 $this->assign('pager', $pager); return $this->fetch(); } //--处理api-- public function deal_api() { $id = I("id"); $data = M("api_err")->where("id", $id)->find(); if (empty($data)) return json(['code' => -1, 'msg' => '未找到数据']); $p_data = json_decode($data['data']); $rs = getApiData_java_p($data['api'], $data['erpid'], $p_data, 1, 10, null, "POST"); if (empty($rs)) return json(['code' => -1, 'msg' => '处理失败']); $rs_data = json_decode($rs, true); if ($rs_data['code'] != 0) return json(['code' => -1, 'msg' => $rs_data[msg]]); M("api_err")->where("id", $id)->save(['is_deal' => 1]); return json(['code' => 0, 'msg' => '处理成功']); } //--重新注册等级-- public function re_chuce_dj() { $is_ajax = I("is_ajax"); if ($is_ajax) { $data = I("data"); $date = I("date"); $accdb = I("accdb"); $data = json_decode($data, true); if (!is_array($data)) $this->success("补卡失败,补卡数据错误", U('System/re_chuce_dj')); $store = M("store")->where("ERPId", $accdb)->find(); if (!$store) $this->success("补卡失败,未找到商家", U('System/re_chuce_dj')); $data['RegisterDate'] = $date; $api = "/api/erp/vip/mem/card/register"; $mrs = getApiData_java_p($api, $accdb, $data, 1, 10, null, "POST"); $mrs = json_decode($mrs, true); if ($mrs['code'] == 0) { $this->success("补卡成功", U('System/re_chuce_dj')); exit(); } $this->success("补卡失败", U('System/re_chuce_dj')); } return $this->fetch(); } //--补发代金券-- public function re_sendcoupon() { $is_ajax = I("is_ajax"); if ($is_ajax) { $stoid = I('stoid/d', 0); $couponid = I('couponid/d', 0); if (empty($stoid) || empty($couponid)) { $this->error("补卡失败,参数有误"); } $storeinfo = M('store')->where(array('store_id' => $stoid))->find(); if (empty($storeinfo)) { $this->error("补卡失败,没有该商家"); } $sto_erpid = $storeinfo['ERPId']; $coupon = M("coupon")->where(array("id" => $couponid, 'send_start_time' => array('elt', time()), 'send_end_time' => array('egt', time())))->find(); if (empty($coupon)) { $this->error("补卡失败,没有代金券或代金券发放时间未开始或已结束"); } $userlist = Db::query("select a.user_id,a.mobile,a.weapp_openid,b.id,b.cid,FROM_UNIXTIME(reg_time),a.erpvipid,a.erpvipno from wxd_users a left join wxd_coupon_list b on a.user_id=b.uid and b.type=2 and b.remark='注册发放' where a.store_id=" . $stoid . " and a.reg_time>" . $coupon['add_time'] . " and a.reg_time>1570694939 and a.mobile<>'' and a.erpvipid<>'' and b.id is null order by reg_time desc"); if (empty($userlist)) { $this->error("补卡失败,没有记录可补发"); } foreach ($userlist as $k => $value) { $this->reg_send_quan($coupon, $value, $sto_erpid, $stoid); } $this->success('补发成功', U('System/re_sendcoupon')); } return $this->fetch(); } public function reg_send_quan($coupon, $user_info, $sto_erpid, $stoid, $t = 0) { $first_info = $user_info; if ($coupon["send_end_time"] > time()) { $CashRepNo = "1005" . date("ymdHis") . get_total_millisecond(); if ($sto_erpid) { $data = array( 'CashRepNo' => $CashRepNo,//券号 'VIPId' => $first_info["erpvipid"],//会员id 'Sum' => $coupon["money"],//金额 'SendMan' => '注册发放',//发放类型 'Operator' => '微信商城',//来源 'BuySum' => $coupon["condition"],//满多少才能使用 'Remark' => '注册送微券【消费满' . $coupon["condition"] . '元可用】', ); if ($t == 1) { $data['Remark'] = '邀请送微券【消费满' . $coupon["condition"] . '元可用】'; $data['SendMan'] = '邀请发放'; } if ($coupon['useobjecttype']) { $data['UseObjectType'] = $coupon['useobjecttype']; $data['UseObjectID'] = $coupon['useobjectid']; $data['UseObjectNo'] = $coupon['useobjectno']; $data['UseObjectName'] = $coupon['useobjectname']; } //如果有设置有效期 if ($coupon['endtype'] == 1) { $data['BeginDate'] = date('Y-m-d');//使用开始日期 if ($coupon['days'] > 0) { $ed = strtotime("+" . $coupon['days'] . " day"); $data['ValidDate'] = date('Y-m-d', $ed);//截止期限 } } else { if ($coupon["use_start_time"] != "") { $data['BeginDate'] = date('Y-m-d', $coupon["use_start_time"]);//使用开始日期 } if ($coupon["use_end_time"] != "") { $data['ValidDate'] = date('Y-m-d', $coupon["use_end_time"]);//截止期限 } } $erp = tpCache("shop_info.ERPId", $stoid); $add_rs = getApiData_java_p("/api/erp/vip/cash/insert", $erp, $data, null, null, null, "POST"); if ($add_rs) { $add_rs = json_decode($add_rs, true); if ($add_rs['code'] == 0) { //插入线上优惠券领取表 $coupon_list['cid'] = $coupon['id']; $coupon_list['type'] = 2; $coupon_list['uid'] = $first_info['user_id']; $coupon_list['send_time'] = time(); $coupon_list['code'] = $CashRepNo; $coupon_list['store_id'] = getMobileStoId(); $coupon_list['code'] = time(); if ($coupon['endtype'] == 1) { $coupon_list['begintime'] = time(); if ($coupon['days'] > 0) $coupon_list['validtime'] = strtotime("+" . $coupon['days'] . " day"); else $coupon_list['validtime'] = 0; } else { $coupon_list['begintime'] = $coupon["use_start_time"]; $coupon_list['validtime'] = $coupon["use_end_time"]; } $coupon_list['sum'] = $coupon["money"]; $coupon_list['buysum'] = $coupon["condition"]; $coupon_list['remark'] = "注册发放"; if ($t == 1) $coupon_list['remark'] = "邀请发放"; $add_couponinfo = add_coupon($coupon_list, $first_info, $stoid); } } } } } //清除缓存 public function clearredis() { $is_ajax = I("is_ajax"); if ($is_ajax) { $erpid = I('erpid'); if ($erpid) { $where1['ERPId'] = $erpid; } $store = M('store')->where($where1)->select(); if (empty($store)) { $this->error("没有该商家"); } foreach ($store as $k => $v) { $name = 'weshop:PROD:erp:newToken:' . strtolower($store['ERPId']); Cache::rm($name); $accdb = strtolower($v['ERPId']); $wxdtoken_access_data = cache_new("common", "wxderp", "wxdtoken_access_data:" . $accdb); $wxdtoken_access_time = cache_new("common", "wxderp", "wxdtoken_access_time:" . $accdb); cache_new("common", "wxderp", "wxdtoken_access_data:" . $accdb, ''); cache_new("common", "wxderp", "wxdtoken_access_time:" . $accdb, 11); } $this->success('清除成功', U('System/clearredis')); } return $this->fetch(); } //公众号迁移 public function openidmove() { $is_ajax = I("is_ajax"); if ($is_ajax) { $stoid = I('stoid/d', 0); $from_appid = I('from_appid'); $old_kt = I('old_kt'); if (empty($stoid) || empty($from_appid) || empty($old_kt)) { $this->error("提交失败,参数有误"); } $page = 1; $pagenum = 200; switch ($is_ajax) { case "1": $count = M('users')->where(array('store_id' => $stoid, 'openid' => array('like', '' . $old_kt . '%')))->count(); if (empty($count)) { $this->error("提交失败,找不到相关记录"); } $Page = new Page($count, $pagenum); for ($i = 0; $i < $Page->totalPages; $i++) { $userinfo = M('users')->where(array('store_id' => $stoid, 'openid' => array('like', '' . $old_kt . '%'))) ->field('openid') ->limit($Page->firstRow . ',' . $Page->listRows)->select(); $newopenlist = array(); if ($userinfo) { foreach ($userinfo as $k => $v) { $newopenlist[] = $v['openid']; } } $this->weixin_config = M('wx_user')->where('store_id=' . $stoid)->find(); //获取微信配置 $access_token2 = m_get_access_token($this->weixin_config); $url = "http://api.weixin.qq.com/cgi-bin/changeopenid?access_token=" . $access_token2; $postdata['from_appid'] = $from_appid; $postdata['openid_list'] = $newopenlist; $list = httpRequest($url, 'POST', json_encode($postdata)); if ($list) { $list = json_decode($list, true); if ($list['result_list']) { foreach ($list['result_list'] as $k => $v) { if ($v['err_msg'] == 'ok') { $updatadata['openid'] = $v['new_openid']; M('users')->where(array('store_id' => $stoid, 'openid' => $v['ori_openid']))->update($updatadata); } } } } } break; case "2": $count = M('wx_openlist')->where(array('store_id' => $stoid, 'wxopenid' => array('like', '' . $old_kt . '%')))->count(); if (empty($count)) { $this->error("提交失败,找不到相关记录"); } $Page = new Page($count, $pagenum); for ($i = 0; $i < $Page->totalPages; $i++) { $userinfo = M('wx_openlist')->where(array('store_id' => $stoid, 'wxopenid' => array('like', '' . $old_kt . '%'))) ->field('wxopenid') ->limit($Page->firstRow . ',' . $Page->listRows)->select(); $newopenlist = array(); if ($userinfo) { foreach ($userinfo as $k => $v) { $newopenlist[] = $v['wxopenid']; } } $weixin_config = M('wx_user')->where('store_id=' . $stoid)->find(); //获取微信配置 $access_token2 = m_get_access_token($weixin_config); $url = "http://api.weixin.qq.com/cgi-bin/changeopenid?access_token=" . $access_token2; $postdata['from_appid'] = $from_appid; $postdata['openid_list'] = $newopenlist; $list = httpRequest($url, 'POST', json_encode($postdata)); if ($list) { $list = json_decode($list, true); if ($list['result_list']) { foreach ($list['result_list'] as $k => $v) { if ($v['err_msg'] == 'ok') { $updatadata['wxopenid'] = $v['new_openid']; M('wx_openlist')->where(array('store_id' => $stoid, 'wxopenid' => $v['ori_openid']))->update($updatadata); } else { M('wx_openlist')->where(array('store_id' => $stoid, 'wxopenid' => $v['ori_openid']))->delete(); } } } } } break; } $this->success('解绑成功' . $is_ajax, U('System/openidmove')); } return $this->fetch(); } //替换生成二维码 public function resetqrcode() { $is_ajax = I("is_ajax"); if ($is_ajax) { $stoid = I('stoid/d', 0); if (empty($stoid)) { $this->error("提交失败,参数有误"); } $page = 1; $pagenum = 100; //,'date'=>array('lt',strtotime("-1 hour")) $date=I('date'); if ($date) { $where['date']=array('lt',$date); } $count = M('wx_ewmlist')->where(array('store_id' => $stoid))->where($where)->count(); if (empty($count)) { $this->error("提交失败,找不到相关记录"); } $Page = new Page($count, $pagenum); $weixin_config = M('wx_user')->where(array('store_id' => $stoid))->find(); //获取微信配置 $access_token2 = m_get_access_token($weixin_config); for ($i = 0; $i < $Page->totalPages; $i++) { $userinfo = M('wx_ewmlist')->where(array('store_id' => $stoid)) ->where($where) ->limit($Page->firstRow . ',' . $Page->listRows)->select(); $newopenlist = array(); if ($userinfo) { foreach ($userinfo as $k => $v) { if (empty($v['scene_id'])) { $scene_id = ''; } else { $scene_id = $v['scene_id']; } //获取数据的地址(微信提供) $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" . $access_token2; //发送给微信服务器的数据 if ($scene_id) { $jsonstr = '{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "' . $scene_id . '"}}}'; } else { $jsonstr = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": "' . $scene_id . '"}}}'; } $return = httpRequest($url, 'POST', $jsonstr); $return = json_decode($return, 1); if ($return['ticket']) { $updatedata['ticket'] = $return['ticket']; $updatedata['date'] = time(); $updatedata['loadurl'] = $return['url']; $updateres = M('wx_ewmlist')->where(array('id' => $v['id']))->save($updatedata); } } } } $this->success('生成成功', U('System/resetqrcode')); } return $this->fetch(); } //补发礼包 public function buylibao() { $is_ajax = I("is_ajax"); if ($is_ajax) { $userid = I('userid/d', 0); $storeid = I('stoid/d', 0); $lbid = I('lbid'); $lbnumber = I('lbnumber'); if (empty($userid) || empty($storeid) || empty($lbid) || empty($lbnumber)) { $this->error("提交失败,参数有误"); } $libao_list = M('libao_formvip')->where(array('store_id' => $storeid, 'number' => $lbnumber))->find(); if ($libao_list) { $this->error("提交失败,该订单已存在"); exit(); } $libao = M('libao_form')->where('store_id=' . $storeid . ' and startime<=' . time() . ' and endtime>=' . time() . ' and id=' . $lbid)->select(); if (empty($libao)) { $this->error("提交失败,找不到礼包 "); } $data['user_id'] = $userid; $data['store_id'] = $storeid; $data['lbid'] = $lbid; $data['expdate'] = strtotime('+' . $libao[0]['expday'] . ' day', time()); $data['number'] = $lbnumber; $data['paytype'] = 1; $data['fbillstate'] = 1; $data['add_time'] = time(); $uselbid = M('libao_formvip')->add($data); $list = M('libao_list')->where(array('store_id' => $storeid, 'lbid' => $lbid))->select(); if ($list) { for ($i = 0; $i < count($list); $i++) { if ($libao[0]['lbtype'] == 2)//如果是礼券的话,一个数量生成一条记录 { for ($k = 0; $k < $list[$i]['goods_num']; $k++) { unset($data); $data['user_id'] = $userid; $data['store_id'] = $storeid; $data['lbvipid'] = $uselbid; $data['goods_num'] = 1; $data['goods_name'] = $list[$i]['cpid']; $data['goods_sn'] = $list[$i]['goods_sn']; $data['lb_state'] = $list[$i]['state']; M('libao_listvip')->add($data); } } else { unset($data); $data['user_id'] = $userid; $data['store_id'] = $storeid; $data['lbvipid'] = $uselbid; $data['goods_num'] = $list[$i]['goods_num']; $data['goods_name'] = $libao[0]['lbtype'] == 1 ? $list[$i]['goods_name'] : $list[$i]['cpid']; $data['goods_sn'] = $list[$i]['goods_sn']; $data['lb_state'] = $list[$i]['state']; M('libao_listvip')->add($data); } } } DB::execute("update wxd_libao_form set salenum=salenum+1 where store_id=" . $storeid . " and id=" . $lbid . ""); $this->success('生成成功', U('System/buylibao')); } return $this->fetch(); } //更新订单 public function updateorder() { $is_ajax = I("is_ajax"); if ($is_ajax) { $order_id = I('order_id/d', 0); $storeid = I('stoid/d', 0); if (empty($order_id) || empty($storeid)) { $this->error("提交失败,参数有误"); } $libao_list = M('order')->where(array('store_id' => $storeid, 'order_id' => $order_id,'order_status'=>3,'pay_status'=>0))->find(); if (empty($libao_list)) { $this->error("提交失败,该订单不存在"); exit(); } $updatedata['order_status'] = 1; $updatedata['pay_status'] = 1; $list = M('order')->where(array('store_id' => $storeid, 'order_id' => $order_id))->save($updatedata); if ($list) { M('order_action')->where(array('store_id' => $storeid, 'order_id' => $order_id,'action_note'=>'购扣积分失败取消订单'))->delete(); } $this->success('生成成功', U('System/updateorder')); } return $this->fetch(); } }