Beispiel #1
0
 public function update_win_info()
 {
     $id = $this->input['sendno'];
     if (!$id) {
         $this->errorOutput('请刷新后,再试!');
     }
     $user_id = $this->user['user_id'];
     if (!$user_id) {
         $this->errorOutput('请先登陆!');
     }
     $sql = "SELECT id,prize_id,lottery_id FROM " . DB_PREFIX . "win_info WHERE sendno = '{$id}' AND confirm = 0";
     $res = $this->db->query_first($sql);
     $wininfo_id = $res['id'];
     if (!$res || !$res['lottery_id']) {
         $this->errorOutput('网络超时,请刷新后,再试哦!');
     }
     $data = array();
     $sql = "SELECT score_limit,need_score,exchange_switch FROM " . DB_PREFIX . "lottery WHERE id = " . $res['lottery_id'];
     $data = $this->db->query_first($sql);
     if (empty($data)) {
         $this->errorOutput('活动异常,请稍后再试!');
     }
     if ($data['score_limit'] && $data['need_score']) {
         include_once ROOT_PATH . 'lib/class/members.class.php';
         $mem_obj = new members();
         //同步会员积分
         $credit_type = $mem_obj->get_trans_credits_type();
         if (!empty($credit_type)) {
             $res1 = '';
             $ac = 'sub_' . $credit_type['db_field'];
             $res1 = $mem_obj->{$ac}($user_id, $data['need_score'], $data['id'], APP_UNIQUEID, MOD_UNIQUEID, 'update_win_info', '抽奖扣除');
             if (!$res1) {
                 $this->errorOutput('您的积分不够啦,快去赚取积分吧!');
             }
         }
     }
     $address = $this->input['address'];
     $phone_num = $this->input['phone_num'];
     $ip = hg_getip();
     $up_data = array('device_token' => $this->input['device_token'], 'member_name' => $this->user['user_name'], 'member_id' => $user_id, 'confirm' => 1, 'status' => 1, 'ip' => $ip);
     if ($res['prize_id']) {
         $sql = "SELECT id,type,prize,seller_id,name FROM " . DB_PREFIX . "prize WHERE id = {$res['prize_id']}";
         $prize_res = $this->db->query_first($sql);
         if (!$prize_res['id']) {
             $this->errorOutput('请刷新后,再试~');
         }
         //锁止开关
         if (!$this->settings['lock_stock']) {
             $sql = "UPDATE " . DB_PREFIX . "prize SET prize_win = prize_win + 1 WHERE id = " . $res['prize_id'] . " AND prize_win < prize_num";
             $this->db->query($sql);
             //更新失败提示报错
             if (!$this->db->affected_rows()) {
                 $this->errorOutput('请刷新后,再试~');
             }
         }
         //兑换码
         $up_data['exchange_code'] = generateExchangeCode();
         if ($this->settings['App_qrcode']) {
             include_once ROOT_PATH . 'lib/class/qrcode.class.php';
             $qrcode_server = new qrcode();
             $exchange_url = $this->settings['exchange_url'] . '?send_no=' . $id;
             $data_qrcode = array('content' => $exchange_url);
             $qrcode = $qrcode_server->create($data_qrcode, -1);
             $up_data['exchange_qrcode'] = is_array($qrcode) ? hg_fetchimgurl($qrcode) : '';
         }
         $sync_fail_tag = false;
         if ($prize_res['type'] == 1) {
             $up_data['prize_type'] = 1;
             include_once ROOT_PATH . 'lib/class/members.class.php';
             $mem_obj = new members();
             //同步会员积分
             $credit_type = $mem_obj->get_trans_credits_type();
             if (!$credit_type['db_field']) {
                 $ac = 'add_' . $credit_type['db_field'];
                 $res1 = $mem_obj->{$ac}($user_id, intval($prize_res['prize']), $res['lottery_id'], APP_UNIQUEID, MOD_UNIQUEID, 'update_win_info', '抽奖加积分');
                 if (!$res1) {
                     $sync_fail_tag = true;
                 } else {
                     $up_data['provide_status'] = 1;
                 }
             } else {
                 $sync_fail_tag = true;
             }
         } else {
             if ($prize_res['type'] == 0) {
                 $up_data['prize_type'] = 2;
             }
         }
         if ($prize_res['seller_id']) {
             $up_data['seller_id'] = $prize_res['seller_id'];
         }
         //冗余奖品名称
         if ($prize_res['prize']) {
             $up_data['prize_name'] = $prize_res['prize'];
         } elseif ($prize_res['name']) {
             $up_data['prize_name'] = $prize_res['name'];
         }
     }
     if ($address) {
         $up_data['address'] = $address;
     }
     if ($phone_num) {
         $up_data['phone_num'] = $phone_num;
     }
     $sql = "UPDATE " . DB_PREFIX . "win_info SET ";
     foreach ($up_data as $k => $v) {
         $sql .= " {$k} = '{$v}',";
     }
     $sql = trim($sql, ',');
     $sql .= " WHERE sendno = '" . $id . "'";
     $this->db->query($sql);
     $affect = $this->db->affected_rows();
     if (!$affect) {
         $this->errorOutput('网络超时,请稍后再试~');
     }
     //锁止开关
     if ($this->settings['lock_stock']) {
         //删除库存锁止记录
         $sql = "DELETE FROM " . DB_PREFIX . "stock_lock WHERE send_no = '" . $id . "'";
         $this->db->query($sql);
     }
     //如果奖品是积分,同步会员积分
     if ($prize_res['type'] == 1 && intval($prize_res['prize']) && $sync_fail_tag) {
         //同步失败,记录失败记录
         $sync_fail = array('user_id' => $user_id, 'credits' => $prize_res['prize'], 'lottery_id' => $res['lottery_id'], 'wininfo_id' => $wininfo_id, 'create_time' => TIMENOW, 'update_time' => TIMENOW);
         $sql = " INSERT INTO " . DB_PREFIX . "sync_fail SET ";
         foreach ($sync_fail as $k => $v) {
             $sql .= " {$k} = '{$v}',";
         }
         $sql = trim($sql, ',');
         $this->db->query($sql);
         $this->errorOutput('网络繁忙,积分暂未同步,请稍后到会员中心查看!');
     }
     if ($this->input['tv_interact']) {
         return true;
     } else {
         $this->addItem('success');
         $this->output();
     }
 }
