function addaccountdata()
 {
     #验证用户权限
     if (!$this->chk_delspau()) {
         //跳转到错误页面
         $this->assign('message', '您暂无此添加用户权限');
         $this->error();
     }
     $this->validatorfield($_POST);
     $account_model = M('account');
     //还应该检查用户添加的权限是不是该用户有  防止攻击
     //还需要验证事实不是已经有此用户名
     $chkdata = $account_model->where('loginname=' . $_POST['loginname'])->getfield('id');
     if (!empty($chkdata)) {
         //跳转到错误页面
         $this->assign('message', '用户用户名已存在');
         $this->error();
     }
     //post 传递过来的值解析为权限数组然后添加
     $array = array('up_bindtel', 'up_cardpwd', 'up_userexpirydate', 'man_cardstatus', 'up_cardmoney', 'chk_billrecord', 'count_data', 'transfer_card');
     $authoritydata = array();
     $authorityarr = $_POST['authority'];
     foreach ($array as $value) {
         if (in_array($value, $authorityarr)) {
             $authoritydata[$value] = 1;
         } else {
             $authoritydata[$value] = 0;
         }
     }
     //添加其他代理商的代理商id
     //$accountdata代理商数据
     $accountdata['loginname'] = trim($_POST['loginname']);
     $accountdata['loginpwd'] = trim($_POST['loginpwd']) . md5('timelesszhuang' . trim($_POST['loginname']));
     $accountdata['status'] = trim($_POST['status']);
     $accountdata['tele'] = trim($_POST['tele']);
     $accountdata['remark'] = trim($_POST['remark']);
     //由此确定
     $accountdata['power'] = $_SESSION['power'] + 1;
     $accountdata['ownid'] = $_SESSION['accountid'];
     //事务处理开始
     $tranDb = new Model();
     $tranDb->startTrans();
     $statusAc = $tranDb->table('cb_account')->add($accountdata);
     $accountid = $tranDb->table('cb_account')->where('loginname=' . $_POST['loginname'])->getfield('id');
     $authoritydata['accountid'] = $accountid;
     $statusAp = $tranDb->table('cb_power')->add($authoritydata);
     if ($statusAc && $statusAp) {
         $tranDb->commit();
         $operdetail = '用户' . $_SESSION['loginname'] . '添加代理商' . $accountdata['loginname'];
         $this->addlog($operdetail, '添加用户');
         $this->assign('message', '添加用户成功!');
         $this->success();
     } else {
         $tranDb->rollback();
         $operdetail = '用户' . $_SESSION['loginname'] . '添加代理商' . $accountdata['loginname'] . '失败';
         $this->addlog($operdetail, '添加用户');
         $this->assign('message', '添加用户失败!请重试');
         $this->success();
     }
 }
Example #2
0
 /**
  * 执行结束后执行的任务
  */
 public static function exeComplete()
 {
     if (Action::isRunComplete() && Action::isSuccess()) {
         //代码执行 && 业务成功
         Model::commit();
     } else {
         Model::rollBack();
         $lastError = \error_get_last();
         if ($lastError) {
             Error::errorHandler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line'], []);
             //短信、邮件通知负责人
         }
     }
 }
Example #3
0
 /**
  * ユーザの削除
  *
  * @param Model $model ビヘイビア呼び出し元モデル
  * @param array $data data
  * @return mixed On success Model::$data, false on failure
  * @throws InternalErrorException
  */
 public function deleteUser(Model $model, $data)
 {
     //トランザクションBegin
     $model->begin();
     $model->prepare();
     try {
         //Userデータの削除->論理削除
         $user = $model->create(array('id' => $data['User']['id'], 'handlename' => $data['User']['handlename'], 'is_deleted' => true));
         if (!$model->save($user, false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         //関連DBの削除
         $model->deleteUserAssociations($user['User']['id']);
         //トランザクションCommit
         $model->commit();
     } catch (Exception $ex) {
         //トランザクションRollback
         $model->rollback($ex);
     }
     return true;
 }
Example #4
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;
             }
         }
     }
 }
Example #5
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;
     }
 }
Example #6
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);
     }
 }
