Exemplo n.º 1
0
 public static function callerporder($order_no)
 {
     $url = 'http://192.168.1.28:8088/quanpinMIS/doAPI.iss';
     $ordermodel = new Model("order");
     $pushordermodel = new Model("push_order");
     $pushorderhismodel = new Model("push_order_his");
     $orderconet = $ordermodel->where("order_no=" . $order_no)->find();
     $pushordermodel->data(array('order_id' => $orderconet['id'], 'order_no' => $order_no, 'express_id' => 0, 'tracking_no' => null, 'push_flg' => 1, 'push_type' => 1, 'ins_dt' => Filter::str(date('Y-m-d H:i:s')), 'upd_dt' => Filter::str(date('Y-m-d H:i:s'))))->inserttoerp();
     $pushorderhismodel->data(array('order_id' => $orderconet['id'], 'order_no' => $order_no, 'express_id' => 0, 'tracking_no' => null, 'push_flg' => 1, 'push_type' => 1, 'ins_dt' => Filter::str(date('Y-m-d H:i:s')), 'upd_dt' => Filter::str(date('Y-m-d H:i:s'))))->inserttoerp();
     //        $param = array("order_no" => $order_no, "id" => $orderconet['id']);
     //        $returnVal = Http::doPost($url, $param);
     //        $returnObj = json_decode($returnVal);
     //        if ($returnObj->returnVal == "OK") {
     if (1) {
         $pushordermodel->data(array('push_flg' => 0))->where("order_no=" . $order_no)->updatetoerp();
         $pushorderhismodel->data(array('order_id' => $orderconet['id'], 'order_no' => $order_no, 'express_id' => 0, 'tracking_no' => null, 'push_flg' => 0, 'push_type' => 1, 'ins_dt' => Filter::str(date('Y-m-d H:i:s')), 'upd_dt' => Filter::str(date('Y-m-d H:i:s'))))->inserttoerp();
     } else {
         // 请求失败
     }
 }
Exemplo n.º 2
0
 public static function paymentVoucher($voucherTemplate, $userID = null)
 {
     $model = new Model("voucher");
     do {
         $account = strtoupper(CHash::random(10, 'char'));
         $password = strtoupper(CHash::random(10, 'char'));
         $obj = $model->where("account = '{$account}'")->find();
     } while ($obj);
     $start_time = date('Y-m-d H:i:s');
     $end_time = date('Y-m-d H:i:s', strtotime('+' . $voucherTemplate['valid_days'] . ' days'));
     $model->data(array('account' => $account, 'password' => $password, 'name' => $voucherTemplate['name'], 'value' => $voucherTemplate['value'], 'start_time' => $start_time, 'end_time' => $end_time, 'money' => $voucherTemplate['money'], 'is_send' => 1, 'user_id' => $userID))->insert();
 }
Exemplo n.º 3
0
 /**
  * action 运行入口
  * 
  * @access public
  * @return mixed
  */
 public function run()
 {
     $controller = $this->getController();
     $methodName = preg_split("/_(?=(save|del|edit)\$)/i", $this->getId());
     if (count($methodName) == 2) {
         $op = $methodName[1];
         $modelName = $methodName[0];
     } else {
         $op = $methodName[0];
         $modelName = $controller->getId();
     }
     $operator = array('save' => 'save', 'del' => 'delete', 'edit' => 'find');
     //如果配制文件存在curd函数自动进行处理
     if ($controller->getAutoActionRight() && array_key_exists($op, $operator)) {
         if ($op == 'save') {
             $pre_validator = $modelName . '_validator';
             if (method_exists($controller, $pre_validator)) {
                 $validator = $controller->{$pre_validator}();
                 if (is_array($validator)) {
                     $data = Req::args() + array('validator' => $validator);
                     $controller->redirect($modelName . '_edit', false, $data);
                     exit;
                 }
             }
         }
         $model = new Model($modelName);
         $data = $model->data(Req::args())->{$operator}[$op]();
         switch ($op) {
             case 'save':
                 if ($data !== false) {
                     $controller->redirect($modelName . '_list');
                 } else {
                     $controller->redirect($modelName . '_edit', null, false, array('form' => $model->find()));
                 }
                 break;
             case 'del':
                 $controller->redirect($modelName . '_list');
                 break;
             case 'edit':
                 $data = isset($data) ? $data : array();
                 $controller->redirect($modelName . '_edit', false, $data);
                 break;
         }
     } else {
         $action = new ViewAction($controller, $this->getId());
         $action->run();
         //exit;
     }
 }
Exemplo n.º 4
0
 public function update(Model $model)
 {
     $this->connect();
     $name = $model->name();
     $data = $model->data();
     $query = "UPDATE {$name} SET ";
     $keys = array();
     foreach ($data as $key => $value) {
         if ($key !== 'id') {
             array_push($keys, "{$key} = :{$key}");
         }
         if (is_array($value)) {
             $data[$key] = serialize($value);
         }
     }
     $query .= implode(', ', $keys) . " WHERE id = :id";
     $st = self::$pdo->prepare($query);
     $st->execute($data);
     return $st->rowCount() > 0;
 }
Exemplo n.º 5
0
 public static function write($user_id, $value, $note)
 {
     if (is_numeric($value)) {
         $model = new Model('customer');
         $customer = $model->where("user_id=" . $user_id)->find();
         if ($customer) {
             if ($value < 0) {
                 if ($customer['point'] < abs($value)) {
                     return array('status' => 'fail', 'msg' => '积分不够扣除!');
                 }
             }
             $new_point = $customer['point'] + $value;
             $model->where("user_id=" . $user_id)->data(array('point' => $new_point))->update();
             $logs = array('user_id' => $user_id, 'value' => $value, 'point' => $new_point, 'note' => $note, 'create_time' => date('Y-m-d H:i:s'));
             $model = new Model('point_log');
             $model->data($logs)->insert();
             return true;
         }
     } else {
         return array('status' => 'fail', 'msg' => '积分必需为数值。');
     }
 }
Exemplo n.º 6
0
 public function ship_validator()
 {
     $model = new Model('ship');
     if (Req::args("is_default") == 1) {
         $model->data(array('is_default' => 0))->update();
     } else {
         $obj = $model->where('is_default=1')->find();
         if ($obj) {
         } else {
             Req::args("is_default", "1");
         }
     }
 }
