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 index()
 {
     //分类信息
     $model = new Model();
     $user_temp = $model->table('weixin_user_templet m,weixin_templet c')->where("m.templet_index=c.templet_name and m.token = '" . session('token') . "'")->field('c.* ')->order('c.id')->select();
     $templet_list = $model->table('weixin_user_templet m,weixin_templet c')->where("m.templet_index!=c.templet_name and m.token = '" . session('token') . "'")->field('c.* ')->order('c.id')->select();
     $this->assign('user_temp', $user_temp);
     $this->assign('token', session('token'));
     $this->assign('templet_list', $templet_list);
     $this->display();
 }
Example #3
0
 public function get_user_price_list($user_id)
 {
     $model = new Model();
     $condition['user_id'] = $user_id;
     $list = $model->table('ldh_price_user')->field('ldh_price.code,ldh_price.password,ldh_price_user.price_id')->join('ldh_price ON ldh_price_user.price_id = ldh_price.price_id')->where($condition)->select();
     return $list;
 }
Example #4
0
 public function log()
 {
     $model = new Model();
     $res = $model->table('eye_order a,eye_product b,eye_user c,eye_log d')->where(array("d.userId = c.id", "a.productId = b.id", "a.id = d.orderId"))->order('a.time desc')->field("a.speci,b.name as pName,c.phone,c.name as uName,d.*")->select();
     $this->assign('res', $res);
     $this->display();
 }
Example #5
0
 public function dtl()
 {
     //获取楼盘设定
     $set_info = M('jingcai_set')->where(array('token' => $this->token))->find();
     if (!$set_info || !$set_info['status']) {
         die('商家还未开启微竞猜服务');
     }
     $id = $this->_get('id');
     $changci_db = new Model();
     $where = " a.token='" . $this->token . "' and a.id=" . $id . " and  a.zhudui=b.id and a.kedui=c.id ";
     $info = $changci_db->table(C('DB_PREFIX') . "jingcai_changci a left outer join " . C('DB_PREFIX') . "jingcai_changci_record r on(a.id=r.changci_id and r.token='" . $this->token . "' and r.wecha_id='" . $this->wecha_id . "')," . C('DB_PREFIX') . "jingcai_team b," . C('DB_PREFIX') . "jingcai_team c")->field('a.*,b.name zhuduiname,b.team_logo zhuduilogo,c.name keduiname,c.team_logo keduilogo,r.ycjg')->where($where)->find();
     if (!$info) {
         die('非法数据');
     }
     $week_num = date('w', $info['stime']);
     if ($week_num === 0) {
         $info['week'] = '周日';
     } else {
         if ($week_num === 1) {
             $info['week'] = '周一';
         } else {
             if ($week_num === 2) {
                 $info['week'] = '周二';
             } else {
                 if ($week_num === 3) {
                     $info['week'] = '周三';
                 } else {
                     if ($week_num === 4) {
                         $info['week'] = '周四';
                     } else {
                         if ($week_num === 5) {
                             $info['week'] = '周五';
                         } else {
                             if ($week_num === 6) {
                                 $info['week'] = '周六';
                             }
                         }
                     }
                 }
             }
         }
     }
     /**
      * 计算主队最近战绩
      * 0,
      */
     $info_hz = M('jingcai_changci')->field('count(id) total,sum(case when zhuduinum>keduinum then 1 else 0 end) sl,sum(case when zhuduinum=keduinum then 1 else 0 end) pj,sum(case when zhuduinum<keduinum then 1 else 0 end) sb')->where(array('token' => $this->token, 'zhudui' => $info['zhudui'], 'status' => 1))->find();
     //var_dump($info_hz);
     $info['zhuduitotal'] = $info_hz['total'];
     $info['zhuduislnum'] = $info_hz['sl'];
     $info['zhuduipjnum'] = $info_hz['pj'];
     $info['zhuduisbnum'] = $info_hz['sb'];
     $info['zhuduiper'] = number_format($info_hz['sl'] / $info_hz['total'], 4) * 100;
     $info['keduiper'] = number_format($info_hz['sb'] / $info_hz['total'], 4) * 100;
     $info['pingper'] = number_format($info_hz['pj'] / $info_hz['total'], 4) * 100;
     $this->assign('end', '1');
     $this->assign('info', $info);
     $this->display();
 }
Example #6
0
 public static function balance($amount, $user_id, $note = '', $type = 0, $admin_id = 0)
 {
     //事件类型: 0:订单支付 1:用户充值 2:管理员充值 3:提现
     $model = new Model('customer');
     $customer = $model->fields("balance")->where("user_id=" . $user_id)->find();
     if ($customer) {
         $log = array('amount' => $amount, 'user_id' => $user_id, 'time' => date('Y-m-d H:i:s'), 'amount_log' => $customer['balance'], 'admin_id' => $admin_id, 'type' => $type, 'note' => $note);
         $model->table("balance_log")->data($log)->insert();
     }
 }
Example #7
0
 /**
  * Validate unique fields, object field groups
  * Returns errors array or returns false, is used for ExtJS forms
  * @property boolean $new
  * @return mixed false / array
  */
 public function validateUniqueValues()
 {
     $uniqGroups = array();
     foreach ($this->_config->get('fields') as $k => $v) {
         if ($k === $this->_primaryKey) {
             continue;
         }
         if (!$this->_config->isUnique($k)) {
             continue;
         }
         $value = $this->get($k);
         if (is_array($value)) {
             $value = serialize($value);
         }
         if (is_array($v['unique'])) {
             foreach ($v['unique'] as $val) {
                 if (!isset($uniqGroups[$val])) {
                     $uniqGroups[$val] = array();
                 }
                 $uniqGroups[$val][$k] = $value;
             }
         } else {
             $v['unique'] = strval($v['unique']);
             if (!isset($uniqGroups[$v['unique']])) {
                 $uniqGroups[$v['unique']] = array();
             }
             $uniqGroups[$v['unique']][$k] = $value;
         }
     }
     if (empty($uniqGroups)) {
         return false;
     }
     $db = $this->_model->getDbConnection();
     foreach ($uniqGroups as $group) {
         $sql = $db->select()->from($this->_model->table(), array('count' => 'COUNT(*)'));
         if ($this->getId()) {
             $sql->where(' ' . $db->quoteIdentifier($this->_primaryKey) . ' != ?', $this->getId());
         }
         foreach ($group as $k => $v) {
             if ($k === $this->_primaryKey) {
                 continue;
             }
             $sql->where($db->quoteIdentifier($k) . ' =?', $v);
         }
         $count = $db->fetchOne($sql);
         if ($count > 0) {
             foreach ($group as $k => &$v) {
                 $v = Lang::lang()->get('SB_UNIQUE');
             }
             unset($v);
             return $group;
         }
     }
     return false;
 }
Example #8
0
 /**
  * Connect to the DB
  *
  * This method should be called at the beginning of any function that needs to communicate with the database
  */
 protected static function dbConnect()
 {
     if (!self::$dbc) {
         // Connect to database
         $dbc = new PDO('mysql:host=127.0.0.1;dbname=users_db', 'admin_user', 'x');
         self::$dbc = $dbc;
         self::$table = 'users';
         // Throw exception on PDO error
         self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     }
 }
Example #9
0
 public function receve()
 {
     $po_no = $_REQUEST['po_no'];
     $model = D("Gi");
     $sql = $model->get_wait_sql();
     $model = new Model();
     $where['po_no'] = array('eq', $po_no);
     $list = $model->table("({$sql}) t1")->where($where)->order('supplier,po_no,mat_no')->select();
     $this->assign('list', $list);
     $this->display();
 }
Example #10
0
 public function add()
 {
     $model = new Model();
     $res = $model->table('k_user a,k_order b')->where(array('b.userId = a.Id'))->field('b.*,a.img')->order('b.time desc')->select();
     foreach ($res as $k => $v) {
         $a = explode(',', $v['img']);
         $res[$k]['img1'] = $a[0];
         $res[$k]['img2'] = $a[1];
     }
     $this->assign('res', $res);
     $this->display();
 }
