function add() { $post = $this->req->post; $this->res->json(); $arr = array(); if (empty($this->session->data['user'])) { $arr['fail'] = '需要您先登录'; } else { $product_id = (int) $post['product_id']; $content = trim($post['content']); $stars = (double) $post['stars']; if (strlen($content) < 1) { $arr['fail'] = '内容不能为空'; } else { $arr2 = array('product_id' => $product_id, 'user_id' => (int) $this->session->data['user']['user_id'], 'content' => htmlentities($content), 'date' => timenow(), 'status' => 0, 'stars' => $stars); $result = $this->load->model('comment')->add($arr2); if ($result) { $html = '<div class="comment-list"><p class="fix">'; if ($stars > 3) { $html = $html . '<i class="icon iconfont"></i>'; } else { $html = $html . '<i class="icon iconfont"></i>'; } $html = $html . html_entity_decode($arr2["content"]) . "<span class='r f12'>" . timenow() . "</span></p></div>"; $arr['content'] = $html; } else { $arr['fail'] = '评论失败'; } } } echo json_encode($arr); }
function add() { $post = $this->req->post; if (count($post)) { $content = $post['content']; $role_id = (int) $post["role_id"]; $date_start = $post['date_start']; $date_end = $post['date_end']; $date = timenow(); if (strlen($content) < 1) { setHint('内容不能为空', 'bad'); $this->res->red('broadcast/add'); } if (strlen($date_start) < 1 || strlen($date_end) < 1) { setHint('其实日期都不能为空', 'bad'); $this->res->red('broadcast/add'); } $arr = array("content" => $content, "role_id" => $role_id, "date_start" => $date_start, "date_end" => $date_end, "date" => $date); $result = $this->load->model('broadcast')->add($arr); if ($result) { setHint('添加广播成功'); } else { setHint('添加广播失败', 'bad'); } $this->res->red('broadcast/add'); } else { $roles = $this->load->model('role')->find(); return $this->load->view('broadcast_add', array('roles' => $roles)); } }
function findNotPay($args) { $current = (int) $args[0]; if ($current == 0) { $current = 1; } $arr = array('date_start' => '2015-09-01', 'date_end' => format(timenow(), '-') . ' 23:59:59', 'name' => '', 'pay' => 0); $data = $this->load->model('order')->findByPay($arr, array($current, HOSTNAME . 'admin/order/findNotPay/', 15)); $pagination = $this->db->getPage(); return $this->load->view('order_notPay', array('orders' => $data, 'pagination' => $pagination)); }
function save() { $post = $this->post; $description = $post['description']; if (empty($description) || strlen($description) < 2) { return false; } if ($this->load('resource')->fingByDes($description)) { return false; } return $this->load('resource')->add(array('description' => $description, 'create_time' => timenow())); }
function logs($str) { $file = fopen(LOGS . format(timenow(), '_') . '.txt', 'a'); if (flock($file, LOCK_EX)) { //加写锁 // fputs($file,$string); //写文件 fwrite($file, $str . "--" . timenow() . "\n"); flock($file, LOCK_UN); //解锁 } fclose($file); }
function update() { $post = $this->req->post; $reply_id = (int) $post['reply_id']; $content = $post['content']; header("Content-type: application/json"); if (strlen($content) > 0) { $result = $this->load->model('reply')->update(array('reply_id' => $reply_id, 'content' => $content, 'date' => timenow())); if ($result) { echo $content; } else { echo false; } } else { echo false; } }
function transfer() { $this->res->json(); $user_id = (int) $this->session->data['user']['user_id']; $amount = $this->load->model('amount')->findByUserid($user_id); $ret = array(); if ($amount) { $score = $amount['score']; $money = $amount['money']; if ($score > 0) { //事务开始 $this->db->begin(); try { //查看兑换规则 $configs = $this->load->model('configs')->findMoney(); //更新积分和金额 $total_money = $money + $configs['money'] * $score; $result = $this->load->model('amount')->update(array("money" => (double) $total_money, "score" => 0, "amount_id" => (int) $amount['amount_id'], "user_id" => $user_id)); //插入兑换记录 $history = $this->load->model('transferHistory')->add(array("user_id" => $user_id, "score" => (double) $score, 'money' => (double) $configs['money'] * $score, "date" => timenow())); $history_id = (int) $this->db->lastId(); $this->db->commit(); $ret['tag'] = 'success'; $amount_result = $this->load->model('amount')->findByUserid($user_id); $ret['score'] = array('from' => (double) $score, 'to' => (double) $amount_result['score']); $ret['money'] = array('from' => (double) $money, 'to' => (double) $amount_result['money']); } catch (Exception $e) { $ret['tag'] = 'fail'; $ret['info'] = '网络原因,兑换失败,请稍后再试'; $this->db->rollback(); logs($e); } } else { $ret['tag'] = 'fail'; $ret['info'] = '您的账户中没有可以兑换的积分'; } } else { $ret['tag'] = 'fail'; $ret['info'] = '您还没有积分账户,不能兑换积分'; } echo json_encode($ret); }
function dashboard() { $today = format(timenow(), '-'); $today_order = $this->load->model('order')->findCountByDate($today . " 00:00:00", $today . " 23:59:59"); $today_user = $this->load->model('user')->findCountByDate($today . " 00:00:00", $today . " 23:59:59"); $total_order = $this->load->model('order')->findCountByDate("1970-01-01", $today . " 23:59:59"); $total_user = $this->load->model('user')->findCountByDate("1970-01-01", $today . " 23:59:59"); //未发送成功订单 $not_send = $this->load->model('order')->countNotSend()['count']; //未回复评论 $comment_notReply = $this->load->model('comment')->countByStatus(0)['count']; //共有评论 $comment_total = $this->load->model('comment')->count()['count']; //今天需要审核的提现请求 $cashout_not = $this->load->model('cashoutHistory')->countByStatus(0)['count']; //已审核的体现请求 $cashout_has = $this->load->model('cashoutHistory')->countByStatus(1)['count']; //所有已经审核的金额 $total_money = $this->load->model('cashoutHistory')->countMoney()['money']; return $this->load->view('dashboard', array('today_order' => empty($today_order) ? 0 : $today_order['count'], 'today_user' => empty($today_user) ? 0 : $today_user['count'], 'total_order' => empty($total_order) ? 0 : $total_order['count'], 'total_user' => empty($total_user) ? 0 : $total_user['count'], 'not_send' => $not_send, 'comment_notReply' => $comment_notReply, 'comment_total' => $comment_total, 'cashout_not' => $cashout_not, 'cashout_has' => $cashout_has, 'total_money' => $total_money)); }
function createOrder() { $post = $this->req->post; $user_id = (int) $this->session->data['user']['user_id']; $cart = $post['cart']; $address_id = (int) $post['radio']; $payway = $post['payway']; if (strlen($cart) < 3) { setHint('您的购物车中还没有商品,不能提交订单', 'bad'); $this->res->redirect('checkout/productList'); } if ($payway == 'alipay') { if (isMobil()) { $payway = 'ali_wap_pay'; } else { $payway = 'ali_pc_pay'; } } else { if ($payway == 'weixinpay') { $payway = 'weixin_pay'; } else { if (!empty($payway)) { $paycode = strtoupper($payway); $payway = 'ali_bank_pay'; } else { setHint('请选择支付方式', 'bad'); $this->res->redirect('checkout/productList'); } } } //暂时只能使用此方式 $payway = 'ali_pc_pay'; //检查地址是否存在 $address = $this->load->model('address'); $result_address = $address->findById($address_id, $user_id); if ($result_address) { $address->updateUsed($user_id, 0); $address->updateUsing($address_id, 1); } else { setHint('地址不存在,不能提交订单', 'bad'); $this->res->redirect('checkout/productList'); } /*偏远地区省份id 内蒙古,青海,宁夏,甘肃,广西,海南*/ $remote_arr = array('150000', '630000', '640000', '620000', '450000', '460000'); $is_remote = in_array($result_address['provinceid'], $remote_arr); //查询商品 $product_id_arr = array(); $product_num_arr = array(); preg_match_all('/(\\d+)[:](\\d+)/', $cart, $arr); $product_id_arr = $arr[1]; $product_num_arr = $arr[2]; $products = array(); if (count($product_id_arr) > 0 && count($product_id_arr) == count($product_num_arr)) { $product = $this->load->model('product'); foreach ($product_id_arr as $key => $value) { $result = $product->findById((int) $value); if (!$result || empty($product_num_arr[$key])) { setHint('非法的商品信息,不能提交订单', 'bad'); $this->res->redirect('checkout/productList'); break; } else { $result['piece'] = $product_num_arr[$key]; } $products[] = $result; } //生成订单 //事务 $this->db->begin(); $order = $this->load->model('order'); $order_info = $this->load->model('orderInfo'); $ret = $order->add(array("pay" => 0, "send" => 0, "user_id" => $user_id, "address_id" => $address_id, 'address' => $result_address['province'] . $result_address['city'] . $result_address['area'] . $result_address['zip'] . $result_address['detail'], "date" => timenow())); if (!$ret) { $this->db->rollback(); setHint('生成订单失败'); $this->res->redirect('checkout/productList'); } $lastId = (int) $this->db->lastId(); $total_money = 0; foreach ($products as $key => $value) { $money = $value['piece'] * $value['price']; if ($value['free_postage'] == 1) { if ($is_remote) { $fee = $value['postage_remote']; } else { $fee = $value['postage']; } $money = $money + $value['piece'] * $fee; } $total_money = $total_money + $money; $ret = $order_info->add(array('order_id' => $lastId, "product_id" => (int) $value['product_id'], 'piece' => (int) $value['piece'], "postage" => empty($value['free_postage']) ? 0 : (double) $fee, "price" => (double) $value['price'], "money" => (double) $money)); if (!$ret) { $this->db->rollback(); setHint('生成订单失败'); $this->res->redirect('checkout/productList'); } } $orderNum = createOrderNum(); $ret = $order->update($lastId, $orderNum . $lastId, $total_money); if (!$ret) { $this->db->rollback(); setHint('生成订单失败'); $this->res->redirect('checkout/productList'); } $this->db->commit(); //订单生成后清空cookie // setcookie('cart','',time()-3600); //订单已经提交,查询订单并返回结果 $product_subject = ''; foreach ($products as $key => $value) { $product_subject = $product_subject . $value['name'] . "(" . $value['piece'] . ")"; } $data = $order->findById($lastId); $data['subject'] = $product_subject; $data['body'] = '购物愉快'; $data['url'] = HOSTNAME . 'product/' . $products[0]['product_id']; //生成清单后删除此用户所有其他未付款订单 $order->deleteNotPay($lastId, $user_id); return $this->load->view('checkout_createorder', array('order' => $data, 'products' => $products, 'payway' => $payway, 'paycode' => $paycode)); } else { setHint('非法的商品信息,不能提交订单', 'bad'); } }
function addSubagent() { $post = $this->req->post; if (count($post)) { $name = $post['name']; $phone = $post['phone']; $pass = $post['pass']; $agent_id = (int) $post['agent_id']; $tag = $post['tag']; $arr = array('name' => $name, 'phone' => $phone, 'can_cashout' => 1, 'subagent_id' => 0, 'date' => timenow(), 'pass' => md5($pass)); if (empty($agent_id)) { setHint('代理ID必须是数字'); $this->res->red('user/addSubagent'); } if (strlen($name) < 1) { setHint('名称太短'); $this->res->red('user/addSubagent'); } if (!validate('phone', $phone)) { setHint('电话不符合要求'); $this->res->red('user/addSubagent'); } if (!validate('pass', $pass)) { setHint('密码不符合要求'); $this->res->red('user/addSubagent'); } $hasUser = $this->load->model('user')->findByPhone($phone); if ($hasUser) { setHint('电话已经存在,请重新输入', 'bad'); $this->res->red('user/addSubagent'); } $role = $this->load->model('role')->findByTag($tag); $agent = $this->load->model('user')->findByRole($agent_id, 'agent'); if (!$role) { setHint('tag不存在,不能添加', 'bad'); $this->res->red('user/addSubagent'); } if (!$agent) { setHint('代理不存在,不能添加', 'bad'); $this->res->red('user/addSubagent'); } $arr['role_id'] = (int) $role['role_id']; $arr['branch_id'] = (int) $agent['branch_id']; $arr['sale_id'] = (int) $agent['sale_id']; $arr['p_id'] = (int) $agent['p_id']; $arr['agent_id'] = (int) $agent['user_id']; $result = $this->load->model('user')->add($arr); if ($result) { setHint('添加成功'); $lastId = $this->db->lastId(); //初始化用户积分账户 $this->load->model('amount')->add(array('user_id' => $lastId, 'money' => 0, 'score' => 0)); $randcode = randImgName(25); $link = $randcode . 'u' . $lastId; $imgarr = array('user_id' => $lastId, 'link' => $link, 'linkimg' => $link . '.png', 'logoimg' => $link . "logo.png"); $update = $this->load->model("user")->updateQcode($imgarr); if ($update) { createQcode(HOSTNAME . 'home/register/' . $link, $link, 'logo.png', QCODE, 7); } } else { setHint('添加失败', 'bad'); } $this->res->red('user/addSubagent'); } else { return $this->load->view('user_add_subagent'); } }
function recommend() { $get = $this->req->get; $user_id = (int) $this->session->data['user']['user_id']; $tag = $this->session->data['user']['tag']; $date_start = $get['date_start']; $date_end = $get['date_end']; $current = $get['p']; $name = $get['name']; if (empty($current)) { $current = 1; } if (empty($name)) { $name = ""; } if (empty($date_start)) { $date_start = '2015-09-01 00:00:00'; } else { $date_start = format($date_start, '-') . " 00:00:00"; } if (empty($date_end)) { $date_end = format(timenow(''), '-') . " 23:59:59"; } else { $date_end = format($date_end, '-') . " 23:59:59"; } $page = array($current, HOSTNAME . 'order/recommend/?date_start=' . $date_start . "&date_end=" . $date_end . "&name=" . $name . "&p=", 10); $arr = array('name' => $name, 'date_start' => $date_start, 'date_end' => $date_end); // return var_dump($date_start,$date_end,$page); $order = $this->load->model('order'); if ($tag == 'branch') { $arr['branch_id'] = $user_id; $data = $order->findByBranch($arr, $page); } if ($tag == 'sale') { $arr['sale_id'] = $user_id; $data = $order->findBySale($arr, $page); } if ($tag == 'agent') { $arr['agent_id'] = $user_id; $data = $order->findByAgent($arr, $page); } if ($tag == 'subagent') { $arr['subagent_id'] = $user_id; $data = $order->findBySubagent($arr, $page); } if ($tag == 'member') { $arr['p_id'] = $user_id; $data = $order->findByPid($arr, $page); } $pagination = $this->db->getPage(); return $this->load->view('order', array('orders' => $data, 'date_start' => $date_start, 'date_end' => $date_end, 'name' => $name, 'pagination' => $pagination), 'admin_header', 'admin_footer'); }
public function save() { $post = $this->post; $name = isset($post['name']) ? $post['name'] : null; $phone = isset($post['phone']) ? $post['phone'] : null; $sex = (int) $post['sex']; $department_id = (int) $post['department_id']; $roles_id = (int) $post['roles_id']; if (!validate('name', $name)) { return '姓名不符合要求'; } if (!validate('phone', $phone)) { return '电话不符合要求'; } $lastid = $this->load('employee')->add(array('name' => $name, 'pass' => secret('000000'), 'phone' => $phone, 'sex' => $sex, 'roles_id' => $roles_id, 'create_time' => timenow(), 'department_id' => $department_id)); if ($lastid) { return $this->load('employee')->findById($lastid); } else { return 0; //insert fail } }
function add() { // var_dump($this->req->post); // exit; if (count($this->req->post)) { $post = $this->req->post; $name = $post['name']; $catalog_id = $post['catalog_id']; $price = $post['price']; $free_postage = $post['free_postage']; $postage = $post['postage']; $postage_remote = $post['postage_remote']; $score = $post['score']; $stock = $post['stock']; $detail = $post['editorValue']; $likes = $post['likes']; $attr_group_id = $post['attr_group_id']; $title = $post['title']; $keywords = $post['keywords']; $description = $post['description']; $hits = (int) $post['hits']; $for_presenter = (double) $post['for_presenter']; $for_workers = (double) $post['for_workers']; $date = timenow(); $img_id = $post['img_id']; $arr = array('name' => $name, 'catalog_id' => (int) $catalog_id, 'price' => (double) $price, 'free_postage' => (int) $free_postage, 'postage' => (double) $postage, "postage_remote" => (double) $postage_remote, 'score' => (double) $score, 'stock' => (int) $stock, 'detail' => $detail, 'likes' => (int) $likes, 'date' => $date, 'attr_group_id' => (int) $attr_group_id, 'title' => $title, 'hits' => $hits, 'for_presenter' => $for_presenter, 'for_workers' => $for_workers, 'keywords' => $keywords, 'description' => $description); // 用户输入产品信息验证 if (strlen($name) < 1) { setHint('名字不符合要求', 'bad'); return $this->load->view('product_add', $arr); } if (!is_numeric($price)) { setHint('价格必须是数字', 'bad'); return $this->load->view('product_add', $arr); } if (!is_numeric($postage)) { setHint('运费必须是数字', 'bad'); return $this->load->view('product_add', $arr); } if (!is_numeric($postage_remote)) { setHint('偏远地区运费必须是数字', 'bad'); return $this->load->view('product_add', $arr); } if (!is_numeric($score)) { setHint('积分必须是数字', 'bad'); return $this->load->view('product_add', $arr); } if (!is_numeric($stock)) { setHint('库存必须是数字', 'bad'); return $this->load->view('product_add', $arr); } if (strlen($detail) < 10) { setHint('产品详情太短', 'bad'); return $this->load->view('product_add', $arr); } if (!is_numeric($likes)) { setHint('点赞数必须是数字', 'bad'); return $this->load->view('product_add', $arr); } if (!is_numeric($hits)) { setHint('点击次数必须是数字', 'bad'); return $this->load->view('product_add', $arr); } if (!is_numeric($for_presenter)) { setHint('返给直接推荐者必须是数字', 'bad'); return $this->load->view('product_add', $arr); } if (!is_numeric($for_workers)) { setHint('返给工作人员必须是数字', 'bad'); return $this->load->view('product_add', $arr); } if (strlen($title) < 5) { setHint('详情页标题太短', 'bad'); return $this->load->view('product_add', $arr); } if (strlen($keywords) < 5) { setHint('详情页关键字太短', 'bad'); return $this->load->view('product_add', $arr); } if (strlen($description) < 5) { setHint('详情页描述太短', 'bad'); return $this->load->view('product_add', $arr); } $result = $this->load->model('product')->add($arr); $lastid = $this->db->lastId(); if ($result && $lastid) { $img_id_arr = explode(',', $img_id); $imgobj = $this->load->model('img'); foreach ($img_id_arr as $key => $value) { $imgobj->updateProductid((int) $value, (int) $lastid); } setHint('添加商品成功'); } else { setHint('添加商品失败', 'bad'); } $this->res->red('product/add'); } else { $catalogs = $this->load->model('catalog')->findName(); $attrs = $this->load->model('attr_group')->findName(); return $this->load->view('product_add', array('catalogs' => $catalogs, 'attrs' => $attrs)); } }
function register($args) { $post = $this->req->post; if (count($post)) { $phone = $post['phone']; $pass = $post['pass']; $code = $post['code']; $sms = $post['sms']; $name = $post['name']; // return var_dump($post); if (empty($this->session->data['invitationcode'])) { setHint('对不起,不通过邀请链接不能注册'); $this->res->redirect('home/register'); } if (!validate('pass', $pass)) { setHint('密码不符合要求'); $this->res->redirect('home/register'); } if (!validate('code', $code)) { setHint('验证码格式不正确'); $this->res->redirect('home/register'); } if ($this->session->data['validatecode'] != $code) { setHint('验证码不正确'); $this->res->redirect('home/register'); } if (!validate('sms', $sms)) { setHint('短信验证码格式不正确'); $this->res->redirect('home/register'); } if (!validate('name', $name)) { setHint('姓名必须为2~4个中文字符'); $this->res->redirect('home/register'); } if (empty($this->session->data['smscode'])) { setHint('您没有获取短信验证码'); $this->res->redirect('home/register'); } if ($this->session->data['smscode'] != $sms) { setHint('短信验证码不正确'); $this->res->redirect('home/register'); } $user = $this->load->model('user'); $link = $user->findByLink($this->session->data['invitationcode']); if (!$link) { setHint('对不起,邀请链接不合法', 'bad'); $this->res->redirect('home/register'); } $euser = $user->findByPhone($phone); if ($euser) { setHint('对不起,手机号已经被注册', 'bad'); $this->res->redirect('home/register'); } $arr = array("phone" => $phone, "pass" => md5($pass), 'name' => $name, 'can_cashout' => 1, 'date' => timenow()); $tag = $link['tag']; if ($tag == 'sale') { //添加代理 $role_id = (int) $this->load->model('role')->findByTag('agent')["role_id"]; $arr['role_id'] = $role_id; $arr['branch_id'] = (int) $link['branch_id']; $arr['sale_id'] = (int) $link['user_id']; $arr['agent_id'] = 0; $arr['subagent_id'] = 0; $arr['p_id'] = 0; } else { if ($tag == 'agent') { //添加分代理 $role_id = (int) $this->load->model('role')->findByTag('subagent')["role_id"]; $arr['role_id'] = $role_id; $arr['branch_id'] = (int) $link['branch_id']; $arr['sale_id'] = (int) $link['sale_id']; $arr['agent_id'] = (int) $link['user_id']; $arr['subagent_id'] = 0; $arr['p_id'] = 0; } else { if ($tag == 'subagent') { //添加会员 $role_id = (int) $this->load->model('role')->findByTag('member')["role_id"]; $arr['role_id'] = $role_id; $arr['branch_id'] = (int) $link['branch_id']; $arr['sale_id'] = (int) $link['sale_id']; $arr['agent_id'] = (int) $link['agent_id']; $arr['subagent_id'] = (int) $link['user_id']; $arr['p_id'] = 0; } else { if ($tag == 'member') { //添加介绍会员 $role_id = (int) $this->load->model('role')->findByTag('member')["role_id"]; $arr['role_id'] = $role_id; $arr['branch_id'] = (int) $link['branch_id']; $arr['sale_id'] = (int) $link['sale_id']; $arr['agent_id'] = (int) $link['agent_id']; $arr['subagent_id'] = (int) $link['subagent_id']; $arr['p_id'] = (int) $link['user_id']; } else { setHint('您的链接不合法', 'bad'); $this->res->redirect('home/register'); } } } } $result = $user->add($arr); if ($result) { $lastId = (int) $this->db->lastId(); $randcode = randImgName(25); $link = $randcode . 'u' . $lastId; $update = $user->updateLink(array('user_id' => $lastId, 'link' => $link, 'linkimg' => $link . '.png', 'logoimg' => $link . "logo.png")); if ($update) { createQcode(HOSTNAME . 'home/register/' . $link, $link, 'logo.png', QCODE, 7); } setHint('注册成功'); //为用户生成积分账号 $this->load->model('amount')->add(array('user_id' => $lastId, 'money' => 0, 'score' => 0)); $newuser = $user->findById($lastId); if (!empty($newuser['permission'])) { $newuser['permission'] = unserialize($newuser['permission']); } else { $newuser['permission'] = array(); } $this->session->data['user'] = $newuser; $this->session->data['validatecode'] = null; $this->session->data['smscode'] = null; $this->res->redirect('user/dashboard'); } else { setHint('注册失败', "bad"); } //无论注册成功失败,都重置关于验证码的session $this->session->data['validatecode'] = null; $this->session->data['smscode'] = null; $this->res->redirect('home/register'); } else { if (!empty($args[0])) { $this->session->data['invitationcode'] = $args[0]; } $catalogs = $this->load->model('catalog')->findFirst(); return $this->load->view('register', array('invitationcode' => $this->session->data['invitationcode'], 'catalogs' => $catalogs)); } }