Exemplo n.º 7
0
 public function binds()
 {
     $openid = isset($_SESSION['qqopenid']) ? $_SESSION['qqopenid'] : '';
     if ($openid == '') {
         $this->message2('缺少QQ登陆授权码,注册失败!', __APP__ . '/Index');
     }
     $user_model = new Model('user');
     $data = array();
     $is_valid = 1;
     if ($this->reg_setting['shenhe'] == 1) {
         $data['isvalid'] = 0;
         $is_valid = 0;
     }
     if ($this->reg_setting['verycode'] == 1) {
         if (session('verify') != md5(strtoupper(I('captcha', '')))) {
             $this->message2('验证码不正确!', U('bind'));
         }
     }
     $zs_money = 0;
     if ($this->reg_setting['zs_valid'] == 1 && 0 < $this->reg_setting['zs_money']) {
         $zs_money = $this->reg_setting['zs_money'];
     }
     $zs_user_type = 1;
     if ($reg_setting['zs_levl'] == 1 && 0 < $reg_setting['zs_user_type']) {
         $zs_user_type = $reg_setting['zs_user_type'];
     }
     $create_ip = get_client_ip();
     if ($this->reg_setting['reg_ip'] == 1) {
         $ip_counts = $this->reg_setting['ip_counts'];
         $reg_counts = M('user')->where('create_ip="' . $create_ip . '"')->count();
         if ($ip_counts <= $reg_counts) {
             $this->message2('注册失败:您的IP已被限制注册!', __APP__ . '/Index');
         }
     }
     $username = I('user_name', NULL);
     $data['username'] = $username;
     $data['password'] = MD5(I('pwd', NULL));
     $data['email'] = I('email', NULL);
     $data['user_qq'] = I('user_qq', NULL);
     $data['qqopenid'] = $openid;
     if (0 < $zs_money) {
         $data['money'] = $zs_money;
     }
     if (0 < $zs_user_type) {
         $data['user_type'] = $zs_user_type;
     }
     $data['create_time'] = $this->getDate();
     $data['last_login_time'] = $this->getDate();
     $data['last_login_ip'] = get_client_ip();
     $data['login_counts'] = 1;
     $data['create_ip'] = $create_ip;
     if ($reg_setting['reg_mibao'] == 1) {
         $mibao_name = I('mibao_name', '');
         $mibao_daan = I('mibao_daan', '');
         $data['mibao_setting'] = '{name:"' . $mibao_name . '",daan:"' . $mibao_daan . '"}';
         if ($mibao_name == '') {
             $this->message2('请选择保密问题,便于日后找回密码!', __URL__ . '/reg');
         }
         if ($mibao_daan == '') {
             $this->message2('请输入保密答案!', __URL__ . '/reg');
         }
     }
     $userid = $user_model->data($data)->add();
     if (false !== $userid) {
         if (0 < $zs_money) {
             if (0 < $zs_user_type) {
                 $log_array = array();
                 $log_array['user_id'] = $userid;
                 $log_array['stage'] = 'admin';
                 $log_array['money'] = $zs_money;
                 $log_array['remain_money'] = $zs_money;
                 $log_array['user_type'] = $zs_user_type;
                 $log_array['comm'] = '会员注册赠送体验金';
                 $log_array['addtime'] = $this->getDate();
                 M('account_log')->data($log_array)->add();
             }
         }
         session('userid', $userid);
         session('username', $username);
         session('IS_LOGIN', 1);
         session('isvalid', $is_valid);
         $this->message2('注册并成功绑定QQ!', __APP__ . '/Index');
     } else {
         $this->message2('注册失败:' . $user_model->getError(), __APP__ . '/Index');
     }
 }
Exemplo n.º 8
0
 /**
  * 登录验证动作
  * 
  * @access public
  */
 public function check()
 {
     $this->safebox = Safebox::getInstance();
     $this->title = '后台登录';
     $code = $this->safebox->get($this->captchaKey);
     if ($code != strtolower(Req::args($this->captchaKey))) {
         $this->msg = '验证码错误!';
         $this->layout = "";
         $this->redirect('login', false);
     } else {
         $manager = new Manager(Req::args('name'), Req::args('password'));
         $this->msg = '验证码错误!';
         if ($manager->getStatus() == 'online') {
             $back = Req::args('callback');
             $model = new Model("manager");
             $ip = Chips::getIP();
             $model->data(array('last_ip' => $ip, 'last_login' => date("Y-m-d H:i:s")))->where("id=" . $manager->id)->update();
             if ($back === null) {
                 $back = $this->defaultAction;
             }
             $this->redirect($back, true);
         } else {
             $this->msg = '用户名或者密码错误';
             $this->layout = "";
             $this->redirect('login', false);
         }
     }
 }
Exemplo n.º 9
0
 public static function updateStatusByNo($orderNo, $data)
 {
     $model = new Model('order');
     $model->data($data)->where("order_no=" . $orderNo)->update();
 }
Exemplo n.º 10
0
 private function xhbuy_deal($id, $order_money)
 {
     $return_data = array();
     $return_data['result'] = 'success';
     $xh_info = M('xiaohao')->where('id=' . $id)->find();
     if (empty($xh_info)) {
         $return_data['result'] = 'fail';
         $return_data['comm'] = '选择的小号不存在,请联系网站客服';
         $return_data['rtn_url'] = U('xh');
         return $return_data;
     }
     $xiaohao_type = M('xiaohao_type')->where('id=' . $xh_info['type_id'])->find();
     $type_config = json_decode($xiaohao_type['config'], true);
     $inprice = isset($type_config['in_price']) ? $type_config['in_price'] : 0;
     if ($xh_info['isused'] == 1) {
         $return_data['result'] = 'fail';
         $return_data['comm'] = 'Sorry,该小号已经被其他用户购买,请选择其他小号后尽快购买!';
         $return_data['rtn_url'] = U('xh');
         return $return_data;
     }
     $order_nums = 1;
     $userid = session('userid');
     $user_model = new Model('user');
     $user = $user_model->where('id=' . $userid)->find();
     $utype = 'a' . $user['user_type'];
     $uprice = isset($type_config['price'][$utype]) ? $type_config['price'][$utype] : 0;
     $money = $user['money'];
     if ($order_money < $uprice) {
         $return_data['result'] = 'fail';
         $return_data['comm'] = '订单金额有误!';
         $return_data['rtn_url'] = U('xh');
         return $return_data;
     }
     if ($money < $order_money) {
         $return_data['result'] = 'fail';
         $return_data['comm'] = '你的账户可用金额不足,请先充值!';
         $return_data['rtn_url'] = U('Cash/recharge');
         return $return_data;
     }
     $xh_data = array();
     $xh_data['isused'] = 1;
     $xh_data['id'] = $id;
     M('xiaohao')->data($xh_data)->save();
     $user_model->startTrans();
     $userdata['id'] = $userid;
     $userdata['money'] = $user['money'] - $order_money;
     $userdata['used_money'] = $user['used_money'] + $order_money;
     if (false !== $user_model->data($userdata)->save()) {
         $order_no = $this->create_orderno('XHBuy');
         $reason = '(购买小号) 订单号 ' . $order_no;
         $account_log = array();
         $account_log['user_id'] = $userid;
         $account_log['stage'] = 'buy';
         $account_log['money'] = 0 - $order_money;
         $account_log['comm'] = $reason;
         $account_log['addtime'] = $this->getDate();
         $account_log['remain_money'] = $userdata['money'];
         $account_log['remain_refer_money'] = $user['refer_money'];
         $account_log['order_no'] = $order_no;
         $account_log_model = new Model('account_log');
         $return_1 = D('account_log')->data($account_log)->add();
         $paydata = array();
         $paydata['user_id'] = $userid;
         $paydata['user_type'] = $user['user_type'];
         $paydata['pay_money'] = $order_money;
         $paydata['order_no'] = $order_no;
         $paydata['type'] = 0;
         $paydata['comm'] = '购买小号订单';
         $paydata['status'] = 1;
         $paydata['addtime'] = $this->getDate();
         $return_2 = M('pay_order')->data($paydata)->add();
         if ($return_1 && $return_2) {
             $i = 0;
             $order_time = $this->getDate();
             $result = true;
             $xiaohao_data = array();
             $xiaohao_data['id'] = $xh_info['id'];
             $xiaohao_data['isused'] = 1;
             $xiaohao_data['order_type'] = 0;
             $xiaohao_data['order_no'] = $order_no;
             $return_3 = D('xiaohao')->data($xiaohao_data)->save();
             if (!$return_3) {
                 $result = false;
             }
             if (!$result) {
                 $user_model->rollback();
                 $xh_data = array();
                 $xh_data['isused'] = 0;
                 $xh_data['id'] = $id;
                 M('xiaohao')->data($xh_data)->save();
                 $return_data['result'] = 'fail';
                 $return_data['comm'] = '购买失败1';
                 $return_data['rtn_url'] = U('xh');
                 return $return_data;
             }
             $xiaohao_order_data = array();
             $xiaohao_order_data['user_id'] = $userid;
             $xiaohao_order_data['type_id'] = $xh_info['type_id'];
             $xiaohao_order_data['order_no'] = $order_no;
             $xiaohao_order_data['order_time'] = $order_time;
             $xiaohao_order_data['order_status'] = 1;
             $xiaohao_order_data['order_money'] = $uprice;
             $xiaohao_order_data['in_price'] = $inprice;
             $xiaohao_order_data['user_type'] = $user['user_type'];
             $xiaohao_order_data['note_no'] = $xh_info['note_no'];
             if ($xh_info['encry_key'] != '') {
                 $xiaohao_order_data['note_no'] = encrypt($xh_info['note_no'], 'D', $xh_info['encry_key']);
             }
             $result_4 = D('xiaohao_order')->data($xiaohao_order_data)->add();
             if (!$result_4) {
                 $user_model->rollback();
                 $xh_data = array();
                 $xh_data['isused'] = 0;
                 $xh_data['id'] = $id;
                 M('xiaohao')->data($xh_data)->save();
                 $return_data['result'] = 'fail';
                 $return_data['comm'] = '购买失败2';
                 $return_data['rtn_url'] = U('xh');
                 return $return_data;
             }
             $refer_users = calc_commission($userid, 1, 3, $xh_info['type_id']);
             $add_result = true;
             if (!empty($refer_users)) {
                 $add_result = addrefer_money($refer_users, 1, $order_nums, 3, $order_no);
             }
             if (!$add_result) {
                 $user_model->rollback();
                 $xh_data = array();
                 $xh_data['isused'] = 0;
                 $xh_data['id'] = $id;
                 M('xiaohao')->data($xh_data)->save();
                 $return_data['result'] = 'fail';
                 $return_data['comm'] = '购买失败3';
                 $return_data['rtn_url'] = U('xh');
                 return $return_data;
             }
             $user_model->commit();
             $return_data['comm'] = '购买成功';
             $return_data['rtn_url'] = U('xh');
             return $return_data;
         } else {
             $user_model->rollback();
             $xh_data = array();
             $xh_data['isused'] = 0;
             $xh_data['id'] = $id;
             M('xiaohao')->data($xh_data)->save();
             $return_data['result'] = 'fail';
             $return_data['comm'] = '购买失败4';
             $return_data['rtn_url'] = U('xh');
             return $return_data;
         }
     } else {
         $user_model->rollback();
         $xh_data = array();
         $xh_data['isused'] = 0;
         $xh_data['id'] = $id;
         M('xiaohao')->data($xh_data)->save();
         $return_data['result'] = 'fail';
         $return_data['comm'] = '购买失败5';
         $return_data['rtn_url'] = U('xh');
         return $return_data;
     }
 }
