function updateOrderStock($id, $minus = true) { $ordergoods = mysqld_selectall("SELECT * FROM " . table('shop_order_goods') . " WHERE orderid='{$id}'"); foreach ($ordergoods as $item) { $goods = mysqld_select("SELECT * FROM " . table('shop_goods') . " WHERE id='" . $item['goodsid'] . "'"); if ($minus) { //属性 if (!empty($item['optionid'])) { mysqld_query("update " . table('shop_goods_option') . " set stock=stock-:stock where id=:id", array(":stock" => $item['total'], ":id" => $item['optionid'])); } $data = array(); if ($goods['totalcnf'] != 1) { $data['total'] = $goods['total'] - $item['total']; } $data['sales'] = $goods['sales'] + $item['total']; mysqld_update('shop_goods', $data, array('id' => $item['goodsid'])); } else { //属性 if (!empty($item['optionid'])) { mysqld_query("update " . table('shop_goods_option') . " set stock=stock+:stock where id=:id", array(":stock" => $item['total'], ":id" => $item['optionid'])); } $data = array(); if ($goods['totalcnf'] != 1) { $data['total'] = $goods['total'] + $item['total']; } $data['sales'] = $goods['sales'] - $item['total']; mysqld_update('shop_goods', $data, array('id' => $item['goodsid'])); } } }
$newids = implode("_", $newids); $a = array("title" => $_GP['option_title_' . $ids][0], "productprice" => $_GP['option_productprice_' . $ids][0], "costprice" => $_GP['option_costprice_' . $ids][0], "marketprice" => $_GP['option_marketprice_' . $ids][0], "stock" => $_GP['option_stock_' . $ids][0], "weight" => $_GP['option_weight_' . $ids][0], "goodsid" => $id, "specs" => $newids); $totalstocks += $a['stock']; if (empty($get_option_id)) { mysqld_insert("shop_goods_option", $a); $option_id = mysqld_insertid(); } else { mysqld_update("shop_goods_option", $a, array('id' => $get_option_id)); $option_id = $get_option_id; } $optionids[] = $option_id; } if (count($optionids) > 0) { mysqld_query("delete from " . table('shop_goods_option') . " where goodsid={$id} and id not in ( " . implode(',', $optionids) . ")"); } else { mysqld_query("delete from " . table('shop_goods_option') . " where goodsid={$id}"); } //总库存 if ($totalstocks > 0) { mysqld_update("shop_goods", array("total" => $totalstocks), array("id" => $id)); } message('商品操作成功!', web_url('goods', array('op' => 'post', 'id' => $id)), 'success'); } include page('goods'); } elseif ($operation == 'display') { $pindex = max(1, intval($_GP['page'])); $psize = 10; $condition = ''; if (!empty($_GP['keyword'])) { $condition .= " AND title LIKE '%{$_GP['keyword']}%'"; }
$result = array('result' => 1, 'total' => $carttotal); die(json_encode($result)); } else { if ($op == 'clear') { mysqld_delete('shop_cart', array('session_id' => $openid)); die(json_encode(array("result" => 1))); } else { if ($op == 'remove') { $id = intval($_GP['id']); mysqld_delete('shop_cart', array('session_id' => $openid, 'id' => $id)); die(json_encode(array("result" => 1, "cartid" => $id))); } else { if ($op == 'update') { $id = intval($_GP['id']); $num = intval($_GP['num']); mysqld_query("update " . table('shop_cart') . " set total={$num} where id=:id", array(":id" => $id)); die(json_encode(array("result" => 1))); } else { $list = mysqld_selectall("SELECT * FROM " . table('shop_cart') . " WHERE session_id = '" . $openid . "'"); $totalprice = 0; if (!empty($list)) { foreach ($list as &$item) { $goods = mysqld_select("SELECT title, thumb, marketprice, total FROM " . table('shop_goods') . " WHERE id=:id limit 1", array(":id" => $item['goodsid'])); //属性 $option = mysqld_select("select title,marketprice,stock from " . table("shop_goods_option") . " where id=:id limit 1", array(":id" => $item['optionid'])); if ($option) { $goods['title'] = $goods['title']; $goods['optionname'] = $option['title']; $goods['marketprice'] = $option['marketprice']; $goods['total'] = $option['stock']; }
public function do_getaward() { $xc_zjp = mysqld_select("SELECT * FROM " . table('xc_zjp_reply')); $member = get_member_account(true, intval($xc_zjp['needreg']) == 1); $openid = $member['openid']; if (empty($openid)) { message('非法访问,请重新发送消息进入抽奖页面!'); } $member = member_get($openid); if (empty($xc_zjp)) { message('非法访问,请重新发送消息进入抽奖页面!'); } $result = array('status' => -1, 'message' => ''); $total = mysqld_selectcolumn("SELECT COUNT(*) FROM " . table('xc_zjp_winner') . " WHERE open_id = '{$openid}' and TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(createtime))<= " . $xc_zjp["periodlottery"]); $myuser = mysqld_select("SELECT * FROM " . table('xc_zjp_user') . " WHERE open_id = '{$openid}' "); $friendcount = 0; $arr_times = $this->get_today_times($total, $xc_zjp['maxlottery'], $friendcount); $result['useCount'] = false; $useCredit = false; if ($arr_times['today_has'] <= 0) { if (!empty($xc_zjp['basenum']) && $xc_zjp['basenum'] < $member['credit']) { $useCredit = true; } } if ($arr_times['today_has'] <= 0) { if (empty($xc_zjp['basenum']) || !empty($xc_zjp['basenum']) && $xc_zjp['basenum'] > $member['credit']) { $result['nochance'] = $arr_times['today_has']; $result['message'] = '抽奖机会已用完!'; $vars = array(); $vars['message'] = $result; $vars['redirect'] = refresh(); $vars['type'] = 'ajax'; exit(json_encode($vars)); } } $result['surplusCount'] = $arr_times['today_has'] - 1 < 0 ? -1 : $arr_times['today_has'] - 1; if (!empty($xc_zjp['basenum'])) { $result['useCredit1'] = $xc_zjp['basenum']; $result['surplusCredit1'] = $member['credit'] - $xc_zjp['basenum'] < 0 ? 0 : $member['credit'] - $xc_zjp['basenum']; } else { $result['useCredit1'] = 0; $result['surplusCredit1'] = 0; } $result['useCount'] = true; $gifts = mysqld_selectall("SELECT * FROM " . table('xc_zjp_award') . " WHERE total>0 ORDER BY probalilty ASC"); //计算每个礼物的概率 $probability = 0; $rate = 1; $award = array(); foreach ($gifts as $name => $gift) { if (empty($gift['probalilty'])) { continue; } if ($gift['probalilty'] < 1) { $temp = explode('.', $gift['probalilty']); $temp = pow(10, strlen($temp[1])); $rate = $temp < $rate ? $rate : $temp; } $probability = $probability + $gift['probalilty'] * $rate; $award[] = array('id' => $gift['id'], 'probalilty' => $probability); } $all = 100 * $rate; if ($probability < $all) { $award[] = array('title' => '', 'probalilty' => $all); } mt_srand((double) microtime() * 1000000); $rand = mt_rand(1, $all); foreach ($award as $key => $gift) { if (isset($award[$key - 1])) { if ($rand > $award[$key - 1]['probalilty'] && $rand <= $gift['probalilty']) { $awardid = $gift['id']; break; } } else { if ($rand > 0 && $rand <= $gift['probalilty']) { $awardid = $gift['id']; break; } } } $title = ''; $result['hasPrize'] = false; $result['message'] = '很遗憾,您没能中奖!'; $data = array('open_id' => $openid, 'status' => 0, 'createtime' => TIMESTAMP); $credit = array('award' => (empty($awardid) ? '未' : '') . '中奖', 'open_id' => $openid, 'status' => 3, 'description' => empty($awardid) ? $xc_zjp['misscredit'] : $xc_zjp['hitcredit'], 'createtime' => TIMESTAMP); if (!empty($awardid)) { $gift = mysqld_select("SELECT * FROM " . table('xc_zjp_award') . " WHERE id = '{$awardid}'"); if ($gift['total'] > 0) { $data['award'] = $gift['title']; $result['gift'] = $gift['title']; $result['giftimg'] = $gift['description']; $result['hasPrize'] = true; mysqld_query("UPDATE " . table('xc_zjp_award') . " SET total = total - 1 WHERE id = '{$awardid}'"); $data['description'] = ''; $result['message'] = '恭喜您,得到“' . $data['award'] . '”!' . $desss; $result['status'] = 0; } else { $credit['description'] = $xc_zjp['misscredit']; } $data['gifturl'] = $gift['description']; $data['description'] = $gift['title']; } if ($useCredit) { member_credit($openid, intval($xc_zjp['basenum']), 'usecredit', '抓奖品消费积分'); } if (empty($_SESSION['cachetime']) || $_SESSION['cachetime'] < time()) { $_SESSION['cachetime'] = time() + 3; mysqld_insert('xc_zjp_winner', $data); } $result['myaward'] = mysqld_selectall("SELECT * FROM " . table('xc_zjp_winner') . " WHERE open_id = '{$openid}' AND award <> '' ORDER BY createtime DESC"); $mycredit = mysqld_selectcolumn("SELECT SUM(description) FROM " . table('xc_zjp_winner') . " WHERE open_id = '{$openid}' AND award <> '' "); $result['credit'] = $mycredit; $result['credit'] = !empty($result['credit']) ? $result['credit'] : '0'; $vars = array(); $vars['message'] = $result; $vars['redirect'] = refresh(); $vars['type'] = 'ajax'; exit(json_encode($vars)); }