model.php 13.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
<?php
/**
 * 万能小店
 *
 * @author WeEngine Team & ewei
 * @url
 */
defined('IN_IA') or exit('Access Denied');


function mload() {
	static $mloader;
	if(empty($mloader)) {
		$mloader = new Mloader();
	}
	return $mloader;
}
class Mloader {
	private $cache = array();
	function func($name) {
		if (isset($this->cache['func'][$name])) {
			return true;
		}
		$file = IA_ROOT . '/addons/wn_storex/function/' . $name . '.func.php';
		if (file_exists($file)) {
			include $file;
			$this->cache['func'][$name] = true;
			return true;
		} else {
			trigger_error('Invalid Helper Function /addons/wn_storex/function/' . $name . '.func.php', E_USER_ERROR);
			return false;
		}
	}

	function model($name) {
		if (isset($this->cache['model'][$name])) {
			return true;
		}
		$file = IA_ROOT . '/addons/wn_storex/model/' . $name . '.mod.php';
		if (file_exists($file)) {
			include $file;
			$this->cache['model'][$name] = true;
			return true;
		} else {
			trigger_error('Invalid Model /addons/wn_storex/model/' . $name . '.mod.php', E_USER_ERROR);
			return false;
		}
	}

	function classs($name) {
		if (isset($this->cache['class'][$name])) {
			return true;
		}
		$file = IA_ROOT . '/addons/wn_storex/class/' . $name . '.class.php';
		if (file_exists($file)) {
			include $file;
			$this->cache['class'][$name] = true;
			return true;
		} else {
			trigger_error('Invalid Class /addons/wn_storex/class/' . $name . '.class.php', E_USER_ERROR);
			return false;
		}
	}
}


/**
 * 计算用户密码hash
 * @param int $flag 0注册,1登录
 * @param array $member 用户数据
 * @return string
 */
if(!function_exists('hotel_set_userinfo')) {
	function hotel_set_userinfo($flag = 0, $member) {
		global $_GPC, $_W;
		unset($member['password']);
		unset($member['salt']);
		insert_cookie('__hotel_member', $member);
	}
}



if(!function_exists('hotel_get_userinfo')) {
	function hotel_get_userinfo() {
		global $_W;
		$key = '__hotel_member';
		return get_cookie($key);
	}
}



if(!function_exists('get_cookie')) {
	function get_cookie($key) {
		global $_W;
		$key = $_W['config']['cookie']['pre'] . $key;
		return json_decode(base64_decode($_COOKIE[$key]), true);
	}
}



if(!function_exists('insert_cookie')) {
	function insert_cookie($key, $data) {
		global $_W, $_GPC;
		$session = base64_encode(json_encode($data));
		setcookie($_W['config']['cookie']['pre'].$key, $session);
	}
}

//检查用户是否登录
if(!function_exists('check_hotel_user_login')) {
	function check_hotel_user_login($set) {
		global $_W;
		$weid = $_W['uniacid'];
		$from_user = $_W['fans']['from_user'];
		$user_info = hotel_get_userinfo();
		if (empty($user_info['id'])) {
			return 0;
		} else {
			if ($weid != $user_info['weid']) {
				return 0;
			}
			if ($from_user == $user_info['from_user']) {
				if ($set['user'] == 2 && $user_info['user_set'] != 2) {
					return 0;
				} else {
					return 1;
				}
			} else {
				if ($set['bind'] == 1) {
					return 1;
				} elseif ($set['bind'] == 2) {
					return 0;
				} elseif ($set['bind'] == 3) {
					if ($user_info['userbind'] == 0) {
						return 1;
					} else {
						return 0;
					}
				}
			}
		}
	}
}

/**
 * 计算用户密码hash
 * @param string $input 输入字符串
 * @param string $salt 附加字符串
 * @return string
 */
if(!function_exists('hotel_member_hash')) {
	function hotel_member_hash($input, $salt) {
		global $_W;
		$input = "{$input}-{$salt}-{$_W['config']['setting']['authkey']}";
		return sha1($input);
	}
}