Exemplo n.º 11
0
 /**
  * @brief 获取订单中的支付信息
  * @type         信息获取方式 order:订单支付;recharge:在线充值;
  * @argument     参数
  * @return array 支付提交信息
  * R表示店铺 ; P表示用户;
  */
 public function getPaymentInfo($type, $argument)
 {
     $controller = Tiny::app()->getController();
     //支付信息
     $payment = array();
     //取的支付商户的ID与密钥
     $paymentObj = $this->getPayment();
     $payment['M_PartnerId'] = $paymentObj['partner_id'];
     $payment['M_PartnerKey'] = $paymentObj['partner_key'];
     $model = new Model("order");
     if ($type == 'order') {
         $order_id = $argument;
         //获取订单信息
         $order = $model->where('id = ' . $order_id . ' and status = 2')->find();
         if (empty($order)) {
             $msg = array('type' => 'fail', 'msg' => '订单信息不正确,不能进行支付!');
             $controller->redirect('/index/msg', false, $msg);
             exit;
         }
         //商品名称
         $model2 = new Model("order_goods");
         $model3 = new Model("goods");
         $order_goods = $model2->where('order_id = ' . $order_id . '')->findAll();
         $goods_name = '';
         foreach ($order_goods as $order_item) {
             // 如果订单详细表中行是由于捆绑促销
             if (isset($order_item['prom_type']) && $order_item['prom_type'] === 'bundling') {
                 $goods_name .= $order_item['title'] . ', ';
             } else {
                 $goods_id = $order_item['goods_id'];
                 $goods = $model3->where('id = ' . $goods_id . '')->find();
                 $goods_name .= $goods['name'] . ', ';
             }
         }
         $payment['M_Name'] = trim($goods_name, ', ');
         $payment['M_Remark'] = $order['user_remark'];
         $payment['M_OrderId'] = $order['id'];
         $payment['M_OrderNO'] = $order['order_no'];
         $payment['M_Amount'] = $order['order_amount'];
         //用户信息
         $payment['P_Mobile'] = $order['mobile'];
         $payment['P_Name'] = $order['accept_name'];
         $payment['P_PostCode'] = $order['zip'];
         $payment['P_Telephone'] = $order['phone'];
         $payment['P_Address'] = $order['addr'];
         $payment['P_Email'] = '';
     } else {
         if ($type == 'recharge') {
             if (!isset($argument['account']) || $argument['account'] <= 0) {
                 $msg = array('type' => 'fail', 'msg' => '请填入正确的充值金额!');
                 $controller->redirect('/index/msg', false, $msg);
                 exit;
             }
             $safebox = Safebox::getInstance();
             $user = $safebox->get('user');
             $recharge = new Model('recharge');
             $data = array('user_id' => $user['id'], 'recharge_no' => Common::createOrderNo(), 'account' => $argument['account'], 'time' => date('Y-m-d H:i:s'), 'payment_name' => $argument['paymentName'], 'status' => 0);
             $r_id = $recharge->data($data)->insert();
             //充值时用户id跟随交易号一起发送,以"_"分割
             $payment['M_OrderNO'] = 'recharge_' . $data['recharge_no'];
             $payment['M_OrderId'] = $r_id;
             $payment['M_Amount'] = $data['account'];
         }
     }
     $config = Config::getInstance();
     $site_config = $config->get("globals");
     //交易信息
     $payment['M_Def_Amount'] = 0.01;
     $payment['M_Time'] = time();
     $payment['M_Goods'] = '';
     $payment['M_Language'] = "zh_CN";
     $payment['M_Paymentid'] = $this->payment_id;
     //商城信息
     $payment['R_Address'] = isset($site_config['site_addr']) ? $site_config['site_addr'] : '';
     $payment['R_Name'] = isset($site_config['site_name']) ? $site_config['site_name'] : '';
     $payment['R_Mobile'] = isset($site_config['site_mobile']) ? $site_config['site_mobile'] : '';
     $payment['R_Telephone'] = isset($site_config['site_phone']) ? $site_config['site_phone'] : '';
     $payment['R_Postcode'] = isset($site_config['site_zip']) ? $site_config['site_zip'] : '';
     $payment['R_Email'] = isset($site_config['site_email']) ? $site_config['site_email'] : '';
     return $payment;
 }
