/** * @brief 保存品牌 */ function brand_save() { $brand_id = IFilter::act(IReq::get('brand_id'), 'int'); $name = IFilter::act(IReq::get('name')); $sort = IFilter::act(IReq::get('sort'), 'int'); $url = IFilter::act(IReq::get('url')); $description = IFilter::act(IReq::get('description'), 'text'); $tb_brand = new IModel('brand'); $brand = array('name' => $name, 'sort' => $sort, 'url' => $url, 'description' => $description); if (isset($_FILES['logo']['name']) && $_FILES['logo']['name'] != '') { $uploadObj = new PhotoUpload(); $uploadObj->setIterance(false); $photoInfo = $uploadObj->run(); if (isset($photoInfo['logo']['img']) && file_exists($photoInfo['logo']['img'])) { $brand['logo'] = $photoInfo['logo']['img']; } } $tb_brand->setData($brand); if ($brand_id) { $where = "id=" . $brand_id; $tb_brand->update($where); } else { $tb_brand->add(); } $this->brand_list(); }
public static function add($word, $hot, $order = 99) { $word = IFilter::act($word); $hot = intval($hot); $order = intval($order); if ($word != '') { $keywordObj = new IModel('keyword'); $wordArray = explode(',', $word); //获取各个关键词的管理商品数量 $resultCount = self::count($wordArray); foreach ($wordArray as $word) { if (IString::getStrLen($word) >= 15) { continue; } $is_exists = $keywordObj->getObj('word = "' . $word . '"', 'hot'); if (empty($is_exists)) { $dataArray = array('hot' => $hot, 'word' => $word, 'goods_nums' => $resultCount[$word], 'order' => $order); $keywordObj->setData($dataArray); $keywordObj->add(); } } return array('flag' => true); } return array('flag' => false, 'data' => '请填写关键词'); }
/** * @brief 日志记录 * @param array $config => array('user_id' => 用户ID , 'point' => 积分增减(正,负区分) , 'log' => 日志记录内容) */ private function writeLog($config) { //修改pointLog表 $poinLogObj = new IModel('point_log'); $pointLogArray = array('user_id' => $config['user_id'], 'datetime' => ITime::getDateTime(), 'value' => $config['point'], 'intro' => $config['log']); $poinLogObj->setData($pointLogArray); return $poinLogObj->add(); }
/** * @brief 处理curd动作 * @return String */ public function curd() { $action = $this->id; $controller = $this->controller; $curdinfo = $this->initinfo(); if (is_array($curdinfo)) { $modelName = $curdinfo['model']; $key = $curdinfo['key']; $actions = $curdinfo['actions']; switch ($action) { case 'add': case 'upd': if (method_exists($controller, 'getValidate')) { $validate = $controller->getValidate(); } else { $validate = null; } if ($validate != null) { $formValidate = new IFormValidation($validate); $data = $formValidate->run(); } $model = new IModel($modelName); if (isset($data) && $data !== null) { $model->setData($data[$modelName]); if ($action = 'add') { $flag = $model->add(); } else { $flag = $model->upd("{$key} = '" . IReq::get($key) . "'"); } } if (isset($flag) && $flag) { $_GET['action'] = $actions['success']; } else { $_GET['action'] = $actions['fail']; } $controller->run(); return true; case 'del': $model = new IModel($modelName); $flag = $model->del("{$key} = '" . IReq::get($key) . "'"); if ($flag) { $_GET['action'] = $actions['success']; } else { $_GET['action'] = $actions['fail']; } $controller->run(); return true; case 'get': $model = new IModel($modelName); $rs = $model->getObj("{$key} = '" . IReq::get($key) . "'"); echo JSON::encode($rs); return false; } } }
/** * @brief 建议中心 */ public function complain_edit() { $id = IFilter::act(IReq::get('id'), 'int'); $title = IFilter::act(IReq::get('title'), 'string'); $content = IFilter::act(IReq::get('content'), 'string'); $user_id = $this->user['user_id']; $model = new IModel('suggestion'); $model->setData(array('user_id' => $user_id, 'title' => $title, 'content' => $content, 'time' => date('Y-m-d H:i:s'))); if ($id == '') { $model->add(); } else { $model->update('id = ' . $id); } $this->redirect('complain'); }
/** * @brief 向数据库写入log * @param array log数据 * @return bool 操作结果 */ public function write($logs = array()) { if (!is_array($logs) || empty($logs)) { throw new IException('the $logs parms must be array'); } if ($this->tableName == '') { throw new IException('the tableName is undefined'); } $logObj = new IModel($this->tableName); $logObj->setData($logs); $result = $logObj->add(); if ($result) { return true; } else { return false; } }
public static function ucenter_order() { $siteConfig = new Config('site_config'); $order_cancel_time = $siteConfig->order_cancel_time !== "" ? intval($siteConfig->order_cancel_time) : 7; $order_finish_time = $siteConfig->order_finish_time !== "" ? intval($siteConfig->order_finish_time) : 20; $orderModel = new IModel('order'); $orderCancelData = $order_cancel_time >= 0 ? $orderModel->query(" if_del = 0 and pay_type != 0 and status in(1) and datediff(NOW(),create_time) >= {$order_cancel_time} ", "id,order_no,4 as type_data") : array(); $orderCreateData = $order_finish_time >= 0 ? $orderModel->query(" if_del = 0 and distribution_status = 1 and status in(1,2) and datediff(NOW(),send_time) >= {$order_finish_time} ", "id,order_no,5 as type_data") : array(); $resultData = array_merge($orderCreateData, $orderCancelData); if ($resultData) { foreach ($resultData as $key => $val) { $type = $val['type_data']; $order_id = $val['id']; $order_no = $val['order_no']; //oerder表的对象 $tb_order = new IModel('order'); $tb_order->setData(array('status' => $type, 'completion_time' => ITime::getDateTime())); $tb_order->update('id=' . $order_id); //生成订单日志 $tb_order_log = new IModel('order_log'); //订单自动完成 if ($type == '5') { $action = '完成'; $note = '订单【' . $order_no . '】完成成功'; //完成订单并且进行支付 Order_Class::updateOrderStatus($order_no); //增加用户评论商品机会 Order_Class::addGoodsCommentChange($order_id); $logObj = new log('db'); $logObj->write('operation', array("系统自动", "订单更新为完成", '订单号:' . $order_no)); } else { $action = '作废'; $note = '订单【' . $order_no . '】作废成功'; //订单重置取消 Order_class::resetOrderProp($order_id); $logObj = new log('db'); $logObj->write('operation', array("系统自动", "订单更新为作废", '订单号:' . $order_no)); } $tb_order_log->setData(array('order_id' => $order_id, 'user' => "系统自动", 'action' => $action, 'result' => '成功', 'note' => $note, 'addtime' => ITime::getDateTime())); $tb_order_log->add(); } } }
/** * 写入日志并且更新账户余额 * @param array $config config数据类型 * @return string|bool */ public function write($config) { if (isset($config['user_id'])) { $this->setUser($config['user_id']); } else { throw new IException("用户信息不存在"); } isset($config['seller_id']) ? $this->setSeller($config['seller_id']) : ""; isset($config['admin_id']) ? $this->setAdmin($config['admin_id']) : ""; isset($config['event']) ? $this->setEvent($config['event']) : ""; if (isset($config['num']) && is_numeric($config['num'])) { $this->amount = abs(round($config['num'], 2)); //金额正负值处理 if (in_array($this->allow_event[$this->event], array(2, 3))) { $this->amount = '-' . abs($this->amount); } } else { throw new IException("金额必须大于0元"); } $this->config = $config; $this->noteData = isset($config['note']) ? $config['note'] : $this->note(); //写入数据库 $finnalAmount = $this->user['balance'] + $this->amount; if ($finnalAmount < 0) { throw new IException("用户余额不足"); } $memberDB = new IModel('member'); $memberDB->setData(array("balance" => $finnalAmount)); $memberDB->update("user_id = " . $this->user['id']); $tb_account_log = new IModel("account_log"); $insertData = array('admin_id' => $this->admin ? $this->admin['id'] : 0, 'user_id' => $this->user['id'], 'event' => $this->allow_event[$this->event], 'note' => $this->noteData, 'amount' => $this->amount, 'amount_log' => $finnalAmount, 'type' => $this->amount >= 0 ? 0 : 1, 'time' => ITime::getDateTime()); $tb_account_log->setData($insertData); $result = $tb_account_log->add(); //后台管理员操作记录 if ($insertData['admin_id']) { $logObj = new log('db'); $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "对账户金额进行了修改", $insertData['note'])); } return $result; }
function upload() { //图片上传 $upObj = new IUpload(); //目录散列 $dir = IWeb::$app->config['upload'] . '/' . date('Y') . "/" . date('m') . "/" . date('d'); $upObj->setDir($dir); $upState = $upObj->execute(); //实例化 $obj = new IModel('spec_photo'); //检查上传状态 foreach ($upState['attach'] as $val) { if ($val['flag'] == 1) { $insertData = array('address' => $val['dir'] . $val['name'], 'name' => $val['ininame'], 'create_time' => ITime::getDateTime()); $obj->setData($insertData); $obj->add(); } } if (count($upState['attach']) == 1) { return $upState['attach'][0]; } else { return $upState['attach']; } }
/** * 直接发站内信到用户 * 这个地方直接调用了Mysql的操作类 * @param $userIds string 用户Id的串 * @param $content 信件内容 array('title' => '标题','content' => '内容') */ public static function sendToUser($userIds, $content) { set_time_limit(0); //插入$content $data = array('title' => IFilter::act($content['title']), 'content' => IFilter::act($content['content'], 'text'), 'time' => date('Y-m-d H:i:s')); $msgDB = new IModel("message"); $msgDB->setData($data); $id = $msgDB->add(); if ($id === false) { return false; } else { $db = IDBFactory::getDB(); $tableName = IWeb::$app->config['DB']['tablePre'] . "member"; if ($userIds) { $sql = "UPDATE `{$tableName}` SET message_ids = CONCAT( IFNULL(message_ids,'') ,'{$id},') WHERE user_id in ({$userIds})"; } else { $sql = "UPDATE `{$tableName}` SET message_ids = CONCAT( IFNULL(message_ids,'') ,'{$id},')"; } return $db->query($sql); } }
/** * @brief 保存商品分类 */ function category_save() { //获得post值 $category_id = IFilter::act(IReq::get('category_id'), 'int'); $name = IFilter::act(IReq::get('name')); $parent_id = IFilter::act(IReq::get('parent_id'), 'int'); $visibility = IFilter::act(IReq::get('visibility'), 'int'); $sort = IFilter::act(IReq::get('sort'), 'int'); $title = IFilter::act(IReq::get('title')); $keywords = IFilter::act(IReq::get('keywords')); $descript = IFilter::act(IReq::get('descript')); $tb_category = new IModel('category'); $category_info = array('name' => $name, 'parent_id' => $parent_id, 'sort' => $sort, 'visibility' => $visibility, 'keywords' => $keywords, 'descript' => $descript, 'title' => $title); $tb_category->setData($category_info); if ($category_id) { $where = "id=" . $category_id; $tb_category->update($where); } else { $tb_category->add(); } //更新缓存 $cacheObj = new ICache('file'); $cacheObj->del('goodsCategory'); $this->category_list(); }
function spec_update() { //获取是否为block模块 $isBlock = IReq::get('block', 'get'); //显示方式 $specType = IReq::get('type', 'post'); //规格数据 $valueArray = IReq::get('value', 'post'); //要插入的数据 if (is_array($valueArray) && isset($valueArray[0]) && $valueArray[0] != '') { $valueArray = array_unique($valueArray); foreach ($valueArray as $key => $rs) { if ($rs == '') { unset($valueArray[$key]); } } if (!$valueArray) { $isPass = false; $errorMessage = "请上传规格图片"; } else { $value = serialize($valueArray); } } else { $value = ''; } $editData = array('id' => IReq::get('id', 'post'), 'name' => IReq::get('name', 'post'), 'value' => $value, 'type' => IReq::get('type', 'post'), 'note' => IReq::get('note', 'post')); //校验 $isPass = true; if ($value == '') { $isPass = false; $errorMessage = '规格值不能为空,请填写规格值或上传规格图片'; } if ($editData['name'] == '') { $isPass = false; $errorMessage = '规格名称不能为空'; } if ($isPass == false) { //block部分 if ($isBlock !== null) { $blockObj = new Block($this->module, 'block'); $blockObj->setRenderData($editData); $blockObj->redirect('spec_edit', false); } else { $this->setRenderData($editData); $this->redirect('spec_edit', false); } Util::showMessage($errorMessage); } else { $obj = new IModel('spec'); //执行操作 $obj->setData($editData); if ($id = IReq::get('id')) { $where = 'id = ' . $id; $result = $obj->update($where); } else { $result = $obj->add(); } //执行状态 if ($result === false) { //block部分 if ($isBlock !== null) { $blockObj = new Block($this->module, 'block'); $blockObj->setRenderData($editData); $blockObj->redirect('spec_edit', false); } else { $this->setRenderData($editData); $this->redirect('spec_edit'); } } else { //block部分 if ($isBlock !== null) { echo '<script>parent.closeSpec();</script>'; } else { $this->redirect('spec_list'); } } } }
function goods_copy() { $idArray = explode(',', IReq::get('id')); $idArray = IFilter::act($idArray, 'int'); $goodsDB = new IModel('goods'); $goodsAttrDB = new IModel('goods_attribute'); $goodsPhotoRelationDB = new IModel('goods_photo_relation'); $productsDB = new IModel('products'); $goodsData = $goodsDB->query('id in (' . join(',', $idArray) . ') and is_share = 1 and is_del = 0 and seller_id = 0', '*'); if ($goodsData) { foreach ($goodsData as $key => $val) { //判断是否重复 if ($goodsDB->getObj('seller_id = ' . $this->seller['seller_id'] . ' and name = "' . $val['name'] . '"')) { die('商品不能重复复制'); } $oldId = $val['id']; //商品数据 unset($val['id'], $val['visit'], $val['favorite'], $val['sort'], $val['comments'], $val['sale'], $val['grade'], $val['is_share']); $val['seller_id'] = $this->seller['seller_id']; $val['goods_no'] .= '-' . $this->seller['seller_id']; $goodsDB->setData($val); $goods_id = $goodsDB->add(); //商品属性 $attrData = $goodsAttrDB->query('goods_id = ' . $oldId); if ($attrData) { foreach ($attrData as $k => $v) { unset($v['id']); $v['goods_id'] = $goods_id; $goodsAttrDB->setData($v); $goodsAttrDB->add(); } } //商品图片 $photoData = $goodsPhotoRelationDB->query('goods_id = ' . $oldId); if ($photoData) { foreach ($photoData as $k => $v) { unset($v['id']); $v['goods_id'] = $goods_id; $goodsPhotoRelationDB->setData($v); $goodsPhotoRelationDB->add(); } } //货品 $productsData = $productsDB->query('goods_id = ' . $oldId); if ($productsData) { foreach ($productsData as $k => $v) { unset($v['id']); $v['products_no'] .= '-' . $this->seller['seller_id']; $v['goods_id'] = $goods_id; $productsDB->setData($v); $productsDB->add(); } } } die('success'); } else { die('复制的商品不存在'); } }
public static function cat_edit($arr) { if (!isset($arr['id']) || $arr['id'] === null || !preg_match("![0-9]+!", $arr['id'])) { unset($arr['id']); } if ($arr['name'] === null || !preg_match('!^.{1,10}$!u', $arr['name'])) { return array('flag' => false, 'data' => '分类名称不能超过十个文字'); } $arr['name'] = htmlspecialchars($arr['name'], ENT_QUOTES); $arr['sort'] = intval($arr['sort']); $arr['position_left'] = intval($arr['position_left']) == 1 ? 1 : 0; $arr['position_foot'] = intval($arr['position_foot']) == 1 ? 1 : 0; $tb_help_category = new IModel("help_category"); $tb_help_category->setData($arr); if (isset($arr['id'])) { $id = intval($arr['id']); unset($arr['id']); $tb_help_category->update("id={$id}"); } else { $tb_help_category->add($arr); } return array('flag' => true, 'data' => "编辑成功"); }
function navigation_update() { $id = IFilter::act(IReq::get('id', 'post'), 'int'); $navigationObj = new IModel('quick_naviga'); $navigationObj->setData(array('adminid' => $this->admin['admin_id'], 'naviga_name' => IFilter::act(IReq::get('naviga_name')), 'url' => IFilter::act(IReq::get('url')))); if ($id) { $navigationObj->update('id=' . $id); } else { $navigationObj->add(); } $this->redirect('navigation'); }
function address_add() { $accept_name = IFilter::act(IReq::get('accept_name')); $province = IFilter::act(IReq::get('province'), 'int'); $city = IFilter::act(IReq::get('city'), 'int'); $area = IFilter::act(IReq::get('area'), 'int'); $address = IFilter::act(IReq::get('address')); $zip = IFilter::act(IReq::get('zip')); $telphone = IFilter::act(IReq::get('telphone')); $mobile = IFilter::act(IReq::get('mobile')); $user_id = $this->user['user_id']; if (!$user_id) { die(JSON::encode(array('data' => null))); } //整合的数据,检查数据库中是否存在此收货地址 $sqlData = array('user_id' => $user_id, 'accept_name' => $accept_name, 'zip' => $zip, 'telphone' => $telphone, 'province' => $province, 'city' => $city, 'area' => $area, 'address' => $address, 'mobile' => $mobile); $sqlArray = array(); foreach ($sqlData as $key => $val) { $sqlArray[] = $key . '="' . $val . '"'; } $model = new IModel('address'); $addressRow = $model->getObj(join(' and ', $sqlArray)); if ($addressRow) { $result = array('data' => null); } else { //获取地区text $areaList = area::name($province, $city, $area); //执行insert $model->setData($sqlData); $id = $model->add(); $sqlData['id'] = $id; $sqlData['province_val'] = $areaList[$province]; $sqlData['city_val'] = $areaList[$city]; $sqlData['area_val'] = $areaList[$area]; $result = array('data' => $sqlData); } die(JSON::encode($result)); }
/** * @brief 把订单商品同步到order_goods表中 * @param $order_id 订单ID * @param $goodsInfo 商品和货品信息(购物车数据结构,countSum 最终生成的格式) */ public function insertOrderGoods($order_id, $goodsResult = array()) { $orderGoodsObj = new IModel('order_goods'); //清理旧的关联数据 $orderGoodsObj->del('order_id = ' . $order_id); $goodsArray = array('order_id' => $order_id); $findType = array('goods' => 'goodsList', 'product' => 'productList'); foreach ($findType as $key => $list) { if (isset($goodsResult[$list]) && count($goodsResult[$list]) > 0) { foreach ($goodsResult[$list] as $k => $val) { //拼接商品名称和规格数据 $specArray = array('name' => $val['name'], 'value' => ''); if ($key == 'product') { $goodsArray['product_id'] = $val['id']; $goodsArray['goods_id'] = $val['goods_id']; $spec = block::show_spec($val['spec_array']); foreach ($spec as $skey => $svalue) { $specArray['value'] .= $skey . ':' . $svalue . ' , '; } } else { $goodsArray['goods_id'] = $val['id']; $goodsArray['product_id'] = 0; } $goodsArray['img'] = $val['img']; $goodsArray['goods_price'] = $val['sell_price']; $goodsArray['real_price'] = $val['sell_price'] - $val['reduce']; $goodsArray['goods_nums'] = $val['count']; $goodsArray['goods_weight'] = $val['weight']; $goodsArray['goods_array'] = JSON::encode($specArray); $orderGoodsObj->setData($goodsArray); $orderGoodsObj->add(); } } } }
function trade_ticket() { $ticketId = IFilter::act(IReq::get('ticket_id', 'post'), 'int'); $message = ''; if (intval($ticketId) == 0) { $message = '请选择要兑换的代金券'; } else { $nowTime = ITime::getDateTime(); $ticketObj = new IModel('ticket'); $ticketRow = $ticketObj->getObj('id = ' . $ticketId . ' and point > 0 and start_time <= "' . $nowTime . '" and end_time > "' . $nowTime . '"'); if (empty($ticketRow)) { $message = '对不起,此代金券不能兑换'; } else { $memberObj = new IModel('member'); $where = 'user_id = ' . $this->user['user_id']; $memberRow = $memberObj->getObj($where, 'point'); if ($ticketRow['point'] > $memberRow['point']) { $message = '对不起,您的积分不足,不能兑换此类代金券'; } else { //生成红包 $dataArray = array('condition' => $ticketRow['id'], 'name' => $ticketRow['name'], 'card_name' => 'T' . IHash::random(8), 'card_pwd' => IHash::random(8), 'value' => $ticketRow['value'], 'start_time' => $ticketRow['start_time'], 'end_time' => $ticketRow['end_time'], 'is_send' => 1); $propObj = new IModel('prop'); $propObj->setData($dataArray); $insert_id = $propObj->add(); //用户prop字段值null时 $memberArray = array('prop' => ',' . $insert_id . ','); $memberObj->setData($memberArray); $result = $memberObj->update('user_id = ' . $this->user["user_id"] . ' and ( prop is NULL or prop = "" )'); //用户prop字段值非null时 if (!$result) { $memberArray = array('prop' => 'concat(prop,"' . $insert_id . ',")'); $memberObj->setData($memberArray); $result = $memberObj->update('user_id = ' . $this->user["user_id"], 'prop'); } //代金券成功 if ($result) { $pointConfig = array('user_id' => $this->user['user_id'], 'point' => '-' . $ticketRow['point'], 'log' => '积分兑换代金券,扣除了 -' . $ticketRow['point'] . '积分'); $pointObj = new Point(); $pointObj->update($pointConfig); } } } } //展示 if ($message != '') { $this->integral(); Util::showMessage($message); } else { $this->redirect('redpacket'); } }
/** * @brief 修改商品数据 * @param int $id 商品ID * @param array $paramData 商品所需数据 */ public function update($id, $paramData) { $postData = array(); $nowDataTime = ITime::getDateTime(); foreach ($paramData as $key => $val) { $postData[$key] = $val; //数据过滤分组 if (strpos($key, 'attr_id_') !== false) { $goodsAttrData[ltrim($key, 'attr_id_')] = IFilter::act($val); } else { if ($key == 'content') { $goodsUpdateData['content'] = IFilter::addSlash($val); } else { if ($key[0] != '_') { $goodsUpdateData[$key] = IFilter::act($val, 'text'); } } } } //商家发布商品默认设置 if ($this->seller_id) { $goodsUpdateData['seller_id'] = $this->seller_id; $goodsUpdateData['is_del'] = $goodsUpdateData['is_del'] == 2 ? 2 : 3; //如果商户是VIP则无需审核商品 if ($goodsUpdateData['is_del'] == 3) { $sellerDB = new IModel('seller'); $sellerRow = $sellerDB->getObj('id = ' . $this->seller_id); if ($sellerRow['is_vip'] == 1) { $goodsUpdateData['is_del'] = 0; } } } //上架或者下架处理 if (isset($goodsUpdateData['is_del'])) { //上架 if ($goodsUpdateData['is_del'] == 0) { $goodsUpdateData['up_time'] = $nowDataTime; $goodsUpdateData['down_time'] = null; } else { if ($goodsUpdateData['is_del'] == 2) { $goodsUpdateData['up_time'] = null; $goodsUpdateData['down_time'] = $nowDataTime; } else { $goodsUpdateData['up_time'] = null; $goodsUpdateData['down_time'] = null; } } } //是否存在货品 $goodsUpdateData['spec_array'] = ''; if (isset($postData['_spec_array'])) { //生成goods中的spec_array字段数据 $goods_spec_array = array(); foreach ($postData['_spec_array'] as $key => $val) { foreach ($val as $v) { $tempSpec = JSON::decode($v); if (!isset($goods_spec_array[$tempSpec['id']])) { $goods_spec_array[$tempSpec['id']] = array('id' => $tempSpec['id'], 'name' => $tempSpec['name'], 'type' => $tempSpec['type'], 'value' => array()); } $goods_spec_array[$tempSpec['id']]['value'][] = $tempSpec['value']; } } foreach ($goods_spec_array as $key => $val) { $val['value'] = array_unique($val['value']); $goods_spec_array[$key]['value'] = join(',', $val['value']); } $goodsUpdateData['spec_array'] = JSON::encode($goods_spec_array); } $goodsUpdateData['goods_no'] = isset($postData['_goods_no']) ? current($postData['_goods_no']) : ''; $goodsUpdateData['store_nums'] = array_sum($postData['_store_nums']); $goodsUpdateData['market_price'] = isset($postData['_market_price']) ? current($postData['_market_price']) : 0; $goodsUpdateData['sell_price'] = isset($postData['_sell_price']) ? current($postData['_sell_price']) : 0; $goodsUpdateData['cost_price'] = isset($postData['_cost_price']) ? current($postData['_cost_price']) : 0; $goodsUpdateData['weight'] = isset($postData['_weight']) ? current($postData['_weight']) : 0; //处理商品 $goodsDB = new IModel('goods'); if ($id) { $goodsDB->setData($goodsUpdateData); $where = " id = {$id} "; if ($this->seller_id) { $where .= " and seller_id = " . $this->seller_id; } if ($goodsDB->update($where) === false) { die("更新商品错误"); } } else { $goodsUpdateData['create_time'] = $nowDataTime; $goodsDB->setData($goodsUpdateData); $id = $goodsDB->add(); } //处理商品属性 $goodsAttrDB = new IModel('goods_attribute'); $goodsAttrDB->del('goods_id = ' . $id); if (isset($goodsAttrData) && $goodsAttrData) { foreach ($goodsAttrData as $key => $val) { $attrData = array('goods_id' => $id, 'model_id' => $goodsUpdateData['model_id'], 'attribute_id' => $key, 'attribute_value' => is_array($val) ? join(',', $val) : $val); $goodsAttrDB->setData($attrData); $goodsAttrDB->add(); } } //是否存在货品 $productsDB = new IModel('products'); $productsDB->del('goods_id = ' . $id); if (isset($postData['_spec_array'])) { $productIdArray = array(); //创建货品信息 foreach ($postData['_goods_no'] as $key => $rs) { $productsData = array('goods_id' => $id, 'products_no' => $postData['_goods_no'][$key], 'store_nums' => $postData['_store_nums'][$key], 'market_price' => $postData['_market_price'][$key], 'sell_price' => $postData['_sell_price'][$key], 'cost_price' => $postData['_cost_price'][$key], 'weight' => $postData['_weight'][$key], 'spec_array' => "[" . join(',', $postData['_spec_array'][$key]) . "]"); $productsDB->setData($productsData); $productIdArray[$key] = $productsDB->add(); } } //处理商品分类 $categoryDB = new IModel('category_extend'); $categoryDB->del('goods_id = ' . $id); if (isset($postData['_goods_category']) && $postData['_goods_category']) { foreach ($postData['_goods_category'] as $item) { $categoryDB->setData(array('goods_id' => $id, 'category_id' => $item)); $categoryDB->add(); } } //处理商品促销 $commendDB = new IModel('commend_goods'); $commendDB->del('goods_id = ' . $id); if (isset($postData['_goods_commend']) && $postData['_goods_commend']) { foreach ($postData['_goods_commend'] as $item) { $commendDB->setData(array('goods_id' => $id, 'commend_id' => $item)); $commendDB->add(); } } //处理商品关键词 keywords::add($goodsUpdateData['search_words']); //处理商品图片 $photoRelationDB = new IModel('goods_photo_relation'); $photoRelationDB->del('goods_id = ' . $id); if (isset($postData['_imgList']) && $postData['_imgList']) { $postData['_imgList'] = str_replace(',', '","', trim($postData['_imgList'], ',')); $photoDB = new IModel('goods_photo'); $photoData = $photoDB->query('img in ("' . $postData['_imgList'] . '")', 'id'); if ($photoData) { foreach ($photoData as $item) { $photoRelationDB->setData(array('goods_id' => $id, 'photo_id' => $item['id'])); $photoRelationDB->add(); } } } //处理会员组的价格 $groupPriceDB = new IModel('group_price'); $groupPriceDB->del('goods_id = ' . $id); if (isset($productIdArray) && $productIdArray) { foreach ($productIdArray as $index => $value) { if (isset($postData['_groupPrice'][$index]) && $postData['_groupPrice'][$index]) { $temp = JSON::decode($postData['_groupPrice'][$index]); foreach ($temp as $k => $v) { $groupPriceDB->setData(array('goods_id' => $id, 'product_id' => $value, 'group_id' => $k, 'price' => $v)); $groupPriceDB->add(); } } } } else { if (isset($postData['_groupPrice'][0]) && $postData['_groupPrice'][0]) { $temp = JSON::decode($postData['_groupPrice'][0]); foreach ($temp as $k => $v) { $groupPriceDB->setData(array('goods_id' => $id, 'group_id' => $k, 'price' => $v)); $groupPriceDB->add(); } } } return true; }
function spec_update() { //显示方式 $specType = IReq::get('type'); //规格数据 $valueArray = IReq::get('value'); //要插入的数据 if (is_array($valueArray) && isset($valueArray[0]) && $valueArray[0] != '') { $valueArray = array_unique($valueArray); foreach ($valueArray as $key => $rs) { if ($rs == '') { unset($valueArray[$key]); } } if (!$valueArray) { $isPass = false; $errorMessage = "请上传规格图片"; } else { $value = JSON::encode($valueArray); } } else { $value = ''; } $editData = array('id' => IReq::get('id'), 'name' => IReq::get('name'), 'value' => $value, 'type' => IReq::get('type'), 'note' => IReq::get('note')); //校验 $isPass = true; if ($value == '') { $isPass = false; $errorMessage = '规格值不能为空,请填写规格值或上传规格图片'; } if ($editData['name'] == '') { $isPass = false; $errorMessage = '规格名称不能为空'; } if ($isPass == false) { echo JSON::encode(array('flag' => 'fail', 'message' => $errorMessage)); exit; } else { $obj = new IModel('spec'); //执行操作 $obj->setData($editData); if ($id = IReq::get('id')) { $where = 'id = ' . $id; $result = $obj->update($where); } else { $result = $obj->add(); } //执行状态 if ($result === false) { echo JSON::encode(array('flag' => 'fail', 'message' => '数据库更新失败')); } else { //获取自动增加ID $editData['id'] = $id ? $id : $result; echo JSON::encode(array('flag' => 'success', 'data' => $editData)); } } }
public function expresswaybill_edit_act() { $id = intval(IReq::get('id')); $printExpress = IReq::get('printExpress'); $name = IFilter::act(IReq::get('express_name')); $width = intval(IReq::get('width')); $height = intval(IReq::get('height')); $background = IFilter::act(IReq::get('printBackground')); $background = ltrim($background, IUrl::creatUrl('')); if (!$printExpress) { $printExpress = array(); } if (!$name) { die('快递单的名称不能为空'); } $expressObj = new IModel('expresswaybill'); $data = array('config' => serialize($printExpress), 'name' => $name, 'width' => $width, 'height' => $height, 'background' => $background); $expressObj->setData($data); //修改模式 if ($id) { $is_result = $expressObj->update('id = ' . $id); } else { $is_result = $expressObj->add(); } echo $is_result === false ? '操作失败' : 'success'; }
/** * @brief 商户的增加动作 */ public function seller_add() { $seller_id = IFilter::act(IReq::get('id'), 'int'); $seller_name = IFilter::act(IReq::get('seller_name')); $email = IFilter::act(IReq::get('email')); $password = IFilter::act(IReq::get('password')); $repassword = IFilter::act(IReq::get('repassword')); $truename = IFilter::act(IReq::get('true_name')); $phone = IFilter::act(IReq::get('phone')); $mobile = IFilter::act(IReq::get('mobile')); $province = IFilter::act(IReq::get('province'), 'int'); $city = IFilter::act(IReq::get('city'), 'int'); $area = IFilter::act(IReq::get('area'), 'int'); $cash = IFilter::act(IReq::get('cash'), 'float'); $is_vip = IFilter::act(IReq::get('is_vip'), 'int'); $is_lock = IFilter::act(IReq::get('is_lock'), 'int'); $address = IFilter::act(IReq::get('address')); $account = IFilter::act(IReq::get('account')); $server_num = IFilter::act(IReq::get('server_num')); $home_url = IFilter::act(IReq::get('home_url')); $sort = IFilter::act(IReq::get('sort'), 'int'); if (!$seller_id && $password == '') { $errorMsg = '请输入密码!'; } if ($password != $repassword) { $errorMsg = '两次输入的密码不一致!'; } //创建商家操作类 $sellerDB = new IModel("seller"); if ($sellerDB->getObj("seller_name = '{$seller_name}' and id != {$seller_id}")) { $errorMsg = "登录用户名重复"; } else { if ($sellerDB->getObj("true_name = '{$truename}' and id != {$seller_id}")) { $errorMsg = "商户真实全程重复"; } } //操作失败表单回填 if (isset($errorMsg)) { $this->sellerRow = $_POST; $this->redirect('seller_edit', false); Util::showMessage($errorMsg); } //待更新的数据 $sellerRow = array('true_name' => $truename, 'account' => $account, 'phone' => $phone, 'mobile' => $mobile, 'email' => $email, 'address' => $address, 'is_vip' => $is_vip, 'is_lock' => $is_lock, 'cash' => $cash, 'province' => $province, 'city' => $city, 'area' => $area, 'server_num' => $server_num, 'home_url' => $home_url, 'sort' => $sort); //商户资质上传 if (isset($_FILES['paper_img']['name']) && $_FILES['paper_img']['name']) { $uploadObj = new PhotoUpload(); $uploadObj->setIterance(false); $photoInfo = $uploadObj->run(); if (isset($photoInfo['paper_img']['img']) && file_exists($photoInfo['paper_img']['img'])) { $sellerRow['paper_img'] = $photoInfo['paper_img']['img']; } } //添加新会员 if (!$seller_id) { $sellerRow['seller_name'] = $seller_name; $sellerRow['password'] = md5($password); $sellerRow['create_time'] = ITime::getDateTime(); $sellerDB->setData($sellerRow); $sellerDB->add(); } else { //修改密码 if ($password) { $sellerRow['password'] = md5($password); } $sellerDB->setData($sellerRow); $sellerDB->update("id = " . $seller_id); } $this->redirect('seller_list'); }
/** * @brief 保存用户组修改 */ function group_save() { $maxexp = IReq::get('maxexp'); $minexp = IReq::get('minexp'); if ($maxexp <= $minexp) { $errorMsg = '最大经验值必须大于最小经验值'; } $group_id = (int) IReq::get('group_id', 'post'); $form_array = array('user_group' => array(array('name' => 'group_name', 'field' => 'group_name', 'rules' => 'required'), array('name' => 'discount', 'field' => 'discount'), array('name' => 'minexp', 'field' => 'minexp'), array('name' => 'maxexp', 'field' => 'maxexp'))); //验证表单 $validationObj = new Formvalidation($form_array); $form_data = $validationObj->run(); foreach ($form_data as $key => $value) { foreach ($value as $v) { $group[$v['name']] = $v['postdate']; $tb_model[$v['field']] = $v['postdate']; } } if ($validationObj->isError() || isset($errorMsg)) { //验证失败 $this->data['group'] = $group; $this->setRenderData($this->data); //加载视图 $this->redirect('group_edit', false); $errorMsg = isset($errorMsg) ? $errorMsg : $validationObj->getError(); Util::showMessage($errorMsg); } else { //验证成功 $tb_user_group = new IModel("user_group"); $tb_user_group->setData($tb_model); if ($group_id) { $affected_rows = $tb_user_group->update("id=" . $group_id); if ($affected_rows) { $this->redirect('group_list', false); Util::showMessage('更新用户组成功!'); return; } $this->redirect('group_list', false); } else { $gid = $tb_user_group->add(); $this->redirect('group_list', false); if ($gid) { Util::showMessage('添加用户组成功!'); } else { Util::showMessage('添加用户组失败!'); } } } }
/** * @brief 商品属性添加/修改 * @param array $attribute 表字段 数组格式,如Array ([name] => Array ( [0] => '' ) * [show_type] => Array ( [0] => '' ) * [value] => Array ( [0] => '' ) * [is_seach] => Array ( [0] => 1 )) * @param int $model_id 模型编号 */ public function attribute_update($attribute, $model_id) { //初始化attribute商品模型属性表类对象 $attributeObj = new IModel('attribute'); $len = count($attribute['name']); $ids = ""; for ($i = 0; $i < $len; $i++) { if (isset($attribute['name'][$i]) && isset($attribute['value'][$i])) { $options = str_replace(',', ',', $attribute['value'][$i]); $type = isset($attribute['is_search'][$i]) ? $attribute['is_search'][$i] : 0; //设置商品模型扩展属性 字段赋值 $filedData = array("model_id" => intval($model_id), "type" => IFilter::act($attribute['show_type'][$i]), "name" => $attribute['name'][$i], "value" => rtrim($options, ','), "search" => IFilter::act($type)); $attributeObj->setData($filedData); $id = intval($attribute['id'][$i]); if ($id) { //更新商品模型扩展属性 $attributeObj->update("id = " . $id); } else { //新增商品模型扩展属性 $id = $attributeObj->add(); } $ids .= $id . ','; } } if ($ids) { $ids = trim($ids, ','); //删除商品模型扩展属性 $where = "model_id = {$model_id} and id not in (" . $ids . ") "; $attributeObj->del($where); } }
/** * @brief 保存用户组修改 */ function group_save() { $group_id = IFilter::act(IReq::get('group_id'), 'int'); $maxexp = IFilter::act(IReq::get('maxexp'), 'int'); $minexp = IFilter::act(IReq::get('minexp'), 'int'); $discount = IFilter::act(IReq::get('discount'), 'float'); $group_name = IFilter::act(IReq::get('group_name')); $group = array('maxexp' => $maxexp, 'minexp' => $minexp, 'discount' => $discount, 'group_name' => $group_name); if ($discount > 100) { $errorMsg = '折扣率不能大于100'; } if ($maxexp <= $minexp) { $errorMsg = '最大经验值必须大于最小经验值'; } if (isset($errorMsg) && $errorMsg) { $group['group_id'] = $group_id; $data = array($group); $this->setRenderData($data); $this->redirect('group_edit', false); Util::showMessage($errorMsg); exit; } $tb_user_group = new IModel("user_group"); $tb_user_group->setData($group); if ($group_id) { $affected_rows = $tb_user_group->update("id=" . $group_id); if ($affected_rows) { $this->redirect('group_list', false); Util::showMessage('更新用户组成功!'); return; } $this->redirect('group_list', false); } else { $gid = $tb_user_group->add(); $this->redirect('group_list', false); if ($gid) { Util::showMessage('添加用户组成功!'); } else { Util::showMessage('添加用户组失败!'); } } }
function regiment_edit_act() { $id = IFilter::act(IReq::get('id'), 'int'); $goodsId = IFilter::act(IReq::get('goods_id'), 'int'); $dataArray = array('id' => $id, 'title' => IFilter::act(IReq::get('title', 'post')), 'start_time' => IFilter::act(IReq::get('start_time', 'post')), 'end_time' => IFilter::act(IReq::get('end_time', 'post')), 'is_close' => IFilter::act(IReq::get('is_close', 'post')), 'intro' => IFilter::act(IReq::get('intro', 'post')), 'goods_id' => $goodsId, 'store_nums' => IFilter::act(IReq::get('store_nums', 'post')), 'limit_min_count' => IFilter::act(IReq::get('limit_min_count', 'post'), 'int'), 'limit_max_count' => IFilter::act(IReq::get('limit_max_count', 'post'), 'int'), 'regiment_price' => IFilter::act(IReq::get('regiment_price', 'post')), 'sort' => IFilter::act(IReq::get('sort', 'post'))); if ($goodsId) { $goodsObj = new IModel('goods'); $where = 'id = ' . $goodsId; $goodsRow = $goodsObj->getObj($where); //处理上传图片 if (isset($_FILES['img']['name']) && $_FILES['img']['name'] != '') { $uploadObj = new PhotoUpload(); $photoInfo = $uploadObj->run(); $dataArray['img'] = $photoInfo['img']['img']; } else { $dataArray['img'] = $goodsRow['img']; } $dataArray['sell_price'] = $goodsRow['sell_price']; } else { $this->regimentRow = $dataArray; $this->redirect('regiment_edit', false); Util::showMessage('请选择要关联的商品'); } $regimentObj = new IModel('regiment'); $regimentObj->setData($dataArray); if ($id) { $where = 'id = ' . $id; $regimentObj->update($where); } else { $regimentObj->add(); } $this->redirect('regiment_list'); }
function ad_edit_act() { $id = IFilter::act(IReq::get('id'), 'int'); $adObj = new IModel('ad_manage'); $error_message = null; //获取content数据 $type = IReq::get('type', 'post'); $content = IReq::get('content', 'post'); $upObj = null; switch ($type) { case "1": //图片上传 $upObj = new IUpload(); $attach = 'img'; break; case "2": //flash上传 $upObj = new IUpload('4048', array('flv', 'swf')); $attach = 'flash'; break; case "3": //文字 $content = IReq::get('text', 'post'); break; case "4": //代码 $content = IReq::get('code', 'post'); break; } if ($upObj != null) { //目录散列 $dir = IWeb::$app->config['upload'] . '/' . date('Y') . "/" . date('m') . "/" . date('d'); $upObj->setDir($dir); $upState = $upObj->execute(); if (!isset($upState[$attach])) { if ($content == '') { $error_message = '没有上传文件'; } } else { if ($upState[$attach][0]['flag'] == 1) { $content = $dir . '/' . $upState[$attach][0]['name']; } else { $error_message = IUpload::errorMessage($upState[$attach][0]['flag']); } } } else { if ($content == '') { $error_message = '请填写广告展示类型的内容'; } } $dataArray = array('content' => IFilter::addSlash($content), 'name' => IFilter::act(IReq::get('name')), 'position_id' => IFilter::act(IReq::get('position_id')), 'type' => IFilter::act(IReq::get('type')), 'link' => IFilter::addSlash(IReq::get('link')), 'start_time' => IFilter::act(IReq::get('start_time')), 'end_time' => IFilter::act(IReq::get('end_time')), 'description' => IFilter::act(IReq::get('description'), 'text'), 'order' => IFilter::act(IReq::get('order'), 'int'), 'goods_cat_id' => IFilter::act(IReq::get('goods_cat_id'), 'int')); //上传错误 if ($error_message != null) { if ($id) { $dataArray['id'] = $id; } $this->adRow = $dataArray; $this->redirect('ad_edit', false); Util::showMessage($error_message); } $adObj->setData($dataArray); if ($id) { $where = 'id = ' . $id; $adObj->update($where); } else { $adObj->add(); } $this->redirect("ad_list"); }
public function update_commend() { $data = IFilter::act(IReq::get('data')); //key => 商品ID或货品ID ; value => commend值 1~4 if (!$data) { die(JSON::encode(array('result' => 'fail', 'data' => '商品数据不存在'))); } $goodsCommendDB = new IModel('commend_goods'); //清理旧的commend数据 $goodsIdArray = array_keys($data); $goodsCommendDB->del("goods_id in (" . join(',', $goodsIdArray) . ")"); //插入新的commend数据 foreach ($data as $id => $commend) { foreach ($commend as $k => $value) { if ($value > 0) { $goodsCommendDB->setData(array('commend_id' => $value, 'goods_id' => $id)); $goodsCommendDB->add(); } } } die(JSON::encode(array('result' => 'success'))); }
/** * 操作数据库 * * @param float $num 操作金额 * @return bool|array 返回true代表成功,返回array代表着本次操作的错误信息 */ private function log($num) { if (!is_numeric($num)) { $this->error[] = "错误的操作金额:{$num}"; return $this->error; } $num = sprintf("%.2f", $num); $this->num = $num; if ($this->_note === null) { $this->note(); } if ($this->error) { return $this->error; } $tb_account_log = new IModel("account_log"); $arr = array(); $arr['admin_id'] = $this->admin['id']; $arr['user_id'] = $this->user['id']; $arr['event'] = $this->allow_event[$this->event]; $arr['note'] = addslashes($this->_note); $arr['amount'] = $num; $arr['amount_log'] = $this->user['balance']; $arr['type'] = $num >= 0 ? 0 : 1; $arr['time'] = $this->time; $tb_account_log->setData($arr); $tb_account_log->add(); //后台管理员操作记录 if ($arr['admin_id']) { $logObj = new Log(); $logObj->write('operation', array("管理员:" . ISafe::get('admin_name'), "对账户金额进行了修改", $arr['note'])); } return true; }
/** * @brief 获取订单中的支付信息 M:必要信息; R表示店铺; P表示用户; * @param $payment_id int 支付方式ID * @param $type string 信息获取方式 order:订单支付;recharge:在线充值; * @param $argument mix 参数 * @return array 支付提交信息 */ public static function getPaymentInfo($payment_id, $type, $argument) { //最终返回值 $payment = array(); //初始化配置参数 $paymentInstance = Payment::createPaymentInstance($payment_id); $configParam = $paymentInstance->configParam(); foreach ($configParam as $key => $val) { $payment[$key] = ''; } //获取公共信息 $paymentRow = self::getPaymentById($payment_id, 'config_param'); if ($paymentRow) { $paymentRow = JSON::decode($paymentRow); foreach ($paymentRow as $key => $item) { $payment[$key] = $item; } } if ($type == 'order') { $orderIdArray = $argument; $M_Amount = 0; $M_OrderNO = array(); foreach ($orderIdArray as $key => $order_id) { //获取订单信息 $orderObj = new IModel('order'); $orderRow = $orderObj->getObj('id = ' . $order_id . ' and status = 1'); if (empty($orderRow)) { IError::show(403, '订单信息不正确,不能进行支付'); } //判断商品库存 $orderGoodsDB = new IModel('order_goods'); $orderGoodsList = $orderGoodsDB->query('order_id = ' . $order_id); foreach ($orderGoodsList as $key => $val) { if (!goods_class::checkStore($val['goods_nums'], $val['goods_id'], $val['product_id'])) { IError::show(403, '商品库存不足无法支付,请重新下单'); } } $M_Amount += $orderRow['order_amount']; $M_OrderNO[] = $orderRow['order_no']; } $payment['M_Remark'] = $orderRow['postscript']; $payment['M_OrderId'] = $orderRow['id']; $payment['M_OrderNO'] = $orderRow['order_no']; $payment['M_Amount'] = $M_Amount; //用户信息 $payment['P_Mobile'] = $orderRow['mobile']; $payment['P_Name'] = $orderRow['accept_name']; $payment['P_PostCode'] = $orderRow['postcode']; $payment['P_Telephone'] = $orderRow['telphone']; $payment['P_Address'] = $orderRow['address']; //订单批量结算缓存机制 $cacheObj = new ICache('file'); $cacheObj->set($payment['M_OrderNO'], join(",", $M_OrderNO)); } else { if ($type == 'recharge') { if (ISafe::get('user_id') == null) { IError::show(403, '请登录系统'); } if (!isset($argument['account']) || $argument['account'] <= 0) { IError::show(403, '请填入正确的充值金额'); } $rechargeObj = new IModel('online_recharge'); $reData = array('user_id' => ISafe::get('user_id'), 'recharge_no' => Order_Class::createOrderNum(), 'account' => $argument['account'], 'time' => ITime::getDateTime(), 'payment_name' => $argument['paymentName']); $rechargeObj->setData($reData); $r_id = $rechargeObj->add(); //充值时用户id跟随交易号一起发送,以"_"分割 $payment['M_OrderNO'] = 'recharge' . $reData['recharge_no']; $payment['M_OrderId'] = $r_id; $payment['M_Amount'] = $reData['account']; } } $siteConfigObj = new Config("site_config"); $site_config = $siteConfigObj->getInfo(); //交易信息 $payment['M_Time'] = time(); $payment['M_Paymentid'] = $payment_id; //店铺信息 $payment['R_Address'] = isset($site_config['address']) ? $site_config['address'] : ''; $payment['R_Name'] = isset($site_config['name']) ? $site_config['name'] : ''; $payment['R_Mobile'] = isset($site_config['mobile']) ? $site_config['mobile'] : ''; $payment['R_Telephone'] = isset($site_config['phone']) ? $site_config['phone'] : ''; return $payment; }