/**
 * 用户注册
 * PS:密码字段不要加密
 * @param array $member 用户注册信息,需要的字段必须包括 username, password, remark
 * @return int 成功返回新增的用户编号,失败返回 0
 */
if(!function_exists('hotel_member_check')) {
	function hotel_member_check($member) {
		$sql = 'SELECT `password`,`salt` FROM ' . tablename('storex_member') . " WHERE 1";
		$params = array();
		if (!empty($member['uid'])) {
			$sql .= ' AND `uid`=:uid';
			$params[':uid'] = intval($member['uid']);
		}
		if (!empty($member['weid'])) {
			$sql .= ' AND `weid`=:weid';
			$params[':weid'] = intval($member['weid']);
		}
		if (!empty($member['username'])) {
			$sql .= ' AND `username`=:username';
			$params[':username'] = $member['username'];
		}
		if (!empty($member['from_user'])) {
			$sql .= ' AND `from_user`=:from_user';
			$params[':from_user'] = $member['from_user'];
		}
		if (!empty($member['status'])) {
			$sql .= " AND `status`=:status";
			$params[':status'] = intval($member['status']);
		}
		if (!empty($member['id'])) {
			$sql .= " AND `id`!=:id";
			$params[':id'] = intval($member['id']);
		}
		$sql .= " LIMIT 1";
		$record = pdo_fetch($sql, $params);
		if (!$record || empty($record['password']) || empty($record['salt'])) {
			return false;
		}
		if (!empty($member['password'])) {
			$password = hotel_member_hash($member['password'], $record['salt']);
			return $password == $record['password'];
		}
		return true;
	}
}

/**
 * 获取单条用户信息,如果查询参数多于一个字段,则查询满足所有字段的用户
 * PS:密码字段不要加密
 * @param array $member 要查询的用户字段,可以包括  uid, username, password, status
 * @param bool 是否要同时获取状态信息
 * @return array 完整的用户信息
 */
if(!function_exists('hotel_member_single')) {
	function hotel_member_single($member) {
		$sql = 'SELECT * FROM ' . tablename('storex_member') . " WHERE 1";
		$params = array();
		if (!empty($member['weid'])) {
			$sql .= ' AND `weid`=:weid';
			$params[':weid'] = $member['weid'];
		}
		if (!empty($member['from_user'])) {
			$sql .= ' AND `from_user`=:from_user';
			$params[':from_user'] = $member['from_user'];
		}
		if (!empty($member['username'])) {
			$sql .= ' AND `username`=:username';
			$params[':username'] = $member['username'];
		}
		if (!empty($member['status'])) {
			$sql .= " AND `status`=:status";
			$params[':status'] = intval($member['status']);
		}
		$sql .= " LIMIT 1";
		$record = pdo_fetch($sql, $params);
		if (!$record) {
			return false;
		}
		if (!empty($member['password'])) {
			$password = hotel_member_hash($member['password'], $record['salt']);
			if ($password != $record['password']) {
				return false;
			}
		}
		return $record;
	}
}



if(!function_exists('get_storex_set')) {
	function get_storex_set() {
		global $_GPC, $_W;
		$cachekey = "wn_storex_set:{$_W['uniacid']}";
		$set = cache_load($cachekey);
		if (!empty($set)) {
			return $set;
		}
		$set = pdo_get('storex_set', array('weid' => intval($_W['uniacid'])));
		if (empty($set)) {
			$set = array(
				"user" => 1,
				"bind" => 1,
				"reg" => 1,
				"ordertype" => 1,
				"regcontent" => "",
				"paytype1" => 0,
				"paytype2" => 0,
				"paytype3" => 0,
				"is_unify" => 0,
				"version" => 0,
				"tel" => "",
			);
		}
		cache_write($cachekey, $set);
		return $set;
	}
}

/**
 * 生成分页数据
 * @param int $currentPage 当前页码
 * @param int $totalCount 总记录数
 * @param string $url 要生成的 url 格式,页码占位符请使用 *,如果未写占位符,系统将自动生成
 * @param int $pageSize 分页大小
 * @return string 分页HTML
 */