Exemplo n.º 12
0
 function goods_save()
 {
     $spec_items = Req::args('spec_items');
     $spec_item = Req::args('spec_item');
     $items = explode(",", $spec_items);
     $values_array = array();
     //货品中的一些变量
     $pro_no = Req::args("pro_no");
     $store_nums = Req::args("store_nums");
     $warning_line = Req::args("warning_line");
     $weight = Req::args("weight");
     $sell_price = Req::args("sell_price");
     $market_price = Req::args("market_price");
     $cost_price = Req::args("cost_price");
     //values的笛卡尔积
     $values_dcr = array();
     $specs_new = array();
     if (is_array($spec_item)) {
         foreach ($spec_item as $item) {
             $values = explode(",", $item);
             foreach ($values as $value) {
                 $value_items = explode(":", $value);
                 $values_array[$value_items[0]] = $value_items;
             }
         }
         $value_ids = implode(",", array_keys($values_array));
         $values_model = new Model('spec_value');
         $spec_model = new Model('goods_spec');
         $specs = $spec_model->where("id in ({$spec_items})")->findAll();
         $values = $values_model->where("id in ({$value_ids})")->order('sort')->findAll();
         $values_new = array();
         foreach ($values as $k => $row) {
             $current = $values_array[$row['id']];
             if ($current[1] != $current[2]) {
                 $row['name'] = $current[2];
             }
             if ($current[3] != '') {
                 $row['img'] = $current[3];
             }
             $values_new[$row['spec_id']][$row['id']] = $row;
         }
         foreach ($specs as $key => $value) {
             $value['value'] = isset($values_new[$value['id']]) ? $values_new[$value['id']] : null;
             $specs_new[$value['id']] = $value;
         }
         foreach ($spec_item as $item) {
             $values = explode(",", $item);
             $key_code = ';';
             foreach ($values as $k => $value) {
                 $value_items = explode(":", $value);
                 $key = $items[$k];
                 $tem[$key] = $specs_new[$key];
                 $tem[$key]['value'] = $values_array[$value_items[0]];
                 $key_code .= $key . ':' . $values_array[$value_items[0]][0] . ';';
             }
             $values_dcr[$key_code] = $tem;
         }
     }
     //商品处理
     $goods = new Model('goods');
     Req::args('specs', serialize($specs_new));
     $attrs = is_array(Req::args("attr")) ? Req::args("attr") : array();
     $imgs = is_array(Req::args("imgs")) ? Req::args("imgs") : array();
     Req::args('attrs', serialize($attrs));
     Req::args('imgs', serialize($imgs));
     Req::args('up_time', date("Y-m-d H:i:s"));
     $id = intval(Req::args("id"));
     $gdata = Req::args();
     $gdata['name'] = Filter::sql($gdata['name']);
     //$gdata['sub_title'] = Filter::sql($gdata['sub_title']);
     $gdata['content'] = Filter::htmlstr($gdata['content']);
     $gdata['sale_protection'] = Filter::htmlstr($gdata['sale_protection']);
     if (isset($gdata['pro_no']) && is_array($gdata['pro_no'])) {
         $gdata['pro_no'] = $gdata['pro_no'][0];
     }
     //Tiny::log(__FILE__.__LINE__."-".var_export($gdata, true));
     if ($id == 0) {
         $gdata['create_time'] = date("Y-m-d H:i:s");
         $goods_id = $goods->data($gdata)->save();
         Log::op($this->manager['id'], "添加商品", "管理员[" . $this->manager['name'] . "]:添加了商品 " . Req::args('name'));
     } else {
         $goods_id = $id;
         $goods->data($gdata)->where("id =" . $id)->update();
         //$sql = Tiny::getSqlLog(); Tiny::log(__FILE__.__LINE__."-".var_export($sql, true));
         Log::op($this->manager['id'], "修改商品", "管理员[" . $this->manager['name'] . "]:修改了商品 " . Req::args('name'));
     }
     //货品添加处理
     $g_store_nums = $g_warning_line = $g_weight = $g_sell_price = $g_market_price = $g_cost_price = 0;
     $products = new Model("products");
     $k = 0;
     foreach ($values_dcr as $key => $value) {
         $result = $products->where("goods_id = " . $goods_id . " and specs_key = '{$key}'")->find();
         $data = array('goods_id' => $goods_id, 'pro_no' => $pro_no[$k], 'store_nums' => $store_nums[$k], 'warning_line' => $warning_line[$k], 'weight' => $weight[$k], 'sell_price' => $sell_price[$k], 'market_price' => $market_price[$k], 'cost_price' => $cost_price[$k], 'specs_key' => $key, 'spec' => serialize($value));
         $g_store_nums += $data['store_nums'];
         if ($g_warning_line == 0) {
             $g_warning_line = $data['warning_line'];
         } else {
             if ($g_warning_line > $data['warning_line']) {
                 $g_warning_line = $data['warning_line'];
             }
         }
         if ($g_weight == 0) {
             $g_weight = $data['weight'];
         } else {
             if ($g_weight < $data['weight']) {
                 $g_weight = $data['weight'];
             }
         }
         if ($g_sell_price == 0) {
             $g_sell_price = $data['sell_price'];
         } else {
             if ($g_sell_price > $data['sell_price']) {
                 $g_sell_price = $data['sell_price'];
             }
         }
         if ($g_market_price == 0) {
             $g_market_price = $data['market_price'];
         } else {
             if ($g_market_price < $data['market_price']) {
                 $g_market_price = $data['market_price'];
             }
         }
         if ($g_cost_price == 0) {
             $g_cost_price = $data['cost_price'];
         } else {
             if ($g_cost_price < $data['cost_price']) {
                 $g_cost_price = $data['cost_price'];
             }
         }
         if (!$result) {
             $products->data($data)->insert();
         } else {
             $products->data($data)->where("goods_id=" . $goods_id . " and specs_key='{$key}'")->update();
         }
         $k++;
     }
     //如果没有规格
     if ($k == 0) {
         $g_store_nums = $store_nums;
         $g_warning_line = $warning_line;
         $g_weight = $weight;
         $g_sell_price = $sell_price;
         $g_market_price = $market_price;
         $g_cost_price = $cost_price;
         $data = array('goods_id' => $goods_id, 'pro_no' => $pro_no, 'store_nums' => $store_nums, 'warning_line' => $warning_line, 'weight' => $weight, 'sell_price' => $sell_price, 'market_price' => $market_price, 'cost_price' => $cost_price, 'specs_key' => '', 'spec' => serialize(array()));
         $result = $products->where("goods_id = " . $goods_id)->find();
         if (!$result) {
             $products->data($data)->insert();
         } else {
             $products->data($data)->where("goods_id=" . $goods_id)->update();
         }
     }
     //更新商品相关货品的部分信息
     $goods->data(array('store_nums' => $g_store_nums, 'warning_line' => $g_warning_line, 'weight' => $g_weight, 'sell_price' => $g_sell_price, 'market_price' => $g_market_price, 'cost_price' => $g_cost_price))->where("id=" . $goods_id)->update();
     $keys = array_keys($values_dcr);
     $keys = implode("','", $keys);
     //清理多余的货品
     $products->where("goods_id=" . $goods_id . " and specs_key not in('{$keys}')")->delete();
     //规格与属性表添加部分
     $spec_attr = new Model("spec_attr");
     //处理属性部分
     $value_str = '';
     if ($attrs) {
         foreach ($attrs as $key => $attr) {
             if (is_numeric($attr)) {
                 $value_str .= "({$goods_id},{$key},{$attr}),";
             }
         }
     }
     foreach ($specs_new as $key => $spec) {
         if (isset($spec['value'])) {
             foreach ($spec['value'] as $k => $v) {
                 $value_str .= "({$goods_id},{$key},{$k}),";
             }
         }
     }
     $value_str = rtrim($value_str, ',');
     //更新商品键值对表
     $spec_attr->where("goods_id = " . $goods_id)->delete();
     $dbinfo = DBFactory::getDbInfo();
     $spec_attr->query("insert into {$dbinfo['tablePre']}spec_attr values {$value_str}");
     $this->redirect("goods_list");
 }
