$this->store_id ); $conf = $StoreXcxConfigModel->getFind($map, 'group_status,home_group_status,xcx_group_cover_id'); if (empty($conf)) { $conf['group_status'] = '2'; $conf['home_group_status'] = '2'; $conf['xcx_group_cover_id'] = ''; $conf['xcx_group_cover'] = ''; } else { //拼团封面图 $ImageGalleryModel = new ImageGalleryModel(); $conf['xcx_group_cover'] = $ImageGalleryModel->getFieldPath(array('id' => $conf['xcx_group_cover_id'])); } $this->ajaxReturn([ 'status' => 1, 'msg' => '获取成功', 'data' => $conf ]); } else { $this->display(); } } /** * 获取活动列表 */ public function getGroupList() { $platform_type = $this->role_info['platform_type']; $type = I('post.type'); //活动状态 $page = I('post.page'); //页 $limit = I('post.limit'); //每页数量 $time = time(); switch ($type) { case '1': //全部 $map['act_type'] = array('in', array(1, 2)); //不含已删除 break; case '2': //未开始 $map['start_time'] = array('gt', $time); $map['act_type'] = 1; break; case '3': //进行中 $map['start_time'] = array('elt', $time); $map['end_time'] = array('egt', $time); $map['act_type'] = 1; break; case '4': //已结束 $map['end_time'] = array('lt', $time); $map['act_type'] = 1; break; case '5': //已失效 $map['act_type'] = 2; break; default: //全部 $map['act_type'] = array('in', array(1, 2)); break; } if (I('post.keyword')) { $keyword = I('post.keyword'); $keyword_type = I('post.keyword_type'); switch ($keyword_type) { case '1': //活动名称 $key_name = 'act_name'; break; case '2': //商品名称 $key_name = 'goods_name'; break; case '3': //商品条码 $key_name = 'goods_code'; break; case '4': //商品货号 $key_name = 'goods_number'; break; default: $key_name = 'act_name'; } $map[$key_name] = array('like', "%" . $keyword . "%"); } $map['store_id'] = $this->store_id; $map['status'] = 0; // 查询活动 $RetailGroupViewModel = new RetailGroupViewModel(); $fields = [ 'id', 'goods_name', 'goods_code', 'goods_number', 'gid as goods_id', 'act_name', 'start_time', 'end_time', 'sell_number', 'act_num', 'type', 'act_type', 'act_num', 'attribute_state', 'group_skuid', ]; if ($platform_type == 2) { //第三方平台 $fields[] = 'third_goods_code'; } $list = $RetailGroupViewModel->getSelect($map, $fields, $page, $limit, 'id desc'); $count = 0; if (!empty($list)) { $count = $RetailGroupViewModel->getCount($map); $count = int($count); $Inventory = new \Api\Controller\InventoryController(); if ($platform_type == 2) { //第三方平台接口 $code_arr = []; } foreach ($list as &$val) { if ($val['act_type'] == 2) { $val['type_name'] = '已失效'; $val['act_type'] = 4; } else if ($val['act_type'] == 1 && $val['start_time'] > $time) { $val['type_name'] = '未开始'; $val['act_type'] = 1; } else if ($val['act_type'] == 1 && $val['start_time'] <= $time && $val['end_time'] >= $time) { $val['type_name'] = '进行中'; $val['act_type'] = 2; } else if ($val['act_type'] == 1 && $val['end_time'] < $time) { $val['act_type'] = 3; $val['type_name'] = '已结束'; } $val['act_time'] = date('Y-m-d H:i:s', $val['start_time']) . '至' . date('Y-m-d H:i:s', $val['end_time']); if ($platform_type == 2 && $val['attribute_state'] == 1) { $val['goods_num'] = 0; $code_arr[$val['id']] = $val['third_goods_code']; } else { $val['goods_num'] = $Inventory->goods_num(1, $this->store_id, $val['goods_id']); } } if ($platform_type == 2 && !empty($code_arr)) { //第三方平台 $ThirdGoodsClass = new Goods(); $storeResult = $ThirdGoodsClass->storeCode($this->store_id); $Customer_Codes = $storeResult['data']; $thirdResult = $ThirdGoodsClass->goodsNumQuery([ 'merchant_id' => $this->merchant_id, 'type' => 2, 'code_arr' => $code_arr, 'Customer_Codes' => $Customer_Codes ]); if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) { $goods_stock = $thirdResult['data']; foreach ($list as &$val) { if (!empty($goods_stock[$val['id']])) { $val['goods_num'] = $goods_stock[$val['id']]; } } } } } $res['status'] = 1; $res['msg'] = $list ? '获取成功' : '暂无数据'; $res['data'] = $list; $res['count'] = $count; $this->ajaxReturn($res); } /** * 获取拼团商品规格列表 * @param id 拼团活动id */ public function getGroupSkuList() { $platform_type = $this->role_info['platform_type']; $RetailGroupModel = new RetailGroupModel(); $RetailSkuGroupModel = new RetailSkuGroupModel(); $RetailSkuListModel = new RetailSkuListModel(); $Inventory = new \Api\Controller\InventoryController(); $id = I('post.id'); // 拼团商品信息 $groupInfo = $RetailGroupModel->getFind(['id' => $id, 'store_id' => $this->store_id]); if (empty($groupInfo)) { $this->ajaxReturn(['status' => 0, 'msg' => '该活动不存在']); } // 拼团商品规格id $skuList = $RetailSkuGroupModel->getSelect(['id' => ['in', $groupInfo['group_skuid']]], 'id,sku_id,goods_id,actnum as act_num,sku_id_list'); // 循环获取具体规格名字 if ($platform_type == 2) { //第三方平台 $code_arr = []; $GoodsModel = new RetailGoodsModel(); $SkuGoodsModel = new RetailSkuGoodsModel(); } foreach ($skuList as $key => &$value) { $skuIdList = explode(',', $value['sku_id_list']); $skuIdName = []; foreach ($skuIdList as $val) { $skuIdName[] = $RetailSkuListModel->getFindField(['id' => $val], 'name'); } if ($platform_type == 2) { $value['goods_num'] = 0; if (!empty($value['sku_id'])) { $code_arr[$value['id']] = $SkuGoodsModel->getFindField([ 'id' => $value['sku_id'] ], 'third_goods_code'); } else { $code_arr[$value['id']] = $GoodsModel->getFindField([ 'id' => $value['goods_id'] ], 'third_goods_code'); } } else { $value['goods_num'] = $Inventory->goods_num(1, $this->store_id, $value['goods_id'], $value['sku_id']); } $value['sku_name'] = implode(",", $skuIdName); unset($value['sku_id_list']); } if ($platform_type == 2 && !empty($code_arr)) { $GoodsClass = new Goods(); $storeResult = $GoodsClass->storeCode($this->store_id); $Customer_Codes = $storeResult['data']; $thirdResult = $GoodsClass->goodsNumQuery([ 'merchant_id' => $this->merchant_id, 'code_arr' => $code_arr, 'type' => 2, 'Customer_Codes' => $Customer_Codes ]); if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) { $goods_stock = $thirdResult['data']; foreach ($skuList as &$val) { $val['goods_num'] = $goods_stock[$val['id']]; } } } $this->ajaxReturn(['status' => 1, 'msg' => '规格列表获取成功', 'data' => $skuList]); } /** * 更改拼团库存 * @param id 活动id * @param type 操作类型 1增加 2减少 * @param group_sku_id 拼团规格ID * @param sku_id 商品规格ID * @param operate_num 操作数量 */ public function updateGroupInventory() { $platform_type = $this->role_info['platform_type']; $GroupModel = new RetailGroupModel(); $Inventory = new \Api\Controller\InventoryController(); $id = I('post.id'); $type = I('post.type'); $group_sku_id = I('post.group_sku_id'); $sku_id = I('post.sku_id'); $operateNum = I('post.operate_num'); if (!$id || !empty($group_sku_id) && empty($sku_id) || empty($group_sku_id) && !empty($sku_id)) { $this->ajaxReturn(['status' => 0, 'msg' => '必要参数缺失']); } if (!verifyNumber($operateNum)) { $this->ajaxReturn(['status' => 0, 'msg' => '请输入正确的数量']); } $where = [ 'id' => $id, 'store_id' => $this->store_id, ]; $groupInfo = $GroupModel->getFind($where); if (!$groupInfo) { $this->ajaxReturn(['status' => 0, 'msg' => '数据有误,请刷新重试']); } $SkuGroupModel = new RetailSkuGroupModel(); if ($type == 1) { // 库存验证 if ($platform_type != 2) { //第三方平台 if ($group_sku_id) { $saleGoodsNum = $Inventory->goods_num(2, $this->store_id, $groupInfo['gid'], $sku_id); } else { $saleGoodsNum = $Inventory->goods_num(2, $this->store_id, $groupInfo['gid']); } if ($operateNum > $saleGoodsNum) { $this->ajaxReturn(['status' => 0, 'msg' => '商品库存不足']); } } $result = $GroupModel->toSetInc(['id' => $id], 'actnum', $operateNum); if ($group_sku_id) { $SkuGroupModel->toSetInc(['id' => $group_sku_id], 'actnum', $operateNum); } } else { //验证剩余拼团数量是否足够 if ($operateNum > bcsub($groupInfo['actnum'], $groupInfo['sell_number'])) { $this->ajaxReturn(['status' => 0, 'msg' => '拼团商品活动库存不足']); } $result = $GroupModel->toSetDec(['id' => $id], 'actnum', $operateNum); if ($group_sku_id) { $SkuGroupModel->toSetDec(['id' => $group_sku_id], 'actnum', $operateNum); } } if ($result) { if ($type == 1) { //拼团库存增加商品库存减少 if ($sku_id) { $Inventory->Inventory(2, $operateNum, $groupInfo['gid'], $sku_id); } else { $Inventory->Inventory(2, $operateNum, $groupInfo['gid']); } } else { // 拼团库存减少商品库存增加 if ($sku_id) { $Inventory->Inventory(1, $operateNum, $groupInfo['gid'], $sku_id); } else { $Inventory->Inventory(1, $operateNum, $groupInfo['gid']); } } $res = ['status' => 1, 'msg' => '数据更新成功']; } else { $res = ['status' => 0, 'msg' => '操作失败,请稍后']; } $this->ajaxReturn($res); } /** * 添加拼团展示图 */ public function add_group_cover() { $cover_id = I('post.cover_id'); if (!$cover_id) { $res = array('status' => 0, 'msg' => '请选择图片'); $this->ajaxReturn($res); } $StoreXcxConfigModel = new RetailStoreXcxConfigModel(); $save_result = $StoreXcxConfigModel->updateOrder(array('storeid' => $this->store_id), array('xcx_group_cover_id' => $cover_id)); if ($save_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); } /** * 创建拼团活动(加载模板) */ public function create() { $DeliveryTemplateModel = new DeliveryTemplateModel(); $where = array( 'store_id' => $this->store_id, 'status' => 1, 'state' => 1, ); $delivery_template = $DeliveryTemplateModel->getSelect($where, "id,title"); $this->assign('delivery_template', $delivery_template); $this->display(); } /** * 获取商城出售商品 */ public function getGoodsOnlineList() { $platform_type = $this->role_info['platform_type']; // 查询条件 $map = array( 'store_id' => $this->store_id, 'merchant_id' => $this->merchant_id, 'status' => 0, 'online_state' => 1, 'advance_sale_status' => 0 ); // 接受数据,商品名称搜索 if (trim(I('post.keyword'))) { $map[] = array( 'goods_name' => array('like', '%' . trim(I('post.keyword')) . '%'), 'goods_number|goods_code' => trim(I('post.keyword')), '_logic' => 'OR', ); } // 查询商品 $RGModel = new RetailGoodsModel(); $field = array( $RGModel::ID, $RGModel::GOODS_IMG_ID, $RGModel::GOODS_NAME, $RGModel::ONLINE_PRICE, $RGModel::ADD_TIME, $RGModel::ATTRIBUTE_STATE ); if ($platform_type == 2) { //第三方平台 $field[] = 'third_goods_code'; } $goods_list = $RGModel->getSelect($map, $field, 'id desc', intval(I('post.page')) . ',' . intval(I('post.limit'))); if ($goods_list) { $count = $RGModel->getCount($map); $Inventory = new \Api\Controller\InventoryController(); if ($platform_type == 2) { //第三方平台 $code_arr = []; $sku_code_arr = []; $SkuGoodsModel = new RetailSkuGoodsModel(); $sku_map = [ 'status' => 1, 'state' => 0 ]; } foreach ($goods_list as &$val) { $val['image'] = getImage($val[$RGModel::GOODS_IMG_ID]); $val[$RGModel::ADD_TIME] = date('Y-m-d H:i:s', $val[$RGModel::ADD_TIME]); if ($platform_type == 2) { //第三方平台 $val['goods_num'] = 0; if ($val['attribute_state'] == 1) { $code_arr[$val['id']] = $val['third_goods_code']; } else { $sku_map['goods_id'] = $val['id']; $sku_id = $SkuGoodsModel->getSelect($sku_map, 'id,third_goods_code'); foreach ($sku_id as $v) { $sku_code_arr[$val['id']][] = $v['third_goods_code']; } } } else { $val['goods_num'] = $Inventory->goods_num(2, $this->store_id, $val['id']); } } if ($platform_type == 2) { //第三方平台 $ThirdGoodsClass = new Goods(); $storeResult = $ThirdGoodsClass->storeCode($this->store_id); $Customer_Codes = $storeResult['data']; if (!empty($Customer_Codes)) { $thirdResult = $ThirdGoodsClass->goodsNumQuery([ 'merchant_id' => $this->merchant_id, 'type' => 1, 'code_arr' => $code_arr, 'sku_code_arr' => $sku_code_arr, 'Customer_Codes' => $Customer_Codes ]); if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) { $goods_stock = $thirdResult['data']; foreach ($goods_list as &$val) { if (!empty($goods_stock[$val['id']])) { $val['goods_num'] = $goods_stock[$val['id']]; } } } } } } $res = array( 'code' => 0, 'data' => $goods_list ? $goods_list : array(), 'count' => $count ? intval($count) : 0 ); $this->ajaxReturn($res); } /* 获取商品规格 * 2019-1-18 * */ public function getGoodsSku() { $platform_type = $this->role_info['platform_type']; $goods_id = I('post.goods_id'); if (!$goods_id) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } // 查询规格 $RSGModel = new RetailSkuGoodsModel(); $map = array( $RSGModel::STORE_ID => $this->store_id, $RSGModel::STATUS => 1, $RSGModel::STATE => 0, $RSGModel::GOODS_ID => $goods_id, ); $sku_list = $RSGModel->getSelect($map); if ($sku_list) { // 处理数据 $RSLModel = new RetailSkuListModel(); // 规格模型 $SSaleMGoodsModel = new SSaleMGoodsModel(); if ($platform_type == 2) { $code_arr = []; } foreach ($sku_list as &$val) { $val[$RSGModel::SKU_NUM] = floatval($val[$RSGModel::SKU_NUM]); if ($platform_type == 2) { //第三方平台 $val['goods_num'] = 0; $code_arr[$val['id']] = $val['third_goods_code']; } else { $goods_num = $SSaleMGoodsModel->getFindField(array('goods_id' => $goods_id, 'sku_id' => $val['id'], 'status' => 0), "goods_num"); $val[$RSGModel::GOODS_NUM] = round($goods_num, 3); } // 规格名称 $sku_name = $RSLModel->getFindField(array($RSLModel::ID => array('in', $val['sku_id_list'])), $RSLModel::NAME, true); $val['sku_name'] = implode(',', $sku_name); $val['actnum'] = ''; $val['actprice'] = ''; } if ($platform_type == 2 && !empty($code_arr)) { $ThirdGoodsClass = new Goods(); $storeResult = $ThirdGoodsClass->storeCode($this->store_id); $Customer_Codes = $storeResult['data']; $thirdResult = $ThirdGoodsClass->goodsNumQuery([ 'merchant_id' => $this->merchant_id, 'type' => 2, 'code_arr' => $code_arr, 'Customer_Codes' => $Customer_Codes ]); if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) { $goods_stock = $thirdResult['data']; foreach ($sku_list as &$val) { if (!empty($goods_stock[$val['id']])) { $val['goods_num'] = $goods_stock[$val['id']]; } } } } } $res = array('code' => 0, 'data' => $sku_list ? $sku_list : array()); $this->ajaxReturn($res); } /* 操作数据库 执行添加操作 * method: addsku() quantity_logs() * * */ public function add() { // 接受数据 $goods_id = I('post.gid'); $actname = I('post.actname'); $actprice = I('post.actprice'); $actnum = I('post.actnum'); $starttime = I('post.starttime'); $endtime = I('post.endtime'); $day = I('post.day'); $hour = I('post.hour'); $min = I('post.min'); $number = I('post.number'); $join_time = I('post.join_time'); $item = I('post.item'); $send_type = I('post.send_type'); $delivery_template_id = I('post.delivery_template_id'); $sku_arr = I('post.skuarr'); $rise_num = I('post.rise_num'); $is_recommend = (int)I('post.is_recommend'); // 判断参数 if (!$goods_id || !$actname || !$actprice || !$starttime || !$endtime || !$number || intval($number) < 2 || intval($join_time) < 0 || intval($item) < 0 || $rise_num < 0) { $res = array('status' => 0, 'msg' => '请检查表单是否填写正确'); $this->ajaxReturn($res); } if ($rise_num > $item) { $res = array('status' => 0, 'msg' => '起购数量不能大于限购数量'); $this->ajaxReturn($res); } // 判断活动时间 $start_time = strtotime($starttime); $end_time = strtotime($endtime); if ($end_time <= $start_time) { $res = array('status' => 0, 'msg' => '请检查活动时间设置是否正确'); $this->ajaxReturn($res); } // 判断有效时间 if (!$day && !$hour && !$min) { $res = array('status' => 0, 'msg' => '请检查有效时间是否设置'); $this->ajaxReturn($res); } // 查询商品 $RGModel = new RetailGoodsModel(); $map = array( $RGModel::ID => $goods_id, $RGModel::STORE_ID => $this->store_id, $RGModel::MERCHANT_ID => $this->merchant_id, $RGModel::ONLINE_STATE => 1, $RGModel::STATUS => 0 ); $goods_info = $RGModel->getFind($map); if (!$goods_info) { $res = array('status' => 0, 'msg' => '商品存在异常摸清检查商品状态'); $this->ajaxReturn($res); } // 判断规格 $actual_num = $actnum ? intval($actnum) : 0; // 实际库存 $sku_ids = ''; // 活动规格id拼接的字符串 if ($goods_info[$RGModel::ATTRIBUTE_STATE] == 2) { // 判断规格 if (!$sku_arr) { $res = array('status' => 0, 'msg' => '请设置活动规格'); $this->ajaxReturn($res); } // 添加规格 $sku_result = $this->addGroupSku($sku_arr, $goods_id); if ($sku_result['status'] == 0) { $this->ajaxReturn($sku_result); } // 库存 $sku_ids = trim($sku_result['sku_ids'], ',');; $act_num = $sku_result['act_num']; } else { $Inventory = new \Api\Controller\InventoryController(); $success = $Inventory->Inventory(2, $actual_num, $goods_info[$RGModel::ID], $sku_id = ''); $act_num = $actual_num; if (!$success) { $res['status'] = 0; $res['msg'] = "该商品数量减少操作失败"; $this->ajaxReturn($res); } } // 判断活动数量 if (intval($act_num) <= 0) { $res = array('status' => 0, 'msg' => '请确认活动数量是否设置正确'); $this->ajaxReturn($res); } // 创建拼团活动 $RGroupModel = new RetailGroupModel(); $cr = array( $RGroupModel::GID => $goods_id, $RGroupModel::STORE_ID => $this->store_id, $RGroupModel::MERCHANT_ID => $this->merchant_id, $RGroupModel::GROUP_SKU_IDS => $sku_ids, $RGroupModel::ACT_NAME => $actname, $RGroupModel::ACT_PRICE => $actprice, $RGroupModel::ACT_NUM => $act_num, $RGroupModel::START_TIME => $start_time, $RGroupModel::ENT_TIME => $end_time, $RGroupModel::DAY => $day ? $day : 0, $RGroupModel::HOUR => $hour ? $hour : 0, $RGroupModel::MIN => $min ? $min : 0, $RGroupModel::NUMBER => $number, $RGroupModel::JOIN_TIME => $join_time, $RGroupModel::ITEM => $item, $RGroupModel::RISE_NUM => $rise_num, $RGroupModel::SEND_TYPE => $send_type, $RGroupModel::ACT_TYPE => 1, 'delivery_template_id' => $delivery_template_id, $RGroupModel::IS_RECOMMEND => $is_recommend ); $add_result = $RGroupModel->addOrder($cr); if (!$add_result) { $res['status'] = 0; $res['msg'] = "活动创建失败"; } else { //操作日志记录 $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); } /** * 添加活动规格 * @param array $sku 活动规格 * @param int $goods_id 商品id */ protected function addGroupSku($sku, $goods_id) { // 定义变量 $sku_ids = ''; // 活动sku以id拼接的字符串 $act_num = 0; // 活动规格取出数量 $actual_num = 0; // 规格取出数量对应的商品数量 $RSGModel = new RetailSkuGroupModel(); // 拼团sku模型 // 活动规格条件 $cr = array( $RSGModel::GOODS_ID => $goods_id, $RSGModel::STORE_ID => $this->store_id, $RSGModel::ADD_TIME => time(), ); foreach ($sku as &$val) { // 判断活动数量 if (!$val['actnum'] || intval($val['actnum']) <= 0) { $res = array('status' => 0, 'msg' => '请检查规格库存设置是否正确'); return $res; } // 判断活动金额 if (!$val['actprice'] || floatval($val['actprice']) <= 0) { $res = array('status' => 0, 'msg' => '请检查规格活动售价设置是否正确'); return $res; } // 创建活动规格 $cr1 = $cr; $cr1[$RSGModel::SKU_ID] = $val['id']; $cr1[$RSGModel::ACT_NUM] = intval($val['actnum']); $cr1[$RSGModel::ACT_PRICE] = round($val['actprice'], 2); $cr1[$RSGModel::SKU_ID_LIST] = $val['sku_id_list']; $add_result = $RSGModel->addOrder($cr1); if (!$add_result) { $res = array('status' => 0, 'msg' => '活动规格设置失败'); return $res; } // 规格商品显示数量减少 $Inventory = new \Api\Controller\InventoryController(); $dec_result = $Inventory->Inventory(2, $val['actnum'], $goods_id, $val['id']); if (!$dec_result) { $res = array('status' => 0, 'msg' => '商品规格减库存出现异常,请刷新重试'); return $res; } $sku_ids .= $add_result . ','; $act_num += intval($val['actnum']); $actual_num += intval($val['actnum']) * $val['sku_num']; unset($cr1); unset($add_result); unset($dec_result); } $res = array( 'status' => 1, 'sku_ids' => $sku_ids, 'act_num' => $act_num, 'actual_num' => $actual_num, ); return $res; } // 修改 渲染模板 public function edit($id) { $group_info = $this->getGroupInfo($id); $DeliveryTemplateModel = new DeliveryTemplateModel(); $where = array( 'store_id' => $this->store_id, 'status' => 1 ); $group_info['send_type'] = explode(',', $group_info['send_type']); $delivery_template = $DeliveryTemplateModel->getSelect($where, "id,title"); $this->assign('delivery_template', $delivery_template); $this->assign('group_info', $group_info); $this->assign('send_type', json_encode($group_info['send_type'])); $this->display(); } /** * 查看(加载模板) */ public function see($id) { $group_info = $this->getGroupInfo($id); $this->assign('group_info', $group_info); $this->display(); } /** * 获取拼团活动 */ protected function getGroupInfo($group_id) { $platform_type = $this->role_info['platform_type']; //商户平台类型 1默认系统 2微礼平台 $RGModel = new RetailGroupModel(); // 拼团查询条件 $map = array( 'gr.' . $RGModel::ID => $group_id, 'gr.' . $RGModel::STORE_ID => $this->store_id, 'gr.' . $RGModel::MERCHANT_ID => $this->merchant_id, ); $field = array('gr.*', 'go.goods_name', 'go.online_price', 'go.goods_num', 'go.goods_num', 'go.attribute_state', 'go.goods_img_id', 'go.third_goods_code'); $group_info = $RGModel->getFindGroupAndGoods($map, $field); // 处理数据 if ($group_info) { $group_info['starttime'] = date('Y-m-d H:i:s', $group_info['starttime']); $group_info['endtime'] = date('Y-m-d H:i:s', $group_info['endtime']); $group_info['effective'] = $group_info['day'] . ' 天 ' . $group_info['hour'] . ' 小时 ' . $group_info['min'] . ' 分钟'; $group_info['goods_image'] = getImage($group_info['goods_img_id']); $group_info['rise_num'] = $group_info['rise_num'] ? round($group_info['rise_num'], 3) : ''; } if ($platform_type == 2) { //第三方平台 $group_info['goods_num'] = 0; $ThirdGoodsClass = new Goods(); $storeResult = $ThirdGoodsClass->storeCode($this->store_id); $Customer_Codes = $storeResult['data']; //门店编码 $data = [ 'merchant_id' => $this->merchant_id, 'type' => 2, 'Customer_Codes' => $Customer_Codes ]; if (!empty($group_info['group_skuid'])) { $SkuGroupModel = new RetailSkuGroupModel(); $sku_id_arr = $SkuGroupModel->getFindField([ 'id' => ['in', $group_info['group_skuid']] ], 'sku_id', true); $SkuGoodsModel = new RetailSkuGoodsModel(); $sku_code_arr = $SkuGoodsModel->getFindField([ 'id' => ['in', $sku_id_arr] ], 'third_goods_code', true); $data['code_arr'] = $sku_code_arr; } else { $data['code_arr'] = [$group_info['third_goods_code']]; } $result = $ThirdGoodsClass->goodsNumQuery($data); if ($result['status'] == 1 && !empty($result['data'])) { $stock = $result['data']; foreach ($stock as $val) { $group_info['goods_num'] += $val; } } } return $group_info ? $group_info : array(); } /** * 获取拼团活动规格 */ public function getGroupSku() { // 接受参数 $sku_ids = I('post.group_skuid'); if (!$sku_ids) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } $platform_type = $this->role_info['platform_type']; //商户平台类型 1默认系统 2微礼平台 // 查询规格 $RSGModel = new RetailSkuGroupModel(); $map = array( 'gr.' . $RSGModel::ID => array('in', $sku_ids), 'gr.' . $RSGModel::STORE_ID => $this->store_id ); $field = array('gr.*', 'go.goods_num', 'go.sku_num', 'go.third_goods_code'); $sku_info = $RSGModel->getSelectSku($map, $field); if ($sku_info) { if ($platform_type == 2) { $code_arr = []; } $RSLModel = new RetailSkuListModel(); // 规格模型 foreach ($sku_info as &$val) { if ($platform_type == 2) { $code_arr[$val['sku_id']] = $val['third_goods_code']; $val['goods_num'] = 0; } else { $val['goods_num'] = floatval($val['goods_num']); } $val['sku_num'] = floatval($val['sku_num']); $val['actnum'] = floatval($val['actnum']); $val['act_num'] = floatval($val['actnum']); $val['actprice'] = floatval($val['actprice']); // 规格名称 $sku_name = $RSLModel->getFindField(array($RSLModel::ID => array('in', $val['sku_id_list'])), $RSLModel::NAME, true); $val['sku_name'] = implode(',', $sku_name); } if ($platform_type == 2 && !empty($code_arr)) { //第三方平台 $ThirdGoodsClass = new Goods(); $storeResult = $ThirdGoodsClass->storeCode($this->store_id); $Customer_Codes = $storeResult['data']; //门店编码 $thirdResult = $ThirdGoodsClass->goodsNumQuery([ 'merchant_id' => $this->merchant_id, 'type' => 2, 'code_arr' => $code_arr, 'Customer_Codes' => $Customer_Codes ]); if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) { $goods_stock = $thirdResult['data']; foreach ($sku_info as &$val) { if (!empty($goods_stock[$val['sku_id']])) { $val['goods_num'] = $goods_stock[$val['sku_id']]; } } } } } $res = array('code' => 0, 'data' => $sku_info); $this->ajaxReturn($res); } /** * 修改活动 */ public function update() { // 接受数据 $group_id = I('post.group_id'); $actname = I('post.actname'); $actprice = I('post.actprice'); $endtime = I('post.endtime'); $join_time = I('post.join_time'); $item = I('post.item'); $rise_num = I('post.rise_num'); $send_type = I('post.send_type'); $delivery_template_id = I('post.delivery_template_id'); $sku_arr = I('post.skuarr'); // 判断参数 if (!$group_id || !$actname || !$actprice || !$endtime || intval($join_time) < 0 || intval($item) < 0 || $rise_num < 0) { $res = array('status' => 0, 'msg' => '请检查表单是否填写正确'); $this->ajaxReturn($res); } if ($rise_num > $item) { $res = array('status' => 0, 'msg' => '起购数量不能大于限购数量'); $this->ajaxReturn($res); } // 查询活动 $group_info = $this->getGroupInfo($group_id); if (!$group_info) { $res = array('status' => 0, 'msg' => '活动查询失败'); $this->ajaxReturn($res); } $up['is_recommend'] = (int)I('post.is_recommend'); // 判断时间 $end_time = strtotime($endtime); if ($end_time <= $group_info['starttime']) { $res = array('status' => 0, 'msg' => '截止时间设置不合理'); $this->ajaxReturn($res); } // 判断规格 if ($group_info['attribute_state'] == 2) { if (!$sku_arr) { $res = array('status' => 0, 'msg' => '规格出现异常,请刷新重试'); $this->ajaxReturn($res); } // 修改规格 $sku_result = $this->updateGroupSku($sku_arr); if ($sku_result['status'] == 0) { $this->ajaxReturn($sku_result); } } // 判断活动标题 if ($actname != $group_info['actname']) { $up['actname'] = $actname; } // 判断活动价格 if ($actprice != $group_info['actprice']) { $up['actprice'] = $actprice; } // 判断结束时间 if ($end_time != $group_info['endtime']) { $up['endtime'] = $end_time; } // 判断限制购买次数 if ($join_time != $group_info['join_time']) { $up['join_time'] = $join_time; } // 判断单次限制购买数量 if ($item != $group_info['item']) { $up['item'] = $item; } // 判断起购数量 if ($rise_num != $group_info['rise_num']) { $up['rise_num'] = $rise_num; } // 判断配送方式 if ($send_type != $group_info['send_type']) { $up['send_type'] = $send_type; } if ($delivery_template_id != $group_info['delivery_template_id']) { $up['delivery_template_id'] = $delivery_template_id; } // 再次判断修改 if (!$up) { // 判断规格是否修改 if ($sku_result && $sku_result['status'] == 1) { $res = array('status' => 1, 'msg' => '修改成功'); } else { $res = array('status' => 0, 'msg' => '请先提交修改'); } } else { // 修改活动 $RGModel = new RetailGroupModel(); $save_result = $RGModel->updateOrder(array($RGModel::ID => $group_id), $up); if ($save_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); } /** * 修改规格 * @param array $sku_arr 规格 * @return array $res */ protected function updateGroupSku($sku_arr) { $RSGModel = new RetailSkuGroupModel(); // 拼团sku模型 $num = 0; foreach ($sku_arr as &$val) { // 查询规格 $group_price = $RSGModel->getFindField(array($RSGModel::ID => $val['id']), $RSGModel::ACT_PRICE); if (!$group_price) { $res = array('status' => 0, 'msg' => '活动规格出现异常'); return $res; } if ($group_price != $val['actprice']) { $save_result = $RSGModel->updateOrder(array($RSGModel::ID => $val['id']), array($RSGModel::ACT_PRICE => $val['actprice'])); if (!$save_result) { $res = array('status' => 0, 'msg' => '活动规格售价设置出现异常'); return $res; } else { $num++; } } } if ($num && $num != 0) { $res = array('status' => 1, 'msg' => '修改成功'); } else { $res = array('status' => 2, 'msg' => '未操作规格'); } return $res; } /** * 活动恢复库存 * @param int $id 活动id * @return array $res */ public function recovery() { // 接受数据 $id = I('post.id'); if (!$id) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } // 查询活动 $RGViewModel = new RetailGroupViewModel(); $group_data = $RGViewModel->getFind(array('RetailGroup.id' => $id)); if (!$group_data) { $res = array('status' => 0, 'msg' => '活动查询失败'); $this->ajaxReturn($res); } // 查询商品 $RGModel = new RetailGoodsModel(); $goods_data = $RGModel->getFind(array($RGModel::ID => $group_data['gid'])); if (!$goods_data) { $res = array('status' => 0, 'msg' => '商品异常,恢复失败'); $this->ajaxReturn($res); } if ($group_data['act_num'] <= 0) { $res = array('status' => 2, 'msg' => '活动库存已经出售完毕,无需恢复'); $this->ajaxReturn($res); } // 判断规格 $Inventory = new \Api\Controller\InventoryController(); if ($group_data['attribute_state'] == 2 && $group_data['group_sku_id']) { // 规格商品 $GroupSkuViewModel = new RetailGroupSkuViewModel(); $map = array( 'RetailSkuGroup.id' => array('in', $group_data['group_sku_id']), ); $fields = array( 'RetailSkuGoods.*', 'RetailSkuGroup.sku_num', ); $group_sku_data = $GroupSkuViewModel->getSelect($map, $fields); if (!$group_sku_data) { $res = array('status' => 0, 'msg' => '规格查询失败'); $this->ajaxReturn($res); } // 定义变量 foreach ($group_sku_data as &$val) { if ($val['actnum'] > 0) { $goods_sku_res = $Inventory->Inventory(1, $val['actnum'], $goods_data[$RGModel::ID], $val['sku_id']); if (!$goods_sku_res) { $res = array('status' => 0, 'msg' => '商品规格增加失败'); $this->ajaxReturn($res); } $SkuGroupModel = new RetailSkuGroupModel(); $group_sku_res = $SkuGroupModel->updateOrder(array('id' => $val['id']), array('actnum' => 0)); if (!$group_sku_res) { $res = array('status' => 0, 'msg' => '活动规格库存未被清空'); $this->ajaxReturn($res); } } } } else { $actual_num = $group_data['act_num']; $success = $Inventory->Inventory(1, $actual_num, $goods_data[$RGModel::ID]); if (!$success) { $res['status'] = 0; $res['msg'] = "该商品库存恢复失败"; $this->ajaxReturn($res); } } // 清空活动库存 $RGroupModel = new RetailGroupModel(); $group_result = $RGroupModel->updateOrder(array($RGroupModel::ID => $group_data['id']), array($RGroupModel::ACT_NUM => 0)); if ($group_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['status'] = 1; $res['msg'] = "操作成功"; } else { $res['status'] = 0; $res['msg'] = "活动库存清空失败"; } $this->ajaxReturn($res); } // 删除 public function delete() { // 接受数据 $id = I('post.id'); if (!$id) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } // 删除活动 $RGroupModel = new RetailGroupModel(); $del_res = $RGroupModel->updateOrder(array('id' => $id), array('acttype' => 3)); if ($del_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 = array('status' => 1, 'msg' => '删除成功'); } else { $res = array('status' => 0, 'msg' => '删除失败'); } $this->ajaxReturn($res); } /** * 拼团订单首页,加载页面 */ public function orderindex() { $GroupApi = new \PayApi\Controller\GroupController(); $GroupApi->updateOrderState($this->store_id, $this->merchant_id); $this->display(); } /** * 拼团订单导出 */ public function groupExport() { $RGOViewModel = new RetailGroupOrderViewModel(); $map = array( 'RetailBillOrder.pay_state' => 1, 'RetailBillOrder.store_id' => $this->store_id, 'RetailBillOrder.type' => 1, 'RetailBillOnline.order_genre' => 2, 'RetailBillOrder.order_type' => 1 ); // 接受数据 $state = I('get.group_status'); // 拼团状态 0.所有 1.拼团中 2.成功 3.失败 switch ($state) { case '0': $map['RetailBillGroup.state'] = array('in', array('1', '2', '3'));; break; case '1': $map['RetailBillGroup.state'] = 1; break; case '2': $map['RetailBillGroup.state'] = 2; break; case '3': $map['RetailBillGroup.state'] = 3; break; default: $map['RetailBillGroup.state'] = array('in', array('1', '2', '3')); break; } $order_no = I('get.order_id'); // 订单搜索 if ($order_no) { $map['RetailBillOrder.order_no'] = array('like', "%" . $order_no); } // 时间搜索 $time = I('get.time'); if ($time) { $time = explode(',', $time); $start_date = strtotime($time[0]); $end_date = strtotime($time[1]); $map['RetailBillOrder.add_time'] = ['between', [$start_date, $end_date]]; } $field = array( 'id', 'all_money', 'pay_type', 'refund_status', 'order_type', 'add_time', 'vid', 'uid', 'order_no', 'status', 'pickup_type', 'user_name', 'user_phone', 'user_address', 'state', 'buy_number', 'remind_state', 'remark', 'parent_id', 'pay_coupon_fee' ); $order_list = $RGOViewModel->getSelect($map, $field); if ($order_list) { $RVModel = new RetailVipModel(); $PayOrderModel = new RetailPayOrderModel(); foreach ($order_list as $key => &$val) { $val['index'] = $key + 1; $val['out_trade_no'] = $PayOrderModel->getFindField(array('bill_id' => $val['id']), "out_trade_no"); if ($val['vid']) { $vip_name = $RVModel->getFindField(array($RVModel::ID => $val['vid']), $RVModel::NAME); $val['vip_name'] = $vip_name ? $vip_name : '未设置'; } else { $val['vip_name'] = '非会员'; } $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']); $val['pickup_name'] = $val['pickup_type'] == 1 ? '自提' : '配送'; switch ($val['status']) { case 1: $val['status_name'] = '未发货'; break; case 2: $val['status_name'] = '未收货'; break; case 3: $val['status_name'] = '交易完成'; break; default: $val['status_name'] = '未知类型'; } switch ($val['state']) { case 1: $val['state_name'] = '拼团中'; break; case 2: $val['state_name'] = '拼团成功'; break; case 3: $val['state_name'] = '拼团失败'; break; default: $val['state_name'] = '未知类型'; } $val['remind_name'] = $val['remind_state'] == 1 ? '是' : '否'; $val['order_name'] = $val['order_type'] == 1 ? '购买' : '退款'; $val['pay_coupon_fee'] = $val['pay_coupon_fee'] > 0 ? floatval($val['pay_coupon_fee']) : ''; } } else { $order_list = array(); } $filename = "拼团订单列表"; $arr = array( array('index', '序号'), array('order_no', '门店订单号'), array('out_trade_no', '内部流水号'), array('order_name', '订单类型'), array('vip_name', '会员'), array('all_money', '支付金额'), array('pay_coupon_fee', '代金券优惠金额'), array('add_time', '下单时间'), array('pickup_name', '自提/配送'), array('user_name', '姓名'), array('user_phone', '手机'), array('user_address', '地址'), array('status_name', '发货状态'), array('state_name', '拼团状态'), array('remind_name', '提醒发货'), array('remark', '买家留言'), ); $str = "导出时间" . date('Y-m-d H:i:s', time()); getExcel($filename, $arr, $order_list, $str); } /** * 获取拼团订单 * @return array $res */ public function getOrder_group() { $RGOViewModel = new RetailGroupOrderViewModel(); $map = array( 'RetailBillOrder.pay_state' => 1, 'RetailBillOrder.store_id' => $this->store_id, 'RetailBillOrder.type' => 1, 'RetailBillOnline.order_genre' => 2, 'RetailBillOrder.order_type' => 1 ); // 接受数据 $state = I('post.group_status'); // 拼团状态 0.所有 1.拼团中 2.成功 3.失败 switch ($state) { case '0': $map['RetailBillGroup.state'] = array('in', array('1', '2', '3'));; break; case '1': $map['RetailBillGroup.state'] = 1; break; case '2': $map['RetailBillGroup.state'] = 2; break; case '3': $map['RetailBillGroup.state'] = 3; break; default: $map['RetailBillGroup.state'] = array('in', array('1', '2', '3')); break; } $order_no = I('post.order_id'); // 订单搜索 if ($order_no) { $map['RetailBillOrder.order_no'] = array('like', "%" . $order_no); } // 时间搜索 // 时间搜索 $time = I('post.time'); if ($time) { $start_date = strtotime($time[0]); $end_date = strtotime($time[1]); $map['RetailBillOrder.add_time'] = ['between', [$start_date, $end_date]]; } $field = array( 'id', 'all_money', 'pay_type', 'refund_status', 'order_type', 'add_time', 'vid', 'uid', 'order_no', 'status', 'pickup_type', 'user_name', 'user_phone', 'user_address', 'state', 'buy_number', 'remind_state', 'remark', 'parent_id', 'delivery_type', 'user_select_time', 'pay_coupon_fee', ); $postOne = I('post.'); if (isset($postOne['status']) && $postOne['status'] !== '') { //ls_retail_bill_online -> status 1未发货 2已发货 3已收货 (自提没有类型2) if ($postOne['status'] == 4) { //待自提 $map['RetailBillOnline.pickup_type'] = 1; $map['RetailBillOnline.status'] = 1; } else if ($postOne['status'] == 5) { //已自提 $map['RetailBillOnline.pickup_type'] = 1; $map['RetailBillOnline.status'] = 3; } else { $map['RetailBillOnline.pickup_type'] = array('in', '2,3'); $map['RetailBillOnline.status'] = $postOne['status']; } } if (isset($postOne['pickupType']) && $postOne['pickupType'] !== '') { //ls_retail_bill_online -> pickup_type 是否需要配送 1:自提 2:配送 3快递发货 $map['RetailBillOnline.pickup_type'] = $postOne['pickupType']; } $order_list = $RGOViewModel->getSelect($map, $field, (int)$_POST['page'], (int)$_POST['limit']); if ($order_list) { $whereRoutine = array( 'RetailBillOrder.pay_state' => 1, 'RetailBillOrder.store_id' => $this->store_id, 'RetailBillOrder.type' => 1, 'RetailBillOnline.order_genre' => 2, 'RetailBillOrder.order_type' => 1, 'RetailBillOnline.status' => 1, ); //待,数量,拼团订单 $whereOne = [ 'RetailBillOnline.pickup_type' => 1, $whereRoutine, ]; $whereTwo = [ 'RetailBillOnline.pickup_type' => 2, $whereRoutine, ]; $whereThree = [ 'RetailBillOnline.pickup_type' => 3, $whereRoutine, ]; $pickup_type_one = $RGOViewModel->getCount($whereOne); //待自提数量 $pickup_type_two = $RGOViewModel->getCount($whereTwo); //待配送订单数量 $pickup_type_three = $RGOViewModel->getCount($whereThree); //待发货订单数量 $count = $RGOViewModel->getCount($map); $RVModel = new RetailVipModel(); foreach ($order_list as &$val) { if ($val['vid']) { $vip_name = $RVModel->getFindField(array($RVModel::ID => $val['vid']), $RVModel::NAME); $val['vip_name'] = $vip_name ? $vip_name : '未设置'; } else { $val['vip_name'] = '非会员'; } $val['user_select_time'] = $val['user_select_time'] ? date('Y-m-d H:i', $val['user_select_time']) : ''; $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']); $val['pickup_name'] = $val['pickup_type'] == 1 ? '自提' : ($val['pickup_type'] == 2 ? '同城' : '快递'); switch ($val['status']) { case 1: $val['status_name'] = '未发货'; break; case 2: $val['status_name'] = '未收货'; break; case 3: $val['status_name'] = '交易完成'; break; default: $val['status_name'] = '交易完成'; } switch ($val['state']) { case 1: $val['state_name'] = '拼团中'; break; case 2: $val['state_name'] = '拼团成功'; break; case 3: $val['state_name'] = '拼团失败'; break; default: $val['state_name'] = '未知类型'; } $val['remind_name'] = $val['remind_state'] == 1 ? '是' : '否'; $val['order_name'] = $val['order_type'] == 1 ? '购买' : ''; $val['pay_coupon_fee'] = $val['pay_coupon_fee'] > 0 ? floatval($val['pay_coupon_fee']) : ''; } } $plugClass = new Plug(); //订单获取祝福码,判断该门店是否,有,并且开启 $storePlugStatusPost = [ 'store_id' => $this->store_id, 'identification_arr' => ['blessing'], ]; $storePlugStatus = $plugClass->plugStoreStatus($storePlugStatusPost);//获取状态 if ($storePlugStatus === true) { //有权限 $jurisdictionBlessing = 1; } else { //无权限 $jurisdictionBlessing = 2; } $res = array( 'code' => 0, 'data' => $order_list, 'count' => $count ? $count : 0, 'pickup_type_one' => $pickup_type_one ? $pickup_type_one : 0,//待自提数量 'pickup_type_two' => $pickup_type_two ? $pickup_type_two : 0,//待配送数量 'pickup_type_three' => $pickup_type_three ? $pickup_type_three : 0,//待送货数量 'jurisdiction_blessing' => $jurisdictionBlessing,//1有权限,2无权限 ); $this->ajaxReturn($res); } // 取消活动 public function ban() { $id = I('post.id'); if (!$id) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } // 查询活动 $GroupModel = new RetailGroupModel(); $find_res = $GroupModel->getFind(array('id' => $id)); if (!$find_res) { $res = array('status' => 0, 'msg' => '活动查询失败'); $this->ajaxReturn($res); } // 失效订单 $RBOModel = new RetailBillOrderModel(); $map = array( 'b.' . $RBOModel::STORE_ID => $this->store_id, 'b.' . $RBOModel::MERCHANT_ID => $this->merchant_id, 'b.' . $RBOModel::PAY_STATE => 1, 'b.' . $RBOModel::TYPE => 1, 'o.status' => 1, 'o.order_genre' => 2, 'g.state' => 1, 'g.group_id' => $id ); $select = $RBOModel->getSelectGroup($map); if ($select) { // 处理数据 $RBGModel = new RetailBillGroupModel(); $up = array($RBGModel::STATE => 3); $ActivityOrder = new ActivityOrderController(); foreach ($select as &$val) { $save_res = $RBGModel->updateOrder(array($RBGModel::BILL_ID => $val[$RBOModel::ID]), $up); if (!$save_res) { $res = array('status' => 0, 'msg' => '操作失败'); $this->ajaxReturn($res); } $result = $ActivityOrder->doRefund_v1($val[$RBOModel::ORDER_NO]); if ($result['status'] == 0) { $this->ajaxReturn($result); } } } // 取消活动 $GroupModel = new RetailGroupModel(); $save_res = $GroupModel->updateOrder(array('id' => $id), array('acttype' => 2)); if ($save_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 = array('status' => 1, 'msg' => '活动取消成功'); } else { $res = array('status' => 0, 'msg' => '活动取消失败'); } $this->ajaxReturn($res); } /** * 成团 * @param int $parent_id 关联id * @return array $res */ public function useSuccess() { // 接受数据 $parent_id = I('post.parent_id'); if (!$parent_id) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } // 查询订单 $RBOModel = new RetailBillOrderModel(); $map = array( 'b.' . $RBOModel::STORE_ID => $this->store_id, 'b.' . $RBOModel::MERCHANT_ID => $this->merchant_id, 'b.' . $RBOModel::PAY_STATE => 1, 'b.' . $RBOModel::TYPE => 1, 'o.order_genre' => 2, 'g.state' => 1, 'g.parent_id' => $parent_id, ); $select = $RBOModel->getSelectGroup($map); if (!$select) { $res = array('status' => 0, 'msg' => '查询失败'); $this->ajaxReturn($res); } // 处理数据 $RBGModel = new RetailBillGroupModel(); $up = array($RBGModel::STATE => 2); $num = 0; foreach ($select as &$val) { $save = $RBGModel->updateOrder(array($RBGModel::BILL_ID => $val[$RBOModel::ID]), $up); if (!$save) { $num++; } } if ($num && $num > 0) { $res = array('status' => 0, 'msg' => '成团失败'); } else { $res = array('status' => 1, 'msg' => '成团成功'); } $this->ajaxReturn($res); } /** * 失败成团订单 * @param int $parent_id * @param array $res */ public function useError() { // 接受数据 $platform_type = $this->role_info['platform_type']; //商户平台类型 1默认系统 2微礼平台 $parent_id = I('post.parent_id'); if (!$parent_id) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } // 查询订单 $RBOModel = new RetailBillOrderModel(); $map = array( 'b.' . $RBOModel::STORE_ID => $this->store_id, 'b.' . $RBOModel::MERCHANT_ID => $this->merchant_id, 'b.' . $RBOModel::PAY_STATE => 1, 'b.' . $RBOModel::TYPE => 1, 'o.status' => 1, 'o.order_genre' => 2, 'g.state' => 2, 'g.parent_id' => $parent_id, ); $select = $RBOModel->getSelectGroup($map); if (!$select) { $res = array('status' => 0, 'msg' => '查询失败'); $this->ajaxReturn($res); } // 处理数据 $RBGModel = new RetailBillGroupModel(); $up = array($RBGModel::STATE => 3); $ActivityOrder = new ActivityOrderController(); foreach ($select as &$val) { // 处理数据 if ($platform_type == 2) { //第三方平台 $ThirdClass = new Order(); $ThirdResult = $ThirdClass->orderCancel([ 'merchant_id' => $this->merchant_id, 'third_order' => $val['third_order'] ]); if ($ThirdResult['status'] == 0) { $result['status'] = 0; $result['msg'] = '第三方平台取消订单失败' . $ThirdResult['message']; $this->ajaxReturn($result); } } $result = $ActivityOrder->doRefund_v1($val[$RBOModel::ORDER_NO]); if ($result['status'] == 0) { $this->ajaxReturn($result); } $save_res = $RBGModel->updateOrder(array($RBGModel::BILL_ID => $val[$RBOModel::ID]), $up); if (!$save_res) { $res = array('status' => 0, 'msg' => '操作失败'); $this->ajaxReturn($res); } } $res = array('status' => 1, 'msg' => '操作成功'); //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '拼图订单使失败'; //操作行为描述 action_log($source, $type, $request_data, $desc); //end $this->ajaxReturn($res); } //开启或关闭多人拼团 public function storeOnOrOff() { if (IS_POST) { $group_status = I('post.state'); $map = array( 'storeid' => $this->store_id, ); $StoreXcxConfigModel = new RetailStoreXcxConfigModel(); $xcx_config = $StoreXcxConfigModel->getFind($map); if (empty($xcx_config)) { $data['storeid'] = $this->store_id; $data['group_status'] = $group_status; $data['addtime'] = time(); $add_store = $StoreXcxConfigModel->addOrder($data); if (!empty($add_store)) { $res = ['status' => 1, 'msg' => '操作成功']; } else { $res = ['status' => 0, 'msg' => '操作失败']; } } else { $save_res = $StoreXcxConfigModel->updateOrder($map, array('group_status' => $group_status)); if (!empty($save_res)) { $res = ['status' => 1, 'msg' => '操作成功']; } else { $res = ['status' => 0, 'msg' => '操作失败']; } } //操作日志记录 $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); } } //商城首页开启或关闭拼团显示 public function homeShowOrHide() { if (IS_POST) { $status = I('post.status'); $StoreXcxConfigModel = new RetailStoreXcxConfigModel(); $map = array( 'storeid' => $this->store_id ); if (!empty($status)) { $xcx_config = $StoreXcxConfigModel->getFind($map); if (empty($xcx_config)) { $data['storeid'] = $this->store_id; $data['home_group_status'] = $status; $data['addtime'] = time(); $add_store = $StoreXcxConfigModel->addOrder($data); if (!empty($add_store)) { $res['status'] = 1; $res['msg'] = '修改成功'; } else { $res['status'] = 0; $res['msg'] = '修改失败'; } } else { $save_res = $StoreXcxConfigModel->updateOrder($map, array('home_group_status' => $status)); if (!empty($save_res)) { $res['status'] = 1; $res['msg'] = '修改成功'; } else { $res['status'] = 0; $res['msg'] = '修改失败'; } } } else { $res['status'] = 0; $res['msg'] = '缺少参数'; } //操作日志记录 $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 $order_no string 订单号 * @return $res array $res['status] 状态 */ public function refund() { // 接受数据 $order_no = strval(I('post.order_no')); // 判断参数 if (!$order_no) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } // 查询订单 $RGOViewModel = new RetailGroupOrderViewModel(); $map = array( 'RetailBillOrder.order_no' => strval($order_no), 'RetailBillOrder.pay_state' => 1, 'RetailBillOrder.type' => 1, 'RetailBillOrder.merchant_id' => $this->merchant_id, 'RetailBillOrder.store_id' => $this->store_id, 'RetailBillOrder.order_type' => 2, 'RetailBillOnline.order_genre' => 2 ); $field = array('id', 'pickup_type'); $group_order = $RGOViewModel->getFind($map, $field); if (!$group_order) { $res = array('status' => 0, 'msg' => '订单查询失败'); $this->ajaxReturn($res); } $data = array( 'store_id' => $this->store_id, 'merchant_id' => $this->merchant_id, 'order_no' => $order_no, 'user_type' => 3, 'return_delivery_fee' => $group_order['pickup_type'] == 1 ? 2 : 1, // 是否退还配送费 1.退还 2.不退还 'platform_type' => $this->role_info['platform_type'] ); // 退款 $Refund = new RefundController(); $res = $Refund->onlineOrderRefund_v2($data); //日志记录 if ($res['status'] == 1) { //操作日志记录 $source = 0; //请求来源: 0pc系统 1小助手 $type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST); //请求参数 json数据 $desc = '拼团订单退款'; //操作行为描述 action_log($source, $type, $request_data, $desc); //end } $this->ajaxReturn($res); } /* * 门店id打印机 */ public function linePrint() { $order_id = I('post.order_id'); if (!$order_id) { $res = array('status' => 0, 'msg' => '参数缺失'); $this->ajaxReturn($res); } $Printer = new \PayApi\Controller\PrinterController(); $res = $Printer->linePrinting_v1($this->store_id, $order_id, true); if ($res['status'] == 0) { $this->ajaxReturn($res); } } }