Example #11
0
 public function add_cart()
 {
     import('Think.ORG.Cart');
     // 导入分页类
     $cart = new Cart();
     $goodId = $this->_post('goodId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $spec_id = $this->_post('spec_id', 'intval');
     $goodprice = $this->_post('price');
     //购买数量
     //$goodprice=1.11;
     $goods_stock = 0;
     $spec_1 = '';
     $spec_2 = '';
     $price = 0;
     $item = M('item')->field('id,title,img,price,goods_stock')->find($goodId);
     $item = M('item')->field('id,title,img,price,goods_stock')->find($goodId);
     $model = new Model();
     $members = $model->table('weixin_user a,weixin_member_setting b')->where('a.score_level=b.id and a.id=' . $this->visitor->info['id'])->field('LEFT(b.discount/100 ,4) as discount')->find();
     if (!$members) {
         $members['discount'] = 1;
     }
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     }
     if ($spec_id == 0) {
         $goods_stock = $item['goods_stock'];
         //$price=floor($item['price']*$members['discount']);
         $price = $goodprice;
     } else {
         $item_spec = M('item_spec')->field('spec_1,spec_2,price,stock')->find($spec_id);
         $goods_stock = $item_spec['stock'];
         //$price=floor($item_spec['price']*$members['discount']);
         $price = $goodprice;
         $spec_1 = $item_spec['spec_1'];
         $spec_2 = $item_spec['spec_2'];
     }
     if ($goods_stock < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $result = $cart->addItem($item['id'], $item['title'], $price, $quantity, $item['img'], $spec_id, $spec_1, $spec_2, $goods_stock);
         if ($result == 1) {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '该商品已经存在购物车');
         } else {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '商品已成功添加到购物车');
         }
     }
     //$data=array('status'=>2);
     echo json_encode($data);
 }
Example #12
0
 /**
  * ---
  */
 public function __construct($id = null)
 {
     $this->db = Db::getInstance();
     $this->table = Model::table(get_class($this));
     $this->init();
     if ($id) {
         if (!$this->identifier) {
             throw new Exception('Identifier not found.');
         }
         $this->get($id);
     } else {
         $this->hash = Model::hash($this->properties);
     }
 }
Example #13
0
 /**
  * 标签分类瀑布
  */
 public function get_items_ajax()
 {
     $page = intval($this->_get('page', 'trim'));
     //标签
     $cate_id = $this->_get('cateid', 'intval');
     if ($page > 0) {
         $page = $page * 4;
     }
     $good_mod = new Model();
     $goods = $good_mod->table('weixin_item a')->join('weixin_item_spec b ON a.id = b.item_id')->field('a.id,a.token,a.img,a.title,a.dis_flag,IF (a.price = \'0\',min(b.price),a.price) AS price,IF (a.markprice = \'0\',min(b.markprice),a.markprice) AS markprice,IF(a.tuijian=\'1\',\'热销\',\'0\') as rexiao,IF(a.news=\'1\',\'新品\',\'0\') as xinping,if (a.price = \'0\',LEFT(min(b.price)*10/min(b.markprice),3),LEFT(a.price*10/a.markprice,3) )as sale')->where("cate_id in (select id  from weixin_item_cate where id='" . $cate_id . "'  or pid ='" . $cate_id . "')  and a.status = '1' and a.token ='" . session('user_token') . "'")->group('a.id')->order('a.ordid asc')->limit($page . ',4')->select();
     if ($goods) {
         $this->ajaxReturn(0, L('invalid_item'), $goods);
     } else {
         $this->ajaxReturn(1, L('invalid_item'), $goods);
     }
 }
Example #14
0
 public static function find($id1 = 1, $id2 = null, $id3 = null)
 {
     self::$table = static::$reference;
     //echo self::$table;
     //self::keys();
     //print_r(self::$keys);
     //self::$keys=array();
     $o = new self(self::$table);
     //print_r(get_object_vars($o));
     //echo "<br>";
     //print_r(self::$keys);
     //
     $ids = array($id1, $id2, $id3);
     //
     $sql = null;
     $sql = "select * from " . self::$table . " ";
     if (count(self::$keys) < 3) {
         $i = 0;
         foreach (self::$keys as $value) {
             if ($i > 0) {
                 $sql .= " and ";
             }
             if ($i == 0) {
                 $sql .= " where ";
             }
             $sql .= " " . self::$keys[$i] . "='" . $ids[$i] . "' ";
             $i++;
         }
     }
     $r = Database::read($sql);
     //
     $nums = array();
     for ($i = 0; $i < 201; $i++) {
         $nums[] = $i;
     }
     $i = 0;
     foreach ($r[0] as $key => $value) {
         if ($i % 2 != 0) {
             $o->{$key} = $value;
         }
         $i++;
     }
     //print_r(get_object_vars($o));
     //echo "<br><br>";
     return $o;
 }
Example #15
0
 /**
  * GET 服务列表
  */
 public function servicesOp()
 {
     $model_service = Model('serviceapi');
     $model_upload = Model('upload');
     $model = new Model();
     //        //  排序
     $condition = array();
     $condition['service.gc_id'] = intval($_GET['cate_id']);
     $condition['service.service_show'] = 1;
     $service_list = $model->table('service,company')->join('right join')->on('service.depart_id=company.company_id')->where($condition)->page($this->page)->order('service_sort desc')->select();
     //        $service_list = $model_service->geServiceList($condition, '*', 'service_sort asc', $this->page);
     foreach ($service_list as $key => $val) {
         $imgs = $model_upload->getUploadList(array('item_id' => $val['service_id']));
         $service_list[$key]['service_image'] = $imgs[0]['file_name'];
     }
     $pageCount = $model_service->gettotalpage();
     output_data(array('services' => $service_list), mobile_page($pageCount));
 }
 public function edit()
 {
     $id = $this->_get('id', 'intval');
     //$account_master = $this->_mod_bill_mst->where(array('id'=>$id))->find();
     $modelmst = new Model();
     /*
     $account_master = $modelmst->table("tp_account_bill_mst m, tp_account_setting c")
     ->where("m.tokenTall=c.tokenTall and m.id='".$id."'")
     ->field("m.*, c.bankname, c.account, c.payee, c.mobile")
     ->find();
     */
     $account_master = $modelmst->table('tp_account_bill_mst m')->join('tp_account_setting c on m.tokenTall=c.tokenTall')->where("m.id='" . $id . "'")->field('m.*, c.bankname, c.account, c.payee, c.mobile')->find();
     $model = new Model();
     $account_detail = $model->table("tp_account_bill_dtl m, tp_item_order c")->where("m.orderId=c.orderId and m.billnum='" . $account_master['billnum'] . "'")->field("m.*, c.add_time, c.status")->select();
     //$account_detail = $this->_mod_bill_dtl->where('billnum='.$account_master['billnum'])->select();
     $this->assign('account_detail', $account_detail);
     $this->assign('account_master', $account_master);
     $this->display();
 }
Example #17
0
 /**
  * Change Db table engine
  *
  * @param string $table
  *          - table name without prefix
  * @param string $engine
  *          - new engine name
  * @param boolean $returnQuery
  *          - optional, return update query
  * @return boolean | string
  * @throws Exception
  */
 public function changeTableEngine($engine, $returnQuery = false)
 {
     if ($this->_objectConfig->isLocked() || $this->_objectConfig->isReadOnly()) {
         $this->_errors[] = 'Can not build locked object ' . $this->_objectConfig->getName();
         return false;
     }
     $sql = 'ALTER TABLE `' . $this->_model->table() . '` ENGINE = ' . $engine;
     if ($returnQuery) {
         return $sql;
     }
     try {
         $this->_db->query($sql);
         $this->_logSql($sql);
         return true;
     } catch (Exception $e) {
         $this->_errors[] = $e->getMessage() . ' <br>SQL: ' . $sql;
         return false;
     }
 }