Example #7
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');
     }
 }
 public function addsell()
 {
     $isCard = $_POST['iscard'];
     unset($_POST['iscard']);
     //判断数据是否齐全
     if (empty($_POST)) {
         $this->error('没有提交任何东西');
         exit;
     }
     if ($isCard < 0) {
         $this->error('请选择支付方式');
         exit;
     }
     if ($_POST['sell_expense'] < 1) {
         $this->error('消费金额必须大于0元');
         exit;
     }
     $token = session("token");
     // 检查卡号
     $cardnum = $this->_post('card_num');
     $card = M('Member_card_create')->where(array('token' => $token, 'number' => $cardnum, 'status' => 1))->find();
     if (!$card) {
         $this->error('卡号不存在');
     }
     if (!$card['wecha_id']) {
         $this->error('该卡号未被领用,无法消费');
     }
     //获取商家设置 tp_member_card_exchange
     $getset = M('Member_card_exchange')->where(array('token' => $token))->find();
     $where = array('token' => $token, 'wecha_id' => $card['wecha_id'], 'status' => 1);
     $userinfo = M('Userinfo')->where($where)->find();
     if (!$getset || !$userinfo) {
         Log::record("商家:" . implode($getset, '|') . "会员:" . implode($userinfo, '|') . 'sql:' . M('userinfo')->getlastSql());
         $this->error('没有找到相关的会员信息!');
     }
     $amount = $_POST['sell_expense'];
     $scorebeadd = intval($amount) * $getset['reward'];
     $da['total_score'] = $userinfo['total_score'] + $scorebeadd;
     $da['expend_score'] = $userinfo['expend_score'] + $scorebeadd;
     if ($isCard) {
         if ($amount > $userinfo['total_money']) {
             $this->error("会员卡余额不足!");
             exit;
         } else {
             $da['total_money'] = $userinfo['total_money'] - $amount;
             $da['spend_money'] = $userinfo['spend_money'] + $amount;
         }
     }
     $model = new Model();
     //事务处理开始
     $model->startTrans();
     //在总额上操作
     $isSuccess = $model->autoCheckToken($_POST);
     //验证表单令牌,防止重复提交
     if ($isSuccess) {
         unset($_POST[C('TOKEN_NAME')]);
         //除去post数组中的令牌数据,防止table方法提交失败
         $isSuccess = $model->table('tp_userinfo')->where($where)->save($da);
     }
     $data['token'] = $token;
     $data['wecha_id'] = $card['wecha_id'];
     //若上一步成功则写入积分记录表
     if ($isSuccess) {
         $scoredata = array('sign_time' => time(), 'is_sign' => false, 'score_type' => 2, 'expense' => $scorebeadd, 'delete' => 0);
         $scoredata = array_merge($data, $scoredata, $_POST);
         unset($scoredata['card_num']);
         $isSuccess = $model->table('tp_member_card_sign')->add($scoredata);
     }
     //若上一步成功且是会员卡余额消费则写入充值记录表
     if ($isSuccess && $isCard) {
         $moneydata = array('card_num' => $cardnum, 'amount' => $amount, 'comment' => $_POST['remark'], 'type' => 1, 'logon_ip' => getenv('REMOTE_ADDR'), 'logon_user_id' => session('uid'), 'oprator' => session('uname'));
         $moneydata = array_merge($data, $moneydata);
         $isSuccess = $model->table('tp_member_charge')->add($moneydata);
     }
     if ($isSuccess) {
         $model->commit();
         //成功则事务结束
         $this->success('操作成功');
     } else {
         $model->rollback();
         //失败则rollback
         $this->error('服务器繁忙,请稍候再试');
     }
 }