Exemplo n.º 13
0
 public function deal_uplevel()
 {
     if (!IS_AJAX) {
         $this->message2('无效请求!', __APP__ . '/Index');
     }
     $userid = session('userid');
     $level_id = I('id', NULL);
     if (empty($level_id)) {
         $this->ajaxReturn('', '升级失败1', 0);
     }
     $level_list = M('user_level')->order('sort_order asc')->select();
     $level_array = array();
     foreach ($level_list as $k => $v) {
         $level_array[$v['id']] = $v['title'];
     }
     $user_level = M('user_level')->where('id=' . $level_id)->find();
     if (empty($user_level)) {
         $this->ajaxReturn('', '升级失败2', 0);
     }
     $level_config = json_decode($user_level['config'], true);
     $up_money = $level_config['money'];
     if ($up_money <= 0) {
         $this->ajaxReturn('', '无升级费用', 0);
     }
     $user_model = new Model('user');
     $user = $user_model->where('id=' . $userid)->find();
     if (empty($user)) {
         $this->ajaxReturn('', '获取人员信息出错,或者尚未登录!', 0);
     }
     $current_type = $user['user_type'];
     if ($current_type == $level_id) {
         $this->ajaxReturn('', '你目前已经是' . $level_array[$current_type] . ',无需升级!', 0);
     }
     $money = $user['money'];
     if ($money < $up_money) {
         $this->ajaxReturn('', '您的账户可用余额不足!请先充值或者使用可用佣金转换成账户余额!', 0);
     }
     $userdata['id'] = $userid;
     $userdata['money'] = $user['money'] - $up_money;
     $userdata['used_money'] = $user['used_money'] + $up_money;
     $userdata['user_type'] = $level_id;
     $user_model->startTrans();
     $result = $user_model->data($userdata)->save();
     if ($result) {
         $reason = '(会员升级) 会员由 ' . $level_array[$current_type] . '升级为:' . $level_array[$level_id];
         $account_log = array();
         $account_log['user_id'] = $userid;
         $account_log['stage'] = 'upgrade';
         $account_log['money'] = 0 - $up_money;
         $account_log['comm'] = $reason;
         $account_log['addtime'] = $this->getDate();
         $account_log['remain_money'] = $userdata['money'];
         $account_log['remain_refer_money'] = $user['refer_money'];
         $account_log_model = new Model('account_log');
         $return_1 = D('account_log')->data($account_log)->add();
         if ($return_1) {
             $refer_users = calc_commission($userid, 2);
             $add_result = true;
             if (!empty($refer_users)) {
                 $add_result = addrefer_money($refer_users, 2, 1, 1, $userid);
             }
             if (!$add_result) {
                 $user_model->rollback();
                 $this->ajaxReturn('', '升级失败-l!', 0);
             }
             $user_model->commit();
             $this->ajaxReturn('', '升级成功', 1);
         } else {
             $this->ajaxReturn('', '升级失败 -A', 0);
         }
     } else {
         $user_model->rollback();
         $this->ajaxReturn('', '升级失败 -U', 0);
     }
 }
Exemplo n.º 14
0
function session($name, $value = '', $operation = '')
{
    static $config = null;
    /* session设置 */
    static $type = null;
    /* session类型 */
    static $db = null;
    /* session数据库对象 */
    static $session_id = '';
    /* session数据的id */
    static $session_object = array();
    /* session数据对象 */
    static $initialized = false;
    /* session是否初始化 */
    /* 生成随机的session id */
    function create_session_id()
    {
        $t = microtime();
        $str = $_SERVER['REMOTE_ADDR'] . $t . mt_srand();
        return md5($str);
    }
    /* 读取配置文件 */
    if ($config === null) {
        $config = config('SESSION');
        $type = $config['TYPE'];
    }
    switch ($type) {
        /* 使用系统的session */
        case 'system':
            /* 初始化 */
            if (!$initialized) {
                session_name($config['COOKIE']);
                session_cache_expire($config['EXPIRE']);
                session_start();
                $initialized = true;
            }
            switch ($operation) {
                /* 销毁session */
                case 'destroy':
                    session_unset();
                    session_destroy();
                    return true;
                    /* 删除某个值 */
                /* 删除某个值 */
                case 'delete':
                    if (isset($_SESSION[$name])) {
                        unset($_SESSION[$name]);
                    }
                    return true;
            }
            /* 读取及赋值 */
            if (is_string($name) && $name !== '') {
                if ($value === '') {
                    return $_SESSION[$name];
                } else {
                    $_SESSION[$name] = $value;
                }
            }
            break;
            /* 使用数据库方式存储session */
        /* 使用数据库方式存储session */
        case 'db':
            /* 初始化数据库 */
            if ($db === null) {
                $db = new Model($config['DB']['tableName'], $config['DB']);
            }
            /* 根据几率触发session gc */
            if (mt_rand(1, $config['GCDIVER']) === 1) {
                $db->where(array('last' => array('lt', time() - $config['EXPIRE'])))->delete();
            }
            if (!$initialized) {
                $session_id = cookie($config['COOKIE']);
                if (!$session_id) {
                    $session_id = create_session_id();
                    $db->data(array('key' => $session_id, 'value' => '{}', 'last' => time()))->add();
                }
                $object = $db->where(array('key' => $session_id))->find();
                if ($object) {
                    /* 如果发现session超时 */
                    if ($object['last'] + $config['EXPIRE'] < time()) {
                        $session_id = create_session_id();
                        $db->data(array('key' => $session_id, 'value' => '{}', 'last' => time()))->add();
                        $session_object = array();
                    } else {
                        $session_object = json_decode($object['value'], true);
                    }
                }
                cookie($config['COOKIE'], $session_id);
            }
            switch ($operation) {
                case 'destroy':
                    $db->where(array('key' => $session_id))->delete();
                    $initialized = false;
                    $session_object = array();
                    cookie($config['COOKIE'], '', time() - 100);
                    return true;
                case 'delete':
                    if (isset($session_object[$name])) {
                        unset($session_object[$name]);
                        $db->where(array('key' => $session_id))->data(array('value' => json_encode($session_object), 'last' => time()))->update();
                    }
                    return true;
            }
            if (is_string($name) && $name !== '') {
                if ($value === '') {
                    return $session_object[$name];
                } else {
                    $session_object[$name] = $value;
                    $db->where(array('key' => $session_id))->data(array('value' => json_encode($session_object), 'last' => time()))->update();
                }
            }
            break;
        case 'cache':
            /*
             * @TODO: 完成cache部分
             */
            break;
    }
}
Exemplo n.º 15
0
 public function upload_head()
 {
     $upfile_path = Tiny::getPath("uploads") . "/head/";
     $upfile_url = preg_replace("|" . APP_URL . "|", '', Tiny::getPath("uploads_url") . "head/", 1);
     //$upfile_url = strtr(Tiny::getPath("uploads_url")."head/",APP_URL,'');
     $upfile = new UploadFile('imgFile', $upfile_path, '500k', '', 'hash', $this->user['id']);
     $upfile->save();
     $info = $upfile->getInfo();
     $result = array();
     if ($info[0]['status'] == 1) {
         $result = array('error' => 0, 'url' => $upfile_url . $info[0]['path']);
         $image_url = $upfile_url . $info[0]['path'];
         $image = new Image();
         $image->suffix = '';
         $image->thumb(APP_ROOT . $image_url, 100, 100);
         $model = new Model('user');
         $model->data(array('head_pic' => $image_url))->where("id=" . $this->user['id'])->update();
         $safebox = Safebox::getInstance();
         $user = $this->user;
         $user['head_pic'] = $image_url;
         $safebox->set('user', $user);
     } else {
         $result = array('error' => 1, 'message' => $info[0]['msg']);
     }
     echo JSON::encode($result);
 }
Exemplo n.º 16
0
 public function voucher_create()
 {
     $id = Req::args("id");
     $start_time = Req::args("start_time");
     $start_time = $start_time == null ? date("Y-m-d") : $start_time;
     $end_time = Req::args("end_time");
     $end_time = $end_time == null ? date("Y-m-d 23:59:59", strtotime("+30 days")) : date("Y-m-d 23:59:59", strtotime($end_time));
     $model = new Model('voucher_template');
     $voucher_template = $model->where("id = {$id}")->find();
     if ($voucher_template) {
         $voucher_model = new Model('voucher');
         $num = Req::args('num');
         $i = 0;
         while ($i < $num) {
             do {
                 $account = strtoupper(CHash::random(10, 'char'));
                 $password = strtoupper(CHash::random(10, 'char'));
                 $voucher_template['account'] = $account;
                 $voucher_template['password'] = $password;
                 $voucher_template['start_time'] = $start_time;
                 $voucher_template['end_time'] = $end_time;
                 $obj = $voucher_model->where("account = '{$account}'")->find();
             } while ($obj);
             unset($voucher_template['id'], $voucher_template['point']);
             $voucher_model->data($voucher_template)->insert();
             $i++;
         }
     }
     echo JSON::encode(array('status' => 'success', 'msg' => '已成功生成[' . $voucher_template['name'] . ']代金券(' . $num . ')张'));
 }