Example #18
0
 public function index()
 {
     $map = $this->_search("PoView", true);
     if (method_exists($this, '_filter')) {
         $this->_filter($map);
     }
     if (empty($_POST['start_date']) & empty($_POST['end_date'])) {
         $start_date = toDate(mktime(0, 0, 0, date("m"), 1, date("Y")), 'Y-m-d');
         $end_date = toDate(mktime(0, 0, 0, date("m") + 1, 0, date("Y")), 'Y-m-d');
         $map['po_date'] = array(array('egt', $start_date), array('elt', $end_date));
     } else {
         $start_date = $_POST['start_date'];
         $end_date = $_POST['end_date'];
     }
     $this->assign('start_date', $start_date);
     $this->assign('end_date', $end_date);
     $sql = D("PoView")->buildSql();
     $model = new Model();
     $list = $model->table($sql . "a")->where($map)->order('supplier,po_no')->select();
     $this->assign("list", $list);
     $this->display();
     return;
 }
Example #19
0
 /**
  * GET 消息中心的回答列表
  */
 public function answersOp()
 {
     $themeIds = $this->getMyThemeIds();
     $model = new Model();
     $types = array(5, 6);
     $m_reply = $model->table('circle_threply');
     $where['circle_threply.theme_id'] = array('in', $themeIds);
     $where['circle_theme.thclass_id'] = array('in', $types);
     $fields = "circle_threply.reply_content,circle_threply.reply_addtime,circle_threply.member_name,circle_threply.member_id,\n        circle_threply.circle_id,circle_threply.reply_id,circle_threply.theme_id,circle_theme.theme_name";
     $replies = $model->table('circle_threply,circle_theme')->join('right join')->on('circle_threply.theme_id=circle_theme.theme_id')->where($where)->field($fields)->page($this->page)->order('reply_addtime desc')->select();
     $pageCount = $m_reply->gettotalpage();
     if (!empty($replies)) {
         foreach ($replies as $key => $val) {
             $replies[$key]['member_avatar'] = getMemberAvatarForID($replies[$key]['member_id']);
         }
     }
     output_data(array('receiveAnswers' => $replies), mobile_page($pageCount));
 }
Example #20
0
 /**
  * Eagerly load a many-to-many relationship.
  *
  * @param  object  $relationship
  * @param  array   $parents
  * @param  string  $relating_key
  * @param  string  $relating_table
  * @param  string  $include
  *
  * @return void	
  */
 private static function has_and_belongs_to_many($relationship, &$parents, $relating_key, $relating_table, $include)
 {
     // The model "has and belongs to many" method sets the SELECT clause; however, we need
     // to clear it here since we will be adding the foreign key to the select.
     $relationship->query->select = null;
     $relationship->query->where_in($relating_table . '.' . $relating_key, array_keys($parents));
     // The foreign key is added to the select to allow us to easily match the models back to their parents.
     // Otherwise, there would be no apparent connection between the models to allow us to match them.
     $children = $relationship->query->get(array(Model::table(get_class($relationship)) . '.*', $relating_table . '.' . $relating_key));
     $class = get_class($relationship);
     foreach ($children as $child) {
         $related = new $class();
         $related->attributes = (array) $child;
         $related->exists = true;
         // Remove the foreign key since it was only added to the query to help match the models.
         unset($related->attributes[$relating_key]);
         $parents[$child->{$relating_key}]->ignore[$include][$child->id] = $related;
     }
 }
Example #21
0
 function read()
 {
     $type = $_REQUEST['type'];
     $id = $_REQUEST['id'];
     switch ($type) {
         case "company":
             $model = M("Dept");
             $dept = tree_to_list(list_to_tree(M("Dept")->where('is_del=0')->select(), $id));
             $dept = rotate($dept);
             $dept = implode(",", $dept['id']) . ",{$id}";
         case "emp":
             $model = M("Dept");
             $dept = tree_to_list(list_to_tree(M("Dept")->where('is_del=0')->select(), $id));
             $dept = rotate($dept);
             $dept = implode(",", $dept['id']) . ",{$id}";
             $sql = D("UserView")->buildSql();
             $model = new Model();
             $where['dept_id'] = array('in', $dept);
             $where['is_del'] = array('eq', 0);
             $data = $model->table($sql . "a")->where($where)->select();
             break;
         case "rank":
             $sql = D("UserView")->buildSql();
             $model = new Model();
             $where['rank_id'] = array('eq', $id);
             $where['is_del'] = array('eq', 0);
             $data = $model->table($sql . "a")->where($where)->select();
             break;
         case "position":
             $sql = D("UserView")->buildSql();
             $model = new Model();
             $where['position_id'] = array('eq', $id);
             $where['is_del'] = array('eq', 0);
             $data = $model->table($sql . "a")->where($where)->select();
             break;
         case "personal":
             $model = D("UserTag");
             if ($id == "#") {
                 $data = $model->get_data_list("Contact");
                 $data = rotate($data);
                 $data = $data['row_id'];
                 $where['id'] = array('not in', implode(",", $data));
             } else {
                 $test = $model;
                 $data = $model->get_data_list("Contact", $id);
                 $data = rotate($data);
                 $data = $data['row_id'];
                 $where['id'] = array('in', implode(",", $data));
             }
             $model = M("Contact");
             $where['is_del'] = array('eq', 0);
             $data = $model->where($where)->field('id,name,position as position_name,email')->select();
             //echo $model->getLastSql();
             break;
         default:
     }
     $new = array();
     if (true) {
         // 读取成功
         $this->ajaxReturn($data, dump($test, false), 1);
     }
 }
Example #22
0
 /**
  * 浏览数据表的数据 支持分页
  * @access public
  * @return void
  */
 public function selectTable()
 {
     $table = Session('useDb') . '.' . $_GET['table'];
     $where = array();
     if ($_REQUEST['map']) {
         $where['_string'] = base64_decode($_REQUEST['map']);
     }
     //$this->db->execute('USE '.Session('useDb'));
     $fields = $this->db->getFields($table);
     $field = array_keys($fields);
     $field = $field[0];
     $Model = new Model();
     $count = $Model->table($table)->where($where)->count('*');
     if ($_GET['bench']) {
         $this->db->execute('SET PROFILING=1;');
     }
     import("ORG.Util.Page");
     //创建分页对象
     if (!empty($_REQUEST['listRows'])) {
         $listRows = $_REQUEST['listRows'];
     } else {
         $listRows = '';
     }
     //排序字段 默认为主键名
     if (isset($_REQUEST['_order'])) {
         $order = $_REQUEST['_order'];
     } else {
         $order = !empty($sortBy) ? $sortBy : $field;
     }
     //排序方式默认按照倒序排列
     //接受 sost参数 0 表示倒序 非0都 表示正序
     if (isset($_REQUEST['_sort'])) {
         $sort = $_REQUEST['_sort'] ? 'asc' : 'desc';
     } else {
         $sort = $asc ? 'asc' : 'desc';
     }
     $p = new Page($count, $listRows);
     //分页查询数据
     $voList = $Model->table($table)->where($where)->field(!empty($_REQUEST['field']) ? $_REQUEST['field'] : '')->order($order . ' ' . $sort)->limit($p->firstRow . ',' . $p->listRows)->select();
     $fields = array_keys($voList[0]);
     $this->assign('fieldCount', count($fields) + 2);
     $list[] = $fields;
     if ($_GET['bench']) {
         $data = $this->db->query('SHOW PROFILE');
         $fields = array_keys($data[0]);
         $a[] = $fields;
         foreach ($data as $key => $val) {
             $val = array_values($val);
             $a[] = $val;
         }
         $this->assign('bench', $a);
     }
     //分页显示
     $page = $p->show();
     //列表排序显示
     $sortImg = $sort;
     //排序图标
     $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列';
     //排序提示
     $sort = $sort == 'desc' ? 1 : 0;
     //排序方式
     //模板赋值显示
     $this->assign('list', array_merge($list, $voList));
     $this->assign('sort', $sort);
     $this->assign('order', $order);
     $this->assign('sortImg', $sortImg);
     $this->assign('sortType', $sortAlt);
     $this->assign("page", $page);
     $this->display('table');
 }