Example #9
0
$url_pattern = 'http://localhost/bmtmgr/import/clubs/blv_club_kontakte.php%%3fid=%d';
$imported_clubs = [];
$not_found_since = 0;
Model::beginTransaction();
for ($i = 1; $i < 100000; $i++) {
    $url = \sprintf($url_pattern, $i);
    $page = \file_get_contents($url);
    $r = \preg_match('/
		<label>ClubID:<\\/label><div>(?P<id>[0-9-]+)<\\/div>.*
		<label>Vereinsname:<\\/label><div>(?P<name>[^<]+)<\\/div>.*
		<label>Email:<\\/label><div><a.*?>(?P<email>[^<]+)<\\/a>
		/xs', $page, $m);
    if (!$r) {
        $not_found_since++;
        if ($not_found_since > 100) {
            break;
        }
        continue;
    }
    $id = \html_entity_decode($m['id'], ENT_QUOTES | ENT_HTML5, 'utf-8');
    $name = \html_entity_decode($m['name'], ENT_QUOTES | ENT_HTML5, 'utf-8');
    $email = \html_entity_decode($m['email'], ENT_QUOTES | ENT_HTML5, 'utf-8');
    $c = User::by_id_optional($id);
    if (!$c) {
        $c = new User($id, $name, $email, ['register']);
        $c->save();
        \array_push($imported_clubs, $c);
    }
}
Model::commit();
render_ajax('club/', ['imported_clubs' => $imported_clubs]);
Example #10
0
 /**
  * setSettingToDatasource
  *
  * @param $key, $value = null
  */
 public function setSettingToDatasource(Model $model, $key, $value = null)
 {
     $data = $key;
     if (is_string($key)) {
         $data = array($key => $value);
     }
     $settings = Configure::read('Setting.settings');
     foreach ($data as $k => $v) {
         if (!in_array($k, array_keys($settings))) {
             return false;
         }
         $model->validate[$k] = $settings[$k];
     }
     $model->set($data);
     if (!$model->validates()) {
         return false;
     }
     $model->begin();
     foreach ($data as $k => $v) {
         if (is_array($v) || is_object($v)) {
             $model->rollback();
             return false;
         }
         if (in_array($k, array_keys($settings))) {
             $d = $model->find('first', array('conditions' => array("{$model->alias}.key" => $k)));
             if (empty($d)) {
                 $d = array($model->alias => array('key' => $k, 'value' => $v));
             } else {
                 $d[$model->alias]['value'] = $v;
                 unset($d[$model->alias]['modified']);
             }
             $model->create();
             $model->set($d);
             if (!$model->save($d, false)) {
                 $model->rollback();
                 return false;
             }
         }
     }
     $model->commit();
     return true;
 }
 function clear()
 {
     set_time_limit(0);
     $basepath = ROOT . '/Dynamicconf/truncate';
     $clearLogPath = 'clear_dynamic_' . date('Y-m-d', time());
     // 单个文件
     $file = file_get_contents($basepath . '/file.log');
     // 文件夹
     $folder = file_get_contents($basepath . '/folder.log');
     // 数据表格
     $datatable = file_get_contents($basepath . '/dt.log');
     // 动态建模生成表
     $table = file_get_contents($basepath . '/table.log');
     if ($file) {
         // 开始删除文件
         foreach (explode(',', $file) as $k => $v) {
             $ret = unlink($v);
             $ret = $ret === false ? '失败' : '成功';
             logs('文件删除 :' . $v . $ret, $clearLogPath, '', __CLASS__, __FUNCTION__, __METHOD__);
             // 				sleep(1);
             // 百万分之一秒
             //usleep(10000);
         }
     }
     if ($folder) {
         // 开始删除文件夹
         foreach (explode(',', $folder) as $k => $v) {
             $ret = deldir($v);
             $ret = $ret === false ? '失败' : '成功';
             logs('删除文件夹 :' . $v . $ret, $clearLogPath, '', __CLASS__, __FUNCTION__, __METHOD__);
         }
     }
     $model = new Model();
     $model->startTrans();
     if ($datatable) {
         // 删除数据表格
         $dropSql = "DROP TABLE {$datatable}";
         $ret = $model->query($dropSql);
         logs('删除表状态 :' . $ret === false ? '失败' : '成功', $clearLogPath, '', __CLASS__, __FUNCTION__, __METHOD__);
         logs('删除表 :' . $model->getLastSql(), $clearLogPath, '', __CLASS__, __FUNCTION__, __METHOD__);
     }
     if ($table) {
         // 动态建模生成表
         // 删除数据表格
         $dropSql = "DROP TABLE {$table}";
         $ret = $model->query($dropSql);
         logs('删除表状态 :' . $ret === false ? '失败' : '成功', $clearLogPath, '', __CLASS__, __FUNCTION__, __METHOD__);
         logs('删除表 :' . $model->getLastSql(), $clearLogPath, '', __CLASS__, __FUNCTION__, __METHOD__);
     }
     // 清空动态建模核心表
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_calculate`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_controll_record`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_database_mas`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_database_sub`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_form_datatable`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_form_datatable_oprate`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_form_field`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_form_indatatable`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_form_manage`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_form_propery`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_form_record`";
     $truncateCoreTable[] = "TRUNCATE TABLE `mis_dynamic_form_template`";
     foreach ($truncateCoreTable as $k => $v) {
         $model->execute($v);
         logs('删除表 :' . $model->getLastSql(), $clearLogPath, '', __CLASS__, __FUNCTION__, __METHOD__);
     }
     $model->commit();
     deldir($basepath);
 }
Example #12
0
 /**
  * 重新排序后更新现有数据
  * @Title: changeSort
  * @Description: todo(这里用一句话描述这个方法的作用)   
  * @author quqiang 
  * @date 2015年5月13日 下午6:22:30 
  * @throws
  */
 function changeSort()
 {
     $sortArr = $_POST['data'];
     if ($sortArr) {
         $obj = new Model();
         $tablename = D('MisSystemDesignProperty')->getTableName();
         if ($tablename) {
             $sql = "INSERT INTO `{$tablename}` (id,sort) VALUES  {$sortArr} ON DUPLICATE KEY UPDATE sort=VALUES(sort);";
             $ret = $obj->execute($sql);
             $obj->commit();
             echo $ret;
         }
     }
 }
Example #13
0
 /**
  * ユーザの登録処理
  *
  * @param Model $model ビヘイビア呼び出し元モデル
  * @param int $userId ユーザID
  * @return mixed On success Model::$data, false on failure
  * @throws InternalErrorException
  */
 public function updateLoginTime(Model $model, $userId)
 {
     //トランザクションBegin
     $model->begin();
     try {
         $update = array('User.previous_login' => 'User.last_login', 'User.last_login' => '\'' . date('Y-m-d H:i:s') . '\'');
         $conditions = array('User.id' => (int) $userId);
         if (!$model->updateAll($update, $conditions)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         $model->commit();
     } catch (Exception $ex) {
         $model->rollback($ex);
     }
     return true;
 }