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 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 #3
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 #4
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 #5
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 #7
0
 /**
  * 数据修改控制器
  * @Title: updateControll
  * @Description: todo(数据修改控制器,用于处理关系型表单的数据修改)   
  * @author quqiang 
  * @date 2015年2月28日 下午9:11:26 
  * @throws
  */
 function updateControll()
 {
     //先获取老的数据。(因为套表中途可能重制了数据)
     $oldrequest = $_REQUEST;
     $originalPost = $_POST;
     //logs($originalPost , $this->getActionName().'_updateControll_'.date('Y-m-d-H' , time()) ,'',__CLASS__,__FUNCTION__,__METHOD__);
     // 新版套表提交
     if ($originalPost['__apply__form__'] && $originalPost['__actionlistend__'] == 'end') {
         /**
          *	@todo
          *	没有处理套表无提交情况
          */
         $isStartProcess = false;
         $model = new Model();
         $cacheFormData = $originalPost['__apply__form__'];
         //	遍历真实提交表单数据
         //logs(arr2string($cacheFormData) , 'settingtable');
         unset($_POST);
         $isret = true;
         $model->startTrans();
         try {
             foreach ($cacheFormData as $key => $val) {
                 $_POST = $val;
                 // 操作批次标识
                 $oprateTag = $_POST['__main__'];
                 // 非主表,去除相关功能属性字段值。 // nbmxkj @20150625
                 if ($_POST['__main__'] == $_POST['__selfaction__']) {
                     $_POST['__coverformoperateid__'] = 'main';
                 } else {
                     $_POST['__coverformoperateid__'] = 'children';
                 }
                 unset($tempAction);
                 unset($tempObj);
                 unset($selfAction);
                 unset($selfOprate);
                 $selfAction = $_POST['__selfaction__'];
                 $selfOprate = $_POST['__selfoprate__'];
                 $tempAction = $val['__selfaction__'];
                 $tempObj = A($tempAction);
                 C("TOKEN_ON", false);
                 $isret = "";
                 switch ($selfOprate) {
                     case 'add':
                         if (method_exists($tempObj, "_before_insert")) {
                             call_user_func(array(&$tempObj, "_before_insert"));
                         }
                         $isret = $tempObj->insert(1);
                         break;
                     case 'edit':
                         if ($_POST['__main__'] == $_POST['__selfaction__']) {
                             if (1 == $_POST['__startprocessStatus__']) {
                                 $isStartProcess = $isret = $tempObj->startprocess(true);
                             } elseif (2 == $_POST['__startprocessStatus__']) {
                                 $isStartProcess = $isret = $tempObj->lookupUpdateProcess(true);
                             } else {
                                 // 是主表
                                 if (method_exists($tempObj, "_before_update")) {
                                     call_user_func(array(&$tempObj, "_before_update"));
                                 }
                                 $isret = $tempObj->update(true);
                             }
                         } else {
                             // 是子表修改
                             if (method_exists($tempObj, "_before_update")) {
                                 call_user_func(array(&$tempObj, "_before_update"));
                             }
                             $isret = $tempObj->update(true);
                         }
                         // 是主表
                         // 							if (method_exists($tempObj,"_before_update")) {
                         // 								call_user_func(array(&$tempObj,"_before_update"));
                         // 							}
                         // 							$isret = $tempObj->update(true);
                         // 类型为审批
                         // 							if($_POST['__main__'] == $_POST['__selfaction__'] && 'audit' == $_POST['__selfactiontype__'] ){
                         // 								if(1==$_POST['__startprocessStatus__']){
                         // 									  $isStartProcess = $tempObj->startprocess(true);
                         // 								}elseif(2==$_POST['__startprocessStatus__']){
                         // 									$isStartProcess = $tempObj->lookupUpdateProcess(true);
                         // 								}else{
                         // 									// 未定义操作
                         // 								}
                         // 							}
                         break;
                     default:
                         break;
                 }
                 $retArr[$tempAction] = $isret;
                 C("TOKEN_ON", true);
                 //unset($_POST);
                 if (!$isret) {
                     break;
                 }
             }
             if (!$isret) {
                 $model->rollback();
                 $this->error("表单{$tempAction}进行数据操作时出现未知异常,已回滚!");
             } else {
                 // 拼接返回值
                 $bindid = 0;
                 if (getFieldBy($oprateTag, "bindaname", "inbindaname", "MisAutoBind", "typeid", 1)) {
                     $bindid = $retArr[$oprateTag];
                 } else {
                     $bindid = getFieldBy($retArr[$oprateTag], "id", "orderno", $oprateTag);
                 }
                 // 调用word版本控制生成函数
                 if ($retArr[$oprateTag]) {
                     $bool = getFieldBy($retArr[$oprateTag], "id", "operateid", $oprateTag);
                     if ($bool == 1) {
                         $zhuModel = A($oprateTag);
                         //终审后生成word版本
                         //先关闭版控生成
                         $saveList = $zhuModel->SaveVersionWord($retArr[$oprateTag], $oprateTag);
                     }
                 }
                 $_REQUEST = $oldrequest;
                 unset($oldrequest);
                 $this->success('批量单据保存成功', '', array('id' => $retArr[$oprateTag], 'bindid' => $bindid, 'isprocess' => $isStartProcess));
                 //	}
             }
         } catch (Exception $e) {
             $model->rollback();
             // getMessage()
             $this->error($e->__toString() . ',指操作处理错误,数据回滚!');
             Log::write($e->__toString());
         }
     }
 }
 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);
 }
 public function getOrderno($tableName = "", $modelName = '', $max = 0, $fieldval = null)
 {
     if (!empty($tableName)) {
         $oldorderno = "";
         $RulesInfo = array();
         //编号返回值
         $orderno = '';
         //初始化流水号,订单编号
         $ruleData = $this->GetRules($tableName, $modelName, $fieldval);
         if ($ruleData['status']) {
             //前缀一
             if ($ruleData['prefix1']) {
                 $orderno .= $this->typeCheck($ruleData['prefix1'], $ruleData['prefix1_value'], $ruleData['prefix1_long']);
             }
             //前缀二
             if ($ruleData['prefix2']) {
                 $orderno .= $this->typeCheck($ruleData['prefix2'], $ruleData['prefix2_value'], $ruleData['prefix2_long']);
             }
             //前缀三
             if ($ruleData['prefix3']) {
                 $orderno .= $this->typeCheck($ruleData['prefix3'], $ruleData['prefix3_value'], $ruleData['prefix3_long']);
             }
             //前缀四
             if ($ruleData['prefix4']) {
                 $orderno .= $this->typeCheck($ruleData['prefix4'], $ruleData['prefix4_value'], $ruleData['prefix4_long']);
             }
             $oldorderno = $orderno;
             //判断:如果前缀发生了变化。则将流水号重置
             if ($ruleData['oldrule'] != $orderno && $tableName != 'mis_auto_fuhhu') {
                 $ruleData['numshow'] = 0;
                 $ruleData['numnew'] = 1;
             }
             //流水号
             if ($ruleData['num']) {
                 //先确定当前编号
                 if (empty($ruleData['numshow'])) {
                     $ruleData['numshow'] = 0;
                 } else {
                     $max = $ruleData['numshow'] > $max ? $ruleData['numshow'] : $max;
                 }
                 //再判断
                 $max = $max + 1;
                 $max = $ruleData['numnew'] > $max ? $ruleData['numnew'] : $max;
                 //流水号
                 $orderno .= sprintf("%0" . $ruleData['num'] . "d", $max);
             }
             //后缀
             if ($ruleData['suffix']) {
                 $orderno .= $ruleData['suffix'];
             }
             //递归查询编码是否重复
             $map = array();
             $map['orderno'] = $orderno;
             $list = M($tableName)->where($map)->getField('id');
             if ($list) {
                 return $this->getOrderno($tableName, $modelName, $max, $fieldval);
             } else {
                 //更新表
                 $transeModel = new Model();
                 $transeModel->startTrans();
                 //数据是否存在,不存在新增,存在修改
                 if ($ruleData['notexist']) {
                     if ($fieldval) {
                         $model = M('mis_system_config_orderno_classify');
                         //新增
                         $cldata['masid'] = $result;
                         $cldata['fieldval'] = $fieldval;
                         $cldata['table'] = $tableName;
                         $cldata['modelname'] = $modelName;
                         $cldata['status'] = $ruleData['status'];
                         $cldata['num'] = $ruleData['num'];
                         $cldata['numnew'] = $max;
                         $cldata['oldrule'] = $oldorderno;
                         $result = $model->add($cldata);
                     } else {
                         //新增
                         $data['table'] = $tableName;
                         $data['modelname'] = $modelName;
                         $data['status'] = $ruleData['status'];
                         $data['num'] = $ruleData['num'];
                         $data['numnew'] = $max;
                         $cldata['oldrule'] = $oldorderno;
                         $result = $this->add($data);
                     }
                 } else {
                     if ($fieldval) {
                         $model = M('mis_system_config_orderno_classify');
                         //修改
                         $map = array();
                         $map['table'] = $tableName;
                         $map['modelname'] = $modelName;
                         $map['fieldval'] = $fieldval;
                         $data = array('numnew' => $max);
                         //判断:如果前缀发生了变化。则将流水号重置
                         if ($ruleData['oldrule'] != $oldorderno && $tableName != 'mis_auto_fuhhu') {
                             $data['numshow'] = 0;
                             $data['numnew'] = 1;
                             $data['oldrule'] = $oldorderno;
                         }
                         $result = $model->where($map)->setField($data);
                     } else {
                         //修改
                         $map = array();
                         $map['table'] = $tableName;
                         $map['modelname'] = $modelName;
                         $data['numnew'] = $max;
                         //判断:如果前缀发生了变化。则将流水号重置
                         if ($ruleData['oldrule'] != $oldorderno) {
                             $data['numshow'] = 0;
                             $data['numnew'] = 1;
                             $data['oldrule'] = $oldorderno;
                         }
                         $result = $this->where($map)->setField($data);
                     }
                 }
                 if ($result === false) {
                     $transeModel->rollback();
                 } else {
                     $this->startTrans();
                 }
                 //返回数据信息
                 $RulesInfo['orderno'] = $orderno;
                 $RulesInfo['writable'] = $ruleData['writable'] == 1 ? true : false;
                 $RulesInfo['status'] = $ruleData['status'];
             }
         } else {
             //编码不存在时,直接赋值为空
             $RulesInfo['orderno'] = '';
             $RulesInfo['writable'] = true;
             $RulesInfo['status'] = 0;
         }
         return $RulesInfo;
     }
 }