Exemplo n.º 17
0
 public function doPay()
 {
     // 获得payment_id 获得相关参数
     $payment_id = Filter::int(Req::args('payment_id'));
     $order_id = Filter::int(Req::args('order_id'));
     $recharge = Req::args('recharge');
     $extendDatas = Req::args();
     if ($payment_id) {
         $payment = new Payment($payment_id);
         $paymentPlugin = $payment->getPaymentPlugin();
         //充值处理
         if ($recharge != null) {
             $recharge = Filter::float($recharge);
             $paymentInfo = $payment->getPayment();
             $data = array('account' => $recharge, 'paymentName' => $paymentInfo['name']);
             $packData = $payment->getPaymentInfo('recharge', $data);
             $packData = array_merge($extendDatas, $packData);
             $sendData = $paymentPlugin->packData($packData);
         } else {
             if ($order_id != null) {
                 $order = Order::getOrder($order_id);
                 $model = new Model("order_goods");
                 if ($order) {
                     //获取订单可能延时时长,0不限制
                     $config = Config::getInstance();
                     $config_other = $config->get('other');
                     // todo 修改方法  order type 去掉  详情表中记录 order type
                     switch ($order['type']) {
                         case '1':
                             $order_delay = isset($config_other['other_order_delay_group']) ? intval($config_other['other_order_delay_group']) : 120;
                             break;
                         case '2':
                             $order_delay = isset($config_other['other_order_delay_flash']) ? intval($config_other['other_order_delay_flash']) : 120;
                             break;
                         case '3':
                             $order_delay = isset($config_other['other_order_delay_bund']) ? intval($config_other['other_order_delay_bund']) : 0;
                             break;
                         default:
                             $order_delay = isset($config_other['other_order_delay']) ? intval($config_other['other_order_delay']) : 0;
                             break;
                     }
                     $time = strtotime("-" . $order_delay . " Minute");
                     $create_time = strtotime($order['create_time']);
                     if ($create_time >= $time || $order_delay == 0) {
                         //取得所有订单商品
                         //$order_goods = $model->table('order_goods')->fields("product_id,goods_nums, prom_type")->where('order_id='.$order_id)->findAll();
                         $order_goods_inst = new OrderGoods();
                         $order_goods = $order_goods_inst->getOrderGoods($order_id);
                         $product_ids = array();
                         $order_products = array();
                         // todo 这里判断 prom_type 类型
                         foreach ($order_goods as $value) {
                             // 套餐不在这里检查商品库存  考虑在别的地方检查
                             // 如果订单详细表中行是由于捆绑促销
                             if ($value['prom_type'] == 'bundling') {
                                 continue;
                             } else {
                                 $product_ids[] = $value['product_id'];
                                 $order_products[$value['product_id']] = $value['goods_nums'];
                             }
                         }
                         $packData = $payment->getPaymentInfo('order', $order_id);
                         $packData = array_merge($extendDatas, $packData);
                         $sendData = $paymentPlugin->packData($packData);
                         /* 这里不需要验证库存量  提交订单时已经验证
                                                 if (!empty($product_ids)) {
                         
                                                     $product_ids = implode(',', $product_ids);
                                                     $products = $model->table('products')->fields("id,store_nums")->where("id in ($product_ids)")->findAll();
                                                     $products_list = array();
                                                     foreach ($products as $value) {
                                                         $products_list[$value['id']] = $value['store_nums'];
                                                     }
                                                     $flag = true;
                                                     foreach ($order_goods as $value) {
                                                         if ($order_products[$value['product_id']] > $products_list[$value['product_id']]) {
                                                             $flag = false;
                                                             break;
                                                         }
                                                     }
                                                     //检测库存是否还能满足订单
                                                     if ($flag) {
                                                         //团购订单
                                                         if ($order['type'] == 1 || $order['type'] == 2) {
                                                             if ($order['type'] == 1) {
                                                                 $prom_name = '团购';
                                                                 $prom_table = "groupbuy";
                                                             } else {
                                                                 $prom_name = '抢购';
                                                                 $prom_table = "flash_sale";
                                                             }
                                                             $prom = $model->table($prom_table)->where("id=" . $order['prom_id'])->find();
                                                             if ($prom) {
                                                                 if (time() > strtotime($prom['end_time']) || $prom['max_num'] <= $prom["goods_num"]) {
                                                                     $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update();
                                                                     $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,' . $prom_name . "活动已结束。"));
                                                                     exit;
                                                                 }
                                                             }
                                                         }
                         
                                                         $packData = $payment->getPaymentInfo('order', $order_id);
                                                         $packData = array_merge($extendDatas, $packData);
                                                         $sendData = $paymentPlugin->packData($packData);
                         
                                                     } else {
                                                         $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update();
                                                         $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,库存已不足。'));
                                                         exit;
                         
                                                     }
                                                 }
                                                 */
                     } else {
                         $model->data(array('status' => 6))->where('id=' . $order_id)->update();
                         $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '订单超出了规定时间内付款,已作废.'));
                         exit;
                     }
                 }
             }
         }
         if (!empty($sendData)) {
             $this->assign("paymentPlugin", $paymentPlugin);
             $this->assign("sendData", $sendData);
             $this->redirect('pay_form', false);
         } else {
             $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '需要支付的订单已经不存在。'));
         }
     } else {
         echo "fail";
     }
 }
Exemplo n.º 18
0
 /**
  * Метод для получения прогноза в формате XML
  * @param  string $url путь до файла с прогнозом
  * @return string
  */
 public static function getXmlData($url)
 {
     self::$url = $url;
     self::$data = file_get_contents($url);
     return self::$data;
 }
Exemplo n.º 19
0
 public function activation_user()
 {
     $code = Filter::text(Req::args('code'));
     $email_code = substr($code, 32);
     $valid_code = substr($code, 0, 32);
     $email = Crypt::decode($email_code);
     $model = new Model('user');
     $user = $model->where("email='" . $email . "'")->find();
     if ($user && $user['status'] == 0 && md5($user['validcode']) == $valid_code) {
         $model->data(array('status' => 1))->where('id=' . $user['id'])->update();
         $this->redirect("/index/msg", false, array('type' => "success", "msg" => '账户激活成功', "content" => "账户通过邮件成功激活。", "redirect" => "/simple/login"));
     } else {
         $this->redirect("/index/msg", false, array('type' => "fail", "msg" => '账户激活失败', "content" => "你的连接地址无效,无法进行账户激活,请核实你的连接地址无误。"));
     }
 }
