display(); } // 商城订单信息 public function ordermsg() { $store_id = session('storeid'); $w['b.store_id'] = $store_id; $w['b.type'] = 1; //商城出售 $w['b.pay_state'] = 1; $w['b.pay_type'] = array('in', '5,6,8'); $w['b.order_type'] = 1; $time = I('post.time'); if (!empty($time)) { if ($time[0] && $time[1]) { $start_time = strtotime($time[0]); $end_time = strtotime($time[1]); $w['b.add_time'] = array('between', array($start_time, $end_time)); } else if ($time[0] && !$time[1]) { $start_time = strtotime($time[0]); $w['b.add_time'] = ['gt', $start_time]; } else if (!$time[0] && $time[1]) { $end_time = strtotime($time[1]); $w['b.add_time'] = ['lt', $end_time]; } } $type = I('post.type'); if (!empty($type)) { $w['o.order_genre'] = $type; } //单号 $title = I('post.title'); if (!empty($title)) { $w['b.order_no'] = $title; } $card = I('post.card'); //会员卡号 if (I('post.user_type') == 1) { $w['b.vid'] = array('gt', 0); } else if (I('post.user_type') == 2) { $w['b.vid'] = array(array('exp', 'IS NULL'), 0, 'OR'); } if (!empty($card)) { $w['v.mobile_phone|v.card_key|v.cardnum'] = array('like', '%' . $card . '%'); } $pay = I('post.pay'); //付款方式 if (!empty($pay)) { $w['b.pay_type'] = $pay; } $postOne = I('post.'); if (isset($postOne['status']) && $postOne['status'] !== '') { //ls_retail_bill_online -> status 1未发货 2已发货 3已收货 (自提没有类型2) if ($postOne['status'] == 4) { //待自提 $w['o.pickup_type'] = 1; $w['o.status'] = 1; } else if ($postOne['status'] == 5) { //已自提 $w['o.pickup_type'] = 1; $w['o.status'] = 3; } else { $w['o.pickup_type'] = array('in', '2,3'); $w['o.status'] = $postOne['status']; } $w['b.refund_status'] = 0;//订单类型 0正常买单 } if (isset($postOne['pickupType']) && $postOne['pickupType'] !== '') { //ls_retail_bill_online -> pickup_type 是否需要配送 1:自提 2:配送 3快递发货 $w['o.pickup_type'] = $postOne['pickupType']; $w['b.refund_status'] = 0;//订单类型 0正常买单 1申请退款或换货 2退款换货成功 3换货中、待用户发货 4用户已发货、待商家收货 5商家已收货、待商家发货或退款 6驳回退款或换货 7取消退款换货 } $page = I('post.page'); $limit = I('post.limit'); $count = M('retail_bill_order as b') ->join('ls_retail_bill_online as o on b.id=o.bill_id') ->join('ls_retail_bill_discount as d on b.id=d.bill_id') ->join('ls_retail_vip as v on b.vid=v.id', 'LEFT') ->where($w) ->count(); $orderList = M('retail_bill_order as b') ->join('ls_retail_bill_online as o on b.id=o.bill_id') ->join('ls_retail_bill_discount as d on b.id=d.bill_id') ->join('ls_retail_vip as v on b.vid=v.id', 'LEFT') ->page($page, $limit) ->field('b.*,o.*,o.user_name,d.*,v.mobile_phone as vip_phone,v.name as vip_name') ->where($w) ->order('b.add_time desc') ->select(); //优惠券名称 $coupon_name = [ '门店优惠券:', '会员优惠券:', '微信商家券:', ]; foreach ($orderList as &$v) { $v['addtime'] = date('Y-m-d H:i:s', $v['add_time']); $v['user_select_time'] = $v['user_select_time'] ? date('Y-m-d H:i:s', $v['user_select_time']) : '-'; //支付方式 if ($v['pay_type'] == 1) { $v['payname'] = '现金'; } else if ($v['pay_type'] == 2) { $v['payname'] = '银行卡'; } else if ($v['pay_type'] == 3) { $v['payname'] = '微信支付'; } else if ($v['pay_type'] == 4) { $v['payname'] = '支付宝支付'; } else if ($v['pay_type'] == 5) { $v['payname'] = '会员卡支付'; } else if ($v['pay_type'] == 6) { $v['payname'] = '小程序微信支付'; } else if ($v['pay_type'] == 7) { $v['payname'] = '其他支付'; } else if ($v['pay_type'] == 8) { $v['payname'] = '组合支付'; } else { $v['payname'] = '未支付'; } $v['isneedsend_name'] = $v['pickup_type'] == 2 ? '配送' : ($v['pickup_type'] == 3 ? '快递' : '自取'); switch ($v['status']) { case 1: //正常买单 if ($v['refund_status'] == 0) { //自提 if ($v['pickup_type'] == 1) { $v['have_away'] = '待自提'; } else if ($v['pickup_type'] == 2) { $v['have_away'] = '待配送'; } else if ($v['pickup_type'] == 3) { $v['have_away'] = '待发货'; } } else if ($v['refund_status'] == 1) { //申请退款 $v['have_away'] = '已完成'; } break; case 2: //已发货 $v['have_away'] = '配送中'; break; case 3: $v['have_away'] = '已完成'; break; } $v['coupon_money'] = $v['coupon_money'] > 0 ? $coupon_name[$v['coupon_type'] - 1] . floatval($v['coupon_money']) : ''; $v['pay_coupon_fee'] = $v['pay_coupon_fee'] > 0 ? '微信代金券:' . floatval($v['pay_coupon_fee']) : ''; if (empty($v['coupon_money']) && empty($v['pay_coupon_fee'])) { $v['reduction'] = 1; } else { $v['reduction'] = 2; } } $plugClass = new Plug(); //订单获取祝福码,判断该门店是否,有,并且开启 $storePlugStatusPost = [ 'store_id' => $store_id, 'identification_arr' => ['blessing'], ]; $storePlugStatus = $plugClass->plugStoreStatus($storePlugStatusPost);//获取状态 if ($storePlugStatus === true) { //有权限 $rt['jurisdiction_blessing'] = 1; } else { //无权限 $rt['jurisdiction_blessing'] = 2; } $rt['code'] = 0; $rt['msg'] = ''; $rt['count'] = $count; $rt['data'] = $orderList; $this->ajaxReturn($rt); } //商城总销售额 public function shopvolume() { $RetailVipModel = new RetailVipModel(); $RetailStoreModel = new RetailStoreModel(); $BillOrderModel = new RetailBillOrderModel(); $store_id = session('storeid'); $time = I('post.time'); $order_id = I('post.title'); $card = I('post.card'); $order_type = I('post.order_type'); $where['b.order_type'] = 1; $where['o.order_genre'] = 1; if (!empty($time)) { //时间 $start_time = strtotime($time[0]); $end_time = strtotime($time[1]); $where['b.add_time'] = ['between', [$start_time, $end_time]]; } if (!empty($order_id)) { $where['b.order_no'] = $order_id; } if (!empty($card)) { $merchant_id = $RetailStoreModel->getFindField(['id' => $store_id], 'merchantid'); $vip_id = $RetailVipModel->getFindField(['merchantid' => $merchant_id, 'mobile_phone' => $card], 'id'); $where['b.vid'] = $vip_id; } $where['b.pay_type'] = I('post.pay') ? I('post.pay') : ['neq', 0]; $where['b.store_id'] = $store_id; $where['b.pay_state'] = 1; $where['b.type'] = 1; $postOne = I('post.'); if (isset($postOne['status']) && $postOne['status'] !== '') { //ls_retail_bill_online -> status 1未发货 2已发货 3已收货 (自提没有类型2) if ($postOne['status'] == 4) { //待自提 $where['o.pickup_type'] = 1; $where['o.status'] = 1; } else if ($postOne['status'] == 5) { //已自提 $where['o.pickup_type'] = 1; $where['o.status'] = 3; } else { $where['o.pickup_type'] = array('in', '2,3'); $where['o.status'] = $postOne['status']; } $where['b.refund_status'] = 0;//订单类型 0正常买单 } if (isset($postOne['pickupType']) && $postOne['pickupType'] !== '') { //ls_retail_bill_online -> pickup_type 是否需要配送 1:自提 2:配送 3快递发货 $where['o.pickup_type'] = $postOne['pickupType']; $where['b.refund_status'] = 0;//订单类型 0正常买单 } $whereRoutine['b.order_type'] = 1; $whereRoutine['o.order_genre'] = 1; $whereRoutine['b.pay_type'] = ['neq', 0]; $whereRoutine['b.store_id'] = $store_id; $whereRoutine['b.pay_state'] = 1; $whereRoutine['b.type'] = 1; $whereRoutine['o.status'] = 1; $whereRoutine['b.refund_status'] = 0;//订单类型 0正常买单 //是否需要配送 pickup_type 1:自提 2:配送 3快递发货 $whereOne = [ 'o.pickup_type' => 1, $whereRoutine, ]; $whereTwo = [ 'o.pickup_type' => 2, $whereRoutine, ]; $whereThree = [ 'o.pickup_type' => 3, $whereRoutine, ]; $pickup_type_one = $BillOrderModel->backMoneyCount($whereOne); //待自提数量 $pickup_type_two = $BillOrderModel->backMoneyCount($whereTwo); //待配送订单数量 $pickup_type_three = $BillOrderModel->backMoneyCount($whereThree); //待发货订单数量 $all_money = $BillOrderModel->backMoneySum($where, 'all_money'); //总销售额 $coupon_money = $BillOrderModel->backMoneySum($where, 'coupon_money'); //优惠券金额 $dis_money = $BillOrderModel->backMoneySum($where, 'vip_dis_money'); //折扣金额 $less_money = $BillOrderModel->backMoneySum($where, 'vip_less_money'); //会员价优惠金额 $integral_money = $BillOrderModel->backMoneySum($where, 'integral_dis_money'); //积分抵扣金额 $pay_coupon_money = $BillOrderModel->backMoneySum($where, 'd.pay_coupon_fee'); //代金券总额 $where['b.order_type'] = 2; $where['b.refund_status'] = 2; if ($order_type == 2) { $all_money = 0 - $all_money; $less_money = 0 - $less_money; $integral_money = 0 - $integral_money; $dis_money = 0 - $dis_money; $coupon_money = 0 - $coupon_money; } else { $refund_coupon_money = $BillOrderModel->backMoneySum($where, 'coupon_money'); //退款优惠券金额 $refund_dis_money = $BillOrderModel->backMoneySum($where, 'vip_dis_money'); //退款折扣金额 $refund_less_money = $BillOrderModel->backMoneySum($where, 'vip_less_money'); //退款会员价优惠金额 $refund_integral_money = $BillOrderModel->backMoneySum($where, 'integral_dis_money'); //退款积分抵扣金额 $refund_pay_coupon_money = $BillOrderModel->backMoneySum($where, 'd.pay_coupon_fee'); //代金券金额 $coupon_money = $refund_coupon_money ? round($coupon_money - $refund_coupon_money, 2) : $coupon_money; $dis_money = $refund_dis_money ? round($dis_money - $refund_dis_money, 2) : $dis_money; $less_money = $refund_less_money ? round($less_money - $refund_less_money, 2) : $less_money; $integral_money = $refund_integral_money ? round($integral_money - $refund_integral_money, 2) : $integral_money; $pay_coupon_money = $refund_pay_coupon_money ? round($pay_coupon_money - $refund_pay_coupon_money, 2) : $pay_coupon_money; } $res['all_money'] = $all_money; $res['less_money'] = $less_money; $res['integral_money'] = $integral_money; $res['dis_money'] = $dis_money; $res['coupon_money'] = $coupon_money; $res['pickup_type_one'] = $pickup_type_one; $res['pickup_type_two'] = $pickup_type_two; $res['pickup_type_three'] = $pickup_type_three; $res['pay_coupon_money'] = $pay_coupon_money; $this->ajaxReturn($res); } /** * 后台配送操作 */ public function sendOrder() { if (IS_POST) { $id = $_POST['id']; $status = $_POST['status']; //查询订单类型 if ($id) { $success['status'] = 2; $success['have_away'] = 1; $change = M('retail_bill')->where(array('id' => $id))->save($success); if ($change) { $res['status'] = 1; $res['msg'] = '操作成功'; } else { $res['status'] = 0; $res['msg'] = '操作失败'; } } else { $res['status'] = 0; $res['msg'] = '无效的参数ID'; } $this->ajaxReturn($res); } } /** * 后台完成操作 */ public function completeOrder() { if (IS_POST) { $id = I('post.id'); $status = I('post.status'); if ($id) { $change = M('retail_bill')->where(array('id' => $id))->setField('status', $status); if ($change) { $savedata['have_away'] = 1; $savedata['pickcode'] = ''; $change_status = M('retail_bill')->where(array('id' => $id))->save($savedata); $res['status'] = 1; $res['msg'] = '操作成功'; } else { $res['status'] = 0; $res['msg'] = '操作失败'; } } else { $res['status'] = 0; $res['msg'] = '无效的参数ID'; } $this->ajaxReturn($res); } } public function manager() { if (IS_POST) { $ConfigModel = new StoreConfigModel(); $RetailStoreModel = new RetailStoreModel(); $field = array( 'id', 'status', 'skip', 'self_pick', 'business_non_order', 'delivery_status', 'delivery_cost', 'business', 'business_time', 'address', 'longitude', 'latitude', 'tip', 'phone', 'math', 'smmoney', ); $data = $RetailStoreModel->getFind(['id' => $this->store_id], $field); $data['express_status'] = $ConfigModel->getFindField(['store_id' => $this->store_id], 'delivery_template_status'); //快递发货状态 if ($data['business_time']) { $data['business_time'] = explode(",", $data['business_time']); foreach ($data['business_time'] as &$val) { $val = explode("-", $val); } } else { $data['business_time'] = [[]]; } if ($data['business']) { $data['business'] = explode(",", $data['business']); foreach ($data['business'] as &$value) { $value = explode("-", $value); } } else { $data['business'] = [[]]; } $data['longitude'] = $data['longitude'] * 1; $data['latitude'] = $data['latitude'] * 1; $StoreXcxConfigModel = new RetailStoreXcxConfigModel(); $time = $StoreXcxConfigModel->getFind(['storeid' => $this->store_id], 'send_delayed_time,pickup_delayed_time,auto_set_time');//商城下单订单配送、自提延时的时间(单位:分钟) $data = array_merge($data, $time); // 加载围栏数据 $FenceModel = new \Common\Model\StoreDeliveryFenceModel(); $fenceData = $FenceModel->getFenceData($this->store_id); $data['delivery_fences'] = $fenceData; $result['status'] = 1; $result['msg'] = '查询成功!'; $result['data'] = $data; $this->ajaxReturn($result); } else { $this->display(); } } /** * 保存门店商城设置 */ public function storeSet() { if (IS_POST) { $param = I('post.'); $param['merchant_id'] = $this->merchant_id; $param['store_id'] = $this->store_id; $param['operator_id'] = $this->login_user['id']; $param['source'] = 0; $param['type'] = 4; $Store = new Store(); $this->ajaxReturn($Store->storeXcxSet($param)); } } //保存配送区域 public function saveDeliveryArea() { if (IS_POST) { $param = I('post.'); $param['merchant_id'] = $this->merchant_id; $param['store_id'] = $param['id']; // 前端传递的是id,需要映射到store_id $param['operator_id'] = $this->login_user['id']; $param['source'] = 0; $param['type'] = 4; // 更新math字段(配送区域数据)- 保持向后兼容 $updateData = [ 'math' => $param['math'] ]; $StoreModel = new \Common\Model\RetailStoreModel(); $ret = $StoreModel->where(['id' => $param['store_id']])->save($updateData); // 如果有fence_data参数,保存到新的电子围栏表 if (isset($param['fence_data']) && !empty($param['fence_data'])) { $FenceModel = new \Common\Model\StoreDeliveryFenceModel(); // 先删除该门店的旧围栏数据 $FenceModel->where(['store_id' => $param['store_id']])->delete(); // 解析fence_data(可能是JSON字符串或数组) $fenceData = $param['fence_data']; if (is_string($fenceData)) { $fenceData = json_decode($fenceData, true); } // 如果是有效的数组数据,保存到数据库 if (is_array($fenceData) && !empty($fenceData)) { $saveData = [ 'store_id' => $param['store_id'], 'merchant_id' => $param['merchant_id'], 'fence_name' => '配送区域', 'fence_data' => json_encode($fenceData), 'fence_type' => 1, // 1=多边形 'is_active' => 1, 'create_time' => time(), 'update_time' => time() ]; $fenceRet = $FenceModel->add($saveData); if (!$fenceRet) { $this->ajaxReturn(['status' => 0, 'message' => '电子围栏数据保存失败']); return; } } } if ($ret !== false) { //操作日志记录 action_log($param['source'], $param['type'], json_encode($_POST), '门店设置-配送区域设置'); $this->ajaxReturn(['status' => 1, 'message' => '配送区域保存成功']); } else { $this->ajaxReturn(['status' => 0, 'message' => '配送区域保存失败']); } } else { $this->ajaxReturn(['status' => 0, 'message' => '请求方式错误']); } } //配送费设置 public function distribution() { $arr = array( 'addFee' => '/index.php/Retail/Xcx/addFee', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } //获取费用区间 public function getDistribution() { $storeid = session('storeid'); $post = I("post."); $param = [ 'page',//当前页 'limit',//页大小 ]; foreach ($param as $value) { $isData = array_key_exists($value, $post); if ($isData === false) { $message = "缺少参数 '" . $value . "'"; $res = callBack(statusCode()['error'], $message); $this->ajaxReturn($res); } } $page = $post['page'] . ',' . $post['limit'];//分页 $where[] = 'storeid = ' . $storeid; if (isset($post['start']) && $post['start'] !== '' && isset($post['end']) && $post['end'] !== '') { if ($post['start'] > $post['end']) { $res = callBack(statusCode()['error'], '配送距离起始值不能大于配送距离结束值'); $this->ajaxReturn($res); } } if (isset($post['start']) && $post['start'] !== '') { $where[] = 'start >= ' . $post['start']; } if (isset($post['end']) && $post['end'] !== '') { $where[] = 'end <= ' . $post['end']; } if (isset($post['status']) && $post['status'] !== '') { $where[] = 'status = ' . $post['status']; } $field = 'id,start,end,fee,status'; $order = 'status asc,start asc,end asc,fee asc'; $retailDistributionModel = new RetailDistributionModel(); $data['total'] = $retailDistributionModel->getCount($where); $data['data'] = $retailDistributionModel->getSelect($where, $field, $order, $page); if ($data['total'] === false || $data['data'] === false) { $res = callBack(statusCode()['error'], '失败'); } else { $res = callBack(statusCode()['success'], '成功', $data); } $this->ajaxReturn($res); } //修改费用区间状态 public function distributionStatus() { $storeId = $this->store_id; $post = I("post."); $param = [ 'id',//主键id 'status',//状态:1开启 2关闭 ]; foreach ($param as $value) { $isData = array_key_exists($value, $post); if ($isData === false) { $message = "缺少参数 '" . $value . "'"; $res = callBack(statusCode()['error'], $message); $this->ajaxReturn($res); } } if ($post['status'] !== '' && $post['id'] !== '') { $where = [ 'id' => $post['id'], 'storeid' => $storeId, ]; $save = [ 'status' => $post['status'] ]; $retailDistributionModel = new RetailDistributionModel(); if ($post['status'] == 1) { //开启 $data = $retailDistributionModel->getFind($where); $start = $data['start']; $end = $data['end']; $whereOne = [ [ [ 'start' => ['lt', $start], 'end' => ['gt', $start], ], [ 'start' => ['lt', $end], 'end' => ['gt', $end], ], [ 'start' => ['egt', $start], 'end' => ['elt', $end], ], [ 'start' => ['elt', $start], 'end' => ['egt', $end], ], '_logic' => 'or', ], 'status' => 1, 'storeid' => $storeId, ]; $dataTwo = $retailDistributionModel->getFind($whereOne); if (empty($dataTwo)) { $data = $retailDistributionModel->updateOrder($where, $save); if ($data === false) { $res = callBack(statusCode()['error'], '失败'); } else { $res = callBack(statusCode()['success'], '成功'); } } else { $res = callBack(statusCode()['error'], '开启的配送范围有重复'); } } else if ($post['status'] == 2) { //关闭 $data = $retailDistributionModel->updateOrder($where, $save); if ($data === false) { $res = callBack(statusCode()['error'], '失败'); } else { $res = callBack(statusCode()['success'], '成功'); } } else { $res = callBack(statusCode()['error'], '失败'); } } else { $res = callBack(statusCode()['error'], '失败'); } $this->ajaxReturn($res); } //删除费用区间 public function delFee() { $storeid = session('storeid'); $id = I('post.id'); $info = M('retail_distribution')->where(array('storeid' => $storeid, 'id' => $id))->find(); if (empty($info)) { $res['status'] = 0; $res['msg'] = '请求有误'; } else { $del = M('retail_distribution')->where(array('storeid' => $storeid, 'id' => $id))->delete(); if ($del) { //操作日志记录 $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 setFee() { $storeid = session('storeid'); $list = I('post.list'); if (empty($list)) { $res['status'] = 0; $res['msg'] = '您未添加数据'; } else { $arr = array(); $count = 0; foreach ($list as $value) { $str = $value['start'] . ',' . $value['end']; if (!in_array($str, $arr)) { $arr[] = $str; } else { $count++; } } if ($count) { $res['status'] = 2; $res['msg'] = '有重复配送区间'; } else { foreach ($list as $value) { $save['start'] = $value['start']; $save['end'] = $value['end']; $save['fee'] = $value['fee']; M('retail_distribution')->where(array('storeid' => $storeid, 'id' => $value['id']))->save($save); } $res['status'] = 1; $res['msg'] = '保存成功'; } } $this->ajaxReturn($res); } //添加费用 public function addFee() { $storeid = session('storeid'); $start = I('post.start'); $end = I('post.end'); $fee = I('post.fee'); if (!isset($start) || empty($end) || $fee == '') { $res['status'] = 0; $res['msg'] = '缺少参数'; } else if (!is_numeric($start) || !is_numeric($end) || !is_numeric($fee) || floatval($start) < 0 || floatval($end) < 0 || floatval($fee) < 0) { $res['status'] = 0; $res['msg'] = '参数有误'; } else if (floatval($start) > floatval($end)) { $res['status'] = 0; $res['msg'] = '起始值不能大于结束值'; } else { $add['start'] = $start; $add['end'] = $end; $add['fee'] = $fee; $add['storeid'] = $storeid; $old = M('retail_distribution')->where($add)->find(); if (empty($old)) { // $add['fee'] = $fee; $add['addtime'] = time(); $add['status'] = 2;//1开启 2关闭 $addData = M('retail_distribution')->add($add); if ($addData) { //操作日志记录 $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'] = '添加失败'; } } else { $res['status'] = 0; $res['msg'] = '已存在相同配送区间'; } } $this->ajaxReturn($res); } //推荐商品 public function hot() { $storeid = session('storeid'); $store_config = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); if (!empty($store_config) && $store_config['recommend_status'] == 0) { $status = 0; } else { $status = 1; } $this->assign('status', $status); $arr = array( 'addhot' => '/index.php/Retail/Xcx/addhot', 'changeRecommend' => '/index.php/Retail/Xcx/changeRecommend', 'delhot' => '/index.php/Retail/Xcx/delhot', 'batchDelete' => '/index.php/Retail/Xcx/batchDelete', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } //修改推荐商品开启状态 public function changeRecommend() { $storeid = session('storeid'); $status = I('post.status'); if (!isset($status) || ($status != 1 && $status != 0)) { $result['status'] = 0; $result['msg'] = '参数有误'; $this->ajaxReturn($result); } $store_config = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); if (empty($store_config)) { $item['storeid'] = $storeid; $item['recommend_status'] = 0; $item['addtime'] = time(); $add = M('store_xcx_config')->add($item); if ($add) { $result['status'] = 1; $result['msg'] = '关闭成功'; } else { $result['status'] = 0; $result['msg'] = '关闭失败'; } } else { $update = M('store_xcx_config')->where(array('storeid' => $storeid))->save(array('recommend_status' => $status)); if ($update) { $result['status'] = 1; $result['msg'] = ($status == 1 ? '开启' : '关闭') . '成功'; } else { $result['status'] = 0; $result['msg'] = ($status == 1 ? '开启' : '关闭') . '失败'; } } $this->ajaxReturn($result); } //修改魔方状态 public function changeMagic() { $storeid = session('storeid'); $status = I('post.status'); if (!isset($status) || ($status != 1 && $status != 0)) { $result['status'] = 0; $result['msg'] = '参数有误'; $this->ajaxReturn($result); } $store_config = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); if (empty($store_config)) { $item['storeid'] = $storeid; $item['magic_status'] = 1; $item['addtime'] = time(); $add = M('store_xcx_config')->add($item); if ($add) { $result['status'] = 1; $result['msg'] = '开启成功'; } else { $result['status'] = 0; $result['msg'] = '开启失败'; } } else { $update = M('store_xcx_config')->where(array('storeid' => $storeid))->save(array('magic_status' => $status)); if ($update) { $result['status'] = 1; $result['msg'] = ($status == 1 ? '开启' : '关闭') . '成功'; //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 if ($status == 1) { $desc = '智慧魔方-开启魔方'; //操作行为描述 } else { $desc = '智慧魔方-关闭魔方'; //操作行为描述 } action_log($source, $type, $request_data, $desc); } else { $result['status'] = 0; $result['msg'] = ($status == 1 ? '开启' : '关闭') . '失败'; } } $this->ajaxReturn($result); } //修改最新商品开启状态 public function changeNewStatus() { $storeid = session('storeid'); $status = I('post.status'); if (!isset($status) || ($status != 1 && $status != 0)) { $result['status'] = 0; $result['msg'] = '参数有误'; $this->ajaxReturn($result); } $store_config = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); if (empty($store_config)) { $item['storeid'] = $storeid; $item['new_status'] = 1; $item['addtime'] = time(); $add = M('store_xcx_config')->add($item); if ($add) { $result['status'] = 1; $result['msg'] = '开启成功'; } else { $result['status'] = 0; $result['msg'] = '开启失败'; } } else { $update = M('store_xcx_config')->where(array('storeid' => $storeid))->save(array('new_status' => $status)); if ($update) { $result['status'] = 1; $result['msg'] = ($status == 1 ? '开启' : '关闭') . '成功'; //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 if ($status == 1) { $desc = '最新商品-开启最新商品'; //操作行为描述 } else { $desc = '最新商品-关闭最新商品'; //操作行为描述 } action_log($source, $type, $request_data, $desc); } else { $result['status'] = 0; $result['msg'] = ($status == 1 ? '开启' : '关闭') . '失败'; } } $this->ajaxReturn($result); } // 推荐商品信息 public function hotinfo() { $storeid = session('storeid'); $count = M('retail_host')->alias('h') ->join('ls_retail_goods as g on g.id=h.goods_id', 'LEFT') ->where(array('h.storeid' => $storeid, 'h.status' => 1, 'g.status' => 0, 'h.type' => 1))->count(); $hots = M('retail_host')->alias('h') ->join('ls_retail_goods as g on g.id=h.goods_id', 'LEFT') ->where(array('h.storeid' => $storeid, 'h.status' => 1, 'g.status' => 0, 'h.type' => 1)) ->field('g.*,h.id as hid,h.addtime') ->page($_POST['page'], $_POST['limit']) ->select(); foreach ($hots as $key => $value) { $hots[$key]['index'] = $key + 1; $hots[$key]['goods_code'] = $hots[$key]['goods_code'] ? $hots[$key]['goods_code'] : '--'; $hots[$key]['addtime'] = date('Y-m-d', $value['addtime']); } $rt['code'] = 0; $rt['msg'] = ''; $rt['count'] = $count; $rt['data'] = $hots; $this->ajaxReturn($rt); } /*------------------------促销商品 开始--------------------------*/ //促销商品显示 public function promotion() { $store_id = session('storeid'); $store_config = M('store_xcx_config')->where(array('storeid' => $store_id))->find(); if (session('store_userinfo')) { $merchant_id = session('store_userinfo')['merchantid']; } else { $merchant_id = session('merchant_userinfo')['id']; } $class_name = M('retail_goods_class')->where(array('merchantid' => $merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select(); $this->assign('class_name', json_encode($class_name)); if (!empty($store_config) && $store_config['promotion_status'] == 1) { $status = 1; } else { $status = 0; } $this->assign('status', $status); $arr = array( 'addPromotion' => '/index.php/Retail/Xcx/addPromotion', 'changePromotion' => '/index.php/Retail/Xcx/changePromotion', 'delPromotion' => '/index.php/Retail/Xcx/delPromotion', 'updatePrice' => '/index.php/Retail/Xcx/updatePrice', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } //获取促销商品列表 public function promotionInfo() { $store_id = session('storeid'); $page = I('post.page'); $limit = I('post.limit'); $class_id1 = I('post.class_id1'); $class_id2 = I('post.class_id2'); $class_id3 = I('post.class_id3'); $keyword = I('post.keyword'); $price_section = I('post.price_section'); //价格区间 $promotion_time = I('post.promotion_time'); //时间范围,交集 $act_type = I('post.act_type'); //状态 1未开始 2进行中 3已过期 $HostModel = D('RetailHost'); $map = array( 'h.' . $HostModel::STORE_ID => $store_id, 'h.' . $HostModel::TYPE => 2, 'h.' . $HostModel::STATUS => 1, 'h.' . $HostModel::STATE => 1, ); //关键词搜索 if (!empty($keyword)) { $map['g.goods_name|g.goods_number|g.goods_code'] = array('like', '%' . $keyword . '%'); } //商品分类 $goods_class_id = getGoodsClass($class_id1, $class_id2, $class_id3); if (!empty($goods_class_id)) { $map['g.goods_class_id'] = $goods_class_id; } //价格区间 if (!empty($price_section)) { $section = explode('-', $price_section); if (!empty($section[0]) && !empty($section[1])) { $map['h.act_price'] = array(array('egt', $section[0]), array('elt', $section[1]), 'AND'); } else if (!empty($section[0])) { $map['h.act_price'] = array('egt', $section[0]); } else { $map['h.act_price'] = array('elt', $section[1]); } } //查询状态 if (!empty($act_type)) { $time = time(); switch ($act_type) { case '1': $map['h.starttime'] = array('gt', $time); break; case '2': $map['h.starttime'] = array('elt', $time); $map['h.endtime'] = array('gt', $time); break; case '3': $map['h.endtime'] = array('lt', $time); break; } } //时间交集 if (!empty($promotion_time)) { $start_time = strtotime($promotion_time[0]); $end_time = strtotime($promotion_time[1]); $map['_complex'] = array( array( 'h.starttime' => array('elt', $start_time), 'h.endtime' => array('egt', $end_time), ), array( '_complex' => array( array( '_string' => "h.starttime >={$start_time} AND h.starttime <={$end_time}", ), array( '_string' => "h.endtime >={$start_time} AND h.endtime <={$end_time}", ), '_logic' => 'or' ), ), array( 'h.starttime' => array('egt', $start_time), 'h.endtime' => array('elt', $end_time), ), '_logic' => 'or' ); } $fields = 'h.*,g.goods_name,g.goods_code,g.goods_number,g.online_price,s.sku_id_list,s.sku_goods_number,s.sku_code,s.online_price as s_online_price'; $order = 'h.id desc'; $page = $page . ',' . $limit; $list = $HostModel->getGoodsList($map, $fields, $order, $page); $count = $HostModel->getGoodsCount($map); $SkuListModel = D('RetailSkuList'); foreach ($list as &$value) { if (!empty($value[$HostModel::SKU_ID])) { $value['goods_code'] = $value['sku_code'] ? $value['sku_code'] : '---'; $value['goods_number'] = $value['sku_goods_number'] ? $value['sku_goods_number'] : '---'; $map = array( $SkuListModel::ID => array('in', $value['sku_id_list']), ); $sku_name = $SkuListModel->getFindField($map, $SkuListModel::NAME, true); $value['goods_name'] = $value['goods_name'] . '(' . implode(',', $sku_name) . ')'; $value['online_price'] = $value['s_online_price']; unset($value['s_online_price']); } else { $value['goods_code'] = $value['goods_code'] ? $value['goods_code'] : '---'; $value['goods_number'] = $value['goods_number'] ? $value['goods_number'] : '---'; } $value['add_time'] = date('Y-m-d H:i:s', $value['addtime']); $value['start_time'] = newDate('Y-m-d H:i:s', $value['starttime']); $value['end_time'] = newDate('Y-m-d H:i:s', $value['endtime']); } $res['status'] = 1; $res['msg'] = '获取成功'; $res['count'] = $count; $res['data'] = $list; $this->ajaxReturn($res); } //修改促销商品开启状态 public function changePromotion() { $storeid = session('storeid'); $status = I('post.status'); if (!isset($status) || ($status != 1 && $status != 0)) { $result['status'] = 0; $result['msg'] = '参数有误'; $this->ajaxReturn($result); } $store_config = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); if (empty($store_config)) { $item['storeid'] = $storeid; $item['promotion_status'] = 1; $item['addtime'] = time(); $add = M('store_xcx_config')->add($item); if ($add) { $result['status'] = 1; $result['msg'] = '开启成功'; } else { $result['status'] = 0; $result['msg'] = '开启失败'; } } else { $update = M('store_xcx_config')->where(array('storeid' => $storeid))->save(array('promotion_status' => $status)); if ($update) { $result['status'] = 1; $result['msg'] = ($status == 1 ? '开启' : '关闭') . '成功'; //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 if ($status == 1) { $desc = '促销商品-开启促销商品'; //操作行为描述 } else { $desc = '促销商品-关闭促销商品'; //操作行为描述 } action_log($source, $type, $request_data, $desc); } else { $result['status'] = 0; $result['msg'] = ($status == 1 ? '开启' : '关闭') . '失败'; } } $this->ajaxReturn($result); } //获取商品列表 public function promotionGoodsList() { $store_id = session('storeid'); $keyword = I('post.keyword'); $page = I('post.page'); $limit = I('post.limit'); $class_id1 = I('post.class_id1'); $class_id2 = I('post.class_id2'); $class_id3 = I('post.class_id3'); $attribute_state = I('post.attribute_state'); $GoodsModel = D('RetailGoods'); $map = array( $GoodsModel::STORE_ID => $store_id, $GoodsModel::STATUS => 0, $GoodsModel::ONLINE_STATE => 1, $GoodsModel::ADVANCE_SALE_STATUS => 0 ); if ($keyword) { $map[$GoodsModel::GOODS_NAME . '|' . $GoodsModel::GOODS_CODE . '|' . $GoodsModel::GOODS_NUMBER] = array('like', '%' . $keyword . '%'); } if ($attribute_state) { $map[$GoodsModel::ATTRIBUTE_STATE] = $attribute_state == 1 ? 1 : 2; } $goods_class_id = getGoodsClass($class_id1, $class_id2, $class_id3); if (!empty($goods_class_id)) { $map[$GoodsModel::GOODS_CLASS_ID] = $goods_class_id; } $fields = array( $GoodsModel::ID, $GoodsModel::GOODS_NAME, $GoodsModel::GOODS_CODE, $GoodsModel::GOODS_NUMBER, $GoodsModel::ATTRIBUTE_STATE, $GoodsModel::ONLINE_PRICE, ); $order = $GoodsModel::ID . ' desc'; //商品列表 $goods = $GoodsModel->getSelect($map, $fields, $order, $page . ',' . $limit); $count = $GoodsModel->getCount($map); foreach ($goods as $key => &$value) { $value[$GoodsModel::GOODS_CODE] = $value[$GoodsModel::GOODS_CODE] ? $value[$GoodsModel::GOODS_CODE] : '---'; $value[$GoodsModel::GOODS_NUMBER] = $value[$GoodsModel::GOODS_NUMBER] ? $value[$GoodsModel::GOODS_NUMBER] : '---'; } $res['status'] = 1; $res['count'] = $count; $res['data'] = $goods; $this->ajaxReturn($res); } //获取商品的规格列表 public function getGoodsSkuList() { $store_id = session('storeid'); $keyword = I('post.keyword'); $goods_id = I('post.goods_id'); $page = I('post.page'); $limit = I('post.limit'); $SkuGoodsModel = D('RetailSkuGoods'); $map = array( $SkuGoodsModel::STORE_ID => $store_id, $SkuGoodsModel::GOODS_ID => $goods_id, $SkuGoodsModel::STATUS => 1, $SkuGoodsModel::STATE => 0, ); if ($keyword) { $map[$SkuGoodsModel::SKU_CODE . '|' . $SkuGoodsModel::SKU_GOODS_NUMBER] = array('like', '%' . $keyword . '%'); } $fields = array( $SkuGoodsModel::ID, $SkuGoodsModel::SKU_ID_LIST, $SkuGoodsModel::SKU_CODE, $SkuGoodsModel::SKU_GOODS_NUMBER, $SkuGoodsModel::ONLINE_PRICE, ); $order = $SkuGoodsModel::ID . ' desc'; //商品列表 $goods = $SkuGoodsModel->getSelect($map, $fields, $order, $page . ',' . $limit); $count = $SkuGoodsModel->getCount($map); $SkuListModel = D('RetailSkuList'); foreach ($goods as $key => &$value) { $map = array( $SkuListModel::ID => array('in', $value[$SkuGoodsModel::SKU_ID_LIST]), ); $sku_name = $SkuListModel->getFindField($map, $SkuListModel::NAME, true); $value['sku_name'] = implode(',', $sku_name); $value[$SkuGoodsModel::SKU_CODE] = $value[$SkuGoodsModel::SKU_CODE] ? $value[$SkuGoodsModel::SKU_CODE] : '---'; $value[$SkuGoodsModel::SKU_GOODS_NUMBER] = $value[$SkuGoodsModel::SKU_GOODS_NUMBER] ? $value[$SkuGoodsModel::SKU_GOODS_NUMBER] : '---'; } $res['status'] = 1; $res['count'] = $count; $res['data'] = $goods; $this->ajaxReturn($res); } //添加促销商品 public function addPromotion() { if (IS_POST) { $goods_id = I('post.goods_id'); $time = I('post.time'); //促销活动时间 $act_price = I('post.act_price'); //促销价 $sku = I('post.sku'); //规格 $set_price_type = I('post.set_price_type'); //金额设置方式 if (empty($goods_id) || empty($time)) { $res['status'] = 0; $res['msg'] = '缺少参数'; $this->ajaxReturn($res); } if ($set_price_type == 2 && !verifyPrice($act_price)) { $res['status'] = 0; $res['msg'] = '请设置正确的促销价格'; $this->ajaxReturn($res); } $store_id = session('storeid'); $start_time = newStrToTime($time[0]); //开始时间 $end_time = newStrToTime($time[1]); //结束时间 $time = time(); $merchant_id = session('ls_userinfo')['merchantid']; $sku = json_decode($sku, true); if (empty($sku)) { $sku = array( array('id' => 0), ); } $HostModel = D('RetailHost'); $map = array( $HostModel::GOODS_ID => $goods_id, $HostModel::TYPE => 2, $HostModel::STATE => 1, 'starttime' => array('elt', $time), 'endtime' => array('egt', $time), ); $addItem = array(); $errorItem = array(); foreach ($sku as $key => $value) { if (!empty($value['id'])) { $map[$HostModel::SKU_ID] = $value['id']; } $old = $HostModel->getFind($map); if (!empty($old)) { $msg = '促销列表已存在该商品'; if (!empty($value['id'])) { $msg .= '(' . $value['sku_name'] . ')'; } $errorItem[] = $msg; } if ($set_price_type == 1 && !verifyPrice($value['act_price'])) { $errorItem[] = '第' + ($key + 1) + '个规格价格设置有误'; } $item = array( $HostModel::STORE_ID => $store_id, $HostModel::MERCHANT_ID => $merchant_id, $HostModel::ADD_TIME => $time, $HostModel::STATUS => 1, $HostModel::TYPE => 2, $HostModel::GOODS_ID => $goods_id, $HostModel::ACT_PRICE => $set_price_type == 1 ? $value['act_price'] : $act_price, $HostModel::START_TIME => $start_time, $HostModel::END_TIME => $end_time, $HostModel::SKU_ID => $value['id'], ); $addItem[] = $item; } if (!empty($errorItem)) { $res['status'] = 0; $res['msg'] = '有商品已存在促销列表,请核实再添加'; $res['errorData'] = $errorItem; $this->ajaxReturn($res); } foreach ($addItem as $val) { $HostModel->addOrder($val); } //操作日志记录 $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'] = '促销商品添加成功'; $this->ajaxReturn($res); } } //修改促销商品价格 public function updatePrice() { $store_id = session('storeid'); $id = I('post.id'); $price = I('post.price'); $time = I('post.time'); if (!$id || !$price || !$time) { $res['status'] = 0; $res['msg'] = '缺少参数'; $this->ajaxReturn($res); } $HostModel = D('RetailHost'); $hMap = array( $HostModel::STORE_ID => $store_id, $HostModel::ID => $id, $HostModel::TYPE => 2, $HostModel::STATE => 1, ); $start_time = newStrToTime($time[0]); $end_time = newStrToTime($time[1]); $host = $HostModel->getFind($hMap); if (empty($host)) { $res['status'] = 0; $res['msg'] = '请求参数有误'; $this->ajaxReturn($res); } $GoodsModel = new RetailGoodsModel(); $advance_sale_status = $GoodsModel->getFindField([ 'id' => $host['goods_id'] ], 'advance_sale_status'); if ($advance_sale_status == 1) { $res['status'] = 0; $res['msg'] = '该商品已经开启预售,暂不支持修改'; $this->ajaxReturn($res); } if ($host[$HostModel::START_TIME] == $start_time && $host[$HostModel::END_TIME] == $end_time && $host[$HostModel::ACT_PRICE] == $price) { $res['status'] = 1; $res['msg'] = '保存成功'; $this->ajaxReturn($res); } $save = array( $HostModel::START_TIME => $start_time, $HostModel::END_TIME => $end_time, $HostModel::ACT_PRICE => $price, ); /* 修改促销价格 */ $up = $HostModel->updateOrder($hMap, $save); 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 delPromotion() { $id = I('post.id'); $store_id = session('storeid'); if (!$id || !$store_id) { $res['status'] = 0; $res['msg'] = '缺少参数'; $this->ajaxReturn($res); } $HostModel = D('RetailHost'); $map = array( $HostModel::ID => $id, $HostModel::STATE => 1, ); $promotion = $HostModel->getFind($map); if (empty($promotion)) { $res['status'] = 0; $res['msg'] = '活动不存在'; $this->ajaxReturn($res); } $save = array( $HostModel::STATE => 0, ); $del = $HostModel->updateOrder($map, $save); if ($del) { //操作日志记录 $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 newGoodsInfo() { $map = array( 'h.storeid' => $this->store_id, 'h.status' => 1, 'g.status' => 0, 'h.type' => 3, ); $count = M('retail_host as h') ->join('ls_retail_goods as g on g.id=h.goods_id') ->where($map)->count(); $hots = M('retail_host as h') ->join('ls_retail_goods as g on g.id=h.goods_id') ->where($map) ->field('g.goods_number,g.goods_name,g.goods_code,g.retail_price,g.online_price,h.id,h.addtime') ->page($_POST['page'], $_POST['limit']) ->select(); foreach ($hots as $key => $value) { $hots[$key]['goods_code'] = $hots[$key]['goods_code'] ? $hots[$key]['goods_code'] : '--'; $hots[$key]['add_time'] = date('Y-m-d', $value['addtime']); } $result['code'] = 0; $result['msg'] = '获取成功'; $result['count'] = intval($count); $result['data'] = $hots ? $hots : array(); $this->ajaxReturn($result); } //最新商品 public function new_goods() { $storeid = session('storeid'); $store_config = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); if (!empty($store_config) && $store_config['new_status'] == 1) { $status = 1; } else { $status = 0; } $this->assign('status', $status); $arr = array( 'addNewGoods' => '/index.php/Retail/Xcx/addNewGoods', 'changeNewStatus' => '/index.php/Retail/Xcx/changeNewStatus', 'delNewGoods' => '/index.php/Retail/Xcx/delNewGoods', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } //最新商品列表 public function newGoodsList() { $storeid = session('storeid'); $keyword = I('post.keyword'); if ($keyword) { $map = array(); $map['goods_name'] = array('like', '%' . I('keyword') . '%'); $map['goods_number'] = array('like', '%' . I('keyword') . '%'); $map['_logic'] = 'OR'; } else { $map = ""; } if (!empty($map)) { $wwww['_complex'] = $map; } $arr = M('retail_host')->where(array('storeid' => $storeid, 'status' => array('in', '0,1'), 'type' => 3))->getField('goods_id', true); $arr = $arr ? $arr : array(0); $wwww['id'] = array('not in', $arr); $wwww['store_id'] = $storeid; $wwww['status'] = 0; //正常商品 $wwww['online_state'] = 1; //商品列表 $goods = M('retail_goods')->where($wwww)->page($_POST['page'], $_POST['limit'])->select(); $count = M('retail_goods')->where($wwww)->count(); foreach ($goods as $key => &$value) { //查询出分类名称 $goods[$key]['cate_name'] = M('retail_goods_class')->where(array('id' => $value['goods_class_id']))->getField('class_name'); //直接判断出商品的状态以及是否允许修改折扣价 //商品状态 if ($value['status'] == 0) { $goods[$key]['status_name'] = '正常'; } elseif ($value['status'] == 1) { $goods[$key]['status_name'] = '已下架'; } elseif ($value['status'] == 2) { $goods[$key]['status_name'] = '已删除'; } //是否允许修改折扣价 if ($value['canchangeprice'] == 1) { $goods[$key]['canchangeprice_name'] = '是'; } else { $goods[$key]['canchangeprice_name'] = '不允许'; } $goods[$key]['goods_code'] = $goods[$key]['goods_code'] ? $goods[$key]['goods_code'] : '---'; $goods[$key]['good_number'] = $goods[$key]['goods_number'] ? $goods[$key]['goods_number'] : '---'; } $rt['code'] = 0; $rt['count'] = $count; $rt['data'] = $goods; $this->ajaxReturn($rt); } //添加最新商品 public function addNewGoods() { if (IS_POST) { $id = I('post.id'); $time = time(); $user = session('ls_userinfo'); foreach ($id as $key => &$val) { $Ad['storeid'] = session('storeid'); $Ad['merchantid'] = $user['merchantid']; $Ad['addtime'] = $time; $Ad['status'] = 1; $Ad['type'] = 3; $Ad['goods_id'] = $val; $ret = M('retail_host')->add($Ad); } if ($ret) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '最新商品-新增最新商品'; //操作行为描述 action_log($source, $type, $request_data, $desc); $rt['status'] = 1; $rt['msg'] = '最新商品添加成功'; } else { $rt['status'] = 2; $rt['msg'] = '最新商品添加失败'; } $this->ajaxReturn($rt); } } // 添加推荐商品 public function addhot() { if (IS_POST) { $id = I('post.id'); $time = time(); $user = session('ls_userinfo'); foreach ($id as $key => &$val) { $Ad['storeid'] = session('storeid'); $Ad['merchantid'] = $user['merchantid']; $Ad['addtime'] = $time; $Ad['status'] = 1; $Ad['type'] = 1; $Ad['goods_id'] = $val; $ret = M('retail_host')->add($Ad); } if ($ret) { $rt['status'] = 1; $rt['msg'] = '推荐商品添加成功'; } else { $rt['status'] = 2; $rt['msg'] = '推荐商品添加失败'; } $this->ajaxReturn($rt); } } //修改促销商品价格 public function updatePrice_v1() { if (IS_POST) { $id = I('post.id'); $money = I('post.money'); if (!$id || !$money) { $rt['status'] = 2; $rt['msg'] = '参数错误'; $this->ajaxReturn($rt); } $ret = M('retail_host')->where(array('id' => $id))->find(); $goods = M('retail_goods')->where(array('id' => $ret['goods_id']))->find(); if ($money == $goods['online_price']) { $rt['status'] = 1; $rt['msg'] = '修改成功'; } else { $update = M('retail_goods')->where(array('id' => $ret['goods_id']))->save(array('online_price' => $money)); if ($update) { $rt['status'] = 1; $rt['msg'] = '修改成功'; } else { $rt['status'] = 2; $rt['msg'] = '删除失败'; } } $this->ajaxReturn($rt); } } // 删除推荐商品 public function delhot() { if (IS_POST) { $id = I('post.id'); if (!$id) { $rt['status'] = 2; $rt['msg'] = '参数错误'; $this->ajaxReturn($rt); } $ret = M('retail_host')->where(array('id' => $id))->delete(); if ($ret) { $rt['status'] = 1; $rt['msg'] = '删除成功'; } else { $rt['status'] = 2; $rt['msg'] = '删除失败'; } $this->ajaxReturn($rt); } } /** * 2018-10-20 推荐商品批量删除 */ public function batchDelete() { if (IS_POST) { $ids = I("post.ids"); if (isset($ids)) { $map['goods_id'] = array("in", rtrim($ids, ',')); $change = M("retail_host")->where($map)->delete(); if ($change) { $res['status'] = 1; $res['msg'] = '删除完成'; } else { $res['status'] = 0; $res['msg'] = '删除失败'; } } else { $res['status'] = 0; $res['msg'] = '参数错误'; } $this->ajaxReturn($res); } } //删除最新商品 public function delNewGoods() { if (IS_POST) { $id = I('post.id'); if (!$id) { $rt['status'] = 2; $rt['msg'] = '参数错误'; $this->ajaxReturn($rt); } $ret = M('retail_host')->where(array('id' => $id))->delete(); if ($ret) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '最新商品-删除'; //操作行为描述 action_log($source, $type, $request_data, $desc); $rt['status'] = 1; $rt['msg'] = '删除成功'; } else { $rt['status'] = 2; $rt['msg'] = '删除失败'; } $this->ajaxReturn($rt); } } //获取可推荐商品 public function goodsList() { $storeid = session('storeid'); $tap = I('get.keyword'); if (!empty($tap)) { $map['goods_name|good_number'] = array('like', "%" . $tap . "%"); $wwww['_complex'] = $map; } $arr = M('retail_host')->where(array('storeid' => $storeid, 'status' => array('in', '0,1'), 'type' => 1))->getField('goods_id', true); $arr = $arr ? $arr : array(0); $wwww['id'] = array('not in', $arr); $wwww['storeid'] = $storeid; $wwww['status'] = 0; //正常商品 $wwww['issellonline'] = 1; //商品列表 $goods = M('retail_goods')->where($wwww)->page($_GET['page'], $_GET['limit'])->select(); $count = M('retail_goods')->where($wwww)->count(); foreach ($goods as $key => &$value) { //查询出分类名称 $goods[$key]['cate_name'] = M('retail_goods_class')->where(array('id' => $value['goods_class_id']))->getField('class_name'); //直接判断出商品的状态以及是否允许修改折扣价 //商品状态 if ($value['status'] == 0) { $goods[$key]['status_name'] = '正常'; } elseif ($value['status'] == 1) { $goods[$key]['status_name'] = '已下架'; } elseif ($value['status'] == 2) { $goods[$key]['status_name'] = '已删除'; } //是否允许修改折扣价 if ($value['canchangeprice'] == 1) { $goods[$key]['canchangeprice_name'] = '是'; } else { $goods[$key]['canchangeprice_name'] = '不允许'; } $goods[$key]['goods_code'] = $goods[$key]['goods_code'] ? $goods[$key]['goods_code'] : '---'; $goods[$key]['good_number'] = $goods[$key]['good_number'] ? $goods[$key]['good_number'] : '---'; } $rt['code'] = 0; $rt['count'] = $count; $rt['data'] = $goods; $this->ajaxReturn($rt); } //门店轮播 public function banner() { $storeid = session('storeid'); $icon = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); if (!empty($icon['home_tel_icon_id'])) { $icon['home_tel_icon'] = D('ImageGallery')->getOneField(array('id' => $icon['home_tel_icon_id']), 'path'); } if (!empty($icon['home_back_icon_id'])) { $icon['home_back_icon'] = D('ImageGallery')->getOneField(array('id' => $icon['home_back_icon_id']), 'path'); } if (!empty($icon['home_support_icon_id'])) { $icon['home_support_icon'] = D('ImageGallery')->getOneField(array('id' => $icon['home_support_icon_id']), 'path'); } $this->assign('icon', $icon); $arr = array( 'setIcon' => '/index.php/Retail/Xcx/setIcon', 'bannerSet' => '/index.php/Retail/Xcx/bannerSet', 'deleteBanner' => '/index.php/Retail/Xcx/deleteBanner', 'changeBanner' => '/index.php/Retail/Xcx/changeBanner', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } public function bannerList() { $userInfo = session("ls_userinfo"); if (!empty($userInfo)) { $storeid = session('storeid'); $page = I('post.page'); $limit = I('post.limit'); $map = array('storeid' => $storeid, 'merchantid' => $userInfo['merchantid']); $banner_count = M('retail_banner')->where($map)->count(); $banner = M('retail_banner')->where($map)->page($page, $limit)->order('id desc')->select(); foreach ($banner as $key => &$value) { $value['addtime'] = date('Y-m-d H:i:s', $value['addtime']); $value['index'] = $key + 1; if (!empty($value['imgurl_id'])) { $value['imgurl'] = D('ImageGallery')->getOneField(array('id' => $value['imgurl_id']), 'path'); } } $res['status'] = 1; $res['msg'] = '查询成功'; $res['data'] = $banner; $res['count'] = (int)$banner_count; } $this->ajaxReturn($res); } public function deleteBanner() { if (IS_POST) { $id = $_POST['id']; // var_dump($id); if ($id) { $change = M('retail_banner')->where(array('id' => $id))->delete(); if ($change) { //操作日志记录 $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'] = '删除失败'; } } else { $res['status'] = 0; $res['msg'] = '无效的参数ID'; } $this->ajaxReturn($res); } } public function changeBanner() { $user = session('ls_userinfo'); if (IS_POST && !empty($user)) { $id = I('post.id'); $status = I('post.status'); if ($id) { $change = M('retail_banner')->where(array('id' => $id))->setField('status', $status); if ($change) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 if ($status == 1) { $desc = '门店图片-轮播图-启用'; //操作行为描述 } elseif ($status == 0) { $desc = '门店图片-轮播图-关闭'; //操作行为描述 } action_log($source, $type, $request_data, $desc); $res['data'] = array('status' => $status); $res['status'] = 1; $res['msg'] = '切换成功'; } else { $res['status'] = 0; $res['msg'] = '切换失败'; } } else { $res['status'] = 0; $res['msg'] = '无效的参数ID'; } } else { $res['status'] = 0; $res['msg'] = '登录超时'; } $this->ajaxReturn($res); } public function bannerSet() { $user = session('ls_userinfo'); $storeid = session('storeid'); if (IS_POST && !empty($user)) { $imgurl_id = I('post.imgurl_id'); if (empty($_FILES) || ($_FILES['imgurl']['error'] != 0 && !$imgurl_id)) { $res['status'] = 0; $res['msg'] = '请上传图片'; $this->ajaxReturn($res); } if ($_FILES['imgurl']['error'] === 0) { $item = array( 'add_time' => time(), 'from_type_id' => 30, 'localUrl' => 'Store/MallIcon', 'user_type' => 4, 'merchant_id' => $user['merchantid'], 'store_id' => $storeid ); $uploads = uploadFiles($item); if (empty($uploads['imgurl'])) { $res['status'] = 0; $res['msg'] = '图片上传失败'; $this->ajaxReturn($res); } else { $imgurl_id = $uploads['imgurl']['id']; $imgurl = $uploads['imgurl']['path']; } } else { $imgurl = D('ImageGallery')->getOneField(array('id' => $imgurl_id), 'path'); } // 接受参数 $jump_type = $_POST['jump_type']; $class_id = $_POST['class_id']; $jump_id = $_POST['jump_id']; $goods_id = $_POST['goods_id']; // 判断 if (empty($jump_type)) { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } // 分类 if ($jump_type == 1) { // 判断分类 if (empty($class_id)) { $res['status'] = 0; $res['msg'] = '请选择分类'; $this->ajaxReturn($res); } // 查询分类 $goods_class = M('retail_goods_class')->field('id,class_name')->where(array('id' => $class_id, 'merchantid' => $user['merchantid'], 'status' => 0, 'type' => 1, 'pid' => array('eq', 0)))->find(); if (empty($goods_class)) { $res['status'] = 0; $res['msg'] = '分类查询失败'; $this->ajaxReturn($res); } $data['url_notes'] = '商品分类:' . $goods_class['class_name']; $data['url'] = '/pages/productList/productList?id=' . $goods_class['id'] . '&class_name=' . $goods_class['class_name']; } else if ($jump_type == 2) { // 判断功能 if (empty($jump_id)) { $res['status'] = 0; $res['msg'] = '请选择功能'; $this->ajaxReturn($res); } // 查询功能 $jump_info = M('magic_cube')->field('addtime', true)->where(array('id' => $jump_id, 'status' => 1, 'state' => 1))->find(); if (empty($jump_info)) { $res['status'] = 0; $res['msg'] = '功能查询失败'; $this->ajaxReturn($res); } // 判断type if ($jump_info['type'] == 1 && $jump_info['url'] == '/pages/details/details') { // 判断商品 if (empty($goods_id)) { $res['status'] = 0; $res['msg'] = '请选择商品'; $this->ajaxReturn($res); } // 查询商品 $goods_info = M('retail_goods')->where(array('id' => $goods_id, 'status' => 0, 'store_id' => $storeid, 'online_state' => 1))->field('id,goods_name,online_price,goods_num,goods_img_id')->find(); if (empty($goods_info)) { $res['status'] = 0; $res['msg'] = '商品查询失败'; $this->ajaxReturn($res); } $data['url_notes'] = '商品详情:' . $goods_info['goods_name']; $data['url'] = $jump_info['url'] . '?id=' . $goods_info['id']; } else { $data['url_notes'] = $jump_info['name']; $data['url'] = $jump_info['url']; } } else { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } $data['status'] = I('post.status') || 0; $data['imgurl_id'] = $imgurl_id; $data['imgurl'] = $imgurl; $data['addtime'] = time(); $data['storeid'] = $storeid; $data['merchantid'] = $user['merchantid']; $add = M('retail_banner')->add($data); if ($add) { //操作日志记录 $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'] = '添加失败'; } } else { $res['status'] = 0; $res['msg'] = '登录超时'; } $this->ajaxReturn($res); } public function magic_cube() { $storeid = session('storeid'); $store_config = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); if (!empty($store_config) && $store_config['magic_status'] == 1) { $status = 1; } else { $status = 0; } $this->assign('status', $status); $arr = array( 'add_magic' => '/index.php/Retail/Xcx/add_magic', 'changeMagic' => '/index.php/Retail/Xcx/changeMagic', 'doChangeStatus' => '/index.php/Retail/Xcx/doChangeStatus', 'delMagic' => '/index.php/Retail/Xcx/delMagic', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } public function getMagicCube() { $storeid = session('storeid'); $count = M('magic_store')->where(array('storeid' => $storeid))->count(); $list = M('magic_store')->where(array('storeid' => $storeid))->page($_POST['page'], $_POST['limit'])->order('id desc')->select(); foreach ($list as &$val) { $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']); if ($val['mc_id']) { $val['mc_id'] = M('magic_cube')->where(array('id' => $val['mc_id']))->getField('name'); } else { $val['mc_id'] = '其他链接'; } for ($i = 1; $i < 4; $i++) { if ($val['mc_id_' . $i]) { $val['mc_id_' . $i] = M('magic_cube')->where(array('id' => $val['mc_id_' . $i]))->getField('name'); } else { $val['mc_id_' . $i] = '其他链接'; } } } $res['code'] = 0; $res['data'] = $list; $res['count'] = $count; $this->ajaxReturn($res); } //修改魔方启用状态 public function doChangeStatus() { $id = I('post.id'); $status = I('post.status'); $update = M('magic_store')->where(array('id' => $id))->save(array('status' => $status)); if ($update) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 if ($status == 1) { $desc = '智慧魔方-魔方活动启用'; //操作行为描述 } else { $desc = '智慧魔方-魔方活动关闭'; //操作行为描述 } action_log($source, $type, $request_data, $desc); $res['value'] = $status; $res['status'] = 1; $res['msg'] = $status == 1 ? '启用成功' : '禁用成功'; } else { $res['status'] = 0; $res['value'] = $status == 1 ? 2 : 1; $res['msg'] = $status == 1 ? '启用失败' : '禁用失败'; } $this->ajaxReturn($res); } //添加智慧魔方 public function add_magic() { $storeid = session('storeid'); $id = I('get.id'); if ($id) { $magic = M('magic_store')->where(array('id' => $id))->find(); if (!empty($magic['link_id'])) { $goods = M('retail_goods')->where(array('id' => $magic['link_id']))->find(); $magic['goods_name'] = $goods['goods_name']; if ($goods['status'] == 1) { $magic['goods_state'] = '商品已下架'; } else if ($goods['status'] == 2) { $magic['goods_state'] = '商品失效'; } else if ($goods['issellonline'] == 0) { $magic['goods_state'] = '商品不在商城出售'; } } if ($magic['magic_type'] == 1) { for ($i = 1; $i < 4; $i++) { if (!empty($magic['link_id_' . $i])) { $goods = M('retail_goods')->where(array('id' => $magic['link_id_' . $i]))->find(); $magic['goods_name_' . $i] = $goods['goods_name']; if ($goods['status'] == 1) { $magic['goods_state_' . $i] = '商品已下架'; } else if ($goods['status'] == 2) { $magic['goods_state_' . $i] = '商品失效'; } else if ($goods['issellonline'] == 0) { $magic['goods_state_' . $i] = '商品不在商城出售'; } } } } $this->assign('magic', $magic); } $merchantid = M('retail_store')->where(array('id' => $storeid))->getField('merchantid'); $class_name = M('retail_goods_class')->where(array('merchantid' => $merchantid, 'status' => 0, 'type' => 1))->order('code asc')->select(); $where['status'] = 1; $where['state'] = 1; $where['name'] = array('in', array('充值', '商品详情')); $classList = M('magic_cube')->where($where)->select(); $this->assign('class1', json_encode($class_name)); $this->assign('classList', json_encode($classList)); $this->display(); } public function getOnlineGoods() { $store_id = session('storeid'); $user = session('ls_userinfo'); if (!$user) { $res = array('status' => 0, 'msg' => '登录超时'); $this->ajaxRetrun($res); } $map = array('status' => 0, 'store_id' => $store_id, 'online_state' => 1); // 接收搜索条件 $keyword = I('post.keyword'); if (isset($keyword)) { $map['goods_name|goods_number|goods_code'] = array('like', '%' . $keyword . '%'); } $person1 = I('post.person1'); $person2 = I('post.person2'); $person3 = I('post.person3'); $flag = 0; if (!empty($person3)) { $map['goods_class_id'] = $person3; } else if (!empty($person2)) { $class = M('retail_goods_class as c2') ->join('ls_retail_goods_class as c3 on c2.id=c3.pid') ->where(array('c2.id' => $person2, 'c3.status' => 0)) ->field('c3.id')->select(); $flag = 1; } else if (!empty($person1)) { $class = M('retail_goods_class as c1') ->join('ls_retail_goods_class as c2 on c1.id=c2.pid') ->join('ls_retail_goods_class as c3 on c2.id=c3.pid AND c3.status=0', 'LEFT') ->where(array('c1.id' => $person1, 'c2.status' => 0)) ->field('c2.id,c3.id as c3_id')->select(); $flag = 1; } if (!empty($class)) { $arr = array(); foreach ($class as &$val) { if (!in_array($val['id'], $arr)) { $arr[] = $val['id']; } if (!empty($val['c3_id'])) { if (!in_array($val['c3_id'], $arr)) { $arr[] = $val['c3_id']; } } } $str = implode(',', $arr); $map['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1)); } else if ($flag == 1) { $map['goods_class_id'] = $person2 ? $person2 : $person1; } $page = I('post.page'); $limit = I('post.limit'); $count = $goodsList = M('retail_goods')->where($map)->count(); $goodsList = M('retail_goods') ->where($map) ->page($page, $limit) ->field('id,goods_name,online_price,goods_img_id') ->select(); if (!empty($goodsList)) { foreach ($goodsList as &$value) { $gallery = D('ImageGallery')->getImgPath(['id' => $value['goods_img_id']]); $value['good_image'] = $gallery; $value['goods_num'] = A('Api/Inventory')->goods_num(2, $store_id, $value['id']); } $res['status'] = 1; $res['msg'] = '查询成功'; $res['data'] = $goodsList; $res['count'] = (int)$count; } else { $res['status'] = 0; $res['msg'] = '无该条件商品'; } $this->ajaxReturn($res); } //添加魔方 public function doAddMagic() { $storeid = session('storeid'); $user = session('ls_userinfo'); $title = I('post.magic_title'); $mc_id = I('post.type_url'); $child_img_id = I('post.child_img_id'); $child_img = I('post.child_img'); $link_id = I('post.link_id'); $magic_type = I('post.magic_type'); $id = I('post.id'); if (empty($title) || empty($magic_type) || empty($mc_id)) { $result['status'] = 0; $result['msg'] = '缺少参数'; $this->ajaxReturn($result); } $files = $_FILES; $isUploads = false; if ($files['magic_icon']['error'] === 0) { if (!is_uploaded_file($_FILES['magic_icon']['tmp_name'])) { $result['status'] = 0; $result['msg'] = '大图上传失败1'; $this->ajaxReturn($result); } else { $isUploads = true; } } else if (empty($child_img_id) && empty($child_img)) { $result['status'] = 0; $result['msg'] = '请上传大图'; $this->ajaxReturn($result); } else { $item['child_img'] = $child_img ? $child_img : ''; $item['child_img_id'] = $child_img_id && $child_img_id != 0 ? $child_img_id : ''; } $post = I('post.'); $item['storeid'] = $storeid; $item['title'] = $title; $magic = M('magic_cube')->where(array('id' => $mc_id))->find(); $item['mc_id'] = $mc_id; if ($magic['type'] == 1) { //需要关联id if (empty($link_id)) { $result['status'] = 0; $result['msg'] = '缺少大图关联id'; $this->ajaxReturn($result); } $item['link_id'] = $link_id; if ($magic['url'] == '/pages/details/details') { $goods = M('retail_goods')->where(array('id' => $link_id, 'status' => array('neq', 2), 'store_id' => $storeid))->find(); if (empty($goods)) { $result['status'] = 0; $result['msg'] = 'id为' . $link_id . '的商品不存在'; $this->ajaxReturn($result); } else if ($goods['status'] == 1) { $result['status'] = 0; $result['msg'] = 'id为' . $link_id . '的商品未上架'; $this->ajaxReturn($result); } else if ($goods['online_state'] != 1) { $result['status'] = 0; $result['msg'] = 'id为' . $link_id . '的商品未在商城出售'; $this->ajaxReturn($result); } } $item['url'] = $magic['url']; } $item['magic_type'] = $magic_type; if ($magic_type == 1) { for ($i = 1; $i < 4; $i++) { if ($files['magic_icon_' . $i]['error'] === 0) { if (!is_uploaded_file($_FILES['magic_icon_' . $i]['tmp_name'])) { $result['status'] = 0; $result['msg'] = '小图' . $i . '上传失败'; $this->ajaxReturn($result); } else { $isUploads = true; } } else if (empty($post['child_img_id_' . $i]) && empty($post['child_img_' . $i])) { $result['status'] = 0; $result['msg'] = '请上传小图' . $i; $this->ajaxReturn($result); } else { $item['child_img_' . $i] = $post['child_img_' . $i] ? $post['child_img_' . $i] : ''; $item['child_img_id_' . $i] = $post['child_img_id_' . $i] && $post['child_img_id_' . $i] != 0 ? $post['child_img_id_' . $i] : ''; } $mc_id_other = $post['type_url_' . $i]; $magic = M('magic_cube')->where(array('id' => $mc_id_other))->find(); $item['mc_id_' . $i] = $mc_id_other; if ($magic['type'] == 1) { //需要关联id $link_id_other = $post['link_id_' . $i]; if (empty($link_id_other)) { $result['status'] = 0; $result['msg'] = '缺少小图' . $i . '关联id'; $this->ajaxReturn($result); } $item['link_id_' . $i] = $link_id_other; if ($magic['url'] == '/pages/details/details') { $goods = M('retail_goods')->where(array('id' => $link_id_other, 'status' => array('neq', 2), 'store_id' => $storeid))->find(); if (empty($goods)) { $result['status'] = 0; $result['msg'] = 'id为' . $link_id_other . '的商品不存在'; $this->ajaxReturn($result); } else if ($goods['status'] == 1) { $result['status'] = 0; $result['msg'] = 'id为' . $link_id_other . '的商品未上架'; $this->ajaxReturn($result); } else if ($goods['online_state'] != 1) { $result['status'] = 0; $result['msg'] = 'id为' . $link_id_other . '的商品未在商城出售'; $this->ajaxReturn($result); } } $item['url_' . $i] = $magic['url']; } } } if ($isUploads) { $updata = array( 'add_time' => time(), 'from_type_id' => 31, 'localUrl' => 'Store/MagicCube', 'user_type' => 4, 'merchant_id' => $user['merchantid'], 'store_id' => $storeid ); $uploads = uploadFiles($updata); if ($files['magic_icon']['error'] === 0 && empty($uploads['magic_icon'])) { $result['status'] = 0; $result['msg'] = '大图上传失败'; $this->ajaxReturn($result); } else if (!empty($uploads['magic_icon'])) { $item['child_img'] = $uploads['magic_icon']['savePath']; $item['child_img_id'] = $uploads['magic_icon']['id']; } if ($magic_type == 1) { for ($i = 1; $i < 4; $i++) { if ($files['magic_icon_' . $i]['error'] === 0 && empty($uploads['magic_icon_' . $i])) { $result['status'] = 0; $result['msg'] = '小图' . $i . '上传失败'; $this->ajaxReturn($result); } else if (!empty($uploads['magic_icon_' . $i])) { $item['child_img_' . $i] = $uploads['magic_icon_' . $i]['savePath']; $item['child_img_id_' . $i] = $uploads['magic_icon_' . $i]['id']; } } } } if (!$id) { $item['addtime'] = time(); $item['status'] = 1; $add = M('magic_store')->add($item); if ($add) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '智慧魔方-添加魔方'; //操作行为描述 action_log($source, $type, $request_data, $desc); } } else { $add = M('magic_store')->where(array('id' => $id))->save($item); if ($add) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '智慧魔方-编辑'; //操作行为描述 action_log($source, $type, $request_data, $desc); } } $result['item'] = $item; if ($add) { $result['status'] = 1; $result['msg'] = '创建成功'; } else { $result['status'] = 0; $result['msg'] = '创建失败,请重试'; } $this->ajaxReturn($result); } //删除魔方 public function delMagic() { $id = I('post.id'); $storeid = session('storeid'); $map['id'] = $id; $map['storeid'] = $storeid; $magic = M('magic_store')->where($map)->find(); if (empty($magic)) { $result['status'] = 0; $result['msg'] = '魔方与门店不匹配'; $this->ajaxReturn($result); } $del = M('magic_store')->where($map)->delete(); if ($del) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '智慧魔方-删除'; //操作行为描述 action_log($source, $type, $request_data, $desc); $result['status'] = 1; $result['msg'] = '删除成功'; $delFile = delFile('.' . $magic['child_img']); $delFile1 = delFile('.' . $magic['child_img_1']); $delFile2 = delFile('.' . $magic['child_img_2']); $delFile3 = delFile('.' . $magic['child_img_3']); } else { $result['status'] = 0; $result['msg'] = '删除失败'; } $this->ajaxReturn($result); } //自提提货码 public function lading() { $id = I('post.id'); $code = I('post.ladingcode'); //提货码 $orderinfo = M('retail_bill')->where(array('id' => $id))->find(); if ($orderinfo['pickcode'] != $code) { $res['status'] = 0; $res['msg'] = '提货码有误,请重新输入'; } else { if ($orderinfo['have_away'] == 1) { $res['status'] = 0; $res['msg'] = '该订单已完成提货'; } else { //通过订单编号修改订单状态及自提状态 $data['status'] = 3; $data['have_away'] = 1; $data['pickcode'] = ""; $change = M('retail_bill')->where(array('id' => $id))->save($data); if ($change) { $res['status'] = 1; $res['msg'] = '提货成功'; } else { $res['status'] = 0; $res['msg'] = '提货失败'; } } } $this->ajaxReturn($res); } //导出商城普通订单 public function export() { $storeid = session('storeid'); $w['b.store_id'] = $storeid; $w['b.type'] = 1; //商城出售 $w['b.pay_state'] = 1; $w['b.order_type'] = 1; $w['b.pay_type'] = array('in', '5,6,8'); $time = I('get.date'); if (!empty($time)) { $time = explode(',', $time); $start_time = strtotime($time[0]); $end_time = strtotime($time[1]); $w['b.add_time'] = array('between', array($start_time, $end_time)); } //单号 $title = I('get.title'); if (!empty($title)) { $w['b.order_no'] = $title; } $card = I('get.card'); //会员卡号 if ($card) { $w['v.mobile_phone|v.card_key|v.cardnum'] = array('like', '%' . $card . '%'); } if (I('get.user_type') == 1) { $w['b.vid'] = array('gt', 0); } else if (I('get.user_type') == 2) { $w['b.vid'] = array(array('exp', 'IS NULL'), 0, 'OR'); } $pay = I('get.pay'); //付款方式 if (!empty($pay)) { $w['b.pay_type'] = $pay; } $w['o.order_genre'] = 1; $orderList = M('retail_bill_order')->alias('b') ->join('ls_retail_bill_online as o on b.id=o.bill_id') ->join('ls_retail_bill_discount as d on b.id=d.bill_id') ->join('ls_retail_vip as v on b.vid=v.id', 'LEFT') ->field('b.*,o.*,d.*,v.mobile_phone,v.name') ->where($w) ->order('b.add_time desc') ->select(); $coupon_name = [ '门店优惠券:', '会员优惠券:', '微信商家券:', ]; foreach ($orderList as $k => &$v) { $v['index'] = $k + 1; $v['add_time'] = date('Y-m-d H:i', $v['add_time']); //支付方式 if ($v['pay_type'] == 1) { $v['payname'] = '现金'; } else if ($v['pay_type'] == 2) { $v['payname'] = '银行卡'; } else if ($v['pay_type'] == 3) { $v['payname'] = '微信支付'; } else if ($v['pay_type'] == 4) { $v['payname'] = '支付宝支付'; } else if ($v['pay_type'] == 5) { $v['payname'] = '会员卡支付'; } else if ($v['pay_type'] == 6) { $v['payname'] = '小程序微信支付'; } else { $v['payname'] = '未支付'; } $v['isneedsend_name'] = $v['pickup_type'] == 2 ? '配送' : ($v['pickup_type'] == 3 ? '快递' : '自取'); $coupon_money = ''; if ($v['coupon_money'] > 0) { $coupon_money .= $coupon_name[$v['coupon_type'] - 1] . floatval($v['coupon_money']); } if ($v['pay_coupon_fee'] > 0) { $coupon_money .= '微信代金券:' . floatval($v['pay_coupon_fee']); } $v['coupon_money'] = $coupon_money; //未发货 if ($v['order_type'] == 2) { $v['have_away'] = '退款订单'; $v['all_money'] = -$v['all_money']; } else { if ($v['status'] == 1) { //正常买单 if ($v['refund_status'] == 0) { //自提 if ($v['pickup_type'] == 1) { $v['have_away'] = '待自提'; } else if ($v['pickup_type'] == 2) { $v['have_away'] = '待配送'; } } else if ($v['refund_status'] == 1) { //申请退款 $v['have_away'] = '待商家确认退款'; } else if ($v['refund_status'] == 2) { $v['have_away'] = '退款成功'; } else if ($v['refund_status'] == 3) { $v['have_away'] = '退款成功'; } } else if ($v['status'] == 2) { //已发货 $v['have_away'] = '配送中'; } else if ($v['status'] == 3) { if ($v['refund_status'] == 1) { $v['have_away'] = '待商家确认退款'; } else if ($v['refund_status'] == 2) { $v['have_away'] = '退款成功'; } else if ($v['refund_status'] == 3) { $v['have_away'] = '退款成功'; } else { $v['have_away'] = '已完成'; } } } $v['name'] = $v['user_name']; $v['phone'] = $v['user_phone']; if ($v['pickup_type'] == 2 || $v['pickup_type'] == 3) { //配送、快递 $v['address'] = $v['user_address']; } else { $v['address'] = '到店自提'; } $out_trade_no = D("RetailPayOrder")->getFindField(array('bill_id' => $v['id'], 'order_state' => array('in', 'SUCCESS,REFUND')), "out_trade_no", true); if (!empty($out_trade_no)) { $v['out_trade_no'] = implode(',', $out_trade_no); } else { $v['out_trade_no'] = ''; } } $filename = '商城订单明细'; $str = $filename . '导出时间:' . date('Y-m-d H:i:s', time()); $headArray = array( array('index', '序号'), array('order_no', '单号'), array('out_trade_no', '内部订单号'), array('mobile_phone', '会员号'), array('payname', '付款方式'), array('all_money', '金额'), array('coupon_money', '优惠券减免'), array('vip_dis_money', '折扣金额'), array('add_time', '时间'), array('isneedsend_name', '配送/自取/快递'), array('name', '联系人'), array('phone', '联系人手机号码'), array('address', '地址'), array('have_away', '状态'), ); $this->getExcel($filename, $headArray, $orderList, $str); } //导出方法 private function getExcel($expTitle, $expCellName, $expTableData, $str = "") { $xlsTitle = iconv('utf-8', 'gb2312', $expTitle); //文件名称 $fileName = $expTitle . date('_YmdHis'); //or $xlsTitle 文件名称可根据自己情况设定 $cellNum = count($expCellName); $dataNum = count($expTableData); $common = $str; vendor("PHPExcel.PHPExcel"); ob_clean(); $objPHPExcel = new \PHPExcel(); $cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ'); $objPHPExcel->getActiveSheet(0)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1'); //合并单元格 $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $common); // $objPHPExcel->setActiveSheetIndex(1)->setCellValue('A1', $str); for ($i = 0; $i < $cellNum; $i++) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '2', $expCellName[$i][1]); } for ($i = 0; $i < $dataNum; $i++) { for ($j = 0; $j < $cellNum; $j++) { $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 3), ' ' . $expTableData[$i][$expCellName[$j][0]]); } } foreach ($cellName as $value) { $objPHPExcel->getActiveSheet()->getColumnDimension($value)->setWidth(20); } header('pragma:public'); header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"'); header("Content-Disposition:attachment;filename=$fileName.xls"); //attachment新窗口打印inline本窗口打印 $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit(); } //设置图标 public function setIcon() { $user = session('ls_userinfo'); $storeid = session('storeid'); $home_back_icon_id = I('post.home_back_icon_id'); $home_tel_icon_id = I('post.home_tel_icon_id'); $home_support_icon_id = I('post.home_support_icon_id'); if ($storeid) { if (!empty($_FILES) && ($_FILES['home_back_icon']['error'] == 0 || $_FILES['home_tel_icon']['error'] == 0 || $_FILES['home_support_icon']['error'] == 0)) { $item = array( 'add_time' => time(), 'from_type_id' => 29, 'localUrl' => 'Store/MallIcon', 'user_type' => 4, 'merchant_id' => $user['merchantid'], 'store_id' => $storeid ); $uploads = uploadFiles($item); } if (!empty($uploads['home_back_icon'])) { $save['home_back_icon_id'] = $uploads['home_back_icon']['id']; } else if ($home_back_icon_id) { $save['home_back_icon_id'] = $home_back_icon_id; } if (!empty($uploads['home_tel_icon'])) { $save['home_tel_icon_id'] = $uploads['home_tel_icon']['id']; } else if ($home_tel_icon_id) { $save['home_tel_icon_id'] = $home_tel_icon_id; } if (!empty($uploads['home_support_icon'])) { $save['home_support_icon_id'] = $uploads['home_support_icon']['id']; } else if ($home_support_icon_id) { $save['home_support_icon_id'] = $home_support_icon_id; } if (!empty($save)) { $config = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); if (!empty($config)) { $update = M('store_xcx_config')->where(array('storeid' => $storeid))->save($save); } else { $save['storeid'] = $storeid; $update = M('store_xcx_config')->add($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['status'] = 1; $res['msg'] = '修改成功'; } else { $res['status'] = 0; $res['msg'] = '修改失败'; } } else { $res['status'] = 0; $res['msg'] = '您未修改数据'; } } else { $res['status'] = 0; $res['msg'] = '登录超时'; } $this->ajaxReturn($res); } public function navigation() { $arr = array( 'set_navigation' => '/index.php/Retail/Xcx/set_navigation', 'del_navigation' => '/index.php/Retail/Xcx/del_navigation', 'update_status' => '/index.php/Retail/Xcx/update_status', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } // 获取数据 public function getNavigation() { $user = session('ls_userinfo'); $storeid = session('storeid'); $where['storeid'] = $storeid; $where['merchantid'] = $user['merchantid']; $info = M('retail_xcx_navigation')->where($where)->page((int)$_POST['page'], (int)$_POST['limit'])->order('id desc')->select(); $count = M('retail_xcx_navigation')->where($where)->count(); if (!empty($info)) { $index = 1; foreach ($info as $key => &$val) { $val['index'] = $index++; $val['use'] = 1; $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']); /* 图片 */ if ($val['icon_id']) { $val['icon'] = M('image_gallery')->where(array('id' => $val['icon_id']))->getField('path'); } if ($val['navigation_type'] == 1) { $val['navigation_name'] = '其他链接'; $val['skip'] = $val['other_url']; $val['link'] = '无'; } else if ($val['navigation_type'] == 2) { $val['navigation_name'] = '商品分类'; if (!empty($val['goods_class_id'])) { $val['skip'] = M('retail_goods_class')->where(array('id' => $val['goods_class_id']))->getField('class_name'); $val['link'] = '无'; } } else if ($val['navigation_type'] == 3) { $val['navigation_name'] = '功能入口'; if (!empty($val['magic_cube_id'])) { $magic = M('magic_cube')->where(array('id' => $val['magic_cube_id']))->field('name,url,type')->find(); if ($magic['type'] == 2) { $val['skip'] = $magic['name']; $val['link'] = '无'; } else if ($magic['type'] == 1 && $magic['url'] == '/pages/details/details' && !empty($val['goods_id'])) { // 跳转商品 $val['skip'] = $magic['name']; $val['link'] = M('retail_goods')->where(array('id' => $val['goods_id']))->getField('goods_name'); } $plug_state = $this->plug_state(); if ($magic['url'] == '/pages/Group-purchase/Group-purchase') { if ($plug_state['group_status'] == false) { $val['use'] = 2; } } if ($magic['url'] == '/pages/Seckill-purchase/Seckill-purchase') { if ($plug_state['seckill_status'] == false) { $val['use'] = 2; } } if ($magic['url'] == '/pages/gift_home/gift_home') { if ($plug_state['gift_card_status'] == false) { $val['use'] = 2; } } } } } } $res['code'] = 0; $res['data'] = $info; $res['count'] = $count; $this->ajaxReturn($res); } // 删除导航 public function del_navigation() { if (IS_POST) { $id = I('post.id'); if (!empty($id)) { $delete_res = M('retail_xcx_navigation')->where(array('id' => $id))->delete(); if (!empty($delete_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); $res['status'] = 1; $res['msg'] = '删除成功'; } else { $res['status'] = 0; $res['msg'] = '删除失败'; } } else { $res['status'] = 0; $res['msg'] = '缺失参数'; } $this->ajaxReturn($res); } } // 修改状态 public function update_status() { if (IS_POST) { $id = I('post.id'); $status = I('post.status'); if (!empty($id) && !empty($status)) { $xcx_navigation_find = M('retail_xcx_navigation')->where(array('id' => $id, 'status' => array('neq', $status)))->find(); if (!empty($xcx_navigation_find)) { $xcx_navigation_save = M('retail_xcx_navigation')->where(array('id' => $id))->setField('status', $status); if (!empty($xcx_navigation_save)) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 if ($status == 1) { $desc = '分类导航-启用导航'; //操作行为描述 } elseif ($status == 2) { $desc = '分类导航-关闭导航'; //操作行为描述 } action_log($source, $type, $request_data, $desc); $res['status'] = 1; $res['msg'] = '修改成功'; } else { $res['status'] = 0; $res['msg'] = '修改失败'; } } else { $res['status'] = 0; $res['msg'] = '查询失败'; } } else { $res['status'] = 0; $res['msg'] = '参数缺失'; } $this->ajaxReturn($res); } } // 判断拼团 秒杀插件状态 private function plug_state() { $storeid = session('storeid'); $user = session('ls_userinfo'); // 判断是否有拼团插件 门店是否开启了拼团插件 // 拼团插件 $store_xcx_config = M('store_xcx_config')->where(array('storeid' => $storeid))->find(); $plug_group_status = M('plug as p') ->join('ls_plug_store as s on p.id=s.plug_id') ->where(array('p.plug_name' => '拼团', 'p.status' => 1, 's.storeid' => $storeid)) ->getField('s.s_status'); if ($plug_group_status == 1) { $res['group_status'] = $store_xcx_config['group_status'] == 1 ? true : false; } else { $res['group_status'] = false; } // 秒杀插件 $plug_seckill_status = M('plug as p') ->join('ls_plug_store as s on p.id=s.plug_id') ->where(array('p.plug_name' => '秒杀', 'p.status' => 1, 's.storeid' => $storeid)) ->getField('s.s_status'); if ($plug_seckill_status == 1) { $res['seckill_status'] = $store_xcx_config['seckill_status'] == 1 ? true : false; } else { $res['seckill_status'] = false; } //预售插件 $advance_status = M('plug as p') ->join('ls_plug_store as s on p.id=s.plug_id') ->where(array('p.id' => 45, 'p.status' => 1, 's.storeid' => $storeid)) ->getField('s.s_status'); if ($advance_status == 1) { $res['advance_status'] = $store_xcx_config['advance_sale_status'] == 1 ? true : false; } else { $res['advance_status'] = false; } // 礼品卡插件 $plug_gift_card_status = M('plug as p') ->join('ls_plug_merchant as m on p.id=m.plug_id') ->where(array('p.plug_name' => '礼品卡', 'p.status' => 1, 'm.merchant_id' => $user['merchantid'])) ->getField('m.m_status'); $res['gift_card_status'] = $plug_gift_card_status == 1 ? true : false; // 次卡插件 $plug_sub_card_status = M('plug as p') ->join('ls_plug_merchant as m on p.id=m.plug_id') ->where(array('p.plug_name' => '次卡', 'p.status' => 1, 'm.merchant_id' => $user['merchantid'])) ->getField('m.m_status'); $res['plug_sub_card_status'] = $plug_sub_card_status == 1 ? true : false; // plus会员 $plus_status = M('retail_plus_set')->where(array('merchantid' => $user['merchantid']))->getField('switch_type'); $res['plus_status'] = $plus_status == 2 ? true : false; return $res; } /** * 设置导航栏 * @param * @return array * */ public function set_navigation($id) { $this->assign('id', $id); $this->display(); } /** * 获取导航栏 * @param $id id * @return array * */ public function get_navigation() { $id = I('post.id'); if (!$id) { $res['status'] = 0; $res['msg'] = '参数缺失,请重新加载'; $this->ajaxReturn($res); } $navigation = M('retail_xcx_navigation')->field('id,title,icon,icon_id,navigation_type,goods_class_id,magic_cube_id,goods_id,other_url,status,rank')->where(array('id' => $id))->find(); if ($navigation) { /* 查询图片 */ if ($navigation['icon_id']) { $navigation['icon'] = M('image_gallery')->where(array('id' => $navigation['icon_id']))->getField('path'); } /* 查询商品 */ if ($navigation['navigation_type'] == 3) { // 功能入口 $magic_cube = M('magic_cube')->where(array('id' => $navigation['magic_cube_id'], 'status' => 1, 'state' => 1))->find(); if (!$magic_cube) { $res['status'] = 0; $res['msg'] = '功能查询失败'; $this->ajaxReturn($res); } if ($magic_cube['type'] == 1 && $magic_cube['url'] == '/pages/details/details') { $mark = 1; /* 查询商品 */ if ($navigation['goods_id']) { $navigation['goods_name'] = M('retail_goods')->where(array('id' => $navigation['goods_id']))->getField('goods_name'); } } } else if ($navigation['navigation_type'] == 2) { //6.处理商品分类 $GoodsClassifyApi = new GoodsClassify(); $class_list = array(); $GoodsClassifyApi->getAppointGoodsClassList($navigation['goods_class_id'], $class_list); $navigation['unitClassData'] = $class_list; } $res['status'] = 1; $res['mark'] = $mark ? 1 : 0; $res['data'] = $navigation; } else { $res['status'] = 0; $res['msg'] = '查询失败'; } $this->ajaxReturn($res); } /** * 获取功能 * @return array * */ public function get_magic_cube() { $magic_cube = M('magic_cube')->field('addtime', true)->where(array('status' => 1, 'state' => 1))->select(); if ($magic_cube) { $plug_state = $this->plug_state(); // 查询插件状态 $new_magic_cube = array(); foreach ($magic_cube as $key => $val) { /* 拼团状态 */ if ($val['url'] == '/pages/Group-purchase/Group-purchase') { if ($plug_state['group_status'] != false) { array_push($new_magic_cube, $val); } } else if ($val['url'] == '/pages/Seckill-purchase/Seckill-purchase') { /* 秒杀状态 */ if ($plug_state['seckill_status'] != false) { array_push($new_magic_cube, $val); } } else if ($val['url'] == '/pages/advanceSale/advanceSale') { //预售插件 if ($plug_state['advance_status'] != false) { array_push($new_magic_cube, $val); } } else if ($val['url'] == '/pages/gift_home/gift_home') { /* 礼品卡状态 */ if ($plug_state['gift_card_status'] != false) { array_push($new_magic_cube, $val); } } else if ($val['url'] == '/pages/plusHome/plusHome') { /* 判断plus会员状态 */ if ($plug_state['plus_status'] != false) { array_push($new_magic_cube, $val); } } else if ($val['url'] == '/pages/gift_home/gift_home') { /* 判断营销次卡状态 */ if ($plug_state['plug_sub_card_status'] != false) { array_push($new_magic_cube, $val); } } else { array_push($new_magic_cube, $val); } } $res['status'] = 1; $res['magic_cube'] = $magic_cube; } else { $res['status'] = 0; $res['msg'] = '未查询到可用的功能入口'; } $this->ajaxReturn($res); } /** * 保存导航栏设置 * @param $_POST * @return array * */ public function save_set_navigation() { $data = json_decode($_POST['data'], true); if (!$data['title'] || !$data['icon'] || !$data['navigation_type']) { $this->ajaxReturn(['status' => 0, 'msg' => '请完善表单']); } switch ($data['navigation_type']) { case 1: if (!$data['other_url']) { $this->ajaxReturn(['status' => 0, 'msg' => '请完善其他链接地址']); } break; case 2: if (!$data['goods_class_id']) { $this->ajaxReturn(['status' => 0, 'msg' => '请选择分类']); } /* 查询分类 */ $class_goods_data = D('RetailGoodsClass')->getFind(['id' => $data['goods_class_id'], 'merchantid' => $this->merchant_id, 'status' => 0, 'type' => 1]); if (!$class_goods_data) { $this->ajaxReturn(['status' => 0, 'msg' => '未知的商品分类,请确定该分类是否存在']); } break; case 3: if (!$data['magic_cube_id']) { $this->ajaxReturn(['status' => 0, 'msg' => '请选择功能入口']); } $magic = M('magic_cube')->where(array('id' => $data['magic_cube_id'], 'status' => 1, 'state' => 1))->find(); if (!$magic) { $this->ajaxReturn(['status' => 0, 'msg' => '未知的功能入口']); } /* 有关联ID */ if ($magic['type'] == 1) { if (!$data['goods_id']) { $this->ajaxReturn(['status' => 0, 'msg' => '请选择商品']); } /* 商品详情 */ if ($magic['url'] == '/pages/details/details') { $data['type'] = 1; // 标识 关联商品 $goods = D('RetailGoods')->getFind(['id' => $data['goods_id'], 'status' => array('neq', 2), 'storeid' => $this->store_id]); if (!$goods) { $this->ajaxReturn(['status' => 0, 'msg' => '未查询到该商品信息']); } else if ($goods['status'] == 1) { $this->ajaxReturn(['status' => 0, 'msg' => '该商品暂未上架']); } else if ($goods['online_state'] != 1) { $this->ajaxReturn(['status' => 0, 'msg' => '该商品未在商城出售']); } } } break; default: $this->ajaxReturn(['status' => 0, 'msg' => '未知的功能类型']); } /* 上传图片 */ if (!$data['icon_id']) { $this->ajaxReturn(['status' => 0, 'msg' => '请选择图片']); } if (!$data['id']) { // 添加 $res = $this->create_navigation($data); if ($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); } } else { // 修改 $res = $this->update_navigation($data); if ($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); } } $this->ajaxReturn($res); } /** * 添加导航栏 * @param $data 数据 * @param $merchantid 商户id * @param $store_id 门店id * @return array * */ private function create_navigation($data) { $add['storeid'] = $this->store_id; $add['merchantid'] = $this->merchant_id; $add['title'] = $data['title']; $add['icon_id'] = $data['icon_id']; $add['navigation_type'] = $data['navigation_type']; if ($data['navigation_type'] == 1) { $add['other_url'] = $data['other_url']; } else if ($data['navigation_type'] == 2) { $add['goods_class_id'] = $data['goods_class_id']; } else if ($data['navigation_type'] == 3) { $add['magic_cube_id'] = $data['magic_cube_id']; $add['goods_id'] = $data['type'] && $data['type'] == 1 ? $data['goods_id'] : ''; } $add['rank'] = $data['rank'] && $data['rank'] > 0 ? $data['rank'] : 1; $add['status'] = $data['status'] ? $data['status'] : 1; $add['addtime'] = time(); $cr = M('retail_xcx_navigation')->add($add); if ($cr) { $res['status'] = 1; $res['msg'] = '添加成功'; } else { $res['status'] = 0; $res['msg'] = '添加失败'; } return $res; } /** * 编辑导航栏 * @param $data 数据 * @param $merchantid 商户id * @param $store_id 门店id * @return array * */ private function update_navigation($data) { $find = M('retail_xcx_navigation')->where(array('id' => $data['id'], 'merchantid' => $this->merchant_id, 'storeid' => $this->store_id))->find(); if (!$find) { $res['status'] = 0; $res['msg'] = '未查询到该条信息'; return $res; } if ($find['title'] != $data['title']) { $up['title'] = $data['title']; } if ($find['icon_id'] != $data['icon_id']) { $up['icon_id'] = $data['icon_id']; } if ($find['navigation_type'] != $data['navigation_type']) { // 类型改变 $up['navigation_type'] = $data['navigation_type']; if ($find['navigation_type'] == 1) { $up['other_url'] = ''; } else if ($find['navigation_type'] == 2) { $up['goods_class_id'] = ''; } else if ($find['navigation_type'] == 3) { $up['magic_cube_id'] = ''; $up['goods_id'] = ''; } if ($data['navigation_type'] == 1) { $up['other_url'] = $data['other_url']; } else if ($data['navigation_type'] == 2) { $up['goods_class_id'] = $data['goods_class_id']; } else if ($data['navigation_type'] == 3) { $up['magic_cube_id'] = $data['magic_cube_id']; $up['goods_id'] = $data['type'] && $data['type'] == 1 ? $data['goods_id'] : ''; } } else { // 类型未变 if ($find['navigation_type'] == 1) { if ($find['other_url'] != $data['other_url']) { $up['other_url'] = $data['other_url']; } } else if ($find['navigation_type'] == 2) { if ($find['goods_class_id'] != $data['goods_class_id']) { $up['goods_class_id'] = $data['goods_class_id']; } } else if ($find['navigation_type'] == 3) { if ($find['magic_cube_id'] != $data['magic_cube_id']) { $up['magic_cube_id'] = $data['magic_cube_id']; $up['goods_id'] = $data['type'] && $data['type'] == 1 ? $data['goods_id'] : ''; } else { if ($find['goods_id'] && $data['type'] == 1 && $find['goods_id'] != $data['goods_id']) { $up['goods_id'] = $data['goods_id']; } } } } if ($data['status'] && $find['status'] != $data['status']) { $up['status'] = $data['status']; } if ($data['rank'] && $data['rank'] > 0 && $find['rank'] != $data['rank']) { $up['rank'] = $data['rank']; } if (!$up) { $res['status'] = 0; $res['msg'] = '请先修改提交数据'; return $res; } $save = M('retail_xcx_navigation')->where(array('id' => $data['id']))->save($up); if ($save) { $res['status'] = 1; $res['msg'] = '修改成功'; } else { $res['status'] = 0; $res['msg'] = '修改失败'; } return $res; } /* * 门店id获取打印所需 */ public function storeIdGet() { $store_id = session("storeid"); $order_id = I('post.order_id'); if (!$store_id || !$order_id) { $res['status'] = 0; $res['msg'] = '登录超时,请刷新页面'; $this->ajaxReturn($res); } $res = A('PayApi/Printer')->linePrinting_v1($store_id, $order_id, true); $this->ajaxReturn($res); } /** * 新推荐商品 * 获取推荐商品状态 * @return [array] $res */ public function getRecommendStatus() { // 门店id $storeid = I('session.storeid'); if (!$storeid) { $res = array('status' => 0, 'msg' => '登录超时,请重新登录'); $this->ajaxRetrun($res); } $recommend_status = D('StoreXcxConfig')->getFindField(array('storeid' => $storeid), 'recommend_status'); if ($recommend_status) { $res = array('status' => 1, 'recommend_status' => $recommend_status); } else { $res = array('status' => 0, 'msg' => '查询失败'); } $this->ajaxReturn($res); } /** * @param [array] $recommend_status 商城推荐商品状态 * @return [array] $res */ public function setRecommendStatus() { // 门店id $storeid = I('session.storeid'); if (!$storeid) { $res = array('status' => 0, 'msg' => '登录超时,请重新登录'); $this->ajaxRetrun($res); } // 开启,关闭状态 $recommend_status = I('post.recommend_status'); // 查询门店是否存在 $find = D('StoreXcxConfig')->getFind(array('storeid' => $storeid)); if (!$find) { // 添加 $item['storeid'] = $storeid; $item['recommend_status'] = $recommend_status; $item['addtime'] = time(); $add = D('StoreXcxConfig')->addOrder($item); if (!$add) { $res = array('status' => 0, 'msg' => '设置失败'); } else { $res = array('status' => 1, 'msg' => '设置成功'); } } else { // 修改 if ($find['recommend_status'] != $recommend_status) { $save = D('StoreXcxConfig')->updateConfig(array('storeid' => $storeid), array('recommend_status' => $recommend_status)); if ($save) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 if ($recommend_status == 0) { $desc = '推荐商品-关闭推荐商品'; //操作行为描述 } elseif ($recommend_status == 1) { $desc = '推荐商品-开启推荐商品'; //操作行为描述 } action_log($source, $type, $request_data, $desc); $res = array('status' => 1, 'msg' => '设置成功'); } else { $res = array('status' => 0, 'msg' => '设置失败'); } } else { $res = array('status' => 0, 'msg' => '请先提交修改数据'); } } $this->ajaxReturn($res); } /** * 获取推荐商品 * @param [int] $page 分页 * @param [int] $limit 数量 * @return [array] $res */ public function getRecommendGoods() { // 实例化模型 $hostModel = D('Host'); $goodsModel = D('Goods'); $storeid = I('session.storeid'); if (!$storeid) { $res = array('status' => 0, 'msg' => '登录超时'); $this->ajaxReturn($res); } $page = (int)I('post.page'); $limit = (int)I('post.limit'); $map = array('storeid' => $storeid, 'status' => 1, 'type' => 1); // $recommend_goods = $hostModel->getGoodsList($map,$page,$limit,'h.id,h.addtime,h.sort,g.goods_name,g.goods_number,g.goods_code,g.online_price,g.','h.sort asc,h.addtime desc'); $recommend_goods = $hostModel->getSelect($map, $page, $limit, 'id,goods_id,addtime,sort', 'sort asc,addtime desc'); if (!$recommend_goods) { $res = array('status' => 0, 'msg' => '暂无数据'); $this->ajaxReturn($res); } $total = D('Host')->total($map); foreach ($recommend_goods as &$val) { $goods = $goodsModel->getFind(array('id' => $val['goods_id'], 'status' => array('in', '0,1,2')), 'goods_name,goods_number,goods_code,online_price,status'); $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']); $val['goods_name'] = $goods['goods_name'] ? $goods['goods_name'] : '未知商品'; $val['goods_number'] = $goods['goods_number'] ? $goods['goods_number'] : '无'; $val['goods_code'] = $goods['goods_code'] ? $goods['goods_code'] : '无'; $val['online_price'] = floatval($goods['online_price']); if ($goods['status'] == 0) { $val['goods_type'] = '正常商品'; } else if ($goods['status'] == 1) { $val['goods_type'] = '商品已下架'; } else { $val['goods_type'] = '商品已删除'; } unset($goods); } $res = array('status' => 1, 'recommend_goods' => $recommend_goods, 'total' => (int)$total); $this->ajaxReturn($res); } /** * 移除推荐商品 * @param [int] $id 推荐商品id * @return [array] $res */ public function deleteRecommendGoods() { // 实例化模型 $hostModel = D('Host'); // 判断登录 $storeid = I('session.storeid'); if (!$storeid) { $res = array('status' => 0, 'msg' => '登录超时'); $this->ajaxReturn($res); } $id = I('post.id'); if (!$id) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } // 条件 $map = array('id' => $id); // 判断数据 $find = $hostModel->getFind($map); if (!$find) { $res = array('status' => 0, 'msg' => '商品信息查询失败,请刷新重试'); $this->ajaxReturn($res); } // 删除 $del = $hostModel->toDelete($map); if ($del) { //操作日志记录 $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); } /** * 获取商城商品 * @param [array] $page 分页 * @param [array] $limit 数量 * @return [array] $res */ public function getGoodsList() { // 实例化模型 $goodsModel = D('Goods'); $hostModel = D('Host'); // 判断登录 $storeid = I('session.storeid'); if (!$storeid) { $res = array('status' => 0, 'msg' => '登录超时'); $this->ajaxReturn($res); } // 查询推荐商品 $where = array('storeid' => $storeid, 'status' => 1, 'type' => 1); $ids = $hostModel->getFindField($where, 'goods_id', true); if ($ids) { $map['id'] = array('not in', $ids); } // 搜索条件 $seek_data = I('seek_data'); // 名称搜索 if (trim($seek_data['goods_name'])) { $map['goods_name'] = array('like', '%' . trim($seek_data['goods_name']) . '%'); } // 货号、条码搜索 if (trim($seek_data['keyword'])) { $map['goods_number|goods_code'] = trim($seek_data['keyword']); } $map['store_id'] = $storeid; $map['status'] = 0; $map['online_state'] = 1; $page = (int)I('post.page') . ',' . (int)I('post.limit'); $goods_list = $goodsModel->getSelect($map, 'id,goods_name,goods_number,goods_code,online_price', 'id asc', $page); if (!$goods_list) { $res = array('status' => 0, 'msg' => '暂无商品'); $this->ajaxReturn($res); } $total = $goodsModel->getCount($map); foreach ($goods_list as &$val) { $val['online_price'] = floatval($val['online_price']); $val['good_number'] = $val['goods_number'] ? $val['goods_number'] : '无'; $val['goods_code'] = $val['goods_code'] ? $val['goods_code'] : '无'; $val['sort'] = 1; } $res = array('status' => 1, 'goods_list' => $goods_list, 'total' => (int)$total); $this->ajaxReturn($res); } /** * 批量添加推荐商品 * @parma [array] $chose_goods 选择的商品 * @return [array] $res */ public function batchAdd() { // 实例化模型 $hostModel = D('Host'); $storeModel = D('Store'); $goodsModel = D('Goods'); // 判断登录 $storeid = I('session.storeid'); if (!$storeid) { $res = array('status' => 0, 'msg' => '登录超时'); $this->ajaxReturn($res); } $merchantid = $storeModel->getFindField(array('id' => $storeid), 'merchantid'); if (!$merchantid) { $res = array('status' => 1, 'msg' => '未知的门店信息,请登录重试'); $this->ajaxReturn($res); } // 判断参数 $chose_goods = I('post.chose_goods'); if (!$chose_goods) { $res = array('status' => 0, 'msg' => '请勾选商品'); $this->ajaxReturn($res); } $time = time(); $cr['storeid'] = $storeid; $cr['merchantid'] = $merchantid; foreach ($chose_goods as &$val) { $cr1 = $cr; // 判断商品 $find = $goodsModel->getFind(array('id' => $val['id']), 'id'); if (!$find) { $res = array('status' => 0, 'msg' => '未知的商品,请刷新重试'); $this->ajaxReturn($res); } $cr1['goods_id'] = $val['id']; $cr1['sort'] = intval($val['sort']) ? intval($val['sort']) : 1; $cr1['addtime'] = $time; $add = $hostModel->toAdd($cr1); if (!$add) { $res = array('status' => 0, 'msg' => '添加失败,请刷新重试'); $this->ajaxReturn($res); } elseif ($add) { //操作日志记录 $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($cr1); unset($find); unset($add); } $res = array('status' => 1, 'msg' => '添加成功'); $this->ajaxReturn($res); } /** * 删除单个电子围栏 */ public function deleteFence() { if (IS_POST) { $id = I('post.id'); if (!$id) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } $FenceModel = new \Common\Model\StoreDeliveryFenceModel(); // 验证围栏是否属于当前门店 $fence = $FenceModel->where(['id' => $id, 'store_id' => $this->store_id])->find(); if (!$fence) { $res = array('status' => 0, 'msg' => '围栏不存在或无权限删除'); $this->ajaxReturn($res); } // 删除围栏 $result = $FenceModel->where(['id' => $id])->delete(); if ($result) { //操作日志记录 $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); } } }