Example #23
0
 public function order_act()
 {
     if ($this->checkOnline()) {
         $ship_id = Filter::int(Req::args('ship_id'));
         // 发货库房位置 ID
         $address_id = Filter::int(Req::args('address_id'));
         // 地址
         $payment_id = Filter::int(Req::args('payment_id'));
         // 支付ID
         $prom_id = Filter::int(Req::args('prom_id'));
         // 去掉
         $is_invoice = Filter::int(Req::args('is_invoice'));
         //
         $invoice_type = Filter::int(Req::args('invoice_type'));
         //
         $invoice_title = Filter::text(Req::args('invoice_title'));
         //
         $user_remark = Filter::txt(Req::args('user_remark'));
         $voucher_id = Filter::int(Req::args('voucher'));
         //非普通促销信息
         // $type = Req::args("type");  // 去掉
         $id = Filter::int(Req::args('id'));
         $product_id = Req::args('product_id');
         $buy_num = Req::args('buy_num');
         if (!$address_id || !$payment_id || $is_invoice == 1 && $invoice_title == '') {
             // product_id  产品ID列表 处理
             if (is_array($product_id)) {
                 foreach ($product_id as $key => $val) {
                     $product_id[$key] = Filter::int($val);
                 }
                 $product_id = implode('-', $product_id);
             } else {
                 $product_id = Filter::int($product_id);
             }
             $data = Req::args();
             $data['is_invoice'] = $is_invoice;
             if (!$address_id) {
                 $data['msg'] = array('fail', "必需选择收货地址,才能确认订单。");
             } else {
                 if (!$payment_id) {
                     $data['msg'] = array('fail', "必需选择支付方式,才能确认订单。");
                 } else {
                     $data['msg'] = array('fail', "索要发票,必需写明发票抬头。");
                 }
             }
             // type 类型
             // 下面代码没有使用
             //if ($type == null)
             //    $this->redirect("order", false, $data);
             //else {
             unset($data['act']);
             Req::args('pid', $product_id);
             Req::args('id', $id);
             unset($_GET['act']);
             //     Req::args('type', $type);
             Req::args('msg', $data['msg']);
             $this->redirect("/simple/order", true, Req::args());
             //$this->redirect("/simple/order_info", true, Req::args());
             //}
             exit;
         }
         //地址信息
         $address_model = new Model('address');
         $address = $address_model->where("id={$address_id} and user_id=" . $this->user['id'])->find();
         if (!$address) {
             $data = Req::args();
             $data['msg'] = array('fail', "选择的地址信息不正确!");
             $this->redirect("order", false, $data);
             exit;
         }
         //if(!$payment_id)$this->redirect("order",false,Req::args());
         if ($this->getModule()->checkToken('order')) {
             //订单类型: 0普通订单 1团购订单 2限时抢购 3捆绑促销
             $order_type = 0;
             $model = new Model('');
             //团购处理
             // 这部分去掉
             /*
             if($type=="groupbuy"){
                 $product_id = Filter::int($product_id[0]);
                 $num = $buy_num[0];
                 $item = $model->table("groupbuy as gb")->join("left join goods as go on gb.goods_id=go.id left join products as pr on pr.id=$product_id")->fields("*,pr.id as product_id,pr.spec")->where("gb.id=$id")->find();
                 $order_products = $this->packGroupbuyProducts($item,$num);
             
                 $groupbuy = $model->table("groupbuy")->where("id=$id")->find();
                 unset($groupbuy['description']);
                 $data['prom'] = serialize($groupbuy);
                 $data['prom_id'] = $id;
                 $order_type = 1;
             
             }
               if($order_type==0){
                 $order_products = $this->cart[$ship_id]['products'];
                 $data['prom_id'] = $prom_id;
             }
             */
             // 购物车
             //$cart = Cart::getCart();
             $cart_info = $this->cart_inst->all();
             //商品总金额,重量,积分计算
             $payable_amount = 0.0;
             $real_amount = 0.0;
             $weight = 0;
             $point = 0;
             $order_products = array();
             $error = 0;
             // 是否促销
             $error_list = array();
             if (isset($cart_info[$ship_id]['products'])) {
                 $order_products =& $cart_info[$ship_id]['products'];
                 // 循环购物车cart中每个产品
                 // 在这判断每个商品的购买方式
                 //
                 $prom_inst = new Prom();
                 foreach ($order_products as $goods_id => $products) {
                     foreach ($products as $product_id => $item) {
                         $item_ref =& $order_products[$goods_id][$product_id];
                         // Tiny::log(__FILE__ . __LINE__ . "-------products item----$key----" . var_export($item, true));
                         // 校验 所有商品的库存和活动是否结束
                         if (isset($item["order_type"])) {
                             if (is_array($item["order_type"])) {
                                 if ($item["order_type"]["flash_sale"] == true) {
                                     // test OK
                                     $goods_info = array("product_id" => $item["product_id"], 'goods_id' => $item['goods_id']);
                                     $flash_sale = array();
                                     $ret = $prom_inst->get_flash_sale($goods_info);
                                     if ($ret["status"] == 1 && isset($ret["data"])) {
                                         $flash_sale = $ret["data"];
                                         // 抢购促销校验
                                         // 是否有库存
                                         if ($flash_sale['max_num'] <= 0) {
                                             // test OK
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($flash_sale['max_num'] < $item["num"]) {
                                                 // test OK
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $flash_sale['max_num'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                     } else {
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--抢购已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 } elseif ($item["order_type"]["prom_series"] == true && $item["order_type"]["prom_goods"] == true) {
                                     //2 判断商品促销(单品)
                                     $products_inst = new Products();
                                     $products_item = array();
                                     $ret = $products_inst->getProduct($item['product_id']);
                                     // 获取商品信息 item = product
                                     if (isset($ret['status']) && $ret['status'] == 1) {
                                         $item_new = $ret['data'];
                                     }
                                     $item_new['goods_nums'] = $item['num'];
                                     // get prom goods 需要传参数goods_nums
                                     $prom_goods = $prom_inst->get_prom_goods($item_new);
                                     if (!empty($prom_goods)) {
                                         $prom_goods['parse'] = $prom_inst->do_prom_goods($item_new, $prom_goods);
                                         if (isset($prom_goods['parse']['note']) && $prom_goods['parse']['note'] != '') {
                                             $prom_goods['parse']['note'] = '商品优惠:' . $prom_goods['parse']['note'];
                                         }
                                         $amount = sprintf("%01.2f", $prom_goods['parse']['real_price'] * $item["num"]);
                                         $sell_total = $item['sell_price'] * $item["num"];
                                         // 是否有库存
                                         if ($item_new['store_nums'] <= 0) {
                                             // test OK
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($item_new['store_nums'] < $item["num"]) {
                                                 // test OK
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                         //修改ITEM内容 价格
                                         $item_ref['real_price'] = $prom_goods['parse']['real_price'];
                                     } else {
                                         // 单品--商品促销结束
                                         $item_ref['order_type']['prom_goods'] = false;
                                         $item_ref['real_price'] = $item_ref['sell_price'];
                                         // 真正价格 为 原来的 销售价格
                                         $item_ref['prom'] = "";
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--商品促销已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                     //3 系列促销
                                     //商品促销与系列促销叠加运算
                                     //$prom_series = $prom_inst->prom_series($item, $prom_goods);
                                     $prom_series = $prom_inst->get_prom_series($item_new);
                                     if (!empty($prom_series)) {
                                         $prom_series['parse'] = $prom_inst->do_prom_series($item_new, $prom_goods, $prom_series);
                                         $note = isset($prom_goods['parse']['note']) ? $prom_goods['parse']['note'] : "";
                                         if (isset($prom_series['parse']['note']) && $prom_series['parse']['note'] != '') {
                                             $note .= '; 系列优惠:' . $prom_series['parse']['note'];
                                         }
                                         $amount = sprintf("%01.2f", $prom_series['parse']['real_price'] * $item["num"]);
                                         $sell_total = $item['sell_price'] * $item["num"];
                                         //合并商品与系统促销
                                         // 送积分
                                         $multiple = 0;
                                         if (isset($prom_series['multiple']) && $prom_series['multiple'] >= 0) {
                                             $multiple = $prom_series['multiple'];
                                         }
                                         $prom_goods['series'] = $prom_series;
                                         // 是否有库存 --- 上面检查过库存  下面部分代码不需要检查库存
                                         /*
                                                                                    *   if ($item_new['store_nums'] <= 0) {    // test OK
                                                                                         $error = 1;
                                                                                         $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!',
                                                                                             "product_id" => $item['product_id'],
                                                                                         );
                                                                                         $error_list[] = $error_item;
                                                                                     } else if ($item_new['store_nums'] < $item["num"]) {          // test OK
                                                                                         $error = 1;
                                                                                         $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!',
                                                                                             "product_id" => $item['product_id'],
                                                                                         );
                                                                                         $error_list[] = $error_item;
                                                                                     }  */
                                         //修改ITEM内容
                                         $item_ref['real_price'] = $prom_series['parse']['real_price'];
                                         $item_ref['prom'] = $note;
                                         //$item_ref['store_nums']  = $prom_goods['store_nums'];
                                     } else {
                                         // 单品--商品促销结束
                                         $item_ref['order_type']['prom_series'] = false;
                                         // $item_ref['real_price'] = $item_ref['sell_price'];   // 真正价格 为 原来的 销售价格  上一步执行
                                         // $item_ref['prom'] = "";
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--系列促销已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 } elseif ($item["order_type"]["prom_goods"] == true) {
                                     //2 判断商品促销(单品)
                                     $products_inst = new Products();
                                     $ret = $products_inst->getProduct($item['product_id']);
                                     // 获取商品信息 item = product
                                     if (isset($ret['status']) && $ret['status'] == 1) {
                                         $item_new = $ret['data'];
                                     }
                                     $item_new['goods_nums'] = $item['num'];
                                     // get prom goods 需要传参数goods_nums
                                     $prom_goods = $prom_inst->get_prom_goods($item_new);
                                     if (!empty($prom_goods)) {
                                         $prom_goods['parse'] = $prom_inst->do_prom_goods($item_new, $prom_goods);
                                         if (isset($prom_goods['parse']['note']) && $prom_goods['parse']['note'] != '') {
                                             $prom_goods['parse']['note'] = '商品优惠:' . $prom_goods['parse']['note'];
                                         }
                                         $amount = sprintf("%01.2f", $prom_goods['parse']['real_price'] * $item["num"]);
                                         $sell_total = $item['sell_price'] * $item["num"];
                                         // 是否有库存
                                         if ($item_new['store_nums'] <= 0) {
                                             // test OK
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($item_new['store_nums'] < $item["num"]) {
                                                 // test OK
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                         //修改ITEM内容 价格
                                         $item_ref['real_price'] = $prom_goods['parse']['real_price'];
                                     } else {
                                         // 单品--商品促销结束
                                         $item_ref['order_type']['prom_goods'] = false;
                                         $item_ref['real_price'] = $item_ref['sell_price'];
                                         // 真正价格 为 原来的 销售价格
                                         $item_ref['prom'] = "";
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--商品促销已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 } elseif ($item["order_type"]["prom_series"] == true) {
                                     //3 系列促销
                                     //商品促销与系列促销叠加运算
                                     $products_inst = new Products();
                                     $products_item = array();
                                     $note = "";
                                     $ret = $products_inst->getProduct($item['product_id']);
                                     // 获取商品信息 item = product
                                     if (isset($ret['status']) && $ret['status'] == 1) {
                                         $item_new = $ret['data'];
                                     }
                                     $prom_series = $prom_inst->get_prom_series($item_new);
                                     if (!empty($prom_series)) {
                                         $prom_series['parse'] = $prom_inst->do_prom_series($item_new, NULL, $prom_series);
                                         if (isset($prom_series['parse']['note']) && $prom_series['parse']['note'] != '') {
                                             $note .= '; 系列优惠:' . $prom_series['parse']['note'];
                                         }
                                         $amount = sprintf("%01.2f", $prom_series['parse']['real_price'] * $item["num"]);
                                         $sell_total = $item['sell_price'] * $item["num"];
                                         //合并商品与系统促销
                                         $multiple = 0;
                                         if (isset($prom_series['multiple']) && $prom_series['multiple'] >= 0) {
                                             $multiple = $prom_series['multiple'];
                                         }
                                         $prom_goods['series'] = $prom_series;
                                         // 是否有库存
                                         if ($item_new['store_nums'] <= 0) {
                                             // test OK
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($item_new['store_nums'] < $item["num"]) {
                                                 // test OK
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                         //修改ITEM内容
                                         $item_ref['real_price'] = $prom_series['parse']['real_price'];
                                         $item_ref['prom'] = $note;
                                         // $item_ref['store_nums']  = $prom_goods['store_nums'];
                                     } else {
                                         // 单品--商品促销结束
                                         $item_ref['order_type']['prom_series'] = false;
                                         // $item_ref['real_price'] = $item_ref['sell_price'];   // 真正价格 为 原来的 销售价格  上一步执行
                                         // $item_ref['prom'] = "";
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--系列促销已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 } else {
                                     // 正常的销售
                                     $products_inst = new Products();
                                     $products_item = array();
                                     $ret = $products_inst->getProduct($item['product_id']);
                                     // 获取商品信息 item = product
                                     if (isset($ret['status']) && $ret['status'] == 1) {
                                         $item_new = $ret['data'];
                                     }
                                     // 是否有库存
                                     if (isset($item_new)) {
                                         if ($item_new['store_nums'] <= 0) {
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($item_new['store_nums'] < $item["num"]) {
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                     } else {
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--已经下线!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 }
                             }
                         }
                         $payable_amount += $item['sell_price'] * $item['num'];
                         // 成交价格
                         $real_amount += $item['real_price'] * $item['num'];
                         // 真实成交价格
                         // $payable_amount += $item['sell_total'];
                         //$real_amount += $item['amount'];
                         $weight += $item['weight'] * $item['num'];
                         $point += $item['point'] * $item['num'];
                     }
                 }
             }
             $order_bundling = null;
             $error_bd_list = array();
             if (!empty($cart_info[$ship_id]['bundling_list'])) {
                 //Tiny::log(__FILE__ . __LINE__ . "------cart info---" . var_export($cart_info, true));
                 $order_bundling =& $cart_info[$ship_id]['bundling_list'];
                 foreach ($order_bundling as $b_key => $b_val) {
                     // Tiny::log(__FILE__ . __LINE__ . "-------products item----$key----" . var_export($item, true));
                     // 判断是否存在
                     $bundling_total = 0;
                     foreach ($b_val as $v_key => $v_val) {
                         $num = $v_val['num'];
                         // 计算
                         $payable_amount += $v_val["val"]['price'] * $v_val["num"];
                         //$real_amount += $v_val["val"]['price'];  // 在item里面增加amount 项目
                         $real_amount += $v_val["val"]['price'] * $v_val["num"];
                         $bundling_total += $v_val["num"];
                         $arr_id = explode('-', $v_key);
                         //$str_ids = join(',', $arr_id);
                         $product_list = array();
                         if (!empty($arr_id)) {
                             $product_inst = new Products();
                             $ret = $product_inst->getProducts($arr_id);
                             if (isset($ret['status']) && $ret['status'] == 1) {
                                 $product_list = $ret['data'];
                             }
                         }
                         //SKM-ORDER-STORE  todo 判断库存是否足够
                         foreach ($product_list as $p_k => $p_v) {
                             if ($p_v['store_nums'] < $num) {
                                 // test OK
                                 $error = 1;
                                 $error_item = array("msg" => '套餐中商品:' . $p_v['name'] . '--库存只有' . $p_v['store_nums'] . '个!');
                                 $error_bd_list[] = $error_item;
                             }
                         }
                     }
                 }
             }
             if ($error == 1) {
                 $this->assign('error_list', $error_list);
                 $this->assign('error_bd_list', $error_bd_list);
                 // Req::args('msg', "提交订单失败");
                 //$this->redirect("/simple/cart", true, Req::args());
                 $this->redirect("/simple/cart", false);
                 exit;
             }
             // 处理整个订单
             //计算运费
             $fare = new Fare($weight);
             $payable_freight = $fare->calculate($address_id);
             $real_freight = $payable_freight;
             //计算订单优惠
             $prom_order = array();
             $discount_amount = 0;
             // order_type 购买的方式
             //if ($order_type == 0) {
             if ($prom_id) {
                 // 往Prom_Order 表中查询
                 // 这部分属于整个订单促销活动
                 $prom = new Prom($real_amount);
                 $prom_order = $model->table("prom_order")->where("id={$prom_id}")->find();
                 //防止非法会员使用订单优惠
                 $user = $this->user;
                 $group_id = ',0,';
                 if (isset($user['group_id'])) {
                     $group_id = ',' . $user['group_id'] . ',';
                 }
                 if (stripos(',' . $prom_order['group'] . ',', $group_id) !== false) {
                     $prom_parse = $prom->parsePorm($prom_order);
                     $discount_amount = $prom_parse['value'];
                     if ($prom_order['type'] == 4) {
                         $discount_amount = $payable_freight;
                     } else {
                         if ($prom_order['type'] == 2) {
                             $multiple = intval($prom_order['expression']);
                             $multiple = $multiple == 0 ? 1 : $multiple;
                             $point = $point * $multiple;
                         }
                     }
                     $data['prom'] = serialize($prom_order);
                 } else {
                     $data['prom'] = serialize(array());
                 }
             }
             // }
             //税计算
             $tax_fee = 0;
             /*
             $config = Config::getInstance();
             $config_other = $config->get('other');
             $open_invoice = isset($config_other['other_is_invoice']) ? !!$config_other['other_is_invoice'] : false;
             $tax = isset($config_other['other_tax']) ? intval($config_other['other_tax']) : 0;
             if ($open_invoice && $is_invoice) {
                 $tax_fee = $real_amount * $tax / 100;
             }
             */
             $ret = $this->cart_inst->getTaxAmountByShip($ship_id);
             if (isset($ret['status']) && $ret['status'] == 1 && $ret['data'] > 0) {
                 $tax_fee = $ret['data'];
             }
             //代金券处理
             $voucher_value = 0;
             $voucher = array();
             if ($voucher_id) {
                 $voucher = $model->table("voucher")->where("id={$voucher_id} and is_send=1 and user_id=" . $this->user['id'] . " and status = 0 and '" . date("Y-m-d H:i:s") . "' <=end_time and '" . date("Y-m-d H:i:s") . "' >=start_time and money<=" . $real_amount)->find();
                 if ($voucher) {
                     $voucher_value = $voucher['value'];
                     if ($voucher_value > $real_amount) {
                         $voucher_value = $real_amount;
                     }
                 }
             }
             if ($tax_fee <= 50) {
                 $tax_fee = 0;
             }
             //计算订单总金额
             $order_amount = $real_amount + $payable_freight + $tax_fee - $discount_amount - $voucher_value;
             $payable_amount += $payable_freight + $tax_fee;
             //填写订单
             $data['order_no'] = Common::createOrderNo();
             $data['user_id'] = $this->user['id'];
             $data['sender_name'] = $this->user['name'];
             $data['payment'] = $payment_id;
             $data['status'] = 2;
             $data['pay_status'] = 0;
             $data['accept_name'] = $address['accept_name'];
             $data['phone'] = $address['phone'];
             $data['mobile'] = $address['mobile'];
             $data['province'] = $address['province'];
             $data['city'] = $address['city'];
             $data['county'] = $address['county'];
             $data['addr'] = $address['addr'];
             $data['zip'] = $address['zip'];
             $data['payable_amount'] = $payable_amount;
             $data['payable_freight'] = $payable_freight;
             $data['real_freight'] = $real_freight;
             $data['create_time'] = date('Y-m-d H:i:s');
             $data['user_remark'] = $user_remark;
             $data['is_invoice'] = $is_invoice;
             if ($is_invoice == 1) {
                 $data['invoice_title'] = $invoice_type . ':' . $invoice_title;
             } else {
                 $data['invoice_title'] = '';
             }
             $data['taxes'] = $tax_fee;
             $data['discount_amount'] = $discount_amount;
             $data['order_amount'] = $order_amount;
             $data['real_amount'] = $real_amount;
             $data['point'] = $point;
             $data['type'] = $order_type;
             // type -> order_type
             $data['voucher_id'] = $voucher_id;
             $data['voucher'] = serialize($voucher);
             //var_dump($order_products);exit();
             // TODO SKM 写入订单数据
             $order_id = $model->table("order")->data($data)->insert();
             //写入订单商品
             // 单品 加入订单详情表
             foreach ($order_products as $goods_id => $products) {
                 foreach ($products as $product_id => $item) {
                     $tem_data = array('order_id' => '', 'goods_id' => '', 'product_id' => '', 'goods_name' => '', 'goods_price' => '', 'real_price' => '', 'goods_nums' => '', 'tax_code' => '', 'spec' => '');
                     if (isset($item["order_type"])) {
                         if (is_array($item["order_type"])) {
                             if ($item["order_type"]["flash_sale"] == true) {
                             } elseif ($item["order_type"]["prom_series"] == true) {
                                 $tem_data['prom_goods'] = serialize($item['prom_goods']);
                             } elseif ($item["order_type"]["prom_series"] == false && $item["order_type"]["prom_goods"] == true) {
                                 $tem_data['prom_goods'] = serialize($item['prom_goods']);
                             } elseif ($item["order_type"]["bundling"] == true) {
                             }
                         }
                     }
                     $tem_data['order_id'] = $order_id;
                     $tem_data['goods_id'] = $item['goods_id'];
                     $tem_data['goods_no'] = $item['goods_no'];
                     $tem_data['product_id'] = $product_id;
                     $tem_data['goods_name'] = $item['name'];
                     $tem_data['goods_price'] = $item['sell_price'];
                     $tem_data['real_price'] = $item['real_price'];
                     $tem_data['goods_nums'] = $item['num'];
                     //$tem_data['goods_weight'] = $item['weight'];
                     $tem_data['tax_code'] = $item['tax_code'];
                     // todo SKM 跟税种相关
                     $tem_data['origin_country'] = $item['origin_country'];
                     $tem_data['spec'] = serialize($item['spec']);
                     $model->table("order_goods")->data($tem_data)->insert();
                 }
             }
             // 捆绑销售 加入订单详情表
             if (!empty($cart_info[$ship_id]['bundling_list'])) {
                 $order_bundling = $cart_info[$ship_id]['bundling_list'];
                 foreach ($order_bundling as $item) {
                     $tem_data = array();
                     //$tem_data['prom_goods'] = serialize($item['prom_goods']);
                     foreach ($item as $key_bundling => $val_bundling) {
                         $bundling = $val_bundling;
                         $arr_products_id = explode('-', $key_bundling);
                         $str_products_ids = join(',', $arr_products_id);
                         $tem_data['order_id'] = $order_id;
                         $tem_data['goods_ids'] = $bundling["val"]['goods_id'];
                         $tem_data['products_ids'] = $str_products_ids;
                         //  $tem_data['goods_price'] = $item['sell_price'];
                         $tem_data['title'] = $bundling["val"]['title'];
                         $tem_data['prom_type'] = "bundling";
                         $tem_data['bundling_id'] = $bundling["val"]['id'];
                         $tem_data['real_price'] = $bundling['val']['price'];
                         $tem_data['goods_nums'] = $bundling['num'];
                         // $tem_data['goods_weight'] = $item['weight'];
                         //  $tem_data['spec'] = serialize($item['spec']);
                         $model->table("order_goods")->data($tem_data)->insert();
                     }
                 }
             }
             //优惠券锁死
             if (!empty($voucher)) {
                 $model->table("voucher")->where("id={$voucher_id} and user_id=" . $this->user['id'])->data(array('status' => 2))->update();
             }
             //清空购物车与表单缓存
             if ($order_type == 0) {
                 $this->cart_inst = Cart::getCart();
                 $this->cart_inst->clearShip($ship_id);
                 // 清空 ship_id 购物车   分库位置
                 //$cart->clear();
                 Session::clear("order_status");
             }
             $this->redirect("/simple/order_status/order_id/{$order_id}");
         } else {
             $msg = array('type' => 'fail', 'msg' => '非法提交订单!');
             $this->redirect('/index/msg', false, $msg);
         }
     } else {
         $this->redirect("login");
     }
 }
Example #24
0
 public function myOrdersOp()
 {
     $model = new Model();
     $mod_order = $model->table('service_yuyue');
     $where = array();
     $where['service_yuyue.yuyue_member_id'] = $this->member_id;
     $orders = $model->table('service_yuyue,service')->join('right join')->on('service_yuyue.yuyue_service_id=service.service_id')->where($where)->page($this->page)->order('yuyue_time desc')->select();
     $pageCount = $mod_order->gettotalpage();
     output_data(array('yuyues' => $orders), mobile_page($pageCount));
 }
Example #25
0
    public function assureUpdate()
    {
        $this->copyright();
        if ($this->_session('verify') != md5($this->_post('proving'))) {
            $this->error('验证码错误!');
            exit;
        }
        $borrowing = D('Borrowing');
        $refund = M('collection');
        $msgTools = A('msg', 'Event');
        $cache = cache(array('expire' => 40));
        $models = new Model();
        $uid = $this->_post('uid') ? $this->_post('uid') : $this->_session('user_uid');
        $refu = $refund->field('nper')->where('uid=' . $uid . ' and bid=' . $this->_post('id'))->order('`nper` DESC ')->find();
        $uname = $this->_post('uname') ? $this->_post('uname') : $this->_session('user_name');
        if ($uid) {
            $borr = $borrowing->where('`id`=' . $this->_post('id'))->find();
            $one = $borr['valid'] - floor(($borr['endtime'] - time()) / 86400);
            //获取第一个应扣除天数
            $counters = $this->counters($this->_post('price'), $borr['rates'], $borr['deadline'], $borr['candra'], $borr['way']);
            //利息计算
            unset($counters['total']);
            unset($counters['interest']);
            foreach ($counters as $id => $coun) {
                if ($id == 0) {
                    //第一个月
                    $o_interest += round($coun['interest'] / 30 * (30 - $one + 1), 2);
                    //第一个月实际利息
                } else {
                    $o_interest += $coun['interest'];
                }
            }
            unset($counters);
            unset($one);
            if ($borr['surplus'] >= $this->_post('price') || $borr['surplus'] < $borr['min']) {
                //所需金额小于投标金额
                if ($borr['surplus'] < $this->_post('price')) {
                    //如果投资的金额比所需的大,那么就将投资金额改为所需金额
                    $_POST['price'] = $borr['surplus'];
                }
                $users = reset($this->user_details());
                if ($this->_post('update_uid') == $uid) {
                    $this->error("不能投自己的标!");
                } else {
                    if ($this->_post('password') == $borr['password']) {
                        if ($this->_post('price') < $borr['min'] || $this->_post('price') > $borr['surplus']) {
                            if ($borr['surplus'] > $borr['min']) {
                                //如果所需金额大于最小投资金额
                                $this->error("操作有误,已记录,如误操作请联系管理员!");
                            }
                        }
                        if ($this->_post('price') > $borr['max']) {
                            if ($borr['max'] > 0) {
                                $this->error("操作有误,已记录,如误操作请联系管理员!");
                            }
                        }
                        if ($this->_post('price') > $users['available_funds']) {
                            //资金不足
                            $this->error("账户余额不足,请充值!", '__ROOT__/Center/fund/inject.html');
                        }
                        $user = D('User');
                        $pay_password = $user->userPayMd5($this->_post('pay_password'));
                        if ($users['pay_password'] == $pay_password) {
                            //支付密码
                            if ($borrowing->create()) {
                                $data['surplus'] = $borr['surplus'] - $this->_post('price');
                                $borrow = $models->table('ds_borrowing')->where('id=' . $this->_post('id'))->save($data);
                                $rewardCalculationArr['money'] = $borr['money'];
                                $rewardCalculationArr['price'] = $this->_post('price');
                                $money = M('money');
                                $array['type'] = 1;
                                $array['uid'] = $uid;
                                $array['bid'] = $this->_post('id');
                                $array['instructions'] = '对<a href="' . $_SERVER['HTTP_REFERER'] . '">【' . $borr['title'] . '】</a>的投标';
                                $logtotal = $moneyarr['total_money'] = $array['total'] = $users['total_money'] - $this->_post('price');
                                $logavailable = $moneyarr['available_funds'] = $array['available'] = $users['available_funds'] - $this->_post('price');
                                $array['interest'] = $o_interest;
                                $moneyarr['stay_interest'] = $array['stay_interest'] = $users['stay_interest'] + $array['interest'];
                                $moneyarr['due_in'] = $array['collected'] = $users['due_in'] + $this->_post('price') + $array['interest'];
                                $array['candra'] = $borr['candra'];
                                $array['operation'] = $this->_post('price');
                                $borrowlog = $this->borrowLog($array);
                                $money = $models->table('ds_money')->where('uid=' . $uid)->save($moneyarr);
                                //记录添加点
                                $userLog = $this->userLog('对【' . $borr['title'] . '】的投标');
                                //会员记录
                                $moneyLog = $this->moneyLog(array(0, '对【' . $borr['title'] . '】的投标,扣除资金', $array['operation'], '平台', $logtotal, $logavailable, $users['freeze_funds']));
                                //资金记录
                                $sendMsg = $msgTools->sendMsg(3, '对【' . $borr['title'] . '】的投标', '对<a href="' . $_SERVER['HTTP_REFERER'] . '">【' . $borr['title'] . '】</a>的投标,扣除资金', 'admin', $uid);
                                //站内信
                                $arr['member'] = array('uid' => $uid, 'name' => 'mem_flow');
                                $integralAdd = $this->integralAdd($arr);
                                //积分操作
                                //邮件通知
                                $mailNotice['uid'] = $uid;
                                $mailNotice['title'] = '对【' . $borr['title'] . '】的投标';
                                $mailNotice['content'] = '
									<div style="margin: 6px 0 60px 0;">
										<p>对【' . $borr['title'] . '】的投标,扣除资金:<font color="#ff0000"><b>' . $array['operation'] . '元</b></font></p>
										<p><a href="http://' . $_SERVER['HTTP_HOST'] . __ROOT__ . '/Loan/invest/' . $borr['id'] . '.html">http://' . $_SERVER['HTTP_HOST'] . __ROOT__ . '/Loan/invest/' . $borr['id'] . '.html</a></p>
										<p>如果您的邮箱不支持链接点击,请将以上链接地址拷贝到你的浏览器地址栏中。</p>
									</div>
									<div style="color: #999;">
										<p>发件时间:' . date('Y/m/d H:i:s') . '</p>
										<p>此邮件为系统自动发出的,请勿直接回复。</p>
									</div>';
                                $this->mailNotice($mailNotice);
                                unset($array);
                                unset($moneyarr);
                                unset($users);
                                $users = reset($this->user_details($borr['uid']));
                                $array['type'] = 2;
                                $array['uid'] = $borr['uid'];
                                $array['uname'] = $uname;
                                $array['bid'] = $this->_post('id');
                                $array['instructions'] = '用户:' . $uname . '对<a href="' . $_SERVER['HTTP_REFERER'] . '">【' . $borr['title'] . '】</a>的投标';
                                $moneyarr['total_money'] = $array['total'] = $users['total_money'] + $this->_post('price');
                                $moneyarr['available_funds'] = $array['available'] = $users['available_funds'] + $this->_post('price');
                                $array['deadline'] = $this->_post('deadline');
                                $array['candra'] = $borr['candra'];
                                $array['interest'] = $o_interest;
                                $moneyarr['stay_still'] = $array['also'] = $users['stay_still'] + $this->_post('price') + $array['interest'];
                                $array['operation'] = $this->_post('price');
                                $borrowlogs = $this->borrowLog($array);
                                $collection = $this->icollection($this->_post('id'), $uid);
                                //收款记录
                                unset($array);
                                unset($moneyarr);
                                unset($users);
                                if ($borr['surplus'] == $this->_post('price')) {
                                    //满标
                                    $borrows = $models->table('ds_borrowing')->where('id=' . $this->_post('id'))->save(array('state' => 1));
                                    $this->success('投标成功', '__ROOT__/Center/invest/isbid.html');
                                    exit;
                                } else {
                                    $this->success('投标成功', '__ROOT__/Center/invest/isbid.html');
                                    exit;
                                }
                            } else {
                                $this->error($borrowing->getError());
                            }
                        } else {
                            $this->error("支付密码错误!");
                        }
                    } else {
                        $this->error("密码标密码错误!");
                    }
                }
            } else {
                $this->error("此标状态已发生改变,请从新提交!");
            }
        } else {
            $this->error("请先登陆!", '__ROOT__/Logo/login.html');
        }
    }
Example #26
0
    function cards(){
        $this->assign('infoType','card');
        $member_card_set_db=M('Member_card_set');
        $thisCard=$member_card_set_db->where(array('token'=>$this->token,'id'=>intval($_GET['cardid'])))->find();
        $this->assign('thisCard',$thisCard);
        $this->assign('card',$thisCard);
        $error=0;
        if ($thisCard){
            $userinfo_db=M('Userinfo');
            $userInfos=$userinfo_db->where(array('token'=>$this->token,'wecha_id'=>$this->wecha_id))->order('id ASC')->select();
            $userScore=0;
            if ($userInfos){
                $userScore=intval($userInfos[0]['total_score']);
                $userInfo=$userInfos[0];
            }
            $this->assign('userScore',$userScore);
            //
            $member_card_create_db=M('Member_card_create');
            $thisMember=$member_card_create_db->where(array('token'=>$this->token,'wecha_id'=>$this->wecha_id,'cardid'=>intval($_GET['cardid'])))->find();
            $hasApplied=count($thisMember);
            //
            if (!$hasApplied){
                $card = M('Member_card_create')->field('id,number')->where("token='".$this->token."' and cardid=".$thisCard['id']." and wecha_id = ''")->find();
                if(!$card){
                    $this->error('会员卡暂时缺货');
                }else {
                    //
                    if (intval($thisCard['miniscore'])==0 || $userScore>intval($thisCard['miniscore'])){
                        $error=-4;
                        $this->redirect(U('Userinfo/index',array('token'=>$this->token,'wecha_id'=>$this->wecha_id,'cardid'=>$thisCard['id'])));
                    }else if($userScore<intval($thisCard['miniscore'])){
                        $this->error('领取此会员卡需要'.$thisCard['miniscore'].'积分');
                    }
                }
                //
            }else{
                $model  = new Model();

                $this->assign('thisMember',$thisMember);
                //
                $now=time();
                //
                $noticeCount=M('Member_card_notice')->where('cardid='.$thisCard['id'].' AND endtime>'.$now)->count();
                $this->assign('noticeCount',$noticeCount);
                //
                $member_card_vip_db=M('Member_card_vip');
                $previlegeCount=$member_card_vip_db->where('cardid='.$thisCard['id'].' AND ((type=0 AND statdate<'.$now.' AND enddate>'.$now.') OR type=1)')->count();
                $this->assign('previlegeCount',$previlegeCount);
                //
                /*$iwhere       = array('token'=>$this->token,'wecha_id'=>$this->wecha_id,'coupon_type'=>'3','cardid'=>$thisCard['id'],'is_use'=>'0');
                $integralCount  = M('member_card_coupon_record')->where($iwhere)->count();*/
                $integralCount  = $model->table(array(C('DB_PREFIX').'member_card_coupon_record'=>'record',C('DB_PREFIX').'member_card_integral'=>'integral'))->where('record.token="'.$this->token.'" AND record.wecha_id="'.$this->wecha_id.'" AND record.is_use="0" AND record.cardid='.$thisCard['id'].' AND record.coupon_id=integral.id AND record.coupon_type="3" AND integral.enddate >"'.$now.'"')->count();

                $this->assign('integralCount',$integralCount);
                

                /*$cwhere1      = array('token'=>$this->token,'wecha_id'=>$this->wecha_id,'coupon_type'=>'1','cardid'=>$thisCard['id'],'is_use'=>'0');
                $couponCount1   = M('member_card_coupon_record')->where($cwhere1)->count();*/
                $couponCount1  = $model->table(array(C('DB_PREFIX').'member_card_coupon_record'=>'record',C('DB_PREFIX').'member_card_coupon'=>'coupon'))->where('record.token="'.$this->token.'" AND record.wecha_id="'.$this->wecha_id.'" AND record.is_use="0" AND record.cardid='.$thisCard['id'].' AND record.coupon_id=coupon.id AND record.coupon_type="1" AND coupon.enddate >"'.$now.'"')->count();
                $this->assign('couponCount1',$couponCount1);
                //
                /*$cwhere2      = array('token'=>$this->token,'wecha_id'=>$this->wecha_id,'coupon_type'=>'2','cardid'=>$thisCard['id'],'is_use'=>'0');
                $couponCount2   = M('member_card_coupon_record')->where($cwhere2)->count();*/

                $couponCount2  = $model->table(array(C('DB_PREFIX').'member_card_coupon_record'=>'record',C('DB_PREFIX').'member_card_coupon'=>'coupon'))->where('record.token="'.$this->token.'" AND record.wecha_id="'.$this->wecha_id.'" AND record.is_use="0" AND record.cardid='.$thisCard['id'].' AND record.coupon_id=coupon.id AND record.coupon_type="2" AND coupon.enddate >"'.$now.'"')->count();

                $this->assign('couponCount2',$couponCount2);
                //
                $todaySigned=$this->_todaySigned();
                $this->assign('todaySigned',$todaySigned);
                //
                $this->assign('userInfo',$userInfo);
            }
        }else {
            $this->error('您的积分不够');
        }
        $this->assign('error',$error);
        $this->display();
    }
Example #27
0
 /**
  * 用户的回帖
  */
 public function userAnswersOp()
 {
     // 回复列表
     $where = array();
     $types = array(5, 6);
     $model = new Model();
     $m_reply = $model->table('circle_threply');
     $where['circle_threply.member_id'] = $this->member_id;
     $where['circle_theme.thclass_id'] = array('not in', $types);
     $reply_info = $model->table('circle_threply,circle_theme')->join('right join')->on('circle_threply.theme_id=circle_theme.theme_id')->where($where)->page($this->page)->order('reply_addtime desc')->select();
     $pageCount = $m_reply->gettotalpage();
     if (!empty($reply_info)) {
         foreach ($reply_info as $key => $val) {
             $reply_info[$key]['member_avatar'] = getMemberAvatarForID($reply_info[$key]['member_id']);
         }
     }
     output_data(array('answers' => $reply_info), mobile_page($pageCount));
 }
 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 #29
0
 /**
  * Test the Model::table method.
  *
  * @group laravel
  */
 public function testTableMethodReturnsCorrectName()
 {
     $model = new Model();
     $this->assertEquals('models', $model->table());
     Model::$table = 'table';
     $this->assertEquals('table', $model->table());
     Model::$table = null;
     $this->assertEquals('models', $model->table());
 }
Example #30
0
 /**
  * @还款计划更新
  * @id		标ID
  * @--------------
  * @nper	期数
  * @uid		会员
  * @bid		标ID
  * @money	资金
  * @time	时间
  * @作者		shop猫
  * @版权		宁波天发网络
  * @官网		http://www.tifaweb.com http://www.dswjcms.com
  */
 public function irefundsEdit($id = 1)
 {
     $models = new Model();
     $borrowing = M('borrowing');
     $refund = M('refund');
     $borrow = $borrowing->where('id=' . $id)->find();
     $money = $borrow['money'] - $borrow['surplus'];
     $refun = $refund->where('bid=' . $id)->select();
     //获取还款计划
     $counters = $this->counters($money, $borrow['rates'], $borrow['deadline'], $borrow['candra'], $borrow['way']);
     //普通标还款计划
     if ($borrow['candra'] == 0) {
         //如果是月标循环还款计划
         for ($i = 1; $i <= $borrow['deadline']; $i++) {
             //换算出每月还款时间
             $time[] = $this->endMonth($i);
         }
         unset($counters['total']);
         unset($counters['interest']);
         foreach ($refun as $id => $coun) {
             $refun['money'] = $counters[$id]['refund'];
             $refun['interest'] = $counters[$id]['interest'];
             return $models->table('ds_refund')->where('id=' . $coun['id'])->save($refun);
         }
     } else {
         //如果是天标,直接显示最终还款计划
         $refun['money'] = $counters['total'];
         $refun['interest'] = $counters['interest'];
         return $models->table('ds_refund')->where('id=' . $refun[0]['id'])->save($refun);
     }
 }