Exemplo n.º 20
0
 public function lxcz_pay()
 {
     $key = I('key', '');
     $name = I('name', '');
     $money = I('money', 0);
     if (strstr($name, '付款-')) {
         $name = ltrim($name, '付款-');
     }
     $outer_order_no = I('tradeNo', '');
     $config = M('config')->where('id=1')->find();
     $reg_setting = json_decode($config['reg_setting'], true);
     if ($key != $config['alipay_Key']) {
         echo '0';
         exit;
     }
     $is_flag = I('flag', 0);
     $order = M('pay_order')->where('outer_order_no=\'' . $outer_order_no . '\' and type=1 ')->find();
     if ($is_flag == 1) {
         if (empty($order)) {
             echo '0';
             exit;
         }
         $user = M('user')->where('id=' . $order['user_id'])->find();
         if (empty($user)) {
             echo '0';
             exit;
         }
         $userid = $order['user_id'];
         $name = '人工充值:' . $name;
     } else {
         if (substr($name, 0, 1) == 'A') {
             $alipaytitle_array = explode('-', $name);
             $order_type = 0;
         } else {
             if (substr($name, 0, 1) == 'T') {
                 $name1 = 'TS' . substr($name, 1);
                 $alipaytitle_array = explode('S', $name1);
                 $order_type = 1;
             }
         }
         $userid = isset($alipaytitle_array[1]) ? $alipaytitle_array[1] : 0;
         $sign_title_soft = isset($alipaytitle_array[2]) ? $alipaytitle_array[2] : '';
         $auth_type = C('AUTH_TYPE');
         $user = M('user')->where('id=' . $userid)->find();
         if (empty($user)) {
             echo '0';
             exit;
         }
         $user_name = $user['username'];
         $user_name = trim($user_name);
         $sign_title = substr(md5($userid . $user_name . $auth_type), 0, 10);
         if (substr($sign_title_soft, 0, 10) != $sign_title) {
             echo '0';
             exit;
         }
     }
     if (empty($order)) {
         $paydata = array();
         $model = new Model('pay_order');
         $paydata['user_id'] = $userid;
         $paydata['user_type'] = $user['user_type'];
         $paydata['pay_money'] = $money;
         $paydata['order_no'] = $this->create_orderno('APay');
         $paydata['outer_order_no'] = $outer_order_no;
         $paydata['pay_title'] = $name;
         $paydata['type'] = 1;
         $paydata['comm'] = 'LxCz[' . $name . ']';
         $paydata['status'] = 1;
         $paydata['order_type'] = $order_type;
         $paydata['addtime'] = $this->getDate();
         $model->startTrans();
         if (false !== $model->data($paydata)->add()) {
             $user_model = new Model('user');
             $userdata = array();
             $userdata['id'] = $userid;
             $userdata['money'] = $user['money'] + $money;
             if ($reg_setting['reg_zengsong'] == 1) {
                 $config = M('config')->where('id=1')->find();
                 $payrule_setting = json_decode($config['payrule_setting'], true);
                 foreach ($payrule_setting as $row) {
                     if ((double) $row['start'] <= $money && $money <= (double) $row['end']) {
                         $give = (double) $row['give'];
                         $grade = (int) $row['grade'];
                         $userdata['money'] = $user['money'] + $money + $give;
                         $songtext = '送' . $give . '元';
                         $pay_title = '送' . $give . '元';
                         $rs = M('user')->where('id=' . $userid)->find();
                         if ($rs) {
                             $user_type = (int) $rs['user_type'];
                             if ($user_type < $grade) {
                                 $userdata['user_type'] = $grade;
                                 $level = M('user_level')->where('id=' . $grade)->find();
                                 if ($level) {
                                     $songtext .= '+' . $level['title'];
                                     $level_name = '+' . $level['title'];
                                 }
                             }
                         }
                         $zs_order_no = 'ZengSong' . date('YmdHis');
                         $paydata['user_id'] = $userid;
                         $paydata['user_type'] = $user['user_type'];
                         $paydata['pay_money'] = $give;
                         $paydata['order_no'] = $zs_order_no;
                         $paydata['outer_order_no'] = $zs_order_no;
                         $paydata['pay_title'] = $pay_title . $level_name;
                         $paydata['type'] = 1;
                         $paydata['comm'] = 'LxCz[' . $songtext . ']';
                         $paydata['status'] = 1;
                         $paydata['order_type'] = 2;
                         $paydata['addtime'] = $this->getDate();
                         $model->data($paydata)->add();
                         break;
                     }
                 }
             }
             if (false !== $user_model->where('id=' . $userid)->save($userdata)) {
                 $reason = '(用户充值) 订单号 ' . $paydata['order_no'] . '-自动到账' . $songtext;
                 $account_log = array();
                 $account_log['user_id'] = $userid;
                 $account_log['stage'] = 'recharge';
                 $account_log['money'] = $money;
                 $account_log['comm'] = $reason;
                 $account_log['addtime'] = $this->getDate();
                 $account_log['remain_money'] = $userdata['money'];
                 $account_log['remain_refer_money'] = $user['refer_money'];
                 if (false !== D('account_log')->data($account_log)->add()) {
                     $model->commit();
                     echo '1';
                     exit;
                 } else {
                     $model->rollback();
                     echo '0';
                     exit;
                 }
             } else {
                 $model->rollback();
                 echo '0';
                 exit;
             }
         } else {
             $model->rollback();
             echo '0';
             exit;
         }
     } else {
         if ($order['status'] == 1) {
             echo '1';
             exit;
         } else {
             if ($order['user_id'] != $userid) {
                 echo '0';
                 exit;
             }
             if ($money != $order['pay_money']) {
                 echo '0';
                 exit;
             }
             $rtn_1 = $this->deal_account($order['id'], $user, $name, 'LXCZ');
             if ($rtn_1) {
                 echo '1';
                 exit;
             } else {
                 echo '0';
                 exit;
             }
         }
     }
 }
Exemplo n.º 21
0
 public function deal_change()
 {
     if (!IS_POST) {
         $this->message2('无效请求!', __APP__ . '/Index');
     }
     $money = I('money', 0);
     if ($money <= 0) {
         $this->message2('转换金额必须大于0', __APP__ . '/User/Home');
     }
     if ($money % 1 != 0) {
         $this->message2('转换金额必须为整数!', __APP__ . '/User/Home');
     }
     $userid = session('userid');
     $user_model = new Model('user');
     $user = $user_model->where('id=' . $userid)->find();
     if (empty($user)) {
         $this->message2('获取用户信息出错!', __APP__ . '/User/Home');
     }
     $refer_money = $user['refer_money'];
     if ($refer_money < $money) {
         $this->message2('转换金额不能高于当前可用佣金!', __APP__ . '/User/Home');
     }
     $userdata['id'] = $userid;
     $userdata['refer_money'] = $user['refer_money'] - $money;
     $userdata['money'] = $user['money'] + $money;
     $user_model->startTrans();
     $result = $user_model->data($userdata)->save();
     if ($result) {
         $account_log_model = new Model('account_log');
         $reason = '佣金转换成账户余额-佣金减少';
         $account_log = array();
         $account_log['user_id'] = $userid;
         $account_log['stage'] = 'change';
         $account_log['money'] = 0 - $money;
         $account_log['comm'] = $reason;
         $account_log['addtime'] = $this->getDate();
         $account_log['remain_money'] = $userdata['money'];
         $account_log['remain_refer_money'] = $userdata['refer_money'];
         $result_1 = D('account_log')->data($account_log)->add();
         $reason = '佣金转换成账户余额-账户余额增加';
         $account_log['money'] = $money;
         $account_log['comm'] = $reason;
         $result_2 = D('account_log')->data($account_log)->add();
         if ($result_1 && $result_2) {
             $user_model->commit();
             $this->message2('转换成功!', __APP__ . '/User/Home');
         } else {
             $user_model->rollback();
             $this->message2('佣金转换失败:' . $user_model->getError(), __APP__ . '/User/Home');
         }
     } else {
         $user_model->rollback();
         $this->message2('佣金转换失败:' . $user_model->getError(), __APP__ . '/User/Home');
     }
 }
