<?php
defined('IN_IA') or exit('Access Denied');
require 'inc/func/core.php';
require 'common/common.php';
require 'common/store.php';
require 'common/print.php';
require 'common/order.php';
require 'common/server.php';
require 'common/other.php';
require 'common/template.php';
require 'common/profitSharing.php';
class Yb_cyModuleSite extends Core
{
public function dragResult($errno, $message, $data = "", $log = "")
{
global $_W, $_GPC;
exit(json_encode(array("code" => $errno, "message" => $message, "data" => $data)));
}
public function GetIP()
{
global $_W, $_GPC;
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$cip = $_SERVER['HTTP_CLIENT_IP'];
} else {
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$cip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
if (!empty($_SERVER['REMOTE_ADDR'])) {
$cip = $_SERVER['REMOTE_ADDR'];
} else {
$cip = '无法获取!';
}
}
}
return $cip;
}
public function doMobileSaveFile()
{
global $_W, $_GPC;
$TxtFileName = __DIR__ . '/.lock';
if (($TxtRes = fopen($TxtFileName, 'w+')) === FALSE) {
$this->result(1, '写入文件失败!', ["out" => $out]);
}
$StrConents = $_POST['out'];
if (!fwrite($TxtRes, $StrConents)) {
$this->result(1, '写入文件失败!', ["out" => $out]);
}
if ($_POST['plugin']) {
cache_write('ybcy_power_list', $_POST['plugin']);
cache_write('ybcy_power_list_time', time() + 300);
}
cache_write('ybcy_power', $_POST['power']);
cache_write('ybcy_wxMiniNum', $_POST['wxMiniNum']);
fclose($TxtRes);
$this->result(0, '写入成功');
}
public function doMobileActivation()
{
global $_W, $_GPC;
$url = 'https://cloud.y-bei.cn/cloud/we7_auth/authorization';
$data['code'] = $_GPC['__input']['code'];
$data['uniacid'] = $_W['uniacid'];
$name = $_SERVER['HTTP_HOST'];
$host = 'https://' . $name;
$data['domain'] = $host;
$res = Common::httpRequest($url, $data);
$res = json_decode($res, true);
if ($res['code'] == 1) {
$this->result(0, '激活成功');
} else {
$this->result(1, $res['msg']);
}
}
public function doMobileRead()
{
global $_W, $_GPC;
$file_path = __DIR__ . '/.lock';
if (file_exists($file_path)) {
$str = file_get_contents($file_path);
} else {
$this->result(1, '读取失败');
}
$this->result(0, '读取成功', $str);
}
public function doMobileLogin()
{
global $_W, $_GPC;
$openId = $_W['fans']['openid'] ?: 'oYsjtvlA8a3jr6C1KHnLRK7XFbM0';
if (!$openId) {
$this->result(1, 'openId获取失败');
}
$user = pdo_get('ybcy_user', array("openId" => $openId, "uniacid" => $_W['uniacid']));
$userArr['openId'] = $openId;
$userArr['portrait'] = $_W['fans']['headimgurl'];
$userArr['userName'] = $_W['fans']['nickname'];
if ($user) {
$user['userId'] = $user['id'];
$this->result(0, '成功', $user);
}
$userArr['bindType'] = 2;
$userArr['createdAt'] = time();
$userArr['uniacid'] = $_W['uniacid'];
$res = pdo_insert('ybcy_user', $userArr);
if ($res) {
$user = pdo_get('ybcy_user', array("openId" => $openId));
$user['userId'] = $user['id'];
if ($_GPC['inviteId']) {
Common::bindPartner($_GPC['inviteId'], $user['id']);
}
$this->result(0, '成功', $user);
} else {
$this->result(1, '失败');
}
}
public function checkStore($id)
{
global $_W, $_GPC;
$store = pdo_getall('ybcy_store', array("uniacid" => $_W['uniacid'], "deleteAt" => 0, "id !=" => $id));
$copyright = pdo_get('ybcy_core_system', array("uniacid" => $_W['uniacid'], "ident" => "copyright"));
if (!$copyright) {
$copyright = pdo_get('ybcy_core_system', array("ident" => "founder"));
}
$totalNum = json_decode($copyright['data'])->num ?: 1;
$createdNum = count($store);
$set = false;
if ($createdNum < $totalNum) {
$set = true;
}
return $set;
}
public function doMobileAddCity()
{
global $_W, $_GPC;
$cityId = $_GPC['__input']['city'];
$i = 0;
while ($i < count($cityId)) {
$open = pdo_get('mgtc_open_city', array("cityId" => $cityId['id'], "uniacid" => $_W['uniacid']));
if (!$open) {
$city = pdo_get('mgtc_core_district', array("id" => $cityId[$i]));
$data['cityId'] = $city['id'];
$data['state'] = 1;
$data['createdAt'] = time();
$data['pId'] = $city['upid'];
$data['uniacid'] = $_W['uniacid'];
$res = pdo_insert('mgtc_open_city', $data);
}
if (!$res) {
$this->result(1, '添加失败!');
}
$i++;
}
$this->result(0, '添加成功!');
}
public function doMobilebatchGoods()
{
global $_W, $_GPC;
$post = $_GPC['__input'];
if ($post['type'] == 'none') {
$data['display'] = 2;
}
if ($post['type'] == 'display') {
$data['display'] = 1;
}
if ($post['type'] == 'isRecommend') {
$data['isRecommend'] = 1;
}
if ($post['type'] == 'del') {
$data['deleteAt'] = time();
}
$res = pdo_update('ybcy_core_goods', $data, array("id" => $post['id']));
if ($res) {
$this->result(0, '操作操作商品成功!', '', '批量操作商品');
} else {
$this->result(1, '操作失败!');
}
}
public function doMobileSaveStore()
{
global $_W, $_GPC;
$post = $_GPC['__input'];
$rst = self::checkStore($post['id']);
if (!$rst) {
$this->result(1, '非法操作');
}
if (!$post['lng'] or !$post['lat']) {
$this->result(1, '商家经纬度不能为空!');
}
if (!$post['enterEndAt']) {
$this->result(1, '到期时间不能为空!');
}
if (!$post['name']) {
$this->result(1, '店铺名称不能为空!');
}
if (!$post['icon']) {
$this->result(1, '店铺logo不能为空!');
}
if (!$post['linkMan']) {
$this->result(1, '联系人不能为空!');
}
if (!$post['tel']) {
$this->result(1, '商家电话不能为空!');
}
if (!$post['cityData']) {
$this->result(1, '省/市/区不能为空!');
}
if (!$post['address']) {
$this->result(1, '详细地址不能为空!');
}
$data['name'] = $post['name'];
$data['sort'] = $post['sort'];
$data['icon'] = $post['icon'];
$data['mainDishes'] = $post['mainDishes'];
$data['media'] = json_encode($post['media']);
$data['license'] = json_encode($post['license']);
$data['notice'] = str_replace(PHP_EOL, '', $post['notice']);
$service = [];
$i = 0;
while ($i < count($post['service'])) {
$list = pdo_get('ybcy_core_service', array("name" => $post['service'][$i], "uniacid" => $_W['uniacid'], "deleteAt" => 0, "term"