Beispiel #2
0
 private function insertIntoOrder()
 {
     $orderparams['bill_header_content'] = $this->bill_header_content;
     $orderparams['order_id'] = generateOrderCode();
     $orderparams['fid'] = 0;
     $orderparams['froder_id'] = '';
     $orderparams['user_id'] = $this->user['user_id'];
     $orderparams['pay_credits'] = $this->GoodsValues['credits_value'];
     $orderparams['user_name'] = $this->user['user_name'];
     $orderparams['title'] = stripslashes($this->input['title']);
     $orderparams['brief'] = stripslashes($this->input['brief']);
     $orderparams['goods_value'] = $this->GoodsValues['goods_value'];
     $orderparams['order_value'] = $this->GoodsValues['total_value'];
     $orderparams['order_quantity'] = $this->GoodsValues['order_quantity'];
     $orderparams['delivery_fee'] = $this->GoodsValues['delivery_fee'];
     $orderparams['create_time'] = TIMENOW;
     $orderparams['title'] = $this->order_title;
     $orderparams['brief'] = $this->order_brief;
     $orderparams['order_client_type'] = '';
     $orderparams['order_client_ip'] = hg_getip();
     $orderparams['submit_time'] = TIMENOW;
     $orderparams['update_time'] = TIMENOW;
     $orderparams['goods_out_time'] = TIMENOW;
     $orderparams['pay_start_time'] = TIMENOW;
     $orderparams['pay_end_time'] = TIMENOW;
     $orderparams['goods_wait_time'] = TIMENOW;
     $orderparams['completed_time'] = TIMENOW;
     $orderparams['paymethod'] = $this->Paymethod;
     $orderparams['appid'] = $this->user['appid'];
     $orderparams['appname'] = trim($this->user['display_name']);
     $orderparams['ip'] = hg_getip();
     foreach ($this->GoodsInfos as $bundle_id => $datas) {
         foreach ($datas as $k => $v) {
             if ($v['index_img']) {
                 $orderparams['indexpic'] = urlencode(json_encode($v['index_img']));
                 //$orderparams['indexpic'] = serialize($v['index_img']);
                 break;
             }
         }
     }
     //        //商品为自取商品时,生成兑换码
     //        if(!$this->input['pick_up_way'])
     //        {
     //        	$orderparams['exchange_code'] = generateExchangeCode();
     //
     //        	include_once(ROOT_PATH . 'lib/class/qrcode.class.php');
     //			$qrcode_server = new qrcode();
     //
     //			$data = array('content'=>$orderparams['exchange_code']);
     //			$qrcode = $qrcode_server->create($data,-1);
     //
     //			$orderparams['exchange_qrcode'] = is_array($qrcode) ? hg_fetchimgurl($qrcode) : '';
     //        }
     $orderparams['telphone'] = $this->getphone();
     $orderparams['id'] = $this->obj->insert($this->tbname, $orderparams);
     $orderparams['indexpic'] = json_decode(urldecode($orderparams['indexpic']), 1);
     //$orderparams['indexpic'] = serialize($v['index_img']);
     if ($orderparams['id']) {
         /****** 商品为自取商品时,生成兑换码 ******/
         if (!$this->input['pick_up_way']) {
             $exchange_code = $this->input['verify_url'] ? $this->input['verify_url'] . '?id=' . $orderparams['id'] : generateExchangeCode();
             include_once ROOT_PATH . 'lib/class/qrcode.class.php';
             $qrcode_server = new qrcode();
             $data = array('content' => $exchange_code);
             $qrcode = $qrcode_server->create($data, 1);
             $exchange_qrcode = is_array($qrcode) ? hg_fetchimgurl($qrcode) : '';
             $rows = $this->obj->update($this->tbname, array('exchange_code' => $exchange_code, 'exchange_qrcode' => $exchange_qrcode), ' WHERE id=' . $orderparams['id']);
             if ($rows) {
                 $orderparams['exchange_code'] = $this->input['verify_url'] ? '' : $exchange_code;
                 $orderparams['exchange_qrcode'] = $exchange_qrcode;
             }
         }
         /****** 商品为自取商品时,生成兑换码 ******/
         $this->Orderinfo = $orderparams;
         return $orderparams;
     }
     return false;
 }