Exemplo n.º 22
0
 public function notify()
 {
     $rules = array('email:email:邮箱格式不正确!', 'mobile:mobi:手机格式不正确!');
     $validator_info = Validator::check($rules);
     if (is_array($validator_info)) {
         $info = array('status' => 'fail', 'msg' => $validator_info['msg']);
         echo JSON::encode($info);
     } else {
         $goods_id = Filter::int(Req::args('goods_id'));
         $email = Filter::sql(Req::args('email'));
         $mobile = Filter::int(Req::args('mobile'));
         $model = new Model('notify');
         $register_time = Date('Y-m-d H:i:s');
         $info = array('status' => 'fail', 'msg' => '您还没有登录,无法订阅到货通知。');
         if (isset($this->user['id'])) {
             $time = date('Y-m-d H:i:s', strtotime('-3 day'));
             $obj = $model->where('user_id = ' . $this->user['id'] . ' and goods_id=' . $goods_id . ' and register_time >' . "'{$time}'")->find();
             if ($obj) {
                 $info = array('status' => 'warning', 'msg' => '您已订阅过了该商品的到货通知。');
             } else {
                 $data = array('user_id' => $this->user['id'], 'goods_id' => $goods_id, 'register_time' => $register_time, 'email' => $email, 'mobile' => $mobile);
                 $last_id = $model->data($data)->insert();
                 if ($last_id > 0) {
                     $info = array('status' => 'success', 'msg' => '订阅成功。');
                 } else {
                     $info = array('status' => 'fail', 'msg' => '订阅失败。');
                 }
             }
         }
         echo JSON::encode($info);
     }
 }
Exemplo n.º 23
0
 public function change_wel_open()
 {
     $id = Req::args("id");
     $is_open = Req::args("is_open");
     $model = new Model("wel");
     $model->data(array('is_open' => $is_open))->where("id={$id}")->update();
     echo JSON::encode(array('status' => 'success'));
 }
Exemplo n.º 24
0
 public function customer_save()
 {
     $id = Req::args("id");
     $name = Req::args("name");
     $email = Req::args("email");
     $password = Req::args("password");
     $birthday = Req::post("birthday");
     $userModel = new Model("user");
     $customerModel = new Model("customer");
     if ($id) {
         $user = $userModel->where("id={$id}")->find();
         if ($user) {
             if ($name && $email) {
                 $userModel->data(array('name' => $name, 'email' => $email))->where("id={$id}")->update();
             }
             Req::args('user_id', $id);
             $customerModel->where("user_id={$id}")->update();
             Log::op($this->manager['id'], "修改会员", "管理员[" . $this->manager['name'] . "]:修改了会员 " . $user['name'] . " 的信息");
         }
     } else {
         $user = $userModel->where("name = '{$name}' or email = '{$email}'")->find();
         if ($user) {
             $this->msg = array("error", "用户名或邮箱已经存在!");
             $this->redirect("customer_edit", false);
             exit;
         } else {
             $validcode = CHash::random(8);
             $last_id = $userModel->data(array('name' => $name, 'password' => CHash::md5($password, $validcode), 'validcode' => $validcode, 'email' => $email))->add();
             Req::args('user_id', $last_id);
             if (!Validator::date(Req::post('birthday'))) {
                 Req::post('birthday', date('Y-m-d'));
             }
             $customerModel->insert();
             Log::op($this->manager['id'], "添加会员", "管理员[" . $this->manager['name'] . "]:添加了会员 " . $name . " 的信息");
         }
     }
     $this->redirect("customer_list");
 }
Exemplo n.º 25
0
 public function update()
 {
     if (!IS_POST) {
         $this->message2('无效请求!', __APP__ . '/Admin');
     }
     $id = I('id', NULL);
     if (empty($id)) {
         $this->message2('无效参数!', __APP__ . '/Admin');
     }
     $userdata = array();
     $userdata['id'] = $id;
     $userdata['isvalid'] = I('isvalid', 1);
     $userdata['user_qq'] = I('user_qq', '');
     $userdata['user_type'] = I('user_type', 1);
     $refer_id = I('refer_id', 0);
     $refer_user = M('user')->where('id=' . $refer_id)->find();
     if (empty($refer_user)) {
         $refer_id = 0;
     }
     $userdata['refer_id'] = $refer_id;
     $user_model = new Model('user');
     $result = $user_model->data($userdata)->save();
     if (false !== $result) {
         $this->message('操作成功', 'index');
     } else {
         $this->message('操作失败:' . $user_model->getError(), 'index');
     }
 }
Exemplo n.º 26
0
 public static function op($manager_id, $action, $content)
 {
     $logs = array('manager_id' => $manager_id, 'action' => $action, 'content' => $content, 'ip' => Chips::getIP(), 'url' => Url::requestUri(), 'time' => date('Y-m-d H:i:s'));
     $model = new Model('log_operation');
     $model->data($logs)->insert();
 }
Exemplo n.º 27
0
 public function rule_update()
 {
     if (!IS_POST) {
         $this->message2('无效请求', __APP__ . '/Admin');
     }
     $id = I('id', NULL);
     if (empty($id)) {
         $this->message2('未指定更新项!', 'rule_index');
     }
     $url = U('rule_edit', array('id' => $id));
     $title = I('title', '');
     if ($title == '') {
         $this->message2('规则名称不能为空!', $url);
     }
     if (empty($_POST['rule_col'])) {
         $this->message2('请增加单元表格!', $url);
     } else {
         $imp_field_file = 'Public/xhimp_fields.php';
         $filed_list = (include $imp_field_file);
         foreach ($filed_list as $key => $field) {
             $key_list[] = $key;
         }
         $rule_col = $_POST['rule_col'];
         foreach ($rule_col as $k => $v) {
             if (trim($v['name']) == '') {
                 $this->message2('增加的单元格表头名不能为空!', $url);
                 break;
             }
             $content = $v['content'];
             if (trim($content) == '') {
                 $this->message2('增加的单元格显示项目不能为空!', $url);
                 break;
             }
             $c_array = explode(',', $content);
             foreach ($c_array as $con) {
                 if (!in_array($con, $key_list)) {
                     $this->message2('显示项目中存在不合法的字段!', $url);
                     break;
                 }
             }
         }
         $rule_array = array();
         foreach ($rule_col as $rule) {
             $rule_array[] = $rule;
         }
         $data = array();
         $data['id'] = $id;
         $data['title'] = $title;
         $data['comm'] = $_POST['comm'];
         $data['separator'] = $_POST['separator'];
         $data['imp_rule'] = json_encode($rule_array);
         $model = new Model('imp_rule_xh');
         if (false !== $model->data($data)->save()) {
             $this->message2('规则修改成功!', 'rule_index');
         } else {
             $this->message2('规则修改失败:' . $model->getError(), $url);
         }
     }
 }
Exemplo n.º 28
0
 function photoshop_upload()
 {
     $file = $_FILES['upfile'];
     if ($file['error'] == 4) {
         $msg = array('error', '请选择文件后再上传!');
         $this->redirect("photoshop", true, array('msg' => $msg));
     } else {
         if ($file['error'] == 1) {
             $msg = array('error', '文件超出了php.ini文件指定大小!');
             $this->redirect("photoshop", true, array('msg' => $msg));
         } else {
             if ($file['size'] > 0) {
                 $key = md5_file($file['tmp_name']);
                 $gallery = new Model('gallery');
                 $img = $gallery->where("`key`='" . $key . "'")->find();
                 echo JS::import('dialog?skin=brief');
                 echo JS::import('dialogtools');
                 if (!$img) {
                     $upfile_path = Tiny::getPath("uploads");
                     $upfile_url = preg_replace("|^" . APP_URL . "|", '', Tiny::getPath("uploads_url"));
                     $upfile = new UploadFile('upfile', $upfile_path, '10m');
                     $upfile->save();
                     $info = $upfile->getInfo();
                     $result = array();
                     if ($info[0]['status'] == 1) {
                         $url = $upfile_url . $info[0]['path'];
                         $key = md5_file($upfile_path . $info[0]['path']);
                         $type = Req::args("type") == null ? 0 : intval(Req::args('type'));
                         $gallery->data(array('key' => $key, 'type' => $type, 'img' => $url))->save();
                         echo "<script>art.dialog.opener.setImg('{$url}');</script>";
                     } else {
                         $msg = array('error', $info[0]['msg']);
                         $this->msg = $msg;
                         $this->redirect("photoshop", false);
                     }
                 } else {
                     $url = $img['img'];
                     echo "<script>art.dialog.opener.setImg('{$url}');</script>";
                 }
             }
         }
     }
     exit;
 }