Example #10
0
 /**
  * 新增组件属性
  * @Title: ajaxeditporperty
  * @Description: todo(新增组件属性)
  *
  * @author quqiang
  *         @date 2015年5月13日 上午11:24:30
  * @throws
  *
  */
 function ajaxaddporperty()
 {
     $category = $_POST['category'];
     $transeModel = new Model();
     $transeModel->startTrans();
     try {
         // 修改
         if ($_POST[$this->controlsConfig[$category]['primary']['key']]) {
             $obj = D('MisSystemDesignProperty');
             $data = $this->parse('', true, true);
             $modifyData = $obj->create($data);
             if (false === $modifyData) {
                 $msg = $obj->getError();
                 throw new NullDataExcetion($msg);
             }
             $obj->save();
             $obj->commit();
             $controllHtml = $this->createSingleConttrol($modifyData);
             $this->_resoult['data']['data'] = array('html' => $controllHtml, $this->tagIndentity => $modifyData[$this->default['primary']['field']], 'category' => $category);
             echo json_encode($this->_resoult);
             // 				$this->success('好了' , '' , $this->_resoult ['data']);
         } else {
             $tag = $_POST[$this->tagIndentity];
             // 新增
             $data = $this->parse('', true, true);
             $obj = D('MisSystemDesignProperty');
             $addData = $obj->create($data);
             if (false === $addData) {
                 $msg = $obj->getError();
                 throw new NullDataExcetion($msg);
             }
             $addData['masid'] = $_POST['masid'];
             $addret = $obj->add($addData);
             if (false === $ret) {
                 $msg = ' 数据操作失败,' . $obj->getDBError() . ' ' . $obj->getLastSql();
                 throw new NullDataExcetion($msg);
             }
             $addData['id'] = $addret;
             $controllHtml = $this->createSingleConttrol($addData);
             $this->_resoult['data']['data'] = array('html' => $controllHtml, $this->tagIndentity => $tag, 'category' => $category);
             $obj->commit();
             $this->_resoult['message'] = '新增数据成功';
             echo json_encode($this->_resoult);
         }
     } catch (Exeption $e) {
         $transeModel->rollback();
         $this->_resoult['statusCode'] = 0;
         $this->_resoult['message'] = '<pre>' . $e->__toString() . '</pre>';
         echo json_encode($this->_resoult);
     }
 }