public function index() { $error = ''; if (RequestUtil::isPost()) { $validate = new ValidateUtil(); $validate->required('user_name'); $validate->required('password'); $validate->required('verify_code'); $params = RequestUtil::postParams(); if ($params['verify_code'] != UserUtil::getVerifyCode()) { $error = '验证码错误!'; } else { if ($validate->run()) { $userModel = new UserModel(); $params['password'] = $userModel->encodePassword($params['password']); $where = array('user_name' => $params['user_name'], 'password' => $params['password']); $user = (new CurdUtil($userModel))->readOne($where, 'user_id desc', '*, user_type+0 as type'); if (!$user) { $error = '登录失败,账号或者密码错误,请重试!'; } else { (new CurdUtil($userModel))->update($where, array('last_login_time' => DateUtil::now())); UserUtil::saveUser($user); if (UserUtil::isAdmin()) { ResponseUtil::redirect(UrlUtil::createBackendUrl('project/index')); } else { ResponseUtil::redirect(UrlUtil::createBackendUrl('beautician/index')); } } } } } $this->load->view('backend/login', array('error' => $error)); }
/** * 设置订单为已支付 * @param $orderNo * @param $openId * @param $wxOrderNo 微信订单号 */ public function payed($orderNo, $wxOrderNo) { $where = array('order_no' => $orderNo); $updateData = array('pay_time' => DateUtil::now(), 'order_status' => self::ORDER_PAYED, 'transaction_id' => $wxOrderNo); $this->db->where($where); $this->db->update($this->table, $updateData); return $this->db->affected_rows(); }
public static function log($mainTitle, $message, $file = 'log') { $saveFile = APPPATH . DIRECTORY_SEPARATOR . 'logs'; $saveFile = $saveFile . DIRECTORY_SEPARATOR . $file . date('Y-m-d'); if (!is_string($message)) { $message = json_encode($message); } $mainTitle = DateUtil::now() . ' ' . $mainTitle; file_put_contents($saveFile, $mainTitle . $message . "\n\n" . str_repeat('-', 80) . "\n", FILE_APPEND); }
/** * 数据库备份 */ public function backup() { $this->load->dbutil(); $backup = $this->dbutil->backup(); $this->load->helper('file'); $filePath = MAIN_ROOT . 'backup' . DS . date('YmdHis') . '.gz'; if (write_file($filePath, $backup)) { (new CurdUtil($this->backupModel))->create(array('file_path' => $filePath, 'create_time' => DateUtil::now())); $this->message('备份成功', 'tool/index'); } else { $this->message('备份失败,请重试!'); } }
public function addCategory() { if (RequestUtil::isPost()) { if ($this->categoryModel->rules()->run()) { $params = RequestUtil::postParams(); $insertId = (new CurdUtil($this->categoryModel))->create(array('category_name' => $params['category_name'], 'order_sort' => $params['order_sort'], 'create_time' => DateUtil::now())); if ($insertId) { $this->message('新增分类成功!', 'category/index'); } else { $this->message('新增分类失败!', 'category/index'); } } } $this->view('category/addCategory'); }
/** * 新增优惠码 */ public function addCouponCode() { if (RequestUtil::isPost()) { if ($this->couponCodeModel->rules()->run()) { $params = RequestUtil::postParams(); $insertId = (new CurdUtil($this->couponCodeModel))->create(array_merge($params, array('create_time' => DateUtil::now()))); if ($insertId) { $this->message('新增优惠码成功!', 'couponCode/index'); } else { $this->message('新增优惠码失败!', 'couponCode/index'); } } } $this->view('couponCode/addCouponCode'); }
/** * 添加店铺 */ public function addShop() { if (RequestUtil::isPost()) { if ($this->shopModel->rules()->run()) { $params = RequestUtil::postParams(); $params['shop_logo'] = UploadUtil::commonUpload(array('upload/resize_200x200', 'upload/resize_100x100')); $insertId = (new CurdUtil($this->shopModel))->create(array_merge($params, array('create_time' => DateUtil::now()))); if ($insertId) { $this->message('新增店铺成功!', 'shop/index'); } else { $this->message('新增店铺失败!', 'shop/index'); } } } $this->view('shop/addShop'); }
/** * 新增优惠券 */ public function addCoupon() { if (RequestUtil::isPost()) { if ($this->couponModel->rules()->run()) { $params = RequestUtil::postParams(); $params['remain_number'] = $params['total_number']; $insertId = (new CurdUtil($this->couponModel))->create(array_merge($params, array('create_time' => DateUtil::now()))); if ($insertId) { $this->message('新增优惠券成功!', 'coupon/index'); } else { $this->message('新增优惠券失败!', 'coupon/index'); } } } $this->view('coupon/addCoupon'); }
public function addUser() { if (RequestUtil::isPost()) { if ($this->userModel->rules()->run()) { $params = RequestUtil::postParams(); unset($params['re_password']); $params['password'] = $this->userModel->encodePassword($params['password']); $insertId = (new CurdUtil($this->userModel))->create(array_merge($params, array('create_time' => DateUtil::now()))); if ($insertId) { $this->message('新增账户成功!', 'user/index'); } else { $this->message('新增账户失败!', 'user/index'); } } } $this->view('user/addUser'); }
/** * 新增优惠券 */ public function addExchangeGoods() { if (RequestUtil::isPost()) { if ($this->exchangeGoodsModel->rules()->run()) { $params = RequestUtil::postParams(); $params['remain_number'] = $params['total_number']; $params['exchange_goods_pic'] = UploadUtil::commonUpload(array('upload/resize_200x200', 'upload/resize_600x600', 'upload/resize_100x100')); $insertId = (new CurdUtil($this->exchangeGoodsModel))->create(array_merge($params, array('create_time' => DateUtil::now()))); if ($insertId) { $this->message('新增兑换商品成功!', 'exchangeGoods/index'); } else { $this->message('新增兑换商品失败!', 'exchangeGoods/index'); } } } $this->view('exchangeGoods/addExchangeGoods'); }
public function addSlider() { if (RequestUtil::isPost()) { $this->sliderModel->deleteSliderCache(); $params = RequestUtil::postParams(); // href if (!preg_match('~^http[s]?://~', $params['href'])) { $params['href'] = 'http://' . $params['href']; } if ($this->sliderModel->rules()->run()) { $params['pic'] = UploadUtil::commonUpload(array('upload/resize_200x200', 'upload/resize_100x100', 'upload/resize_600x600')); $insertId = (new CurdUtil($this->sliderModel))->create(array_merge($params, array('create_time' => DateUtil::now()))); if ($insertId) { $this->message('新增成功!', 'slider/index'); } else { $this->message('新增失败!', 'slider/index'); } } } $this->view('slider/addSlider'); }
/** * 取消订单 * @param string $order_id */ public function CancelOrder($order_id = '') { if (!$order_id) { $this->message('订单ID不能为空!'); } $orderModel = new OrderModel(); // 获得订单 $order = $orderModel->readOne($order_id); if (!$order) { ResponseUtil::failure('取消订单失败!'); } // 获得积分ID $couponId = $order['use_coupon_id']; if ($couponId) { (new CustomerCouponModel())->refundCoupon($couponId, $order['open_id']); } if ((new CurdUtil($this->orderModel))->update(array('order_id' => $order_id), array('order_status' => OrderModel::ORDER_CANCEL, 'complete_time' => DateUtil::now()))) { $this->message('订单已取消!'); } else { $this->message('处理失败!'); } }
public function addBeauticianRest($beautician_id) { $beautician = (new BeauticianModel())->readOne($beautician_id); if (!$beautician) { $this->message('美容师记录不存在!'); } $beauticianRestModel = new BeauticianRestModel(); if (RequestUtil::isPost()) { if ($beauticianRestModel->rules()->run()) { $params = RequestUtil::postParams(); $insertId = (new CurdUtil($beauticianRestModel))->create(array_merge($params, array('create_time' => DateUtil::now()))); if ($insertId) { $this->message('新增请假记录成功!', 'beautician/rest?beautician_id=' . $beautician_id); } else { $this->message('新增请假记录失败!', 'beautician/rest?beautician_id=' . $beautician_id); } } } $this->view('beautician/addBeauticianRest', array('beautician_id' => $beautician_id, 'beautician' => $beautician)); }
public function appointment() { $params = RequestUtil::postParams(); $userName = urldecode($params['user_name']); if (empty($userName)) { $this->message('联系人不能为空!'); } $phoneNumber = $params['phone_number']; if (empty($phoneNumber)) { $this->message('手机号不能为空!'); } $appointmentDay = $params['appointment_day']; $appointmentTime = $params['appointment_times']; $today = date('Y-m-d'); if ($appointmentDay < $today) { $this->message('错误的预约日期!'); } // 检查时间 $appointmentTime = explode(',', urldecode($appointmentTime)); if (!$appointmentTime || count($appointmentTime) < 1) { $this->message('错误的预约时间!'); } // 只有30分钟的项目 if (count($appointmentTime) == 1) { array_push($appointmentTime, $appointmentTime[0]); } // 只保留头和尾的两个数据 $startTime = array_shift($appointmentTime); $endTime = array_pop($appointmentTime); if ($endTime < $startTime) { $this->message('错误的预约时间!'); } // 预约时间是否小于当前时间 $now = date('Y-m-d H:i'); if (DateUtil::buildDateTime($appointmentDay, $startTime) < $now) { $this->message('错误的预约开始时间!'); } if (DateUtil::buildDateTime($appointmentDay, $endTime) < $now) { $this->message('错误的预约结束时间!'); } $beauticianId = $params['beautician_id']; // 判断相同的时间是否已经被预约 $findHasPayedAppointTimeWhere = array('appointment_day' => $appointmentDay, 'appointment_start_time' => $startTime, 'order_status' => OrderModel::ORDER_PAYED, 'beautician_id' => $beauticianId); $findOrder = (new CurdUtil(new OrderModel()))->readOne($findHasPayedAppointTimeWhere); if ($findOrder) { $this->message('此时间段已被预约!'); } unset($findOrder); $findHasPayedAppointTimeWhere['order_status'] = OfflineOrderModel::ORDER_WAIT; $findOrder = (new CurdUtil(new OfflineOrderModel()))->readOne($findHasPayedAppointTimeWhere); if ($findOrder) { $this->message('此时间段已被预约!'); } // 没有问题 $data = array('project_id' => $params['project_id'], 'project_name' => $params['project_name'], 'use_time' => $params['use_time'], 'shop_id' => $params['shop_id'], 'beautician_id' => $beauticianId, 'appointment_day' => $appointmentDay, 'appointment_start_time' => $startTime, 'appointment_end_time' => $endTime, 'user_name' => $userName, 'phone_number' => $phoneNumber, 'create_time' => DateUtil::now()); if ((new CurdUtil(new OfflineOrderModel()))->create($data)) { $this->message('线下预约成功!', 'offlineOrder/index'); } else { $this->message('线下预约失败!'); } }
public function addProject() { if (RequestUtil::isPost()) { if ($this->projectModel->rules()->run()) { $params = RequestUtil::postParams(); $mainProjectId = $params['main_project_id']; unset($params['main_project_id']); $params['project_cover'] = UploadUtil::commonUpload(array('upload/resize_200x200', 'upload/resize_600x600', 'upload/resize_100x100')); $insertId = (new CurdUtil($this->projectModel))->create(array_merge($params, array('create_time' => DateUtil::now()))); // 关联项目 if ($mainProjectId) { (new CurdUtil(new ProjectRelationModel()))->create(array('main_project_id' => $mainProjectId, 'relation_project_id' => $insertId)); } if ($insertId) { $this->message('新增项目成功!', 'project/index'); } else { $this->message('新增项目失败!', 'project/index'); } } } $categories = (new CategoryModel())->getAllCategories(); $shops = (new ShopModel())->getAllShops(); $this->view('project/addProject', array('categories' => $categories, 'shops' => $shops)); }
public function setIsGet($customerExchangeGoodsId, $openId) { return (new CurdUtil($this))->update(array('customer_exchange_goods_id' => $customerExchangeGoodsId, 'open_id' => $openId), array('is_get' => 1, 'get_time' => DateUtil::now())); }
public function update($openId, $nickName, $avatar, $city, $province, $sex) { $data = array('nick_name' => $nickName, 'avatar' => $avatar, 'city' => $city, 'province' => $province, 'sex' => $sex, 'update_time' => DateUtil::now()); return (new CurdUtil($this))->update(array('open_id' => $openId), $data); }
/** * 下单 * @param $shopId * @param $beauticianId * @param $appointmentDay * @param $appointmentTime * @param $userName * @param $phoneNumber */ public function order($shopId, $beauticianId, $appointmentDay, $appointmentTime, $userName, $phoneNumber) { $openId = (new WeixinUtil())->getOpenId(); if (!$openId) { $this->message('错误的授权'); } if (!(new ShopModel())->isValidShopId($shopId)) { $this->message('门店信息错误,请检查!'); } // 检查美容师 if (!(new BeauticianModel())->isValidBeautician($beauticianId)) { $this->message('美容师信息错误,请检查!'); } $userName = urldecode($userName); // 检查用户 $userName = trim(strip_tags($userName)); if (empty($userName)) { $this->message('联系人不能为空,请检查!'); } if (!preg_match('~^1\\d{10}$~', $phoneNumber)) { $this->message('手机号错误,请检查!'); } // 检查日期,日期为今天或者以后 $today = date('Y-m-d'); if ($appointmentDay < $today) { $this->message('错误的预约日期!'); } // 检查时间 $appointmentTime = explode(',', urldecode($appointmentTime)); if (!$appointmentTime || count($appointmentTime) < 1) { $this->message('错误的预约时间!'); } // 只有30分钟的项目 if (count($appointmentTime) == 1) { array_push($appointmentTime, $appointmentTime[0]); } // 只保留头和尾的两个数据 $startTime = array_shift($appointmentTime); $endTime = array_pop($appointmentTime); if ($endTime < $startTime) { $this->message('错误的预约时间!'); } // 预约时间是否小于当前时间 $now = date('Y-m-d H:i'); if (DateUtil::buildDateTime($appointmentDay, $startTime) < $now) { $this->message('错误的预约开始时间!'); } if (DateUtil::buildDateTime($appointmentDay, $endTime) < $now) { $this->message('错误的预约结束时间!'); } // 结束时间 + 30分钟为真正的结束时间 //$timeStamp = DateUtil::buildDateTime($appointmentDay, $endTime); //$timeStamp += 1800; //$endTime = date('H:i', $timeStamp); // 处理优惠 $couponId = $this->input->get('coupon_id', true) + 0; $couponCode = $this->input->get('coupon_code', true) + 0; $customerCouponModel = new CustomerCouponModel(); $couponCodeModel = new CouponCodeModel(); $today = date('Y-m-d'); if ($couponId) { $couponCode = ''; $coupon = $customerCouponModel->readOneById($couponId); // 判断是否能使用 if ($coupon['is_use'] == 1) { $this->message('选择的优惠券已被使用!'); } // 是否到领取时间 if ($today < $coupon['start_time']) { $this->message('优惠券未到使用时间!'); } if ($today > $coupon['expire_time']) { $this->message('优惠券已到期!'); } } else { if ($couponCode) { $couponId = ''; $queryCouponCode = $couponCodeModel->readOneByCode($couponCode); if (!$queryCouponCode) { $this->message('优惠码不存在!'); } // 是否到使用时间 if ($today < $queryCouponCode['start_time']) { $this->message('优惠码未到使用时间!'); } // 是有已过期 if ($today > $queryCouponCode['expire_time']) { $this->message('优惠码已到期!'); } } else { } } //**********处理下单************// $projectId = (new CartUtil())->cart(); if (empty($projectId) || $projectId <= 0) { $this->message('预约项目为空!'); } if ((new ProjectPropertyModel())->projectOnlyForNewUser($projectId, $openId)) { $this->message('此美容项目只针对新用户!'); } $orderProjectModel = new OrderProjectModel(); // 获得购物车的项目 $project = (new ProjectModel())->readOne($projectId); // 判断订单金额是否可以使用优惠券 $totalFee = $originalTotalFee = $project['price']; if ($couponId && $project['can_use_coupon']) { if ($totalFee < $coupon['use_rule']) { $this->message('当前订单金额不足' . $coupon['use_rule'] . '元,不能使用此优惠券'); } } else { if ($couponCode && $project['can_use_coupon_code']) { if ($totalFee < $queryCouponCode['use_rule']) { $this->message('当前订单金额不足' . $queryCouponCode['use_rule'] . '元,不能使用此优惠码'); } } else { } } // 生成订单号, 有重复订单号则重新生成,直到不重复为止 $orderNo = StringUtil::generateOrderNo(); $orderModel = new OrderModel(); while ((new CurdUtil($orderModel))->readOne(array('order_no' => $orderNo))) { $orderNo = StringUtil::generateOrderNo(); } // 优惠 if ($couponId && $project['can_use_coupon']) { // 使用优惠码, 抵消金额 $totalFee -= $coupon['counteract_amount']; } else { if ($couponCode && $project['can_use_coupon_code']) { $totalFee *= $queryCouponCode['discount']; } else { } } // 订单数据 $orderData = array('order_no' => $orderNo, 'shop_id' => $shopId, 'create_time' => DateUtil::now(), 'original_total_fee' => $originalTotalFee, 'total_fee' => $totalFee, 'open_id' => $openId, 'order_status' => OrderModel::ORDER_NOT_PAY, 'beautician_id' => $beauticianId, 'appointment_day' => $appointmentDay, 'appointment_start_time' => $startTime, 'appointment_end_time' => $endTime, 'user_name' => $userName, 'phone_number' => $phoneNumber, 'use_coupon_id' => $couponId, 'use_coupon_code' => $couponCode); // 事务开始 $this->db->trans_start(); // 设置优惠券已使用 if ($couponId && $project['can_use_coupon']) { $customerCouponModel->useCoupon($couponId, $openId); } else { if ($couponCode && $project['can_use_coupon_code']) { $couponCodeModel->addUseTimes($couponCode); } else { } } $insertOrderNo = (new CurdUtil($orderModel))->create($orderData); if ($insertOrderNo) { $orderProjectData = array('order_id' => $insertOrderNo, 'project_id' => $project['project_id'], 'project_use_time' => $project['use_time'], 'project_price' => $project['price'], 'create_time' => DateUtil::now(), 'project_name' => $project['project_name'], 'project_cover' => $project['project_cover']); } else { $this->message('提交订单失败,请重试!'); } (new CurdUtil($orderProjectModel))->create($orderProjectData); $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $this->message('提交订单失败,请重试!'); } else { $this->db->trans_commit(); // 清空购物车 (new CartUtil())->emptyCart(); // 跳到 订单显示 ResponseUtil::redirect(UrlUtil::createUrl('order/pay/' . $orderNo)); } }
public function getExchangeGoods($exchangeGoodsId) { $openId = (new WeixinUtil())->getOpenId(); if (!$openId) { ResponseUtil::failure('错误的授权!'); } // 查询是否已经领取优惠券 if ((new CustomerExchangeGoodsModel())->readOne($exchangeGoodsId, $openId)) { ResponseUtil::failure('您已经兑换了此商品!'); } $exchangeGoods = (new ExchangeGoodsModel())->readOne($exchangeGoodsId); // 剩余数量为0 if ($exchangeGoods['remain_number'] <= 0) { ResponseUtil::failure('商品已经兑换完!'); } $today = date('Y-m-d'); // 是否到领取时间 if ($today < $exchangeGoods['start_time']) { ResponseUtil::failure('商品未到兑换时间!'); } if ($today > $exchangeGoods['expire_time']) { ResponseUtil::failure('商品已过兑换时间!'); } // 判断积分 $customerModel = new CustomerModel(); $customer = $customerModel->readOne($openId); if ($exchangeGoods['exchange_credits'] > $customer['credits']) { ResponseUtil::failure('积分不足,兑换商品失败!'); } $userName = $this->input->post('contact_name', true); $phoneNumber = $this->input->post('contact_phone', true); $userName = urldecode($userName); // 检查用户 $userName = trim(strip_tags($userName)); if (empty($userName)) { ResponseUtil::failure('联系人不能为空,请检查!'); } if (!preg_match('~^1\\d{10}$~', $phoneNumber)) { ResponseUtil::failure('手机号错误,请检查!'); } $this->db->trans_start(); // 领取 $data = array('exchange_goods_id' => $exchangeGoodsId, 'open_id' => $openId, 'is_get' => 0, 'contact_name' => $userName, 'contact_phone' => $phoneNumber, 'exchange_time' => DateUtil::now()); $customerExchangeGoodsId = (new CustomerExchangeGoodsModel())->create($data); if ($customerExchangeGoodsId) { (new ExchangeGoodsModel())->subExchangeGoodsNumber($exchangeGoodsId); } // 积分 $customerModel->subCredits($openId, $exchangeGoods['exchange_credits']); $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); ResponseUtil::failure('兑换商品失败!'); } else { $this->db->trans_commit(); ResponseUtil::executeSuccess('兑换商品成功!'); } }