if(!function_exists('get_page_array')) {
	function get_page_array($tcount, $pindex, $psize = 15) {
		global $_W;
		$pdata = array(
			'tcount' => 0,
			'tpage' => 0,
			'cindex' => 0,
			'findex' => 0,
			'pindex' => 0,
			'nindex' => 0,
			'lindex' => 0,
			'options' => ''
		);
		$pdata['tcount'] = $tcount;
		$pdata['tpage'] = ceil($tcount / $psize);
		if ($pdata['tpage'] <= 1) {
			$pdata['isshow'] = 0;
			return $pdata;
		}
		$cindex = $pindex;
		$cindex = min($cindex, $pdata['tpage']);
		$cindex = max($cindex, 1);
		$pdata['cindex'] = $cindex;
		$pdata['findex'] = 1;
		$pdata['pindex'] = $cindex > 1 ? $cindex - 1 : 1;
		$pdata['nindex'] = $cindex < $pdata['tpage'] ? $cindex + 1 : $pdata['tpage'];
		$pdata['lindex'] = $pdata['tpage'];
		if ($pdata['cindex'] == $pdata['lindex']) {
			$pdata['isshow'] = 0;
			$pdata['islast'] = 1;
		} else {
			$pdata['isshow'] = 1;
			$pdata['islast'] = 0;
		}
		return $pdata;
	}
}
//完成订单后加售出数量
if(!function_exists('add_sold_num')) {
	function add_sold_num($room){
		if (intval($_GPC['store_type']) == 1){
			pdo_update('storex_room', array('sold_num' => ($room['sold_num']+1)), array('id' => $room['id']));
		} else {
			pdo_update('storex_goods', array('sold_num' => ($room['sold_num']+1)), array('id' => $room['id']));
		}
	}
}
//获取房型某天的记录
if(!function_exists('getRoomPrice')) {
	function getRoomPrice($hotelid, $roomid, $date) {
		global $_W;
		$btime = strtotime($date);
		$roomprice = pdo_get('storex_room_price', array('weid' => intval($_W['uniacid']), 'hotelid' => $hotelid, 'roomid' => $roomid, 'roomdate' => $btime));
		if (empty($roomprice)) {
			$room = pdo_get('storex_room', array('hotelid' => $hotelid, 'id' => $roomid, 'weid' => intval($_W['uniacid'])));
			$roomprice = array(
					"weid" => $_W['uniacid'],
					"hotelid" => $hotelid,
					"roomid" => $roomid,
					"oprice" => $room['oprice'],
					"cprice" => $room['cprice'],
					"status" => $room['status'],
					"roomdate" => strtotime($date),
					"thisdate" => $date,
					"num" => "-1",
					"status" => 1,
			);
		}
		return $roomprice;
	}
}

if(!function_exists('gettablebytype')) {
	function gettablebytype($store_type){
		if ($store_type == 1) {
			return 'storex_room';
		} else {
			return 'storex_goods';
		}
	}
}

//获取订单的商户订单号
if(!function_exists('getOrderUniontid')) {
	function getOrderUniontid(&$lists){
		if (!empty($lists)){
			foreach ($lists as $orderkey=>$orderinfo){
				$paylog = pdo_get('core_paylog', array('uniacid' => $orderinfo['weid'], 'tid' => $orderinfo['id'], 'module' => 'wn_storex'), array('uniacid', 'uniontid', 'tid'));
				if (!empty($paylog)){
					$lists[$orderkey]['uniontid'] = $paylog['uniontid'];
				}
			}
		}
		return $list;
	}
}

if(!function_exists('format_list')) {
	function format_list($category, $list){
		if (!empty($category) && !empty($list)){
			$cate = array();
			foreach ($category as $category_info){
				$cate[$category_info['id']] = $category_info;
			}
			foreach ($list as $k => $info){
				if (!empty($cate[$info['pcate']])){
					$list[$k]['pcate'] = $cate[$info['pcate']]['name'];
				}
				if (!empty($cate[$info['ccate']])){
					$list[$k]['ccate'] = $cate[$info['ccate']]['name'];
				}
			}
		}
		return $list;
	}
}

