Exemplo n.º 1
0
 function addOrder($order, $good_ids, $good_counts)
 {
     $hint = '';
     //要对订单进行拆分
     $goods = array();
     //商品组
     foreach ($good_ids as $key => $v) {
         $good = D('StoreInfo')->getById($v);
         $good['count'] = $good_counts[$key];
         //对每个商品进行遍历,按照uid分配商品组
         $goods[$good['uid']][] = $good;
     }
     //对商品组分别创建订单
     foreach ($goods as $key => $v) {
         $sum = $this->comput_sum_good($v);
         $t_order = $order;
         //临时订单
         $t_order['id'] = doubleval(time() . create_rand(4, 'num'));
         $t_order['total_cny'] = $sum['cny'];
         $t_order['total_count'] = $sum['count'];
         $t_order['s_uid'] = $key;
         //卖家ID
         $shop = D('StoreShop')->getById($v[0]['shop_id']);
         $rs = $this->add($t_order);
         if ($rs == 0) {
             return array(false, $this->getError());
         }
         D('order_link')->add(array('order_id' => $rs, 'model' => 'store_order', 'app' => 'store'));
         //给店主发信息
         D('Message')->sendMessage($shop['uid'], $content = '【微店】订单' . $rs . '已创建,等待买家付款!', $title = '微店下单通知', 'store/center/sold', array(), is_login());
         //添加订单完成,添加商品
         foreach ($v as $k => $g) {
             $t_good['good_id'] = $g['id'];
             $t_good['h_price'] = $g['price'];
             $t_good['cTime'] = time();
             $t_good['h_name'] = $g['title'];
             $t_good['h_pic'] = $g['cover_id'];
             $t_good['order_id'] = $rs;
             $t_good['count'] = $g['count'];
             $rs_good = D('store_item')->add($t_good);
             D('Goods')->where('id=' . $g['id'])->setField('sell', $g['sell'] + $g['count']);
             if ($rs_good == 0) {
                 return array(false, $this->getError());
             }
         }
     }
     D('Cart')->clear();
     return array(true, $hint);
 }
Exemplo n.º 2
0
 public function addVerify($account, $type, $uid = 0)
 {
     $uid = $uid ? $uid : is_login();
     if ($type == 'mobile' || modC('EMAIL_VERIFY_TYPE', 0, 'USERCONFIG') == 2 && $type == 'email') {
         $verify = create_rand(6, 'num');
     } else {
         $verify = create_rand(32);
     }
     $this->where(array('account' => $account, 'type' => $type))->delete();
     $data['verify'] = $verify;
     $data['account'] = $account;
     $data['type'] = $type;
     $data['uid'] = $uid;
     $data = $this->create($data);
     $res = $this->add($data);
     if (!$res) {
         return false;
     }
     return $verify;
 }
 private function rand_nickname()
 {
     $nickname = create_rand(4);
     if ($this->where(array('nickname' => $nickname))->select()) {
         $this->rand_nickname();
     } else {
         return $nickname;
     }
 }
Exemplo n.º 4
0
 protected function randId()
 {
     $id = time() . create_rand(4, 'num');
     return doubleval($id);
 }
Exemplo n.º 5
0
 protected function rand_email()
 {
     $email = create_rand(10) . '@ocenter.com';
     if ($this->where(array('email' => $email))->select()) {
         $this->rand_email();
     } else {
         return $email;
     }
 }
Exemplo n.º 6
0
 /**
  * 创建邀请码
  * @param array $data
  * @param $length
  * @return array|mixed
  * @author 郑钟良<*****@*****.**>
  */
 private function createOneCode($data = array(), $length)
 {
     $length = $length ? $length : 11;
     do {
         //生成随机数
         $map['code'] = create_rand($length);
     } while ($this->where($map)->count());
     $data['code'] = $map['code'];
     $data = $this->create($data);
     return $data;
 }
Exemplo n.º 7
0
 protected function weixin_js()
 {
     $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
     $url = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
     $arr = array('jsapi_ticket' => S('jsapi_ticket') ? S('jsapi_ticket') : D('Common/weixin')->get_jsapi_ticket(), 'noncestr' => create_rand(), 'timestamp' => NOW_TIME, 'url' => $url);
     $str = '';
     foreach ($arr as $key => $val) {
         if ($key == 'url') {
             $str .= $key . '=' . $val;
         } else {
             $str .= $key . '=' . $val . '&';
         }
     }
     $str = sha1($str);
     $arr['signature'] = $str;
     $weixin_json = json_encode($arr);
     $this->assign('weixin_json', $weixin_json);
 }