if(!function_exists('express_name')) {
	function express_name (){
		return array(
			"shunfeng" => "顺丰",
			"shentong" => "申通",
			"yunda" => "韵达快运",
			"tiantian" => "天天快递",
			"yuantong" => "圆通速递",
			"zhongtong" => "中通速递",
			"ems" => "ems快递",
			"huitongkuaidi" => "汇通快运",
			"quanfengkuaidi" => "全峰快递",
			"zhaijisong" => "宅急送",
			"aae" => "aae全球专递",
			"anjie" => "安捷快递",
			"anxindakuaixi" => "安信达快递",
			"biaojikuaidi" => "彪记快递",
			"bht" => "bht",
			"baifudongfang" => "百福东方国际物流",
			"coe" => "中国东方(COE)",
			"changyuwuliu" => "长宇物流",
			"datianwuliu" => "大田物流",
			"debangwuliu" => "德邦物流",
			"dhl" => "dhl",
			"dpex" => "dpex",
			"dsukuaidi" => "d速快递",
			"disifang" => "递四方",
			"fedex" => "fedex(国外)",
			"feikangda" => "飞康达物流",
			"fenghuangkuaidi" => "凤凰快递",
			"feikuaida" => "飞快达",
			"guotongkuaidi" => "国通快递",
			"ganzhongnengda" => "港中能达物流",
			"guangdongyouzhengwuliu" => "广东邮政物流",
			"gongsuda" => "共速达",
			"hengluwuliu" => "恒路物流",
			"huaxialongwuliu" => "华夏龙物流",
			"haihongwangsong" => "海红",
			"haiwaihuanqiu" => "海外环球",
			"jiayiwuliu" => "佳怡物流",
			"jinguangsudikuaijian" => "京广速递",
			"jixianda" => "急先达",
			"jjwl" => "佳吉物流",
			"jymwl" => "加运美物流",
			"jindawuliu" => "金大物流",
			"jialidatong" => "嘉里大通",
			"jykd" => "晋越快递",
			"kuaijiesudi" => "快捷速递",
			"lianb" => "联邦快递(国内)",
			"lianhaowuliu" => "联昊通物流",
			"longbanwuliu" => "龙邦物流",
			"lijisong" => "立即送",
			"lejiedi" => "乐捷递",
			"minghangkuaidi" => "民航快递",
			"meiguokuaidi" => "美国快递",
			"menduimen" => "门对门",
			"ocs" => "OCS",
			"peisihuoyunkuaidi" => "配思货运",
			"quanchenkuaidi" => "全晨快递",
			"quanjitong" => "全际通物流",
			"quanritongkuaidi" => "全日通快递",
			"quanyikuaidi" => "全一快递",
			"rufengda" => "如风达",
			"santaisudi" => "三态速递",
			"shenghuiwuliu" => "盛辉物流",
			"sue" => "速尔物流",
			"shengfeng" => "盛丰物流",
			"saiaodi" => "赛澳递",
			"tiandihuayu" => "天地华宇",
			"tnt" => "tnt",
			"ups" => "ups",
			"wanjiawuliu" => "万家物流",
			"wenjiesudi" => "文捷航空速递",
			"wuyuan" => "伍圆",
			"wxwl" => "万象物流",
			"xinbangwuliu" => "新邦物流",
			"xinfengwuliu" => "信丰物流",
			"yafengsudi" => "亚风速递",
			"yibangwuliu" => "一邦速递",
			"youshuwuliu" => "优速物流",
			"youzhengguonei" => "邮政包裹挂号信",
			"youzhengguoji" => "邮政国际包裹挂号信",
			"yuanchengwuliu" => "远成物流",
			"yuanweifeng" => "源伟丰快递",
			"yuanzhijiecheng" => "元智捷诚快递",
			"yuntongkuaidi" => "运通快递",
			"yuefengwuliu" => "越丰物流",
			"yad" => "源安达",
			"yinjiesudi" => "银捷速递",
			"zhongtiekuaiyun" => "中铁快运",
			"zhongyouwuliu" => "中邮物流",
			"zhongxinda" => "忠信达",
			"zhimakaimen" => "芝麻开门",
		);
	}
}