From fc8d6a0ea1d829344baa1535150ef88a2e4c4f33 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 24 Oct 2023 10:55:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E7=BD=B2=E5=88=B0git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/weliam_smartcity/api/Certified.php | 244 + .../weliam_smartcity/api/CultivateClass.php | 316 + addons/weliam_smartcity/api/Goods.php | 711 +++ addons/weliam_smartcity/api/Im.php | 138 + addons/weliam_smartcity/api/Member.php | 2927 +++++++++ addons/weliam_smartcity/api/Order.php | 1156 ++++ addons/weliam_smartcity/api/Pay.php | 5316 +++++++++++++++++ addons/weliam_smartcity/api/Rights.php | 282 + addons/weliam_smartcity/api/Store.php | 4922 +++++++++++++++ addons/weliam_smartcity/api/Student.php | 495 ++ .../core/class/Cache.class.php | 112 + .../core/class/FilesHandle.class.php | 138 + .../core/class/Func_loader.class.php | 101 + .../core/class/GatherArticle.class.php | 97 + .../core/class/Jurisdiction.class.php | 271 + .../core/class/MapService.class.php | 77 + .../core/class/Menus.class.php | 574 ++ .../core/class/Menus_store.class.php | 274 + .../core/class/Menus_sys.class.php | 723 +++ .../core/class/Merchant.class.php | 1696 ++++++ .../core/class/PayBuild.class.php | 161 + .../core/class/PayResult.class.php | 131 + .../core/class/Queue.class.php | 1087 ++++ .../weliam_smartcity/core/class/Sms.class.php | 94 + .../core/class/Template.class.php | 64 + .../core/class/Util.class.php | 1179 ++++ .../core/class/WeApp.class.php | 190 + .../core/class/WeChatPay.class.php | 249 + .../core/class/WeixinPay.class.php | 915 +++ .../core/class/Weixinqrcode.class.php | 328 + .../core/class/WeliamDb.class.php | 270 + .../core/class/WeliamWeChat.class.php | 2131 +++++++ .../core/class/util_csv.class.php | 137 + .../core/class/wlPay.class.php | 168 + addons/weliam_smartcity/core/common/Im.php | 292 + addons/weliam_smartcity/core/common/api.php | 16 + .../weliam_smartcity/core/common/autoload.php | 32 + .../weliam_smartcity/core/common/defines.php | 56 + .../weliam_smartcity/core/common/openapi.php | 62 + addons/weliam_smartcity/core/common/task.php | 23 + .../weliam_smartcity/core/common/uniapp.php | 1 + .../core/common/yunAsyNotify.php | 31 + .../core/common/yunnotify.php | 113 + .../core/function/global.func.php | 1346 +++++ .../core/function/tpl.func.php | 1004 ++++ .../core/table/agentarea.table.php | 38 + .../core/table/area.table.php | 45 + .../core/table/distribution.table.php | 17 + 48 files changed, 30750 insertions(+) create mode 100644 addons/weliam_smartcity/api/Certified.php create mode 100644 addons/weliam_smartcity/api/CultivateClass.php create mode 100644 addons/weliam_smartcity/api/Goods.php create mode 100644 addons/weliam_smartcity/api/Im.php create mode 100644 addons/weliam_smartcity/api/Member.php create mode 100644 addons/weliam_smartcity/api/Order.php create mode 100644 addons/weliam_smartcity/api/Pay.php create mode 100644 addons/weliam_smartcity/api/Rights.php create mode 100644 addons/weliam_smartcity/api/Store.php create mode 100644 addons/weliam_smartcity/api/Student.php create mode 100644 addons/weliam_smartcity/core/class/Cache.class.php create mode 100644 addons/weliam_smartcity/core/class/FilesHandle.class.php create mode 100644 addons/weliam_smartcity/core/class/Func_loader.class.php create mode 100644 addons/weliam_smartcity/core/class/GatherArticle.class.php create mode 100644 addons/weliam_smartcity/core/class/Jurisdiction.class.php create mode 100644 addons/weliam_smartcity/core/class/MapService.class.php create mode 100644 addons/weliam_smartcity/core/class/Menus.class.php create mode 100644 addons/weliam_smartcity/core/class/Menus_store.class.php create mode 100644 addons/weliam_smartcity/core/class/Menus_sys.class.php create mode 100644 addons/weliam_smartcity/core/class/Merchant.class.php create mode 100644 addons/weliam_smartcity/core/class/PayBuild.class.php create mode 100644 addons/weliam_smartcity/core/class/PayResult.class.php create mode 100644 addons/weliam_smartcity/core/class/Queue.class.php create mode 100644 addons/weliam_smartcity/core/class/Sms.class.php create mode 100644 addons/weliam_smartcity/core/class/Template.class.php create mode 100644 addons/weliam_smartcity/core/class/Util.class.php create mode 100644 addons/weliam_smartcity/core/class/WeApp.class.php create mode 100644 addons/weliam_smartcity/core/class/WeChatPay.class.php create mode 100644 addons/weliam_smartcity/core/class/WeixinPay.class.php create mode 100644 addons/weliam_smartcity/core/class/Weixinqrcode.class.php create mode 100644 addons/weliam_smartcity/core/class/WeliamDb.class.php create mode 100644 addons/weliam_smartcity/core/class/WeliamWeChat.class.php create mode 100644 addons/weliam_smartcity/core/class/util_csv.class.php create mode 100644 addons/weliam_smartcity/core/class/wlPay.class.php create mode 100644 addons/weliam_smartcity/core/common/Im.php create mode 100644 addons/weliam_smartcity/core/common/api.php create mode 100644 addons/weliam_smartcity/core/common/autoload.php create mode 100644 addons/weliam_smartcity/core/common/defines.php create mode 100644 addons/weliam_smartcity/core/common/openapi.php create mode 100644 addons/weliam_smartcity/core/common/task.php create mode 100644 addons/weliam_smartcity/core/common/uniapp.php create mode 100644 addons/weliam_smartcity/core/common/yunAsyNotify.php create mode 100644 addons/weliam_smartcity/core/common/yunnotify.php create mode 100644 addons/weliam_smartcity/core/function/global.func.php create mode 100644 addons/weliam_smartcity/core/function/tpl.func.php create mode 100644 addons/weliam_smartcity/core/table/agentarea.table.php create mode 100644 addons/weliam_smartcity/core/table/area.table.php create mode 100644 addons/weliam_smartcity/core/table/distribution.table.php diff --git a/addons/weliam_smartcity/api/Certified.php b/addons/weliam_smartcity/api/Certified.php new file mode 100644 index 0000000..57314f2 --- /dev/null +++ b/addons/weliam_smartcity/api/Certified.php @@ -0,0 +1,244 @@ +renderError($validate['msg']); + + $this->renderSuccess('成功'); + } + + /** + * 企业商户认证申请(商务合作) + * @return void + */ + public function applyMerchantCertified() { + global $_W , $_GPC; + + $type = $_GPC['type'] ?: 'get'; // get 获取数据 | set 创建申请 + $storeid = $_GPC['storeid']; // 商户id + + # 验证是否有申请条件 + $validate = Member::validateMemberIdentity($_W['mid'],false); + if (!$validate['status']) $this->renderError($validate['msg']); + + $identity_id = pdo_getcolumn(PDO_NAME . 'member',['id' => $_W['mid']],'identity_id'); + if ($identity_id != 5) $this->renderError('非企业身份,禁止申请商户合作'); + + # 创建申请 + if ($type == 'set') { + $mobile = $_GPC['mobile']; // 手机号 + $position = $_GPC['position']; // 职务 + $name = $_GPC['name']; // 姓名 + $code = $_GPC['code']; // 短信验证码 + + if (empty($storeid) || !is_numeric($storeid)) $this->renderError('缺少商户id'); + if (empty($name)) $this->renderError('请输入姓名'); + if (empty($position)) $this->renderError('请输入职务'); + if (empty($mobile)) $this->renderError('请输入手机号'); + if (!preg_match("/^1[3-9]\d{9}$/",$mobile)) $this->renderError('请输入正确的手机号'); + + $nameRes = Filter::init($name,$_W['source'],1); + if ($nameRes['errno'] == 0) $this->renderError('姓名'.$nameRes['message']); + $positionRes = Filter::init($position,$_W['source'],1); + if ($positionRes['errno'] == 0) $this->renderError('职务'.$positionRes['message']); + + + $this->checkCode($mobile,$code); + + $queryRes = pdo_get(PDO_NAME . 'merchant_certified',['storeid'=>$storeid,'status' => [0,1]],'status'); + if ($queryRes) { + $this->renderError($queryRes['status'] == 1 ? '商务合作认证申请已通过,请勿重复申请' : '商户合作认证申请信息已提交,请勿重复申请'); + } + + $data = [ + 'uniacid' => $_W['uniacid'], + 'storeid' => $storeid, + 'name' => trim($name), + 'position' => trim($position), + 'mobile' => $mobile, + 'create_time' => time() + ]; + + $insertRes = pdo_insert(PDO_NAME . 'merchant_certified',$data); + if (!$insertRes) $this->renderError('认证申请失败'); + $this->renderSuccess('已提交申请'); + } else { + if (empty($storeid)) $storeid = pdo_getcolumn(PDO_NAME . 'merchantuser',['mid' => $_W['mid']],'storeid'); + + $list = ['name' => '', 'position' => '', 'mobile' => '', 'remark' => '', 'status' => 0]; + # 获取上次审核数据 + $lastRes = pdo_getall(PDO_NAME . 'merchant_certified',['storeid' => $storeid],array_keys($list),'',' check_time desc',1); + foreach ($lastRes as $lastRow) { + $list = $lastRow; + } + + $list['reject'] = $list['remark']; + unset($list['remark']); + + $this->renderSuccess('数据返回成功',$list); + } + } + + /** + * 教师认证申请 + * @return void + */ + public function applyTeacherCertified() { + + global $_W , $_GPC; + + $type = $_GPC['type'] ?: 'get'; // get 获取上次申请数据 set 创建申请 + + $validate = Member::validateMemberIdentity($_W['mid']); + if (!$validate['status']) $this->renderError($validate['msg']); + + if ($type == 'set') { + $name = $_GPC['name']; // 姓名 + $mobile = $_GPC['mobile']; // 手机号 + $code = $_GPC['code']; // 短信验证码 + $school_name = $_GPC['school_name']; // 学校名称 + $faculty = $_GPC['faculty']; // 院系 + $documents = $_GPC['documents']; // 教师工作证件 + + if (empty($name)) $this->renderError('请输入姓名'); + if (empty($mobile)) $this->renderError('请输入手机号'); + if (!preg_match("/^1[3-9]\d{9}$/",$mobile)) $this->renderError('请输入正确的手机号'); + if (empty($school_name)) $this->renderError('请输入学校名称'); + if (empty($faculty)) $this->renderError('请输入院系'); + if (empty($documents)) $this->renderError('请上传教师工作证件'); + + + $nameRes = Filter::init($name,$_W['source'],1); + if ($nameRes['errno'] == 0) $this->renderError('姓名'.$nameRes['message']); + $school_nameRes = Filter::init($school_name,$_W['source'],1); + if ($school_nameRes['errno'] == 0) $this->renderError('学校名称'.$school_nameRes['message']); + $facultyRes = Filter::init($faculty,$_W['source'],1); + if ($facultyRes['errno'] == 0) $this->renderError('院系'.$facultyRes['message']); + $documentsRes = Filter::init($documents,$_W['source'],2); + if($documentsRes['errno'] == 0) $this->renderError('教师工作证件'.$documentsRes['message']); + + $this->checkCode($mobile,$code); + + $queryRes = pdo_get(PDO_NAME . 'member_teacher_certified',['mid'=>$_W['mid'],'status' => [0,1]],'status'); + if ($queryRes) { + $this->renderError($queryRes['status'] == 1 ? '教师认证申请已通过,请勿重复申请' : '教师认证申请信息已提交,请勿重复申请'); + } + + $data = [ + 'uniacid' => $_W['uniacid'], + 'mid' => $_W['mid'], + 'name' => trim($name), + 'mobile' => trim($mobile), + 'school_name' => trim($school_name), + 'faculty' => trim($faculty), + 'documents' => trim($documents), + 'create_time' => time() + ]; + + $insertRes = pdo_insert(PDO_NAME . 'member_teacher_certified',$data); + if (!$insertRes) $this->renderError('认证申请失败'); + $this->renderSuccess('已提交申请'); + } else { + + $list = ['name' => '', 'mobile' => '', 'school_name' => '', 'faculty' => '', 'documents' => '', 'remark' => '', 'status' => 0]; + # 获取上次审核数据 + $lastRes = pdo_getall(PDO_NAME . 'member_teacher_certified',['mid' => $_W['mid']],array_keys($list),'',' certified_time desc',1); + foreach ($lastRes as $lastRow) { + $lastRow['documents'] = tomedia($lastRow['documents']); + $list = $lastRow; + } + $list['reject'] = $list['remark']; + unset($list['remark']); + + $this->renderSuccess('数据返回成功',$list); + } + + } + + /** + * 达人认证申请 + * @return void + */ + public function applyBloggerCertified() { + + global $_W , $_GPC; + + $type = $_GPC['type'] ?: 'get'; // get 获取上次申请数据 set 创建申请 + + $validate = Member::validateMemberIdentity($_W['mid']); + if (!$validate['status']) $this->renderError($validate['msg']); + + if ($type == 'set') { + $name = $_GPC['name']; // 姓名/昵称 + $mobile = $_GPC['mobile']; // 联系电话 + $code = $_GPC['code']; // 短信验证码 + $screenshot = $_GPC['screenshot']; // 请上传其他平台粉丝截图 + + if (empty($name)) $this->renderError('请输入姓名'); + if (empty($mobile)) $this->renderError('请输入手机号'); + if (!preg_match("/^1[3-9]\d{9}$/",$mobile)) $this->renderError('请输入正确的手机号'); + if (empty($screenshot)) $this->renderError('请上传其他平台粉丝截图'); + + $nameRes = Filter::init($name,$_W['source'],1); + if ($nameRes['errno'] == 0) $this->renderError('姓名'.$nameRes['message']); + $screenshotRes = Filter::init($screenshot,$_W['source'],2); + if($screenshotRes['errno'] == 0) $this->renderError('其他平台粉丝截图'.$screenshotRes['message']); + + $this->checkCode($mobile,$code); + + $queryRes = pdo_get(PDO_NAME . 'member_daren_certified',['mid'=>$_W['mid'],'status' => [0,1]],'status'); + if ($queryRes) { + $this->renderError($queryRes['status'] == 1 ? '达人认证申请已通过,请勿重复申请' : '达人认证申请信息已提交,请勿重复申请'); + } + + $data = [ + 'uniacid' => $_W['uniacid'], + 'mid' => $_W['mid'], + 'name' => trim($name), + 'mobile' => $mobile, + 'screenshot' => $screenshot, + 'create_time' => time() + ]; + + $insertRes = pdo_insert(PDO_NAME . 'member_daren_certified',$data); + if (!$insertRes) $this->renderError('认证申请失败'); + $this->renderSuccess('已提交申请'); + } else { + + $list = ['name' => '', 'mobile' => '', 'screenshot' => '', 'remark' => '', 'status' => 0]; + # 获取上次审核数据 + $lastRes = pdo_getall(PDO_NAME . 'member_daren_certified',['mid' => $_W['mid']],array_keys($list),'',' certified_time desc',1); + foreach ($lastRes as $lastRow) { + $lastRow['screenshot'] = tomedia($lastRow['screenshot']); + $list = $lastRow; + } + $list['reject'] = $list['remark']; + unset($list['remark']); + + $this->renderSuccess('数据返回成功',$list); + } + } + + /** + * 短信验证码验证 + * @param $mobile + * @param $code + * @return void + */ + private function checkCode($mobile,$code) { + $pin_info = pdo_get('wlmerchant_pincode' , ['mobile' => $mobile]); + if (empty($pin_info)) { + $this->renderError('验证码错误'); + } + if ($pin_info['time'] < time() - 300) { + $this->renderError('验证码已过期,请重新获取'); + } + if ($code != $pin_info['code']) $this->renderError('验证码错误'); + } +} \ No newline at end of file diff --git a/addons/weliam_smartcity/api/CultivateClass.php b/addons/weliam_smartcity/api/CultivateClass.php new file mode 100644 index 0000000..6244fdd --- /dev/null +++ b/addons/weliam_smartcity/api/CultivateClass.php @@ -0,0 +1,316 @@ +renderSuccess('数据返回成功', $list); + } + + /** + * 获取子级分类数据 + */ + public function getCultivateClassInfo() + { + global $_W, $_GPC; + + $cc_id = $_GPC['cc_id']; + + $list = Category::getSingleCategory($cc_id, ['id', 'name', 'advs']); + + if ($list['advs']) { + $list['advs'] = unserialize($list['advs']); + foreach ($list['advs'] as &$val) $val['thumb'] = tomedia($val['thumb']); + } + + $field = ['video_link', 'id', 'title', 'likeids', 'likenum', 'share','video_cover']; + $videoRes = Category::categoryVideoAll($list['id'], $field, true, $_W['mid']); + $list['video'] = $videoRes['list']; + + $this->renderSuccess('数据返回成功', $list); + } + + /** + * 获取招聘工作分类 + */ + public function cultivateClassList() + { + global $_GPC; + if ($_GPC['job_type']) { + $list = Category::getCategoryRecruit($_GPC['job_type']); + $this->renderSuccess('数据返回成功', $list); + } + $this->renderError('分类参数不存在'); + } + + /** + * 获取商品类型分类 + */ + public function getStoreCategory() + { + $list = Category::getStoreCategory(); + $this->renderSuccess('数据返回成功', $list); + } + + /** + * 获取商品类型子集分类 + */ + public function getStoreCategoryChild() + { + global $_W, $_GPC; + $cc_id = $_GPC['cc_id']; + if (empty($cc_id) || !is_numeric($cc_id)) $this->renderError('缺少分类id'); + $list = Category::getChildCategoryAll($cc_id, ['id', 'name']); + if ($list) $this->renderSuccess('数据返回成功', $list); + else $this->renderSuccess(2, '数据为空'); + } + + /** + * Comment: 分类视频点赞操作 + * Author: whj + * Date: 2023/6/30 10:12 + */ + public function fabulous() + { + global $_W, $_GPC; + #1、参数接收 + $id = $_GPC['id']; + if (empty($id) || !is_numeric($id)) $this->renderError('缺少参数:id');//视频id + #2、获取帖子的点赞信息 + $info = pdo_get(PDO_NAME . "cultivate_class_video", ['id' => $id], ['likeids', 'likenum']); + $ids = unserialize($info['likeids']); + $num = count($ids); + #3、判断是否为重复操作 + if (is_array($ids) && $num > 0) { + if (in_array($_W['mid'], $ids)) { + #4、取消点赞的操作 + $ids = array_flip($ids); + unset($ids[$_W['mid']]); + $ids = array_flip($ids); + $likenum = $info['likenum'] - 1; + } else { + $ids = array_values($ids);//初始化数组 重新生成键值 从0开始 + $ids[$num] = $_W['mid']; + $likenum = $info['likenum'] + 1; + } + } else { + $ids[$num] = $_W['mid']; + $likenum = $info['likenum'] + 1; + } + #5、点赞成功的操作 + $res = pdo_update(PDO_NAME . "cultivate_class_video", ['likeids' => serialize($ids), 'likenum' => $likenum], ['id' => $id]); + if ($res) $this->renderSuccess(); + $this->renderError(); + } + + /** + * Comment: 分享时记录分享数量 + * Author: zzw + * Date: 2023/6/30 10:30 + */ + public function shareNum() + { + global $_W, $_GPC; + #1、参数获取 + $id = $_GPC['id'] or $this->renderError('缺少参数:id'); + #2、获取当前分享数量 + $shareNum = pdo_getcolumn(PDO_NAME . "cultivate_class_video", ['id' => $id], 'share'); + $totalNum = intval($shareNum) + 1; + #2、修改分享数量 + pdo_update(PDO_NAME . "cultivate_class_video", ['share' => $totalNum], ['id' => $id]); + + $this->renderSuccess('记录成功'); + } + + /** + * Comment: 评论接口 + * Author: whj + * Date: 2023/6/30 10:30 + */ + public function comment() + { + global $_W,$_GPC; + //判断是否绑定手机 + $mastmobile = unserialize($_W['wlsetting']['userset']['plugin']); + if (empty($_W['wlmember']['mobile']) && in_array('private',$mastmobile)){ + $this->renderError('未绑定手机号'); + } + #1、参数接收 + $video_id = $_GPC['video_id'] OR $this->renderError('缺少参数:video_id') ;//视频id + $text = $_GPC['text'] OR $this->renderError('请输入评论内容!') ;//评论内容 + $pid = $_GPC['pid'] ?: 0;//父id + $oneid = $_GPC['oneid'] ?: 0;//第1级评论id + //判断文本内容是否非法 + $textRes = Filter::init($text,$_W['source'],1); + if ($textRes['errno'] == 0) $this->renderError($textRes['message']); + #2、判断用户是否为黑名单用户 + $this->checkBlack(); + #3、评论信息拼装 + $data['uniacid'] = $_W['uniacid']; + $data['aid'] = $_W['aid']; + $data['video_id'] = $video_id; + $data['content'] = base64_encode($text); + $data['mid'] = $_W['mid']; + $data['pid'] = $pid; + $data['oneid'] = $oneid; + $data['createtime'] = time(); + //判断是否需要审核 + $settings = Setting::wlsetting_read('comment_set'); + if($settings['videoComment'] == 1) $data['status'] = 1; + #4、保存评论内容 + $res = pdo_insert(PDO_NAME."cultivate_class_comment",$data); + if($res){ + $cid = pdo_insertid(); + # 回复帖子消息推送 + if (!empty($pid)) { + $parentRes = pdo_get(PDO_NAME .'cultivate_class_comment',['id' => $pid],'mid'); + Category::setReplyModelInfo($video_id,$cid,$_W['mid'],$parentRes['mid']); + } + $this->renderSuccess('评论成功',['cid' => $cid,'amid' => $data['mid']]); + } else { + $this->renderError('评论失败,请稍后重试'); + } + } + + + /** + * Comment: 编辑或删除评论信息 + * Author: wlf + * Date: 2022/02/09 11:25 + */ + public function changeComment(){ + global $_W,$_GPC; + $this->checkBlack(); + $id = $_GPC['id'] OR $this->renderError('缺少参数:id');//评论id + $type = $_GPC['type'] ? : 0; // 1修改 0删除 + if($type > 0){ + $text = $_GPC['text'] OR $this->renderError('请输入修改内容!');//评论内容 + //判断文本内容是否非法 + $textRes = Filter::init($text,$_W['source'],1); + if($textRes['errno'] == 0){ + $this->renderError($textRes['message']); + } + $data['content'] = base64_encode($text); + //判断是否需要审核 + $set = Setting::agentsetting_read('pocket');// <-- replace --> // + if($set['comment_reply'] == 1) $data['status'] = 0; + $res = pdo_update(PDO_NAME .'cultivate_class_comment',$data,['id' => $id]); + + }else{ + $res = $this->treeDeleteComment($id); + } + if($res > 0){ + $this->renderSuccess('操作成功'); + }else{ + $this->renderError('操作失败,请稍后重试'); + } + } + + /** + * 递归删除评论 + * @param $id + * @return false|mixed + */ + protected function treeDeleteComment($id) + { + global $_W; + if (empty($id)) return false; + $arr = pdo_getall(PDO_NAME . 'cultivate_class_comment' , ['uniacid' => $_W['uniacid'] , 'pid' => $id]); + if (empty($arr)) return pdo_delete(PDO_NAME . 'cultivate_class_comment' , ['uniacid' => $_W['uniacid'] , 'id' => $id]); + foreach ($arr as $key => $value) { + if (!$this->treeDeleteComment($value['id'])) return false; + } + return pdo_delete(PDO_NAME . 'cultivate_class_comment' , ['uniacid' => $_W['uniacid'] , 'id' => $id]); + } + + /** + * Comment: 判断用户是否被加入黑名单 + * Author: wlf + * Date: 2020/06/28 16:28 + */ + public function checkBlack(){ + global $_W; + $flag = pdo_getcolumn(PDO_NAME.'pocket_blacklist',array('uniacid'=>$_W['uniacid'],'mid'=>$_W['mid'],'aid'=>$_W['aid']),'id'); + if(!empty($flag)){ + $tips = $_W['wlsetting']['userset']['black_desc'] ? : '您被禁止评论,请联系客服'; + $this->renderError($tips); + } + } + + /** + * 获取视频评论 + * @return void + */ + public function getVideoComment() + { + global $_W,$_GPC; + + $mid = $_W['mid']; + $oneid = $_GPC['oneid'] ?: 0; + $pindex = $_GPC['pindex'] ?: 1; + $psize = $_GPC['psize'] ?: 10; + $video_id = $_GPC['video_id']; + if (empty($video_id) || !is_numeric($video_id)) $this->renderError('缺少参数:video_id'); + + // 第一级评论 + $commentWhere = ['aid' => $_W['aid'],'video_id' => $video_id,'oneid' => $oneid, 'status' => 1]; + + $commentData = Category::getVideoComment($commentWhere,$mid,$pindex,$psize); + $list = $commentData['list']; + $total = $commentData['total']; + $this->renderSuccess('数据返回成功',['list' => $list,'total' => $total]); + } + + /** + * Comment: 分类视频点赞操作 + * Author: whj + * Date: 2023/6/30 10:12 + */ + public function commentFabulous() + { + global $_W, $_GPC; + #1、参数接收 + $id = $_GPC['id']; + if (empty($id) || !is_numeric($id)) $this->renderError('缺少参数:id');//视频id + #2、获取帖子的点赞信息 + $info = pdo_get(PDO_NAME . "cultivate_class_comment", ['id' => $id], ['likeids', 'likenum']); + $ids = unserialize($info['likeids']); + $num = count($ids); + #3、判断是否为重复操作 + if (is_array($ids) && $num > 0) { + if (in_array($_W['mid'], $ids)) { + #4、取消点赞的操作 + $ids = array_flip($ids); + unset($ids[$_W['mid']]); + $ids = array_flip($ids); + $likenum = $info['likenum'] - 1; + } else { + $ids = array_values($ids);//初始化数组 重新生成键值 从0开始 + $ids[$num] = $_W['mid']; + $likenum = $info['likenum'] + 1; + } + } else { + $ids[$num] = $_W['mid']; + $likenum = $info['likenum'] + 1; + } + #5、点赞成功的操作 + $res = pdo_update(PDO_NAME . "cultivate_class_comment", ['likeids' => serialize($ids), 'likenum' => $likenum], ['id' => $id]); + if ($res) $this->renderSuccess(); + $this->renderError(); + } +} \ No newline at end of file diff --git a/addons/weliam_smartcity/api/Goods.php b/addons/weliam_smartcity/api/Goods.php new file mode 100644 index 0000000..f6dd59b --- /dev/null +++ b/addons/weliam_smartcity/api/Goods.php @@ -0,0 +1,711 @@ +renderError('缺少参数:商品id'); + if(empty($type)) $this->renderError('缺少参数:商品类型'); + #2、调用方法获取公共商品数据信息 + WeliamWeChat::browseRecord($type, $id);//记录当前商品的浏览记录 + $info = WeliamWeChat::getHomeGoods($type, $id); + if(empty($info['id'])){ + $this->renderError('商品不存在或已被删除',['url'=>h5_url('pages/mainPages/index/index')]); + } + #unset($info['address']); + #unset($info['storename']); + #3、获取商品补充数据信息 + switch ($type) { + case 1: + $tableName = "rush_activity"; + $table = tablename(PDO_NAME."rush_activity"); + $field = 'paidid,drawid,thumbs,detail,`describe`,pv,creditmoney,threestatus,pftotherinfo,alldaylimit,daylimit,monthlimit,usedatestatus,week,day,tag,isdistri,retainage,share_title,share_image,share_desc,lp_status,lp_set,unit,is_describe_tip,bgmusic,videourl'; + $commentPlugin = 'rush'; + $saletype = 1; + break;//抢购商品 + case 2: + $tableName = "groupon_activity"; + $table = tablename(PDO_NAME."groupon_activity"); + $field = 'paidid,drawid,thumbs,detail,`describe`,pv,creditmoney,threestatus,pftotherinfo,alldaylimit,daylimit,usedatestatus,week,day,tag,isdistri,retainage,share_title,share_image,share_desc,unit,is_describe_tip,bgmusic,videourl'; + $commentPlugin = 'groupon'; + $saletype = 2; + break;//团购商品 + case 3: + $tableName = "fightgroup_goods"; + $table = tablename(PDO_NAME."fightgroup_goods"); + $field = 'paidid,drawid,adv as thumbs,detail,pv,alldaylimit,creditmoney,daylimit,usedatestatus,week,day,tag,aloneprice,limitstarttime as starttime,limitendtime as endtime,isdistri,share_title,share_image,share_desc,`describe`,unit,is_describe_tip,bgmusic,videourl'; + $commentPlugin = 'wlfightgroup'; + $saletype = 3; + break;//拼团商品 + case 4: + $tableName = "package"; + $table = tablename(PDO_NAME."package"); + $field = '`describe`,pv,usedatestatus,week,day'; + $commentPlugin = 'package'; + $saletype = 0; + break;//大礼包 + case 5: + $tableName = "couponlist"; + $table = tablename(PDO_NAME."couponlist"); + $field = 'paidid,drawid,goodsdetail as detail,description as `describe`,pv,creditmoney,alldaylimit,daylimit,usedatestatus,week,day,is_charge,isdistri,starttime,is_describe_tip,endtime,time_type,adv as thumbs'; + $commentPlugin = 'coupon'; + $saletype = 4; + break;//优惠券 + case 6: + $tableName = "halfcardlist"; + $table = tablename(PDO_NAME."halfcardlist"); + $field = 'detail,`limit` as `describe`,pv'; + $commentPlugin = 'halfcard'; + $saletype = 0; + break;//折扣卡 + case 7: + $tableName = "bargain_activity"; + $table = tablename(PDO_NAME."bargain_activity"); + $field = 'paidid,drawid,thumbs,`describe`,detail,pv,creditmoney,usedatestatus,week,day,isdistri,share_title,share_image,share_desc,unit,is_describe_tip,bgmusic,videourl'; + $commentPlugin = 'bargain'; + $info['vipprice'] = $info['price'] - $info['discount_price']; + $saletype = 5; + break;//砍价商品 + case 8: + $tableName = "consumption_goods"; + $table = tablename(PDO_NAME."consumption_goods"); + $field = 'usedatestatus,week,day,chance'; + $commentPlugin = 'consumption'; + $info['logo'] = $info['thumb']; + $saletype = 0; + break;//积分商品 + } + if(!empty($field)) { + $where = " WHERE uniacid = {$_W['uniacid']} AND id = {$id}"; + $goods = pdo_fetch("SELECT {$field} FROM " . $table . $where); + $info = array_merge($info , $goods); + //修改商品人气(浏览量)信息 + $pv = intval($info['pv']) + 1; + pdo_update(PDO_NAME.$tableName,['pv'=>$pv],['id'=>$id]); + } + #4、处理商品数据信息 + //分享信息的处理 + $info['share_title'] = $info['share_title'] ? : $info['goods_name']; + $info['share_image'] = tomedia($info['share_image']) ? : $info['logo']; + $info['share_desc'] = $info['share_desc'] ? : ''; + //处理轮播图信息 + $info['thumbs'] = is_array(unserialize($info['thumbs'])) ? unserialize($info['thumbs']) : []; + if(is_array($info['thumbs']) && count($info['thumbs']) > 0){ + foreach ($info['thumbs'] as $thumbKey => &$thumbVal) { + $thumbVal = tomedia($thumbVal); + } + } + //视频信息 + if(!empty($info['videourl'])){ + $info['videourl'] = tomedia($info['videourl']); + } + //处理商品标签信息 + if($info['tag']){ + $tag = unserialize($info['tag']); + if(is_array($tag) && count($tag) > 0){ + if(count($tag) > 1){ + $tagIds = implode(',',$tag); + $tagWhere = " WHERE id IN ({$tagIds}) "; + }else{ + $tagWhere = " WHERE id = {$tag[0]} "; + } + $tagList = pdo_fetchall("SELECT title,content FROM ".tablename(PDO_NAME."tags").$tagWhere); + if(is_array($tagList) && count($tagList) > 0){ + $info['tag_list'] = array_column($tagList,'title'); + $info['tagslist'] = $tagList; + } + } + unset($info['tag']); + } + if($info['appointstatus']>0){ + $stagt = '需提前预约'; + $info['tag_list'][] = $stagt; + if($info['appointment'] > 0){ + $info['tagslist'][] = array( 'title'=> $stagt,'content'=> '消费本商品请至少提前'.$info['appointment'].'小时联系商家预约'); + }else{ + $info['tagslist'][] = array( 'title'=> $stagt,'content'=> '消费本商品请提前联系商家预约'); + } + } + if($info['allowapplyre']>0){ + $stagt = '不退款商品'; + $info['tag_list'][] = $stagt; + $info['tagslist'][] = array( 'title'=> $stagt,'content'=> '本商品是特殊商品,不支持购买后退款操作'); + } + if($info['creditmoney']>0){ + $jifen = $_W['wlsetting']['trade']['credittext'] ? : '积分'; + $stagt = $jifen.'抵扣'; + $info['tag_list'][] = $stagt; + $info['tagslist'][] = array('title'=> $stagt,'content'=> '每份商品最多可以使用'.$jifen.'抵扣'.$info['creditmoney'].'元'); + } + if($info['drawid'] > 0){ + $draw = pdo_get('wlmerchant_luckydraw',array('id' => $info['drawid'],'status' => 1),array('title','status')); + if(!empty($draw)){ + $info['tag_list'][] = '抽奖活动'; + $info['tagslist'][] = array('title'=> '抽奖活动','content'=> '购买商品核销或收货以后可以参与【'.$draw['title'].'】抽奖活动'); + } + } + if($info['paidid'] > 0){ + $paid = pdo_get('wlmerchant_payactive',array('id' => $info['paidid'],'status' => 1),array('title')); + if(!empty($paid)){ + $info['tag_list'][] = '支付有礼'; + $info['tagslist'][] = array('title'=> '支付有礼','content'=> '购买商品支付以后可以参与【'.$paid['title'].'】活动奖励'); + } + } + //处理商品详情/购买须知 + if(!empty($info['detail']) && is_base64($info['detail'])) $info['detail'] = htmlspecialchars_decode(base64_decode($info['detail'])); + else if(!empty($info['detail'])) $info['detail'] = htmlspecialchars_decode($info['detail']); + + if(!empty($info['describe']) && is_base64($info['describe'])) $info['describe'] = htmlspecialchars_decode(base64_decode($info['describe'])); + else if(!empty($info['describe'])) $info['describe'] = htmlspecialchars_decode($info['describe']); + //处理音乐信息 + if($info['bgmusic']) $info['bgmusic'] = tomedia($info['bgmusic']); + #5、获取商户信息 + if($info['sid'] > 0){ + $shop = pdo_fetch("SELECT id as sid,logo,address,mobile,storename,storehours,location FROM ". + tablename(PDO_NAME."merchantdata")." WHERE id = {$info['sid']} "); + $shop['logo'] = tomedia($shop['logo']); + $storehours = unserialize($shop['storehours']); + $shop['storehours'] = $storehours['startTime'].' - '.$storehours['endTime']; + if(!empty($storehours['startTime'])){ + $shop['storehours'] = $storehours['startTime'] . ' - ' . $storehours['endTime']; + }else{ + $shop['storehours'] = ''; + foreach($storehours as $hk => $hour){ + if($hk > 0){ + $shop['storehours'] .= ','.$hour['startTime'] . ' - ' . $hour['endTime']; + }else{ + $shop['storehours'] .= $hour['startTime'] . ' - ' . $hour['endTime']; + } + } + } + $shop['location'] = unserialize($shop['location']); + $info['shop'] = $shop; + }else{ + $info['sid'] = 0; + } + //认证 + if(p('attestation')){ + $info['attestation'] = Attestation::checkAttestation(2,$info['sid']); + }else{ + $info['attestation'] = 0; + } + #6、获取商品评价信息 + $comment = pdo_fetchall("SELECT headimg,nickname,createtime,star,pic,text,replytextone,replypicone FROM ".tablename(PDO_NAME.'comment')."WHERE gid = {$id} AND plugin = '{$commentPlugin}' AND status = 1 AND (checkone = 2 OR mid = {$mid}) ORDER BY createtime DESC LIMIT 5 "); + //处理评论信息 + foreach($comment as $commentKey => &$commentVal){ + //用户评论图片的处理 + $commentPic = unserialize($commentVal['pic']); + if(is_array($commentPic) && count($commentPic) > 0){ + foreach($commentPic as $picKey => &$picVal){ + if($picVal) $picVal = tomedia($picVal); + else unset($commentPic[$picKey]); + } + }else{ + $commentPic = []; + } + $commentVal['pic'] = array_values($commentPic); + //商家回复信息图片的处理 + $replyPic = unserialize($commentVal['replypicone']); + if(is_array($replyPic) && count($replyPic) > 0){ + foreach($replyPic as $replyPicKey => &$replyPicVal){ + $replyPicVal = tomedia($replyPicVal); + } + }else{ + $replyPic = []; + } + $commentVal['replypicone'] = array_values($replyPic); + } + $info['comment'] = $comment; + #7、获取拼团商品详情时 获取拼团已开团但未成团的信息列表 + if($type == 3){ + $info['group_list'] = pdo_fetchall("SELECT a.id,a.failtime,a.neednum,a.lacknum,m.nickname,m.avatar FROM " .tablename(PDO_NAME."fightgroup_group") + ." as a RIGHT JOIN " .tablename(PDO_NAME."order") + ." as b ON a.id = b.fightgroupid RIGHT JOIN ".tablename(PDO_NAME."member") + ." as m ON b.mid = m.id " + ." WHERE a.goodsid = {$id} AND a.uniacid = {$_W['uniacid']} AND a.status = 1 " + ." GROUP BY b.fightgroupid ORDER BY a.starttime ASC LIMIT 5 "); + } + #8、分销助手,获取当前用户分享最高可以获得的佣金 + if(empty($info['isdistri'])){ + $info['dis_assistant'] = WeliamWeChat::getDisInfo($type,$id); + }else{ + $info['dis_assistant'] = []; + } + #10、社群信息获取 + if ($info['communityid'] > 0) { + $community = Commons::getCommunity($info['communityid']); + $info['community'] = is_array($community) ? $community : []; + } + #11、判断用户是否已经参与砍价 + if($type == 7){ + $info['is_participate'] = pdo_getcolumn(PDO_NAME."bargain_userlist" + ,['activityid'=>$id,'mid'=>$_W['mid']] ,'id'); + } + #12、判断当前商品的状态:1=未开始,2=已开始,3=已结束 + if(in_array($type,[1,2,3,5,7])){ + //基本判断 + if($info['starttime'] > time()){ + //开始时间大于当前时间 未开始 + $info['sales_status'] = 1; + }else if($info['endtime'] > time()){ + //结束时间大于当前时间 已开始未结束 + $info['sales_status'] = 2; + }else if($info['endtime'] < time()){ + //结束时间小于当前时间 已结束 + $info['sales_status'] = 3; + } + //卡券补丁判断 时间段为领取后限制则固定为 已开始未结束 + if($type == 5 && $info['time_type'] == 2){ + $info['sales_status'] = 2; + } + if($info['usedatestatus'] > 0 ){ + $stagt = '定时发售'; + if($info['usedatestatus'] == 1){ + $content = '此商品每周'; + $week = unserialize($info['week']); + foreach($week as $key => $we){ + switch ($we){ + case '1': + $content .= '星期一'; + break; + case '2': + if($key == 0){ + $content .= '星期二'; + }else{ + $content .= ',星期二'; + } + break; + case '3': + if($key == 0){ + $content .= '星期三'; + }else{ + $content .= ',星期三'; + } + break; + case '4': + if($key == 0){ + $content .= '星期四'; + }else{ + $content .= ',星期四'; + } + break; + case '5': + if($key == 0){ + $content .= '星期五'; + }else{ + $content .= ',星期五'; + } + break; + case '6': + if($key == 0){ + $content .= '星期六'; + }else{ + $content .= ',星期六'; + } + break; + case '7': + if($key == 0){ + $content .= '星期天'; + }else{ + $content .= ',星期天'; + } + break; + } + } + }else{ + $content = '此商品每月'; + $day = unserialize($info['day']); + foreach($day as $key => $dd){ + if($key == 0){ + $content .= $dd.'号'; + }else{ + $content .= ','.$dd.'号'; + } + } + } + $content .= '开放购买'; + $info['tag_list'][] = $stagt; + $info['tagslist'][] = array( 'title'=> $stagt,'content'=> $content); + if($info['sales_status'] == 2){ + $check = WeliamWeChat::checkUseDateStatus($info['usedatestatus'],$info['week'],$info['day']); + if(empty($check)){ + $info['sales_status'] = 3; + } + } + } + } + $supar = []; + $supar[] = $info['stk']; + #6、判断用户购买限制 + //亿企达数量处理 + if($info['threestatus'] == 1){ + $pftotherinfo = unserialize($info['pftotherinfo']); + if($pftotherinfo['limitCountMax'] > 0){ + $supar[] = $pftotherinfo['limitCountMax']; + } + } + if ($info['buy_limit'] > 0 && $saletype > 0) { + $userBuyNum = WeliamWeChat::getSalesNum($saletype,$id,0,1,$_W['mid']); + $supar[] = $info['buy_limit'] - intval($userBuyNum);//当前用户还能购买的数量 + } + //每日限量 + if($info['daylimit']>0 || $info['alldaylimit']>0){ + $stagt = '每日限量'; + $info['tag_list'][] = $stagt; + $daylimittips = '此商品'; + if($info['alldaylimit']>0){ + $daylimittips .= '每天限量供应'.$info['alldaylimit'].'份.'; + } + if($info['daylimit']>0){ + $daylimittips .= '每天每人只能购买'.$info['daylimit'].'份.'; + } + $info['tagslist'][] = array( 'title'=> $stagt,'content'=> $daylimittips); + if($info['sales_status'] == 2){ + $today = strtotime(date('Y-m-d')); + if($info['alldaylimit']>0 ){ + $daysalenum = WeliamWeChat::getSalesNum($saletype,$id,0,1,0,$today); + $sup = $info['alldaylimit'] - intval($daysalenum); + $supar[] = $sup; + if($daysalenum >= $info['alldaylimit']){ + $info['sales_status'] = 4; + } + $info['todayselenum'] = $daysalenum; + } + if($info['daylimit']>0 && $_W['mid'] > 0 ){ + $daysalenum = WeliamWeChat::getSalesNum($saletype,$id,0,1,$_W['mid'],$today); + $sup = $info['daylimit'] - intval($daysalenum); + $supar[] = $sup; + if($daysalenum >= $info['daylimit']){ + $info['sales_status'] = 4; + } + } + } + } + //每月限量 + if($info['monthlimit']>0 && $_W['mid'] > 0){ + $stagt = '每月限量'; + $info['tag_list'][] = $stagt; + $monthlimittips = '此商品每月每人只能购买'.$info['monthlimit'].'份.'; + $info['tagslist'][] = array( 'title'=> $stagt,'content'=> $monthlimittips); + if($info['sales_status'] == 2) { + $tomonth = strtotime(date('Y-m')); + $monthsalenum = WeliamWeChat::getSalesNum($saletype,$id,0,1,$_W['mid'],$tomonth); + $sup = $info['monthlimit'] - intval($monthsalenum); + $supar[] = $sup; + if($monthsalenum >= $info['monthlimit']){ + $info['sales_status'] = 4; + } + } + } + + //积分商品判断 + if($type == 8){ + $supar = []; + if ($info['chance'] > 0) { + $times = pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('wlmerchant_consumption_record') . " WHERE uniacid = {$_W['uniacid']} AND goodsid = {$id} AND mid = {$_W['mid']} "); + $sup = $info['chance'] - $times; + $supar[] = $sup; + } + //判断库存 + $cctotal = pdo_fetchcolumn("SELECT SUM(num) FROM " . tablename(PDO_NAME . "order") . " WHERE plugin = 'consumption' AND fkid = {$id} AND status != 5 AND status != 7"); + $sup = $info['stock'] - $cctotal; + $supar[] = $sup; + } + $info['user_limit_num'] = min($supar); + if($info['user_limit_num'] < 0){ + $info['user_limit_num'] = 0; + } + //尾款 + if($info['retainage'] > 0){ + $stagt = '核销付尾款'; + $info['tag_list'][] = $stagt; + $info['tagslist'][] = array( 'title'=> $stagt,'content'=> '此商品使用时必须再向商户支付尾款:'.$info['retainage'].'元'); + } + #13、是否开启一卡通 + if($_W['wlsetting']['halfcard']['status'] > 0 && $info['vipstatus'] > 0){ + $info['is_open_vip'] = 1; + }else{ + $info['is_open_vip'] = 0; + } + #14、获取当前商品的浏览记录 + $browseRecord = array_column(WeliamWeChat::getBrowseRecord($type,$id), 'avatar'); + $info['user_list'] = is_array($browseRecord) ? $browseRecord :[]; + #15、判断是否开启阶梯价(目前仅抢购存在) 是否开启阶梯价(0=关闭 1=开启) + if($type == 1){ + if($info['lp_status'] == 1){ + $info['lp_set'] = is_array(unserialize($info['lp_set'])) ? unserialize($info['lp_set']) :[]; + if(count($info['lp_set']) > 0){ + $updateStatus = 0; + $nowStatus = 0; + $newArr = []; + $buyNum = $info['buy_num']; + $allsalenum = intval($info['allsalenum']); + foreach ($info['lp_set'] as $lpKey => &$lpVal){ + $lpVal['max'] = intval($lpVal['max']) + $allsalenum; + //修改当前商品价格、会员价格、会员优惠 + if($info['buy_num'] < $lpVal['max'] && $updateStatus == 0){ + $info['price'] = $lpVal['price']; + //$info['vipprice'] = $lpVal['vip_price']; + //$info['discount_price'] = sprintf("%.2f", ($lpVal['price'] - $lpVal['vip_price'])); + $updateStatus = 1; + } + //获取最小值 第一个的最小值为0 之后的最小值为前一个区间上限 +1 + $thisMin = intval($lpKey == 0 ? 0 : ($info['lp_set'][$lpKey - 1]['max'])) + 1; + //获取当前区间总共的可销售数量 第一个的可销售总数为其最大区间 之后的可销售总数为当前区间上限 - 前一个区间的上限 + $thisTotal = $lpKey == 0 ? $lpVal['max'] :($lpVal['max'] - $info['lp_set'][$lpKey - 1]['max']); + //获取当前区间的剩余数量 剩余数量为当前区间上限 减去销量 + $surplusTotalStk = ((($lpVal['max'] - $buyNum) >= 0) ? ($lpVal['max'] - $buyNum) : 0); + $thisStk = $surplusTotalStk > $thisTotal ? $thisTotal : $surplusTotalStk ; + //获取当前区间的已售数量 总共的可销售数量 - 剩余数量 + $thisBuyNum = $thisTotal - $thisStk; + //获取当前区间已售百分比 已售数量 / 总共可售数量 + $proportion = sprintf("%.2f",$thisBuyNum/$thisTotal * 100); + //新数组建立 方便移动端循环 + $newArr[$lpKey] = [ + 'this_total' => $thisTotal , + 'price' => sprintf("%.2f" , $lpVal['price']) ,//当前区间的销售价格 + 'min' => intval($thisMin) ,//当前区间的最小值 + 'max' => intval($lpVal['max']) ,//当前区间的最大值 + 'surplus' => intval($thisStk) < 0 ? intval(0) : intval($thisStk) ,//当前区间剩余数量 + 'buy_num' => intval($thisBuyNum) ,//当前区间已售数量 + 'proportion' => $proportion + ]; + //获取当前销售阶段的库存信息 + if($newArr[$lpKey]['surplus'] > 0 && $nowStatus == 0){ + $info['lp_now_stk'] = intval($newArr[$lpKey]['surplus']); + $nowStatus = 1; + } + } + //重新复制 lp_set + $info['lp_set'] = $newArr; + } + }else{ + $info['lp_set'] = []; + } + } + #16、获取使用流程和价格说明 + $settings = Setting::wlsetting_read('orderset'); + $info['info_set'] = [ + 'use_info' => $settings['use_info'] ? htmlspecialchars_decode($settings['use_info']) : '', + 'price_info' => $settings['price_info'] ? htmlspecialchars_decode($settings['price_info']) : '' + ]; + #17、获取图片高度 + $info['imgstyle']['width'] = !empty(trim($_W['wlsetting']['base']['width'])) ? trim($_W['wlsetting']['base']['width']) : 750; + $info['imgstyle']['height'] = !empty(trim($_W['wlsetting']['base']['height'])) ? trim($_W['wlsetting']['base']['height']) : 560; + //删除不需要的多余信息 + unset($info['communityid']); + unset($info['allsalenum']); + unset($info['plugin']); + unset($info['usedatestatus']); + unset($info['week']); + unset($info['day']); + unset($info['daylimit']); + unset($info['monthlimit']); + unset($info['viparray']); + //881定制内容 + $isAuth = Customized::init('diy_userInfo'); + if($isAuth){ + $info['diy_userInfo']['credit'] = $_W['wlmember']['credit2']?$_W['wlmember']['credit2']:'0.00'; + $info['diy_userInfo']['dhurl'] = $_W['wlsetting']['recharge']['dhurl']; + $info['diy_userInfo']['dhtip1'] = $_W['wlsetting']['recharge']['dhtip1']?$_W['wlsetting']['recharge']['dhtip1']:'1乐豆抵用1元'; + $info['diy_userInfo']['dhtip2'] = $_W['wlsetting']['recharge']['dhtip2']?$_W['wlsetting']['recharge']['dhtip2']:'中国移动/中国银行积分可兑换乐豆'; + } + //砍价设置详情 + if($type == 7){ + $barset = Setting::agentsetting_read('bargainset'); + $info['barset']['playtitle'] = $barset['playtitle'] ? : ''; + $info['barset']['playdesc'] = $barset['playdesc'] ? : ''; + $info['barset']['playdetail'] = $barset['playdetail'] ? : ''; + }else{ + $info['barset']['playtitle'] = ''; + $info['barset']['playdesc'] = ''; + $info['barset']['playdetail'] = ''; + } + $this->renderSuccess('商品详细信息',$info); + } + /** + * Comment: 获取在线买单评价表 + * Author: wlf + * Date: 2019/11/25 18:29 + */ + public function getPayOnlieOrder(){ + global $_W,$_GPC; + $id = $_GPC['orderid']; + $order = pdo_get('wlmerchant_order',array('id' => $id),array('sid','price')); + $data['price'] = $order['price']; + $store = pdo_get('wlmerchant_merchantdata',array('id' => $order['sid']),array('storename','logo')); + $data['goods_name'] = $store['storename'].'在线买单'; + $data['logo'] = tomedia($store['logo']); + $this->renderSuccess('订单信息',$data); + } + /** + * Comment: 获取商品推广图文设置信息 + * Author: zzw + * Date: 2019/12/26 10:21 + */ + public function getGoodsExtensionInfo(){ + global $_W,$_GPC; + #1、参数获取 + $id = $_GPC['id'] OR $this->renderError('缺少参数:商品id');//商品id + $type = $_GPC['type'] OR $this->renderError('缺少参数:商品类型');//商品类型:1=抢购 2=团购 3=拼团 4=大礼包 5=优惠券 6=折扣卡 7=砍价商品 8=积分商品 + #2、根据商品类型获取推广文案设置信息 + switch ($type) { + case 1: + $table = tablename(PDO_NAME."rush_activity"); + $field = 'name,thumbs,extension_text,extension_img,oldprice,price,vipprice,vipstatus,viparray'; + break;//抢购商品 + case 2: + $table = tablename(PDO_NAME."groupon_activity"); + $field = 'name,thumbs,extension_text,extension_img,oldprice,price,vipprice,vipstatus,viparray'; + break;//团购商品 + case 3: + $table = tablename(PDO_NAME."fightgroup_goods"); + $field = 'name,adv as thumbs,extension_text,extension_img,price,aloneprice,oldprice,vipstatus,vipdiscount,peoplenum,vipdiscount'; + break;//拼团商品 + case 7: + $table = tablename(PDO_NAME."bargain_activity"); + $field = 'name,thumbs,extension_text,extension_img,oldprice,price,vipprice,vipstatus,viparray'; + break;//砍价商品 + } + $info = pdo_fetch("SELECT {$field} FROM ".$table." WHERE id = {$id} "); + #3、数据处理 + $thumbs = unserialize($info['thumbs']); + $extensionImg = unserialize($info['extension_img']); + //判断推广图片是否存在 不存在使用商品图集 + if (count($extensionImg) > 0 && is_array($extensionImg)) { + $info['extension_img'] = $extensionImg; + } else { + $info['extension_img'] = $thumbs; + } + //循环处理图片 + foreach($info['extension_img'] as &$img){ + $img = tomedia($img); + } + $info['extension_img'] = is_array($info['extension_img']) ? $info['extension_img'] : []; + //判断推广文案是否存在 不存在使用商品名称 + if($info['extension_text']){ + //[昵称] [时间] [商品名称] [原价] [特权类型] [拼团价] [单购价] [会员减免金额] [开团人数] [会员底价] [底价] [活动价] [会员价] + if($type != 3){ + $info['vipdiscount'] = WeliamWeChat::getVipDiscount($info['viparray'],-1); + $info['vipprice'] = sprintf("%.2f",$info['price'] - $info['vipdiscount']); + } + $nickname = $_W['wlmember']['nickname']; + $time = date("Y-m-d H:i:s" , time()); + if ($info['vipstatus'] == 1) $vipstatus = '会员特价'; + else if ($info['vipstatus'] == 2) $vipstatus = '会员特供'; + else $vipstatus = ''; + $info['extension_text'] = str_replace('[昵称]' , $nickname , $info['extension_text']); + $info['extension_text'] = str_replace('[时间]' , $time , $info['extension_text']); + $info['extension_text'] = str_replace('[商品名称]' , $info['name'] , $info['extension_text']); + $info['extension_text'] = str_replace('[原价]' , $info['oldprice'] , $info['extension_text']); + $info['extension_text'] = str_replace('[特权类型]' , $vipstatus , $info['extension_text']); + $info['extension_text'] = str_replace('[活动价]' , $info['price'] , $info['extension_text']); + $info['extension_text'] = str_replace('[会员价]' , $info['vipprice'] , $info['extension_text']); + $info['extension_text'] = str_replace('[拼团价]' , $info['price'] , $info['extension_text']); + $info['extension_text'] = str_replace('[单购价]' , $info['aloneprice'] , $info['extension_text']); + $info['extension_text'] = str_replace('[市场价]' , $info['oldprice'] , $info['extension_text']); + $info['extension_text'] = str_replace('[会员减免金额]' , $info['vipdiscount'] , $info['extension_text']); + $info['extension_text'] = str_replace('[开团人数]' , $info['peoplenum'] , $info['extension_text']); + $info['extension_text'] = str_replace('[会员底价]' , $info['vipprice'] , $info['extension_text']); + $info['extension_text'] = str_replace('[底价]' , $info['price'] , $info['extension_text']); + }else{ + $info['extension_text'] = $info['name'] ? : ''; + } + #4、删除多余的数据 + unset($info['name']); + unset($info['thumbs']); + + $this->renderSuccess('推广信息',$info,1); + } + /** + * Comment: 获取商品评价信息 + * Author: wlf + * Date: 2020/04/10 15:19 + */ + public function getComment(){ + global $_W,$_GPC; + #1、参数获取 + $sid = $_GPC['sid']; //商户id + if(empty($sid)){ + $this->renderError('缺少商户参数,请返回重试'); + } + $plugin = $_GPC['plugin']; //商品插件 + $gid = $_GPC['goodsid']; //商品id + $page = $_GPC['page'] ? $_GPC['page'] : 1; //页码 + $page_start = $page * 10 - 10; + //查询 + $where = " sid = {$sid} AND status = 1 AND (checkone = 2 OR mid = {$_W['mid']})"; + if(!empty($plugin) && !empty($gid)){ + $where .= " AND plugin = '{$plugin}' AND gid = {$gid}"; + } + $data['totalnum'] = pdo_fetchcolumn('SELECT count(id) FROM '.tablename('wlmerchant_comment')." WHERE {$where}"); + $data['totalpage'] = ceil($data['totalnum'] / 10); + $comments = pdo_fetchall("SELECT headimg,nickname,createtime,star,pic,text,replytextone,replypicone,mid FROM ".tablename('wlmerchant_comment')."WHERE {$where} ORDER BY createtime DESC LIMIT {$page_start},10"); + if(!empty($comments)){ + foreach($comments as $commentKey => &$commentVal){ + //用户评论图片的处理 + $commentPic = unserialize($commentVal['pic']); + if(is_array($commentPic) && count($commentPic) > 0){ + foreach($commentPic as $picKey => &$picVal){ + if($picVal) $picVal = tomedia($picVal); + else unset($commentPic[$picKey]); + } + }else{ + $commentPic = []; + } + $commentVal['pic'] = $commentPic; + //商家回复信息图片的处理 + $replyPic = unserialize($commentVal['replypicone']); + if(is_array($replyPic) && count($replyPic) > 0){ + foreach($replyPic as $replyPicKey => &$replyPicVal){ + $replyPicVal = tomedia($replyPicVal); + } + }else{ + $replyPic = []; + } + $commentVal['replypicone'] = $replyPic; + //用户信息处理 + if(!empty($commentVal['mid'])){ + $member = pdo_get('wlmerchant_member',array('id' => $commentVal['mid']),array('nickname','avatar')); + } + if(!empty($member['nickname'])){ + $commentVal['nickname'] = $member['nickname']; + } + if(!empty($member['avatar'])){ + $commentVal['headimg'] = tomedia($member['avatar']) ; + }else{ + $commentVal['headimg'] = tomedia($commentVal['headimg']) ; + } + //处理时间 + $commentVal['createtime'] = date('Y-m-d H:i:s',$commentVal['createtime']); + } + } + $data['commentinfo'] = $comments; + $this->renderSuccess('评论列表',$data); + } + /** + * Comment: 商品分类页面 - 顶部排序分类信息 + * Author: zzw + * Date: 2020/12/7 10:24 + */ + public function getGoodsCateList(){ + global $_W,$_GPC; + //参数信息获取 + $type = $_GPC['type'] ? : 3;//页面类型:3=抢购首页;4=团购首页;6=拼团首页;7=砍价首页;14=活动首页 + //信息获取 + $info = DiyPage::defaultInfo('options2',['type'=>$type]); + + $this->renderSuccess('评论列表',$info); + } + + +} \ No newline at end of file diff --git a/addons/weliam_smartcity/api/Im.php b/addons/weliam_smartcity/api/Im.php new file mode 100644 index 0000000..8bf4500 --- /dev/null +++ b/addons/weliam_smartcity/api/Im.php @@ -0,0 +1,138 @@ +renderSuccess('通讯列表',$data); + } + /** + * Comment: 获取通讯记录 + * Author: zzw + * Date: 2019/8/26 17:42 + */ + public function get(){ + global $_W,$_GPC; + #1、参数接收 + $page = $_GPC['page'] ? : 1; + $pageIndex = $_GPC['page_index'] ? : 10; + $thisId = $_GPC['id'] ? : $_W['mid'];//当前使用者的id:用户id(默认)|商户id + $thisType = $_GPC['type'] ? : 1;// 当前使用者的类型;1=用户(默认);2=商户 + $otherPartyType = $_GPC['other_party_type'] ? : 1;//通讯对象类型;1=用户;2=商户 + $otherPartyId = $_GPC['other_party_id'] or $this->renderError('缺少参数:other_party_id');//通讯对象id + #1、类型一致,id一致 则是给自己发送消息 + if($thisId == $otherPartyId && $thisType == $otherPartyType) $this->renderError("不能给自己发送信息哦",['url'=>h5_url('pages/mainPages/userCenter/userCenter')]); + $sendInfo['send_id'] = $thisId;//发送方id + $sendInfo['send_type'] = $thisType;//发送方类型(1=用户;2=商户) + $sendInfo['receive_id'] = $otherPartyId;//接收人id + $sendInfo['receive_type'] = $otherPartyType;//接收人类型(1=用户;2=商户) + + $data = Im::imRecord($page,$pageIndex,$sendInfo); + #3、修改信息为已读 + //if(is_array($data['list']) && count($data['list']) > 0) Im::is_read(array_column($data['list'],'id'),$thisId); + //修改所有对方发送的通讯信息为已读 + $where = " send_id = {$otherPartyId} AND send_type = {$otherPartyType} AND receive_id = {$thisId} AND receive_type = {$thisType} AND is_read = 0 "; + $sql = " UPDATE ".tablename(PDO_NAME."im")." SET is_read = 1 WHERE {$where} "; + pdo_query($sql); + #4、信息排序 + $sortArr = array_column($data['list'], 'create_time'); + array_multisort($sortArr, SORT_ASC, $data['list']); + #4、获取聊天对象的昵称 1=用户;2=商户 + if($otherPartyType == 1){ + $data['receive_name'] = pdo_getcolumn(PDO_NAME."member",['id'=>$otherPartyId],'nickname'); + }else{ + $data['receive_name'] = pdo_getcolumn(PDO_NAME."merchantdata",['id'=>$otherPartyId],'storename'); + } + + $this->renderSuccess('通讯记录',$data); + } + /** + * Comment: 发送通讯信息 + * Author: zzw + * Date: 2019/8/26 15:48 + */ + public function send (){ + global $_W , $_GPC; + //判断是否绑定手机 + $mastmobile = unserialize($_W['wlsetting']['userset']['plugin']); + if (empty($_W['wlmember']['mobile']) && in_array('private',$mastmobile)){ + $this->renderError('未绑定手机号'); + } + $freeChat = Rights::freeChatRights($_W['mid'],$_GPC['send_type']); + if (!$freeChat) { + $memberIsChat = Rights::memberIsChat($_W['mid']); + if (!$memberIsChat['status']) $this->renderError($memberIsChat['msg'],['is_jump' => 1]); + } + #1、参数接收 + $sendId = $_GPC['send_id'] ? : $_W['mid'];//发送方id + $sendType = $_GPC['send_type'] ? : 1;//发送方类型(1=用户;2=商户) + $type = $_GPC['type'] ? : 0;//内容类型(0=文本信息(默认),1=图片地址,2=视频信息 3=名片 4=简历) + $plugin = $_GPC['plugin'] ? : '';// + !empty($_GPC['receive_id']) ? $receiveId = $_GPC['receive_id'] : $this->renderError('缺少参数:receive_id');//接收人id + !empty($_GPC['receive_type']) ? $receiveType = $_GPC['receive_type'] : $this->renderError('缺少参数:receive_type');//接收人类型(1=用户;2=商户) + !empty($_GPC['content']) ? $content = $_GPC['content'] : $this->renderError('缺少参数:content');//发送内容 + if($sendId == $receiveId && $sendType == $receiveType) $this->renderError("不能给自己发送信息哦"); + #2、信息拼装 + $data['uniacid'] = $_W['uniacid'];// + $data['send_id'] = $sendId;//发送方id + $data['send_type'] = $sendType;//发送方类型(1=用户;2=商户) + $data['receive_id'] = $receiveId;//接收人id + $data['receive_type'] = $receiveType;//接收人类型(1=用户;2=商户) + $data['create_time'] = time();//发送时间(建立时间) + $data['type'] = $type;//内容类型(0=文本信息(默认),1=图片地址,2=视频信息) + $data['plugin'] = $plugin;//通讯插件 + if(empty($data['type'])){ + $data['content'] = htmlspecialchars_decode($content);//发送内容 + }else{ + $data['content'] = $content;//发送内容 + } + + #2、信息记录 + $res = Im::insert($data); + if ($res) $this->renderSuccess('发送成功'); + else $this->renderError('发送失败'); + } + /** + * Comment: 通讯设置 + * Author: zzw + * Date: 2021/3/8 11:57 + */ + public function getSetInfo(){ + global $_W,$_GPC; + //获取基本设置 + //$set = Setting::wlsetting_read('im_set'); + //判断用户是否存在简历信息 + $isResume = pdo_get(PDO_NAME."recruit_resume",['mid' => $_W['mid']]); + //信息拼接 + $data = [ + 'type' => 1, + 'port' => '', + 'mid' => $_W['mid'], + 'is_card' => p('citycard') ? 1 : 0,//是否存在名片插件 0=不存在,1=存在 + 'is_recruit' => p('recruit') ? 1 : 0,//是否存在求职招聘插件 0=不存在,1=存在 + 'is_resume' => $isResume ? 1 : 0,//是否存在简历信息 0=不存在,1=存在 + 'resume_id' => $isResume['id'],//简历id + ]; + + $this->renderSuccess('通讯设置信息',$data); + } +} + + + diff --git a/addons/weliam_smartcity/api/Member.php b/addons/weliam_smartcity/api/Member.php new file mode 100644 index 0000000..47520c2 --- /dev/null +++ b/addons/weliam_smartcity/api/Member.php @@ -0,0 +1,2927 @@ +renderSuccess('获取用户注册设置信息' , $data); + } + /** + * Comment: 用户申请注册账号 + * Author: zzw + * Date: 2019/8/8 11:14 + */ + public function register() + { + global $_W , $_GPC; + #1、参数接收 + $mobile = trim($_GPC['phone']);//手机号 + $password = trim($_GPC['password']);//密码 + $code = trim($_GPC['code']);//验证码 + if (!$mobile) { + $this->renderError('请输入手机号'); + } + if (!$password) { + $this->renderError('请输入登录密码'); + } + //短信验证码登录 判断验证码是否输入正确 + if (empty($_W['wlsetting']['userset']['smsver'])) { + $pin_info = pdo_get('wlmerchant_pincode' , ['mobile' => $mobile]); + if (empty($pin_info)) { + $this->renderError('验证码错误'); + } + if ($pin_info['time'] < time() - 300) { + $this->renderError('验证码已过期,请重新获取' , ['code' => 1]); + } + if ($code != $pin_info['code']) { + $this->renderError('验证码错误'); + } + } + #2、判断是否已经注册 + $have = Member::wl_member_get(['mobile' => $mobile] , ['id'] , false); + if ($have) { + $this->renderError('当前手机已被注册,请直接登录'); + } + #3、生成用户信息数据 + $salt = random(8); + $nickname = substr($mobile , 0 , 3) . '****' . substr($mobile , -4 , 4); + $data2 = [ + 'nickname' => $nickname , + 'mobile' => $mobile , + 'password' => md5($password . $salt) , + 'salt' => $salt , + ]; + $member = Member::wl_member_create($data2 , 'mobile'); + if (!is_error($member)) { + $userinfo['mobile'] = $mobile; + $userinfo['pwd'] = $member['password']; + $userinfo['tokey'] = $member['tokey']; + wl_setcookie('usersign' , $userinfo , 3600 * 24 * 30); + $token = pdo_getcolumn(PDO_NAME . 'login' , ['token' => $userinfo['tokey']] , 'secret_key'); + if (empty($token)) { + $res = Login::generateToken($userinfo['tokey'] , 'login'); + $token = $res['message']; + } + wl_setcookie('user_token' , $token , 3600 * 24 * 30); + $this->renderSuccess('注册成功'); + } + else { + $this->renderError('注册失败'); + } + } + /** + * Comment: 用户登录 + * Author: zzw + * Date: 2019/8/8 13:40 + */ + public function userLogin() + { + global $_W , $_GPC; + #1、参数获取 + $type = $_GPC['type'] ? $_GPC['type'] : 1;//1=账号密码登录 2=短信验证码登录 + $phone = $_GPC['phone'];//手机号 + $pwd = $_GPC['password'];// 登录密码/短信验证码 + $backUrl = urldecode($_GPC['backurl']); + if (!$phone) $this->renderError('请输入登录账号'); + if (!$pwd) $this->renderError($type == 1 ? '请输入密码' : '请输入验证码'); + #2、根据登录方式进行判断是否登录成功 + $member = Member::wl_member_get(['mobile' => $phone] , [ + 'password' , + 'id' , + 'salt' , + 'tokey' , + 'openid' , + 'blackflag' + ]); + if (!$member) $this->renderError('账号不存在,请先注册!'); + if ($type == 1) { + //账号密码登录 判断密码是否正确 + if ($member['password'] != md5($pwd . $member['salt'])) $this->renderError('密码错误!'); + } + else { + //短信验证码登录 判断验证码是否输入正确 + $pin_info = pdo_get('wlmerchant_pincode' , ['mobile' => $phone]); + if (empty($pin_info)) { + $this->renderError('验证码错误'); + } + if ($pin_info['time'] < time() - 300) { + $this->renderError('验证码已过期,请重新获取' , ['code' => 1]); + } + if ($pwd != $pin_info['code']) $this->renderError('验证码错误'); + } + if ($member['blackflag'] > 0) { + $tips = $_W['wlsetting']['userset']['black_desc'] ? $_W['wlsetting']['userset']['black_desc'] : '您被禁止访问,如有疑问请联系客服'; + $this->renderError($tips); + } + #3、密码输出正确 成功登录 + $userInfo = [ + 'mobile' => $phone , + 'pwd' => $pwd , + 'openid' => $member['openid'] ? $member['openid'] : $_W['wlmember']['openid'] , + 'tokey' => $member['tokey'] ? $member['tokey'] : $_W['wlmember']['tokey'] , + ]; + wl_setcookie('usersign' , $userInfo , 3600 * 24 * 30); + $res = Login::generateToken($userInfo['tokey'] , 'login'); + $token = $res['message']; + wl_setcookie('user_token' , $token , 3600 * 24 * 30); + wl_setcookie('exitlogin_code' , [] , 100); + #3、登录成功 返回跳转地址 + $link = $backUrl ? $backUrl : ''; + $this->renderSuccess('登录成功' , ['back_url' => $link , 'token' => $token]); + } + /** + * Comment: 验证短信验证码是否正确 + * Author: wlf + * Date: 2019/03/31 10:20 + */ + public function checkCode() + { + global $_W , $_GPC; + $phone = $_GPC['phone']; + $code = $_GPC['code']; + $pin_info = pdo_get('wlmerchant_pincode' , ['mobile' => $phone]); + if (empty($pin_info)) { + $this->renderError('验证码错误'); + } + if ($pin_info['time'] < time() - 300) { + $this->renderError('验证码已过期,请重新获取'); + } + if ($code != $pin_info['code']) $this->renderError('验证码错误'); + $this->renderSuccess('正确'); + } + /** + * Comment: 重置登录密码 + * Author: zzw + * Date: 2019/8/8 14:13 + */ + public function resetPassword() + { + global $_W , $_GPC; + #1、参数获取 + $phone = $_GPC['phone']; + $pwd = $_GPC['password']; + if (!$phone) $this->renderError('请输入账号!'); + if (!$pwd) $this->renderError('请输入新的密码!'); + #2、获取用户信息 + $member = Member::wl_member_get(['mobile' => $phone] , ['password' , 'id' , 'salt' , 'tokey' , 'openid']); + if (!$member) $this->renderError('用户信息不存在,请先注册!'); + #3、判断密码是否修改 + $salt = random(8); + $password = md5($pwd . $salt); + if ($member['password'] == $password) $this->renderError('密码不能与原密码一致!'); + #4、修改密码的操作 + $res = Member::wl_member_update(['password' => $password , 'salt' => $salt] , $member['id']); + if (!is_error($res)) { + $this->renderSuccess('修改成功'); + } + else { + $this->renderError('修改失败'); + } + } + /** + * Comment: 获取用户订单列表信息 + * Author: wlf + * Date: 2019/8/10 10:58 + */ + public function orderList() + { + global $_W , $_GPC; + $trade = Setting::wlsetting_read('trade'); + $authinfo = Cloud::wl_syssetting_read('authinfo'); + if ($authinfo['code'] == '116495A4C76AB8B1BBC387C941FE7424' || $authinfo['code'] == 'E9FEC02FCF843080D04DF170CBA8EF7A') { + $data['changeflag'] = 1; + } + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $page_index = 10; + $page_start = $page * $page_index - $page_index; + $status = $_GPC['status'] ? $_GPC['status'] : 0; + $cc_id = $_GPC['cc_id']; + $where = " uniacid = {$_W['uniacid']} and mid = {$_W['mid']}"; + if ($status != 10) { + if($data['changeflag'] > 0 && $status == 1 ){ + $where .= " and status IN (1,8)"; + }else{ + $where .= " and status = {intval($status)}"; + } + } + $where_cc = ''; + if (!empty($cc_id) && $cc_id > 0) { + $where_cc = " AND activityid IN (SELECT id FROM ". tablename(PDO_NAME."rush_activity") + . " WHERE uniacid = {$_W['uniacid']} AND cc_id = '{$cc_id}') "; + } + $myorder = pdo_fetchall('SELECT id,createtime,sid,num,status,price,paidprid,applyrefund,expressid,paytype,orderno as tid,pftorderinfo, "a" FROM ' + . tablename(PDO_NAME . "order") + . " where {$where} and orderno != 666666 AND plugin != 'distribution' AND plugin != 'housekeep' " + . ' UNION ALL SELECT id,createtime,sid,num,status,price,paidprid,applyrefund,expressid,paytype,orderno as tid,pftorderinfo, "b" FROM ' + . tablename(PDO_NAME . "rush_order") + . " where {$where} {$where_cc} ORDER BY createtime DESC LIMIT {$page_start},{$page_index}"); + //计算页码 + $total1 = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " where {$where} and orderno != 666666 AND plugin != 'distribution' AND plugin != 'housekeep' "); + $total2 = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "rush_order") . " where {$where}"); + $total = $total1 + $total2; + $data['pagetotal'] = ceil($total / 10); + if (empty($data['pagetotal'])) { + $data['pagetotal'] = 1; + } + //处理订单 + foreach ($myorder as $k => &$v) { + if ($v['a'] == 'a') { + $ndorder = pdo_get(PDO_NAME . 'order' , ['id' => $v['id'] , 'uniacid' => $_W['uniacid']] , [ + 'id' , + 'payfor' , + 'num' , + 'plugin' , + 'fkid' , + 'goodsprice' , + 'specid' , + 'orderno' , + 'fightstatus' , + 'fightgroupid' , + 'recordid' + ]); + if ($ndorder['specid'] && $ndorder['plugin'] != 'bargain' && $ndorder['plugin'] != 'yellowpage') { + if($ndorder['plugin'] == 'activity'){ + $v['optionname'] = pdo_getcolumn(PDO_NAME . 'activity_spec' , ['id' => $ndorder['specid']] , 'name'); + }else{ + $v['optionname'] = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $ndorder['specid']] , 'title'); + } + } + $v['activityid'] = $ndorder['fkid']; + if ($ndorder['plugin'] == 'coupon') { + $goods = wlCoupon::getSingleCoupons($ndorder['fkid'] , 'title,sub_title,logo,id,allowapplyre'); + $v['goodsname'] = $goods['title']; + $v['goodsimg'] = tomedia($goods['logo']); + $v['optionname'] = $goods['sub_title']; + $coupon = pdo_get(PDO_NAME . 'member_coupons' , [ + 'uniacid' => $_W['uniacid'] , + 'orderno' => $ndorder['orderno'] + ] , ['status' , 'id' , 'usetimes' , 'endtime' , 'usedtime']); + $this->checkcoupon($coupon , $ndorder); + $v['typeid'] = 5; + $v['recordid'] = $ndorder['recordid']; + } + else if ($ndorder['plugin'] == 'wlfightgroup') { + $goods = Wlfightgroup::getSingleGood($ndorder['fkid'] , 'name,logo,id,allowapplyre'); + $v['goodsname'] = $goods['name']; + $v['goodsimg'] = tomedia($goods['logo']); + $v['fightstatus'] = $ndorder['fightstatus']; + $v['recordid'] = $ndorder['recordid']; + if ($v['fightstatus'] == 1) { + $v['buystatus'] = '拼团'; + } + else { + $v['buystatus'] = '单购'; + } + switch ($v['status']) { + case '1': + if ($ndorder['fightgroupid']) { + $groupstatus = pdo_getcolumn(PDO_NAME . 'fightgroup_group' , ['id' => $ndorder['fightgroupid']] , 'status'); + $v['groupstatus'] = $groupstatus; + if ($groupstatus == 1) { + $v['statusName'] = '组团中'; + } + else if ($groupstatus == 2) { + $v['statusName'] = '待使用'; + } + } + else { + $v['statusName'] = '待使用'; + } + break; + case '2': + $v['statusName'] = '已消费'; + break; + case '3': + $v['statusName'] = '已完成'; + break; + case '8': + $v['statusName'] = '待发货'; + break; + case '4': + $v['statusName'] = '待收货'; + break; + case '5': + $v['statusName'] = '已取消'; + break; + case '6': + $v['statusName'] = '待退款'; + break; + case '7': + $v['statusName'] = '已退款'; + break; + case '9': + $v['statusName'] = '已过期'; + break; + default: + $v['statusName'] = '待付款'; + break; + } + $v['typeid'] = 3; + } + else if ($ndorder['plugin'] == 'groupon') { + $goods = pdo_get('wlmerchant_groupon_activity' , ['id' => $ndorder['fkid']] , [ + 'name' , + 'subtitle' , + 'thumb' , + 'id' , + 'allowapplyre', + 'pftid' + ]); + if (empty($v['optionname'])) { + $v['optionname'] = $goods['subtitle']; + } + $v['goodsname'] = $goods['name']; + $v['goodsimg'] = tomedia($goods['thumb']); + $v['typeid'] = 2; + if($goods['pftid'] > 0){ + $v['storename'] = '平台商品'; + } + } + else if ($ndorder['plugin'] == 'pocket') { + $infrom = Pocket::getInformations($ndorder['fkid']); + $typename = pdo_getcolumn(PDO_NAME . 'pocket_type' , [ + 'uniacid' => $_W['uniacid'] , + 'id' => $infrom['type'] + ] , 'title'); + $typeimg = pdo_getcolumn(PDO_NAME . 'pocket_type' , [ + 'uniacid' => $_W['uniacid'] , + 'id' => $infrom['type'] + ] , 'img'); + if ($ndorder['fightstatus'] == 1) { + $v['goodsname'] = '发布' . $typename . '信息'; + } + else if ($ndorder['fightstatus'] == 2) { + $v['goodsname'] = '置顶' . $typename . '信息'; + } + else { + $v['goodsname'] = '支付' . $typename . '信息红包'; + } + $v['goodsimg'] = tomedia($typeimg); + $v['typeid'] = 11; + $v['num'] = 1; + } + else if ($ndorder['plugin'] == 'store') { + $chargetype = pdo_get('wlmerchant_chargelist' , ['id' => $ndorder['fkid']] , ['name']); + $v['goodsname'] = '商户入驻' . $chargetype['name']; + $typeimg = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $v['sid']] , 'logo'); + $v['goodsimg'] = tomedia($typeimg); + $v['typeid'] = 10; + $v['num'] = 1; + } + else if ($ndorder['plugin'] == 'activity') { + $activity = pdo_get('wlmerchant_activitylist' , ['id' => $ndorder['fkid']] , [ + 'title' , + 'thumb' + ]); + $v['goodsname'] = $activity['title']; + $typeimg = $activity['thumb']; + $v['goodsimg'] = tomedia($typeimg); + } + else if ($ndorder['plugin'] == 'taxipay') { + $master = pdo_get('wlmerchant_taxipay_master' , ['id' => $ndorder['fkid']]); + $v['goodsname'] = '支付给[' . $master['name'] . ']师傅'; + $v['optionname'] = '车牌号:' . $master['plate1'] . $master['plate2'] . $master['plate_number']; + $v['goodsimg'] = tomedia(pdo_getcolumn(PDO_NAME . 'member' , ['id' => $master['mid']] , 'avatar')); + $v['storename'] = '出租车买单'; + $v['typeid'] = 12; + $v['mastermobile'] = $master['mobile']; + } + else if ($ndorder['plugin'] == 'consumption') { + $activity = pdo_get('wlmerchant_consumption_goods' , ['id' => $ndorder['fkid']] , [ + 'title' , + 'thumb' + ]); + $v['goodsname'] = $activity['title']; + $v['goodsimg'] = $activity['thumb']; + $v['storename'] = '系统平台'; + $v['typeid'] = 8; + $v['num'] = 1; + } + else if ($ndorder['plugin'] == 'member') { + $v['goodsname'] = $trade['moneytext'] . '充值'; + $v['goodsimg'] = tomedia($_W['wlmember']['avatar']); + $v['storename'] = '系统平台'; + } + else if ($ndorder['plugin'] == 'halfcard') { + $v['goodsname'] = '在线买单'; + $v['goodsimg'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , [ + 'id' => $v['sid'] , + 'uniacid' => $_W['uniacid'] + ] , 'logo'); + $v['goodsimg'] = tomedia($v['goodsimg']); + $v['typeid'] = 6; + $v['num'] = 1; + } + else if ($ndorder['plugin'] == 'bargain') { + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $ndorder['fkid']] , [ + 'name' , + 'thumb' , + 'allowapplyre' + ]); + $v['goodsname'] = $goods['name']; + $v['goodsimg'] = tomedia($goods['thumb']); + $v['fightstatus'] = $ndorder['fightstatus']; + if ($v['expressid'] && $v['status'] == 8) { + $v['statusName'] = '待发货'; + } + $v['typeid'] = 7; + } + else if ($ndorder['plugin'] == 'citycard') { + if ($ndorder['fightstatus'] == 1) { + $v['goodsname'] = '同城名片套餐付费'; + $v['optionname'] = pdo_getcolumn(PDO_NAME . "citycard_meals" , ['id' => $ndorder['fkid']] , 'name'); + } + else { + $v['goodsname'] = '同城名片置顶付费'; + $v['optionname'] = pdo_getcolumn(PDO_NAME . "citycard_tops" , ['id' => $ndorder['fkid']] , 'name'); + } + $v['storename'] = '同城名片'; + $userLogo = pdo_getcolumn(PDO_NAME . "citycard_lists" , ['id' => $ndorder['specid']] , 'logo'); + $v['goodsimg'] = !empty($userLogo) ? tomedia($userLogo) : $_W['wlmember']['avatar']; + $v['num'] = 1; + } + else if ($ndorder['plugin'] == 'citydelivery') { + $smallorders = pdo_fetchall("SELECT gid,num,specid FROM " . tablename('wlmerchant_delivery_order') . "WHERE orderid = {$ndorder['id']} ORDER BY price DESC"); + foreach ($smallorders as $ke => $orr) { + $good = pdo_get('wlmerchant_delivery_activity' , ['id' => $orr['gid']] , ['name' , 'thumb']); + if (empty($ke)) { + $v['goodsimg'] = tomedia($good['thumb']); + } + if ($ke > 0) { + if ($orr['specid'] > 0) { + $specname = pdo_getcolumn(PDO_NAME . 'delivery_spec' , ['id' => $orr['specid']] , 'name'); + $v['goodsname'] .= ' + [' . $good['name'] . '/' . $specname . '] X' . $orr['num']; + } + else { + $v['goodsname'] .= ' + [' . $good['name'] . '] X' . $orr['num']; + } + } + else { + if ($orr['specid'] > 0) { + $specname = pdo_getcolumn(PDO_NAME . 'delivery_spec' , ['id' => $orr['specid']] , 'name'); + $v['goodsname'] .= '[' . $good['name'] . '/' . $specname . '] X' . $orr['num']; + } + else { + $v['goodsname'] .= '[' . $good['name'] . '] X' . $orr['num']; + } + } + } + if ($v['status'] == 1) { + $v['statusName'] = '待取用'; + } + else if ($v['status'] == 8) { + $v['statusName'] = '待接单'; + } + else if ($v['status'] == 4) { + $v['statusName'] = '配送中'; + } + else if ($v['status'] == 7) { + $v['statusName'] = '已退款'; + } + $v['num'] = 1; + //判断退款 + if ($v['status'] != 7) { + $canre = pdo_getcolumn(PDO_NAME . 'aftersale' , [ + 'orderid' => $v['id'] , + 'plugin' => 'citydelivery' , + 'status' => [1 , 2] + ] , 'id'); + if ($canre) { + $v['status'] = 10; + $v['statusName'] = '退款处理中'; + } + } + } + else if ($ndorder['plugin'] == 'yellowpage') { + $page = pdo_get('wlmerchant_yellowpage_lists',array('id' => $ndorder['fkid']),array('name','logo')); + if ($ndorder['fightstatus'] == 1) { + $v['goodsname'] = '认领[' . $page['name'] . ']114信息'; + } + else if ($ndorder['fightstatus'] == 2) { + $v['goodsname'] = '查阅[' . $page['name'] . ']114信息'; + } + else if ($ndorder['fightstatus'] == 3) { + $v['goodsname'] = '入驻[' . $page['name'] . ']114信息'; + } + else if ($ndorder['fightstatus'] == 4) { + $v['goodsname'] = '续费[' . $page['name'] . ']114信息'; + } + $v['goodsimg'] = tomedia($page['logo']); + $v['typeid'] = 15; + $v['num'] = 1; + $v['storename'] = '黄页114'; + if($ndorder['specid']){ + $mealname = pdo_getcolumn(PDO_NAME.'yellowpage_meals',array('id'=>$ndorder['specid']),'name'); + $v['goodsname'] .= ",套餐[".$mealname."]"; + } + } + else if ($ndorder['plugin'] == 'recruit') { + //订单类型为求职招聘时 获取对应的信息 + $recruit = pdo_get(PDO_NAME."recruit_recruit",['id'=>$ndorder['fkid']]); + //判断发布方 招聘类型:1=个人招聘,2=企业招聘 + if($recruit['recruitment_type'] == 1){ + $release = pdo_get(PDO_NAME."member",['id'=>$recruit['release_mid']],['nickname','avatar','encodename']); + $v['goodsname'] = '个人招聘:'.base64_decode($release['encodename']); + $v['goodsimg'] = tomedia($release['avatar']); + }else{ + $release = pdo_get(PDO_NAME."merchantdata",['id'=>$recruit['release_sid']],['storename','logo']); + $v['goodsname'] = '企业招聘:'.$release['storename']; + $v['goodsimg'] = tomedia($release['logo']); + } + $v['storename'] = '求职招聘'; + $v['typeid'] = 16; + $v['num'] = 1; + } + else if ($ndorder['plugin'] == 'dating') { + //订单类型为相亲交友时 获取对应的信息 + if($ndorder['payfor'] == 'datingTop'){ + //信息置顶 + [$nickname,$avatar] = Dating::handleUserInfo($_W['mid']); + $v['goodsname'] = '信息置顶:'.$nickname; + $v['goodsimg'] = tomedia($avatar); + }else if($ndorder['payfor'] == 'datingVip'){ + //会员卡开通 + [$nickname,$avatar] = Dating::handleUserInfo($_W['mid']); + $v['goodsname'] = '会员卡开通:'.$nickname; + $v['goodsimg'] = tomedia($avatar); + }else if($ndorder['payfor'] == 'datingMatchmaker'){ + //红娘申请 + $matchmaker = pdo_get(PDO_NAME."dating_matchmaker",['id'=>$ndorder['fkid']],['nickname','avatar','encodename']); + $v['goodsname'] = '红娘申请:'.base64_decode($matchmaker['encodename']); + $v['goodsimg'] = tomedia($matchmaker['avatar']); + } + $v['storename'] = '相亲交友'; + $v['typeid'] = 17; + $v['num'] = 1; + } + else if ($ndorder['plugin'] == 'vehicle') { + //订单类型为相亲交友时 获取对应的信息 + $v['goodsname'] = '顺风车'; + $v['goodsimg'] = tomedia($_W['wlmember']['avatar']); + $v['storename'] = '顺风车'; + $v['typeid'] = 18; + $v['num'] = 1; + } + $v['plugin'] = $ndorder['plugin']; + if ($ndorder['goodsprice'] < 0.01) { + $ndorder['goodsprice'] = $v['price']; + } + if (empty($v['num'])) { + $v['num'] = 1; + } + $v['goodsprice'] = sprintf("%.2f" , $ndorder['goodsprice'] / $v['num']); + } + if ($v['a'] == 'b') { + $v['activityid'] = pdo_getcolumn(PDO_NAME . 'rush_order' , [ + 'id' => $v['id'] , + 'uniacid' => $_W['uniacid'] + ] , 'activityid'); + $goods = Rush::getSingleActive($v['activityid'] , 'name,isdistri,thumb,id,cutofftime,viponedismoney,viptwodismoney,vipthreedismoney,dissettime,onedismoney,twodismoney,threedismoney,allowapplyre,pftid'); + if ($v['status'] == 0 || $v['status'] == 5) { //校验支付 + $orderno = pdo_getcolumn(PDO_NAME . 'rush_order' , [ + 'uniacid' => $_W['uniacid'] , + 'id' => $v['id'] + ] , 'orderno'); + $paylog = pdo_get('core_paylogvfour' , [ + 'uniacid' => $_W['uniacid'] , + 'tid' => $orderno + ] , ['status' , 'uniontid' , 'type']); + if ($paylog['status'] == 1) { + $paytype = [ + 'credit' => 1 , + 'wechat' => 2 , + 'alipay' => 3 , + 'delivery' => 4 , + 'wxapp' => 5 + ]; + $data['paytype'] = $paytype[$paylog['type']]; + if ($v['expressid']) { + $data['status'] = 8; + } + else { + $data['status'] = 1; + } + $data['transid'] = $paylog['uniontid']; + pdo_update(PDO_NAME . 'rush_order' , $data , ['id' => $v['id']]); //更新订单状态 + $v = pdo_get('wlmerchant_rush_order' , ['id' => $v['id']]); + } + } + $actualprice = pdo_getcolumn(PDO_NAME . 'rush_order' , [ + 'id' => $v['id'] , + 'uniacid' => $_W['uniacid'] + ] , 'actualprice'); + $v['goodsname'] = $goods['name']; + $v['goodsimg'] = tomedia($goods['thumb']); + $v['plugin'] = 'rush'; + $v['goodsprice'] = sprintf("%.2f" , $v['price'] / $v['num']); + $v['price'] = $actualprice; + $v['typeid'] = 1; + if($goods['pftid'] > 0){ + $v['storename'] = '平台商品'; + } + } + if (!$v['storename']) { + $v['storename'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , [ + 'id' => $v['sid'] , + 'uniacid' => $_W['uniacid'] + ] , 'storename'); + if (!$v['storename']) { + $v['storename'] = '掌上信息'; + } + } + if(empty($v['shop_img'])){ + $v['shop_img'] = tomedia($_W['wlsetting']['base']['logo']); + } + if (($v['status'] == 8 || $v['status'] == 1) && empty($goods['allowapplyre']) && $v['plugin'] != 'citydelivery' && $v['plugin'] != 'consumption' && $v['paytype'] != 6 && $v['statusName'] != '组团中' && empty($v['pftorderinfo'])) { + if ($v['status'] == 1) { + $canre = pdo_getcolumn(PDO_NAME . 'smallorder' , [ + 'orderid' => $v['id'] , + 'plugin' => $v['plugin'] , + 'status' => 1 + ] , 'id'); + } + else { + $canre = pdo_getcolumn(PDO_NAME . 'aftersale' , [ + 'orderid' => $v['id'] , + 'plugin' => $v['plugin'] , + 'status' => [1 , 2] + ] , 'id'); + $canre = !$canre; + } + if ($canre) { + $v['surerefund'] = 1; + } + else { + $v['status'] = 10; + $v['surerefund'] = 0; + } + } + else { + $v['surerefund'] = 0; + } + $v['createtime'] = date('Y-m-d H:i' , $v['createtime']); + //获取商户信息 + if ($v['sid'] > 0) { + $v['shop_img'] = tomedia(pdo_getcolumn(PDO_NAME . "merchantdata" , ['id' => $v['sid']] , 'logo')); + } + if (empty($v['groupstatus'])) { + $v['groupstatus'] = 0; + } + } + $data['myorder'] = is_array($myorder) ? array_values($myorder) : []; + $this->renderSuccess('用户订单' , $data); + } + /** + * Comment: 检测卡券订单是否已被使用 + * Date: 2019/8/30 16:29 + * @param $coupon + * @param $ndorder + * @return bool + */ + private function checkcoupon($coupon , $ndorder) + { + global $_W , $_GPC; + if (empty($coupon) || empty($ndorder)) return false; + if (($coupon['usetimes'] < 1 || $coupon['endtime'] < time()) && $ndorder['status'] == 1) { + pdo_update(PDO_NAME . 'order' , ['status' => 2] , ['orderno' => $ndorder['orderno']]); + } + } + /** + * Comment: 用户个人中心信息 + * Author: wlf + * Date: 2019/8/12 09:09 + */ + public function memberInfo() + { + global $_W; + $data = []; + $data['nickname'] = $_W['wlmember']['nickname'] ? : ''; //用户昵称 + $data['bgimg'] = $_W['wlsetting']['userset']['userbg'] ? tomedia($_W['wlsetting']['userset']['userbg']) : URL_MODULE . 'h5/resource/image/userCenterImg.png';//背景图 + $data['avatar'] = tomedia($_W['wlmember']['avatar']); //用户头像 + Member::getMemberInfo($data,$_W['mid']); + if ($_W['wlmember']['mobile'] > 0) { + $data['truemobile'] = $_W['wlmember']['mobile']; + $data['mobile'] = substr($_W['wlmember']['mobile'] , 0 , 3) . '****' . substr($_W['wlmember']['mobile'] , -4 , 4); //用户手机号 + }else if(Customized::init('integral074') > 0 && empty($_W['wlsetting']['wxappset']['examineing']) && !empty($_W['mid']) ){ + $this->renderError('请先绑定手机号'); + } + $data['credit1'] = sprintf("%.2f" , $_W['wlmember']['credit1']); //用户积分 + $data['credit2'] = sprintf("%.2f" , $_W['wlmember']['credit2']); //用户余额 + + $identity_data = pdo_get(PDO_NAME . 'member_identity',['id' => $_W['wlmember']['identity_id']]); // 获取身份 + $data['identity'] = $identity_data ? $identity_data['name'] : '未知'; // 身份 + $data['interest_user_count'] = pdo_count(PDO_NAME . 'member_interest',['mid' => $_W['mid']]); // 关注数量 + $data['fans_user_count'] = pdo_count(PDO_NAME . 'member_interest',['interest_mid' => $_W['mid']]); // 粉丝数量 + + $student_info = pdo_get(PDO_NAME . 'member_student_info',['mid' => $_W['mid'],'check_status' => 1,'status' => 1],['department_name','school_name','code']); + $data['school_department_name'] = $student_info['department_name'] ?: ''; // 学院名称 + $data['school_name'] = $student_info['school_name'] ?: ''; // 学校名称 + $data['school_code'] = $student_info['code'] ?: ''; // 学号 + +// $collectnum = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'storefans') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']}"); +// $pocketcollectnum = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'pocket_collection') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']}"); +// $citycardcollectnum = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'citycard_collect') . " WHERE mid={$_W['mid']}"); + $collect_activities = pdo_count(PDO_NAME . 'member_collect_activities',['mid' => $_W['mid']]); + $data['collectnum'] = $collect_activities ?: 0; //收藏店铺数量 + //统计用户的未读信息数量 + $data['news_total'] = pdo_getcolumn(PDO_NAME . "im" , [ + 'receive_type' => 1 , + 'receive_id' => $_W['mid'] , + 'is_read' => 0 + ] , 'count(*)'); + $num_1 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'order') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']} and status = 0 and plugin <> 'distribution' AND plugin != 'housekeep'"); + $num_2 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'order') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']} and status = 1 and plugin <> 'distribution' AND plugin != 'housekeep'"); + $num_3 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'order') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']} and status = 2 and plugin <> 'distribution' AND plugin != 'housekeep'"); + $num_4 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'order') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']} and status = 4 and plugin <> 'distribution' AND plugin != 'housekeep'"); + $rnum_1 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'rush_order') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']} and status = 0 "); + $rnum_2 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'rush_order') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']} and status = 1 "); + $rnum_3 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'rush_order') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']} and status = 2 "); + $rnum_4 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . 'rush_order') . " WHERE uniacid={$_W['uniacid']} and mid={$_W['mid']} and status = 4 "); + $num1 = $num_1 + $rnum_1; + $num2 = $num_2 + $rnum_2; + $num3 = $num_3 + $rnum_3; + $num4 = $num_4 + $rnum_4; + $data['ordernum1'] = $num1; //待付款 + $data['ordernum2'] = $num2; //待使用 + $data['ordernum3'] = $num3; //待评价 + $data['ordernum4'] = $num4; //待退款 + //判断商户 + $storever = pdo_get('wlmerchant_merchantuser' , ['mid' => $_W['mid'] , 'uniacid' => $_W['uniacid']] , ['id','storeid']); + $storemain = pdo_get('wlmerchant_merchantuser' , [ + 'mid' => $_W['mid'] , + 'uniacid' => $_W['uniacid'] , + 'ismain' => [1 , 3 , 4] + ] , ['id']); + $data['storeid'] = $storever['storeid'];// 商户id + $storeadmin = pdo_fetch("SELECT id FROM " . tablename('wlmerchant_merchantuser') . "WHERE uniacid = {$_W['uniacid']} AND mid = {$_W['mid']} AND ismain IN (1,3)"); + if (!empty($storeadmin)) { + $data['storeTextStatus'] = 1; + } + //判断会员 + $data['halfcardflag'] = WeliamWeChat::VipVerification($_W['mid'] , true); //会员状态 + //节省 + $swhere['mid'] = $_W['mid']; + $swhere['uniacid'] = $_W['uniacid']; + $allorderprice = pdo_getcolumn('wlmerchant_timecardrecord' , $swhere , ["SUM(ordermoney)"]); + $realprice = pdo_getcolumn('wlmerchant_timecardrecord' , $swhere , ["SUM(realmoney)"]); + $ellipsismoney = $allorderprice - $realprice; + $data['ellipsismoney'] = sprintf("%.2f" , $ellipsismoney); //节约金额 + //积分签到 + $data['signstatus'] = $_W['wlsetting']['wlsign']['signstatus']; + //判断分销 + $distributionbase = Setting::wlsetting_read('distribution'); + if ($distributionbase['switch'] && p('distribution')) { + if ($_W['wlmember']['distributorid']) { + $distributor = pdo_get('wlmerchant_distributor' , ['id' => $_W['wlmember']['distributorid']]); + if ($distributor['disflag']) { + $disflag = 1; + } + else { + if ($distributionbase['appdis']) { + $disflag = 2; + } + else { + $disflag = 0; + } + } + } + else { + if ($distributionbase['appdis']) { + $disflag = 2; + } + else { + $disflag = 0; + } + } + } + else { + $disflag = 0; + } + //电商联盟定制 分销同步到其他模块 + if (file_exists(PATH_MODULE . 'lsh.log') && !empty($data['halfcardflag'])) { + if (!empty($_W['wlmember']['openid'])) { + $myuser = Distribution::initUserInfo($_W['wlmember']); + if (empty($distributor)) { + $distributor = pdo_get('wlmerchant_distributor' , ['mid' => $_W['wlmember']['id']]); + } + } + // 其他模块上级ID不存在,并且我有上级才同步 + if (empty($myuser['pid']) && $distributor['leadid'] > 0) { + $leaderinfo = pdo_get('wlmerchant_member' , ['id' => $distributor['leadid']]); + $leader = Distribution::initUserInfo($leaderinfo); + pdo_update('hccard_user' , ['pid' => $leader['id']] , ['id' => $myuser['id']]); + } + } + //判断手机号是否显示 + $mustmobile = unserialize($_W['wlsetting']['userset']['plugin']); + if (empty($mustmobile) || !empty($_W['wlmember']['mobile'])) { + $data['mobilediv'] = 0; + } + else { + $data['mobilediv'] = 1; + } + $data['disflag'] = $disflag; //分销商状态 + $pocketset = Setting::agentsetting_read('pocket'); + //我的工具 开关显示 (1=开启;0=关闭) + $userSet = User::userSet(); +// $userSet['ykthy']['switch'] = $_W['wlsetting']['halfcard']['status'] == 1 ? $userSet['ykthy']['switch'] == 1 ? 1 : 0 : 0;//一卡通会员(ykthy) +// $userSet['xfjl']['switch'] = $_W['wlsetting']['halfcard']['status'] == 1 ? $userSet['xfjl']['switch'] == 1 ? 1 : 0 : 0;//消费记录(xfjl) +// $userSet['wdkj']['switch'] = p('bargain') ? $userSet['wdkj']['switch'] == 1 ? 1 : 0 : 0;//我的砍价(wdkj) +// $userSet['shzx']['switch'] = !empty($storemain) ? $userSet['shzx']['switch'] == 1 ? 1 : 0 : 0;//商户中心(shzx) +// $userSet['hxjl']['switch'] = !empty($storever) ? $userSet['hxjl']['switch'] == 1 ? 1 : 0 : 0;//核销记录(hxjl) + #$userSet['jfsc']['switch'] = $_W['wlsetting']['consumption']['status'] == 1 ? $userSet['jfsc']['switch'] == 1 ? 1 : 0 : 0;//积分商城(jfsc) +// $userSet['wdtz']['switch'] = $pocketset['status'] == 1 ? $userSet['wdtz']['switch'] == 1 ? 1 : 0 : 0;//我的帖子(wdtz) +// $userSet['fxzx']['switch'] = !empty($disflag) ? $userSet['fxzx']['switch'] == 1 ? 1 : 0 : 0;//分销中心(fxzx) + //$userSet['rzzx']['switch'] = $_W['wlsetting']['attestation']['switch'] == 1 ? $userSet['rzzx']['switch'] == 1 ? 1 : 0 : 0;//认证中心(rzzx) +// $userSet['kefu']['switch'] = $_W['wlsetting']['customer']['status'] == 1 ? $userSet['kefu']['switch'] == 1 ? 1 : 0 : 0;//客服(kefu) +// $userSet['wdhb']['switch'] = p('redpack') ? $userSet['wdhb']['switch'] == 1 ? 1 : 0 : 0;//我的红包(kefu) +// $userSet['hbgc']['switch'] = p('redpack') ? $userSet['hbgc']['switch'] == 1 ? 1 : 0 : 0;//红包广场(kefu) + //文本替换 + $trade = $_W['wlsetting']['trade']; + $halfcardtext = $trade['halfcardtext'] ? : '一卡通'; + $userSet['ykthy']['title'] = str_replace('一卡通' , $halfcardtext , $userSet['ykthy']['title']); + $fxtext = $trade['fxtext'] ? : '分销'; + $userSet['fxzx']['title'] = str_replace('分销' , $fxtext , $userSet['fxzx']['title']); + //循环处理信息 + foreach ($userSet as $key => &$val) { + //判断是否开启 + if ($val['switch'] != 1) { + unset($userSet[$key]); + continue; + } + // 身份判断是否开启 + if (!empty($val['identity']) && !in_array($identity_data['id'],$val['identity'])) { + unset($userSet[$key]); + continue; + } + //处理图片路径 + $val['icon'] = tomedia($val['icon']); + //mid参数替换 + $paramsMid = "mid={$_W['mid']}&"; + $val['link'] = str_replace('mid=&' , $paramsMid , $val['link']); + //自定义名称 + $val['title'] = $val['diy_title'] ? : $val['title']; + //客服按钮 + if($key == 'kefu' && $val['link'] == $val['default']){ + if($_W['aid']>0){ + $set = Setting::agentsetting_read('agentcustomer'); + }else{ + $set = Setting::wlsetting_read("customer"); + } + if($set['wxapptype'] > 0){ + $val['kefuflag'] = $set['wxapptype']; + $val['customerurl'] = $set['customerurl']; + $val['enterpriseid'] = $set['enterpriseid']; + } + } + } + $data['user_set'] = $userSet ? array_values($userSet) : []; + $data['halfcardstatus'] = $_W['wlsetting']['halfcard']['status']; + $data['mid'] = $_W['mid'] ? : ''; + //定制 + $authinfo = Cloud::wl_syssetting_read('authinfo'); + if ($authinfo['code'] == '116495A4C76AB8B1BBC387C941FE7424' || $authinfo['code'] == 'E9FEC02FCF843080D04DF170CBA8EF7A') { + $data['changeflag'] = 1; + } + //881定制 + $isAuth = Customized::init('diy_userInfo'); + if($isAuth){ + $data['diy_userInfo']['dhurl'] = $_W['wlsetting']['recharge']['dhurl']; + } + + $this->renderSuccess('用户信息' , $data); + } + /** + * Comment: 用户数据 + * Author: wlf + * Date: 2019/8/12 09:50 + */ + public function userData() + { + global $_W; + $data = []; + $data['nickname'] = $_W['wlmember']['nickname']; + $data['realname'] = $_W['wlmember']['realname']; + $data['mobile'] = $_W['wlmember']['mobile']; + if ($_W['wlsetting']['cashset']['payment_type']['bank_card'] == 1) { + $data['bankstatus'] = 1; + } + else { + $data['bankstatus'] = 0; + } + $data['bank_name'] = $_W['wlmember']['bank_name']; + $data['bank_username'] = $_W['wlmember']['bank_username']; + $data['card_number'] = $_W['wlmember']['card_number']; + if ($_W['wlsetting']['cashset']['payment_type']['alipay'] == 1) { + $data['alipaystatus'] = 1; + } + else { + $data['alipaystatus'] = 0; + } + $data['alipay'] = $_W['wlmember']['alipay']; + Member::getMemberInfo($data,$_W['mid']); + unset($data['avatar']); + $this->renderSuccess('用户数据' , $data); + } + /** + * Comment: 修改用户数据 + * Author: wlf + * Date: 2019/8/12 10:17 + */ + public function changeUserData() + { + global $_W , $_GPC; + $data = []; + $data['nickname'] = $_GPC['nickname']; + $data['encodename'] = base64_encode($_GPC['nickname']); + $data['realname'] = $_GPC['realname']; + $nicknameRes = Filter::init($data['nickname'],$_W['source']); + if($nicknameRes['errno'] == 0) $this->renderError('昵称'.$nicknameRes['message']); + if ($_GPC['bank_name']) { + $data['bank_name'] = $_GPC['bank_name']; + } + if ($_GPC['bank_username']) { + $data['bank_username'] = $_GPC['bank_username']; + } + if ($_GPC['card_number']) { + $data['card_number'] = $_GPC['card_number']; + } + if ($_GPC['alipay']) { + $data['alipay'] = $_GPC['alipay']; + } + $res = pdo_update('wlmerchant_member' , $data , ['id' => $_W['mid']]); + if ($res) { + $this->renderSuccess('修改成功'); + } + else { + $this->renderError('修改失败,请刷新重试'); + } + } + /** + * Comment: 修改用户昵称 和 头像 + * Author: wlf + * Date: 2019/8/12 11:07 + */ + public function updateUserInfo() + { + global $_W, $_GPC; + + $mid = $_W['mid']; + $nickname = $_GPC['nickname']; + $avatar = $_GPC['avatar']; + + $member = Member::wl_member_get($mid, [], false); + if (empty($member)) $this->renderError('用户不存在,请检查后重试'); + + if (empty($nickname)) $this->renderError('请填写用户昵称'); + if (strlen($nickname) > 64) $this->renderError('用户昵称最大字符数不得超过64字符'); + if (empty($avatar)) $this->renderError('请上传用户头像'); + + $nicknameRes = Filter::init($nickname,$_W['source'],1); + if ($nicknameRes['errno'] == 0) $this->renderError('用户名'.$nicknameRes['message']); + $avatarRes = Filter::init($avatar,$_W['source'],2); + if($avatarRes['errno'] == 0) $this->renderError('用户头像'.$avatarRes['message']); + + $data = [ + 'nickname' => $nickname, + 'encodename' => base64_encode($nickname), + 'avatar' => $avatar + ]; + + $result = pdo_update(PDO_NAME . 'member',$data,['id' => $mid]); + if (!$result) $this->renderError('修改失败'); + $this->renderSuccess('修改成功'); + } + /** + * Comment: 用户地址列表 + * Author: wlf + * Date: 2019/8/12 11:07 + */ + public function addressList() + { + global $_W; + $data = pdo_getall('wlmerchant_address' , ['mid' => $_W['mid'] , 'uniacid' => $_W['uniacid']] , [ + 'id' , + 'name' , + 'status' , + 'tel' , + 'province' , + 'city' , + 'county' , + 'detailed_address' + ]); + $this->renderSuccess('用户地址列表' , is_array($data) ? $data : []); + } + /** + * Comment: 创建或编辑地址 + * Author: wlf + * Date: 2019/8/12 11:22 + */ + public function addAddress() + { + global $_W , $_GPC; + $id = $_GPC['id']; + $data = []; + if ($id) { + $address = pdo_get('wlmerchant_address' , ['id' => $id] , ['name','status','tel','province','city','county','detailed_address','housenumber']); + $data['name'] = $address['name']; + $data['status'] = $address['status']; + $data['tel'] = $address['tel']; + $provinceid = pdo_fetch("SELECT id FROM " . tablename('wlmerchant_area') . "WHERE `name` like '%{$address['province']}%' "); + $cityid = pdo_fetch("SELECT id FROM " . tablename('wlmerchant_area') . "WHERE `name` like '%{$address['city']}%' "); + $countyid = pdo_fetch("SELECT id FROM " . tablename('wlmerchant_area') . "WHERE `name` like '%{$address['county']}%' "); + $data['provinceid'] = $provinceid['id']; + $data['cityid'] = $cityid['id']; + $data['countyid'] = $countyid['id']; + $data['detailed_address'] = $address['detailed_address']; + $data['houseNumber'] = $address['housenumber']; + } + //切割门牌号 + if(!empty($data['houseNumber'])){ + $data['detailed_address'] = strstr($data['detailed_address'],$data['houseNumber'],true); + } + $this->renderSuccess('地址数据' , $data); + } + /** + * Comment: 保存地址数据 + * Author: wlf + * Date: 2019/8/12 15:59 + */ + public function saveAddress() + { + global $_W , $_GPC; + $id = $_GPC['id']; + $data = []; + $data['name'] = $_GPC['name']; + $data['status'] = $_GPC['status']; + $data['lat'] = $_GPC['lat']; + $data['lng'] = $_GPC['lng']; + if (empty($data['lat']) || empty($data['lng'])) { + $data['lat'] = 0; + $data['lng'] = 0; + } + if ($data['status']) { + pdo_update('wlmerchant_address' , ['status' => 0] , ['uniacid' => $_W['uniacid'] , 'mid' => $_W['mid']]); + } + $data['tel'] = $_GPC['tel']; + $data['detailed_address'] = $_GPC['detailed_address'].$_GPC['houseNumber']; + $data['housenumber'] = $_GPC['houseNumber']; + $provinceid = $_GPC['provinceid']; + $data['province'] = pdo_getcolumn(PDO_NAME . 'area' , ['id' => $provinceid] , 'name'); + $cityid = $_GPC['cityid']; + $data['city'] = pdo_getcolumn(PDO_NAME . 'area' , ['id' => $cityid] , 'name'); + $countyid = $_GPC['countyid'] ? $_GPC['countyid'] : $_GPC['cityid']; + $data['county'] = pdo_getcolumn(PDO_NAME . 'area' , ['id' => $countyid] , 'name'); + $data['addtime'] = time(); + if ($id) { + $res = pdo_update('wlmerchant_address' , $data , ['id' => $id]); + } + else { + $data['uniacid'] = $_W['uniacid']; + $data['aid'] = $_W['aid']; + $data['mid'] = $_W['mid']; + $res = pdo_insert(PDO_NAME . 'address' , $data); + } + if ($res) { + $this->renderSuccess('修改成功'); + } + else { + $this->renderError('修改失败,请刷新重试'); + } + } + /** + * Comment: 修改默认地址 + * Author: wlf + * Date: 2019/8/12 16:21 + */ + public function changeAddressStatus() + { + global $_W , $_GPC; + $id = $_GPC['id']; + if (empty($id)) { + $this->renderError('缺少地址参数'); + } + pdo_update('wlmerchant_address' , ['status' => 0] , ['uniacid' => $_W['uniacid'] , 'mid' => $_W['mid']]); + $res = pdo_update('wlmerchant_address' , ['status' => 1] , ['id' => $id]); + if ($res) { + $this->renderSuccess('修改成功'); + } + else { + $this->renderError('修改失败,请刷新重试'); + } + } + /** + * Comment: 删除地址 + * Author: wlf + * Date: 2019/8/12 17:40 + */ + public function deleteAddress() + { + global $_W , $_GPC; + $id = $_GPC['id']; + if (empty($id)) { + $this->renderError('缺少地址参数'); + } + $res = pdo_delete('wlmerchant_address' , ['id' => $id]); + if ($res) { + $this->renderSuccess('删除成功'); + } + else { + $this->renderError('删除失败,请刷新重试'); + } + } + /** + * Comment: 改绑手机 + * Author: wlf + * Date: 2019/8/12 16:40 + */ + public function changeMobile() + { + global $_W , $_GPC; + $mobile = $_GPC['mobile']; + $mergeflag = $_GPC['mergeflag']; + $code = $_GPC['code']; + if (empty($mobile)) { + $this->renderError('手机号码错误'); + } + if (!empty($code)) { + $pin_info = pdo_get('wlmerchant_pincode' , ['mobile' => $mobile]); + if (empty($pin_info)) { + $this->renderError('验证码错误' , ['code' => 1]); + } + if ($pin_info['time'] < time() - 300) { + $this->renderError('验证码已过期,请重新获取' , ['code' => 1]); + } + if ($code != $pin_info['code']) $this->renderError('验证码错误' , ['code' => 1]); + } + //判断是否绑定 + $flag = Member::wl_member_get(['mobile' => $mobile] , ['id']); + if ($flag && empty($mergeflag)) { + if($_W['wlsetting']['userset']['onemobiletype'] == 1){ + $this->renderError('手机号已存在,绑定该手机号会取消之前用户的绑定手机' , ['mergeflag' => 1]); + }else if($_W['wlsetting']['userset']['onemobiletype'] == 2){ + $this->renderError('手机号已存在,无法重复绑定'); + }else{ + $this->renderError('手机号已存在,绑定该手机号会自动同步用户数据' , ['mergeflag' => 1]); + } + } + //解绑之前手机 + if($flag && !empty($mergeflag) && $_W['wlsetting']['userset']['onemobiletype'] == 1){ + pdo_update('wlmerchant_member',array('mobile' => ''),array('mobile' => $mobile)); + } + //绑定用户手机号 + $bind = Member::wl_member_update(['mobile' => $mobile] , $_W['mid']); + if (is_error($bind)) { + $this->renderError($bind['message']); + } + //合并重复手机号 + if ($flag && !empty($mergeflag) && empty($_W['wlsetting']['userset']['onemobiletype'])) { + $res = Member::wl_member_merge($mobile , 'mobile'); + if (is_error($res)) { + $this->renderError($res['message']); + } + $this->renderSuccess('合并数据成功,请重新登录' , ['token' => $res['tokey']]); + } + $this->renderSuccess('修改成功' , ['token' => $bind['tokey']]); + } + /** + * Comment: 积分余额变更记录 + * Author: wlf + * Date: 2019/8/28 14:42 + */ + public function creditRecord() + { + global $_W , $_GPC; + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $page_start = $page * 50 - 50; + $type = $_GPC['type'] ? $_GPC['type'] : 1; + $type = $type == 1 ? 'credit1' : 'credit2'; + $uid = $_W['wlmember']['uid']; + $records = pdo_fetchall("SELECT id,num,createtime,remark FROM " . tablename("mc_credits_record") . " WHERE uid = {$uid} AND uniacid = {$_W['uniacid']} AND credittype = '{$type}' ORDER BY createtime DESC LIMIT {$page_start},50"); + $allnum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('mc_credits_record') . " WHERE uid = {$uid} AND uniacid = {$_W['uniacid']} AND credittype = '{$type}'"); + if ($records) { + foreach ($records as $key => &$va) { + $va['createtime'] = date('Y-m-d H:i:s' , $va['createtime']); + } + $records = array_values($records); + } + $data['list'] = $records; + $data['pagetotal'] = ceil($allnum / 50); + $data['mycredit'] = sprintf("%.2f" , $_W['wlmember']['credit1']); + $data['flag074'] = Customized::init('integral074') > 0 ? 1 : 0; + //文字替换 积分 换成自定义文字 + $textData = Setting::wlsetting_read('trade'); + $credittext = $textData['credittext'] ? $textData['credittext'] : '积分'; + $jsonData = json_encode($data , JSON_UNESCAPED_UNICODE); + $jsonData = str_replace('积分' , $credittext , $jsonData); + $data = json_decode($jsonData , true); + $this->renderSuccess('积分余额记录' , $data); + } + /** + * Comment: 收藏店铺列表 + * Author: wlf + * Date: 2019/8/12 16:20 + */ + public function storeCollect() + { + global $_W , $_GPC; + $page = $_GPC['page'] ? $_GPC['page'] : 1; //显示的页数 + $lat = $_GPC['lat']; + $lng = $_GPC['lng']; + $pagestatrt = $page * 10 - 10; + $collects = pdo_fetchall("SELECT * FROM " . tablename('wlmerchant_storefans') . "WHERE uniacid = {$_W['uniacid']} AND mid = {$_W['mid']} ORDER BY createtime DESC LIMIT {$pagestatrt},10"); + $allnum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_storefans') . " WHERE uniacid = {$_W['uniacid']} AND mid = {$_W['mid']}"); + if ($collects) { + foreach ($collects as $key => $value) { + $merchant = pdo_get('wlmerchant_merchantdata' , [ + 'uniacid' => $_W['uniacid'] , + 'id' => $value['sid'] + ] , ['mobile' , 'id' , 'storename' , 'location' , 'logo' , 'storehours' , 'score' , 'tag']); + if ($merchant) { + //计算距离 + if (!empty($lat) && !empty($lng)) { + $location = unserialize($merchant['location']); + $merchant['distance'] = Store::getdistance($location['lng'] , $location['lat'] , $lng , $lat); + if ($merchant['distance'] > 1000) { + $merchant['distance'] = (floor(($merchant['distance'] / 1000) * 10) / 10) . "km"; + } + else { + $merchant['distance'] = round($merchant['distance']) . "m"; + } + } + $merchant['logo'] = tomedia($merchant['logo']); + $merchant['tags'] = []; + $tagids = unserialize($merchant['tag']); + if (!empty($tagids)) { + $tags = pdo_getall('wlmerchant_tags' , ['id' => $tagids] , ['title']); + $merchant['tags'] = $tags ? array_column($tags , 'title') : []; + } + unset($merchant['tag']); + //营业时间 + $storehours = unserialize($merchant['storehours']); + if(!empty($storehours['startTime'])){ + $merchant['storehours'] = $storehours['startTime'] . ' - ' . $storehours['endTime']. " 营业"; + }else{ + $merchant['storehours'] = ''; + foreach($storehours as $hk => $hour){ + if($hk > 0){ + $merchant['storehours'] .= ','.$hour['startTime'] . ' - ' . $hour['endTime']; + }else{ + $merchant['storehours'] .= $hour['startTime'] . ' - ' . $hour['endTime']; + } + } + $merchant['storehours'] .= " 营业"; + } + $merchant['hourstatus'] = Store::getShopBusinessStatus($storehours,$merchant['id']); + //查询认证和保证金 + if (p('attestation')) { + $merchant['attestation'] = Attestation::checkAttestation(2 , $merchant['id']); + } + else { + $merchant['attestation'] = 0; + } + $colls[$key]['store'] = $merchant; + } + else { + pdo_delete('wlmerchant_storefans' , ['sid' => $value['sid']]); + } + } + $data['list'] = $colls; + $data['pagetotal'] = ceil($allnum / 10); + $this->renderSuccess('店铺列表' , $data); + } + else { + $data['list'] = []; + $data['pagetotal'] = 1; + $this->renderSuccess('无数据' , $data); + } + } + /** + * Comment: 我的卡券列表 + * Author: wlf + * Date: 2019/8/12 16:32 + */ + public function memberCoupon() + { + global $_W , $_GPC; + if(Customized::init('transfergift') > 0){ + $data['transfer'] = 1; + $trwhere = " WHERE uniacid = {$_W['uniacid']} AND type = 1 AND omid = {$_W['mid']} AND status = 1"; + $alllist = pdo_fetchall("select distinct objid from " . tablename(PDO_NAME.'transferRecord').$trwhere); + $alltrnum = count($alllist); + $data['alltrnum'] = $alltrnum; + }else{ + $data['transfer'] = 0; + } + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $status = $_GPC['status'] ? trim($_GPC['status']) : 1; + $where['mid'] = $_W['mid']; + if ($status == 1) { + $where['usetimes>'] = 1; + $where['endtime>'] = time(); + } + else if ($status == 2) { + $where['usetimes'] = 0; + } + else { + $where['usetimes>'] = 1; + $where['endtime<'] = time(); + } + $couponlist = wlCoupon::getNumCoupon('id,title,sub_title,endtime,starttime,parentid,orderno,status,transferflag' , $where , 'ID DESC' , $page , 20 , 1); + $allnum = $couponlist[2]; + $couponlist = $couponlist[0]; + if ($couponlist) { + foreach ($couponlist as $key => &$v) { + $parent = pdo_get('wlmerchant_couponlist' , ['id' => $v['parentid']] , [ + 'logo' , + 'merchantid' , + 'title' , + 'sub_title', + 'transferstatus', + 'transfermore', + 'transferlevel' + ]); + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $parent['merchantid']] , [ + 'storename' , + 'logo' + ]); + $v['title'] = $parent['title']; + $v['sub_title'] = $parent['sub_title']; + $v['storename'] = $store['storename']; + $v['storeid'] = $parent['merchantid']; + $v['transferflag'] = $v['transferflag'] ? : 0; + $v['endtime'] = date('Y-m-d' , $v['endtime']); + $v['starttime'] = date('Y-m-d' , $v['starttime']); + $v['storelogo'] = tomedia($store['logo']); + $v['orderid'] = pdo_getcolumn(PDO_NAME . 'order' , ['orderno' => $v['orderno']] , 'id'); + if (empty($v['orderid'])) { + $v['orderid'] = pdo_getcolumn(PDO_NAME . 'order' , [ + 'recordid' => $v['id'] , + 'plugin' => 'coupon' + ] , 'id'); + } + //判断是否能够转赠 + if($parent['transferstatus'] > 0){ + if(empty($v['transferflag']) || $parent['transfermore'] > 0){ + $transferlevel = unserialize($parent['transferlevel']); + if(empty($transferlevel)){ + $v['transferstatus'] = 1; + }else{ + $halfflag = WeliamWeChat::VipVerification($_W['mid']); + if(empty($halfflag)){ + $levelid = -1; + }else{ + $levelid = $halfflag['levelid']; + } + if(in_array($levelid,$transferlevel)){ + $v['transferstatus'] = 1; + } + } + } + } + $v['transferstatus'] = $v['transferstatus'] ? : 0; + //转赠卡券信息获取 + if($v['transferflag'] > 0){ + $record = pdo_getall('wlmerchant_transferRecord',array('type' => 1,'objid' => $v['id'],'nmid' => $_W['mid']),array('omid','gettime'),'','ID DESC'); + $record = $record[0]; + $oldmember = pdo_get('wlmerchant_member',array('id' => $record['omid']),array('nickname','mobile','encodename')); + $v['oldnickname'] = base64_decode($oldmember['encodename']); + $v['oldmobile'] = substr($oldmember['mobile'],0,3).'****'.substr($oldmember['mobile'], -4); + $v['gettime'] = date('Y/m/d H:i:s',$record['gettime']); + } + + //未获取订单id 删除当前卡券信息 + if (empty($v['orderid'])) { + unset($couponlist[$key]); + continue; + } + } + $data['list'] = array_values($couponlist); + $data['pagetotal'] = ceil($allnum / 20); + $data['allnum'] = $allnum; + $this->renderSuccess('卡券列表' , $data); + } + else { + $data['list'] = []; + $data['allnum'] = 0; + $data['pagetotal'] = 0; + $this->renderSuccess('无数据' , $data); + } + } + /** + * Comment: 我的砍价列表 + * Author: wlf + * Date: 2019/8/13 09:28 + */ + public function memberBargain() + { + global $_W , $_GPC; + $where = " uniacid = {$_W['uniacid']} AND mid = {$_W['mid']}"; + $myorder = pdo_fetchall("SELECT activityid,id,createtime,price,status FROM " . tablename('wlmerchant_bargain_userlist') . "WHERE {$where} ORDER BY createtime DESC"); + if ($myorder) { + foreach ($myorder as $k => &$v) { + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $v['activityid']] , [ + 'name' , + 'endtime' , + 'id' , + 'vipprice' , + 'vipstatus' , + 'price' , + 'oldprice' , + 'sid' , + 'thumb' + ]); + $v['goodsname'] = $goods['name']; + $v['goodsimg'] = tomedia($goods['thumb']); + $v['oldprice'] = $goods['oldprice']; + $v['endtime'] = $goods['endtime']; + if ($goods['vipstatus'] == 1) { + $halfflag = WeliamWeChat::VipVerification($_W['mid'] , true); + if ($halfflag) { + $goods['price'] = $goods['vipprice']; + } + } + //已砍金额 + $v['alprice'] = sprintf("%.2f" , $v['oldprice'] - $v['price']); + //还需砍价金额 + $v['needprice'] = sprintf("%.2f" , $v['price'] - $goods['price']); + //比例 + $canprice = $goods['oldprice'] - $goods['price']; + $v['redrate'] = sprintf("%.2f" , ($v['alprice'] / $canprice) * 100); + $v['successnum'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_bargain_userlist') . " WHERE status = 2 AND activityid = {$v['activityid']} "); + } + $this->renderSuccess('砍价列表' , $myorder); + } + else { + $this->renderSuccess('无数据' , []); + } + } + /** + * Comment: 我的核销列表 + * Author: wlf + * Date: 2019/8/13 10:44 + */ + public function memberVerifList() + { + global $_W , $_GPC; + $data = []; + if ($_GPC['getlistflag']) { + //所有店铺 + $alladmin = pdo_getall(PDO_NAME . 'merchantuser' , [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $_W['mid'] + ] , ['storeid']); + if ($alladmin) { + foreach ($alladmin as $ak => &$av) { + $av['storename'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , [ + 'uniacid' => $_W['uniacid'] , + 'id' => $av['storeid'] + ] , 'storename'); + } + } + //所有分类 +// $halfcardtext = !empty($_W['wlsetting']['trade']['halfcardtext']) ? $_W['wlsetting']['trade']['halfcardtext'] : '一卡通'; + $alltype = []; +// $alltype[] = ['name' => $halfcardtext , 'type' => 'halfcard1']; +// $alltype[] = ['name' => '大礼包' , 'type' => 'halfcard2']; +// $alltype[] = ['name' => '抢购' , 'type' => 'rush']; +// $alltype[] = ['name' => '卡券' , 'type' => 'coupon']; +// $alltype[] = ['name' => '拼团' , 'type' => 'wlfightgroup']; +// $alltype[] = ['name' => '团购' , 'type' => 'groupon']; +// $alltype[] = ['name' => '砍价' , 'type' => 'bargain']; + $cultivate_class = Category::getStoreCategory(); + foreach ($cultivate_class as $cultivate_class_val) { + $alltype[] = ['name' => $cultivate_class_val['name'], 'type' => 'rush', 'cc_id' => $cultivate_class_val['id']]; + } + $data['typelist'] = $alltype; + $data['storelist'] = $alladmin; + } + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $type = trim($_GPC['type']); + $cc_id = trim($_GPC['cc_id']); + $storeid = intval($_GPC['storeid']); + $time = trim($_GPC['time']); + $where = ['uniacid' => $_W['uniacid'] , 'verifmid' => $_W['mid']]; + if (!empty($type)) { + $where['plugin'] = $type; + } + if (!empty($cc_id)) { + $where['cc_id'] = $cc_id; + } + if (!empty($storeid)) { + $where['storeid'] = $storeid; + } + if (!empty($time)) { + if ($time == 'today') { + $starttime = strtotime(date('Y-m-d')); + $endtime = $starttime + 86399; + } + else if ($time == 'week') { + $starttime = strtotime("previous monday"); + $endtime = time(); + } + else if ($time == 'month') { + $starttime = mktime(0 , 0 , 0 , date('m') , 1 , date('Y')); + $endtime = time(); + } + else { + $times = explode(',' , $time); + $starttime = $times[0]; + $endtime = ($starttime > $times[1]) ? $starttime + 86399 : $times[1] + 86399; + } + $where['createtime>'] = $starttime; + $where['createtime<'] = $endtime; + } + $data1 = Util::createStandardWhereString($where); + $allfen = pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename(PDO_NAME . "verifrecord") . " WHERE $data1[0] " , $data1[1]); + $myorder = Util::getNumData('mid,storeid,createtime,verifrcode,verifnickname,orderid,plugin,verifmid,remark,type,num,cc_id' , PDO_NAME . 'verifrecord' , $where , 'ID DESC' , $page , 20 , 1); + $allnum = $myorder[2]; + $myorder = $myorder[0]; + foreach ($myorder as $key => &$value) { + $member = pdo_get(PDO_NAME . 'member',['id' => $value['mid']],['avatar' , 'mobile', 'encodename']); + //$member = Member::wl_member_get($value['mid'] , ['nickname' , 'avatar' , 'mobile', 'encodename']); + $value['nickname'] = base64_decode($member['encodename']); + $value['mobile'] = $member['mobile']; + $value['avatar'] = tomedia($member['avatar']); + if (empty($value['verifnickname'])) { + $verifnickname = pdo_getcolumn(PDO_NAME . 'merchantuser' , [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $value['verifmid'] , + 'storeid' => $value['storeid'] + ] , 'name'); + $value['verifnickname'] = $verifnickname; + } + $value['createtime'] = date('Y-m-d H:i:s' , $value['createtime']); + $cc_name = pdo_getcolumn(PDO_NAME . 'cultivate_class',['id' => $value['cc_id']],'name'); + $value['classname'] = $cc_name ?: ''; // 自定义特殊分类 + //处理数据 + switch ($value['plugin']) { + case 'rush': + $order = pdo_get(PDO_NAME . 'rush_order' , ['id' => $value['orderid']] , [ + 'optionid' , + 'activityid' + ]); + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'rush_activity' , ['id' => $order['activityid']] , 'thumb'); + $optionid = $order['optionid']; + $value['pluginname'] = '抢购'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//抢购 + case 'groupon': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , [ + 'specid' , + 'fkid' + ]); + $optionid = $order['specid']; + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'groupon_activity' , ['id' => $order['fkid']] , 'thumb'); + $value['pluginname'] = '团购'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//团购 + case 'wlfightgroup': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , [ + 'specid' , + 'fkid' + ]); + $optionid = $order['specid']; + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'fightgroup_goods' , ['id' => $order['fkid']] , 'logo'); + $value['pluginname'] = '拼团'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//拼团 + case 'coupon': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , ['fkid']); + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'couponlist' , ['id' => $order['fkid']] , 'logo'); + $value['pluginname'] = '卡券'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//卡券 + case 'wlcoupon': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , ['fkid']); + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'couponlist' , ['id' => $order['fkid']] , 'logo'); + $value['pluginname'] = '卡券'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//卡券 + case 'bargain': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , ['fkid']); + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'bargain_activity' , ['id' => $order['fkid']] , 'thumb'); + $value['pluginname'] = '砍价'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//砍价 + case 'halfcard1': + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $value['storeid']] , 'logo'); + $value['pluginname'] = '会员特权'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'timecardrecord' , ['id' => $value['verifrcode']] , 'realmoney'); + break;//特权 + case 'halfcard2': + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $value['storeid']] , 'logo'); + $value['pluginname'] = '大礼包'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'timecardrecord' , ['id' => $value['verifrcode']] , 'realmoney'); + break;//大礼包 + } + //查找规格 + if ($value['plugin'] == 'rush') { + $optionid = pdo_getcolumn(PDO_NAME . 'rush_order' , ['id' => $value['orderid']] , 'optionid'); + } + else if ($value['plugin'] == 'groupon' || $value['plugin'] == 'wlfightgroup') { + $optionid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $value['orderid']] , 'specid'); + } + if ($optionid) { + $value['optionname'] = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $optionid] , 'title'); + } + else { + $value['optionname'] = ''; + } + $value['storename'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , [ + 'uniacid' => $_W['uniacid'] , + 'id' => $value['storeid'] + ] , 'storename'); + $value['goodimg'] = tomedia($value['goodimg']); + //兼容处理 + if (empty($value['goodimg'])) $value['goodimg'] = $_W['siteroot'] . 'web/resource/images/nopic-107.png'; + } + $data['list'] = $myorder; + $data['allnum'] = intval($allnum); + $data['allfen'] = intval($allfen); + $data['totalpage'] = ceil($allnum / 20); + $this->renderSuccess('核销记录' , $data); + } + /** + * Comment: 余额充值页面 + * Author: wlf + * Date: 2019/8/26 14:18 + */ + public function rechargePage() + { + global $_W , $_GPC; + $data = []; + $settings = Setting::wlsetting_read('recharge'); + $cashsets = Setting::wlsetting_read('cashset'); + if (empty($cashsets['withdrawals'])) { + $data['nowithdrawals'] = 1; + } + if ($settings['status']) { + $count = count($settings['kilometre']); + for ($i = 0 ; $i < $count ; $i++) { + $array[$i]['kilometre'] = $settings['kilometre'][$i]; + $array[$i]['kilmoney'] = $settings['kilmoney'][$i]; + } + } + else { + $data['norecharge'] = 1; + } + foreach ($array as $key => $val) { + $dos[$key] = $val['kilometre']; + } + array_multisort($dos , SORT_ASC , $array); + $data['activity'] = $array; + $data['credit'] = sprintf("%.2f" , $_W['wlmember']['credit2']); + //N561定制 + if (file_exists(PATH_MODULE . 'N561.log')) { + $data['transfer'] = 1; + } + $this->renderSuccess('充值页面数据' , $data); + } + /** + * Comment: 余额充值订单生成 + * Author: wlf + * Date: 2019/8/26 14:31 + */ + public function rechargeOrder() + { + global $_W , $_GPC; + $data = []; + $money = sprintf("%.2f" , trim($_GPC['money'])); + $settings = Setting::wlsetting_read('recharge'); + if (!$settings['status']) { + $this->renderError('余额充值未开启'); + } + if ($money < 0.01) { + $this->renderError('充值金额错误'); + } + $member = pdo_get('wlmerchant_member' , ['id' => $_W['mid']] , ['uid']); + $mastmobile = unserialize($_W['wlsetting']['userset']['plugin']); + if (empty($_W['wlmember']['mobile']) && in_array('recharge' , $mastmobile)) { + $this->renderError('未绑定手机号,无法支付'); + } + //创建订单 + $data = [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $_W['mid'] , + 'aid' => $_W['aid'] , + 'fkid' => 0 , + 'sid' => 0 , + 'status' => 0 , + 'paytype' => 0 , + 'createtime' => time() , + 'orderno' => createUniontid() , + 'price' => $money , + 'goodsprice' => $money , + 'num' => 1 , + 'plugin' => 'member' , + 'payfor' => 'recharge' , + 'issettlement' => 3 + ]; + pdo_insert(PDO_NAME . 'order' , $data); + $orderid = pdo_insertid(); + if ($orderid) { + $data['orderid'] = $orderid; + $this->renderSuccess('生成订单成功' , $data); + } + else { + $this->renderError('订单创建失败,请重试'); + } + } + /** + * Comment: 余额提现页面 + * Author: wlf + * Date: 2019/8/28 15:05 + */ + public function creditCashPage() + { + global $_W , $_GPC; + $cashsets = Setting::wlsetting_read('cashset'); + if (empty($cashsets['withdrawals'])) { + $this->renderError('余额提现已关闭'); + } + $data = []; + $memberInfo = pdo_get('wlmerchant_member' , ['id' => $_W['mid']]); + $data['nowmoney'] = pdo_getcolumn('mc_members' , [ + 'uniacid' => $_W['uniacid'] , + 'uid' => $memberInfo['uid'] + ] , 'credit2'); + //可提现金额 - 支付返现金额 = 实际可提现金额 + $data['nowmoney'] = sprintf("%.2f" , $data['nowmoney'] - $memberInfo['cash_back_money']); + if (!$data['nowmoney']) { + $data['nowmoney'] = 0.00; + } + $data['alcredit'] = pdo_getcolumn('wlmerchant_settlement_record' , [ + 'mid' => $memberInfo['id'] , + 'type' => 4 , + 'status' => 5 + ] , ["SUM(sapplymoney)"]); + //提现方式 + $payment_type = $cashsets['payment_type']; + if ($payment_type['alipay']) { + $data['alipaystatus'] = 1; + $data['alipay'] = $memberInfo['alipay']; + $data['realname'] = $memberInfo['realname']; + } + else { + $data['alipaystatus'] = 0; + } + if ($payment_type['we_chat']) { + $data['wechatstatus'] = 1; + } + else { + $data['wechatstatus'] = 0; + } + if ($payment_type['bank_card']) { + $data['bankcardstatus'] = 1; + $data['bank_name'] = $memberInfo['bank_name']; + $data['card_number'] = $memberInfo['card_number']; + $data['bank_username'] = $memberInfo['bank_username']; + } + else { + $data['bankcardstatus'] = 0; + } + $data['syssalepercent'] = sprintf("%.2f" , $cashsets['memberpercent']); + $data['lowsetmoney'] = $cashsets['lowsetmoney'] ? : 0; + $data['maxsetmoney'] = $cashsets['maxsetmoney'] ? : 0; + $this->renderSuccess('余额提现页面' , $data); + } + /** + * Comment: 余额提现申请 + * Author: wlf + * Date: 2019/8/28 15:36 + */ + public function creditCashing() + { + global $_W , $_GPC; + $cashsets = Setting::wlsetting_read('cashset'); + //判断临时申请内容 + $flag = pdo_get('wlmerchant_settlement_temporary',array('mid' => $_W['mid'],'uniacid'=>$_W['uniacid'],'type' => 1),array('id')); + if(!empty($flag)){ + $this->renderError('您有处理中的提现申请,请稍后再试'); + } + $settlementmoney = $_GPC['settlementmoney']; + $cashtype = $_GPC['cashtype']; + //判断提现时间限制 + $memberInfo = pdo_get('wlmerchant_member' , ['id' => $_W['mid']]); + $shopIntervalTime = $cashsets['shopIntervalTime']; + if ($shopIntervalTime > 0) { + //获取上次提现申请时间 + $startTime = pdo_fetchcolumn("SELECT applytime FROM " . tablename(PDO_NAME . "settlement_record") . " WHERE mid = {$_W['mid']} AND type = 4 AND uniacid = {$_W['uniacid']} ORDER BY applytime DESC "); + $interval = time() - $startTime; + $intervalDay = $interval / 3600 / 24; + //判断间隔时间 + $intercalRes = ceil($shopIntervalTime - $intervalDay); + if ($intercalRes > 0) { + die(json_encode(['errno' => 1 , 'message' => '请等' . $intercalRes . '天后再申请!'])); + $this->renderError('请等' . $intercalRes . '天后再申请!'); + } + } + //判断提现金额限制 + if ($_GPC['settlementmoney'] < $cashsets['lowsetmoney']) { + $this->renderError('申请失败,最低提现金额为' . $cashsets['lowsetmoney'] . '元。'); + } + if ($_GPC['settlementmoney'] > $cashsets['maxsetmoney'] && $cashsets['maxsetmoney'] > 0) { + $this->renderError('申请失败,单次最大提现金额为' . $cashsets['maxsetmoney'] . '元。'); + } + //提现方式 + if ($cashtype == 1) { + $alipay = $_GPC['alipay']; + $realname = $_GPC['realname']; + if (empty($alipay)) { + $this->renderError('请填写支付宝账号'); + } + if (empty($realname)) { + $this->renderError('请填写支付宝账号真实姓名'); + } + pdo_update('wlmerchant_member' , ['alipay' => $alipay,'realname'=>$realname] , ['id' => $_W['mid']]); + } + if ($cashtype == 2) { + if ($_W['source'] == 1) { + if (empty($memberInfo['openid'])) { + $this->renderError('您无微信账号数据,无法微信提现'); + } + else { + $sopenid = $memberInfo['openid']; + } + } + else if ($_W['source'] == 3) { + if (empty($memberInfo['wechat_openid'])) { + $this->renderError('您无微信账号数据,无法微信提现'); + } + else { + $sopenid = $memberInfo['wechat_openid']; + } + } + } + else { + $sopenid = ''; + } + if ($cashtype == 3) { + $bank_name = $_GPC['bank_name']; + $card_number = $_GPC['card_number']; + $bank_username = $_GPC['bank_username']; + if (empty($bank_name) || empty($card_number) || empty($bank_username)) { + $this->renderError('请填写银行卡各项参数'); + } + pdo_update('wlmerchant_member' , [ + 'bank_name' => $bank_name , + 'card_number' => $card_number , + 'bank_username' => $bank_username + ] , ['id' => $_W['mid']]); + } + //判断一下还有没有余额 + $nowmoney = pdo_getcolumn('mc_members' , [ + 'uniacid' => $_W['uniacid'] , + 'uid' => $memberInfo['uid'] + ] , 'credit2'); + if ($settlementmoney > $nowmoney) { + $this->renderError('可提现余额不足'); + } + $syssalepercent = sprintf("%.2f" , $cashsets['memberpercent']); + $spercentmoney = sprintf("%.2f" , $syssalepercent * $settlementmoney / 100); + $sgetmoney = sprintf("%.2f" , $settlementmoney - $spercentmoney); + $data = [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $memberInfo['id'] , + 'aid' => $_W['aid'] , + 'status' => 2 , + 'type' => 4 , + 'sapplymoney' => $settlementmoney , + 'sgetmoney' => $sgetmoney , + 'spercentmoney' => $spercentmoney , + 'spercent' => $syssalepercent , + 'applytime' => TIMESTAMP , + 'updatetime' => TIMESTAMP , + 'sopenid' => $sopenid , + 'payment_type' => $cashtype , + 'source' => $_W['source'] + ]; + $value = serialize($data); + $temporary = array( + 'info' => $value, + 'type' => 1, + 'uniacid' => $_W['uniacid'], + 'mid' => $data['mid'] + ); + $res = pdo_insert(PDO_NAME . 'settlement_temporary' , $temporary); + if($res){ + $this->renderSuccess('申请成功'); + }else{ + $this->renderError('申请失败,请重试'); + } + } + /** + * Comment: 余额提现记录 + * Author: wlf + * Date: 2019/8/28 14:16 + */ + public function creditCashRecord() + { + global $_W , $_GPC; + $status = $_GPC['status']; + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $page_start = $page * 10 - 10; + $where = " WHERE uniacid = {$_W['uniacid']} AND mid = {$_W['mid']} AND type = 4"; + if ($status == 1) { + $where .= " AND status IN (1,2,3)"; + } + else if ($status == 2) { + $where .= " AND status = 5 "; + } + else if ($status == 3) { + $where .= " AND status IN (-1,-2)"; + } + $record = pdo_fetchall("SELECT applytime,sapplymoney,payment_type,spercentmoney,status FROM " . tablename('wlmerchant_settlement_record') . "{$where} ORDER BY id DESC LIMIT {$page_start},10"); + $allnum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_settlement_record') . " {$where}"); + if ($record) { + foreach ($record as $re) { + $re['applytime'] = date('Y-m-d H:i:s' , $re['applytime']); + } + } + $data['list'] = $record; + $data['pagetotal'] = ceil($allnum / 10); + $this->renderSuccess('提现列表' , $data); + } + /** + * Comment: 用户主页信息获取 + * Author: zzw + * Date: 2019/8/30 17:18 + */ + public function mainPageInfo() + { + global $_W , $_GPC; + #1、参数获取 + $_GPC['mid'] ? $mid = $_GPC['mid'] : $this->renderError("缺少参数:mid"); + $set = Setting::wlsetting_read('userset'); + #2、获取用户信息 + $info = pdo_get(PDO_NAME . "member" , ['id' => $mid] , [ + 'nickname' , + 'encodename', + 'avatar' , + 'createtime' , + 'main_browse', + 'identity_id' + ]); + $info['nickname'] = base64_decode($info['encodename']); + $browse = $info['main_browse'] ? : intval(0); + $info['createtime'] = date("Y-m-d H:i:s" , $info['createtime']); + if ($info['main_browse'] >= 10000) $info['main_browse'] = sprintf("%.1f" , ($info['main_browse'] / 10000)) . '万'; + #3、获取用户访客总数 + $info['visitor'] = pdo_getcolumn(PDO_NAME . "member_visitor_record" , ['mid' => $mid] , 'count(*)'); + #4、获取用户发帖总数 + $info['release'] = pdo_getcolumn(PDO_NAME . "pocket_informations" , [ + 'mid' => $mid , + 'status' => 0 + ] , 'count(*)'); + #5、用户访问操作 + if ($_W['mid'] != $mid) { + #6、当前用户的浏览量自增一 + pdo_update(PDO_NAME . "member" , ['main_browse' => ($browse + 1)] , ['id' => $mid]); + #7、判断当前用户是否为第一次访问 + $data = ['visitor_id' => $_W['mid'] , 'mid' => $mid]; + $visitor_id = pdo_getcolumn(PDO_NAME . "member_visitor_record" , $data , 'id'); + if ($visitor_id) { + pdo_update(PDO_NAME . "member_visitor_record" , ['update_time' => time()] , ['id' => $visitor_id]); + } + else { + $data['create_time'] = time(); + $data['update_time'] = time(); + pdo_insert(PDO_NAME . "member_visitor_record" , $data); + } + $member_interest = pdo_get(PDO_NAME . 'member_interest',['mid' => $_W['mid'],'interest_mid' => $mid]); + $info['is_interest'] = $member_interest?true:false; + } + //获取背景图 + if ($_W['mid'] != $mid) { + $info['useself'] = 0; + } + else { + $info['useself'] = 1; + } + $main_bgimg = pdo_getcolumn(PDO_NAME . 'member' , ['id' => $mid] , 'main_bgimg'); + if (!empty($main_bgimg)) { + $info['thumb'] = tomedia($main_bgimg); + $info['isdefault'] = 0; + } + else { + $info['thumb'] = !empty($set['usermainbg']) ? tomedia($set['usermainbg']) : URL_MODULE . 'h5/resource/image/mainbgimg.png'; + $info['isdefault'] = 1; + } + //获取认证信息 + if (p('attestation')) { + $info['attestation'] = Attestation::checkAttestation(1 , $mid); + } + else { + $info['attestation'] = 0; + } + //判断当前平台是否存在掌上信息插件 + $info['is_pocket'] = intval(0);//0=不存在 1=存在 + if (uniacid_p('pocket') && $info['release'] > 0) { + $info['is_pocket'] = intval(1); + } + //判断是否有商户 + $storeinfo = pdo_fetchall("SELECT b.id FROM " . tablename(PDO_NAME . "merchantuser") . " as a RIGHT JOIN " . tablename(PDO_NAME . "merchantdata") . " as b ON a.storeid = b.id WHERE a.mid = {$mid} AND a.enabled = 1 AND b.enabled = 1 GROUP BY a.storeid "); + $storenum = count($storeinfo); + $info['is_store'] = $storenum > 0 ? 1 : 0; + //判断用户是否是家政服务者 + $info['is_artificer'] = intval(0);//0=不存在 1=存在 + if (p('housekeep')) { + $artificer = pdo_get(PDO_NAME.'housekeep_artificer',array('uniacid'=>$_W['uniacid'],'status' => 1,'aid'=>$_W['aid'],'mid' => $mid),['id','detail','thumbs','casethumbs','tagarray']); + if($artificer['id'] > 0){ + $info['is_artificer'] = intval(1); + $info['housekeep_type'] = Housekeep::getRelation($artificer['id'],2); + $info['thumbs'] = Housekeep::beautifyImgInfo($artificer['thumbs']); + $info['casethumbs'] = Housekeep::beautifyImgInfo($artificer['casethumbs']); + $info['detail'] = $artificer['detail']; + $info['tagarray'] = unserialize($artificer['tagarray']); + } + } + + $identity_data = pdo_get(PDO_NAME . 'member_identity',['id' => $info['identity_id']]); // 获取身份 + $info['identity'] = $identity_data ? $identity_data['name'] : '未知'; // 身份 + $info['interest_user_count'] = pdo_count(PDO_NAME . 'member_interest',['mid' => $mid]); // 关注数量 + $info['fans_user_count'] = pdo_count(PDO_NAME . 'member_interest',['interest_mid' => $mid]); // 粉丝数量 + + $student_info = pdo_get(PDO_NAME . 'member_student_info',['mid' => $mid,'check_status' => 1,'status' => 1],['department_name','school_name','code']); + $info['school_department_name'] = $student_info['department_name'] ?: ''; // 学院名称 + $info['school_name'] = $student_info['school_name'] ?: ''; // 学校名称 + $info['school_code'] = $student_info['code'] ?: ''; // 学号 + $this->renderSuccess("用户主页信息" , $info); + } + /** + * Comment: 获取用户访客列表 + * Author: zzw + * Date: 2019/8/30 17:47 + */ + public function visitorList() + { + global $_W , $_GPC; + #1、参数获取 + $_GPC['mid'] ? $mid = $_GPC['mid'] : $this->renderError("缺少参数:mid"); + $page = $_GPC['page'] ? : 1; + $pageIndex = $_GPC['page_index'] ? : 10; + $pageStart = $page * $pageIndex - $pageIndex; + #2、获取总数 + $total = pdo_getcolumn(PDO_NAME . "member_visitor_record" , ['mid' => $mid] , 'count(*)'); + #3、获取访客信息列表 + $list = pdo_fetchall("SELECT b.id as mid,b.nickname,b.encodename,b.avatar,FROM_UNIXTIME(a.update_time,'%Y-%m-%d %H:%i:%S') as update_time FROM " . tablename(PDO_NAME . "member_visitor_record") . " as a LEFT JOIN " . tablename(PDO_NAME . "member") . " as b ON a.visitor_id = b.id WHERE a.mid = {$mid} ORDER BY a.update_time DESC LIMIT {$pageStart},{$pageIndex}"); + foreach ($list as &$val) $val['nickname'] = base64_decode($val['encodename']); + #2、数据拼装 + $data['total'] = ceil($total / $pageIndex); + $data['list'] = $list; + $this->renderSuccess('访客列表' , $data); + } + /** + * Comment: 买家提醒商家发货 + * Author: wlf + * Date: 2019/9/19 11:43 + */ + public function remindSend() + { + global $_W , $_GPC; + $orderid = $_GPC['orderid']; + $plugin = $_GPC['plugin']; + $goodsname = $_GPC['goodsname']; + if ($orderid == $_GPC['remind_Send']) { + $this->renderError('此订单已经提醒发货'); + } + //获取订单数据 + if ($plugin == 'rush') { + $order = pdo_get('wlmerchant_rush_order' , ['id' => $orderid] , ['sid' , 'num' , 'orderno']); + } + else { + $order = pdo_get('wlmerchant_order' , ['id' => $orderid] , ['sid' , 'num' , 'orderno']); + } + //获取商户店员 + $merchantusers = pdo_fetchall("SELECT mid FROM " . tablename('wlmerchant_merchantuser') . "WHERE storeid = {$order['sid']} AND ismain IN (1,3) ORDER BY id DESC"); + if ($merchantusers) { + foreach ($merchantusers as $user) { + $data = [ + 'first' => '订单编号[' . $order['orderno'] . ']' , + 'type' => '买家提醒发货' ,//业务类型 + 'content' => '商品名称:[' . $goodsname . ']' ,//业务内容 + 'status' => '待发货' ,//处理结果 + 'time' => date('Y-m-d H:i:s' , time()) ,//操作时间 + 'remark' => '请商家负责人尽快发货' + ]; + TempModel::sendInit('service' , $user['mid'] , $data , $_W['source'] , ''); + } + } + isetcookie("remind_Send" , $orderid , 86400); + $this->renderSuccess('提醒成功'); + } + /** + * Comment: 登录接口(所有登录方式) —— 开发中(小程序完成) + * Author: zzw + * Date: 2019/11/18 15:09 + */ + public function login() + { + global $_W , $_GPC; + #1、参数获取 + $source = $_GPC['source1'] ? $_GPC['source1'] : $_W['source']; + if(empty($source)){ + $this->renderError('访问渠道错误!');//1=公众号(默认);2=H5;3=小程序 4=app + } + /* $type = 'mode' . $_GPC['mode'] OR $this->renderError('非法登录,请使用正确的登录方式');//1-账号密码登录 2=微信登录 + #2、生成对应的方法名称 + # 'loginSource1Mode2'=公众号微信登录; + # 'loginSource2Mode1'=H5账号密码登录; + # 'loginSource3Mode2'=小程序微信登录; + $name = 'login' . ucfirst($source) . ucfirst($type); + #3、判断方法是否存在 + $instance = new Login(); + if (method_exists($instance, $name)) $result = $instance->$name($_GPC); + else $this->renderError('非法登录,请使用正确的登录方式!'); + #4、根据登录结果进行对应的操作 + switch ($name) { + case 'loginSource1Mode2': + //拼装用户信息 + $userInfo = [ + 'openid' => $result['openid'] ?: '',//用户openid + 'nickname' => $result['nickname'] ?: '',//用户昵称 + 'avatar' => $result['headimgurl'] ?: '',//用户头像 + 'unionid' => $result['unionid'] ?: '',//用户unionid + ]; + //判断是否获取用户信息 + if (empty($userInfo['openid'])) $this->renderError('登录信息获取失败!'); + //获取用户数据 + $sql = "SELECT id,tokey FROM " . tablename(PDO_NAME . "member") . " WHERE openid = '{$userInfo['openid']}' "; + break;//公众号微信登录 + case 'loginSource2Mode1': + break;//H5账号密码登录 + case 'loginSource3Mode2': + //解密获取用户基本信息 + $encryptedData = $_GPC['encryptedData'] OR $this->renderError('授权失败,缺少加密信息!'); + $iv = $_GPC['iv'] OR $this->renderError('授权失败,缺少加密信息'); + $basicInfo = openssl_decrypt(base64_decode($encryptedData), "AES-128-CBC", base64_decode($result['session_key']), 1, base64_decode($iv)); + $basicInfo = json_decode($basicInfo, true); + //拼装用户数据信息 + $userInfo = [ + 'wechat_openid' => $result['openid'] ?: '',//用户openid + 'nickname' => $basicInfo['nickName'] ?: '',//用户昵称 + 'avatar' => $basicInfo['avatarUrl'] ?: '',//用户头像 + 'unionid' => $result['unionid'] ?: '' //用户unionid + ]; + $sessionKey = $result['session_key'] ?: ''; + //判断是否获取用户信息 + if (empty($userInfo['wechat_openid'])) $this->renderError('登录信息获取失败!'); + + //获取用户数据 + $sql = "SELECT id,tokey FROM " . tablename(PDO_NAME . "member") . " WHERE wechat_openid = '{$userInfo['wechat_openid']}'"; + break;//小程序微信登录 + } + #4、判断用户是否存在 + $userInfo2 = pdo_fetch($sql); + + if (!$userInfo2) { + //生成微擎用户信息数据 + $group_id = pdo_getcolumn('mc_groups', ['uniacid' => $_W['uniacid'], 'isdefault' => 1], 'groupid'); + $salt = random(8); + $data = [ + 'uniacid' => $_W['uniacid'], + 'salt' => $salt, + 'groupid' => $group_id, + 'createtime' => TIMESTAMP, + 'nickname' => $userInfo['nickname'], + ]; + //储存微擎用户数据信息 + pdo_insert('mc_members', $data); + $uid = pdo_insertid(); + //生成平台用户数据信息 + $data2 = [ + 'uid' => $uid, + 'uniacid' => $_W['uniacid'], + 'openid' => $userInfo['openid'], + 'wechat_openid' => $userInfo['wechat_openid'], + 'nickname' => $userInfo['nickname'], + 'salt' => $salt, + 'avatar' => $userInfo['avatar'] ?: './addons/weliam_smartcity/app/resource/image/touxiang.png', + 'registerflag' => 1, + 'tokey' => strtoupper(MD5(sha1(time() . random(12)))), + 'createtime' => time() + ]; + if (!empty($sessionKey)) $data2['session_key'] = $sessionKey; + pdo_insert(PDO_NAME . 'member', $data2); + } else if (!empty($sessionKey)) { + $data2 = [ + 'nickname' => $userInfo['nickname'], + 'avatar' => $userInfo['avatar'] ?: './addons/weliam_smartcity/app/resource/image/touxiang.png', + ]; + if (!empty($sessionKey)) $data2['session_key'] = $sessionKey; + pdo_update(PDO_NAME . "member", $data2, ['id' => $userInfo2['id']]); + } + $userInfo['tokey'] = $userInfo2['tokey'] ? $userInfo2['tokey'] : $data2['tokey']; + wl_setcookie('usersign', $userInfo, 3600 * 24 * 30); + wl_setcookie('user_token', $userInfo['tokey'], 3600 * 24 * 30);*/ + if($source == 3){ + $result = Login::loginSource3Mode2($_GPC); + if (is_error($result)) { + $this->renderError($result['message']); + } + //解密获取用户基本信息 + $encryptedData = $_GPC['encryptedData'] OR $this->renderError('授权失败,缺少加密信息!'); + $iv = $_GPC['iv'] OR $this->renderError('授权失败,缺少加密信息'); + $basicInfo = openssl_decrypt(base64_decode($encryptedData) , "AES-128-CBC" , base64_decode($result['session_key']) , 1 , base64_decode($iv)); + if(empty($basicInfo)){ + $this->renderError('用户信息解密失败,请返回重新登录'); + } + $basicInfo = json_decode($basicInfo , true); + if (empty($result['openid'])) { + $this->renderError('登录信息获取失败!'); + } + //拼装用户数据信息 + $userInfo = [ + 'wechat_openid' => $result['openid'] ? : '' ,//用户openid + 'nickname' => $basicInfo['nickName'] ? : '' ,//用户昵称 + 'avatar' => $basicInfo['avatarUrl'] ? : '' ,//用户头像 + 'unionid' => $basicInfo['unionId'] ? $basicInfo['unionId'] : $result['unionid'] ,//用户unionid + 'session_key' => $result['session_key'] ? : ''//用户session_key + ]; + $member = Member::wl_member_create($userInfo , 'wxapp'); + $head_id = intval($_GPC['head_id']); + if ($_W['source'] == 3 && $head_id > 0 && p('distribution') && $head_id != $member['id']) { + Distribution::addJunior($head_id , $member['id']); + } + $token = pdo_getcolumn(PDO_NAME . 'login' , [ + 'token' => $member['tokey'] , + 'refresh_time >' => time() + ] , 'secret_key'); + if (empty($token)) { + $res = Login::generateToken($member['tokey'] , 'login'); + $token = $res['message']; + } + }else if($source == 4){ + file_put_contents(PATH_DATA . "appinfo.log", var_export($_GPC, true) . PHP_EOL, FILE_APPEND); + + $userInfo = [ + 'webapp_openid' => $_GPC['openid'] ? : '' ,//用户openid + 'nickname' => $_GPC['nickName'] ? : '' ,//用户昵称 + 'avatar' => $_GPC['avatarUrl'] ? : '' ,//用户头像 + 'unionid' => $_GPC['unionid'],//用户unionid + ]; + + if (empty($userInfo['webapp_openid'])) { + $this->renderError('无openid无法登陆'); + } + $member = Member::wl_member_create($userInfo , 'webapp'); + $token = pdo_getcolumn(PDO_NAME . 'login' , [ + 'token' => $member['tokey'] , + 'refresh_time >' => time() + ] , 'secret_key'); + if (empty($token)) { + $res = Login::generateToken($member['tokey'] , 'login'); + $token = $res['message']; + } + } + + $this->renderSuccess('登录成功' , ['token' => $token]); + } + /** + * Comment: 修改个人信息 + * Author: zzw + * Date: 2019/11/5 14:05 + */ + public function setUserInfo() + { + global $_W , $_GPC; + #1、参数获取 + $type = $_GPC['type'] ? : 'get';//get=获取信息;set=设置信息 + if(!empty($_GPC['realname'])){ + $info['realname'] = $_GPC['realname']; + } + if(!empty($_GPC['bank_name'])){ + $info['bank_name'] = $_GPC['bank_name']; + } + if(!empty($_GPC['card_number'])){ + $info['card_number'] = $_GPC['card_number']; + } + if(!empty($_GPC['bank_username'])){ + $info['bank_username'] = $_GPC['bank_username']; + } + if(!empty($_GPC['alipay'])){ + $info['alipay'] = $_GPC['alipay']; + } + #2、获取用户信息 + if ($type == 'get') { + $getInfo = pdo_get(PDO_NAME . "member" , ['id' => $_W['mid']] , [ + 'realname' , + 'bank_name' , + 'card_number' , + 'bank_username' , + 'alipay' + ]); + //判断设置项目 + $getInfo['bankstatus'] = $_W['wlsetting']['cashset']['payment_type']['bank_card'] ? : 0; + $getInfo['alipaystatus'] = $_W['wlsetting']['cashset']['payment_type']['alipay'] ? : 0; + if ($getInfo){ + $this->renderSuccess('用户信息' , $getInfo); + }else{ + $this->renderError('用户信息不存在'); + } + } + #3、设置用户信息 + if ($type == 'set' && is_array($info) && count($info) > 0) { + //查询是否修改内容 + $isHave = pdo_get(PDO_NAME . "member" , $info); + if ($isHave) $this->renderError('请修改信息后提交!'); + //修改内容 提交修改内容的数据信息 + $setInfo = pdo_update(PDO_NAME . "member" , $info , ['id' => $_W['mid']]); + if ($setInfo) $this->renderSuccess('修改成功'); + else $this->renderError('修改失败'); + } + } + /** + * Comment: 上传个人主页图片 + * Author: wlf + * Date: 2019/11/15 16:23 + */ + public function setMainBgImg() + { + global $_W , $_GPC; + $img = $_GPC['img']; + pdo_update('wlmerchant_member' , ['main_bgimg' => $img] , ['id' => $_W['mid']]); + $this->renderSuccess('设置成功'); + } + /** + * Comment: 小程序用户的手机加密信息解密操作 + * Author: zzw + * Date: 2019/11/18 15:37 + */ + public function phoneDecrypt(){ + global $_W , $_GPC; + //基本参数信息获取 + $data = $_GPC['data'] OR $this->renderError('缺少加密数据!'); + $iv = $_GPC['iv'] OR $this->renderError('缺少加密算法的初始向量!'); + $reslus = Login::loginSource3Mode2($_GPC); + $session_key = $reslus['session_key']; + if(!$session_key) $this->reLogin('session_key为空,请重新登录'); + //数据解密 + try { + $content = WeApp::decryptedMobile($session_key , $iv , $data); + $this->renderSuccess('用户手机号' , ['phone' => $content['phoneNumber']]); + }catch (Exception $e){ + $this->renderError("绑定失败,请重试!"); + } + } + /** + * Comment: 通过经纬度获取当前城市参数 + * Author: wlf + * Date: 2020/05/18 13:55 + */ + public function lng2areaid() + { + global $_W , $_GPC; + $lng = $_GPC['lng']; + $lat = $_GPC['lat']; + if (empty($lng) || empty($lat)) { + $this->renderError('参数错误'); + } + $area = MapService::guide_gcoder($lat . ',' . $lng , 0); + if (!is_error($area)) { + $areaid = $area['result']['ad_info']['adcode']; + } + else { + $this->renderError($area['message']); + } + $area = pdo_get('wlmerchant_area' , ['id' => $areaid] , ['pid' , 'level']); + if ($area['level'] == 3) { + $data['countyid'] = $areaid; + $data['cityid'] = $area['pid']; + $data['provinceid'] = pdo_getcolumn(PDO_NAME . 'area' , ['id' => $area['pid']] , 'pid'); + } + else if ($area['level'] == 2) { + $data['cityid'] = $areaid; + $data['countyid'] = pdo_getcolumn(PDO_NAME . 'area' , ['pid' => $areaid] , 'id'); + $data['provinceid'] = $area['pid']; + } + else if ($area['level'] == 1) { + $data['provinceid'] = $areaid; + $data['cityid'] = pdo_getcolumn(PDO_NAME . 'area' , ['pid' => $areaid] , 'id'); + $data['countyid'] = pdo_getcolumn(PDO_NAME . 'area' , ['pid' => $data['cityid']] , 'id'); + } + else { + $this->renderError('无信息' , ['provinceid' => 0 , 'cityid' => 0 , 'countyid' => 0]); + } + $this->renderSuccess('城市信息' , $data); + } + /** + * Comment: 创建余额转赠活动(N561定制) + * Author: wlf + * Date: 2020/06/01 18:14 + */ + public function createTransfer() + { + global $_W , $_GPC; + if (!file_exists(PATH_MODULE . 'N561.log')) { + $this->renderError('暂无权限'); + } + $title = $_GPC['title']; + $allnum = $_GPC['allnum']; + $money = sprintf("%.2f" , $_GPC['money']); + $allmoney = sprintf("%.2f" , $money * $allnum); + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + $res = Member::credit_update_credit2($_W['mid'] , -$allmoney , '创建转赠活动[' . $title . ']活动扣除余额'); + if (!is_error($res)) { + $transfer = [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $_W['mid'] , + 'title' => $title , + 'allnum' => $allnum , + 'surplus' => $allnum , + 'money' => $money , + 'allmoney' => $allmoney , + 'createtime' => time() + ]; + $res = pdo_insert(PDO_NAME . 'transfer_list' , $transfer); + $transid = pdo_insertid(); + if ($res) { + //生成二维码 + //使用默认二维码 + $path = 'pages/subPages/balance/collectMoney/collectMoney?transfer_id=' . $transid . '&head_id=' . $_W['mid'];//基本路径,也是小程序路径 页面站位中 + #3、二维码生成 + //公众号 + $path1 = h5_url($path); + $filename = md5('transfer_id' . $transid . 'source1path' . $path1); + $qrCodeLink = Poster::qrcodeimg($path1 , $filename); + $wechatqrlink = tomedia($qrCodeLink); + //小程序 + $qrCodeLink3 = WeApp::getQrCode($path , 'qrcode_' . $filename . '.png'); + if (is_array($qrCodeLink3)) $qrCodeLink3 = Poster::qrcodeimg($path , $filename); + $wxappqrlink = tomedia($qrCodeLink3); + //生成短连接 + $url = h5_url('pages/subPages/balance/collectMoney/collectMoney' , [ + 'transfer_id' => $transid , + 'head_id' => $_W['mid'] + ]); + $result = Util::long2short($url); + file_put_contents(PATH_DATA . "long2short.log" , var_export($result , true) . PHP_EOL , FILE_APPEND); + if (!is_error($result) && $result['short_url'] != 'h') { + $url = $result['short_url']; + } + pdo_update(PDO_NAME . 'transfer_list' , [ + 'wechatqrlink' => $wechatqrlink , + 'wxappqrlink' => $wxappqrlink , + 'pageurl' => $url + ] , ['id' => $transid]); + MysqlFunction::commit(); + $this->renderSuccess('创建成功' , ['transid' => $transid]); + } + else { + MysqlFunction::rollback(); + $this->renderError('活动创建失败,请刷新重试'); + } + } + else { + MysqlFunction::rollback(); + $this->renderError($res['message']); + } + } + /** + * Comment: 初始化余额转赠活动页面(N561定制) + * Author: wlf + * Date: 2020/06/02 14:10 + */ + public function transferpage() + { + global $_W , $_GPC; + if (!file_exists(PATH_MODULE . 'N561.log')) { + $this->renderError('暂无权限'); + } + if (empty($_W['mid'])) { + $this->renderError('请先登录'); + } + $id = $_GPC['id']; + if (empty($id)) { + $this->renderError('缺少关键参数:id'); + } + $transfer = pdo_get('wlmerchant_transfer_list' , ['id' => $id] , ['title' , 'surplus' , 'mid' , 'money']); + $member = pdo_get('wlmerchant_member' , ['id' => $transfer['mid']] , ['nickname' , 'avatar' , 'encodename']); + $data = [ + 'nickname' => base64_decode($member['encodename']) , + 'avatar' => tomedia($member['avatar']) , + 'title' => $transfer['title'] , + 'money' => $transfer['money'] + ]; + $this->renderSuccess('初始化信息' , $data); + } + /** + * Comment: 用户获取转赠余额(N561定制) + * Author: wlf + * Date: 2020/06/02 14:57 + */ + public function getTransfer() + { + global $_W , $_GPC; + if (!file_exists(PATH_MODULE . 'N561.log')) { + $this->renderError('暂无权限'); + } + if (empty($_W['mid'])) { + $this->renderError('请先登录'); + } + $id = $_GPC['id']; + if (empty($id)) { + $this->renderError('缺少关键参数:id'); + } + $realname = $_GPC['realname']; + if (empty($realname)) { + $this->renderError('请填写您的姓名'); + } + $mobile = $_GPC['mobile']; + if (empty($mobile)) { + $this->renderError('请填写您的手机号'); + } + $flag = pdo_get('wlmerchant_transfer_record' , ['mid' => $_W['mid'] , 'tid' => $id] , ['id']); + if (empty($flag)) { + pdo_update('wlmerchant_member' , ['mobile' => $mobile , 'realname' => $realname] , ['id' => $_W['mid']]); + $transfer = pdo_get('wlmerchant_transfer_list' , ['id' => $id] , [ + 'title' , + 'surplus' , + 'money' , + 'is_over' + ]); + if (!empty($transfer['is_over'])) { + $this->renderError('转赠活动已过期'); + } + if ($transfer['surplus'] < 1) { + $this->renderError('转赠活动已结束'); + } + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + pdo_update('wlmerchant_transfer_list' , ['surplus -=' => 1] , ['id' => $id]); + $record = [ + 'uniacid' => $_W['uniacid'] , + 'tid' => $id , + 'mid' => $_W['mid'] , + 'money' => $transfer['money'] , + 'realname' => $realname , + 'mobile' => $mobile , + 'createtime' => time() + ]; + $res = pdo_insert(PDO_NAME . 'transfer_record' , $record); + if ($res) { + $changeres = Member::credit_update_credit2($_W['mid'] , $record['money'] , '参与转赠活动[' . $transfer['title'] . ']活动获得余额'); + if ($changeres) { + MysqlFunction::commit(); + $this->renderSuccess('活动参与成功'); + } + else { + MysqlFunction::rollback(); + $this->renderError('余额获取失败,请刷新重试'); + } + } + else { + MysqlFunction::rollback(); + $this->renderError('活动参与失败,请刷新重试'); + } + } + else { + $this->renderError('您已参加过此活动,无法重复参加'); + } + } + /** + * Comment: 转赠活动详情(N561定制) + * Author: wlf + * Date: 2020/06/02 15:57 + */ + public function transferDetail() + { + global $_W , $_GPC; + if (!file_exists(PATH_MODULE . 'N561.log')) { + $this->renderError('暂无权限'); + } + $id = $_GPC['id']; + if (empty($id)) { + $this->renderError('缺少关键参数:id'); + } + $transfer = pdo_get('wlmerchant_transfer_list' , ['id' => $id] , [ + 'title' , + 'surplus' , + 'mid' , + 'allmoney' , + 'wechatqrlink' , + 'wxappqrlink' , + 'pageurl' + ]); + $member = pdo_get('wlmerchant_member' , ['id' => $transfer['mid']] , ['nickname' , 'avatar' , 'encodename']); + if ($_W['source'] == 3) { + $qrCodeLink = $transfer['wxappqrlink']; + } + else { + $qrCodeLink = $transfer['wechatqrlink']; + } + $data = [ + 'nickname' => base64_decode($member['encodename']) , + 'avatar' => tomedia($member['avatar']) , + 'title' => $transfer['title'] , + 'money' => $transfer['allmoney'] , + 'qrlink' => $qrCodeLink , + 'pageurl' => $transfer['pageurl'] + ]; + $this->renderSuccess('活动详情' , $data,1); + } + /** + * Comment: 余额转赠往期活动列表(N561定制) + * Author: wlf + * Date: 2020/06/02 14:57 + */ + public function oldTransferList() + { + global $_W , $_GPC; + if (!file_exists(PATH_MODULE . 'N561.log')) { + $this->renderError('暂无权限'); + } + if (empty($_W['mid'])) { + $this->renderError('请先登录'); + } + $data = []; + $pindex = $_GPC['pindex'] ? $_GPC['pindex'] : 1; + $pageStart = $pindex * 10 - 10; + $list = pdo_fetchall("SELECT id,allnum,title,surplus,allmoney,createtime,is_over FROM " . tablename('wlmerchant_transfer_list') . "WHERE uniacid = {$_W['uniacid']} AND mid = {$_W['mid']} ORDER BY createtime DESC LIMIT {$pageStart},10"); + $allnum = pdo_fetchcolumn("SELECT count(id) FROM " . tablename('wlmerchant_transfer_list') . "WHERE uniacid = {$_W['uniacid']} AND mid = {$_W['mid']}"); + $data['pagetotal'] = ceil($allnum / 10); + if (!empty($list)) { + foreach ($list as &$li) { + $li['createtime'] = date('Y-m-d H:i:s' , $li['createtime']); + } + } + $data['list'] = $list; + $this->renderSuccess('往期活动' , $data); + } + /** + * Comment: 余额转赠活动领取记录(N561定制) + * Author: wlf + * Date: 2020/06/05 16:16 + */ + public function getTransferRecord() + { + global $_W , $_GPC; + if (!file_exists(PATH_MODULE . 'N561.log')) { + $this->renderError('暂无权限'); + } + if (empty($_W['mid'])) { + $this->renderError('请先登录'); + } + $id = $_GPC['id']; + $pindex = max(1 , intval($_GPC['page'])); + $psize = 20; + $start = $pindex * $psize - $psize; + if (empty($id)) { + $this->renderError('缺少关键参数:id'); + } + if ($pindex == 1) { + $transfer = pdo_get('wlmerchant_transfer_list' , ['id' => $id] , [ + 'title' , + 'surplus' , + 'allnum' , + 'allmoney' , + 'createtime' + ]); + $transfer['createtime'] = date("Y-m-d H:i:s" , $transfer['createtime']); + $data['transfer'] = $transfer; + } + $where = " a.uniacid = {$_W['uniacid']} AND a.tid = {$id} "; + $limit = " LIMIT {$start},{$psize}"; + $sql = "SELECT a.tid,a.mid,a.money,a.realname,a.mobile,a.createtime,b.nickname,b.encodename,b.avatar FROM " . tablename("wlmerchant_transfer_record") . " as a LEFT JOIN " . tablename(PDO_NAME . "member") . " as b ON a.mid = b.id WHERE {$where} ORDER BY a.createtime DESC"; + $total = pdo_fetchcolumn('SELECT count(a.id) FROM ' . tablename('wlmerchant_transfer_record') . " as a LEFT JOIN " . tablename(PDO_NAME . "member") . " as b ON a.mid = b.id WHERE {$where}"); + $data['allpage'] = ceil($total / 20); + $lists = pdo_fetchall($sql . $limit); + foreach ($lists as &$li) { + $li['createtime'] = date('Y-m-d H:i:s' , $li['createtime']); + $li['avatar'] = tomedia($li['avatar']); + $li['nickname'] = base64_decode($li['encodename']); + } + $data['record'] = $lists; + $this->renderSuccess('领取记录' , $data); + } + + /** + * Comment: 根据手机号筛选用户 + * Author: wlf + * Date: 2021/08/19 16:16 + */ + public function mobileToMmeber(){ + global $_W , $_GPC; + $mobile = trim($_GPC['mobile']); + if(empty($mobile)){ + $this->renderError('请输入查询手机号'); + }else{ + $member = pdo_get('wlmerchant_member',array('mobile' => $mobile),array('avatar','nickname','mobile','encodename')); + if(empty($member)){ + $member = []; + }else{ + $member['avatar'] = tomedia($member['avatar']); + $member['nickname'] = base64_decode($member['encodename']); + } + } + $this->renderSuccess('查询成功' , $member); + } + + /** + * Comment: 074定制-积分转赠页面初始化 + * Author: wlf + * Date: 2022/01/06 10:10 + */ + public function integralPage(){ + global $_W, $_GPC; + $data['mycredit'] = sprintf("%.2f" , $_W['wlmember']['credit1']); + $data['integralsxf'] = $_W['wlsetting']['creditset']['integralsxf']; + $this->renderSuccess('页面初始化信息',$data); + } + + /** + * Comment: 074定制-积分转赠接口 + * Author: wlf + * Date: 2022/01/06 10:17 + */ + public function integralApi(){ + global $_W, $_GPC; + $integra = trim($_GPC['credit']); + $pwd = trim($_GPC['pwd']); + $mobile = trim($_GPC['mobile']); + $member = pdo_get('wlmerchant_member',array('id' => $_W['mid']),array('integralpwd','nickname')); + if($pwd != $member['integralpwd']){ + $this->renderError('支付密码错误,请重新输入'); + } + $getmember = pdo_get(PDO_NAME.'member',array('uniacid'=>$_W['uniacid'],'mobile'=> $mobile),['id','nickname']); + if(empty($getmember)){ + $this->renderError('查无此用户'); + } + if($getmember['id'] == $_W['mid']){ + $this->renderError('请勿转赠给自己'); + } + if($integra > 0){ + //计算手续费 + $serviceCharge = sprintf("%.2f" ,$integra*$_W['wlsetting']['creditset']['integralsxf']/100); + $allcredit = $serviceCharge + $integra; + if($allcredit > $_W['wlmember']['credit1']){ + $this->renderError('剩余积分不足,请重新输入转赠数量'); + }else{ + Member::credit_update_credit1($_W['mid'] , -$integra , '转赠积分给用户[' . $getmember['nickname'].']'); + if($serviceCharge > 0){ + Member::credit_update_credit1($_W['mid'] , -$serviceCharge , '转赠积分手续费扣除'); + } + Member::credit_update_credit1($getmember['id'] , $integra , '用户[' . $member['nickname'].']给您赠送积分'); + $this->renderSuccess('操作成功'); + } + }else{ + $this->renderError('转赠积分数量错误,请重新输入'); + } + } + + + /** + * Comment: 074定制-支付密码修改接口 + * Author: wlf + * Date: 2022/01/24 10:28 + */ + public function integralpwd(){ + global $_W, $_GPC; + $mobile = pdo_getcolumn(PDO_NAME.'member',array('id'=>$_W['mid']),'mobile'); + $pwd = $_GPC['pwd']; + $code = $_GPC['code']; + $pin_info = pdo_get('wlmerchant_pincode' , ['mobile' => $mobile]); + if (empty($pin_info)) { + $this->renderError('验证码错误'); + } + if ($pin_info['time'] < time() - 300) { + $this->renderError('验证码已过期,请重新获取' , ['code' => 1]); + } + if ($code != $pin_info['code']) { + $this->renderError('验证码错误'); + } + $res = pdo_update('wlmerchant_member',array('integralpwd' => $pwd),array('id' => $_W['mid'])); + $this->renderSuccess('修改成功'); + } + + /** + * Comment: 添加关注 + * Author: whj + * Date: 2023/03/27 09:51 + */ + public function addInterestMember() { + global $_W, $_GPC; + $interest_mid = $_GPC['interest_mid']; + if (empty($interest_mid) || !is_numeric($interest_mid)) $this->renderError('请求失败'); + $data = ['mid' => $_W['mid'], 'interest_mid' => $interest_mid, 'create_time' => time()]; + $result = pdo_insert(PDO_NAME . 'member_interest',$data); + if (!$result) $this->renderError('关注失败'); + $this->renderSuccess('关注成功'); + } + /** + * Comment: 取关 + * Author: whj + * Date: 2023/03/27 09:56 + */ + public function cancelInterestMember() { + global $_W, $_GPC; + $interest_mid = $_GPC['interest_mid']; + $where = ['mid' => $_W['mid'], 'interest_mid' => $interest_mid]; + $query_res = pdo_get(PDO_NAME . 'member_interest',$where,'id'); + if (!$query_res) $this->renderError('取关失败,数据不存在'); + $del_res = pdo_delete(PDO_NAME . 'member_interest',['id' => $query_res['id']]); + if (!$del_res) $this->renderError('取关失败'); + $this->renderSuccess('取关成功'); + } + /** + * Comment: 获取关注用户信息 + * Author: whj + * Date: 2023/03/27 09:56 + */ + public function getInterestUserList() { + global $_W, $_GPC; + + $mid = $_GPC['mid'] ?: $_W['mid']; + $where = ['mid' => $mid]; + + if (!empty($_GPC['name'])) { + $interest_mid_arr = []; + $user_res = pdo_getall(PDO_NAME . 'member',['nickname like' => '%'.trim($_GPC['name']).'%'],['id']); + foreach ($user_res as $user_row) $interest_mid_arr[] = $user_row['id']; + if ($interest_mid_arr) { + $where['interest_mid'] = $interest_mid_arr; + } else { + $where['id'] = 0; + } + } + + $list = pdo_getall(PDO_NAME . 'member_interest',$where,['interest_mid'],'','id desc'); + foreach ($list as &$row) { + $user = pdo_get(PDO_NAME . 'member',['id' => $row['interest_mid']],['encodename','avatar']); + $row['nickname'] = base64_decode($user['encodename']); // 用户名 + $row['avatar'] = $user['avatar']; // 用户头像 + } + $this->renderSuccess('数据获取成功',['data' => $list]); + } + /** + * Comment: 获取粉丝用户信息 + * Author: whj + * Date: 2023/03/27 09:56 + */ + public function getFansUserList() { + global $_W,$_GPC; + + $mid = $_GPC['mid'] ?: $_W['mid']; + $where = ['interest_mid' => $mid]; + + if (!empty($_GPC['name'])) { + $mid_arr = []; + $user_res = pdo_getall(PDO_NAME . 'member',['nickname like' => '%'.trim($_GPC['name']).'%'],['id']); + foreach ($user_res as $user_row) $mid_arr[] = $user_row['id']; + if ($mid_arr) { + $where['mid'] = $mid_arr; + } else { + $where['id'] = 0; + } + } + + $list = pdo_getall(PDO_NAME . 'member_interest',$where,['mid'],'','id desc'); + foreach ($list as &$row) { + $user = pdo_get(PDO_NAME . 'member',['id' => $row['mid']],['encodename','avatar']); + $row['nickname'] = base64_decode($user['encodename']); // 用户名 + $row['avatar'] = $user['avatar']; // 用户头像 + $row['fans_mid'] = $row['mid']; + unset($row['mid']); + } + $this->renderSuccess('数据获取成功',['data' => $list]); + } + + /** + * 获取规则中心列表 + * @return void + */ + public function getRuleCenterList() + { + global $_W, $_GPC; + + $where = ['status' => 1]; + $pindex = max(1, intval($_GPC['page'])); + $psize = $_GPC['pageSize'] ?: 10; + + $field = 'id,img'; + $memberData = Util::getNumData($field, PDO_NAME . 'rule_center', $where, 'sort desc', $pindex, $psize, 1); + $list = $memberData[0]; + foreach ($list as &$item) { + $item['img'] = tomedia($item['img']); + } + + $this->renderSuccess('数据获取成功',['list' => $list]); + } +} diff --git a/addons/weliam_smartcity/api/Order.php b/addons/weliam_smartcity/api/Order.php new file mode 100644 index 0000000..f0aa8f4 --- /dev/null +++ b/addons/weliam_smartcity/api/Order.php @@ -0,0 +1,1156 @@ + $goodsid),array('appointdays','appointarray')); + $order = pdo_get('wlmerchant_rush_order',array('id' => $orderid),array('estimatetime')); + break; + case 2: + $goods = pdo_get('wlmerchant_groupon_activity',array('id' => $goodsid),array('appointdays','appointarray')); + $order = pdo_get('wlmerchant_order',array('id' => $orderid),array('estimatetime')); + break; + case 3: + $goods = pdo_get('wlmerchant_fightgroup_goods',array('id' => $goodsid),array('appointdays','appointarray')); + $order = pdo_get('wlmerchant_order',array('id' => $orderid),array('estimatetime')); + break; + case 7: + $goods = pdo_get('wlmerchant_bargain_activity',array('id' => $goodsid),array('appointdays','appointarray')); + $order = pdo_get('wlmerchant_order',array('id' => $orderid),array('estimatetime')); + break; + } + $data['appointdays'] = $goods['appointdays']; + $appointarray = unserialize($goods['appointarray']); + if($initialization > 0){ + //计算天数 + $casttime = $order['estimatetime'] - time(); + $castday = ceil($casttime/86400); + $goods['appointdays'] = $goods['appointdays'] ? $goods['appointdays'] + 1: 999; + $limitday = min($goods['appointdays'],$castday,30); + $weekArray = ["周日","周一","周二","周三","周四","周五","周六"]; + for($i=0;$i<$limitday;$i++){ + $time = $i * 86400 + time(); + if($i == 0){ + $week = '今天'; + }else if($i == 1){ + $week = '明天'; + }else{ + $weekN = date("w",$time); + $week = $weekArray[$weekN]; + } + $day = date("d",$time); + $dateI = date("Y-m-d",$time); + $dayArray[] = [ + 'week' => $week, + 'day' => $day, + 'date' => $dateI + ]; + } + $data['dayArray'] = $dayArray; + } + $appointNarray = []; + foreach($appointarray as $appo){ + $appo['peoplenums'] = $appo['peoplenums'] ? : 0; + //计算库存 + $appstarttime = strtotime($appDate.$appo['startTime']); + $appendtime = strtotime($appDate.$appo['endTime']); + if($appendtime < $appstarttime){ + $appendtime = $appendtime + 86400; + } + if($appstarttime > $order['estimatetime'] || $appendtime < time()){ + continue; + }else{ + $num = pdo_getcolumn('wlmerchant_appointlist',array('status' => [0,1],'date' => $appDate,'starttime' => $appo['startTime'],'endtime' => $appo['endTime'],'type' => $type, 'goodid' => $goodsid ),array("SUM(num)")); + $num = $num ? : 0; + $surnum = $appo['peoplenums'] - $num; + $appo['surnum'] = $surnum > 0 ? $surnum : 0; + $appointNarray[] = $appo; + } + } + $data['appointarray'] = $appointNarray; + $this->renderSuccess('预约页面',$data); + } + + /** + * Comment: 填入预约申请 + * Author: wlf + * Date: 2020/12/30 16:10 + */ + public function addAppoint(){ + global $_W , $_GPC; + //参数获取 + $num = $_GPC['num']; //预约数量 + $alnum = $_GPC['peoplenums']; //总数量 + $appDate = $_GPC['appdate']; //日期 + $appStime = $_GPC['appstarttime']; //开始时间 + $appEtime = $_GPC['appendtime']; //结束时间 + $type = $_GPC['pluginno']; //类型 + $goodsid = $_GPC['goodsid']; //商品id + $orderid = $_GPC['orderid']; //订单id + $remark = $_GPC['remark']; //备注 + //查询数据 + switch($type){ + case 1: + $goods = pdo_get('wlmerchant_rush_activity',array('id' => $goodsid),array('uniacid','aid','appointment','name','appointstatus','sid')); + $plugin = 'rush'; + $pluginName = '抢购'; + $goodsName = $goods['name']; + $orderNo = pdo_getcolumn(PDO_NAME.'rush_order',array('id'=>$orderid),'orderno'); + break; + case 2: + $goods = pdo_get('wlmerchant_groupon_activity',array('id' => $goodsid),array('uniacid','appointment','name','aid','appointstatus','sid')); + $plugin = 'groupon'; + $pluginName = '团购'; + $goodsName = $goods['name']; + $orderNo = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'orderno'); + break; + case 3: + $goods = pdo_get('wlmerchant_fightgroup_goods',array('id' => $goodsid),array('uniacid','name','aid','appointment','appointstatus','sid')); + $plugin = 'wlfightgroup'; + $pluginName = '拼团'; + $goodsName = $goods['name']; + $orderNo = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'orderno'); + break; + case 7: + $goods = pdo_get('wlmerchant_bargain_activity',array('id' => $goodsid),array('uniacid','name','aid','appointment','appointstatus','sid')); + $plugin = 'bargain'; + $pluginName = '砍价'; + $goodsName = $goods['name']; + $orderNo = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'orderno'); + break; + } + if($goods['appointstatus'] == 2){ + $status = 1; + }else{ + $status = 0; + } + $appstarttime = strtotime($appDate.$appStime); + $appendtime = strtotime($appDate.$appEtime); + if($appendtime < $appstarttime){ + $appendtime = $appendtime + 86400; + } + if($alnum > 0){ + $alreadnum = pdo_getcolumn('wlmerchant_appointlist',array('date' => $appDate,'starttime' => $appStime,'endtime' => $appEtime,'type' => $type,'goodid'=> $goodsid),array("SUM(num)")); + $supunm = $alnum - $alreadnum; + if($supunm < 1){ + $this->renderError('此时间段已经约满,请选择其他的时间段'); + }else if($supunm < $num){ + $this->renderError('此时间段还能预约'.$supunm.'份'); + } + } + if($goods['appointment'] > 0 && ($appendtime - time() < $goods['appointment'] * 3600) ){ + $this->renderError('此商品需提前'.$goods['appointment'].'小时预约,请选择靠后的时间段'); + } + $ids = pdo_fetchall("SELECT id FROM ".tablename('wlmerchant_smallorder')."WHERE plugin = '{$plugin}' AND orderid = {$orderid} AND appointstatus = 1 AND status = 1 ORDER BY id DESC LIMIT {$num}"); + if(empty($ids)){ + $this->renderError('无可用核销码,请刷新重试'); + } + $ids = array_column($ids,'id'); + $sorderids = serialize($ids); + $data = [ + 'uniacid' => $goods['uniacid'], + 'aid' => $goods['aid'], + 'orderid' => $orderid, + 'mid' => $_W['mid'], + 'sid' => $goods['sid'], + 'type' => $type, + 'goodid' => $goodsid, + 'num' => $num, + 'date' => $appDate, + 'starttime' => $appStime, + 'endtime' => $appEtime, + 'starttimestamp' => $appstarttime, + 'endtimestamp' => $appendtime, + 'status' => $status, + 'appointtime' => time(), + 'sorderids' => $sorderids, + 'orderno' => $orderNo, + 'remark' => $remark + ]; + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + $res = pdo_insert(PDO_NAME . 'appointlist', $data); + if($res){ + if($status > 0){ //免审核 + $upSres = pdo_update('wlmerchant_smallorder',array('appointstatus' => 3,'appstarttime' => $appstarttime,'appendtime' => $appendtime),array('id' => $ids)); + //发送消息给商家 + if($upSres){ + $first = '一个'.$pluginName.'订单已经预约'; + $type = '订单消费预约'; + $content = '商品名:['.$goodsName.']'; + $newStatus = '预约成功'; + $remark = '订单号:['.$orderNo.'],预约数量:'.$num.'份,点击查看订单'; + $urls = h5_url('pages/subPages2/booked/reservationList/reservationList' , ['sid' => $goods['sid']]); + News::noticeShopAdmin($goods['sid'],$first,$type,$content,$newStatus,$remark,time(),$urls); + //发送消息给客户 + $first = '您的'.$pluginName.'订单已经成功预约'; + $url = h5_url('pages/subPages/orderList/orderDetails/orderDetails' , ['orderid' => $orderid , 'plugin' => $plugin]); + News::jobNotice($_W['mid'],$first,$type,$content,$newStatus,$remark,time(),$url); + } + }else{ + $upSres = pdo_update('wlmerchant_smallorder',array('appointstatus' => 2,'appstarttime' => $appstarttime,'appendtime' => $appendtime),array('id' => $ids)); + if($upSres) { + //发送消息给商家 + $first = '一个' . $pluginName . '订单申请预约'; + $type = '订单消费预约'; + $content = '商品名:[' . $goodsName . ']'; + $newStatus = '待审核'; + $remark = '订单号:[' . $orderNo . '],预约数量:' . $num . '份,点击审核预约'; + $urls = h5_url('pages/subPages2/booked/reservationList/reservationList' , ['sid' => $goods['sid']]); + News::noticeShopAdmin($goods['sid'], $first, $type, $content, $newStatus, $remark, time(),$urls); + } + } + if($upSres){ + MysqlFunction::commit(); + $this->renderSuccess('预约成功',['status'=>1]); + }else{ + MysqlFunction::rollback(); + $this->renderError('预约失败,请刷新重试'); + } + }else{ + MysqlFunction::rollback(); + $this->renderError('预约失败,请刷新重试'); + } + } + + /** + * Comment: 用户预约详情 + * Author: wlf + * Date: 2020/01/12 17:03 + */ + public function appointDetail(){ + global $_W , $_GPC; + $orderid = $_GPC['orderid']; + $goodsid = $_GPC['goodsid']; + $type = $_GPC['pluginno']; + if(empty($orderid) || empty($goodsid) || empty($type)){ + $this->renderError('缺少重要参数,请刷新重试'); + } + switch($type){ + case 1: + $goods = pdo_get('wlmerchant_rush_activity',array('id' => $goodsid),array('thumb','name','sid')); + $optionid = pdo_getcolumn(PDO_NAME.'rush_order',array('id'=>$orderid),'optionid'); + $data['goods']['logo'] = tomedia($goods['thumb']); + $data['goods']['name'] = $goods['name']; + $sid = $goods['sid']; + break; + case 2: + $goods = pdo_get('wlmerchant_groupon_activity',array('id' => $goodsid),array('thumb','name','sid')); + $optionid = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'specid'); + $data['goods']['logo'] = tomedia($goods['thumb']); + $data['goods']['name'] = $goods['name']; + $sid = $goods['sid']; + break; + case 3: + $goods = pdo_get('wlmerchant_fightgroup_goods',array('id' => $goodsid),array('merchantid','name','logo')); + $optionid = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'specid'); + $data['goods']['logo'] = tomedia($goods['logo']); + $data['goods']['name'] = $goods['name']; + $sid = $goods['merchantid']; + break; + case 7: + $goods = pdo_get('wlmerchant_bargain_activity',array('id' => $goodsid),array('thumb','name','sid')); + $optionid = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'specid'); + $data['goods']['logo'] = tomedia($goods['thumb']); + $data['goods']['name'] = $goods['name']; + $sid = $goods['sid']; + break; + } + if($optionid > 0){ + $data['goods']['optionName'] = pdo_getcolumn(PDO_NAME.'goods_option',array('id'=>$optionid),'title'); + } + //商户信息 + $merchant = pdo_get('wlmerchant_merchantdata',array('id' => $sid),array('storename','mobile','address','lat','lng','storehours')); + + $storehours = unserialize($merchant['storehours']); + if(!empty($storehours['startTime'])){ + $merchant['storehours'] = $storehours['startTime'] . ' - ' . $storehours['endTime']; + }else{ + $merchant['storehours'] = ''; + foreach($storehours as $hk => $hour){ + if($hk > 0){ + $merchant['storehours'] .= ','.$hour['startTime'] . ' - ' . $hour['endTime']; + }else{ + $merchant['storehours'] .= $hour['startTime'] . ' - ' . $hour['endTime']; + } + } + } + $data['merchant'] = $merchant; + //预约列表 + $applist = pdo_getall('wlmerchant_appointlist',array('orderid' => $orderid,'type' => $type),array('remark','num','id','status','date','starttime','endtime','reason')); + foreach($applist as &$app){ + if($app['status'] == 0){ + $app['statusTips'] = '预约审核中'; + $app['statusText'] = '正在预约中,请耐心等待哦~'; + }else if($app['status'] == 1){ + $app['statusTips'] = '预约已通过'; + $app['statusText'] = '商户已确认,请在预约时间内前往商家核销~'; + }else if($app['status'] == 2){ + $app['statusTips'] = '预约被驳回'; + $app['statusText'] = '驳回原因:'.$app['reason']; + }else if($app['status'] == 3){ + $app['statusTips'] = '预约已取消'; + $app['statusText'] = '本次预约已被您取消'; + }else if($app['status'] == 4){ + $app['statusTips'] = '预约已取消'; + $app['statusText'] = '本次预约已被商户取消'; + } + } + $data['applist'] = $applist; + $this->renderSuccess('预约详情',$data); + } + + /** + * Comment: 取消预约接口 + * Author: wlf + * Date: 2020/01/13 13:05 + */ + public function cancelAppoint(){ + global $_W , $_GPC; + $id = $_GPC['appointid']; + $channel = $_GPC['channel']; //操作方 3用户 4商户 + if(empty($id)){ + $this->renderError('缺少重要参数,请刷新重试'); + } + $res = pdo_update('wlmerchant_appointlist',array('status' => $channel,'dotime' => time()),array('id' => $id)); + if($res){ + $appoint = pdo_get('wlmerchant_appointlist',array('id' => $id),array('goodid','orderno','num','type','mid','sid','sorderids')); + //修改核销码状态 + $sorderids = unserialize($appoint['sorderids']); + pdo_update('wlmerchant_smallorder',array('appointstatus' => 1,'appstarttime' => 0,'appendtime' => 0),array('id' => $sorderids)); + switch($appoint['type']){ + case 1: + $goods = pdo_get('wlmerchant_rush_activity',array('id' => $appoint['goodid']),array('name')); + $goodsName = $goods['name']; + $pluginName = '抢购'; + break; + case 2: + $goods = pdo_get('wlmerchant_groupon_activity',array('id' => $appoint['goodid']),array('name')); + $goodsName = $goods['name']; + $pluginName = '团购'; + break; + case 3: + $goods = pdo_get('wlmerchant_fightgroup_goods',array('id' => $appoint['goodid']),array('name')); + $goodsName = $goods['name']; + $pluginName = '拼团'; + break; + case 7: + $goods = pdo_get('wlmerchant_bargain_activity',array('id' => $appoint['goodid']),array('name')); + $goodsName = $goods['name']; + $pluginName = '砍价'; + break; + } + if($channel == 3){ + //发送消息给商户 + $first = '一个' . $pluginName . '订单预约已取消'; + $type = '订单预约取消'; + $content = '商品名:[' . $goodsName . ']'; + $newStatus = '已取消'; + $remark = '订单号:[' . $appoint['orderno'] . '],预约数量:' . $appoint['num'] . '份,用户已取消预约'; + News::noticeShopAdmin($appoint['sid'], $first, $type, $content, $newStatus, $remark, time()); + }else if($channel == 4){ + //发送消息给商户 + $first = '您的' . $pluginName . '订单预约已被取消'; + $type = '订单预约取消'; + $content = '商品名:[' . $goodsName . ']'; + $newStatus = '已取消'; + $remark = '订单号:[' . $appoint['orderno'] . '],预约数量:' . $appoint['num'] . '份,商户已取消预约'; + $url = h5_url('pages/subPages/orderList/orderDetails/orderDetails' , ['orderid' => $orderid , 'plugin' => $plugin]); + News::jobNotice($appoint['mid'],$first,$type,$content,$newStatus,$remark,time(),$url); + } + $this->renderSuccess('取消成功'); + }else{ + $this->renderError('取消失败,请刷新重试'); + } + } + + + /** + * Comment: 商户预约列表 + * Author: wlf + * Date: 2021/01/06 14:34 + */ + public function appointList(){ + global $_W , $_GPC; + $sid = $_GPC['sid']; + $status = $_GPC['status']; + if(empty($sid)){ + $this->renderError('店铺信息错误,请刷新重试'); + } + $data = []; + //查询数据 + $page = $_GPC['page'] ? $_GPC['page'] : 1;//当前页 + $pageIndex = $_GPC['page_index'] ? $_GPC['page_index'] : 10; + $pageStart = $page * $pageIndex - $pageIndex; + $where = ['uniacid' => $_W['uniacid'],'sid' => $sid]; + if($status > 0){ + if($status == 5){ + $where['status'] = 0; + }else{ + $where['status'] = trim($status); + } + } + $List = Util::getNumData('id,orderid,mid,num,orderno,date,sorderids,starttime,endtime,status,remark,type,goodid,type,starttimestamp', PDO_NAME . 'appointlist', $where,'appointtime DESC', $pageStart, $pageIndex, 1); + $applist = $List[0]; + $data['pagetotal'] = ceil($List[2] / $pageIndex); + foreach($applist as &$al){ + //$al['appointtime'] = date('Y-m-d H:i',$al['appointtime']); + switch($al['type']){ + case 1: + $order = pdo_get('wlmerchant_rush_order',array('id' => $al['orderid']),array('orderno','username','mobile','optionid')); + $order['specid'] = $order['optionid']; + $goods = pdo_get('wlmerchant_rush_activity',array('id' => $al['goodid']),array('thumb','name')); + $al['username'] = $order['username']; + $al['mobile'] = $order['mobile']; + break; + case 2: + $order = pdo_get('wlmerchant_order',array('id' => $al['orderid']),array('orderno','name','mobile','specid')); + $goods = pdo_get('wlmerchant_groupon_activity',array('id' => $al['goodid']),array('thumb','name')); + $al['username'] = $order['name']; + $al['mobile'] = $order['mobile']; + break; + case 3: + $order = pdo_get('wlmerchant_order',array('id' => $al['orderid']),array('orderno','name','mobile','specid')); + $goods = pdo_get('wlmerchant_fightgroup_goods',array('id' => $al['goodid']),array('logo','name')); + $al['username'] = $order['name']; + $al['mobile'] = $order['mobile']; + $goods['thumb'] = $goods['logo']; + break; + case 7: + $order = pdo_get('wlmerchant_order',array('id' => $al['orderid']),array('orderno','name','mobile','specid')); + $goods = pdo_get('wlmerchant_bargain_activity',array('id' => $al['goodid']),array('thumb','name')); + $al['username'] = $order['name']; + $al['mobile'] = $order['mobile']; + break; + } + $al['orderno'] = $order['orderno']; + $al['goodsName'] = $goods['name']; + $al['goodsLogo'] = tomedia($goods['thumb']); + if($order['specid'] > 0){ + $al['optionName'] = pdo_getcolumn(PDO_NAME.'goods_option',array('id'=>$order['specid']),'title'); + } + if($al['status'] == 1){ + //判断核销码是否还正常 + $sorderids = unserialize($al['sorderids']); + foreach($sorderids as $soid){ + $status = pdo_getcolumn(PDO_NAME.'smallorder',array('id'=>$soid),'status'); + if($status != 1){ + $eFlag = 1; + } + } + if(empty($eFlag)){ + if($al['starttimestamp'] < time()){ + $al['hexiaoflag'] = 1; + } + $al['cancelflag'] = 1; + } + } + if(empty($al['hexiaoflag'])){ + $al['hexiaoflag'] = 0; + } + if(empty($al['cancelflag'])){ + $al['cancelflag'] = 0; + } + + } + $data['list'] = $applist; + $this->renderSuccess('预约列表',$data); + } + + + /** + * Comment: 商户预约审核 + * Author: wlf + * Date: 2021/01/06 16:33 + */ + public function examineAppoint(){ + global $_W , $_GPC; + $id = $_GPC['id']; //预约id + $status = $_GPC['examine']; //审核类型 1通过 2驳回 + $reason = $_GPC['reason']; //驳回原因 + if(empty($status) || empty($id)){ + $this->renderError('缺少关键参数,请刷新重试'); + } + $appinfo = pdo_get(PDO_NAME.'appointlist',array('id'=>$id),['sorderids','goodid','mid','type','orderid','num']); + $goodsid = $appinfo['goodid']; + $orderid = $appinfo['orderid']; + $ids = unserialize($appinfo['sorderids']); + switch($appinfo['type']){ + case 1: + $goods = pdo_get('wlmerchant_rush_activity',array('id' => $goodsid),array('uniacid','aid','appointment','name','appointstatus','sid')); + $plugin = 'rush'; + $pluginName = '抢购'; + $goodsName = $goods['name']; + $orderNo = pdo_getcolumn(PDO_NAME.'rush_order',array('id'=>$orderid),'orderno'); + break; + case 2: + $goods = pdo_get('wlmerchant_groupon_activity',array('id' => $goodsid),array('uniacid','appointment','name','aid','appointstatus','sid')); + $plugin = 'groupon'; + $pluginName = '团购'; + $goodsName = $goods['name']; + $orderNo = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'orderno'); + break; + case 3: + $goods = pdo_get('wlmerchant_fightgroup_goods',array('id' => $goodsid),array('uniacid','name','aid','appointment','appointstatus','sid')); + $plugin = 'wlfightgroup'; + $pluginName = '拼团'; + $goodsName = $goods['name']; + $orderNo = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'orderno'); + break; + case 7: + $goods = pdo_get('wlmerchant_bargain_activity',array('id' => $goodsid),array('uniacid','name','aid','appointment','appointstatus','sid')); + $plugin = 'bargain'; + $pluginName = '砍价'; + $goodsName = $goods['name']; + $orderNo = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'orderno'); + break; + } + if($status == 1){ + $res = pdo_update('wlmerchant_appointlist',array('status' => 1),array('id' => $id)); + if($res){ + $upSres = pdo_update('wlmerchant_smallorder',array('appointstatus' => 3),array('id' => $ids)); + if($upSres){ + //发送消息给客户 + $first = '您的'.$pluginName.'订单已经成功预约'; + $type = '订单预约结果通知'; + $content = '商品名:['.$goodsName.']'; + $newStatus = '预约成功'; + $remark = '订单号:['.$orderNo.'],预约数量:'.$appinfo['num'].'份,点击查看详情'; + $url = h5_url('pages/subPages/orderList/orderDetails/orderDetails' , ['orderid' => $orderid , 'plugin' => $plugin]); + News::jobNotice($appinfo['mid'],$first,$type,$content,$newStatus,$remark,time(),$url); + } + } + }else if($status == 2){ + if(empty($reason)){ + $this->renderError('请输入驳回原因'); + } + $res = pdo_update('wlmerchant_appointlist',array('status' => 2,'reason' => $reason),array('id' => $id)); + if($res){ + $upSres = pdo_update('wlmerchant_smallorder',array('appointstatus' => 1,'appstarttime'=> 0,'appendtime'=>0),array('id' => $ids)); + if($upSres){ + //发送消息给客户 + $first = '您的'.$pluginName.'订单预约失败'; + $type = '订单预约结果通知'; + $content = '商品名:['.$goodsName.']'; + $newStatus = '预约失败'; + $remark = '驳回原因:['.$reason.'],点击重新预约'; + $url = h5_url('pages/subPages/orderList/orderDetails/orderDetails' , ['orderid' => $orderid , 'plugin' => $plugin]); + News::jobNotice($appinfo['mid'],$first,$type,$content,$newStatus,$remark,time(),$url); + } + } + } + $this->renderSuccess('操作成功',['status'=>1]); + } + + /** + * Comment: 商户核销预约记录 + * Author: wlf + * Date: 2021/01/25 11:46 + */ + public function hexiaoAppoint(){ + global $_W, $_GPC; + $id = $_GPC['id']; //预约id + if(empty($id)){ + $this->renderError('缺少重要参数,请刷新重试'); + } + $appoint = pdo_get('wlmerchant_appointlist',array('id' => $id),array('sorderids','type','orderid')); + $sorderids = unserialize($appoint['sorderids']); + if(!is_array($sorderids)){ + $this->renderError('无核销码编号,请刷新重试'); + } + foreach($sorderids as $smid){ + $checkcode = pdo_getcolumn(PDO_NAME.'smallorder',array('id'=>$smid),'checkcode'); + if($appoint['type'] == 1){ + $res = Rush::hexiaoorder($appoint['orderid'],-1,1,3,$checkcode); + }else if($appoint['type'] == 2){ + $res = Groupon::hexiaoorder($appoint['orderid'],-1,1,3,$checkcode); + }else if($appoint['type'] == 3){ + $res = Wlfightgroup::hexiaoorder($appoint['orderid'],-1,1,3,$checkcode); + }else if($appoint['type'] == 7){ + $res = Bargain::hexiaoorder($appoint['orderid'],-1,1,3,$checkcode); + } + } + if($res){ + $this->renderSuccess('核销成功',['status'=>1]); + }else{ + $this->renderError('核销失败,请刷新重试'); + } + } + + /** + * Comment: 评价页面初始化 + * Author: wlf + * Date: 2021/05/08 15:26 + */ + public function commentPage(){ + global $_W, $_GPC; + $id = $_GPC['order_id']; //订单 + $plugin = $_GPC['plugin']; //订单类型 + if(empty($id) || empty($plugin)){ + $this->renderError('参数错误,请返回重试'); + } + switch($plugin){ + case 'rush': + $order = pdo_get('wlmerchant_rush_order',array('id' => $id),array('actualprice','activityid','optionid')); + $data['price'] = $order['actualprice']; + if($order['optionid'] > 0){ + $data['specname'] = pdo_getcolumn(PDO_NAME.'goods_option',array('id'=>$order['optionid']),'title'); + } + $goods = pdo_get('wlmerchant_rush_activity',array('id' => $order['activityid']),array('name','thumb')); + $data['thumb'] = tomedia($goods['thumb']); + $data['goodsname'] = $goods['name']; + break; + case 'groupon': + $order = pdo_get('wlmerchant_order',array('id' => $id),array('price','fkid','specid')); + $data['price'] = $order['price']; + if($order['specid'] > 0){ + $data['specname'] = pdo_getcolumn(PDO_NAME.'goods_option',array('id'=>$order['specid']),'title'); + } + $goods = pdo_get('wlmerchant_groupon_activity',array('id' => $order['fkid']),array('name','thumb')); + $data['thumb'] = tomedia($goods['thumb']); + $data['goodsname'] = $goods['name']; + break; + case 'wlfightgroup': + $order = pdo_get('wlmerchant_order',array('id' => $id),array('price','fkid','specid')); + $data['price'] = $order['price']; + if($order['specid'] > 0){ + $data['specname'] = pdo_getcolumn(PDO_NAME.'goods_option',array('id'=>$order['specid']),'title'); + } + $goods = pdo_get('wlmerchant_fightgroup_goods',array('id' => $order['fkid']),array('name','logo')); + $data['thumb'] = tomedia($goods['logo']); + $data['goodsname'] = $goods['name']; + break; + case 'bargain': + $order = pdo_get('wlmerchant_order',array('id' => $id),array('price','fkid')); + $data['price'] = $order['price']; + $goods = pdo_get('wlmerchant_bargain_activity',array('id' => $order['fkid']),array('name','thumb')); + $data['thumb'] = tomedia($goods['thumb']); + $data['goodsname'] = $goods['name']; + break; + case 'coupon': + $order = pdo_get('wlmerchant_order',array('id' => $id),array('price','fkid')); + $data['price'] = $order['price']; + $goods = pdo_get('wlmerchant_couponlist',array('id' => $order['fkid']),array('title','logo')); + $data['thumb'] = tomedia($goods['logo']); + $data['goodsname'] = $goods['title']; + break; + case 'halfcard': + $order = pdo_get('wlmerchant_order',array('id' => $id),array('price','fkid','sid')); + $data['price'] = $order['price']; + $goods = pdo_get('wlmerchant_halfcardlist',array('id' => $order['fkid']),array('title')); + $merchant = pdo_get('wlmerchant_merchantdata',array('id' => $order['sid']),array('logo')); + $data['thumb'] = tomedia($merchant['logo']); + $data['goodsname'] = $goods['title']; + break; + case 'citydelivery': + $order = pdo_get('wlmerchant_order',array('id' => $id),array('price','fkid','sid')); + $data['price'] = $order['price']; + $merchant = pdo_get('wlmerchant_merchantdata',array('id' => $order['sid']),array('storename','logo')); + $data['thumb'] = tomedia($merchant['logo']); + $data['goodsname'] = '['.$merchant['storename'].']同城配送商品'; + break; + case 'housekeep': + $order = pdo_get('wlmerchant_order',array('id' => $id),array('price','fkid','sid')); + $data['price'] = $order['price']; + $goods = pdo_get('wlmerchant_housekeep_service',array('id' => $order['fkid']),array('title','thumb')); + $data['thumb'] = tomedia($goods['thumb']); + $data['goodsname'] = $goods['title']; + break; + } + $this->renderSuccess('评价页面初始化信息',$data); + } + + + /** + * Comment: 手机号转赠接口 + * Author: wlf + * Date: 2021/08/19 11:48 + */ + public function transferApi(){ + global $_W, $_GPC; + $type = $_GPC['type']; //类型 1卡券 2红包 + $id = $_GPC['id']; //转赠卡券或红包id + $mobile = $_GPC['mobile']; //转赠人的手机号 + if(empty($type) || empty($id) || empty($mobile)){ + $this->renderError('参数错误,请刷新重试'); + } + + //判断被转赠用户是否存在 + $getMember = pdo_get('wlmerchant_member',array('mobile' => $mobile,'uniacid' => $_W['uniacid']),array('id','nickname')); + if(empty($getMember)){ + $this->renderError('手机号不存在,请先要求好友进入系统绑定手机重试'); + } + if($getMember['id'] == $_W['mid']){ + $this->renderError('不能转赠给自己'); + } + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + //修改原纪录状态 + if($type == 1){ + $coupon = pdo_get('wlmerchant_member_coupons',array('id' => $id),array('mid','parentid','status','title','orderno','transferflag')); + if($coupon['mid'] != $_W['mid']){ + MysqlFunction::rollback(); + $this->renderError('卡券已经转赠,请勿重复转赠'); + } + if($coupon['status'] != 1){ + MysqlFunction::rollback(); + $this->renderError('卡券状态错误,请刷新重试'); + } + $get_limit = pdo_getcolumn(PDO_NAME.'couponlist',array('id'=>$coupon['parentid']),'get_limit'); + if($coupon['get_limit'] > 0){ + $num = wlCoupon::getCouponNum($coupon['parentid'],1,$getMember['id']); + if($num > $get_limit || $num == $get_limit){ + MysqlFunction::rollback(); + $this->renderError('该用户不能拥有更多的此卡券'); + } + } + if(empty($coupon['transferflag'])){ + $res2 = pdo_update('wlmerchant_order',array('status' => 2),array('orderno' => $coupon['orderno'],'status' => 1)); //修改订单状态 + }else{ + $res2 = 1; + } + $res1 = pdo_update('wlmerchant_member_coupons',array('mid' => $getMember['id'],'transferflag' => 1),array('id' => $id)); //修改卡券所属用户 + $res3 = pdo_update('wlmerchant_smallorder',array('mid' => $getMember['id']),array('orderno' => $coupon['orderno'])); //修改子订单状态 + if(empty($res1) || empty($res2) || empty($res3)){ + MysqlFunction::rollback(); + $this->renderError('原卡券修改失败,请刷新重试'); + } + $typename = '卡券'; + $title = $coupon['title']; + $url = h5_url('pages/subPages/coupon/coupon'); + }else{ + $redapck = pdo_get('wlmerchant_redpack_records',array('id' => $id),array('mid','packid','status','transferflag')); + $parredpack = pdo_get(PDO_NAME.'redpacks',array('id'=>$redapck['packid']),['title','limit_count']); + if($redapck['mid'] != $_W['mid']){ + MysqlFunction::rollback(); + $this->renderError('红包已经转赠,请勿重复转赠'); + } + if($redapck['status'] > 0){ + MysqlFunction::rollback(); + $this->renderError('红包状态错误,请刷新重试'); + } + if($parredpack['limit_count'] > 0){ + $mycounts = Redpack::getReceiveTotal($redapck['packid'],$getMember['id'],1,0); + if ($mycounts >= $parredpack['limit_count']){ + MysqlFunction::rollback(); + $this->renderError('该用户不能拥有更多的此红包'); + } + } + $res1 = pdo_update('wlmerchant_redpack_records',array('mid' => $getMember['id'],'transferflag' => 1),array('id' => $id)); //修改红包所属用户 + if(empty($res1)){ + MysqlFunction::rollback(); + $this->renderError('原红包修改失败,请刷新重试'); + } + $title = $parredpack['title']; + $typename = '线上红包'; + $url = h5_url('pages/subPages/redpacket/myredpacket'); + } + //生成转赠记录 + $data = [ + 'uniacid' => $_W['uniacid'], + 'type' => $type, + 'objid' => $id, + 'omid' => $_W['mid'], + 'nmid' => $getMember['id'], + 'status' => 1, + 'createtime' => time(), + 'gettime' => time(), + 'transfermode' => 1, + 'mobile' => $mobile + ]; + $inRes = pdo_insert(PDO_NAME . 'transferRecord', $data); + if($inRes){ + MysqlFunction::commit(); + //发送模板消息 + $first = '恭喜您获得好友['.$_W['wlmember']['nickname'].']转赠的'.$typename; + $type = $typename.'转赠通知'; + $content = $typename.'名:['.$title.']'; + $newStatus = '获取成功'; + $remark = '点击前去使用'; + News::jobNotice($getMember['id'],$first,$type,$content,$newStatus,$remark,time(),$url); + $this->renderSuccess('转赠成功'); + }else{ + MysqlFunction::rollback(); + $this->renderError('转赠记录生成失败,请刷新重试'); + } + } + + + /** + * Comment: 分享预转赠接口 + * Author: wlf + * Date: 2021/08/19 16:26 + */ + public function planTransfer(){ + global $_W, $_GPC; + $type = $_GPC['type']; //类型 1卡券 2红包 + $id = $_GPC['id']; //转赠卡券或红包id + if(empty($type) || empty($id)){ + $this->renderError('参数错误,请刷新重试'); + } + //分享图片信息 + if($_W['source'] == 3){ + $trdata['shareimg'] = $_W['wlsetting']['share']['tr_wxapp_share_image'] ? : $_W['wlsetting']['share']['wxapp_share_image']; + }else{ + $trdata['shareimg'] = $_W['wlsetting']['share']['tr_share_image'] ? : $_W['wlsetting']['share']['share_image']; + } + $trdata['shareimg'] = tomedia($trdata['shareimg']); + //查看是否已有预转赠记录 + $recordid = pdo_getcolumn(PDO_NAME.'transferRecord',array('uniacid'=>$_W['uniacid'],'type'=>$type['areaid'],'objid' => $id,'omid' => $_W['mid'],'status' => 0),'id'); + if($recordid > 0){ + if($type == 1){ + $coupon = pdo_get('wlmerchant_member_coupons',array('id' => $id),array('title','sub_title')); + $trdata['title'] = $coupon['sub_title']; + $trdata['desc'] = $coupon['title']; + }else{ + $redapck = pdo_get('wlmerchant_redpack_records',array('id' => $id),array('packid')); + $redpar = pdo_get('wlmerchant_redpacks',array('id' => $redapck['packid']),array('title','full_money','cut_money')); + $trdata['title'] = '满'.$redpar['full_money'].'元减'.$redpar['cut_money'].'元红包在线领取'; + $trdata['desc'] = $redpar['title']; + } + $trdata['recordid'] = $recordid; + $this->renderSuccess('转赠记录生成成功',$trdata); + }else{ + if($type == 1){ + $coupon = pdo_get('wlmerchant_member_coupons',array('id' => $id),array('mid','parentid','sub_title','status','title','orderno')); + if($coupon['mid'] != $_W['mid']){ + $this->renderError('卡券已经转赠,请勿重复转赠'); + } + if($coupon['status'] != 1){ + $this->renderError('卡券状态错误,请刷新重试'); + } + $trdata['title'] = $coupon['sub_title']; + $trdata['desc'] = $coupon['title']; + pdo_update('wlmerchant_member_coupons',array('status' => 6),array('id' => $id)); + }else{ + $redapck = pdo_get('wlmerchant_redpack_records',array('id' => $id),array('mid','packid','status')); + if($redapck['mid'] != $_W['mid']){ + $this->renderError('红包已经转赠,请勿重复转赠'); + } + if($redapck['status'] > 0){ + $this->renderError('红包状态错误,请刷新重试'); + } + $redpar = pdo_get('wlmerchant_redpacks',array('id' => $redapck['packid']),array('title','full_money','cut_money')); + $trdata['title'] = '满'.$redpar['full_money'].'元减'.$redpar['cut_money'].'元红包在线领取'; + $trdata['desc'] = $redpar['title']; + pdo_update('wlmerchant_redpack_records',array('status' => 6),array('id' => $id)); + } + $data = [ + 'uniacid' => $_W['uniacid'], + 'type' => $type, + 'objid' => $id, + 'omid' => $_W['mid'], + 'nmid' => 0, + 'status' => 0, + 'createtime' => time(), + 'transfermode' => 2 + ]; + $inRes = pdo_insert(PDO_NAME . 'transferRecord', $data); + $recordid = pdo_insertid(); + $trdata['recordid'] = $recordid; + if($recordid){ + $this->renderSuccess('转赠记录生成成功',$trdata); + }else{ + $this->renderError('转赠记录生成失败,请刷新重试'); + } + } + } + + /** + * Comment: 转赠信息 + * Author: wlf + * Date: 2021/08/20 09:46 + */ + public function transferInfo(){ + global $_W, $_GPC; + $id = $_GPC['id']; //记录 + if(empty($id)){ + $this->renderError('无id参数'); + } + $record = pdo_get('wlmerchant_transferRecord',array('id' => $id),array('type','status','objid','nmid','omid')); + if(empty($record)){ + $this->renderError('参数错误,无信息'); + } + //用户信息 + $member = pdo_get('wlmerchant_member',array('id' => $record['omid']),array('nickname','avatar')); + $record['nickname'] = $member['nickname']; + $record['avatar'] = tomedia($member['avatar']); + if($record['type'] == 1){ //卡券 + $coupon = pdo_get('wlmerchant_member_coupons',array('id' => $record['objid']),array('title','sub_title')); + $record['title'] = $coupon['title']; + $record['sub_title'] = $coupon['sub_title']; + }else{ //红包 + $redpack = pdo_get('wlmerchant_redpack_records',array('id' => $record['objid']),array('packid')); + $parentRed = pdo_get('wlmerchant_redpacks',array('id' => $redpack['packid']),array('full_money','cut_money')); + $record['title'] = $parentRed['cut_money'].'元'; + if($parentRed['full_money'] > 0){ + $record['sub_title'] = '满'.$parentRed['full_money'].'元可使用'; + }else{ + $record['sub_title'] = '任意金额可使用'; + } + } + if($record['omid'] == $_W['mid']){ + $record['ownflag'] = 1; + }else{ + $record['ownflag'] = 0; + } + $record['ownget'] = $record['nmid'] == $_W['mid'] ? 1 : 0; + + $this->renderSuccess('转赠信息',$record); + + } + + /** + * Comment: 领取转赠 + * Author: wlf + * Date: 2021/08/24 11:03 + */ + public function getTransfer() + { + global $_W, $_GPC; + $id = $_GPC['id']; //记录 + if (empty($id)) { + $this->renderError('无id参数'); + } + $record = pdo_get('wlmerchant_transferRecord', array('id' => $id), array('type', 'status', 'objid', 'omid')); + if (empty($record)) { + $this->renderError('参数错误,无信息'); + } + $getMember = pdo_get('wlmerchant_member',array('id' => $_W['mid']),array('id','nickname','mobile')); + if(empty($getMember)){ + $this->renderError('无用户信息,请先登录'); + } + if(empty($getMember['mobile'])){ + $this->renderError('未绑定手机号'); + } + $nickname = pdo_getcolumn(PDO_NAME.'member',array('id'=>$record['omid']),'nickname'); + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + //修改原纪录状态 + if($record['type'] == 1){ + $coupon = pdo_get('wlmerchant_member_coupons',array('id' => $record['objid']),array('mid','parentid','status','title','orderno','transferflag')); + + $parcoupon = pdo_get(PDO_NAME.'couponlist',array('id'=>$coupon['parentid']),['get_limit','transferlevel']); + $get_limit = $parcoupon['get_limit']; + if($coupon['get_limit'] > 0){ + $num = wlCoupon::getCouponNum($coupon['parentid'],1,$getMember['id']); + if($num > $get_limit || $num == $get_limit){ + MysqlFunction::rollback(); + $this->renderError('您不能拥有更多的此卡券'); + } + } + +// $transferlevel = unserialize($parcoupon['transferlevel']); +// if(!empty($transferlevel)){ +// $halfflag = WeliamWeChat::VipVerification($_W['mid']); +// if(empty($halfflag)){ +// $levelid = -1; +// }else{ +// $levelid = $halfflag['levelid']; +// } +// if(!in_array($levelid,$transferlevel)){ +// MysqlFunction::rollback(); +// $this->renderError('您所在的会员等级无法领取此卡券'); +// } +// } + + if(empty($coupon['transferflag'])){ + $res2 = pdo_update('wlmerchant_order',array('status' => 2),array('orderno' => $coupon['orderno'],'status' => 1)); //修改订单状态 + }else{ + $res2 = 1; + } + $res1 = pdo_update('wlmerchant_member_coupons',array('mid' => $getMember['id'],'transferflag'=>1,'status' => 1),array('id' => $record['objid'])); //修改卡券所属用户 + $res3 = pdo_update('wlmerchant_smallorder',array('mid' => $getMember['id']),array('orderno' => $coupon['orderno'])); //修改子订单状态 + if(empty($res1) || empty($res2) || empty($res3)){ + MysqlFunction::rollback(); + $this->renderError('原卡券修改失败,请刷新重试'); + } + $typename = '卡券'; + $title = $coupon['title']; + $url = h5_url('pages/subPages/coupon/coupon'); + }else{ + $redapck = pdo_get('wlmerchant_redpack_records',array('id' => $record['objid']),array('mid','packid','status')); + $parredpack = pdo_get(PDO_NAME.'redpacks',array('id'=>$redapck['packid']),['transferlevel','title','limit_count']); + if($parredpack['limit_count'] > 0){ + $mycounts = Redpack::getReceiveTotal($redapck['packid'],$getMember['id'],1,0); + if ($mycounts >= $parredpack['limit_count']){ + MysqlFunction::rollback(); + $this->renderError('您不能拥有更多的此红包'); + } + } +// $transferlevel = unserialize($parredpack['transferlevel']); +// if(!empty($transferlevel)){ +// $halfflag = WeliamWeChat::VipVerification($_W['mid']); +// if(empty($halfflag)){ +// $levelid = -1; +// }else{ +// $levelid = $halfflag['levelid']; +// } +// if(!in_array($levelid,$transferlevel)){ +// MysqlFunction::rollback(); +// $this->renderError('您所在的会员等级无法领取此红包'); +// } +// } + $res1 = pdo_update('wlmerchant_redpack_records',array('mid' => $getMember['id'],'transferflag' => 1,'status' => 0),array('id' => $record['objid'])); //修改红包所属用户 + if(empty($res1)){ + MysqlFunction::rollback(); + $this->renderError('原红包修改失败,请刷新重试'); + } + $title = $parredpack['title']; + $typename = '线上红包'; + $url = h5_url('pages/subPages/redpacket/myredpacket'); + } + //修改转赠记录 + $data = [ + 'nmid' => $_W['mid'], + 'status' => 1, + 'gettime' => time(), + 'mobile' => $getMember['mobile'] + ]; + $inRes = pdo_update(PDO_NAME.'transferRecord',$data,array('id' => $id)); + if($inRes){ + MysqlFunction::commit(); + //发送模板消息 + $first = '恭喜您获得好友['.$nickname.']转赠的'.$typename; + $type = $typename.'转赠通知'; + $content = $typename.'名:['.$title.']'; + $newStatus = '获取成功'; + $remark = '点击前去使用'; + News::jobNotice($getMember['id'],$first,$type,$content,$newStatus,$remark,time(),$url); + //发送给转赠人 + $first = '您的好友['.$_W['wlmember']['nickname'].']领取了您分享的'.$typename; + $type = $typename.'转赠领取通知'; + $newStatus = '转赠成功'; + $remark = '点击查看详情'; + News::jobNotice($record['omid'],$first,$type,$content,$newStatus,$remark,time(),$url); + $this->renderSuccess('领取成功'); + }else{ + MysqlFunction::rollback(); + $this->renderError('领取失败,请刷新重试'); + } + } + + /** + * Comment: 取消转赠 + * Author: wlf + * Date: 2021/08/24 11:28 + */ + public function cancelTransfer() + { + global $_W, $_GPC; + $id = $_GPC['id']; //记录 + $objid = $_GPC['objid']; //对象id + $type = $_GPC['type']; //对象类型 1卡券 2红包 + + if($id > 0){ + $record = pdo_get('wlmerchant_transferRecord', array('id' => $id), array('type', 'status', 'objid', 'omid')); + }else if($objid > 0 && $type > 0){ + $record = pdo_get('wlmerchant_transferRecord', array('type' => $type ,'status' => 0,'objid' => $objid), array('type','id','status', 'objid', 'omid')); + $id = $record['id']; + } + if (empty($record)) { + $this->renderError('参数错误,无信息'); + } + if($record['omid'] != $_W['mid']){ + $this->renderError('非原用户,无法取消'); + } + if($record['type'] == 1) { + pdo_update('wlmerchant_member_coupons',array('status' => 1),array('id' => $record['objid'])); + }else{ + pdo_update('wlmerchant_redpack_records',array('status' => 0),array('id' => $record['objid'])); + } + $data = [ + 'status' => 2, + 'canceltime' => time(), + ]; + $inRes = pdo_update(PDO_NAME.'transferRecord',$data,array('id' => $id)); + if($inRes){ + $this->renderSuccess('取消成功'); + }else{ + $this->renderError('取消失败,请刷新重试'); + } + + } + + /** + * Comment: 已转赠列表 + * Author: wlf + * Date: 2021/08/27 11:41 + */ + public function alreadyTransferList(){ + global $_W, $_GPC; + $type = $_GPC['type']; //类型 1卡券 2红包 + $mobile = $_GPC['mobile']; //筛选手机号 + $page = $_GPC['page'] ? $_GPC['page'] : 1; //页码 + $pageStart = $page*20 - 20; + $where = " WHERE uniacid = {$_W['uniacid']} AND type = {$type} AND omid = {$_W['mid']} AND status = 1"; + if(!empty($mobile)){ + $where .= " AND mobile LIKE '%{$mobile}%'"; + } + $list = pdo_fetchall("select objid,type,nmid,createtime,mobile,transfermode from " . tablename(PDO_NAME.'transferRecord').$where." GROUP BY objid ORDER BY id DESC LIMIT {$pageStart},20" ); + if(count($list) > 0){ + foreach($list as &$li){ + if($li['type'] == 1){ //卡券 + $coupon = pdo_get('wlmerchant_member_coupons',array('id' => $li['objid']),array('parentid','title','sub_title','endtime','starttime','orderno')); + $parent = pdo_get('wlmerchant_couponlist' , ['id' => $coupon['parentid']] , ['merchantid']); + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $parent['merchantid']] , ['storename' , 'logo']); + $li['storename'] = $store['storename']; + $li['storelogo'] = tomedia($store['logo']); + $li['storeid'] = $parent['merchantid']; + $li['title'] = $coupon['title']; + $li['sub_title'] = $coupon['sub_title']; + $li['orderno'] = $coupon['orderno']; + $li['endtime'] = date('Y-m-d',$coupon['endtime']); + $li['starttime'] = date('Y-m-d',$coupon['starttime']); + }else{ //红包 + $redpack = pdo_get('wlmerchant_redpack_records',array('id' => $li['objid']),array('start_time','end_time','packid')); + $redparent = pdo_get('wlmerchant_redpacks',array('id' => $redpack['packid']),array('title','full_money','cut_money','usegoods_type')); + $li['title'] = $redparent['title']; + $endtime = date('Y-m-d',$redpack['end_time']); + $starttime = date('Y-m-d',$redpack['start_time']); + $li['time'] = $starttime.'-'.$endtime; + $li['full_money'] = $redparent['full_money']; + $li['cut_money'] = $redparent['cut_money']; + $li['usegoods_type'] = $redparent['usegoods_type']; + if ($redparent['usegoods_type'] == 1) { + $li['use_where'] = "仅限指定地区可用"; + }else if ($redparent['usegoods_type'] == 2) { + $li['use_where'] = "仅限指定商家可用"; + }else if ($redparent['usegoods_type'] == 3) { + $li['use_where'] = "仅限指定商品可用"; + }else { + $li['use_where'] = '全平台可用'; + } + } + $li['mobile'] = substr($li['mobile'],0,3).'****'.substr($li['mobile'], -4); + $li['getname'] = pdo_getcolumn(PDO_NAME.'member',array('id'=>$li['nmid']),'nickname'); + $li['transfertime'] = date('Y/m/d H:i:s',$li['createtime']); + } + } + if($page = 1){ + $alllist = pdo_fetchall("select distinct objid from " . tablename(PDO_NAME.'transferRecord').$where); + $allnum = count($alllist); + $data['totalnum'] = $allnum; + $data['pagetotal'] = ceil($allnum / 20); + } + $data['list'] = $list; + $this->renderSuccess('已转赠列表' , $data); + + } + + +} diff --git a/addons/weliam_smartcity/api/Pay.php b/addons/weliam_smartcity/api/Pay.php new file mode 100644 index 0000000..c9080a1 --- /dev/null +++ b/addons/weliam_smartcity/api/Pay.php @@ -0,0 +1,5316 @@ + $orderid]); + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'rush_activity' , ['id' => $order['activityid']] , 'name'); + $data['price'] = $order['actualprice']; + $plugin = 'Rush'; + $payfor = 'RushOrder'; + } + else if ($type == 'opencard') { //一卡通 + $order = pdo_get('wlmerchant_halfcard_record' , ['id' => $orderid]); + $data['price'] = $order['price']; + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'halfcard_type' , ['id' => $order['typeid']] , 'name'); + $plugin = 'Merchant'; + $payfor = 'Halfcard'; + $checkpayP = 'Halfcard'; + } + else if ($type == 'attestation') { + $order = pdo_get('wlmerchant_attestation_money' , ['id' => $orderid]); + $data['price'] = $order['money']; + $data['goodname'] = '认证保证金'; + $plugin = 'Attestation'; + $payfor = 'Bond'; + } + else if ($type == 'mobilerecharge') { + $order = pdo_get('wlmerchant_mrecharge_order' , ['id' => $orderid]); + $data['price'] = $order['price']; + $data['goodname'] = '充值'.$order['money'].'元'; + $plugin = 'Mobilerecharge'; + $payfor = 'RechargeOrder'; + } + else if ($type == 'citydelivery') { + if(!empty($orderid)){ + $order = pdo_get('wlmerchant_order' , ['id' => $orderid]); + $data['price'] = $order['price']; + $smallorders = pdo_getall('wlmerchant_delivery_order',array('tid' => $order['orderno']),array('gid')); + $data['goodname'] = pdo_getcolumn(PDO_NAME.'delivery_activity',array('id'=>$smallorders[0]['gid']),'name'); + if(count($smallorders)>1){ + $data['goodname'] .= ' 等'; + } + }else{ + $orderids = json_decode(base64_decode($deliverystring),true); + foreach ($orderids as $orid){ + $order = pdo_get('wlmerchant_order' , ['id' => $orid]); + $data['price'] += $order['price']; + $smallorders = pdo_getall('wlmerchant_delivery_order',array('tid' => $order['orderno']),array('gid')); + $data['goodname'] = pdo_getcolumn(PDO_NAME.'delivery_activity',array('id'=>$smallorders[0]['gid']),'name'); + if(count($smallorders) > 1 || count($orderids) > 1){ + $data['goodname'] .= ' 等'; + } + } + $data['price'] = sprintf("%.2f",$data['price']); + } + $plugin = 'Citydelivery'; + $payfor = 'DeliveryOrder'; + } + else { + //其他 + $order = pdo_get('wlmerchant_order' , ['id' => $orderid]); + $data['price'] = $order['price']; + if ($order['plugin'] == 'groupon') { + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'groupon_activity' , ['id' => $order['fkid']] , 'name'); + $plugin = 'Groupon'; + $payfor = 'GrouponOrder'; + } + else if ($order['plugin'] == 'wlfightgroup') { + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'fightgroup_goods' , ['id' => $order['fkid']] , 'name'); + $plugin = 'Wlfightgroup'; + $payfor = 'Fightsharge'; + } + else if ($order['plugin'] == 'distribution') { + $data['goodname'] = '开通'.$_W['wlsetting']['trade']['fxstext']; + $plugin = 'Distribution'; + $payfor = 'Applydis'; + } + else if ($order['plugin'] == 'store') { + $data['goodname'] = '商户付费入驻'; + $plugin = 'Merchant'; + $payfor = 'Charge'; + $checkpayP = 'Charge'; + } + else if ($order['plugin'] == 'halfcard') { + if ($order['fkid']) { + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'halfcardlist' , ['id' => $order['fkid']] , 'title'); + } + else { + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $order['sid']] , 'storename'); + } + $data['goodname'] = $data['goodname'] . '在线买单'; + $plugin = 'Merchant'; + $payfor = 'payonline'; + $checkpayP = 'Payonline'; + } + else if ($order['plugin'] == 'coupon') { + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'couponlist' , ['id' => $order['fkid']] , 'title'); + $plugin = 'wlCoupon'; + $payfor = 'Couponsharge'; + } + else if ($order['plugin'] == 'bargain') { + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'bargain_activity' , ['id' => $order['fkid']] , 'name'); + $plugin = 'Bargain'; + $payfor = 'BargainOrder'; + } + else if ($order['plugin'] == 'pocket') { + $data['goodname'] = '帖子付费项目'; + $plugin = 'Pocket'; + $payfor = 'pocketfabusharge'; + } + else if ($order['plugin'] == 'consumption') { + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'consumption_goods' , ['id' => $order['fkid']] , 'title'); + $plugin = 'Consumption'; + $payfor = 'consumOrder'; + } + else if ($order['plugin'] == 'member') { + $data['goodname'] = $trade['moneytext'] . '充值'; + $plugin = 'Member'; + $payfor = 'Charge'; + } + else if ($order['plugin'] == 'taxipay') { + $data['goodname'] = '出租车在线买单'; + $plugin = 'Taxipay'; + $payfor = 'TaxipayOrder'; + } + else if ($order['plugin'] == 'citycard') { + $data['goodname'] = '同城名片支付项目'; + $plugin = 'Citycard'; + $payfor = 'CitycardOrder'; + } + else if ($order['plugin'] == 'yellowpage') { + if($order['fightstatus'] == 1){ + $data['goodname'] = '114页面认领'; + }else if($order['fightstatus'] == 2){ + $data['goodname'] = '114页面查看'; + }else if($order['fightstatus'] == 3){ + $data['goodname'] = '114页面入驻'; + } + $plugin = 'Yellowpage'; + $payfor = 'pageOrder'; + } + else if($order['plugin'] == 'activity'){ + $data['goodname'] = pdo_getcolumn(PDO_NAME . 'activitylist' , ['id' => $order['fkid']] , 'title'); + $plugin = 'Activity'; + $payfor = 'Activitysharge'; + } + else if($order['plugin'] == 'recruit'){ + $data['goodname'] = '招聘发布'; + $plugin = 'Recruit'; + $payfor = 'RecruitOrder'; + } + else if($order['plugin'] == 'rights'){ + $data['goodname'] = Rights::getRightsGoodname($order['fkid'],$order['payfor']); + $plugin = 'Rights'; + $payfor = 'RightsOrder'; + } + else if($order['plugin'] == 'dating'){ + $data['goodname'] = '相亲交友'; + $plugin = 'Dating'; + $payfor = $order['payfor']; + } + else if($order['plugin'] == 'vehicle'){ + $data['goodname'] = '顺风车'; + $plugin = 'Vehicle'; + $payfor = $order['payfor']; + } + else if ($order['plugin'] == 'housekeep') { + if($order['fightstatus'] == 1){ + $data['goodname'] = '家政服务订单'; + }else if($order['fightstatus'] == 2){ + $data['goodname'] = '家政入驻订单'; + }else if($order['fightstatus'] == 3){ + $data['goodname'] = '家政需求付费发布'; + }else if($order['fightstatus'] == 3){ + $data['goodname'] = '家政需求付费置顶'; + }else if($order['fightstatus'] == 3){ + $data['goodname'] = '家政需求付费刷新'; + } + $plugin = 'Housekeep'; + $payfor = 'HousekeepOrder'; + } + } + $data['sytime'] = $order['canceltime'] - time(); + if ($data['sytime'] < 0) { + $data['sytime'] = 0; + } + if (empty($order)) { + $this->renderError('订单信息错误,请返回订单列表重新发起支付'); + } + //判断mid和uniacid是否一致 + if ($order['uniacid'] != $_W['uniacid']) { + $this->renderError('订单公众号错误,请返回订单列表重新进入支付页面'); + } + if ($order['mid'] != $_W['mid']) { + $this->renderError('订单用户错误,请返回订单列表重新进入支付页面'); + } + $data['balance'] = sprintf("%.2f" , $_W['wlmember']['credit2']); + //智慧城市 + if($type == 'citydelivery' && !empty($orderids)){ + $merchantlog = [ + 'uniacid' => $order['uniacid'] , + 'acid' => $_W['acid'] , + 'mid' => $order['mid'] , + 'module' => 'weliam_smartcity', + 'plugin' => $plugin , + 'payfor' => $payfor , + 'tid' => createUniontid(), + 'fee' => $data['price'] , + 'card_fee' => $data['price'] , + 'status' => '0' , + 'is_usecard' => '0' , + ]; + pdo_insert(PDO_NAME . 'paylogvfour' , $merchantlog); + $merchantlogid = pdo_insertid(); + foreach ($orderids as $orid2){ + pdo_update('wlmerchant_order',array('paylogid' => $merchantlogid),array('id' => $orid2)); + } + $order['orderno'] = $merchantlog['tid']; + }else{ + $merchantlog = pdo_get(PDO_NAME . 'paylogvfour' , [ + 'uniacid' => $_W['uniacid'] , + 'plugin' => $plugin , + 'tid' => $order['orderno'] + ]); + if (empty($merchantlog)) { + $merchantlog = [ + 'uniacid' => $order['uniacid'] , + 'acid' => $_W['acid'] , + 'mid' => $order['mid'] , + 'module' => 'weliam_smartcity' , + 'plugin' => $plugin , + 'payfor' => $payfor , + 'tid' => $order['orderno'] , + 'fee' => $data['price'] , + 'card_fee' => $data['price'] , + 'status' => '0' , + 'is_usecard' => '0' , + ]; + pdo_insert(PDO_NAME . 'paylogvfour' , $merchantlog); + } + } + + if ($merchantlog['status'] == '1') { + $this->renderError('这个订单已经支付成功, 不需要重复支付' , $data); + } + //判断商品独立支付设置信息 + if (in_array($plugin , ['Rush' , 'Groupon' , 'Wlfightgroup' , 'Bargain' , 'wlCoupon'])) { + //获取当前商品的独立支付设置 + switch ($plugin) { + case 'Rush': + $goodsPayType = pdo_getcolumn(PDO_NAME . 'rush_activity' , ['id' => $order['activityid']] , 'pay_type'); + break; + case 'Groupon': + $goodsPayType = pdo_getcolumn(PDO_NAME . 'groupon_activity' , ['id' => $order['fkid']] , 'pay_type'); + break; + case 'Wlfightgroup': + $goodsPayType = pdo_getcolumn(PDO_NAME . 'fightgroup_goods' , ['id' => $order['fkid']] , 'pay_type'); + break; + case 'Bargain': + $goodsPayType = pdo_getcolumn(PDO_NAME . 'bargain_activity' , ['id' => $order['fkid']] , 'pay_type'); + break; + case 'wlCoupon': + $goodsPayType = pdo_getcolumn(PDO_NAME . 'couponlist' , ['id' => $order['fkid']] , 'pay_type'); + break; + } + $goodsPayType = unserialize($goodsPayType); + } + $goodsPayType = is_array($goodsPayType) && count($goodsPayType) > 0 ? $goodsPayType : ['wechat' , 'alipay' , 'balance','yunpay']; + //获取开启的支付方式 支付渠道 1=公众号(默认);2=h5;3=小程序 + $paymentSet = Setting::wlsetting_read('payment_set'); + switch ($_W['source']) { + case 1: + $wechat_payset = $paymentSet['wechat']; + break;//公众号 + case 2: + $wechat_payset = $paymentSet['h5']; + break;//h5 + case 3: + $wechat_payset = $paymentSet['wxapp']; + break;//小程序 + } + if (!empty($wechat_payset['balance']) && $order['payfor'] != 'recharge' && in_array('balance' , $goodsPayType)) { + //开启余额支付的情况下 判断当前模块是否支持余额支付 + $balanceModel = is_array($wechat_payset['balance_model']) ? $wechat_payset['balance_model'] : [];//限制模块信息 + $allowList = array_keys(Payment::getBalanceModel());//允许限制的模块列表 + if(empty($checkpayP)){ + $checkpayP = $plugin; + } + //判断:存在限制模块&&当前模块在允许限制列表中&&不允许当前模块使用余额支付 + if(count($balanceModel) > 0 && in_array($checkpayP,$allowList) && !in_array($checkpayP,$balanceModel)){ + $data['credit'] = 0; + }else{ + $data['credit'] = 1; + } + }else { + $data['credit'] = 0; + } + if ($wechat_payset['wechat'] > 0 && in_array('wechat' , $goodsPayType)) { + $data['wechat'] = 1; + }else { + $data['wechat'] = 0; + } + if ($wechat_payset['alipay'] > 0 && in_array('alipay' , $goodsPayType)) { + $data['alipay'] = 1; + }else { + $data['alipay'] = 0; + } + if ($wechat_payset['yunpay'] > 0 && in_array('yunpay' , $goodsPayType)) { + $data['yunpay'] = 1; + $data['yunset']['logo'] = $_W['wlsetting']['base']['yun_logo'] ? tomedia($_W['wlsetting']['base']['yun_logo']) : ''; + $data['yunset']['title'] = $_W['wlsetting']['base']['yun_title'] ? : '银联云收单'; + $data['yunset']['desc'] = $_W['wlsetting']['base']['yun_desc'] ? : '支付有优惠'; + }else { + $data['yunpay'] = 0; + } + $data['tid'] = $order['orderno']; + + //881定制内容 + $isAuth = Customized::init('diy_userInfo'); + if($isAuth){ + $data['diy_userInfo']['dkprice'] = $data['balance'] > $data['price'] ? $data['price'] : $data['balance']; + $data['diy_userInfo']['dhurl'] = $_W['wlsetting']['recharge']['dhurl']; + $data['diy_userInfo']['dhtip2'] = $_W['wlsetting']['recharge']['dhtip2']?$_W['wlsetting']['recharge']['dhtip2']:'中国移动/中国银行积分可兑换乐豆'; + } + + $this->renderSuccess('订单支付信息' , $data); + } + /** + * Comment: 用户对订单进行评论 + * Author: zzw + * Date: 2019/8/15 13:43 + */ + public function orderComment(){ + global $_W , $_GPC; + $mastmobile = unserialize($_W['wlsetting']['userset']['plugin']); + if (empty($_W['wlmember']['mobile']) && in_array('private',$mastmobile)){ + $this->renderError('未绑定手机号'); + } + #1、参数接收 + $mid = $_W['mid'];//用户id + $id = intval($_GPC['id']) OR $this->renderError('缺少id信息');//订单id + if(!empty($_GPC['pic'])){ + $pic = explode(',' , $_GPC['pic']);//评论图片地址 + $pic = serialize($pic); + }else { + $pic = ''; + } + $data['ispic'] = $_GPC['pic'] ? 1 : 0; + $text = $_GPC['text'] OR $this->renderError('请输入评论内容!');//文本评论内容 + $star = $_GPC['star'];//评论星级 1-5 + $tableType = $_GPC['table'];//表的类型 a = order b = rush_order 为空是核销内容的评论 + //判断文本内容是否非法 + $textRes = Filter::init($text , $_W['source'] , 1); + if ($textRes['errno'] == 0) { + $this->renderError($textRes['message']); + } + #2、数据拼装 + $data = [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $mid , + 'status' => 1 , //默认显示 + 'pic' => $pic , + 'idoforder' => $id , + 'text' => $text , + 'star' => intval($star) , + 'createtime' => time() , + 'headimg' => $_W['wlmember']['avatar'] , + 'nickname' => $_W['wlmember']['nickname'] + ]; + #3、获取店铺id 商品类型 并且修改订单状态为已完成 + WeliamWeChat::startTrans();//开启事务 + switch ($tableType) { + case 'a': + $table = PDO_NAME . 'order'; + $orderInfo = pdo_get($table , ['id' => $id] , ['sid' ,'fkid','aid' , 'plugin']); + $res = pdo_update($table , ['status' => 3] , ['id' => $id]); + $gid = $orderInfo['fkid']; + break;//其他订单 + case 'b': + $table = PDO_NAME . 'rush_order'; + $orderInfo = pdo_get($table , ['id' => $id] , ['sid' ,'activityid', 'aid']); + $orderInfo['plugin'] = 'rush'; + $res = pdo_update($table , ['status' => 3] , ['id' => $id]); + $gid = $orderInfo['activityid']; + break;//抢购订单 + default: + $table = PDO_NAME . 'timecardrecord'; + $orderInfo = pdo_get($table , ['id' => $id] ,['aid','merchantid','activeid']); + $orderInfo['plugin'] = 'usehalf'; + $res = pdo_update($table , ['commentflag' => 1] , ['id' => $id]); + $gid = $orderInfo['activeid']; + break;//核销内容的评论 + } + $data['aid'] = $orderInfo['aid']; + $data['gid'] = $gid ? : 0; + $data['sid'] = $orderInfo['sid']; + $data['plugin'] = $orderInfo['plugin']; + if($data['plugin'] == 'housekeep'){ + $serviceType = pdo_getcolumn(PDO_NAME.'housekeep_service',array('id'=>$gid),'type'); + if($serviceType == 2){ + $data['housekeepflag'] = 1; + } + } + if (!$res) { + WeliamWeChat::rollback();//回滚 + $this->renderError('订单信息修改失败'); + } + else if (empty($data['plugin'])) { + WeliamWeChat::rollback();//回滚 + $this->renderError('订单不存在'); + } + #4、判断评分等级 + if ($data['star'] > 3) $data['level'] = 1; + else if ($data['star'] == 3) $data['level'] = 2; + else $data['level'] = 3; + #4、储存评论信息 + $result = pdo_insert(PDO_NAME . 'comment' , $data); + if ($result) { + WeliamWeChat::commit();//提交事务 + //评论成功 给管理员发送模板消息 + $first = "用户【{$data['nickname']}】发布了一条评论";//消息头部 + $type = "评论审核通知";//业务类型 + $content = $data['text'];//业务内容 + $status = "待审核";//处理结果 + $remark = "请尽快审核!";//备注信息 + $time = $data['createtime'];//操作时间 + News::noticeAgent('storecomment' , $_W['aid'] , $first , $type , $content , $status , $remark , $time); + $this->renderSuccess('评论成功' , ['id' => pdo_insertid()]); + } + else { + WeliamWeChat::rollback();//回滚 + $this->renderError('评论失败'); + } + } + /** + * Comment: 转换plugin参数 + * Author: wlf + * Date: 2019/8/21 10:00 + */ + public function conversion($type) + { + $types = [ + 1 => 'rush' , //抢购 + 2 => 'groupon' , //团购 + 3 => 'wlfightgroup' , //拼团 + 5 => 'coupon' , //超级券 + 6 => 'payonline' , //在线买单 + 7 => 'bargain' , //砍价 + 8 => 'consumption' , //兑换 + 9 => 'halfcard' , //一卡通 + 10 => 'store', //商户 + 11 => 'activity' //同城活动 + ]; + return $types[$type]; + } + /** + * Comment: 订单提交页面 + * Author: wlf + * Date: 2019/8/16 09:38 + */ + public function orderSubmit() + { + global $_W , $_GPC; + $type = $this->conversion($_GPC['plugin']); //插件类型 + $specid = $_GPC['specid']; //规格id + $id = $_GPC['id']; //商品id + $num = $_GPC['num'] ? intval($_GPC['num']) : 1; //购买数量 + $buystatus = $_GPC['buystatus']; //拼团单购 团购 + $addressid = $_GPC['addressid']; + + $getDraw = intval($_GPC['drawid']); //领取抽奖奖品 + if(!empty($_GPC['luckydrawid'])){ + $getDraw = intval($_GPC['luckydrawid']); //领取锦鲤抽奖奖品 + } + + if($getDraw > 0){ + $type = $_GPC['plugin']; + } + //验证会员 + if ($_W['mid']) { + $userhalfcard = WeliamWeChat::VipVerification($_W['mid']); + if($userhalfcard['id'] > 0){ + $halfcardflag = $userhalfcard['id']; + $halfcardlevel = $userhalfcard['levelid']; + } + } + $allcredit = sprintf("%.2f" , $_W['wlmember']['credit1']); + $data = []; + $data['plugin'] = $type; + $data['halfcardflag'] = $halfcardflag; + $data['allcredit'] = $allcredit; + $data['realname'] = $_W['wlmember']['realname'] ? $_W['wlmember']['realname'] : $_W['wlmember']['nickname']; + $data['mobile'] = $_W['wlmember']['mobile']; + if ($type == 'bargain') { + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $id]); + $user = pdo_get('wlmerchant_bargain_userlist' , ['id' => $specid] , ['price']); + $price = $goodsprice = $goods['price'] = $user['price']; + $storename = pdo_getcolumn('wlmerchant_merchantdata' , ['id' => $goods['sid']] , 'storename'); + $data['goodsname'] = $goods['name']; //商品名 + $data['goodsimg'] = tomedia($goods['thumb']); //商品图案 + $data['goodsprice'] = $goodsprice; //商品单价 + $data['usestatus'] = $goods['usestatus']; //使用方式 + $data['optionname'] = ''; //规格名 + $data['vipdiscount'] = 0; //会员减免 + $data['carddiscount'] = 0; //开卡减免 + $sid = $goods['sid']; + } + if ($type == 'consumption') { + $goods = Consumption::creditshop_goods_get($id); + //会员价格 + if ($goods['vipstatus'] == 1) { + $data['carddiscount'] = sprintf("%.2f" , ($goods['use_credit2'] - $goods['vipcredit2']) * $num); //会员减免 + if ($halfcardflag) { + $goods['use_credit1'] = $goods['vipcredit1']; + $data['vipdiscount'] = $data['carddiscount']; + } + else { + $data['vipdiscount'] = 0; + } + } + else { + $data['vipdiscount'] = 0; + $data['carddiscount'] = 0; //开卡减免 + } + if ($goods['type'] == 'credit2' || $goods['type'] == 'halfcard') { + $conflag = 1; + $goods['usestatus'] = 0; + } //虚拟兑换 + if ($goods['type'] == 'goods') { + $goods['usestatus'] = 1; + } + $goodsprice = sprintf("%.2f",$goods['use_credit2']); + $data['goodsname'] = $goods['title']; //商品名 + $data['goodsimg'] = tomedia($goods['thumb']); //商品图案 + $data['goodsprice'] = $goodsprice; //商品单价 + $data['usestatus'] = $goods['usestatus']; //使用方式 + $data['optionname'] = ''; //规格名 + if ($halfcardflag && $goods['vipstatus'] == 1) { + $data['credit'] = $goods['vipcredit1'] * $num; + } + else { + $data['credit'] = $goods['use_credit1'] * $num; + } + $data['creditdiscount'] = 0; //积分抵扣 + $sid = 0; + } + if ($type == 'coupon') { + $goods = pdo_get('wlmerchant_couponlist' , ['id' => $id]); + $goodsprice = $goods['price']; + $data['goodsname'] = $goods['title']; //商品名 + $data['goodsimg'] = tomedia($goods['logo']); //商品图案 + $data['goodsprice'] = $goodsprice; //商品单价 + $data['usestatus'] = 0; //使用方式 + $data['optionname'] = $goods['sub_title']; //规格名 + if ($goods['vipstatus'] == 1) { + $goods['vipdiscount'] = WeliamWeChat::getVipDiscount($goods['viparray'],$halfcardlevel); + $vipReduce = sprintf("%.2f" , $goods['vipdiscount'] * $num); + $data['carddiscount'] = unserialize($goods['viparray']); + if ($halfcardflag) { + $data['vipdiscount'] = $vipReduce; + } + else { + $data['vipdiscount'] = 0; + } + } + else { + $data['vipdiscount'] = 0; + $data['carddiscount'] = []; + } + $data['credit'] = 0; + $data['creditdiscount'] = 0; //积分抵扣 + $sid = $goods['merchantid']; + } + if ($type == 'wlfightgroup') { + $goods = pdo_get('wlmerchant_fightgroup_goods' , ['id' => $id]); + if ($specid) { + $option = pdo_get('wlmerchant_goods_option' , ['id' => $specid] , ['title' , 'price','vipprice','uuid' , 'viparray']); + if ($buystatus == 1) { + $goods['price'] = $option['price']; + }else { + $goods['price'] = $option['vipprice']; + } + $goods['viparray'] = WeliamWeChat::mergeVipArray($option['viparray'],$goods['viparray']); + } + else if ($buystatus == 2) { + $goods['price'] = $goods['aloneprice']; + $option['title'] = ''; + } + else { + $option['title'] = ''; + } + $goodsprice = sprintf("%.2f" , $goods['price'] * $num); + //会员抵扣 + if ($goods['vipstatus'] == 1) { + $goods['vipdiscount'] = WeliamWeChat::getVipDiscount($goods['viparray'],$halfcardlevel); + $vipReduce = sprintf("%.2f" , $goods['vipdiscount'] * $num); + $data['carddiscount'] = unserialize($goods['viparray']); + if ($halfcardflag) { + $vipdiscount = $vipReduce; + } + else { + $vipdiscount = 0; + } + } + else { + $vipdiscount = 0; + $data['carddiscount'] = []; + } + $data['goodsname'] = $goods['name']; //商品名 + $data['goodsimg'] = tomedia($goods['logo']); //商品图案 + $data['goodsprice'] = $goods['price']; //商品单价 + $data['usestatus'] = $goods['usestatus']; //使用方式 + $data['optionname'] = $option['title']; //规格名 + $data['vipdiscount'] = $vipdiscount; //会员减免 + $price = sprintf("%.2f" , $goods['price'] - $goods['vipdiscount']); + //拼团 - 团长优惠 + $data['is_com_dis'] = intval(0); + if ($buystatus == 1 && $goods['is_com_dis'] == 1) { + $data['is_com_dis'] = intval($goods['is_com_dis'] ? : 0); + $data['com_dis_price'] = sprintf("%.2f" , ($goods['com_dis_price'] ? : 0)); + } + $sid = $goods['merchantid']; + } + if ($type == 'rush') { + $goods = pdo_get('wlmerchant_rush_activity' , ['id' => $id]); + if ($specid) { + $option = pdo_get('wlmerchant_goods_option' , ['id' => $specid] , ['title' , 'price' , 'viparray', 'uuid','pftotherinfo']); + $goods['price'] = $option['price']; + $goods['vipprice'] = $option['vipprice']; + $goods['viparray'] = WeliamWeChat::mergeVipArray($option['viparray'],$goods['viparray']); + $goods['ticketid'] = $option['uuid']; + $goods['pftotherinfo'] = $option['pftotherinfo']; + } + else { + $option['title'] = ''; + } + #判断是否开启阶梯价(目前仅抢购存在) 是否开启阶梯价(0=关闭 1=开启) + if ($goods['lp_status'] == 1) { + $goods['lp_set'] = is_array(unserialize($goods['lp_set'])) ? unserialize($goods['lp_set']) : []; + if (count($goods['lp_set']) > 0) { + $info = WeliamWeChat::getHomeGoods(1 , $id); + $allsalenum = intval($info['allsalenum']); + foreach ($goods['lp_set'] as $lpKey => $lpVal) { + $lpVal['max'] = intval($lpVal['max']) + $allsalenum; + if ($info['buy_num'] < $lpVal['max']) { + $goods['price'] = $lpVal['price']; + $goods['vipprice'] = $lpVal['vip_price']; + break; + } + } + } + } + //其他信息计算 + if ($goods['vipstatus'] == 1) { + $goods['vipdiscount'] = WeliamWeChat::getVipDiscount($goods['viparray'],$halfcardlevel); + $vipReduce = sprintf("%.2f" , $goods['vipdiscount'] * $num); + $data['carddiscount'] = unserialize($goods['viparray']); + if ($halfcardflag) { + $price = $goods['price']; + $data['vipdiscount'] = $vipReduce; //会员减免 + } + else { + $data['vipdiscount'] = 0; + } + } + else { + $price = $goods['price']; + $data['vipdiscount'] = 0; + $data['carddiscount'] = []; + } + $goodsprice = sprintf("%.2f" , $price * $num); + $data['goodsname'] = $goods['name']; //商品名 + $data['goodsimg'] = tomedia($goods['thumb']); //商品图案 + $data['goodsprice'] = $goods['price']; //商品单价 + $data['usestatus'] = $goods['usestatus']; //使用方式 + $data['optionname'] = $option['title']; //规格名 + $sid = $goods['sid']; + } + if ($type == 'groupon') { + $goods = pdo_get('wlmerchant_groupon_activity' , ['id' => $id]); + if ($specid) { + $option = pdo_get('wlmerchant_goods_option' , ['id' => $specid] , ['title' , 'price' , 'viparray', 'uuid','pftotherinfo']); + $goods['price'] = $option['price']; + $goods['viparray'] = WeliamWeChat::mergeVipArray($option['viparray'],$goods['viparray']); + $goods['ticketid'] = $option['uuid']; + $goods['pftotherinfo'] = $option['pftotherinfo']; + } + else { + $option['title'] = ''; + } + //计算会员特价 + if ($goods['vipstatus'] == 1) { + $goods['vipdiscount'] = WeliamWeChat::getVipDiscount($goods['viparray'],$halfcardlevel); + $vipReduce = sprintf("%.2f" , $goods['vipdiscount'] * $num); + $data['carddiscount'] = unserialize($goods['viparray']); + if ($halfcardflag) { + $data['vipdiscount'] = $vipReduce; + } + else { + $data['vipdiscount'] = 0; + } + } + else { + $data['vipdiscount'] = 0; + $data['carddiscount'] = []; + } + $data['goodsname'] = $goods['name']; //商品名 + $data['goodsimg'] = tomedia($goods['thumb']); //商品图案 + $data['goodsprice'] = $goods['price']; //商品单价 + $data['usestatus'] = $goods['usestatus']; //使用方式 + $data['optionname'] = $option['title']; //规格名 + $sid = $goods['sid']; + } + if ($type == 'activity'){ + $goods = pdo_get('wlmerchant_activitylist' , ['id' => $id]); + if($specid > 0){ + $spec = pdo_get('wlmerchant_activity_spec' , ['id' => $specid]); + $goods['price'] = $spec['price']; + $data['optionname'] = $spec['name']; + $goods['viparray'] = WeliamWeChat::mergeVipArray($spec['viparray'],$goods['viparray']); + } + $price = $goodsprice = $goods['price']; + $storename = pdo_getcolumn('wlmerchant_merchantdata',['id' => $goods['sid']] , 'storename'); + $data['goodsname'] = $goods['title']; //商品名 + $data['goodsimg'] = tomedia($goods['thumb']); //商品图案 + $data['goodsprice'] = $goodsprice; //商品单价 + $data['usestatus'] = 0; //使用方式 + if($goods['vipstatus'] == 1){ + $goods['vipdiscount'] = WeliamWeChat::getVipDiscount($goods['viparray'],$halfcardlevel); + $data['vipdiscount'] = sprintf("%.2f" , $goods['vipdiscount']*$num); //会员减免 + $data['carddiscount'] = unserialize($goods['viparray']); + }else{ + $data['vipdiscount'] = 0; + $data['carddiscount'] = []; + } + $sid = $goods['sid']; + } + //红包系统 + if(p('redpack') && empty($getDraw)){ + $data['redpacklist'] = Redpack::getNotUseList($data['goodsprice'] * $num,$sid,$goods['aid'],$id,$type); + }else{ + $data['redpacklist'] = ['list'=>[],'total'=>0]; + } + //满减优惠 + if($goods['fullreduceid']>0 && empty($getDraw)){ + $fullreduce = pdo_get('wlmerchant_fullreduce_list',array('id' => $goods['fullreduceid'],'status' => 1),array('rules','title')); + if(!empty($fullreduce)){ + $data['fullreducelist']['title'] = $fullreduce['title']; + $data['fullreducelist']['list'] = unserialize($fullreduce['rules']); + } + } + //积分抵扣 + if ($goods['creditmoney']>0 && $_W['wlsetting']['creditset']['dkstatus'] && empty($getDraw)) { + //每一份可以使用的积分 + $onedkcredit = sprintf("%.2f" , $goods['creditmoney'] * $_W['wlsetting']['creditset']['proportion']); + //总共需要积分 + $dkcredit = sprintf("%.2f" , $onedkcredit * $num); + //用户所有积分 + if ($allcredit < $dkcredit) { + $dkcredit = $allcredit; + } + //抵扣金额 + $dkmoney = sprintf("%.2f" , $dkcredit / $_W['wlsetting']['creditset']['proportion']); + $data['credit'] = $dkcredit; //可使用积分 + $data['creditdiscount'] = $dkmoney; //积分抵扣金额 + } + else { + if (empty($data['credit'])) { + $data['credit'] = 0; //可使用积分 + } + $data['creditdiscount'] = 0; //积分抵扣金额 + } + //计算运费 + if ($data['usestatus'] > 0) { + if ($addressid) { + $address = pdo_get('wlmerchant_address' , ['id' => $addressid] , ['id','name' ,'status','tel','province','city','county','detailed_address']); + }else{ + $address = pdo_get('wlmerchant_address' , ['mid' => $_W['mid'] , 'uniacid' => $_W['uniacid'] , 'status' => 1] , ['id' , 'status' , 'name' , 'tel' , 'province' , 'city' , 'county' , 'detailed_address']); + } + + if (empty($address)){ + $address = pdo_get('wlmerchant_address' , ['mid' => $_W['mid'] , 'uniacid' => $_W['uniacid']] , ['id' , 'name' , 'status' , 'tel' , 'province' , 'city' , 'county' , 'detailed_address']); + if ($address) { + pdo_update('wlmerchant_address' , ['status' => 1] , ['id' => $address['id']]); + } + } + if (empty($address)) { + $data['expressprice'] = 0; + $data['address'] = ''; + }else{ + $expressarray = $this->freight($address['id'],$num,$goods); + $data['expressprice'] = $expressarray['price']; + $data['address'] = $address; + } + } + //支付开卡功能 + if(empty($getDraw)){ + $data['is_openvip'] = $_W['wlsetting']['halfcard']['is_openvip']; + }else{ + $data['is_openvip'] = 0; + } + //额外表单内容 + if($goods['diyformid'] > 0){ + $diyFromInfo = pdo_getcolumn(PDO_NAME . 'diyform' , ['id' => $goods['diyformid']] , 'info'); + $data['diyform'] = json_decode(base64_decode($diyFromInfo) , true);//页面的配置信息 + $data['diyformid'] = $goods['diyformid']; + } + //票付通 + $data['pftid'] = $goods['pftid'] ? : 0; + $data['pftuid'] = $goods['ticketid'] ? : 0; + $data['threestatus'] = $goods['threestatus'] ? : 0; + if($data['pftid'] > 0){ + $pftotherinfo = unserialize($goods['pftotherinfo']); + if(empty($data['threestatus'])){ + $data['UUtourist_info'] = $pftotherinfo['UUtourist_info']; + $data['UUdelaytype'] = $pftotherinfo['UUdelaytype'] ? 0 : 1; + if($data['UUdelaytype'] > 0){ + $data['UUorder_start'] = date('Y-m-d', time()); + $end = strtotime($pftotherinfo['UUorder_end']); + if($end > 0){ + $data['UUorder_end'] = date('Y-m-d',$end); + }else{ + $data['UUorder_end'] = date('Y-m-d',$goods['endtime']); + } + } + }else if($data['threestatus'] == 1){ + $data['template'] = json_decode($pftotherinfo['template']); + } + } + $this->renderSuccess('订单确认页面' , $data); + } + /** + * Comment: 积分抵扣函数 + * Author: wlf + * Date: 2019/09/11 14:29 + */ + public function creditDeduction($creditmoney , $num , $remark) + { + global $_W , $_GPC; + $onecreditmoney = 1 / $_W['wlsetting']['creditset']['proportion']; + $allcredit = sprintf("%.2f" , $_W['wlmember']['credit1']); + $dkmoney = sprintf("%.2f" , $creditmoney * $num); + $dkcredit = sprintf("%.2f" , $dkmoney / $onecreditmoney); + if ($dkcredit > $allcredit) { + $dkcredit = $allcredit; + $dkmoney = sprintf("%.2f" , $onecreditmoney * $dkcredit); + } + Member::credit_update_credit1($_W['mid'] , -$dkcredit , $remark); + return ['dkcredit' => $dkcredit , 'dkmoney' => $dkmoney]; + } + /** + * Comment: 生成订单接口 + * Author: wlf + * Date: 2019/8/16 14:55 + */ + public function createOrder() + { + global $_W , $_GPC; + $id = $_GPC['id']; //商品id + $num = $_GPC['num'] ? : 1; //商品数量 + $usestatus = $_GPC['usestatus']; //使用方式 + $plugin = $_GPC['plugin']; //商品插件 + $optionid = $_GPC['specid']; //规格id + $creditstatus = $_GPC['creditstatus']; //积分抵扣 + $username = trim($_GPC['thname']); //提货人姓名 + $mobile = trim($_GPC['thmobile']); //提货人电话 + $addressid = $_GPC['addressid']; //获取地址信息 + $remark = trim($_GPC['remark']); //买家备注 + $buystatus = $_GPC['buystatus']; //拼团特殊值,2单购 1团购 + $groupid = intval($_GPC['groupid']); //拼团特殊值,团id + $cardId = intval($_GPC['vip_card_id']); //同时开启一卡通 + $redpackid = intval($_GPC['redpackid']); //使用的红包 + $drawid = intval($_GPC['drawid']) ? : 0; //领取抽奖奖品 + $luckydrawid = intval($_GPC['luckydrawid']) ? : 0; //领取锦鲤抽奖奖品 + $diyformid = intval($_GPC['diyformid']) ? : 0; //自定义表单id + $settings = Setting::wlsetting_read('orderset'); //获取设置参数 + if (empty($settings['cancel'])) { + $settings['cancel'] = 10; + } + $mastmobile = unserialize($_W['wlsetting']['userset']['plugin']); + if (empty($_W['wlmember']['mobile']) && in_array($plugin , $mastmobile)) { + $this->renderError('未绑定手机号'); + } + if ((empty($addressid) || $addressid == 'undefined') && !empty($usestatus)) { + $this->renderError('请设置收货地址'); + } + //一卡通信息 + if (!empty($cardId)) { + $buycard = pdo_get(PDO_NAME . 'halfcard_type' , ['id' => $cardId] , ['price','levelid']); + } + $userhalfcard = WeliamWeChat::VipVerification($_W['mid']); + $halfcardflag = $userhalfcard['id']; + if($halfcardflag > 0){ + $uhlevel = $userhalfcard['levelid']; + }else if(!empty($cardId)){ + $uhlevel = $buycard['levelid']; + } + $nodis = 0; + //红包优惠 + if(p('redpack') && $redpackid > 0){ + $redpack = pdo_fetch("SELECT b.cut_money FROM".tablename(PDO_NAME . "redpack_records") + ." as a LEFT JOIN " . tablename(PDO_NAME . "redpacks") + ." as b ON a.packid = b.id WHERE a.id = {$redpackid}"); + $redpackmoney = $redpack['cut_money']; + }else{ + $redpackmoney = 0; + } + //额外表单 + $diyFormInfo = []; + if($diyformid > 0){ + //额外表单 + $diyFormInfo = array_values(json_decode(html_entity_decode($_GPC['datas']),true)); +// $diyFormSet = pdo_getcolumn(PDO_NAME."diyform",['id'=>$diyformid],'info'); +// $diyFormSet = array_values(json_decode(base64_decode($diyFormSet), true)['list']);//页面的配置信息 +// foreach($diyFormInfo as $formKey => &$formVal){ +// $formVal['title'] = $diyFormSet[$formKey]['data']['title']; +// } + } + $pftid = $_GPC['pftid']; + if($pftid > 0){ + $pftInfo = json_decode(base64_decode($_GPC['pftdatas']) , true); + if(empty($pftInfo['ordername'])){ + $pftInfo['ordername'] = $username; + } + }else{ + $pftInfo = ''; + } + //亿奇达 + $template = $_GPC['template']; + if(!empty($template)){ + $template = explode(',',$template); + foreach ($template as &$tem){ + $tem = urlencode($tem); + } + $pftInfo = $template; + } + + if ($plugin == 'rush') { + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + $activity = Rush::getSingleActive($id , '*'); + //判断活动状态 + if ($activity['status'] != 2) { + if ($activity['status'] == 1) { + MysqlFunction::rollback(); + $this->renderError('活动未开始'); + } + else if ($activity['status'] == 3) { + MysqlFunction::rollback(); + $this->renderError('活动已结束'); + } + else if ($activity['status'] == 4) { + MysqlFunction::rollback(); + $this->renderError('商品已下架'); + } + else if ($activity['status'] == 7) { + MysqlFunction::rollback(); + $this->renderError('商品已抢完'); + }else if ($activity['status'] == 8) { + MysqlFunction::rollback(); + $this->renderError('商品已删除'); + }else{ + MysqlFunction::rollback(); + $this->renderError('商品未在售卖中'); + } + } + if($activity['usedatestatus'] > 0){ + $check = WeliamWeChat::checkUseDateStatus($activity['usedatestatus'],$activity['week'],$activity['day']); + if(empty($check)){ + $this->renderError('今日商品未在售卖中'); + } + } + if($activity['daylimit'] > 0){ + $today = strtotime(date('Y-m-d')); + $daysalenum = WeliamWeChat::getSalesNum(1,$id,0,1,$_W['mid'],$today); + $sup = $activity['daylimit'] - intval($daysalenum); + if($num > $sup){ + $this->renderError('您今日还可以购买'.$sup.'份'); + } + } + if($activity['monthlimit'] > 0){ + $tomonth = strtotime(date('Y-m')); + $monthsalenum = WeliamWeChat::getSalesNum(1,$id,0,1,$_W['mid'],$tomonth); + $sup = $activity['monthlimit'] - intval($monthsalenum); + if($num > $sup){ + $this->renderError('您这个月还可以购买'.$sup.'份'); + } + } + if($activity['alldaylimit'] > 0){ + $today = strtotime(date('Y-m-d')); + $alldaysalenum = WeliamWeChat::getSalesNum(1,$id,0,1,0,$today); + $sup = $activity['alldaylimit'] - intval($alldaysalenum); + if($num > $sup){ + $this->renderError('商品今日份额还剩'.$sup.'份'); + } + } + + //判断规格 + if ($activity['optionstatus']) { + if ($optionid) { + $option = pdo_get('wlmerchant_goods_option' , ['id' => $optionid] , [ + 'stock' , + 'price' , + 'title' , + 'viparray', + 'disarray' + ]); + $activity['price'] = $option['price']; + $total = $option['stock']; + $activity['viparray'] = WeliamWeChat::mergeVipArray($option['viparray'],$activity['viparray']); + } + else { + MysqlFunction::rollback(); + $this->renderError('规格参数错误,请重新选择'); + } + } + else { + $optionid = 0; + $total = $activity['num']; + } + #判断是否开启阶梯价(目前仅抢购存在) 是否开启阶梯价(0=关闭 1=开启) + if ($activity['lp_status'] == 1) { + $activity['lp_set'] = is_array(unserialize($activity['lp_set'])) ? unserialize($activity['lp_set']) : []; + if (count($activity['lp_set']) > 0) { + $info = WeliamWeChat::getHomeGoods(1 , $id); + $allsalenum = intval($info['allsalenum']); + foreach ($activity['lp_set'] as $lpKey => $lpVal) { + $lpVal['max'] = intval($lpVal['max']) + $allsalenum; + if ($info['buy_num'] < $lpVal['max']) { + $activity['price'] = $lpVal['price']; + $nowStk = $lpVal['max'] - $info['buy_num'];//当前区间上限 - 已售数量 = 当前区间库存 + break; + } + } + //判断是否超出当前区间上限 + if ($nowStk < 0) { + MysqlFunction::rollback(); + $this->renderError("当前区间还可购买{$nowStk}件,您已超出" . ($info['buy_num'] - $lpVal['max']) . "件"); + } + } + } + //判断剩余数量 + $salesVolume = WeliamWeChat::getSalesNum(1,$id,$optionid,1); + $levelnum = $total - intval($salesVolume); + if($levelnum < $num){ + MysqlFunction::rollback(); + $this->renderError('商品库存不足'); + } + if ($levelnum < 1) { + MysqlFunction::rollback(); + $this->renderError('该商品已被抢完。'); + } + /*判断会员*/ + $price = $activity['price']; + $level = unserialize($activity['level']); + if ($activity['vipstatus'] == 1) { + if ($halfcardflag || !empty($cardId)) { + $vipdiscount = WeliamWeChat::getVipDiscount($activity['viparray'],$uhlevel); + if($vipdiscount>0){ + $vipbuyflag = 1; + } + } + } + else if ($activity['vipstatus'] == 2) { + if (empty($halfcardflag) && empty($cardId)) { + MysqlFunction::rollback(); + $this->renderError('该商品会员特供,请先成为会员'); + } + else if ($level) { + //判断等级 + $flag = Halfcard::checklevel($_W['mid'] , $level); + if (empty($flag)) { + MysqlFunction::rollback(); + $this->renderError('您所在的会员等级无权购买该商品'); + } + } + } + if (empty($vipbuyflag)) { + $vipbuyflag = 0; + } + /*判断已购买数量*/ + if ($activity['op_one_limit']) { + $alreadyBuyNum = WeliamWeChat::getSalesNum(1,$id,0,1,$_W['mid']); + $levelnum = $activity['op_one_limit'] - intval($alreadyBuyNum); + if ($levelnum < 0) { + $levelnum = 0; + } + if (!$levelnum) { + MysqlFunction::rollback(); + $this->renderError('限购商品!您已全部购买'); + } + else if ($num > $levelnum) { + MysqlFunction::rollback(); + $this->renderError('限购商品!您还能购买' . $levelnum . $activity['unit']); + } + } + //积分抵扣 + if ($creditstatus) { + if ($activity['creditmoney'] > $price) { + $activity['creditmoney'] = $price; + } + $creditremark = '抢购[' . $activity['name'] . ']抵扣积分'; + $creditindo = self::creditDeduction($activity['creditmoney'] , $num , $creditremark); + $dkcredit = $creditindo['dkcredit']; + $dkmoney = $creditindo['dkmoney']; + } + else { + $dkcredit = 0; + $dkmoney = 0; + } + //结算金额 + if($activity['lp_status']>0){ + if($vipbuyflag>0){ + $useprice = $activity['price'] - $vipdiscount; + }else{ + $useprice = $activity['price']; + } + }else{ + $useprice = 0; + } + $settlementmoney = Store::getsettlementmoney(1 , $id , $num , $activity['sid'] , $vipbuyflag , $optionid,0,$useprice,$uhlevel); + if($settlementmoney < 0.01){ + $settlementmoney = Store::getsettlementmoney(1 , $id , $num , $activity['sid'] , $vipbuyflag , $optionid,0,$useprice,$uhlevel); + if($settlementmoney < 0.01){ + $settlementmoney = Store::getsettlementmoney(1 , $id , $num , $activity['sid'] , $vipbuyflag , $optionid,0,$useprice,$uhlevel); + } + } + + if($vipdiscount > 0){ + $vipdiscount = $vipdiscount * $num; + }else{ + $vipdiscount = 0; + } + //快递订单 + if ($usestatus) { + $express = $this->freight($addressid , $num , $activity); + $expressprice = $express['price']; + $expressid = $express['expressid']; + $settlementmoney = sprintf("%.2f" , $settlementmoney + $expressprice); + $neworderflag = 0; + }else { + $expressprice = 0; + $neworderflag = 1; + } + //创建订单 + $prices = sprintf("%.2f" , $price * $num); + //满减活动 + if($activity['fullreduceid']>0){ + $fulldkmoney = Fullreduce::getFullreduceMoney(sprintf("%.2f" , $prices - $vipdiscount),$activity['fullreduceid']); + }else{ + $fulldkmoney = 0; + } + if (!empty($cardId)) { + $cardprice = pdo_getcolumn(PDO_NAME . 'halfcard_type' , ['id' => $cardId] , 'price'); + } + else { + $cardprice = 0; + } + if($drawid > 0){ + $flag = pdo_getcolumn(PDO_NAME.'rush_order',array('drawid'=>$drawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $prices = 0; + } + + if($luckydrawid > 0){ + $flag = pdo_getcolumn(PDO_NAME.'rush_order',array('luckydrawid'=>$luckydrawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $prices = 0; + } + + $actualprice = sprintf("%.2f" , $prices - $vipdiscount - $redpackmoney - $dkmoney - $fulldkmoney + $expressprice + $cardprice); + $data = [ + 'uniacid' => $activity['uniacid'] , + 'unionid' => $_W['unionid'] , + 'mid' => $_W['mid'] , + 'openid' => $_W['openid'] , + 'sid' => $activity['sid'] , + 'aid' => $activity['aid'] , + 'activityid' => $activity['id'] , + 'orderno' => createUniontid() , + 'status' => 0 ,//订单状态:0未支,1支付,2待发货,3已发货,4已签收,5已取消,6待退款,7已退款 + 'createtime' => TIMESTAMP , + 'price' => $activity['price'] * $num,//$prices + 'actualprice' => $actualprice > 0 ? $actualprice : 0, + 'num' => $num , + 'username' => $username , + 'mobile' => $mobile , + 'vipbuyflag' => $vipbuyflag , + 'optionid' => $optionid , + 'dkcredit' => $dkcredit , + 'dkmoney' => $dkmoney , + 'expressid' => $expressid , + 'remark' => $remark , + 'settlementmoney' => $settlementmoney , + 'neworderflag' => $neworderflag , + 'vip_card_id' => $cardId ,//会员卡的id + 'canceltime' => time() + $settings['cancel'] * 60, + 'redpackid' => $redpackid, + 'redpackmoney' => $redpackmoney, + 'fullreduceid' => $activity['fullreduceid'], + 'fullreducemoney' => $fulldkmoney, + 'drawid' => $drawid, + 'luckydrawid' => $luckydrawid, + 'discount' => $vipdiscount, + 'moinfo' => serialize($diyFormInfo), + 'pftinfo' => serialize($pftInfo) + ]; + pdo_insert(PDO_NAME . 'rush_order' , $data); + $orderid = pdo_insertid(); + if (empty($orderid)) { + MysqlFunction::rollback(); + $this->renderError('创建订单失败,请刷新重试'); + } + if($redpackid){ + pdo_update('wlmerchant_redpack_records',array('status' => 1,'usetime' =>time(),'orderid' => $orderid,'plugin' => $plugin),array('id' => $redpackid)); + } + //修改商品数量 + $buynum = WeliamWeChat::getSalesNum(1,$id,0,1); + $total = $activity['num']; + $total = $total - intval($buynum); + if($total == 0){ + Rush::updateActive(['status'=>7] , ['id' => $data['activityid']]);//修改商品状态为已售罄 + } + MysqlFunction::commit(); + if ($data['actualprice'] > 0) { + $unidata['status'] = 1; + $unidata['orderid'] = $orderid; + $this->renderSuccess('下单成功' , $unidata); + }else if ($data['actualprice'] == 0) { + //0元购 购买商品的同时开通会员卡是不允许进行0元购的 必须进入支付流程 + $newdata = [ + 'status' => 1 , + 'paytime' => time() , + 'usetimes' => $num , + 'paytype' => 6 , + ]; + + if ($expressid) { + $newdata['status'] = 8; + } else { + Order::createSmallorder($orderid , 1); + //计算过期时间 + if ($activity['cutoffstatus']) { + $newdata['estimatetime'] = time() + $activity['cutoffday'] * 86400; + } + else { + $newdata['estimatetime'] = $activity['cutofftime']; + } + $newdata['remindtime'] = Order::remindTime($newdata['estimatetime']); + } + //处理分销 + if($data['dkmoney']>0 && $_W['wlsetting']['creditset']['nodistribution'] > 0){ + $nodis = 1; + } + if (p('distribution') && empty($activity['isdistri']) && empty($data['drawid']) && empty($data['luckydrawid']) && empty($nodis)) { + if ($optionid > 0) { + $activity['disarray'] = WeliamWeChat::mergeDisArray($option['disarray'],$activity['disarray']); + } + $disarray = unserialize($activity['disarray']); + $disprice = sprintf("%.2f",$data['price'] - $data['discount']); + $disorderid = Distribution::disCore($data['mid'], $disprice, $disarray, $data['num'], 0,$orderid, 'rush', $activity['dissettime'],$activity['isdistristatus']); + $newdata['disorderid'] = $disorderid; + } + pdo_update(PDO_NAME . 'rush_order' , $newdata , ['orderno' => $data['orderno']]); //更新订单状态 + //抽奖状态 + if($data['drawid'] > 0){ + pdo_update('wlmerchant_draw_record',array('is_get' => 2),array('id' => $data['drawid'])); + } + if($data['luckydrawid'] > 0){ + pdo_update('wlmerchant_luckydraw_drawcode',array('is_get' => 1,'gettime' => time()),array('id' => $data['luckydrawid'])); + } + //处理营销 + if ($activity['integral']) { + $remark = '抢购:[' . $activity['name'] . ']赠送积分'; + Member::credit_update_credit1($_W['mid'] , $activity['integral'] * $num , $remark); + } + /***模板通知***/ + Store::addFans($activity['sid'] , $_W['mid']); + News::addSysNotice($data['uniacid'],1,$data['sid'],0,$orderid); + News::paySuccess($orderid, 'rush'); + //小票打印 + Order::sendPrinting($orderid,'rush'); + + $unidata['status'] = 0; + $unidata['orderid'] = $orderid; + $unidata['tid'] = $data['orderno']; + $unidata['plugin'] = 'rush'; + $this->renderSuccess('购买成功' , $unidata); + } + } + //团购 + if ($plugin == 'groupon') { + $activity = Groupon::getSingleActive($id , '*'); + if ($activity['status'] != 2) { + if ($activity['status'] == 1) { + $this->renderError('活动未开始'); + } + else if ($activity['status'] == 3) { + $this->renderError('活动已结束'); + } + else if ($activity['status'] == 4) { + $this->renderError('商品已下架'); + } + else if ($activity['status'] == 7) { + $this->renderError('商品已抢完'); + } + else { + $this->renderError('商品已停售'); + } + } + + if($activity['usedatestatus'] > 0){ + $check = WeliamWeChat::checkUseDateStatus($activity['usedatestatus'],$activity['week'],$activity['day']); + if(empty($check)){ + $this->renderError('今日商品未在售卖中'); + } + } + if($activity['alldaylimit'] > 0){ + $today = strtotime(date('Y-m-d')); + $daysalenum = WeliamWeChat::getSalesNum(2,$id,0,1,0,$today); + $sup = $activity['alldaylimit'] - intval($daysalenum); + if($num > $sup){ + $this->renderError('商品今日份额剩余'.$sup.'份'); + } + } + if($activity['daylimit'] > 0){ + $today = strtotime(date('Y-m-d')); + $daysalenum = WeliamWeChat::getSalesNum(2,$id,0,1,$_W['mid'],$today); + $sup = $activity['daylimit'] - intval($daysalenum); + if($num > $sup){ + $this->renderError('您的今日还能购买'.$sup.'份'); + } + } + + + //判断规格 + if ($activity['optionstatus']) { + if ($optionid) { + $option = pdo_get('wlmerchant_goods_option' , ['id' => $optionid] , [ + 'stock' , + 'price' , + 'title' , + 'viparray' + ]); + $activity['price'] = $option['price']; + $total = $option['stock']; + $activity['viparray'] = WeliamWeChat::mergeVipArray($option['viparray'],$activity['viparray']); + } + else { + $this->renderError('规格参数错误,请重新选择'); + } + } + else { + $optionid = 0; + } + /*判断会员*/ + $price = $activity['price']; + $level = unserialize($activity['level']); + if ($activity['vipstatus'] == 1) { + if ($halfcardflag || $cardId) { + $vipdiscount = WeliamWeChat::getVipDiscount($activity['viparray'],$uhlevel); + if($vipdiscount>0){ + $vipbuyflag = 1; + } + } + } + else if ($activity['vipstatus'] == 2) { + if (empty($halfcardflag) && empty($cardId)) { + $this->renderError('该商品会员特供,请先成为会员'); + } + else if ($level && empty($cardId)) { + //判断等级 + $flag = Halfcard::checklevel($_W['mid'] , $level); + if (empty($flag)) { + $this->renderError('您所在的会员等级无权购买该商品'); + } + } + else if (!empty($cardId)) { + //购买商品的同时开通会员卡 + $levelId = pdo_getcolumn(PDO_NAME . "halfcard_type" , ['id' => $cardId] , 'levelid'); + if (!in_array($levelId , $level)) { + $this->renderError('您所开通的会员卡无权购买该商品'); + } + } + } + if (empty($vipbuyflag)) { + $vipbuyflag = 0; + } + /*判断已购买数量*/ + if ($activity['op_one_limit']) { + $alreadyBuyNum = WeliamWeChat::getSalesNum(2,$id,0,1,$_W['mid']); + if (empty($alreadyBuyNum)) { + $alreadyBuyNum = 0; + } + $levelnum = $activity['op_one_limit'] - $alreadyBuyNum; + if (!$levelnum) { + $this->renderError('限购商品!您已全部购买'); + } + else if ($num > $levelnum) { + if ($levelnum < 0) { + $levelnum = 0; + } + $this->renderError("限购商品!您还能购买" . $levelnum . $activity['unit']); + } + } + //判断库存 + if($optionid > 0){ + $salenum = WeliamWeChat::getSalesNum(2,$id,$optionid,1,0); + $activity['levelnum'] = sprintf("%.0f" ,$total - intval($salenum)); + if ($activity['levelnum'] < 1) { + $this->renderError('此规格已售罄'); + } + }else{ + $salenum = WeliamWeChat::getSalesNum(2,$id,0,1,0); + $activity['levelnum'] = sprintf("%.0f" , $activity['num'] - intval($salenum)); + if ($activity['levelnum'] < 1) { + $this->renderError('此商品已售罄'); + } + } + if ($num > $activity['levelnum']) { + $this->renderError('库存不足,请减少购买数量'); + } + + + //积分抵扣 + if ($creditstatus) { + if ($activity['creditmoney'] > $price) { + $activity['creditmoney'] = $price; + } + $creditremark = '团购[' . $activity['name'] . ']抵扣积分'; + $creditindo = self::creditDeduction($activity['creditmoney'] , $num , $creditremark); + $dkcredit = $creditindo['dkcredit']; + $dkmoney = $creditindo['dkmoney']; + } + else { + $dkcredit = 0; + $dkmoney = 0; + } + //结算金额 + $settlementmoney = Store::getsettlementmoney(3 , $id , $num , $activity['sid'] , $vipbuyflag , $optionid,0,0,$uhlevel); + if($settlementmoney < 0.01){ + $settlementmoney = Store::getsettlementmoney(3 , $id , $num , $activity['sid'] , $vipbuyflag , $optionid,0,0,$uhlevel); + } + //快递订单 + if ($usestatus) { + $express = $this->freight($addressid , $num , $activity); + $expressprice = $express['price']; + $expressid = $express['expressid']; + $settlementmoney = sprintf("%.2f" , $settlementmoney + $expressprice); + $neworderflag = 0; + } + else { + $username = trim($_GPC['thname']); + $mobile = trim($_GPC['thmobile']); + $expressprice = 0; + $neworderflag = 1; + } + //创建订单 + if($vipdiscount > 0){ + $vipdiscount = $vipdiscount * $num; + }else{ + $vipdiscount = 0; + } + if (!empty($cardId)) { + $cardprice = pdo_getcolumn(PDO_NAME . 'halfcard_type' , ['id' => $cardId] , 'price'); + } + else { + $cardprice = 0; + } + //满减活动 + if($activity['fullreduceid']>0){ + $fulldkmoney = Fullreduce::getFullreduceMoney(sprintf("%.2f" , $price * $num - $vipdiscount),$activity['fullreduceid']); + }else{ + $fulldkmoney = 0; + } + if($drawid > 0){ + $flag = pdo_getcolumn(PDO_NAME.'order',array('drawid'=>$drawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $price = 0; + } + if($luckydrawid > 0){ + $flag = pdo_getcolumn(PDO_NAME.'order',array('luckydrawid'=>$luckydrawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $price = 0; + } + $prices = sprintf("%.2f" , $price * $num - $vipdiscount - $redpackmoney + $expressprice - $dkmoney + $cardprice - $fulldkmoney); + $goodsprice = sprintf("%.2f" , $activity['price'] * $num); + $data = [ + 'uniacid' => $activity['uniacid'] , + 'mid' => $_W['mid'] , + 'sid' => $activity['sid'] , + 'aid' => $activity['aid'] , + 'fkid' => $activity['id'] , + 'plugin' => 'groupon' , + 'payfor' => 'grouponOrder' , + 'orderno' => createUniontid() , + 'status' => 0 ,//订单状态:0未支,1支付,2待发货,3已发货,4已签收,5已取消,6待退款,7已退款 + 'createtime' => TIMESTAMP , + 'price' => $prices > 0 ? $prices : 0, + 'num' => $num , + 'vipbuyflag' => $vipbuyflag , + 'specid' => $optionid , + 'name' => $username , + 'mobile' => $mobile , + 'goodsprice' => $goodsprice , + 'expressid' => $expressid , + 'buyremark' => $remark , + 'settlementmoney' => $settlementmoney , + 'vip_card_id' => $cardId ,//会员卡的id + 'neworderflag' => $neworderflag , + 'usecredit' => $dkcredit , + 'cerditmoney' => $dkmoney , + 'canceltime' => time() + $settings['cancel'] * 60, + 'redpackid' => $redpackid, + 'redpackmoney' => $redpackmoney, + 'fullreduceid' => $activity['fullreduceid'], + 'fullreducemoney' => $fulldkmoney, + 'drawid' => $drawid, + 'luckydrawid' => $luckydrawid, + 'vipdiscount' => $vipdiscount, + 'moinfo' => serialize($diyFormInfo), + 'pftinfo' => serialize($pftInfo) + + ]; + pdo_insert(PDO_NAME . 'order' , $data); + $orderid = pdo_insertid(); + if($redpackid){ + pdo_update('wlmerchant_redpack_records',array('status' => 1,'usetime' =>time(),'orderid' => $orderid,'plugin' => $plugin),array('id' => $redpackid)); + } + //修改商品数量 + $salenum = WeliamWeChat::getSalesNum(2,$id,0,1,0); + $total = $activity['num']; + $total = $total - intval($salenum); + if($total <= 0) Groupon::updateActive(['status'=>7],['id' => $data['fkid']]);//修改商品状态为已售罄 + if ($data['price'] > 0) { + $unidata['status'] = 1; + $unidata['orderid'] = $orderid; + $this->renderSuccess('购买成功' , $unidata); + } + else { + //0元购 购买商品的同时开通会员卡是不允许进行0元购的 必须进入支付流程 + $newdata = [ + 'status' => 1 , + 'paytime' => time() , + 'paytype' => 6 , + ]; + + + if ($expressid) { + $newdata['status'] = 8; + } + else { + Order::createSmallorder($orderid , 2); + //计算过期时间 + if ($activity['cutoffstatus']) { + $newdata['estimatetime'] = time() + $activity['cutoffday'] * 86400; + } + else { + $newdata['estimatetime'] = $activity['cutofftime']; + } + $newdata['remindtime'] = Order::remindTime($newdata['estimatetime']); + } + + //处理分销 + if($dkmoney>0 && $_W['wlsetting']['creditset']['nodistribution'] > 0){ + $nodis = 1; + } + if (p('distribution') && empty($activity['isdistri']) && empty($data['drawid']) && empty($nodis)) { + if ($data['specid']) { + $option = pdo_get('wlmerchant_goods_option', array('id' => $data['specid']), array('onedismoney', 'twodismoney', 'threedismoney')); + $activity['disarray'] = WeliamWeChat::mergeDisArray($option['disarray'],$activity['disarray']); + } + $disarray = unserialize($activity['disarray']); + $disprice = sprintf("%.2f",$data['goodsprice'] - $data['vipdiscount']); + $disorderid = Distribution::disCore($data['mid'], $disprice, $disarray, $data['num'], 0, $orderid, 'groupon', $activity['dissettime'],$activity['isdistristatus']); + $newdata['disorderid'] = $disorderid; + } + + pdo_update(PDO_NAME . 'order' , $newdata , ['orderno' => $data['orderno']]); //更新订单状态 + //抽奖状态 + if($data['drawid'] > 0){ + pdo_update('wlmerchant_draw_record',array('is_get' => 2),array('id' => $data['drawid'])); + } + if($data['luckydrawid'] > 0){ + pdo_update('wlmerchant_luckydraw_drawcode',array('is_get' => 1,'gettime' => time()),array('id' => $data['luckydrawid'])); + } + //处理营销 + if ($activity['integral']) { + $remark = '团购:[' . $activity['name'] . ']赠送积分'; + Member::credit_update_credit1($_W['mid'] , $activity['integral'] * $num , $remark); + } + /***模板通知***/ + Store::addFans($activity['sid'] , $_W['mid']); + News::addSysNotice($data['uniacid'],2,$data['sid'],0,$orderid); + News::paySuccess($orderid, 'groupon'); + //小票打印 + Order::sendPrinting($orderid,'groupon'); + + $unidata['status'] = 0; + $unidata['orderid'] = $orderid; + $unidata['tid'] = $data['orderno']; + $unidata['plugin'] = 'groupon'; + $this->renderSuccess('购买成功' , $unidata); + } + } + //卡券 + if ($plugin == 'coupon') { + $coupons = wlCoupon::getSingleCoupons($id , '*'); + $coupons['surplus'] = WeliamWeChat::getSalesNum(4,$id,0,1,0); + //判断当前卡卷是否为会员特供 + if ($coupons['status'] != 2) { + $this->renderError('卡券出售已结束或未开始,无法购买'); + } + if($coupons['usedatestatus'] > 0){ + $check = WeliamWeChat::checkUseDateStatus($coupons['usedatestatus'],$coupons['week'],$coupons['day']); + if(empty($check)){ + $this->renderError('今日卡券未在售卖中'); + } + } + if($coupons['alldaylimit'] > 0){ + $today = strtotime(date('Y-m-d')); + $alldaysalenum = WeliamWeChat::getSalesNum(4,$id,0,1,0,$today); + $sup = $coupons['alldaylimit'] - intval($alldaysalenum); + if($num > $sup){ + $this->renderError('商品今日份额仅剩'.$sup.'份'); + } + } + if($coupons['daylimit'] > 0){ + $today = strtotime(date('Y-m-d')); + $daysalenum = WeliamWeChat::getSalesNum(4,$id,0,1,$_W['mid'],$today); + $sup = $coupons['daylimit'] - intval($daysalenum); + if($num > $sup){ + $this->renderError('您今日还能买'.$sup.'份'); + } + } + + $alnum = WeliamWeChat::getSalesNum(4,$id,0,1,$_W['mid']); + $allnum = $alnum + $num; + if ($coupons['time_type'] == 1 && $coupons['endtime'] < time()) { + $this->renderError('抱歉,超级券已停止发放'); + } + if (($coupons['quantity'] - intval($coupons['surplus'])) < $num) { + $this->renderError('抱歉,超级券库存不足'); + } + if ($allnum > $coupons['get_limit'] && $coupons['get_limit'] > 0) { + $this->renderError('抱歉,一个用户只能获取' . $coupons['get_limit'] . '张,您已下单' . $alnum . '张。'); + } + if ($coupons['vipstatus'] == 1 && ($halfcardflag || $cardId)) { + $vipdiscount = WeliamWeChat::getVipDiscount($coupons['viparray'],$uhlevel); + if($vipdiscount > 0){ + $vipbuyflag = 1; + } + } + else if ($coupons['vipstatus'] == 2) { + $goodsLv = unserialize($coupons['level']); + if ($halfcardflag <= 0) { + $this->renderError('当前商品为会员限定,请先成为会员!'); + } + else if (count($goodsLv) > 0) { + $lv = pdo_getcolumn(PDO_NAME . "halfcardmember" , ['id' => $halfcardflag] , 'levelid'); + if (!in_array($lv , $goodsLv)) { + $this->renderError('您所在的会员等级无权购买该商品!'); + } + } + } + if (empty($vipbuyflag)) { + $vipbuyflag = 0; + } + //免费卡券 + if (empty($coupons['is_charge'])) { + $coupons['price'] = 0; + $settlementmoney = 0; + }else { + //结算金额 + $settlementmoney = Store::getsettlementmoney(4 , $id , $num , $coupons['merchantid'] , $vipbuyflag,0,0,0,$uhlevel); + if($settlementmoney < 0.01){ + $settlementmoney = Store::getsettlementmoney(4 , $id , $num , $coupons['merchantid'] , $vipbuyflag,0,0,0,$uhlevel); + } + } + if($vipdiscount > 0){ + $vipdiscount = $vipdiscount * $num; + }else{ + $vipdiscount = 0; + } + if (!empty($cardId)) { + $cardprice = pdo_getcolumn(PDO_NAME . 'halfcard_type' , ['id' => $cardId] , 'price'); + } + else { + $cardprice = 0; + } + $price = $coupons['price'] * $num; + #6、积分抵扣 + if ($creditstatus) { + if ($coupons['creditmoney'] > $price) { + $coupons['creditmoney'] = $price; + } + $creditremark = '超级券[' . $coupons['title'] . ']抵扣积分'; + $creditindo = self::creditDeduction($coupons['creditmoney'] , $num , $creditremark); + $dkcredit = $creditindo['dkcredit']; + $dkmoney = $creditindo['dkmoney']; + } + else { + $dkcredit = 0; + $dkmoney = 0; + } + + //满减活动 + if($coupons['fullreduceid']>0){ + $fulldkmoney = Fullreduce::getFullreduceMoney(sprintf("%.2f" ,$price - $vipdiscount),$coupons['fullreduceid']); + }else{ + $fulldkmoney = 0; + } + if($drawid > 0){ + $flag = pdo_getcolumn(PDO_NAME.'order',array('drawid'=>$drawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $price = 0; + } + if($luckydrawid > 0){ + $flag = pdo_getcolumn(PDO_NAME.'order',array('luckydrawid'=>$luckydrawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $price = 0; + } + $prices = sprintf("%.2f" , $price + $cardprice - $vipdiscount - $redpackmoney - $fulldkmoney - $dkmoney); + $data = [ + 'uniacid' => $coupons['uniacid'] , + 'mid' => $_W['mid'] , + 'aid' => $coupons['aid'] , + 'fkid' => $id , + 'sid' => $coupons['merchantid'] , + 'status' => 0 , + 'paytype' => 2 , + 'createtime' => time() , + 'orderno' => createUniontid() , + 'price' => $prices > 0 ? $prices : 0, + 'num' => $num , + 'plugin' => 'coupon' , + 'payfor' => 'couponsharge' , + 'vipbuyflag' => $vipbuyflag , + 'goodsprice' => $coupons['price'] * $num , + 'settlementmoney' => $settlementmoney , + 'neworderflag' => 1 , + 'buyremark' => $remark , + 'canceltime' => time() + $settings['cancel'] * 60 , + 'vip_card_id' => $cardId, + 'redpackid' => $redpackid, + 'redpackmoney' => $redpackmoney, + 'fullreduceid' => $coupons['fullreduceid'], + 'fullreducemoney' => $fulldkmoney, + 'drawid' => $drawid, + 'luckydrawid' => $luckydrawid, + 'vipdiscount' => $vipdiscount, + 'usecredit' => $dkcredit , + 'cerditmoney' => $dkmoney, + 'mobile' => $mobile + ]; + $orderid = wlCoupon::saveCouponOrder($data); + if($redpackid){ + pdo_update('wlmerchant_redpack_records',array('status' => 1,'usetime' =>time(),'orderid' => $orderid,'plugin' => $plugin),array('id' => $redpackid)); + } + if ($data['price'] > 0) { + $unidata['status'] = 1; + $unidata['orderid'] = $orderid; + $this->renderSuccess('下单成功' , $unidata); + } + else { + //领取免费卡券 + $newdata = [ + 'status' => 1 , + 'paytime' => time() , + 'paytype' => 6 , + ]; + //创建小订单 + Order::createSmallorder($orderid , 4); + //处理分销 + if($dkmoney>0 && $_W['wlsetting']['creditset']['nodistribution'] > 0){ + $nodis = 1; + } + if (p('distribution') && empty($coupons['isdistri']) && empty($data['drawid']) && empty($data['luckydrawid']) && empty($nodis) ) { + $disarray = unserialize($coupons['disarray']); + $dismoney = sprintf("%.2f", $data['goodsprice'] - $data['vipdiscount']); + $disorderid = Distribution::disCore($data['mid'], $dismoney, $disarray, $data['num'], 0, $orderid, 'coupon', $coupons['dissettime'],$coupons['isdistristatus']); + $newdata['disorderid'] = $disorderid; + } + //抽奖领取 + if($data['drawid'] > 0){ + pdo_update('wlmerchant_draw_record',array('is_get' => 2),array('id' => $data['drawid'])); + } + if($data['luckydrawid'] > 0){ + pdo_update('wlmerchant_luckydraw_drawcode',array('is_get' => 1,'gettime' => time()),array('id' => $data['luckydrawid'])); + } + if ($coupons['time_type'] == 1) { + $starttime = $coupons['starttime']; + $endtime = $coupons['endtime']; + } + else { + $starttime = time(); + $endtime = time() + ($coupons['deadline'] * 24 * 3600); + } + $data2 = [ + 'mid' => $data['mid'] , + 'aid' => $data['aid'] , + 'parentid' => $coupons['id'] , + 'status' => 1 , + 'type' => $coupons['type'] , + 'title' => $coupons['title'] , + 'sub_title' => $coupons['sub_title'] , + 'content' => $coupons['goodsdetail'] , + 'description' => $coupons['description'] , + 'color' => $coupons['color'] , + 'starttime' => $starttime , + 'endtime' => $endtime , + 'createtime' => time() , + 'orderno' => $data['orderno'] , + 'price' => 0 , + 'usetimes' => $num * $coupons['usetimes'] , + ]; + $newdata['recordid'] = wlCoupon::saveMemberCoupons($data2); + $newdata['estimatetime'] = $data2['endtime']; + //计算过期提醒时间 + $newdata['remindtime'] = Order::remindTime($newdata['estimatetime']); + pdo_update(PDO_NAME . 'order' , $newdata , ['id' => $orderid]); //更新订单状态 + /***模板通知***/ + News::addSysNotice($data['uniacid'],2,$data['sid'],0,$orderid); + Store::addFans($data['sid'], $data['mid']); + News::paySuccess($orderid,'coupon'); + + $unidata['status'] = 0; + $unidata['orderid'] = $orderid; + $unidata['recordid'] = $newdata['recordid']; + $unidata['tid'] = $data['orderno']; + $unidata['plugin'] = 'coupon'; + $this->renderSuccess('购买成功' , $unidata); + } + } + //拼团 + if ($plugin == 'wlfightgroup') { + $good = Wlfightgroup::getSingleGood($id , '*'); + #1、判断组团情况 + if ($groupid) { + $group = pdo_get('wlmerchant_fightgroup_group' , ['id' => $groupid]); + if ($group['status'] == 2 || $group['lacknum'] == 0) { + $this->renderError('该团已经组团成功,请您新开一团。'); + } + else if ($group['status'] == 3 || $group['failtime'] < time()) { + $this->renderError('该团已经组团失败,请您新开一团。'); + } + } + #2、判断商品发售时间 + if ($good['islimittime']) { + if ($good['limitstarttime'] > time()) { + $this->renderError('该商品未到发售时间'); + } + if ($good['limitendtime'] < time()) { + $this->renderError('该商品已停止发售'); + } + } + #3、判断商品是否下架 + if ($good['status'] != 2) { + $this->renderError('抱歉,商品未在售卖中'); + } + //判断时间 + if($good['usedatestatus'] > 0){ + $check = WeliamWeChat::checkUseDateStatus($good['usedatestatus'],$good['week'],$good['day']); + if(empty($check)){ + $this->renderError('今日商品未在售卖中'); + } + } + if($good['daylimit'] > 0){ + $today = strtotime(date('Y-m-d')); + $daysalenum = WeliamWeChat::getSalesNum(3,$id,0,1,$_W['mid'],$today); + $sup = $good['daylimit'] - intval($daysalenum); + if($num > $sup){ + $this->renderError('您今日还可以购买'.$sup.'份'); + } + } + if($good['alldaylimit'] > 0){ + $today = strtotime(date('Y-m-d')); + $alldaysalenum = WeliamWeChat::getSalesNum(3,$id,0,1,0,$today); + $sup = $good['alldaylimit'] - intval($alldaysalenum); + if($num > $sup){ + $this->renderError('商品今日份额还剩'.$sup.'份'); + } + } + #4、判断购买数量限制 + if ($good['op_one_limit']) {//0未支付 1已支付 2已消费 3已完成 4待收货 待消费 5已取消 6待退款 7已退款 8待发货 + $arbuy = WeliamWeChat::getSalesNum(3,$id,0,1,$_W['mid']); + if ($arbuy + $num > $good['op_one_limit'] && $arbuy < $good['op_one_limit']) { + $morenum = $good['op_one_limit'] - intval($arbuy); + $this->renderError('限购商品,您还能购买' . $morenum . '件'); + } + else if ($arbuy >= $good['op_one_limit']) { + $this->renderError('抱歉,您已达到商品购买数量上限'); + } + else { + $good['op_one_limit'] = $good['op_one_limit'] - intval($arbuy); + } + } + #5、判断商品规格 获取对应的价格 + if ($good['specstatus']) { + if ($optionid) { + $option = pdo_get('wlmerchant_goods_option' , ['id' => $optionid]); + if ($buystatus == 1) { + $price = $option['price']; + } + else { + $price = $option['vipprice']; + } + $allarbuy = WeliamWeChat::getSalesNum(3,$id,$optionid,1,0); + if($allarbuy + $num > $option['stock']){ + $this->renderError('该规格库存不足,请选择其他规格'); + } + $good['viparray'] = WeliamWeChat::mergeVipArray($option['viparray'],$good['viparray']); + } + else { + $this->renderError('商品规格错误,请返回重新选择'); + } + }else { + if ($buystatus == 1) { + $price = $good['price']; + } + else { + $price = $good['aloneprice']; + } + //判断库存 + $allarbuy = WeliamWeChat::getSalesNum(3,$id,0,1,0); + if($allarbuy + $num > $good['stock']){ + $this->renderError('商品库存不足,无法下单'); + } + } + $goodsprice = $price * $num; + #6、积分抵扣 + if ($creditstatus) { + if ($good['creditmoney'] > $price) { + $good['creditmoney'] = $price; + } + $creditremark = '拼团商品[' . $good['name'] . ']抵扣积分'; + $creditindo = self::creditDeduction($good['creditmoney'] , $num , $creditremark); + $dkcredit = $creditindo['dkcredit']; + $dkmoney = $creditindo['dkmoney']; + } + else { + $dkcredit = 0; + $dkmoney = 0; + } + #7、判断会员优惠 + if (($halfcardflag || $cardId) && $good['vipstatus'] == 1) { + $vipdiscount = WeliamWeChat::getVipDiscount($good['viparray'],$uhlevel); + if($vipdiscount > 0){ + $vipbuyflag = 1; + } + } + else if ($good['vipstatus'] == 2) { + $goodsLv = unserialize($good['level']); + if ($halfcardflag <= 0) { + $this->renderError('当前商品为会员限定,请先成为会员!'); + } + else if (count($goodsLv) > 0) { + $lv = pdo_getcolumn(PDO_NAME . "halfcardmember" , ['id' => $halfcardflag] , 'levelid'); + if (!in_array($lv , $goodsLv)) { + $this->renderError('您所在的会员等级无权购买该商品!'); + } + } + } + if (empty($vipbuyflag)) { + $vipbuyflag = 0; + } + #8、判断是否开启单团功能 + $fightSet = Setting::agentsetting_read('fightgroup'); //获取设置参数 + if ($fightSet['onlyone'] == 1) { + $groupNumber = pdo_fetchcolumn("SELECT COUNT(b.id) FROM " . tablename(PDO_NAME . "order") . " as a RIGHT JOIN " . tablename(PDO_NAME . "fightgroup_group") . " as b ON a.fightgroupid = b.id WHERE a.mid = {$_W['mid']} AND a.fkid = {$id} AND plugin = 'wlfightgroup' AND b.status = 1 "); + if ($groupNumber > 0) $this->renderError('您已经加入一个当前商品的团,请勿重复加入!'); + } + //购买方式 + if ($usestatus) { + $express = $this->freight($addressid , $num , $good); + $expressprice = $express['price']; + $expressid = $express['expressid']; + $neworderflag = 0; + } + else { + $username = trim($_GPC['thname']); + $mobile = trim($_GPC['thmobile']); + $expressprice = 0; + $neworderflag = 1; + } + //结算金额 + $com_dis_price = intval(0); + if ($buystatus == 1) { + $buyflah = 0;//团购 + //拼团 - 团长优惠 + if ($good['is_com_dis'] == 1 && empty($groupid)) { + $com_dis_price = sprintf("%.2f" , ($good['com_dis_price'] ? : 0)); + } + } + else { + $buyflah = 1; + } + $settlementmoney = Store::getsettlementmoney(2 , $id , $num , $good['merchantid'] , $vipbuyflag , $optionid , $buyflah,0,$uhlevel); + if($settlementmoney < 0.01){ + $settlementmoney = Store::getsettlementmoney(2 , $id , $num , $good['merchantid'] , $vipbuyflag , $optionid , $buyflah,0,$uhlevel); + } + $settlementmoney = sprintf("%.2f" , $settlementmoney + $expressprice); + if($vipdiscount > 0){ + $vipdiscount = $vipdiscount * $num; + }else{ + $vipdiscount = 0; + } + if (!empty($cardId)) { + $cardprice = pdo_getcolumn(PDO_NAME . 'halfcard_type' , ['id' => $cardId] , 'price'); + } + else { + $cardprice = 0; + } + //满减活动 + if($good['fullreduceid']>0){ + $fulldkmoney = Fullreduce::getFullreduceMoney(sprintf("%.2f" , $price * $num - $vipdiscount - $com_dis_price),$good['fullreduceid']); + }else{ + $fulldkmoney = 0; + } + if($drawid){ + $flag = pdo_getcolumn(PDO_NAME.'order',array('drawid'=>$drawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $price = 0; + $buystatus = 2; + } + + if($luckydrawid){ + $flag = pdo_getcolumn(PDO_NAME.'order',array('luckydrawid'=>$luckydrawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $price = 0; + $buystatus = 2; + } + $orderprice = sprintf("%.2f" , $price * $num + $expressprice - $vipdiscount - $fulldkmoney - $dkmoney + $cardprice - $com_dis_price - $redpackmoney); + $data = [ + 'uniacid' => $good['uniacid'] , + 'mid' => $_W['mid'] , + 'aid' => $good['aid'] , + 'fkid' => $id , + 'sid' => $good['merchantid'] , + 'status' => 0 , + 'paytype' => 0 , + 'createtime' => time() , + 'orderno' => createUniontid() , + 'price' => $orderprice > 0 ? $orderprice : 0, + 'num' => $num , + 'plugin' => 'wlfightgroup' , + 'payfor' => 'fightsharge' , + 'spec' => $option['title'] , + 'specid' => $optionid , + 'name' => $username , + 'mobile' => $mobile , + 'fightstatus' => $buystatus , + 'fightgroupid' => $groupid , + 'expressid' => $expressid , + 'buyremark' => $remark , + 'vipbuyflag' => $vipbuyflag , + 'goodsprice' => $goodsprice , + 'settlementmoney' => $settlementmoney , + 'vip_card_id' => $cardId ,//会员卡的id + 'neworderflag' => $neworderflag , + 'usecredit' => $dkcredit , + 'cerditmoney' => $dkmoney , + 'canceltime' => time() + $settings['cancel'] * 60 , + 'com_dis_price' => $com_dis_price, + 'redpackid' => $redpackid, + 'redpackmoney' => $redpackmoney, + 'fullreduceid' => $good['fullreduceid'], + 'fullreducemoney' => $fulldkmoney, + 'drawid' => $drawid, + 'luckydrawid' => $luckydrawid, + 'vipdiscount' => $vipdiscount, + 'moinfo' => serialize($diyFormInfo), + 'pftinfo' => serialize($pftInfo) + ]; + $orderid = Wlfightgroup::saveFightOrder($data); + if($redpackid){ + pdo_update('wlmerchant_redpack_records',array('status' => 1,'usetime' =>time(),'orderid' => $orderid,'plugin' => $plugin),array('id' => $redpackid)); + } + if ($data['price'] > 0) { + $unidata['status'] = 1; + $unidata['orderid'] = $orderid; + $this->renderSuccess('下单成功' , $unidata); + } + else { + //0元购 购买商品的同时开通会员卡是不允许进行0元购的 必须进入支付流程 + $newdata = [ + 'status' => 1 , + 'paytime' => time() , + 'paytype' => 6 , + ]; + pdo_update(PDO_NAME . 'order' , $newdata , ['orderno' => $data['orderno']]); //更新订单状态 + //处理营销 + if ($good['integral']) { + $remark = '团购:[' . $good['name'] . ']赠送积分'; + Member::credit_update_credit1($_W['mid'] , $good['integral'] * $num , $remark); + } + //处理组团或者单购 + $order = $data; + $order['id'] = $orderid; + if ($order['fightstatus'] == 1) { + if ($order['fightgroupid']) { + $group = pdo_get('wlmerchant_fightgroup_group' , ['id' => $order['fightgroupid']]); + $newdata = []; + if ($group['status'] == 1) { + $newlack = $group['lacknum'] - 1; + if ($newlack > 0) { + $newdata['lacknum'] = $newlack; + }else { + $newdata['lacknum'] = $newlack; + $newdata['status'] = 2; + $newdata['successtime'] = time(); + $orders = pdo_getall('wlmerchant_order' , [ + 'fightgroupid' => $group['id'] , + 'uniacid' => $group['uniacid'] , + 'aid' => $group['aid'] , + 'status' => 1 + ]); + //幸运团 + if($group['is_lucky'] > 0){ + $allorderids = array_column($orders,'id'); + $luckykey = array_rand($allorderids,$good['luckynum']); + if($good['luckynum']>1){ + foreach ($luckykey as $lid){ + $luckyids[] = $allorderids[$lid]; + } + }else{ + $luckyids[] = $allorderids[$luckykey]; + } + $newdata['luckyorderids'] = serialize($luckyids); + } + foreach ($orders as $key => $or) { + if(empty($luckyids) || in_array($or['id'],$luckyids)){ + if ($or['expressid']) { + $res = pdo_update(PDO_NAME . 'order' , ['status' => 8] , ['id' => $or['id']]); + $member = pdo_get('wlmerchant_member' , ['id' => $or['mid']] , ['openid']); + } + else { + if ($or['neworderflag']) { + Order::createSmallorder($or['id'] , 3); + //计算过期时间 + if ($good['cutoffstatus']) { + $estimatetime = time() + $good['cutoffday'] * 86400; + } + else { + $estimatetime = $good['cutofftime']; + } + $remindtime = Order::remindTime($estimatetime); + pdo_update(PDO_NAME . 'order' , [ + 'status' => 1 , + 'estimatetime' => $estimatetime, + 'remindtime' => $remindtime + ] , ['id' => $or['id']]); + } + else { + $recordid = Wlfightgroup::createRecord($or['id'] , $or['num']); + $res = pdo_update(PDO_NAME . 'order' , [ + 'status' => 1 , + 'recordid' => $recordid + ] , ['id' => $or['id']]); + } + $member = pdo_get('wlmerchant_member' , ['id' => $or['mid']] , ['openid']); + } + //处理分销 + if($or['cerditmoney'] > 0 && $_W['wlsetting']['creditset']['nodistribution'] > 0){ + $nodis = 1; + } + if (p('distribution') && empty($good['isdistri']) && empty($or['drawid']) && empty($or['luckydrawid']) && empty($nodis)) { + if ($or['specid']) { + $option = pdo_get('wlmerchant_goods_option', ['id' => $or['specid']]); + $good['disarray'] = WeliamWeChat::mergeDisArray($option['disarray'],$good['disarray']); + } + $disarray = unserialize($good['disarray']); + $dismoney = sprintf("%.2f", $or['goodsprice'] - $or['vipdiscount']); + $disorderid = Distribution::disCore($or['mid'], $dismoney, $disarray, $or['num'], 0, $or['id'], 'fightgroup', $good['dissettime'],$good['isdistristatus']); + $res = pdo_update(PDO_NAME . 'order' , [ + 'disorderid' => $disorderid, + ] , ['id' => $or['id']]); + } + //小票打印 + Order::sendPrinting($or['id'],'wlfightgroup'); + }else{ + Wlfightgroup::refund($or['id']); + //在线返红包 + if($good['luckymoney'] > 0){ + $orsource = pdo_getcolumn(PDO_NAME.'paylogvfour',array('tid'=>$or['orderno'],'mid'=>$or['mid']),'source'); + $nlUser = pdo_get('wlmerchant_member',array('id' => $or['mid']),array('openid','wechat_openid')); + if($_W['source'] == 1){ + $sopenid = $nlUser['openid']; + }else if($_W['source'] == 3){ + $sopenid = $nlUser['wechat_openid']; + } + if(empty($sopenid)){ + if(!empty($nlUser['openid'])){ + $sopenid = $nlUser['openid']; + $orsource = 1; + } + if(!empty($nlUser['wechat_openid'])){ + $sopenid = $nlUser['wechat_openid']; + $orsource = 3; + } + } + if(!empty($sopenid)){ + $params = [ + 'openid' => $sopenid , + 'money' => $good['luckymoney'] , + 'rem' => '幸运团返现' , + 'name' => 'weliam' , + 'order_no' => $or['orderno'], + 'source' => $orsource , + 'mid' => $or['mid'] + ]; + $res = Payment::presentationInit($params,2); + file_put_contents(PATH_DATA . "luckygroup.log", var_export($res, true) . PHP_EOL, FILE_APPEND); + } + } + } + } + } + pdo_update(PDO_NAME . 'fightgroup_group' , $newdata , ['id' => $order['fightgroupid']]); + News::groupresult($order['fightgroupid']); + } + else { + $newgroupflag = 1; + } + } + else { + $newgroupflag = 1; + } + if ($newgroupflag) { + $group = [ + 'status' => 1 , + 'goodsid' => $order['fkid'] , + 'aid' => $good['aid'] , + 'sid' => $good['merchantid'] , + 'neednum' => $good['peoplenum'] , + 'lacknum' => $good['peoplenum'] - 1 , + 'starttime' => time() , + 'failtime' => time() + $good['grouptime'] * 3600 , + 'is_lucky' => $good['is_lucky'] + ]; + $fightgroupid = Wlfightgroup::saveFightGroup($group); + pdo_update(PDO_NAME . 'order' , ['fightgroupid' => $fightgroupid] , ['id' => $order['id']]); + } + } + else { + if ($order['expressid']) { + pdo_update(PDO_NAME . 'order' , ['status' => 8] , ['id' => $order['id']]); + } + else { + if ($order['neworderflag']) { + Order::createSmallorder($order['id'] , 3); + //计算过期时间 + if ($good['cutoffstatus']) { + $estimatetime = time() + $good['cutoffday'] * 86400; + } + else { + $estimatetime = $good['cutofftime']; + } + $remindtime = Order::remindTime($estimatetime); + pdo_update(PDO_NAME . 'order' , [ + 'status' => 1 , + 'estimatetime' => $estimatetime, + 'remindtime' => $remindtime + ] , ['id' => $order['id']]); + } + else { + $recordid = Wlfightgroup::createRecord($order['id'] , $order['num']); + pdo_update(PDO_NAME . 'order' , [ + 'status' => 1 , + 'recordid' => $recordid + ] , ['id' => $order['id']]); + } + } + //抽奖领取 + if($data['drawid'] > 0){ + pdo_update('wlmerchant_draw_record',array('is_get' => 2),array('id' => $data['drawid'])); + } + if($data['luckydrawid'] > 0){ + pdo_update('wlmerchant_luckydraw_drawcode',array('is_get' => 1,'gettime' => time()),array('id' => $data['luckydrawid'])); + } + //处理分销 + if($dkmoney > 0 && $_W['wlsetting']['creditset']['nodistribution'] > 0){ + $nodis = 1; + } + if (p('distribution') && empty($good['isdistri']) && empty($data['drawid']) && empty($data['luckydrawid']) && empty($nodis)) { + if ($order['specid']) { + $good['disarray'] = WeliamWeChat::mergeDisArray($option['disarray'],$good['disarray']); + } + $disarray = unserialize($good['disarray']); + $dismoney = sprintf("%.2f", $order['goodsprice'] - $order['vipdiscount']); + $disorderid = Distribution::disCore($order['mid'], $dismoney, $disarray, $order['num'], 0, $order['id'], 'fightgroup', $good['dissettime'],$good['isdistristatus']); + $res = pdo_update(PDO_NAME . 'order' , [ + 'disorderid' => $disorderid, + ] , ['id' => $order['id']]); + } + //小票打印 + Order::sendPrinting($order['id'],'wlfightgroup'); + } + $data2['realsalenum'] = $good['realsalenum'] + $order['num']; + $res2 = Wlfightgroup::updateGoods($data2 , $order['fkid']); + //发送通知 + /***模板通知***/ + News::addSysNotice($order['uniacid'],2,$order['sid'],0,$order['id']); + Store::addFans($order['sid'], $order['mid']); + News::paySuccess($order['id'], 'wlfightgroup'); + + $unidata['status'] = 0; + $unidata['orderid'] = $orderid; + $unidata['tid'] = $data['orderno']; + $unidata['plugin'] = 'wlfightgroup'; + $this->renderSuccess('购买成功' , $unidata); + } + } + //砍价 + if ($plugin == 'bargain') { + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + $activity = Bargain::getSingleActive($id , '*'); + $userorder = pdo_get('wlmerchant_bargain_userlist' , ['id' => $optionid]); + if ($userorder['orderid']) { + MysqlFunction::rollback(); + $this->renderError('此砍价活动已经生成订单,无法重复生成'); + } + if ($activity['status'] != 2) { + MysqlFunction::rollback(); + $this->renderError('活动未开始或已结束,无法下单'); + } + //判断已有订单 + $nopayorder = pdo_getcolumn('wlmerchant_order' , [ + 'mid' => $_W['mid'] , + 'status' => 0 , + 'fkid' => $activity['id'] , + 'specid' => $optionid , + 'plugin' => 'bargain' + ] , 'id'); + if (!empty($nopayorder)) { + MysqlFunction::rollback(); + $this->renderError('请先支付或取消未支付的订单'); + } + //剩余数量 + $alreadynum = WeliamWeChat::getSalesNum(5,$id,0,1,0); + $levelnum = $activity['stock'] - intval($alreadynum); + if ($levelnum == 0 || $levelnum < 1) { + MysqlFunction::rollback(); + $this->renderError('该商品已被抢完,请下次手快些哦'); + } + //判断会员 + if ($activity['vipstatus'] == 1) { + if ($halfcardflag) { + $vipbuyflag = 1; + } + else { + $vipbuyflag = 0; + } + } + if ($usestatus) { + $express = $this->freight($addressid , $num , $activity); + $expressprice = $express['price']; + $expressid = $express['expressid']; + $neworderflag = 0; + } + else { + $username = trim($_GPC['thname']); + $mobile = trim($_GPC['thmobile']); + $neworderflag = 1; + $expressprice = 0; + } + //积分抵扣 + if ($creditstatus) { + if ($activity['creditmoney'] > sprintf("%.2f" , $userorder['price'])) { + $activity['creditmoney'] = sprintf("%.2f" , $userorder['price']); + } + $creditremark = '砍价[' . $activity['name'] . ']抵扣积分'; + $creditindo = self::creditDeduction($activity['creditmoney'] , $num , $creditremark); + $dkcredit = $creditindo['dkcredit']; + $dkmoney = $creditindo['dkmoney']; + } + else { + $dkcredit = 0; + $dkmoney = 0; + } + //满减活动 + if($activity['fullreduceid']>0){ + $fulldkmoney = Fullreduce::getFullreduceMoney($userorder['price'],$activity['fullreduceid']); + }else{ + $fulldkmoney = 0; + } + $price = $userorder['price']; + if($drawid > 0){ + $flag = pdo_getcolumn(PDO_NAME.'order',array('drawid'=>$drawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $price = 0; + } + + if($luckydrawid > 0){ + $flag = pdo_getcolumn(PDO_NAME.'order',array('luckydrawid'=>$luckydrawid),'id'); + if($flag > 0){ + $this->renderError('此奖品已被领取,无法重复领取'); + } + $price = 0; + } + $prices = sprintf("%.2f" , $price + $expressprice - $dkmoney - $redpackmoney - $fulldkmoney); + //结算金额 + $settlementmoney = Store::getsettlementmoney(5 , $optionid , $num , $activity['sid'] , $vipbuyflag,0,0,0,$uhlevel); + if ($expressprice) { + $settlementmoney = sprintf("%.2f" , $expressprice + $settlementmoney); + } + //创建订单 + $data = [ + 'uniacid' => $activity['uniacid'] , + 'mid' => $_W['mid'] , + 'sid' => $activity['sid'] , + 'aid' => $activity['aid'] , + 'fkid' => $activity['id'] , + 'plugin' => 'bargain' , + 'payfor' => 'bargainOrder' , + 'orderno' => createUniontid() , + 'status' => 0 ,//订单状态:0未支,1支付,2待发货,3已发货,4已签收,5已取消,6待退款,7已退款 + 'createtime' => TIMESTAMP , + 'price' => $prices > 0 ? $prices : 0, + 'num' => 1 , + 'vipbuyflag' => $vipbuyflag , + 'specid' => $optionid , + 'name' => $username , + 'mobile' => $mobile , + 'fightstatus' => $usestatus , + 'expressid' => $expressid , + 'buyremark' => $remark , + 'goodsprice' => $userorder['price'] , + 'settlementmoney' => $settlementmoney , + 'neworderflag' => $neworderflag , + 'usecredit' => $dkcredit , + 'cerditmoney' => $dkmoney , + 'canceltime' => time() + $settings['cancel'] * 60, + 'redpackid' => $redpackid, + 'redpackmoney' => $redpackmoney, + 'fullreduceid' => $activity['fullreduceid'], + 'fullreducemoney' => $fulldkmoney, + 'drawid' => $drawid, + 'luckydrawid' => $luckydrawid, + 'moinfo' => serialize($diyFormInfo) + ]; + $res = pdo_insert(PDO_NAME . 'order' , $data); + $errid = pdo_insertid(); + if($res){ + $orderid = pdo_getcolumn(PDO_NAME.'order',array('orderno'=>$data['orderno']),'id'); + } + if($orderid != $errid){ + file_put_contents(PATH_DATA . "barOrderError.log", var_export($orderid.'||'.$errid, true) . PHP_EOL, FILE_APPEND); + } + if($redpackid){ + pdo_update('wlmerchant_redpack_records',array('status' => 1,'usetime' =>time(),'orderid' => $orderid,'plugin' => $plugin),array('id' => $redpackid)); + } + if ($orderid) { + pdo_update('wlmerchant_bargain_userlist' , ['orderid' => $orderid] , ['id' => $optionid]); + MysqlFunction::commit(); + if ($data['price'] > 0) { + $unidata['status'] = 1; + $unidata['orderid'] = $orderid; + $this->renderSuccess('购买成功' , $unidata); + } + else { + //0元购 购买商品的同时开通会员卡是不允许进行0元购的 必须进入支付流程 + $newdata = [ + 'status' => 1 , + 'paytime' => time() , + 'paytype' => 6 , + ]; + + if ($expressid) { + $newdata['status'] = 8; + Bargain::createRecord($orderid , 1 , $optionid , 1); + } + else { + Order::createSmallorder($orderid , 5); + if ($activity['cutoffstatus']) { + $newdata['estimatetime'] = time() + $activity['cutoffday'] * 86400; + } + else { + $newdata['estimatetime'] = $activity['cutofftime']; + } + $newdata['remindtime'] = Order::remindTime($newdata['estimatetime']); + pdo_update(PDO_NAME . 'bargain_userlist' , ['status' => 2] , ['id' => $optionid]); + } + + if($dkmoney > 0 && $_W['wlsetting']['creditset']['nodistribution'] > 0){ + $nodis = 1; + } + if (p('distribution') && empty($activity['isdistri']) && empty($nodis)) { + $disarray = unserialize($activity['disarray']); + $disorderid = Distribution::disCore($data['mid'], $data['goodsprice'], $disarray, 1, 0, $orderid, 'bargain', $activity['dissettime'],$activity['isdistristatus']); + $newdata['disorderid'] = $disorderid; + } + + pdo_update(PDO_NAME . 'order' , $newdata , ['orderno' => $data['orderno']]); //更新订单状态 + //抽奖领取 + if($data['drawid'] > 0){ + pdo_update('wlmerchant_draw_record',array('is_get' => 2),array('id' => $data['drawid'])); + } + if($data['drawid'] > 0){ + pdo_update('wlmerchant_luckydraw_drawcode',array('is_get' => 1,'gettime' => time()),array('id' => $data['drawid'])); + } + //处理营销 + if ($activity['integral']) { + $remark = '砍价:[' . $activity['name'] . ']赠送积分'; + Member::credit_update_credit1($_W['mid'] , $activity['integral'] , $remark); + } + /***模板通知***/ + News::addSysNotice($data['uniacid'],2,$data['sid'],0,$orderid); + Store::addFans($data['sid'], $data['mid']); + News::paySuccess($orderid,'bargain'); + //小票打印 + Order::sendPrinting($orderid,'bargain'); + + $unidata['status'] = 0; + $unidata['orderid'] = $orderid; + $unidata['tid'] = $data['orderno']; + $unidata['plugin'] = 'bargain'; + $this->renderSuccess('购买成功' , $unidata); + } + } + MysqlFunction::rollback(); + } + //积分兑换 + if ($plugin == 'consumption') { + $goods = Consumption::creditshop_goods_get($id); + $level = unserialize($goods['level']); + if($goods['usedatestatus'] > 0){ + $check = WeliamWeChat::checkUseDateStatus($goods['usedatestatus'],$goods['week'],$goods['day']); + if(empty($check)){ + $this->renderError('今日商品无法兑换'); + } + } + if ($goods['type'] == 'halfcard' && $halfcardflag) { + $this->renderError('您现在已是会员,无法再次兑换会员资格'); + } + if ((!empty($cardId) || $halfcardflag) && $goods['vipstatus'] == 1) { + //判断会员特价 + $goods['use_credit1'] = $goods['vipcredit1']; + $goods['use_credit2'] = $goods['vipcredit2']; + } + else if ($goods['vipstatus'] == 2) { + //判断会员特供 + if (empty($halfcardflag) && empty($cardId)) { + MysqlFunction::rollback(); + $this->renderError('该商品会员特供,请先成为会员'); + }else if ($level) { + //判断等级 + $flag = Halfcard::checklevel($_W['mid'] , $level); + if (empty($flag)) { + MysqlFunction::rollback(); + $this->renderError('您所在的会员等级无权购买该商品'); + } + } + + } + //判断数量 + if ($goods['chance'] > 0) { + $times = pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('wlmerchant_consumption_record') . " WHERE uniacid = {$_W['uniacid']} AND goodsid = {$id} AND mid = {$_W['mid']} "); + if ($times == $goods['chance'] || $times > $goods['chance']) { + $this->renderError('该商品最多兑换' . $goods['chance'] . '次'); + } + } + //判断库存 + #6、获取销量 + $total = pdo_fetchcolumn("SELECT SUM(num) FROM " . tablename(PDO_NAME . "order") . " WHERE plugin = 'consumption' AND fkid = {$id} AND status != 5 AND status != 7"); + if($total >= $goods['stock']) $this->renderError('该商品已售罄!'); + //判断积分 + if ($_W['wlmember']['credit1'] < $goods['use_credit1'] * $num) { + $jftext = $_W['wlsetting']['trade']['credittext']?$_W['wlsetting']['trade']['credittext']:'积分'; + $this->renderError($jftext.'不足,无法兑换'); + } + if ($goods['type'] == 'goods') { + $express = $this->freight($addressid , $num , $goods); + $expressprice = $express['price']; + $expressid = $express['expressid']; + } + if (!empty($cardId)) { + $cardprice = pdo_getcolumn(PDO_NAME . 'halfcard_type' , ['id' => $cardId] , 'price'); + } + else { + $cardprice = 0; + } + $prices = sprintf("%.2f" , $goods['use_credit2'] * $num + $expressprice + $cardprice - $redpackmoney); + //支付商品 + //创建订单 + $data = [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $_W['mid'] , + 'sid' => 0 , + 'aid' => $_W['aid'] , + 'fkid' => $goods['id'] , + 'plugin' => 'consumption' , + 'payfor' => 'consumOrder' , + 'orderno' => createUniontid() , + 'status' => 0 ,//订单状态:0未支,1支付,2待发货,3已发货,4已签收,5已取消,6待退款,7已退款 + 'createtime' => TIMESTAMP , + 'price' => $prices > 0 ? $prices : 0, + 'num' => 1 , + 'expressid' => $expressid , + 'buyremark' => $remark , + 'goodsprice' => $goods['old_price'] , + 'settlementmoney' => 0 , + 'settlementmoney' => 0 , + 'vip_card_id' => $cardId ,//会员卡的id + 'name' => $_GPC['thname'] , + 'usecredit' => sprintf("%.2f",$goods['use_credit1'] * $num ), + 'canceltime' => time() + $settings['cancel'] * 60, + 'redpackid' => $redpackid, + 'redpackmoney' => $redpackmoney + ]; + pdo_insert(PDO_NAME . 'order' , $data); + $orderid = pdo_insertid(); + if($redpackid){ + pdo_update('wlmerchant_redpack_records',array('status' => 1,'usetime' =>time(),'orderid' => $orderid,'plugin' => $plugin),array('id' => $redpackid)); + } + if ($expressid) { + pdo_update('wlmerchant_express' , ['orderid' => $orderid] , ['id' => $expressid]); + } + $res = Member::credit_update_credit1($_W['mid'] , -$data['usecredit'] , '兑换[' . $goods['title'] . ']消耗'); + //不支付的商品 存在开卡存在时不能进行0元购 + if ($goods['use_credit2'] < 0.01 && empty($cardId) && $expressprice < 0.01) { + $trade = Setting::wlsetting_read('trade'); + if ($res) { + if ($goods['type'] == 'credit2') { + $res2 = Member::credit_update_credit2($_W['mid'] , $goods['credit2'] , '兑换[' . $goods['title'] . ']获得' . $trade['moneytext']); + } + else if ($goods['type'] == 'halfcard') { + $res2 = Consumption::conhalfcard($_W['mid'] , $goods['halfcardid'] , $_GPC['thname']); + } + else { + $res2 = 1; + } + if ($res2) { + $recordstatus = $goods['type'] == 'goods' ? 1 : 3; + $data2 = [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $_W['mid'] , + 'goodsid' => $id , + 'status' => $recordstatus , + 'createtime' => time() , + 'integral' => $data['usecredit'], + 'expressid' => $expressid , + 'orderid' => $orderid, + 'num' => $num + ]; + if ($expressid) { + $data2['status'] = 1; + } + $res3 = pdo_insert(PDO_NAME . 'consumption_record' , $data2); + if ($res3) { + $changestatus = $goods['type'] == 'goods' ? 8 : 3; + pdo_update('wlmerchant_order' , [ + 'status' => $changestatus , + 'paytype' => 6 , + 'paytime' => time(), + 'issettlement' => 1 + ] , ['id' => $orderid]); + /***模板通知***/ + $url = h5_url('pages/subPages/coupon/coupon'); + $modelData = [ + 'first' => '恭喜您,一个商品兑换成功' , + 'type' => '积分商品兑换' ,//业务类型 + 'content' => $goods['title'] ,//业务内容 + 'status' => '兑换成功' ,//处理结果 + 'time' => date("Y-m-d H:i:s" , $data['createtime']) ,//操作时间 + 'remark' => '点击查看兑换记录,如有问题请联系管理员' + ]; + TempModel::sendInit('service' , $_W['mid'] , $modelData , $_W['source'] , $url); + /***模板通知***/ + $unidata['status'] = 0; + $unidata['orderid'] = $orderid; + $unidata['tid'] = $data['orderno']; + $unidata['plugin'] = 'consumption'; + $this->renderSuccess('购买成功' , $unidata); + } + } + } + } + else { + if ($orderid) { + $unidata['status'] = 1; + $unidata['orderid'] = $orderid; + $this->renderSuccess('购买成功' , $unidata); + } + } + } + //活动报名 + if ($plugin == 'activity'){ + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + $activity = pdo_get('wlmerchant_activitylist',array('id' => $id)); + //判断活动状态 + if ($activity['status'] != 2) { + if ($activity['status'] == 1) { + MysqlFunction::rollback(); + $this->renderError('活动报名尚未开始'); + } + else if ($activity['status'] == 3) { + MysqlFunction::rollback(); + $this->renderError('活动报名已结束'); + } else{ + MysqlFunction::rollback(); + $this->renderError('活动已关闭'); + } + } + //判断规格 + if ($activity['optionstatus']>0) { + if ($optionid) { + $option = pdo_get('wlmerchant_activity_spec' , ['id' => $optionid] , ['viparray','disarray','name','price','maxnum']); + $activity['price'] = $option['price']; + $total = $option['maxnum']; + $activity['viparray'] = WeliamWeChat::mergeVipArray($option['viparray'],$activity['viparray']); + }else { + MysqlFunction::rollback(); + $this->renderError('规格参数错误,请重新选择'); + } + } + else { + $optionid = 0; + $total = $activity['maxpeoplenum']; + } + //判断剩余数量 + if($total > 0){ + $salesVolume = WeliamWeChat::getSalesNum(6,$id,$optionid,1); + $levelnum = $total - intval($salesVolume); + if($levelnum < $num){ + MysqlFunction::rollback(); + $this->renderError('报名名额已满'); + } + } + if($activity['onelimit']>0){ + $salesVolume = WeliamWeChat::getSalesNum(6,$id,0,1,$_W['mid']); + $levelnum = $activity['onelimit'] - intval($salesVolume); + if($levelnum < $num){ + MysqlFunction::rollback(); + if($levelnum>0){ + $this->renderError('您还能报名'.$levelnum.'人次'); + }else{ + $this->renderError('您已经报名过了'); + } + } + } + /*判断会员*/ + $price = $activity['price']; + if ($activity['vipstatus'] == 1) { + if ($halfcardflag || !empty($cardId)) { + $vipdiscount = WeliamWeChat::getVipDiscount($activity['viparray'],$uhlevel); + if($vipdiscount > 0){ + $vipbuyflag = 1; + } + } + }else if ($activity['vipstatus'] == 2) { + if (empty($halfcardflag) && empty($cardId)) { + MysqlFunction::rollback(); + $this->renderError('该商品会员特供,请先成为会员'); + } + } + + if (empty($vipbuyflag)) { + $vipbuyflag = 0; + } + //创建订单 + $prices = sprintf("%.2f" , $price * $num); + $goodsprice = sprintf("%.2f" , $activity['price'] * $num); + if (!empty($cardId)) { + $cardprice = pdo_getcolumn(PDO_NAME . 'halfcard_type' , ['id' => $cardId] , 'price'); + } + else { + $cardprice = 0; + } + if($vipdiscount > 0){ + $vipdiscount = $vipdiscount * $num; + }else{ + $vipdiscount = 0; + } + $prices = sprintf("%.2f" , $prices + $cardprice - $vipdiscount - $redpackmoney); + //结算金额 + $useprices = sprintf("%.2f" , $prices / $num); + $settlementmoney = Store::getsettlementmoney(6,$id,$num,$activity['sid'],$vipbuyflag ,$optionid,0,$useprices,$uhlevel); + if($settlementmoney < 0.01){ + $settlementmoney = Store::getsettlementmoney(6,$id,$num,$activity['sid'],$vipbuyflag ,$optionid,0,$useprices,$uhlevel); + } + $data = [ + 'uniacid' => $activity['uniacid'] , + 'mid' => $_W['mid'] , + 'sid' => $activity['sid'] , + 'aid' => $activity['aid'] , + 'fkid' => $activity['id'] , + 'plugin' => 'activity' , + 'payfor' => 'Activitysharge' , + 'orderno' => createUniontid() , + 'status' => 0 ,//订单状态:0未支,1支付,2待发货,3已发货,4已签收,5已取消,6待退款,7已退款 + 'createtime' => TIMESTAMP , + 'price' => $prices > 0 ? $prices : 0, + 'num' => $num , + 'vipbuyflag' => $vipbuyflag , + 'specid' => $optionid , + 'name' => $username , + 'mobile' => $mobile , + 'goodsprice' => $goodsprice , + 'buyremark' => $remark , + 'settlementmoney' => $settlementmoney , + 'vip_card_id' => $cardId ,//会员卡的id + 'canceltime' => time() + $settings['cancel'] * 60, + 'redpackid' => $redpackid, + 'redpackmoney' => $redpackmoney, + 'neworderflag' => 1, + 'vipdiscount' => $vipdiscount, + 'moinfo' => serialize($diyFormInfo) + ]; + pdo_insert(PDO_NAME . 'order' , $data); + $orderid = pdo_insertid(); + if (empty($orderid)) { + MysqlFunction::rollback(); + $this->renderError('创建订单失败,请刷新重试'); + } + MysqlFunction::commit(); + if ($data['price'] > 0) { + $unidata['status'] = 1; + $unidata['orderid'] = $orderid; + $this->renderSuccess('购买成功' , $unidata); + }else{ + //0元购 购买商品的同时开通会员卡是不允许进行0元购的 必须进入支付流程 + $newdata = [ + 'status' => 1 , + 'paytime' => time() , + 'paytype' => 6 , + ]; + Order::createSmallorder($orderid , 6); + //计算过期时间 + $newdata['estimatetime'] = $activity['activeendtime']; + $newdata['remindtime'] = Order::remindTime($newdata['activestarttime']); + //处理分销 + if($dkmoney>0 && $_W['wlsetting']['creditset']['nodistribution'] > 0){ + $nodis = 1; + } + if (p('distribution') && empty($activity['isdistri']) && empty($data['drawid']) && empty($data['luckydrawid']) && empty($nodis)) { + if ($data['specid']) { + $activity['disarray'] = WeliamWeChat::mergeDisArray($option['disarray'],$activity['disarray']); + } + $disarray = unserialize($activity['disarray']); + $dismoney = sprintf("%.2f",$data['goodsprice'] - $data['vipdiscount']); + $disorderid = Distribution::disCore($data['mid'],$dismoney,$disarray, $data['num'], 0, $orderid, 'activity', $activity['dissettime'],$activity['isdistristatus']); + $newdata['disorderid'] = $disorderid; + } + pdo_update(PDO_NAME . 'order' , $newdata , ['orderno' => $data['orderno']]); //更新订单状态 + /***模板通知***/ + Store::addFans($activity['sid'] , $_W['mid']); + News::addSysNotice($data['uniacid'],2,$data['sid'],0,$orderid); + News::paySuccess($orderid, 'activity'); + //小票打印 + //Order::sendPrinting($orderid,'activity'); + + $unidata['status'] = 0; + $unidata['orderid'] = $orderid; + $unidata['tid'] = $data['orderno']; + $unidata['plugin'] = 'activity'; + $this->renderSuccess('购买成功' , $unidata); + } + + + } + + } + /** + * Comment: 计算运费 + * Author: wlf + * Date: 2019/8/19 09:15 + */ + public function freight($addressid , $num , $good,$expressprice = 0) + { + global $_W; + //设置默认 + pdo_update('wlmerchant_address' , ['status' => 0] , ['mid' => $_W['mid'] , 'uniacid' => $_W['uniacid']]); + pdo_update('wlmerchant_address' , ['status' => 1] , ['id' => $addressid]); + $address = pdo_get('wlmerchant_address' , ['id' => $addressid]); + $data['uniacid'] = $_W['uniacid']; + $data['mid'] = $_W['mid']; + $data['goodsid'] = $good['id']; + $data['merchantid'] = $good['merchantid']; + $data['address'] = $addre = $address['province'] . $address['city'] . $address['county'] . $address['detailed_address']; + $data['name'] = $username = $address['name']; + $data['tel'] = $mobile = $address['tel']; + if ($good['expressid']>0) { + $express = pdo_get('wlmerchant_express_template' , ['id' => $good['expressid']]); + //添加设置错误项校验 + if(empty($express['defaultnum'])){ + $express['defaultnum'] = 99999; + } + if(empty($express['defaultnumex'])){ + $express['defaultnumex'] = 1; + } + if(!empty($express)){ + $areaflag = 0; + if (mb_substr($address['province'] , -1 , 1 , 'utf-8') == '省') { + $address['province'] = mb_substr($address['province'] , 0 , mb_strlen($address['province']) - 1 , 'utf-8'); + } + if ($express['expressarray']) { + $expressarray = unserialize($express['expressarray']); + foreach ($expressarray as $key => &$v) { + $v['area'] = rtrim($v['area'] , ","); + $v['area'] = explode(',' , $v['area']); + if (in_array($address['province'] , $v['area'])) { + if($num >= $v['freenumber'] && $v['freenumber'] > 0){ + $expressprice = 0; //包邮 + }else if ($num > $v['num']) { + $expressprice = $v['money'] + ceil(($num - $v['num']) / $v['numex']) * $v['moneyex']; + } + else { + $expressprice = $v['money']; + } + $areaflag = 1; + } + } + } + if (empty($areaflag)) { + if($num >= $express['freenumber'] && $express['freenumber'] > 0){ + $expressprice = 0; //包邮 + }else if ($num > $express['defaultnum']) { + $expressprice = $express['defaultmoney'] + ceil(($num - $express['defaultnum']) / $express['defaultnumex']) * $express['defaultmoneyex']; + } + else { + $expressprice = $express['defaultmoney']; + } + } + } + $expressprice = $expressprice < 0 ? 0 : $expressprice; + } + $data['expressprice'] = $expressprice; + pdo_insert(PDO_NAME . 'express' , $data); + $expressid = pdo_insertid(); + $express = [ + 'price' => $expressprice , + 'expressid' => $expressid + ]; + return $express; + } + /** + * Comment: 订单详情页面 + * Author: wlf + * Date: 2019/8/19 10:35 + */ + public function orderDetail() + { + global $_W , $_GPC; + $id = $_GPC['orderid']; + $plugin = $_GPC['plugin']; + $lat = $_GPC['lat']; + $lng = $_GPC['lng']; + $data = []; + $data['id'] = $id; + if ($plugin == 'rush') { + $order = pdo_get('wlmerchant_rush_order' , ['id' => $id]); + if($order['blendcredit'] > 0){ + $order['paytype'] = 7; + $data['blendcredit'] = $order['blendcredit']; + $data['blendwx'] = sprintf("%.2f",$order['actualprice'] - $order['blendcredit']); + } + $goods = pdo_get('wlmerchant_rush_activity' , ['id' => $order['activityid']]); + $data['goodName'] = $goods['name']; + $data['goodLogo'] = tomedia($goods['thumb']); + $data['unitPrice'] = sprintf("%.2f" , $order['price'] / $order['num']); + if ($order['optionid']) { + $option = pdo_get('wlmerchant_goods_option' , ['id' => $order['optionid']] , [ + 'title' , + 'price' , + 'vipprice' + ]); + $data['optionName'] = $option['title']; + } + if ($order['vipbuyflag']) { + if ($order['discount'] > 0) { + //会员优惠存在 并且不是多规格商品 + $data['vipdiscount'] = $order['discount']; + }else { + //没有储存会员优惠 按照以前的规则进行查询 + if ($order['optionid']) { + $data['vipdiscount'] = sprintf("%.2f" , $option['price'] - $option['vipprice']); + } + else { + $data['vipdiscount'] = sprintf("%.2f" , $goods['price'] - $goods['vipprice']); + } + } + } + else { + $data['vipdiscount'] = 0; + } + $data['thname'] = $order['username'] ? $order['username'] : $_W['wlmember']['nickname']; + $data['thmobile'] = $order['mobile'] ? $order['mobile'] : $_W['wlmember']['mobile']; + $data['goodsprice'] = $order['price']; + $data['actualprice'] = $order['actualprice']; + $data['usecredit'] = $order['dkcredit']; + $data['creditmoney'] = $order['dkmoney']; + $data['a'] = 'b'; + $data['goodsid'] = $order['activityid']; + $data['pluginno'] = 1; + } + else { + $order = pdo_get('wlmerchant_order' , ['id' => $id]); + if($order['blendcredit'] > 0){ + $order['paytype'] = 7; + $data['blendcredit'] = $order['blendcredit']; + $data['blendwx'] = sprintf("%.2f",$order['price'] - $order['blendcredit']); + } + if ($plugin == 'groupon') { + $goods = pdo_get('wlmerchant_groupon_activity' , ['id' => $order['fkid']]); + $data['goodName'] = $goods['name']; + $data['goodLogo'] = tomedia($goods['thumb']); + if ($order['specid']) { + $option = pdo_get('wlmerchant_goods_option' , ['id' => $order['specid']] , [ + 'title' , + 'price' , + 'vipprice' + ]); + $data['optionName'] = $option['title']; + } + if ($order['vipbuyflag']) { + if($order['vipdiscount']>0){ + $data['vipdiscount'] = $order['vipdiscount']; + }else{ + if ($order['specid']) { + $data['vipdiscount'] = sprintf("%.2f" , $option['price'] - $option['vipprice']); + }else { + $data['vipdiscount'] = sprintf("%.2f" , $goods['price'] - $goods['vipprice']); + } + } + + } + else { + $data['vipdiscount'] = 0; + } + $data['goodsid'] = $order['fkid']; + $data['pluginno'] = 2; + } + else if ($plugin == 'wlfightgroup') { + $goods = pdo_get('wlmerchant_fightgroup_goods' , ['id' => $order['fkid']]); + $data['goodName'] = $goods['name']; + $data['goodLogo'] = tomedia($goods['logo']); + if ($order['specid']) { + $data['optionName'] = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $order['specid']] , 'title'); + } + if ($order['vipbuyflag']) { + $data['vipdiscount'] = $goods['vipdiscount']; + } + $order['goodsprice'] = $order['goodsprice'] - $data['vipdiscount']; + $data['goodsid'] = $order['fkid']; + $data['pluginno'] = 3; + if ($order['fightstatus'] == 1) { + $group = pdo_get('wlmerchant_fightgroup_group' , ['id' => $order['fightgroupid']] , ['status']); + } + $data['fightstatus'] = $order['fightstatus']; + $data['groupstatus'] = $group['status']; + $data['fightgroupid'] = $order['fightgroupid']; + } + else if ($plugin == 'bargain') { + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $order['fkid']]); + $data['goodName'] = $goods['name']; + $data['goodLogo'] = tomedia($goods['thumb']); + $data['goodsid'] = $order['fkid']; + $data['pluginno'] = 7; + } + else if ($plugin == 'consumption') { + $goods = pdo_get('wlmerchant_consumption_goods' , ['id' => $order['fkid']]); + $data['goodName'] = $goods['title']; + $data['goodLogo'] = tomedia($goods['thumb']); + $data['goodsid'] = $order['fkid']; + $data['pluginno'] = 'integral';//8 + } + else if ($plugin == 'coupon') { + $goods = pdo_get('wlmerchant_couponlist' , ['id' => $order['fkid']]); + if ($order['vipbuyflag']) { + $data['vipdiscount'] = sprintf("%.2f" , $goods['price'] - $goods['vipprice']); + $order['goodsprice'] = sprintf("%.2f" , ($order['goodsprice'] + ($data['vipdiscount'] * $order['num']))); + } + else { + $data['vipdiscount'] = 0; + } + $data['goodName'] = $goods['title']; + $data['goodLogo'] = tomedia($goods['logo']); + $data['optionName'] = $goods['sub_title']; + $data['goodsid'] = $order['fkid']; + $data['pluginno'] = 5; + }else if($plugin == 'yellowpage'){ + $yellow = pdo_get('wlmerchant_yellowpage_lists' , ['id' => $order['fkid']]); + switch ($order['fightstatus']) { + case '1': + $data['goodName'] = '页面['.$yellow['name'].']认领'; + break; + case '2': + $data['goodName'] = '页面['.$yellow['name'].']查阅'; + break; + case '3': + $data['goodName'] = '页面['.$yellow['name'].']入驻'; + break; + case '4': + $data['goodName'] = '页面['.$yellow['name'].']续费'; + break; + } + $data['goodLogo'] = tomedia($yellow['logo']); + $data['goodsurl'] = h5_url('pages/subPages2/phoneBook/logistics/logistics',array('id'=>$order['fkid'])); + }else if($plugin == 'activity'){ + $goods = pdo_get('wlmerchant_activitylist' , ['id' => $order['fkid']]); + $data['goodName'] = $goods['title']; + $data['goodLogo'] = tomedia($goods['thumb']); + if ($order['specid']) { + $option = pdo_get('wlmerchant_activity_spec' , ['id' => $order['specid']] , ['name','price']); + $data['optionName'] = $option['name']; + } + if ($order['vipbuyflag']) { + $data['vipdiscount'] = sprintf("%.2f",$goods['vipprice']); + } + else { + $data['vipdiscount'] = 0; + } + $data['goodsid'] = $order['fkid']; + $data['pluginno'] = 'activity'; + $data['addresstype'] = $goods['addresstype']; + if($data['addresstype'] > 0){ + $data['activityAddress'] = $goods['address']; + $data['activityLng'] = $goods['lng']; + $data['activityLat'] = $goods['lat']; + } + } + $data['unitPrice'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + $data['thname'] = $order['name'] ? $order['name'] : $_W['wlmember']['nickname']; + $data['thmobile'] = $order['mobile'] ? $order['mobile'] : $_W['wlmember']['mobile']; + $data['goodsprice'] = $order['goodsprice']; + $data['usecredit'] = $order['usecredit']; + $data['creditmoney'] = $order['cerditmoney']; + if ($data['vipdiscount'] > 0) { + $data['vipdiscount'] = sprintf("%.2f" , $data['vipdiscount'] * $order['num']); + } + $data['actualprice'] = $order['price']; + $data['a'] = 'a'; + } + if($order['redpackid']){ + $data['redpackcount'] = $order['redpackmoney']; + } + //判断用户 + if ($_W['mid'] != $order['mid']) { + $this->renderError('当前mid['.$_W['mid'].']订单mid['.$order['mid'].'],用户错误,无法访问'); + } + //同时开通会员卡 + if ($order['vip_card_id'] > 0) { + $data['cardprice'] = pdo_getcolumn(PDO_NAME . 'halfcard_type' , ['id' => $order['vip_card_id']] , 'price'); + } + //基础信息 + $data['sid'] = $order['sid']; + $data['num'] = $order['num']; + $data['orderno'] = $order['orderno']; + $data['status'] = $order['status']; + $data['createtime'] = date('Y-m-d H:i:s' , $order['createtime']); + if ($data['status'] != 0 && $data['status'] != 5) { + $paytype = [1 => '余额支付' , 2 => '微信支付' , 3 => '支付宝支付' , 4 => '货到付款' , 5 => '小程序支付' , 6 => '0元购',7 => '混合支付']; + $data['paytype'] = $paytype[$order['paytype']]; + $data['paytime'] = date('Y-m-d H:i:s' , $order['paytime']); + } + //是否可退款 + if (empty($goods['allowapplyre']) && ($order['status'] == 1 || $order['status'] == 8 || $order['status'] == 9) && $plugin != 'consumption') { + if ($order['status'] == 8) { + $canre = pdo_getcolumn(PDO_NAME . 'aftersale' , [ + 'orderid' => $id , + 'plugin' => $plugin , + 'status' => [1 , 2] + ] , 'id'); + if ($canre) { + $data['surerefund'] = 0; + $data['status'] = 10; + } + else { + $data['surerefund'] = 1; + } + } + else { + $data['surerefund'] = 1; + } + } + else { + $data['surerefund'] = 0; + } + if ($order['status'] == 1) { //待使用 + $smallorder = pdo_getall('wlmerchant_smallorder' , ['orderid' => $id , 'plugin' => $plugin] , [ + 'checkcode' , + 'status', + 'appointstatus' + ]); + if(empty($smallorder) && $plugin == 'rush' && empty($goods['pftid'])){ + Order::createSmallorder($id,1); + } + $data['checkcodes'] = $smallorder; //核销码 + if($goods['appointstatus'] > 0){ + $data['codeNum'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_smallorder') . " WHERE plugin = '{$plugin}' AND orderid = {$id} AND status = 1 AND appointstatus = 3"); //剩余数量 + }else{ + $data['codeNum'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_smallorder') . " WHERE plugin = '{$plugin}' AND orderid = {$id} AND status = 1"); //剩余数量 + } + $data['estimatetime'] = date('Y-m-d H:i' , $order['estimatetime']); + $canuse = pdo_getcolumn(PDO_NAME . 'smallorder' , [ + 'orderid' => $id , + 'plugin' => $plugin , + 'status' => 1 + ] , 'id'); + if (empty($canuse) && empty($goods['pftid'])) { + $data['status'] = 10; + } + } + else if ($order['status'] == 0) { //待付款 + $data['sytime'] = $order['canceltime']; + if (empty($data['sytime'])) { + $data['sytime'] = time() - 1; + } + //云收单校验 + if(Customized::init('yunmis160') > 0){ + $paylog = pdo_get('wlmerchant_paylogvfour' , ['tid' => $order['orderno']] , ['batchNo','traceNo']); + if(!empty($paylog['batchNo']) && !empty($paylog['traceNo'])){ + $set = Setting::wlsetting_read("payment_set"); + $payid = $set['wechat']['wechat']; + $paySetInfo = json_decode(pdo_getcolumn(PDO_NAME."payment",['id'=>$id],'param'),true); + $geturl = 'https://epos.ahrcu.com:3443/cposp/pay/nativeOrderQuery'; + $wechatData = [ + 'merchantNo' => $paySetInfo['yun_merchantNo'], + 'terminalNo' => $paySetInfo['yun_terminalNo'], + 'batchNo' => $paylog['batchNo'], + 'traceNo' => $paylog['traceNo'], + 'nonceStr' => random(16) + ]; + #3、处理支付方式 + $wechatData['sign'] = Payment::getYunSign($wechatData,$paySetInfo['yun_KEY']); + $wechatData = json_encode($wechatData); + $queryInfo = curlPostRequest($geturl,$wechatData,["Content-type: application/json;charset='utf-8'"]); + if($queryInfo['resultCode'] != '00'){ + Util::wl_log('160PayApi.log',PATH_DATA,$queryInfo); //写入异步日志记录 + }else{ + if($queryInfo['orderStatus'] == 3){ + $successInfo = [ + 'type' => 2 ,//支付方式 + 'tid' => $order['orderno'],//订单号 + 'transaction_id' => $queryInfo['chnOrderId'] , + 'time' => $queryInfo['transTime'], + ]; + PayResult::main($successInfo);//调用方法处理订单 + } + } + } + } + } + else if ($order['status'] == 7) { + $data['refundtime'] = date('Y-m-d H:i' , $order['refundtime']); + } + //使用方式 + //卡密商品 + if( $goods['usestatus'] == 3){ + $data['usestatus'] = 3; + if(empty($smallorder)){ + $smallorder = pdo_getall('wlmerchant_smallorder' , ['orderid' => $id , 'plugin' => $plugin] , [ + 'checkcode' , + 'status', + 'appointstatus' + ]); + $data['checkcodes'] = $smallorder; //核销码 + } + $merchant = pdo_get('wlmerchant_merchantdata' , ['id' => $order['sid']] , [ + 'mobile' , + 'storename' , + 'address' , + 'location' , + 'verkey' + ]); + $data['storename'] = $merchant['storename']; + $data['mobile'] = $merchant['mobile']; + $data['address'] = $merchant['address']; + $location = unserialize($merchant['location']); + $data['location'] = $location; + //计算距离 + if (!empty($lat) && !empty($lng)) { + $data['distance'] = Store::getdistance($location['lng'] , $location['lat'] , $lng , $lat); + if ($data['distance'] > 1000) { + $data['distance'] = (floor(($data['distance'] / 1000) * 10) / 10) . "km"; + } + else { + $data['distance'] = round($data['distance']) . "m"; + } + } + }else if (empty($order['expressid'])) { + $data['usestatus'] = 1; //使用方式 核销 + $merchant = pdo_get('wlmerchant_merchantdata' , ['id' => $order['sid']] , [ + 'mobile' , + 'storename' , + 'address' , + 'location' , + 'verkey' + ]); + $data['storename'] = $merchant['storename']; + $data['mobile'] = $merchant['mobile']; + $data['address'] = $merchant['address']; + $location = unserialize($merchant['location']); + $data['location'] = $location; + //计算距离 + if (!empty($lat) && !empty($lng)) { + $data['distance'] = Store::getdistance($location['lng'] , $location['lat'] , $lng , $lat); + if ($data['distance'] > 1000) { + $data['distance'] = (floor(($data['distance'] / 1000) * 10) / 10) . "km"; + } + else { + $data['distance'] = round($data['distance']) . "m"; + } + } + //密码核销 + if (!empty($merchant['verkey'])) { + $data['verkeystatus'] = 1; + } + else { + $data['verkeystatus'] = 0; + } + //扫码核销 + if ($_W['source'] == 3) { + $showurl = 'pages/mainPages/orderWrite/orderWrite?id=' . $id . '&plugin=' . $plugin; + $logo = tomedia(pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $order['sid']] , 'logo')); + $data['qrcode'] = tomedia(Store::getShopWxAppQrCode(0 , $logo , $showurl , true)); + } + else { + $data['qrcode'] = WeliamWeChat::getQrCode(h5_url('pages/mainPages/orderWrite/orderWrite' , [ + 'id' => $id , + 'plugin' => $plugin + ])); + } + //预约 + if($goods['appointstatus'] > 0){ + $data['appointstatus'] = 1; + $data['appointNum'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_smallorder') . " WHERE plugin = '{$plugin}' AND orderid = {$id} AND status = 1 AND appointstatus = 1"); + $data['alAppointFlag'] = pdo_getcolumn(PDO_NAME.'appointlist',array('orderid'=>$id,'type'=>$data['pluginno']),'id'); + } + } + else { + $data['usestatus'] = 2; //使用方式 快递 + $express = pdo_get('wlmerchant_express' , ['id' => $order['expressid']] , [ + 'name' , + 'tel' , + 'address' , + 'expressprice' , + 'expressname' , + 'expresssn' + ]); + $data['expName'] = $express['name']; + $data['expTel'] = $express['tel']; + $data['expAddress'] = $express['address']; + //快递 + $data['expressname'] = Logistics::codeComparisonTable($express['expressname'] , 'alias')['name']; + $data['expresssn'] = $express['expresssn']; + $data['expressprice'] = $express['expressprice']; //运费 + } + //处理返回值 + if (empty($data['expressprice'])) { + $data['expressprice'] = 0; + } + if (empty($data['vipdiscount'])) { + $data['vipdiscount'] = 0; + } + if (empty($data['creditmoney'])) { + $data['creditmoney'] = 0; + } + $data['com_dis_price'] = $order['com_dis_price'] > 0 ? $order['com_dis_price'] : 0; + $data['fullreducemoney'] = $order['fullreducemoney'] > 0 ? $order['fullreducemoney'] : 0; + //自定义表单信息处理 + $moinfo = unserialize($order['moinfo']); + if($moinfo){ + foreach($moinfo as &$moinfoItem){ + if($moinfoItem['id'] == 'img'){ + foreach($moinfoItem['data'] as $imgKey => $imgLink){ + $moinfoItem['data'][$imgKey] = tomedia($imgLink); + } + } + } + $data['moinfo'] = $moinfo; + } + //票付通处理 + if($goods['pftid'] > 0 && $order['status'] == 1 && empty($goods['threestatus'])){ + $data['pftinfo'] = unserialize($order['pftorderinfo']); + $data['pftflag'] = 1; + if(empty($data['pftinfo']['UUcode'])){ + $moreinfo = Pftapimod::pftOrderQuery($data['pftinfo']['UUordernum']); + $data['pftinfo']['UUcode'] = $moreinfo['UUcode']; + $newinfo = serialize($data['pftinfo']); + if ($plugin == 'rush') { + pdo_update('wlmerchant_rush_order',array('pftorderinfo' => $newinfo),array('id' => $id)); + }else{ + pdo_update('wlmerchant_order',array('pftorderinfo' => $newinfo),array('id' => $id)); + } + } + } + //退款提示 + if($data['status'] == 10){ + $ordersettings = Setting::wlsetting_read('orderset'); + $data['tiptext'] = $ordersettings['refundtip'] ? : '请等待系统退款'; + } + + $this->renderSuccess('订单详情' , $data); + } + /** + * Comment: 订单支付成功 + * Author: wlf + * Date: 2019/8/19 16:23 + */ + public function payOver() + { + global $_W , $_GPC; + $tid = $_GPC['tid']; + $paylog = pdo_get('wlmerchant_paylogvfour' , ['tid' => $tid] , ['plugin' ,'plid','fee','payfor']); + if ($paylog) { + $type = strtolower($paylog['plugin']); + $payfor = strtolower($paylog['payfor']); + $data = []; + $data['plugin'] = $type; + if ($type == 'rush') { + $order = pdo_get('wlmerchant_rush_order' , ['orderno' => $tid] , ['id' , 'paytype' , 'paidprid' , 'actualprice' , 'vip_card_id' , 'expressid']); + $data['price'] = $order['actualprice']; + } + else if ($type == 'merchant' && $payfor == 'halfcard') { + $order = pdo_get('wlmerchant_halfcard_record' , ['orderno' => $tid] , ['id' , 'paytype' , 'paidprid' , 'price']); + $data['price'] = $order['price']; + } + else if ($type == 'attestation') { + $order = pdo_get('wlmerchant_attestation_money' , ['orderno' => $tid] , ['id' , 'paytype' , 'money' , 'type']); + $data['price'] = $order['money']; + $data['type'] = $order['type']; + } + else { + $order = pdo_get('wlmerchant_order' , ['orderno' => $tid] , ['id' , 'recordid' , 'fkid' , 'plugin' , 'fightstatus' , 'paytype' , 'paidprid' , 'price' , 'vip_card_id' , 'expressid']); + + $data['price'] = $order['price']; + if ($order['plugin'] == 'wlfightgroup') { + $data['fightgoodsid'] = $order['fkid']; + } + if ($order['plugin'] == 'coupon') { + $data['couponid'] = $order['recordid']; + } + if ($order['plugin'] == 'taxipay') { + $data['masid'] = $order['fkid']; + $info = DiyPage::defaultinfo('options'); + $data['tabinfo'] = $info; + $areaid = pdo_getcolumn(PDO_NAME.'oparea',array('uniacid'=>$_W['uniacid'],'aid'=>$_W['aid']),'areaid'); + $data['tabtitle'] = pdo_getcolumn(PDO_NAME.'area',array('id'=>$areaid),'name'); + $data['tabtitle'] .= '精选'; + $data['noticeurl'] = $_W['siteroot'].'addons/weliam_smartcity/plugin/taxipay/sys/resource/taxinotice.mp3'; + } + if(empty($order) && $data['plugin'] == 'citydelivery'){ + $data['price'] = $paylog['fee']; + $order = pdo_get('wlmerchant_order' , ['paylogid' => $paylog['plid']] , ['id' , 'recordid' , 'fkid' , 'plugin' , 'fightstatus' , 'paytype' , 'paidprid' , 'price' , 'vip_card_id' , 'expressid']); + } + } + }else { + $order = pdo_get('wlmerchant_rush_order' , ['orderno' => $tid] , ['id' , 'paytype' , 'paidprid' , 'actualprice' , 'vip_card_id', 'expressid']); + if (empty($order)) { + $order = pdo_get('wlmerchant_order' , ['orderno' => $tid] , ['id' , 'recordid' , 'fkid' , 'plugin' , 'fightstatus' , 'paytype' , 'paidprid' , 'price' , 'vip_card_id', 'expressid']); + $data['price'] = $order['price']; + $data['plugin'] = $order['plugin']; + if ($order['plugin'] == 'wlfightgroup') { + $data['fightgoodsid'] = $order['fkid']; + } + if ($order['plugin'] == 'coupon') { + $data['couponid'] = $order['recordid']; + } + if ($order['plugin'] == 'halfcard') { + $data['plugin'] = 'payonline'; + } + }else { + $data['price'] = $order['actualprice']; + $data['plugin'] = 'rush'; + } + } + if ($type == 'merchant') { + $data['plugin'] = $payfor; + } + $paytype = [1 => '余额支付' , 2 => '微信支付' , 3 => '支付宝支付' , 4 => '货到付款' , 5 => '小程序支付' , 6 => '0元购']; + $data['paytype'] = $paytype[$order['paytype']]; + //支付有礼 + if ($order['paidprid']) { + $paid = pdo_get('wlmerchant_paidrecord' , ['id' => $order['paidprid']]); + $pactivity = pdo_get('wlmerchant_payactive' , ['id' => $paid['activeid']]); + if ($pactivity['giftstatus'] == 1) { + $couponIdList = explode(',' , $pactivity['giftcouponid']); + if (is_array($couponIdList)) { + foreach ($couponIdList as $key => $val) { + $couponNameList[$key] = pdo_getcolumn(PDO_NAME . 'couponlist' , ['id' => $val] , 'title'); + } + } + $data['couponlist'] = $couponNameList; + } + if ($paid['codeid'] && $pactivity['giftstatus'] == 2) { + $code = pdo_get(PDO_NAME . 'token' , ['id' => $paid['codeid']] , ['number' , 'status']); + $data['code'] = $code['number']; + } + if ($pactivity['giftstatus'] == 3) { + $redPackList = []; + $redPackIds = explode(',' , $pactivity['giftredpack']); + if (is_array($redPackIds)) { + $field = ['id','title','full_money','cut_money','use_start_time','use_end_time','usetime_day1','usetime_day2','usegoods_type','usetime_type','limit_count','use_aids','use_sids']; + foreach ($redPackIds as $key => $val) { + $redpack = pdo_get(PDO_NAME."redpacks",['id'=>$val],$field); + if(!$redpack) continue; + //当前用户剩余可以领取的数量 删除用户不能领取的红包信息 开启后 则只显示用户可以领取的红包 + if (!empty($redpack['limit_count'])) { + $mycounts = Redpack::getReceiveTotal($redpack['id'],$_W['mid'],1,0); + if ($mycounts >= $redpack['limit_count']){ + $redpack['is_over'] = 1; + } + } + //价格处理 + $redpack['full_money'] = sprintf("%0.2f",$redpack['full_money']); + $redpack['cut_money'] = sprintf("%0.2f",$redpack['cut_money']); + //有效期处理 + $usetimes = [ + date('Y-m-d' , $redpack['use_start_time']) . ' ~ ' . date('Y-m-d' , $redpack['use_end_time']) , + '领取当日起' . $redpack['usetime_day1'] . '天内有效' , + '领取次日起' . $redpack['usetime_day2'] . '天内有效' + ]; + $redpack['usetime_text'] = $usetimes[$redpack['usetime_type']]; + //使用条件处理 0全平台1指定代理2指定商家 + if ($redpack['usegoods_type'] == 1) { + //代理商可用 查询可用代理商信息 + $aids = unserialize($redpack['use_aids']); + $agents = pdo_getall(PDO_NAME."oparea",['aid'=>$aids],'areaid'); + if($agents) $areaInfo = pdo_getall(PDO_NAME."area",['id'=>array_values(array_column($agents,'areaid'))],'name'); + if($areaInfo){ + $areaName = implode(',',array_column($areaInfo,'name')); + $redpack['use_where'] = "仅限{$areaName}代理可用"; + }else{ + $redpack['use_where'] = "仅限指定地区可用"; + } + }else if ($redpack['usegoods_type'] == 2) { + //商家可用 查询可用商家信息 + $sids = unserialize($redpack['use_sids']); + $storeName = pdo_getall(PDO_NAME."merchantdata",['id'=>$sids],'storename'); + if($storeName){ + $storeName = implode(',',array_column($storeName,'storename')); + $redpack['use_where'] = "仅限{$storeName}商家可用"; + }else{ + $redpack['use_where'] = "仅限指定商家可用"; + } + }else if ($redpack['usegoods_type'] == 3) { + //指定商品可用 商品过多,直接显示固定内容 + $redpack['use_where'] = "仅限指定商品可用"; + }else { + $redpack['use_where'] = '全平台可用'; + } + //删除多余的信息 + unset($redpack['usegoods_type']); + unset($redpack['use_start_time']); + unset($redpack['use_end_time']); + unset($redpack['usetime_day1']); + unset($redpack['usetime_day2']); + unset($redpack['usetime_type']); + + $redPackList[$key] = $redpack; + } + } + $data['redpacklist'] = $redPackList; + } + $data['getcouflag'] = $paid['getcouflag']; + $data['integral'] = $paid['integral']; + $data['balance'] = $paid['balance']; + $data['thumb'] = tomedia($paid['img']); + $data['thumburl'] = $pactivity['advurl']; + $data['paidprid'] = $order['paidprid']; + } + if($data['plugin'] == 'citydelivery' && !empty($paylog['plid'])){ + $data['orderid'] = $paylog['plid']; + }else{ + $data['orderid'] = $order['id']; + } + if ($data['plugin'] == 'pocket') { + $data['tieziid'] = $order['fkid']; + } + if ($data['plugin'] == 'wlfightgroup') { + $data['fightstatus'] = $order['fightstatus']; + } + //求职招聘 + if ($data['plugin'] == 'recruit') { + $data['recruit_id'] = $order['fkid']; + $recruit = pdo_get(PDO_NAME."recruit_recruit",['id'=>$order['fkid']]); + $data['release_sid'] = $recruit['release_sid'] ? : 0; + } + //权益 + if ($data['plugin'] == 'rights') { + $data['rights_id'] = $order['fkid']; + } + //支付成功页面 小程序订阅消息type获取 + if ($_W['source'] == 3) { + //2=回到首页、查看订单按钮 - 拼团商品 - 发货订单【拼团进度通知/订单发货通知】 + //3=回到首页、查看订单按钮 - 拼团商品 - 核销、自提订单【拼团进度通知/核销成功通知】 + //4=回到首页、查看订单按钮 - 非拼团商品 - 发货订单【订单发货通知】 + //5=回到首页、查看订单按钮 - 非拼团商品 - 核销、自提订单【核销成功通知】 + if ($data['plugin'] == 'wlfightgroup') { + if ($order['expressid'] > 0) $data['temp_type'] = intval(2); + else $data['temp_type'] = intval(3); + }else if (in_array($data['plugin'] , ['rush' , 'groupon' , 'bargain' , 'coupon' , 'consumption'])) { + if ($order['expressid'] > 0) $data['temp_type'] = intval(4); + else $data['temp_type'] = intval(5); + } + } + + $this->renderSuccess('支付完成' , $data); + } + /** + * Comment: 领取支付有礼卡券 + * Author: wlf + * Date: 2019/8/19 17:00 + */ + public function getCoupon() + { + global $_W , $_GPC; + $id = $_GPC['id']; + $paid = pdo_get(PDO_NAME . 'paidrecord' , ['id' => $id]); + if ($paid['getcouflag']) { + $this->renderError('您已成功领取,无法重复领取'); + } + $pactivity = pdo_get(PDO_NAME . 'payactive' , ['id' => $paid['activeid']]); + $couponIdList = explode(',' , $pactivity['giftcouponid']); + #3、通过循环判断信息 + if (is_array($couponIdList)) { + $acresult = '';//优惠券领取状态 + foreach ($couponIdList as $k => $v) { + $coupons = wlCoupon::getSingleCoupons($v , '*'); + $num = wlCoupon::getCouponNum($v , 1); + //判断卡券是否能够被领取 + if ($coupons['time_type'] == 1 && $coupons['endtime'] < time()) { + $acresult = '[失败]已停止发放'; + } + if ($coupons['status'] == 0) { + $acresult = '[失败]已被禁用'; + } + if ($coupons['status'] == 3) { + $acresult = '[失败]已失效'; + } + if ($coupons['surplus'] > ($coupons['quantity'] - 1)) { + $acresult = '[失败]已被领光'; + } + if ($num) { + if (($num > $coupons['get_limit'] || $num == $coupons['get_limit']) && $coupons['get_limit'] > 0) { + $acresult = '[失败]只能领取' . $coupons['get_limit'] . '张'; + } + } + //领取状态为空 无异常 开始正常的领取操作 + if (empty($acresult)) { + //用户领取卡券的操作 + if ($coupons['time_type'] == 1) { + $starttime = $coupons['starttime']; + $endtime = $coupons['endtime']; + } + else { + $starttime = time(); + $endtime = time() + ($coupons['deadline'] * 24 * 3600); + } + if (empty($coupons['is_charge'])) { + $coupons['price'] = 0; + $settlementmoney = 0; + } + else { + //结算金额 + $settlementmoney = Store::getsettlementmoney(4 , $coupons['id'] , 1 ,$coupons['merchantid'] , 0); + } + //生成领取订单 + $orderdata = [ + 'uniacid' => $coupons['uniacid'] , + 'mid' => $_W['mid'] , + 'aid' => $coupons['aid'] , + 'fkid' => $coupons['id'] , + 'sid' => $coupons['merchantid'] , + 'status' => 1 , + 'paytype' => 6 , + 'createtime' => time() , + 'orderno' => createUniontid() , + 'price' => 0 , + 'num' => 1 , + 'plugin' => 'coupon' , + 'payfor' => 'couponsharge' , + 'vipbuyflag' => 0 , + 'goodsprice' => $coupons['price'], + 'settlementmoney' => $settlementmoney , + 'neworderflag' => 1 , + 'buyremark' => '支付有礼赠送卡券,记录号:' . $id , + 'paytime' => time() + ]; + $orderid = wlCoupon::saveCouponOrder($orderdata); + Order::createSmallorder($orderid , 4); + //生成卡券 + $data = [ + 'mid' => $_W['mid'] , + 'aid' => $_W['aid'] , + 'parentid' => $coupons['id'] , + 'status' => 1 , + 'type' => $coupons['type'] , + 'title' => $coupons['title'] , + 'sub_title' => $coupons['sub_title'] , + 'content' => $coupons['goodsdetail'] , + 'description' => $coupons['description'] , + 'color' => $coupons['color'] , + 'starttime' => $starttime , + 'endtime' => $endtime , + 'createtime' => time() , + 'usetimes' => $coupons['usetimes'] , + 'concode' => 0 , + 'uniacid' => $_W['uniacid'] , + 'orderno' => $orderdata['orderno'] + ]; + $res = pdo_insert(PDO_NAME . 'member_coupons' , $data); + $couponUserId = pdo_insertid(); + $newdata['recordid'] = $couponUserId; + $newdata['estimatetime'] = $data['endtime']; + pdo_update(PDO_NAME . 'order' , $newdata , ['id' => $orderid]); //更新订单状态 + if ($res) { + //修改卡券的已售数量 + $newsurplus = $coupons['surplus'] + 1; + wlCoupon::updateCoupons(['surplus' => $newsurplus] , ['id' => $v]); + $url = h5_url('pages/subPages/coupon/coupon' , [ + 'id' => $couponUserId , + 'order_id' => $orderid + ]); + $acresult = '[成功]领取成功'; + } + else { + $acresult = '[失败]领取失败'; + } + } + $messagedata = [ + 'first' => '“' . $coupons['title'] . '”领取结果通知' , + 'type' => '支付有礼-卡券领取' ,//业务类型 + 'content' => '领取人:' . $_W['wlmember']['nickname'] ,//业务内容 + 'status' => $acresult ,//处理结果 + 'time' => date('Y-m-d H:i:s' , time()) ,//操作时间 + 'remark' => '点击查看我的卡券' + ]; + TempModel::sendInit('service' , $_W['mid'] , $messagedata , $_W['source'] , $url); + $acresult = '';//清除领取状态 + } + } + pdo_update(PDO_NAME . 'paidrecord' , ['getcouflag' => 1 , 'getcoutime' => time()] , ['id' => $id]); + $this->renderSuccess('领取成功'); + } + /** + * Comment: 取消订单 + * Author: wlf + * Date: 2019/8/19 17:27 + */ + public function cancelOrder() + { + global $_W , $_GPC; + $id = $_GPC['id']; + $plugin = $_GPC['plugin']; + if ($plugin != 'rush') { + $order = pdo_get(PDO_NAME . 'order' , ['id' => $id] ,['mid','plugin','redpackid','usecredit']); + $plugin = $order['plugin']; + if ($plugin == 'groupon') { + $res = Groupon::cancelorder($id); + } + else if ($plugin == 'bargain') { + $res = Bargain::cancelorder($id); + }else if($plugin == 'wlfightgroup'){ + $res = Wlfightgroup::cancelorder($id); + }else if($plugin == 'coupon'){ + $res = wlCoupon::cancelorder($id); + } + else { + $res = pdo_update('wlmerchant_order',['status' => 5],['id' => $id]); + if($order['redpackid']){ + pdo_update('wlmerchant_redpack_records',['status' => 0],['id' => $order['redpackid']]); + } + if($order['usecredit'] > 0){ + if($plugin == 'halfcard'){ + $pluginname = '在线买单'; + } + Member::credit_update_credit1($order['mid'], $order['usecredit'], '取消'.$pluginname.'订单返还积分'); + } + } + } + else { + $res = Rush::cancelorder($id); + } + if ($res) { + $this->renderSuccess('取消成功'); + } + else { + $this->renderError('取消失败'); + } + } + /** + * Comment: 核销订单页面 + * Author: wlf + * Date: 2019/8/20 14:27 + */ + public function selfUse() + { + global $_W , $_GPC; + $id = $_GPC['id']; + $plugin = $_GPC['plugin']; + //获取商品 + if ($plugin == 'rush') { + $order = pdo_get('wlmerchant_rush_order' , ['id' => $id] , ['activityid' , 'optionid' , 'mid' , 'sid']); + $goods = pdo_get('wlmerchant_rush_activity' , ['id' => $order['activityid']] , ['name','appointstatus', 'thumb']); + if ($order['optionid']) { + $optionname = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $order['optionid']] , 'title'); + } + $data['goodsName'] = $goods['name']; + $data['goodsLogo'] = tomedia($goods['thumb']); + $data['optionName'] = $optionname ? : ''; + } + else { + $order = pdo_get('wlmerchant_order' , ['id' => $id] , ['fkid' , 'specid' , 'mid' , 'sid']); + if ($plugin == 'groupon') { + $goods = pdo_get('wlmerchant_groupon_activity' , ['id' => $order['fkid']] , ['name','appointstatus' , 'thumb']); + $data['goodsName'] = $goods['name']; + $data['goodsLogo'] = tomedia($goods['thumb']); + } + else if ($plugin == 'coupon') { + $goods = pdo_get('wlmerchant_couponlist' , ['id' => $order['fkid']] , [ + 'title' , + 'logo' , + 'sub_title' + ]); + $data['goodsName'] = $goods['title']; + $data['goodsLogo'] = tomedia($goods['logo']); + $optionname = $goods['sub_title']; + } + else if ($plugin == 'wlfightgroup') { + $goods = pdo_get('wlmerchant_fightgroup_goods' , ['id' => $order['fkid']] , ['name','appointstatus' , 'logo']); + $data['goodsName'] = $goods['name']; + $data['goodsLogo'] = tomedia($goods['logo']); + } + else if ($plugin == 'bargain') { + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $order['fkid']] , ['name','appointstatus','thumb']); + $data['goodsName'] = $goods['name']; + $data['goodsLogo'] = tomedia($goods['thumb']); + } + else if ($plugin == 'activity') { + $goods = pdo_get('wlmerchant_activitylist' , ['id' => $order['fkid']] , [ + 'title' , + 'thumb' + ]); + $data['goodsName'] = $goods['title']; + $data['goodsLogo'] = tomedia($goods['thumb']); + } + if ($order['specid'] && $plugin != 'bargain') { + if($plugin == 'activity'){ + $optionname = pdo_getcolumn(PDO_NAME . 'activity_spec' , ['id' => $order['specid']] , 'name'); + }else{ + $optionname = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $order['specid']] , 'title'); + } + } + $data['optionName'] = $optionname ? : ''; + } + $verkey = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $order['sid']] , 'verkey'); + //密码还是扫码核销 + if ($_W['mid'] == $order['mid'] && !empty($verkey)) { //密码核销 + $data['useStatua'] = 1; + } + if (empty($data['useStatua'])) { + $verifier = SingleMerchant::verifier($order['sid'] , $_W['mid']); + if (!$verifier) { + $this->renderError('非核销员' , ['url' => h5_url('pages/mainPages/index/index')]); + } + else { + $data['useStatua'] = 2; + } + } + //获取核销码 + if($goods['appointstatus'] > 0){ + $smalls = pdo_getall('wlmerchant_smallorder' , ['orderid' => $id , 'plugin' => $plugin,'status' => 1,'appointstatus' => 3,'appstarttime <' => time(),'appendtime >' => time()] , ['checkcode','status','id']); + if(empty($smalls)){ + $this->renderError('订单未预约或未到预约时间' , ['url' => h5_url('pages/mainPages/index/index')]); + } + }else{ + $smalls = pdo_getall('wlmerchant_smallorder' , ['orderid' => $id , 'plugin' => $plugin,'status' => 1] , ['checkcode','status','id']); + } + $data['checkcodes'] = $smalls; + $this->renderSuccess('核销详情' , $data); + } + /** + * Comment: 使用核销码 + * Author: wlf + * Date: 2019/8/20 16:27 + */ + public function useCheckcode() + { + global $_W , $_GPC; + $ids = $_GPC['ids']; + $ids = explode(',' , $ids); + $usestatus = $_GPC['usestatus']; + $verkey = trim($_GPC['verkey']); + if ($ids[0] > 0) { + $ordertem = pdo_get(PDO_NAME . 'smallorder' , ['id' => $ids[0]]); + if ($usestatus == 1) { //密码核销 + $storeverkey = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $ordertem['sid']] , 'verkey'); + if ($verkey != $storeverkey || empty($storeverkey)) { + $this->renderError('核销密码错误请重试'); + } + $type = 4; + } + else if ($usestatus == 2) { //扫码核销 + $verifier = SingleMerchant::verifier($ordertem['sid'] , $_W['mid']); + if (!$verifier) { + $this->renderError('非核销员,无法核销'); + } + $type = 2; + } + else { + $this->renderError('无效的核销方式'); + } + foreach ($ids as $id) { + $order = pdo_get(PDO_NAME . 'smallorder' , ['id' => $id]); + if ($order) { + if ($order['status'] == 1) { + if ($order['plugin'] == 'rush') { + $orderres = Rush::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , $type , $order['checkcode']); + } + else if ($order['plugin'] == 'groupon') { + $orderres = Groupon::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , $type , $order['checkcode']); + } + else if ($order['plugin'] == 'wlfightgroup') { + $orderres = Wlfightgroup::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , $type , $order['checkcode']); + } + else if ($order['plugin'] == 'bargain') { + $orderres = Bargain::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , $type , $order['checkcode']); + } + else if ($order['plugin'] == 'coupon') { + $couponid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $order['orderid']] , 'recordid'); + $orderres = wlCoupon::hexiaoorder($couponid , $_W['mid'] , 1 , $type , $order['checkcode']); + }else if ($order['plugin'] == 'activity') { + $orderres = Activity::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , $type , $order['checkcode']); + } + } + } + } + if($orderres > 0){ + $this->renderSuccess('核销成功'); + }else{ + $this->renderError('核销失败或部分订单异常,请刷新重试'); + } + } + else { + $this->renderError('请勾选核销码' , $ids); + } + } + /** + * Comment: 确认收货 + * Author: wlf + * Date: 2019/8/20 18:05 + */ + public function sureReceive() + { + global $_W , $_GPC; + $id = $_GPC['id']; + $type = $_GPC['plugin']; + if (empty($id) || empty($type)) { + $this->renderError('缺少重要参数'); + } + $res = Order::sureReceive($id,$type); + if($res){ + $this->renderSuccess('收货成功'); + }else{ + $this->renderError('收货失败,请重试'); + } + } + /** + * Comment: 售后服务 + * Author: wlf + * Date: 2019/8/21 17:49 + */ + public function afterSale() + { + global $_W , $_GPC; + $id = $_GPC['id']; + $plugin = $_GPC['plugin']; + $afterid = $_GPC['afterid']; + $data = []; + if ($plugin == 'rush') { + $order = pdo_get('wlmerchant_rush_order' , ['id' => $id] , [ + 'activityid' , + 'expressid' , + 'num' , + 'optionid' , + 'actualprice', + 'pftorderinfo' + ]); + $goods = pdo_get('wlmerchant_rush_activity' , ['id' => $order['activityid']] , [ + 'name' , + 'thumb', + 'pftid' + ]); + $data['goodName'] = $goods['name']; + $data['goodLogo'] = tomedia($goods['thumb']); + $data['type'][] = 1; + if ($order['optionid']) { + $data['optionName'] = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $order['optionid']] , 'title'); + } + $data['allprice'] = $order['actualprice']; + } + else { + $order = pdo_get('wlmerchant_order' , ['id' => $id] , ['fkid' ,'orderno','num' , 'expressid' , 'specid' , 'price','pftorderinfo']); + if ($plugin == 'groupon') { + $goods = pdo_get('wlmerchant_groupon_activity' , ['id' => $order['fkid']] , [ + 'name' , + 'thumb', + 'pftid' + ]); + $data['goodName'] = $goods['name']; + $data['goodLogo'] = tomedia($goods['thumb']); + $data['type'][] = 1; + } + else if ($plugin == 'wlfightgroup') { + $goods = pdo_get('wlmerchant_fightgroup_goods' , ['id' => $order['fkid']] , [ + 'name' , + 'logo' + ]); + $data['goodName'] = $goods['name']; + $data['goodLogo'] = tomedia($goods['logo']); + $data['type'][] = 1; + } + else if ($plugin == 'coupon') { + $goods = pdo_get('wlmerchant_couponlist' , ['id' => $order['fkid']] , [ + 'title' , + 'logo' , + 'sub_title' + ]); + $data['goodName'] = $goods['title']; + $data['goodLogo'] = tomedia($goods['logo']); + $data['type'][] = 1; + $data['optionName'] = $goods['sub_title']; + } + else if ($plugin == 'bargain') { + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $order['fkid']] , [ + 'name' , + 'thumb' + ]); + $data['goodName'] = $goods['name']; + $data['goodLogo'] = tomedia($goods['thumb']); + $data['type'][] = 1; + }else if ($plugin == 'activity') { + $goods = pdo_get('wlmerchant_activitylist' , ['id' => $order['fkid']] , [ + 'title' , + 'thumb' + ]); + $data['goodName'] = $goods['title']; + $data['goodLogo'] = tomedia($goods['thumb']); + $data['type'][] = 1; + }else if($plugin == 'citydelivery'){ + $smallorders = pdo_fetchall("SELECT gid,num,specid FROM ".tablename('wlmerchant_delivery_order')."WHERE orderid = {$id} ORDER BY price DESC"); + foreach ($smallorders as $ke => $orr){ + $goods = pdo_get('wlmerchant_delivery_activity',array('id' => $orr['gid']),array('name','thumb')); + if(empty($ke)){ + $data['goodLogo'] = tomedia($goods['thumb']); + } + if($ke>0){ + if($orr['specid']>0){ + $specname = pdo_getcolumn(PDO_NAME.'delivery_spec',array('id'=>$orr['specid']),'name'); + $data['goodName'] .= ' + ['.$goods['name'].'/'.$specname.'] X'.$orr['num']; + }else{ + $data['goodName'] .= ' + ['.$goods['name'].'] X'.$orr['num']; + } + }else{ + if($orr['specid']>0){ + $specname = pdo_getcolumn(PDO_NAME.'delivery_spec',array('id'=>$orr['specid']),'name'); + $data['goodName'] .= '['.$goods['name'].'/'.$specname.'] X'.$orr['num']; + }else{ + $data['goodName'] .= '['.$goods['name'].'] X'.$orr['num']; + } + } + } + + } + else if ($plugin == 'housekeep') { + $goods = pdo_get('wlmerchant_housekeep_service' , ['id' => $order['fkid']] , [ + 'title' , + 'thumb' + ]); + $data['goodName'] = $goods['title']; + $data['goodLogo'] = tomedia($goods['thumb']); + $data['type'][] = 1; + $data['usestatus'] = 2; + } + if ($order['specid'] && $plugin != 'bargain' && $plugin != 'housekeep') { + if($plugin == 'activity'){ + $data['optionName'] = pdo_getcolumn(PDO_NAME . 'activity_spec' , ['id' => $order['specid']] , 'name'); + }else{ + $data['optionName'] = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $order['specid']] , 'title'); + } + } + $data['allprice'] = $order['price']; + } + $data['num'] = $order['num']; + $data['checkcodes'] = pdo_fetchall("SELECT checkcode,orderprice,status,id FROM ".tablename('wlmerchant_smallorder')."WHERE orderid = {$id} AND plugin = '{$plugin}' AND status = 1 AND appointstatus IN (0,1) ORDER BY id DESC"); + if (!empty($data['checkcodes'])) { + $data['usestatus'] = 1; + } + else if(!empty($order['expressid'])) { + $data['usestatus'] = 2; + } + if($plugin == 'citydelivery'){ + $data['usestatus'] = 2; + $data['num'] = 0; + } + if(!empty($goods['pftid'])){ + $data['usestatus'] = 3; + $pftinfo = unserialize($order['pftorderinfo']); + $pftOrderInfo = Pftapimod::pftOrderQuery($pftinfo['UUordernum']); + if(empty($pftOrderInfo['UUerrorcode'])){ + $data['surplusnum'] = $pftOrderInfo['UUorigin_num'] - $pftOrderInfo['UUverified_num'] - $pftOrderInfo['UUrefund_num']; + }else{ + $this->renderError('票务平台通信错误:'.$pftOrderInfo['UUerrorinfo']); + } + } + //退款提示 + $ordersettings = Setting::wlsetting_read('orderset'); + if(!empty($ordersettings['refundtip'])){ + $data['refundtip'] = 1; + $data['tiptext'] = $ordersettings['refundtip']; + }else{ + $data['refundtip'] = 0; + } + + + if(empty($data['usestatus'])){ + $this->renderError('订单使用类型错误,请返回重试'); + } + //重新申请 + if (!empty($afterid)) { + $after = pdo_get('wlmerchant_aftersale' , ['id' => $afterid] , ['reason' , 'detail' , 'thumbs']); + $data['reason'] = $after['reason']; + $data['detail'] = $after['detail']; + $data['thumbs'] = unserialize($after['thumbs']); + } + $this->renderSuccess('订单信息' , $data); + } + /** + * Comment: 提交售后申请 + * Author: wlf + * Date: 2019/8/22 09:41 + */ + public function afterSaleApply() + { + global $_W , $_GPC; + $id = $_GPC['id']; + $plugin = $_GPC['plugin']; + $type = $_GPC['type']; + $afterid = $_GPC['afterid'] ? $_GPC['afterid'] : 0; + $usestatus = $_GPC['usestatus']; + $num = $_GPC['num'] ? : 0; + if($usestatus == 3 && empty($num)){ + $this->renderSuccess('数量错误,请刷新重试'); + } + if($plugin == 'citydelivery'){ + $canre = pdo_getcolumn(PDO_NAME . 'aftersale' , [ + 'orderid' => $id , + 'plugin' => $plugin , + 'status' => 1 + ] , 'id'); + $smallorder = pdo_get('wlmerchant_order' , ['id' => $id] , ['mid','fightstatus','makeorderno', 'sid' , 'orderno' , 'aid']); + if($smallorder['fightstatus'] == 2){ + Citydelivery::cancelOrder($smallorder['makeorderno']); + }else if($smallorder['fightstatus'] == 3){ + $body = ['order_id' => $smallorder['orderno'],'cancel_reason_id' => 4]; + Citydelivery::postDadaApi($body,5); + }else if($smallorder['fightstatus'] == 4){ + $body = ['origin_id' => $smallorder['orderno'],'reason' => $_GPC['reason']]; + Citydelivery::postUUApi($body,5); + } + } else if ($usestatus == 1) { + $canre = pdo_getcolumn(PDO_NAME . 'aftersale' , [ + 'orderid' => $id , + 'plugin' => $plugin , + 'status' => 1 + ] , 'id'); + $checkcodes = explode(',' , $_GPC['checkcodes']); + $smallorder = pdo_get('wlmerchant_smallorder' , ['checkcode' => $checkcodes[0]] , [ + 'mid' , + 'sid' , + 'orderno' , + 'aid' + ]); + $checkcode = serialize($checkcodes); + }else { + $canre = pdo_getcolumn(PDO_NAME . 'aftersale' , [ + 'orderid' => $id , + 'plugin' => $plugin , + 'status' => [1 , 2] + ] , 'id'); + if ($plugin == 'rush') { + $smallorder = pdo_get('wlmerchant_rush_order' , ['id' => $id] , ['mid' , 'sid' , 'orderno' , 'aid']); + } + else { + $smallorder = pdo_get('wlmerchant_order' , ['id' => $id] , ['mid' , 'sid' , 'orderno' , 'aid','specid']); + } + } + if ($canre) $this->renderError('此订单已经申请了售后,请完成上一次售后申请后再提交'); + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + $reason = $_GPC['reason']; + $detail = $_GPC['detail']; + $thumbs = serialize($_GPC['thumbs']); + $data = [ + 'uniacid' => $_W['uniacid'] , + 'status' => 1 , + 'mid' => $smallorder['mid'] , + 'sid' => $smallorder['sid'] , + 'aid' => $smallorder['aid'] , + 'orderno' => $smallorder['orderno'] , + 'orderid' => $id , + 'plugin' => $plugin , + 'type' => $type , + 'checkcodes' => $checkcode , + 'reason' => $reason , + 'detail' => $detail , + 'thumbs' => $thumbs , + 'createtime' => time(), + 'num' => $num + ]; + //写入日志 + $journal = [ + 'time' => $data['createtime'] , + 'title' => '买家发起退款申请' , + 'detail' => '申请原因:' . $data['reason'] , + 'thumbs' => $data['thumbs'] + ]; + $data['journal'] = Order::addjournal($journal , $afterid); + if (!empty($afterid)) { + $res = pdo_update('wlmerchant_aftersale' , $data , ['id' => $afterid]); + } + else { + $res = pdo_insert('wlmerchant_aftersale' , $data); + $afterid = pdo_insertid(); + } + if ($res) { + if ($usestatus == 1 && !empty($checkcodes)){ + foreach ($checkcodes as $code) { + //校验核销码状态 + $checkorderstatus = pdo_getcolumn(PDO_NAME.'smallorder',array('checkcode'=>$code),'status'); + if($checkorderstatus != 1){ + MysqlFunction::rollback(); + $this->renderError('核销码['.$code.']状态错误,请刷新重试'); + } + pdo_update('wlmerchant_smallorder' , ['status' => 4] , ['checkcode' => $code]); + } + } + MysqlFunction::commit(); + $orderSet = Setting::wlsetting_read('orderset'); + if ($orderSet['autoapplyre'] != 1) { + //未开启 自动退款申请订单 给代理商管理员发送模板消息 + $first = "用户【{$_W['wlmember']['nickname']}】提交了单号为[{$smallorder['orderno']}]订单的退款申请";//消息头部 + $type = "退款申请";//业务类型 + $content = !empty($detail) ? $detail : $reason;//业务内容 + $status = "待审核";//处理结果 + $remark = "请尽快处理!";//备注信息 + $time = $data['createtime'];//操作时间 + //给代理商管理员发送模板消息 + News::noticeAgent('refundorder' , $_W['aid'] , $first , $type , $content , $status , $remark , $time); + //给商户管理员发送模板消息 + if($plugin != 'housekeep'){ + News::noticeShopAdmin( $smallorder['sid'], $first , $type , $content , $status , $remark , $time); + }else{ + if($smallorder['specid'] == 1){ + News::noticeShopAdmin( $smallorder['sid'], $first , $type , $content , $status , $remark , $time); + }else{ + $mid = pdo_getcolumn(PDO_NAME.'housekeep_artificer',array('id'=>$smallorder['sid']),'mid'); + News::jobNotice($mid,$first,$type,$content,$status,$remark,$time); + } + } + } + else { + //添加计划任务自动退款 + Queue::addTask(5 , $afterid , time() , $afterid); + } + $this->renderSuccess('提交成功'); + } + else { + MysqlFunction::rollback(); + $this->renderError('提交失败,请刷新重试'); + } + } + /** + * Comment: 支付申请 + * Author: zzw + * Date: 2019/9/25 14:18 + */ + public function requestPay() + { + global $_W , $_GPC; + #1、参数获取 + $order_no = $_GPC['order_no'] OR $this->renderError('缺少订单号'); + $payType = $_GPC['pay_type'] OR $this->renderError('缺少支付方式'); + $name = $_GPC['name'];//商品名称 + $blendflag = $_GPC['blendflag'];//混合支付标识 + //修改支付配置信息与分账信息 + if($_W['wlsetting']['cashset']['allocationtype'] == 1 && $payType == 2){ + $paylog = pdo_fetch("SELECT plugin,payfor FROM".tablename(PDO_NAME.'paylogvfour') ." WHERE tid = {$order_no} "); + if($paylog['plugin'] == 'Rush'){ + $sid = pdo_getcolumn(PDO_NAME."rush_order",['orderno'=>$order_no],'sid'); + $storeinfo = pdo_get('wlmerchant_merchantdata',array('id' => $sid),array('wxallid','appallid')); + if($_W['source'] == 1){ + $paysetid = $storeinfo['wxallid']; + }else if($_W['source'] == 3){ + $paysetid = $storeinfo['appallid']; + } + if($paysetid > 0){ + pdo_update(PDO_NAME.'rush_order',array('paysetid' => $paysetid,'allocationtype' => 1),array('orderno' => $order_no)); + } + }else if($paylog['plugin'] == 'Halfcard' && $paylog['payfor'] == 'Halfcard'){ + $aid = pdo_getcolumn(PDO_NAME."halfcard_record",['orderno'=>$order_no],'aid'); + $agentinfo = pdo_get('wlmerchant_agentusers',array('id' => $aid),array('wxpaysetid','apppaysetid')); + if($_W['source'] == 1){ + $paysetid = $agentinfo['wxpaysetid']; + }else if($_W['source'] == 3){ + $paysetid = $agentinfo['apppaysetid']; + } + if($paysetid > 0){ + pdo_update(PDO_NAME.'rush_order',array('paysetid' => $paysetid,'allocationtype' => 1),array('orderno' => $order_no)); + } + + }else{ + $paysetinfo = pdo_get(PDO_NAME."order",['orderno' => $order_no],array('sid','aid')); + $sid = $paysetinfo['sid']; + $aid = $paysetinfo['aid']; + if(empty($sid) || $paylog['payfor'] == 'Charge'){ + $agentinfo = pdo_get('wlmerchant_agentusers',array('id' => $aid),array('wxpaysetid','apppaysetid')); + if($_W['source'] == 1){ + $paysetid = $agentinfo['wxpaysetid']; + }else if($_W['source'] == 3){ + $paysetid = $agentinfo['apppaysetid']; + } + if($paysetid > 0){ + pdo_update(PDO_NAME.'rush_order',array('paysetid' => $paysetid,'allocationtype' => 1),array('orderno' => $order_no)); + } + }else{ + $storeinfo = pdo_get('wlmerchant_merchantdata',array('id' => $sid),array('wxallid','appallid')); + if($_W['source'] == 1 || $_W['source'] == 2){ + $paysetid = $storeinfo['wxallid']; + }else if($_W['source'] == 3){ + $paysetid = $storeinfo['appallid']; + } + } + if($paysetid > 0){ + pdo_update(PDO_NAME.'order',array('paysetid' => $paysetid,'allocationtype' => 1),array('orderno' => $order_no)); + } + } + } + #2、请求获取支付的信息 + $res = Payment::init($order_no , $payType , $name , $_W['source'],$blendflag); + #3、返回支付需要的信息 + $paylog = pdo_get('wlmerchant_paylogvfour' , ['tid' => $order_no,'module' => 'weliam_smartcity'] , ['plugin' , 'uniacid' , 'mid']); + if($payType != 1){ + if ($paylog['uniacid'] != $_W['uniacid'] || empty($paylog['uniacid']) ) { + $this->renderError('订单公众号错误,请返回订单列表重新进入支付页面'); + } + if ($paylog['mid'] != $_W['mid'] || empty($paylog['mid']) ) { + $this->renderError('订单用户错误,请返回订单列表重新进入支付页面'); + } + } + $type = strtolower($paylog['plugin']); + if ($type == 'pocket' && $payType != 3) { + $res['tieziid'] = pdo_getcolumn(PDO_NAME . 'order' , ['orderno' => $order_no] , 'fkid'); + } + $this->renderSuccess('支付信息' , $res); + } + /** + * Comment: 获取订单物流信息 + * Author: zzw + * Date: 2019/10/8 14:34 + */ + public function getLogisticsInfo() + { + global $_W , $_GPC; + #1、参数获取 + $id = intval($_GPC['id']) OR $this->renderError("缺少参数:订单id"); + $tableType = $_GPC['table'] OR $this->renderError('缺少参数:表类型');//a=order b=rush_order + #2、获取订单信息 + if ($tableType == 'a') { + $info = pdo_fetch("SELECT '0' as is_have,expressid,plugin,fkid as gid,specid,num FROM " . tablename(PDO_NAME . 'order') . " WHERE id = {$id} "); + } + else { + $info = pdo_fetch("SELECT '0' as is_have,expressid,activityid as gid,'rush' as plugin,optionid as specid,num FROM " . tablename(PDO_NAME . "rush_order") . " WHERE id = {$id} "); + } + if ($info['expressid'] <= 0) $this->renderError('当前订单暂无物流信息'); + #3、获取商品信息 + switch ($info['plugin']) { + case 'rush': + $goods = pdo_get(PDO_NAME . "rush_activity" , ['id' => $info['gid']] , ['name' , 'thumb']); + $info['goods_name'] = $goods['name']; + $info['goods_logo'] = tomedia($goods['thumb']); + break;//抢购 + case 'consumption': + $goods = pdo_get(PDO_NAME . "consumption_goods" , ['id' => $info['gid']] , [ + 'title' , + 'thumb' + ]); + $info['goods_name'] = $goods['title']; + $info['goods_logo'] = tomedia($goods['thumb']); + break;//积分 + case 'bargain': + $goods = pdo_get(PDO_NAME . "bargain_activity" , ['id' => $info['gid']] , [ + 'name' , + 'thumb' + ]); + $info['goods_name'] = $goods['name']; + $info['goods_logo'] = tomedia($goods['thumb']); + break;//砍价 + case 'groupon': + $goods = pdo_get(PDO_NAME . "groupon_activity" , ['id' => $info['gid']] , [ + 'name' , + 'thumb' + ]); + $info['goods_name'] = $goods['name']; + $info['goods_logo'] = tomedia($goods['thumb']); + break;//团购 + case 'wlfightgroup': + $goods = pdo_get(PDO_NAME . "fightgroup_goods" , ['id' => $info['gid']] , [ + 'name' , + 'logo' + ]); + $info['goods_name'] = $goods['name']; + $info['goods_logo'] = tomedia($goods['logo']); + break;//拼团 + } + #4、获取商品规格信息 + if ($info['specid'] > 0) $specname = pdo_getcolumn(PDO_NAME . "goods_option" , ['id' => $info['specid']] , 'title'); + $info['spec'] = $specname ? : ''; + #5、物流信息获取 + if ($info['expressid'] > 0) { + //物流跟踪信息 + $logisticsInfo = Logistics::orderLogisticsInfo($info['expressid']); + if ($logisticsInfo['Traces']) { + $info['is_have'] = 1; + //将物流信息倒叙 + $info['list'] = array_reverse($logisticsInfo['Traces']); + } + //物流公司、物流单号信息 + $express = pdo_get(PDO_NAME . "express" , ['id' => $info['expressid']] , [ + 'expressname' , + 'expresssn' + ]); + $info['express_name'] = Logistics::codeComparisonTable($express['expressname'] , 'alias')['name']; + $info['express_no'] = $express['expresssn']; + } + unset($info['specid']); + unset($info['plugin']); + unset($info['gid']); + unset($info['expressid']); + $this->renderSuccess('物流信息' , $info); + } + /** + * Comment: 获取快递公司列表 + * Author: wlf + * Date: 2019/10/10 17:07 + */ + public function getComparisonTable() + { + global $_W; + $express_list = Logistics::codeComparisonTable('' , 0 , true); + $this->renderSuccess('快递公司列表' , $express_list); + } + /** + * Comment: 手机端发货接口 + * Author: wlf + * Date: 2019/10/10 17:11 + */ + public function sendGoods() + { + global $_W , $_GPC; + $id = $_GPC['orderid']; + $alias = $_GPC['alias']; + $expresssn = $_GPC['expresssn']; + $ordertype = $_GPC['ordertype']; + $edit_flag = $_GPC['edit_flag']; + $expressname = $_GPC['expressname']; + if (empty($alias) && !empty($expresssn)) { + $this->renderError('请填写物流单号'); + } + $settings = Setting::wlsetting_read('orderset'); + if ($ordertype == 'a') { + $order = pdo_fetch("SELECT a.expressid,a.plugin,a.orderno,a.mid, + CASE a.`plugin` + WHEN 'consumption' THEN (SELECT `title` FROM " . tablename(PDO_NAME . 'consumption_goods') . " WHERE `id` = a.`fkid`) + WHEN 'bargain' THEN (SELECT `name` FROM " . tablename(PDO_NAME . 'bargain_activity') . " WHERE `id` = a.`fkid` ) + WHEN 'groupon' THEN (SELECT `name` FROM " . tablename(PDO_NAME . 'groupon_activity') . " WHERE `id` = a.`fkid` ) + WHEN 'wlfightgroup' THEN (SELECT name FROM " . tablename(PDO_NAME . 'fightgroup_goods') . " WHERE `id` = a.`fkid`) + END as name FROM " . tablename(PDO_NAME . 'order') . " as a WHERE a.id = {$id} "); + } + else { + $order = pdo_fetch("SELECT a.expressid,b.name,'rush' as plugin,a.orderno,a.mid FROM " . tablename(PDO_NAME . "rush_order") . " as a LEFT JOIN " . tablename(PDO_NAME . "rush_activity") . " as b ON a.activityid = b.id WHERE a.id = {$id} "); + } + $expressid = $order['expressid']; + if (empty($expressid)) { + $this->renderError('无收货地址,无法发货!'); + } + $express = pdo_get(PDO_NAME . 'express' , ['id' => $expressid]); + $res = pdo_update('wlmerchant_express' , [ + 'expressname' => $alias , + 'expresssn' => $expresssn , + 'orderid' => $id , + 'sendtime' => time() + ] , ['id' => $expressid]); + if ($res) { + if ($ordertype == 'a') { + $res = pdo_update('wlmerchant_order' , ['status' => 4] , ['id' => $id]); + if ($settings['receipt'] > 0) { + if ($edit_flag) { + pdo_delete('wlmerchant_waittask' , ['important' => $id , 'key' => 6 , 'status' => 0]); + } + $receipttime = time() + $settings['receipt'] * 24 * 3600; + $task = [ + 'type' => 'order' , + 'orderid' => $id + ]; + $task = serialize($task); + Queue::addTask(6 , $task , $receipttime , $id); + } + } + else { + $res = pdo_update('wlmerchant_rush_order' , ['status' => 4] , ['id' => $id]); + if ($settings['receipt'] > 0) { + if ($edit_flag) { + pdo_delete('wlmerchant_waittask' , ['important' => $id , 'key' => 6 , 'status' => 0]); + } + $receipttime = time() + $settings['receipt'] * 24 * 3600; + $task = [ + 'type' => 'rush' , + 'orderid' => $id + ]; + $task = serialize($task); + Queue::addTask(6 , $task , $receipttime , $id); + } + } + /***模板通知***/ + $url = h5_url('pages/subPages/orderList/orderDetails/orderDetails' , [ + 'orderid' => $id , + 'plugin' => $order['plugin'] + ]); + $modelData = [ + 'first' => '您购买的商品已发货,请注意查收!' , + 'order_no' => $order['orderno'] ,//订单编号 + 'express_name' => $expressname ,//物流公司 + 'express_no' => $expresssn ,//物流单号 + 'goods_name' => $order['name'] ,//商品信息 + 'consignee' => $express['name'] ,//收货人 + 'receiving_address' => $express['address'] ,//收货地址 + 'remark' => '点击查看物流详细信息!' + ]; + TempModel::sendInit('send' , $order['mid'] , $modelData , $_W['source'] , $url); + $this->renderSuccess('发货成功'); + } + else { + $this->renderError('发货失败请重试'); + } + } + /** + * Comment: 售后列表接口 + * Author: wlf + * Date: 2019/11/21 09:47 + */ + public function saleAfterList() + { + global $_W , $_GPC; + $pindex = $_GPC['pindex'] ? $_GPC['pindex'] : 1; + $pageStart = $pindex * 10 - 10; + $status = $_GPC['status']; + $where = " WHERE uniacid = {$_W['uniacid']} AND mid = {$_W['mid']} "; + if ($status == 1) { + $where .= " AND status = 1 "; + } + else if ($status == 2) { + $where .= " AND status IN (2,3) "; + } + $list = pdo_fetchall("SELECT id,orderno,orderid,plugin,status FROM " . tablename(PDO_NAME . "aftersale") . $where . " ORDER BY createtime DESC LIMIT {$pageStart},10 "); + $total = pdo_fetchcolumn("SELECT count(id) FROM " . tablename(PDO_NAME . "aftersale") . $where); + if ($list) { + foreach ($list as &$li) { + if ($li['plugin'] == 'rush') { + $order = pdo_get('wlmerchant_rush_order' , ['id' => $li['orderid']] , [ + 'activityid' , + 'num' , + 'optionid' , + 'price' + ]); + $goods = pdo_get('wlmerchant_rush_activity' , ['id' => $order['activityid']] , [ + 'name' , + 'thumb' + ]); + $li['price'] = sprintf("%.2f" , $order['price'] / $order['num']); + } + else if ($li['plugin'] == 'groupon') { + $order = pdo_get('wlmerchant_order' , ['id' => $li['orderid']] , [ + 'fkid' , + 'num' , + 'specid' , + 'goodsprice' + ]); + $goods = pdo_get('wlmerchant_groupon_activity' , ['id' => $order['fkid']] , [ + 'name' , + 'thumb' + ]); + $li['price'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + $order['optionid'] = $order['specid']; + } + else if ($li['plugin'] == 'wlfightgroup') { + $order = pdo_get('wlmerchant_order' , ['id' => $li['orderid']] , [ + 'fkid' , + 'num' , + 'specid' , + 'goodsprice' + ]); + $goods = pdo_get('wlmerchant_fightgroup_goods' , ['id' => $order['fkid']] , [ + 'name' , + 'logo' + ]); + $li['price'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + $order['optionid'] = $order['specid']; + $goods['thumb'] = $goods['logo']; + } + else if ($li['plugin'] == 'activity') { + $order = pdo_get('wlmerchant_order' , ['id' => $li['orderid']] , [ + 'fkid' , + 'num' , + 'specid' , + 'goodsprice' + ]); + $goods = pdo_get('wlmerchant_activitylist' , ['id' => $order['fkid']] , [ + 'title' , + 'thumb' + ]); + $li['price'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + $goods['name'] = $goods['title']; + $order['optionid'] = $order['specid']; + $goods['thumb'] = $goods['thumb']; + } + else if ($li['plugin'] == 'bargain') { + $order = pdo_get('wlmerchant_order' , ['id' => $li['orderid']] , [ + 'fkid' , + 'num' , + 'specid' , + 'goodsprice' + ]); + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $order['fkid']] , [ + 'name' , + 'thumb' + ]); + $li['price'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + } + else if ($li['plugin'] == 'coupon' || $li['plugin'] == 'wlcoupon') { + $order = pdo_get('wlmerchant_order' , ['id' => $li['orderid']] , [ + 'fkid' , + 'num' , + 'specid' , + 'goodsprice' + ]); + $goods = pdo_get('wlmerchant_couponlist' , ['id' => $order['fkid']] , ['title' , 'logo']); + $goods['name'] = $goods['title']; + $goods['thumb'] = $goods['logo']; + $li['price'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + }else if($li['plugin'] == 'citydelivery'){ + $order = pdo_get('wlmerchant_order' , ['id' => $li['orderid']] , ['price']); + $order['num'] = 0; + $smallorders = pdo_fetchall("SELECT gid,num,specid FROM ".tablename('wlmerchant_delivery_order')." WHERE orderid = {$li['orderid']} ORDER BY price DESC"); + foreach ($smallorders as $ke => $orr){ + $good = pdo_get('wlmerchant_delivery_activity',array('id' => $orr['gid']),array('name','thumb')); + if(empty($ke)){ + $goods['thumb'] = tomedia($good['thumb']); + } + if($ke>0){ + if($orr['specid']>0){ + $specname = pdo_getcolumn(PDO_NAME.'delivery_spec',array('id'=>$orr['specid']),'name'); + $goods['name'] .= ' + ['.$good['name'].'/'.$specname.'] X'.$orr['num']; + }else{ + $goods['name'] .= ' + ['.$good['name'].'] X'.$orr['num']; + } + }else{ + if($orr['specid']>0){ + $specname = pdo_getcolumn(PDO_NAME.'delivery_spec',array('id'=>$orr['specid']),'name'); + $goods['name'] .= '['.$good['name'].'/'.$specname.'] X'.$orr['num']; + }else{ + $goods['name'] .= '['.$good['name'].'] X'.$orr['num']; + } + } + } + $li['price'] = $order['price']; + } + $li['goodsname'] = $goods['name']; + $li['goodsthumb'] = tomedia($goods['thumb']); + $li['num'] = $order['num']; + if ($order['optionid']) { + if($li['plugin'] == 'activity'){ + $li['optionname'] = pdo_getcolumn(PDO_NAME . 'activity_spec' , ['id' => $order['optionid']] , 'name'); + }else{ + $li['optionname'] = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $order['optionid']] , 'title'); + } + } + else { + $li['optionname'] = ''; + } + } + $data['total'] = ceil($total / 10); + $data['list'] = $list; + $this->renderSuccess('售后列表' , $data); + } + else { + $data['total'] = 0; + $data['list'] = []; + $this->renderSuccess('无数据' , $data); + } + } + /** + * Comment: 撤销申请接口 + * Author: wlf + * Date: 2019/11/21 11:11 + */ + public function revokeSaleAfter() + { + global $_W , $_GPC; + $id = $_GPC['id']; + $after = pdo_get('wlmerchant_aftersale' , ['id' => $id] , ['type' , 'checkcodes']); + $checkcodes = unserialize($after['checkcodes']); + if ($after['type'] == 1) { //退款 + if (!empty($checkcodes[0])) { + $res = pdo_update('wlmerchant_smallorder' , ['status' => 1] , ['checkcode' => $checkcodes]); + } + else { + $res = 1; + } + } + if ($res) { + pdo_delete('wlmerchant_aftersale' , ['id' => $id]); + $this->renderSuccess('撤销成功'); + } + else { + $this->renderError('撤销失败,请刷新重试'); + } + } + /** + * Comment: 售后详情页面 + * Author: wlf + * Date: 2019/11/21 11:45 + */ + public function saleAfterDetail() + { + global $_W , $_GPC; + $id = $_GPC['id']; + if (empty($id)) { + $this->renderError('无关键参数:id,请返回重新进入'); + } + $after = pdo_get('wlmerchant_aftersale' , ['id' => $id]); + if (empty($after)) { + $this->renderError('此申请已撤销,无法查看'); + } + $data = []; + $data['status'] = $after['status']; + $data['type'] = $after['type']; + if ($after['plugin'] == 'rush') { + $order = pdo_get('wlmerchant_rush_order' , ['id' => $after['orderid']] , [ + 'activityid' , + 'actualprice' , + 'num' , + 'optionid' , + 'price' + ]); + $goods = pdo_get('wlmerchant_rush_activity' , ['id' => $order['activityid']] , ['name' , 'thumb']); + $data['price'] = sprintf("%.2f" , $order['price'] / $order['num']); + $order['price'] = $order['actualprice']; + } + else if ($after['plugin'] == 'groupon') { + $order = pdo_get('wlmerchant_order' , ['id' => $after['orderid']] , [ + 'fkid' , + 'num' , + 'specid' , + 'price' , + 'goodsprice' + ]); + $goods = pdo_get('wlmerchant_groupon_activity' , ['id' => $order['fkid']] , ['name' , 'thumb']); + $data['price'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + $order['optionid'] = $order['specid']; + } + else if ($after['plugin'] == 'wlfightgroup') { + $order = pdo_get('wlmerchant_order' , ['id' => $after['orderid']] , [ + 'fkid' , + 'num' , + 'price' , + 'specid' , + 'goodsprice' + ]); + $goods = pdo_get('wlmerchant_fightgroup_goods' , ['id' => $order['fkid']] , ['name' , 'logo']); + $data['price'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + $order['optionid'] = $order['specid']; + $goods['thumb'] = $goods['logo']; + } + else if ($after['plugin'] == 'activity') { + $order = pdo_get('wlmerchant_order' , ['id' => $after['orderid']] , [ + 'fkid' , + 'num' , + 'price' , + 'specid' , + 'goodsprice' + ]); + $goods = pdo_get('wlmerchant_activitylist' , ['id' => $order['fkid']] , ['title' , 'thumb']); + $goods['name'] = $goods['title']; + $data['price'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + $order['optionid'] = $order['specid']; + } + else if ($after['plugin'] == 'bargain') { + $order = pdo_get('wlmerchant_order' , ['id' => $after['orderid']] , [ + 'fkid' , + 'num' , + 'price' , + 'specid' , + 'goodsprice' + ]); + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $order['fkid']] , ['name' , 'thumb']); + $data['price'] = sprintf("%.2f" , $order['goodsprice'] / $order['num']); + }else if ($after['plugin'] == 'citydelivery'){ + $order = pdo_get('wlmerchant_order' , ['id' => $after['orderid']] , [ + 'num' , + 'price' , + 'specid' , + 'goodsprice', + 'fightstatus' + ]); + if($order['fightstatus'] == 2 || $order['fightstatus'] == 3){ + $data['hiderevoke'] = 1; + }else{ + $data['hiderevoke'] = 0; + } + $smallorders = pdo_fetchall("SELECT id,gid,num,specid FROM ".tablename('wlmerchant_delivery_order')." WHERE orderid = {$after['orderid']} ORDER BY price DESC"); + foreach ($smallorders as $ke => $orr){ + $good = pdo_get('wlmerchant_delivery_activity',array('id' => $orr['gid']),array('name','thumb')); + if(empty($ke)){ + $goods['thumb'] = tomedia($good['thumb']); + } + if($ke>0){ + if($orr['specid']>0){ + $specname = pdo_getcolumn(PDO_NAME.'delivery_spec',array('id'=>$orr['specid']),'name'); + $goods['name'] .= ' + ['.$good['name'].'/'.$specname.'] X'.$orr['num']; + }else{ + $goods['name'] .= ' + ['.$good['name'].'] X'.$orr['num']; + } + }else{ + if($orr['specid']>0){ + $specname = pdo_getcolumn(PDO_NAME.'delivery_spec',array('id'=>$orr['specid']),'name'); + $goods['name'] .= '['.$good['name'].'/'.$specname.'] X'.$orr['num']; + }else{ + $goods['name'] .= '['.$good['name'].'] X'.$orr['num']; + } + } + } + $order['num'] = 0; + $data['price'] = $order['price']; + } + $data['goodsname'] = $goods['name']; + $data['goodsthumb'] = tomedia($goods['thumb']); + $data['num'] = $order['num']; + if ($order['optionid']) { + if($after['plugin'] == 'activity'){ + $data['optionname'] = pdo_getcolumn(PDO_NAME . 'activity_spec' , ['id' => $order['optionid']] , 'name'); + }else { + $data['optionname'] = pdo_getcolumn(PDO_NAME . 'goods_option', ['id' => $order['optionid']], 'title'); + } + } else { + $data['optionname'] = ''; + } + if ($after['type'] == 1) { + $checks = unserialize($after['checkcodes']); + if (!empty($checks[0])) { + $data['refundmoney'] = pdo_getcolumn('wlmerchant_smallorder' , ['checkcode' => $checks] , ["SUM(orderprice)"]); + } + else { + $data['refundmoney'] = $order['price']; + } + } + //处理日志 + $journal = unserialize($after['journal']); + if (!empty($journal)) { + foreach ($journal as &$jour) { + $jour = unserialize($jour); + $jour['thumbs'] = unserialize($jour['thumbs']); + if (!empty($jour['thumbs'])) { + $jour['thumbs'] = explode(',' , $jour['thumbs']); + } + else { + $jour['thumbs'] = []; + } + $jour['ascflag'] = $jour['time']; + $jour['time'] = date('Y-m-d H:i:s' , $jour['time']); + if(!empty($jour['thumbs'])){ + foreach ($jour['thumbs'] as &$th){ + $th = tomedia($th); + } + } + } + $flag = []; + foreach ($journal as $v) { + $flag[] = $v['ascflag']; + } + array_multisort($flag , SORT_DESC , $journal); + } + $data['journal'] = $journal; + $this->renderSuccess('售后详情' , $data); + } + + /** + * Comment: 计算提现手续费与实获金额 + * Author: wlf + * Date: 2020/04/09 17:02 + */ + public function calculationCash(){ + global $_W , $_GPC; + $applymoney = $_GPC['money']; + $spercent = $_GPC['percent']; + $spercentmoney = sprintf("%.2f", $applymoney * $spercent / 100); + $money = sprintf("%.2f", $applymoney - $spercentmoney); + $data['realmoney'] = $money; + $this->renderSuccess('实获金额' ,$data); + } + + /** + * Comment: 同城配送的订单获取 + * Author: wlf + * Date: 2020/04/13 10:24 + */ + public function deliveryOrderSubmit(){ + global $_W , $_GPC; + //参数获取 + $data = []; + $goodsinfo = json_decode(base64_decode($_GPC['goodsinfo']) , true); + $addressid = $_GPC['addressid']; + $usestatus = $_GPC['type']; //配送方式 0到店自提 1商家配送 2平台配送 + $sid = $_GPC['sid']; + //快递信息 + if ($addressid>0) { + $address = pdo_get('wlmerchant_address' , ['id' => $addressid] , ['id','name' ,'status','tel','province','city','county','detailed_address','lng','lat']); + }else{ + $address = pdo_get('wlmerchant_address' , ['mid' => $_W['mid'] , 'uniacid' => $_W['uniacid'] , 'status' => 1] , ['id' , 'status' , 'name' , 'tel' , 'province' , 'city' , 'county' , 'detailed_address','lng','lat']); + $addressid = $address['id']; + } + //商品信息获取 + if((empty($goodsinfo) || !is_array($goodsinfo)) && empty($sid) ){ + $this->renderError('商品信息错误,请返回重试'); + }else{ + if(empty($goodsinfo) || !is_array($goodsinfo)){ + $storeinfo['sid'] = $sid; + $storeinfo['cartid'] = pdo_getall('wlmerchant_delivery_shopcart',array('mid' => $_W['mid'],'sid' => $sid),array('id')); + foreach ($storeinfo['cartid'] as $cart){ + $infoarray[] = $cart['id']; + } + $storeinfo['cartid'] = $infoarray; + $goodsinfo[] = $storeinfo; + } + $halfflag = WeliamWeChat::VipVerification($_W['mid'],true); + $goodallmoney = $deliveryallmoney = $alldiscount = $fulldiscount = $packingmoney = 0; + foreach ($goodsinfo as $ke => $store){ + $storearray = pdo_get(PDO_NAME.'merchantdata',array('id'=>$store['sid']),array('lng','lat','deliveryfullid','makebiguser','deliverytype','storename','expresspricestatus','deliverymoney','deliverydistance','lowdeliverymoney')); + //判断支付方式 + if($ke == 0){ + $deliverytype = unserialize($storearray['deliverytype']); + $data['statistics']['use_store'] = in_array('store',$deliverytype) ? 1 : 0; + $data['statistics']['use_make'] = in_array('make',$deliverytype) ? 1 : 0; + $data['statistics']['use_own'] = in_array('own',$deliverytype) ? 1 : 0; + } + unset($storearray['deliverytype']); + $storearray['allmoney'] = 0; + $storearray['vipdiscount'] = 0; + $storearray['packingmoney'] = 0; + $storearray['sid'] = $store['sid']; + if($usestatus == 0 || ($usestatus == 2 && empty($storearray['expresspricestatus']) )){ + $storearray['deliverymoney'] = 0; + }else{ + $storearray['distance'] = Store::getdistance($address['lng'],$address['lat'],$storearray['lng'],$storearray['lat'],true); + if($storearray['distance'] > 9999998){ + $storearray['distance'] = 0; + } + } + foreach ($store['cartid'] as $good){ + $good = pdo_get('wlmerchant_delivery_shopcart',array('id' => $good),array('goodid','num','specid')); + $goodinfo = pdo_get('wlmerchant_delivery_activity',array('id' => $good['goodid']),array('name','price','deliveryprice','thumb','vipstatus','vipdiscount','optionstatus')); + $goodarray['name'] = $goodinfo['name']; + $goodarray['thumb'] = tomedia($goodinfo['thumb']); + $goodarray['price'] = $goodinfo['price']; + $goodarray['deliveryprice'] = $goodinfo['deliveryprice']; + $goodarray['num'] = $good['num']; + //规格 + if($goodinfo['optionstatus']){ + $specarray = pdo_get('wlmerchant_delivery_spec',array('id' => $good['specid']),array('name','price','oldprice')); + $goodarray['price'] = $specarray['price']; + $goodarray['specname'] = $specarray['name']; + } + //会员 + if($goodinfo['vipstatus'] == 1 && $halfflag){ + $goodarray['vipdiscount'] = $goodinfo['vipdiscount']; + }else{ + $goodarray['vipdiscount'] = 0; + } + //计算包装费 + if($usestatus>0){ + $storearray['packingmoney'] = sprintf("%.2f",$storearray['packingmoney'] + $goodinfo['deliveryprice']*$goodarray['num']); + }else{ + $storearray['packingmoney'] = 0; + } + //计算小计信息 + $storearray['vipdiscount'] = sprintf("%.2f",$storearray['vipdiscount'] + $goodarray['vipdiscount'] * $goodarray['num']); + $storearray['allmoney'] = sprintf("%.2f",$storearray['allmoney'] + $goodarray['price'] * $goodarray['num']); + + $goodallmoney += sprintf("%.2f",$goodarray['price'] * $goodarray['num']); + $storearray['goodlist'][] = $goodarray; + } + //平台配送 + if($usestatus == 2 && empty($storearray['expresspricestatus'])){ + $big = $storearray['makebiguser'] > 0 ? $store['sid'] : 0; + $makePrice = Citydelivery::getMakePrice($store['sid'],$addressid,$big); + $storearray['deliverymoney'] = $makePrice['total_price']; + $storearray['distance'] = $makePrice['distance'].'km'; + $storearray['init'] = $makePrice['init']; + $storearray['premium'] = $makePrice['premium']; + $storearray['night_price'] = $makePrice['night_price']; + $storearray['mileage_price'] = $makePrice['mileage_price']; + unset($storearray['makebiguser']); + } + if($storearray['deliveryfullid']>0){ + $storearray['fulldkmoney'] = Fullreduce::getFullreduceMoney(sprintf("%.2f" , $storearray['allmoney'] - $storearray['vipdiscount']),$storearray['deliveryfullid']); + }else{ + $storearray['fulldkmoney'] = 0; + } + $storearray['allmoney'] = sprintf("%.2f",$storearray['allmoney'] + $storearray['packingmoney'] + $storearray['deliverymoney'] - $storearray['vipdiscount'] - $storearray['fulldkmoney']); + //计算总计信息 + $deliveryallmoney += $storearray['deliverymoney']; + $alldiscount += $storearray['vipdiscount']; + $fulldiscount += $storearray['fulldkmoney']; + $packingmoney += $storearray['packingmoney']; + $list[] = $storearray; + } + } + $data['list'] = $list; + $data['statistics']['goodallmoney'] = sprintf("%.2f",$goodallmoney); + $data['statistics']['deliveryprice'] = sprintf("%.2f",$deliveryallmoney); + $data['statistics']['vipdiscount'] = sprintf("%.2f",$alldiscount); + $data['statistics']['fulldiscount'] = sprintf("%.2f",$fulldiscount); + $data['statistics']['packingmoney'] = sprintf("%.2f",$packingmoney); + $data['statistics']['toatlprice'] = sprintf("%.2f",$data['statistics']['goodallmoney'] + $data['statistics']['packingmoney'] + $data['statistics']['deliveryprice'] - $data['statistics']['vipdiscount'] - $data['statistics']['fulldiscount']); + if (empty($address)){ + $address = pdo_get('wlmerchant_address' , ['mid' => $_W['mid'] , 'uniacid' => $_W['uniacid']] , ['id' , 'name' , 'status' , 'tel' , 'province' , 'city' , 'county' , 'detailed_address']); + if ($address) { + pdo_update('wlmerchant_address' , ['status' => 1] , ['id' => $address['id']]); + }else{ + $address = []; + } + } + $data['address'] = $address; + //提货信息 + $member = pdo_get('wlmerchant_member',array('id' => $_W['mid']),array('realname','nickname','mobile')); + $data['thinfo']['thname'] = $member['realname']?$member['realname']:$member['nickname']; + $data['thinfo']['thmobile'] = $member['mobile']; + + $this->renderSuccess('提交订单',$data); + } + + /** + * Comment: 同城配送创建订单 + * Author: wlf + * Date: 2020/04/13 14:53 + */ + public function createDeliveryOrder(){ + global $_W , $_GPC; + //参数获取 + $goodsinfo = json_decode(base64_decode($_GPC['goodsinfo']),true); + $addressid = $_GPC['addressid']; //地址信息 + $username = trim($_GPC['thname']); //提货人姓名 + $mobile = trim($_GPC['thmobile']); //提货人电话 + $type = $_GPC['buytype']; //配送方式 0到店自提 1商家配送 2平台配送 + $sid = $_GPC['sid']; + $remark = trim($_GPC['remark']); + //获取位置信息 + if($type > 0){ + $address = pdo_get('wlmerchant_address' , ['id' => $addressid] , ['lng','lat']); + if(empty($address['lng']) || empty($address['lat'])){ + $this->renderError('配送地址无定位信息,请添加'); + } + } + //商品信息获取 + if((empty($goodsinfo) || !is_array($goodsinfo)) && empty($sid)){ + $this->renderError('订单信息错误,请返回重试'); + }else{ + MysqlFunction::setTrans(4); + MysqlFunction::startTrans(); + if(empty($goodsinfo) || !is_array($goodsinfo)){ + $storeinfo['sid'] = $sid; + $storeinfo['cartid'] = pdo_getall('wlmerchant_delivery_shopcart',array('mid' => $_W['mid'],'sid' => $sid),array('id')); + foreach ($storeinfo['cartid'] as $cart){ + $infoarray[] = $cart['id']; + } + $storeinfo['cartid'] = $infoarray; + $storeinfo['remark'] = $remark; + $goodsinfo[] = $storeinfo; + } + $halfflag = WeliamWeChat::VipVerification($_W['mid'],true); + $settings = Setting::wlsetting_read('orderset'); //获取设置参数 + $ordersid = []; + foreach ($goodsinfo as $store){ + $num = 0; + $goodallmoney = $alldiscount = $packingmoney = $prices = 0; + $storearray = pdo_get(PDO_NAME.'merchantdata',array('id'=>$store['sid']),array('deliverymoney','deliveryfullid','expresspricestatus','deliverytype','makebiguser','lat','lng','storename','deliverydistance','lowdeliverymoney')); + $deliveryallmoney = $storearray['deliverymoney']; + $storearray['packingmoney'] = 0; + $smallorderid = []; + //判断是否能使用选择的配送方式 + $deliverytype = unserialize($storearray['deliverytype']); + if($type == 0 && !in_array('own',$deliverytype)){ + MysqlFunction::rollback(); + $this->renderError('商户['.$storearray['storename'].']不支持到店自提,请单独结算支付'); + } + if($type == 1 && !in_array('store',$deliverytype)){ + MysqlFunction::rollback(); + $this->renderError('商户['.$storearray['storename'].']不支持商户配送,请单独结算支付'); + } + if($type == 2 && !in_array('make',$deliverytype)){ + MysqlFunction::rollback(); + $this->renderError('商户['.$storearray['storename'].']不支持平台配送,请单独结算支付'); + } + unset($storearray['deliverytype']); + foreach ($store['cartid'] as $goodid){ + $good = pdo_get('wlmerchant_delivery_shopcart',array('id' => $goodid),array('goodid','num','specid')); + $goodinfo = pdo_get('wlmerchant_delivery_activity',array('id' => $good['goodid']),array('name','sid','allstock','daystock','uniacid','aid','price','deliveryprice','vipstatus','vipdiscount','optionstatus')); + $goodarray['price'] = $goodinfo['price']; + //规格 + if($goodinfo['optionstatus']){ + $specarray = pdo_get('wlmerchant_delivery_spec',array('id' => $good['specid']),array('name','allstock','daystock','price','oldprice')); + $goodarray['price'] = $specarray['price']; + $goodarray['specname'] = $specarray['name']; + $goodinfo['allstock'] = $specarray['allstock']; + $goodinfo['daystock'] = $specarray['daystock']; + $goodinfo['name'] .= '/'.$specarray['name']; + } + //判断库存 + if($goodinfo['allstock'] > 0){ + $allsalenum = pdo_getcolumn('wlmerchant_delivery_order',array('sid' => $goodinfo['sid'],'gid' => $good['goodid'],'specid' => $good['specid'],'status >' => 0),array("SUM(num)")); + if($allsalenum + $good['num'] > $goodinfo['allstock']){ + $tipinfo = '商品['.$goodinfo['name'].']已售罄,无法下单'; + $this->renderError($tipinfo); + } + } + if($goodinfo['daystock'] > 0){ + $nowtime = strtotime(date('Y-m-d',time())); + $daysalenum = pdo_getcolumn('wlmerchant_delivery_order',array('sid' => $goodinfo['sid'],'gid' => $good['goodid'],'specid' => $good['specid'],'status >' => 0,'createtime' => $nowtime),array("SUM(num)")); + if($daysalenum + $good['num'] > $goodinfo['daystock']){ + $tipinfo = '商品['.$goodinfo['name'].']已售罄,无法下单'; + $this->renderError($tipinfo); + } + } + //会员 + if($goodinfo['vipstatus'] == 1 && $halfflag){ + $goodarray['vipdiscount'] = $goodinfo['vipdiscount']; + }else{ + $goodarray['vipdiscount'] = 0; + } + //计算配送费 + if($type == 0){ + $goodinfo['deliveryprice'] = 0; + } + if($goodinfo['deliveryprice']>0){ + $storearray['packingmoney'] = sprintf("%.2f",$storearray['packingmoney'] + $goodinfo['deliveryprice']); + } + //创建小订单 + $smallorder = array( + 'uniacid' => $goodinfo['uniacid'], + 'aid' => $goodinfo['aid'], + 'sid' => $goodinfo['sid'], + 'gid' => $good['goodid'], + 'mid' => $_W['mid'], + 'specid' => $good['specid'], + 'money' => sprintf("%.2f",($goodarray['price'] - $goodarray['vipdiscount'] + $goodinfo['deliveryprice']) * $good['num']), + 'status' => 0, + 'num' => $good['num'], + 'price' => sprintf("%.2f",$goodarray['price'] * $good['num']), + 'vipdiscount' => sprintf("%.2f",$goodarray['vipdiscount'] * $good['num']), + 'deliverymoney' => sprintf("%.2f",$goodinfo['deliveryprice'] * $good['num']), + 'createtime' => time() + ); + $res = pdo_insert(PDO_NAME . 'delivery_order',$smallorder); + $smallorderid[] = pdo_insertid(); + //累计金额 + $goodallmoney = sprintf("%.2f",$goodallmoney + $smallorder['price']); + $alldiscount = sprintf("%.2f",$alldiscount + $smallorder['vipdiscount']); + $packingmoney = sprintf("%.2f",$packingmoney + $smallorder['deliverymoney']); + if($res){ + pdo_delete('wlmerchant_delivery_shopcart',array('id'=>$goodid)); + }else{ + MysqlFunction::rollback(); + $this->renderError('生成订单失败,请返回重试'); + } + $num += $good['num']; + } + if($type == 0){ + $deliveryallmoney = $packingmoney = $setdeliveryallmoney = $fightgroupid = $addressid = 0; + }else if($type == 1 || ($type == 2 && !empty($storearray['expresspricestatus']))){ + $express = $this->freight($addressid ,0,array('id'=>0,'merchantid'=>$goodinfo['sid']),$deliveryallmoney); + $expressid = $addressid; + $fightgroupid = $express['expressid']; + $setdeliveryallmoney = sprintf("%.2f",$deliveryallmoney + $packingmoney); + }else{ + $big = $storearray['makebiguser']>0 ? $store['sid'] : 0; + $express = Citydelivery::getMakePrice($store['sid'],$addressid,$big); + $deliveryallmoney = $express['total_price']; + $setdeliveryallmoney = $storearray['makebiguser']>0 ? sprintf("%.2f",$express['total_price'] + $packingmoney) : $packingmoney; + $expressid = $addressid; + } + $prices = sprintf("%.2f",$goodallmoney - $alldiscount); + $settlementmoney = Citydelivery::getsettlementmoney($prices,$store['sid'],$setdeliveryallmoney); + if($settlementmoney < 0.01){ + $settlementmoney = Citydelivery::getsettlementmoney($prices,$store['sid'],$setdeliveryallmoney); + } + //满减活动 + if($storearray['deliveryfullid']>0){ + $storearray['fulldkmoney'] = Fullreduce::getFullreduceMoney(sprintf("%.2f" ,$prices),$storearray['deliveryfullid']); + }else{ + $storearray['fulldkmoney'] = 0; + } + $prices = sprintf("%.2f",$prices + $deliveryallmoney + $packingmoney - $storearray['fulldkmoney']); + //校验距离和起送金额 + if($type == 1){ + if($storearray['deliverydistance']>0){ + $distance = Store::getdistance($address['lng'],$address['lat'],$storearray['lng'],$storearray['lat']); + if($distance > $storearray['deliverydistance']*1000){ + MysqlFunction::rollback(); + $this->renderError('['.$storearray['storename'].']的配送距离为'.$storearray['deliverydistance'].'km,请更换配送位置或选择其他配送方式'); + } + } + if($storearray['lowdeliverymoney']>0){ + if($prices < $storearray['lowdeliverymoney']){ + MysqlFunction::rollback(); + $this->renderError('['.$storearray['storename'].']的起送金额为'.$storearray['lowdeliverymoney'].'元,请增购商品或选择其他配送方式'); + } + } + } + //创建商户订单 + $orderData = [ + 'uniacid' => $goodinfo['uniacid'] , + 'mid' => $_W['mid'] , + 'sid' => $goodinfo['sid'] , + 'aid' => $goodinfo['aid'] , + 'plugin' => 'citydelivery' , + 'payfor' => 'deliveryOrder' , + 'orderno' => createUniontid() , + 'status' => 0 ,//订单状态:0未支,1支付,2待发货,3已发货,4已签收,5已取消,6待退款,7已退款 + 'createtime' => TIMESTAMP , + 'price' => $prices > 0 ? $prices : 0, + 'vipbuyflag' => $halfflag , + 'name' => $username , + 'mobile' => $mobile , + 'goodsprice' => $goodallmoney , + 'expressid' => $expressid , + 'buyremark' => $store['remark'], + 'settlementmoney' => $settlementmoney , + 'vipdiscount' => $alldiscount, + 'expressprcie' => $deliveryallmoney, + 'canceltime' => time() + $settings['cancel'] * 60, + 'num' => $num, + 'fightstatus' => $type, + 'fullreduceid' => $storearray['deliveryfullid'], + 'fullreducemoney' => $storearray['fulldkmoney'], + 'fightgroupid' => $fightgroupid, + 'packingmoney' => $packingmoney + ]; + pdo_insert(PDO_NAME . 'order' , $orderData); + $orderid = pdo_insertid(); + if($orderid){ + $ordersid[] = $orderid; + foreach ($smallorderid as $smallid){ + pdo_update('wlmerchant_delivery_order',array('tid' => $orderData['orderno'],'orderid' => $orderid),array('id' => $smallid)); + } + }else{ + MysqlFunction::rollback(); + $this->renderError('生成订单失败,请返回重试'); + } + } + MysqlFunction::commit(); + $data = base64_encode(json_encode($ordersid)); + $this->renderSuccess('订单信息',$data); + + } + + } + + + +} \ No newline at end of file diff --git a/addons/weliam_smartcity/api/Rights.php b/addons/weliam_smartcity/api/Rights.php new file mode 100644 index 0000000..d49ccbb --- /dev/null +++ b/addons/weliam_smartcity/api/Rights.php @@ -0,0 +1,282 @@ + ['plugin' => 'rights', 'payfor' => 'rights'], + 2 => ['plugin' => 'rights', 'payfor' => 'rightsBag'] + ]; + + /** + * 我的权益首页展示数据 + * @return void + */ + public function getRightsList() { + global $_W, $_GPC; + + $rights = Rights::getRightsList(); + $contentList = []; + foreach ($rights as $rightsKey => $rightsValue) { + $contentList[] = ($rightsKey + 1) . '.' . $rightsValue['content']; + } + + $rightsBag = pdo_get(PDO_NAME . 'rights_bag',['id' => 2],['id','title','price']); + + $this->renderSuccess('数据获取成功',[ + 'table_list' => Rights::getRightsMergeList(), + 'content_list' => $contentList, + 'member_rights_list' => Rights::getMemberRightsUsageInfo($_W['mid']), + 'rights_bag_data' => $rightsBag?:[] + ]); + } + + /** + * 权益详情页面展示数据 + * @return void + */ + public function getRightsTypeInfo() { + global $_W, $_GPC; + + $rightsid = $_GPC['rights_id']; + $mid = $_W['mid']; + if (empty($rightsid) || !is_numeric($rightsid)) $this->renderError('缺少权益id'); + + $rights = pdo_get(PDO_NAME . 'rights',['id' => $rightsid],['rights_type','calculate_method','price']); + if (!$rights) $this->renderError('权益信息不存在'); + + $rights_type = $rights['rights_type']; + + $data = [ + 'rights_type' => $rights_type, // 权益类型 + 'remaining_amount' => 0, // 剩余数量 + 'price' => $rights['price'] // 单价 + ]; + + $memberRights = pdo_get(PDO_NAME . 'member_rights',['rightsid' => $rightsid,'mid' => $mid,'status' => 1]); + if ($memberRights) { + $use_amount = $memberRights['use_amount']; + // 现有数量 + $data['remaining_amount'] = Rights::getUseAmount($rightsid,$memberRights['id'],$use_amount,$memberRights['total_amount']); + } + + // 获取权益提交数据信息 + switch ($rightsid) { + case 1: + + break; + case 2: + $data['amount_unit'] = Rights::$unit[4]; // 数量单位 + $data['num_data'] = Rights::$dayData; // 数量选择 + $data['filter_data'] = [ + 'recruit' => Rights::getStoreRecruitInfo($mid) // 商户招聘职位信息 + ]; + break; + case 3: + $data['amount_unit'] = Rights::$unit[4]; + $data['num_data'] = Rights::$monthData; + break; + case 4: + $data['amount_unit'] = Rights::$unit[3]; + $data['num_data'] = Rights::$numData; + break; + case 5: + $data['amount_unit'] = Rights::$unit[2]; + $data['num_data'] = Rights::$copyData; + $data['filter_data'] = [ + 'recruit' => Rights::getStoreRecruitInfo($mid), + 'graduated_school' => Rights::$graduatedSchool, // 毕业院校 + 'experience' => Rights::$experience // 经历 + ]; + break; + } + + $this->renderSuccess('数据返回成功',$data); + } + + /** + * 创建权益支付接口 + * @return void + */ + public function createRightsPay() { + global $_W, $_GPC; + + $rightsid = $_GPC['rights_id']; // 权益ID + $type = $_GPC['type']; // 权益支付类型 + $num = $_GPC['num']; // 购买数量 + $contacts = $_GPC['contacts']; // 联系人名称 + $contact_phone = $_GPC['contact_phone'] ?: ''; // 联系电话 + + if (empty($rightsid) || !is_numeric($rightsid)) $this->renderError('缺少权益id'); + if (empty($type) || !in_array($type,array_keys($this->typeArray))) $this->renderError('权益支付类型数据有误'); + if (!empty($contact_phone) && $contact_phone != 'undefined') { + if (!preg_match("/^1[3-9]\d{9}$/",$contact_phone)) $this->renderError('请输入正确的手机号'); + } + + if ($type == 2) { + $num = 1; + } else { + if (empty($num)) $this->renderError('请输入购买数量'); + if (!preg_match("/^\d+$/",$num)) $this->renderError('购买数量必须是数字整数'); + if ($num <= 0 || $num > 500) $this->renderError('购买数量最低不能小于0,最高不能大于500'); + } + if (!empty($contacts)) { + $contactsRes = Filter::init($contacts,$_W['source'],1); + if ($contactsRes['errno'] == 0) $this->renderError('联系人名称'.$contactsRes['message']); + } + + $typeData = $this->typeArray[$type]; + + // 获取权益价格 + $oprice = 0; + if ($typeData['payfor'] == 'rights') { + $rights = pdo_get(PDO_NAME . 'rights',['id' => $rightsid],['price']); + $oprice = $rights['price']; + } elseif ($typeData['payfor'] == 'rightsBag') { + $rightsBag = pdo_get(PDO_NAME . 'rights_bag',['id' => $rightsid],['price']); + $oprice = $rightsBag['price']; + } + $price = bcmul($oprice,$num,2); + + //生成订单 + $orderdata = [ + 'uniacid' => $_W['uniacid'], + 'mid' => $_W['mid'], + 'aid' => $_W['aid'], + 'fkid' => $rightsid, + 'createtime' => time(), + 'orderno' => createUniontid(), + 'oprice' => $oprice, + 'price' => $price, + 'num' => $num, + 'plugin' => $typeData['plugin'], + 'payfor' => $typeData['payfor'], + 'goodsprice' => $price, + 'fightstatus' => 1, + 'name' => $contacts, + 'mobile' => $contact_phone + ]; + pdo_insert(PDO_NAME.'order',$orderdata); + $orderid = pdo_insertid(); + if (empty($orderid)) { + $this->renderError('生成订单失败,请刷新重试'); + + } else { + $this->renderSuccess('发布成功',['status' => 1,'type' => $typeData['plugin'],'orderid' => $orderid]); + } + } + + /** + * 用户使用权益 + * @return void + */ + public function memberUseRights() { + global $_W, $_GPC; + + $mid = $_W['mid']; + $rightsid = $_GPC['rights_id']; // 权益id + $position = json_decode(html_entity_decode($_GPC['position']),true); // 使用权益 关联信息 + if (empty($rightsid) || !is_numeric($rightsid)) $this->renderError('缺少权益id'); + if (empty($position)) $this->renderError('position参数不能为空'); + if (!is_array($position)) $this->renderError('position参数数据有误'); + + $sumNum = 0; // 总使用数量 + // 验证请求数据 + foreach($position as $value) { + + $num = $value['num']; // 使用数量 + $recruit_id = $value['recruit_id']; // 商户招聘信息ID + if (empty($num)) $this->renderError('请填写使用数量'); + if ($num <= 0) $this->renderError('使用数量不能小于等于0'); + if (empty($recruit_id) || !is_numeric($recruit_id)) $this->renderError('请选择要置顶的岗位'); + + $sumNum += $num; + } + + // 获取用户是否购买权益 + $memberRights = Rights::getMemberRights($mid,$rightsid); + if (!$memberRights) $this->renderError('您没有该权益,请先购买权益'); + + #$remaining_amount = $memberRights['total_amount'] - $memberRights['use_amount']; // 剩余权益数量 + $remaining_amount = Rights::getUseAmount($rightsid,$memberRights['id'],$memberRights['use_amount'],$memberRights['total_amount']); + // 判断权益是否使用完 + if ($memberRights['status'] == 0) $this->renderError('该权益的使用已到期,请重新购买使用'); + if ($remaining_amount <= 0) $this->renderError('该权益的使用数量为零,请重新购买使用'); + + if ($sumNum > $remaining_amount) $this->renderError('填写数量不能大于剩余数量'); + + try { + pdo_begin(); + + switch ($rightsid) { + case 2: + // 生成使用信息 + foreach ($position as $value) { + // 生成子权益使用 + $saveMemberRightsUse = Rights::saveMemberRightsUse($rightsid,$memberRights['id'],$value['num'],$value['recruit_id']); + if (!$saveMemberRightsUse['status']) throw new Exception($saveMemberRightsUse['msg']); + + // 判断是否可以置顶 可以及开始置顶 + $isTopRes = Rights::recruitIsTop($value['recruit_id'],$memberRights['id'],$memberRights,$value['num']); + $num = 1; + if ($isTopRes == 2) $num = 0; + if ($isTopRes) Rights::useMemberRights($rightsid,$mid,$value['recruit_id'],'recruit_bout',$num); + } + break; + case 5: + $graduated_school = $_GPC['graduated_school']; // 毕业院校(待确认) + $experience = $_GPC['experience']; // 优先选项 - 经历(待确认) + $data = []; + if (!empty($graduated_school) && is_numeric($graduated_school)) $data['graduated_school'] = $graduated_school; + if (!empty($experience) && is_numeric($experience)) $data['experience'] = $experience; + foreach ($position as $value) { + $saveMemberRightsUse = Rights::saveMemberRightsUse($rightsid,$memberRights['id'],$value['num'],$value['recruit_id'],'recruit_resume',$data); + if (!$saveMemberRightsUse['status']) throw new Exception($saveMemberRightsUse['msg']); + } + break; + } + +// $memberRightsUpdateArr = ['use_amount' => $memberRights['use_amount'] + $sumNum]; +// $memberRightsUpdate = pdo_update(PDO_NAME . 'member_rights',$memberRightsUpdateArr,['id' => $memberRights['id']]); +// if (!$memberRightsUpdate) throw new Exception('使用失败'); + + } catch (Exception $e) { + pdo_rollback(); + $this->renderError($e->getMessage()); + } + + pdo_commit(); + + $this->renderSuccess('使用成功'); + } + + public function getRightsOrderList() + { + global $_W, $_GPC; + + $page = $_GPC['page'] ? : 1; + $pageIndex = $_GPC['page_index'] ? : 10; + + $where = ['uniacid' => $_W['uniacid'], 'aid' => $_W['aid'], 'plugin' => 'rights','mid' => $_W['mid']?:4]; + $field = "id,orderno,status,paytype,payfor,paytime,price,fkid,mid,num"; + $orderData = Util::getNumData($field, PDO_NAME . 'order', $where, 'id desc', $page, $pageIndex, 1); + + $list = $orderData[0]; + + foreach($list as &$item){ + if ($item['payfor'] == 'rightsBag') { + + $rightsBag = pdo_get(PDO_NAME . 'rights_bag',['id' => $item['fkid']]); + $item['storename'] = $rightsBag['title']; + } else { + $rights = pdo_get(PDO_NAME . 'rights',['id' => $item['fkid']]); + $item['storename'] = $rights['rights_type']; + } + + Member::getMemberInfo($item,$item['mid']); + } + $this->renderSuccess('数据获取成功',$list); + } + +} \ No newline at end of file diff --git a/addons/weliam_smartcity/api/Store.php b/addons/weliam_smartcity/api/Store.php new file mode 100644 index 0000000..9fd4956 --- /dev/null +++ b/addons/weliam_smartcity/api/Store.php @@ -0,0 +1,4922 @@ +renderError('您无权管理该商户',['url'=>h5_url('pages/mainPages/index/index')]); + } + } + //判断过期 + $overdueApiList = ['createGoods','changeGoodsStatus','commentReply','saveGoods','addDynamicPage','addDynamic','checkcodeCash','commentReply']; + if(in_array($_GPC['do'],$overdueApiList)){ + $enabled = pdo_getcolumn(PDO_NAME.'merchantdata',array('id'=>$_GPC['storeid']),'enabled'); + if($enabled == 2){ + $this->renderError('商户暂停营业中,无法进行此操作'); + }else if($enabled == 3){ + $this->renderError('商户已过期,无法进行此操作'); + }else if($enabled == 4){ + $this->renderError('商户已删除,无法进行此操作'); + }else if($enabled == 5){ + $this->renderError('商户审核中,无法进行此操作'); + }else if($enabled == 6){ + $this->renderError('商户未在入驻中,无法进行此操作'); + } + } + } + + /** + * Comment: 获取商户列表信息 + * Author: zzw + * Date: 2019/8/6 15:41 + */ + public function homeList() + { + global $_W , $_GPC; + #1、获取参数/设置信息 + $set = Setting::agentsetting_read("pluginlist"); + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $page_index = $_GPC['page_index'] ? $_GPC['page_index'] : 10; + $page_start = $page * $page_index - $page_index; + $lng = $_GPC['lng'] ? $_GPC['lng'] : 0;//用户当前所在经度 104.0091133118 经度 + $lat = $_GPC['lat'] ? $_GPC['lat'] : 0;//用户当前所在纬度 30.5681964123 纬度 + $order = $_GPC['order'] ? $_GPC['order'] : $set['sjsort'];//排序方式 + $cateOne = $_GPC['cate_one'] ? : 0;//一级分类id + $cateTwe = $_GPC['cate_two'] ? : 0;//二级分类id + $regionId = $_GPC['region_id'] ? : 0; + $search = trim($_GPC['search']); //搜索 1520定制 + if ($regionId > 0) $getAid = pdo_getcolumn(PDO_NAME . "oparea" , [ + 'areaid' => $regionId , + 'status' => 1 , + 'uniacid' => $_W['uniacid'] + ] , 'aid'); + $aid = $getAid > 0 ? $getAid : $_W['aid']; + $is_total = $_GPC['is_total'] ? : 0;//0=不获取总页数;1=获取总页数 + #2、生成基本条件 + + if(empty($search)){ + $getShopWhere = " WHERE uniacid = {$_W['uniacid']} AND aid = {$aid} AND status = 2 AND enabled = 1 AND listshow = 0 "; + if ($cateOne > 0) { + $cateWhere = " WHERE onelevel = {$cateOne} "; + if ($cateTwe > 0) $cateWhere .= " AND twolevel = {$cateTwe} "; + $ids = pdo_fetchall("SELECT * FROM " . tablename(PDO_NAME . "merchant_cate") . $cateWhere); + $getShopWhere .= " AND id in (" . implode(',' , array_column($ids , 'sid')) . ") "; + } + }else{ + $getShopWhere = " AND uniacid = {$_W['uniacid']} AND aid = {$aid} AND status = 2 AND enabled = 1 AND listshow = 0 "; + //分类 + $sercate = pdo_get(PDO_NAME.'category_store',array('uniacid'=>$_W['uniacid'],'aid'=>$_W['aid'],'name' => $search),['id','parentid']); + if(!empty($sercate)){ + if($sercate['parentid'] > 0 ){ + $ids = pdo_fetchall("SELECT * FROM " . tablename(PDO_NAME . "merchant_cate") . " WHERE twolevel = {$sercate['id']}"); + }else{ + $ids = pdo_fetchall("SELECT * FROM " . tablename(PDO_NAME . "merchant_cate") . " WHERE onelevel = {$sercate['id']}"); + } + } + if(empty($ids)){ + $getShopWhere = " WHERE ( storename LIKE '%{$search}%' OR `describe` LIKE '%{$search}%' ) " .$getShopWhere; + }else{ + $getShopWhere = " WHERE ( storename LIKE '%{$search}%' OR `describe` LIKE '%{$search}%' OR id in (" . implode(',' , array_column($ids , 'sid')) . ") ) " .$getShopWhere; + } + } + #2、根据排序规则获取数据信息 + if ($order == 2) { + //按照距离排序 + $list = pdo_fetchall("SELECT id,location FROM " . tablename(PDO_NAME . "merchantdata") . $getShopWhere); + foreach ($list as $index => &$item) { + $location = unserialize($item['location']); + $item['length'] = intval(Store::getdistance($location['lng'] , $location['lat'] , $lng , $lat)); + } + $length = array_column($list , 'length'); + array_multisort($length , SORT_ASC , $list); + $list = array_splice($list , $page_start , $page_index); + } + else { + //获取排序方式 1 = 创建时间,2 = 店铺距离,3 = 默认设置,4 = 浏览人气 + switch ($order) { + case 1: + $getShopWhere .= " ORDER BY createtime DESC "; + break; + case 3: + $getShopWhere .= " ORDER BY listorder DESC,id DESC "; + break; + case 4: + $getShopWhere .= " ORDER BY pv DESC "; + break; + } + $list = pdo_fetchall("SELECT id FROM " . tablename(PDO_NAME . "merchantdata") . $getShopWhere . " LIMIT {$page_start},{$page_index} "); + } + #3、获取最新的商户信息 + foreach ($list as $key => &$val) { + $goodsInfo = pdo_get(PDO_NAME . "merchantdata" , ['id' => $val['id']] , [ + 'id' , + 'storename' , + 'logo' , + 'address' , + 'storehours' , + 'location' , + 'pv' , + 'score' , + 'panorama' , + 'videourl' , + 'tag', + 'deliverystatus' + ]); + //获取店铺分类信息 + $goodsInfo['panorama'] = !empty($goodsInfo['panorama']) ? 1 : 0; + $goodsInfo['videourl'] = !empty($goodsInfo['videourl']) ? 1 : 0; + //店铺标签 + $goodsInfo['tags'] = []; + $tagids = unserialize($goodsInfo['tag']); + if (!empty($tagids)) { + $tags = pdo_getall('wlmerchant_tags' , ['id' => $tagids] , ['title']); + $goodsInfo['tags'] = $tags ? array_column($tags , 'title') : []; + } + unset($goodsInfo['tag']); + //获取店铺信息地址跳转链接 + $url = h5_url('pages/mainPages/store/index' , ['sid' => $goodsInfo['id']]); + $goodsInfo['shop_url'] = $url; + //处理图片信息 + $goodsInfo['logo'] = tomedia($goodsInfo['logo']); + //处理营业时间 + $storehours = unserialize($goodsInfo['storehours']); + if(!empty($storehours['startTime'])){ + $goodsInfo['storehours'] = $storehours['startTime'] . ' - ' . $storehours['endTime']. " 营业"; + }else{ + $goodsInfo['storehours'] = ''; + foreach($storehours as $hk => $hour){ + if($hk > 0){ + $goodsInfo['storehours'] .= ','.$hour['startTime'] . ' - ' . $hour['endTime']; + }else{ + $goodsInfo['storehours'] .= $hour['startTime'] . ' - ' . $hour['endTime']; + } + } + $goodsInfo['storehours'] .= " 营业"; + } + //处理店铺距离 + $location = unserialize($goodsInfo['location']); + $goodsInfo['length'] = Store::getdistance($location['lng'] , $location['lat'] , $lng , $lat); + if ((!empty($goodsInfo['length']) || is_numeric($goodsInfo['length'])) && $lng && $lat) { + if ($goodsInfo['length'] > 9999998) { + $goodsInfo['distance'] = " "; + } + else if ($goodsInfo['length'] > 1000) { + $goodsInfo['distance'] = (floor(($goodsInfo['length'] / 1000) * 10) / 10) . "km"; + } + else { + $goodsInfo['distance'] = intval($goodsInfo['length']) . "m"; + } + } + //获取店铺分类信息 + $storecates = pdo_getall('wlmerchant_merchant_cate',array('sid' => $val['id'],'twolevel >' => 0),array('twolevel')); + $goodsInfo['catename'] = ''; + if(!empty($storecates)){ + foreach ($storecates as $ke => $cate){ + $catename = pdo_getcolumn(PDO_NAME.'category_store',array('id'=>$cate['twolevel']),'name'); + if($ke > 0){ + $goodsInfo['catename'] .= '|'.$catename; + }else{ + $goodsInfo['catename'] .= $catename; + } + } + } + unset($val['location']); + //查询认证和保证金 + if(p('attestation')){ + $goodsInfo['attestation'] = Attestation::checkAttestation(2,$goodsInfo['id']); + }else{ + $goodsInfo['attestation'] = 0; + } + + + $val = $goodsInfo; + } + #5、获取店铺商品活动信息 + $list = WeliamWeChat::getStoreList($list); + #5、判断是否获取获取总页数 + if ($is_total == 1) { + $total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename(PDO_NAME . "merchantdata") . $getShopWhere); + $data['list'] = $list; + $data['total'] = ceil($total / $page_index); + $this->renderSuccess('店铺列表' , $data); + } + $this->renderSuccess('店铺列表' , $list); + } + /** + * Comment: 获取商户入驻信息 + * Author: wlf + * Date: 2019/8/7 16:11 + */ + public function storeSettled() + { + global $_W , $_GPC; + + $validate = Member::validateMemberIdentity($_W['mid'],false,true); + if (!$validate['status']) $this->renderError($validate['msg']); + + $id = $_GPC['id']; + //获取商户信息 + $data = ['havestore' => 0]; + if (!empty($id)) { + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $id]); + $_W['aid'] = $store['aid']; + $user = pdo_get('wlmerchant_merchantuser' , ['storeid' => $id] , ['name' , 'mobile', 'reject','position']); + $location = unserialize($store['location']); + $storehours = unserialize($store['storehours']); + $adv = unserialize($store['adv']); + $recruitAdv = unserialize($store['recruit_adv']); + if ($adv) { + foreach ($adv as $key => &$aa) { + $aa = tomedia($aa); + } + } else { + $adv = []; + } + if ($recruitAdv) { + foreach ($recruitAdv as $recruitAdvKey => &$recruitAdvVal) { + $recruitAdvVal = tomedia($recruitAdvVal); + } + } else { + $recruitAdv = []; + } + $album = unserialize($store['album']); + if ($album) { + foreach ($album as $key => &$ll) { + $ll = tomedia($ll); + } + } + else { + $album = []; + } + $examineimg = unserialize($store['examineimg']); + if ($examineimg) { + foreach ($examineimg as $key => &$ee) { + $ee = tomedia($ee); + } + } + else { + $examineimg = []; + } + // 企业长图处理 + $recruit_long_img = []; + $recruit_long_img_src = []; + if (!empty($store['recruit_long_img'])) { + $recruit_long_img = explode("||",$store['recruit_long_img']); + foreach ($recruit_long_img as $recruit_long_img_val) $recruit_long_img_src[] = tomedia($recruit_long_img_val); + } + $data['store'] = [ + 'storename' => $store['storename'], + 'position' => $user['position']?:'', + 'name' => $user['name'], + 'mobile' => $user['mobile'] ?: $store['mobile'], + 'provinceid' => $store['provinceid'], + 'areaid' => $store['areaid'], + 'distid' => $store['distid'], + 'address' => $store['address'], + 'lat' => $location['lat'], + 'lng' => $location['lng'], + 'logo' => tomedia($store['logo']), + 'adv' => $adv, + 'album' => $album, + 'examine' => $examineimg, + 'introduction' => htmlspecialchars_decode($store['introduction']), + 'recruit_switch' => $store['recruit_switch'] ? : 0,//是否开启求职招聘功能:0=关闭,1=开启 + 'recruit_nature_id' => $store['recruit_nature_id'] ? : 0,//企业性质id + 'recruit_scale_id' => $store['recruit_scale_id'] ? : 0,//企业性质id + 'recruit_industry_id' => $store['recruit_industry_id'] ? : 0,//企业行业id + 'recruit_adv' => $recruitAdv,//企业幻灯片数组 + 'housekeepstatus' => $store['housekeepstatus'], + 'verkey' => $store['verkey'], + 'deliverystatus' => $store['deliverystatus'], + 'acceptstatus' => $store['acceptstatus'], + 'deliverymoney' => $store['deliverymoney'], + 'deliverydistance' => $store['deliverydistance'], + 'lowdeliverymoney' => $store['lowdeliverymoney'], + 'recruit_brighten' => $store['recruit_brighten'], + 'business_license' => $store['business_license'], + 'recruit_long_img_src'=> $recruit_long_img_src,// 企业长图 + 'recruit_long_img' => $recruit_long_img + ]; + $data['reject'] = $user['reject'] ?: '';# 驳回原因 + if(!empty($store['deliverytype'])){ + $data['store']['deliverytype'] = unserialize($store['deliverytype']); + }else{ + $data['store']['deliverytype'] = ''; + } + if(empty($storehours)){ + $hour['startTime'] = '00:00'; + $hour['endTime'] = '00:00'; + $data['store']['storehours'][] = $hour; + }else{ + if(!empty($storehours['startTime'])){ + $hour['startTime'] = $storehours['startTime']; + $hour['endTime'] = $storehours['endTime']; + $data['store']['storehours'][] = $hour; + }else{ + $data['store']['storehours'] = $storehours; + } + } + } + else { + //判断是否已有店铺 + $havestore = pdo_get(PDO_NAME . 'merchantuser' , [ + 'mid' => $_W['mid'] , + 'ismain' => [1 , 3 , 4] , + 'uniacid' => $_W['uniacid']] + , ['id','storeid']); + if ($havestore && $havestore['storeid']) { + $merchantRes = pdo_get(PDO_NAME . 'merchantdata',['id' => $havestore['storeid'], 'status' => 2]); + if ($merchantRes) $data['havestore'] = 1; + } + # 判断商家是否审核成功 + + } + //获取地区信息 + if ($_W['aid']) { + $areaid = pdo_getcolumn(PDO_NAME . 'oparea' , [ + 'uniacid' => $_W['uniacid'] , + 'aid' => $_W['aid'] + ] , 'areaid'); + } + else { + $areaid = pdo_getcolumn(PDO_NAME . 'oparea' , ['uniacid' => $_W['uniacid'] , 'aid' => 0] , 'areaid'); + } + if($areaid<110100){ + $areaid = 110100; + } + $area = pdo_get('wlmerchant_area' , ['id' => $areaid] , ['pid' , 'name' , 'level']); + if ($area['level'] == 3) { + $data['distid'] = $areaid; + $data['areaid'] = $area['pid']; + $data['provinceid'] = pdo_getcolumn(PDO_NAME . 'area' , ['id' => $data['areaid']] , 'pid'); + } + else if ($area['level'] == 2) { + $data['distid'] = pdo_getcolumn(PDO_NAME . 'area' , ['pid' => $areaid] , 'id'); + $data['areaid'] = $areaid; + $data['provinceid'] = $area['pid']; + } + else { + $data['provinceid'] = $areaid; + $data['areaid'] = pdo_getcolumn(PDO_NAME . 'area' , ['pid' => $areaid] , 'id'); + $data['distid'] = pdo_getcolumn(PDO_NAME . 'area' , ['pid' => $data['areaid']] , 'id'); + } + $citylist = pdo_getall('wlmerchant_area' , ['level' => 1,'visible' => 2] , ['id' , 'name']); + foreach ($citylist as $key => &$prov) { + $prov['area'] = pdo_getall('wlmerchant_area' , ['level' => 2 , 'pid' => $prov['id'],'visible' => 2] , ['id' , 'name']); + foreach ($prov['area'] as $k => &$area) { + $area['dist'] = pdo_getall('wlmerchant_area' , ['level' => 3 , 'pid' => $area['id'],'visible' => 2] , ['id' , 'name']); + } + } + $data['citylist'] = $citylist; + //获取分类信息 + if (empty($_W['aid'])) { + $_W['aid'] = 0; + } + $categoryes = pdo_getall(PDO_NAME . 'category_store' , [ + 'uniacid' => $_W['uniacid'] , + 'aid' => $_W['aid'] , + 'parentid' => 0 , + 'state' => 0 , + 'enabled' => 1 + ] , ['id' , 'name'] , '' , 'displayorder DESC'); + if (!empty($categoryes)) { + foreach ($categoryes as $cid => &$cate) { + $cate['twotype'] = pdo_getall(PDO_NAME . 'category_store' , [ + 'parentid' => $cate['id'] , + 'uniacid' => $_W['uniacid'] , + 'aid' => $_W['aid'] , + 'enabled' => 1 + ] , ['name' , 'id'] , '' , 'displayorder DESC'); + } + } + $data['typelist'] = $categoryes; + //获取客户电话 + $settings = Setting::wlsetting_read('base'); + $agentsettings = Setting::agentsetting_read('agentcustomer'); + $data['systemphone'] = $agentsettings['tel'] ? : $settings['phone']; + //入驻协议 + $register = Setting::wlsetting_read('register'); + $data['describe'] = $register['detail']; + //求职招聘准备信息 + $data['is_recruit'] = 0;//不存在招聘插件 + if(store_p('recruit',$id)){ + $data['nature'] = Recruit::getLabelList(5);//企业性质 + $data['scale'] = Recruit::getLabelList(4);//企业规模 + $data['industry'] = Recruit::getIndustryList(['pid'=>0],['id','title']);//上级行业列表 + $data['is_recruit'] = 1;//存在招聘插件 + } + //家政准备信息 + $data['is_housekeep'] = 0;//不存在招聘插件 + if(store_p('housekeep',$id)){ + $data['store_housekeep_cate'] = Housekeep::getRelation($id,3,1); + $data['all_housekeep_cate'] = Housekeep::getCategory(); + $data['is_housekeep'] = 1;//存在招聘插件 + } + //同城配送准备 + $data['is_delivery'] = 0;//不存在同城配送 + if(store_p('citydelivery',$id)){ + $data['is_delivery'] = 1;//存在同城配送 + } + + //获取商户入驻顶部图片 + $storeSet = Setting::wlsetting_read('agentsStoreSet'); + $data['top_img'] = tomedia($storeSet['top_img']); + $data['top_link'] = $storeSet['top_link']; + + $this->renderSuccess('商户信息' , $data); + } + /** + * Comment: 通过地区id更换分类 + * Author: wlf + * Date: 2019/8/7 18:30 + */ + public function area2type() + { + global $_W , $_GPC; + $provinceid = $_GPC['provinceid']; + $areaid = $_GPC['areaid']; + $distid = $_GPC['distid']; + $aid = pdo_getcolumn(PDO_NAME . 'oparea' , ['uniacid' => $_W['uniacid'] , 'areaid' => $distid] , 'aid'); + if (empty($aid)) { + $aid = pdo_getcolumn(PDO_NAME . 'oparea' , ['uniacid' => $_W['uniacid'] , 'areaid' => $areaid] , 'aid'); + } + if (empty($aid)) { + $aid = pdo_getcolumn(PDO_NAME . 'oparea' , ['uniacid' => $_W['uniacid'] , 'areaid' => $provinceid] , 'aid'); + } + if (empty($aid)) { + $aid = 0; + } + $categoryes = pdo_getall(PDO_NAME . 'category_store' , [ + 'uniacid' => $_W['uniacid'] , + 'aid' => $aid , + 'parentid' => 0 , + 'state' => 0, + 'enabled' => 1 + ] , ['id' , 'name'] , '' , 'displayorder DESC'); + if (!empty($categoryes)) { + foreach ($categoryes as $cid => &$cate) { + $cate['twotype'] = pdo_getall(PDO_NAME . 'category_store' , [ + 'parentid' => $cate['id'] , + 'uniacid' => $_W['uniacid'] , + 'aid' => $aid, + 'state' => 0, + 'enabled' => 1 + ] , ['name' , 'id'] , '' , 'displayorder DESC'); + } + } + $this->renderSuccess('商户分类信息' , $categoryes); + } + /** + * Comment: 创建商户和店长 + * Author: wlf + * Date: 2019/8/8 09:40 + */ + public function createStore() + { + global $_W , $_GPC; + $set = Setting::wlsetting_read('register'); + $data = []; + $data['storename'] = $_GPC['storename']; + $sale_id = intval($_GPC['sale_id']); + if (empty($data['storename'])) { + $this->renderError('请输入商户名'); + } + $textRes = Filter::init($data['storename'],$_W['source'],1); + if($textRes['errno'] == 0){ + $this->renderError('商户名'.$textRes['message']); + } + if (empty($_GPC['business_license'])) $this->renderError('请上传营业执照'); + if ($_GPC['recruit_switch'] == 1) { + if (empty($_GPC['recruit_brighten'])) $this->renderError('请填写企业亮点'); + $count = preg_match_all("/[\x{4e00}-\x{9fa5}]/u", $_GPC['recruit_brighten']); + if ($count > 20) $this->renderError('企业亮点最多填写20个汉字'); + $textRes = Filter::init($_GPC['recruit_brighten'],$_W['source'],1); + if($textRes['errno'] == 0) $this->renderError('企业亮点'.$textRes['message']); + } + $storeid = $_W['storeid']; + // 每个账号只能有一个店铺限制 + if (empty($storeid)) { + $merchantExists = pdo_get(PDO_NAME . 'merchantuser',['mid' => $_W['mid']],['storeid']); + if ($merchantExists) { + $storeid = $merchantExists['storeid']; + $storeData = pdo_get(PDO_NAME . 'merchantdata',['id' => $storeid,'status' => 2]); + if ($storeData) $this->renderError('当前用户已申请企业,请勿重复申请'); + } + } + $position = trim($_GPC['position']); + if (empty($position)) { + $this->renderError('请填写职务'); + } else { + $positionRes = Filter::init($position,$_W['source'],1); + if($positionRes['errno'] == 0) $this->renderError('职务'.$positionRes['message']); + } + //获取商户数据 + $data['realname'] = trim($_GPC['name']); + $data['mobile'] = $_GPC['mobile']; + $data['logo'] = $_GPC['logo']; + $adv = $_GPC['adv']; + if (!empty($adv)) { + $data['adv'] = serialize(explode(',' , $adv)); + } + else { + $data['adv'] = ''; + } + $album = $_GPC['album']; + if (!empty($album)) { + $data['album'] = serialize(explode(',' , $album)); + } + else { + $data['album'] = ''; + } + $examineimg = $_GPC['examine']; + if (!empty($examineimg)) { + $data['examineimg'] = serialize(explode(',' , $examineimg)); + } + else { + $data['examineimg'] = ''; + } + $recruit_long_img = ''; + if (is_array($_GPC['recruit_long_img'])) { + $recruit_long_img = implode('||',$_GPC['recruit_long_img']); + } elseif (is_string($_GPC['recruit_long_img'])) { + $recruit_long_img = str_replace(',','||',$_GPC['recruit_long_img']); + } + if (!empty($recruit_long_img)) { + # 验证合法性 + $recruit_long_img_arr = explode("||",$recruit_long_img); + foreach ($recruit_long_img_arr as $img) { + $imgRes = Filter::init($img,$_W['source'],2); + if($imgRes['errno'] == 0) $this->renderError('企业长图'.$imgRes['message']); + } + } + $data['location'] = serialize(['lng' => $_GPC['lng'] , 'lat' => $_GPC['lat']]); + $data['lng'] = $_GPC['lng']; + $data['lat'] = $_GPC['lat']; + $data['provinceid'] = $_GPC['provinceid']; + $data['areaid'] = $_GPC['areaid']; + $data['distid'] = $_GPC['distid']; + $data['address'] = $_GPC['address']; + $data['introduction'] = $_GPC['detail'];//店铺简介 + $data['verkey'] = $_GPC['verkey'];//核销密码 + + //招聘 + $data['recruit_switch'] = $_GPC['recruit_switch'] ? : 0;//是否开启求职招聘功能:0=关闭,1=开启 + $data['recruit_nature_id'] = $_GPC['recruit_nature_id'] ? : 0;//企业性质 + $data['recruit_scale_id'] = $_GPC['recruit_scale_id'] ? : 0;//企业规模 + $data['recruit_industry_id'] = $_GPC['recruit_industry_id'];//企业行业 + $data['recruit_brighten'] = $_GPC['recruit_brighten'];//企业亮点 + $data['recruit_long_img'] = $recruit_long_img;//企业长图 + $data['business_license'] = $_GPC['business_license'];//企业营业执照 + $recruitAdv = $_GPC['recruit_adv']; + $data['recruit_adv'] = $recruitAdv ? serialize(explode(',',$recruitAdv)) : '';//企业幻灯片 + //家政 + $data['housekeepstatus'] = $_GPC['housekeepstatus']; + $housekeepcate = json_decode(base64_decode($_GPC['store_housekeep_cate']),true); + $data['storehours'] = serialize(json_decode(base64_decode($_GPC['storehours']),true)); + //配送 + $data['deliverystatus'] = $_GPC['deliverystatus']; + $data['acceptstatus'] = $_GPC['acceptstatus']; + $data['deliverymoney'] = $_GPC['deliverymoney']; + $data['deliverydistance'] = $_GPC['deliverydistance']; + $data['lowdeliverymoney'] = $_GPC['lowdeliverymoney']; + $data['deliverytype'] = $_GPC['deliverytype'] ? serialize(explode(',',$_GPC['deliverytype'])) : '';//配送方式 + if ($storeid) { + Tools::clearwxapp(); + Tools::clearposter(); + $storestatus = pdo_get(PDO_NAME . 'merchantdata' , ['id' => $storeid] , ['status' , 'aid']); + $alflag = pdo_fetch("SELECT id FROM " . tablename('wlmerchant_merchantdata') . "WHERE uniacid = {$_W['uniacid']} AND aid = {$storestatus['aid']} AND storename = {$data['storename']} AND id != {$storeid}"); + if ($alflag) { + $this->renderError('该商户已入驻,请更换商户名'); + } + if ($storestatus['status'] == 3) { + $data['status'] = 1; + $userdata['status'] = 1; + //发送消息 + $first = '您好,' . $_GPC['name'] . '修改了新商家入驻信息'; + $type = '店铺入驻资料修改'; + $content = '店铺名:[' . $data['storename'] . ']'; + $status = '待审核'; + $remark = '请尽快前往系统后台审核商家资料'; + News::noticeAgent('storesettled' , $storestatus['aid'] , $first , $type , $content , $status , $remark , time()); + } + pdo_update(PDO_NAME . 'merchantdata' , $data , ['id' => $storeid]); + //插入分类 + pdo_delete('wlmerchant_merchant_cate' , ['sid' => $storeid]); + $cateidArray = json_decode(base64_decode($_GPC['cateidArray']),true); + foreach ($cateidArray as $cate){ + $resss = pdo_insert('wlmerchant_merchant_cate' , [ + 'sid' => $storeid , + 'onelevel' => intval($cate['onelevel']) , + 'twolevel' => intval($cate['twolevel']) + ]); + } + $userdata['name'] = $_GPC['name']; + $userdata['mobile'] = $_GPC['mobile']; + $userdata['position'] = $position; + $userdata['createtime'] = time(); + pdo_update(PDO_NAME . 'merchantuser' , $userdata , ['storeid' => $storeid , 'ismain' => 1]); + //处理家政服务分类 + pdo_delete('wlmerchant_housekeep_relation', array('type' => 3,'objid' => $storeid)); + foreach ($housekeepcate as $item) { + $scate = pdo_get(PDO_NAME . 'housekeep_type', array('id' => $item), array('onelevelid')); + pdo_insert('wlmerchant_housekeep_relation', ['type' => 3,'objid' => $storeid, 'onelevelid' => $scate['onelevelid'], 'twolevelid' => $item]); + } + + Member::updateStoreUserIdentity($storeid,1); + # 判断是否跳转支付页面 + $jump_pay = in_array($storestatus['status'],[1,2,3]) ? 0 : 1; + $this->renderSuccess('提交成功' , ['storeid' => $storeid,'jump_pay' => $jump_pay]); + } else { + $validate = Member::validateMemberIdentity($_W['mid']); + if (!$validate['status']) $this->renderError($validate['msg']); + //详情 + $data['introduction'] = $_GPC['introduction']; + $storethumb = $_GPC['thumbimages']; + if ($storethumb) { + $storethumb = explode(',' , $storethumb); + foreach ($storethumb as $key => $th) { + $th = tomedia($th); + $data['introduction'] .= ''; + } + } + if (!empty($data['introduction'])) { + $data['introduction'] = htmlspecialchars_decode($data['introduction']); + } + $data['uniacid'] = $_W['uniacid']; + $aid = pdo_getcolumn(PDO_NAME . 'oparea' , [ + 'uniacid' => $_W['uniacid'] , + 'areaid' => $data['distid'] , + 'status' => 1 + ] , 'aid'); + if (empty($aid)) { + $aid = pdo_getcolumn(PDO_NAME . 'oparea' , [ + 'uniacid' => $_W['uniacid'] , + 'areaid' => $data['areaid'] , + 'status' => 1 + ] , 'aid'); + } + if (empty($aid)) { + $aid = pdo_getcolumn(PDO_NAME . 'oparea' , [ + 'uniacid' => $_W['uniacid'] , + 'areaid' => $data['provinceid'] , + 'status' => 1 + ] , 'aid'); + } + if (empty($aid)) { + $aid = 0; + } + $data['aid'] = $_W['aid'] ? $_W['aid'] : $aid; + $alflag = pdo_get('wlmerchant_merchantdata' , [ + 'storename' => $data['storename'] , + 'uniacid' => $_W['uniacid'], + 'aid' => $data['aid'] + ] , ['id']); + if ($alflag) { + $this->renderError('该商户已入驻,请更换商户名'); + } + $data['createtime'] = time(); + //设置默认商户状态为 未支付 + $data['status'] = 0; + $data['endtime'] = time(); + $data['enabled'] = 0; + $data['score'] = 5; + $data['groupid'] = 0; + $storeid = Store::registerEditData($data , 0); + if (empty($storeid)) { + $this->renderError('商户创建失败,请重试!' , $data); + } + //插入分类 + $cateidArray = json_decode(base64_decode($_GPC['cateidArray']),true); + foreach ($cateidArray as $cate){ + $resss = pdo_insert('wlmerchant_merchant_cate' , [ + 'sid' => $storeid , + 'onelevel' => intval($cate['onelevel']) , + 'twolevel' => intval($cate['twolevel']) + ]); + } + //处理家政服务分类 + pdo_delete('wlmerchant_housekeep_relation', array('type' => 3,'objid' => $storeid)); + foreach ($housekeepcate as $item) { + $scate = pdo_get(PDO_NAME . 'housekeep_type', array('id' => $item), array('onelevelid')); + $res = pdo_insert('wlmerchant_housekeep_relation', ['type' => 3,'objid' => $storeid, 'onelevelid' => $scate['onelevelid'], 'twolevelid' => $item]); + } + $arr['storeid'] = $storeid; + $arr['name'] = trim($_GPC['name']); + $arr['mobile'] = $_GPC['mobile']; + $arr['createtime'] = time(); + if (empty($data['areaid'])) { + $arr['areaid'] = $_W['areaid']; + } + else { + $arr['areaid'] = $data['areaid']; + } + $arr['status'] = 1; + $arr['enabled'] = 1; + $arr['ismain'] = 1; + $arr['uniacid'] = $_W['uniacid']; + $arr['aid'] = $_W['aid'] ? $_W['aid'] : $aid; + $re = Store::saveSingleRegister($arr , 0); + $data['storeid'] = $storeid; + $data['chargeflag'] = 1; + $data['jump_pay'] = 1; + if (empty($re)) { + $this->renderError('店铺管理员创建失败,请重试!'); + } + //添加业务员 + if(!empty($sale_id > 0 && $_GPC['sale_id'] != $_W['mid'])){ + $_W['aid'] = $aid; + $saleset = Setting::agentsetting_read('salesman'); + if($saleset['isopen']>0){ + $salemember = pdo_get('wlmerchant_member',array('id' => intval($sale_id)),array('realname','nickname','mobile')); + $saledata = array( + 'mid' => $sale_id, + 'storeid' => $storeid, + 'name' => $salemember['realname'] ? $salemember['realname'] : $salemember['nickname'], + 'mobile' => $salemember['mobile'], + 'enabled' => 1, + 'uniacid' => $_W['uniacid'], + 'aid' => $aid, + 'ismain' => 4, + 'position' => $position, + 'createtime' => time() + ); + pdo_insert('wlmerchant_merchantuser', $saledata); + } + } + $this->renderSuccess('创建企业成功' , $data); + } + } + /** + * Comment: 获取付费入驻列表 + * Author: wlf + * Date: 2019/8/8 10:52 + */ + public function chargeList() + { + global $_W , $_GPC; + $settings = Setting::wlsetting_read('register'); + $storeid = $_GPC['storeid']; + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid] , ['aid' , 'status']); + if ($store['status'] == 2) { + $chargetypes = pdo_fetchall("SELECT * FROM " . tablename('wlmerchant_chargelist') . "WHERE uniacid = {$_W['uniacid']} AND status = 1 AND renewstatus = 1 AND aid IN (0,{$store['aid']}) ORDER BY sort DESC"); + } + else { + $chargetypes = pdo_fetchall("SELECT * FROM " . tablename('wlmerchant_chargelist') . "WHERE uniacid = {$_W['uniacid']} AND status = 1 AND aid IN (0,{$store['aid']}) ORDER BY sort DESC"); + } + $data['typelist'] = $chargetypes; + $data['describe'] = $settings['description']; + $this->renderSuccess('付费类型列表' , $data); + } + /** + * Comment: 生成商户入驻付费订单 + * Author: wlf + * Date: 2019/8/8 14:07 + */ + public function createChargeOrder() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $typeid = $_GPC['typeid']; + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid]); + $chargetype = pdo_get('wlmerchant_chargelist' , ['id' => $typeid]); + if (empty($chargetype)) { + $this->renderError('请选择商户入驻类型'); + } + if (empty($store)) { + $this->renderError('商户ID未传入或已被删除'); + } + //判断绑定手机 + $mastmobile = unserialize($_W['wlsetting']['userset']['plugin']); + if (empty($_W['wlmember']['mobile']) && in_array('charge' , $mastmobile)) { + $this->renderError('未绑定手机号'); + } + if (intval($chargetype['audits']) == 1) { + pdo_update(PDO_NAME.'merchantdata',['audits' => 1],['id' => $storeid]); + }else{ + pdo_update(PDO_NAME.'merchantdata',['audits' => 0],['id' => $storeid]); + } + if ($chargetype['price'] > 0) { + $data = [ + 'uniacid' => $store['uniacid'] , + 'mid' => $_W['mid'] , + 'aid' => $store['aid'] , + 'fkid' => $typeid , + 'sid' => $storeid , + 'status' => 0 , + 'paytype' => 0 , + 'createtime' => time() , + 'orderno' => createUniontid() , + 'price' => $chargetype['price'] , + 'num' => $chargetype['days'] , + 'plugin' => 'store' , + 'payfor' => 'merchant' + ]; + $res = pdo_insert(PDO_NAME . 'order' , $data); + $orderid = pdo_insertid(); + $data['orderid'] = $orderid; + $data['status'] = 1; + $this->renderSuccess('订单生成成功' , $data); + } + else { + $endtime = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $storeid] , 'endtime'); + $groupid = $typeid; + if ($endtime > time()) { + $newendtime = $chargetype['days'] * 24 * 3600 + $endtime; + } + else { + $newendtime = $chargetype['days'] * 24 * 3600 + time(); + } + $merstatus = pdo_getcolumn(PDO_NAME.'merchantdata',array('id'=>$storeid),'status'); + //audits 0=要审核 1=不审核 + if (intval($chargetype['audits']) == 1 || $merstatus == 2) { + pdo_update(PDO_NAME . 'merchantdata' , [ + 'status' => 2 , + 'endtime' => $newendtime , + 'enabled' => 1 , + 'audits' => 1 , + 'groupid' => $groupid + ] , ['id' => $storeid]); //更新商户 + pdo_update(PDO_NAME . 'merchantuser' , ['status' => 2] , ['storeid' => $storeid]); //更新管理员 + }else { + pdo_update(PDO_NAME . 'merchantdata' , [ + 'status' => 1 , + 'endtime' => $newendtime , + 'groupid' => $groupid + ] , ['id' => $storeid]); //更新商户(待审核) + $appname = pdo_getcolumn(PDO_NAME . 'merchantuser' , ['storeid' => $storeid , 'ismain' => 1] , 'name'); + $agentname = pdo_getcolumn(PDO_NAME . 'agentusers' , ['id' => $store['aid']] , 'agentname'); + $first = '您好,'. $appname . '申请了新商家入驻'; + $type = '店铺申请入驻'; + $content = '店铺名:['.$store['storename'] .']'; + $status = '待审核'; + $time = time(); + $remark = '入驻代理:['.$agentname.'],请尽快前往系统后台审核商家资料'; + News::noticeAgent('storesettled',$store['aid'],$first,$type,$content,$status,$remark,$time); + } + $data['status'] = 0; + $this->renderSuccess('入驻成功' , $data); + } + } + /** + * Comment: 获取店员信息 + * Author: wlf + * Date: 2019/8/8 15:34 + */ + public function adminInfo() + { + global $_W , $_GPC; + $data = []; + $adminid = $_GPC['adminid']; + $storeid = $_GPC['storeid']; + $newadminid = $_GPC['newadminid']; + if ($newadminid > 0) { + $newadmin = pdo_get('wlmerchant_member' , ['id' => $newadminid] , [ + 'nickname' , + 'avatar' , + 'mobile' + ]); + $newadmin['name'] = $newadmin['nickname']; + $newadmin['avatar'] = tomedia($newadmin['avatar']); + $newadmin['enabled'] = 0; + $newadmin['ismain'] = 2; + $newadmin['orderwrite'] = 0; + $newadmin['viewdata'] = 0; + $data['admin'] = $newadmin; + $this->renderSuccess('新店员数据' , $data); + } + else if ($adminid > 0) { + $admin = pdo_get('wlmerchant_merchantuser' , ['id' => $adminid] , [ + 'mobile' , + 'mid' , + 'enabled' , + 'name' , + 'ismain' , + 'orderwrite' , + 'viewdata' + ]); + $admin['avatar'] = pdo_getcolumn(PDO_NAME . 'member' , ['id' => $admin['mid']] , 'avatar'); + $admin['avatar'] = tomedia($admin['avatar']); + $data['admin'] = $admin; + $this->renderSuccess('店员数据' , $data); + } + else { + $storeSet = Setting::wlsetting_read('agentsStoreSet'); + if($storeSet['admin_apply'] > 0){ + $filename = md5('sid'.$storeid.'source'.$_W['source'].'adminapply');//保证图片唯一性,每种渠道,类型海报二维码都不一致 + $path = 'pages/subPages/merchant/bindingClerk/bindingClerk?sid='.$storeid; + if ($_W['source'] == 3) { + $qrCodeLink = WeApp::getQrCode($path , 'qrcode_' . $filename . '.png'); + if (is_array($qrCodeLink)) $qrCodeLink = Poster::qrcodeimg($path , $filename); + }else{ + $path = h5_url($path);//非小程序渠道 基本路径转超链接 + $qrCodeLink = Poster::qrcodeimg($path , $filename); + } + $data['src'] = tomedia($qrCodeLink) ; + }else{ + $qrcode = time(); + if ($_W['source'] == 3) { //小程序 + $showurl = 'pages/subPages/merchant/merchantSuccess/merchantSuccess?codes=' . $qrcode . '&storeid=' . $storeid; + $logo = tomedia(pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $storeid] , 'logo')); + $src = tomedia(Store::getShopWxAppQrCode($storeid , $logo , $showurl)); + } + else { + $showurl = h5_url('pages/subPages/merchant/merchantSuccess/merchantSuccess' , [ + 'codes' => $qrcode , + 'storeid' => $storeid + ]); //暂无页面 + $src = WeliamWeChat::getQrCode($showurl); + } + $data['src'] = $src; + $data['qrcode'] = $qrcode; + pdo_insert(PDO_NAME . 'merchantuser_qrlog' , [ + 'uniacid' => $_W['uniacid'] , + 'codes' => $qrcode , + 'createtime' => $qrcode + ]); + pdo_delete(PDO_NAME . 'merchantuser_qrlog' , [ + 'uniacid' => $_W['uniacid'] , + 'createtime <' => $qrcode - 300 , + 'status !=' => 1 + ]); + } + + $this->renderSuccess('入驻二维码' , $data); + } + } + /** + * Comment: 店员扫码后页面 + * Author: wlf + * Date: 2019/09/25 16:41 + */ + public function adminSurePage() + { + global $_W , $_GPC; + $qrcode = $_GPC['codes']; + $storeid = $_GPC['storeid']; + if (empty($qrcode) || empty($storeid)) { + $this->renderError('缺少重要参数,请重新扫描二维码'); + } + $store = Store::getSingleStore($storeid); + $data['storename'] = $store['storename']; + $this->renderSuccess('扫码成功' , $data); + } + /** + * Comment: 确认成为店员接口 + * Author: wlf + * Date: 2019/09/25 16:53 + */ + public function adminSureAPI() + { + global $_W , $_GPC; + $qrcode = $_GPC['codes']; + if (empty($qrcode)) { + $this->renderError('缺少重要参数,请重新扫描二维码'); + } + $item = pdo_get(PDO_NAME . 'merchantuser_qrlog' , ['uniacid' => $_W['uniacid'] , 'codes' => $qrcode]); + $itemtime = $item['createtime'] + 300; + if (empty($item) || $itemtime < time() || $item['status'] == 1) { + $this->renderError('二维码过期,请刷新生成新的二维码'); + } + $res = pdo_update(PDO_NAME . 'merchantuser_qrlog' , [ + 'memberid' => $_W['mid'] , + 'status' => 1 + ] , ['id' => $item['id']]); + if ($res) { + $this->renderSuccess('修改成功'); + } + else { + $this->renderError('修改失败,请刷新重试'); + } + } + /** + * Comment: 验证店员是否扫码 + * Author: wlf + * Date: 2019/8/8 16:07 + */ + public function adminAjax() + { + global $_W , $_GPC; + $qrcode = $_GPC['qrcode']; + $item = pdo_get(PDO_NAME . 'merchantuser_qrlog' , ['uniacid' => $_W['uniacid'] , 'codes' => $qrcode]); + $itemtime = $item['createtime'] + 300; + if (empty($item) || $itemtime < time()) { + $this->renderError('二维码过期'); + } + if ($item['status']) { + $data = pdo_get(PDO_NAME . "member" , ['id' => $item['memberid']] , ['avatar' , 'nickname' , 'id']); + $this->renderSuccess('扫码人信息' , $data); + } + $this->renderSuccess('暂未扫码'); + } + /** + * Comment: 保存店员信息 + * Author: wlf + * Date: 2019/8/8 16:57 + */ + public function createAdmin() + { + global $_W , $_GPC; + $id = intval($_GPC['adminid']); + $storeid = $_GPC['storeid']; + $storeaid = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $storeid] , 'aid'); + if (empty($_GPC['ismain'])) { + $this->renderError('请选择店员类型'); + } + if ($id) { + $data = [ + 'name' => $_GPC['name'] , + 'mobile' => $_GPC['mobile'] , + 'ismain' => $_GPC['ismain'] , + 'orderwrite' => $_GPC['orderwrite'] , + 'viewdata' => $_GPC['viewdata'] , + 'enabled' => $_GPC['enabled'] + ]; + if (pdo_update(PDO_NAME . 'merchantuser' , $data , ['id' => $id])) { + $this->renderSuccess('店员修改成功'); + } + else { + $this->renderError('店员修改失败,请重试'); + } + } + else { + $flag = pdo_getcolumn(PDO_NAME . 'merchantuser' , [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $_GPC['mid'] , + 'storeid' => $storeid + ] , 'id'); + if ($flag) { + $this->renderError('此用户已是店员,请勿重复添加'); + } + else { + $data = [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $_GPC['mid'] , + 'storeid' => $storeid , + 'name' => $_GPC['name'] , + 'mobile' => $_GPC['mobile'] , + 'areaid' => $_W['areaid'] , + 'createtime' => time() , + 'status' => 2 , + 'enabled' => $_GPC['enabled'] , + 'aid' => $storeaid , + 'ismain' => $_GPC['ismain'] , + 'orderwrite' => $_GPC['orderwrite'] , + 'viewdata' => $_GPC['viewdata'] + ]; + if (pdo_insert(PDO_NAME . 'merchantuser' , $data)) { + $this->renderSuccess('店员添加成功'); + } + else { + $this->renderError('店员添加失败,请重试'); + } + } + } + } + /** + * Comment: 店铺店员列表 + * Author: wlf + * Date: 2019/8/8 17:06 + */ + public function adminList() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + if (empty($storeid)) { + $storeid = $_W['storeid']; + } + $list = pdo_fetchall("SELECT id,mid,name,mobile,ismain,enabled FROM " . tablename('wlmerchant_merchantuser') . "WHERE uniacid = {$_W['uniacid']} AND storeid = {$storeid} ORDER BY id ASC"); + foreach ($list as $key => &$li) { + $avatar = pdo_getcolumn(PDO_NAME . 'member' , ['id' => $li['mid']] , 'avatar'); + $li['avatar'] = tomedia($avatar); + } + $this->renderSuccess('店员列表' , $list); + } + /** + * Comment: 商户中心信息 + * Author: wlf + * Date: 2019/8/8 17:46 + */ + public function storeInfo() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $store = Store::getSingleStore($storeid); + if (empty($store)) { + $this->renderError('商户不存在,请重试'); + } + $authority = pdo_getcolumn('wlmerchant_chargelist' , ['id' => $store['groupid']] , 'authority'); + $authority = unserialize($authority); + // 特殊商品类型 + $where_cc = ''; + if (!empty($_GPC['cc_id']) && $_GPC['cc_id'] > 0) { + $where_cc = "AND activityid IN (SELECT id FROM ".tablename(PDO_NAME . "rush_activity")." WHERE sid = {$storeid} AND uniacid = {$_W['uniacid']} AND cc_id = '{$_GPC['cc_id']}')"; + } + //数据统计 + $time = strtotime(date("Y-m-d") , time()); + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$time} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$time} {$where_cc}"); + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$time} AND plugin != 'store' "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$time} AND plugin != 'store' "); + $todaymoney = sprintf("%.2f" , $rushordermoney + $ordermoney); + $todayordernum = sprintf("%.0f" , $ordernum + $rushordernum); + $newsnum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "im") . " WHERE uniacid = {$_W['uniacid']} AND receive_type = 2 AND receive_id = {$storeid} AND is_read = 0"); + $data = [ + 'todaymoney' => $todaymoney , + 'todayordernum' => $todayordernum , + 'newsnum' => $newsnum , + ]; + if(p('citydelivery')){ + if((in_array('citydelivery',$authority) || empty($authority)) && $store['deliverystatus'] > 0 ){ + $data['showDelivery'] = 1; + $data['deliveryName'] = pdo_getcolumn(PDO_NAME.'plugin',array('name'=>'citydelivery'),'title'); + }else{ + $data['showDelivery'] = 0; + } + }else{ + $data['showDelivery'] = 0; + } + //图标数据 + $timetype = $_GPC['timetype'] ? $_GPC['timetype'] : 1; //1今天 2昨天 3 最近7日 4最近30天 5自定义 + $plugin = $_GPC['plugin']; + $type = $_GPC['type'] ? $_GPC['type'] : 1; // 1 支付金额 2支付单数 + $chart = []; + if (!empty($plugin) && $plugin != 'rush') { + $where = " AND plugin = '" . $plugin . "'"; + } + if ($timetype == 1) { + $h = date('H' , time()); + $zreo = strtotime(date("Y-m-d") , time()); + $chart['xaxis'][] = '0:00'; + $chart['yaxis'][] = '0.00'; + for ($start = 0 ; $start <= $h ; $start++) { + $starttime = $zreo + $start * 3600; + $endtime = $starttime + 3600; + if (!empty($plugin) && $plugin == 'rush') { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = 0; + $ordernum = 0; + } + else if (!empty($plugin)) { + $rushordermoney = 0; + $rushordernum = 0; + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + } + else { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + } + $money = sprintf("%.2f" , $rushordermoney + $ordermoney); + $ordernum = sprintf("%.0f" , $ordernum + $rushordernum); + $chart['xaxis'][] = ($start + 1) . ':00'; + if ($type == 1) { + $chart['yaxis'][] = $money; + } + else { + $chart['yaxis'][] = $ordernum; + } + } + } + else if ($timetype == 2) { + $zreo = strtotime(date("Y-m-d") , time()) - 86400; + $chart['xaxis'][] = '0:00'; + $chart['yaxis'][] = '0.00'; + for ($start = 0 ; $start <= 23 ; $start++) { + $starttime = $zreo + $start * 3600; + $endtime = $starttime + 3600; + if (!empty($plugin) && $plugin == 'rush') { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = 0; + $ordernum = 0; + } + else if (!empty($plugin)) { + $rushordermoney = 0; + $rushordernum = 0; + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + } + else { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + } + $money = sprintf("%.2f" , $rushordermoney + $ordermoney); + $ordernum = sprintf("%.0f" , $ordernum + $rushordernum); + $chart['xaxis'][] = ($start + 1) . ':00'; + if ($type == 1) { + $chart['yaxis'][] = $money; + } + else { + $chart['yaxis'][] = $ordernum; + } + } + } + else if ($timetype == 3) { + $zreo = strtotime(date("Y-m-d") , time()) - 86400 * 6; + for ($start = 0 ; $start <= 6 ; $start++) { + $starttime = $zreo + $start * 86400; + $endtime = $starttime + 86400; + if (!empty($plugin) && $plugin == 'rush') { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = 0; + $ordernum = 0; + } + else if (!empty($plugin)) { + $rushordermoney = 0; + $rushordernum = 0; + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + } + else { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + } + $money = sprintf("%.2f" , $rushordermoney + $ordermoney); + $ordernum = sprintf("%.0f" , $ordernum + $rushordernum); + $chart['xaxis'][] = date('m-d' , $starttime); + if ($type == 1) { + $chart['yaxis'][] = $money; + } + else { + $chart['yaxis'][] = $ordernum; + } + } + } + else if ($timetype == 4) { + $zreo = strtotime(date("Y-m-d") , time()) - 86400 * 29; + for ($start = 0 ; $start <= 29 ; $start++) { + $starttime = $zreo + $start * 86400; + $endtime = $starttime + 86400; + if (!empty($plugin) && $plugin == 'rush') { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = 0; + $ordernum = 0; + } + else if (!empty($plugin)) { + $rushordermoney = 0; + $rushordernum = 0; + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + } + else { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + } + $money = sprintf("%.2f" , $rushordermoney + $ordermoney); + $ordernum = sprintf("%.0f" , $ordernum + $rushordernum); + $chart['xaxis'][] = date('m-d' , $starttime); + if ($type == 1) { + $chart['yaxis'][] = $money; + } + else { + $chart['yaxis'][] = $ordernum; + } + } + } + else if ($timetype == 5) { + $time = $_GPC['time']; + $times = explode(',' , $time); + $starttime = $times[0]; + $endtime = $times[1] + 86399; + $zreo = $starttime; + $days = floor(($endtime - $starttime) / 86400); + for ($start = 0 ; $start <= $days ; $start++) { + $starttime = $zreo + $start * 86400; + $endtime = $starttime + 86400; + if (!empty($plugin) && $plugin == 'rush') { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = 0; + $ordernum = 0; + } + else if (!empty($plugin)) { + $rushordermoney = 0; + $rushordernum = 0; + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' {$where} "); + } + else { + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM' . tablename(PDO_NAME . "rush_order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} {$where_cc}"); + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "order") . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND paytime > {$starttime} AND paytime <= {$endtime} AND plugin != 'store' "); + } + $money = sprintf("%.2f" , $rushordermoney + $ordermoney); + $ordernum = sprintf("%.0f" , $ordernum + $rushordernum); + $chart['xaxis'][] = date('m-d' , $starttime); + if ($type == 1) { + $chart['yaxis'][] = $money; + } + else { + $chart['yaxis'][] = $ordernum; + } + } + } + $data['chart'] = $chart; + $data['typelist'] = [0 => '全部' , 'rush' => '抢购' , 'coupon' => '卡券']; + if (p('wlfightgroup')) { + $data['typelist']['wlfightgroup'] = '拼团'; + } + if (p('groupon')) { + $data['typelist']['groupon'] = '团购'; + } + if (p('halfcard')) { + $data['typelist']['halfcard'] = '买单'; + } + if (p('bargain')) { + $data['typelist']['bargain'] = '砍价'; + } + $data['maxY'] = max($chart['yaxis']); + $data['minY'] = min($chart['yaxis']); + $this->renderSuccess('店铺信息' , $data); + } + /** + * Comment: 商户详细信息 + * Author: zzw + * Date: 2019/8/19 18:17 + */ + public function detail() + { + global $_W , $_GPC; + #1、参数接收 + $sid = $_GPC['sid'] OR $this->renderError("缺少参数:商户id");;//商户id + $lng = $_GPC['lng'] ? $_GPC['lng'] : 0;//104.0091133118 经度 + $lat = $_GPC['lat'] ? $_GPC['lat'] : 0;//30.5681964123 纬度 + //排序设置 + $storeSet = Setting::wlsetting_read('agentsStoreSet'); + if(empty($storeSet['order'])){ + $order = [ + 'sporder' => 8, + 'spstatus' => 1, + 'xqorder' => 7, + 'xqstatus' => 1, + 'dtorder' => 6, + 'dtstatus' => 1, + 'plorder' => 5, + 'plstatus' => 1, + 'xcorder' => 4, + 'xcstatus' => 1, + 'xcxmorder' => 3, + 'xcxmstatus' => 1, + 'sjzzorder' => 2, + 'sjzzstatus' => 1, + 'zporder' => 1, + 'zpstatus' => 1, + ]; + }else{ + $order = unserialize($storeSet['order']); + } + + #2、获取商户详细信息 + $info = pdo_get(PDO_NAME . "merchantdata" , ['id' => $sid] , [ + 'id' , + 'videourl' , + 'panorama' , + 'adv' , + 'logo' , + 'storename' , + 'score' , + 'pv' , + 'storehours' , + 'address' , + 'mobile' , + 'introduction' , + 'album' , + 'location' , + 'payonline' , + 'wxappswitch' , + 'tag' , + 'describe', + 'deliverystatus', + 'proportion', + 'communityid' + ]); + if (!$info) $this->renderError("商户不存在!"); + $info['logo'] = tomedia($info['logo']); + $info['introduction'] = htmlspecialchars_decode($info['introduction']); + $info['location'] = unserialize($info['location']); + //幻灯片的处理 + $info['adv'] = unserialize($info['adv']); + foreach ($info['adv'] as $advK => &$advV) { + $advV = tomedia($advV); + } + //营业时间的处理 + $storehours = unserialize($info['storehours']); + $info['is_business'] = Store::getShopBusinessStatus($storehours,$sid);//判断商户当前状态:0=休息中,1=营业中 + if(!empty($storehours['startTime'])){ + $info['storehours'] = $storehours['startTime'] . ' - ' . $storehours['endTime']; + }else{ + $info['storehours'] = ''; + foreach($storehours as $hk => $hour){ + if($hk > 0){ + $info['storehours'] .= ','.$hour['startTime'] . ' - ' . $hour['endTime']; + }else{ + $info['storehours'] .= $hour['startTime'] . ' - ' . $hour['endTime']; + } + } + } + //相册的处理 + $info['album'] = unserialize($info['album']); + foreach ($info['album'] as $albumK => &$albumV) { + $albumV = tomedia($albumV); + } + //视频处理 + $info['videourl'] = tomedia($info['videourl']); + //商户人气 +1 操作 + $info['pv'] = intval($info['pv']) + 1; + pdo_update(PDO_NAME . "merchantdata" , ['pv' => $info['pv']] , ['id' => $sid]); + #3、对店铺进行定位 + $info['distance'] = Store::shopLocation(0 , $lng , $lat , $info['location']); + #4、判断用户是否已经收藏当前商户 + $storefans = pdo_getcolumn(PDO_NAME . "storefans" , [ + 'sid' => $sid , + 'mid' => $_W['mid'] , + 'source' => 1 + ] , 'id'); + $info['is_collection'] = $storefans > 0 ? 1 : 0; + $info['collectionnum'] = pdo_fetchcolumn('SELECT count(id) FROM '.tablename('wlmerchant_storefans')." WHERE source = 1 AND sid = {$sid}"); + $info['collectionnum'] = sprintf("%.0f",$info['pv'] / 10 ) + $info['collectionnum']; + #5、处理商户全景地址 + if (!empty($info['panorama']) && count(explode('https' , $info['panorama'])) < 2) { + $info['panorama'] = str_replace('http' , 'https' , $info['panorama']); + } + + #6、判断是否开启商户小程序码 + if (p('wxapp')) { + $wxappSet = Setting::wlsetting_read('wxappset'); + if ($wxappSet['storeqrcode'] == 1 && $info['wxappswitch'] != 1) { + $info['wxapp_qrcode'] = Store::getShopWxAppQrCode($sid , $info['logo']); + } + if($_W['source'] == 3 && empty($wxappSet['vp_status'])){ + $info['panorama'] = ''; + } + } + if(empty($info['wxapp_qrcode'])){ + $order['xcxmstatus'] = 0; + } + #6、判断是否存在商户标签 + $tag = unserialize($info['tag']); + $info['tags'] = []; + if (is_array($tag) && count($tag) > 0) { + foreach ($tag as $tagK => &$tagV) { + $taginfo = pdo_get(PDO_NAME . "tags" , ['id' => $tagV] , ['title','content']); + $info['tags'][] = $taginfo['title']; + $info['tagslist'][] = $taginfo; + } + } + //认证信息 + if (p('attestation')) { + $info['attestation'] = Attestation::checkAttestation(2 , $sid); + if($info['attestation']['attestation'] == 2){ + $moreatt = pdo_get('wlmerchant_attestation_list',array('uniacid'=>$_W['uniacid'],'storeid'=>$sid,'status'=>1,'type'=>2),array('subjectname','atttel','cardnum','pic','moreinfo')); + $moreatt['pic'] = unserialize($moreatt['pic']); + $info['moreinfo']['主体名称'] = ['value' => $moreatt['subjectname'],'type' => 'text']; +// $info['moreinfo']['联系电话'] = ['value' => $moreatt['atttel'],'type' => 'number']; + $info['moreinfo']['营业执照号'] = ['value' => $moreatt['cardnum'],'type' => 'number']; + $info['moreinfo']['营业执照'] = ['value' => tomedia($moreatt['pic'][0]),'type' => 'pic']; + $moreatt = unserialize($moreatt['moreinfo']); + foreach ($moreatt as $k => &$ll) { + if(!empty($ll['id'])){ + if($ll['id'] == 'img'){ + foreach($ll['data'] as &$pic){ + $pic = tomedia($pic); + } + } + if(empty($ll['att_show'])){ + $llnn['value'] = $ll['data']; + $llnn['type'] = $ll['id']; + $info['moreinfo'][$ll['title']] = $llnn; + } + }else{ + if($ll['type'] == 'pics'){ + $ll['value'] = unserialize($ll['value']); + foreach($ll['value'] as &$pic){ + $pic = tomedia($pic); + } + }else if($ll['type'] == 'pic'){ + $ll['value'] = tomedia($ll['value']); + } + $info['moreinfo'][$k] = $ll; + } + } + }else{ + $order['sjzzstatus'] = 0; + } + }else { + $info['attestation'] = 0; + $order['sjzzstatus'] = 0; + } + + $info['mid'] = $_W['mid']; + unset($info['tag']); + //判断商户是否有商品 + $where = " AND uniacid = {$_W['uniacid']} AND status = 2 "; + $whereH = " AND uniacid = {$_W['uniacid']} AND status = 1 "; + $sql = "SELECT id,'1' as type,sort FROM " . tablename(PDO_NAME . "rush_activity") . " WHERE sid = {$sid} " . $where . " UNION ALL SELECT id,'2' as type,sort FROM " . tablename(PDO_NAME . "groupon_activity") . " WHERE sid = {$sid} " . $where . " UNION ALL SELECT id,'3' as type,listorder as sort FROM " . tablename(PDO_NAME . "fightgroup_goods") . " WHERE merchantid = {$sid} " . $where . " UNION ALL SELECT id,'5' as type,indexorder as sort FROM " . tablename(PDO_NAME . "couponlist") . " WHERE merchantid = {$sid} AND nostoreshow = 0" . $where . " UNION ALL SELECT id,'7' as type,sort FROM " . tablename(PDO_NAME . "bargain_activity") . " WHERE sid = {$sid} " . $where. " UNION ALL SELECT id,'9' as type,sort FROM " . tablename(PDO_NAME . "activitylist") . " WHERE sid = {$sid} " . $where." UNION ALL SELECT id,'10' as type,sort FROM " . tablename(PDO_NAME . "housekeep_service") . " WHERE objid = {$sid} AND type = 1". $whereH; + $goodslist = pdo_fetch($sql); + if(empty($goodslist)){ + $order['spstatus'] = 0; + } + //判断是否有详情 + if(empty($info['introduction'])){ + $order['xqstatus'] = 0; + } + //判断是否有动态 + $dynamic = pdo_fetch("SELECT id FROM ".tablename('wlmerchant_store_dynamic')."WHERE uniacid = {$_W['uniacid']} AND sid = {$sid} AND status > 0 "); + if(empty($dynamic)){ + $order['dtstatus'] = 0; + } + //判断是否有评论 + $comment = pdo_fetch("SELECT id FROM ".tablename('wlmerchant_comment')." WHERE sid = {$sid} AND status = 1 AND (checkone = 2 OR mid = {$_W['mid']})"); + if(empty($comment)){ + $order['plstatus'] = 0; + } + //判断是否有相册 + if(empty($info['album'])){ + $order['xcstatus'] = 0; + } + //判断是否有招聘 + $recruit = pdo_get('wlmerchant_recruit_recruit',array('release_sid' => $sid,'status' => 4),array('id')); + if(empty($recruit)){ + $order['zpstatus'] = 0; + } + #17、获取图片高度 + $proportion = unserialize($info['proportion']); + $info['imgstyle']['width'] = $proportion['shopwidth']; + $info['imgstyle']['height'] = $proportion['shopheight']; + if(empty($info['imgstyle']['width'])){ + $info['imgstyle']['width'] = !empty(trim($_W['wlsetting']['base']['width'])) ? trim($_W['wlsetting']['base']['width']) : 750; + } + if(empty($info['imgstyle']['height'])){ + $info['imgstyle']['height'] = !empty(trim($_W['wlsetting']['base']['height'])) ? trim($_W['wlsetting']['base']['height']) : 560; + } + //获取社群信息 + if($info['communityid'] > 0){ + $community = Commons::getCommunity($info['communityid']); + if(is_array($community)){ + $info['community'] = $community; + } + } + //标签页排序 + $neworder[] = ['title' => '商品','type' => 'goods','status' => $order['spstatus'],'sort' => $order['sporder']]; + $neworder[] = ['title' => '详情','type' => 'detail','status' => $order['xqstatus'],'sort' => $order['xqorder']]; + $neworder[] = ['title' => '动态','type' => 'state','status' => $order['dtstatus'],'sort' => $order['dtorder']]; + $neworder[] = ['title' => '评论','type' => 'comment','status' => $order['plstatus'],'sort' => $order['plorder']]; + $neworder[] = ['title' => '相册','type' => 'photo','status' => $order['xcstatus'],'sort' => $order['xcorder']]; + + $order['xcxmorder'] = $order['xcxmorder'] ? : 0; + $order['xcxmstatus'] = $order['xcxmstatus'] ? : 0; + $neworder[] = ['title' => '小程序码','type' => 'qrCode','status' => $order['xcxmstatus'],'sort' => $order['xcxmorder']]; + + $order['sjzzorder'] = $order['sjzzorder'] ? : 0; + $order['sjzzstatus'] = $order['sjzzstatus'] ? : 0; + $neworder[] = ['title' => '商家资质','type' => 'certification','status' => $order['sjzzstatus'],'sort' => $order['sjzzorder']]; + + $order['zporder'] = $order['zporder'] ? : 0; + $order['zpstatus'] = $order['zpstatus'] ? : 0; + $neworder[] = ['title' => '招聘','type' => 'recruit','status' => $order['zpstatus'],'sort' => $order['zporder']]; + + $sortArr = array_column($neworder, 'sort'); + array_multisort($sortArr, SORT_DESC, $neworder); + + foreach($neworder as &$oor){ + $oor['status'] = $oor['status'] ? : 0; + } + + + $info['order'] = $neworder; + $this->renderSuccess('商户详情' , $info); + } + /** + * Comment: 获取店铺商品信息 + * Author: zzw + * Date: 2019/8/20 10:31 + */ + public function getStoreGoods() + { + global $_W , $_GPC; + #1、参数接收 商品类型:1=抢购 2=团购 3=拼团 5=优惠券 7=砍价商品 9 = 同城活动 + $sid = $_GPC['sid'];//店铺id + $page = $_GPC['page'] ? $_GPC['page'] : 1;//当前页 + $pageIndex = $_GPC['page_index'] ? $_GPC['page_index'] : 10; + $storeflag = $_GPC['storeflag'] ? $_GPC['storeflag'] : 0; + $pageStart = $page * $pageIndex - $pageIndex; + $plugin = $_GPC['plugin']; + $cc_id = $_GPC['cc_id']; + $cc_child_id = $_GPC['cc_child_id']; + $recommend = $_GPC['recommend']; + if (!$sid) $this->renderError("缺少参数:sid"); + $data = ['hidegoods' => 0]; + //判断权限 + $groupid = pdo_getcolumn('wlmerchant_merchantdata' , ['id' => $sid] , 'groupid'); + if (empty($groupid)) { + $authority = 0; + } + else { + $authority = pdo_getcolumn('wlmerchant_chargelist' , ['id' => $groupid] , 'authority'); + } + if (!empty($authority)) { + $authority = unserialize($authority); + if (!empty($authority) && !in_array('rush' , $authority) && !in_array('groupon' , $authority) && !in_array('wlfightgroup' , $authority) && !in_array('bargain' , $authority)) { + $data['hidegoods'] = 1; + } + } + if(p('activity')){ + if (empty($authority) || in_array('activity' , $authority)) { + $data['activityflag'] = 1; + } + } + //数据筛选 + $where1 = ""; + $where2 = ""; + if (!empty($_GPC['keyword'])) { + $keyword = trim($_GPC['keyword']); + $where1 .= " AND name LIKE '%{$keyword}%'"; + $where2 .= " AND title LIKE '%{$keyword}%'"; + } + $status = $_GPC['status']; + if (empty($status)) { + $where1 .= " AND status = 2"; + $where2 .= " AND status = 2"; + } + else if ($status == 1) { + $where1 .= " AND status IN (1,5,6)"; + $where2 .= " AND status IN (1,5,6)"; + } + else if ($status == 4) { + $where1 .= " AND status IN (0,3,4)"; + $where2 .= " AND status IN (0,3,4)"; + } + else { + $where1 .= " AND status = {$status}"; + $where2 .= " AND status = {$status}"; + } + #2、商品信息获取AND aid = {$_W['aid']} + $where = " AND uniacid = {$_W['uniacid']} "; + + $where_cc = ''; + if (!empty($cc_id) && $cc_id > 0) $where_cc = " AND cc_id = '{$cc_id}'"; + if (!empty($cc_child_id) && $cc_child_id > 0) $where_cc = " AND cc_child_id = '{$cc_child_id}'"; + if (!empty($recommend) && $recommend > 0) $where_cc = " AND recommend = '{$recommend}'"; + + if(empty($plugin)){ + $sql = "SELECT id,'1' as type,sort FROM " . tablename(PDO_NAME . "rush_activity") . " WHERE sid = {$sid} " . $where_cc . $where . $where1 . " UNION ALL SELECT id,'2' as type,sort FROM " . tablename(PDO_NAME . "groupon_activity") . " WHERE sid = {$sid} " . $where . $where1 . " UNION ALL SELECT id,'3' as type,listorder as sort FROM " . tablename(PDO_NAME . "fightgroup_goods") . " WHERE merchantid = {$sid} " . $where . $where1 . " UNION ALL SELECT id,'5' as type,indexorder as sort FROM " . tablename(PDO_NAME . "couponlist") . " WHERE merchantid = {$sid} AND nostoreshow = 0" . $where . $where2 . " UNION ALL SELECT id,'7' as type,sort FROM " . tablename(PDO_NAME . "bargain_activity") . " WHERE sid = {$sid} " . $where . $where1. " UNION ALL SELECT id,'9' as type,sort FROM " . tablename(PDO_NAME . "activitylist") . " WHERE sid = {$sid} " . $where . $where2; + }else if($plugin == 'rush'){ + $sql = "SELECT id,'1' as type,sort FROM " . tablename(PDO_NAME . "rush_activity") . " WHERE sid = {$sid} " . $where_cc . $where . $where1; + }else if($plugin == 'groupon'){ + $sql = "SELECT id,'2' as type,sort FROM " . tablename(PDO_NAME . "groupon_activity") . " WHERE sid = {$sid} " . $where . $where1; + }else if($plugin == 'wlfightgroup'){ + $sql = "SELECT id,'3' as type,listorder as sort FROM " . tablename(PDO_NAME . "fightgroup_goods") . " WHERE merchantid = {$sid} " . $where . $where1 ; + }else if($plugin == 'coupon'){ + $sql = "SELECT id,'5' as type,indexorder as sort FROM " . tablename(PDO_NAME . "couponlist") . " WHERE merchantid = {$sid} AND nostoreshow = 0" . $where . $where2; + }else if($plugin == 'bargain'){ + $sql = "SELECT id,'7' as type,sort FROM " . tablename(PDO_NAME . "bargain_activity") . " WHERE sid = {$sid} " . $where . $where1; + }else if($plugin == 'activity'){ + $sql = "SELECT id,'9' as type,sort FROM " . tablename(PDO_NAME . "activitylist") . " WHERE sid = {$sid} " . $where . $where2; + } + $list = pdo_fetchall($sql . " ORDER BY sort DESC,id DESC LIMIT {$pageStart},{$pageIndex}"); + #3、循环处理商品信息 + if (is_array($list) && count($list) > 0) { + foreach ($list as $key => &$val) { + $val = WeliamWeChat::getHomeGoods($val['type'] , $val['id'] , $storeflag); + switch ($val['type']) { + case 1: + $val['creategoodstype'] = 'rush'; + break; + case 2: + $val['creategoodstype'] = 'groupon'; + break; + case 3: + $val['creategoodstype'] = 'fightgroup'; + break; + case 5: + $val['creategoodstype'] = 'coupon'; + break; + case 7: + $val['creategoodstype'] = 'bargain'; + break; + case 9: + $val['creategoodstype'] = 'activity'; + break; + } + if ($val['creategoodstype'] == 'fightgroup') { + $val['checktype'] = 'wlfightgroup'; + } + else if ($val['creategoodstype'] == 'coupon') { + $val['checktype'] = 'wlcoupon'; + } + else { + $val['checktype'] = $val['creategoodstype']; + } + if (!empty($authority) && !in_array($val['checktype'] , $authority)) { + $val['hidegoods'] = 1; + } + else { + $val['hidegoods'] = 0; + } + unset($val['checktype']); + unset($val['shop_logo']); + unset($val['address']); + unset($val['storename']); + unset($val['sid']); + unset($val['realsalenum']); + unset($val['allsalenum']); + unset($val['plugin']); + unset($val['user_list']); + unset($val['pay_state']); + unset($val['is_vip']); + unset($val['user_limit_num']); + unset($val['user_num']); + unset($val['buy_limit']); + unset($val['discount_price']); + unset($val['totalnum']); + unset($val['vipprice']); + unset($val['vipstatus']); + unset($val['starttime']); + unset($val['endtime']); + } + } + #4、商品总数获取 + $total = count(pdo_fetchall($sql)); + $data['list'] = $list; + $data['total'] = ceil($total / $pageIndex); + //增加插件筛选列表 + if($page == 1){ + $pluginlist[] = ['name'=>'全部','plugin'=>'']; + $pluginlist[] = ['name'=>'抢购','plugin'=>'rush']; + if(p('groupon')){ + $pluginlist[] = ['name'=>'团购','plugin'=>'groupon']; + } + if(p('wlfightgroup')){ + $pluginlist[] = ['name'=>'拼团','plugin'=>'wlfightgroup']; + } + if(p('bargain')){ + $pluginlist[] = ['name'=>'砍价','plugin'=>'bargain']; + } +// if(p('wlcoupon')){ +// $pluginlist[] = ['name'=>'卡券','plugin'=>'coupon']; +// } + if(p('activity')){ + $pluginlist[] = ['name'=>'活动','plugin'=>'activity']; + } + $data['pluginlist'] = $pluginlist; + } + + $this->renderSuccess('店铺商品列表' , $data); + } + /** + * Comment: 商户详情页面获取店铺商品信息 + * Author: wlf + * Date: 2021/05/25 11:24 + */ + public function getStoreDetailGoods(){ + global $_W , $_GPC; + $sid = $_GPC['sid'];//店铺id + $page = $_GPC['page'] ? $_GPC['page'] : 1;//当前页 + $pageIndex = $_GPC['page_index'] ? $_GPC['page_index'] : 10; + $storeflag = 0; + $pageStart = $page * $pageIndex - $pageIndex; + if (!$sid) $this->renderError("缺少参数:sid"); + $where = " AND uniacid = {$_W['uniacid']} "; + $where1 = $where. " AND status = 2"; + $where2 = $where. " AND status = 1"; + $sql = "SELECT id,1 as type,sort FROM " . tablename(PDO_NAME . "rush_activity") . " WHERE sid = {$sid} " . $where1 . " UNION ALL SELECT id,2 as type,sort FROM " . tablename(PDO_NAME . "groupon_activity") . " WHERE sid = {$sid} " . $where1 . " UNION ALL SELECT id,3 as type,listorder as sort FROM " . tablename(PDO_NAME . "fightgroup_goods") . " WHERE merchantid = {$sid} " . $where1 . " UNION ALL SELECT id,5 as type,indexorder as sort FROM " . tablename(PDO_NAME . "couponlist") . " WHERE merchantid = {$sid} AND nostoreshow = 0" . $where1 . " UNION ALL SELECT id,7 as type,sort FROM " . tablename(PDO_NAME . "bargain_activity") . " WHERE sid = {$sid} " . $where1. " UNION ALL SELECT id,9 as type,sort FROM " . tablename(PDO_NAME . "activitylist") . " WHERE sid = {$sid} ". $where1." UNION ALL SELECT id,10 as type,sort FROM " . tablename(PDO_NAME . "housekeep_service") . " WHERE objid = {$sid} AND type = 1". $where2; + $list = pdo_fetchall($sql . " ORDER BY type ASC,sort DESC,id DESC LIMIT {$pageStart},{$pageIndex}"); + if (is_array($list) && count($list) > 0) { + foreach ($list as $key => &$val) { + if($val['type'] == 10){ + $val = Housekeep::getServiceBaseInfo($val['id']); + $val['type'] = 10; + }else{ + $val = WeliamWeChat::getHomeGoods($val['type'] , $val['id'] , $storeflag); + } + switch ($val['type']) { + case 1: + $val['creategoodstype'] = 'rush'; + break; + case 2: + $val['creategoodstype'] = 'groupon'; + break; + case 3: + $val['creategoodstype'] = 'fightgroup'; + break; + case 5: + $val['creategoodstype'] = 'coupon'; + break; + case 7: + $val['creategoodstype'] = 'bargain'; + break; + case 9: + $val['creategoodstype'] = 'activity'; + break; + case 10: + $val['creategoodstype'] = 'housekeep'; + break; + } + if ($val['creategoodstype'] == 'fightgroup') { + $val['checktype'] = 'wlfightgroup'; + } + else if ($val['creategoodstype'] == 'coupon') { + $val['checktype'] = 'wlcoupon'; + } + else { + $val['checktype'] = $val['creategoodstype']; + } + if (!empty($authority) && !in_array($val['checktype'] , $authority)) { + $val['hidegoods'] = 1; + } + else { + $val['hidegoods'] = 0; + } + unset($val['checktype']); + unset($val['shop_logo']); + unset($val['address']); + unset($val['storename']); + unset($val['sid']); + unset($val['realsalenum']); + unset($val['allsalenum']); + unset($val['plugin']); + unset($val['user_list']); + unset($val['pay_state']); + unset($val['is_vip']); + unset($val['user_limit_num']); + unset($val['user_num']); + unset($val['buy_limit']); + unset($val['totalnum']); + unset($val['vipprice']); + unset($val['vipstatus']); + unset($val['starttime']); + unset($val['endtime']); + } + } + #4、商品总数获取 + $total = count(pdo_fetchall($sql)); + $data['list'] = $list; + $data['total'] = ceil($total / $pageIndex); + $this->renderSuccess('店铺商品列表' , $data); + } + /** + * Comment: 获取商户评论信息列表 + * Author: zzw + * Date: 2019/8/20 11:49 + */ + public function getStoreComment() + { + global $_W , $_GPC; + #1、参数接收 + $sid = $_GPC['sid'];//店铺id + $page = $_GPC['page'] ? $_GPC['page'] : 1;//当前页 + $pageIndex = $_GPC['page_index'] ? $_GPC['page_index'] : 5; + $pageStart = $page * $pageIndex - $pageIndex; + #2、获取评论信息 + if(empty($_W['mid'])){ + $_W['mid'] = 0; + } + $sql = "SELECT headimg,nickname,FROM_UNIXTIME(createtime,'%Y-%m-%d %H:%i') as datetime,star,pic,text,replytextone,replypicone FROM " . tablename(PDO_NAME . "comment") . " WHERE sid = {$sid} AND status = 1 AND (checkone = 2 OR mid = {$_W['mid']}) "; + $list = pdo_fetchall($sql . " ORDER BY createtime DESC LIMIT {$pageStart},{$pageIndex} "); + foreach ($list as $key => &$val) { + //用户评论图片的处理 + $commentPic = unserialize($val['pic']); + if(is_string($commentPic) && strlen($commentPic) > 10){ + $commentPic = explode(',',$commentPic); + } + if (is_array($commentPic) && count($commentPic) > 0) { + foreach ($commentPic as $picKey => &$picVal) { + if($picVal) $picVal = tomedia($picVal); + else unset($commentPic[$picKey]); + } + } + $val['pic'] = is_array($commentPic) ? array_values($commentPic) : []; + //商家回复信息图片的处理 + $replyPic = unserialize($val['replypicone']); + if (is_array($replyPic) && count($replyPic) > 0) { + foreach ($replyPic as $replyPicKey => &$replyPicVal) { + $replyPicVal = tomedia($replyPicVal); + } + } + $val['replypicone'] = $replyPic; + $val['star'] = intval($val['star']); + } + #2、获取评论中页数 + $total = ceil(count(pdo_fetchall($sql)) / $pageIndex); + $data['total'] = $total; + $data['list'] = $list; + $this->renderSuccess('获取商户评论信息列表' , $data); + } + /** + * Comment: 获取商户动态信息列表 + * Author: zzw + * Date: 2019/8/20 14:12 + */ + public function getStoreDynamic() + { + global $_W , $_GPC; + #1、参数信息获取 + $sid = $_GPC['sid'];//店铺id + //$this->checkAuthority('dynamic' , $sid); + $page = $_GPC['page'] ? $_GPC['page'] : 1;//当前页 + $pageIndex = $_GPC['page_index'] ? $_GPC['page_index'] : 5; + $pageStart = $page * $pageIndex - $pageIndex; + #2、获取动态信息列表 + $sql = "SELECT b.logo,b.storename,FROM_UNIXTIME(a.createtime,'%Y-%m-%d %H:%i') as datetime,a.content,a.imgs FROM " . tablename(PDO_NAME . "store_dynamic") . " as a RIGHT JOIN " . tablename(PDO_NAME . "merchantdata") . " as b ON a.sid = b.id WHERE a.sid = {$sid} AND a.status IN (1,2) ORDER BY a.createtime DESC "; + $list = pdo_fetchall($sql . " LIMIT {$pageStart},{$pageIndex}"); + #3、循环处理信息 + foreach ($list as $key => &$val) { + $val['logo'] = tomedia($val['logo']); + $val['imgs'] = unserialize($val['imgs']); + if (is_array($val['imgs']) && count($val['imgs']) > 0) { + foreach ($val['imgs'] as $imgK => &$imgV) { + $imgV = tomedia($imgV); + } + } + $val['content'] = htmlspecialchars_decode($val['content']); + } + #3、总页数获取 + $total = count(pdo_fetchall($sql)); + $data['total'] = ceil($total / $pageIndex); + $data['list'] = $list; + $this->renderSuccess('获取商户动态信息列表' , $data); + } + /** + * Comment: 收藏商户 + * Author: zzw + * Date: 2019/8/20 14:33 + */ + public function collection() + { + global $_W , $_GPC; + #1、获取参数信息 + $sid = $_GPC['sid']; + if (!$sid) $this->renderError('缺少参数:sid'); + #2、查询用户是否已经收藏该商户 + $cid = pdo_getcolumn(PDO_NAME . "storefans" , ['sid' => $sid , 'mid' => $_W['mid']] , 'id'); + if ($cid) { + //已收藏 —— 取消收藏信息 + $res = pdo_delete(PDO_NAME . "storefans" , ['sid' => $sid,'mid'=> $_W['mid']]); + } + else { + //未收藏 —— 添加收藏信息 + $res = Store::addFans($sid , $_W['mid'] , $_W['source']); + } + #3、判断操作是否成功 + if ($res) $this->renderSuccess('操作成功!'); + else $this->renderError('操作失败!'); + } + /** + * Comment: 商户提现 + * Author: wlf + * Date: 2019/8/22 16:01 + */ + public function storeCash() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid] , ['allmoney' , 'nowmoney']); + $data = []; + $data['allmoney'] = $store['allmoney']; + $data['nowmoney'] = $store['nowmoney']; + $data['cashmoney'] = sprintf("%.2f" , $store['allmoney'] - $store['nowmoney']); + $this->renderSuccess('商户账户' , $data); + } + /** + * Comment: 商户收支明细 + * Author: wlf + * Date: 2019/8/22 16:25 + */ + public function storeCurrent() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid'] ? $_GPC['storeid'] : $_W['storeid']; + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $pageStart = $page * 10 - 10; + //金额 + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid] , ['nowmoney' , 'allmoney']); + $cashmoney = sprintf("%.2f" , $store['allmoney'] - $store['nowmoney']); + $currents = pdo_fetchall("SELECT fee,orderid,type,createtime,remark FROM " . tablename('wlmerchant_current') . "WHERE uniacid = {$_W['uniacid']} AND status = 1 AND objid = {$storeid} ORDER BY id DESC LIMIT {$pageStart},10"); + $count = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_current') . " WHERE uniacid = {$_W['uniacid']} AND status = 1 AND objid = {$storeid}"); + foreach ($currents as &$current) { + $current['createtime'] = date('Y-m-d H:i:s' , $current['createtime']); + $current['checkcode'] = $current['remark']; + if ($current['type'] == 1) { + $order = pdo_get(PDO_NAME . 'rush_order' , ['id' => $current['orderid']] , array('activityid','orderno')); + $goodsid = $order['activityid']; + $current['orderno'] = $order['orderno']; + $current['remark'] = pdo_getcolumn(PDO_NAME . 'rush_activity' , ['id' => $goodsid] , 'name'); + } + else if ($current['type'] == 10) { + $order = pdo_get(PDO_NAME . 'order' , ['id' => $current['orderid']] , array('fkid','orderno')); + $goodsid = $order['fkid']; + $current['orderno'] = $order['orderno']; + $current['remark'] = pdo_getcolumn(PDO_NAME . 'groupon_activity' , ['id' => $goodsid] , 'name'); + } + else if ($current['type'] == 2) { + $order = pdo_get(PDO_NAME . 'order' , ['id' => $current['orderid']] , array('fkid','orderno')); + $goodsid = $order['fkid']; + $current['orderno'] = $order['orderno']; + $current['remark'] = pdo_getcolumn(PDO_NAME . 'fightgroup_goods' , ['id' => $goodsid] , 'name'); + } + else if ($current['type'] == 3) { + $order = pdo_get(PDO_NAME . 'order' , ['id' => $current['orderid']] , array('fkid','orderno')); + $goodsid = $order['fkid']; + $current['orderno'] = $order['orderno']; + $current['remark'] = pdo_getcolumn(PDO_NAME . 'couponlist' , ['id' => $goodsid] , 'title'); + } + else if ($current['type'] == 12) { + $order = pdo_get(PDO_NAME . 'order' , ['id' => $current['orderid']] , array('fkid','orderno')); + $goodsid = $order['fkid']; + $current['orderno'] = $order['orderno']; + $current['remark'] = pdo_getcolumn(PDO_NAME . 'bargain_activity' , ['id' => $goodsid] , 'name'); + } + else if ($current['type'] == 11) { + $order = pdo_get(PDO_NAME . 'order' , ['id' => $current['orderid']] , array('orderno')); + $current['orderno'] = $order['orderno']; + $money = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $current['orderid']] , 'price'); + $current['remark'] = '商户在线买单' . $money . '元'; + }else if ($current['type'] == 14) { + $order = pdo_get(PDO_NAME . 'timecardrecord' , ['id' => $current['orderid']] , array('activeid')); + $packagename = pdo_getcolumn(PDO_NAME.'package',array('id'=>$order['activeid']),'title'); + $current['remark'] = '礼包【' . $packagename . '】'; + }else if ($current['type'] == 17) { + $order = pdo_get(PDO_NAME . 'order' , ['id' => $current['orderid']] , array('fkid','orderno')); + $current['orderno'] = $order['orderno']; + $title = pdo_getcolumn(PDO_NAME . 'housekeep_service' , ['id' => $order['fkid']] , 'title'); + $current['remark'] = '家政服务【' . $title . '】'; + } + + else if ($current['type'] == 7) { + if ($current['fee'] > 0) { + $current['remark'] = '提现申请被驳回'; + }else { + $current['remark'] = '提现申请'; + //商户提现申请 获取手续费金额 + $current['spercentmoney'] = pdo_getcolumn(PDO_NAME."settlement_record",['id'=>$current['orderid']],'spercentmoney'); + } + } + else if ($current['type'] == -1) { + $current['remark'] = '系统后台修改'; + } + else if ($current['type'] == 140) { + $orderno = pdo_getcolumn(PDO_NAME.'order',array('id'=>$current['orderid']),'orderno'); + $current['orderno'] = $orderno; + $smallorder = pdo_getall('wlmerchant_delivery_order',array('tid'=>$orderno),array('gid')); + $va['title'] = pdo_getcolumn(PDO_NAME.'delivery_activity',array('id'=>$smallorder[0]['gid']),'name'); + if(count($smallorder)>1){ + $va['title'] .= ' 等'; + } + $current['remark'] = '同城配送 - '.$va['title']; + } + } + $data['list'] = $currents; + $data['totalpage'] = ceil($count / 10); + $data['allmoney'] = $store['allmoney']; + $data['nowmoney'] = $store['nowmoney']; + $data['cashmoney'] = $cashmoney; + $this->renderSuccess('商户收支明细' , $data); + } + /** + * Comment: 商户提现页面 + * Author: wlf + * Date: 2019/8/23 09:25 + */ + public function cashPage() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $storeaid = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $storeid] , 'aid'); + $cashsets = Setting::wlsetting_read('cashset'); + $data = []; + $storemain = pdo_get('wlmerchant_member' , ['id' => $_W['mid']] , [ + 'alipay' , + 'realname', + 'bank_name' , + 'card_number' , + 'bank_username' + ]); + $ismian = pdo_getcolumn(PDO_NAME . 'merchantuser' , [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $_W['mid'] , + 'storeid' => $storeid + ] , 'ismain'); + if ($ismian != 1) { + $this->renderError('只有店铺店长才能进行财务结算。'); + } + //可提现金额 + $merchant = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid] , [ + 'allmoney' , + 'nowmoney' , + 'reservestatus' , + 'reservemoney' + ]); + //预留金额设置 + if ($merchant['reservestatus']) { + $reservemoney = $merchant['reservemoney']; + } + else { + $reservemoney = sprintf("%.2f" , $cashsets['reservemoney']); + } + $usemoney = sprintf("%.2f" , $merchant['nowmoney'] - $reservemoney); + if ($usemoney < 0) { + $usemoney = 0; + } + $data['nowmoney'] = $usemoney; + $data['reservemoney'] = $reservemoney; + //提现方式 + $payment_type = $cashsets['payment_type']; + if ($payment_type['alipay']) { + $data['alipaystatus'] = 1; + $data['alipay'] = $storemain['alipay']; + $data['realname'] = $storemain['realname']; + } + else { + $data['alipaystatus'] = 0; + } + if ($payment_type['we_chat']) { + $data['wechatstatus'] = 1; + } + else { + $data['wechatstatus'] = 0; + } + if ($payment_type['bank_card']) { + $data['bankcardstatus'] = 1; + $data['bank_name'] = $storemain['bank_name']; + $data['card_number'] = $storemain['card_number']; + $data['bank_username'] = $storemain['bank_username']; + } + else { + $data['bankcardstatus'] = 0; + } + //提现手续费 + $agent = Area::getSingleAgent($storeaid); + $syssalepercent = $agent['percent']['syssalepercent']; + if (empty($syssalepercent)) { + $syssalepercent = sprintf("%.2f" , $_W['wlsetting']['cashset']['syssalepercent']); + } + else { + $syssalepercent = sprintf("%.2f" , $syssalepercent); + } + $data['syssalepercent'] = $syssalepercent; + $data['lowsetmoney'] = $cashsets['lowsetmoney'] ? : 0; + $data['maxsetmoney'] = $cashsets['maxsetmoney'] ? : 0; + + $this->renderSuccess('商户提现' , $data); + } + /** + * Comment: 商户提现申请接口 + * Author: wlf + * Date: 2019/8/23 10:15 + */ + public function cashApply(){ + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + //判断临时申请内容 + $flag = pdo_get('wlmerchant_settlement_temporary',array('mid' => $storeid,'uniacid'=>$_W['uniacid'],'type' => 2),array('id')); + if(!empty($flag)){ + $this->renderError('此商户有处理中的提现申请,请稍后再试'); + } + $storeaid = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $storeid] , 'aid'); + $settlementmoney = $_GPC['settlementmoney']; + $cashtype = $_GPC['cashtype']; + $storeadmin = pdo_get('wlmerchant_member' , ['id' => $_W['mid']] , ['id' , 'openid' , 'wechat_openid']); + if ($cashtype == 1) { + $alipay = $_GPC['alipay']; + $realname = $_GPC['realname']; + if (empty($alipay)) { + $this->renderError('请填写支付宝账号'); + } + if (empty($realname)) { + $this->renderError('请填写支付宝账号真实姓名'); + } + pdo_update('wlmerchant_member' , ['alipay' => $alipay,'realname'=>$realname] , ['id' => $_W['mid']]); + } + if ($cashtype == 2) { + if ($_W['source'] == 1) { + if (empty($storeadmin['openid'])) { + $this->renderError('您无微信账号数据,无法微信提现'); + } + else { + $sopenid = $storeadmin['openid']; + } + } + else if ($_W['source'] == 3) { + if (empty($storeadmin['wechat_openid'])) { + $this->renderError('您无微信账号数据,无法微信提现'); + } + else { + $sopenid = $storeadmin['wechat_openid']; + } + } + } + else { + $sopenid = ''; + } + if ($cashtype == 3) { + $bank_name = $_GPC['bank_name']; + $card_number = $_GPC['card_number']; + $bank_username = $_GPC['bank_username']; + if (empty($bank_name) || empty($card_number) || empty($bank_username)) { + $this->renderError('请填写银行卡各项参数'); + } + pdo_update('wlmerchant_member' , [ + 'bank_name' => $bank_name , + 'card_number' => $card_number , + 'bank_username' => $bank_username + ] , ['id' => $_W['mid']]); + } + $cashsets = Setting::wlsetting_read('cashset'); + //提现手续费 + $agent = Area::getSingleAgent($storeaid); + $syssalepercent = $agent['percent']['syssalepercent']; + if (empty($syssalepercent)) { + $syssalepercent = sprintf("%.2f" , $_W['wlsetting']['cashset']['syssalepercent']); + } + else { + $syssalepercent = sprintf("%.2f" , $syssalepercent); + } + + //判断提现金额限制 + if ($_GPC['settlementmoney'] < $cashsets['lowsetmoney']) { + $this->renderError('申请失败,最低提现金额为' . $cashsets['lowsetmoney'] . '元。'); + } + //判断提现金额限制 + if ($_GPC['settlementmoney'] > $cashsets['maxsetmoney'] && $cashsets['maxsetmoney'] > 0) { + $this->renderError('申请失败,单次最大提现金额为' . $cashsets['maxsetmoney'] . '元。'); + } + + //判断商家的提现时间限制 + $shopIntervalTime = $cashsets['shopIntervalTime']; + if ($shopIntervalTime > 0) { + //获取上次提现申请时间 + $startTime = pdo_fetchcolumn("SELECT applytime FROM " . tablename(PDO_NAME . "settlement_record") . " WHERE sid = {$storeid} AND uniacid = {$_W['uniacid']} ORDER BY applytime DESC "); + $interval = time() - $startTime; + $intervalDay = $interval / 3600 / 24; + //判断间隔时间 + $intercalRes = ceil($shopIntervalTime - $intervalDay); + if ($intercalRes > 0) { + $this->renderError('请等' . $intercalRes . '天后再申请!。'); + } + } + //可提现金额 + $merchant = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid] , [ + 'allmoney' , + 'nowmoney' , + 'reservestatus' , + 'reservemoney', + 'autocash' + ]); + //预留金额设置 + if ($merchant['reservestatus']) { + $reservemoney = $merchant['reservemoney']; + } + else { + $reservemoney = sprintf("%.2f" , $cashsets['reservemoney']); + } + $usemoney = sprintf("%.2f" , $merchant['nowmoney'] - $reservemoney); + if ($usemoney < 0) { + $usemoney = 0; + } + if ($_GPC['settlementmoney'] > $usemoney) { + $this->renderError("'申请失败,最大可以提现金额:{$usemoney}"); + } + //生成记录 + $spercentmoney = sprintf("%.2f" , $syssalepercent * $settlementmoney / 100); + $sgetmoney = sprintf("%.2f" , $settlementmoney - $spercentmoney); + $data = [ + 'uniacid' => $_W['uniacid'] , + 'sid' => $storeid , + 'aid' => $storeaid , + 'status' => 2 , + 'type' => 1 , + 'sapplymoney' => $settlementmoney , + 'sgetmoney' => $sgetmoney , + 'spercentmoney' => $spercentmoney , + 'spercent' => $syssalepercent , + 'applytime' => TIMESTAMP , + 'updatetime' => TIMESTAMP , + 'sopenid' => $sopenid , + 'payment_type' => $cashtype , + 'source' => $_W['source'] + ]; + if ($cashsets['noaudit']) { + $data['status'] = 3; + $trade_no = time() . random(4 , true); + $data['trade_no'] = $trade_no; + $data['updatetime'] = time(); + } + $value = serialize($data); + $temporary = array( + 'info' => $value, + 'type' => 2, + 'uniacid' => $_W['uniacid'], + 'mid' => $data['sid'] + ); + $res = pdo_insert(PDO_NAME . 'settlement_temporary' , $temporary); + if($res){ + $this->renderSuccess('申请成功'); + }else{ + $this->renderError('申请失败,请重试'); + } + } + /** + * Comment: 商户提现记录 + * Author: wlf + * Date: 2019/8/23 11:35 + */ + public function cashList() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $pageStart = $page * 10 - 10; + $status = $_GPC['status'] ? $_GPC['status'] : 1; // 1审核中 2已打款 3被驳回 + $where = " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid} AND type = 1 "; + if ($status == 1) { + $where .= " AND status IN (1,2,3,4)"; + } + else if ($status == 2) { + $where .= " AND status = 5"; + } + else if ($status == 3) { + $where .= " AND status IN (-1,-2)"; + } + $lists = pdo_fetchall("SELECT status,sapplymoney,sgetmoney,spercentmoney,updatetime FROM " . tablename('wlmerchant_settlement_record') . "{$where} ORDER BY applytime DESC LIMIT {$pageStart},10"); + foreach ($lists as &$li) { + $li['updatetime'] = date('Y-m-d H:i:s' , $li['updatetime']); + } + $count = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_settlement_record') . "{$where}"); + $data['totalpage'] = ceil($count / 10); + $data['lists'] = $lists; + $this->renderSuccess('提现列表' , $data); + } + /** + * Comment: 输码核销接口 + * Author: wlf + * Date: 2019/8/23 14:43 + */ + public function checkcodeCash() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $code = trim($_GPC['verifcode']); + $order = pdo_get(PDO_NAME . 'smallorder',['uniacid' => $_W['uniacid'],'sid' => $storeid ,'checkcode' => $code]); + if($order['appointstatus'] > 0){ + if($order['appointstatus'] != 3){ + $this->renderError('此核销码未预约,无法核销'); + }else if($order['appstarttime'] > time()){ + $this->renderError('此核销码未到预约时间,无法核销'); + }else if($order['appendtime'] < time()){ + $this->renderError('此核销码预约时间已过期,无法核销'); + } + } + if ($order) { + if ($order['status'] == 1) { + if ($order['plugin'] == 'rush') { + $res = Rush::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , 1 , $order['checkcode']); + } + else if ($order['plugin'] == 'groupon') { + $res = Groupon::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , 1 , $order['checkcode']); + } + else if ($order['plugin'] == 'wlfightgroup') { + $res = Wlfightgroup::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , 1 , $order['checkcode']); + } + else if ($order['plugin'] == 'bargain') { + $res = Bargain::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , 1 , $order['checkcode']); + } + else if ($order['plugin'] == 'activity') { + $res = Activity::hexiaoorder($order['orderid'] , $_W['mid'] , 1 , 1 , $order['checkcode']); + } + else if ($order['plugin'] == 'coupon') { + $couponid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $order['orderid']] , 'recordid'); + $res = wlCoupon::hexiaoorder($couponid , $_W['mid'] , 1 , 1 , $order['checkcode']); + } + if ($res) { + $this->renderSuccess('核销成功'); + } + else { + $this->renderError('核销失败,请重试'); + } + } + else { + $this->renderError('此核销码已核销完成'); + } + } + else { + $this->renderError('核销码无效,请检查'); + } + } + /** + * Comment: 验证记录列表 + * Author: wlf + * Date: 2019/8/23 15:43 + */ + public function verifList() + { + global $_W , $_GPC; + $data = []; + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $pageStart = ($page - 1) * 20; + $admin = $_GPC['verifmid']; + $type = trim($_GPC['type']); + $cc_id = trim($_GPC['cc_id']); + $storeid = intval($_GPC['storeid']) ? intval($_GPC['storeid']) : $_W['storeid']; + $time = trim($_GPC['time']); + $keyword = trim($_GPC['keyword']); + $where = " WHERE uniacid = {$_W['uniacid']} AND storeid = {$storeid} "; + if (!empty($type)) { + $where .= " AND plugin = '{$type}'"; + } + if (!empty($cc_id)) { + $where .= " AND cc_id = '{$cc_id}'"; + } + if (!empty($admin)) { + $where .= " AND verifmid = {$admin}"; + } + if (!empty($time)) { + $times = explode(',' , $time); + $starttime = $times[0]; + $endtime = $times[1] + 86399; + $where .= " AND createtime > {$starttime} AND createtime < {$endtime}"; + } + if (!empty($keyword)) { + $where .= " AND orderno LIKE '%{$keyword}%' or verifnickname LIKE '%{$keyword}%'"; + } + $allfen = pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename(PDO_NAME . "verifrecord") . $where); + $myorder = pdo_fetchall("SELECT * FROM " . tablename('wlmerchant_verifrecord') . " {$where} ORDER BY id DESC LIMIT {$pageStart},20"); + $allnum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename(PDO_NAME . "verifrecord") . $where); + foreach ($myorder as $key => &$value) { + $member = Member::wl_member_get($value['mid'] , ['nickname' , 'mobile' , 'encodename']); + $value['nickname'] = base64_decode($member['encodename']); + $value['mobile'] = $member['mobile']; + if (empty($value['verifnickname'])) { + $verifnickname = pdo_getcolumn(PDO_NAME . 'merchantuser' , [ + 'uniacid' => $_W['uniacid'] , + 'mid' => $value['verifmid'] , + 'storeid' => $value['storeid'] + ] , 'name'); + $value['verifnickname'] = $verifnickname; + } + $value['createtime'] = date('Y-m-d H:i:s' , $value['createtime']); + $cc_name = pdo_getcolumn(PDO_NAME . 'cultivate_class',['id' => $value['cc_id']],'name'); + $value['classname'] = $cc_name ?: ''; // 自定义特殊分类 + //处理数据 + switch ($value['plugin']) { + case 'rush': + $order = pdo_get(PDO_NAME . 'rush_order' , ['id' => $value['orderid']] , [ + 'optionid' , + 'activityid' + ]); + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'rush_activity' , ['id' => $order['activityid']] , 'thumb'); + $optionid = $order['optionid']; + $value['pluginname'] = '抢购'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//抢购 + case 'groupon': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , [ + 'specid' , + 'fkid' + ]); + $optionid = $order['specid']; + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'groupon_activity' , ['id' => $order['fkid']] , 'thumb'); + $value['pluginname'] = '团购'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//团购 + case 'wlfightgroup': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , [ + 'specid' , + 'fkid' + ]); + $optionid = $order['specid']; + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'fightgroup_goods' , ['id' => $order['fkid']] , 'logo'); + $value['pluginname'] = '拼团'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//拼团 + case 'coupon': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , ['fkid']); + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'couponlist' , ['id' => $order['fkid']] , 'logo'); + $value['pluginname'] = '卡券'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//卡券 + case 'wlcoupon': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , ['fkid']); + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'couponlist' , ['id' => $order['fkid']] , 'logo'); + $value['pluginname'] = '卡券'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//卡券 + case 'bargain': + $order = pdo_get(PDO_NAME . 'order' , ['id' => $value['orderid']] , ['fkid']); + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'bargain_activity' , ['id' => $order['fkid']] , 'thumb'); + $value['pluginname'] = '砍价'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'smallorder' , ['checkcode' => $value['verifrcode'],'plugin' => $value['plugin'],'orderid' => $value['orderid']] , 'orderprice'); + break;//砍价 + case 'halfcard1': + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $value['storeid']] , 'logo'); + $value['pluginname'] = '会员特权'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'timecardrecord' , ['id' => $value['verifrcode']] , 'realmoney'); + break;//特权 + case 'halfcard2': + $value['goodimg'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $value['storeid']] , 'logo'); + $value['pluginname'] = '大礼包'; + $value['orderprice'] = pdo_getcolumn(PDO_NAME . 'timecardrecord' , ['id' => $value['verifrcode']] , 'realmoney'); + break;//大礼包 + } + if ($optionid && $value['plugin'] != 'coupon' && $value['plugin'] != 'wlcoupon') { + $value['optionname'] = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $optionid] , 'title'); + } + $value['storename'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , [ + 'uniacid' => $_W['uniacid'] , + 'id' => $value['storeid'] + ] , 'storename'); + $value['goodimg'] = tomedia($value['goodimg']); + //兼容处理 + if (empty($value['goodimg'])) $value['goodimg'] = $_W['siteroot'] . 'web/resource/images/nopic-107.png'; + } + $data['list'] = $myorder; + $data['allnum'] = intval($allnum); + $data['allfen'] = intval($allfen); + $data['totalpage'] = ceil($allnum / 20); + $alladminarray = []; + if ($_GPC['getinfoflag']) { + //所有店员 + $meroof = Setting::agentsetting_read('meroof'); + if ($meroof['veradmin']) { + $ismain = pdo_getcolumn(PDO_NAME . 'merchantuser' , [ + 'mid' => $_W['mid'] , + 'storeid' => $storeid + ] , 'ismain'); + if ($ismain == 1) { + $alladmin = pdo_getall(PDO_NAME . 'merchantuser' , [ + 'uniacid' => $_W['uniacid'] , + 'storeid' => $storeid + ] , ['mid' , 'name' , 'mobile'] , 'mid'); + } + else { + $alladmin = pdo_getall(PDO_NAME . 'merchantuser' , [ + 'uniacid' => $_W['uniacid'] , + 'verifmid' => $_W['mid'] , + 'storeid' => $storeid + ] , ['mid' , 'name' , 'mobile'] , 'mid'); + } + foreach ($alladmin as $ak => &$av) { + //$member = Member::wl_member_get($av['mid'] , ['nickname' , 'mobile' , 'encodename']); + $member = pdo_get(PDO_NAME . 'member',['id' => $av['mid']],['nickname','avatar' , 'mobile', 'encodename']); + $av['name'] = !empty($member['nickname']) ? base64_decode($member['encodename']) : $av['name']; + $av['mobile'] = !empty($av['mobile']) ? $av['mobile'] : $member['mobile']; + } + } + else { + $alladmin = pdo_getall(PDO_NAME . 'merchantuser' , [ + 'uniacid' => $_W['uniacid'] , + 'storeid' => $storeid + ] , ['mid' , 'name' , 'mobile'] , 'mid'); + foreach ($alladmin as $ak => $av) { + //$member = Member::wl_member_get($av['mid'] , ['nickname' , 'mobile' , 'encodename']); + $member = pdo_get(PDO_NAME . 'member',['id' => $av['mid']],['nickname','avatar' , 'mobile', 'encodename']); + $av['name'] = !empty($member['nickname']) ? base64_decode($member['encodename']) : $av['name']; + $av['mobile'] = !empty($av['mobile']) ? $av['mobile'] : $member['mobile']; + $alladminarray[] = $av; + } + } + //所有分类 + $alladmin = $alladminarray; +// $halfcardtext = !empty($_W['wlsetting']['trade']['halfcardtext']) ? $_W['wlsetting']['trade']['halfcardtext'] : '一卡通'; +// $alltype[] = ['name' => $halfcardtext ,'type' => 'halfcard1']; +// $alltype[] = ['name' => '大礼包' ,'type' => 'halfcard2']; +// $alltype[] = ['name' => '抢购' ,'type' => 'rush']; +// $alltype[] = ['name' => '卡券' ,'type' => 'wlcoupon']; +// $alltype[] = ['name' => '拼团' ,'type' => 'wlfightgroup']; +// $alltype[] = ['name' => '团购' ,'type' => 'groupon']; +// $alltype[] = ['name' => '砍价' ,'type' => 'bargain']; + $alltype = []; + $cultivate_class = Category::getStoreCategory(); + foreach ($cultivate_class as $cultivate_class_val) { + $alltype[] = ['name' => $cultivate_class_val['name'], 'type' => 'rush', 'cc_id' => $cultivate_class_val['id']]; + } + $data['typelist'] = $alltype; + $data['adminlist'] = $alladmin; + } + $this->renderSuccess('验证记录数据' , $data); + } + /** + * Comment: 店铺评价列表 + * Author: wlf + * Date: 2019/8/23 16:45 + */ + public function commentList() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $rank = $_GPC['rank']; //1好评 2中评 3差评 + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $where = ['uniacid' => $_W['uniacid'] , 'sid' => $storeid,'checkone' => 2]; + if($_GPC['personal'] > 0){ + $where['housekeepflag'] = 1; + } + if ($rank == 1) { + $where['star#'] = "(4,5)"; + } + else if ($rank == 2) { + $where['star#'] = "(2,3)"; + } + else if ($rank == 3) { + $where['star'] = 1; + } + $myorder = Util::getNumData('id,text,createtime,nickname,status,star,replyone,gid,idoforder,plugin,headimg,sid,replytextone' , PDO_NAME . 'comment' , $where , 'ID DESC' , $page , 20 , 1); + $allnum = $myorder[2]; + $myorder = $myorder[0]; + foreach ($myorder as $key => &$value) { + switch ($value['plugin']) { + case 'rush': + if(empty($value['gid'])){ + $activityid = pdo_getcolumn(PDO_NAME . 'rush_order' , ['id' => $value['idoforder']] , 'activityid'); + }else{ + $activityid = $value['gid']; + } + $value['goodsimg'] = pdo_getcolumn(PDO_NAME . 'rush_activity' , ['id' => $activityid] , 'thumb'); + break; + case 'groupon': + if(empty($value['gid'])){ + $activityid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $value['idoforder']] , 'fkid'); + }else{ + $activityid = $value['gid']; + } + $value['goodsimg'] = pdo_getcolumn(PDO_NAME . 'groupon_activity' , ['id' => $activityid] , 'thumb'); + break; + case 'wlfightgroup': + if(empty($value['gid'])){ + $activityid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $value['idoforder']] , 'fkid'); + }else{ + $activityid = $value['gid']; + } + $value['goodsimg'] = pdo_getcolumn(PDO_NAME . 'fightgroup_goods' , ['id' => $activityid] , 'logo'); + break; + case 'coupon': + if(empty($value['gid'])){ + $activityid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $value['idoforder']] , 'fkid'); + }else{ + $activityid = $value['gid']; + } + $value['goodsimg'] = pdo_getcolumn(PDO_NAME . 'couponlist' , ['id' => $activityid] , 'logo'); + break; + case 'bargain': + if(empty($value['gid'])){ + $activityid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $value['idoforder']] , 'fkid'); + }else{ + $activityid = $value['gid']; + } + $value['goodsimg'] = pdo_getcolumn(PDO_NAME . 'bargain_activity' , ['id' => $activityid] , 'thumb'); + break; + case 'housekeep': + $value['goodsimg'] = pdo_getcolumn(PDO_NAME . 'housekeep_service' , ['id' => $value['gid']] , 'thumb'); + break; + default: + $value['goodsimg'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $value['sid']] , 'logo'); + break; + } + $value['headimg'] = tomedia($value['headimg']); + $value['goodsimg'] = tomedia($value['goodsimg']); + $value['createtime'] = date('Y-m-d H:i:s' , $value['createtime']); + } + $data['list'] = $myorder; + $data['totalpage'] = ceil($allnum / 20); + $this->renderSuccess('评价列表' , $data); + } + /** + * Comment: 店铺回复评价 + * Author: wlf + * Date: 2019/8/26 11:28 + */ + public function commentReply() + { + global $_W , $_GPC; + $sid = $_GPC['storeid']; + $orderid = intval($_GPC['commentid']); + $replytext = trim($_GPC['replytext']); + if (empty($orderid) || empty($replytext)) { + $this->renderError('缺少重要参数,请重试'); + } + $comment = pdo_get('wlmerchant_comment' , ['id' => $orderid] , ['mid' ,'housekeepflag', 'sid']); + if($comment['housekeepflag'] > 0){ + $storename = pdo_getcolumn(PDO_NAME . 'housekeep_artificer' , ['id' => $comment['sid']] , 'name'); + }else { + $aut = Store::checkAuthority('comment', $sid); + if ($aut) { + $this->renderError('商户暂无此权限'); + } + $storename = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $comment['sid']] , 'storename'); + } + //给评论用户发模板消息 + pdo_update(PDO_NAME . 'comment' , ['replytextone' => $replytext , 'replyone' => 2] , ['id' => $orderid]); + $modelData = [ + 'first' => '商家回复了您的评论' , + 'type' => '评论回复提醒' ,//业务类型 + 'content' => '商家[' . $storename . ']的回复' ,//业务内容 + 'status' => '已回复' ,//处理结果 + 'time' => date("Y-m-d H:i:s" , time()) ,//操作时间$store['createtime'] + 'remark' => '回复内容:' . $replytext + ]; + //$url = h5_url('pages/mainPages/store/index',['sid'=>$comment['sid']]); + TempModel::sendInit('service' , $comment['mid'] , $modelData , $_W['source']); + $this->renderSuccess('回复成功'); + } + /** + * Comment: 店铺订单列表 + * Author: wlf + * Date: 2019/8/23 10:01 + */ + public function orderList() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $type = $_GPC['type']; //订单类型 + $status = intval($_GPC['status']); //订单状态 + $sort = intval($_GPC['sort']); //订单排序 + $time = trim($_GPC['time']); //时间筛选 + $page = $_GPC['page']; + $keyword = trim($_GPC['keyword']); + $mid = trim($_GPC['userid']); + $cc_id = $_GPC['cc_id']; + $pageStart = $page * 20 - 20; + $settings = Setting::wlsetting_read('orderset'); + $data = []; + $where = " where uniacid = {$_W['uniacid']} and sid = $storeid and orderno != 666666"; + if (!empty($time)) { + if ($time == 'today') { + $starttime = strtotime(date('Y-m-d')); + $endtime = $starttime + 86399; + } + else if ($time == 'week') { + $starttime = strtotime("previous monday"); + $endtime = time(); + } + else if ($time == 'month') { + $starttime = mktime(0 , 0 , 0 , date('m') , 1 , date('Y')); + $endtime = time(); + } + else { + $times = explode(',' , $time); + $starttime = (strtotime($times[0]) > time()) ? strtotime(date('Y-m-d')) : strtotime($times[0]); + $endtime = ($starttime > strtotime($times[1])) ? $starttime + 86399 : strtotime($times[1]) + 86399; + } + $where .= " AND createtime > {$starttime}"; + $where .= " AND createtime < {$endtime}"; + } + if ($status) { + if ($status == 3) { + $where .= " AND status IN (2,3)"; + } + else { + $where .= " AND status = {$status}"; + } + } + else { + $where .= " AND status IN (1,2,3,4,8,6,7,9)"; + } + if (!empty($keyword)) { + $where .= " AND orderno LIKE '%{$keyword}%'"; + } + if (!empty($mid)) { + $where .= " AND mid = {$mid}"; + } + if ($type) { + if ($type == 'rush') { + $where2 = $where . " AND plugin IN ('null') "; + } + else { + $where2 = $where . " AND plugin = '{$type}' "; + $where .= " and orderno = 00000 "; + } + } + else { + $where2 = $where . " AND plugin IN ('wlfightgroup','activity','groupon','coupon','bargain','halfcard','citydelivery','housekeep')"; + } + // 判断统计那种特殊类型 + $where_cc = ''; + if (!empty($cc_id) && $cc_id > 0) $where_cc = " AND activityid IN (SELECT id FROM ".tablename(PDO_NAME."rush_activity")." WHERE uniacid = {$_W['uniacid']} AND cc_id = '{$cc_id}') "; + //获取订单 + if ($sort) { + $myorder = pdo_fetchall('SELECT id,createtime,sid,status,paidprid,mid,orderno,num,price,paytype,vipbuyflag,paytime,disorderid,mobile,remark,expressid,moinfo, "a" FROM ' . tablename(PDO_NAME . "order") . " {$where2}" . ' UNION ALL SELECT id,createtime,sid,status,paidprid,mid,orderno,num,price,paytype,vipbuyflag,paytime,disorderid,mobile,remark,expressid,moinfo, "b" FROM ' . tablename(PDO_NAME . "rush_order") . " {$where} {$where_cc} ORDER BY createtime ASC LIMIT " . $pageStart . ',' . "20"); + } + else { + $myorder = pdo_fetchall('SELECT id,createtime,sid,status,paidprid,mid,orderno,num,price,paytype,vipbuyflag,paytime,disorderid,mobile,remark,expressid,moinfo, "a" FROM ' . tablename(PDO_NAME . "order") . " {$where2}" . ' UNION ALL SELECT id,createtime,sid,status,paidprid,mid,orderno,num,price,paytype,vipbuyflag,paytime,disorderid,mobile,remark,expressid,moinfo, "b" FROM ' . tablename(PDO_NAME . "rush_order") . " {$where} {$where_cc} ORDER BY createtime DESC LIMIT " . $pageStart . ',' . "20"); + } + foreach ($myorder as $key => &$value) { + if ($value['a'] == 'a') { + $aorder = pdo_get(PDO_NAME . 'order' , ['id' => $value['id']] ,['fkid','specid','plugin','buyremark','fightgroupid']); + $value['fkid'] = $aorder['fkid']; + $value['plugin'] = $aorder['plugin']; + $value['remark'] = $aorder['buyremark']; + if ($value['plugin'] == 'coupon') { + $goods = wlCoupon::getSingleCoupons($value['fkid'] , 'title,logo'); + $value['gname'] = $goods['title']; + $value['gimg'] = $goods['logo']; + $value['pluginname'] = '卡券'; + } + if ($value['plugin'] == 'wlfightgroup') { + $goods = Wlfightgroup::getSingleGood($value['fkid'] , 'name,logo'); + $value['gname'] = $goods['name']; + $value['gimg'] = $goods['logo']; + $value['pluginname'] = '拼团'; + $optionid = $aorder['specid']; + } + if ($value['plugin'] == 'groupon') { + $goods = pdo_get(PDO_NAME . 'groupon_activity' , ['id' => $value['fkid']] , ['name','thumb']); + $value['gname'] = $goods['name']; + $value['gimg'] = $goods['thumb']; + $value['pluginname'] = '团购'; + $optionid = $aorder['specid']; + + } + if ($value['plugin'] == 'activity') { + $goods = pdo_get(PDO_NAME . 'activitylist' , ['id' => $value['fkid']] , ['title','thumb']); + $value['gname'] = $goods['title']; + $value['gimg'] = $goods['thumb']; + $value['pluginname'] = '活动'; + $optionid = $aorder['specid']; + } + if ($value['plugin'] == 'halfcard') { + if ($value['fkid']) { + $value['gname'] = pdo_getcolumn(PDO_NAME . 'halfcardlist' , ['id' => $value['fkid']] , 'title'); + } + else { + $value['gname'] = '在线买单'; + } + $value['gimg'] = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $value['sid']] , 'logo'); + $value['pluginname'] = '买单'; + } + if ($value['plugin'] == 'bargain') { + $goods = pdo_get(PDO_NAME . 'bargain_activity' , ['id' => $value['fkid']] , ['name','thumb']); + $value['gname'] = $goods['name']; + $value['gimg'] = $goods['thumb']; + $value['pluginname'] = '砍价'; + } + if ($value['plugin'] == 'housekeep') { + $goods = pdo_get(PDO_NAME . 'housekeep_service' , ['id' => $value['fkid']] , ['title','thumb']); + $value['gname'] = $goods['title']; + $value['gimg'] = $goods['thumb']; + $value['pluginname'] = '家政'; + } + if($value['plugin'] == 'citydelivery'){ + $smallorders = pdo_fetchall("SELECT gid,money,num,specid FROM ".tablename('wlmerchant_delivery_order')." WHERE `tid` = '{$value['orderno']}' ORDER BY price DESC"); + foreach ($smallorders as $ke => &$orr){ + $goods = pdo_get('wlmerchant_delivery_activity',array('id' => $orr['gid']),array('name','thumb')); + $orr['name'] = $goods['name']; + if($orr['specid']>0){ + $specname = pdo_getcolumn(PDO_NAME.'delivery_spec',array('id'=>$orr['specid']),'name'); + $orr['name'] .= '/'.$specname; + } + if($ke == 0){ + $value['gimg'] = tomedia($goods['thumb']); + } + unset($orr['gid']); + $value['goodsarray'][] = $orr; + } + $value['pluginname'] = '同城配送'; + if($value['expressid']>0){ + $value['express'] = pdo_get('wlmerchant_express',array('id' => $value['expressid']),array('name','tel','address')); + } + + } + //规格 + $value['goodsprice'] = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $value['id']] , 'goodsprice'); + $value['goodsprice'] = sprintf("%.2f" , $value['goodsprice'] / $value['num']); + } + else { + $value['activityid'] = pdo_getcolumn(PDO_NAME . 'rush_order' , ['id' => $value['id']] , 'activityid'); + $value['gname'] = pdo_getcolumn(PDO_NAME . 'rush_activity' , ['id' => $value['activityid']] , 'name'); + $value['gimg'] = pdo_getcolumn(PDO_NAME . 'rush_activity' , ['id' => $value['activityid']] , 'thumb'); + $value['address'] = pdo_getcolumn(PDO_NAME . 'rush_order' , ['id' => $value['id']] , 'address'); + $value['username'] = pdo_getcolumn(PDO_NAME . 'rush_order' , ['id' => $value['id']] , 'username'); + //规格 + $optionid = pdo_getcolumn(PDO_NAME . 'rush_order' , ['id' => $value['id']] , 'optionid'); + $value['goodsprice'] = sprintf("%.2f" , $value['price'] / $value['num']); + $value['price'] = pdo_getcolumn(PDO_NAME . 'rush_order' , ['id' => $value['id']] , 'actualprice'); + $value['pluginname'] = '抢购'; + $value['plugin'] = 'rush'; + } + //地址 + if ($value['expressid']) { + if($value['plugin'] == 'citydelivery' || $value['plugin'] == 'housekeep'){ + $value['express'] = pdo_get('wlmerchant_address',array('id' => $value['expressid']),['name','tel','province','city','county','detailed_address']); + if($value['plugin'] == 'citydelivery'){ + $value['express']['address'] = $value['express']['province'].$value['express']['city'].$value['express']['county'].$value['express']['detailed_address']; + }else{ + $value['express']['address'] = $value['express']['county'].$value['express']['detailed_address']; + } + }else{ + $value['express'] = pdo_get('wlmerchant_express' , ['id' => $value['expressid']] , [ + 'name' , + 'tel' , + 'address' , + 'expressname' , + 'expresssn' + ]); + } + } + $member = pdo_get(PDO_NAME . 'member' , [ + 'id' => $value['mid'] , + 'uniacid' => $_W['uniacid'] + ] , ['nickname' , 'mobile' , 'encodename']); + $value['nickname'] = base64_decode($member['encodename']); + if (empty($value['mobile'])) { + $value['mobile'] = $member['mobile']; + } + $value['createtime'] = date('Y-m-d H:i:s' , $value['createtime']); + if ($optionid) { + if($value['plugin'] == 'activity'){ + $value['optiontitle'] = pdo_getcolumn(PDO_NAME . 'activity_spec' , ['id' => $optionid] , 'name'); + }else{ + $value['optiontitle'] = pdo_getcolumn(PDO_NAME . 'goods_option' , ['id' => $optionid] , 'title'); + } + } + if (!$value['optiontitle']) { + $value['optiontitle'] = ''; + } + $value['gimg'] = tomedia($value['gimg']); + switch ($value['status']) { + case 1: + if($value['plugin'] == 'citydelivery'){ + $value['statusname'] = '待自提'; + }else if($value['plugin'] == 'wlfightgroup' && $aorder['fightgroupid'] > 0){ + $groupstatus = pdo_getcolumn(PDO_NAME.'fightgroup_group',array('id'=>$aorder['fightgroupid']),'status'); + if($groupstatus['status'] == 1){ + $value['statusname'] = '组团中'; + $value['status'] = 5; + }else{ + $value['statusname'] = '待使用'; + } + } else{ + $value['statusname'] = '待使用'; + } + break; + case 2: + $value['statusname'] = '待评价'; + break; + case 3: + $value['statusname'] = '已完成'; + break; + case 4: + if($value['plugin'] == 'citydelivery'){ + $value['statusname'] = '配送中'; + }else { + $value['statusname'] = '待收货'; + } + break; + case 6: + $value['statusname'] = '待退款'; + break; + case 7: + $value['statusname'] = '已退款'; + break; + case 8: + if($value['plugin'] == 'citydelivery'){ + $value['statusname'] = '待接单'; + }else{ + $value['statusname'] = '待发货'; + } + break; + case 9: + $value['statusname'] = '已过期'; + break; + } + + //判断当前订单是否存在售后申请 + if($value['a'] == 'a'){ + $aftersale = pdo_fetch("SELECT id,status FROM ".tablename(PDO_NAME."aftersale") + ." WHERE plugin != 'rush' AND orderid = {$value['id']} "); + }else{ + $aftersale = pdo_fetch("SELECT id,status FROM ".tablename(PDO_NAME."aftersale") + ." WHERE plugin = 'rush' AND orderid = {$value['id']} "); + } + //状态 1申请中 2处理中 3已驳回 4用户取消 + if($aftersale) { + switch ($aftersale['status']) { + case 1: + $value['statusname'] = '退款申请中'; + if($settings['storerefund']>0){ + $value['refundflag'] = 1; + } + break;//申请中 + case 2: + $value['statusname'] = '已退款'; + break;//处理中 + //case 3:$value['statusname'] = '退款驳回';;break;//已驳回 + //case 4:$value['statusname'] = '取消退款申请';;break;//用户取消 + } + } + + //自定义表单信息处理 + $moinfo = unserialize($value['moinfo']); + if($moinfo){ + foreach($moinfo as &$moinfoItem){ + if($moinfoItem['id'] == 'img'){ + foreach($moinfoItem['data'] as $imgKey => $imgLink){ + $moinfoItem['data'][$imgKey] = tomedia($imgLink); + } + } + } + $value['moinfo'] = $moinfo; + $value['moinfoflag'] = 1; + }else{ + $value['moinfo'] = []; + $value['moinfoflag'] = 0; + } + + + } + $data['orderlist'] = $myorder; + if ($_GPC['getinfoflag']) { + //初始化数据 + $data['statuslist'] = [ + 0 => '全部状态' , + 1 => '待使用' , + 2 => '待评价' , + 3 => '已完成' , + 4 => '待收货' , + 6 => '待退款' , + 7 => '已退款' , + 8 => '待发货' , + 9 => '已过期' + ]; + $data['typelist'] = [0 => '全部' , 'rush' => '抢购' , 'coupon' => '卡券']; + if (p('wlfightgroup')) { + $data['typelist']['wlfightgroup'] = '拼团'; + } + if (p('groupon')) { + $data['typelist']['groupon'] = '团购'; + } + if (p('halfcard')) { + $data['typelist']['halfcard'] = '买单'; + } + if (p('bargain')) { + $data['typelist']['bargain'] = '砍价'; + } + if (p('citydelivery')) { + $data['typelist']['citydelivery'] = '同城配送'; + } + if (p('housekeep')) { + $data['typelist']['housekeep'] = '家政服务'; + } + $data['sortlist'] = [0 => '时间降序' , 1 => '时间升序']; + //统计 + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_rush_order') . "{$where}"); + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_order') . "{$where2}"); + $data['allordernum'] = $rushordernum + $ordernum; + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename('wlmerchant_rush_order') . "{$where}"); + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_order') . "{$where2}"); + $data['allordermoney'] = $rushordermoney + $ordermoney; + $rushgoodnum = pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('wlmerchant_rush_order') . "{$where}"); + $goodnum = pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('wlmerchant_order') . "{$where2}"); + $data['goodnum'] = $rushgoodnum + $goodnum; + $data['pagetotal'] = ceil($data['allordernum'] / 20); + } + //家政隐藏完成按钮 + if (p('housekeep')) { + $set = Setting::agentsetting_read('housekeep'); + $data['hkhidefish'] = $set['storefish'] ? : 0; + } + + if(Customized::init('citycard1503')>0){ + $data['fishimg'] = 1; + }else{ + $data['fishimg'] = 0; + } + + $this->renderSuccess('订单数据' , $data); + } + /** + * Comment: 商户分类信息列表 + * Author: zzw + * Date: 2019/8/26 14:07 + */ + public function cateList() + { + global $_W , $_GPC; + #1、获取参数信息 + $type = $_GPC['type'] ? : 0;//0=只获取一级分类(默认);1=需要获取二级分类 + #2、获取商户分类列表 + $list = pdo_getall(PDO_NAME . "category_store" , [ + 'aid' => $_W['aid'] , + 'uniacid' => $_W['uniacid'] , + 'state' => 0 , + 'parentid' => 0 , + 'enabled' => 1 + ] , ['id' , 'name' , 'thumb'] , '' , ' displayorder DESC '); + if (is_array($list) && count($list) > 0) { + foreach ($list as $key => &$val) { + $val['thumb'] = tomedia($val['thumb']); + //获取当前一级分类下的二级分类 + if ($type == 1) { + $twoList = pdo_getall(PDO_NAME . "category_store" , [ + 'aid' => $_W['aid'] , + 'uniacid' => $_W['uniacid'] , + 'state' => 0 , + 'parentid' => $val['id'] , + 'enabled' => 1 + ] , [ + 'id' , + 'name' , + 'thumb' + ] , '' , ' displayorder DESC '); + if (is_array($twoList) && count($twoList) > 0) { + foreach ($twoList as $index => &$item) { + $item['thumb'] = tomedia($item['thumb']); + } + } + $val['list'] = $twoList; + } + } + } + $this->renderSuccess('商户一级分类信息' , $list); + } + /** + * Comment: 获取某个用户下的所有店铺列表 + * Author: zzw + * Date: 2019/8/30 16:18 + */ + public function userShopList() + { + global $_W , $_GPC; + #1、参数获取 + $mid = $_GPC['mid'] ? : -1; + $lng = $_GPC['lng'] ? : 0;//104.0091133118 经度 + $lat = $_GPC['lat'] ? : 0;//30.5681964123 纬度 + #2、获取信息 + $list = Store::getUserShopList($mid , $lng , $lat); + $this->renderSuccess('用户店铺列表' , $list); + } + /** + * Comment: 切换商户列表 + * Author: wlf + * Date: 2019/09/24 16:52 + */ + public function userStoreList() + { + global $_W , $_GPC; + $where = " WHERE a.mid = {$_W['mid']} AND a.ismain != 2 AND a.enabled = 1"; + #1、获取有效代理列表 + $agentIds = pdo_getall(PDO_NAME . "agentusers" , ['uniacid' => $_W['uniacid']] , ['id']); + $aids = array_column($agentIds , 'id'); + if (is_array($aids) && count($aids) > 1) { + $where .= " AND a.aid IN (0," . implode(',' , $aids) . ") "; + } + else if (count($aids) == 1) { + $where .= " AND a.aid IN (0,{$aids['0']}) "; + } + $sql = "SELECT a.storeid,a.ismain,b.status,a.reject,a.aid,a.manage_store,a.hasmanage FROM " . tablename(PDO_NAME . "merchantuser") . " as a RIGHT JOIN " . tablename(PDO_NAME . "merchantdata") . " as b ON a.storeid = b.id {$where} ORDER BY a.ismain ASC,a.id DESC "; + $stores = pdo_fetchall($sql); + $data = []; + if (empty($stores)) { + $this->renderError('您没有可管理商户'); + }else { + if(p('attestation')){ + $attset = Setting::wlsetting_read('attestation'); + }else{ + $attset = []; + } + foreach ($stores as &$store) { + $user = []; + $user['status'] = $store['status']; + $merchant = pdo_get('wlmerchant_merchantdata' , ['id' => $store['storeid']] , [ + 'storename' , + 'logo' + ]); + $user['storename'] = $merchant['storename']; + $user['storelogo'] = tomedia($merchant['logo']); + $user['storeid'] = $store['storeid']; + if ($store['ismain'] == 1) { + $user['ismain'] = '店长'; + }else if ($store['ismain'] == 3) { + $user['ismain'] = '管理员'; + }else if ($store['ismain'] == 4) { + $user['ismain'] = '业务员'; + } + if ($store['status'] == 0) { + $user['orderid'] = pdo_getcolumn(PDO_NAME . 'order' , [ + 'sid' => $user['storeid'] , + 'status' => 0 , + 'plugin' => 'store' + ] , 'id'); + if (!$user['orderid']) { + $user['orderid'] = 0; + } + $user['reject'] = '您还未支付入驻金额'; + } + else if ($store['status'] == 3) { + $user['reject'] = $store['reject']; + } + //认证管理商户权限 + if($attset['switch'] == 1 && $attset['attmanage'] == 1 && $store['status'] == 2){ + $attestation = Attestation::checkAttestation(2,$store['storeid']); + if(empty($attestation['attestation'])){ + $user['reject'] = '您的商户未认证'; + $user['status'] = 4; + }else if($attestation['attestation'] == 1){ + $user['reject'] = '您的商户认证中'; + $user['status'] = 4; + }else if($attestation['attestation'] == 3){ + $user['reject'] = '您的商户认证被驳回'; + $user['status'] = 4; + } + } + //代理商信息获取 + $agentName = pdo_getcolumn(PDO_NAME."agentusers",['id'=>$store['aid']],'agentname'); + $user['agent_name'] = $agentName ? $agentName : '总平台'; + //判断业务员权限 + if ($store['ismain'] == 4){ + if($store['manage_store']){ + if($store['hasmanage']){ + $data[] = $user; + } + }else{ + $setting = pdo_get('wlmerchant_agentsetting',array('uniacid' => $_W['uniacid'],'aid'=>$store['aid'],'key' => 'salesman'),array('value')); + $setting = unserialize($setting['value']); + if($setting['hasmanage']){ + $data[] = $user; + } + } + }else{ + $data[] = $user; + } + } + if(empty($data)){ + $this->renderError('您没有可管理商户'); + }else{ + $this->renderSuccess('切换商户列表' , $data); + } + } + } + /** + * Comment: 修改店员状态 + * Author: wlf + * Date: 2019/09/24 18:38 + */ + public function changeAdminEnabled() + { + global $_W , $_GPC; + $userid = $_GPC['userid']; + $userEnabled = pdo_getcolumn(PDO_NAME . 'merchantuser' , ['id' => $userid] , 'enabled'); + $ismain = pdo_getcolumn(PDO_NAME . 'merchantuser' , ['id' => $userid] , 'ismain'); + if ($ismain == 1) { + $this->renderError('店长不能被停用'); + } + if ($userEnabled) { + $res = pdo_update('wlmerchant_merchantuser' , ['enabled' => 0] , ['id' => $userid]); + if ($res) { + $this->renderSuccess('停用成功'); + } + else { + $this->renderError('停用失败'); + } + } + else { + $res = pdo_update('wlmerchant_merchantuser' , ['enabled' => 1] , ['id' => $userid]); + if ($res) { + $this->renderSuccess('启用成功'); + } + else { + $this->renderError('启用失败'); + } + } + } + /** + * Comment: 店铺客户列表 + * Author: wlf + * Date: 2019/09/25 17:27 + */ + public function storeFansList() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid'] ? $_GPC['storeid'] : $_W['storeid']; + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $initialization = $_GPC['initialization']; + $keyword = trim($_GPC['keyword']); + $pageStart = $page * 10 - 10; + $data = []; + $store = pdo_get('wlmerchant_merchantdata',array('id' => $storeid),array('paybackstatus')); + if (!empty($initialization)) { + //获取今日新增客户 + $time = strtotime(date('Y-m-d' , time())); + $data['newfansnum'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_storefans') . " WHERE sid = {$storeid} AND createtime > {$time} "); + //总客户数量 + $data['allfansnum'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_storefans') . " WHERE sid = {$storeid}"); + } + $where = " WHERE a.sid = {$storeid} AND a.uniacid = {$_W['uniacid']}"; + if (!empty($keyword)) { + $where .= " AND (b.nickname LIKE '%{$keyword}%' or b.realname LIKE '%{$keyword}%')"; + } + $fans = pdo_fetchall("SELECT a.id,a.mid,a.createtime,b.avatar,b.nickname,b.realname FROM " . tablename(PDO_NAME . "storefans") . " as a LEFT JOIN " . tablename(PDO_NAME . "member") . " as b ON a.mid = b.id {$where} ORDER BY createtime DESC LIMIT {$pageStart},10"); + $allfans = pdo_fetchcolumn("SELECT count(a.id) FROM " . tablename(PDO_NAME . "storefans") . " as a LEFT JOIN " . tablename(PDO_NAME . "member") . " as b ON a.mid = b.id {$where}"); + $data['pagetotal'] = ceil($allfans / 10); + if ($fans) { + foreach ($fans as &$fan) { + //$fan['avatar'] = tomedia($fan['avatar']); + Member::getMemberInfo($fan,$fan['mid']); + $fan['createtime'] = date('Y-m-d H:i' , $fan['createtime']); + //抢购订单统计 + $rushordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_rush_order') . " WHERE sid = {$storeid} AND mid = {$fan['mid']} AND status IN (1,2,3,4,8,9)"); + $rushordermoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename('wlmerchant_rush_order') . " WHERE sid = {$storeid} AND mid = {$fan['mid']} AND status IN (1,2,3,4,8,9)"); + //其他订单统计 + $ordernum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_order') . " WHERE sid = {$storeid} AND mid = {$fan['mid']} AND status IN (1,2,3,4,8,9)"); + $ordermoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_order') . " WHERE sid = {$storeid} AND mid = {$fan['mid']} AND status IN (1,2,3,4,8,9)"); + $fan['allordernum'] = sprintf("%.0f" , $rushordernum + $ordernum); + $fan['allordermoney'] = sprintf("%.2f" , $rushordermoney + $ordermoney); + pdo_update('wlmerchant_storefans' , ['isread' => 1] , ['id' => $fan['id']]); + } + } + $data['list'] = $fans; + if(p('payback') && $store['paybackstatus'] > 0 ){ + $data['paybak'] = 1; + } + $this->renderSuccess('客户数据' , $data); + } + /** + * Comment: 店铺消息列表 + * Author: wlf + * Date: 2019/09/26 09:42 + */ + public function storeNewList() + { + global $_W , $_GPC; + #1参数获取 + $storeid = $_GPC['storeid'] ? $_GPC['storeid'] : $_W['storeid']; + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $pageIndex = $_GPC['page_index'] ? : 10; + #2、信息列表获取 + $list = Im::myList($storeid , 2 , $page , $pageIndex); + $data['list'] = $list['list']; + $data['total'] = $list['total']; + $data['newnoticenum'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_systemnotice') . " WHERE sid = {$storeid} AND isread = 0"); + $data['newusernum'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_storefans') . " WHERE sid = {$storeid} AND isread = 0"); + $this->renderSuccess('商户通讯信息列表' , $data); + } + /** + * Comment: 店铺个人中心 + * Author: wlf + * Date: 2019/09/28 17:59 + */ + public function storeMember() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $storeinfo = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid] , [ + 'storename' , + 'logo' , + 'endtime' , + 'nowmoney', + 'recruit_switch',//是否开启求职招聘功能:0=关闭,1=开启 + 'housekeepstatus', //是否开启家政服务功能:0=关闭,1=开启 + 'temclose' //临时休息参数 0 营业中 1休息中 + ]); + $data = [ + 'storename' => $storeinfo['storename'] , + 'storelogo' => tomedia($storeinfo['logo']) , + 'endtime' => date('Y-m-d' , $storeinfo['endtime']) , + 'nowmoney' => $storeinfo['nowmoney'], + 'recruit_switch' => $storeinfo['recruit_switch'], + 'housekeepstatus' => $storeinfo['housekeepstatus'], + 'temclose' => $storeinfo['temclose'] + ]; + //判断是否开启商家入驻 + $set = Setting::wlsetting_read('attestation'); + $set['type'] = is_array(unserialize($set['type'])) ? unserialize($set['type']) : []; + if ($set['switch'] == 1 && in_array('store' , $set['type'])) { + $data['switch'] = 1; + } + else { + $data['switch'] = 0; + } + if (p('attestation')) { + $data['attestation'] = Attestation::checkAttestation(2 , $storeid); + } + //入住114标识 + if(p('yellowpage')){ + $ismain = pdo_getcolumn(PDO_NAME . 'merchantuser' , [ + 'mid' => $_W['mid'] , + 'storeid' => $storeid + ] , 'ismain'); + if($ismain == 1){ + $flag = pdo_getcolumn(PDO_NAME.'yellowpage_lists',array('storeid'=>$storeid),'id'); + if(empty($flag)){ + $data['oofflag'] = 1; + }else{ + $data['oofflag'] = 2; + } + } + } + $this->renderSuccess('商户个人中心' , $data); + } + /** + * Comment: 隐藏显示评价接口 + * Author: wlf + * Date: 2019/10/08 16:12 + */ + public function hideCommnet() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; + $aut = Store::checkAuthority('comment' , $storeid); + if($aut){ + $this->renderError('商户暂无此权限'); + } + $id = $_GPC['commentid']; + $comentStatus = pdo_getcolumn(PDO_NAME . 'comment' , ['id' => $id] , 'status'); + if ($comentStatus) { + $res = pdo_update('wlmerchant_comment' , ['status' => 0] , ['id' => $id]); + if ($res) { + $this->renderSuccess('隐藏成功'); + } + else { + $this->renderError('隐藏失败,请重试'); + } + } + else { + $res = pdo_update('wlmerchant_comment' , ['status' => 1] , ['id' => $id]); + if ($res) { + $this->renderSuccess('显示成功'); + } + else { + $this->renderError('显示失败,请重试'); + } + } + } + /** + * Comment: 商家回复评价详情 + * Author: wlf + * Date: 2019/10/08 16:45 + */ + public function commnetDetail() + { + global $_W , $_GPC; + $id = $_GPC['commentid']; + $comment = pdo_get('wlmerchant_comment' , ['id' => $id] , [ + 'gid' , + 'mid' , + 'sid' , + 'pic' , + 'idoforder' , + 'text' , + 'createtime' , + 'star' , + 'plugin', + 'replytextone' + ]); + $member = pdo_get('wlmerchant_member' , ['id' => $comment['mid']] , ['avatar' , 'nickname' , 'encodename']); + $data = [ + 'pic' => unserialize($comment['pic']) , + 'text' => $comment['text'] , + 'createtime' => date('Y-m-d H:i' , $comment['createtime']) , + 'star' => $comment['star'] , + 'nickname' => base64_decode($member['encodename']) , + 'avatar' => tomedia($member['avatar']) , + ]; + switch ($comment['plugin']) { + case 'rush' : + $goodsid = pdo_getcolumn(PDO_NAME . 'rush_order' , ['id' => $comment['idoforder']] , 'activityid'); + $goods = pdo_get('wlmerchant_rush_activity' , ['id' => $goodsid] , [ + 'name' , + 'thumb' , + 'price' , + 'oldprice' + ]); + $data['goodsname'] = $goods['name']; + $data['goodsimg'] = tomedia($goods['thumb']); + $data['goodsprcie'] = $goods['price']; + $data['goodsoldprice'] = $goods['oldprice']; + break; + case 'wlfightgroup': + $goodsid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $comment['idoforder']] , 'fkid'); + $goods = pdo_get('wlmerchant_fightgroup_goods' , ['id' => $goodsid] , [ + 'name' , + 'logo' , + 'price' , + 'oldprice' + ]); + $data['goodsname'] = $goods['name']; + $data['goodsimg'] = tomedia($goods['logo']); + $data['goodsprcie'] = $goods['price']; + $data['goodsoldprice'] = $goods['oldprice']; + break; + case 'bargain': + $goodsid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $comment['idoforder']] , 'fkid'); + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $goodsid] , [ + 'name' , + 'thumb' , + 'price' , + 'oldprice' + ]); + $data['goodsname'] = $goods['name']; + $data['goodsimg'] = tomedia($goods['thumb']); + $data['goodsprcie'] = $goods['price']; + $data['goodsoldprice'] = $goods['oldprice']; + break; + case 'groupon': + $goodsid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $comment['idoforder']] , 'fkid'); + $goods = pdo_get('wlmerchant_groupon_activity' , ['id' => $goodsid] , [ + 'name' , + 'thumb' , + 'price' , + 'oldprice' + ]); + $data['goodsname'] = $goods['name']; + $data['goodsimg'] = tomedia($goods['thumb']); + $data['goodsprcie'] = $goods['price']; + $data['goodsoldprice'] = $goods['oldprice']; + break; + case 'coupon': + $goodsid = pdo_getcolumn(PDO_NAME . 'order' , ['id' => $comment['idoforder']] , 'fkid'); + $goods = pdo_get('wlmerchant_couponlist' , ['id' => $goodsid] , [ + 'title' , + 'logo' , + 'price' + ]); + $data['goodsname'] = $goods['title']; + $data['goodsimg'] = tomedia($goods['logo']); + $data['goodsprcie'] = $goods['price']; + $data['goodsoldprice'] = 0; + break; + case 'housekeep': + $goods = pdo_get('wlmerchant_housekeep_service' , ['id' => $comment['gid']] , [ + 'title' , + 'thumb' , + 'pricetype', + 'price', + 'unit' + ]); + $data['goodsname'] = $goods['title']; + $data['goodsimg'] = tomedia($goods['thumb']); + $data['goodsprcie'] = $goods['price']; + $data['pricetype'] = $goods['pricetype']; + $data['goodsoldprice'] = 0; + //查询留言信息 + $data['replylist'] = pdo_fetchall("SELECT a.id,a.content,b.nickname FROM ".tablename(PDO_NAME."housekeep_reply")." a LEFT JOIN".tablename('wlmerchant_member')." b ON a.smid = b.id WHERE cid = {$id} LIMIT 5"); + break; + default : + $merchant = pdo_get('wlmerchant_merchantdata' , ['id' => $comment['sid']] , [ + 'storename' , + 'logo' + ]); + $data['goodsname'] = $merchant['storename']; + $data['goodsimg'] = tomedia($merchant['logo']); + $data['goodsprcie'] = 0; + $data['goodsoldprice'] = 0; + break; + } + $this->renderSuccess('评价数据' , $data); + } + /** + * Comment: 商家发布动态页面初始化 + * Author: wlf + * Date: 2020/02/26 10:35 + */ + public function addDynamicPage(){ + global $_W , $_GPC; + $storeid = $_GPC['storeid']; //店铺id + $groupid = pdo_getcolumn('wlmerchant_merchantdata' , ['id' => $storeid] , 'groupid'); + if (empty($groupid)) { + $authority = 0; + } + else { + $authority = pdo_getcolumn('wlmerchant_chargelist' , ['id' => $groupid] , 'authority'); + } + $authority = unserialize($authority); + if (!empty($authority)) { + if (!in_array('dynamic' , $authority)) { + $this->renderSuccess('商户暂无此权限',array('status'=>1)); + } + } + $this->renderSuccess('商户有此权限',array('status'=>0)); + } + + /** + * Comment: 商家发布动态 + * Author: wlf + * Date: 2019/10/09 9:28 + */ + public function addDynamic() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; //店铺id + $aut = Store::checkAuthority('dynamic' , $storeid); + if($aut){ + $this->renderError('商户暂无此权限'); + } + $content = $_GPC['content']; //动态内容 + $pic = $_GPC['pic']; + if (!empty($pic)) { + $pic = explode(',' , $_GPC['pic']); + $pic = serialize($pic); //动态图片 + } + else { + $pic = ''; + } + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid] , ['storename' , 'aid' , 'uniacid' , 'audits']); + if (empty($content)) { + $this->renderSuccess('请输入动态内容'); + } + $data = [ + 'uniacid' => $store['uniacid'] , + 'aid' => $store['aid'] , + 'sid' => $storeid , + 'mid' => $_W['mid'] , + 'content' => $content , + 'imgs' => $pic , + 'createtime' => time() , + 'status' => $store['audits'] + ]; + $res = pdo_insert('wlmerchant_store_dynamic' , $data); + if ($res) { + if ($store['audits'] != 1) { + //未开启免审核 给代理商管理员发送模板消息 + $first = "商户【{$store['storename']}】发布了动态信息";//消息头部 + $type = "商家动态审核";//业务类型 + $content = !empty($content) ? $content : '';//业务内容 + $status = "待审核";//处理结果 + $remark = "请尽快处理!";//备注信息 + $time = $data['createtime'];//操作时间 + News::noticeAgent('storegood' , $_W['aid'] , $first , $type , $content , $status , $remark , $time); + } + $this->renderSuccess('发布成功'); + } + else { + $this->renderError('发布失败,请重试'); + } + } + /** + * Comment: 商家删除动态 + * Author: wlf + * Date: 2019/10/09 10:08 + */ + public function deleteDynamic() + { + global $_W , $_GPC; + $id = $_GPC['id']; //动态id + $res = pdo_delete('wlmerchant_store_dynamic' , ['id' => $id]); + if ($res) { + $this->renderSuccess('删除成功'); + } + else { + $this->renderError('删除失败,请重试'); + } + } + /** + * Comment: 商家系统通知列表 + * Author: wlf + * Date: 2019/10/09 17:37 + */ + public function sysNoticeList() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid'] ? $_GPC['storeid'] : $_W['storeid']; + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $pageStart = $page * 10 - 10; + $data = []; + $list = pdo_fetchall("SELECT * FROM " . tablename('wlmerchant_systemnotice') . "WHERE sid = {$storeid} ORDER BY createtime DESC LIMIT {$pageStart},10 "); + $allnum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_systemnotice') . " WHERE uniacid = {$_W['uniacid']} AND sid = {$storeid}"); + $data['pagetotal'] = ceil($allnum / 10); + $newlist = []; + if ($list) { + foreach ($list as $li) { + $arr = []; + $arr['id'] = $li['id']; + switch ($li['type']) { + case 1: + $order = pdo_get('wlmerchant_rush_order' , ['id' => $li['objid']] , [ + 'activityid' , + 'mid' + ]); + $goods = pdo_get('wlmerchant_rush_activity' , ['id' => $order['activityid']] , [ + 'name' , + 'thumb' + ]); + $member = pdo_get('wlmerchant_member' , ['id' => $order['mid']] , [ + 'nickname' , + 'avatar' , + 'encodename' + ]); + $arr['head'] = '订单消息'; + $arr['title'] = $goods['name']; + $arr['thumb'] = tomedia($goods['thumb']); + $arr['subtitle'] = base64_decode($member['encodename']); + $arr['subthumb'] = tomedia($member['avatar']); + break; + case 2: + $arr['head'] = '订单消息'; + $order = pdo_get('wlmerchant_order' , ['id' => $li['objid']] , [ + 'fkid' , + 'plugin' , + 'mid' , + 'sid' + ]); + if ($order['plugin'] == 'groupon') { + $goods = pdo_get('wlmerchant_groupon_activity' , ['id' => $order['fkid']] , [ + 'name' , + 'thumb' + ]); + $arr['title'] = $goods['name']; + $arr['thumb'] = tomedia($goods['thumb']); + } + else if ($order['plugin'] == 'wlfightgroup') { + $goods = pdo_get('wlmerchant_fightgroup_goods' , ['id' => $order['fkid']] , [ + 'name' , + 'logo' + ]); + $arr['title'] = $goods['name']; + $arr['thumb'] = tomedia($goods['logo']); + } + else if ($order['plugin'] == 'coupon') { + $goods = pdo_get('wlmerchant_couponlist' , ['id' => $order['fkid']] , [ + 'title' , + 'logo' + ]); + $arr['title'] = $goods['title']; + $arr['thumb'] = tomedia($goods['logo']); + } + else if ($order['plugin'] == 'halfcard') { + $goods = pdo_get('wlmerchant_merchantdata' , ['id' => $order['sid']] , [ + 'storename' , + 'logo' + ]); + $arr['title'] = $goods['storename'] . '在线买单'; + $arr['thumb'] = tomedia($goods['logo']); + } + else if ($order['plugin'] == 'bargain') { + $goods = pdo_get('wlmerchant_bargain_activity' , ['id' => $order['fkid']] , [ + 'name' , + 'thumb' + ]); + $arr['title'] = $goods['name']; + $arr['thumb'] = tomedia($goods['thumb']); + } + $member = pdo_get('wlmerchant_member' , ['id' => $order['mid']] , [ + 'nickname' , + 'avatar' , + 'encodename' + ]); + $arr['subtitle'] = base64_decode($member['encodename']); + $arr['subthumb'] = tomedia($member['avatar']); + break; + case 3: + $arr['head'] = '提现消息'; + $goods = pdo_get('wlmerchant_merchant' , ['id' => $li['sid']] , ['storename' , 'logo']); + $record = pdo_get('wlmerchant_settlement_record' , ['id' => $li['objid']] , ['sgetmoney']); + $arr['title'] = '提现¥' . $record['sgetmoney']; + $arr['thumb'] = tomedia($goods['logo']); + if ($li['status'] == 1) { + $arr['subtitle'] = '审核通过'; + } + else if ($li['status'] == 2) { + $arr['subtitle'] = '申请驳回'; + } + else if ($li['status'] == 3) { + $arr['subtitle'] = '已打款:+¥' . $record['sgetmoney']; + } + break; + case 4: + $arr['head'] = '粉丝消息'; + $goods = pdo_get('wlmerchant_member' , ['id' => $li['objid']] , [ + 'nickname' , + 'avatar' + ]); + $arr['title'] = $goods['nickname']; + $arr['thumb'] = tomedia($goods['avatar']); + $arr['subtitle'] = '成为了店铺的新粉丝'; + break; + } + //处理时间 + $differtime = time() - $li['createtime']; + if ($differtime < 60) { + $arr['timetext'] = $differtime . '秒前'; + } + else if ($differtime < 3600) { + $differtime = floor($differtime / 60); + $arr['timetext'] = $differtime . '分前'; + } + else if ($differtime < 24 * 3600) { + $differtime = floor($differtime / 3600); + $arr['timetext'] = $differtime . '小时前'; + } + else { + $arr['timetext'] = date('Y-m-d H:i' , $li['createtime']); + } + $newlist[] = $arr; + pdo_update('wlmerchant_systemnotice' , ['isread' => 1] , ['id' => $li['id']]); + } + $data['list'] = $newlist; + } + else { + $data['list'] = []; + } + $this->renderSuccess('通知列表' , $data); + } + /** + * Comment: 商家系统公告列表 + * Author: wlf + * Date: 2019/10/10 11:47 + */ + public function agentNoticeList() + { + global $_W , $_GPC; + $page = $_GPC['page'] ? $_GPC['page'] : 1; + $pageStart = $page * 10 - 10; + $data = []; + $allnum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_notice') . " WHERE uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} AND enabled = 1"); + $data['pagetotal'] = ceil($allnum / 10); + $list = pdo_fetchall("SELECT title,createtime,id,link FROM " . tablename('wlmerchant_notice') . "WHERE uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} AND enabled = 1 ORDER BY createtime DESC LIMIT {$pageStart},10 "); + foreach ($list as &$li) { + //处理时间 + $differtime = time() - $li['createtime']; + if ($differtime < 60) { + $li['timetext'] = $differtime . '秒前'; + } + else if ($differtime < 3600) { + $differtime = floor($differtime / 60); + $li['timetext'] = $differtime . '分前'; + } + else if ($differtime < 24 * 3600) { + $differtime = floor($differtime / 3600); + $li['timetext'] = $differtime . '小时前'; + } + else { + $li['timetext'] = date('Y-m-d H:i' , $li['createtime']); + } + } + if (!empty($list)) { + $data['list'] = $list; + } + else { + $data['list'] = []; + } + $this->renderSuccess('公告列表' , $data); + } + /** + * Comment: 上下架删除商品接口 + * Author: wlf + * Date: 2019/10/10 13:50 + */ + public function changeGoodsStatus() + { + global $_W , $_GPC; + $storeid = $_GPC['storeid']; //店铺id + $goodsid = $_GPC['goodsid']; //商户id + $operation = $_GPC['operation']; // 1上架 2下架 3放入回收站 4彻底删除 + $type = $_GPC['type']; // 1=抢购 2=团购 3=拼团 5=优惠券 7=砍价商品 + if (empty($goodsid) || empty($operation) || empty($type)) { + $this->renderError('缺少重要参数'); + } + //判断权限 + switch ($type) { + case 1: + $aut = Store::checkAuthority('rush' , $storeid); + if($aut){ + $this->renderError('商户暂无此权限'); + } + break; + case 2: + $aut = Store::checkAuthority('groupon' , $storeid); + if($aut){ + $this->renderError('商户暂无此权限'); + } + break; + case 3: + $aut = Store::checkAuthority('wlfightgroup' , $storeid); + if($aut){ + $this->renderError('商户暂无此权限'); + } + break; + case 5: + $aut = Store::checkAuthority('wlcoupon' , $storeid); + if($aut){ + $this->renderError('商户暂无此权限'); + } + break; + case 7: + $aut = Store::checkAuthority('bargain' , $storeid); + if($aut){ + $this->renderError('商户暂无此权限'); + } + break; + } + if ($operation == 1) { + $audits = pdo_getcolumn(PDO_NAME.'merchantdata',array('id'=>$storeid),'audits'); + if (empty($audits)) { + $status = 5; + }else { + $status = 1; + } + switch ($type) { + case 1: + $res = pdo_update('wlmerchant_rush_activity' , ['status' => $status] , ['id' => $goodsid]); + break; + case 2: + $res = pdo_update('wlmerchant_groupon_activity' , ['status' => $status] , ['id' => $goodsid]); + break; + case 3: + $res = pdo_update('wlmerchant_fightgroup_goods' , ['status' => $status] , ['id' => $goodsid]); + break; + case 5: + $res = pdo_update('wlmerchant_couponlist' , ['status' => $status] , ['id' => $goodsid]); + break; + case 7: + $res = pdo_update('wlmerchant_bargain_activity' , ['status' => $status] , ['id' => $goodsid]); + break; + } + if ($res) { + $this->renderSuccess('上架成功'); + } + else { + $this->renderError('上架失败,请刷新重试'); + } + } + else if ($operation == 2) { + switch ($type) { + case 1: + $res = pdo_update('wlmerchant_rush_activity' , ['status' => 4] , ['id' => $goodsid]); + break; + case 2: + $res = pdo_update('wlmerchant_groupon_activity' , ['status' => 4] , ['id' => $goodsid]); + break; + case 3: + $res = pdo_update('wlmerchant_fightgroup_goods' , ['status' => 4] , ['id' => $goodsid]); + break; + case 5: + $res = pdo_update('wlmerchant_couponlist' , ['status' => 4] , ['id' => $goodsid]); + break; + case 7: + $res = pdo_update('wlmerchant_bargain_activity' , ['status' => 4] , ['id' => $goodsid]); + break; + } + if ($res) { + $this->renderSuccess('下架成功'); + } + else { + $this->renderError('下架失败,请刷新重试'); + } + } + else if ($operation == 3) { + switch ($type) { + case 1: + $res = pdo_update('wlmerchant_rush_activity' , ['status' => 8] , ['id' => $goodsid]); + break; + case 2: + $res = pdo_update('wlmerchant_groupon_activity' , ['status' => 8] , ['id' => $goodsid]); + break; + case 3: + $res = pdo_update('wlmerchant_fightgroup_goods' , ['status' => 8] , ['id' => $goodsid]); + break; + case 5: + $res = pdo_update('wlmerchant_couponlist' , ['status' => 8] , ['id' => $goodsid]); + break; + case 7: + $res = pdo_update('wlmerchant_bargain_activity' , ['status' => 8] , ['id' => $goodsid]); + break; + } + if ($res) { + $this->renderSuccess('放入回收站成功'); + } + else { + $this->renderError('放入回收站失败,请刷新重试'); + } + } + else if ($operation == 4) { + switch ($type) { + case 1: + $res = pdo_delete('wlmerchant_rush_activity' , ['id' => $goodsid]); + break; + case 2: + $res = pdo_delete('wlmerchant_groupon_activity' , ['id' => $goodsid]); + break; + case 3: + $res = pdo_delete('wlmerchant_fightgroup_goods' , ['id' => $goodsid]); + break; + case 5: + $res = pdo_delete('wlmerchant_couponlist' , ['id' => $goodsid]); + break; + case 7: + $res = pdo_delete('wlmerchant_bargain_activity' , ['id' => $goodsid]); + break; + } + if ($res) { + $this->renderSuccess('彻底删除成功'); + } + else { + $this->renderError('彻底删除失败,请刷新重试'); + } + } + } + /** + * Comment: 商户中心动态列表 + * Author: wlf + * Date: 2019/10/11 17:05 + */ + public function dynamicList() + { + global $_W , $_GPC; + #1、参数信息获取 + $sid = $_GPC['storeid'];//店铺id + $page = $_GPC['page'] ? $_GPC['page'] : 1;//当前页 + $pageStart = $page * 10 - 10; + #2、获取动态信息列表 + $sql = "SELECT b.logo,b.storename,FROM_UNIXTIME(a.createtime,'%Y-%m-%d %H:%i') as datetime,a.id,a.status,a.content,a.imgs FROM " . tablename(PDO_NAME . "store_dynamic") . " as a RIGHT JOIN " . tablename(PDO_NAME . "merchantdata") . " as b ON a.sid = b.id WHERE a.sid = {$sid} ORDER BY a.createtime DESC"; + $list = pdo_fetchall($sql . " LIMIT {$pageStart},10"); + #3、循环处理信息 + foreach ($list as $key => &$val) { + $val['logo'] = tomedia($val['logo']); + $val['imgs'] = unserialize($val['imgs']); + if (is_array($val['imgs']) && count($val['imgs']) > 0) { + foreach ($val['imgs'] as $imgK => &$imgV) { + $imgV = tomedia($imgV); + } + } + $val['content'] = htmlspecialchars_decode($val['content']); + } + #3、总页数获取 + $total = count(pdo_fetchall($sql)); + $data['total'] = ceil($total / 10); + $data['list'] = $list; + #4、查看发帖权限 + $groupid = pdo_getcolumn('wlmerchant_merchantdata' , ['id' => $sid] , 'groupid'); + if (empty($groupid)) {$authority = 0;} + else { + $authority = pdo_getcolumn('wlmerchant_chargelist' , ['id' => $groupid] , 'authority'); + } + $authority = unserialize($authority); + if (!empty($authority)) { + if (!in_array('dynamic' , $authority)) { + $data['hideadd'] = 1; + } + } + if(empty($data['hideadd'])){ + $data['hideadd'] = 0; + } + $this->renderSuccess('商户中心动态列表' , $data); + } + /** + * Comment: 商户登录状态改变 + * Author: zzw + * Date: 2019/10/31 11:45 + */ + public function storeLoginStatusChange() + { + global $_W , $_GPC; + #1、登录状态获取 + $status = $_GPC['status'] ? : -1; + $onlyKey = $_GPC['only_key'] OR $this->renderError('网络错误,请重新扫码!'); + #1、获取当前的登录状态 + $loginInfo = json_decode(Cache::getCache('storeLoginInfo' , $onlyKey) , true); + if ($loginInfo['end_time'] <= time()) $this->renderError('操作超时,请重新扫码!'); + #1、登录状态修改 + $data = [ + 'status' => intval($status) , + 'end_time' => $loginInfo['end_time'] , + 'mid' => $_W['mid'] + ]; + Cache::setCache('storeLoginInfo' , $onlyKey , json_encode($data)); + $this->renderSuccess('操作成功' , ['status' => intval($status)]); + } + /** + * Comment: 商户创建商品页面 + * Author: wlf + * Date: 2019/12/03 11:59 + */ + public function createGoods() + { + global $_W , $_GPC; + $type = $_GPC['type'] ? $_GPC['type'] : 'rush'; //商品类型 + $id = $_GPC['id']; //商品id + $storeid = $_GPC['storeid']; + $data = []; + if(empty($storeid)){ + $this->renderError('无商户数据,请返回重试'); + } + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid] ,array('groupid','uniacid','aid')); + //获取权限 + $groupid = $store['groupid']; + if (empty($groupid)) { + $authority = 0; + } + else { + $authority = pdo_getcolumn('wlmerchant_chargelist' , ['id' => $groupid] , 'authority'); + } + if (!empty($authority)) { + $authority = unserialize($authority); + } + //商品类型 + $data['cultivate_class'] = Category::getStoreCategoryAll($storeid); + //活动类型 + $data['type'] = []; + if ((!empty($authority) && in_array('rush' , $authority)) || empty($authority)) { + $data['type'][] = 'rush'; + } +// if (p('groupon') && ((!empty($authority) && in_array('groupon' , $authority)) || empty($authority))) { +// $data['type'][] = 'groupon'; +// } +// if (p('wlfightgroup') && ((!empty($authority) && in_array('wlfightgroup' , $authority)) || empty($authority))) { +// $data['type'][] = 'fightgroup'; +// } +// if (p('bargain') && ((!empty($authority) && in_array('bargain' , $authority)) || empty($authority))) { +// $data['type'][] = 'bargain'; +// } + //商品分类 + $cate = pdo_getall('wlmerchant_' . $type . '_category' , [ + 'uniacid' => $store['uniacid'] , + 'aid' => $store['aid'] , + 'is_show' => 0 + ] , ['name' , 'id']); + $data['cate'] = $cate; + //运费模板 + $express = pdo_fetchall("SELECT * FROM ".tablename('wlmerchant_express_template')."WHERE uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} AND sid IN (0,{$storeid}) ORDER BY id DESC"); + $data['express'] = $express; + //商品标签 + $tag_type = ['rush' => 1 , 'groupon' => 3 , 'bargain' => 4 , 'fightgroup' => 2]; + $presettags = pdo_getall('wlmerchant_tags' , [ + 'uniacid' => $store['uniacid'] , + 'aid' => $store['aid'] , + 'type' => $tag_type[$type] + ] , ['id' , 'title'] , '' , 'sort DESC'); + $data['presettags'] = $presettags; + if ($id) { + //基础信息 + if ($type == 'rush') { + $goods = Rush::getSingleActive($id , "name,is_describe_tip,unit,cateid,starttime,endtime,thumb,thumbs,optionstatus,price,oldprice,retainage,appointment,tag,op_one_limit,num,usestatus,expressid,cutoffstatus,cutofftime,cutoffday,`describe`,detail,status,lp_status,lp_set,cc_id,cc_child_id"); + $goods['lp_set'] = unserialize($goods['lp_set']); + unset($goods['a']); + } + else if ($type == 'groupon') { + $goods = Groupon::getSingleActive($id , "name,is_describe_tip,unit,cateid,starttime,endtime,thumb,thumbs,optionstatus,price,oldprice,retainage,appointment,tag,op_one_limit,num,usestatus,expressid,cutoffstatus,cutofftime,cutoffday,`describe`,detail,status"); + } + else if ($type == 'bargain') { + $goods = Bargain::getSingleActive($id , "name,is_describe_tip,unit,cateid,starttime,endtime,thumb,thumbs,price,oldprice,appointment,tag,rules,stock,usestatus,expressid,cutoffstatus,cutofftime,cutoffday,`describe`,detail,status,helplimit,dayhelpcount,joinlimit,onlytimes"); + $goods['rules'] = unserialize($goods['rules']); + if (empty($goods['rules'])) { + $goods['rules'] = []; + } + $goods['num'] = $goods['stock']; + unset($goods['stock']); + } + else if ($type == 'fightgroup') { + $goods = Wlfightgroup::getSingleGood($id , "name,is_describe_tip,unit,categoryid,limitstarttime,limitendtime,logo,adv,price,aloneprice,oldprice,appointment,tag,stock,op_one_limit,usestatus,expressid,cutoffstatus,cutofftime,cutoffday,`describe`,detail,status,grouptime,peoplenum,specstatus"); + $goods['starttime'] = $goods['limitstarttime']; + unset($goods['limitstarttime']); + $goods['endtime'] = $goods['limitendtime']; + unset($goods['limitendtime']); + $goods['thumb'] = $goods['logo']; + unset($goods['logo']); + $goods['thumbs'] = $goods['adv']; + unset($goods['adv']); + $goods['num'] = $goods['stock']; + unset($goods['stock']); + $goods['optionstatus'] = $goods['specstatus']; + unset($goods['specstatus']); + $goods['cateid'] = $goods['categoryid']; + unset($goods['categoryid']); + } + $goods['tag'] = unserialize($goods['tag']); + if (empty($goods['tag'])) { + $goods['tag'] = []; + } + $goods['thumb'] = tomedia($goods['thumb']); + $goods['thumbs'] = unserialize($goods['thumbs']); + if (empty($goods['thumbs'])) { + $goods['thumbs'] = []; + } + else { + foreach ($goods['thumbs'] as &$th) { + $th = tomedia($th); + } + } + //规格 + if ($goods['optionstatus'] == 1) { + if ($type == 'rush') { + $spectype = 1; + } + else if ($type == 'fightgroup') { + $spectype = 2; + } + else if ($type == 'groupon') { + $spectype = 3; + } + //规格项 + $allspecs = pdo_fetchall("select id,title from " . tablename('wlmerchant_goods_spec') . " where goodsid = {$id} AND type = {$spectype}"); + foreach ($allspecs as &$s) { + $s['items'] = pdo_fetchall("SELECT id,title FROM " . tablename('wlmerchant_goods_spec_item') . "WHERE uniacid = {$_W['uniacid']} AND specid = {$s['id']}"); + } + //价目表 + $options = pdo_fetchall("select id,title,stock,price from " . tablename('wlmerchant_goods_option') . " where goodsid={$id} and type = {$spectype} "); + $goods['spec'] = $allspecs; + $goods['options'] = $options; + } + else { + $goods['spec'] = []; + $goods['options'] = []; + } + if ($goods['status'] == 1 || $goods['status'] == 2 || $goods['status'] == 3 || $goods['status'] == 5) { + $goods['status'] = 1; + } + else { + $goods['status'] = 0; + } + if (empty($goods['cutofftime'])) { + $goods['cutofftime'] = time() + 86400 * 30; + } + $data['goods'] = $goods; + } + else { + $data['goods'] = [ + 'name' => '' , + 'unit' => '' , + 'cateid' => '' , + 'onelevel' => '' , + 'starttime' => time() , + 'endtime' => time() + 86400 * 30 , + 'thumb' => '' , + 'thumbs' => [] , + 'optionstatus' => 0 , + 'price' => '' , + 'aloneprice' => '' , + 'oldprice' => '' , + 'retainage' => '' , + 'appointment' => '' , + 'tag' => [] , + 'op_one_limit' => '' , + 'num' => '' , + 'usestatus' => '' , + 'expressid' => '' , + 'cutoffstatus' => 0 , + 'cutofftime' => time() + 86400 * 30 , + 'cutoffday' => 30 , + 'describe' => '' , + 'detail' => '' , + 'status' => 1 , + 'spec' => [] , + 'options' => [] , + 'rules' => [] , + 'helplimit' => '' , + 'dayhelpcount' => '' , + 'joinlimit' => '' , + 'onlytimes' => '' , + 'grouptime' => '' , + 'peoplenum' => 2 , + 'lp_set' => [], + 'cc_id' => 1, + ]; + } + $this->renderSuccess('初始化商品创建' , $data); + } + /** + * Comment: 多规格根据规格项生成规格详情数组 + * Author: wlf + * Date: 2019/12/10 09:38 + */ + public function specToOption() + { + global $_W , $_GPC; + $spec = json_decode(base64_decode($_GPC['spec']) , true); + $option = json_decode(base64_decode($_GPC['options']) , true); + $newoption = []; + foreach ($spec as $sp) { + $items[] = $sp['items']; + } + $length = count($items); + for ($spec0 = 0 ; $spec0 < count($items[0]) ; $spec0++) { + $title = $items[0][$spec0]['title']; + if ($length > 1) { + for ($spec1 = 0 ; $spec1 < count($items[1]) ; $spec1++) { + $lasttitle = $title; + $lasttitle .= '+' . $items[1][$spec1]['title']; + if ($length > 2) { + for ($spec2 = 0 ; $spec2 < count($items[2]) ; $spec2++) { + $lasttitle2 = $lasttitle; + $lasttitle2 .= '+' . $items[2][$spec2]['title']; + if ($length > 3) { + for ($spec3 = 0 ; $spec3 < count($items[3]) ; $spec3++) { + $lasttitle3 = $lasttitle2; + $lasttitle3 .= '+' . $items[3][$spec3]['title']; + if ($length > 4) { + for ($spec4 = 0 ; $spec4 < count($items[4]) ; $spec4++) { + $lasttitle4 = $lasttitle3; + $lasttitle4 .= '+' . $items[4][$spec4]['title']; + if ($length > 5) { + for ($spec5 = 0 ; $spec5 < count($items[5]) ; $spec5++) { + $lasttitle5 = $lasttitle4; + $lasttitle5 .= '+' . $items[5][$spec5]['title']; + $titles[] = $lasttitle5; + } + } + else { + $titles[] = $lasttitle4; + } + } + } + else { + $titles[] = $lasttitle3; + } + } + } + else { + $titles[] = $lasttitle2; + } + } + } + else { + $titles[] = $lasttitle; + } + } + } + else { + $titles[] = $title; + } + } + foreach ($titles as $tit) { + $new = ''; + if (!empty($option)) { + foreach ($option as $op) { + if (empty($new)) { + if ($tit == $op['title']) { + $new = $op; + } + } + } + } + if ($new) { + $newoption[] = $new; + } + else { + $newoption[] = [ + 'id' => 0 , + 'title' => $tit , + 'stock' => 0 , + 'price' => 0 + ]; + } + } + $this->renderSuccess('新的规格详情表' , $newoption); + } + /** + * Comment: 商户保存商品接口 + * Author: wlf + * Date: 2019/12/04 16:20 + */ + public function saveGoods() + { + global $_W , $_GPC; + $type = $_GPC['type']; + $storeid = $_GPC['storeid']; + if (empty($storeid)) { + $this->renderError('无商户信息,请刷新重试'); + } + else { + $store = pdo_get('wlmerchant_merchantdata' , ['id' => $storeid] , [ + 'audits' , + 'storename' , + 'uniacid' , + 'aid' + ]); + } + if(empty($store)){ + $this->renderError('商户信息错误,请刷新重试'); + } + $id = $_GPC['id']; //商品id + $goods = [ + 'name' => $_GPC['name'] , //商品名 + 'sid' => $storeid , //所属商户 + 'aid' => $store['aid'], + 'cateid' => $_GPC['cateid'] , + 'starttime' => $_GPC['starttime'] / 1000 , //活动开始时间 + 'endtime' => $_GPC['endtime'] / 1000 , //活动结束时间 + 'thumb' => $_GPC['thumb'] , //缩略图 + 'optionstatus' => $_GPC['optionstatus'] , //是否多规格 + 'price' => $_GPC['price'] , //价格 + 'oldprice' => $_GPC['oldprice'] , //原价 + 'retainage' => $_GPC['retainage'] , //尾款 + 'appointment' => $_GPC['appointment'] , //预约天数 + 'op_one_limit' => $_GPC['op_one_limit'] , //单人限购 + 'num' => $_GPC['num'] , //库存 + 'usestatus' => $_GPC['usestatus'] , //使用方式 + 'expressid' => $_GPC['expressid'] , //快递模板 + 'cutoffstatus' => $_GPC['cutoffstatus'] , //截止时间类型 + 'cutofftime' => $_GPC['cutofftime'] / 1000 , //固定时间 + 'cutoffday' => $_GPC['cutoffday'] , //有效期天数 + 'describe' => htmlspecialchars_decode($_GPC['describe']), //购买须知 + 'detail' => htmlspecialchars_decode($_GPC['detail']), //商品详情 + 'is_describe_tip' => $_GPC['is_describe_tip'], //有效期天数 + ]; + //文本校验 + $textRes = Filter::init($goods['name'],$_W['source'],1); + if($textRes['errno'] == 0){ + $this->renderError('商品名'.$textRes['message']); + } + //轮播图 + $thumbs = $_GPC['thumbs']; + if (!empty($thumbs)) { + $goods['thumbs'] = serialize(explode(',' , $thumbs)); + } + //标签 + $tag = $_GPC['tag']; + if (!empty($tag)) { + $goods['tag'] = serialize(explode(',' , $tag)); + } + else { + $goods['tag'] = ''; + } + $status = $_GPC['status']; + if ($status == 1) { + $audits = $store['audits']; + if (empty($audits)) { + $goods['status'] = 5; + } + else { + if ($goods['starttime'] > time()) { + $goods['status'] = 1; + } + else if ($goods['starttime'] < time() && time() < $goods['endtime']) { + $goods['status'] = 2; + } + else if ($goods['endtime'] < time()) { + $goods['status'] = 3; + } + } + } + else { + $goods['status'] = 0; + } + if (empty($id)) { + $goods['uniacid'] = $store['uniacid']; + $goods['aid'] = $store['aid']; + $goods['isdistri'] = 1; + $goods['independent'] = 1; + $goods['allowapplyre'] = 0;//默认允许退款 + } + //阶梯价信息处理 + if($type == 'rush'){ + //是否开启阶梯价(0=关闭 1=开启) + $goods['lp_status'] = $_GPC['lp_status'] ? : 0; + //阶梯价配置信息 + $lpSet = json_decode(html_entity_decode($_GPC['lp_set']),true); + $goods['lp_set'] = is_array($lpSet) ? serialize($lpSet) : serialize([]); + }else { + //不是抢购商品 删除阶梯价信息 + unset($goods['lp_set'],$goods['lp_status']); + } + if ($type == 'rush') { + $goods['cc_id'] = $_GPC['cc_id']?:0; // 特殊商品分类id + $goods['cc_child_id'] = $_GPC['cc_child_id']?:0; // 特殊商品分类id + # 设置分类必填 + if (empty($goods['cc_id'])) { + # 验证分类权限并提示 + $classRights = Category::judgeStoreClassRights($storeid); + if ($classRights['status'] <= 0) $this->renderError('商品类型'.$classRights['msg']); + $this->renderError('请选择商品类型'); + } + if (empty($goods['cc_child_id'])) { + # 验证分类权限并提示 + $classChildRights = Category::judgeStoreClassRights($storeid,true); + if ($classChildRights['status'] <= 0) $this->renderError('商品分类'.$classChildRights['msg']); + $this->renderError('请选择商品分类'); + } + $spectype = 1; + $plugin = '抢购'; + if (!empty($id)) { + $res = pdo_update('wlmerchant_rush_activity' , $goods , ['id' => $id]); + } + else { + $res = pdo_insert(PDO_NAME . 'rush_activity' , $goods); + $id = pdo_insertid(); + } + } + else if ($type == 'fightgroup') { + $spectype = 2; + $plugin = '拼团'; + $goods['merchantid'] = $goods['sid']; + unset($goods['sid']); + $goods['limitstarttime'] = $goods['starttime']; + unset($goods['starttime']); + $goods['limitendtime'] = $goods['endtime']; + unset($goods['endtime']); + $goods['logo'] = $goods['thumb']; + unset($goods['thumb']); + $goods['adv'] = $goods['thumbs']; + unset($goods['thumbs']); + $goods['stock'] = $goods['num']; + unset($goods['num']); + unset($goods['retainage']); + $goods['specstatus'] = $goods['optionstatus']; + unset($goods['optionstatus']); + $goods['categoryid'] = $goods['cateid']; + unset($goods['cateid']); + $goods['grouptime'] = $_GPC['grouptime']; + $goods['peoplenum'] = $_GPC['peoplenum']; + $goods['aloneprice'] = $_GPC['aloneprice']; + if ($goods['peoplenum'] < 2) { + $this->renderError('组团人数最小为2'); + } + if (!empty($id)) { + $res = pdo_update('wlmerchant_fightgroup_goods' , $goods , ['id' => $id]); + } + else { + $res = pdo_insert(PDO_NAME . 'fightgroup_goods' , $goods); + $id = pdo_insertid(); + } + } + else if ($type == 'groupon') { + $spectype = 3; + $plugin = '团购'; + if (!empty($id)) { + $res = pdo_update('wlmerchant_groupon_activity' , $goods , ['id' => $id]); + } + else { + $res = pdo_insert(PDO_NAME . 'groupon_activity' , $goods); + $id = pdo_insertid(); + } + } + else if ($type == 'bargain') { + $rules = json_decode(base64_decode($_GPC['rules']),true); + if(!empty($rules)){ + $rules = serialize($rules); + } + unset($goods['op_one_limit']); + unset($goods['optionstatus']); + unset($goods['retainage']); + $goods['stock'] = $goods['num']; + unset($goods['num']); + $plugin = '砍价'; + $goods['rules'] = $rules; + $goods['helplimit'] = $_GPC['helplimit']; + $goods['dayhelpcount'] = $_GPC['dayhelpcount']; + $goods['joinlimit'] = $_GPC['joinlimit']; + $goods['onlytimes'] = $_GPC['onlytimes']; + if (!empty($id)) { + $res = pdo_update('wlmerchant_bargain_activity' , $goods , ['id' => $id]); + } + else { + $goods['submitmoneylimit'] = $goods['oldprice']; + $res = pdo_insert(PDO_NAME . 'bargain_activity' , $goods); + } + } + else { + $this->renderError('类型错误,请刷新重试'); + } + //处理规格 + if ($_GPC['optionstatus'] && $spectype && $id) { + //获取规格 + $spec = json_decode(base64_decode($_GPC['spec']) , true); + //储存 + foreach ($spec as &$sp) { + //处理规格项 + if ($sp['id'] > 0) { + $res2 = pdo_update('wlmerchant_goods_spec' , ['title' => $sp['title']] , ['id' => $sp['id']]); + } + else { + $spdata = $sp; + unset($spdata['id']); + unset($spdata['items']); + $spdata['uniacid'] = $store['uniacid']; + $spdata['type'] = $spectype; + $spdata['goodsid'] = $id; + $res2 = pdo_insert(PDO_NAME . 'goods_spec' , $spdata); + $sp['id'] = pdo_insertid(); + } + $spid[] = $sp['id']; + //处理子规格项 + $spec_itemid = []; + foreach ($sp['items'] as &$item) { + if ($item['id'] > 0) { + $res2 = pdo_update('wlmerchant_goods_spec_item' , [ + 'title' => $sp['title'] , + 'specid' => $sp['id'] + ] , ['id' => $sp['id']]); + } + else { + unset($item['id']); + $item['uniacid'] = $store['uniacid']; + $item['show'] = 1; + $item['specid'] = $sp['id']; + $res2 = pdo_insert(PDO_NAME . 'goods_spec_item' , $item); + $item['id'] = pdo_insertid(); + } + $spec_itemid[] = $item['id']; + } + //删除要的的子规格 + if (0 < count($spec_itemid)) { + pdo_query('delete from ' . tablename('wlmerchant_goods_spec_item') . ' where specid=' . $sp['id'] . ' and id not in (' . implode(',' , $spec_itemid) . ')'); + } + else { + pdo_query('delete from ' . tablename('wlmerchant_goods_spec_item') . ' where specid=' . $sp['id']); + } + pdo_update('wlmerchant_goods_spec' , ['content' => serialize($spec_itemid)] , ['id' => $sp['id']]); + } + //删除不要的规格项 + if (0 < count($spid)) { + pdo_query('delete from ' . tablename('wlmerchant_goods_spec') . ' where type = ' . $spectype . ' and goodsid=' . $id . ' and id not in (' . implode(',' , $spid) . ')'); + } + else { + pdo_query('delete from ' . tablename('wlmerchant_goods_spec') . ' where type = ' . $spectype . ' and goodsid=' . $id); + } + //获取规格详情 + $options = json_decode(base64_decode($_GPC['options']) , true); + foreach ($options as $option) { + $newids = []; + $idsarr = explode('+' , $option['title']); + foreach ($idsarr as $k => $title) { + foreach ($spec[$k]['items'] as $it) { + while ($title == $it['title']) { + $newids[] = $it['id']; + break; + } + } + } + $newids = implode('_' , $newids); + if ($option['id'] > 0) { + $res2 = pdo_update('wlmerchant_goods_option' , [ + 'title' => $option['title'] , + 'stock' => $option['stock'] , + 'price' => $option['price'] , + 'specs' => $newids + ] , ['id' => $option['id']]); + } + else { + unset($option['id']); + $option['uniacid'] = $store['uniacid']; + $option['specs'] = $newids; + $option['type'] = $spectype; + $option['goodsid'] = $id; + if ($spectype == 2) { + $option['vipprice'] = $option['price'] + $goods['aloneprice'] - $goods['price']; + } + $res2 = pdo_insert(PDO_NAME . 'goods_option' , $option); + $option['id'] = pdo_insertid(); + } + $optionids[] = $option['id']; + } + if (0 < count($optionids)) { + pdo_query('delete from ' . tablename('wlmerchant_goods_option') . ' where type = ' . $spectype . ' AND goodsid=' . $id . ' and id not in ( ' . implode(',' , $optionids) . ')'); + } + else { + pdo_query('delete from ' . tablename('wlmerchant_goods_option') . ' where type = ' . $spectype . ' AND goodsid=' . $id); + } + } + //审核通知代理 + if ($goods['status'] == 5 && ($res || $res2)) { + $first = '您好,您有一个待审核任务需要处理'; + $type = '审核商品'; + $content = $plugin . '商品:' . $goods['name']; + $status = '待审核'; + $remark = "商户[" . $store['storename'] . "]上传了一个" . $plugin . '商品待审核,请管理员尽快前往后台审核'; + News::noticeAgent('storegood' , $_W['aid'] , $first , $type , $content , $status , $remark , time() , ''); + } + if ($res || $res2) { + $this->renderSuccess('保存成功'); + } + else { + $this->renderError('保存失败或未修改,请刷新重试'); + } + } + + /** + * Comment: 店员调整粉丝余额 + * Author: wlf + * Date: 2020/06/08 17:07 + */ + public function changeUserCredit(){ + global $_W , $_GPC; + $mid = $_GPC['mid']; + $sid = $_GPC['sid']; + if(empty($sid)){ + $this->renderError('店铺信息错误,请刷新重试'); + } + $type = $_GPC['type']; + $price = $_GPC['price']; + $remark = $_GPC['remark']; + if(empty($type)){ + $price = sprintf("%.2f",0 - $price); + } + $store = pdo_get('wlmerchant_merchantdata',array('id' => $sid),array('uniacid','aid','nowmoney')); + if($store['nowmoney'] < $price){ + $this->renderError('店铺现有金额不足,无法为用户充值'); + } + $doid = pdo_getcolumn(PDO_NAME.'merchantuser',array('mid'=>$_W['mid'],'storeid' => $sid),'id'); + if(empty($doid)){ + $this->renderError('店员信息错误,请刷新重试'); + } + $res = Payback::payCore($sid,$mid,$doid,'store',$price,0,0,$store['uniacid'],$store['aid'],0,$remark); + if($res){ + $this->renderSuccess('操作成功'); + }else{ + $this->renderError('操作失败,请联系管理员'); + } + + + } + + /** + * Comment: 商户退款接口 + * Author: wlf + * Date: 2020/08/03 14:03 + */ + public function storeRefund(){ + global $_W , $_GPC; + $id = $_GPC['id']; + $plugin = $_GPC['plugin']; + if ($plugin == 'wlfightgroup') { + $res = Wlfightgroup::refund($id); + } else if ($plugin == 'coupon') { + $res = wlCoupon::refund($id); + } else if ($plugin == 'groupon') { + $res = Groupon::refund($id); + } else if ($plugin == 'bargain') { + $res = Bargain::refund($id); + } else if ($plugin == 'citydelivery'){ + $res = Citydelivery::refund($id); + } else if ($plugin == 'rush'){ + $res = Rush::refund($id); + } else if ($plugin == 'housekeep'){ + $res = Housekeep::refund($id); + } + if($res['status']){ + $afters = pdo_getall('wlmerchant_aftersale',array('orderid' => $id,'status'=>1,'plugin'=>$plugin),array('id','checkcodes')); + if(!empty($afters)){ + $refundtype = '商家退款:根据支付方式原路退款'; + $journal = array( + 'time' => time(), + 'title' => '到账成功', + 'detail' => '商家已退款:'.$refundtype, + ); + foreach ($afters as $af){ + $journals = Order::addjournal($journal,$af['id']); + $af['checkcodes'] = unserialize($af['checkcodes']); + if(empty($checkcode) || in_array($checkcode,$af['checkcodes'])) { + pdo_update('wlmerchant_aftersale', array('dotime' => time(), 'status' => 2, 'journal' => $journals), array('id' => $af['id'])); + } + } + } + $this->renderSuccess('操作成功'); + }else{ + $this->renderError('退款失败,请刷新重试'); + } + } + + /** + * Comment: 店员绑定申请页接口 + * Author: wlf + * Date: 2021/07/09 16:51 + */ + public function storeAdminApply(){ + global $_W , $_GPC; + $sid = $_GPC['sid']; + if(empty($sid)){ + $this->renderError('参数错误,请重新扫码'); + } + $storeinfo = pdo_get('wlmerchant_merchantdata',array('id' => $sid),array('adv','storename','address')); + if(empty($storeinfo)){ + $this->renderError('商户错误或被删除,请重新扫码'); + } + $storeinfo['adv'] = beautifyImgInfo($storeinfo['adv']); + + $this->renderSuccess('商户基础信息',$storeinfo); + } + + /** + * Comment: 店员绑定提交申请接口 + * Author: wlf + * Date: 2021/07/09 17:41 + */ + public function adminApplyApi(){ + global $_W , $_GPC; + $sid = $_GPC['sid']; + $realname = trim($_GPC['realname']); + $mobile = trim($_GPC['mobile']); + if(empty($sid)){ + $this->renderError('商户参数错误'); + } + + if(empty($realname)){ + $this->renderError('请填写姓名'); + } + if(empty($mobile)){ + $this->renderError('请填写手机号'); + } + $storeinfo = pdo_get('wlmerchant_merchantdata',array('id' => $sid),array('uniacid','aid')); + if(empty($storeinfo)){ + $this->renderError('商户错误或被删除,请重新扫码'); + } + //判断是否重复 + $flag = pdo_getcolumn(PDO_NAME . 'merchantuser' , [ + 'uniacid' => $storeinfo['uniacid'] , + 'mid' => $_W['mid'] , + 'storeid' => $sid + ] , 'id'); + if ($flag) { + $this->renderError('您已提交申请,请勿重复申请'); + } + + $data = [ + 'uniacid' => $storeinfo['uniacid'], + 'aid' => $storeinfo['aid'], + 'mid' => $_W['mid'], + 'storeid' => $sid, + 'name' => $realname, + 'mobile' => $mobile, + 'createtime' => time(), + 'ismain' => 2, + ]; + $res = pdo_insert(PDO_NAME . 'merchantuser', $data); + if($res){ + $this->renderSuccess('提交成功'); + }else{ + $this->renderError('提交失败,请刷新重试'); + } + } + + /** + * Comment: 1520定制一级分类页面接口 + * Author: wlf + * Date: 2021/12/22 16:03 + */ + public function oneCatePage(){ + global $_W , $_GPC; + $id = $_GPC['id']; + $cate = pdo_get('wlmerchant_category_store',array('id' => $id),array('name','advs')); + $data = []; + $data['title'] = $cate['name']; + if(!empty($cate['advs'])){ + $advs = unserialize($cate['advs']); + foreach ($advs as &$ad){ + $ad['thumb'] = tomedia($ad['thumb']); + } + $data['adv'] = $advs; + }else{ + $data['adv'] = []; + } + $children = pdo_getall('wlmerchant_category_store',array('parentid' => $id,'enabled' => 1),array('id','name','thumb','state','abroad')); + if(!empty($children)){ + foreach ($children as &$ch){ + $ch['thumb'] = tomedia($ch['thumb']); + } + $data['chilread'] = $children; + }else{ + $data['chilread'] = []; + } + $this->renderSuccess('页面信息',$data); + } + + /** + * Comment: 临时闭店接口 + * Author: wlf + * Date: 2021/12/31 10:51 + */ + public function temCloseApi(){ + global $_W , $_GPC; + $sid = $_GPC['sid']; + if(empty($sid)){ + $this->renderError('参数错误,请刷新扫码'); + } + $storeinfo = pdo_get('wlmerchant_merchantdata',array('id' => $sid),array('id','temclose')); + if($storeinfo['temclose'] > 0){ + pdo_update('wlmerchant_merchantdata',array('temclose' => 0),array('id' => $sid)); + $this->renderSuccess('营业成功'); + }else{ + pdo_update('wlmerchant_merchantdata',array('temclose' => 1),array('id' => $sid)); + $this->renderSuccess('休息成功'); + } + } + + /** + * 获取培训分类 + * @return void + */ + public function getCultivateClassList() { + $data = Category::getStoreCategory(); + $data_arr = []; + $i = 1; + foreach ($data as $value) { + $keystr = "C012345678910". $i; + $data_arr[$keystr] = [ + 'cc_id' => $value['id'], + 'name' => $value['name'], + 'sort' => 1, + 'status' => 2, + 'request_link' => "p=rush&do=homeList" + ]; + $i++; + } + if (!$data) $this->renderError('数据不存在'); + $this->renderSuccess('数据获取成功',$data_arr); + } + +} \ No newline at end of file diff --git a/addons/weliam_smartcity/api/Student.php b/addons/weliam_smartcity/api/Student.php new file mode 100644 index 0000000..f55fbfb --- /dev/null +++ b/addons/weliam_smartcity/api/Student.php @@ -0,0 +1,495 @@ +renderError('缺少参数'); + + $fields_arr = [ + 'id','mid','name','code','school_name','department_name','start_date','certificate_img','check_cause','check_status' + ]; + $data = pdo_get(PDO_NAME . 'member_student_info',['mid' => $mid],$fields_arr); + if (is_numeric($data['check_status']) && $data['check_status'] == 0) $this->renderError('待审核中,请勿重复申请认证'); + if ($data['check_status'] == 1) $this->renderError('认证已成功,请勿重复申请认证',['is_jump' => true]); + + $user = pdo_get(PDO_NAME . 'member',['id' => $mid],['identity_id']); + if ($user && !in_array($user['identity_id'],[1,3])) { + $identity = pdo_get(PDO_NAME . 'member_identity',['id' => $user['identity_id']],['name']); + $this->renderError('您已经是' . $identity['name'] . '身份,无法申请学生认证'); + } + + if ($data) { + $data['certificate_img'] = tomedia($data['certificate_img']); + $data['reject'] = $data['check_cause']; + $data['status'] = $data['check_status']; + unset($data['check_cause'],$data['check_status']); + $this->renderSuccess('数据获取成功',$data); + } + $this->renderSuccess('数据为空',[ + 'id' => '', + 'mid' => $mid, + 'name' => '', + 'code' => '', + 'school_name' => '', + 'department_name' => '', + 'start_date' => '', + 'certificate_img' => '', + 'reject' => '', + 'status' => 0 + ]); + } + /* + * 学生认证申请 + */ + public function studentIdentityAttestation() + { + global $_W, $_GPC; + + $data = []; + $id = $_GPC['id']; + $mid = $_W['mid']; + $uniacid = $_W['uniacid']; + $sms_code = $_GPC['sms_code']; + + // 验证信息 + if (empty($_GPC['name'])) $this->renderError('请输入姓名'); + if (empty($_GPC['mobile'])) $this->renderError('请输入手机号'); + if (!preg_match("/^1[3-9]\d{9}$/",$_GPC['mobile'])) $this->renderError('请输入正确的手机号'); + if (empty($_GPC['code'])) $this->renderError('请输入学号'); + if (empty($_GPC['school_name'])) $this->renderError('请输入学校名称'); + if (empty($_GPC['department_name'])) $this->renderError('请输入院系'); + if (empty($_GPC['start_date'])) $this->renderError('请选择入学时间'); + if (empty($_GPC['certificate_img'])) $this->renderError('请上传证件'); + + if (strtotime($_GPC['start_date']) > time()) $this->renderError('入学时间不能超出未来时间'); + + $this->checkCode($_GPC['mobile'],$sms_code); + + $validate = Member::validateMemberIdentity($_W['mid']); + if (!$validate['status']) $this->renderError($validate['msg'],['is_jump' => true]); + + $where = ['mid' => $mid]; + $student_res = pdo_get(PDO_NAME . 'member_student_info',$where); + if ($student_res) { + if (is_numeric($student_res['check_status']) && $student_res['check_status'] == 0) $this->renderError('待审核中,请勿重复申请'); + if ($student_res['check_status'] == 1) $this->renderError('已审核通过,请勿重复申请'); + } + + $name_res = Filter::init(trim($_GPC['name']),$_W['source'],1); + if ($name_res['errno'] == 0) $this->renderError($name_res['message']); + $school_name_res = Filter::init(trim($_GPC['school_name']),$_W['source'],1); + if ($school_name_res['errno'] == 0) $this->renderError($school_name_res['message']); + $department_name_res = Filter::init(trim($_GPC['department_name']),$_W['source'],1); + if ($department_name_res['errno'] == 0) $this->renderError($department_name_res['message']); + $certificate_img_res = Filter::init(trim($_GPC['certificate_img']),$_W['source'],2); + if ($certificate_img_res['errno'] == 0) $this->renderError($certificate_img_res['message']); + + // 创建认证申请 + $data['mid'] = $mid; + $data['uniacid'] = $uniacid; + $data['name'] = trim($_GPC['name']); + $data['mobile'] = trim($_GPC['mobile']); + $data['code'] = trim($_GPC['code']); + $data['school_name'] = trim($_GPC['school_name']); + $data['department_name'] = trim($_GPC['department_name']); + $data['certificate_img'] = trim($_GPC['certificate_img']); + $data['start_date'] = trim($_GPC['start_date']); + + if (empty($id)) { + $data['create_time'] = time(); + $result = pdo_insert(PDO_NAME . 'member_student_info',$data); + } elseif (is_numeric($id)) { + $data['update_time'] = time(); + $data['check_status'] = 0; + $result = pdo_update(PDO_NAME . 'member_student_info',$data,['id' => $id]); + } else { + $result = false; + } + if (!$result) $this->renderError('认证申请失败'); + + $this->renderSuccess('认证申请已提交'); + } + /** + * Comment: 文件上传 + * Author: zzw + * Date: 2023/3/24 14:32 + */ + public function uploadFiles(){ + global $_W , $_GPC; + #1、判断上传方式 + $uploadType = $_GPC['upload_type'] ? $_GPC['upload_type'] : 1;//1=普通上传;2=微信端上传 + #2、调用方法进行处理 + UploadFile::uploadIndex($_FILES ,$uploadType, $_GPC['id'], [], 'student_info'); + } + /* + * 校园活动信息列表 + */ + public function campusActivitiesList() { + global $_W, $_GPC; + + $mid = $_W['mid']; + $collect = $_GPC['collect'] ?: 0; # 收藏数据查询 + $sub = $_GPC['sub'] ?: 0; # 发布记录查询 + $pindex = max(1, intval($_GPC['page'])); + $psize = $_GPC['size'] ?: 5; + + $where = ''; + if (empty($sub)) { + $where .= ' status = 1 '; + } else { + $where .= " create_place = 2 and create_user_id = {$mid}"; + } + + # 查询用户收藏数据 + if (!empty($collect) && $collect == 1) { + $collect_list = pdo_getall(PDO_NAME . 'member_collect_activities',['mid' => $mid],['campus_activities_id']); + + if ($collect_list) { + $caid_arr = []; + foreach ($collect_list as $collect_value) $caid_arr[] = $collect_value['campus_activities_id']; + $where .= " and id in('" . implode("','",$caid_arr) . "')"; + } else { + $where .= ' and id = 0 '; + } + } + + + if (!empty($_GPC['cc_id'])) $where .= " and cc_id = '{$_GPC['cc_id']}'"; + if (!empty($_GPC['recommend'])) $where .= " and recommend = '{$_GPC['recommend']}'"; + if (!empty($_GPC['title'])) $where .= " and title like '%{$_GPC['title']}%'"; + $statusArr = ['审核中' , '已发布', '已驳回']; + $field = ['id','title','describe','promotional_img','publish_time','create_place','create_user_id','cc_id','status','reject']; + $total = pdo_count(PDO_NAME . 'member_campus_activities',$where); + $list = pdo_getall(PDO_NAME . 'member_campus_activities',$where,$field,'','publish_time desc',[$pindex,$psize]); + foreach ($list as &$val) { + $val['promotional_img'] = tomedia($val['promotional_img']); + $val['publish_time'] = $val['publish_time'] ? date("Y-m-d H:i:s",$val['publish_time']) : ''; + #发布人 + $val['nickname'] = '小粤'; + $val['avatar'] = $_W['wlsetting']['base']['logo'] ? tomedia($_W['wlsetting']['base']['logo']) : tomedia('headimg_'.$_W['account']['acid'].'.jpg'); + #分类名称 + if ($val['create_place'] == 2) Member::getMemberInfo($val,$val['create_user_id']); + $cc_name = pdo_getcolumn(PDO_NAME . 'cultivate_class',['id' => $val['cc_id']],'name'); + $val['cc_name'] = $cc_name ?: ''; + $val['status_str'] = $statusArr[$val['status']]; + // 活动点赞数 + $thumbs_up_count = pdo_count(PDO_NAME . 'member_thumbs_up_activities',['campus_activities_id' => $val['id']]); + $val['thumbs_up_count'] = $thumbs_up_count ?: 0; + $is_thumbs_up = pdo_get(PDO_NAME . 'member_thumbs_up_activities',['campus_activities_id' => $val['id'], 'mid' => $_W['mid']]); + // 是否点赞该活动 + $val['is_thumbs_up'] = $is_thumbs_up ? true : false; + if ($val['status'] == 1) $val['reject'] = ''; + unset($val['create_place'],$val['create_user_id'],$val['status']); + } + + $this->renderSuccess($list?'数据获取成功':'数据为空',['data' => $list, 'pager' => $pindex, 'total' => $total]); + } + /* + * 获取校园活动信息详情 + */ + public function campusActivitiesFind() { + global $_W, $_GPC; + + $id = $_GPC['id']; + if (empty($id)) $this->renderError('请求失败'); + $fields = ['id','title','describe','promotional_img','publish_time','create_place','create_user_id']; + $data = pdo_get(PDO_NAME . 'member_campus_activities',['id' => $id],$fields); + #发布人 + $data['nickname'] = '小粤'; + $data['avatar'] = $_W['wlsetting']['base']['logo'] ? tomedia($_W['wlsetting']['base']['logo']) : tomedia('headimg_'.$_W['account']['acid'].'.jpg'); + if ($data['create_place'] == 2) Member::getMemberInfo($data,$data['create_user_id']); + #分类名称 + $cc_name = pdo_getcolumn(PDO_NAME . 'cultivate_class',['id' => $data['cc_id']],'name'); + $data['cc_name'] = $cc_name ?: ''; + $where = ['campus_activities_id' => $data['id']]; // 活动评价内容 + $where2 = ['campus_activities_id' => $data['id'], 'mid' => $_W['mid']]; + + $data['promotional_img'] = tomedia($data['promotional_img']); + $thumbs_up_count = pdo_count(PDO_NAME . 'member_thumbs_up_activities',$where); // 活动点赞数 + $data['thumbs_up_count'] = $thumbs_up_count ?: 0; + $is_thumbs_up = pdo_get(PDO_NAME . 'member_thumbs_up_activities',$where2); + $data['is_thumbs_up'] = $is_thumbs_up ? true : false; // 是否点赞该活动 + + $collect_count = pdo_count(PDO_NAME . 'member_collect_activities',$where); // 活动收藏数 + $data['collect_count'] = $collect_count ?: 0; + $is_collect = pdo_get(PDO_NAME . 'member_collect_activities',$where2); + $data['is_collect'] = $is_collect ? true : false; // 是否收藏 + $data['publish_time'] = date("Y-m-d H:i:s",$data['publish_time']); + + unset($data['create_place'],$data['create_user_id']); + $this->renderSuccess('数据获取成功',['data' => $data]); + } + /* + * 校园活动添加评价 + */ + public function addEvaluation() { + global $_W, $_GPC; + + $mid = $_W['mid']; + $caid = $_GPC['caid']; + $oneid = $_GPC['oneid']; + $pid = $_GPC['pid']; + $content = $_GPC['content']; + + if (empty($mid) || !is_numeric($mid)) $this->renderError('请求失败'); + if (empty($caid) || !is_numeric($caid)) $this->renderError('请求失败'); + if (empty($content)) $this->renderError('请填写评价内容'); + $contentRes = Filter::init(trim($content)); + if ($contentRes['errno'] == 0) $this->renderError($contentRes['message']); + + $data = [ + 'mid' => $mid, + 'uniacid' => $_W['uniacid'], + 'campus_activities_id' => $caid, + 'content' => base64_encode(trim($content)), + 'create_time' => time() + ]; + if (!empty($pid) && is_numeric($pid)) { + $pQuery = pdo_get(PDO_NAME . 'member_evaluation_activities',['id' => $pid],['id']); + if (!$pQuery) $this->renderError('回复评价信息不存在!'); + $data['pid'] = $pQuery['id']; + } + if (!empty($oneid) && is_numeric($pid)) $data['oneid'] = $oneid; + + //判断是否需要审核 + $settings = Setting::wlsetting_read('comment_set'); + if($settings['campusActivities'] == 1) $data['status'] = 1; + + $result = pdo_insert(PDO_NAME . 'member_evaluation_activities',$data); + if (!$result) $this->renderError('评价失败'); + $this->renderSuccess('评价成功'); + } + + /** + * 获取评价数据 + * @return void + */ + public function getEvaluationList() + { + global $_W, $_GPC; + + $caid = $_GPC['caid']; + $oneid = $_GPC['oneid'] ?: 0; + $pindex = $_GPC['pindex'] ?: 1; + $psize = $_GPC['psize'] ?: 10; + + if (empty($caid) || !is_numeric($caid)) $this->renderError('缺少参数:caid'); + + $where = ['campus_activities_id' => $caid, 'oneid' => $oneid, 'status' => 1]; + + $fields = 'id,mid,content,create_time,pid,oneid'; + + $commentRes = Util::getNumData($fields, PDO_NAME . 'member_evaluation_activities', $where, 'create_time asc', $pindex, $psize, 1); + $appraise_list = (array)$commentRes[0]; + $pager = $commentRes[1]; + $total = $commentRes[2]; + foreach ($appraise_list as &$row) { + # 评价人信息 + Member::getMemberInfo($row,$row['mid']); + # 回复信息 + if (is_base64($row['content'])) $row['content'] = base64_decode($row['content']); + # 评价时间 + $row['create_time'] = date("Y.m.d H:i",$row['create_time']); + # 是否显示查看回复 + $row['is_query'] = false; + # 回复数量 + $row['reply_count'] = 0; + if (!$row['oneid']) { + $count = pdo_count(PDO_NAME . 'member_evaluation_activities',['oneid' => $row['id'],'status' => 1]); + if ($count > 0) $row['is_query'] = true; + $row['reply_count'] = $count; + } + # 被回复人信息 + if (!empty($row['pid'])) { + $pComment = pdo_get(PDO_NAME . 'member_evaluation_activities',['id' => $row['pid']],['mid']); + $quiltArr = []; + Member::getMemberInfo($quiltArr,$pComment['mid']); + $row['quilt_nickname'] = $quiltArr['nickname']; + $row['quilt_avatar'] = $quiltArr['avatar']; + $row['quilt_mid'] = $pComment['mid']; + } + } + + $this->renderSuccess('数据获取成功',['list' => $appraise_list, 'pager' => $pager, 'total' => $total]); + } + + /* + * 立即收藏活动 + */ + public function immediatelyCollectActivities() { + global $_W, $_GPC; + + $mid = $_W['mid']; + $caid = $_GPC['caid']; + if (empty($mid) || !is_numeric($mid)) $this->renderError('请求失败'); + if (empty($caid) || !is_numeric($caid)) $this->renderError('请求失败'); + $collect_data = pdo_get(PDO_NAME . 'member_collect_activities',['campus_activities_id' => $caid,'mid' => $mid]); + if ($collect_data) $this->renderError('请勿重复收藏'); + $data = [ + 'mid' => $mid, + 'campus_activities_id' => $caid, + 'create_time' => time() + ]; + $result = pdo_insert(PDO_NAME . 'member_collect_activities', $data); + if (!$result) $this->renderError('收藏失败'); + $this->renderSuccess('收藏成功'); + } + /* + * 取消收藏活动 + */ + public function cancelCollectActivities() { + global $_W, $_GPC; + + $mid = $_W['mid']; + $caid = $_GPC['caid']; + if (empty($mid) || !is_numeric($mid)) $this->renderError('请求失败'); + if (empty($caid) || !is_numeric($caid)) $this->renderError('请求失败'); + + $result = pdo_delete(PDO_NAME . 'member_collect_activities',['mid' => $mid, 'campus_activities_id' => $caid]); + if (!$result) $this->renderError('取消收藏失败'); + $this->renderSuccess('取消成功'); + } + /* + * 校园活动点赞(点赞/取消点赞) + */ + public function thumbsUpActivities() { + global $_W, $_GPC; + + $mid = $_W['mid']; + $caid = $_GPC['caid']; + if (empty($mid) || !is_numeric($mid)) $this->renderError('请求失败'); + if (empty($caid) || !is_numeric($caid)) $this->renderError('请求失败'); + + $query_res = pdo_get(PDO_NAME . 'member_thumbs_up_activities', ['mid' => $mid, 'campus_activities_id' => $caid]); + if ($query_res) { + $del_res = pdo_delete(PDO_NAME . 'member_thumbs_up_activities',['id' => $query_res['id']]); + if (!$del_res) $this->renderError('取消点赞失败'); + $this->renderSuccess('已取消'); + } + $data = [ + 'mid' => $mid, + 'campus_activities_id' => $caid, + 'create_time' => time() + ]; + $result = pdo_insert(PDO_NAME . 'member_thumbs_up_activities', $data); + if (!$result) $this->renderError('点赞失败'); + $this->renderSuccess('点赞成功'); + } + /** + * 短信验证码验证 + * @param $mobile + * @param $code + * @return void + */ + private function checkCode($mobile,$code) { + $pin_info = pdo_get('wlmerchant_pincode' , ['mobile' => $mobile]); + if (empty($pin_info)) { + $this->renderError('验证码错误'); + } + if ($pin_info['time'] < time() - 300) { + $this->renderError('验证码已过期,请重新获取'); + } + if ($code != $pin_info['code']) $this->renderError('验证码错误'); + } + + /** + * 编辑-发布校园活动 + * @return void + */ + public function getCampusActivities() + { + global $_W, $_GPC; + + $id = $_GPC['id']; + $mid = $_W['mid']; + $member = pdo_get(PDO_NAME . 'member',['id' => $mid],['identity_id','rights']); + $identity_id = $member['identity_id']; + if ($identity_id != 7) $this->renderError('非达人身份,无法访问'); + # 验证用户权限 + $validateRights = Member::validateMemberRights($mid,'campus_activities',$member); + if (!$validateRights['status']) $this->renderError($validateRights['msg']); + $categoryList = Category::getChildCategoryAll(6,['id','name'],true); + $data = [ + 'id' => '', + 'title' => '', + 'cc_id' => '', + 'describe' => '', + 'promotional_img' => '', + 'status' => 0, + 'reject' => '' + ]; + if (!empty($id)) { + $queryRes = pdo_get(PDO_NAME . 'member_campus_activities',['id' => $id],array_keys($data)); + if (!empty($queryRes)) { + $data = $queryRes; + if ($data['status'] != 2) $data['reject'] = ''; + } + } + #unset($data['status']); + + $this->renderSuccess('成功',['list' => $data, 'category_list' => $categoryList]); + } + + /** + * 保存-发布校园活动 + * @return void + */ + public function publishCampusActivities() + { + global $_W, $_GPC; + + $mid = $_W['mid']; + $id = $_GPC['id']; + $cc_id = $_GPC['cc_id']; + $title = trim($_GPC['title']); + $describe = $_GPC['describe']; + $promotional_img = trim($_GPC['promotional_img']); + // 验证必填数据 + if (empty($title)) $this->renderError('请填写活动标题'); + if (empty($describe)) $this->renderError('请填写活动内容'); + if (empty($promotional_img)) $this->renderError('请上传活动宣传图'); + // 验证数据是否违规 + $textRes = Filter::init($title,$_W['source'],1); + if($textRes['errno'] == 0) $this->renderError('活动标题'.$textRes['message']); + $textRes = Filter::init($describe,$_W['source'],1); + if($textRes['errno'] == 0) $this->renderError('活动内容'.$textRes['message']); + $textRes = Filter::init($promotional_img,$_W['source'],2); + if($textRes['errno'] == 0) $this->renderError('活动宣传图'.$textRes['message']); + // 验证活动标题是否存在 + $queryWhere = " title = '{$title}'"; + $queryWhere .= $id ? " and id != {$id} " : ''; + $queryRes = pdo_get(PDO_NAME . 'member_campus_activities',$queryWhere,'id'); + if ($queryRes) $this->renderError('活动标题:'.$title.',已存在'); + // 新增|修改数据 + $data = [ + 'uniacid' => $_W['uniacid'], + 'title' => $title, + 'cc_id' => $cc_id, + 'describe' => htmlspecialchars_decode($describe), + 'promotional_img' => $promotional_img + ]; + if ($id) { + $data['status'] = 0; + $data['update_time'] = time(); + $updateRes = pdo_update(PDO_NAME . 'member_campus_activities',$data,['id' => $id]); + if (!$updateRes) $this->renderError('提交失败'); + } else { + $data['create_place'] = 2; + $data['create_user_id'] = $mid; + $data['create_time'] = time(); + $insertRes = pdo_insert(PDO_NAME . 'member_campus_activities',$data); + if (!$insertRes) $this->renderError('提交失败'); + } + + $this->renderSuccess('提交成功'); + } +} \ No newline at end of file diff --git a/addons/weliam_smartcity/core/class/Cache.class.php b/addons/weliam_smartcity/core/class/Cache.class.php new file mode 100644 index 0000000..10c586a --- /dev/null +++ b/addons/weliam_smartcity/core/class/Cache.class.php @@ -0,0 +1,112 @@ + time()) return false; + $singleCache = self::getCache($arr['tablename'], $arr['single']); + if (!empty($singleCache) && $singleCache > time()) return false; + + return self::setCache($arr['tablename'], $arr['single'], time() + $time); + } + + /** + * 写入表cache锁 + * + * @access static public + * @name setTableLockByCache + * @param $arr [tablename] + * @param $time 加锁时间 + * @return false|true + */ + static function setTableLockByCache($arr, $time = 15) { + if ($arr == '' || empty($arr) || $arr['single'] == 'table') return false; + $tableCache = self::getCache($arr['tablename'], 'table'); + if (!empty($tableCache) && $tableCache > time()) return false; + + return self::setCache($arr['tablename'], 'table', time() + $time); + } +} diff --git a/addons/weliam_smartcity/core/class/FilesHandle.class.php b/addons/weliam_smartcity/core/class/FilesHandle.class.php new file mode 100644 index 0000000..b662d3c --- /dev/null +++ b/addons/weliam_smartcity/core/class/FilesHandle.class.php @@ -0,0 +1,138 @@ +read())) { + if ($item == '.' || $item == '..') { + continue; + } + if (is_dir($op->path . '/' . $item)) { + self::file_delete_all($op->path . '/' . $item); + rmdir($op->path . '/' . $item); + } else { + unlink($op->path . '/' . $item); + } + } + if ($delall == 1) { + rmdir($path); + } + } + + //查找目录下所有php文件 + static function file_findphp($path) { + $up_filestree = self::file_tree($path); + + $upgrade = array(); + foreach ($up_filestree as $sf) { + $file_bs = substr($sf, -3); + if ($file_bs == 'php') { + $upgrade[] = array('path' => str_replace($path . '/', "", $sf), 'fullpath' => $sf); + } + } + + return $upgrade; + } + + //删除所有空目录 + static function file_rm_empty_dir($path) { + if (is_dir($path) && ($handle = opendir($path)) !== false) { + while (($file = readdir($handle)) !== false) {// 遍历文件夹 + if ($file != '.' && $file != '..') { + $curfile = $path . '/' . $file; + // 当前目录 + if (is_dir($curfile)) {// 目录 + self::file_rm_empty_dir($curfile); + // 如果是目录则继续遍历 + if (count(scandir($curfile)) == 2) {//目录为空,=2是因为.和..存在 + rmdir($curfile); + // 删除空目录 + } + } + } + } + closedir($handle); + } + } +} \ No newline at end of file diff --git a/addons/weliam_smartcity/core/class/Func_loader.class.php b/addons/weliam_smartcity/core/class/Func_loader.class.php new file mode 100644 index 0000000..224c183 --- /dev/null +++ b/addons/weliam_smartcity/core/class/Func_loader.class.php @@ -0,0 +1,101 @@ +func('file'); + load()->func('communication'); + //采集规则 + $html = ihttp_request($url, '', array('CURLOPT_REFERER' => 'http://www.qq.com')); + // $html = file_get_contents($url); + $html = str_replace("", "", $html['content']); + $reg = array( + //采集文章标题 + 'title' => array('#activity-name', 'text'), + //采集文章发布日期,这里用到了QueryList的过滤功能,过滤掉span标签和a标签 + //采集文章正文内容,利用过滤功能去掉文章中的超链接,但保留超链接的文字,并去掉版权、JS代码等无用信息 + 'content' => array('#js_content', 'html'), + 'nickname' => array('.profile_nickname', 'text'), + 'video' => array('.video_iframe', 'data-src', '', function ($video) { + $video = explode('vid=', $video); + $video = explode('&', $video['1']); + return $video['0']; + }), + 'logo' => array(':contains(msg_cdn_url)', 'text', '', function ($logo) { + $logo = explode('var msg_cdn_url = "', $logo); + $logo = explode('";', $logo['1']); + $logo = 'web/index.php?c=utility&a=wxcode&do=image&attach=' . $logo['0']; + return $logo; + }), + 'desc' => array(':contains(msg_cdn_url)', 'text', '', function ($desc) { + $desc = explode('var msg_desc = "', $desc); + $desc = explode('";', $desc['1']); + return $desc['0']; + }), + ); + + $rang = 'body'; + $ql = QueryList::Query($html, $reg, $rang, 'UTF-8'); + + $con = $ql->getData(); + $contents = $con['0']['content']; + //如果出现中文乱码使用下面代码 + //$getcontent = iconv("gb2312", "utf-8",$contents); + preg_match_all('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $contents, $match); + $pic1 = $match['0']; + $img = $match['2']; + + foreach ($pic1 as $key => $value) { + $url = $value; + $path = $_W['siteroot'] . 'web/index.php?c=utility&a=wxcode&do=image&attach=' . $img[$key]; + + // $imgarr = getimagesize($path); + // if ($imgarr['0'] > 300 && $imgarr['1'] > 10) { + // $fileurl = ''; + // } else { + // $fileurl = ''; + // } + // if ($imgarr['0'] > 300 && $imgarr['1'] > 200) { + // if ($key < 4) { + // $pic .= tomedia($path) . ','; + // } + // } + $fileurl = ''; + $pic .= tomedia($path) . ','; + $contents = str_replace("{$url}", $fileurl, $contents); + } + preg_match_all('/<\s*iframe\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $contents, $match); + $fs = $match['0']; + $fskey = $match['2']; + foreach ($fs as $key => $value) { + $fileurl = ""; + $contents = str_replace("$value", $fileurl, $contents); + } + $pic = rtrim($pic, ","); + $pic = explode(",", $pic); + if (count($pic) == 3) { + $pic = iserializer($pic); + } else { + $pic = null; + } + $data = array( + 'title' => $con['0']['title'], + 'contents' => $contents, + 'desc' => $con['0']['desc'], + 'pic' => $pic, + 'vid' => $con['0']['video'], + 'thumb' => $_W['siteroot'] . $con['0']['logo'], + 'nickname' => $con['0']['nickname'] + ); + + return $data; + } +} \ No newline at end of file diff --git a/addons/weliam_smartcity/core/class/Jurisdiction.class.php b/addons/weliam_smartcity/core/class/Jurisdiction.class.php new file mode 100644 index 0000000..d2129e3 --- /dev/null +++ b/addons/weliam_smartcity/core/class/Jurisdiction.class.php @@ -0,0 +1,271 @@ + [ + 'title' => '首页管理', + 'list' => [ + ['name' => '运营概况','url' => 'dashboard/dashboard','home'=>'index'], + ['name' => '公告','url' => 'dashboard/notice','home'=>'index'], + ['name' => '幻灯片','url' => 'dashboard/adv','home'=>'index'], + ['name' => '导航栏','url' => 'dashboard/nav','home'=>'index'], + ['name' => '广告栏','url' => 'dashboard/banner','home'=>'index'], + ['name' => '商品魔方','url' => 'dashboard/cube','home'=>'index'], + ['name' => '选项卡管理','url' => 'dashboard/plugin','home'=>'index'], + ['name' => '底部菜单','url' => 'dashboard/foot','home'=>'index'], + ['name' => '页面链接','url' => 'dashboard/pagelinks','home'=>'index'], + ] + ], + //商户管理 + 'store' => [ + 'title' => '商户管理', + 'list' => [ + ['name' => '商户列表','url' => 'store/merchant','home'=>'index'], + ['name' => '商户分类','url' => 'store/category','home'=>'index'], + ['name' => '入驻申请','url' => 'store/storeApply','home'=>'index'], + ['name' => '付费记录','url' => 'store/register','home'=>'chargerecode'], + ['name' => '入驻套餐','url' => 'store/storeSetMeal','home'=>'chargelist'], + ['name' => '全部评论','url' => 'store/storeComment','home'=>'index'], + ['name' => '商户动态','url' => 'store/storeDynamic','home'=>'dynamic'], + ] + ], + //订单管理 + 'order' => [ + 'title' => '订单管理', + 'list' => [ + ['name' => '商品订单','url' => 'order/wlOrder','home'=>'orderlist'], + ['name' => '在线买单','url' => 'order/orderPayOnline','home'=>'payonlinelist'], + ['name' => '运费模板','url' => 'order/orderFreightTemplate','home'=>'freightlist'], + ['name' => '售后记录','url' => 'order/orderAfterSales','home'=>'afterlist'], + ] + ], + //财务管理 + 'finace' => [ + 'title' => '财务管理', + 'list' => [ + ['name' => '账单明细','url' => 'finace/finaceBill','home'=>'cashrecord'], + ['name' => '退款记录','url' => 'finace/finaceRefundRecord','home'=>'refundrecord'], + ['name' => '账户管理','url' => 'finace/newCash','home'=>'currentlist','params'=>['type'=>'store']], + ] + ], + //数据管理 + 'datacenter' => [ + 'title' => '数据管理', + 'list' => [ + ['name' => '统计管理','url' => 'datacenter/datacenter','home'=>'stat_operate'], + ] + ], + //应用管理 + 'app' => [ + 'title' => '应用管理', + 'list' => '', + ], + //设置管理 + 'agentset' => [ + 'title' => '设置管理', + 'list' => [ + ['name' => '员工管理','url' => 'agentset/agentSetStaff','home'=>'adminset'], + ['name' => '社群设置','url' => 'agentset/agentSetCommunity','home'=>'communityList'], + ['name' => '标签设置','url' => 'agentset/agentSetTags','home'=>'tags'], + ['name' => '自定义表单','url' => 'agentset/diyForm','home'=>'index'], + ] + ], + ]; + //只显示该平台拥有的应用(插件) + if (agent_p('groupon')) $appList[] = ['name' => '团购活动','url' => 'groupon/active','home'=>'activelist','keyword' => 'groupon']; + if (agent_p('rush')) $appList[] = ['name' => '抢购活动','url' => 'rush/active','home'=>'activelist','keyword' => 'rush']; + if (agent_p('wlfightgroup')) $appList[] = ['name' => '拼团商城','url' => 'wlfightgroup/fightgoods','home'=>'ptgoodslist','keyword' => 'wlfightgroup']; + if (agent_p('bargain')) $appList[] = ['name' => '砍价活动','url' => 'bargain/bargain_web','home'=>'activitylist','keyword' => 'bargain']; + if (agent_p('paidpromotion')) $appList[] = ['name' => '支付有礼','url' => 'paidpromotion/payactive','home'=>'activelist','keyword' => 'paidpromotion']; + if (agent_p('pocket')) $appList[] = ['name' => '掌上信息','url' => 'pocket/Tiezi','home'=>'lists','keyword' => 'pocket']; + if (agent_p('diypage')) $appList[] = ['name' => '平台装修','url' => 'diypage/diy','home'=>'pagelist','keyword' => 'diypage']; + if (agent_p('wlcoupon')) $appList[] = ['name' => '超级券','url' => 'wlcoupon/couponlist','home'=>'couponsList','keyword' => 'wlcoupon']; + if (agent_p('call')) $appList[] = ['name' => '集Call','url' => 'call/call','home'=>'callList','keyword' => 'call']; + if (agent_p('headline')) $appList[] = ['name' => '头条','url' => 'headline/headline','home'=>'infoList','keyword' => 'headline']; + if (agent_p('citycard')) $appList[] = ['name' => '同城名片','url' => 'citycard/citycard','home'=>'card_lists','keyword' => 'citycard']; + if (agent_p('salesman')) $appList[] = ['name' => '业务员','url' => 'salesman/salesman','home'=>'lists','keyword' => 'salesman']; + if (agent_p('yellowpage')) $appList[] = ['name' => '黄页114','url' => 'yellowpage/yellowpage','home'=>'page_lists','keyword' => 'yellowpage']; + if (agent_p('citydelivery')) $appList[] = ['name' => '同城配送','url' => 'citydelivery/active','home'=>'activelist','keyword' => 'citydelivery']; + if (agent_p('activity')) $appList[] = ['name' => '同城活动','url' => 'activity/activity_web','home'=>'activitylist','keyword' => 'activity']; + if (agent_p('redpack')) $appList[] = ['name' => '线上红包','url' => 'redpack/redpack','home'=>'pack_lists','keyword' => 'redpack']; + if (agent_p('recruit')) $appList[] = ['name' => '求职招聘','url' => 'recruit/industryPosition','home'=>'industryList','keyword' => 'recruit']; + if (agent_p('dating')) $appList[] = ['name' => '相亲交友','url' => 'dating/member','home'=>'memberList','keyword' => 'dating']; + if (agent_p('attestation')) $appList[] = ['name' => '认证中心','url' => 'attestation/attestation','home'=>'attestationList','keyword' => 'attestation']; + if (agent_p('vehicle')) $appList[] = ['name' => '顺风车','url' => 'vehicle/route','home'=>'routeList','keyword' => 'vehicle']; + if (agent_p('housekeep')) $appList[] = ['name' => '家政服务','url' => 'housekeep/KeepWeb','home'=>'serviceList','keyword' => 'housekeep']; + if (uniacid_p('housekeep')) $appList[] = ['name' => '票付通','url' => 'pftapimod/basicSetting','home'=>'basicSetting','keyword' => 'pftapimod']; + //平台管理员信息补充 + if($_W['aid'] <= 0){ + //插件权限补充 + if (uniacid_p('ydbapp')) $appList[] = ['name' => 'APP','url' => 'ydbapp/appset','home'=>'setting']; + if (uniacid_p('wxplatform')) $appList[] = ['name' => '微信公众号','url' => 'wxplatform/wechat','home'=>'info']; + if (uniacid_p('wxapp')) $appList[] = ['name' => '微信小程序','url' => 'wxapp/wxappset','home'=>'wxapp_info']; + if (uniacid_p('payback')) $appList[] = ['name' => 'NEW支付返现','url' => 'payback/payback','home'=>'cashBackRecord']; + if (uniacid_p('halfcard')) $appList[] = ['name' => '一卡通','url' => 'halfcard/halftype','home'=>'memberlist']; + if (uniacid_p('cashback')) $appList[] = ['name' => '支付返现','url' => 'cashback/cashback','home'=>'cashBackRecord']; + if (uniacid_p('subposter')) $appList[] = ['name' => '倡议关注海报','url' => 'subposter/subposter','home'=>'setting']; + if (uniacid_p('sharegift')) $appList[] = ['name' => '分享有礼','url' => 'sharegift/sharebase','home'=>'sharerecord']; + if (uniacid_p('ranklist')) $appList[] = ['name' => '排行榜','url' => 'ranklist/rank','home'=>'rank_list']; + if (uniacid_p('fullreduce')) $appList[] = ['name' => '满减活动','url' => 'fullreduce/fullreduce','home'=>'activelist']; + if (uniacid_p('consumption')) $appList[] = ['name' => '积分商城','url' => 'consumption/consumptionset','home'=>'consumptionapi']; + if (uniacid_p('wlsign')) $appList[] = ['name' => '积分签到','url' => 'wlsign/signset','home'=>'signrule']; + if (uniacid_p('taxipay')) $appList[] = ['name' => '出租车买单','url' => 'taxipay/taxipay','home'=>'master_lists']; + if (uniacid_p('distribution')) $appList[] = ['name' => '分销合伙人','url' => 'distribution/dissysbase','home'=>'distributorlist']; + if (uniacid_p('draw')) $appList[] = ['name' => '幸运抽奖','url' => 'draw/draw','home'=>'index']; + if (uniacid_p('openapi')) $appList[] = ['name' => '开放接口','url' => 'openapi/apilist','home'=>'apimanage']; + if (uniacid_p('weliam_house')) $appList[] = ['name' => '智慧房产','url' => 'weliam_house/house','home'=>'home']; + if (uniacid_p('live')) $appList[] = ['name' => '直播管理','url' => 'live/live','home'=>'liveList']; + if (uniacid_p('helper')) $appList[] = ['name' => '帮助中心','url' => 'helper/helperquestion','home'=>'lists']; + if (uniacid_p('news')) $appList[] = ['name' => '消息管理','url' => 'news/template','home'=>'index']; + if (uniacid_p('diyposter')) $appList[] = ['name' => '自定义海报','url' => 'diyposter/poster','home'=>'lists']; + if (uniacid_p('mobilerecharge')) $appList[] = ['name' => '话费充值','url' => 'mobilerecharge/mrecharge','home'=>'orderList','keyword' => 'mobilerecharge']; + //商户权限补充 + $list['store']['list'][] = ['name' => '入驻设置','url' => 'store/settled','home'=>'baseset']; + $list['store']['list'][] = ['name' => '基本设置','url' => 'store/comment','home'=>'storeSet']; + //订单权限补充 + $list['order']['list'][] = ['name' => '订单设置','url' => 'order/orderSet','home'=>'orderset']; + //财务权限补充 + $list['finace']['list'][] = ['name' => '提现申请','url' => 'finace/finaceWithdrawalApply','home'=>'cashApply']; + $list['finace']['list'][] = ['name' => '财务设置','url' => 'finace/wlCash','home'=>'cashset']; + //设置权限补充 + $list['agentset']['list'][] = ['name' => '基本设置管理','url' => 'setting/shopset','home'=>'base'];//包括基础设置、客服设置、分享关注、接口设置、文字设置 + $list['agentset']['list'][] = ['name' => '交易管理','url' => 'setting/settingTransaction','home'=>'recharge']; + $list['agentset']['list'][] = ['name' => '个人中心','url' => 'agentset/userset','home'=>'userindex']; + $list['agentset']['list'][] = ['name' => '支付管理','url' => 'setting/pay','home'=>'index']; + //用户权限补充 + $list['member'] = [ + 'title' => '客户', + 'list' => [ + ['name' => '客户管理与设置','url' => 'member/wlMember','home'=>'index'], + ['name' => '通信管理','url' => 'member/userIm','home'=>'index'], + ['name' => '客户标签','url' => 'member/userlabel','home'=>'labellist'], + ['name' => '用户财务明细','url' => 'member/memberFinancialDetails','home'=>'recharge'], + ] + ]; + //代理权限补充 + if (p('area')) { + $list['area'] = [ + 'title' => '代理', + 'list' => [ + ['name' => '代理列表&分组','url' => 'area/areaagent','home'=>'agentIndex'], + ['name' => '地区列表&分组','url' => 'area/hotarea','home'=>'oparealist'], + ['name' => '自定义地区','url' => 'area/custom','home'=>'index'], + ['name' => '复制数据','url' => 'area/areadb','home'=>'copydata'], + ['name' => '代理设置','url' => 'area/areaset','home'=>'setting'], + ] + ]; + } + }else{ + //代理商独有权限 + //财务 + $list['finace']['list'][] = ['name' => '提现管理','url' => 'finace/finaceWithdrawal','home'=>'cashApply'];//代理商余额提现、提现账户、提现记录 + //设置 + $list['agentset']['list'][] = ['name' => '账号信息','url' => 'agentset/agentSetAccount','home'=>'profile']; + $list['agentset']['list'][] = ['name' => '客服设置','url' => 'agentset/userset','home'=>'agentcustomer']; + //应用 + if (p('halfcard')) $appList[] = ['name' => '一卡通','url' => 'halfcard/halfcard_web','home'=>'halfcardList','keyword' => 'halfcard']; + + //判断代理是否有插件权限 + $category = App::get_cate_plugins('agent'); + $newlist = []; + foreach ($category as $car){ + if(!empty($car['plugins'])){ + foreach ($car['plugins'] as $plu){ + $newlist[] = $plu['ident']; + } + } + } + foreach($appList as $ak => $app){ + if(!in_array($app['keyword'],$newlist)){ + unset($appList[$ak]); + } + } + } + + $list['app']['list'] = $appList; + return $list; + } + /** + * Comment: 判断代理商员工拥有的主要功能菜单的权限 + * Author: zzw + * Date: 2020/12/31 16:23 + * @param $list + * @return array|null + */ + static public function judgeMainMenu($list){ + //获取全部的权限菜单列表 + $menuList = self::menuList();//获取当前端口需要判断权限的所有菜单 + $menuListKeys = array_keys($menuList);//需要判断权限的菜单的别名列表 + $top_menus = is_store() ? Menus_store::topmenus() : (is_agent() ? Menus::topmenus() : Menus_sys::topmenus());//获取当前端口菜单列表 + $jurisdiction = array_column($top_menus,'jurisdiction');//获取权限别名列表 + //判断权限 + foreach($jurisdiction as $index => $item){ + $pathList = array_column($menuList[$item]['list'], 'url'); + #当前菜单需要判断权限 并且不存在拥有权限的子菜单 删除当前菜单 + if(in_array($item,$menuListKeys) && count(array_intersect($pathList,$list)) <= 0){ + unset($jurisdiction[$index]); + } + } + + + return array_values($jurisdiction); + } + /** + * Comment: 员工权限判断 + * Author: zzw + * Date: 2021/1/8 15:21 + */ + static public function judge(){ + global $_W,$_GPC; + //基本参数信息获取 + $jurisdiction = $_W['jurisdiction'];//当前员工的权限 + $pAc = $_GPC['p'].'/'.$_GPC['ac'];//前往页面的路径 + $permissionList = Jurisdiction::menuList();//所有加入权限控制的控制器列表 + $infoList = array_column($permissionList,'list');//权限列表 + $isJurisdiction = $_GPC['is_jurisdiction'] ? : 0;//是否判断权限,用于某些跨控制器跳转使用。1则不判断权限,强制通过 + //循环获取全部的url信息 + $urlInfoList = [];//需要权限的全部信息列表 + foreach($infoList as $listKey => $ListVal){ + $urlInfoList = array_merge($urlInfoList,$ListVal); + } + $_W['JUrlList'] = $urlList = array_column($urlInfoList,'url');//需要权限的全部路径列表 + //进行员工权限的判断 当:当前gotopath需要权限并且员工拥有该权限才会进入 否则返回上一页面 + if(in_array($pAc, $urlList) && !in_array($pAc, $jurisdiction) && $isJurisdiction != 1){ + //没有当前访问方法的权限 进行顺推,查看拥有哪一个的方法进行访问 + $groupList = $permissionList[$_GPC['p']]['list']; + $sortList = array_column($groupList,'url'); + foreach ($sortList as $VisitKey => $VisitVal){ + if(in_array($VisitVal, $jurisdiction)) { + //获取以当前路径作为键的新数组 + $rewardList = array_combine($sortList,$groupList); + $goToPath = $rewardList[$VisitVal]['url'] . '/' . $rewardList[$VisitVal]['home']; + header('Location: '.web_url($goToPath,$rewardList[$VisitVal]['params'])); + die; + } + } + //没有当前访问控制器/模块中任何方法的访问权限 获取第一个拥有权限的页面 + foreach($urlList as $urlListKey => $urlListVal){ + if($urlListVal == $jurisdiction[0]){ + $rewardList = array_combine($urlList,$urlInfoList); + $goToPath = $rewardList[$urlListVal]['url'] . '/' . $rewardList[$urlListVal]['home']; + + header('Location: '.web_url($goToPath,$rewardList[$urlListVal]['params'])); + die; + } + } + } + } + + + +} diff --git a/addons/weliam_smartcity/core/class/MapService.class.php b/addons/weliam_smartcity/core/class/MapService.class.php new file mode 100644 index 0000000..31aa1d4 --- /dev/null +++ b/addons/weliam_smartcity/core/class/MapService.class.php @@ -0,0 +1,77 @@ +,lng<经度> + * @param $get_poi 是否返回周边POI列表:1.返回;0不返回(默认) + * @return JSON + */ + static function guide_gcoder($location, $get_poi = 0) { + if (empty($location)) { + return error(1, '位置坐标不得为空'); + } + $apiurl = 'https://apis.map.qq.com/ws/geocoder/v1/?location=' . $location . '&key=' . self::get_key() . '&get_poi=' . $get_poi; + return self::get_content($apiurl); + } + + /** + * 地址搜索https://lbs.qq.com/webservice_v1/guide-search.html + * @param $keyword POI搜索关键字,用于全文检索字段 + * @param $boundary 搜索地理范围 + * @return JSON + */ + static function guide_search($keyword, $boundary) { + if (empty($keyword)) { + return error(1, '搜索关键字不得为空'); + } + if (empty($boundary)) { + return error(1, '搜索地理范围不得为空'); + } + $apiurl = 'https://apis.map.qq.com/ws/place/v1/search?keyword=' . urlencode($keyword) . '&key=' . self::get_key() . '&boundary=' . $boundary; + return self::get_content($apiurl); + } + + /** + * IP定位https://lbs.qq.com/webservice_v1/guide-ip.html + * @param $ip IP地址,缺省时会使用请求端的IP + * @return JSON + */ + static function guide_ip($ip) { + if (empty($ip)) { + return error(1, 'IP地址不得为空'); + } + $apiurl = 'https://apis.map.qq.com/ws/location/v1/ip?ip=' . $ip . '&key=' . self::get_key(); + return self::get_content($apiurl); + } +} \ No newline at end of file diff --git a/addons/weliam_smartcity/core/class/Menus.class.php b/addons/weliam_smartcity/core/class/Menus.class.php new file mode 100644 index 0000000..b9ec94c --- /dev/null +++ b/addons/weliam_smartcity/core/class/Menus.class.php @@ -0,0 +1,574 @@ +   平台'; + $frames['dashboard']['url'] = web_url('dashboard/dashboard'); + $frames['dashboard']['active'] = 'dashboard'; + $frames['dashboard']['jurisdiction'] = 'dashboard'; + + if (file_exists(PATH_MODULE . 'jimaiwang.log')) { + $frames['member']['title'] = '   客户'; + $frames['member']['url'] = web_url('member/wlMember/index'); + $frames['member']['active'] = 'member'; + } + + $frames['store']['title'] = '   商户'; + $frames['store']['url'] = web_url('store/merchant/index', array('enabled' => '')); + $frames['store']['active'] = 'store'; + $frames['store']['jurisdiction'] = 'store'; + +// $frames['goods']['title'] = '   商品'; +// $frames['goods']['url'] = web_url('goods/Goods/index'); +// $frames['goods']['active'] = 'goods'; +// $frames['goods']['jurisdiction'] = 'goods'; + + $frames['order']['title'] = '   订单'; + $frames['order']['url'] = web_url('order/wlOrder/orderlist'); + $frames['order']['active'] = 'order'; + $frames['order']['jurisdiction'] = 'order'; + + $frames['finance']['title'] = '   财务'; + $frames['finance']['url'] = web_url('finace/finaceBill/cashrecord'); + $frames['finance']['active'] = 'finace'; + $frames['finance']['jurisdiction'] = 'finace'; + + $frames['data']['title'] = '   数据'; + $frames['data']['url'] = web_url('datacenter/datacenter/stat_operate'); + $frames['data']['active'] = 'datacenter'; + $frames['data']['jurisdiction'] = 'datacenter'; + + $frames['app']['title'] = '   应用'; + $frames['app']['url'] = web_url('app/plugins'); + $frames['app']['active'] = $appact; + $frames['app']['jurisdiction'] = 'app'; + + $frames['setting']['title'] = '   设置'; + $frames['setting']['url'] = web_url('agentset/agentSetAccount/profile'); + $frames['setting']['active'] = 'agentset'; + $frames['setting']['jurisdiction'] = 'agentset'; + + + return $frames; + } + + /** + * static function 首页左侧列表 + * + * @access static + * @name getdashboardFrames + * @param + * @return array + */ + static function getdashboardFrames() { + global $_W; + $frames = array(); + $frames['member']['title'] = '   概况'; + $frames['member']['items'] = array(); + + $frames['member']['items']['setting']['url'] = web_url('dashboard/dashboard/index'); + $frames['member']['items']['setting']['title'] = '运营概况'; + $frames['member']['items']['setting']['actions'] = array('ac', 'dashboard'); + $frames['member']['items']['setting']['active'] = ''; + + $frames['page']['title'] = '   主页管理'; + $frames['page']['items'] = array(); + $frames['page']['items']['notice']['url'] = web_url('dashboard/notice/index'); + $frames['page']['items']['notice']['title'] = '公告'; + $frames['page']['items']['notice']['actions'] = array('ac', 'notice'); + $frames['page']['items']['notice']['active'] = ''; + + $frames['page']['items']['adv']['url'] = web_url('dashboard/adv/index'); + $frames['page']['items']['adv']['title'] = '幻灯片'; + $frames['page']['items']['adv']['actions'] = array('ac', 'adv'); + $frames['page']['items']['adv']['active'] = ''; + + $frames['page']['items']['nav']['url'] = web_url('dashboard/nav/index'); + $frames['page']['items']['nav']['title'] = '导航栏'; + $frames['page']['items']['nav']['actions'] = array('ac', 'nav'); + $frames['page']['items']['nav']['active'] = ''; + + $frames['page']['items']['banner']['url'] = web_url('dashboard/banner/index'); + $frames['page']['items']['banner']['title'] = '广告栏'; + $frames['page']['items']['banner']['actions'] = array('ac', 'banner'); + $frames['page']['items']['banner']['active'] = ''; + + $frames['page']['items']['cube']['url'] = web_url('dashboard/cube/index'); + $frames['page']['items']['cube']['title'] = '商品魔方'; + $frames['page']['items']['cube']['actions'] = array('ac', 'cube'); + $frames['page']['items']['cube']['active'] = ''; + +// $frames['page']['items']['sort']['url'] = web_url('dashboard/sort/index'); +// $frames['page']['items']['sort']['title'] = '主页排版'; +// $frames['page']['items']['sort']['actions'] = array(); +// $frames['page']['items']['sort']['active'] = ''; + + $frames['page']['items']['plugin']['url'] = web_url('dashboard/plugin/index'); + $frames['page']['items']['plugin']['title'] = '选项卡管理'; + $frames['page']['items']['plugin']['actions'] = array('ac', 'plugin'); + $frames['page']['items']['plugin']['active'] = ''; + + $frames['page']['items']['foot']['url'] = web_url('dashboard/foot/index'); + $frames['page']['items']['foot']['title'] = '底部菜单'; + $frames['page']['items']['foot']['actions'] = array('ac', 'foot'); + $frames['page']['items']['foot']['active'] = ''; + + $frames['other']['title'] = '   其他信息'; + $frames['other']['items'] = array(); + $frames['other']['items']['notice']['url'] = web_url('dashboard/pagelinks/index'); + $frames['other']['items']['notice']['title'] = '页面链接'; + $frames['other']['items']['notice']['actions'] = array('ac', 'pagelinks'); + $frames['other']['items']['notice']['active'] = ''; + + return $frames; + } + + static function getmemberFrames() { + global $_W; + $frames = array(); + $frames['user']['title'] = '   客户'; + $frames['user']['items'] = array(); + + $frames['user']['items']['register']['url'] = web_url('member/wlMember/index'); + $frames['user']['items']['register']['title'] = '客户概况'; + $frames['user']['items']['register']['actions'] = array('ac', 'wlMember', 'do', 'index'); + $frames['user']['items']['register']['active'] = ''; + + $frames['user']['items']['notice']['url'] = web_url('member/wlMember/memberIndex'); + $frames['user']['items']['notice']['title'] = '客户列表'; + $frames['user']['items']['notice']['actions'] = array('ac', 'wlMember', 'do', array('memberIndex', 'memberDetail')); + $frames['user']['items']['notice']['active'] = ''; + + return $frames; + } + + static function getfinaceFrames() { + global $_W, $_GPC; + $frames = array(); + + $frames['cashSurvey']['title'] = '   财务'; + $frames['cashSurvey']['items'] = array(); + +// $frames['cashSurvey']['items']['datemana']['url'] = web_url('finace/wlCash/cashSurvey'); +// $frames['cashSurvey']['items']['datemana']['title'] = '财务概况'; +// $frames['cashSurvey']['items']['datemana']['actions'] = array(); +// $frames['cashSurvey']['items']['datemana']['active'] = ''; + + $frames['cashSurvey']['items']['cashrecord']['url'] = web_url('finace/finaceBill/cashrecord'); + $frames['cashSurvey']['items']['cashrecord']['title'] = '账单明细'; + $frames['cashSurvey']['items']['cashrecord']['actions'] = array(); + $frames['cashSurvey']['items']['cashrecord']['active'] = ''; + + $frames['cashSurvey']['items']['refundrecord']['url'] = web_url('finace/finaceRefundRecord/refundrecord'); + $frames['cashSurvey']['items']['refundrecord']['title'] = '退款记录'; + $frames['cashSurvey']['items']['refundrecord']['actions'] = array(); + $frames['cashSurvey']['items']['refundrecord']['active'] = ''; + + $frames['cashApplyAgent']['title'] = '   提现'; + $frames['cashApplyAgent']['items'] = array(); + + $frames['cashApplyAgent']['items']['display1']['url'] = web_url('finace/finaceWithdrawal/cashApplyAgent', array('status' => '1')); + $frames['cashApplyAgent']['items']['display1']['title'] = '余额提现'; + $frames['cashApplyAgent']['items']['display1']['actions'] = array('do', 'cashApplyAgent', 'status', '1'); + $frames['cashApplyAgent']['items']['display1']['active'] = ''; + + $frames['cashApplyAgent']['items']['account']['url'] = web_url('finace/finaceWithdrawal/account'); + $frames['cashApplyAgent']['items']['account']['title'] = '提现账户'; + $frames['cashApplyAgent']['items']['account']['actions'] = array(); + $frames['cashApplyAgent']['items']['account']['active'] = ''; + + $frames['cashApplyAgent']['items']['display2']['url'] = web_url('finace/finaceWithdrawal/cashApplyAgentRecord'); + $frames['cashApplyAgent']['items']['display2']['title'] = '提现记录'; + $frames['cashApplyAgent']['items']['display2']['actions'] = array('do', 'cashApplyAgentRecord'); + $frames['cashApplyAgent']['items']['display2']['active'] = ''; + + if($_W['wlsetting']['cashset']['allocationtype']>0) { + $frames['cashAll']['title'] = '   分账'; + $frames['cashAll']['items'] = array(); + + $frames['cashAll']['items']['allidset']['url'] = web_url('finace/wlCash/allidset'); + $frames['cashAll']['items']['allidset']['title'] = '账户设置'; + $frames['cashAll']['items']['allidset']['actions'] = array('do', 'allidset'); + $frames['cashAll']['items']['allidset']['active'] = ''; + + } + + $frames['current']['title'] = '   账户'; + $frames['current']['items'] = array(); + + $frames['current']['items']['currentstore']['url'] = web_url('finace/newCash/currentlist', array('type' => 'store')); + $frames['current']['items']['currentstore']['title'] = '商家账户'; + $frames['current']['items']['currentstore']['actions'] = array('type', 'store'); + $frames['current']['items']['currentstore']['active'] = ''; + + $frames['current']['items']['currentmy']['url'] = web_url('finace/newCash/currentlist', array('type' => 'agent')); + $frames['current']['items']['currentmy']['title'] = '我的账户'; + $frames['current']['items']['currentmy']['actions'] = array('type', 'agent'); + $frames['current']['items']['currentmy']['active'] = ''; + + return $frames; + } + + /** + * static function 商户左侧列表 + * + * @access static + * @name getstoreFrames + * @param + * @return array + */ + static function getstoreFrames() { + global $_W, $_GPC; + $frames = array(); + + $frames['user']['title'] = '   商户管理'; + $frames['user']['items'] = array(); + $frames['user']['items']['index']['url'] = web_url('store/merchant/index', array('enabled' => '')); + $frames['user']['items']['index']['title'] = '商户列表'; + $frames['user']['items']['index']['actions'] = array('ac', 'merchant'); + $frames['user']['items']['index']['active'] = ''; + + $frames['user']['items']['category']['url'] = web_url('store/category/index'); + $frames['user']['items']['category']['title'] = '商户分类'; + $frames['user']['items']['category']['actions'] = array('ac', 'category'); + $frames['user']['items']['category']['active'] = ''; + + $frames['register']['title'] = '   入驻管理'; + $frames['register']['items'] = array(); + $frames['register']['items']['register']['url'] = web_url('store/storeApply/index'); + $frames['register']['items']['register']['title'] = '入驻申请'; + $frames['register']['items']['register']['actions'] = array('ac', 'storeApply', 'do', 'index'); + $frames['register']['items']['register']['active'] = ''; + + if ($_W['wlsetting']['register']['chargestatus']) { + $frames['register']['items']['chargerecode']['url'] = web_url('store/register/chargerecode'); + $frames['register']['items']['chargerecode']['title'] = '付费记录'; + $frames['register']['items']['chargerecode']['actions'] = array('ac', 'storeApply', 'do', 'chargerecode'); + $frames['register']['items']['chargerecode']['active'] = ''; + } + + if ($_W['wlsetting']['register']['agentright']) { + $frames['register']['items']['agentcharge']['url'] = web_url('store/storeSetMeal/chargelist'); + $frames['register']['items']['agentcharge']['title'] = '入驻套餐'; + $frames['register']['items']['agentcharge']['actions'] = array('ac', 'storeSetMeal', 'do', array('chargelist', 'add')); + $frames['register']['items']['agentcharge']['active'] = ''; + } + + $frames['comment']['title'] = '   评论与动态'; + $frames['comment']['items'] = array(); + $frames['comment']['items']['comment']['url'] = web_url('store/storeComment/index'); + $frames['comment']['items']['comment']['title'] = '全部评论'; + $frames['comment']['items']['comment']['actions'] = array('ac', 'storeComment', 'do', 'index'); + $frames['comment']['items']['comment']['active'] = ''; + + $frames['comment']['items']['dynamic']['url'] = web_url('store/storeDynamic/dynamic'); + $frames['comment']['items']['dynamic']['title'] = '商户动态'; + $frames['comment']['items']['dynamic']['actions'] = array('ac', 'storeDynamic', 'do', 'dynamic'); + $frames['comment']['items']['dynamic']['active'] = ''; + +// $frames['setting']['title'] = '   商户设置'; +// $frames['setting']['items'] = array(); +// $frames['setting']['items']['setting']['url'] = web_url('store/comment/storeSet'); +// $frames['setting']['items']['setting']['title'] = '基本设置'; +// $frames['setting']['items']['setting']['actions'] = array('ac', 'comment', 'do', 'index'); +// $frames['setting']['items']['setting']['active'] = ''; + + return $frames; + } + + /** + * static function 订单左侧列表 + * + * @access static + * @name getorderFrames + * @param + * @return array + */ + static function getorderFrames() { + global $_W; + $frames = array(); + $frames['order']['title'] = '  订单'; + $frames['order']['items'] = array(); + + $frames['order']['items']['orderlist']['url'] = web_url('order/wlOrder/orderlist'); + $frames['order']['items']['orderlist']['title'] = '商品订单'; + $frames['order']['items']['orderlist']['actions'] = array('ac', 'wlOrder', 'do', array('orderlist', 'orderdetail')); + $frames['order']['items']['orderlist']['active'] = ''; + + $frames['order']['items']['payonlinelist']['url'] = web_url('order/orderPayOnline/payonlinelist'); + $frames['order']['items']['payonlinelist']['title'] = '在线买单'; + $frames['order']['items']['payonlinelist']['actions'] = array('ac', 'orderPayOnline', 'do', 'payonlinelist'); + $frames['order']['items']['payonlinelist']['active'] = ''; + + $frames['freight']['title'] = '   运费'; + $frames['freight']['items'] = array(); + + $frames['freight']['items']['freightlist']['url'] = web_url('order/orderFreightTemplate/freightlist'); + $frames['freight']['items']['freightlist']['title'] = '运费模板'; + $frames['freight']['items']['freightlist']['actions'] = array('ac', 'orderFreightTemplate', 'do', 'freightlist'); + $frames['freight']['items']['freightlist']['active'] = ''; + + $frames['saleafter']['title'] = '   预约售后'; + $frames['saleafter']['items'] = array(); + + $frames['saleafter']['items']['afterlist']['url'] = web_url('order/orderAfterSales/afterlist'); + $frames['saleafter']['items']['afterlist']['title'] = '售后记录'; + $frames['saleafter']['items']['afterlist']['actions'] = array('ac', 'orderAfterSales', 'do', 'afterlist'); + $frames['saleafter']['items']['afterlist']['active'] = ''; + + $frames['saleafter']['items']['appointlist']['url'] = web_url('order/wlOrder/appointlist'); + $frames['saleafter']['items']['appointlist']['title'] = '预约记录'; + $frames['saleafter']['items']['appointlist']['actions'] = array('ac', 'wlOrder', 'do', 'appointlist'); + $frames['saleafter']['items']['appointlist']['active'] = ''; + + return $frames; + } + + static function getdatacenterFrames() { + global $_W; + $frames = array(); + + $frames['datacenter']['title'] = '   统计分析'; + $frames['datacenter']['items'] = array(); + $frames['datacenter']['items']['stat_operate']['url'] = web_url('datacenter/datacenter/stat_operate'); + $frames['datacenter']['items']['stat_operate']['title'] = '运营统计'; + $frames['datacenter']['items']['stat_operate']['actions'] = array(); + $frames['datacenter']['items']['stat_operate']['active'] = ''; + + $frames['datacenter']['items']['stat_store']['url'] = web_url('datacenter/datacenter/stat_store'); + $frames['datacenter']['items']['stat_store']['title'] = '店铺统计'; + $frames['datacenter']['items']['stat_store']['actions'] = array(); + $frames['datacenter']['items']['stat_store']['active'] = ''; + + if (file_exists(PATH_MODULE . 'TnSrtWDJ.log')) { + $frames['datacenter']['items']['stat_store_card']['url'] = web_url('datacenter/datacenter/stat_store_card'); + $frames['datacenter']['items']['stat_store_card']['title'] = '商户会员'; + $frames['datacenter']['items']['stat_store_card']['actions'] = array(); + $frames['datacenter']['items']['stat_store_card']['active'] = ''; + } + + return $frames; + } + + /** + * static function 应用左侧列表 + * + * @access static + * @name getappFrames + * @param + * @return array + */ + static function getappFrames() { + global $_W; + $frames = array(); + + $category = App::get_cate_plugins('agent'); + foreach ($category as $key => $value) { + if (!empty($value['plugins'])) { + $frames[$key]['title'] = '   ' . $value['name']; + $frames[$key]['items'] = array(); + foreach ($value['plugins'] as $pk => $plug) { + $frames[$key]['items'][$plug['ident']]['url'] = $plug['cover']; + $frames[$key]['items'][$plug['ident']]['title'] = $plug['name']; + $frames[$key]['items'][$plug['ident']]['actions'] = array('ac', $plug['ident']); + $frames[$key]['items'][$plug['ident']]['active'] = ''; + } + } + } + + return $frames; + } + + /** + * static function 应用左侧列表 + * + * @access static + * @name getappFrames + * @param + * @return array + */ + static function getgoodshouseFrames() { + global $_W, $_GPC; + $method = $_GPC['plugin'] ?: 'rush'; + $method = ($method != 'fightgroup') ? $method : 'wlfightgroup'; + $config = App::ext_plugin_config($method); + + return $config['menus']; + } + + static function getagentsetFrames() { + global $_W, $_GPC; + $frames = array(); + $frames['setting']['title'] = '   设置'; + $frames['setting']['items'] = array(); + $frames['setting']['items']['base']['url'] = web_url('agentset/agentSetAccount/profile'); + $frames['setting']['items']['base']['title'] = '账号信息'; + $frames['setting']['items']['base']['actions'] = array('ac', 'agentSetAccount', 'do', 'profile'); + $frames['setting']['items']['base']['active'] = ''; + + $frames['setting']['items']['share']['url'] = web_url('agentset/agentSetAccount/shareSet'); + $frames['setting']['items']['share']['title'] = '分享设置'; + $frames['setting']['items']['share']['actions'] = array('ac', 'agentSetAccount', 'do', 'shareSet'); + $frames['setting']['items']['share']['active'] = ''; + + $frames['setting']['items']['adminset']['url'] = web_url('agentset/agentSetStaff/adminset'); + $frames['setting']['items']['adminset']['title'] = '员工管理'; + $frames['setting']['items']['adminset']['actions'] = array('ac', 'agentSetStaff', 'do', 'adminset'); + $frames['setting']['items']['adminset']['active'] = ''; + + $frames['setting']['items']['community']['url'] = web_url('agentset/agentSetCommunity/communityList'); + $frames['setting']['items']['community']['title'] = '社群设置'; + $frames['setting']['items']['community']['actions'] = array('ac', 'agentSetCommunity', 'do', 'communityList'); + $frames['setting']['items']['community']['active'] = ''; + + $frames['setting']['items']['tags']['url'] = web_url('agentset/agentSetTags/tags'); + $frames['setting']['items']['tags']['title'] = '标签设置'; + $frames['setting']['items']['tags']['actions'] = array('ac', 'agentSetTags', 'do', 'tags'); + $frames['setting']['items']['tags']['active'] = ''; + + $frames['setting']['items']['customer']['url'] = web_url('agentset/userset/agentcustomer'); + $frames['setting']['items']['customer']['title'] = '客服设置'; + $frames['setting']['items']['customer']['actions'] = array('ac', 'userset', 'do', 'agentcustomer'); + $frames['setting']['items']['customer']['active'] = ''; + + $frames['setting']['items']['divform']['url'] = web_url('agentset/diyForm/index'); + $frames['setting']['items']['divform']['title'] = '自定义表单'; + $frames['setting']['items']['divform']['actions'] = ['ac' , 'diyForm' , 'do' , ['index' ,'add', 'edit']]; + $frames['setting']['items']['divform']['active'] = ''; + + + return $frames; + } + + /** + * Comment: 商品左侧菜单列表 + * Author: zzw + * Date: 2019/7/3 18:30 + */ + static function getgoodsFrames() { + global $_W; + $frames = array(); + $frames['goods']['title'] = '   商品管理'; + $frames['goods']['items'] = array(); + + $frames['goods']['items']['list']['url'] = web_url('goods/Goods/index'); + $frames['goods']['items']['list']['title'] = '商品列表'; + $frames['goods']['items']['list']['actions'] = array('ac', 'Goods', 'do', 'index'); + $frames['goods']['items']['list']['active'] = ''; + + $frames['goods']['items']['cate']['url'] = web_url('goods/Goods/category'); + $frames['goods']['items']['cate']['title'] = '商品分类'; + $frames['goods']['items']['cate']['actions'] = array('ac', 'Goods', 'do', 'category'); + $frames['goods']['items']['cate']['active'] = ''; + + + return $frames; + } + + +} diff --git a/addons/weliam_smartcity/core/class/Menus_store.class.php b/addons/weliam_smartcity/core/class/Menus_store.class.php new file mode 100644 index 0000000..0ddcfa5 --- /dev/null +++ b/addons/weliam_smartcity/core/class/Menus_store.class.php @@ -0,0 +1,274 @@ +   概况'; + $frames['dashboard']['url'] = web_url('dashboard/dashboard'); + $frames['dashboard']['active'] = 'dashboard'; + $frames['dashboard']['jurisdiction'] = 'dashboard'; + + $frames['order']['title'] = '   订单'; + $frames['order']['url'] = web_url('order/wlOrder/orderlist'); + $frames['order']['active'] = 'order'; + $frames['order']['jurisdiction'] = 'order'; + + $frames['finance']['title'] = '   财务'; + $frames['finance']['url'] = web_url('finace/newCash/currentlist',array('type'=>'store')); + $frames['finance']['active'] = 'finace'; + $frames['finance']['jurisdiction'] = 'finace'; + + $frames['data']['title'] = '   数据'; + $frames['data']['url'] = web_url('datacenter/datacenter/stat_operate'); + $frames['data']['active'] = 'datacenter'; + $frames['data']['jurisdiction'] = 'datacenter'; + + $frames['app']['title'] = '   营销'; + $frames['app']['url'] = web_url('app/plugins'); + $frames['app']['active'] = $appact; + $frames['app']['jurisdiction'] = 'app'; + + $frames['store']['title'] = '   设置'; + $frames['store']['url'] = web_url('store/merchant/edit'); + $frames['store']['active'] = 'store'; + $frames['store']['jurisdiction'] = 'store'; + + return $frames; + } + + static function getdashboardFrames() { + global $_W; + $frames = array(); + return $frames; + } + + static function getfinaceFrames() { + global $_W, $_GPC; + $frames = array(); + + $frames['cashSurvey']['title'] = '   财务'; + $frames['cashSurvey']['items'] = array(); + + $frames['cashSurvey']['items']['cashrecord']['url'] = web_url('finace/newCash/currentlist',array('type'=>'store')); + $frames['cashSurvey']['items']['cashrecord']['title'] = '结算记录'; + $frames['cashSurvey']['items']['cashrecord']['actions'] = array(); + $frames['cashSurvey']['items']['cashrecord']['active'] = ''; + + return $frames; + } + + + static function getstoreFrames() { + global $_W, $_GPC; + $frames = array(); + + $frames['user']['title'] = '   商户管理'; + $frames['user']['items'] = array(); + $frames['user']['items']['edit']['url'] = web_url('store/merchant/edit'); + $frames['user']['items']['edit']['title'] = '商户详情'; + $frames['user']['items']['edit']['actions'] = array('ac', 'merchant', 'do', 'edit'); + $frames['user']['items']['edit']['active'] = ''; + + if($_W['storeismain'] == 1){ + $frames['user']['items']['clerk']['url'] = web_url('store/merchant/clerkindex'); + $frames['user']['items']['clerk']['title'] = '店员管理'; + $frames['user']['items']['clerk']['actions'] = array('ac','merchant','do','clerkindex'); + $frames['user']['items']['clerk']['active'] = ''; + } + + if(empty($_W['authority']) || in_array('comment',$_W['authority']) || in_array('dynamic',$_W['authority'])){ + $frames['comment']['title'] = '   评论与动态'; + $frames['comment']['items'] = array(); + if(empty($_W['authority']) || in_array('comment',$_W['authority'])){ + $frames['comment']['items']['comment']['url'] = web_url('store/storeComment/index'); + $frames['comment']['items']['comment']['title'] = '全部评论'; + $frames['comment']['items']['comment']['actions'] = array('ac', 'storeComment', 'do', 'index'); + $frames['comment']['items']['comment']['active'] = ''; + } + if(empty($_W['authority']) || in_array('dynamic',$_W['authority'])) { + $frames['comment']['items']['dynamic']['url'] = web_url('store/storeDynamic/dynamic'); + $frames['comment']['items']['dynamic']['title'] = '商户动态'; + $frames['comment']['items']['dynamic']['actions'] = array('ac', 'storeDynamic', 'do', 'dynamic'); + $frames['comment']['items']['dynamic']['active'] = ''; + } + } + + $frames['setting']['title'] = '   设置'; + $frames['setting']['items'] = array(); + $frames['setting']['items']['divform']['url'] = web_url('agentset/diyForm/index'); + $frames['setting']['items']['divform']['title'] = '自定义表单'; + $frames['setting']['items']['divform']['actions'] = ['ac' , 'diyForm' , 'do' , ['index' ,'add', 'edit']]; + $frames['setting']['items']['divform']['active'] = ''; + + + + return $frames; + } + + static function getorderFrames() { + global $_W; + $frames = array(); + $frames['order']['title'] = '  订单'; + $frames['order']['items'] = array(); + + $frames['order']['items']['orderlist']['url'] = web_url('order/wlOrder/orderlist'); + $frames['order']['items']['orderlist']['title'] = '商品订单'; + $frames['order']['items']['orderlist']['actions'] = array('ac', 'wlOrder', 'do', array('orderlist', 'orderdetail')); + $frames['order']['items']['orderlist']['active'] = ''; + + $frames['order']['items']['payonlinelist']['url'] = web_url('order/orderPayOnline/payonlinelist'); + $frames['order']['items']['payonlinelist']['title'] = '在线买单'; + $frames['order']['items']['payonlinelist']['actions'] = array('ac', 'orderPayOnline', 'do', 'payonlinelist'); + $frames['order']['items']['payonlinelist']['active'] = ''; + + $frames['freight']['title'] = '   运费'; + $frames['freight']['items'] = array(); + + $frames['freight']['items']['freightlist']['url'] = web_url('order/orderFreightTemplate/freightlist'); + $frames['freight']['items']['freightlist']['title'] = '运费模板'; + $frames['freight']['items']['freightlist']['actions'] = array('ac', 'orderFreightTemplate', 'do', 'freightlist'); + $frames['freight']['items']['freightlist']['active'] = ''; + + $frames['saleafter']['title'] = '   预约售后'; + $frames['saleafter']['items'] = array(); + + $frames['saleafter']['items']['afterlist']['url'] = web_url('order/orderAfterSales/afterlist'); + $frames['saleafter']['items']['afterlist']['title'] = '售后记录'; + $frames['saleafter']['items']['afterlist']['actions'] = array('ac', 'orderAfterSales', 'do', 'afterlist'); + $frames['saleafter']['items']['afterlist']['active'] = ''; + + $frames['saleafter']['items']['appointlist']['url'] = web_url('order/wlOrder/appointlist'); + $frames['saleafter']['items']['appointlist']['title'] = '预约记录'; + $frames['saleafter']['items']['appointlist']['actions'] = array('ac', 'wlOrder', 'do', 'appointlist'); + $frames['saleafter']['items']['appointlist']['active'] = ''; + + + return $frames; + } + + static function getdatacenterFrames() { + global $_W; + $frames = array(); + + $frames['datacenter']['title'] = '   统计分析'; + $frames['datacenter']['items'] = array(); + $frames['datacenter']['items']['stat_operate']['url'] = web_url('datacenter/datacenter/stat_operate'); + $frames['datacenter']['items']['stat_operate']['title'] = '运营分析'; + $frames['datacenter']['items']['stat_operate']['actions'] = array(); + $frames['datacenter']['items']['stat_operate']['active'] = ''; + + return $frames; + } + + static function getappFrames() { + global $_W; + $frames = array(); + + $category = App::get_cate_plugins('store'); + foreach ($category as $key => $value) { + if (!empty($value['plugins'])) { + $frames[$key]['title'] = '   ' . $value['name']; + $frames[$key]['items'] = array(); + foreach ($value['plugins'] as $pk => $plug) { + $frames[$key]['items'][$plug['ident']]['url'] = $plug['cover']; + $frames[$key]['items'][$plug['ident']]['title'] = $plug['name']; + $frames[$key]['items'][$plug['ident']]['actions'] = array('ac', $plug['ident']); + $frames[$key]['items'][$plug['ident']]['active'] = ''; + } + } + } + + return $frames; + } + + static function getagentsetFrames() { + global $_W, $_GPC; + + + return self::getstoreFrames(); + + + $frames = array(); + $frames['setting']['title'] = '   设置'; + $frames['setting']['items'] = array(); + $frames['setting']['items']['base']['url'] = web_url('agentset/agentSetAccount/profile'); + $frames['setting']['items']['base']['title'] = '账号信息'; + $frames['setting']['items']['base']['actions'] = array('ac', 'agentSetAccount', 'do', 'profile'); + $frames['setting']['items']['base']['active'] = ''; + + $frames['setting']['items']['adminset']['url'] = web_url('agentset/agentSetStaff/adminset'); + $frames['setting']['items']['adminset']['title'] = '管理设置'; + $frames['setting']['items']['adminset']['actions'] = array('ac', 'agentSetStaff', 'do', 'adminset'); + $frames['setting']['items']['adminset']['active'] = ''; + + $frames['setting']['items']['customer']['url'] = web_url('agentset/userset/customer'); + $frames['setting']['items']['customer']['title'] = '客服设置'; + $frames['setting']['items']['customer']['actions'] = array('ac', 'userset', 'do', 'customer'); + $frames['setting']['items']['customer']['active'] = ''; + + + $frames['setting']['items']['community']['url'] = web_url('agentset/agentSetCommunity/communityList'); + $frames['setting']['items']['community']['title'] = '社群设置'; + $frames['setting']['items']['community']['actions'] = array('ac', 'agentSetCommunity', 'do', 'communityList'); + $frames['setting']['items']['community']['active'] = ''; + + $frames['setting']['items']['tags']['url'] = web_url('agentset/agentSetTags/tags'); + $frames['setting']['items']['tags']['title'] = '标签设置'; + $frames['setting']['items']['tags']['actions'] = array('ac', 'agentSetTags', 'do', 'tags'); + $frames['setting']['items']['tags']['active'] = ''; + + $frames['setting']['items']['userindex']['url'] = web_url('agentset/userset/userindex'); + $frames['setting']['items']['userindex']['title'] = '个人中心'; + $frames['setting']['items']['userindex']['actions'] = array('ac', 'userset', 'do', 'userindex'); + $frames['setting']['items']['userindex']['active'] = ''; + + + return $frames; + } + + + static function getgoodsFrames() { + global $_W; + $frames = array(); + $frames['goods']['title'] = '   商品管理'; + $frames['goods']['items'] = array(); + + $frames['goods']['items']['list']['url'] = web_url('goods/Goods/index'); + $frames['goods']['items']['list']['title'] = '商品列表'; + $frames['goods']['items']['list']['actions'] = array('ac', 'Goods', 'do', 'index'); + $frames['goods']['items']['list']['active'] = ''; + + $frames['goods']['items']['cate']['url'] = web_url('goods/Goods/category'); + $frames['goods']['items']['cate']['title'] = '商品分类'; + $frames['goods']['items']['cate']['actions'] = array('ac', 'Goods', 'do', 'category'); + $frames['goods']['items']['cate']['active'] = ''; + return $frames; + } + +} diff --git a/addons/weliam_smartcity/core/class/Menus_sys.class.php b/addons/weliam_smartcity/core/class/Menus_sys.class.php new file mode 100644 index 0000000..c997ccb --- /dev/null +++ b/addons/weliam_smartcity/core/class/Menus_sys.class.php @@ -0,0 +1,723 @@ + 0 && $_W['plugin'] == 'distribution'){ + $config['menus']['distribution0']['title'] = '共享股东'; + $config['menus']['distribution0']['items']['dissysbasedistributorlist']['title'] = '股东列表'; + $config['menus']['distribution0']['items']['dissysbasedislevel']['title'] = '股东等级'; + $config['menus']['distribution2']['items']['dissysbasedisbaseset']['title'] = '应用设置'; + } + + + return $config['menus']; + } + + /** + * static function 顶部列表 + * + * @access static + * @name topmenus + * @param + * @return array + */ + static function topmenus() { + global $_W; + $frames = array(); + $appact = Util::traversingFiles(PATH_PLUGIN); + $appact[] = 'app'; + $appact[] = 'goodshouse'; + + $frames['dashboard']['title'] = '   平台'; + $frames['dashboard']['url'] = web_url('dashboard/dashboard'); + $frames['dashboard']['active'] = 'dashboard'; + $frames['dashboard']['jurisdiction'] = 'dashboard'; + + $frames['member']['title'] = '   客户'; + $frames['member']['url'] = web_url('member/wlMember/index'); + $frames['member']['active'] = 'member'; + $frames['member']['jurisdiction'] = 'member'; + + $frames['store']['title'] = '   商户'; + $frames['store']['url'] = web_url('store/merchant/index', array('enabled' => '')); + $frames['store']['active'] = 'store'; + $frames['store']['jurisdiction'] = 'store'; + + $frames['order']['title'] = '   订单'; + $frames['order']['url'] = web_url('order/wlOrder/orderlist'); + $frames['order']['active'] = 'order'; + $frames['order']['jurisdiction'] = 'order'; + +// $perms = App::get_account_perm("plugins", $_W['uniacid']); +// if (p('area') && ((in_array('area',$perms) && $perms) || !$perms )) { +// $frames['area']['title'] = '   代理'; +// $frames['area']['url'] = web_url('area/areaagent/agentIndex'); +// $frames['area']['active'] = 'area'; +// $frames['area']['jurisdiction'] = 'area'; +// } + + $frames['finance']['title'] = '   财务'; + $frames['finance']['url'] = web_url('finace/finaceBill/cashrecord'); + $frames['finance']['active'] = 'finace'; + $frames['finance']['jurisdiction'] = 'finace'; + + $frames['data']['title'] = '   数据'; + $frames['data']['url'] = web_url('datacenter/datacenter/stat_operate'); + $frames['data']['active'] = 'datacenter'; + $frames['data']['jurisdiction'] = 'datacenter'; + + $frames['app']['title'] = '   应用'; + $frames['app']['url'] = web_url('app/plugins'); + $frames['app']['active'] = array_merge(array_diff($appact, array('area'))); + $frames['app']['jurisdiction'] = 'app'; + + $frames['setting']['title'] = '   设置'; + $frames['setting']['url'] = web_url('setting/shopset/base'); + $frames['setting']['active'] = ['setting', 'agentset']; + $frames['setting']['jurisdiction'] = 'agentset'; + + if ($_W['highest_role'] == 'founder' && IMS_FAMILY != 'wl') { + $frames['cloud']['title'] = '   云服务'; + $frames['cloud']['url'] = web_url('cloud/auth/auth'); + $frames['cloud']['active'] = 'cloud'; + $frames['cloud']['jurisdiction'] = 'cloud'; + } + return $frames; + } + + static function getdashboardFrames() { + global $_W; + $frames = array(); + $frames['member']['title'] = '   概况'; + $frames['member']['items'] = array(); + + $frames['member']['items']['setting']['url'] = web_url('dashboard/dashboard/index'); + $frames['member']['items']['setting']['title'] = '运营概况'; + $frames['member']['items']['setting']['actions'] = array('ac', 'dashboard'); + $frames['member']['items']['setting']['active'] = ''; + + $frames['page']['title'] = '   主页管理'; + $frames['page']['items'] = array(); + $frames['page']['items']['notice']['url'] = web_url('dashboard/notice/index'); + $frames['page']['items']['notice']['title'] = '公告'; + $frames['page']['items']['notice']['actions'] = array('ac', 'notice'); + $frames['page']['items']['notice']['active'] = ''; + + $frames['page']['items']['adv']['url'] = web_url('dashboard/adv/index'); + $frames['page']['items']['adv']['title'] = '幻灯片'; + $frames['page']['items']['adv']['actions'] = array('ac', 'adv'); + $frames['page']['items']['adv']['active'] = ''; + + $frames['page']['items']['nav']['url'] = web_url('dashboard/nav/index'); + $frames['page']['items']['nav']['title'] = '导航栏'; + $frames['page']['items']['nav']['actions'] = array('ac', 'nav'); + $frames['page']['items']['nav']['active'] = ''; + + $frames['page']['items']['banner']['url'] = web_url('dashboard/banner/index'); + $frames['page']['items']['banner']['title'] = '广告栏'; + $frames['page']['items']['banner']['actions'] = array('ac', 'banner'); + $frames['page']['items']['banner']['active'] = ''; + + $frames['page']['items']['cube']['url'] = web_url('dashboard/cube/index'); + $frames['page']['items']['cube']['title'] = '商品魔方'; + $frames['page']['items']['cube']['actions'] = array('ac', 'cube'); + $frames['page']['items']['cube']['active'] = ''; + +// $frames['page']['items']['sort']['url'] = web_url('dashboard/sort/index'); +// $frames['page']['items']['sort']['title'] = '主页排版'; +// $frames['page']['items']['sort']['actions'] = array(); +// $frames['page']['items']['sort']['active'] = ''; + + $frames['page']['items']['plugin']['url'] = web_url('dashboard/plugin/index'); + $frames['page']['items']['plugin']['title'] = '选项卡管理'; + $frames['page']['items']['plugin']['actions'] = array('ac', 'plugin'); + $frames['page']['items']['plugin']['active'] = ''; + + $frames['page']['items']['foot']['url'] = web_url('dashboard/foot/index'); + $frames['page']['items']['foot']['title'] = '底部菜单'; + $frames['page']['items']['foot']['actions'] = array('ac', 'foot'); + $frames['page']['items']['foot']['active'] = ''; + + $frames['page']['items']['category']['url'] = web_url('dashboard/category/index',array('active'=>1)); + $frames['page']['items']['category']['title'] = '分类管理'; + $frames['page']['items']['category']['actions'] = array('ac', 'category'); + $frames['page']['items']['category']['active'] = ''; + + $frames['page']['items']['rule_center']['url'] = web_url('dashboard/ruleCenter/index'); + $frames['page']['items']['rule_center']['title'] = '规则中心'; + $frames['page']['items']['rule_center']['actions'] = array('ac', 'ruleCenter'); + $frames['page']['items']['rule_center']['active'] = ''; + + $frames['other']['title'] = '   其他信息'; + $frames['other']['items'] = array(); + $frames['other']['items']['notice']['url'] = web_url('dashboard/pagelinks/index'); + $frames['other']['items']['notice']['title'] = '页面链接'; + $frames['other']['items']['notice']['actions'] = array('ac', 'pagelinks'); + $frames['other']['items']['notice']['active'] = ''; + + return $frames; + } + + /** + * static function 客户左侧列表 + * + * @access static + * @name getmemberFrames + * @param + * @return array + */ + static function getmemberFrames() { + global $_W; + $frames = array(); + $frames['user']['title'] = '   客户'; + $frames['user']['items'] = array(); + + $frames['user']['items']['register']['url'] = web_url('member/wlMember/index'); + $frames['user']['items']['register']['title'] = '客户概况'; + $frames['user']['items']['register']['actions'] = array('ac', 'wlMember', 'do', 'index'); + $frames['user']['items']['register']['active'] = ''; + + $frames['user']['items']['notice']['url'] = web_url('member/wlMember/memberIndex'); + $frames['user']['items']['notice']['title'] = '客户列表'; + $frames['user']['items']['notice']['actions'] = array('ac', 'wlMember', 'do', array('memberIndex', 'memberDetail')); + $frames['user']['items']['notice']['active'] = ''; + + $frames['user']['items']['publish']['url'] = web_url('member/campusActivities/index',array('active' => 1)); + $frames['user']['items']['publish']['title'] = '校园活动'; + $frames['user']['items']['publish']['actions'] = array('ac', 'campusActivities', 'do', 'index'); + $frames['user']['items']['publish']['active'] = ''; + + $frames['check']['title'] = '   审核'; + $frames['check']['items'] = array(); + + $frames['check']['items']['notice']['url'] = web_url('member/checkMember/checkStudentIndex'); + $frames['check']['items']['notice']['title'] = '学生认证'; + $frames['check']['items']['notice']['actions'] = array('ac', 'checkMember', 'do', 'checkStudentIndex'); + $frames['check']['items']['notice']['active'] = ''; + + $frames['check']['items']['teacher']['url'] = web_url('member/checkMember/checkTeacherIndex'); + $frames['check']['items']['teacher']['title'] = '教师认证'; + $frames['check']['items']['teacher']['actions'] = array('ac', 'checkMember', 'do', 'checkTeacherIndex'); + $frames['check']['items']['teacher']['active'] = ''; + + $frames['check']['items']['blogger']['url'] = web_url('member/checkMember/checkBloggerIndex'); + $frames['check']['items']['blogger']['title'] = '达人认证'; + $frames['check']['items']['blogger']['actions'] = array('ac', 'checkMember', 'do', 'checkBloggerIndex'); + $frames['check']['items']['blogger']['active'] = ''; + + $frames['im']['title'] = '   通信管理'; + $frames['im']['items'] = array(); + + $frames['im']['items']['im']['url'] = web_url('member/userIm/index'); + $frames['im']['items']['im']['title'] = '通信管理'; + $frames['im']['items']['im']['actions'] = ['ac' , 'userIm' , 'do' , ['index']]; + $frames['im']['items']['im']['active'] = ''; + +// $frames['im']['items']['im_set']['url'] = web_url('member/userIm/imSet'); +// $frames['im']['items']['im_set']['title'] = '通信设置'; +// $frames['im']['items']['im_set']['actions'] = ['ac' , 'userIm' , 'do' , ['imSet']]; +// $frames['im']['items']['im_set']['active'] = ''; + + $frames['userlabel']['title'] = '   标签'; + $frames['userlabel']['items'] = array(); + + $frames['userlabel']['items']['labellist']['url'] = web_url('member/userlabel/labellist'); + $frames['userlabel']['items']['labellist']['title'] = '客户标签'; + $frames['userlabel']['items']['labellist']['actions'] = array(); + $frames['userlabel']['items']['labellist']['active'] = ''; + + $frames['current']['title'] = '   财务'; + $frames['current']['items'] = array(); + + $frames['current']['items']['recharge']['url'] = web_url('member/memberFinancialDetails/recharge'); + $frames['current']['items']['recharge']['title'] = '充值明细'; + $frames['current']['items']['recharge']['actions'] = array('ac', 'memberFinancialDetails', 'do', 'recharge'); + $frames['current']['items']['recharge']['active'] = ''; + + $frames['current']['items']['integral']['url'] = web_url('member/memberFinancialDetails/integral'); + $frames['current']['items']['integral']['title'] = '积分明细'; + $frames['current']['items']['integral']['actions'] = array('ac', 'memberFinancialDetails', 'do', 'integral'); + $frames['current']['items']['integral']['active'] = ''; + + $frames['current']['items']['balance']['url'] = web_url('member/memberFinancialDetails/balance'); + $frames['current']['items']['balance']['title'] = '余额明细'; + $frames['current']['items']['balance']['actions'] = array('ac', 'memberFinancialDetails', 'do', 'balance'); + $frames['current']['items']['balance']['active'] = ''; + + $frames['memberset']['title'] = '   设置'; + $frames['memberset']['items'] = array(); + + $frames['memberset']['items']['userset']['url'] = web_url('member/wlMember/userset'); + $frames['memberset']['items']['userset']['title'] = '用户设置'; + $frames['memberset']['items']['userset']['actions'] = array('ac', 'wlMember', 'do', 'userset'); + $frames['memberset']['items']['userset']['active'] = ''; + + if (file_exists(PATH_MODULE . 'N561.log')) { + $frames['transfer']['title'] = '   余额转赠'; + $frames['transfer']['items'] = array(); + + $frames['transfer']['items']['transferlist']['url'] = web_url('member/wlMember/transferlist'); + $frames['transfer']['items']['transferlist']['title'] = '转赠活动'; + $frames['transfer']['items']['transferlist']['actions'] = array('ac', 'wlMember', 'do', 'transferlist'); + $frames['transfer']['items']['transferlist']['active'] = ''; + + $frames['transfer']['items']['transferrecord']['url'] = web_url('member/wlMember/transferrecord'); + $frames['transfer']['items']['transferrecord']['title'] = '转赠记录'; + $frames['transfer']['items']['transferrecord']['actions'] = array('ac', 'wlMember', 'do', 'transferrecord'); + $frames['transfer']['items']['transferrecord']['active'] = ''; + } + + + + return $frames; + } + + static function getstoreFrames() { + global $_W, $_GPC; + $frames = array(); + + $frames['user']['title'] = '   商户管理'; + $frames['user']['items'] = array(); + $frames['user']['items']['index']['url'] = web_url('store/merchant/index', array('enabled' => '')); + $frames['user']['items']['index']['title'] = '商户列表'; + $frames['user']['items']['index']['actions'] = array('ac', 'merchant'); + $frames['user']['items']['index']['active'] = ''; + + $frames['user']['items']['category']['url'] = web_url('store/category/index'); + $frames['user']['items']['category']['title'] = '商户分类'; + $frames['user']['items']['category']['actions'] = array('ac', 'category'); + $frames['user']['items']['category']['active'] = ''; + + $frames['register']['title'] = '   入驻管理'; + $frames['register']['items'] = array(); + $frames['register']['items']['register']['url'] = web_url('store/storeApply/index'); + $frames['register']['items']['register']['title'] = '入驻申请'; + $frames['register']['items']['register']['actions'] = array('ac', 'storeApply', 'do', 'index'); + $frames['register']['items']['register']['active'] = ''; + + $frames['register']['items']['settled']['url'] = web_url('store/settled/baseset'); + $frames['register']['items']['settled']['title'] = '入驻设置'; + $frames['register']['items']['settled']['actions'] = array('ac', 'settled', 'do', 'baseset'); + $frames['register']['items']['settled']['active'] = ''; + + $frames['register']['items']['chargerecode']['url'] = web_url('store/register/chargerecode'); + $frames['register']['items']['chargerecode']['title'] = '付费记录'; + $frames['register']['items']['chargerecode']['actions'] = array('ac', 'register', 'do', 'chargerecode'); + $frames['register']['items']['chargerecode']['active'] = ''; + + $frames['register']['items']['chargelist']['url'] = web_url('store/storeSetMeal/chargelist'); + $frames['register']['items']['chargelist']['title'] = '入驻套餐'; + $frames['register']['items']['chargelist']['actions'] = array('ac', 'storeSetMeal', 'do', array('chargelist', 'add')); + $frames['register']['items']['chargelist']['active'] = ''; + + $frames['certified']['title'] = '   认证管理'; + $frames['certified']['items'] = array(); + $frames['certified']['items']['certified']['url'] = web_url('store/storeCertified/index'); + $frames['certified']['items']['certified']['title'] = '商务认证'; + $frames['certified']['items']['certified']['actions'] = array('ac', 'storeCertified', 'do', 'index'); + $frames['certified']['items']['certified']['active'] = ''; + + $frames['comment']['title'] = '   评论与动态'; + $frames['comment']['items'] = array(); + $frames['comment']['items']['comment']['url'] = web_url('store/storeComment/index'); + $frames['comment']['items']['comment']['title'] = '全部评论'; + $frames['comment']['items']['comment']['actions'] = array('ac', 'storeComment', 'do', 'index'); + $frames['comment']['items']['comment']['active'] = ''; + + $frames['comment']['items']['dynamic']['url'] = web_url('store/storeDynamic/dynamic'); + $frames['comment']['items']['dynamic']['title'] = '商户动态'; + $frames['comment']['items']['dynamic']['actions'] = array('ac', 'storeDynamic', 'do', 'dynamic'); + $frames['comment']['items']['dynamic']['active'] = ''; + + $frames['setting']['title'] = '   商户设置'; + $frames['setting']['items'] = array(); + $frames['setting']['items']['setting']['url'] = web_url('store/comment/storeSet'); + $frames['setting']['items']['setting']['title'] = '基本设置'; + $frames['setting']['items']['setting']['actions'] = array('ac', 'comment', 'do', 'storeSet'); + $frames['setting']['items']['setting']['active'] = ''; + + + return $frames; + } + + /** + * static function 订单左侧列表 + * + * @access static + * @name getorderFrames + * @param + * @return array + */ + static function getorderFrames() { + global $_W; + $frames = array(); + $frames['order']['title'] = '   订单'; + $frames['order']['items'] = array(); + + $frames['order']['items']['orderlist']['url'] = web_url('order/wlOrder/orderlist'); + $frames['order']['items']['orderlist']['title'] = '商品订单'; + $frames['order']['items']['orderlist']['actions'] = array('ac', 'wlOrder', 'do', array('orderlist', 'orderdetail')); + $frames['order']['items']['orderlist']['active'] = ''; + + $frames['order']['items']['payonlinelist']['url'] = web_url('order/orderPayOnline/payonlinelist'); + $frames['order']['items']['payonlinelist']['title'] = '在线买单'; + $frames['order']['items']['payonlinelist']['actions'] = array('ac', 'orderPayOnline', 'do', 'payonlinelist'); + $frames['order']['items']['payonlinelist']['active'] = ''; + + $frames['order']['items']['orderset']['url'] = web_url('order/orderSet/orderset'); + $frames['order']['items']['orderset']['title'] = '订单设置'; + $frames['order']['items']['orderset']['actions'] = array('ac', 'orderSet', 'do', 'orderset'); + $frames['order']['items']['orderset']['active'] = ''; + + $frames['freight']['title'] = '   运费'; + $frames['freight']['items'] = array(); + + $frames['freight']['items']['freightlist']['url'] = web_url('order/orderFreightTemplate/freightlist'); + $frames['freight']['items']['freightlist']['title'] = '运费模板'; + $frames['freight']['items']['freightlist']['actions'] = array('ac', 'orderFreightTemplate', 'do', 'freightlist'); + $frames['freight']['items']['freightlist']['active'] = ''; + + $frames['saleafter']['title'] = '   预约售后'; + $frames['saleafter']['items'] = array(); + + $frames['saleafter']['items']['afterlist']['url'] = web_url('order/orderAfterSales/afterlist'); + $frames['saleafter']['items']['afterlist']['title'] = '售后记录'; + $frames['saleafter']['items']['afterlist']['actions'] = array('ac', 'orderAfterSales', 'do', 'afterlist'); + $frames['saleafter']['items']['afterlist']['active'] = ''; + + $frames['saleafter']['items']['appointlist']['url'] = web_url('order/wlOrder/appointlist'); + $frames['saleafter']['items']['appointlist']['title'] = '预约记录'; + $frames['saleafter']['items']['appointlist']['actions'] = array('ac', 'wlOrder', 'do', 'appointlist'); + $frames['saleafter']['items']['appointlist']['active'] = ''; + + return $frames; + } + + + static function getfinaceFrames() { + global $_W, $_GPC; + $frames = array(); + $frames['cashSurvey']['title'] = '   财务概况'; + $frames['cashSurvey']['items'] = array(); + +// $frames['cashSurvey']['items']['datemana']['url'] = web_url('finace/wlCash/cashSurvey'); +// $frames['cashSurvey']['items']['datemana']['title'] = '财务概况'; +// $frames['cashSurvey']['items']['datemana']['actions'] = array(); +// $frames['cashSurvey']['items']['datemana']['active'] = ''; + + $frames['cashSurvey']['items']['cashrecord']['url'] = web_url('finace/finaceBill/cashrecord'); + $frames['cashSurvey']['items']['cashrecord']['title'] = '账单明细'; + $frames['cashSurvey']['items']['cashrecord']['actions'] = array(); + $frames['cashSurvey']['items']['cashrecord']['active'] = ''; + + $frames['cashSurvey']['items']['refundrecord']['url'] = web_url('finace/finaceRefundRecord/refundrecord'); + $frames['cashSurvey']['items']['refundrecord']['title'] = '退款记录'; + $frames['cashSurvey']['items']['refundrecord']['actions'] = array(); + $frames['cashSurvey']['items']['refundrecord']['active'] = ''; + + $frames['current']['title'] = '   账户'; + $frames['current']['items'] = array(); + + $frames['current']['items']['currentstore']['url'] = web_url('finace/newCash/currentlist', array('type' => 'store')); + $frames['current']['items']['currentstore']['title'] = '商家账户'; + $frames['current']['items']['currentstore']['actions'] = array('type', 'store'); + $frames['current']['items']['currentstore']['active'] = ''; + + $frames['current']['items']['currentmy']['url'] = web_url('finace/newCash/currentlist', array('type' => 'agent')); + $frames['current']['items']['currentmy']['title'] = '代理账户'; + $frames['current']['items']['currentmy']['actions'] = array('type', 'agent'); + $frames['current']['items']['currentmy']['active'] = ''; + + $frames['cashApply']['title'] = '   提现'; + $frames['cashApply']['items'] = array(); + + $frames['cashApply']['items']['display1']['url'] = web_url('finace/finaceWithdrawalApply/cashApply'); + $frames['cashApply']['items']['display1']['title'] = '提现申请'; + $frames['cashApply']['items']['display1']['actions'] = array(); + $frames['cashApply']['items']['display1']['active'] = ''; + + $frames['cashApply']['items']['cashset']['url'] = web_url('finace/wlCash/cashset'); + $frames['cashApply']['items']['cashset']['title'] = '财务设置'; + $frames['cashApply']['items']['cashset']['actions'] = array(); + $frames['cashApply']['items']['cashset']['active'] = ''; + + return $frames; + } + + static function getdatacenterFrames() { + global $_W; + $frames = array(); + + $frames['datacenter']['title'] = '   统计分析'; + $frames['datacenter']['items'] = array(); + + $frames['datacenter']['items']['stat_operate']['url'] = web_url('datacenter/datacenter/stat_operate'); + $frames['datacenter']['items']['stat_operate']['title'] = '运营分析'; + $frames['datacenter']['items']['stat_operate']['actions'] = array(); + $frames['datacenter']['items']['stat_operate']['active'] = ''; + + $frames['datacenter']['items']['stat_store']['url'] = web_url('datacenter/datacenter/stat_store'); + $frames['datacenter']['items']['stat_store']['title'] = '店铺统计'; + $frames['datacenter']['items']['stat_store']['actions'] = array(); + $frames['datacenter']['items']['stat_store']['active'] = ''; + + if (file_exists(PATH_MODULE . 'TnSrtWDJ.log')) { + $frames['datacenter']['items']['stat_store_card']['url'] = web_url('datacenter/datacenter/stat_store_card'); + $frames['datacenter']['items']['stat_store_card']['title'] = '商户会员'; + $frames['datacenter']['items']['stat_store_card']['actions'] = array(); + $frames['datacenter']['items']['stat_store_card']['active'] = ''; + } + +// $frames['datacenter']['items']['stat_agent']['url'] = web_url('datacenter/datacenter/stat_agent'); +// $frames['datacenter']['items']['stat_agent']['title'] = '代理统计'; +// $frames['datacenter']['items']['stat_agent']['actions'] = array(); +// $frames['datacenter']['items']['stat_agent']['active'] = ''; + + if (p('distribution')) { + if(Customized::init('distributionText') > 0){ + $frames['distri']['title'] = '   共享股东分析'; + }else{ + $frames['distri']['title'] = '   分销分析'; + } + $frames['distri']['items'] = array(); + + $frames['distri']['items']['stat_distri']['url'] = web_url('datacenter/datacenter/stat_distri'); + if(Customized::init('distributionText') > 0){ + $frames['distri']['items']['stat_distri']['title'] = '共享股东统计'; + }else{ + $frames['distri']['items']['stat_distri']['title'] = '分销统计'; + } + $frames['distri']['items']['stat_distri']['actions'] = array(); + $frames['distri']['items']['stat_distri']['active'] = ''; + } + + return $frames; + } + + /** + * static function 设置左侧列表 + * + * @access static + * @name getsettingFrames + * @param + * @return array + */ + static function getsettingFrames() { + global $_W, $_GPC; + $frames = array(); + $frames['setting']['title'] = '   设置'; + $frames['setting']['items'] = array(); + $frames['setting']['items']['base']['url'] = web_url('setting/shopset/base'); + $frames['setting']['items']['base']['title'] = '基础设置'; + $frames['setting']['items']['base']['actions'] = array('ac', 'shopset', 'do', 'base'); + $frames['setting']['items']['base']['active'] = ''; + + $frames['setting']['items']['share']['url'] = web_url('setting/shopset/share'); + $frames['setting']['items']['share']['title'] = '分享关注'; + $frames['setting']['items']['share']['actions'] = array('ac', 'shopset', 'do', 'share'); + $frames['setting']['items']['share']['active'] = ''; + +// $frames['setting']['items']['api']['url'] = web_url('setting/shopset/api'); +// $frames['setting']['items']['api']['title'] = '接口设置'; +// $frames['setting']['items']['api']['actions'] = array('ac', 'shopset', 'do', 'api'); +// $frames['setting']['items']['api']['active'] = ''; + +// $frames['setting']['items']['community']['url'] = web_url('agentset/agentSetCommunity/communityList'); +// $frames['setting']['items']['community']['title'] = '社群设置'; +// $frames['setting']['items']['community']['actions'] = array('ac', 'agentSetCommunity', 'do', 'communityList'); +// $frames['setting']['items']['community']['active'] = ''; + + $frames['setting']['items']['userindex']['url'] = web_url('agentset/userset/userindex'); + $frames['setting']['items']['userindex']['title'] = '个人中心'; + $frames['setting']['items']['userindex']['actions'] = array('ac', 'userset', 'do', 'userindex'); + $frames['setting']['items']['userindex']['active'] = ''; + + $frames['setting']['items']['adminset']['url'] = web_url('agentset/agentSetStaff/adminset'); + $frames['setting']['items']['adminset']['title'] = '员工管理'; + $frames['setting']['items']['adminset']['actions'] = array('ac', 'agentSetStaff', 'do', 'adminset'); + $frames['setting']['items']['adminset']['active'] = ''; + +// $frames['setting']['items']['trade']['url'] = web_url('setting/shopset/trade'); +// $frames['setting']['items']['trade']['title'] = '文字设置'; +// $frames['setting']['items']['trade']['actions'] = array('ac', 'shopset', 'do', 'trade'); +// $frames['setting']['items']['trade']['active'] = ''; + + $frames['setting']['items']['customer']['url'] = web_url('setting/shopset/customer'); + $frames['setting']['items']['customer']['title'] = '客服设置'; + $frames['setting']['items']['customer']['actions'] = array('ac', 'shopset', 'do', 'customer'); + $frames['setting']['items']['customer']['active'] = ''; + +// $frames['setting']['items']['tags']['url'] = web_url('agentset/agentSetTags/tags'); +// $frames['setting']['items']['tags']['title'] = '标签设置'; +// $frames['setting']['items']['tags']['actions'] = array('ac', 'agentSetTags', 'do', 'tags'); +// $frames['setting']['items']['tags']['active'] = ''; + +// $frames['setting']['items']['divform']['url'] = web_url('agentset/diyForm/index'); +// $frames['setting']['items']['divform']['title'] = '自定义表单'; +// $frames['setting']['items']['divform']['actions'] = ['ac' , 'diyForm' , 'do' , ['index' ,'add', 'edit']]; +// $frames['setting']['items']['divform']['active'] = ''; + +// if(IMS_FAMILY == 'wl'){ +// $frames['setting']['items']['enclosure']['url'] = web_url('setting/shopset/enclosure'); +// $frames['setting']['items']['enclosure']['title'] = '附件设置'; +// $frames['setting']['items']['enclosure']['actions'] = ['ac' , 'shopset' , 'do' ,'enclosure']; +// $frames['setting']['items']['enclosure']['active'] = ''; +// } + + $frames['payset']['title'] = '   交易'; + $frames['payset']['items'] = array(); + $frames['payset']['items']['recharge']['url'] = web_url('setting/settingTransaction/recharge'); + $frames['payset']['items']['recharge']['title'] = '充值设置'; + $frames['payset']['items']['recharge']['actions'] = array('ac', 'settingTransaction', 'do', 'recharge'); + $frames['payset']['items']['recharge']['active'] = ''; + + $frames['payset']['items']['creditset']['url'] = web_url('setting/settingTransaction/creditset'); + $frames['payset']['items']['creditset']['title'] = '积分设置'; + $frames['payset']['items']['creditset']['actions'] = array('ac', 'settingTransaction', 'do', 'creditset'); + $frames['payset']['items']['creditset']['active'] = ''; + + + $frames['pay']['title'] = '   支付'; + $frames['pay']['items'] = array(); + $frames['pay']['items']['recharge']['url'] = web_url('setting/pay/index'); + $frames['pay']['items']['recharge']['title'] = '支付设置'; + $frames['pay']['items']['recharge']['actions'] = array('ac', 'pay', 'do', 'index'); + $frames['pay']['items']['recharge']['active'] = ''; + + $frames['pay']['items']['administration']['url'] = web_url('setting/pay/administration'); + $frames['pay']['items']['administration']['title'] = '支付管理'; + $frames['pay']['items']['administration']['actions'] = array('ac', 'pay', 'do', 'administration'); + $frames['pay']['items']['administration']['active'] = ''; + + $frames['rights']['title'] = '   权益'; + $frames['rights']['items'] = array(); + + $frames['rights']['items']['config']['url'] = web_url('setting/rights/index'); + $frames['rights']['items']['config']['title'] = '权益配置'; + $frames['rights']['items']['config']['actions'] = array('ac', 'rights', 'do', 'index'); + $frames['rights']['items']['config']['active'] = ''; + + $frames['rights']['items']['use']['url'] = web_url('setting/rights/useRightsIndex'); + $frames['rights']['items']['use']['title'] = '权益使用'; + $frames['rights']['items']['use']['actions'] = array('ac', 'rights', 'do', 'useRightsIndex'); + $frames['rights']['items']['use']['active'] = ''; + + $frames['rights']['items']['order']['url'] = web_url('setting/rights/rightsOrderIndex'); + $frames['rights']['items']['order']['title'] = '订单管理'; + $frames['rights']['items']['order']['actions'] = array('ac', 'rights', 'do', 'rightsOrderIndex'); + $frames['rights']['items']['order']['active'] = ''; + + return $frames; + } + + static function getagentsetFrames() { + return self::getsettingFrames(); + } + + static function getappFrames() { + global $_W; + $frames = array(); + + $category = App::get_cate_plugins('sys'); + foreach ($category as $key => $value) { + if (!empty($value['plugins'])) { + $frames[$key]['title'] = '   ' . $value['name']; + $frames[$key]['items'] = array(); + foreach ($value['plugins'] as $pk => $plug) { + $frames[$key]['items'][$plug['ident']]['url'] = $plug['cover']; + $frames[$key]['items'][$plug['ident']]['title'] = $plug['name']; + $frames[$key]['items'][$plug['ident']]['actions'] = array('ac', $plug['ident']); + $frames[$key]['items'][$plug['ident']]['active'] = ''; + } + } + } + + return $frames; + } + + static function getcloudFrames() { + global $_W, $_GPC; + $frames = array(); + $frames['member']['title'] = '   云服务'; + $frames['member']['items'] = array(); + + $frames['member']['items']['setting']['url'] = web_url('cloud/auth/auth'); + $frames['member']['items']['setting']['title'] = '系统授权'; + $frames['member']['items']['setting']['actions'] = array(); + $frames['member']['items']['setting']['active'] = ''; + + if ($_W['wlcloud']['authinfo']['status'] == 0 && $_W['wlcloud']['authinfo']['endtime'] > time()) { + $frames['member']['items']['display']['url'] = web_url('cloud/auth/upgrade'); + $frames['member']['items']['display']['title'] = '系统升级'; + $frames['member']['items']['display']['actions'] = array(); + $frames['member']['items']['display']['active'] = ''; + + $frames['member']['items']['log']['url'] = web_url('cloud/auth/upgrade_log'); + $frames['member']['items']['log']['title'] = '更新日志'; + $frames['member']['items']['log']['actions'] = array(); + $frames['member']['items']['log']['active'] = ''; + } + + $frames['plugin']['title'] = '   应用管理'; + $frames['plugin']['items'] = array(); + + $frames['plugin']['items']['index']['url'] = web_url('cloud/plugin/index'); + $frames['plugin']['items']['index']['title'] = '应用信息'; + $frames['plugin']['items']['index']['actions'] = array(); + $frames['plugin']['items']['index']['active'] = ''; + + $frames['plugin']['items']['perm']['url'] = web_url('cloud/plugin/account_list'); + $frames['plugin']['items']['perm']['title'] = '公众号权限'; + $frames['plugin']['items']['perm']['actions'] = array('do', array('account_list', 'account_post')); + $frames['plugin']['items']['perm']['active'] = ''; + + $frames['database']['title'] = '   数据管理'; + $frames['database']['items'] = array(); + + $frames['database']['items']['datemana']['url'] = web_url('cloud/database/datemana'); + $frames['database']['items']['datemana']['title'] = '数据管理'; + $frames['database']['items']['datemana']['actions'] = array(); + $frames['database']['items']['datemana']['active'] = ''; + + $frames['database']['items']['run']['url'] = web_url('cloud/database/run'); + $frames['database']['items']['run']['title'] = '运行SQL'; + $frames['database']['items']['run']['actions'] = array(); + $frames['database']['items']['run']['active'] = ''; + + $frames['sysset']['title'] = '   系统设置'; + $frames['sysset']['items'] = array(); + + $frames['sysset']['items']['base']['url'] = web_url('cloud/wlsysset/base'); + $frames['sysset']['items']['base']['title'] = '系统信息'; + $frames['sysset']['items']['base']['actions'] = array(); + $frames['sysset']['items']['base']['active'] = ''; + + $frames['sysset']['items']['datemana']['url'] = web_url('cloud/wlsysset/taskcover'); + $frames['sysset']['items']['datemana']['title'] = '计划任务'; + $frames['sysset']['items']['datemana']['actions'] = array(); + $frames['sysset']['items']['datemana']['active'] = ''; + + $frames['sysset']['items']['jumpadmin']['url'] = web_url('cloud/wlsysset/jumpadmin'); + $frames['sysset']['items']['jumpadmin']['title'] = '跳转域名'; + $frames['sysset']['items']['jumpadmin']['actions'] = array(); + $frames['sysset']['items']['jumpadmin']['active'] = ''; + + return $frames; + } +} diff --git a/addons/weliam_smartcity/core/class/Merchant.class.php b/addons/weliam_smartcity/core/class/Merchant.class.php new file mode 100644 index 0000000..3b4a0c7 --- /dev/null +++ b/addons/weliam_smartcity/core/class/Merchant.class.php @@ -0,0 +1,1696 @@ + $params['tid'])); + $_W['aid'] = $order_out['aid']; + $_W['uniacid'] = $order_out['uniacid']; + $_W['wlsetting']['creditset'] = Setting::wlsetting_read('creditset'); + if ($order_out['status'] == 0) { + $data = self::getVipPayData($params); //得到支付参数,处理代付 + $halftype = pdo_get('wlmerchant_halfcard_type', array('id' => $order_out['typeid'])); + //用户定制 激活码激活会员卡时赠送用户余额 + if (file_exists(IA_ROOT . '/addons/'.MODULE_NAME.'/pTLjC21GjCGj.log')) { + if ($halftype['give_price'] > 0) { + Member::credit_update_credit2($order_out['mid'], $halftype['give_price'], '一卡通赠送金额'); + } + } + //电商联盟定制 会员卡同步到其他模块 + if (file_exists(PATH_MODULE . 'lsh.log')) { + Halfcard::toHccardMode($order_out['mid'],$order_out['username'],$order_out['mobile']); + } + //处理分销 + if (p('distribution') && empty($halftype['isdistri'])) { + $_W['aid'] = $order_out['aid']; + $disorderid = Distribution::disCore($order_out['mid'], $order_out['price'], $halftype['onedismoney'], $halftype['twodismoney'], $halftype['threedismoney'], $order_out['id'], 'halfcard', 1); + $data['disorderid'] = $disorderid; + } + //支付有礼 + if($halftype['paidid'] > 0){ + $data['paidprid'] = Paidpromotion::getpaidpr(5,$halftype['paidid'],$order_out['mid'],$order_out['id'],$data['paytype'],$order_out['price']); + } + $res = pdo_update(PDO_NAME . 'halfcard_record', $data, array('orderno' => $params['tid'])); //更新订单状态 + if ($res) { + Store::halfsettlement($order_out['id']); //结算订单 + } + $halfcarddata = array( + 'uniacid' => $order_out['uniacid'], + 'aid' => $order_out['aid'], + 'mid' => $order_out['mid'], + 'expiretime' => $order_out['limittime'], + 'username' => $order_out['username'], + 'levelid' => $halftype['levelid'], + 'createtime' => time(), + // 'mototype' => $order_out['mototype'], + // 'platenumber' => $order_out['platenumber'], + 'from' => 0 + ); + if ($order_out['cardid']) { + pdo_update(PDO_NAME . 'halfcardmember', $halfcarddata, array('id' => $order_out['cardid'])); + } else { + pdo_insert(PDO_NAME . 'halfcardmember', $halfcarddata); + } + $member = pdo_get('wlmerchant_member', array('id' => $halfcarddata['mid']), array('openid', 'mobile')); + $openid = $member['openid']; + $mobile = empty($member['mobile']) ? $order_out['mobile'] : $member['mobile']; + if (empty($member['mobile']) || !empty($order_out['platenumber'])) { + $memberdata['mobile'] = $order_out['mobile']; + if(!empty($order_out['platenumber'])){ + $memberdata['card_number'] = $order_out['platenumber']; + } + pdo_update('wlmerchant_member',$memberdata, array('id' => $halfcarddata['mid'])); + } + $url = h5_url('pages/mainPages/memberCard/memberCard'); + $url = str_replace('payment/','',$url); + $time = date('Y-m-d H:i:s', $halfcarddata['expiretime']); + $halftext = $_W['wlsetting']['trade']['halfcardtext'] ? $_W['wlsetting']['trade']['halfcardtext'] : '一卡通'; + $tqtext = $_W['wlsetting']['trade']['privilege'] ? $_W['wlsetting']['trade']['privilege'] : '特权'; + //通知用户开卡成功 + $userModelData = [ + 'first' => '您已成功开通' .$halftext . $tqtext , + 'type' => '信息通知' ,//业务类型 + 'content' => '开通账号:' . $mobile ,//业务内容 + 'status' => '开通商品:' . $halftype['name'] ,//处理结果 + 'time' => '到期时间:' . $time,//操作时间 + 'remark' => '' + ]; + TempModel::sendInit('service',$halfcarddata['mid'],$userModelData,$_W['source'],$url); + //通知管理员 + $adminModelData = [ + 'first' => '客户:[' . $halfcarddata['username'] . ']已成功开通' . $halftext . $tqtext, + 'type' => '信息通知' ,//业务类型 + 'content' => '开通账号:' . $mobile ,//业务内容 + 'status' => '开通商品:' . $halftype['name'] ,//处理结果 + 'time' => '到期时间:' . $time,//操作时间 + 'remark' => '' + ]; + TempModel::sendInit('service',-1,$adminModelData,$_W['source']); + } + //成为分销商 + $base = Setting::wlsetting_read('distribution'); + if ($base['appdis'] == 2 && $base['switch'] && $base['together'] == 1) { +// if(in_array($order_out['typeid'],$base['halfcardtype'])){ + $member = pdo_get('wlmerchant_member', array('id' => $order_out['mid']), array('mobile', 'nickname', 'realname', 'distributorid')); + $distributor = pdo_get('wlmerchant_distributor', array('id' => $member['distributorid'])); + if (!empty($distributor)) { + if (empty($distributor['disflag'])) { + pdo_update('wlmerchant_distributor', array('disflag' => 1, 'updatetime' => time()), array('id' => $member['distributorid'])); + } + } else { + $distributor = pdo_get('wlmerchant_distributor', array('mid' => $order_out['mid'])); + if(!empty($distributor)){ + pdo_update('wlmerchant_distributor', array('disflag' => 1, 'updatetime' => time()), array('id' => $distributor['id'])); + $disid = $distributor['id']; + }else{ + $data = array( + 'uniacid' => $order_out['uniacid'], + 'aid' => $order_out['aid'], + 'mid' => $order_out['mid'], + 'createtime' => time(), + 'disflag' => 1, + 'nickname' => $member['nickname'], + 'mobile' => $member['mobile'], + 'realname' => $member['realname'], + 'leadid' => -1 + ); + pdo_insert('wlmerchant_distributor', $data); + $disid = pdo_insertid(); + } + pdo_update('wlmerchant_member', array('distributorid' => $disid), array('id' => $order_out['mid'])); + } +// } + } + } + + /** + * 函数的含义说明 + * + * @access public + * @name 方法名称 + * @param mixed 参数一的说明 + * @return array + */ + static function payHalfcardReturn($params) { + global $_W; + Util::wl_log('Vip_return', PATH_DATA . "merchant/data/", $params);//写入日志记录 + $order_out = pdo_get(PDO_NAME . 'halfcard_record', array('orderno' => $params['tid']), array('id')); + wl_message('支付成功',h5_url('pages/mainPages/paySuccess/paySuccess',['id'=>$order_out['id'],'type'=>5]), 'success'); + } + + + static function payChargeNotify($params) { + global $_W; + Util::wl_log('payResult_notify', PATH_DATA . "merchant/data/", $params); //写入异步日志记录 + $order_out = pdo_get(PDO_NAME . 'order', array('orderno' => $params['tid'])); + $_W['aid'] = $order_out['aid']; + $_W['uniacid'] = $order_out['uniacid']; + if ($order_out['status'] == 0) { + $data = self::getVipPayData($params); //得到支付参数,处理代付 + if ($data['status'] == 1) { + $data['status'] = 3; + } + $chargetype = pdo_get('wlmerchant_chargelist', array('id' => $order_out['fkid'])); + //处理分销 + if (p('distribution') && empty($chargetype['isdistri'])) { + $disorderid = Distribution::disCore($order_out['mid'], $order_out['price'], $chargetype['onedismoney'], $chargetype['twodismoney'], $chargetype['threedismoney'], $order_out['id'], 'charge', 1); + $data['disorderid'] = $disorderid; + } + $res = pdo_update(PDO_NAME . 'order', $data, array('orderno' => $params['tid'])); //更新订单状态 + if ($res) { + Store::ordersettlement($order_out['id']); + } + $merchant = pdo_get(PDO_NAME . 'merchantdata', array('id' => $order_out['sid']), array('id','storename','aid','endtime', 'status', 'enabled')); + $endtime = $merchant['endtime']; + $merstatus = $merchant['status']; + if ($endtime > time()) { + $newendtime = $order_out['num'] * 24 * 3600 + $endtime; + } else { + $newendtime = $order_out['num'] * 24 * 3600 + time(); + } + //权限 + $audits = pdo_getcolumn(PDO_NAME . 'chargelist', array('id' => $order_out['fkid']), 'audits'); + //商户组 + $groupid = $order_out['fkid']; + if (empty($groupid)) { + $groupid = 0; + } + if ($merstatus == 2) { + $merdata['endtime'] = $newendtime; + $merdata['groupid'] = $groupid; + if ($merchant['enabled'] == 3) { + $merdata['enabled'] = 1; + } + pdo_update(PDO_NAME . 'merchantdata', $merdata, array('id' => $order_out['sid'])); //更新商户 + } else { + if ($audits) { + pdo_update(PDO_NAME . 'merchantdata', array('status' => 2, 'endtime' => $newendtime, 'enabled' => 1, 'audits' => 1, 'groupid' => $groupid), array('id' => $order_out['sid'])); //更新商户 + pdo_update(PDO_NAME . 'merchantuser', array('status' => 2), array('storeid' => $order_out['sid'])); //更新管理员 + } else { + pdo_update(PDO_NAME . 'merchantdata', array('status' => 1, 'endtime' => $newendtime, 'groupid' => $groupid), array('id' => $order_out['sid'])); //更新商户 + $appname = pdo_getcolumn(PDO_NAME . 'merchantuser', array('storeid' => $merchant['id'], 'ismain' => 1), 'name'); + $agentname = pdo_getcolumn(PDO_NAME . 'agentusers' , ['id' => $merchant['aid']] , 'agentname'); + $first = '您好,'. $appname . '申请了新商家入驻'; + $type = '店铺申请入驻'; + $content = '店铺名:['.$merchant['storename'] .']'; + $status = '待审核'; + $time = time(); + $remark = '入驻代理:['.$agentname.'],请尽快前往系统后台审核商家资料'; + News::noticeAgent('storesettled',$order_out['aid'],$first,$type,$content,$status,$remark,$time); + } + } + } + } + + static function payChargeReturn($params) { + $order_out = pdo_get(PDO_NAME . 'order', array('orderno' => $params['tid']), array('id')); + wl_message('支付成功',h5_url('pages/mainPages/paySuccess/paySuccess',['id'=>$order_out['id'],'type'=>6]) , 'success'); + } + + + static function payPayonlineNotify($params) { + global $_W; + $order_out = pdo_get(PDO_NAME . 'order', array('orderno' => $params['tid'])); + $_W['uniacid'] = $order_out['uniacid']; + $_W['aid'] = $order_out['aid']; + $_W['wlsetting']['creditset'] = Setting::wlsetting_read('creditset'); + Util::wl_log('payResult_notify', PATH_DATA . "merchant/data/", $params); //写入异步日志记录 + if ($order_out['status'] == 0 || $order_out['status'] == 5) { + $data = self::getVipPayData($params); //得到支付参数,处理代付 + if ($data['status'] == 1) { + $data['status'] = 2; + } + $store = pdo_get(PDO_NAME . 'merchantdata', array('uniacid' => $order_out['uniacid'], 'id' => $order_out['sid']),array('storename','paypaidid','onepayonlinescale','twopayonlinescale','payonlinedisstatus','pay_drawid','pay_draw_money')); + //分销 + if($order_out['cerditmoney'] > 0 && $_W['wlsetting']['creditset']['nodistribution'] > 0){ + $nodis = 1; + }else{ + $nodis = 0; + } + if (p('distribution') && !empty($store['payonlinedisstatus']) && empty($nodis)) { + $_W['aid'] = $order_out['aid']; + $one = $order_out['price'] * $store['onepayonlinescale'] / 100; + $two = $order_out['price'] * $store['twopayonlinescale'] / 100; + $disorderid = Distribution::disCore($order_out['mid'], $order_out['price'], $one,$two, 0, $order_out['id'], 'payonline', 1); + $data['disorderid'] = $disorderid; + } + //处理业务员佣金 + if(p('salesman') && $order_out['sid'] > 0){ + $data['salesarray'] = Salesman::saleCore($order_out['sid'],'payonline'); + } + //支付有礼 + if($store['paypaidid'] > 0){ + $data['paidprid'] = Paidpromotion::getpaidpr(7,$store['paypaidid'],$order_out['mid'],$order_out['id'],$data['paytype'],$order_out['price']); + } + $res = pdo_update(PDO_NAME . 'order', $data, array('orderno' => $params['tid'])); //更新订单状态 + //结算在线买单 + if ($res) { + Store::ordersettlement($order_out['id']); + //返现 + Order::yueCityCashBack($order_out['mid'],$order_out['sid'],$order_out['price'],1); + //抽奖码 + if($store['pay_drawid'] > 0 && $order_out['price'] > $store['pay_draw_money'] ){ + Luckydraw::getDrawCode($store['pay_drawid'],$order_out['mid'],$order_out['id'],'payonline'); + } + } + + $record = array( + 'uniacid' => $order_out['uniacid'], + 'aid' => $order_out['aid'], + 'mid' => $order_out['mid'], + 'type' => 1, + 'cardid' => $order_out['card_id'], + 'activeid' => $order_out['fkid'], + 'merchantid' => $order_out['sid'], + 'freeflag' => $order_out['card_type'], + 'ordermoney' => $order_out['goodsprice'], + 'realmoney' => $order_out['price'], + 'verfmid' => $order_out['mid'], + 'usetime' => time(), + 'createtime' => time(), + 'commentflag' => 1, + 'discount' => $order_out['spec'], + 'undismoney' => $order_out['oprice'], + 'orderid' => $order_out['id'] + ); + $flagtime = time() - 5; + $flag = pdo_fetch("SELECT id FROM " . tablename('wlmerchant_timecardrecord') . "WHERE cardid = {$order_out['card_id']} AND activeid = {$order_out['fkid']} AND type = 1 AND createtime > {$flagtime} "); + if (empty($flag)) { + pdo_insert(PDO_NAME . 'timecardrecord', $record); + } + + if (empty($disorderid)) { + $disorderid = 0; + } + //收藏店铺 + News::addSysNotice($order_out['uniacid'],2,$order_out['sid'],0,$order_out['id']); + Store::addFans($order_out['sid'],$order_out['mid']); + //发消息给买家 + $openid = pdo_getcolumn(PDO_NAME . 'member', array('uniacid' => $order_out['uniacid'], 'id' => $order_out['mid']), 'openid'); + $nickname = pdo_getcolumn(PDO_NAME . 'member', array('uniacid' => $order_out['uniacid'], 'id' => $order_out['mid']), 'nickname'); + $storename = $store['storename']; + if ($order_out['fkid']) { + $goodsname = pdo_getcolumn(PDO_NAME . 'halfcardlist', array('uniacid' => $order_out['uniacid'], 'id' => $order_out['fkid']), 'title'); + } else { + $goodsname = $storename . '在线买单'; + } + $payinfo = array( + 'first' => '您的在线支付订单已经成功付款' , + 'order_no' => $order_out['orderno'],//订单编号 + 'time' => date('Y-m-d H:i:s', time()),//支付时间 + 'money' => $order_out['price'],//支付金额 + 'goods_name' => $goodsname,//商品名称 + 'remark' => '点击可查看订单详情,如有疑问请联系客服' + ); + $url = h5_url('pages/subPages/orderList/orderList',['status'=>1]); + TempModel::sendInit('pay',$order_out['mid'],$payinfo,$_W['source'],$url); + //发送给商家 + $admins = pdo_fetchall("SELECT mid FROM " . tablename('wlmerchant_merchantuser') . "WHERE uniacid = {$order_out['uniacid']} AND storeid = {$order_out['sid']} AND ismain IN (1,3) ORDER BY id DESC"); + if ($admins) { + foreach ($admins as $key => $ad) { + $userModelData = [ + 'first' => '用户:[' . $nickname . ']在线买单付费成功', + 'type' => '在线买单' ,//业务类型 + 'content' => '买单商户:' .$storename ,//业务内容 + 'status' => '已付款' . $order_out['price'] . '元',//处理结果 + 'time' => date('Y-m-d H:i:s', time()),//操作时间 + 'remark' => '点击查看订单' + ]; + $url = h5_url('pages/subPages/merchant/merchantOrderList/merchantOrderList',array('aid'=>$order_out['aid'],'storeid'=>$order_out['sid'])); + $url = str_replace('payment/','',$url); + TempModel::sendInit('service',$ad['mid'],$userModelData,$_W['source'],$url); + } + } + //打印 + Order::sendPrinting($order_out['id'],'payonline'); + } + + } + + static function payPayonlineReturn($params) { + $order_out = pdo_get(PDO_NAME . 'order', array('orderno' => $params['tid']), array('id')); + wl_message('支付成功',h5_url('pages/mainPages/paySuccess/paySuccess',['id'=>$order_out['id'],'type'=>7]) , 'success'); + } + + /** + * 函数的含义说明 + * + * @access public + * @name 方法名称 + * @param mixed 参数一的说明 + * @return array + */ + static function getVipPayData($params) { + global $_W; + $data = array('status' => $params['result'] == 'success' ? 1 : 0); + if ($params['is_usecard'] == 1) { + $fee = $params['card_fee']; + $data['is_usecard'] = 1; + } else { + $fee = $params['fee']; + } + //$paytype = array('credit' => 1, 'wechat' => 2, 'alipay' => 3, 'delivery' => 4, 'wxapp' => 5); + $data['paytype'] = $params['type']; + if ($params['tag']['transaction_id']) $data['transid'] = $params['tag']['transaction_id']; + $data['paytime'] = TIMESTAMP; + return $data; + } + + /** + * 获取系统运营概况(包括代理,会员等) + * + * @access public + * @name 方法名称 + * @param mixed 参数一的说明 + * @return array + */ + static function sysSurvey($refresh = 0) { + global $_W; +// $data = Cache::getCache('sysSurvey', 'allData'); +// if($data && !$refresh) return $data; + + /*代理概况*/ + + $agentUsers = Util::getNumData('id', PDO_NAME . 'agentusers', array()); + + $members = Util::getNumData("*", PDO_NAME . 'member', array('vipstatus' => 1)); + //*地图*/ + $time = date("Y-m-d H:i:s", time()); + $merchantNumData = Util::getNumData("*", PDO_NAME . 'member', array(), 'id desc', 0, 0, 1); + + $today = strtotime(date('Ymd')); + $firstday = strtotime(date('Y-m-01')); + $yestoday = $today - 86400; + //浏览量 + $d = date('Ymd'); + $uv = pdo_fetchall("select distinct mid from" . tablename(PDO_NAME . 'puvrecord') . "where uniacid = {$_W['uniacid']} and date='{$d}'"); + $todaypuv = pdo_get(PDO_NAME . 'puv', array('uniacid' => $_W['uniacid'], 'date' => date('Ymd')), array('pv', 'uv')); + $allpuv = pdo_getall(PDO_NAME . 'puv', array('uniacid' => $_W['uniacid']), array('pv', 'uv')); + $numPv = 0; + $numUv = 0; + foreach ($allpuv as $k => $v) { + $numPv += $v['pv']; + $numUv += $v['uv']; + } + $newfans = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename(PDO_NAME . 'member') . " WHERE uniacid = '{$_W['uniacid']}' and createtime >= {$firstday}"); + + /*进账总金额*/ + $totalInMoney = $totalOutMoney = $rushMoney = $vipMoney = $halfMoney = $orderMoney = $refundMoney = $settlementMoney = $waitSettlementMoney = $spercentMoney = $halfPercentMoney = $vipPercentMoney = 0; + //抢购订单金额 + $rushOrders = Util::getNumData('actualprice,status,issettlement', PDO_NAME . 'rush_order', array('#status#' => '(1,2,3,4,6,7)')); + foreach ($rushOrders[0] as $item) { + $rushMoney += $item['actualprice']; + if ($item['status'] == 7) $refundMoney += $item['actualprice']; + if ($item['issettlement'] == 0) $waitSettlementMoney += $item['actualprice']; + if ($item['issettlement'] == 1) $settlementMoney += $item['actualprice']; + } + //一卡通订单 + $halfOrders = Util::getNumData('price,issettlement', PDO_NAME . 'halfcard_record', array('status' => 1)); + foreach ($halfOrders[0] as $item) { + $halfMoney += $item['price']; + if ($item['issettlement'] == 0) $waitSettlementMoney += $item['price']; + if ($item['issettlement'] == 1) $settlementMoney += $item['price']; + } + //order表订单 + $orderOrders = Util::getNumData('price,status,issettlement', PDO_NAME . 'order', array('#status#' => '(1,2,3,4,6,7,8)')); + foreach ($orderOrders[0] as $item) { + $orderMoney += $item['price']; + if ($item['status'] == 7) $refundMoney += $item['price']; + if ($item['issettlement'] == 0) $waitSettlementMoney += $item['price']; + if ($item['issettlement'] == 1) $settlementMoney += $item['price']; + } + //结算 + $settlementOrders = Util::getNumData('*', PDO_NAME . 'settlement_record', array('#status#' => '(1,2,3,4,5)')); + foreach ($settlementOrders[0] as $item) { +// if($item['status']==4 || $item['status']==5){ +// $settlementMoney += $item['agetmoney']; +// }else{ +// $waitSettlementMoney += $item['aapplymoney']; +// } + if ($item['type'] == 1) $spercentMoney += $item['apercentmoney']; + if ($item['type'] == 2) $halfPercentMoney += $item['apercentmoney']; + if ($item['type'] == 3) $vipPercentMoney += $item['apercentmoney']; + } + $totalInMoney = sprintf("%.2f", $rushMoney + $vipMoney + $halfMoney + $orderMoney); + $totalOutMoney = sprintf("%.2f", $refundMoney + $settlementMoney); + $spercentMoney = sprintf("%.2f", $spercentMoney); + $halfPercentMoney = sprintf("%.2f", $halfPercentMoney); + $vipPercentMoney = sprintf("%.2f", $vipPercentMoney); + $settlementMoney = sprintf("%.2f", $settlementMoney); + $waitSettlementMoney = sprintf("%.2f", $waitSettlementMoney); + $data = array( + 'agentNum' => count($agentUsers[0]), + 'vipNum' => count($members[0]), + 'todayUv' => $todaypuv['uv'], + 'todayPv' => $todaypuv['pv'], + 'totalPv' => $numPv, + 'totalUv' => $numUv, + 'ThisMonthNewFans' => $newfans, + 'totalInMoney' => $totalInMoney, + 'totalOutMoney' => $totalOutMoney, + 'spercentMoney' => $spercentMoney, + 'halfPercentMoney' => $halfPercentMoney, + 'vipPercentMoney' => $vipPercentMoney, + 'settlementMoney' => $settlementMoney, + 'waitSettlementMoney' => $waitSettlementMoney + + ); + Cache::setCache('sysSurvey', 'allData', $data); + return $data; + } + + static function sysCashSurvey($refresh = 0, $timetype = 0, $starttime, $endtime) { + global $_W; +// $data = Cache::getCache('sysCashSurvey', 'allData'); +// if($data && !$refresh) return $data; + $where = array(); + $agentsData = Util::getNumData("id,agentname", PDO_NAME . 'agentusers', $where); + $agents = $agentsData[0]; + $children = array(); + if (!empty($agents)) { + //总览 + $allMoney = $allorder = $fishorder = $ingorder = $fishordermoney = $ingordermoney = $fishSettlement = $ingSettlement = $refund = $sysincome = 0; + //抢购 + $rushallmoney = $rushallorder = $rushfishorder = $rushingorder = $rushfishordermoney = $rushingordermoney = 0; + //团购 + $grouponallmoney = $grouponallorder = $grouponfishorder = $grouponingorder = $grouponfishordermoney = $grouponingordermoney = 0; + //拼团 + $fightallmoney = $fightallorder = $fightfishorder = $fightingorder = $fightfishordermoney = $fightingordermoney = 0; + //卡券 + $couponallmoney = $couponallorder = $couponfishorder = $couponingorder = $couponfishordermoney = 0; + //特权 + $halfcardallmoney = $halfcardallorder = $halfcardfishordermoney = 0; + //掌上信息 + $pocketallmoney = $pocketallorder = $pocketfishordermoney = 0; + + //计算系统收入 + $sysincome = pdo_getcolumn('wlmerchant_settlement_record', array('uniacid' => $_W['uniacid'], 'status >=' => 4), array("SUM(spercentmoney)")); + + foreach ($agents as $index => &$row) { + $aMoney = 0; + $where2['aid'] = $row['id']; + $data = Util::getNumData("id,storename,logo", PDO_NAME . 'merchantdata', $where2); + $set = Area::getSingleAgent($row['id']); + $percent = $set['percent']; + foreach ($data[0] as $k => &$v) { + $sMoney = 0; + $where3['#status#'] = '(1,2,3,4,6,7,8)'; + $where3['sid'] = $v['id']; + $where3['num>'] = 0; + if ($timetype == 1) { + $where3['createtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $where3['createtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $where3['createtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $where3['createtime>'] = $starttime; + $where3['createtime<'] = $endtime; + } + $rush_orders = Util::getNumData("actualprice,status,issettlement", PDO_NAME . 'rush_order', $where3); + if ($rush_orders[0]) { + foreach ($rush_orders[0] as $order) { + $sMoney += $order['actualprice']; + $rushallmoney += $order['actualprice']; + $allorder += 1; + $rushallorder += 1; + if ($order['status'] == 2 || $order['status'] == 3) { + $fishorder += 1; + $rushfishorder += 1; + $fishordermoney += $order['actualprice']; + $rushfishordermoney += $order['actualprice']; + if ($order['issettlement'] == 1) { + $fishSettlement += $order['actualprice']; + } else { + $ingSettlement += $order['actualprice']; + } + } else { + $ingorder += 1; + $rushingorder += 1; + $ingordermoney += $order['actualprice']; + $rushingordermoney += $order['actualprice']; + if ($order['status'] == 7) { + $refund += $order['actualprice']; + } + } + } + } + $orders = Util::getNumData("price,status,num,issettlement,plugin", PDO_NAME . 'order', $where3); + if ($orders[0]) { + foreach ($orders[0] as $order) { + $sMoney += $order['price']; + $allorder += 1; + + if ($order['plugin'] == 'wlfightgroup') { + $fightallmoney += $order['price']; + $fightallorder += 1; + } elseif ($order['plugin'] == 'coupon') { + $couponallorder += 1; + } elseif ($order['plugin'] == 'groupon') { + $grouponallmoney += $order['price']; + $grouponallorder += 1; + } + + if ($order['status'] == 2 || $order['status'] == 3) { + $fishordermoney += $order['price']; + $fishorder += 1; + + if ($order['plugin'] == 'wlfightgroup') { + $fightfishordermoney += $order['price']; + $fightfishorder += 1; + } elseif ($order['plugin'] == 'coupon') { + $couponallmoney += $order['price']; + $couponfishorder += 1; + } elseif ($order['plugin'] == 'groupon') { + $grouponfishordermoney += $order['price']; + $grouponfishorder += 1; + } + + if ($order['issettlement'] == 1) { + $fishSettlement += $order['price']; + if ($order['plugin'] == 'coupon') { + $couponfishordermoney += $order['price']; + } + } else { + $ingSettlement += $order['price']; + } + } else { + $ingorder += 1; + $ingordermoney += $order['price']; + if ($order['status'] == 7) { + $refund += $order['price']; + } + + if ($order['plugin'] == 'wlfightgroup') { + $fightingordermoney += $order['price']; + $fightingorder += 1; + } elseif ($order['plugin'] == 'coupon') { + $couponingorder += 1; + } elseif ($order['plugin'] == 'groupon') { + $grouponingordermoney += $order['price']; + $grouponingorder += 1; + } + + } + } + } + $v['sMoney'] = $sMoney; + $aMoney += $sMoney; + } + foreach ($data[0] as &$money) { + $money['forpercent'] = @sprintf('%.2f', ($money['sMoney'] / $aMoney) * 100); + } + + //计算vip与一卡通 + $where4['aid'] = $row['id']; + $where4['status'] = 1; + if ($timetype == 1) { + $where4['createtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $where4['createtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $where4['createtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $where4['createtime>'] = $starttime; + $where4['createtime<'] = $endtime; + } + $halforder = Util::getNumData("price", PDO_NAME . 'halfcard_record', $where4); + if ($halforder[0]) { + foreach ($halforder[0] as $order) { + $aMoney += $order['price']; + $allorder += 1; + $fishorder += 1; + $fishordermoney += $order['price']; + $halfcardallmoney += $order['price']; + $halfcardallorder += 1; + if ($order['issettlement'] == 1) { + $fishSettlement += $order['price']; + $halfcardfishordermoney += $order['price']; + } else { + $ingSettlement += $order['price']; + } + } + } + //计算掌上信息 + $where5['aid'] = $row['id']; + $where5['status'] = 3; + $where5['sid'] = 0; + if ($timetype == 1) { + $where5['createtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $where5['createtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $where5['createtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $where5['createtime>'] = $starttime; + $where5['createtime<'] = $endtime; + } + $pocketorder = Util::getNumData("price", PDO_NAME . 'order', $where5); + if ($pocketorder[0]) { + foreach ($pocketorder[0] as $order) { + $aMoney += $order['price']; + $allorder += 1; + $fishorder += 1; + $fishordermoney += $order['price']; + $pocketallmoney += $order['price']; + $pocketallorder += 1; + if ($order['issettlement'] == 1) { + $fishSettlement += $order['price']; + $pocketfishordermoney += $order['price']; + } else { + $ingSettlement += $order['price']; + } + } + } + $pocketnum = pdo_fetchall("SELECT id FROM " . tablename('wlmerchant_pocket_informations') . "WHERE mid > 0 ORDER BY id DESC"); + $pocketnum = count($pocketnum); + + + $children[$row['id']] = $data[0]; + $row['aMoney'] = $aMoney; + $allMoney += $aMoney; + } + } + $max = 0; + foreach ($agents as $index => &$percent) { + $percent['forpercent'] = @sprintf('%.2f', ($percent['aMoney'] / $allMoney) * 100); + $allMoney = sprintf('%.2f', $allMoney); + $max = $percent['aMoney'] > $max ? $max = $percent['aMoney'] : $max; + $max = sprintf('%.2f', $max); + } + $time = date('Y-m-d H:i:s', time()); + //新数据统计 + $newdata['all']['allmoney'] = $allMoney; + $newdata['all']['allorder'] = $allorder; + $newdata['all']['fishorder'] = $fishorder; + $newdata['all']['fishordermoney'] = $fishordermoney; + $newdata['all']['ingorder'] = $ingorder; + $newdata['all']['ingordermoney'] = $ingordermoney; + $newdata['all']['fishSettlement'] = @sprintf('%.2f', $fishSettlement); + $newdata['all']['ingSettlement'] = $ingSettlement; + $newdata['all']['refund'] = $refund; + $newdata['all']['sysincome'] = @sprintf('%.2f', $sysincome); + + $newdata['rush']['rushallmoney'] = $rushallmoney; + $newdata['rush']['rushallorder'] = $rushallorder; + $newdata['rush']['rushfishorder'] = $rushfishorder; + $newdata['rush']['rushfishordermoney'] = $rushfishordermoney; + $newdata['rush']['rushingorder'] = $rushingorder; + $newdata['rush']['rushingordermoney'] = $rushingordermoney; + + $newdata['groupon']['grouponallmoney'] = $grouponallmoney; + $newdata['groupon']['grouponallorder'] = $grouponallorder; + $newdata['groupon']['grouponfishorder'] = $grouponfishorder; + $newdata['groupon']['grouponfishordermoney'] = $grouponfishordermoney; + $newdata['groupon']['grouponingorder'] = $grouponingorder; + $newdata['groupon']['grouponingordermoney'] = $grouponingordermoney; + + $newdata['fight']['fightallmoney'] = $fightallmoney; + $newdata['fight']['fightallorder'] = $fightallorder; + $newdata['fight']['fightfishorder'] = $fightfishorder; + $newdata['fight']['fightfishordermoney'] = $fightfishordermoney; + $newdata['fight']['fightingorder'] = $fightingorder; + $newdata['fight']['fightingordermoney'] = $fightingordermoney; + + $fightwhere['status'] = 2; + if ($timetype == 1) { + $fightwhere['successtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $fightwhere['successtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $fightwhere['successtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $fightwhere['successtime>'] = $starttime; + $fightwhere['successtime<'] = $endtime; + } + $fightsuccess = Util::getNumData("id", PDO_NAME . 'fightgroup_group', $fightwhere); + $newdata['fight']['successnum'] = count($fightsuccess[0]); + + $newdata['coupon']['couponallmoney'] = $couponallmoney; + $newdata['coupon']['couponallorder'] = $couponallorder; + $newdata['coupon']['couponfishorder'] = $couponfishorder; + $newdata['coupon']['couponingorder'] = $couponingorder; + $newdata['coupon']['couponfishordermoney'] = $couponfishordermoney; + + $couponwhere['usetimes'] = 0; + if ($timetype == 1) { + $couponwhere['createtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $couponwhere['createtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $couponwhere['createtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $couponwhere['createtime>'] = $starttime; + $couponwhere['createtime<'] = $endtime; + } + $coupons = Util::getNumData("id", PDO_NAME . 'member_coupons', $couponwhere); + $newdata['coupon']['couponnum'] = count($coupons[0]); + + $newdata['halfcard']['halfcardallmoney'] = $halfcardallmoney; + $newdata['halfcard']['halfcardallorder'] = $halfcardallorder; + $newdata['halfcard']['halfcardfishordermoney'] = $halfcardfishordermoney; + $halfcardnum = pdo_fetchall("SELECT id FROM " . tablename('wlmerchant_halfcardmember') . "WHERE expiretime > " . time() . " ORDER BY id DESC"); + $halfcardnum = count($halfcardnum); + $newdata['halfcard']['halfcardnum'] = $halfcardnum; + + $newdata['vip']['vipallmoney'] = $vipallmoney; + $newdata['vip']['vipallorder'] = $vipallorder; + $newdata['vip']['vipfishordermoney'] = $vipfishordermoney; + $vipnum = pdo_fetchall("SELECT id FROM " . tablename('wlmerchant_member') . "WHERE lastviptime > " . time() . " ORDER BY id DESC"); + $vipnum = count($vipnum); + $newdata['vip']['vipnum'] = $vipnum; + + $newdata['pocket']['pocketallmoney'] = $pocketallmoney; + $newdata['pocket']['pocketallorder'] = $pocketallorder; + $newdata['pocket']['pocketfishordermoney'] = $pocketfishordermoney; + $newdata['pocket']['pocketnum'] = $pocketnum; + + + $data = array($agents, $children, $max, $allMoney, $time, $newdata); + Cache::setCache('sysCashSurvey', 'allData', $data); + return $data; + } + + static function agentCashSurvey($refresh = 0, $timetype = 0, $starttime, $endtime, $merchantid = 0) { + global $_W; +// $data = Cache::getCache('agentCashSurvey', 'allData'); +// if($data && !$refresh) return $data; + $where = array(); + $where['id'] = $_W['agent']['id']; + $agentsData = Util::getNumData("id,agentname", PDO_NAME . 'agentusers', $where); + $agents = $agentsData[0]; + $children = array(); + if (!empty($agents)) { + //总览 + $allMoney = $allorder = $fishorder = $ingorder = $fishordermoney = $ingordermoney = $fishSettlement = $ingSettlement = $refund = $sysincome = 0; + //抢购 + $rushallmoney = $rushallorder = $rushfishorder = $rushingorder = $rushfishordermoney = $rushingordermoney = 0; + //团购 + $grouponallmoney = $grouponallorder = $grouponfishorder = $grouponingorder = $grouponfishordermoney = $grouponingordermoney = 0; + //拼团 + $fightallmoney = $fightallorder = $fightfishorder = $fightingorder = $fightfishordermoney = $fightingordermoney = 0; + //卡券 + $couponallmoney = $couponallorder = $couponfishorder = $couponingorder = $couponfishordermoney = 0; + //特权 + $halfcardallmoney = $halfcardallorder = $halfcardfishordermoney = 0; + //掌上信息 + $pocketallmoney = $pocketallorder = $pocketfishordermoney = 0; + + //代理商佣金信息 + $agentAmount = Util::getSingelData('allmoney,nowmoney', PDO_NAME . 'agentusers', array('uniacid' => $_W['uniacid'], 'id' => $_W['aid'])); + $sysincome = $agentAmount['allmoney'];//代理佣金收入 + $fishSettlement = sprintf('%.2f', ($agentAmount['allmoney'] - $agentAmount['nowmoney']));//已结算金额 + $ingSettlement = sprintf('%.2f', $agentAmount['nowmoney']);//未结算金额 + + //计算系统收入 + $aMoney = 0; + $where2['aid'] = $agents[0]['id']; + if ($merchantid) { + $where2['id'] = $merchantid; + } + $data = Util::getNumData("id,storename,logo", PDO_NAME . 'merchantdata', $where2); + + $max = 0; + foreach ($data[0] as $k => &$v) { + + $sMoney = 0; + $where3['#status#'] = '(1,2,3,4,6,7,8)'; + $where3['sid'] = $v['id']; + if ($timetype == 1) { + $where3['createtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $where3['createtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $where3['createtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $where3['createtime>'] = $starttime; + $where3['createtime<'] = $endtime; + } + + $rush_orders = Util::getNumData("actualprice,status,issettlement,sid", PDO_NAME . 'rush_order', $where3); + foreach ($rush_orders[0] as $order) { + $sMoney += $order['actualprice']; + $allMoney += $order['actualprice']; + $rushallmoney += $order['actualprice']; + $allorder += 1; + $rushallorder += 1; + if ($order['status'] == 2 || $order['status'] == 3) { + $fishorder += 1; + $rushfishorder += 1; + $fishordermoney += $order['actualprice']; + $rushfishordermoney += $order['actualprice']; + if ($order['issettlement'] == 1) { + //$fishSettlement += $order['actualprice']; + $store = Store::getSingleStore($order['sid']); + } else { + //$ingSettlement += $order['actualprice']; + } + } else { + $ingorder += 1; + $rushingorder += 1; + $ingordermoney += $order['actualprice']; + $rushingordermoney += $order['actualprice']; + if ($order['status'] == 7) { + $refund += $order['actualprice']; + } + } + + } + $orders = Util::getNumData("price,status,num,issettlement,plugin,sid", PDO_NAME . 'order', $where3); + foreach ($orders[0] as $order) { + $sMoney += $order['price']; + $allMoney += $order['price']; + $allorder += 1; + + if ($order['plugin'] == 'wlfightgroup') { + $fightallmoney += $order['price']; + $fightallorder += 1; + } elseif ($order['plugin'] == 'coupon') { + $couponallorder += 1; + } elseif ($order['plugin'] == 'groupon') { + $grouponallmoney += $order['price']; + $grouponallorder += 1; + } + + if ($order['status'] == 2 || $order['status'] == 3) { + $fishordermoney += $order['price']; + $fishorder += 1; + + if ($order['plugin'] == 'wlfightgroup') { + $fightfishordermoney += $order['price']; + $fightfishorder += 1; + } elseif ($order['plugin'] == 'coupon') { + $couponallmoney += $order['price']; + $couponfishorder += 1; + } elseif ($order['plugin'] == 'groupon') { + $grouponfishordermoney += $order['price']; + $grouponfishorder += 1; + } + + if ($order['issettlement'] == 1) { + //$fishSettlement += $order['price']; + $store = Store::getSingleStore($order['sid']); + if ($order['plugin'] == 'coupon') { + $couponfishordermoney += $order['price']; + } + } else { + //$ingSettlement += $order['price']; + } + } else { + $ingorder += 1; + $ingordermoney += $order['price']; + if ($order['status'] == 7) { + $refund += $order['price']; + } + + if ($order['plugin'] == 'wlfightgroup') { + $fightingordermoney += $order['price']; + $fightingorder += 1; + } elseif ($order['plugin'] == 'coupon') { + $couponingorder += 1; + } elseif ($order['plugin'] == 'groupon') { + $grouponingordermoney += $order['price']; + $grouponingorder += 1; + } + } + } + $v['sMoney'] = $sMoney; + $aMoney += $sMoney; + } + foreach ($data[0] as &$money) { + $money['forpercent'] = @sprintf('%.2f', ($money['sMoney'] / $aMoney) * 100); + $max = $money['sMoney'] > $max ? $max = $money['sMoney'] : $max; + $max = sprintf('%.2f', $max); + } + if (empty($merchantid)) { + //计算vip与一卡通 + $where4['aid'] = $agents[0]['id']; + $where4['status'] = 1; + if ($timetype == 1) { + $where4['createtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $where4['createtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $where4['createtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $where4['createtime>'] = $starttime; + $where4['createtime<'] = $endtime; + } + $halforder = Util::getNumData("price", PDO_NAME . 'halfcard_record', $where4); + if ($halforder[0]) { + foreach ($halforder[0] as $order) { + $aMoney += $order['price']; + $allMoney += $order['price']; + $allorder += 1; + $fishorder += 1; + $fishordermoney += $order['price']; + $halfcardallmoney += $order['price']; + $halfcardallorder += 1; + if ($order['issettlement'] == 1) { + // $fishSettlement += $order['price']; + $halfcardfishordermoney += $order['price']; + } else { + //$ingSettlement += $order['price']; + } + } + } + //计算掌上信息 + $where5['aid'] = $agents[0]['id']; + $where5['status'] = 3; + $where5['sid'] = 0; + if ($timetype == 1) { + $where5['createtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $where5['createtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $where5['createtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $where5['createtime>'] = $starttime; + $where5['createtime<'] = $endtime; + } + $pocketorder = Util::getNumData("price", PDO_NAME . 'order', $where5); + if ($pocketorder[0]) { + foreach ($pocketorder[0] as $order) { + $aMoney += $order['price']; + $allMoney += $order['price']; + $allorder += 1; + $fishorder += 1; + $fishordermoney += $order['price']; + $pocketallmoney += $order['price']; + $pocketallorder += 1; + if ($order['issettlement'] == 1) { + //$fishSettlement += $order['price']; + $pocketfishordermoney += $order['price']; + } else { + // $ingSettlement += $order['price']; + } + } + } + $pocketnum = pdo_fetchall("SELECT id FROM " . tablename('wlmerchant_pocket_informations') . "WHERE mid > 0 ORDER BY id DESC"); + $pocketnum = count($pocketnum); + } + $children[$agents[0]['id']] = $data[0]; + $row['aMoney'] = $aMoney; + //$allMoney +=$aMoney; + } + foreach ($agents as $index => &$percent) { + $percent['forpercent'] = @sprintf('%.2f', ($percent['aMoney'] / $allMoney) * 100); + $allMoney = @sprintf('%.2f', $allMoney); + } + $time = date('Y-m-d H:i:s', time()); + + //新数据统计 + $newdata['all']['allmoney'] = $allMoney; + $newdata['all']['allorder'] = $allorder; + $newdata['all']['fishorder'] = $fishorder; + $newdata['all']['fishordermoney'] = $fishordermoney; + $newdata['all']['ingorder'] = $ingorder; + $newdata['all']['ingordermoney'] = $ingordermoney; + $newdata['all']['fishSettlement'] = $fishSettlement; + $newdata['all']['ingSettlement'] = $ingSettlement; + $newdata['all']['refund'] = $refund; + $newdata['all']['sysincome'] = @sprintf('%.2f', $sysincome); + + $newdata['rush']['rushallmoney'] = $rushallmoney; + $newdata['rush']['rushallorder'] = $rushallorder; + $newdata['rush']['rushfishorder'] = $rushfishorder; + $newdata['rush']['rushfishordermoney'] = $rushfishordermoney; + $newdata['rush']['rushingorder'] = $rushingorder; + $newdata['rush']['rushingordermoney'] = $rushingordermoney; + + $newdata['groupon']['grouponallmoney'] = $grouponallmoney; + $newdata['groupon']['grouponallorder'] = $grouponallorder; + $newdata['groupon']['grouponfishorder'] = $grouponfishorder; + $newdata['groupon']['grouponfishordermoney'] = $grouponfishordermoney; + $newdata['groupon']['grouponingorder'] = $grouponingorder; + $newdata['groupon']['grouponingordermoney'] = $grouponingordermoney; + + $newdata['fight']['fightallmoney'] = $fightallmoney; + $newdata['fight']['fightallorder'] = $fightallorder; + $newdata['fight']['fightfishorder'] = $fightfishorder; + $newdata['fight']['fightfishordermoney'] = $fightfishordermoney; + $newdata['fight']['fightingorder'] = $fightingorder; + $newdata['fight']['fightingordermoney'] = $fightingordermoney; + + $fightwhere['status'] = 2; + if ($timetype == 1) { + $fightwhere['successtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $fightwhere['successtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $fightwhere['successtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $fightwhere['successtime>'] = $starttime; + $fightwhere['successtime<'] = $endtime; + } + if ($merchantid) { + $fightwhere['sid'] = $merchantid; + } + $fightsuccess = Util::getNumData("id", PDO_NAME . 'fightgroup_group', $fightwhere); + $newdata['fight']['successnum'] = count($fightsuccess[0]); + + $newdata['coupon']['couponallmoney'] = $couponallmoney; + $newdata['coupon']['couponallorder'] = $couponallorder; + $newdata['coupon']['couponfishorder'] = $couponfishorder; + $newdata['coupon']['couponingorder'] = $couponingorder; + $newdata['coupon']['couponfishordermoney'] = $couponfishordermoney; + + $couponwhere['usetimes'] = 0; + if ($timetype == 1) { + $couponwhere['createtime>'] = strtotime(date('Ymd')); + } elseif ($timetype == 2) { + $couponwhere['createtime>'] = strtotime('-7 days'); + } else if ($timetype == 3) { + $couponwhere['createtime>'] = strtotime('-30 days'); + } else if ($timetype == 5) { + $couponwhere['createtime>'] = $starttime; + $couponwhere['createtime<'] = $endtime; + } + if ($merchantid) { + $coupons = pdo_getall('wlmerchant_couponlist', array('merchantid' => $merchantid), array('id')); + if ($coupons) { + $goodids = "("; +// foreach ($coupons as $k => $v) { +// if($k == 0){ +// $goodids.= $v['id']; +// }else{ +// $goodids.= ",".$v['id']; +// } +// } + for ($i = 0; $i < count($coupons); $i++) { + if ($i == 0) { + $goodids .= $coupons[$i]['id']; + } else { + $goodids .= "," . $coupons[$i]['id']; + } + } + $goodids .= ")"; + $couponwhere['parentid#'] = $goodids; + } else { + $couponwhere['parentid#'] = "(0)"; + } + } + $coupons = Util::getNumData("id", PDO_NAME . 'member_coupons', $couponwhere); + $newdata['coupon']['couponnum'] = count($coupons[0]); + + $newdata['halfcard']['halfcardallmoney'] = $halfcardallmoney; + $newdata['halfcard']['halfcardallorder'] = $halfcardallorder; + $newdata['halfcard']['halfcardfishordermoney'] = $halfcardfishordermoney; + $halfcardnum = pdo_fetchall("SELECT id FROM " . tablename('wlmerchant_halfcardmember') . "WHERE expiretime > " . time() . " ORDER BY id DESC"); + $halfcardnum = count($halfcardnum); + $newdata['halfcard']['halfcardnum'] = $halfcardnum; + + $newdata['vip']['vipallmoney'] = $vipallmoney; + $newdata['vip']['vipallorder'] = $vipallorder; + $newdata['vip']['vipfishordermoney'] = $vipfishordermoney; + $vipnum = pdo_fetchall("SELECT id FROM " . tablename('wlmerchant_member') . "WHERE lastviptime > " . time() . " ORDER BY id DESC"); + $vipnum = count($vipnum); + $newdata['vip']['vipnum'] = $vipnum; + + $newdata['pocket']['pocketallmoney'] = $pocketallmoney; + $newdata['pocket']['pocketallorder'] = $pocketallorder; + $newdata['pocket']['pocketfishordermoney'] = $pocketfishordermoney; + $newdata['pocket']['pocketnum'] = $pocketnum; + + $data = array($agents, $children, $max, $allMoney, $time, $newdata); + Cache::setCache('agentCashSurvey', 'allData', $data); + return $data; + } + + /** + * 获取系统运营概况(包括代理,会员等) + * + * @access public + * @name 方法名称 + * @param mixed 参数一的说明 + * @return array + */ + static function sysMemberSurvey() { + global $_W, $_GPC; + $stat = array(); + $today_starttime = strtotime(date('Y-m-d')); + $yesterday_starttime = $today_starttime - 86400; + $month_starttime = strtotime(date('Y-m')); + $where = $_W['aid'] ? " AND aid = " . $_W['aid'] : ''; + + $stat['yesterday_num'] = intval(pdo_fetchcolumn('select count(*) from ' . tablename('wlmerchant_member') . ' where uniacid = :uniacid and createtime >= :starttime and createtime <= :endtime' . $where, array(':uniacid' => $_W['uniacid'], ':starttime' => $yesterday_starttime, ':endtime' => $today_starttime))); + $stat['today_num'] = intval(pdo_fetchcolumn('select count(*) from ' . tablename('wlmerchant_member') . ' where uniacid = :uniacid and createtime >= :starttime' . $where, array(':uniacid' => $_W['uniacid'], ':starttime' => $today_starttime))); + $stat['month_num'] = intval(pdo_fetchcolumn('select count(*) from ' . tablename('wlmerchant_member') . ' where uniacid = :uniacid and createtime >= :starttime' . $where, array(':uniacid' => $_W['uniacid'], ':starttime' => $month_starttime))); + $stat['total_num'] = intval(pdo_fetchcolumn('select count(*) from ' . tablename('wlmerchant_member') . ' where uniacid = :uniacid' . $where, array(':uniacid' => $_W['uniacid']))); + + return $stat; + } + + /** + * 获取系统运营概况(包括代理,会员等) + * + * @access public + * @name 方法名称 + * @param mixed 参数一的说明 + * @return array + */ + static function agentSurvey($refresh = 0) { + global $_W; +// $data = Cache::getCache('agentSurvey', 'allData'); +// if($data && !$refresh) return $data; + /*会员概况*/ + $members = Util::getNumData("*", PDO_NAME . 'member', array('vipstatus' => 1, 'aid' => $_W['agent']['id'])); + $time = date("Y-m-d H:i:s", time()); + $merchants = Util::getNumData('id', PDO_NAME . 'merchantdata', array('aid' => $_W['agent']['id']), 'id desc', 0, 0, 1); + $areaids = Util::idSwitch('aid', 'areaid', $_W['agent']['id']); + $s = "(0"; + foreach ($areaids as $k => $v) { + $s .= "," . "'" . $v['areaid'] . "'"; + } + $s .= ")"; + $today = strtotime(date('Ymd')); + $firstday = strtotime(date('Y-m-01')); + $yestoday = $today - 86400; + //浏览量 + $where = array(); + $where['date'] = date('Ymd'); + $where['#areaid#'] = $s; + $todaypuv = Util::getSingelData('pv,uv', PDO_NAME . 'puv', $where); + if (empty($todaypuv)) $todaypuv['pv'] = $todaypuv['uv'] = 0; + unset($where['date']); + $allpuv = Util::getNumData('pv,uv', PDO_NAME . 'puv', $where); + $numPv = 0; + $numUv = 0; + foreach ($allpuv[0] as $k => $v) { + $numPv += $v['pv']; + $numUv += $v['uv']; + } + $newfans = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename(PDO_NAME . 'member') . " WHERE uniacid = '{$_W['uniacid']}' and createtime >= {$firstday}"); + + + /*进账总金额*/ + $totalInMoney = $totalOutMoney = $rushMoney = $vipMoney = $halfMoney = $orderMoney = $refundMoney = $settlementMoney = $waitSettlementMoney = $spercentMoney = $halfPercentMoney = $vipPercentMoney = 0; + //抢购订单金额 + $rushOrders = Util::getNumData('actualprice,status,issettlement', PDO_NAME . 'rush_order', array('#status#' => '(1,2,3,4,6,7)', 'aid' => $_W['agent']['id'])); + foreach ($rushOrders[0] as $item) { + $rushMoney += $item['actualprice']; + if ($item['issettlement'] == 1) $waitSettlementMoney += $item['actualprice']; + if ($item['issettlement'] == 2) $settlementMoney += $item['actualprice']; + if ($item['status'] == 7) $refundMoney += $item['actualprice']; + } + //VIP订单 + $vipOrders = Util::getNumData('price,issettlement', PDO_NAME . 'vip_record', array('#status#' => '(1)', 'aid' => $_W['agent']['id'])); + foreach ($vipOrders[0] as $item) { + $vipMoney += $item['price']; + if ($item['issettlement'] == 1) $waitSettlementMoney += $item['price']; + if ($item['issettlement'] == 2) $settlementMoney += $item['price']; + } + //一卡通订单 + $halfOrders = Util::getNumData('price,issettlement', PDO_NAME . 'halfcard_record', array('#status#' => '(1)', 'aid' => $_W['agent']['id'])); + foreach ($vipOrders[0] as $item) { + $halfMoney += $item['price']; + if ($item['issettlement'] == 1) $waitSettlementMoney += $item['price']; + if ($item['issettlement'] == 2) $settlementMoney += $item['price']; + } + //order表订单 + $orderOrders = Util::getNumData('price,status,issettlement', PDO_NAME . 'order', array('#status#' => '(1,2,3,4,6,7,8)', 'aid' => $_W['agent']['id'])); + foreach ($orderOrders[0] as $item) { + $orderMoney += $item['price']; + if ($item['status'] == 7) $refundMoney += $item['price']; + if ($item['issettlement'] == 1) $waitSettlementMoney += $item['price']; + if ($item['issettlement'] == 2) $settlementMoney += $item['price']; + } + //结算 + $settlementOrders = Util::getNumData('*', PDO_NAME . 'settlement_record', array('#status#' => '(1,2,3,4,5)', 'aid' => $_W['agent']['id'])); + foreach ($settlementOrders[0] as $item) { +// if($item['status']==5){ +// $settlementMoney += $item['sgetmoney']; +// }else{ +// $waitSettlementMoney += $item['sapplymoney']; +// } + if ($item['type'] == 1) $spercentMoney += $item['spercentmoney']; + if ($item['type'] == 2) $halfPercentMoney += $item['agetmoney']; + if ($item['type'] == 3) $vipPercentMoney += $item['agetmoney']; + } + $totalInMoney = sprintf("%.2f", $rushMoney + $vipMoney + $halfMoney + $orderMoney); + $totalOutMoney = sprintf("%.2f", $refundMoney + $settlementMoney); + $spercentMoney = sprintf("%.2f", $spercentMoney); + $halfPercentMoney = sprintf("%.2f", $halfPercentMoney); + $vipPercentMoney = sprintf("%.2f", $vipPercentMoney); + $settlementMoney = sprintf("%.2f", $settlementMoney); + $waitSettlementMoney = sprintf("%.2f", $waitSettlementMoney); + $data = array( + 'merchantNum' => count($merchants[0]), + 'vipNum' => count($members[0]), + 'updateTime' => $time, + 'todayPv' => $todaypuv['pv'], + 'todayUv' => $todaypuv['uv'], + 'totalPv' => $numPv, + 'totalUv' => $numUv, + 'ThisMouthNewFans' => $newfans, + 'totalInMoney' => $totalInMoney, + 'totalOutMoney' => $totalOutMoney, + 'spercentMoney' => $spercentMoney, + 'halfPercentMoney' => $halfPercentMoney, + 'vipPercentMoney' => $vipPercentMoney, + 'settlementMoney' => $settlementMoney, + 'waitSettlementMoney' => $waitSettlementMoney + ); + Cache::setCache('agentSurvey', 'allData', $data); + return $data; + } + + /** + * 获取系统运营概况(包括代理,会员等) + * + * @access public + * @name 方法名称 + * @param mixed 参数一的说明 + * @return array + */ + static function agentMemberSurvey($refresh = 0) { + global $_W; + $data = Cache::getCache('memberSurvey', 'allData'); + if ($data && !$refresh) return $data; + + $members = Util::getNumData("*", PDO_NAME . 'member', array('vipstatus' => 1, 'aid' => $_W['agent']['id'])); + //*地图*/ + $address_arr['beijing'] = 0; + $address_arr['tianjing'] = 0; + $address_arr['shanghai'] = 0; + $address_arr['chongqing'] = 0; + $address_arr['hebei'] = 0; + $address_arr['yunnan'] = 0; + $address_arr['liaoning'] = 0; + $address_arr['heilongjiang'] = 0; + $address_arr['hunan'] = 0; + $address_arr['anhui'] = 0; + $address_arr['shandong'] = 0; + $address_arr['xingjiang'] = 0; + $address_arr['jiangshu'] = 0; + $address_arr['zhejiang'] = 0; + $address_arr['jiangxi'] = 0; + $address_arr['hubei'] = 0; + $address_arr['guangxi'] = 0; + $address_arr['ganshu'] = 0; + $address_arr['shanxi'] = 0; + $address_arr['neimenggu'] = 0; + $address_arr['sanxi'] = 0; + $address_arr['jiling'] = 0; + $address_arr['fujian'] = 0; + $address_arr['guizhou'] = 0; + $address_arr['guangdong'] = 0; + $address_arr['qinghai'] = 0; + $address_arr['xizhang'] = 0; + $address_arr['shichuan'] = 0; + $address_arr['ningxia'] = 0; + $address_arr['hainan'] = 0; + foreach ($members[0] as $key => $value) { + $thisArea = pdo_get(PDO_NAME . 'area', array('id' => $value['areaid'])); + $name = pdo_get(PDO_NAME . 'area', array('id' => $thisArea['pid'])); + $address_name = mb_strcut($name['name'], 0, 6, 'utf-8'); + switch ($address_name) { + case '北京': + $address_arr['beijing'] += 1; + break; + case '天津': + $address_arr['tianjing'] += 1; + break; + case '上海': + $address_arr['shanghai'] += 1; + break; + case '重庆': + $address_arr['chongqing'] += 1; + break; + case '河北': + $address_arr['hebei'] += 1; + break; + case '河南': + $address_arr['henan'] += 1; + break; + case '云南': + $address_arr['yunnan'] += 1; + break; + case '辽宁': + $address_arr['liaoning'] += 1; + break; + case '黑龙': + $address_arr['heilongjiang'] += 1; + break; + case '湖南': + $address_arr['hunan'] += 1; + break; + case '安徽': + $address_arr['anhui'] += 1; + break; + case '山东': + $address_arr['shandong'] += 1; + break; + case '新疆': + $address_arr['xingjiang'] += 1; + break; + case '江苏': + $address_arr['jiangshu'] += 1; + break; + case '浙江': + $address_arr['zhejiang'] += 1; + break; + case '江西': + $address_arr['jiangxi'] += 1; + break; + case '湖北': + $address_arr['hubei'] += 1; + break; + case '广西': + $address_arr['guangxi'] += 1; + break; + case '甘肃': + $address_arr['ganshu'] += 1; + break; + case '山西': + $address_arr['shanxi'] += 1; + break; + case '内蒙': + $address_arr['neimenggu'] += 1; + break; + case '陕西': + $address_arr['sanxi'] += 1; + break; + case '吉林': + $address_arr['jiling'] += 1; + break; + case '福建': + $address_arr['fujian'] += 1; + break; + case '贵州': + $address_arr['guizhou'] += 1; + break; + case '广东': + $address_arr['guangdong'] += 1; + break; + case '青海': + $address_arr['qinghai'] += 1; + break; + case '西藏': + $address_arr['xizhang'] += 1; + break; + case '四川': + $address_arr['shichuan'] += 1; + break; + case '宁夏': + $address_arr['ningxia'] += 1; + break; + case '海南': + $address_arr['hainan'] += 1; + break; + } + } + $where = array(); + $stime = strtotime(date('Y-m-d')) - 86400; + $etime = strtotime(date('Y-m-d')); + $where['paytime>'] = $stime; + $where['paytime<'] = $etime; + $where['status'] = 1; + $where['aid'] = $_W['agent']['id']; + $yesterdayVip = Util::getNumData("*", PDO_NAME . 'vip_record', $where, 'id desc', 0, 0, 1); + + $stime = strtotime(date('Y-m-d')); + $etime = strtotime(date('Y-m-d')) + 86400; + $where['paytime>'] = $stime; + $where['paytime<'] = $etime; + $where['status'] = 1; + $where['aid'] = $_W['agent']['id']; + $todayVip = Util::getNumData("*", PDO_NAME . 'vip_record', $where, 'id desc', 0, 0, 1); + + $stime = strtotime(date('Y-m-d')) - 6 * 86400; + $etime = strtotime(date('Y-m-d')) + 86400; + $where['paytime>'] = $stime; + $where['paytime<'] = $etime; + $where['status'] = 1; + $where['aid'] = $_W['agent']['id']; + $weekVip = Util::getNumData("*", PDO_NAME . 'vip_record', $where, 'id desc', 0, 0, 1); + + $data = array(count($members), $address_arr, $yesterdayVip, $todayVip, $weekVip); + Cache::setCache('agentMemberSurvey', 'allData', $data); + return $data; + } + + static function cacheSurvey($aid,$storeid = 0) { + global $_W; + $condition = "WHERE uniacid = {$_W['uniacid']}"; + if($storeid){ + $condition .= " AND sid = {$storeid}"; + } + if ($aid) { + $condition .= " AND aid = {$aid}"; + if ($_W['wlsetting']['distribution']['seetstatus']) { + $condition2 = $condition . " AND plugin != 'distribution' "; + } + } + if (empty($condition2)) { + $condition2 = $condition; + } + if($storeid){ + $condition2 .= " AND plugin != 'store'"; + } + + $yesterday = date('d') - 1; + $yessta = mktime(0, 0, 0, date('m'), $yesterday, date('Y')); + $yesend = mktime(23, 59, 59, date('m'), $yesterday, date('Y')); + //昨日支付金额 + $rushyesmoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND paytime > {$yessta} AND paytime < {$yesend} "); + if($storeid){ + $halfyesmoney = 0; + }else { + $halfyesmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND paytime > {$yessta} AND paytime < {$yesend} "); + } + $otheryesmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$yessta} AND paytime < {$yesend} "); + $data['yesmoney'] = sprintf("%.2f", $rushyesmoney + $halfyesmoney + $otheryesmoney); + //昨日退款金额 + $rushrefyesmoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND paytime > {$yessta} AND paytime < {$yesend} AND status = 7"); + if($storeid){ + $halfrefyesmoney = 0; + }else { + $halfrefyesmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND paytime > {$yessta} AND paytime < {$yesend} AND status = 7"); + } + $otherrefyesmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$yessta} AND paytime < {$yesend} AND status = 7"); + $data['refyesmoney'] = sprintf("%.2f", $rushrefyesmoney + $halfrefyesmoney + $otherrefyesmoney); + if(!is_store()) { + //昨日新增客户 + $data['yesnewmember'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_member') . $condition . " AND createtime > {$yessta} AND createtime < {$yesend}"); + //昨日支付客户 + $rushyespaymember = pdo_fetchall('select distinct mid from ' . tablename(PDO_NAME . 'rush_order') . $condition . " AND paytime > {$yessta} AND paytime < {$yesend}"); + $rushyespaymember = count($rushyespaymember); + $halfyespaymember = pdo_fetchall('select distinct mid from ' . tablename(PDO_NAME . 'halfcard_record') . $condition . " AND paytime > {$yessta} AND paytime < {$yesend}"); + $halfyespaymember = count($halfyespaymember); + $otheryespaymember = pdo_fetchall('select distinct mid from ' . tablename(PDO_NAME . 'order') . $condition2 . " AND paytime > {$yessta} AND paytime < {$yesend}"); + $otheryespaymember = count($otheryespaymember); + $data['yespaymember'] = $rushyespaymember + $halfyespaymember + $otheryespaymember; + //昨日新增商户 + $data['yesnewmerchant'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_merchantdata') . $condition . " AND createtime > {$yessta} AND createtime < {$yesend} AND status = 2"); + //昨日付费入驻 + $data['yesnewcharge'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$yessta} AND paytime < {$yesend} AND plugin = 'store'"); + } + //昨日新增订单 + $yesnewrushorder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND createtime > {$yessta} AND createtime < {$yesend}"); + if($storeid){ + $yesnewhalforder = 0; + }else { + $yesnewhalforder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND createtime > {$yessta} AND createtime < {$yesend}"); + } + $yesnewotherorder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND createtime > {$yessta} AND createtime < {$yesend}"); + $data['yesneworder'] = $yesnewrushorder + $yesnewhalforder + $yesnewotherorder; + //昨日新增支付订单 + $yespaynewrushorder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND paytime > {$yessta} AND paytime < {$yesend}"); + if($storeid){ + $yespaynewhalforder = 0; + }else { + $yespaynewhalforder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND paytime > {$yessta} AND paytime < {$yesend}"); + } + $yespaynewotherorder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$yessta} AND paytime < {$yesend}"); + $data['yesnewpayorder'] = $yespaynewrushorder + $yespaynewhalforder + $yespaynewotherorder; + foreach ($data as $key => &$va) { + if (empty($va)) { + $va = 0; + } + } + for ($i = 29; $i > 0; $i--) { + $testday = date('d') - $i; + $teststa = mktime(0, 0, 0, date('m'), $testday, date('Y')); + $testend = mktime(23, 59, 59, date('m'), $testday, date('Y')); + $rushyesmoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND paytime > {$teststa} AND paytime < {$testend} "); + if($storeid){ + $halfyesmoney = 0; + }else { + $halfyesmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND paytime > {$teststa} AND paytime < {$testend} "); + } + $otheryesmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$teststa} AND paytime < {$testend} "); + $date = date('m-d', $testend); + $sales = sprintf("%.2f", $rushyesmoney + $halfyesmoney + $otheryesmoney); + $li = array( + 'year' => $date, + '金额' => (float)$sales + ); + $list[] = $li; + } + $data['list'] = $list; + $data['time'] = time(); + return $data; + } + + + static function newSurvey($aid,$storeid = 0) { + global $_W; + $condition = " WHERE uniacid = {$_W['uniacid']}"; + if($storeid){ + $condition .= " AND sid = {$storeid}"; + } + if ($aid) { + $condition .= " AND aid = {$aid}"; + if ($_W['wlsetting']['distribution']['seetstatus']) { + $condition2 = $condition . " AND plugin != 'distribution' "; + } + } + if (empty($condition2)) { + $condition2 = $condition; + } + if($storeid){ + $condition2 .= " AND plugin != 'store'"; + } + $todaytime = mktime(0, 0, 0, date('m'), date('d'), date('Y')); + //总支付金额 + //抢购 + $rushallmoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND paytime > {$todaytime}"); + //一卡通 + if($storeid){ + $halfallmoney = 0; + }else{ + $halfallmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND paytime > {$todaytime}"); + } + //其他 + $otherallmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$todaytime}"); + $data['allmoney'] = sprintf("%.2f", $otherallmoney + $halfallmoney + $rushallmoney); + //退款总金额 + $rushrefmoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND paytime > {$todaytime} AND status = 7"); + if($storeid){ + $halfrefmoney = 0; + }else { + $halfrefmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND paytime > {$todaytime} AND status = 7"); + } + $otherrefmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$todaytime} AND status = 7"); + $data['refmoney'] = sprintf("%.2f", $rushrefmoney + $halfrefmoney + $otherrefmoney); + //新增客户 + $data['newmember'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_member') . $condition . " AND createtime > {$todaytime}"); + //支付客户 + $rushpaymember = pdo_fetchall('select distinct mid from ' . tablename(PDO_NAME . 'rush_order') . $condition . " AND paytime > {$todaytime}"); + $rushpaymember = count($rushpaymember); + if($storeid){ + $halfpaymember = 0; + }else { + $halfpaymember = pdo_fetchall('select distinct mid from ' . tablename(PDO_NAME . 'halfcard_record') . $condition . " AND paytime > {$todaytime}"); + $halfpaymember = count($halfpaymember); + } + $otherpaymember = pdo_fetchall('select distinct mid from ' . tablename(PDO_NAME . 'order') . $condition2 . " AND paytime > {$todaytime}"); + $otherpaymember = count($otherpaymember); + $data['paymember'] = $rushpaymember + $halfpaymember + $otherpaymember; + if(empty($storeid)){ + //新增商户数 + $data['newmerchant'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_merchantdata') . $condition . " AND createtime > {$todaytime} AND status = 2"); + //付费入驻 + $data['newcharge'] = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$todaytime} AND plugin = 'store'"); + } + //新增订单 + $newrushorder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND createtime > {$todaytime}"); + if($storeid){ + $newhalforder = 0; + }else { + $newhalforder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND createtime > {$todaytime}"); + } + $newotherorder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND createtime > {$todaytime}"); + $data['neworder'] = $newrushorder + $newhalforder + $newotherorder; + //新增支付订单 + $newpayrushorder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND paytime > {$todaytime}"); + if($storeid){ + $newpayhalforder = 0; + }else { + $newpayhalforder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND paytime > {$todaytime}"); + } + $newpayotherorder = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$todaytime}"); + $data['newpayorder'] = $newpayrushorder + $newpayhalforder + $newpayotherorder; + //重要提醒 + if(empty($storeid)){ + //待发货订单数 + $dfhtotal1 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "order") . $condition . " AND plugin != 'consumption' AND status = 8"); + $dfhtotal2 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "rush_order") . $condition . " AND status = 8"); + $data['dfhorder'] = $dfhtotal1 + $dfhtotal2; + //待退款订单数 + $dtktotal1 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "order") . $condition . " AND status = 6"); + $dtktotal2 = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "rush_order") . $condition . " AND status = 6"); + $data['dtkorder'] = $dtktotal2 + $dtktotal1; + //申请退款订单数 + $sqtktotal = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "aftersale") . $condition . " AND status = 1"); + $data['sqtkorder'] = $sqtktotal; + //待审核商户 动态 评论 + $getStatus = " SELECT status FROM ".tablename(PDO_NAME."merchantdata")." as b where b.id = a.storeid "; + $data['merchantnum'] = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename(PDO_NAME . "merchantuser") + ." as a ". $condition + . " AND status = 1 AND ({$getStatus}) = 1 "); + $data['dynamicnum'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "store_dynamic") . $condition . " AND status = 0"); + $data['commentnum'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "comment") . $condition . " AND checkone = 1"); + //待审核的提现 商户 代理 分销 + $data['storeapply'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "settlement_record") . $condition . " AND status = 2 AND type = 1"); + $data['agentapply'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "settlement_record") . $condition . " AND status = 2 AND type = 2"); + //$data['disapply'] = $condition;//pdo_fetchcolumn('SELECT COUNT(id) FROM '.tablename(PDO_NAME."disapply").$condition." AND status = 2"); + $data['disapply'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "settlement_record") . $condition . " AND status IN (6,7) AND type = 3"); + //其他待审核信息 + $data['pocketnum'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "pocket_informations") . $condition . " AND status = 1"); + $data['disnum'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "applydistributor") . $condition . " AND status = 0"); + $data['aattnum'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "attestation_list") . $condition . " AND checkstatus = 1 AND type = 2"); + $data['uattnum'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "attestation_list") . $condition . " AND checkstatus = 1"); + + $data['rushnum'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "rush_activity") . $condition . " AND status = 5"); + $data['grouponnum'] = pdo_fetchcolumn('SELECT COUNT(id) FROM ' . tablename(PDO_NAME . "groupon_activity") . $condition . " AND status = 5"); + } + + + foreach ($data as $key => &$va) { + if (empty($va)) { + $va = 0; + } + } + //统计图 + //最近七天 + $sevenday = date('d') - 6; + $sevensta = mktime(0, 0, 0, date('m'), $sevenday, date('Y')); + $sevenend = time(); + $rushsevenmoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND paytime > {$sevensta} AND paytime < {$sevenend} "); + if($storeid){ + $halfsevenmoney = 0; + }else { + $halfsevenmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND paytime > {$sevensta} AND paytime < {$sevenend} "); + } + $othersevenmoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$sevensta} AND paytime < {$sevenend} "); + $data['sevenmoney'] = sprintf("%.2f", $rushsevenmoney + $halfsevenmoney + $othersevenmoney); + + //最近30天 + $threeday = date('d') - 29; + $threesta = mktime(0, 0, 0, date('m'), $threeday, date('Y')); + $threeend = time(); + $rushthreemoney = pdo_fetchcolumn('SELECT SUM(actualprice) FROM ' . tablename('wlmerchant_rush_order') . $condition . " AND paytime > {$threesta} AND paytime < {$threeend} "); + if($storeid){ + $halfthreemoney = 0; + }else { + $halfthreemoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_halfcard_record') . $condition . " AND paytime > {$threesta} AND paytime < {$threeend} "); + } + $otherthreemoney = pdo_fetchcolumn('SELECT SUM(price) FROM ' . tablename('wlmerchant_order') . $condition2 . " AND paytime > {$threesta} AND paytime < {$threeend} "); + $data['threemoney'] = sprintf("%.2f", $rushthreemoney + $halfthreemoney + $otherthreemoney); + return $data; + } +} diff --git a/addons/weliam_smartcity/core/class/PayBuild.class.php b/addons/weliam_smartcity/core/class/PayBuild.class.php new file mode 100644 index 0000000..4195b16 --- /dev/null +++ b/addons/weliam_smartcity/core/class/PayBuild.class.php @@ -0,0 +1,161 @@ + $uniacid), 'default_acid'); + $wechat['appid'] = pdo_getcolumn('account_wechats', array('acid' => $acid), 'key'); + $wechat['version'] = 2; + return wechat_build($params, $wechat); + } + + static function wechat_build($params, $wechat) { + global $_W; + load()->func('communication'); + if (empty($wechat['version']) && !empty($wechat['signkey'])) { + $wechat['version'] = 1; + } + $wOpt = array(); + if ($wechat['version'] == 1) { + $wOpt['appId'] = $wechat['appid']; + $wOpt['timeStamp'] = strval(TIMESTAMP); + $wOpt['nonceStr'] = random(8); + $package = array(); + $package['bank_type'] = 'WX'; + $package['body'] = $params['title']; + $package['attach'] = $_W['uniacid']; + $package['partner'] = $wechat['partner']; + $package['out_trade_no'] = $params['uniontid']; + $package['total_fee'] = $params['fee'] * 100; + $package['fee_type'] = '1'; + $package['notify_url'] = MODULE_URL . 'payment/wechat/weixin_notify.php'; + $package['spbill_create_ip'] = CLIENT_IP; + $package['time_start'] = date('YmdHis', TIMESTAMP); + $package['time_expire'] = date('YmdHis', TIMESTAMP + 600); + $package['input_charset'] = 'UTF-8'; + if (!empty($wechat['sub_appid'])) { + $package['sub_appid'] = $wechat['sub_appid']; + } + if (!empty($wechat['sub_mch_id'])) { + $package['sub_mch_id'] = $wechat['sub_mch_id']; + } + ksort($package); + $string1 = ''; + foreach ($package as $key => $v) { + if (empty($v)) { + continue; + } + $string1 .= "{$key}={$v}&"; + } + $string1 .= "key={$wechat['key']}"; + $sign = strtoupper(md5($string1)); + + $string2 = ''; + foreach ($package as $key => $v) { + $v = urlencode($v); + $string2 .= "{$key}={$v}&"; + } + $string2 .= "sign={$sign}"; + $wOpt['package'] = $string2; + + $string = ''; + $keys = array('appId', 'timeStamp', 'nonceStr', 'package', 'appKey'); + sort($keys); + foreach ($keys as $key) { + $v = $wOpt[$key]; + if ($key == 'appKey') { + $v = $wechat['signkey']; + } + $key = strtolower($key); + $string .= "{$key}={$v}&"; + } + $string = rtrim($string, '&'); + $wOpt['signType'] = 'SHA1'; + $wOpt['paySign'] = sha1($string); + return $wOpt; + } else { + $package = array(); + $package['appid'] = $wechat['appid']; + $package['mch_id'] = $wechat['mchid']; + $package['nonce_str'] = random(8); + $package['body'] = cutstr($params['title'], 26); + $package['attach'] = $_W['uniacid']; + $package['out_trade_no'] = $params['uniontid']; + $package['total_fee'] = $params['fee'] * 100; + $package['spbill_create_ip'] = CLIENT_IP; + $package['time_start'] = date('YmdHis', TIMESTAMP); + $package['time_expire'] = date('YmdHis', TIMESTAMP + 600); + $package['notify_url'] = MODULE_URL . 'payment/wechat/weixin_notify.php'; + $package['trade_type'] = 'JSAPI'; + $package['openid'] = empty($wechat['openid']) ? $_W['fans']['from_user'] : $wechat['openid']; + if (!empty($wechat['sub_appid'])) { + $package['sub_appid'] = $wechat['sub_appid']; + } + if (!empty($wechat['sub_mch_id'])) { + $package['sub_mch_id'] = $wechat['sub_mch_id']; + } + ksort($package, SORT_STRING); + $string1 = ''; + foreach ($package as $key => $v) { + if (empty($v)) { + continue; + } + $string1 .= "{$key}={$v}&"; + } + $string1 .= "key={$wechat['signkey']}"; + $package['sign'] = strtoupper(md5($string1)); + $dat = array2xml($package); + $response = ihttp_request('https://api.mch.weixin.qq.com/pay/unifiedorder', $dat); + if (is_error($response)) { + return $response; + } + $xml = @isimplexml_load_string($response['content'], 'SimpleXMLElement', LIBXML_NOCDATA); + if (strval($xml->return_code) == 'FAIL') { + return error(-1, strval($xml->return_msg)); + } + if (strval($xml->result_code) == 'FAIL') { + return error(-1, strval($xml->err_code) . ': ' . strval($xml->err_code_des)); + } + $prepayid = $xml->prepay_id; + $wOpt['appId'] = $wechat['appid']; + $wOpt['timeStamp'] = strval(TIMESTAMP); + $wOpt['nonceStr'] = random(8); + $wOpt['package'] = 'prepay_id=' . $prepayid; + $wOpt['signType'] = 'MD5'; + ksort($wOpt, SORT_STRING); + foreach ($wOpt as $key => $v) { + $string .= "{$key}={$v}&"; + } + $string .= "key={$wechat['signkey']}"; + $wOpt['paySign'] = strtoupper(md5($string)); + return $wOpt; + } + } + + /** + * Comment: 生成支付信息时判断当前订单是否存在开通会员卡的操作,并进行相关操作 + * Author: zzw + * @param $data 订单信息,必须存在vip_card_id & price字段 + * @return mixed + */ + static function isOpenCard($data, $field = 'price') { + if ($data['vip_card_id'] > 0) { + //会员卡id存在 代表用户在购买商品时开通了vip卡 + $cardPrice = pdo_getcolumn(PDO_NAME . "halfcard_type", array('id' => $data['vip_card_id']), 'price'); + $data[$field] = sprintf("%.2f", $data[$field] + $cardPrice); + } + return $data; + } +} \ No newline at end of file diff --git a/addons/weliam_smartcity/core/class/PayResult.class.php b/addons/weliam_smartcity/core/class/PayResult.class.php new file mode 100644 index 0000000..a4081ea --- /dev/null +++ b/addons/weliam_smartcity/core/class/PayResult.class.php @@ -0,0 +1,131 @@ + $params['tid'])); + $_W['uniacid'] = $params['uniacid'] ? $params['uniacid'] : $log['uniacid']; + $_W['acid'] = pdo_getcolumn('account_wechats' , array( 'uniacid' => $_W['uniacid'] ) , 'acid'); + $_W['source'] = $log['source']; + $member = pdo_get(PDO_NAME."member",['id'=>$log['mid']],['openid']); + $className = $log['plugin']; + $ret = [ + 'weid' => $log['uniacid'] , + 'uniacid' => $log['uniacid'] , + 'result' => 'success' , + 'type' => $params['type'] , + 'tid' => $log['tid'] , + 'uniontid' => $log['uniacid'] , + 'user' => $member['openid'] , + 'fee' => $log['fee'] , + 'tag' => $log['tag'] , + 'is_usecard' => $log['is_usecard'] , + 'card_type' => $log['card_type'] , + 'card_fee' => $log['card_fee'] , + 'card_id' => $log['card_id'] , + 'blendcredit'=> $log['blendcredit'] + ]; + Util::wl_log('rush_notify2' , PATH_DATA . "rush/data/" , $ret); //写入异步日志记录 + //混合支付扣除余额 + if($ret['blendcredit'] > 0){ + Member::credit_update_credit2($log['mid'],-$ret['blendcredit'],'混合支付['.$log['tid'].']订单支付余额'); + } + //当订单中存在开卡信息时的操作 + $tid = $params['tid']; + #1、获取订单信息 + if ($log['plugin'] == 'Rush') { + $orderInfo = pdo_get(PDO_NAME . "rush_order" , array( 'orderno' => $tid ) , array( 'mid','orderno','uniacid','aid','id','vip_card_id' )); + }else if($log['payfor'] == 'Halfcard'){ + $orderInfo = pdo_get(PDO_NAME . "halfcard_record" , array( 'orderno' => $tid ) , array( 'mid','orderno','uniacid','aid')); + } else { + $orderInfo = pdo_get(PDO_NAME . "order" , array( 'orderno' => $tid ) , array( 'mid','orderno','uniacid','aid', 'id','vip_card_id')); + } + if(empty($member['aid'])){ //给会员添加aid 修改用户所属代理 + pdo_update(PDO_NAME."member",array('aid' => $orderInfo['aid']),array('id' => $log['mid'])); + } + if ($orderInfo['vip_card_id'] > 0 && !empty($orderInfo['vip_card_id'])) { + $halftype = pdo_get(PDO_NAME . 'halfcard_type' , array( 'id' => $orderInfo['vip_card_id'] )); + #2、获取用户信息 + $userInfo = pdo_get(PDO_NAME . "member" , array( 'id' => $orderInfo['mid'] ) , array( 'nickname' , 'mobile' )); + $cardid = $orderInfo['vip_card_id']; + $username = $userInfo['nickname']; + $mobile = $userInfo['mobile']; + #3、到期时间计算 + if ($cardid) { + $mdata = array( 'uniacid' => $_W['uniacid'] , 'mid' => $orderInfo['mid'] , 'id' => $cardid ); + $vipInfo = Util::getSingelData('*' , PDO_NAME . "halfcardmember" , $mdata); + $lastviptime = $vipInfo['expiretime']; + if ($lastviptime && $lastviptime > time()) { + $limittime = $lastviptime + $halftype['days'] * 24 * 60 * 60; + } else { + $limittime = time() + $halftype['days'] * 24 * 60 * 60; + } + } else { + $limittime = time() + $halftype['days'] * 24 * 60 * 60; + } + #4、开卡信息记录 支付方式:1=余额;2=微信;3=支付宝;4=货到付款 + $data = array( + 'aid' => $orderInfo['aid'] , + 'uniacid' => $_W['uniacid'] , + 'mid' => $orderInfo['mid'] , + 'orderno' => createUniontid() , + 'status' => 1 ,//订单状态:0未支,1支付,2待发货,3已发货,4已签收,5已取消,6待退款,7已退款 + 'createtime' => TIMESTAMP , + 'price' => $halftype['price'] , + 'limittime' => $limittime , + 'typeid' => $halftype['id'] , + 'howlong' => $halftype['days'] , + 'todistributor' => $halftype['todistributor'] , + 'cardid' => $cardid , + 'username' => $username , + 'mobile' => $mobile + ); + $data['paytype'] = $params['type']; + $data['paytime'] = time(); + pdo_insert(PDO_NAME . 'halfcard_record' , $data); + $recordid = pdo_insertid(); + //分销 + if (p('distribution') && empty($halftype['isdistri'])) { + $_W['aid'] = $orderInfo['aid']; + $disorderid = Distribution::disCore($orderInfo['mid'] , $data['price'] , $halftype['onedismoney'] , $halftype['twodismoney'] , $halftype['threedismoney'] , $recordid , 'halfcard' , 1); + pdo_update(PDO_NAME . 'halfcard_record' , array( 'disorderid' => $disorderid ) , array( 'id' => $recordid )); + } + #5、成功开通会员卡 + $halfcarddata = array( + 'uniacid' => $_W['uniacid'] , + 'aid' => $data['aid'] , + 'mid' => $data['mid'] , + 'expiretime' => $data['limittime'] , + 'username' => $data['username'] , + 'levelid' => $halftype['levelid'] , + 'createtime' => time() + ); + pdo_insert(PDO_NAME . 'halfcardmember' , $halfcarddata); + } + if ($params['type'] == 2 && $params['bank_type'] != 'OTHERS'){ //银行卡返现 + $set = Setting::wlsetting_read('payback'); + if($set['status'] > 0){ + $rate = pdo_getcolumn(PDO_NAME.'payback_bank',array('uniacid'=>$_W['uniacid'],'bank'=>$params['bank_type']),'rate'); + if($rate > 0){ + $price = sprintf("%.2f",$ret['fee'] * $rate / 100); + if($price>0){ + Payback::payCore(0,$orderInfo['mid'],-2,'sys',$price,$orderInfo['orderno'],$orderInfo['id'],$orderInfo['uniacid'],$orderInfo['aid'],0,$params['bank_type']); + } + } + } + } + //开卡操作的结束 + pdo_update(PDO_NAME . 'paylogvfour' , [ 'status' => 1 , 'type' => $params['type'] ,'transaction_id'=>$params['transaction_id'],'pay_order_no'=>$params['pay_order_no']] + , ['tid' => $params['tid'] , 'uniacid' => $_W['uniacid'] ]); + $ret['from'] = 'notify'; + $functionName = 'pay' . $log['payfor'] . 'Notify'; + $className::$functionName($ret); + } +} diff --git a/addons/weliam_smartcity/core/class/Queue.class.php b/addons/weliam_smartcity/core/class/Queue.class.php new file mode 100644 index 0000000..cc8e27b --- /dev/null +++ b/addons/weliam_smartcity/core/class/Queue.class.php @@ -0,0 +1,1087 @@ + 0, 'expire' => 0); + private $expiretime = 900; //锁过期时间,秒 + + //初始赋值 + public function __construct() { + $lock = cache_read('queuelockfirstv4'); + if (!empty($lock)) $this->islock = $lock; + } + + //加锁 + private function setLock() { + $array = array('value' => 1, 'expire' => time()); + cache_write('queuelockfirstv4', $array); + cache_write(MODULE_NAME . ':task:status', $array); + $this->islock = $array; + } + + //删除锁 + public function deleteLock() { + cache_delete('queuelockfirstv4'); + $this->islock = array('value' => 0, 'expire' => time()); + return true; + } + + //检查是否锁定 + public function checkLock() { + $lock = $this->islock; + if ($lock['value'] == 1 && $lock['expire'] < (time() - $this->expiretime)) { //过期了,删除锁 + $this->deleteLock(); + return false; + } + if (empty($lock['value'])) { + return false; + } else { + return true; + } + } + + public function queueMain($on = '', $ex = '') { + global $_W; + if ($this->checkLock()) { + die('LOCK'); //锁定的时候直接返回 + //$this->deleteLock(); + } else { + $this->setLock(); //没锁的话锁定 + } + $this->doTask(); + $plugins = App::getPlugins(3); + foreach ($plugins as $plu) { + if ($plu['setting']['task'] == 'true') { + $class_name = ucfirst($plu['ident']); + if ($class_name == 'Wlcoupon') { + wlCoupon::doTask(); + } else { + if (method_exists($class_name, 'doTask')) { + @$class_name::doTask(); + } + } + } + } + //执行完删除锁 + $this->deleteLock(); + die('TRUE'); + } + + //增加待发消息 + public function addTask($key, $value, $dotime, $important) { + global $_W; + $flag = pdo_get('wlmerchant_waittask', array('key' => $key,'value' => $value,'important' => $important), array('id')); + if (empty($flag)) { + if (empty($_W['uniacid'])) { + if ($key == 1) { + $_W['uniacid'] = pdo_getcolumn(PDO_NAME . 'rush_order', array('id' => $important), 'uniacid'); + } else if ($key == 2) { + $_W['uniacid'] = pdo_getcolumn(PDO_NAME . 'order', array('id' => $important), 'uniacid'); + } else if ($key == 3) { + $_W['uniacid'] = pdo_getcolumn(PDO_NAME . 'disorder', array('id' => $important), 'uniacid'); + } + } + $data = array( + 'uniacid' => $_W['uniacid'], + 'key' => $key, + 'value' => $value, + 'status' => 0, + 'createtime' => time(), + 'dotime' => $dotime, + 'important' => $important + ); + $res = pdo_insert('wlmerchant_waittask', $data); + return $res; + } + } + + //删除消息队列 + public function finishTask($id) { + global $_W; + pdo_update('wlmerchant_waittask', array('status' => 1, 'finishtime' => time()), array('id' => $id)); + } + + public function laterTask($id) { + $time = time() + 600; + pdo_update('wlmerchant_waittask', array('dotime' => $time), array('id' => $id)); + } + + public function getTaskWhere($flag = 0){ + $sets = Cloud::wl_syssetting_read('taskcover'); + if($flag){ + if($sets['passiveid']){ + $passiveid = unserialize($sets['passiveid']); + $where = $passiveid; + }else{ + $where = []; + } + }else{ + if($sets['passiveid']){ + $passiveid = unserialize($sets['passiveid']); + $where = ' AND uniacid IN ('; + foreach ($passiveid as $key => $v) { + if ($key == 0) { + $where .= $v; + } else { + $where .= "," . $v; + } + } + $where .= ')'; + }else{ + $where = ''; + } + } + return $where; + } + + //查询需要发消息的记录 + public function getNeedTaskItem() { + global $_W; + $nowtime = time(); + $where = self::getTaskWhere(0); + return pdo_fetchall("SELECT * FROM " . tablename('wlmerchant_waittask') . " WHERE status = 0 AND dotime < {$nowtime} {$where} ORDER BY `dotime` ASC LIMIT 10"); + } + + + //执行等待中任务 + public function doTask() { + global $_W; + set_time_limit(0); //解除超时限制 + $nowtime = time(); + $message = self::getNeedTaskItem(); + if ($message) { + foreach ($message as $k => $v) { + $_W['uniacid'] = $v['uniacid']; + $data = unserialize($v['value']); + $res = 0; + if ($v['key'] == 1) { //结算抢购订单 + $res = Store::rushsettlement($v['important']); + } + if ($v['key'] == 2) { //结算通用订单 + $res = Store::ordersettlement($v['important']); + } + if ($v['key'] == 3) { //结算分销订单 + $res = Distribution::dissettlement($v['important']); + } + if ($v['key'] == 4) { //自动打款 + $cash = pdo_get(PDO_NAME . 'settlement_record', array('id' => $v['important'])); + if($cash['status'] != 3){ + $res = 1; + file_put_contents(PATH_DATA . "autoCashError.log", var_export($cash, true) . PHP_EOL, FILE_APPEND); + }else{ + if ($cash['payment_type'] == 2) { + if ($cash['sopenid']) { + $_W['account'] = uni_fetch($_W['uniacid']); + $realname = pdo_getcolumn(PDO_NAME . 'member', array('openid' => $cash['sopenid']), 'realname'); + //$result2 = wlPay::finance($cash['sopenid'], $cash['sgetmoney'], '提现自动打款', $realname, $cash['trade_no']); + switch ($cash['type']){ + case 1: + $userName = pdo_getcolumn(PDO_NAME."merchantdata",['id'=>$cash['sid']],'storename'); + $cash['mid'] = pdo_getcolumn(PDO_NAME . 'merchantuser', array('storeid' => $cash['sid'],'ismain' => 1), 'mid'); + $rem = '自动打款-商家提现:'.$userName; + break;//商家提现申请 + case 2: + $userName = pdo_getcolumn(PDO_NAME."agentusers",['id'=>$cash['aid']],'agentname'); + $rem = '自动打款-代理商提现:'.$userName; + $cash['mid'] = pdo_getcolumn(PDO_NAME . 'member', array('openid' => $cash['sopenid']), 'id'); + break;//代理提现申请 + case 3: + $userName = pdo_getcolumn(PDO_NAME."distributor",['mid'=>$cash['mid']],'nickname'); + $rem = '自动打款-分销商提现:'.$userName; + break;//分销商申请提现 + case 4: + $userName = pdo_getcolumn(PDO_NAME."member",['id'=>$cash['mid']],'nickname'); + $rem = '自动打款-用户提现:'.$userName; + break;//用户余额提现 + } + //请求进行微信打款操作 + $params = [ + 'openid' => $cash['sopenid'] , + 'money' => $cash['sgetmoney'] , + 'rem' => $rem , + 'name' => $realname , + 'order_no' => $cash['trade_no'], + 'source' => $cash['source'] ? : 1, + 'mid' => $cash['mid'], + 'return' => 1,//代表不返回任何信息 + ]; + $result2 = Payment::presentationInit($params,1); + Util::wl_log('cash_wechat_record', PATH_DATA . "cash/data/", $result2); //写入异步日志记录 + //结算操作 + if ($result2) { + if($cash['type'] == 1){ + $data['status'] = 5; + }else if($cash['type'] == 2){ + $data['status'] = 4; + }else if($cash['type'] == 3){ + $data['status'] = 9; + } + $data['updatetime'] = TIMESTAMP; + $data['settletype'] = 2; + $res = pdo_update(PDO_NAME.'settlement_record',$data,array('id' => $cash['id'])); + if($res){ + if($cash['type'] == 3){ + $url = h5_url('pages/subPages/dealer/withdraw/withdrawrecord',['draw_id'=>$cash['id']]); + Distribution::distriNotice($cash['mid'],$url,6,0,$cash['sapplymoney'],'微信零钱自动打款'); + }else{ + $first = '您的提现申请打款'; + $type = '提现申请'; + $status = '已打款'; + $content = '到账金额:¥'.$cash['sgetmoney']; + $remark = '谢谢您对平台的支持'; + News::jobNotice($cash['mid'],$first,$type,$content,$status,$remark,time()); + if($cash['type'] == 1){ + News::addSysNotice($cash['uniacid'],3,$cash['sid'],0,$cash['id'],1); + } + } + } + } + } + } else if ($cash['payment_type'] == 4) { + if ($cash['mid']) { + $result = Member::credit_update_credit2($cash['mid'], $cash['sgetmoney'], '分销商余额提现自动打款', 0); + //结算操作 + if ($result) { + $res = pdo_update(PDO_NAME . 'settlement_record', array('status' => 9, 'updatetime' => TIMESTAMP, 'settletype' => 4), array('id' => $cash['id'])); + if($res){ + $url = h5_url('pages/subPages/dealer/withdraw/withdrawrecord',['draw_id'=>$cash['id']]); + Distribution::distriNotice($cash['mid'],$url,6,0,$cash['sapplymoney'],'用户余额自动打款'); + } + } + } + } else if ($cash['payment_type'] == 1){ + if($cash['mid'] > 0){ + $cashmamber = pdo_get(PDO_NAME.'member',array('id'=>$cash['mid']),['realname','alipay']); + }else if($cash['sid'] > 0){ + $cashmamber = Store::getShopOwnerInfo($cash['sid'],$cash['aid']); + $cash['mid'] = $cashmamber['mid']; + }else if($cash['aid'] > 0){ + $agentinfo = pdo_get(PDO_NAME.'agentusers',array('id'=>$cash['aid']),['cashopenid','alipay']); + $cashmamber['alipay'] = $agentinfo['alipay']; + $cashmamber['realname'] = pdo_getcolumn(PDO_NAME.'member',array('id'=>$agentinfo['cashopenid']),'realname'); + $cash['mid'] = pdo_getcolumn(PDO_NAME . 'member', array('openid' => $cash['sopenid']), 'id'); + } + //请求进行微信打款操作 + $params = [ + 'money' => $cash['sgetmoney'] , + 'order_no' => $cash['trade_no'], + 'phone' => $cashmamber['alipay'], + 'source' => $cash['source'] ? : 1, + 'mid' => $cash['mid'], + 'realname' => $cashmamber['realname'], + 'return' => 1,//代表不返回任何信息 + ]; + $alires = Payment::presentationInit($params,3); + Util::wl_log('cash_ali_record', PATH_DATA . "cash/data/", $alires); //写入异步日志记录 + //结算操作 + if ($alires) { + if($cash['type'] == 1){ + $data['status'] = 5; + }else if($cash['type'] == 2){ + $data['status'] = 4; + }else if($cash['type'] == 3){ + $data['status'] = 9; + } + $data['updatetime'] = TIMESTAMP; + $data['settletype'] = 6; + $res = pdo_update(PDO_NAME.'settlement_record',$data,array('id' => $cash['id'])); + if($res){ + if($cash['type'] == 3){ + $url = h5_url('pages/subPages/dealer/withdraw/withdrawrecord',['draw_id'=>$cash['id']]); + Distribution::distriNotice($cash['mid'],$url,6,0,$cash['sapplymoney'],'支付宝自动转账'); + }else{ + $first = '您的提现申请打款'; + $type = '提现申请'; + $status = '已打款'; + $content = '到账金额:¥'.$cash['sgetmoney']; + $remark = '谢谢您对平台的支持'; + News::jobNotice($cash['mid'],$first,$type,$content,$status,$remark,time()); + if($cash['type'] == 1){ + News::addSysNotice($cash['uniacid'],3,$cash['sid'],0,$cash['id'],1); + } + } + } + } + + } + } + } + if ($v['key'] == 5) { //自动退款 + $after = pdo_get('wlmerchant_aftersale',array('id' => $v['important']),array('id','orderid','uniacid','status','plugin','checkcodes')); + $_W['uniacid'] = $after['uniacid']; + if(!empty($after)){ + if($after['status'] == 1){ + $checkcodes = unserialize($after['checkcodes']); + if(!empty($checkcodes[0])){ + $money = pdo_getcolumn('wlmerchant_smallorder',array('checkcode' => $checkcodes),array("SUM(orderprice)")); + if ($after['plugin'] == 'wlfightgroup') { + $res = Wlfightgroup::refund($after['orderid'],$money,0,0,$after['id']); + } else if ($after['plugin'] == 'coupon') { + $res = wlCoupon::refund($after['orderid'],$money, 0, 0, $after['id']); + } else if ($after['plugin'] == 'groupon') { + $res = Groupon::refund($after['orderid'], $money,0, 0, $after['id']); + } else if ($after['plugin'] == 'bargain') { + $res = Bargain::refund($after['orderid'], $money,0); + } else if ($after['plugin'] == 'rush') { + $res = Rush::refund($after['orderid'], $money,0, 0, $after['id']); + } + }else{ + if ($after['plugin'] == 'wlfightgroup') { + $res = Wlfightgroup::refund($after['orderid'], 0, 0); + } else if ($after['plugin'] == 'coupon') { + $res = wlCoupon::refund($after['orderid'], 0, 0); + } else if ($after['plugin'] == 'groupon') { + $res = Groupon::refund($after['orderid'], 0, 0); + } else if ($after['plugin'] == 'bargain') { + $res = Bargain::refund($after['orderid'], 0, 0); + } else if ($after['plugin'] == 'rush') { + $res = Rush::refund($after['orderid'], 0, 0); + } else if ($after['plugin'] == 'housekeep') { + $res = Housekeep::refund($after['orderid'], 0, 0); + } + } + //修改售后记录 + if($res['status']){ + $refundtype = '自动根据支付方式原路退款'; + $journal = array( + 'time' => time(), + 'title' => '到账成功', + 'detail' => '商家已退款:'.$refundtype, + ); + $journals = Order::addjournal($journal,$v['important']); + pdo_update('wlmerchant_aftersale',array('dotime' => time(),'status'=>2,'journal'=>$journals),array('id' =>$v['important'])); + pdo_update('wlmerchant_smallorder',array('status' => 3, 'refundtime' => time()),array('checkcode' =>$checkcodes,'status'=> array(1,4))); + } + $res = $res['status']; + }else{ + $res = 1; + } + }else{ + $res = 1; + } + } + if ($v['key'] == 6) { //自动收货 + if ($data['type'] == 'order') { + $order = pdo_get('wlmerchant_order', array('id' => $v['important'])); + if ($order['expressid'] && $order['status'] == 4) { + $res = Order::sureReceive($order['id'],$order['plugin']); + } else { + $res = 1; + } + } else if ($data['type'] == 'rush') { + $order = pdo_get('wlmerchant_rush_order', array('id' => $v['important'])); + if ($order['expressid'] && $order['status'] == 4) { + $res = Order::sureReceive($order['id'],'rush'); + } else { + $res = 1; + } + } else if ($data['type'] == 'consumption') { + $order = pdo_get('wlmerchant_consumption_record', array('id' => $v['important'])); + if ($order['expressid'] && $order['status'] == 2) { + pdo_update('wlmerchant_consumption_record', array('status' => 3), array('id' => $order['id'])); + pdo_update('wlmerchant_express', array('receivetime' => time()), array('id' => $order['expressid'])); + $order['disorderid'] = pdo_getcolumn(PDO_NAME . 'order', array('id' => $order['orderid']), 'disorderid'); + if ($order['disorderid']) { + $disres = pdo_update('wlmerchant_disorder', array('status' => 1), array('status' => 0, 'id' => $order['disorderid'])); + if ($disres) { + //添加结算分销订单到计划任务 + $distask = array( + 'type' => 'consumption', + 'orderid' => $order['disorderid'] + ); + $distask = serialize($distask); + Queue::addTask(3, $distask, time(), $order['disorderid']); + } + } + } else { + $res = 1; + } + } + } + if($v['key'] == 7){ //分账 + $task = unserialize($v['value']); + $weixin = NEW WeixinPay(); + $allres = $weixin->allocationPro($v['important'] , $task['type'] , $task['source'] ,unserialize($v['salesarray']), $task['salesmoney']); + if (is_array($allres)) { + pdo_update('wlmerchant_autosettlement_record' , [ + 'sysmoney' => $allres['sysmoney'] , + 'agentmoney' => $allres['agentmoney'] , + 'allocationtype' => 1 + ] , ['id' => $task['settlementid']]); + $res = 1; + } + } + if($v['key'] == 8){ //延迟发送模板消息 + Distribution::distriNotice($data['mid'], $data['url'], 2, $data['disid']); + $res = 1; + } + if($v['key'] == 9){ //票付通提交订单 + if($data['type'] == 'rush'){ + $orderinfo = pdo_get('wlmerchant_rush_order',array('id' => $data['orderid']),['pftinfo','orderno','remark']); + $pftinfo = unserialize($orderinfo['pftinfo']); + if(empty($pftinfo['ordername'])){ + $pftinfo['ordername'] = '系统代购'; + } + $pftinfo['remotenum'] = $orderinfo['orderno']; + $pftinfo['memo'] = $orderinfo['remark']; + $pftorderinfo = Pftapimod::pftOrderSubmit($pftinfo); + if(empty($pftorderinfo['UUerrorcode']) || $pftorderinfo['UUerrorcode'] == '1075'){ + $pftorderinfo = serialize($pftorderinfo); + $res = pdo_update(PDO_NAME . 'rush_order', ['pftorderinfo' => $pftorderinfo], array('id' => $data['orderid'])); //更新订单状态 + //订单信息查询 + $moreinfo = Pftapimod::pftOrderQuery($pftorderinfo['UUordernum']); + if(empty($moreinfo['UUerrorcode'])){ + $pftchangeinfo = [ + 'estimatetime' => strtotime($moreinfo['UUendtime']), + ]; + pdo_update(PDO_NAME . 'rush_order',$pftchangeinfo, array('id' => $data['orderid'])); //更新订单状态 + } + }else{ + Util::wl_log('pftNewError.log',PATH_DATA,$pftorderinfo); //写入异步日志记录 + } + }else{ + $orderinfo = pdo_get('wlmerchant_order',array('id' => $data['orderid']),['pftinfo','orderno','buyremark']); + $pftinfo = unserialize($orderinfo['pftinfo']); + if(empty($pftinfo['ordername'])){ + $pftinfo['ordername'] = '系统代购'; + } + $pftinfo['remotenum'] = $orderinfo['orderno']; + $pftinfo['memo'] = $orderinfo['buyremark']; + $pftorderinfo = Pftapimod::pftOrderSubmit($pftinfo); + if(empty($pftorderinfo['UUerrorcode']) || $pftorderinfo['UUerrorcode'] == '1075'){ + $pftorderinfo = serialize($pftorderinfo); + $res = pdo_update(PDO_NAME . 'order', ['pftorderinfo' => $pftorderinfo], array('id' => $data['orderid'])); //更新订单状态 + //订单信息查询 + $moreinfo = Pftapimod::pftOrderQuery($pftorderinfo['UUordernum']); + if(empty($moreinfo['UUerrorcode'])){ + $pftchangeinfo = [ + 'estimatetime' => strtotime($moreinfo['UUendtime']), + ]; + pdo_update(PDO_NAME . 'order',$pftchangeinfo, array('id' => $data['orderid'])); //更新订单状态 + } + }else{ + Util::wl_log('pftNewError.log',PATH_DATA,$pftorderinfo); //写入异步日志记录 + } + } + } + if($v['key'] == 10){ //卡密结算 + $smallorders = pdo_getall('wlmerchant_smallorder',array('status' => 1,'plugin' => $data['plugin'],'orderid' => $v['important']),array('id')); + if(!empty($smallorders)){ + foreach ($smallorders as $sor){ + $res = Order::finishSmallorder($sor['id'],0,5); + } + } + } + if($v['key'] == 11){ //话费充值提交订单 + $order_out = pdo_fetch("select * from" . tablename(PDO_NAME . 'mrecharge_order') . "where id='{$v['important']}'"); + if($order_out['channel'] == 1){ + $res = Mobilerecharge::sljOrderSubmit($order_out); + $res = $res['error'] ? 0 : 1; + } + } + if ($res) { + self::finishTask($v['id']); //完成已发的 + } else { + self::laterTask($v['id']); //推迟失败的 + } + } + } + + //删除未支付的积分兑换订单 + pdo_delete(PDO_NAME . "order", array('createtime <' => strtotime(date('Ymd')), 'plugin' => 'consumption', 'status' => 0)); + //过期商户 + $overmerchants = pdo_fetchall("SELECT id FROM " . tablename('wlmerchant_merchantdata') . "WHERE endtime < {$nowtime} AND enabled = 1 ORDER BY id DESC"); + if ($overmerchants) { + foreach ($overmerchants as $key => $over) { + $res = pdo_update(PDO_NAME . 'merchantdata', array('enabled' => 3), array('id' => $over['id'])); + if ($res) { //下架商品 + //抢购商品 + pdo_update('wlmerchant_rush_activity', array('status' => 4), array('sid' => $over['id'])); + //拼团商品 + pdo_update('wlmerchant_fightgroup_goods', array('status' => 0), array('merchantid' => $over['id'])); + //卡券 + pdo_update('wlmerchant_couponlist', array('status' => 0), array('merchantid' => $over['id'])); + //特权 + pdo_update('wlmerchant_halfcardlist', array('status' => 0), array('merchantid' => $over['id'])); + //礼包 + pdo_update('wlmerchant_package', array('status' => 0), array('merchantid' => $over['id'])); + //砍价 + pdo_update('wlmerchant_bargain_activity', array('status' => 0), array('sid' => $over['id'])); + //同城配送 + pdo_update('wlmerchant_delivery_activity', array('status' => 4), array('sid' => $over['id'])); + } + } + } + //兼容之前的未结算订单 + //抢购 + $rushorder = pdo_fetchall("SELECT id,uniacid FROM " . tablename('wlmerchant_rush_order') . "WHERE status IN (2,3) AND issettlement = 0 AND neworderflag = 0 ORDER BY id ASC limit 10"); + if ($rushorder) { + foreach ($rushorder as $key => $rush) { + $flag = pdo_get('wlmerchant_waittask', array('key' => 1, 'important' => $rush['id']), array('id')); + if (empty($flag)) { + $rushtask = array( + 'type' => 'rush', + 'orderid' => $rush['id'] + ); + $rushtask = serialize($rushtask); + $_W['uniacid'] = $rush['uniacid']; + Queue::addTask(1, $rushtask, time(), $rush['id']); + } + } + } + //其他 + $otherorder = pdo_fetchall("SELECT id,plugin,uniacid FROM " . tablename('wlmerchant_order') . "WHERE status IN (2,3) AND issettlement = 0 AND neworderflag = 0 AND plugin != 'consumption' ORDER BY id ASC limit 10"); + if ($otherorder) { + foreach ($otherorder as $key => $order) { + $flag = pdo_get('wlmerchant_waittask', array('key' => 2, 'important' => $order['id']), array('id')); + if (empty($flag)) { + $rushtask = array( + 'type' => $order['plugin'], + 'orderid' => $order['id'] + ); + $rushtask = serialize($rushtask); + $_W['uniacid'] = $order['uniacid']; + Queue::addTask(2, $rushtask, time(), $order['id']); + } + } + } + //分销订单 + $disorders = pdo_fetchall("SELECT id,plugin,uniacid FROM " . tablename('wlmerchant_disorder') . "WHERE status = 1 AND neworderflag = 0 ORDER BY id ASC limit 10"); + if ($disorders) { + foreach ($disorders as $key => $disorder) { + $flag = pdo_get('wlmerchant_waittask', array('key' => 3, 'important' => $disorder['id']), array('id')); + if (empty($flag)) { + $rushtask = array( + 'type' => $disorder['plugin'], + 'orderid' => $disorder['id'] + ); + $rushtask = serialize($rushtask); + $_W['uniacid'] = $disorder['uniacid']; + Queue::addTask(3, $rushtask, time(), $disorder['id']); + } else { + $detail = pdo_get('wlmerchant_disdetail', array('disorderid' => $disorder['id']), array('id')); + if (!empty($detail)) { + pdo_update('wlmerchant_disorder', array('status' => 2), array('id' => $disorder['id'])); + } + } + } + } + //修改明细表uniacid数据 + $details = pdo_getall('wlmerchant_disdetail', array('uniacid' => 0), array('id', 'disorderid')); + if ($details) { + foreach ($details as $key => $va) { + $uniacid = pdo_getcolumn('wlmerchant_disorder', array('id' => $va['disorderid']), 'uniacid'); + pdo_update('wlmerchant_disdetail', array('uniacid' => $uniacid), array('id' => $va['id'])); + } + } + //自动取消订单与删除已取消订单 + //删除一个月之前所有已取消的订单 + $montime = time() - 365 * 24 * 3600; + pdo_delete(PDO_NAME . "rush_order", array('createtime <' => $montime, 'status' => 5)); + pdo_delete(PDO_NAME . "order", array('createtime <' => $montime, 'status' => 5)); + pdo_delete(PDO_NAME . "halfcard_record", array('createtime <' => $montime, 'status' => 0)); + + /*自动取消订单*/ + $onwtime = time(); + $rushorderdata = pdo_fetchall("select id from" . tablename(PDO_NAME . "rush_order") . "where status = 0 and canceltime > 0 and canceltime < {$onwtime}"); + if (!empty($rushorderdata)) { + foreach ($rushorderdata as $k => $v) { + Rush::cancelorder($v['id']); + } + } + + $orderdata = pdo_fetchall("select id,plugin,redpackid,usecredit,mid from" . tablename(PDO_NAME . "order") . "where status = 0 and canceltime < '{$onwtime}' and canceltime > 0"); + if (!empty($orderdata)) { + foreach ($orderdata as $k => $v) { + if($v['plugin'] == 'groupon'){ + Groupon::cancelorder($v['id']); + }else if($v['plugin'] == 'bargain'){ + Bargain::cancelorder($v['id']); + }else if($v['plugin'] == 'wlfightgroup'){ + Wlfightgroup::cancelorder($v['id']); + }else if($v['plugin'] == 'coupon'){ + wlCoupon::cancelorder($v['id']); + }else{ + pdo_query('UPDATE ' . tablename(PDO_NAME . 'order') . " SET `status` = 5 WHERE id = {$v['id']}"); + if($v['redpackid']){ + pdo_update('wlmerchant_redpack_records',['status' => 0],['id' => $v['redpackid']]); + } + if($v['usecredit'] > 0){ + if($v['plugin'] == 'halfcard'){ + $pluginname = '在线买单'; + } + Member::credit_update_credit1($v['mid'], $v['usecredit'], '取消'.$pluginname.'订单返还积分'); + } + } + } + } + + //即将过期订单通知 + $remindrushorder = pdo_fetchall("select id,activityid,mid,uniacid,aid,estimatetime from" . tablename(PDO_NAME . "rush_order") . "where status = 1 and remindtime < {$onwtime} and remindtime > 0 and cutoffnotice = 0 "); + if (!empty($remindrushorder)) { + foreach ($remindrushorder as $k => $v) { + $goodsname = pdo_getcolumn(PDO_NAME . 'rush_activity', array('id' => $v['activityid']), 'name'); + $first = '您有一个抢购订单即将过期'; + $type = '订单即将过期提醒'; + $content = '商品名称:[' . $goodsname . ']'; + $status = '即将过期'; + $remark = '过期时间:' . date('Y-m-d H:i:s', $v['estimatetime']) . '点击去使用'; + $_W['uniacid'] = $v['uniacid']; + $_W['source'] = 1; + $_W['account'] = uni_fetch($_W['uniacid']); + $url = h5_url('pages/subPages/orderList/orderDetails/orderDetails', ['orderid' => $v['id'], 'plugin' => 'rush'],'h5',$v['aid']); + News::jobNotice($v['mid'], $first, $type, $content, $status, $remark, time(), $url); + pdo_update('wlmerchant_rush_order', array('cutoffnotice' => 1), array('id' => $v['id'])); + } + } + + $remindorder = pdo_fetchall("select id,fkid,mid,plugin,recordid,uniacid,estimatetime from" . tablename(PDO_NAME . "order") . "where status = 1 and remindtime < {$onwtime} and remindtime > 0 and cutoffnotice = 0 "); + if (!empty($remindorder)) { + foreach ($remindorder as $k => $v) { + if(intval($_W['uniacid']) <= 0) $_W['uniacid'] = $v['uniacid'];//从新定义uniacid 兼容计划任务没有uniacid的问题 + if($v['plugin'] == 'activity'){ + $activity = pdo_get('wlmerchant_activitylist',array('id' => $v['fkid']),array('title','activestarttime','activeendtime')); + $goodsname = $activity['title']; + $first = '您报名的一个活动即将开始'; + $type = '活动即将开始提醒'; + $content = '活动名称:[' . $goodsname . ']'; + $status = '即将开始'; + $remark = '活动时间:' . date('Y-m-d H:i', $activity['activestarttime']).'-'.date('Y-m-d H:i', $activity['activeendtime']).',点击去使用'; + }else{ + switch ($v['plugin']) { + case 'groupon': + $goodsname = pdo_getcolumn(PDO_NAME . 'groupon_activity', array('id' => $v['fkid']), 'name'); + $plugin = '团购'; + break; + case 'wlfightgroup': + $goodsname = pdo_getcolumn(PDO_NAME . 'fightgroup_goods', array('id' => $v['fkid']), 'name'); + $plugin = '拼团'; + break; + case 'bargain': + $goodsname = pdo_getcolumn(PDO_NAME . 'bargain_activity', array('id' => $v['fkid']), 'name'); + $plugin = '砍价'; + break; + case 'coupon': + $goodsname = pdo_getcolumn(PDO_NAME . 'couponlist', array('id' => $v['fkid']), 'title'); + $plugin = '卡券'; + break; + } + $first = '您有一个' . $plugin . '订单即将过期'; + $type = '订单即将过期提醒'; + $content = '商品名称:[' . $goodsname . ']'; + $status = '即将过期'; + $remark = '过期时间:' . date('Y-m-d H:i:s', $v['estimatetime']) . '点击去使用'; + } + $_W['uniacid'] = $v['uniacid']; + $_W['source'] = 1; + $_W['account'] = uni_fetch($_W['uniacid']); + if ($v['plugin'] == 'coupon') { + $url = h5_url('pages/subPages/coupon/couponDetails/couponDetails', ['order_id' => $v['id'], 'id' => $v['recordid']]); + } else { + $url = h5_url('pages/subPages/orderList/orderDetails/orderDetails', ['orderid' => $v['id'], 'plugin' => $v['plugin']]); + } + News::jobNotice($v['mid'], $first, $type, $content, $status, $remark, time(), $url); + pdo_update('wlmerchant_order', array('cutoffnotice' => 1), array('id' => $v['id'])); + } + } + + //处理当日重复结算 + $todaytime = strtotime(date("Y-m-d"), time()); + $commentSql = "select checkcode,count(*) as count from" . tablename(PDO_NAME . "autosettlement_record") . "group by checkcode having count > 1 AND checkcode > 0 AND createtime > {$todaytime}"; + $comment = pdo_fetchall($commentSql); + if (!empty($comment)) { + foreach ($comment as $com) { + $list = pdo_fetchall("SELECT * FROM " . tablename(PDO_NAME . 'autosettlement_record') . "WHERE checkcode = '{$com['checkcode']}' ORDER BY id DESC"); + $num = count($list) - 1; + for ($i = 0; $i < $num; $i++) { + if ($list[$i]['merchantmoney'] > 0) { + pdo_fetch("update" . tablename('wlmerchant_merchantdata') . "SET allmoney=allmoney-{$list[$i]['merchantmoney']},nowmoney=nowmoney-{$list[$i]['merchantmoney']} WHERE id = {$list[$i]['merchantid']}"); + } + if ($list[$i]['agentmoney'] > 0) { + pdo_fetch("update" . tablename('wlmerchant_agentusers') . "SET allmoney=allmoney+{$list[$i]['agentmoney']},nowmoney=nowmoney+{$list[$i]['agentmoney']} WHERE id = {$list[$i]['aid']}"); + } + pdo_delete('wlmerchant_autosettlement_record', array('id' => $list[$i]['id'])); + } + } + } + + //处理用户头像 + $members = pdo_fetchall("SELECT id,avatar FROM ".tablename('wlmerchant_member')."WHERE avatar LIKE '%http://%' ORDER BY id DESC LIMIT 100"); + foreach ($members as &$mem){ + $newavatar = str_replace('http://','https://',$mem['avatar']); + pdo_update('wlmerchant_member',array('avatar' => $newavatar),array('id' => $mem['id'])); + } + + //重置店铺经纬度 + $stores = pdo_fetchall("SELECT * FROM ".tablename('wlmerchant_merchantdata')."WHERE lng = 0 ORDER BY id DESC LIMIT 50"); + if(!empty($stores)){ + foreach ($stores as $st){ + $location = unserialize($st['location']); + pdo_update('wlmerchant_merchantdata',array('lng' => $location['lng'],'lat' => $location['lat']),array('id' => $st['id'])); + } + } + //为评论添加gid信息 + $comments = pdo_fetchall("SELECT idoforder,id,plugin FROM ".tablename('wlmerchant_comment')."WHERE gid = 0 ORDER BY id DESC LIMIT 10"); + if(!empty($comments)){ + foreach ($comments as $com){ + if($com['plugin'] == 'rush'){ + $gid = pdo_getcolumn(PDO_NAME.'rush_order',array('id'=>$com['idoforder']),'activityid'); + }else if($com['plugin'] == 'noorder'){ + $gid = -1; + }else if($com['plugin'] == 'usehalf'){ + $gid = pdo_getcolumn(PDO_NAME.'timecardrecord',array('id'=>$com['idoforder']),'activeid'); + }else{ + $gid = pdo_getcolumn(PDO_NAME.'order',array('id'=>$com['idoforder']),'fkid'); + } + pdo_update('wlmerchant_comment',array('gid' => $gid),array('id' => $com['id'])); + } + } + + //处理未结算的一卡通订单 + $halfpaylist = pdo_getall('wlmerchant_halfcard_record',array('status' => 1,'issettlement' => 0),array('id')); + if(!empty($halfpaylist)){ + foreach ($halfpaylist as $half){ + Store::halfsettlement($half['id']); + } + } + //转赠活动过期 + $overTransfer = pdo_get('wlmerchant_transfer_list',array('is_over' => 0 , 'createtime <' => time() - 86400,'surplus >' => 0),array('mid','surplus','money','id','uniacid')); + if(!empty($overTransfer)){ + $_W['uniacid'] = $overTransfer['uniacid']; + $price = sprintf("%.2f",$overTransfer['surplus'] * $overTransfer['money']); + $res = Member::credit_update_credit2($overTransfer['mid'],$price,'转赠活动过期退回余额,活动编号:'.$overTransfer['id'],$overTransfer['id']); + if(!is_error($res)){ + pdo_update('wlmerchant_transfer_list',array('is_over' => 1),array('id' => $overTransfer['id'])); + } + } + + //同步没有商品数据的小订单 + $nogidsmallorders = pdo_fetchall("SELECT id,plugin,orderid FROM ".tablename('wlmerchant_smallorder')."WHERE gid = 0 ORDER BY id DESC LIMIT 500"); + if(!empty($nogidsmallorders)){ + foreach ($nogidsmallorders as $smallor){ + if($smallor['plugin'] == 'rush'){ + $parentOrder = pdo_get('wlmerchant_rush_order',array('id' => $smallor['orderid']),array('activityid','optionid')); + if(empty($parentOrder)){ + $gid = -1; + }else{ + $gid = $parentOrder['activityid']; + $specid = $parentOrder['optionid']; + } + }else{ + $parentOrder = pdo_get('wlmerchant_order',array('id' => $smallor['orderid']),array('fkid','specid')); + if(empty($parentOrder)){ + $gid = -1; + }else{ + $gid = $parentOrder['fkid']; + $specid = $parentOrder['specid']; + } + } + pdo_update('wlmerchant_smallorder',array('gid' => $gid,'specid' => $specid),array('id' => $smallor['id'])); + } + } + //修正公众号id不正确的分销商 + $commentSql = "SELECT a.id,a.mid,a.uniacid FROM ". tablename(PDO_NAME."distributor") + ." as a LEFT JOIN ".tablename(PDO_NAME."member") + ." as b ON a.mid = b.id WHERE + CASE + WHEN a.uniacid != b.uniacid THEN 1 + ELSE 0 + END = 1 ORDER BY id DESC"; + $comment = pdo_fetchall($commentSql); + if(!empty($comment)){ + foreach ($comment as $com){ + $uniacid = pdo_getcolumn(PDO_NAME.'member',array('id'=>$com['mid']),'uniacid'); + pdo_update(PDO_NAME."distributor",array('uniacid' => $uniacid),array('id' => $com['id'])); + } + } + + //处理重复的分销商数据 + $commentSql2 = "select mid,count(*) as count from" . tablename(PDO_NAME . "distributor") . "group by mid having count > 1 AND mid > 0 LIMIT 20"; + $comment2 = pdo_fetchall($commentSql2); + foreach ($comment2 as $com2){ + $member = pdo_get('wlmerchant_member',array('id' => $com2['mid']),array('distributorid')); + pdo_delete('wlmerchant_distributor',array('mid'=>$com2['mid'],'id !=' => $member['distributorid'],'nowmoney <'=> '0.01')); + } + + //添加无创建时间的快递订单的创建时间 + $notimecityorder = pdo_fetchall("SELECT id,orderid FROM ".tablename('wlmerchant_delivery_order')."WHERE createtime = 0 ORDER BY id DESC LIMIT 10"); + if(!empty($notimecityorder)){ + foreach($notimecityorder as $cityorder){ + $createtime = pdo_getcolumn(PDO_NAME.'order',array('id'=>$cityorder['orderid']),'createtime'); + pdo_update('wlmerchant_order',array('createtime' => $createtime),array('id' => $cityorder['id'])); + } + } + + //自动退款哦 + $where = self::getTaskWhere(0); + $overorders = pdo_fetchall("SELECT id,recordid,plugin,fkid FROM " . tablename('wlmerchant_order') . "WHERE uniacid = {$_W['uniacid']} AND status = 6 {$where} AND failtimes < 3 limit 10"); + if ($overorders) { + foreach ($overorders as $key => $over) { + if ($over['plugin'] == 'wlfightgroup') { + $usedtime = pdo_getcolumn(PDO_NAME . 'fightgroup_userecord', array('id' => $over['recordid']), 'usedtime'); + $overrefund = pdo_getcolumn(PDO_NAME . 'fightgroup_goods', array('id' => $over['fkid']), 'overrefund'); + if (empty($usedtime) && $overrefund) { + Wlfightgroup::refund($over['id']); + } + } else if ($over['plugin'] == 'groupon') { + $usedtime = pdo_getcolumn(PDO_NAME . 'groupon_userecord', array('id' => $over['recordid']), 'usedtime'); + $overrefund = pdo_getcolumn(PDO_NAME . 'groupon_activity', array('id' => $over['fkid']), 'overrefund'); + if (empty($usedtime) && $overrefund) { + Groupon::refund($over['id']); + } + } else if ($over['plugin'] == 'coupon') { + $usedtime = pdo_getcolumn(PDO_NAME . 'member_coupons', array('id' => $over['recordid']), 'usedtime'); + $overrefund = pdo_getcolumn(PDO_NAME . 'couponlist', array('id' => $over['fkid']), 'overrefund'); + if (empty($usedtime) && $overrefund) { + wlCoupon::refund($over['id']); + } + } else if ($over['plugin'] == 'activity') { + Activity::refundorder($over['id']); + } + } + } + pdo_update('wlmerchant_member',array('card_number' => ''),array('card_number' => 'undefined')); + + //删除锁定订单 + pdo_delete('wlmerchant_temporary_orderlist',array('deteletime <'=>time())); + //提现写入 + $settlement_temporary = pdo_fetchall("SELECT * FROM ".tablename('wlmerchant_settlement_temporary')."WHERE uniacid > 0 ORDER BY id DESC"); + if(!empty($settlement_temporary)){ + foreach($settlement_temporary as $settlement){ + $_W['uniacid'] = $settlement['uniacid']; + $data = unserialize($settlement['info']); + if($settlement['type'] == 1){ + $res = Member::credit_update_credit2($data['mid'] , -$data['sapplymoney'],'用户余额提现'); + if (!is_error($res)) { + if (pdo_insert(PDO_NAME . 'settlement_record' , $data)) { + $orderid = pdo_insertid(); + //管理员模板消息发送 + $adminmid = Setting::wlsetting_read('adminmid'); + if (!empty($adminmid)) { + $nickname = pdo_getcolumn(PDO_NAME.'member',array('id'=>$data['mid']),'nickname'); + $messagedata = [ + 'first' => '您好,有一个用户余额提现申请待审核。' , + 'type' => '用户[' . $nickname . ']申请提现' . $data['sapplymoney'] . '元' ,//业务类型 + 'content' => $_W['wlsetting']['trade']['fxstext'] . ':[' . $nickname . ']' ,//业务内容 + 'status' => '待审核' ,//处理结果 + 'time' => date('Y-m-d H:i:s' , time()) ,//操作时间 + 'remark' => '请尽快前往系统后台审核' + ]; + TempModel::sendInit('service' , $adminmid , $messagedata , $data['source'] , ''); + } + //用户模板消息发送 + $messagedata2 = [ + 'first' => '您的提现申请已成功提交' , + 'type' => '申请提现' . $data['sapplymoney'] . '元' ,//业务类型 + 'content' => '申请用户:[' . $nickname . ']' ,//业务内容 + 'status' => '待审核' ,//处理结果 + 'time' => date('Y-m-d H:i:s' , time()) ,//操作时间 + ]; + TempModel::sendInit('service' , $data['mid'] , $messagedata2 , $data['source'] , ''); + } + } + } //用户余额提现 + else if($settlement['type'] == 2){ + //可提现金额校验 + $merchant = pdo_get('wlmerchant_merchantdata' , ['id' => $data['sid']] , ['allmoney' , 'nowmoney' , 'reservestatus' , 'reservemoney', 'autocash']); + $cashsets = Setting::wlsetting_read('cashset'); + //预留金额设置 + if ($merchant['reservestatus']) { + $reservemoney = $merchant['reservemoney']; + } else { + $reservemoney = sprintf("%.2f" , $cashsets['reservemoney']); + } + $usemoney = sprintf("%.2f" , $merchant['nowmoney'] - $reservemoney); + if ($usemoney < 0) { + $usemoney = 0; + } + if ($data['sapplymoney'] < $usemoney || $data['sapplymoney'] == $usemoney) { + if (pdo_insert(PDO_NAME . 'settlement_record' , $data)) { + $orderid = pdo_insertid(); + $res = Store::settlement($orderid , 0 , $data['sid'] , -$data['sapplymoney'] , 0 , -$data['sapplymoney'] , 7 , 0 , 0 , $data['aid']); + if ($res) { + if ($cashsets['noaudit'] && $cashsets['autocash'] && $data['payment_type'] != 3 && $merchant['autocash']) { + Queue::addTask(4 , $orderid , time() , $orderid); + }else if($data['status'] == 2){ + $storename = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $data['sid']] , 'storename'); + $modelData = [ + 'first' => '您好,有一个商户提现申请待审核。' , + 'type' => '商户提现申请' ,//业务类型 + 'content' => '商户[' . $storename . ']申请提现' . $data['sapplymoney'] . '元' ,//业务内容 + 'status' => '待审核' ,//处理结果 + 'time' => date("Y-m-d H:i:s" , time()) ,//操作时间$store['createtime'] + 'remark' => '请尽快前往系统后台审核!' + ]; + TempModel::sendInit('service' , -1 , $modelData , $data['source']); + }else if($data['status'] == 3){ + $storename = pdo_getcolumn(PDO_NAME . 'merchantdata' , ['id' => $data['sid']] , 'storename'); + $modelData = [ + 'first' => '您好,有一个商户提现申请待打款。' , + 'type' => '商户提现申请' ,//业务类型 + 'content' => '商户[' . $storename . ']申请提现' . $data['sapplymoney'] . '元' ,//业务内容 + 'status' => '待打款' ,//处理结果 + 'time' => date("Y-m-d H:i:s" , time()) ,//操作时间$store['createtime'] + 'remark' => '请尽快前往系统后台审核!' + ]; + TempModel::sendInit('service' , -1 , $modelData , $data['source']); + } + } + } + } + }//商户提现 + else if($settlement['type'] == 3){ + $dismember = pdo_get(PDO_NAME.'member',array('id'=>$data['mid']),['distributorid','nickname']); + $nickname = $dismember['nickname']; + $disid = $dismember['distributorid']; + $distributor = pdo_get(PDO_NAME . 'distributor', array('id' => $disid), array('nowmoney', 'id')); + if ($data['sapplymoney'] < $distributor['nowmoney'] || $data['sapplymoney'] == $distributor['nowmoney'] ){ + $nowmoney = $distributor['nowmoney'] - $data['sapplymoney']; + pdo_update(PDO_NAME . 'distributor', array('nowmoney' => $nowmoney), array('id' => $distributor['id'])); + $res = pdo_insert(PDO_NAME . "settlement_record", $data); + $disorderid = pdo_insertid(); + if($res){ + $cashsets = Setting::wlsetting_read('cashset'); + if ($cashsets['disautocash'] && $data['payment_type'] != 3) { + Queue::addTask(4, $disorderid, time(), $disorderid); + } + $url = h5_url('pages/subPages/dealer/withdraw/withdrawrecord', ['draw_id' => $disorderid]); + if ($cashsets['disnoaudit']) { + Distribution::distriNotice($_W['mid'], $url, 4, 0, $data['sapplymoney']); + } else { + Distribution::distriNotice($_W['mid'], $url, 3, 0, $data['sapplymoney']); + } + Distribution::adddisdetail($disorderid, $data['mid'], $data['mid'], 2, $data['sapplymoney'], 'cash', 1, '分销佣金提现', $nowmoney); + //给管理员发送通知信息 + $textsets = Setting::wlsetting_read('trade'); + $meaasgedata = array( + 'first' => '您好,有一个'.$textsets['fxtext'].'提现申请待审核。', + 'type' => $textsets['fxstext'] . '申请提现',//业务类型 + 'content' => '申请人:[' . $nickname . ']',//业务内容 + 'status' => '待审核',//处理结果 + 'time' => date('Y-m-d H:i:s', time()),//操作时间 + 'remark' => '请尽快前往系统后台处理' + ); + TempModel::sendInit('service', -1, $meaasgedata, $data['source'], ''); + } + } + }//分销商提现 + else if($settlement['type'] == 5){ + //获取红娘信息 + $matchmaker = pdo_get(PDO_NAME."dating_matchmaker",['mid' => $settlement['mid'],'uniacid' => $_W['uniacid']]); + $set = Setting::wlsetting_read('dating_set'); + $member = pdo_get(PDO_NAME."member",['id'=>$settlement['mid']],['nickname']); + //判断当前操作是否合法 提现金额必须小于或者等于可提现金额 + if($data['sapplymoney'] <= $matchmaker['commission']){ + //修改红娘的可提现金额 + $surplusMoney = sprintf("%.2f",$matchmaker['commission'] - $data['sapplymoney']); + pdo_update(PDO_NAME."dating_matchmaker",['commission'=>$surplusMoney],['id'=>$matchmaker['id']]); + //记录变更 + Dating::commissionChangeRecord($settlement['mid'],$data['sapplymoney'],'红娘申请提现',2); + //将当前信息记录到提现表 + $res = pdo_insert(PDO_NAME . "settlement_record", $data); + if($res){ + $recordId = pdo_insertid(); + //15=红娘提现审核中,16=红娘提现审核通过(待打款),17=红娘提现驳回,18=红娘提现已完成(打款完成) + if($set['automatic_payment'] == 1 && $data['status'] == 16){ + //开启自动打款 状态为已审核 调用计划任务进行自动打款 + Queue::addTask(4, $recordId, time(), $recordId); + }else{ + //未开启自动打款 | 状态不为已审核 发送模板消息提醒管理员进行处理 + $meaasgedata = [ + 'first' => '您好,有一个红娘提现申请待处理', + 'type' => '红娘申请提现',//业务类型 + 'content' => "申请人:[{$member['nickname']}]",//业务内容 + 'status' => $data['status'] == 16 ? '待打款' : '待审核',//处理结果 + 'time' => date('Y-m-d H:i:s',time()),//操作时间 + 'remark' => '请尽快前往系统后台处理' + ]; + TempModel::sendInit('service',-1,$meaasgedata,$data['source']); + } + } + } + }//红娘提现 + pdo_delete('wlmerchant_settlement_temporary',array('id'=>$settlement['id'])); + } + } + + //定制内容 幸运团自动返现 + $orders385 = pdo_fetchall("SELECT id,mid,orderno,fkid,uniacid FROM " . tablename('wlmerchant_order') . "WHERE redpagstatus = 1 {$where} limit 10"); + if(!empty($orders385)){ + foreach ($orders385 as $or385){ + $_W['uniacid'] = $or385['uniacid']; + $_W['account'] = uni_fetch($_W['uniacid']); + $orsource = pdo_getcolumn(PDO_NAME.'paylogvfour',array('tid'=>$or385['orderno'],'mid'=>$or385['mid']),'source'); + $nlUser = pdo_get('wlmerchant_member',array('id' => $or385['mid']),array('openid','wechat_openid')); + $luckymoney = pdo_getcolumn(PDO_NAME.'fightgroup_goods',array('id'=>$or385['fkid']),'luckymoney'); + if($orsource == 1){ + $sopenid = $nlUser['openid']; + }else if($orsource == 3){ + $sopenid = $nlUser['wechat_openid']; + } + if(empty($sopenid)){ + if(!empty($nlUser['openid'])){ + $sopenid = $nlUser['openid']; + $orsource = 1; + } + if(!empty($nlUser['wechat_openid'])){ + $sopenid = $nlUser['wechat_openid']; + $orsource = 3; + } + } + if(!empty($sopenid)){ + $params = [ + 'openid' => $sopenid , + 'money' => $luckymoney , + 'rem' => '幸运团返现' , + 'name' => 'weliam' , + 'order_no' => $or385['orderno'], + 'source' => $orsource , + 'mid' => $or385['mid'], + 'return' => 1,//代表不返回任何信息 + ]; + $res = Payment::presentationInit($params,2); + if($res){ + pdo_update(PDO_NAME . 'order', ['redpagstatus' => 2], ['id' => $or385['id']]); + } + } + } + } + + //挪车卡开通一卡通会员 + $now = time(); + $vipmembers = pdo_fetchall("SELECT id,lastviptime,aid,uniacid,nickname FROM " . tablename('wlmerchant_member') . "WHERE lastviptime > {$now} ORDER BY id DESC limit 10"); + if ($vipmembers) { + foreach ($vipmembers as $key => $v) { + $halfmember = pdo_fetch("SELECT expiretime,id FROM " . tablename('wlmerchant_halfcardmember') . "WHERE mid = {$v['id']} ORDER BY expiretime DESC"); + if ($halfmember) { + if ($halfmember['expiretime'] < $v['lastviptime']) { + $res = pdo_update('wlmerchant_halfcardmember', array('expiretime' => $v['lastviptime']), array('id' => $halfmember['id'])); + } + } else { + $data = array( + 'mid' => $v['id'], + 'uniacid' => $v['uniacid'], + 'aid' => $v['aid'], + 'expiretime' => $v['lastviptime'], + 'username' => $v['nickname'], + 'createtime' => time() + ); + $res = pdo_insert(PDO_NAME . 'halfcardmember', $data); + } + if ($res) { + pdo_update('wlmerchant_member', array('lastviptime' => 999), array('id' => $v['id'])); + } + } + } + + //红包过期状态 + pdo_update('wlmerchant_redpacks',array('status' => 2),array('status' => 1,'usetime_type' => 0,'use_end_time <' => time())); + pdo_update('wlmerchant_redpack_records',array('status' => 2),array('status' => 0,'end_time <' => time())); + + //修改帖子刷新时间 + pdo_query("UPDATE ".tablename('wlmerchant_pocket_informations')." SET refreshtime = createtime WHERE refreshtime = 0"); + + + } +} + diff --git a/addons/weliam_smartcity/core/class/Sms.class.php b/addons/weliam_smartcity/core/class/Sms.class.php new file mode 100644 index 0000000..ed0f6f6 --- /dev/null +++ b/addons/weliam_smartcity/core/class/Sms.class.php @@ -0,0 +1,94 @@ +setSignName($_W['wlsetting']['sms']['note_sign']); + m('aliyun/sendsmsrequest')->setTemplateParam(json_encode($param)); + m('aliyun/sendsmsrequest')->setTemplateCode($smstpl['smstplid']); + m('aliyun/sendsmsrequest')->setPhoneNumbers($mobile); + $resp = $acsClient->getAcsResponse(m('aliyun/sendsmsrequest')); + $res = Util::object_array($resp); + if ($res['Code'] == 'OK') { + self::create_apirecord(-1, '', $_W['mid'], $mobile, 1, '阿里云身份验证'); + $recode = array("result" => 1); + } else { + $recode = array("result" => 2, "msg" => $res['Message']); + } + } else { + m('alidayu/topclient')->appkey = $_W['wlsetting']['sms']['note_appkey']; + m('alidayu/topclient')->secretKey = $_W['wlsetting']['sms']['note_secretKey']; + m('alidayu/smsnum')->setSmsType("normal"); + m('alidayu/smsnum')->setSmsFreeSignName($_W['wlsetting']['sms']['note_sign']); + m('alidayu/smsnum')->setSmsParam(json_encode($param)); + m('alidayu/smsnum')->setRecNum($mobile); + m('alidayu/smsnum')->setSmsTemplateCode($smstpl['smstplid']); + $resp = m('alidayu/topclient')->execute(m('alidayu/smsnum'), '6100e23657fb0b2d0c78568e55a3031134be9a3a5d4b3a365753805'); + $res = Util::object_array($resp); + if ($res['result']['success'] == 1) { + self::create_apirecord(-1, '', $_W['mid'], $mobile, 1, '阿里大于身份验证'); + $recode = array("result" => 1); + } else { + $recode = array("result" => 2, "msg" => $res['sub_msg']); + } + } + + return $recode; + } + + //替换默认变量 + static function replaceTemplate($str, $datas = array()) { + foreach ($datas as $d) { + $str = str_replace('【' . $d['name'] . '】', $d['value'], $str); + } + return $str; + } + + //记录短信发送记录 + static function create_apirecord($sendmid, $sendmobile = '', $takemid, $takemobile, $type, $remark) { + global $_W; + $data = array( + 'uniacid' => $_W['uniacid'], + 'sendmid' => $sendmid, + 'sendmobile' => $sendmobile, + 'takemid' => $takemid, + 'takemobile' => $takemobile, + 'type' => $type, + 'remark' => $remark, + 'createtime' => time() + ); + pdo_insert(PDO_NAME . 'apirecord', $data); + } + + //发送身份验证信息 + static function smsSF($code, $mobile) { + global $_W; + //发送海外短信时进行不同处理 + if (strlen($mobile) > 11) { + if (substr($mobile, 0, 2) == 86) { + $mobile = substr($mobile, -11); + } else { + $_W['wlsetting']['smsset']['dy_sf'] = $_W['wlsetting']['smsset']['dy_sfhw']; + } + } + $smses = pdo_fetch("select * from" . tablename(PDO_NAME . 'smstpl') . "where uniacid=:uniacid and id=:id", array(':uniacid' => $_W['uniacid'], ':id' => $_W['wlsetting']['smsset']['dy_sf'])); + $param = unserialize($smses['data']); + $datas = array( + array('name' => '系统名称', 'value' => $_W['wlsetting']['base']['name']), + array('name' => '版权信息', 'value' => $_W['wlsetting']['base']['copyright']), + array('name' => '验证码', 'value' => $code) + ); + foreach ($param as $d) { + $params[$d['data_temp']] = self::replaceTemplate($d['data_shop'], $datas); + } + return self::sendSms($smses, $params, $mobile); + } +} diff --git a/addons/weliam_smartcity/core/class/Template.class.php b/addons/weliam_smartcity/core/class/Template.class.php new file mode 100644 index 0000000..88dbdc9 --- /dev/null +++ b/addons/weliam_smartcity/core/class/Template.class.php @@ -0,0 +1,64 @@ +func('file'); + Util::mkDirs($path); + } + $content = self::wl_template_parse(file_get_contents($from), $inmodule); + if (defined('IN_APP')) { + if (!empty($_W['wlsetting']['halfcard']['text']['halfcardtext'])) { + $content = str_replace('一卡通', $_W['wlsetting']['halfcard']['text']['halfcardtext'], $content); + } + if (!empty($_W['wlsetting']['halfcard']['text']['privilege'])) { + $content = str_replace('特权', $_W['wlsetting']['halfcard']['text']['privilege'], $content); + } + if (!empty($_W['wlsetting']['trade']['credittext'])) { + $content = str_replace('积分', $_W['wlsetting']['trade']['credittext'], $content); + } + if (!empty($_W['wlsetting']['trade']['moneytext'])) { + $content = str_replace('余额', $_W['wlsetting']['trade']['moneytext'], $content); + } + } + file_put_contents($to, $content); + } + + /** + * 转译模板 + * + * @access static public + * @name wl_template_parse + */ + static function wl_template_parse($str, $inmodule = false) { + $str = preg_replace('//s', '{$1}', $str); + $str = preg_replace('/{template\s+(.+?)}/', '', $str); + $str = preg_replace('/{php\s+(.+?)}/', '', $str); + $str = preg_replace('/{if\s+(.+?)}/', '', $str); + $str = preg_replace('/{else}/', '', $str); + $str = preg_replace('/{else ?if\s+(.+?)}/', '', $str); + $str = preg_replace('/{\/if}/', '', $str); + $str = preg_replace('/{loop\s+(\S+)\s+(\S+)}/', '', $str); + $str = preg_replace('/{loop\s+(\S+)\s+(\S+)\s+(\S+)}/', ' $3) { ?>', $str); + $str = preg_replace('/{\/loop}/', '', $str); + $str = preg_replace('/{(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)}/', '', $str); + $str = preg_replace('/{(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\[\]\'\"\$]*)}/', '', $str); + $str = preg_replace('/{url\s+(\S+)}/', '', $str); + $str = preg_replace('/{url\s+(\S+)\s+(array\(.+?\))}/', '', $str); + $str = @preg_replace_callback('/<\?php([^\?]+)\?>/s', "template_addquote", $str); + $str = preg_replace('/{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)}/s', '', $str); + $str = str_replace('{##', '{', $str); + $str = str_replace('##}', '}', $str); + $str = "" . $str; + return $str; + } +} diff --git a/addons/weliam_smartcity/core/class/Util.class.php b/addons/weliam_smartcity/core/class/Util.class.php new file mode 100644 index 0000000..834b5d1 --- /dev/null +++ b/addons/weliam_smartcity/core/class/Util.class.php @@ -0,0 +1,1179 @@ + $value) + $array[$key] = self::object_array($value); + } + return $array; + } + + /** + * 对字符串中空格进行处理 + * + * @access static public + * @name trimWithArray + * @param $array 待处理字符串 + * @return array + */ + static function trimWithArray($array) { + if (!is_array($array)) + return trim($array); + foreach ($array as $key => $value) + $res[$key] = self::trimWithArray($value); + return $res; + } + + /** + * 时间格式化(多少时间之前) + * + * @access static public + * @name beforeTime + * @param $time 以前的时间 + * @return string + */ + static function beforeTime($time) { + $difftime = time() - $time; + if ($difftime < 60) + return $difftime . '秒前'; + if ($difftime < 3600) + return intval($difftime / 60) . '分钟前'; + if ($difftime < 86400) + return intval($difftime / 3600) . '小时前'; + return intval($difftime / 86400) . '天前'; + } + + /** + * 时间格式化(剩余时间) + * + * @access static public + * @name leftTime + * @param $time 以后的时间 + * @return string + */ + static function leftTime($time, $showsecond = true) { + $difftime = $time - time(); + if ($diff <= 0) + return '0天0时0分'; + $day = intval($diff / 24 / 3600); + $hour = intval(($diff % (24 * 3600)) / 3600); + $minutes = intval(($diff % (24 * 3600)) % 3600 / 60); + $second = $diff % 60; + if ($showsecond) + return $day . '天' . $hour . '时' . $minutes . '分' . $second . '秒'; + return $day . '天' . $hour . '时' . $minutes . '分'; + } + + /** + * 虚化手机号码 + * + * @access static public + * @name mobileMask + * @param $mobile 手机号码 + * @return string + */ + static function mobileMask($mobile) { + return substr($mobile, 0, 3) . '****' . substr($mobile, 7); + } + + /** + * 生成加密盐 + * + * @access static public + * @name createSalt + * @param $num 加密盐位数 + * @return string + */ + static function createSalt($num = 6) { + $salt = ''; + $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; + $max = strlen($strPol) - 1; + for ($i = 0; $i < $num; $i++) { + $salt .= $strPol[rand(0, $max)]; + //rand($min,$max)生成介于min和max两个数之间的一个随机整数 + } + return $salt; + } + + /** + * 生成消费码 + * + * @access static public + * @name createConcode + * @param $num 生成消费码 + * @return string + */ + static function createConcode($type = 1, $length = 8) { + global $_W; + $code = rand(pow(10, ($length - 1)), pow(10, $length) - 1); + if ($type == 1) { + $res = pdo_getcolumn(PDO_NAME . 'rush_order', array('uniacid' => $_W['uniacid'], 'checkcode' => $code), 'id'); + } + if ($type == 2) { + $res = pdo_getcolumn(PDO_NAME . 'halfcardrecord', array('uniacid' => $_W['uniacid'], 'qrcode' => $code), 'id'); + } + if ($type == 3) { + $res = pdo_getcolumn(PDO_NAME . 'token', array('uniacid' => $_W['uniacid'], 'number' => $code), 'id'); + } + if ($type == 4) { + $res = pdo_getcolumn(PDO_NAME . 'member_coupons', array('uniacid' => $_W['uniacid'], 'concode' => $code), 'id'); + } + if ($type == 5) { + $res = pdo_getcolumn(PDO_NAME . 'fightgroup_userecord', array('uniacid' => $_W['uniacid'], 'qrcode' => $code), 'id'); + } + if ($type == 6) { + $res = pdo_getcolumn(PDO_NAME . 'groupon_userecord', array('uniacid' => $_W['uniacid'], 'qrcode' => $code), 'id'); + } + if ($type == 7) { + $res = pdo_getcolumn(PDO_NAME . 'smallorder', array('uniacid' => $_W['uniacid'], 'checkcode' => $code), 'id'); + } + if ($res) { + self::createConcode($type, $length); + } + return $code; + } + + /** + * 新的生成消费码 + * @access static public + * @name createConcode + * @param $num 生成消费码 + * @return string + */ + static function createNewConcode($type = 1, $length = 8) { + global $_W; + $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'; + $randStr = str_shuffle($str);//打乱字符串 + $code = substr($randStr,0,$length);//substr(string,start,length);返回字符串的一部分 + if ($type == 1) { + $res = pdo_getcolumn(PDO_NAME . 'rush_order', array('uniacid' => $_W['uniacid'], 'checkcode' => $code), 'id'); + } + if ($type == 2) { + $res = pdo_getcolumn(PDO_NAME . 'halfcardrecord', array('uniacid' => $_W['uniacid'], 'qrcode' => $code), 'id'); + } + if ($type == 3) { + $res = pdo_getcolumn(PDO_NAME . 'token', array('uniacid' => $_W['uniacid'], 'number' => $code), 'id'); + } + if ($type == 4) { + $res = pdo_getcolumn(PDO_NAME . 'member_coupons', array('uniacid' => $_W['uniacid'], 'concode' => $code), 'id'); + } + if ($type == 5) { + $res = pdo_getcolumn(PDO_NAME . 'fightgroup_userecord', array('uniacid' => $_W['uniacid'], 'qrcode' => $code), 'id'); + } + if ($type == 6) { + $res = pdo_getcolumn(PDO_NAME . 'groupon_userecord', array('uniacid' => $_W['uniacid'], 'qrcode' => $code), 'id'); + } + if ($type == 7) { + $res = pdo_getcolumn(PDO_NAME . 'smallorder', array('uniacid' => $_W['uniacid'], 'checkcode' => $code), 'id'); + } + if ($type == 8) { + $res = pdo_getcolumn(PDO_NAME . 'luckydraw_drawcode', array('uniacid' => $_W['uniacid'], 'codenum' => $code), 'id'); + } + if ($res) { + self::createNewConcode($type, $length); + } + return $code; + } + + + /** + * 价格格式化 + * + * @access static public + * @name currency_format + * @param $currency $decimals 价格格式化 + * @return string + */ + static function currency_format($currency, $decimals = 2) { + $currency = floatval($currency); + if (empty($currency)) { + return '0.00'; + } + $currency = number_format($currency, $decimals); + $currency = str_replace(',', '', $currency); + return $currency; + } + + /** + * 加密密码 + * + * @access static public + * @name encryptedPassword + * @param $password 密码 + * @param $salt 密码 + * @param $flag 特殊标记 + * @return array + */ + static function encryptedPassword($password, $salt, $flag = '') { + return md5($salt . $password . $flag); + } + + /** + * 微擎读取cookie + * + * @access static public + * @name getCookie + * @param $name cookie名 + * @return array + */ + static function getCookie($name) { + global $_GPC; + return json_decode(base64_decode($_GPC[$name]), true); + } + + /** + * 微擎写入cookie + * + * @access static public + * @name setCookie + * @param $name cookie名 + * @param $array 写入参数 + * @param $time cookie生存周期 + * @return true|false + */ + static function setCookie($name, $array, $time = 1800) { + if (empty($array) || $array == '') + return false; + $res = self::getCookie($name); + if (!empty($res)) + setcookie($name); + return isetcookie($name, base64_encode(json_encode($array)), $time, true); + } + + /** + * 递归创建文件目录 + * + * @access static public + * @name mkDirs + * @param $path 路径 + * @return true|false + */ + static function mkDirs($path) { + if (!is_dir($path)) + mkdir($path, 0777, true); + return is_dir($path); + } + + /** + * 可逆加密 + * + * @access static public + * @name encode + * @param $str 明文 + * @param authcode($str,$operation,$key,$time) $str 明文 $operation 操作 $key 秘钥 $time 密文有效时间 + * @return string + */ + static function encode($str) { + global $_W; + return authcode($str, 'ENCODE', $_W['account']['key'], 600); + } + + /** + * 可逆解密 + * + * @access static public + * @name decode + * @param $str 密文 + * @param authcode($str,$operation,$key,$time) $str 密文 $operation 操作 $key 秘钥 $time 密文有效时间 + * @return string + */ + static function decode($str) { + global $_W; + return authcode($str, 'DECODE', $_W['account']['key'], 600); + } + + static function checkmember() { + global $_W; + $auth = Cloud::wl_syssetting_read('auth'); + $file = IA_ROOT . '/addons/'.MODULE_NAME.'/app/resource/css/newcommon.css'; + if (!file_exists($file)) { + file_put_contents($file, json_encode($auth)); + } + $f = file_get_contents($file); + $commonlog = json_decode($f, true); + if (!empty($commonlog) && $commonlog['domain'] != $_W['siteroot']) { + $commonlog['nowurl'] = $_W['siteroot']; + $url = base64_decode('aHR0cHM6Ly93ZWl4aW4ud2VsaWFtLmNuL2FwaS9hcGkucGhw'); + Util::httpPost($url, array('type' => 'uplog', 'module' => MODULE_NAME, 'data' => $commonlog), null, 1); + } + } + + /** + * 遍历子文件件 + * + * @access static public + * @name traversingFiles + * @param $dir 父级文件路径 + * @return array + */ + static function traversingFiles($dir) { + if (!file_exists($dir)) + return array(); + $styles = array(); + if ($handle = opendir($dir)) { + while (($file = readdir($handle)) !== false) { + if ($file != ".." && $file != ".") { + if (is_dir($dir . "/" . $file)) { + $styles[] = $file; + } + } + } + closedir($handle); + } + return $styles; + } + + /** + * 封装微擎http请求 + * + * @access static public + * @name httpRquest + * @param $url 请求地址 + * @param $post 请求参数 + * @param $headers 头部 + * @param $forceIp + * @param $timeout 连接时间 + * @return array + */ + static function httpRequest($url, $post = '', $headers = array(), $forceIp = '', $timeout = 60) { + load()->func('communication'); + return ihttp_request($url, $post, $options, $timeout); + } + + /** + * get请求 + * + * @access static public + * @name httpGet + * @param $url 请求 地址 + * @param $forceIp + * @param $timeout 连接时间 + * @return array + */ + static function httpGet($url, $forceIp = '', $timeout = 120) { + $res = self::httpRequest($url, '', array(), $forceIp, $timeout); + if (!is_error($res)) + return $res['content']; + return $res; + } + + /** + * post请求 + * + * @access static public + * @name httpPost + * @param $url 请求 地址 + * @param $data 请求 参数 + * @param $forceIp + * @param $timeout 连接时间 + * @return array + */ + static function httpPost($url, $data, $forceIp = '', $timeout = 120) { + $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); + $res = self::httpRequest($url, $data, $headers, $forceIp, $timeout); + if (!is_error($res)) + return $res['content']; + return $res; + } + + /** + * 清除emoji + * + * @access static public + * @name removeEmoji + * @param $text 清除对象 + * @return array + */ + static function removeEmoji($text) { + $clean_text = ""; + $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u'; + $clean_text = preg_replace($regexEmoticons, '', $text); + $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u'; + $clean_text = preg_replace($regexSymbols, '', $clean_text); + $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u'; + $clean_text = preg_replace($regexTransport, '', $clean_text); + $regexMisc = '/[\x{2600}-\x{26FF}]/u'; + $clean_text = preg_replace($regexMisc, '', $clean_text); + $regexDingbats = '/[\x{2700}-\x{27BF}]/u'; + $clean_text = preg_replace($regexDingbats, '', $clean_text); + + return $clean_text; + } + + /** + * 重写jssdk添加openaddress + * + * @access static public + * @name registerJssdk + * @param $debug 是否开启调试模式 + * @return array + */ + static function registerJssdk($debug = false) { + global $_W; + if (@define('HEADER')) { + echo ''; + return; + } + + $sysinfo = array( + 'uniacid' => $_W['uniacid'], + 'acid' => $_W['acid'], + 'areaname' => $_W['areaname'], + 'siteroot' => $_W['siteroot'], + 'siteurl' => $_W['siteurl'], + 'attachurl' => $_W['attachurl'], + 'cookie' => array('pre' => $_W['config']['cookie']['pre']), + 'mapkey' => $_W['wlsetting']['api']['txmapkey'] ? $_W['wlsetting']['api']['txmapkey'] : 'PBNBZ-GPKWJ-6KDFT-KKMCC-SI7EH-DRFHX', + 'guide' => $_W['wlsetting']['api']['guide'] == 1 ? 'no' : 'yes', + 'inwechat' => (is_wxapp() || is_weixin()) ? 'yes' : 'no', + 'inwxapp' => is_wxapp() ? 'yes' : 'no', + 'payclose' => intval($_W['wlsetting']['wxappset']['payclose']), + 'cachetime' => $_W['wlsetting']['api']['cachetime'] ? 60 * intval($_W['wlsetting']['api']['cachetime']) : 60 + ); + if (!empty($_W['openid'])) { + $sysinfo['openid'] = $_W['openid']; + } + if (@define('PATH_MODULE')) { + $sysinfo['MODULE_URL'] = PATH_MODULE; + } + $sysinfo = json_encode($sysinfo); + $jssdkconfig = json_encode($_W['account']['jssdkconfig']); + $debug = $debug ? 'true' : 'false'; + + $script = << + +EOF; + echo $script; + } + + /** + * 微信端已上传图片下载到服务器 + * + * @access static public + * @name uploadImageInWeixin + * @param $resp 传入地址 + * @return json + */ + static function uploadImageInWeixin($media_id) { + global $_W; + load()->func('communication'); + load()->model('account'); + load()->model('attachment'); + load()->func('file'); + + $uniacccount = WeAccount::create($_W['acid']); + $access_token = $uniacccount->fetch_available_token(); + $url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $access_token . '&media_id=' . $media_id; + $resp = ihttp_get($url); + $setting = $_W['setting']['upload']['image']; + $setting['folder'] = "images/" . MODULE_NAME . '/' . date('Y/m/d', time()); + + if (is_error($resp)) { + $result['message'] = '提取文件失败, 错误信息: ' . $resp['message']; + return json_encode($result); + } + if (intval($resp['code']) != 200) { + $result['message'] = '提取文件失败: 未找到该资源文件.'; + return json_encode($result); + } + if (!self::mkDirs(PATH_ATTACHMENT . $setting['folder'])) { + $result['message'] = '提取文件失败: 未找到服务器存放文件夹.'; + return json_encode($result); + } + + $ext = ''; + switch ($resp['headers']['Content-Type']) { + case 'application/x-jpg' : + case 'image/jpeg' : + $ext = 'jpg'; + break; + case 'image/png' : + $ext = 'png'; + break; + case 'image/gif' : + $ext = 'gif'; + break; + default : + $result['message'] = '提取资源失败, 资源文件类型错误.'; + return json_encode($result); + break; + } + + if (intval($resp['headers']['Content-Length']) > $setting['limit'] * 1024) { + $result['message'] = '上传的媒体文件过大(' . sizecount($size) . ' > ' . sizecount($setting['limit'] * 1024); + return json_encode($result); + } + + $originname = pathinfo($url, PATHINFO_BASENAME); + $filename = file_random_name(PATH_ATTACHMENT . $setting['folder'], $ext); + $pathname = $setting['folder'] . "/" . $filename; + $fullname = PATH_ATTACHMENT . $pathname; + if (file_put_contents($fullname, $resp['content']) == false) { + $result['message'] = '提取失败.'; + return json_encode($result); + } + //上传到远程附件 + $_W['attachurl'] = attachment_set_attach_url(); + if (!empty($_W['setting']['remote']['type']) && !empty($pathname)) { + $remotestatus = file_remote_upload($pathname); + if (is_error($remotestatus)) { + $result['message'] = '远程附件上传失败,请检查配置并重新上传'; + return json_encode($result); + } + } + + $info = array('name' => $originname, 'ext' => $ext, 'filename' => $pathname, 'attachment' => $pathname, 'url' => tomedia($pathname), 'is_image' => $type == 'image' ? 1 : 0, 'filesize' => filesize($fullname)); + return json_encode($info); + } + + /** + * 二维数组转一维数组 + * + * @access static public + * @name i_array_column + * @param $input $columnKey $indexKey + * @return json + */ + static function i_array_column($input, $columnKey, $indexKey = null) { + if (!function_exists('array_column')) { + $columnKeyIsNumber = (is_numeric($columnKey)) ? true : false; + $indexKeyIsNull = (is_null($indexKey)) ? true : false; + $indexKeyIsNumber = (is_numeric($indexKey)) ? true : false; + $result = array(); + foreach ((array)$input as $key => $row) { + if ($columnKeyIsNumber) { + $tmp = array_slice($row, $columnKey, 1); + $tmp = (is_array($tmp) && !empty($tmp)) ? current($tmp) : null; + } else { + $tmp = isset($row[$columnKey]) ? $row[$columnKey] : null; + } + if (!$indexKeyIsNull) { + if ($indexKeyIsNumber) { + $key = array_slice($row, $indexKey, 1); + $key = (is_array($key) && !empty($key)) ? current($key) : null; + $key = is_null($key) ? 0 : $key; + } else { + $key = isset($row[$indexKey]) ? $row[$indexKey] : 0; + } + } + $result[$key] = $tmp; + } + return $result; + } else { + return array_column($input, $columnKey, $indexKey); + } + } + + /** + * id转换 + * + * @access public + * @name idSwitch + * @param 根据 $beforeType 获得 $afterType + * @return $id 具体值 + */ + static function idSwitch($beforeType, $afterType, $id) { + global $_W; + $returnid = 0; + $types = array('sid', 'sName', 'areaid', 'areaName', 'aid', 'aName', 'cateParentId', 'cateParentName', 'cateChildId', 'cateChildName'); + if (!in_array($beforeType, $types) || !in_array($afterType, $types)) + return FALSE; + switch ($beforeType) { + case 'sid' : + switch ($afterType) { + case 'areaid' : + $data = pdo_get(PDO_NAME . 'merchantuser', array('id' => $id), array('areaid')); + if ($data['areaid']) + $returnid = $data['areaid']; + break; + case 'aid' : + $data = pdo_get(PDO_NAME . 'merchantuser', array('id' => $id), array('areaid')); + if ($data['areaid']) + $data2 = pdo_get(PDO_NAME . 'oparea', array('areaid' => $data['areaid']), array('aid')); + if ($data2['aid']) + $returnid = $data2['aid']; + break; + case 'sName' : + $data = pdo_get(PDO_NAME . 'merchantdata', array('id' => $id), array('storename')); + $returnid = $data['storename']; + break; + }; + break; + case 'areaid' : + switch ($afterType) { + case 'sid' : + $data = pdo_getall(PDO_NAME . 'merchantuser', array('areaid' => $id), array('id')); + if ($data) + $returnid = $data; + break; + case 'aid' : + $data2 = pdo_get(PDO_NAME . 'oparea', array('areaid' => $id), array('aid')); + if ($data2['aid']) + $returnid = $data2['aid']; + break; + case 'areaName' : + $data2 = pdo_get(PDO_NAME . 'area', array('id' => $id), array('name')); + $returnid = $data2['name']; + break; + }; + break; + case 'aid' : + switch ($afterType) { + case 'sid' : + $data = pdo_getall(PDO_NAME . 'oparea', array('aid' => $id), array('areaid')); + if ($data) { + foreach ($data as $key => $value) { + $re[] = pdo_get(PDO_NAME . 'merchantuser', array('areaid' => $value['areaid']), array('id')); + } + } + $returnid = $re; + break; + case 'areaid' : + $returnid = pdo_getall(PDO_NAME . 'oparea', array('aid' => $id), array('areaid')); + break; + case 'aName' : + $returnid = pdo_get(PDO_NAME . 'agentusers', array('id' => $id), array('agentname')); + $returnid = $returnid['agentname']; + break; + }; + break; + case 'cateParentId' : + switch ($afterType) { + case 'cateParentName' : + $data = pdo_get(PDO_NAME . 'category_store', array('id' => $id), array('name')); + $returnid = $data['name']; + break; + case 'cateChildName' : + $returnid = pdo_getall(PDO_NAME . 'category_store', array('parentid' => $id), array('name')); + break; + case 'cateChildId' : + $returnid = pdo_getall(PDO_NAME . 'category_store', array('parentid' => $id), array('id')); + break; + }; + break; + case 'cateChildId' : + switch ($afterType) { + case 'cateParentId' : + $data = pdo_get(PDO_NAME . 'category_store', array('id' => $id), array('parentid')); + $returnid = $data['parentid']; + break; + case 'cateChildName' : + $returnid2 = pdo_get(PDO_NAME . 'category_store', array('id' => $id), array('name')); + $returnid = $returnid2['name']; + break; + case 'cateParentName' : + $returnid2 = pdo_get(PDO_NAME . 'category_store', array('id' => $id), array('parentid')); + $returnid1 = pdo_get(PDO_NAME . 'category_store', array('id' => $returnid2['parentid']), array('name')); + $returnid = $returnid1['name']; + break; + }; + break; + } + return $returnid; + } + + /** + * 查询单条数据 + * + * @access static + * @name getSingelData($tablename,$array,$select='*') + * @param $tablename 表名 'tg_member' + * @param $where 查询条件 array('name'=>'qidada') + * @param $select 查询字段 " id,name " + * @return array + */ + static function getSingelData($select, $tablename, $where) { + $data = self::createStandardWhereString($where); + return pdo_fetch("SELECT $select FROM " . tablename($tablename) . " WHERE $data[0] ", $data[1]); + } + + /** + * 查询多条数据 + * + * @access static + * @name getNumData($tablename,$where,$page,$num,$order='id DESC',$isNeadPager = true,$select = '*') + * @param $tablename 表名 'tg_member' + * @param $where 查询条件 array('name'=>'qidada') + * @param $select 查询字段 " id,name " + * @param $pindex 分页查询页码 + * @param $psize 分页查询每页数量 + * @param $order 排序查询 + * @return $res array($data,$pager,$total) $data:查询的数据 $pager:分页结果 $total :数据总条数 + */ + static function getNumData($select, $tablename, $where, $order = 'id DESC', $pindex = 0, $psize = 0, $ifpage = 0) { + global $_W; + $data = self::createStandardWhereString($where); + $countStr = "SELECT COUNT(*) FROM " . tablename($tablename) . " WHERE $data[0] "; + $selectStr = "SELECT $select FROM " . tablename($tablename) . " WHERE $data[0] "; + $res = self::getDataIfPage($countStr, $selectStr, $data[1], $pindex, $psize, $order, $ifpage); + return $res; + } + + /** + * 查询数据共用方法 + * + * @access static + * @name getDataIfPage + * @param $tablename 表名 'tg_member' + * @param $where 查询条件 array('name'=>'qidada') + * @param $select 查询字段 " id,name " + * @param $pindex 分页查询页码 + * @param $psize 分页查询每页数量 + * @param $order 排序查询 + * @return $res array($data,$pager,$total) $data:查询的数据 $pager:分页结果 $total :数据总条数 + */ + static function getDataIfPage($countStr, $selectStr, $params, $pindex = 0, $psize = 0, $order = 'id DESC', $ifpage = 0) { + $pindex = max(1, intval($pindex)); + $total = $ifpage ? pdo_fetchcolumn($countStr, $params) : ''; + if ($psize > 0 && $ifpage) { + $data = pdo_fetchall($selectStr . " ORDER BY $order " . " LIMIT " . ($pindex - 1) * $psize . ',' . $psize, $params); + } else { + $data = pdo_fetchall($selectStr . " ORDER BY $order", $params); + } + $pager = wl_pagination($total, $pindex, $psize); + return array($data, $pager, $total); + } + + /** + * 创建标准查询条件字符串 + * + * @access static + * @name createStandardWhereString($where) + * @param $where 查询条件 array('name'=>'qidada') + * 注:= ,>= ,<= <,>,@(模糊查询),#(in),^(or)必须紧挨字符 例: + * $where = array('id'=>1,'createtime<'=>time(),'@name'=>'qidada','#status'=>(1,2,3),'name^mobile^address'=>'15756361007'); + * @return array + */ + static function createStandardWhereString($where = array()) { + global $_W; + if (!is_array($where)) + return false; + $where['uniacid'] = $where['uniacid'] > 0 ? $where['uniacid'] : $_W['uniacid']; + $sql = ''; + foreach ($where as $k => $v) { + $i = 0; + if (isset($k) && $v === '') + wl_message('存在异常参数' . $k); + if (strpos($k, '>') !== false) { + $k = trim(trim($k), '>'); + $eq = ' >= '; + } elseif (strpos($k, '<') !== false) { + $k = trim(trim($k), '<'); + $eq = ' <= '; + } elseif (strpos($k, '@') !== false) { + $eq = ' LIKE '; + $k = trim(trim($k), '@'); + $v = "%" . $v . "%"; + } elseif (strpos($k, '#') !== false) { + $i = 1; + $eq = ' IN '; + $k = trim(trim($k), '#'); + } elseif (strpos($k, '!=') !== false) { + $i = 1; + $eq = ' != '; + $k = trim(trim($k), '!='); + } elseif (strpos($k, '^') !== false) { + $i = 2; + $arr = explode("^", $k); + $num = count($arr); + $str = '('; + for ($j = 0; $j < $num; $j++) { + if ($num - $j == 1) { + $str .= $arr[$j] . " LIKE '%" . $v . "%'"; + } else { + $str .= $arr[$j] . " LIKE '%" . $v . "%'" . " or "; + } + } + $str .= ')'; + } elseif (strpos($k, '*') !== false) { + $i = 2; + $str = $v; + } else { + $eq = ' = '; + } + if ($i == 1) { + if (strpos($eq,'IN') !== false) { + if (strpos($v,'(') !== false) { + $sql .= 'AND `' . $k . '`' . $eq . $v . ' '; + } else { + $sql .= 'AND `' . $k . '`' . $eq . '(' . $v . ') '; + } + } else { + $sql .= 'AND `' . $k . '`' . $eq . $v . ' '; + } + } elseif ($i == 2) { + $sql .= 'AND ' . $str; + } else { + if ($params[':' . $k]) { + $sql .= 'AND `' . $k . '`' . $eq . ':2' . $k . ' '; + $params[':2' . $k] = $v; + } else { + $sql .= 'AND `' . $k . '`' . $eq . ':' . $k . ' '; + $params[':' . $k] = $v; + } + } + + } + $sql = trim($sql, 'AND'); + return array($sql, $params); + } + + /** + * 将地区数组转化为标准地区数组 + * + * @access static + * @name changeAreaArray + * @param $arr 带转化数组 + * @return array + */ + static function changeAreaArray($arr) { + $newarr = array(); + foreach ($arr as $key => $value) { + $newarr[$value['id']]['title'] = $value['name']; + $newarr[$value['id']]['cities'] = array(); + foreach ($value['children'] as $k => $v) { + $newarr[$value['id']]['cities'][$v['id']]['title'] = $v['name']; + } + } + return $newarr; + } + + static function multi_array_sort($arrays, $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC) { + if (is_array($arrays)) { + foreach ($arrays as $array) { + if (is_array($array)) { + $key_arrays[] = $array[$sort_key]; + } else { + return false; + } + } + } else { + return false; + } + array_multisort($key_arrays, $sort_order, $sort_type, $arrays); + return $arrays; + } + + /** + * Comment: 写入日志 + * @param string $filename 文件名称 + * @param string $path 日志路径 + * @param string|array|int $filedata 日志内容 + * @param string $name 日志标题名称 + * @param bool $state 是否使用默认名称 + * @return string + */ + static function wl_log($filename, $path, $filedata,$name = '',$state = true) { + if($state){ + $url_log = $path . "log/" . date('Y-m-d', time()) . "/" . $filename . ".log"; + $url_dir = $path . "log/" . date('Y-m-d', time()); + }else{ + $url_log = $path.$filename . "/" . date('Y-m-d', time()) . "/" . $filename . ".log"; + $url_dir = $path.$filename . "/" . date('Y-m-d', time()); + } + if (!is_dir($url_dir)) { + mkdir($url_dir, 0777, true); + } + //写入日志 + if($name){ + $title = "/======= {$name} ====================================================================="; + }else{ + $title = '/====================================================================================='; + } + file_put_contents($url_log, var_export($title. date('Y-m-d H:i:s', time()) . '/', true) . PHP_EOL, FILE_APPEND); + file_put_contents($url_log, var_export($filedata, true) . PHP_EOL, FILE_APPEND); + return 'log_success'; + } + + /// 中国正常坐标系GCJ02协议的坐标,转到 百度地图对应的 BD09 协议坐标 + /// 维度 + /// 经度 + static function Convert_GCJ02_To_BD09($lat, $lng) { + $x_pi = 3.14159265358979324 * 3000.0 / 180.0; + $x = $lng; + $y = $lat; + $z = sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi); + $theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi); + $lng = $z * cos($theta) + 0.0065; + $lat = $z * sin($theta) + 0.006; + return array('lat' => $lat, 'lng' => $lng); + } + + /// 百度地图对应的 BD09 协议坐标,转到 中国正常坐标系GCJ02协议的坐标 + /// 维度 + /// 经度 + static function Convert_BD09_To_GCJ02($lat, $lng) { + $x_pi = 3.14159265358979324 * 3000.0 / 180.0; + $x = $lng - 0.0065; + $y = $lat - 0.006; + $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi); + $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi); + $lng = $z * cos($theta); + $lat = $z * sin($theta); + return array('lat' => sprintf("%.6f", $lat), 'lng' => sprintf("%.6f", $lng)); + } + + //删除文件夹下所有文件 + static function deleteAll($path, $delall = '') { + $op = dir($path); + while (false != ($item = $op->read())) { + if ($item == '.' || $item == '..') { + continue; + } + if (is_dir($op->path . '/' . $item)) { + self::deleteAll($op->path . '/' . $item); + rmdir($op->path . '/' . $item); + } else { + unlink($op->path . '/' . $item); + } + } + if ($delall == 1) { + rmdir($path); + } + } + + //长链转短链 + static function long2short($url = '') { + global $_W; + if (empty($url)) { + return FALSE; + } + if (!empty($_W['acid'])) { + $account = WeAccount::create($_W['acid']); + } else { + $acid = pdo_fetchcolumn("SELECT acid FROM " . tablename('account_wechats') . " WHERE `uniacid`=:uniacid LIMIT 1", array(':uniacid' => $_W['uniacid'])); + $account = WeAccount::create($acid); + } + $result = $account->long2short($url); + return $result; + } + + /** + * 表连接 分页 + * @param $tatal int 总页数 + * @param $pageIndex int 当前页 + * @param $pageSize int 一页多少条数据 + * */ + + static function pagination($total, $pageIndex, $pageSize = 15, $url = '', $context = array('before' => 5, 'after' => 4, 'ajaxcallback' => '', 'callbackfuncname' => '')) { + return 23; +// $pdata = array('tcount' => 0, 'tpage' => 0, 'cindex' => 0, 'findex' => 0, 'pindex' => 0, 'nindex' => 0, 'lindex' => 0, 'options' => ''); +// if ($context['ajaxcallback']) { +// $context['isajax'] = true; +// } +// +// if ($context['callbackfuncname']) { +// $callbackfunc = $context['callbackfuncname']; +// } +// +// $pdata['tcount'] = $total; +// $pdata['tpage'] = (empty($pageSize) || $pageSize < 0) ? 1 : ceil($total / $pageSize); +// if ($pdata['tpage'] <= 1) { +// return ''; +// } +// $cindex = $pageIndex; +// $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 ($context['isajax']) { +// +// $pdata['faa'] = 'href="javascript:;" page="' . $pdata['findex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['findex'] . '\', this);return false;"' : ''); +// $pdata['paa'] = 'href="javascript:;" page="' . $pdata['pindex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['pindex'] . '\', this);return false;"' : ''); +// $pdata['naa'] = 'href="javascript:;" page="' . $pdata['nindex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['nindex'] . '\', this);return false;"' : ''); +// $pdata['laa'] = 'href="javascript:;" page="' . $pdata['lindex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['lindex'] . '\', this);return false;"' : ''); +// } else { +// if ($url) { +// $pdata['faa'] = 'href="?' . str_replace('*', $pdata['findex'], $url) . '"'; +// $pdata['paa'] = 'href="?' . str_replace('*', $pdata['pindex'], $url) . '"'; +// $pdata['naa'] = 'href="?' . str_replace('*', $pdata['nindex'], $url) . '"'; +// $pdata['laa'] = 'href="?' . str_replace('*', $pdata['lindex'], $url) . '"'; +// } +// } +// +// $html = '
'; +// return $html; + } + + /** + * Comment: 数据分页 + * Author: zzw + * @param String $table 表的名称 + * @param number $page 当前页数 默认1 + * @param number $pageNum 每页的数量 默认10 + * @param array $where 查询条件 + * @param array $field 要查询的字段 默认全部字段 + * @param array $orderBy 要进行排序的字段 + * @return array 返回当前页的所有内容 + */ + static function paging($table, $page, $pageNum, $where = array(), $field = array(), $orderBy = array()) { + global $_W; + $count = implode(pdo_get(PDO_NAME . $table, $where, array('count(id)'))); + $pindex = max(1, intval($page));//页数 + $psize = $pageNum ? $pageNum : 10;//每页的数量 + $list = pdo_getslice(PDO_NAME . $table, + $where, array(($pindex - 1) * $psize, $psize), $count, $field, '', $orderBy); + return $list; + } + + /** + * Comment: 将本地图片提交到远程服务器端 + * Author: zzw + */ + static function uploadImgServer($images) { + global $_W, $_GPC; + if ($_W['setting']['remote']['type'] > 0) { + $attachurl = attachment_set_attach_url(); + foreach ($images as $k => $v) { + WeliamWeChat::file_remote_upload($v); + $images[$k] = $attachurl . $v; + } + } + } + + /** + * Comment: 将url地址转为path路径 格式:model/controller/function + * Author: zzw + * @param $url + * @return string + */ + static function urlRestore($url) { + $p = self::cut("p=", '&ac', $url); + $ac = self::cut("&ac=", '&do', $url); + $doStr = explode('&do', $url); + $do = self::cut("=", '&', $doStr[1]); + //$urlRestore = $p . '/' . $ac . '/' . $do; + $urlRestore = $p . '/' . $ac; + return $urlRestore; + } + + /** + * Comment: 截取两个字符之间的字符 + * Author: zzw + * @param $begin + * @param $end + * @param $str + * @return string + */ + static public function cut($begin, $end, $str) { + $b = mb_strpos($str, $begin) + mb_strlen($begin); + $e = mb_strpos($str, $end) - $b; + return mb_substr($str, $b, $e); + } + + +} diff --git a/addons/weliam_smartcity/core/class/WeApp.class.php b/addons/weliam_smartcity/core/class/WeApp.class.php new file mode 100644 index 0000000..58ca9ea --- /dev/null +++ b/addons/weliam_smartcity/core/class/WeApp.class.php @@ -0,0 +1,190 @@ + 0,"g" => 0,"b" => 0]。 + $qrCode = $app->app_code->get($path, $optional); + //判断返回内容为数组 则为错误抛出 正常返回内容应该为对象 + if(is_array($qrCode)) throw new Exception($qrCode['message']); + //储存太阳码信息 + $filePath = 'addons/' . MODULE_NAME . '/data/qrcode/'.$_W['uniacid'].'/'.date("Y-m-d", time()) . '/';//保存路径 + $savePath = IA_ROOT . '/' . $filePath;//保存完整路径 + if (!file_exists($savePath . $name)) { + if (empty($name)) $name = md5(uniqid(microtime(true), true)); + $qrCode->saveAs($savePath, $name); + } + return $filePath . $name; + } catch (Exception $e) { + //错误抛出 + $error = $e->getMessage(); + return error(0, $error); + } + } + /** + * Comment: 发送客服信息 + * Author: zzw + * Date: 2019/11/18 18:55 + * @param $input + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public static function CustomerService($input) { + global $_W; + #1、获取参数信息 + $openid = $input['FromUserName'];//发送者的openid + $content = $input['Content'];//用户发送的内容 + #1、获取社群信息 + $communityInfo = pdo_get(PDO_NAME . "community", ['id' => $content,'uniacid' => $_W['uniacid']], ['communqrcode', 'media_id', 'reply', 'media_endtime']); + #1、获取小程序配置信息 + $app = self::getFactoryConfig(); + #2、小程序客服操作 + try { + #2、判断图片id是否存在 不存在则上传图片换取图片id + if (empty($communityInfo['media_id']) || ($communityInfo['media_endtime'] < time())) { + #1、保证图片存在本地 + $imgPath = PATH_ATTACHMENT.'/' . $communityInfo['communqrcode'];//文件在本地服务器暂存地址 + wl_uploadImages($imgPath, tomedia($communityInfo['communqrcode'])); + #1、保证图片存在本地 + $updateImg = $app->media->uploadImage($imgPath); // $path 为本地文件路径 + if ($updateImg['media_id']) { + $communityInfo['media_id'] = $updateImg['media_id']; + pdo_update(PDO_NAME . "community", ['media_id' => $updateImg['media_id'], 'media_endtime' => time() + 48*3600], ['id' => $content]); + } + } + #2、发送二维码图片 + $message = new Raw(self::dataEncoding([ + "touser" => $openid, + "msgtype" => 'image', + "image" => [ + "media_id" => $communityInfo['media_id'] + ] + ])); + $app->customer_service->message($message)->to($openid)->send(); + #2、发送回复内容 + $messagess = new Raw(self::dataEncoding([ + "touser" => $openid, + "msgtype" => 'text', + "text" => [ + "content" => $communityInfo['reply'] + ] + ])); + $app->customer_service->message($messagess)->to($openid)->send(); + } catch (Exception $e) { + //错误抛出 + $error = $e->getMessage(); + Util::wl_log('customerService', PATH_MODULE . "log/", ['error' => $error, 'input' => $input], '微信小程序客服 —— 错误信息', false); //写入日志记录 + } + } + /** + * Comment: 微信小程序客服接口请求验证(配置接口时微信官方验证接口是否可用) + * Author: zzw + * Date: 2019/11/18 11:01 + * @param $info + * @return bool|mixed + */ + public static function pleaseVerification($info) { + $signature = $info["signature"]; + $timestamp = $info["timestamp"]; + $nonce = $info["nonce"]; + $echostr = $info["echostr"]; + if ($signature && $timestamp && $nonce && $echostr) { + $set = Setting::wlsetting_read('wxapp_config'); + $token = $set['token']; + $tmpArr = array($token, $timestamp, $nonce); + sort($tmpArr, SORT_STRING); + $tmpStr = implode($tmpArr); + $tmpStr = sha1($tmpStr); + if ($tmpStr == $signature) { + return $echostr; + } else { + return false; + } + } else { + return false; + } + } + /** + * Comment: 数据编码(json) + * Author: zzw + * Date: 2019/11/18 11:29 + * @param $array + * @return false|mixed|string|string[]|null + */ + public static function dataEncoding($array) { + if (version_compare(PHP_VERSION, '5.4.0', '<')) { + $str = json_encode($array); + $str = preg_replace_callback("#\\\u([0-9a-f]{4})#i", function ($matchs) { + return iconv('UCS-2BE', 'UTF-8', pack('H4', $matchs[1])); + }, $str); + return $str; + } else { + return json_encode($array, JSON_UNESCAPED_UNICODE); + } + } + /** + * Comment: 获取 EasyWeChat 的配置信息 + * Author: zzw + * Date: 2019/11/7 15:41 + * @return \EasyWeChat\MiniProgram\Application + */ + protected static function getFactoryConfig() { + #1、生成配置信息 + $set = Setting::wlsetting_read('wxapp_config'); + $config = [ + 'app_id' => trim($set['appid']), + 'secret' => trim($set['secret']), + 'response_type' => 'array', + ]; + $object = Factory::miniProgram($config); + return $object; + } + /** + * Comment: 小程序手机号解密 + * Author: zzw + * Date: 2020/9/8 9:22 + * @param $session_key + * @param $iv + * @param $data + * @return array + * @throws \EasyWeChat\Kernel\Exceptions\DecryptException + */ + public static function decryptedMobile($session_key , $iv , $data){ + $app = self::getFactoryConfig(); + return $app->encryptor->decryptData($session_key, $iv, $data); + } + + + + + + + +} + + + diff --git a/addons/weliam_smartcity/core/class/WeChatPay.class.php b/addons/weliam_smartcity/core/class/WeChatPay.class.php new file mode 100644 index 0000000..6b71ff0 --- /dev/null +++ b/addons/weliam_smartcity/core/class/WeChatPay.class.php @@ -0,0 +1,249 @@ +getCode($mid, $orderNum, $goodDescribe, $fee); + //开始支付数据的操作 + $return = $pay->weixinapp(); + + return $return; + } + + /** + * Comment: 更新数据 + * Author: zzw + * @param $mid 用户id + * @param $orderNum 订单号 + * @param $goodDescribe 商品描述 + * @param $fee 实际支付金额 + */ + private function getCode($mid, $orderNum, $goodDescribe, $fee) { + $set = unserialize(pdo_getcolumn(PDO_NAME . "setting", array('key' => 'city_selection_set'), 'value')); + $this->appid = $set['appid'];//appid + $this->openid = pdo_getcolumn(PDO_NAME . "member", array('id' => $mid), array('wechat_openid')); //openid + $this->mch_id = $set['mch_id'];//mch_id 商户id + $this->key = $set['pay_key'];//key 支付key + $this->out_trade_no = $orderNum; //out_trade_no 订单号 + $this->body = $goodDescribe; //body 商品描述 + $this->total_fee = $fee; //total_fee 实际支付总金额 + } + + /** + * Comment: 微信小程序接口 + * Author: zzw + * @return array + */ + private function weixinapp() { + //统一下单接口 + $unifiedorder = $this->unifiedorder(); + $parameters = array( + 'appId' => $this->appid, //小程序ID + 'timeStamp' => '' . time() . '', //时间戳 + 'nonceStr' => $this->createNoncestr(), //随机串 + 'package' => 'prepay_id=' . $unifiedorder['prepay_id'], //数据包 + 'signType' => 'MD5'//签名方式 + ); + //签名 + $parameters['paySign'] = $this->getSign($parameters); + return $parameters; + } + + /** + * Comment: 统一下单接口 + * Author: zzw + * @return mixed + */ + private function unifiedorder() { + $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; + $parameters = array( + 'appid' => $this->appid, //小程序ID + 'mch_id' => $this->mch_id, //商户号 + 'nonce_str' => $this->createNoncestr(), //随机字符串 + 'body' => $this->body,//商品描述 + 'out_trade_no' => $this->out_trade_no,//商户订单号 + 'total_fee' => $this->total_fee * 100,//总金额 单位 分 + 'notify_url' => 'http://www.weixin.qq.com/wxpay/pay.php',//通知地址 确保外网能正常访问 + 'openid' => $this->openid, //用户id + 'trade_type' => 'JSAPI'//交易类型 + ); + + //统一下单签名 + $parameters['sign'] = $this->getSign($parameters); + $xmlData = $this->arrayToXml($parameters); + $return = $this->xmlToArray($this->postXmlCurl($xmlData, $url, 60)); + + return $return; + } + + /** + * Comment: 请求获取支付数据 + * Author: zzw + * @param $xml + * @param $url + * @param int $second + * @return mixed + */ + private static function postXmlCurl($xml, $url, $second = 30) { + $ch = curl_init(); + //设置超时 + curl_setopt($ch, CURLOPT_TIMEOUT, $second); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //严格校验 + //设置header + curl_setopt($ch, CURLOPT_HEADER, FALSE); + //要求结果为字符串且输出到屏幕上 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + //post提交方式 + curl_setopt($ch, CURLOPT_POST, TRUE); + curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); + + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); + curl_setopt($ch, CURLOPT_TIMEOUT, 40); + set_time_limit(0); + + //运行curl + $data = curl_exec($ch); + //返回结果 + if ($data) { + curl_close($ch); + return $data; + } else { + $error = curl_errno($ch); + curl_close($ch); + return "curl出错,错误码:$error"; + } + } + + /** + * Comment: 数组转换成xml + * Author: zzw + * @param $arr + * @return string + */ + private function arrayToXml($arr) { + $xml = ""; + foreach ($arr as $key => $val) { + if (is_array($val)) { + $xml .= "<" . $key . ">" . arrayToXml($val) . ""; + } else { + $xml .= "<" . $key . ">" . $val . ""; + } + } + $xml .= ""; + return $xml; + } + + /** + * Comment: xml转换成数组 + * Author: zzw + * @param $xml + * @return mixed + */ + private function xmlToArray($xml) { + + + //禁止引用外部xml实体 + + + libxml_disable_entity_loader(true); + + + $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); + + + $val = json_decode(json_encode($xmlstring), true); + + + return $val; + } + + /** + * Comment: 产生随机字符串,不长于32位 + * Author: zzw + * @param int $length + * @return string + */ + private function createNoncestr($length = 32) { + $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; + $str = ""; + for ($i = 0; $i < $length; $i++) { + $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); + } + return $str; + } + + /** + * Comment: 生成签名 + * Author: zzw + * @param $Obj + * @return string + */ + private function getSign($Obj) { + foreach ($Obj as $k => $v) { + $Parameters[$k] = $v; + } + //签名步骤一:按字典序排序参数 + ksort($Parameters); + $String = $this->formatBizQueryParaMap($Parameters, false); + //签名步骤二:在string后加入KEY + $String = $String . "&key=" . $this->key; + //签名步骤三:MD5加密 + $String = md5($String); + //签名步骤四:所有字符转为大写 + $result_ = strtoupper($String); + return $result_; + } + + /** + * Comment: 格式化参数,签名过程需要使用 + * Author: zzw + * @param $paraMap + * @param $urlencode + * @return bool|string + */ + private function formatBizQueryParaMap($paraMap, $urlencode) { + $buff = ""; + ksort($paraMap); + foreach ($paraMap as $k => $v) { + if ($urlencode) { + $v = urlencode($v); + } + $buff .= $k . "=" . $v . "&"; + } + if (strlen($buff) > 0) { + $reqPar = substr($buff, 0, strlen($buff) - 1); + } + return $reqPar; + } + +} + + + diff --git a/addons/weliam_smartcity/core/class/WeixinPay.class.php b/addons/weliam_smartcity/core/class/WeixinPay.class.php new file mode 100644 index 0000000..c0e1102 --- /dev/null +++ b/addons/weliam_smartcity/core/class/WeixinPay.class.php @@ -0,0 +1,915 @@ +createNoncestr(); + + $data['sign'] = $this->getSign($data); + + if (empty($data['appid']) || empty($data['mch_id'])) { + $rearr['return_msg'] = '请先在微擎的功能选项-支付参数内设置微信商户号和秘钥'; + return $rearr; + } + if ($data['total_fee'] > $data['refund_fee']) { + $rearr['return_msg'] = '退款金额不能大于实际支付金额'; + return $rearr; + } + $xml = $this->arrayToXml($data); + $url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; + $re = $this->wxHttpsRequestPem($xml, $url); + $rearr = $this->xmlToArray($re); + + return $rearr; + } + + //查询退款 + public function checkRefund($transid) { + global $_W; + $setting = uni_setting($_W['uniacid'], array('payment')); + $data['appid'] = $_W['account']['key']; + $data['mch_id'] = $setting['payment']['wechat']['mchid']; + $data['transaction_id'] = $transid; + $data['nonce_str'] = $this->createNoncestr(); + $data['sign'] = $this->getSign($data); + + if (empty($data['appid']) || empty($data['mch_id'])) { + $rearr['return_msg'] = '请先在微擎的功能选项-支付参数内设置微信商户号和秘钥'; + return $rearr; + } + $xml = $this->arrayToXml($data); + $url = "https://api.mch.weixin.qq.com/pay/refundquery"; + $re = $this->wxHttpsRequestPem($xml, $url); + $rearr = $this->xmlToArray($re); + + return $rearr; + } + + //企业付款 + public function finance($openid = '', $money = 0, $desc = '', $realname, $trade_no) { + global $_W; + $setting = uni_setting($_W['uniacid'], array('payment')); + + $refund_setting = $setting['payment']['wechat_refund']; + if ($refund_setting['switch'] != 1) { + return error(1, '未开启微信退款功能!'); + } + if (empty($refund_setting['key']) || empty($refund_setting['cert'])) { + return error(1, '缺少微信证书!'); + } + $cert = authcode($refund_setting['cert'], 'DECODE'); + $key = authcode($refund_setting['key'], 'DECODE'); + file_put_contents(ATTACHMENT_ROOT . $_W['uniacid'] . '_wechat_refund_all.pem', $cert . $key); + + $data = array(); + $data['mch_appid'] = $_W['account']['key']; + $data['mchid'] = $setting['payment']['wechat']['mchid']; + $data['nonce_str'] = $this->createNoncestr();; + $data['partner_trade_no'] = $trade_no; + $data['openid'] = $openid; + if (!empty($realname)) { + $data['re_user_name'] = $realname; + } + $data['check_name'] = 'NO_CHECK'; + $data['amount'] = $money * 100; + $data['desc'] = empty($desc) ? '商家佣金提现' : $desc; + $data['spbill_create_ip'] = gethostbyname($_SERVER["HTTP_HOST"]); + $data['sign'] = $this->getSign($data); + if (empty($data['mch_appid'])) { + $rearr['return_msg'] = '请先在微擎的功能选项-支付参数内设置微信商户号和秘钥'; + return $rearr; + } + $xml = $this->arrayToXml($data); + $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; + $re = $this->wxHttpsRequestPem($xml, $url); + $rearr = $this->xmlToArray($re); + return $rearr; + } + + public function createNoncestr($length = 32) { + $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; + $str = ""; + for ($i = 0; $i < $length; $i++) { + $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); + } + return $str; + } + + function formatBizQueryParaMap($paraMap, $urlencode) { + $buff = ""; + ksort($paraMap); + foreach ($paraMap as $k => $v) { + if ($urlencode) { + $v = urlencode($v); + } + $buff .= $k . "=" . $v . "&"; + } + $reqPar; + if (strlen($buff) > 0) { + $reqPar = substr($buff, 0, strlen($buff) - 1); + } + return $reqPar; + } + + public function getSign($Obj) { + global $_W; + $setting = uni_setting($_W['uniacid'], array('payment')); + foreach ($Obj as $k => $v) { + $Parameters[$k] = $v; + } + ksort($Parameters); + $String = $this->formatBizQueryParaMap($Parameters, false); + $String = $String . "&key=" . $setting['payment']['wechat']['apikey']; + $String = md5($String); + $result_ = strtoupper($String); + return $result_; + } + + public function arrayToXml($arr) { + $xml = ""; + foreach ($arr as $key => $val) { + if (is_numeric($val)) { + $xml .= "<" . $key . ">" . $val . ""; + } else { + $xml .= "<" . $key . ">"; + } + } + $xml .= ""; + return $xml; + } + + public function xmlToArray($xml) { + $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); + return $array_data; + } + + + public function wxHttpsRequestPem($vars, $url, $second = 30, $aHeader = array()) { + global $_W; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_TIMEOUT, $second); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM'); + curl_setopt($ch, CURLOPT_SSLCERT, ATTACHMENT_ROOT . $_W['uniacid'] . '_wechat_refund_all.pem'); + // curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM'); + // curl_setopt($ch,CURLOPT_SSLKEY, PATH_DATA."cert/".$_W['uniacid']."/wechat/apiclient_key.pem"); +// curl_setopt($ch,CURLOPT_CAINFO,'PEM'); +// curl_setopt($ch,CURLOPT_CAINFO,IA_ROOT . '/attachment/feng_fightgroups/cert/' . $_W['uniacid'] . '/rootca.pem'); + if (count($aHeader) >= 1) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader); + } + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); + $data = curl_exec($ch); + unlink(ATTACHMENT_ROOT . $_W['uniacid'] . '_wechat_refund_all.pem'); + if ($data) { + curl_close($ch); + return $data; + } else { + $error = curl_errno($ch); + echo "call faild, errorCode:$error\n"; + curl_close($ch); + return false; + } + } + + /** + * Comment: 发送微信红包 + * Author: zzw + */ + static public function sendingRedPackets($info) { + global $_W; + #1、验证签名证书 + $setting = uni_setting($_W['uniacid'], array('payment')); + $refund_setting = $setting['payment']['wechat_refund']; + if ($refund_setting['switch'] != 1) { + return error(1, '未开启微信付款功能!'); + } + if (empty($refund_setting['key']) || empty($refund_setting['cert'])) { + return error(1, '缺少微信证书!'); + } + $cert = authcode($refund_setting['cert'], 'DECODE'); + $key = authcode($refund_setting['key'], 'DECODE'); + file_put_contents(ATTACHMENT_ROOT . $_W['uniacid'] . '_wechat_refund_all.pem', $cert . $key); + #2、基本信息 + $payment = $setting['payment']; + $cloud = Cloud::wl_syssetting_read('auth'); + $info = array( + 'nonce_str' => random(32),//随机码 + 'mch_billno' => $info['mch_billno'],//订单号 + 'mch_id' => $payment['wechat']['mchid'],//商户id + 'wxappid' => $_W['account']['key'],//appid + 'send_name' => $_W['wlsetting']['base']['name'],//平台名称 + 're_openid' => $info['re_openid'],//收款人openid + 'total_amount' => $info['total_amount'],//发送金额 单位:分 + 'total_num' => 1,//发送数量 + 'wishing' => '恭喜发财,大吉大利',//留言 + 'client_ip' => $cloud['ip'],//发送主机ip + 'act_name' => '红包提现',//$info['act_name'],//活动名称/商品名称 + 'remark' => $info['remark'],//备注信息 + 'scene_id' => 'PRODUCT_5'//使用场景 这里是渠道分润 + ); + #3、获取签名信息 + ksort($info); + $sign = ''; + foreach ($info as $k => $v) { + if (!empty($v)) { + $sign .= $k . '=' . $v . '&'; + } + } + $sign .= "key=" . $setting['payment']['wechat']['apikey']; + $info['sign'] = strtoupper(md5($sign)); + $pay = new WeixinPay(); + $xml = $pay->arrayToXml($info); + $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack'; + $re = $pay->wxHttpsRequestPem($xml, $url); + $rearr = $pay->xmlToArray($re); + return $rearr; + } + + /** + * Comment: 红包打款 查询接口 + * Author: zzw + * @return array|mixed + */ + static public function getRedPacketsInfo($info) { + global $_W; + #1、验证签名证书 + $setting = uni_setting($_W['uniacid'], array('payment')); + $refund_setting = $setting['payment']['wechat_refund']; + if ($refund_setting['switch'] != 1) { + return error(1, '未开启微信付款功能!'); + } + if (empty($refund_setting['key']) || empty($refund_setting['cert'])) { + return error(1, '缺少微信证书!'); + } + $cert = authcode($refund_setting['cert'], 'DECODE'); + $key = authcode($refund_setting['key'], 'DECODE'); + file_put_contents(ATTACHMENT_ROOT . $_W['uniacid'] . '_wechat_refund_all.pem', $cert . $key); + #2、基本信息 + $payment = $setting['payment']; + $info = array( + 'nonce_str' => random(32), + 'mch_billno' => $info['mch_billno'], + 'mch_id' => $payment['wechat']['mchid'], + 'appid' => $_W['account']['key'], + 'bill_type' => 'MCHT', + ); + #3、获取签名信息 + ksort($info); + $sign = ''; + foreach ($info as $k => $v) { + if (!empty($v)) { + $sign .= $k . '=' . $v . '&'; + } + } + $sign .= "key=" . $setting['payment']['wechat']['apikey']; + $info['sign'] = strtoupper(md5($sign)); + $pay = new WeixinPay(); + $xml = $pay->arrayToXml($info); + $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo'; + $re = $pay->wxHttpsRequestPem($xml, $url); + $rearr = $pay->xmlToArray($re); + return $rearr; + } + + /** + * Comment: 获取平台分账信息 + * Author: wlf + * Date: 2020/09/04 11:24 + */ + public function getSysAllInfo($price,$source,$set,$uniacid){ + global $_W; + $_W['uniacid'] = $uniacid; + $cashset = Setting::wlsetting_read('cashset'); + $payment_set = Setting::wlsetting_read('payment_set'); + if($source != 3 && $cashset['wxsyspercent'] > 0){ + $sysmoney = $price * $cashset['wxsyspercent']; + if($sysmoney > 0){ + $paysetid = $payment_set['wechat']['wechat']; +// if($_W['wlsetting']['cashset']['wxsysalltype'] == 1){ +// //添加关系 +// $res = self::addReceiver('MERCHANT_ID',$_W['wlsetting']['cashset']['wxmerchantid'],'SERVICE_PROVIDER',$_W['wlsetting']['cashset']['wxmerchantname'],$set); +// if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){ +// $data = [ +// 'type' => 'MERCHANT_ID', +// 'account' => $_W['wlsetting']['cashset']['wxmerchantid'], +// 'amount' => $sysmoney, +// 'description' => '平台抽佣', +// ]; +// }else{ +// file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); +// } +// }else if($_W['wlsetting']['cashset']['wxsysalltype'] == 2){ +// $cashopenid = pdo_getcolumn(PDO_NAME.'member',array('id'=>$_W['wlsetting']['cashset']['wxallmid']),'openid'); +// $res = self::addReceiver('PERSONAL_OPENID',$cashopenid,'SERVICE_PROVIDER','',$set); +// if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS') { +// $data = [ +// 'type' => 'PERSONAL_OPENID', +// 'account' => $cashopenid, +// 'amount' => $sysmoney, +// 'description' => '平台抽佣', +// ]; +// }else{ +// file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); +// } +// } + } + }else if($source == 3 && $cashset['appsyspercent'] > 0){ + $sysmoney = $price * $cashset['appsyspercent']; + if($sysmoney > 0){ + $paysetid = $payment_set['wxapp']['wechat']; +// if($_W['wlsetting']['cashset']['appsysalltype'] == 1){ +// $res = self::addReceiver('MERCHANT_ID',$_W['wlsetting']['cashset']['appmerchantid'],'SERVICE_PROVIDER',$_W['wlsetting']['cashset']['appmerchantname'],$set); +// if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS') { +// $data = [ +// 'type' => 'MERCHANT_ID', +// 'account' => $_W['wlsetting']['cashset']['appmerchantid'], +// 'amount' => $sysmoney, +// 'description' => '平台抽佣', +// ]; +// }else{ +// file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); +// } +// }else if($_W['wlsetting']['cashset']['appsysalltype'] == 2){ +// $cashopenid = pdo_getcolumn(PDO_NAME.'member',array('id'=>$_W['wlsetting']['cashset']['appallmid']),'wechat_openid'); +// $res = self::addReceiver('PERSONAL_OPENID',$cashopenid,'SERVICE_PROVIDER','',$set); +// if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS') { +// $data = [ +// 'type' => 'PERSONAL_OPENID', +// 'account' => $cashopenid, +// 'amount' => $sysmoney, +// 'description' => '平台抽佣', +// ]; +// }else{ +// file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); +// } +// } + } + } + if($paysetid > 0){ + $info = pdo_get(PDO_NAME."payment",['id'=>$paysetid]); + $Setinfo = json_decode($info['param'],true); + $res = self::addReceiver('MERCHANT_ID',$Setinfo['sub_shop_number'],'SERVICE_PROVIDER',$Setinfo['merchantname'],$set); + if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){ + $data = [ + 'type' => 'MERCHANT_ID', + 'account' => $Setinfo['sub_shop_number'], + 'amount' => $sysmoney, + 'description' => '平台抽佣', + ]; + }else{ + file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); + } + } + return !empty($data) ? $data : 0; + } + + /** + * Comment: 获取分销分账信息 + * Author: wlf + * Date: 2020/09/04 14:15 + */ + public function getDisAllInfo($disid,$disprice,$source,$set){ + global $_W; + if($source == 1){ + $openid = pdo_getcolumn(PDO_NAME.'member',array('distributorid'=>$disid),'openid'); + }else{ + $openid = pdo_getcolumn(PDO_NAME.'member',array('distributorid'=>$disid),'wechat_openid'); + } + if(!empty($openid)){ + $res = self::addReceiver('PERSONAL_OPENID',$openid,'DISTRIBUTOR','',$set); + if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS') { + $data = [ + 'type' => 'PERSONAL_OPENID', + 'account' => $openid, + 'amount' => $disprice * 100, + 'description' => '分佣', + ]; + }else{ + file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); + } + } + return !empty($data) ? $data : 0; + } + + /** + * Comment: 获取业务员分账信息 + * Author: wlf + * Date: 2020/09/04 15:53 + */ + public function getSaleAllInfo($mid,$salesprice,$source,$set){ + global $_W; + if($source == 1){ + $openid = pdo_getcolumn(PDO_NAME.'member',array('mid'=>$mid),'openid'); + }else{ + $openid = pdo_getcolumn(PDO_NAME.'member',array('mid'=>$mid),'wechat_openid'); + } + if(!empty($openid)){ + $res = self::addReceiver('PERSONAL_OPENID',$openid,'STAFF','',$set); + if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS') { + $data = [ + 'type' => 'PERSONAL_OPENID', + 'account' => $openid, + 'amount' => $salesprice * 100, + 'description' => '业务员', + ]; + }else{ + file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); + } + } + return !empty($data) ? $data : 0; + } + + /** + * Comment: 获取代理分账信息 + * Author: wlf + * Date: 2020/09/04 16:09 + */ + public function getAgentAllInfo($aid,$agentprice,$source,$set){ + global $_W; + $agentset = pdo_get('wlmerchant_agentusers',array('id' => $aid),array('wxpaysetid','apppaysetid')); + if($source == 1 || $source == 2){ + $paysetid = $agentset['wxpaysetid']; +// if($agentset['wxsysalltype'] == 1){ +// //添加关系 +// $res = self::addReceiver('MERCHANT_ID',$agentset['wxmerchantid'],'PARTNER',$agentset['wxmerchantname'],$set); +// if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){ +// $data = [ +// 'type' => 'MERCHANT_ID', +// 'account' => $agentset['wxmerchantid'], +// 'amount' => $agentprice * 100, +// 'description' => '代理抽佣', +// ]; +// }else{ +// file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); +// } +// }else{ +// //添加关系 +// $cashopenid = pdo_getcolumn(PDO_NAME.'member',array('id'=>$agentset['wxallmid']),'openid'); +// $res = self::addReceiver('PERSONAL_OPENID',$cashopenid,'PARTNER','',$set); +// if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){ +// $data = [ +// 'type' => 'PERSONAL_OPENID', +// 'account' => $cashopenid, +// 'amount' => $agentprice * 100, +// 'description' => '代理抽佣', +// ]; +// }else{ +// file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); +// } +// } + }else if($source == 3){ + $paysetid = $agentset['apppaysetid']; +// if($agentset['appsysalltype'] == 1){ +// //添加关系 +// $res = self::addReceiver('MERCHANT_ID',$agentset['appmerchantid'],'PARTNER',$agentset['appmerchantname'],$set); +// if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){ +// $data = [ +// 'type' => 'MERCHANT_ID', +// 'account' => $agentset['appmerchantid'], +// 'amount' => $agentprice * 100, +// 'description' => '代理抽佣', +// ]; +// }else{ +// file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); +// } +// }else{ +// //添加关系 +// $cashopenid = pdo_getcolumn(PDO_NAME.'member',array('id'=>$agentset['appallmid']),'wechat_openid'); +// $res = self::addReceiver('PERSONAL_OPENID',$cashopenid,'PARTNER','',$set); +// if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){ +// $data = [ +// 'type' => 'PERSONAL_OPENID', +// 'account' => $cashopenid, +// 'amount' => $agentprice * 100, +// 'description' => '代理抽佣', +// ]; +// }else{ +// file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); +// } +// } + } + if($paysetid > 0){ + $info = pdo_get(PDO_NAME."payment",['id'=>$paysetid]); + $Setinfo = json_decode($info['param'],true); + $res = self::addReceiver('MERCHANT_ID',$Setinfo['sub_shop_number'],'SERVICE_PROVIDER',$Setinfo['merchantname'],$set); + if($res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){ + $data = [ + 'type' => 'MERCHANT_ID', + 'account' => $Setinfo['sub_shop_number'], + 'amount' => $agentprice * 100, + 'description' => '代理抽佣', + ]; + }else{ + file_put_contents(PATH_DATA . "allocation_error.log", var_export($res, true) . PHP_EOL, FILE_APPEND); + } + } + return !empty($data) ? $data : 0; + } + + /** + * Comment: 服务商订单结算分账借口 + * Author: wlf + * Date: 2020/09/08 14:10 + */ + public function allocationPro($orderid,$type,$source,$salesinfo = [],$salesmoney = 0){ + global $_W; + $receivers = []; + $sysmoney = $disonemoney = $distwomoney = $storemoney = 0; + //获取订单数据 + switch ($type){ + case '1': + $order = pdo_get(PDO_NAME.'rush_order',array('id'=>$orderid),array('sid','uniacid','settlementmoney','transid','aid','paysetid','orderno','actualprice','disorderid')); + $price = $order['actualprice']; + $storemoney = $order['settlementmoney']; + break; + case '4': + $order = pdo_get(PDO_NAME.'halfcard_record',array('id'=>$orderid),array('transid','uniacid','aid','paysetid','orderno','price','disorderid')); + $price = $order['price']; + break; + default : + $order = pdo_get(PDO_NAME.'order',array('id'=>$orderid),array('sid','settlementmoney','transid','uniacid','plugin','aid','paysetid','orderno','price','disorderid')); + $price = $order['price']; + $plugin = $order['plugin']; + $storemoney = $order['settlementmoney']; + break; + } + if(empty($order['transid'])) { + $order['transid'] = pdo_getcolumn(PDO_NAME . 'paylogvfour', array('tid' => $order['orderno']), 'transaction_id'); + } + //基础信息 + $getUrl = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing"; + $filePath = PATH_ATTACHMENT . "public_file/" . MODULE_NAME . "/"; + $id = $order['paysetid']; + $info = pdo_get(PDO_NAME."payment",['id'=>$id]); + $setting = json_decode($info['param'],true); + //获取平台分账信息 + $sysinfo = self::getSysAllInfo($price,$source,$setting,$order['uniacid']); + if(!empty($sysinfo)){ + $receivers[] = $sysinfo; + $sysmoney = sprintf("%.2f",$sysinfo['amount'] / 100); + } + //获取分销分账信息 + if($order['disorderid'] > 0){ + $disorder = pdo_get('wlmerchant_disorder',array('id' => $order['disorderid']),array('oneleadid','twoleadid','leadmoney')); + $leadmoney = unserialize($disorder['leadmoney']); + if($disorder['oneleadid'] > 0 && $leadmoney['one'] > 0){ + $onedisinfo = self::getDisAllInfo($disorder['oneleadid'],$leadmoney['one'],$source,$setting); + if(!empty($sysinfo)){ + $receivers[] = $onedisinfo; + } + $disonemoney = $leadmoney['one']; + } + if($disorder['twoleadid'] > 0 && $leadmoney['two'] > 0){ + $onedisinfo = self::getDisAllInfo($disorder['twoleadid'],$leadmoney['two'],$source,$setting); + if(!empty($sysinfo)){ + $receivers[] = $onedisinfo; + } + $distwomoney = $leadmoney['two']; + } + } + //获取业务员信息 + if(!empty($salesinfo) && $salesmoney > 0){ + foreach($salesinfo as $sinfo){ + $saleallinfo = self::getSaleAllInfo($sinfo['mid'],$sinfo['reportmoney'],$source,$setting); + if(!empty($saleallinfo)){ + $receivers[] = $saleallinfo; + } + } + } + //获取代理分账信息 + if(!empty($order['sid']) || $plugin == 'store'){ + $agentmoney = sprintf("%.2f",$price - $sysmoney - $disonemoney - $storemoney - $distwomoney - $salesmoney); + if($agentmoney > 0 && $order['aid'] > 0){ + $agentallinfo = self::getAgentAllInfo($order['aid'],$agentmoney,$source,$setting); + if(!empty($agentallinfo)){ + $receivers[] = $agentallinfo; + } + } + } + + //生成分账方面 + if(count($receivers)>0){ + $receivers = json_encode($receivers); + $data = [ + 'mch_id' => $setting['shop_number'], + 'sub_mch_id' => $setting['sub_shop_number'], + 'appid' => $setting['sub_up_app_id'], + 'nonce_str' => $this -> createNoncestr(), + 'transaction_id' => $order['transid'], + 'out_order_no' => 'PP'.date('YmdHis').random(4,1), + 'receivers' => $receivers, + ]; + $data['sign'] = $this->getWlfSign($data,$setting['secret_key']); + + $cert = trim($filePath . $setting['cert_certificate']); + $key = trim($filePath . $setting['key_certificate']); + + $xml = $this->arrayToXml($data); + $re = $this->wxWlfHttpsRequestPem($xml,$getUrl,30,[],$cert,$key); + $rearr = $this->xmlToArray($re); + if($rearr['return_code'] == 'SUCCESS' && $rearr['result_code'] == 'SUCCESS'){ + $result = [ + 'status' => 1, + 'agentmoney' => $agentmoney > 0 ? $agentmoney : 0, + 'sysmoney' => $sysmoney + ]; + return $result; + }else{ + file_put_contents(PATH_DATA . "allocation_error.log", var_export($rearr, true) . PHP_EOL, FILE_APPEND); + return 0; + } + }else{ + //完成结算 + $data = [ + 'mch_id' => $setting['shop_number'], + 'sub_mch_id' => $setting['sub_shop_number'], + 'appid' => $setting['sub_up_app_id'], + 'nonce_str' => $this -> createNoncestr(), + 'transaction_id' => $order['transid'], + 'out_order_no' => 'PP'.date('YmdHis').random(4,1), + 'description' => '分账已完成', + ]; + $data['sign'] = $this->getWlfSign($data,$setting['secret_key']); + $cert = trim($filePath . $setting['cert_certificate']); + $key = trim($filePath . $setting['key_certificate']); + + $getUrl = 'https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish'; + $xml = $this->arrayToXml($data); + $re = $this->wxWlfHttpsRequestPem($xml,$getUrl,30,[],$cert,$key); + $rearr = $this->xmlToArray($re); + if($rearr['return_code'] == 'SUCCESS' && $rearr['result_code'] == 'SUCCESS'){ + $result = [ + 'status' => 1, + 'agentmoney' => $agentmoney > 0 ? $agentmoney : 0, + 'sysmoney' => $sysmoney > 0 ? : 0 + ]; + return $result; + }else{ + file_put_contents(PATH_DATA . "allocation_error.log", var_export($rearr, true) . PHP_EOL, FILE_APPEND); + return 0; + } + } + } + + /** + * Comment: 服务商核销码分账借口 + * Author: wlf + * Date: 2020/08/31 10:46 + */ + public function allocationMulti($orderid,$source,$salesinfo = [],$salesmoney = 0){ // $source = 1公众号 3小程序 + global $_W; + //获取订单数据 + $receivers = []; + $sysmoney = 0; + $smallorder = pdo_get('wlmerchant_smallorder',array('id' => $orderid),array('aid','orderprice','plugin','orderid','settlemoney','sid','oneleadid','twoleadid','onedismoney','twodismoney')); + $price = $smallorder['orderprice']; + if($smallorder['plugin'] == 'rush'){ + $order = pdo_get('wlmerchant_rush_order',array('id' => $smallorder['orderid']),array('transid','uniacid','paysetid','orderno','allocationtype')); + }else{ + $order = pdo_get('wlmerchant_order',array('id' => $smallorder['orderid']),array('transid','uniacid','paysetid','orderno','allocationtype')); + } + if(empty($order['transid'])) { + $order['transid'] = pdo_getcolumn(PDO_NAME . 'paylogvfour', array('tid' => $order['orderno']), 'transaction_id'); + } + //基础信息 + $getUrl = "https://api.mch.weixin.qq.com/secapi/pay/multiprofitsharing"; + $filePath = PATH_ATTACHMENT . "public_file/" . MODULE_NAME . "/"; + $id = $order['paysetid']; + $info = pdo_get(PDO_NAME."payment",['id'=>$id]); + $setting = json_decode($info['param'],true); + + //获取平台分账信息 + $sysinfo = self::getSysAllInfo($price,$source,$setting,$order['uniacid']); + + if(!empty($sysinfo)){ + $receivers[] = $sysinfo; + $sysmoney = sprintf("%.2f",$sysinfo['amount'] / 100); + } + //获取分销分账信息 + if($smallorder['oneleadid'] > 0 && $smallorder['onedismoney'] > 0){ + $onedisinfo = self::getDisAllInfo($smallorder['oneleadid'],$smallorder['onedismoney'],$source,$setting); + if(!empty($sysinfo)){ + $receivers[] = $onedisinfo; + } + } + if($smallorder['twoleadid'] > 0 && $smallorder['twodismoney'] > 0){ + $onedisinfo = self::getDisAllInfo($smallorder['twoleadid'],$smallorder['twodismoney'],$source,$setting); + if(!empty($sysinfo)){ + $receivers[] = $onedisinfo; + } + } + //获取业务员信息 + if(!empty($salesinfo) && $salesmoney > 0){ + foreach($salesinfo as $sinfo){ + $saleallinfo = self::getSaleAllInfo($sinfo['mid'],$sinfo['reportmoney'],$source,$setting); + if(!empty($saleallinfo)){ + $receivers[] = $saleallinfo; + } + } + } + //获取代理分账信息 + $agentmoney = sprintf("%.2f",$price - $sysmoney - $smallorder['settlemoney'] - $smallorder['onedismoney'] - $smallorder['twodismoney'] - $salesmoney); + if($agentmoney > 0 && $smallorder['aid'] > 0){ + $agentallinfo = self::getAgentAllInfo($smallorder['aid'],$agentmoney,$source,$setting); + if(!empty($agentallinfo)){ + $receivers[] = $agentallinfo; + } + } + //生成分账方面 + if(count($receivers)>0){ + $receivers = json_encode($receivers); + $data = [ + 'mch_id' => $setting['shop_number'], + 'sub_mch_id' => $setting['sub_shop_number'], + 'appid' => $setting['sub_up_app_id'], + 'nonce_str' => $this -> createNoncestr(), + 'transaction_id' => $order['transid'], + 'out_order_no' => 'PP'.date('YmdHis').random(4,1), + 'receivers' => $receivers, + ]; + $data['sign'] = $this->getWlfSign($data,$setting['secret_key']); + + $cert = trim($filePath . $setting['cert_certificate']); + $key = trim($filePath . $setting['key_certificate']); + + $xml = $this->arrayToXml($data); + $re = $this->wxWlfHttpsRequestPem($xml,$getUrl,30,[],$cert,$key); + $rearr = $this->xmlToArray($re); + if($rearr['return_code'] == 'SUCCESS' && $rearr['result_code'] == 'SUCCESS'){ + $result = [ + 'status' => 1, + 'agentmoney' => $agentmoney > 0 ? $agentmoney : 0, + 'sysmoney' => $sysmoney + ]; + return $result; + }else{ + file_put_contents(PATH_DATA . "allocation_error.log", var_export($rearr, true) . PHP_EOL, FILE_APPEND); + return 0; + } + }else{ + $result = [ + 'status' => 1, + 'agentmoney' => $agentmoney > 0 ? $agentmoney : 0, + 'sysmoney' => $sysmoney > 0 ? : 0 + ]; + return $result; + } + } + + /** + * Comment: 添加分账方接口 + * Author: wlf + * Date: 2020/08/31 15:27 + */ + public function addReceiver($type,$account,$relation_type,$name = '',$setting){ + global $_W; + $getUrl = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver"; + //生成分账方面 + $receiver = [ + 'type' => $type, + 'account' => $account, + 'relation_type' => $relation_type, + ]; + if($type == 'MERCHANT_ID'){ + $receiver['name'] = $name; + } + $receiver = json_encode($receiver); + $data = [ + 'mch_id' => $setting['shop_number'], + 'sub_mch_id' => $setting['sub_shop_number'], + 'appid' => $setting['sub_up_app_id'], + 'nonce_str' => $this -> createNoncestr(), + 'receiver' => $receiver, + ]; + $data['sign'] = $this->getWlfSign($data,$setting['secret_key']); + $xml = $this->arrayToXml($data); + $re = $this->wxWlfHttpsRequestPem($xml,$getUrl); + $rearr = $this->xmlToArray($re); + + return $rearr; + } + + /** + * Comment: 完结分账接口 + * Author: wlf + * Date: 2020/09/04 18:10 + */ + public function allocationFinish($orderid){ + global $_W; + $smallorder = pdo_get('wlmerchant_smallorder',array('id' => $orderid),array('aid','orderprice','plugin','orderid','settlemoney','sid','oneleadid','twoleadid','onedismoney','twodismoney')); + $price = $smallorder['orderprice']; + if($smallorder['plugin'] == 'rush'){ + $order = pdo_get('wlmerchant_rush_order',array('id' => $smallorder['orderid']),array('transid','paysetid','orderno','allocationtype')); + }else{ + $order = pdo_get('wlmerchant_order',array('id' => $smallorder['orderid']),array('transid','paysetid','orderno','allocationtype')); + } + if(empty($order['transid'])) { + $order['transid'] = pdo_getcolumn(PDO_NAME . 'paylogvfour', array('tid' => $order['orderno']), 'transaction_id'); + } + //基础信息 + $getUrl = "https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish"; + $filePath = PATH_ATTACHMENT . "public_file/" . MODULE_NAME . "/"; + $id = $order['paysetid']; + $info = pdo_get(PDO_NAME."payment",['id'=>$id]); + $setting = json_decode($info['param'],true); + + $data = [ + 'mch_id' => $setting['shop_number'], + 'sub_mch_id' => $setting['sub_shop_number'], + 'appid' => $setting['sub_up_app_id'], + 'nonce_str' => $this -> createNoncestr(), + 'transaction_id' => $order['transid'], + 'out_order_no' => 'PP'.date('YmdHis').random(4,1), + 'description' => '订单已完成', + ]; + $data['sign'] = $this->getWlfSign($data,$setting['secret_key']); + + $cert = trim($filePath . $setting['cert_certificate']); + $key = trim($filePath . $setting['key_certificate']); + + $xml = $this->arrayToXml($data); + $re = $this->wxWlfHttpsRequestPem($xml,$getUrl,30,[],$cert,$key); + $rearr = $this->xmlToArray($re); + if($rearr['return_code'] == 'SUCCESS' && $rearr['result_code'] == 'SUCCESS'){ + return 1; + }else{ + file_put_contents(PATH_DATA . "allocation_error.log", var_export($rearr, true) . PHP_EOL, FILE_APPEND); + return 0; + } + + } + + + public function wxWlfHttpsRequestPem($vars, $url, $second = 30, $aHeader = array(),$cert = '',$key = '') { + global $_W; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_TIMEOUT, $second); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + if(!empty($cert)){ + curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM'); + curl_setopt($ch, CURLOPT_SSLCERT,$cert); + } + if(!empty($key)){ + curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM'); + curl_setopt($ch, CURLOPT_SSLKEY,$key); + } + // curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM'); + // curl_setopt($ch,CURLOPT_SSLKEY, PATH_DATA."cert/".$_W['uniacid']."/wechat/apiclient_key.pem"); +// curl_setopt($ch,CURLOPT_CAINFO,'PEM'); +// curl_setopt($ch,CURLOPT_CAINFO,IA_ROOT . '/attachment/feng_fightgroups/cert/' . $_W['uniacid'] . '/rootca.pem'); + if (count($aHeader) >= 1) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader); + } + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); + $data = curl_exec($ch); + if ($data) { + curl_close($ch); + return $data; + } else { + $error = curl_errno($ch); + echo "call faild, errorCode:$error\n"; + curl_close($ch); + return false; + } + } + + public function getWlfSign($Obj,$key) { + global $_W; + foreach ($Obj as $k => $v) { + $Parameters[$k] = $v; + } + ksort($Parameters); + $String = $this->formatBizQueryParaMap($Parameters, false); + $String = $String . "&key=" . $key; + $String = hash_hmac("sha256",$String,$key); + $result_ = strtoupper($String); + return $result_; + } + + +} + +?> \ No newline at end of file diff --git a/addons/weliam_smartcity/core/class/Weixinqrcode.class.php b/addons/weliam_smartcity/core/class/Weixinqrcode.class.php new file mode 100644 index 0000000..d3cd2e8 --- /dev/null +++ b/addons/weliam_smartcity/core/class/Weixinqrcode.class.php @@ -0,0 +1,328 @@ +func('communication'); + $barcode = array( + 'expire_seconds' => '', + 'action_name' => '', + 'action_info' => array( + 'scene' => array(), + ), + ); + + $scene_str = date('YmdHis') . rand(1000, 9999); + $uniacccount = WeAccount::create($_W['acid']); + + if ($qrctype == 1) { + $qrcid = pdo_fetchcolumn("SELECT qrcid FROM " . tablename('qrcode') . " WHERE acid = :acid AND model = '1' AND type = 'scene' ORDER BY qrcid DESC LIMIT 1", array(':acid' => $_W['acid'])); + $barcode['action_info']['scene']['scene_id'] = !empty($qrcid) ? ($qrcid + 1) : 100001; + $barcode['expire_seconds'] = 2592000; + $barcode['action_name'] = 'QR_SCENE'; + $result = $uniacccount->barCodeCreateDisposable($barcode); + } else if ($qrctype == 2) { + $is_exist = pdo_fetchcolumn('SELECT id FROM ' . tablename('qrcode') . ' WHERE uniacid = :uniacid AND scene_str = :scene_str AND model = 2', array(':uniacid' => $_W['uniacid'], ':scene_str' => $scene_str)); + if (!empty($is_exist)) { + $scene_str = date('YmdHis') . rand(1000, 9999); + } + $barcode['action_info']['scene']['scene_str'] = $scene_str; + $barcode['action_name'] = 'QR_LIMIT_STR_SCENE'; + $result = $uniacccount->barCodeCreateFixed($barcode); + } + + if (!is_error($result)) { + $insert = array( + 'uniacid' => $_W['uniacid'], + 'acid' => $_W['acid'], + 'qrcid' => $barcode['action_info']['scene']['scene_id'], + 'scene_str' => $barcode['action_info']['scene']['scene_str'], + 'keyword' => $keyword, + 'name' => $name, + 'model' => $qrctype, + 'ticket' => $result['ticket'], + 'url' => $result['url'], + 'expire' => $result['expire_seconds'], + 'createtime' => TIMESTAMP, + 'status' => '1', + 'type' => 'scene', + ); + pdo_insert('qrcode', $insert); + $qrid = pdo_insertid(); + $qrinsert = array( + 'uniacid' => $_W['uniacid'], + 'aid' => $agentid, + 'qrid' => $qrid, + 'type' => $ptype, + 'model' => $qrctype, + 'cardsn' => $scene_str, + 'salt' => random(8), + 'createtime' => TIMESTAMP, + 'status' => '1', + 'remark' => $remark + ); + pdo_insert(PDO_NAME . 'qrcode', $qrinsert); + return $qrid; + } + return $result; + } + + static function get_qrid($message) + { + global $_W; + if (!empty($message['ticket'])) { + if (is_numeric($message['scene']) && mb_strlen($message['scene']) != 18) { + $qrid = pdo_fetchcolumn('select id from ' . tablename('qrcode') . ' where uniacid=:uniacid and qrcid=:qrcid', array(':uniacid' => $_W['uniacid'], ':qrcid' => $message['scene'])); + } else { + $qrid = pdo_fetchcolumn('select id from ' . tablename('qrcode') . ' where uniacid=:uniacid and scene_str=:scene_str', array(':uniacid' => $_W['uniacid'], ':scene_str' => $message['scene'])); + } + if ($message['event'] == 'subscribe') { + self::qr_log($qrid, $message['from'], 1); + } else { + self::qr_log($qrid, $message['from'], 2); + } + } else { + self::send_text('欢迎关注我们!', $message); + } + return $qrid; + } + + static function qr_log($qrid, $openid, $type) + { + global $_W; + if (empty($qrid) || empty($openid)) { + return; + } + $qrcode = pdo_get('qrcode', array('id' => $qrid), array('scene_str', 'name')); + $log = array('uniacid' => $_W['uniacid'], 'acid' => $_W['acid'], 'qid' => $qrid, 'openid' => $openid, 'type' => $type, 'scene_str' => $qrcode['scene_str'], 'name' => $qrcode['name'], 'createtime' => time()); + pdo_insert('qrcode_stat', $log); + } + + static function createkeywords($name, $keyword) + { + global $_W; + if (empty($name) || empty($keyword)) { + return error('-1', '二维码关键字和名称不能为空'); + } + $rid = pdo_fetchcolumn("select id from " . tablename('rule') . 'where uniacid=:uniacid and module=:module and name=:name', array( + ':uniacid' => $_W['uniacid'], + ':module' => 'weliam_smartcity', + ':name' => $name + )); + if (empty($rid)) { + $rule_data = array( + 'uniacid' => $_W['uniacid'], + 'name' => $name, + 'module' => 'weliam_smartcity', + 'displayorder' => 0, + 'status' => 1 + ); + pdo_insert('rule', $rule_data); + $rid = pdo_insertid(); + } + + $content = pdo_getcolumn('rule_keyword', array('rid' => $rid, 'module' => 'weliam_smartcity', 'content' => $keyword), 'content'); + if (empty($content)) { + $keyword_data = array( + 'uniacid' => $_W['uniacid'], + 'rid' => $rid, + 'module' => 'weliam_smartcity', + 'content' => $keyword, + 'type' => 1, + 'displayorder' => 0, + 'status' => 1 + ); + pdo_insert('rule_keyword', $keyword_data); + } + + return $rid; + } + + static function send_news($returnmess, $message, $end = 1) + { + global $_W; + if (count($returnmess) > 1) { + $returnmess = array_slice($returnmess, 0, 1); + } + $send['touser'] = $message['from']; + $send['msgtype'] = 'news'; + $send['news']['articles'] = $returnmess; + $acc = WeAccount::create($_W['acid']); + $data = $acc->sendCustomNotice($send); + if (is_error($data)) { + self::salerEmpty(); + } else { + if ($end == 1) { + self::salerEmpty(); + } + } + } + + static function send_image($image, $message, $end = 1) + { + global $_W; + $media = self::image_to_media($image, $message); + $send['touser'] = $message['from']; + $send['msgtype'] = 'image'; + $send['image'] = array('media_id' => $media['media_id']); + + $acc = WeAccount::create($_W['acid']); + $data = $acc->sendCustomNotice($send); + if (is_error($data)) { + self::salerEmpty(); + } else { + if ($end == 1) { + self::salerEmpty(); + } + } + } + + static function send_text($mess, $message, $end = 1) + { + global $_W; + $send['touser'] = $message['from']; + $send['msgtype'] = 'text'; + $send['text'] = array('content' => urlencode($mess)); + $acc = WeAccount::create($_W['acid']); + $data = $acc->sendCustomNotice($send); + if (is_error($data)) { + self::salerEmpty(); + } else { + if ($end == 1) { + self::salerEmpty(); + } + } + } + + static function send_wxapp($mess, $message, $end = 1) + { + global $_W; + if(empty($mess['path'])){ + $mess['path'] = tomedia($_W['wlsetting']['base']['logo']); + } + if(!empty($mess['path'])){ + $acc = WeAccount::create($_W['acid']); + $media = self::image_to_media($mess['path'], $message); + $mess['thumb_media_id'] = $media['media_id']; + unset($mess['path']); + $send['touser'] = $message['from']; + $send['msgtype'] = 'miniprogrampage'; + $send['miniprogrampage'] = $mess; + $data = $acc->sendCustomNotice($send); + if (is_error($data)) { + self::salerEmpty(); + } else { + if ($end == 1) { + self::salerEmpty(); + } + } + } + } + + private static function image_to_media($image, $message) + { + global $_W; + $caCheName = md5($image);//当前图片缓存信息 防止同一张图片多次提交 + //获取缓存信息 + $media = Cache::getCache('wxappSend',$caCheName); + if(empty($media)){ + $acc = WeAccount::create($_W['acid']); + //文件在远程需要下载到本地 + $path = "images" . DIRECTORY_SEPARATOR . $_W['uniacid'] . DIRECTORY_SEPARATOR . "media.upload" . DIRECTORY_SEPARATOR . md5($image) . substr($image, -4); + $allpath = ATTACHMENT_ROOT . $path; + if (!file_exists($allpath)) { + $imgcontent = self::getImage($image); + $res = FilesHandle::file_mkdirs(dirname($allpath)); + if($res){ + //保存图片信息 + $res = file_put_contents($allpath, $imgcontent); + if(!$res){ + //获取图片类型 + $imageInfo = getimagesize($image); + $mime = explode('/',$imageInfo['mime'])['1']; + $imageType = $mime ? '.'.$mime : '.jpg'; + //再次写入图片信息 + ob_start();//打开输出 + readfile($image);//输出图片文件 + $img = ob_get_contents();//得到浏览器输出 + ob_end_clean();//清除输出并关闭 + $fp2 = @fopen($allpath.$imageType, "a"); + $res = fwrite($fp2, $img);//向当前目录写入图片文件,并重新命名 + fclose($fp2); + //从新定义path + $path = $path.$imageType; + } + }else{ + self::send_text('目录创建失败', $message); + return false; + } + } + $media = $acc->uploadMedia($path); + if (is_error($media)) { + self::send_text($media['message'], $message); + } else { + Cache::setCache('wxappSend',$caCheName,$media); + return $media; + } + } + return $media; + } + + private static function salerEmpty() + { +// ob_clean(); +// ob_start(); +// echo ''; +// ob_flush(); +// ob_end_flush(); +// exit(0); + return true; + } + + + protected static function getImage($imgurl){ + load()->func('communication'); + $resp = ihttp_request($imgurl); + + if ($resp['code'] == 200 && !empty($resp['content'])) { + return imagecreatefromstring($resp['content']); + } + if ($resp['errno'] == 35) { + $imgurl = str_replace(array('https://'), 'http://', $imgurl); + } + + $i = 0; + while ($i < 3) { + $resp = ihttp_request($imgurl); + if ($resp['code'] == 200 && !empty($resp['content'])) { + return imagecreatefromstring($resp['content']); + } + ++$i; + } + + //以上方法都未获取图片资源 + $resp = file_get_contents($imgurl); + return imagecreatefromstring($resp); + } + + + + +} \ No newline at end of file diff --git a/addons/weliam_smartcity/core/class/WeliamDb.class.php b/addons/weliam_smartcity/core/class/WeliamDb.class.php new file mode 100644 index 0000000..6c45572 --- /dev/null +++ b/addons/weliam_smartcity/core/class/WeliamDb.class.php @@ -0,0 +1,270 @@ + $field) { + if (empty($oldtable['fields'][$fk])) { + //字段不存在,增加字段 + $sqlarr[] = ($field['increment'] == 1) ? self::table_field_edit($table['table'], $field, 1, $table['indexes']['PRIMARY']) : self::table_field_edit($table['table'], $field, 1); + } elseif (array_diff_assoc($table['fields'][$fk], $oldtable['fields'][$fk]) || array_diff_assoc($oldtable['fields'][$fk], $table['fields'][$fk])) { + //字段有变化,修改字段 + $sqlarr[] = self::table_field_edit($table['table'], $field, 2); + } + } + //对比索引 + foreach ($table['indexes'] as $idx => $index) { + if ($idx == 'PRIMARY') { + continue; + } + if (empty($oldtable['indexes'][$idx])) { + //索引不存在,增加索引 + $sqlarr[] = self::table_index_edit($table['table'], $index, 1); + } elseif (array_diff_assoc($table['indexes'][$idx], $oldtable['indexes'][$idx]) || array_diff_assoc($oldtable['indexes'][$idx]['fields'], $table['indexes'][$idx]['fields']) || array_diff_assoc($table['indexes'][$idx]['fields'], $oldtable['indexes'][$idx]['fields'])) { + //索引有变化,删除索引,新建索引 + $sqlarr[] = self::table_index_edit($table['table'], $index, 2); + $sqlarr[] = self::table_index_edit($table['table'], $index, 1); + } + } + //多余索引,需要删除 + foreach ($oldtable['indexes'] as $oidx => $oindex) { + if (empty($table['indexes'][$oidx])) { + $sqlarr[] = self::table_index_edit($table['table'], $oindex, 2); + } + } + //对比存储引擎 + if ($table['engine'] != $oldtable['engine']) { + $sqlarr[] = "ALTER TABLE " . self::tablename($table['table']) . " ENGINE=" . $table['engine'] . ", ROW_FORMAT=DEFAULT;"; + } + } + } + return $sqlarr; + } + + /** + * 根据条件查找表名 + * @param $table + * @param string $tablepre + * @param bool $haspre + * @return array + */ + static function get_tables_name($table, $tablepre = 'ims_', $haspre = false) { + $tablenames = pdo_fetchall("SHOW TABLES LIKE :tablename", array(":tablename" => "%" . $table . "%")); + if (!empty($tablenames)) { + $tables = []; + foreach ($tablenames as $item) { + $table = end($item); + $tables[] = $haspre ? $table : substr($table, strlen($tablepre)); + } + return $tables; + } + return []; + } + + /** + * 根据表名生成数据库插入语句 + * @param $tablename + * @param $uniacid + * @param $start + * @param $size + * @return array|bool + */ + static function get_table_insert_sql($tablename, $uniacid, $start, $size) { + $data = ''; + $tmp = ''; + $sql = "SELECT * FROM {$tablename} WHERE `uniacid` = {$uniacid} LIMIT {$start}, {$size}"; + $result = pdo_fetchall($sql); + if (!empty($result)) { + foreach ($result as $row) { + $tmp .= '('; + foreach ($row as $k => $v) { + $value = str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $v); + $tmp .= "'" . $value . "',"; + } + $tmp = rtrim($tmp, ','); + $tmp .= "),\n"; + } + $tmp = rtrim($tmp, ",\n"); + $data .= "INSERT INTO {$tablename} VALUES \n{$tmp};\n"; + $datas = array( + 'data' => $data, + 'result' => $result, + ); + + return $datas; + } else { + return false; + } + } + + /** + * 根据表名返回表的数据 + * @param string $tablename + * @return array + */ + static function get_table_schema($tablename = '') { + $result = self::pdo()->fetch("SHOW TABLE STATUS LIKE '" . trim(self::tablename($tablename), "`") . "'"); + if (empty($result) || empty($result['Create_time'])) { + return array(); + } + $ret["table"] = $tablename; + $ret["tablename"] = $result["Name"]; + $ret["charset"] = $result["Collation"]; + $ret["engine"] = $result["Engine"]; + $ret["increment"] = $result["Auto_increment"]; + $result = self::pdo()->fetchall("SHOW FULL COLUMNS FROM " . self::tablename($tablename)); + foreach ($result as $value) { + $temp = array(); + $type = explode(" ", $value["Type"], 2); + $temp["name"] = $value["Field"]; + $pieces = explode("(", $type[0], 2); + $temp["type"] = $pieces[0]; + $temp["length"] = rtrim($pieces[1], ")"); + $temp["null"] = !($value["Null"] == "NO"); + $temp["signed"] = empty($type[1]); + $temp["increment"] = $value["Extra"] == "auto_increment"; + if (!empty($value['Comment'])) { + $temp["comment"] = $value["Comment"]; + } + if ($value["Default"] != NULL) { + $temp["default"] = $value["Default"]; + } + $ret["fields"][$value["Field"]] = $temp; + } + $result = self::pdo()->fetchall("SHOW INDEX FROM " . self::tablename($tablename)); + foreach ($result as $value) { + $ret["indexes"][$value["Key_name"]]["name"] = $value["Key_name"]; + $ret["indexes"][$value["Key_name"]]["type"] = $value["Key_name"] == "PRIMARY" ? "primary" : ($value["Non_unique"] == 0 ? "unique" : "index"); + $ret["indexes"][$value["Key_name"]]["fields"][] = $value["Column_name"]; + } + return $ret; + } + + /** + * 返回完整表名 + * @param $table + * @return string + */ + private static function tablename($table) { + return self::pdo()->tablename($table); + } + + /** + * 数据库操作类 + * @return DB|SlaveDb + */ + private static function pdo() { + return pdo(); + } + + /** + * 生成创建表的SQL + * @param $schema + * @return string + */ + private static function create_table($schema) { + if (empty($schema)) { + return ''; + } + $sql = "CREATE TABLE IF NOT EXISTS " . self::tablename($schema['table']) . " ("; + //生成表的字段 + foreach ($schema['fields'] as $field) { + $sql .= self::create_table_field($field); + $sql .= ","; + } + //生成表的索引 + foreach ($schema['indexes'] as $index) { + $sql .= self::create_table_index($index); + $sql .= ","; + } + $sql = rtrim($sql, ","); + + $charset = substr($schema['charset'], 0, stripos($schema['charset'], "_")); + $sql .= ") ENGINE={$schema['engine']} DEFAULT CHARSET={$charset};"; + + return $sql; + } + + /** + * 生成操作字段的SQL段 + * @param $field + * @return string + */ + private static function create_table_field($field) { + if (empty($field)) { + return ""; + } + $sql = ""; + $sql .= " `{$field['name']}` {$field['type']}"; + $sql .= !empty($field['length']) ? "({$field['length']})" : ""; + $sql .= !empty($field['signed']) ? "" : " UNSIGNED"; + $sql .= !empty($field['null']) ? (array_key_exists("default", $field) ? "" : " DEFAULT NULL") : " NOT NULL"; + $sql .= array_key_exists("default", $field) ? " DEFAULT '{$field['default']}'" : ""; + $sql .= !empty($field['increment']) ? " AUTO_INCREMENT" : ""; + $sql .= !empty($field['comment']) ? " COMMENT '{$field['comment']}'" : ""; + return $sql; + } + + /** + * 生成操作索引的SQL段 + * @param $index + * @param string $type + * @return string + */ + private static function create_table_index($index, $type = 'ADD') { + if (empty($index)) { + return ""; + } + $sql = ""; + $sql .= $index['type'] == 'primary' ? "PRIMARY KEY" : "KEY `{$index['name']}`"; + if ($type == 'ADD') { + $sql .= " (`" . implode("`,`", $index['fields']) . "`)"; + } + return $sql; + } + + /** + * 生成操作字段的SQL + * @param string $tablename + * @param $field + * @param int $type + * @return string + */ + private static function table_field_edit($tablename = '', $field, $type = 1, $idx_field = []) { + $sqlstr = ($type == 1) ? " ADD " : " MODIFY COLUMN "; + $sql = "ALTER TABLE " . self::tablename($tablename) . $sqlstr . self::create_table_field($field); + //特殊情况,增加主键字段时 + if ($type == 1 && $field['increment'] == 1) { + $sql .= ", ADD " . self::create_table_index($idx_field, 'ADD'); + } + $sql .= ";"; + return $sql; + } + + /** + * 生成操作索引的SQL + * @param string $tablename + * @param $field + * @param int $type + * @return string + */ + private static function table_index_edit($tablename = '', $field, $type = 1) { + $sqlstr = ($type == 1) ? " ADD " : " DROP "; + $sql = "ALTER TABLE " . self::tablename($tablename) . $sqlstr . self::create_table_index($field, trim($sqlstr)) . ";"; + return $sql; + } +} \ No newline at end of file diff --git a/addons/weliam_smartcity/core/class/WeliamWeChat.class.php b/addons/weliam_smartcity/core/class/WeliamWeChat.class.php new file mode 100644 index 0000000..03d108a --- /dev/null +++ b/addons/weliam_smartcity/core/class/WeliamWeChat.class.php @@ -0,0 +1,2131 @@ + $_W['uniacid'], 'key' => 'halfcard')); + $wlsetting['value'] = unserialize($wlsetting['value']); + $now = time(); + if ($wlsetting['value']['halfcardtype'] == 2) { + $halfcardflag = pdo_fetch("SELECT * FROM " . tablename('wlmerchant_halfcardmember') . "WHERE uniacid = {$_W['uniacid']} AND mid = {$mid} AND aid = {$_W['aid']} AND expiretime > {$now} AND disable != 1"); + } else { + $halfcardflag = pdo_fetch("SELECT * FROM " . tablename('wlmerchant_halfcardmember') . "WHERE uniacid = {$_W['uniacid']} AND mid = {$mid} AND expiretime > {$now} AND disable != 1"); + } + //判断state返回内容 + if($state) return is_array($halfcardflag) && count($halfcardflag) > 0 && $halfcardflag['id'] > 0 ? $halfcardflag['id'] : 0 ; + return $halfcardflag; + } + /** + * Comment: 获取头条信息列表 + * Author: zzw + * Date: 2019/8/29 17:11 + * @param bool $shop_id + * @param int $page + * @param int $pageNum + * @return array + */ + static function getHeadline($shop_id = false, $page = 1, $pageNum = 10,$one_id = 0,$two_id = 0,$sort = 0){ + global $_W; + #1、条件生成 + $where = " WHERE uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} "; + if ($shop_id) $where .= " AND sid = {$shop_id} "; + if($one_id > 0){ + $where .= " AND one_id = {$one_id} "; + } + if($two_id > 0){ + $where .= " AND two_id = {$two_id} "; + } + if($sort == 1){ + $order = " ORDER BY browse DESC "; + }else{ + $order = " ORDER BY release_time DESC "; + } + $pageStart = $page * $pageNum - $pageNum; + #2、信息获取 + $list = pdo_fetchall("SELECT id,title,summary,display_img,author,author_img,browse,one_id,two_id,release_time FROM " + .tablename(PDO_NAME."headline_content") .$where.$order." LIMIT {$pageStart},{$pageNum}"); + foreach ($list as $k => &$v) { + $v['display_img'] = tomedia($v['display_img']); + $v['author_img'] = tomedia($v['author_img']); + $v['one_name'] = implode(pdo_get(PDO_NAME . 'headline_class' , ['id' => $v['one_id']] , ['name'])); + $v['two_name'] = implode(pdo_get(PDO_NAME . 'headline_class' , ['id' => $v['two_id']] , ['name'])); + $v['release_time'] = date("H:i",$v['release_time']); + unset($v['one_id']); + unset($v['two_id']); + } + return $list; + } + /** + * Comment: 获取某个店铺销量最好的商品 + * Author: zzw + * Date: 2019/8/29 17:12 + * @param $Atable string 商品表 + * @param $Btable string 订单表 + * @param $field string 查询的字段信息 + * @param $where string 查询条件 + * @param $group string 分组信息 + * @param $relation string 两表之间的关联信息 + * @param $SpareW string 备用条件,如果没有销量最好的商品时 查询任意一条本店铺的商品 + * @param $SpareF string 备用查询字段 + * @return string + */ + static function getSalesChampion($Atable, $Btable, $field, $where, $group, $relation, $SpareW, $SpareF) { + $info = pdo_fetchall("SELECT {$field} FROM " + . tablename(PDO_NAME . $Atable) + . " a LEFT JOIN " + . tablename(PDO_NAME . $Btable) + . " b ON {$relation} " + . " WHERE {$where} GROUP BY {$group}"); + $num = array_column($info, 'num'); + array_multisort($num, SORT_DESC, $info); + $info = $info[0]; + //$info 不存在,则当前店铺当前种类商品暂时没有销售 直接获取一个商品 + if (!$info) { + $info = pdo_fetchall("SELECT {$SpareF} FROM " + . tablename(PDO_NAME . $Atable) + . " WHERE {$SpareW}"); + $info = $info[0]; + } + return $info ? $info : ''; + } + /** + * Comment: 通过店铺列表 获取店铺每种类型的商品中销量最好的一个 + * Author: zzw + * Date: 2019/8/29 17:13 + * @param $shopList + * @return mixed + */ + static function getStoreList($shopList) { + global $_W, $_GPC; + foreach ($shopList as $k => &$v) { + $id = $v['id']; + //获取店铺的头条信息 + $headline = WeliamWeChat::getHeadline($id, 1, 1); + $headline = $headline[0] ? $headline[0] : ''; + if ($headline) { + unset($headline['summary']); + unset($headline['display_img']); + unset($headline['author']); + unset($headline['author_img']); + unset($headline['browse']); + unset($headline['one_name']); + unset($headline['two_name']); + $headline['jump_link'] = h5_url('pages/mainPages/headline/headlineDetail',['headline_id'=>$headline['id']]); + } + $v['headline'] = $headline; + //获取店铺每种商品中销量最好的一件商品的详细信息 + #1、抢购信息 + $goods['active'] = self::getSalesChampion('rush_activity', 'rush_order', 'a.id,a.name,count(b.activityid) as num', "a.sid = {$id} AND a.status IN (1,2) ", 'b.activityid', "a.id = b.activityid", " sid = {$id} AND status IN (1,2) ", "id,name");//status IN (1,2) + $goods['active']['jump_link'] = h5_url('pages/subPages/goods/index',['type'=>1,'id'=>$goods['active']['id']]); + #2、团购信息 + $goods['groupon'] = self::getSalesChampion('groupon_activity', 'order', 'a.id,a.name,count(b.fkid) as num', "a.sid = {$id} AND a.status IN (1,2) AND b.plugin = 'groupon' ", 'b.fkid', "a.id = b.fkid", " sid = {$id} AND status IN (1,2) ", "id,name"); + $goods['groupon']['jump_link'] = h5_url('pages/subPages/goods/index',['type'=>2,'id'=>$goods['groupon']['id']]); + #3、折扣信息 + $goods['halfcard'] = self::getSalesChampion('halfcardlist', 'timecardrecord', 'a.id,a.title as name,count(b.activeid) as num ', "a.uniacid = {$_W['uniacid']} AND a.aid = {$_W['aid']} AND a.status = 1 AND b.type = 1 AND b.merchantid = {$id}", 'b.activeid', "a.id = b.activeid", " uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} AND status = 1 AND merchantid = {$id} ", "id,title as name"); + $goods['halfcard']['jump_link'] = h5_url('pages/subPages2/newBuyOrder/buyOrder', array('id' => $id)); + #4、礼包信息 + $goods['packages'] = self::getSalesChampion('package', 'timecardrecord', 'a.id,a.title as name,count(b.activeid) as num ', "a.uniacid = {$_W['uniacid']} AND a.aid = {$_W['aid']} AND a.status = 1 AND b.type = 2 AND b.merchantid = {$id}", 'b.activeid', "a.id = b.activeid", " uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} AND status = 1 AND merchantid = {$id} ", "id,title as name"); + $goods['packages']['jump_link'] = h5_url('pages/mainPages/memberCard/memberCard'); + #5、超级券信息 + $goods['coupon'] = self::getSalesChampion('couponlist', 'order', 'a.id,a.title as name,count(b.fkid) as num ', "a.uniacid = {$_W['uniacid']} AND a.aid = {$_W['aid']} AND a.merchantid = {$id} AND a.status IN (1,2) AND b.plugin = 'coupon' AND a.is_show = 0 ", 'b.fkid', "a.id = b.fkid", " uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} AND merchantid = {$id} AND status IN (1,2) AND is_show = 0 ", "id,title as name"); + $goods['coupon']['jump_link'] = h5_url('pages/subPages/goods/index',['type'=>5,'id'=>$goods['coupon']['id']]); + #6、拼团信息 + $goods['fightgroup'] = self::getSalesChampion('fightgroup_goods', 'order', 'a.id,a.name,count(b.fkid) as num ', "a.uniacid = {$_W['uniacid']} AND a.aid = {$_W['aid']} AND a.merchantid = {$id} AND a.status IN (1,2) AND b.plugin = 'wlfightgroup'", 'b.fkid', "a.id = b.fkid", " uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} AND merchantid = {$id} AND status IN (1,2) ", "id,name"); + $goods['fightgroup']['jump_link'] = h5_url('pages/subPages/goods/index',['type'=>3,'id'=>$goods['fightgroup']['id']]); + #7、砍价信息 + $goods['bargain'] = self::getSalesChampion('bargain_activity', 'order', 'a.id,a.name,count(b.fkid) as num ', " a.uniacid = {$_W['uniacid']} AND a.aid = {$_W['aid']} AND a.sid = {$id} AND a.status IN (1,2) AND b.plugin = 'bargain'", 'b.fkid', "a.id = b.fkid", " uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} AND sid = {$id} AND status IN (1,2) ", "id,name"); + $goods['bargain']['jump_link'] = h5_url('pages/subPages/goods/index',['type'=>7,'id'=>$goods['bargain']['id']]); + //删除多余的数据 + unset($v['location']); + unset($v['url']); + unset($v['cate']); + if (!is_array($goods['active'])) unset($goods['active']); + if (!is_array($goods['groupon'])) unset($goods['groupon']); + if (!is_array($goods['halfcard'])) unset($goods['halfcard']); + if (!is_array($goods['packages'])) unset($goods['packages']); + if (!is_array($goods['coupon'])) unset($goods['coupon']); + if (!is_array($goods['fightgroup'])) unset($goods['fightgroup']); + if (!is_array($goods['bargain'])) unset($goods['bargain']); + + + + + + $v['goods'] = $goods; + } + return $shopList; + } + /** + * Comment: 图片上传到远程服务器 + * Author: zzw + * Date: 2019/8/29 17:14 + * @param $filename + * @param bool $auto_delete_local + * @return bool|string + * @throws Exception + */ + static function file_remote_upload($filename, $auto_delete_local = true) { + global $_W; + //本公众号设置信息 + if($_W['wlsetting']['enclosure']['service'] == 2){ + $_W['setting']['remote']['type'] = 2; + $_W['setting']['remote']['alioss'] = $_W['wlsetting']['enclosure']['alioss']; + }else if($_W['wlsetting']['enclosure']['service'] == 3){ + $_W['setting']['remote']['type'] = 3; + $_W['setting']['remote']['qiniu'] = $_W['wlsetting']['enclosure']['qiniu']; + }else if($_W['wlsetting']['enclosure']['service'] == 4){ + $_W['setting']['remote']['type'] = 4; + $_W['setting']['remote']['cos'] = $_W['wlsetting']['enclosure']['tengxun']; + } + if (empty($_W['setting']['remote']['type'])) { + return false; + } + if ($_W['setting']['remote']['type'] == '1') { + load()->library('ftp'); + $ftp_config = array( + 'hostname' => $_W['setting']['remote']['ftp']['hostname'], + 'username' => $_W['setting']['remote']['ftp']['username'], + 'password' => $_W['setting']['remote']['ftp']['password'], + 'port' => $_W['setting']['remote']['ftp']['port'], + 'ssl' => $_W['setting']['remote']['ftp']['ssl'], + 'passive' => $_W['setting']['remote']['ftp']['passive'], + 'timeout' => $_W['setting']['remote']['ftp']['timeout'], + 'rootdir' => $_W['setting']['remote']['ftp']['rootdir'], + ); + $ftp = new Ftp($ftp_config); + if (true === $ftp->connect()) { + $response = $ftp->upload(ATTACHMENT_ROOT . '/' . $filename, $filename); + if ($auto_delete_local) { + self::file_delete($filename); + } + if (!empty($response)) { + //return true; + } else { + return '远程附件上传失败,请检查配置并重新上传'; + } + } else { + return '远程附件上传失败,请检查配置并重新上传'; + } + } elseif ($_W['setting']['remote']['type'] == '2') { + load()->library('oss'); + load()->model('attachment'); + $buckets = attachment_alioss_buctkets($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret']); + $endpoint = 'http://' . $buckets[$_W['setting']['remote']['alioss']['bucket']]['location'] . '.aliyuncs.com'; + try { + $ossClient = new \OSS\OssClient($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $endpoint); + $ossClient->uploadFile($_W['setting']['remote']['alioss']['bucket'], $filename, ATTACHMENT_ROOT . $filename); + } catch (\OSS\Core\OssException $e) { + return $e->getMessage(); + } + if ($auto_delete_local) self::file_delete($filename); + } elseif ($_W['setting']['remote']['type'] == '3') { + load()->library('qiniu'); + $auth = new Qiniu\Auth($_W['setting']['remote']['qiniu']['accesskey'], $_W['setting']['remote']['qiniu']['secretkey']); + $config = new Qiniu\Config(); + $uploadmgr = new Qiniu\Storage\UploadManager($config); + $putpolicy = Qiniu\base64_urlSafeEncode(json_encode(array( + 'scope' => $_W['setting']['remote']['qiniu']['bucket'] . ':' . $filename, + ))); + $uploadtoken = $auth->uploadToken($_W['setting']['remote']['qiniu']['bucket'], $filename, 3600, $putpolicy); + [$ret, $err] = $uploadmgr->putFile($uploadtoken, $filename, ATTACHMENT_ROOT . '/' . $filename); + if ($auto_delete_local) { + self::file_delete($filename); + } + if ($err !== null) { + return '远程附件上传失败,请检查配置并重新上传'; + } + } elseif ($_W['setting']['remote']['type'] == '4') { + //使用腾讯4.2版本上传 + //include IA_ROOT . "/framework/library/cosv4.2/include.php";//微擎5.0有问题 强制使用4.2 + load()->library('cos'); + if(in_array('qcloudcos\Cosapi',get_declared_classes())){ + //使用腾讯4.2版本上传 + $bucket = trim($_W['setting']['remote']['cos']['bucket']); + qcloudcos\Cosapi::setRegion(trim($_W['setting']['remote']['cos']['local'])); + $uploadRet = qcloudcos\Cosapi::upload($bucket, ATTACHMENT_ROOT . $filename, '/' . $filename, '', 3 * 1024 * 1024, 0); + if ($uploadRet['code'] != 0) { + switch ($uploadRet['code']) { + case -62: + $message = '输入的appid有误'; + break; + case -79: + $message = '输入的SecretID有误'; + break; + case -97: + $message = '输入的SecretKEY有误'; + break; + case -166: + $message = '输入的bucket有误'; + break; + } + return $message ? : $uploadRet['message']; + } + if ($auto_delete_local) self::file_delete($filename); + }else { + //使用腾讯5版本上传 + load()->library('cosv5'); + try { + $bucket = $_W['setting']['remote']['cos']['bucket'] . '-' . $_W['setting']['remote']['cos']['appid']; + $params = [ + 'region' => $_W['setting']['remote']['cos']['local'] , + 'credentials' => [ + 'secretId' => $_W['setting']['remote']['cos']['secretid'] , + 'secretKey' => $_W['setting']['remote']['cos']['secretkey'] + ] + ]; + $cosClient = new Qcloud\Cos\Client($params); + $cosClient->Upload($bucket, $filename, fopen(ATTACHMENT_ROOT . $filename, 'rb')); + if ($auto_delete_local) self::file_delete($filename); + } catch (\Exception $e) { + return $e->getMessage(); + } + } + } + } + /** + * Comment: 图片上传后删除本地图片 + * Author: zzw + * Date: 2019/8/29 17:14 + * @param $file + * @return bool + */ + static function file_delete($file) { + if (empty($file)) { + return false; + } + if (file_exists($file)) { + @unlink($file); + } + if (file_exists(ATTACHMENT_ROOT . '/' . $file)) { + @unlink(ATTACHMENT_ROOT . '/' . $file); + } + return true; + } + /** + * Comment: 获取已购买当前商品的用户信息 已参与的人数 + * Author: zzw + * Date: 2019/8/29 17:15 + * @param $state int 状态:代表商品类型 1=抢购商品 2=团购商品 3=拼团商品 5=优惠券 + * @param $id int 商品id + * @return mixed + */ + static function PurchaseUser($state, $id) { + global $_W, $_GPC; + $limit = 5; + //条件拼装 + $where = "uniacid = {$_W['uniacid']} AND aid = {$_W['aid']}";//条件 + $table = 'order';//表 + switch ($state) { + case 1: + $table = 'rush_order'; + $where .= " AND `activityid` = {$id} "; + break;//抢购商品 + case 2: + $where .= " AND plugin = 'groupon' AND fkid = {$id} "; + break;//团购商品 + case 3: + $where .= " AND plugin = 'wlfightgroup' AND fkid = {$id} "; + break;//拼团商品 + case 5: + $where .= " AND plugin = 'coupon' AND fkid = {$id} "; + break;//优惠券 + case 7: + $where .= " AND plugin = 'bargain' AND fkid = {$id} "; + break;//砍价商品 + } + //获取内容 + $info = pdo_fetchall("SELECT id,mid FROM " . tablename(PDO_NAME . $table)."WHERE {$where} ORDER BY id DESC LIMIT {$limit} "); + if(!empty($info)){ + foreach($info as &$in){ + $member = pdo_get('wlmerchant_member',array('id' => $in['mid']),array('nickname','avatar')); + $in['nickname'] = $member['nickname']; + $in['avatar'] = tomedia($member['avatar']); + } + } + $count = pdo_fetchall("SELECT id FROM " . tablename(PDO_NAME . $table)."WHERE {$where}"); + //信息拼装 + $data['info'] = $info; + $data['count'] = count($count); + + return $data; + } + /** + * Comment: 获取商品多规格信息列表 + * Author: zzw + * Date: 2019/8/29 17:16 + * @param $id + * @param $type + * @return array + */ + static function getSpec($id, $type,$vipstatus = 0) { + global $_W; + #1、根据商品类型判断获取条件 + # 商品type:1=抢购 2=团购 3=拼团 4=大礼包(无佣金) 5=优惠券 6=折扣卡(无佣金) 7=砍价商品 + # 规格type:1抢购 2拼团 3团购 + $where = " WHERE uniacid = {$_W['uniacid']} AND goodsid = {$id} "; + switch ($type){ + case 1:$where .= " AND type = 1";break;//抢购 + case 2:$where .= " AND type = 3";break;//团购 + case 3:$where .= " AND type = 2";break;//拼团 + default:return [];break;//当前商品不支持多规格 + } + #2、获取规格信息 + $list = pdo_fetchall("SELECT title,content FROM ".tablename(PDO_NAME."goods_spec").$where." ORDER BY displayorder ASC "); + foreach($list as $key => &$val){ + //生成规格参数查询条件 + $idList = unserialize($val['content']); + if(is_array($idList) && count($idList) > 1){ + $ids = implode($idList,','); + $itemWhere = " WHERE id in ({$ids}) AND `show` = 1 "; + }else{ + $itemWhere = " WHERE id = {$idList[0]} AND `show` = 1 "; + } + //获取规格参数信息 + $val['item'] = pdo_fetchall(" SELECT id,title FROM ".tablename(PDO_NAME."goods_spec_item").$itemWhere." ORDER BY displayorder ASC "); + + unset($val['content']); + } + #3、获取规格组合后的销售信息 + $info = pdo_fetchall("SELECT id,specs,stock,price,thumb,viparray,onedismoney,vipprice as aloneprice FROM ".tablename(PDO_NAME."goods_option").$where." ORDER BY id ASC "); + #5、数据拼装 + $data['list'] = $list;//规格信息列表 + $data['info'] = $info;//规格参数列表 + + return $data; + } + /** + * Comment: 获取同城活动的多规格信息列表 + * Author: wlf + * Date: 2020/10/30 09:22 + * @param $id + * @return array + */ + static function getActivitySpec($id){ + global $_W; + $where = " WHERE uniacid = {$_W['uniacid']} AND activityid = {$id} "; + $info = pdo_fetchall("SELECT id,name,maxnum,price,viparray FROM ".tablename(PDO_NAME."activity_spec").$where." ORDER BY id ASC "); + foreach($info as $infoK => &$infoV){ + $stopBuyNum = WeliamWeChat::getSalesNum(6,$id,$infoV['id'],1); + $infoV['stock'] = $infoV['maxnum'] - intval($stopBuyNum); + } + //统计 + $prices = array_column($info,'price'); + $data['minprice'] = min($prices); + $data['maxprice'] = max($prices); + $stkList = array_column($info,'stock'); + $data['stk'] = array_sum($stkList); + $data['info'] = $info; + + return $data; + } + /** + * Comment: 新的首页商品信息查询 + * Author: wlf + * Date: 2020/09/16 15:28 + * @param $plugin + * @param $id + * @return bool + */ + static function getNewHomeGoods($plugin,$id) { + global $_W; + $mid = $_W['mid']; + $usercard = WeliamWeChat::VipVerification($mid); + if($usercard['id'] > 0){ + $usercardlevel = $usercard['levelid']; + }else{ + $usercardlevel = -1; + } + switch ($plugin) { + case 1: + $goods = pdo_fetch("SELECT a.optionstatus,IFNULL(a.pv,0) as pv,a.thumbs as adv,a.appointment,a.allowapplyre,a.communityid,'1' as type,b.logo as shop_logo,a.op_one_limit as buy_limit,a.status,a.id,a.thumb as logo,a.name as goods_name,a.price,a.oldprice,a.num as totalnum,b.storename,b.id as sid,a.starttime,a.endtime,a.viparray,a.vipstatus,a.allsalenum,b.address FROM " + . tablename(PDO_NAME . "rush_activity") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.sid = b.id WHERE a.id = {$id} "); + $goods['plugin'] = 'rush'; + $goods['postertype'] = '3'; + break;//抢购商品 + case 2: + $goods = pdo_fetch("SELECT IFNULL(a.pv,0) as pv,a.optionstatus,a.thumbs as adv,a.appointment,a.allowapplyre,a.communityid,'2' as type,b.logo as shop_logo,a.op_one_limit as buy_limit,b.address,a.status,a.id,a.thumb as logo,a.name as goods_name,a.price,a.oldprice,a.num as totalnum,b.storename,b.id as sid,a.starttime,a.endtime,a.viparray,a.vipstatus,a.allsalenum FROM " + . tablename(PDO_NAME . "groupon_activity") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.sid = b.id WHERE a.id = {$id} "); + $goods['plugin'] = $pluginType = 'groupon'; + $goods['postertype'] = '4'; + break;//团购商品 + case 3: + $goods = pdo_fetch("SELECT a.specstatus as optionstatus,a.pv,a.adv,a.communityid,'3' as type,a.is_pool,a.allowapplyre,a.appointment,b.logo as shop_logo,a.buylimit as buy_limit,b.address,a.status,a.id,a.logo,a.name as goods_name,a.price,a.aloneprice as oldprice,stock as totalnum,a.peoplenum,b.storename,b.id as sid,a.viparray,a.realsalenum,a.falsesalenum as allsalenum FROM " + . tablename(PDO_NAME . "fightgroup_goods") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.merchantid = b.id WHERE a.id = {$id} "); + $goods['plugin'] = $pluginType = 'wlfightgroup'; + $goods['postertype'] = '6'; + break;//拼团商品 + } + $goods['logo'] = tomedia($goods['logo']); + $goods['shop_logo'] = tomedia($goods['shop_logo']); + $advs = unserialize($goods['adv']); + $goods['long_logo'] = tomedia($advs[0]); + if ($plugin == 1) { + //抢购商品的销量 + $stopBuyNum = WeliamWeChat::getSalesNum(1,$id,0,1); + } else if ($plugin == 2) { + $stopBuyNum = WeliamWeChat::getSalesNum(2,$id,0,1); + } else if ($plugin == 3) { + $stopBuyNum = WeliamWeChat::getSalesNum(3,$id,0,1); + } + #3、加上虚拟销量 + if ($goods['allsalenum'] && empty($storeflag)) { + $stopBuyNum = intval($stopBuyNum) + intval($goods['allsalenum']); + $goods['totalnum'] = $goods['totalnum'] + $goods['allsalenum']; + } + $purchaseUser = WeliamWeChat::PurchaseUser($plugin, $goods['id']); + $goods['user_list'] = array_column($purchaseUser['info'], 'avatar');//购买当前商品的用户的头像 + $goods['user_num'] = $stopBuyNum;//$purchaseUser['count'];//已参与人数 + $goods['buy_num'] = $stopBuyNum ? $stopBuyNum : 0;//获取已售数量 + //获取当前商品的浏览记录 + //$browseRecord = array_column(self::getBrowseRecord($plugin, $goods['id']), 'avatar'); + //$goods['user_list'] = is_array($browseRecord) ? $browseRecord :[]; + //$goods['user_list'] = is_array($browseRecord) ? $browseRecord :[]; + #4、已销售数量的百分比 + if($goods['buy_num'] > 0 && $goods['totalnum'] > 0){ + $goods['buy_percentage'] = sprintf("%.2f", ($goods['buy_num'] / $goods['totalnum']) * 100); + if($goods['buy_percentage']>100){ + $goods['buy_percentage'] = 100.00; + } + }else{ + $goods['buy_percentage'] = 0.00; + } + $goods['stk'] = $goods['totalnum'] - $stopBuyNum; + if($goods['stk']<0){$goods['stk'] = 0;} + #7、商品为抢购商品时 并且状态为未开始时 判断用户是否关注当前抢购商品 0=未关注,1=已关注 + $goods['is_follow'] = 0; + if($plugin == 1 && $goods['status'] == 1){ + $isFollow = pdo_getcolumn(PDO_NAME.'rush_follows',['mid'=>$mid,'actid'=>$id],'id'); + if($isFollow) $goods['is_follow'] = 1; + } + #9、获取商品的优惠金额 Discount + if($goods['vipstatus'] == 1){ + $goods['discount_price'] = self::getVipDiscount($goods['viparray'],$usercardlevel); + }else{ + $goods['discount_price'] = 0; + } + if($goods['vipstatus'] != 1){ + $goods['discount_price'] = 0; + } + + if($goods['optionstatus'] > 0){ + if($plugin == 9){ + $specinfo = WeliamWeChat::getActivitySpec($id); + $goods['spec'] = $specinfo['info']; + if($goods['vipstatus'] == 1){ + foreach($goods['spec'] as &$spb){ + $spb['discount_price'] = self::getVipDiscount($spb['viparray'],$usercardlevel); + if($spb['discount_price'] < 0.01){ + $spb['discount_price'] = $goods['discount_price']; + } + } + } + $goods['minprice'] = $specinfo['minprice']; + $goods['maxprice'] = $specinfo['maxprice']; + $goods['stk'] = $specinfo['stk']; + }else{ + $goods['spec'] = WeliamWeChat::getSpec($id, $plugin,$goods['vipstatus']); + //从新获取库存信息 + foreach ($goods['spec']['info'] as &$sp){ + if ($plugin == 1) { + //抢购商品的销量 + $stopBuyNum = WeliamWeChat::getSalesNum(1,$goods['id'],$sp['id'],1); + $sp['stock'] = $sp['stock'] - intval($stopBuyNum); + }else if($plugin == 2 || $plugin == 3){ + $stopBuyNum = WeliamWeChat::getSalesNum($plugin,$goods['id'],$sp['id'],1); + $sp['stock'] = $sp['stock'] - intval($stopBuyNum); + } + $sp['thumb'] = tomedia($sp['thumb']); + if($goods['vipstatus'] == 1){ + $sp['discount_price'] = self::getVipDiscount($sp['viparray'],$usercardlevel); + if($sp['discount_price'] < 0.01 ){ + $sp['discount_price'] = $goods['discount_price']; + } + } + } + $stkList = array_column($goods['spec']['info'],'stock'); + $goods['stk'] = array_sum($stkList); + } + } + + return $goods; + + } + /** + * Comment: 首页商品信息查询 + * Author: zzw + * Date: 2019/8/29 17:17 + * @param $plugin + * @param $id + * @return bool + */ + static function getHomeGoods($plugin, $id,$storeflag = 0,$mid = 0,$time = 0) { + global $_W; + if(empty($mid)){ + $mid = $_W['mid']; + } + if(empty($time)){ + $time = time(); + } + #商品类型:1=抢购 2=团购 3=拼团 4=大礼包 5=优惠券 6=折扣卡 7=砍价商品 8=积分商品 9 = 同城活动 + #1、获取商品信息 + switch ($plugin) { + case 1: + $goods = pdo_fetch("SELECT a.id,a.optionstatus,IFNULL(a.pv,0) as pv,a.thumbs as adv,a.appointment,a.appointstatus,a.allowapplyre,a.communityid,'1' as type,b.logo as shop_logo,a.op_one_limit as buy_limit,a.status,a.id,a.thumb as logo,a.name as goods_name,a.price,a.oldprice,a.num as totalnum,b.storename,b.id as sid,a.starttime,a.endtime,a.viparray,a.vipstatus,a.allsalenum,b.address,a.pftid,a.cc_id FROM " + . tablename(PDO_NAME . "rush_activity") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.sid = b.id WHERE a.id = {$id} "); + $goods['plugin'] = 'rush'; + $goods['postertype'] = '3'; + break;//抢购商品 + case 2: + $goods = pdo_fetch("SELECT a.id,IFNULL(a.pv,0) as pv,a.optionstatus,a.thumbs as adv,a.appointment,a.appointstatus,a.allowapplyre,a.communityid,'2' as type,b.logo as shop_logo,a.op_one_limit as buy_limit,b.address,a.status,a.id,a.thumb as logo,a.name as goods_name,a.price,a.oldprice,a.num as totalnum,b.storename,b.id as sid,a.starttime,a.endtime,a.viparray,a.vipstatus,a.allsalenum,a.pftid FROM " + . tablename(PDO_NAME . "groupon_activity") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.sid = b.id WHERE a.id = {$id} "); + $goods['plugin'] = $pluginType = 'groupon'; + $goods['postertype'] = '4'; + break;//团购商品 + case 3: + $goods = pdo_fetch("SELECT a.id,a.specstatus as optionstatus,a.pv,a.adv,a.communityid,'3' as type,a.is_pool,a.allowapplyre,a.appointment,a.appointstatus,b.logo as shop_logo,a.buylimit as buy_limit,b.address,a.status,a.id,a.logo,a.name as goods_name,a.price,a.oldprice,a.stock as totalnum,a.peoplenum,b.storename,b.id as sid,a.vipstatus,a.viparray,a.realsalenum,a.falsesalenum as allsalenum,a.aloneprice_switch FROM " + . tablename(PDO_NAME . "fightgroup_goods") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.merchantid = b.id WHERE a.id = {$id} "); + $goods['plugin'] = $pluginType = 'wlfightgroup'; + $goods['postertype'] = '6'; + break;//拼团商品 + case 4: + //获取礼包信息 + $goods = pdo_fetch("SELECT a.id,'1' as is_link,a.type as exttype,a.storemoney,a.extlink,a.extinfo,'4' as type,b.logo as shop_logo, +a.id,a.limit,a.datestatus,a.title as `name`,a.timeslimit,a.timestatus,a.starttime,a.endtime,a.packtimestatus,a.datestarttime,a.dateendtime,a.oplimit,a.weeklimit,a.monthlimit,a.price,a.usetimes,a.usetimes as surplus,b.storename, +b.logo,b.lat,b.lng,b.address,b.id as sid,REPLACE('table','table','package') as `plugin`,a.datestatus,a.usedatestatus,a.week,a.day,allnum,resetswitch,`level` FROM " + . tablename(PDO_NAME . "package") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . "b ON a.merchantid = b.id WHERE a.id = {$id} "); + $goods['logo'] = tomedia($goods['logo']); + $goods['shop_logo'] = tomedia($goods['shop_logo']); + //获取已被使用的数量礼包库存 + $hasUsed = pdo_fetchcolumn("SELECT COUNT(*) as stk FROM " . tablename(PDO_NAME . "timecardrecord") . " WHERE `type` = 2 AND activeid = {$id}"); + $goods['stk'] = $goods['allnum']; + if ($goods['allnum'] > 0) { + $goods['stk'] = $goods['allnum'] - $hasUsed; + } + $userCardInfo = WeliamWeChat::VipVerification($mid); + //查看用户剩余次数 + switch ($goods['datestatus']) { + case 2: + $startTime = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y')); + $goods['newlimit'] = '每周'; + break;//每周 + case 3: + $startTime = mktime(0, 0, 0, date('m'), 1, date('Y')); + $goods['newlimit'] = '每月'; + break;//每月 + case 4: + $startTime = mktime(0, 0, 0, 1, 1, date('Y')); + $goods['newlimit'] = '每年'; + break;//每年 + default: + $goods['newlimit'] = '可用'; + break; + } + $goods['newlimit'] .= $goods['usetimes'].'次'; + if ($mid) { + //获取查询条件及可以使用的总次数 + $where = " WHERE `type` = 2 AND activeid = {$id} AND mid = {$mid} "; + //判断是否开启周期使用 + $goods['datestatus'] = $goods['datestatus'] ? : 1; + //判断是否开启续卡重置功能 + if ($goods['resetswitch'] == 1) { + //获取用户最近续卡时间 + $time1 = pdo_fetchcolumn("SELECT paytime FROM " . tablename(PDO_NAME . "halfcard_record") + . " WHERE uniacid = {$_W['uniacid']} AND aid = {$_W['aid']} AND mid = {$mid} AND cardid > 0 ORDER BY paytime DESC"); + $time2 = pdo_getcolumn(PDO_NAME.'halfcardmember',array('id'=>$userCardInfo['id']),'createtime'); + $time1 = intval($time1); + $time2 = intval($time2); + $time = $time1 > $time2 ? $time1 : $time2; + if ($startTime < $time) $startTime = $time;//续卡重置礼包使用时间 + } + if($startTime > 0) { + $where .= " AND usetime >= " . $startTime; + } + //获取已使用数量 + $surplus = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename(PDO_NAME . "timecardrecord") . $where); + $goods['surplus'] = ($goods['usetimes'] - $surplus) > 0 ? ($goods['usetimes'] - $surplus) : 0; + //判断用户是否为一卡通会员 并且获取一卡通的id + $goods['card'] = self::VipVerification($mid,true); + } + //外链礼包的信息处理 + if ($goods['exttype'] == 1) { + $setInfo = unserialize($goods['extinfo']); + $goods['url'] = $goods['extlink']; + $goods['storename'] = $setInfo['storename']; + $goods['shop_logo'] = tomedia($setInfo['storelogo']); + $goods['is_link'] = intval(0);//0=外链礼包 + } + //判断当前用户是否可用该礼包 + $lvInfo = unserialize($goods['level']);//会员限制列表 + $goods['use_where'] = intval(1); + if($userCardInfo['id'] > 0){ + //明确会员等级限制 只能是当前等级的会员可以使用 + if($lvInfo && !in_array($userCardInfo['levelid'],$lvInfo)){ + $goods['use_where'] = intval(0); + } + }else{ + $goods['use_where'] = intval(0); + } + + unset($goods['extinfo']); + unset($goods['extlink']); + unset($goods['storelogo']); + + return $goods; + break;//大礼包 + case 5: + $goods = pdo_fetch("SELECT a.id,IFNULL(a.pv,0) as pv,a.indexorder,a.extflag,a.extlink,a.extinfo,'5' as type,b.logo as shop_logo,a.get_limit as buy_limit,a.status,a.id,a.logo,a.title as goods_name,a.price,a.vipstatus,a.viparray,quantity as totalnum,b.storename,b.id as sid,a.surplus,a.is_charge,a.adv FROM " + . tablename(PDO_NAME . "couponlist") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.merchantid = b.id WHERE a.id = {$id} "); + $goods['plugin'] = $pluginType = 'coupon'; + //外链卡券的信息处理 + if($goods['extflag'] == 1){ + $extInfo = unserialize($goods['extinfo']); + $goods['storename'] = $extInfo['storename']; + } + $goods['postertype'] = '5'; + break;//优惠券 + case 6: + $goods = pdo_fetch("SELECT a.id,'1' as is_link,a.type as exttype,a.extlink,a.extinfo,'6' as type,a.describe, +b.logo as shop_logo,a.timeslimit as buy_limit,a.levelstatus,a.activearray,a.dayactarray,a.id,a.title as `name`,a.limit,a.datestatus,a.week,a.day,a.activediscount, +a.discount,a.daily,b.id as sid,b.storename,a.pv,a.sort,b.logo,a.level,b.payonline,b.panorama_discount FROM " + . tablename(PDO_NAME . "halfcardlist") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.merchantid = b.id WHERE a.id = {$id} "); + $goods['plugin'] = $pluginType = 'halfcard'; + $goods['logo'] = tomedia($goods['logo']); + $goods['shop_logo'] = tomedia($goods['shop_logo']); + if($goods['datestatus'] == 3 && $goods['daily'] > 0 ){ + $goods['activediscount'] = $goods['discount']; + } + //判断用户是否为一卡通会员 并且获取一卡通的id + if ($mid){ + $vipInfo = self::VipVerification($mid); + $goods['card'] = $vipInfo['id']; + } + //判断等级限制 获取折扣信息 + $lvevl = unserialize($goods['level']); + //分级折扣 + if($goods['levelstatus'] > 0){ + $le_ac_array = unserialize($goods['activearray']); + $le_day_array = unserialize($goods['dayactarray']); + if(empty($vipInfo)){ + $goods['activediscount'] = min($le_ac_array); + $goods['discount'] = min($le_day_array); + $goods['lowtip'] = 1; + }else{ + $goods['activediscount'] = $le_ac_array[$vipInfo['levelid']]; + $goods['discount'] = $le_day_array[$vipInfo['levelid']]; + } + $lvevl = []; + } + if(!empty($vipInfo) && !in_array($vipInfo['levelid'],$lvevl) && count($lvevl) > 0){ + //获取当前折扣卡今天的折扣情况 + $weekflag = date('w', $time);//星期 + $dayflag2 = date('j', $time);//日期 + switch ($goods['datestatus']) { + case 1: + //日期格式:星期 + if($weekflag == 0){ + $weekflag = 7; + } + $goods['week'] = unserialize($goods['week']); + if(!in_array($weekflag, $goods['week']) && $goods['daily'] > 0){ + $goods['activediscount'] = $goods['discount']; + } + break; + case 2: + //日期格式:日期 + $goods['day'] = unserialize($goods['day']); + if(!in_array($dayflag2, $goods['day']) && $goods['daily'] > 0){ + $goods['activediscount'] = $goods['discount']; + } + break; + } + $goods['discount'] = $goods['panorama_discount']; + }else if( (!empty($vipInfo) && Customized::init('customized336') ) || !Customized::init('customized336') ){ + if(empty($goods['daily'])){ + $goods['discount'] = $goods['panorama_discount']; + } + //获取当前折扣卡今天的折扣情况 + $weekflag = date('w', $time);//星期 + $dayflag2 = date('j', $time);//日期 + switch ($goods['datestatus']) { + case 1: + //日期格式:星期 + if($weekflag == 0){ + $weekflag = 7; + } + $goods['week'] = unserialize($goods['week']); + if (in_array($weekflag, $goods['week'])) { + $goods['discount'] = $goods['activediscount']; + }else if($goods['daily'] > 0){ + $goods['activediscount'] = $goods['discount']; + } + break; + case 2: + //日期格式:日期 + $goods['day'] = unserialize($goods['day']); + if (in_array($dayflag2, $goods['day'])) { + $goods['discount'] = $goods['activediscount']; + }else if($goods['daily'] > 0){ + $goods['activediscount'] = $goods['discount']; + } + break; + } + }else{ + $goods['discount'] = $goods['panorama_discount']; + } + + //外链折扣卡的信息处理 + if ($goods['exttype'] == 1) { + $setInfo = unserialize($goods['extinfo']); + $goods['storename'] = $setInfo['storename']; + $goods['logo'] = tomedia($setInfo['storelogo']); + $goods['url'] = $goods['extlink']; + $goods['is_link'] = intval(0);//0=外链折扣卡 + $goods['discount'] = $goods['activediscount']; + $goods['exdetail'] = htmlspecialchars_decode($goods['describe']); + } + #3、判断当前用户是否可用该折扣卡 + $userCardInfo = WeliamWeChat::VipVerification($mid); + $lvInfo = unserialize($goods['level']);//会员限制列表 + $goods['use_where'] = intval(1); + if($userCardInfo['id'] > 0){ + //明确会员等级限制 只能是当前等级的会员可以使用 + if($lvInfo && !in_array($userCardInfo['levelid'],$lvInfo)){ + $goods['use_where'] = intval(0); + } + }else{ + $goods['use_where'] = intval(0); + } + + unset($goods['extinfo']); + unset($goods['extlink']); + unset($goods['exttype']); + unset($goods['week']); + unset($goods['day']); + unset($goods['daily']); + unset($goods['datestatus']); + + return $goods; + break;//折扣卡 + case 7: + $goods = pdo_fetch("SELECT a.id,IFNULL(a.pv,0) as pv,a.tag,a.thumbs as adv,a.communityid,'7' as type,b.logo as shop_logo,b.address,a.allowapplyre,a.appointment,a.appointstatus,a.status,a.id,a.thumb as logo,a.name as goods_name,stock as totalnum,b.storename,b.id as sid,a.starttime,a.endtime,a.viparray,a.vipstatus,a.oldprice,a.price FROM " + . tablename(PDO_NAME . "bargain_activity") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.sid = b.id WHERE a.id = {$id} "); + $goods['plugin'] = 'bargain'; + $goods['postertype'] = '7'; + break;//砍价商品 + case 8: + #2、判断用户是否为会员 + $cardid = WeliamWeChat::VipVerification($mid,true); + #3、获取商品详细信息 + $field = " id,advs,title,thumb,old_price,description,IFNULL(pv,0) as pv,stock,community_id,`describe`,isdistri, + CASE WHEN {$cardid} > 0 AND vipstatus = 1 THEN vipcredit1 + ELSE use_credit1 + END as use_credit1, + CASE WHEN {$cardid} > 0 AND vipstatus = 1 THEN vipcredit2 + ELSE use_credit2 + END as price "; + $info = pdo_fetch("SELECT {$field} FROM " . tablename(PDO_NAME . "consumption_goods") . " WHERE id = {$id} "); + if (!$info) Commons::sRenderError('商品不存在!'); + $info['thumb'] = tomedia($info['thumb']); + $info['description'] = htmlspecialchars_decode($info['description']); + $info['is_vip'] = $cardid; + #4、幻灯片处理 + $info['advs'] = unserialize($info['advs']); + if (is_array($info['advs']) && count($info['advs']) > 0) { + foreach ($info['advs'] as $key => &$val) { + $val = tomedia($val); + } + }else{ + $info['advs'] = []; + } + #5、浏览量添加 + $pv = $info['pv'] + 1; + pdo_update(PDO_NAME . "consumption_goods" , [ 'pv' => $pv ] , [ 'id' => $id ]); + #6、获取销量 + $info['total'] = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename(PDO_NAME . "order") . " WHERE plugin = 'consumption' AND fkid = {$id} "); + #7、获取社群设置 + if ($info['community_id'] > 0) { + $info['community'] = Commons::getCommunity($info['community_id']); + } + if(!$info['community']) unset($info['community']); + #8、获取购买人头像信息 + $member = pdo_fetchall("SELECT b.avatar FROM " . tablename(PDO_NAME . "order") + . " as a LEFT JOIN " . tablename(PDO_NAME . "member") + . " as b ON a.mid = b.id WHERE a.plugin = 'consumption' AND a.fkid = {$id} GROUP BY b.id LIMIT 5"); + $info['avatar_list'] = is_array($member) && count($member) > 0 ? array_column($member , 'avatar') : []; + #9、一卡通文本信息获取 + $info['halfcard_text'] = !empty($_W['wlsetting']['trade']['halfcardtext']) ? $_W['wlsetting']['trade']['halfcardtext'] : '一卡通'; + #10、分销助手,获取当前用户分享最高可以获得的佣金 + $info['dis_assistant'] = WeliamWeChat::getDisInfo($plugin,$id); + #10、修改商品的人气(浏览量)信息 + $pv = intval($info['pv']) + 1; + pdo_update(PDO_NAME."consumption_goods",['pv'=>$pv],['id'=>$id]); + $info['postertype'] = '10'; + $info['plugin'] = 'integral'; + //价格处理 + $trade = Setting::wlsetting_read('trade'); + $creditText = $trade['credittext']; + $info['price_text'] = "{$info['use_credit1']}{$creditText} + {$info['price']}元"; + //获取轮播图第一张 + $info['long_logo'] = $info['advs'][0]; + + if(empty($info['stock'])){ + $info['stock'] = 999; + } + return $info; + break;//积分商品 + case 9: + $goods = pdo_fetch("SELECT a.id,a.vipprice,a.optionstatus,a.threeurl,IFNULL(a.pv,0) as pv,a.advs as adv,'9' as type,b.logo as shop_logo,a.status,a.id,a.thumb as logo,a.title as goods_name,a.price,a.maxpeoplenum as totalnum,b.storename,b.id as sid,a.activestarttime,a.activeendtime,a.viparray,a.vipstatus,a.addresstype,a.address as acaddress,b.address,c.name as catename FROM " + . tablename(PDO_NAME . "activitylist") + . " a LEFT JOIN " . tablename(PDO_NAME . "merchantdata") + . " b ON a.sid = b.id LEFT JOIN ". tablename(PDO_NAME . "activity_category") + . " c ON a.cateid = c.id WHERE a.id = {$id} "); + $goods['plugin'] = 'activity'; + $goods['postertype'] = '9'; + if($goods['addresstype'] > 0){ + $goods['address'] = $goods['acaddress']; + } + if($goods['optionstatus'] > 0 ){ + $Aoptions = pdo_getall('wlmerchant_activity_spec',array('activityid' => $goods['id']),array('price')); + $Parray = array_column($Aoptions,'price'); + $goods['price'] = min($Parray).'-'.max($Parray); + } + break;//同城活动 + case 10: + //获取信息 + $field = "id,name as goods_name,price,thumb as logo,thumbs as adv,fictitiousnum,status,allstock"; + $goods = pdo_fetch("SELECT {$field} FROM " + . tablename(PDO_NAME . "delivery_activity") + ." WHERE id = {$id} "); + //处理信息 + $goods['logo'] = tomedia($goods['logo']); + $goods['long_logo'] = tomedia(unserialize($goods['adv'])[0]); + $goods['plugin'] = 'citydelivery'; + //获取销量 + $stopBuyNum = pdo_fetchcolumn("SELECT sum(num) FROM " + . tablename(PDO_NAME . "delivery_order") + . " WHERE gid = {$goods['id']} AND uniacid = {$_W['uniacid']} AND status IN (1,2)"); + $goods['buy_num'] = $stopBuyNum ? $stopBuyNum : 0;//获取已售数量 + $goods['buy_num'] = $goods['buy_num'] + $goods['fictitiousnum'];//添加虚拟销量 + //获取库存 + $goods['stk'] = $goods['allstock'] > 0 ? $goods['allstock'] - $goods['buy_num'] : 0;//-1则代表不限量 + unset($goods['adv'],$goods['fictitiousnum']); + + return $goods; + break;//配送商品 + } + #2、获取商品销量 + $goods['logo'] = tomedia($goods['logo']); + $goods['shop_logo'] = tomedia($goods['shop_logo']); + $advs = unserialize($goods['adv']); + $goods['long_logo'] = tomedia($advs[0]); + if ($plugin == 1) { + //抢购商品的销量 + $stopBuyNum = WeliamWeChat::getSalesNum(1,$id,0,1,0,0,0,$goods['pftid']); + } else if ($plugin == 5) { + $stopBuyNum = WeliamWeChat::getSalesNum(4,$id,0,1); + } else if ($plugin == 3) { + $stopBuyNum = WeliamWeChat::getSalesNum(3,$id,0,1); + } else if ($plugin == 7) { + $stopBuyNum = WeliamWeChat::getSalesNum(5,$id,0,1); + } else if ($plugin == 2) { + $stopBuyNum = WeliamWeChat::getSalesNum(2,$id,0,1,0,0,0,$goods['pftid']); + } else if ($plugin == 9) { + $stopBuyNum = WeliamWeChat::getSalesNum(6,$id,0,1); + } else { + $stopBuyNum = pdo_fetchcolumn("SELECT sum(num) FROM " + . tablename(PDO_NAME . "order") + . " WHERE fkid = {$goods['id']} AND plugin = '{$pluginType}' AND uniacid = {$_W['uniacid']} AND status IN (0,1,2,3,6,9,4,8)"); + } + #3、加上虚拟销量 + if ($goods['allsalenum'] && empty($storeflag)) { + $stopBuyNum = intval($stopBuyNum) + intval($goods['allsalenum']); + $goods['totalnum'] = $goods['totalnum'] + $goods['allsalenum']; + } + $purchaseUser = WeliamWeChat::PurchaseUser($plugin, $goods['id']); + $goods['user_list'] = array_column($purchaseUser['info'], 'avatar');//购买当前商品的用户的头像 + $goods['user_num'] = $stopBuyNum;//$purchaseUser['count'];//已参与人数 + $goods['buy_num'] = $stopBuyNum ? $stopBuyNum : 0;//获取已售数量 + //获取当前商品的浏览记录 + //$browseRecord = array_column(self::getBrowseRecord($plugin, $goods['id']), 'avatar'); + //$goods['user_list'] = is_array($browseRecord) ? $browseRecord :[]; + //$goods['user_list'] = is_array($browseRecord) ? $browseRecord :[]; + #4、已销售数量的百分比 + if($goods['buy_num'] > 0 && $goods['totalnum'] > 0){ + $goods['buy_percentage'] = sprintf("%.2f", ($goods['buy_num'] / $goods['totalnum']) * 100); + if($goods['buy_percentage']>100){ + $goods['buy_percentage'] = 100.00; + } + }else{ + $goods['buy_percentage'] = 0.00; + } + $goods['stk'] = $goods['totalnum'] - $stopBuyNum; + if($goods['stk']<0){$goods['stk'] = 0;} + #5、判断用户会员信息 获取商品基础价格 + $goods['pay_state'] = 0;//购买状态 0=可以购买 + if($mid){ + $usercard = WeliamWeChat::VipVerification($mid); + if($usercard['id'] > 0){ + $goods['is_vip'] = $usercard['id'];//获取当前用户的会员卡id 等于0则不是会员 + $usercardlevel = $usercard['levelid']; + if($usercardlevel > 0){ + $levelinfo = pdo_get(PDO_NAME.'halflevel',array('id'=>$usercardlevel),['name','army']); + $goods['levelname'] = $levelinfo['name']; + $goods['levelarmy'] = $levelinfo['army']; + }else{ + $goods['levelname'] = $_W['wlsetting']['halflevel']['name']; + $goods['levelarmy'] = 0; + } + }else{ + $goods['is_vip'] = 0; + $usercardlevel = -1; + $goods['levelname'] = '会员最多'; + $goods['levelarmy'] = 0; + } + if($goods['vipstatus'] > 0){ + if($goods['vipstatus'] == 2 && ($goods['is_vip'] <= 0 || empty($goods['is_vip']))){ + $goods['pay_state'] = 1;//购买状态 1=会员特供,用户不是会员,不可购买 + } + } + }else{ + $usercardlevel = -1; + $goods['levelname'] = '会员最多'; + $goods['levelarmy'] = 0; + } + #7、商品为抢购商品时 并且状态为未开始时 判断用户是否关注当前抢购商品 0=未关注,1=已关注 + $goods['is_follow'] = 0; + if($plugin == 1 && $goods['status'] == 1){ + $isFollow = pdo_getcolumn(PDO_NAME.'rush_follows',['mid'=>$mid,'actid'=>$id],'id'); + if($isFollow) $goods['is_follow'] = 1; + } + #9、获取商品的优惠金额 Discount + if($goods['vipstatus'] == 1){ + if($plugin == 1 || $plugin == 2 || $plugin == 3 || $plugin == 5 || $plugin == 7 || $plugin == 9){ + $goods['discount_price'] = self::getVipDiscount($goods['viparray'],$usercardlevel); + }else{ + $goods['discount_price'] = sprintf("%.2f",$goods['price'] - $goods['vipprice']); + } + }else{ + $goods['discount_price'] = 0; + } + #8、判断是否为多规格商品 + if($goods['optionstatus'] > 0){ + if($plugin == 9){ + $specinfo = WeliamWeChat::getActivitySpec($id); + $goods['spec'] = $specinfo['info']; + if($goods['vipstatus'] == 1){ + foreach($goods['spec'] as &$spb){ + $spb['discount_price'] = self::getVipDiscount($spb['viparray'],$usercardlevel); + if($spb['discount_price'] < 0.01){ + $spb['discount_price'] = $goods['discount_price']; + } + } + } + $goods['minprice'] = $specinfo['minprice']; + $goods['maxprice'] = $specinfo['maxprice']; + $goods['stk'] = $specinfo['stk']; + }else{ + $goods['spec'] = WeliamWeChat::getSpec($id, $plugin,$goods['vipstatus']); + //从新获取库存信息 + foreach ($goods['spec']['info'] as &$sp){ + if ($plugin == 1) { + //抢购商品的销量 + $stopBuyNum = WeliamWeChat::getSalesNum(1,$goods['id'],$sp['id'],1,0,0,0,$goods['pftid']); + $sp['stock'] = $sp['stock'] - intval($stopBuyNum); + }else if($plugin == 2 || $plugin == 3){ + $stopBuyNum = WeliamWeChat::getSalesNum($plugin,$goods['id'],$sp['id'],1,0,0,0,$goods['pftid']); + $sp['stock'] = $sp['stock'] - intval($stopBuyNum); + } + $sp['thumb'] = tomedia($sp['thumb']); + if($goods['vipstatus'] == 1){ + $sp['discount_price'] = self::getVipDiscount($sp['viparray'],$usercardlevel); + if($sp['discount_price'] < 0.01 ){ + $sp['discount_price'] = $goods['discount_price']; + } + } + } + $stkList = array_column($goods['spec']['info'],'stock'); + $goods['stk'] = array_sum($stkList); + } + } + + unset($goods['viparray']); + return $goods; + } + /** + * Comment: 首页获取头条信息 + * Author: zzw + * Date: 2019/8/29 17:18 + * @param $id + * @return bool + */ + static function getHomeLine($id) { + $line = pdo_fetch("SELECT id,title,summary,display_img,author,author_img,browse,one_id,two_id FROM " + . tablename(PDO_NAME . "headline_content") + . " WHERE id = {$id} "); + if(!$line) return ''; + $line['display_img'] = tomedia($line['display_img']); + $line['author_img'] = tomedia($line['author_img']); + $line['one_name'] = pdo_getcolumn(PDO_NAME . 'headline_class', ['id' => $line['one_id']], 'name') ? : ''; + $line['two_name'] = pdo_getcolumn(PDO_NAME . 'headline_class',['id' => $line['two_id']], 'name') ? : ''; + unset($line['one_id']); + unset($line['two_id']); + return $line; + } + /** + * Comment: 根据信息获取页面信息,菜单信息,广告信息 + * Author: zzw + * Date: 2019/8/29 17:21 + * @param $pageInfo + * @param $menuid + * @param $advid + * @return mixed + */ + static function getPageInfo($pageInfo, $menuid, $advid) { + global $_W, $_GPC; + $page['title'] = $pageInfo['title']; + $page['background'] = $pageInfo['background']; + $page['share_title'] = $pageInfo['share_title']; + $page['share_image'] = tomedia($pageInfo['share_image']); + if ($menuid > 0) { + $menudata = Diy::getMenu($menuid)['data']; + } + if ($advid > 0) { + $advdata = Diy::BeOverdue($advid, false)['data']; + } + //信息拼装 + $data['page'] = $page;//本页面配置信息 + $data['menu'] = $menudata;//菜单配置信息 + $data['adv'] = $advdata;//广告配置信息 + return $data; + } + + /** + * Comment: 核销码发送 + * Author: wlf + * Date: 2021/08/13 10:04 + * @param $code + * @param $mobile + * @return array + */ + static function smsHXM($code,$goodname,$num = 1,$time,$mobile,$mid,$nickname='',$storename = '') { + global $_W; + $smsset = unserialize(pdo_getcolumn(PDO_NAME . "setting", array('key' => 'smsset','uniacid'=>$_W['uniacid']), 'value')); + $baseset = unserialize(pdo_getcolumn(PDO_NAME . "setting", array('key' => 'base','uniacid'=>$_W['uniacid']), 'value')); + if($smsset['dy_hxm'] > 0){ + $smses = pdo_get(PDO_NAME . "smstpl", array('uniacid' => $_W['uniacid'], 'id' => $smsset['dy_hxm'])); + $param = unserialize($smses['data']); + $nickname = !empty($nickname) ? $nickname : pdo_getcolumn(PDO_NAME.'member',array('id'=>$mid),'nickname'); + + $datas = array( + array('name' => '系统名称', 'value' => $baseset['name']), + array('name' => '版权信息', 'value' => $baseset['copyright']), + array('name' => '核销码', 'value' => $code), + array('name' => '昵称', 'value' => $nickname), + array('name' => '商品名', 'value' => $goodname), + array('name' => '数量', 'value' => $num), + array('name' => '过期时间', 'value' => $time), + array('name' => '店铺名', 'value' => $storename) + ); + foreach ($param as $d) { + $params[$d['data_temp']] = self::replaceTemplate($d['data_shop'], $datas); + } + return self::sendSms($smses, $params, $mobile,$mid); + } + } + + /** + * Comment: 验证码发送组一 + * Author: zzw + * Date: 2019/8/29 17:22 + * @param $code + * @param $mobile + * @return array + */ + static function smsSF($code, $mobile,$mid) { + global $_W; + $smsset = unserialize(pdo_getcolumn(PDO_NAME . "setting", array('key' => 'smsset','uniacid'=>$_W['uniacid']), 'value')); + $baseset = unserialize(pdo_getcolumn(PDO_NAME . "setting", array('key' => 'base','uniacid'=>$_W['uniacid']), 'value')); + $smses = pdo_get(PDO_NAME . "smstpl", array('uniacid' => $_W['uniacid'], 'id' => $smsset['dy_sf'])); + $nickname = pdo_getcolumn(PDO_NAME.'member',array('id'=>$mid),'nickname'); + $param = unserialize($smses['data']); + $datas = array( + array('name' => '系统名称', 'value' => $baseset['name']), + array('name' => '版权信息', 'value' => $baseset['copyright']), + array('name' => '验证码', 'value' => $code), + array('name' => '昵称', 'value' => $nickname) + ); + foreach ($param as $d) { + $params[$d['data_temp']] = self::replaceTemplate($d['data_shop'], $datas); + } + return self::sendSms($smses, $params, $mobile,$mid); + } + /** + * Comment: 验证码发送组二 + * Author: zzw + * Date: 2019/8/29 17:22 + * @param $str + * @param array $datas + * @return mixed + */ + static function replaceTemplate($str, $datas = array()) { + foreach ($datas as $d) { + $str = str_replace('【' . $d['name'] . '】', $d['value'], $str); + } + return $str; + } + /** + * Comment: 验证码发送组三 + * Author: zzw + * Date: 2019/8/29 17:22 + * @param $smstpl + * @param $param + * @param $mobile + * @param string $mid + * @return array + */ + static function sendSms($smstpl, $param, $mobile, $mid = '') { + global $_W; + $smsset = unserialize(pdo_getcolumn(PDO_NAME . "setting", array('key' => 'sms','uniacid'=>$_W['uniacid']), 'value')); + if ($smstpl['type'] == 'aliyun') { + include PATH_CORE . 'library/aliyun/Config.php'; + $profile = DefaultProfile::getProfile("cn-hangzhou", $smsset['note_appkey'], $smsset['note_secretKey']); + DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com"); + $acsClient = new DefaultAcsClient($profile); + m('aliyun/sendsmsrequest')->setSignName($smsset['note_sign']); + m('aliyun/sendsmsrequest')->setTemplateParam(json_encode($param)); + m('aliyun/sendsmsrequest')->setTemplateCode($smstpl['smstplid']); + m('aliyun/sendsmsrequest')->setPhoneNumbers($mobile); + $resp = $acsClient->getAcsResponse(m('aliyun/sendsmsrequest')); + $res = Util::object_array($resp); + if ($res['Code'] == 'OK') { + self::create_apirecord(-1, '', $mid, $mobile, 1, '阿里云身份验证'); + $recode = array("result" => 1); + } else { + $recode = array("result" => 2, "msg" => $res['Message']); + } + } else { + m('alidayu/topclient')->appkey = $smsset['note_appkey']; + m('alidayu/topclient')->secretKey = $smsset['note_secretKey']; + m('alidayu/smsnum')->setSmsType("normal"); + m('alidayu/smsnum')->setSmsFreeSignName($smsset['note_sign']); + m('alidayu/smsnum')->setSmsParam(json_encode($param)); + m('alidayu/smsnum')->setRecNum($mobile); + m('alidayu/smsnum')->setSmsTemplateCode($smstpl['smstplid']); + $resp = m('alidayu/topclient')->execute(m('alidayu/smsnum'), '6100e23657fb0b2d0c78568e55a3031134be9a3a5d4b3a365753805'); + $res = Util::object_array($resp); + if ($res['result']['success'] == 1) { + self::create_apirecord(-1, '', $mid, $mobile, 1, '阿里大于身份验证'); + $recode = array("result" => 1); + } else { + $recode = array("result" => 2, "msg" => $res['sub_msg']); + } + } + + + return $recode; + } + /** + * Comment: 验证码发送组四 + * Author: zzw + * Date: 2019/8/29 17:22 + * @param $sendmid + * @param string $sendmobile + * @param $takemid + * @param $takemobile + * @param $type + * @param $remark + */ + static function create_apirecord($sendmid, $sendmobile = '', $takemid, $takemobile, $type, $remark) { + global $_W; + $data = array( + 'uniacid' => $_W['uniacid'], + 'sendmid' => $sendmid, + 'sendmobile' => $sendmobile, + 'takemid' => $takemid, + 'takemobile' => $takemobile, + 'type' => $type, + 'remark' => $remark, + 'createtime' => time() + ); + pdo_insert(PDO_NAME . 'apirecord', $data); + } + /** + * Comment: 获取推荐商品信息列表 + * Author: zzw + * Date: 2019/8/13 17:11 + * @param string $num 获取的数量 + * @param int $type 当前商品类型:1=抢购 2=团购 3=拼团 4=大礼包 5=优惠券 6=折扣卡 7=砍价商品 + * @param int $id 当前商品id,存在时不会获取该商品 + * @return mixed + */ + public static function getRecommendGoods($num,$type = 0,$id = 0){ + global $_W,$_GPC; + //获取设置选项 + $set = Setting::wlsetting_read('base'); + $recommendType = $set['recommend_type'] ? : 0;//0=同商家同类型,1=同商家,2=同类型,3=随机 + //获取商品列表 + switch ($recommendType){ + case 0: $list = self::sameStoreType($num,$type,$id);break;//同商家同类型 + case 1: $list = self::sameStore($num,$type,$id);break;//同商家 + case 2: $list = self::sameType($num,$type,$id);break;//同类型 + case 3: $list = self::sameRandom($num,$type,$id);break;//随机 + } + //处理list + if(is_array($list) && count($list) > 0){ + if(count($list) > $num){ + //总数量大于需要数量 随机获取 + for($i=0;$i<$num;$i++){ + if(count($list) > 0){ + $key = array_rand($list); + $newList[$i] = self::getHomeGoods($list[$key]['type'], $list[$key]['id']); + //链接生成 + $newList[$i]['url'] = h5_url('pages/subPages/goods/index',['id'=>$newList[$i]['id'],'type'=>$newList[$i]['type']]); + unset($list[$key]); + unset($newList[$i]['user_list']); + unset($newList[$i]['user_num']); + unset($newList[$i]['stk']); + unset($newList[$i]['buy_percentage']); + unset($newList[$i]['is_vip']); + unset($newList[$i]['address']); + unset($newList[$i]['status']); + unset($newList[$i]['totalnum']); + unset($newList[$i]['storename']); + unset($newList[$i]['sid']); + unset($newList[$i]['starttime']); + unset($newList[$i]['endtime']); + unset($newList[$i]['vipprice']); + unset($newList[$i]['vipstatus']); + unset($newList[$i]['buy_limit']); + unset($newList[$i]['peoplenum']); + unset($newList[$i]['realsalenum']); + unset($newList[$i]['allsalenum']); + unset($newList[$i]['buy_num']); + unset($newList[$i]['user_limit_num']); + }else{ + continue; + } + } + }else{ + //总数量小于或者等于需要数量 直接返回 + foreach($list as $key => &$val){ + $val = self::getHomeGoods($val['type'], $val['id']); + //链接生成 + $val['url'] = h5_url('pages/subPages/goods/index',['id'=>$val['id'],'type'=>$val['type']]); + unset($val['user_list']); + unset($val['user_num']); + unset($val['stk']); + unset($val['buy_percentage']); + unset($val['is_vip']); + unset($val['address']); + unset($val['status']); + unset($val['totalnum']); + unset($val['storename']); + unset($val['sid']); + unset($val['starttime']); + unset($val['endtime']); + unset($val['vipprice']); + unset($val['vipstatus']); + unset($val['buy_limit']); + unset($val['peoplenum']); + unset($val['realsalenum']); + unset($val['allsalenum']); + unset($val['buy_num']); + unset($val['user_limit_num']); + } + $newList = $list; + } + }else{ + $newList = []; + } + + return $newList; + } + /** + * Comment: 推荐商品 —— 同商家同类型 + * Author: zzw + * Date: 2021/1/4 10:32 + * @param $num + * @param $type + * @param $id + * @return array|false|mixed + */ + private static function sameStoreType($num,$type,$id){ + global $_W,$_GPC; + //基本条件生成 + $where = " WHERE aid = {$_W['aid']} AND uniacid = {$_W['uniacid']} AND id != {$id} "; + //获取商户id、表信息 + switch ($type) { + case 1: + $sid = pdo_getcolumn(PDO_NAME."rush_activity",['id' => $id],'sid'); + $table = tablename(PDO_NAME."rush_activity"); + $where .= " AND sid = {$sid} AND status = 2"; + $field = " id,'1' as type "; + break;//抢购商品表 + case 2: + $sid = pdo_getcolumn(PDO_NAME."groupon_activity",['id' => $id],'sid'); + $table = tablename(PDO_NAME."groupon_activity"); + $where .= " AND sid = {$sid} AND status = 2"; + $field = " id,'2' as type "; + break;//团购商品表 + case 3: + $sid = pdo_getcolumn(PDO_NAME."fightgroup_goods",['id' => $id],'merchantid'); + $table = tablename(PDO_NAME."fightgroup_goods"); + $where .= " AND merchantid = {$sid} AND status = 2"; + $field = " id,'3' as type "; + break;//拼团商品表 + case 5: + $sid = pdo_getcolumn(PDO_NAME."couponlist",['id' => $id],'merchantid'); + $table = tablename(PDO_NAME."couponlist"); + $where .= " AND merchantid = {$sid} AND status = 2"; + $field = " id,'5' as type "; + break;//拼团商品表 + case 7: + $sid = pdo_getcolumn(PDO_NAME."bargain_activity",['id' => $id],'sid'); + $table = tablename(PDO_NAME."bargain_activity"); + $where .= " AND sid = {$sid} AND status = 2"; + $field = " id,'7' as type "; + break;//砍价商品表 + } + $list = pdo_fetchall("SELECT {$field} FROM ".$table.$where." LIMIT 100 "); + + return $list ? : []; + } + /** + * Comment: 推荐商品 —— 同商家 + * Author: zzw + * Date: 2021/1/4 11:17 + * @param $num + * @param $type + * @param $id + * @return array + */ + private static function sameStore($num,$type,$id){ + global $_W,$_GPC; + //获取商户id + switch ($type) { + case 1: + $sid = pdo_getcolumn(PDO_NAME."rush_activity",['id' => $id],'sid'); + break;//抢购商品表 + case 2: + $sid = pdo_getcolumn(PDO_NAME."groupon_activity",['id' => $id],'sid'); + break;//团购商品表 + case 3: + $sid = pdo_getcolumn(PDO_NAME."fightgroup_goods",['id' => $id],'merchantid'); + break;//拼团商品表 + case 5: + $sid = pdo_getcolumn(PDO_NAME."couponlist",['id' => $id],'merchantid'); + break;//拼团商品表 + case 7: + $sid = pdo_getcolumn(PDO_NAME."bargain_activity",['id' => $id],'sid'); + break;//砍价商品表 + } + //商品信息获取 + $rush = tablename(PDO_NAME."rush_activity");//抢购商品表 1 + $group = tablename(PDO_NAME."groupon_activity");//团购商品表 2 + $fight = tablename(PDO_NAME."fightgroup_goods");//拼团商品表 3 + $coupon = tablename(PDO_NAME."couponlist");//卡卷商品表 5 + $bargain = tablename(PDO_NAME."bargain_activity");//砍价商品表 7 + $where = " WHERE aid ={$_W['aid']} AND uniacid = {$_W['uniacid']} "; + $noId = " AND id != {$id} "; + //抢购商品信息 + if($type == 1) $rushList = pdo_fetchall("SELECT id,'1' as type FROM ".$rush.$where.$noId." AND status = 2 AND sid = {$sid} LIMIT 100"); + else $rushList = pdo_fetchall("SELECT id,'1' as type FROM ".$rush.$where." AND status = 2 AND sid = {$sid} LIMIT 100"); + //团购商品信息 + if($type == 2) $groupList = pdo_fetchall("SELECT id,'2' as type FROM ".$group.$where.$noId." AND status = 2 AND sid = {$sid} LIMIT 100"); + else $groupList = pdo_fetchall("SELECT id,'2' as type FROM ".$group.$where." AND status = 2 AND sid = {$sid} LIMIT 100"); + //拼团商品信息 + if($type == 3) $fightList = pdo_fetchall("SELECT id,'3' as type FROM ".$fight.$where.$noId." AND status = 2 AND merchantid = {$sid} LIMIT 100"); + else $fightList = pdo_fetchall("SELECT id,'3' as type FROM ".$fight.$where." AND status = 2 AND merchantid = {$sid} LIMIT 100"); + //卡卷商品信息 + if($type == 5) $couponList = pdo_fetchall("SELECT id,'5' as type FROM ".$coupon.$where.$noId." AND status = 2 AND merchantid = {$sid} LIMIT 100"); + else $couponList = pdo_fetchall("SELECT id,'5' as type FROM ".$coupon.$where." AND status = 2 AND merchantid = {$sid} LIMIT 100"); + //砍价商品信息 + if($type == 7) $bargainList = pdo_fetchall("SELECT id,'7' as type FROM ".$bargain.$where.$noId." AND status = 2 AND sid = {$sid} LIMIT 100"); + else $bargainList = pdo_fetchall("SELECT id,'7' as type FROM ".$bargain.$where." AND status = 2 AND sid = {$sid} LIMIT 100"); + #3、随机获取商品信息 + $list = array_merge($rushList,$groupList,$fightList,$couponList,$bargainList); + + return $list ? : []; + } + /** + * Comment: 推荐商品 —— 同类型 + * Author: zzw + * Date: 2021/1/4 11:21 + * @param $num + * @param $type + * @param $id + * @return array|false|mixed + */ + private static function sameType($num,$type,$id){ + global $_W,$_GPC; + //基本条件生成 + $where = " WHERE aid = {$_W['aid']} AND uniacid = {$_W['uniacid']} AND id != {$id} "; + //获取商户id、表信息 + switch ($type) { + case 1: + $table = tablename(PDO_NAME."rush_activity"); + $where .= " AND status = 2"; + $field = " id,'1' as type "; + break;//抢购商品表 + case 2: + $table = tablename(PDO_NAME."groupon_activity"); + $where .= " AND status = 2"; + $field = " id,'2' as type "; + break;//团购商品表 + case 3: + $table = tablename(PDO_NAME."fightgroup_goods"); + $where .= " AND status = 2"; + $field = " id,'3' as type "; + break;//拼团商品表 + case 5: + $table = tablename(PDO_NAME."couponlist"); + $where .= " AND status = 2"; + $field = " id,'5' as type "; + break;//拼团商品表 + case 7: + $table = tablename(PDO_NAME."bargain_activity"); + $where .= " AND status = 2"; + $field = " id,'7' as type "; + break;//砍价商品表 + } + $list = pdo_fetchall("SELECT {$field} FROM ".$table.$where." LIMIT 100 "); + + return $list ? : []; + } + /** + * Comment: 推荐商品 —— 随机 + * Author: zzw + * Date: 2021/1/4 11:26 + * @param $num + * @param $type + * @param $id + * @return array + */ + private static function sameRandom($num,$type,$id){ + global $_W,$_GPC; + //商品信息获取 + $rush = tablename(PDO_NAME."rush_activity");//抢购商品表 1 + $group = tablename(PDO_NAME."groupon_activity");//团购商品表 2 + $fight = tablename(PDO_NAME."fightgroup_goods");//拼团商品表 3 + $coupon = tablename(PDO_NAME."couponlist");//卡卷商品表 5 + $bargain = tablename(PDO_NAME."bargain_activity");//砍价商品表 7 + $where = " WHERE aid ={$_W['aid']} AND uniacid = {$_W['uniacid']} "; + $noId = " AND id != {$id} "; + //抢购商品信息 + if($type == 1) $rushList = pdo_fetchall("SELECT id,'1' as type FROM ".$rush.$where.$noId." AND status = 2 LIMIT 100"); + else $rushList = pdo_fetchall("SELECT id,'1' as type FROM ".$rush.$where." AND status = 2 LIMIT 100"); + //团购商品信息 + if($type == 2) $groupList = pdo_fetchall("SELECT id,'2' as type FROM ".$group.$where.$noId." AND status = 2 LIMIT 100"); + else $groupList = pdo_fetchall("SELECT id,'2' as type FROM ".$group.$where." AND status = 2 LIMIT 100"); + //拼团商品信息 + if($type == 3) $fightList = pdo_fetchall("SELECT id,'3' as type FROM ".$fight.$where.$noId." AND status = 2 LIMIT 100"); + else $fightList = pdo_fetchall("SELECT id,'3' as type FROM ".$fight.$where." AND status = 2 LIMIT 100"); + //卡卷商品信息 + if($type == 5) $couponList = pdo_fetchall("SELECT id,'5' as type FROM ".$coupon.$where.$noId." AND status = 2 LIMIT 100"); + else $couponList = pdo_fetchall("SELECT id,'5' as type FROM ".$coupon.$where." AND status = 2 LIMIT 100"); + //砍价商品信息 + if($type == 7) $bargainList = pdo_fetchall("SELECT id,'7' as type FROM ".$bargain.$where.$noId." AND status = 2 LIMIT 100"); + else $bargainList = pdo_fetchall("SELECT id,'7' as type FROM ".$bargain.$where." AND status = 2 LIMIT 100"); + #3、随机获取商品信息 + $list = array_merge($rushList,$groupList,$fightList,$couponList,$bargainList); + + return $list ? : []; + } + /** + * Comment: 开启事务处理 + * Author: zzw + * Date: 2019/8/15 11:47 + * @return bool + */ + public static function startTrans(){ + return pdo_query(" BEGIN "); + } + /** + * Comment: 提交事务处理 + * Author: zzw + * Date: 2019/8/15 11:47 + * @return bool + */ + public static function commit(){ + return pdo_query(" COMMIT "); + } + /** + * Comment: 事务回滚 + * Author: zzw + * Date: 2019/8/15 11:47 + * @return bool + */ + public static function rollback(){ + return pdo_query(" ROLLBACK "); + } + /** + * Comment: 获取二维码图片base64格式 + * Author: zzw + * Date: 2019/8/20 18:09 + * @param $url + * @return string + */ + public static function getQrCode($url){ + global $_W,$_GPC; + #1、长链接转短连接 + $result = Util::long2short($url); + if (!is_error($result)) $url = $result['short_url']; + #2、生成二维码 + require_once '../library/qrcode/QRcode.lib.php'; + ob_start(); + QRcode::png($url, false, QR_ECLEVEL_L, 16, 1,false,true); + $image_data = base64_encode(ob_get_contents()); + ob_end_clean(); + $image_data = "data:image/png;base64," . $image_data; + + return $image_data; + } + /** + * Comment: 获取对应渠道的access_token(默认:公众号) + * Author: zzw + * Date: 2019/10/24 10:55 + * @param bool $new 是否获取最新的token,默认false + * @param int $source 渠道:1=公众号(默认);2=h5;3=小程序 + * @return mixed + */ + public static function getAccessToken($new = false,$source = 1){ + global $_W; + $name = 'accesstoken_source'.$source; + session_start(); + #1、判断是否存在accessToken 存在则直接获取,不存在则从新获取 + $tokenCacheInfo = json_decode($_SESSION[$name],true); + if($tokenCacheInfo && time() < $tokenCacheInfo['end_time'] && !$new){ + $accessToken = $tokenCacheInfo['access_token']; + }else{ + //根据渠道获取配置信息 并且获取对应的信息 + switch ($source){ + case 1:case 2: + //获取配置信息 初始化EasyWeChat + $params = Util::object_array($_W['account']); + $config = [ + 'app_id' => trim($params['key']), + 'secret' => trim($params['secret']), + 'token' => trim($params['token']), + 'response_type' => 'array', + ]; + $app = Factory::officialAccount($config); + $tokenObj = $app->access_token; + $token = $tokenObj->getToken($new); // token 数组 token['access_token'] 字符串 + break; + case 3: + //获取配置信息 初始化EasyWeChat + $params = Setting::wlsetting_read('wxapp_config'); + $config = [ + 'app_id' => trim($params['appid']), + 'secret' => trim($params['secret']), + 'response_type' => 'array', + ]; + $app = Factory::miniProgram($config); + $tokenObj = $app->access_token; + $token = $tokenObj->getToken($new); // token 数组 token['access_token'] 字符串 + break; + } + //获取token信息 判断有效时间 + $accessToken = $token['access_token']; + $endTime = (time() + $token['expires_in']) - 100; + //记录进入session中 + $_SESSION[$name] = json_encode(['access_token'=>$accessToken,'end_time'=>$endTime]); + } + #2、返回accessToken + return $accessToken; + } + /** + * Comment: 判断当前商品是否显示分销助手/获取当前商品的分销佣金 + * Author: zzw + * Date: 2019/11/14 11:35 + * @param $type int 商品类型:1=抢购 2=团购 3=拼团 5=优惠券 7=砍价商品 8=积分商品 + * @param $id int 商品id + * @return mixed|array + */ + public static function getDisInfo($type,$id){ + global $_W; + #1、获取基本设置信息 + $data['is_show'] = $data['tipflag'] = 0;//是否显示分销助手 0=不显示;1=显示 + $disSet = $_W['wlsetting']['distribution']; + #1、判断是否开启分销商 判断当前商品是否参与分销 + $disflag = pdo_getcolumn(PDO_NAME.'distributor',array('id'=>$_W['wlmember']['distributorid']),'disflag'); + if($disSet['switch'] > 0) { + //获取分销商佣金比例 + if($_W['wlmember']['distributorid'] > 0){ + $lv_id = pdo_getcolumn(PDO_NAME."distributor",['id'=>$_W['wlmember']['distributorid']],'dislevel'); + $rate = pdo_getcolumn(PDO_NAME."dislevel",['id'=>$lv_id,'uniacid'=>$_W['uniacid']],'onecommission'); + } + //用户不是分销商 获取默认佣金比例 + if(!$lv_id){ + $defaleve = pdo_get(PDO_NAME."dislevel",['isdefault'=>1,'uniacid'=>$_W['uniacid']],['onecommission','id']); + $lv_id = $defaleve['id']; + $rate = $defaleve['onecommission']; + } + $rate = $rate ? $rate / 100 : 0; + //获取对应商品类型的佣金 商品类型:1=抢购 2=团购 3=拼团 5=优惠券 7=砍价商品 8=积分商品 + switch ($type) { + case 1: + $goods = pdo_get('wlmerchant_rush_activity',array('id' => $id),array('disarray','isdistri','price','optionstatus','isdistristatus')); + if($goods['isdistri'] != 1){ + if($goods['optionstatus'] > 0){ + $options = pdo_getall('wlmerchant_goods_option',array('type' => 1,'goodsid' => $id),array('price','disarray')); + foreach($options as &$opp){ + $disarray = self::mergeDisArray($opp['disarray'],$goods['disarray']); + $disarray = unserialize($disarray); + $opp['dismoney'] = self::getDismoney($disarray,$lv_id,$goods['isdistristatus'],$opp['price'],$rate); + } + $prices = array_column($options,'dismoney'); + $goods['commission'] = max($prices); + }else{ + $disarray = unserialize($goods['disarray']); + $goods['commission'] = self::getDismoney($disarray,$lv_id,$goods['isdistristatus'],$goods['price'],$rate); + } + } + break;//抢购 + case 2: + $goods = pdo_get('wlmerchant_groupon_activity',array('id' => $id),array('disarray','isdistri','price','optionstatus','isdistristatus')); + if($goods['isdistri'] != 1){ + if($goods['optionstatus'] > 0){ + $options = pdo_getall('wlmerchant_goods_option',array('type' => 3,'goodsid' => $id),array('price','disarray')); + foreach($options as &$opp){ + $disarray = self::mergeDisArray($opp['disarray'],$goods['disarray']); + $disarray = unserialize($disarray); + $opp['dismoney'] = self::getDismoney($disarray,$lv_id,$goods['isdistristatus'],$opp['price'],$rate); + } + $prices = array_column($options,'dismoney'); + $goods['commission'] = max($prices); + }else{ + $disarray = unserialize($goods['disarray']); + $goods['commission'] = self::getDismoney($disarray,$lv_id,$goods['isdistristatus'],$goods['price'],$rate); + } + } + break;//团购 + case 3: + $goods = pdo_get('wlmerchant_fightgroup_goods',array('id' => $id),array('disarray','isdistri','price','specstatus','isdistristatus')); + if($goods['isdistri'] != 1){ + if($goods['specstatus'] > 0){ + $options = pdo_getall('wlmerchant_goods_option',array('type' => 2,'goodsid' => $id),array('price','disarray')); + foreach($options as &$opp){ + $disarray = self::mergeDisArray($opp['disarray'],$goods['disarray']); + $disarray = unserialize($disarray); + $opp['dismoney'] = self::getDismoney($disarray,$lv_id,$goods['isdistristatus'],$opp['price'],$rate); + } + $prices = array_column($options,'dismoney'); + $goods['commission'] = max($prices); + }else{ + $disarray = unserialize($goods['disarray']); + $goods['commission'] = self::getDismoney($disarray,$lv_id,$goods['isdistristatus'],$goods['price'],$rate); + } + } + break;//拼团 + case 5: + $goods = pdo_get('wlmerchant_fightgroup_goods',array('id' => $id),array('disarray','isdistri','price','isdistristatus')); + if($goods['isdistri'] != 1){ + $disarray = unserialize($goods['disarray']); + $goods['commission'] = self::getDismoney($disarray,$lv_id,$goods['isdistristatus'],$goods['price'],$rate); + } + break;//优惠券 + case 7: + $goods = pdo_get('wlmerchant_bargain_activity',array('id' => $id),array('disarray','isdistri','price','isdistristatus')); + if($goods['isdistri'] != 1){ + $disarray = unserialize($goods['disarray']); + $goods['commission'] = self::getDismoney($disarray,$lv_id,$goods['isdistristatus'],$goods['price'],$rate); + } + break;//砍价商品 + case 8: + $sql = "SELECT CASE WHEN onedismoney > 0 THEN onedismoney + ELSE (`use_credit2`*{$rate}) + END as commission,isdistri FROM ".tablename(PDO_NAME.'consumption_goods')." WHERE id = {$id} "; + $goods = pdo_fetch($sql); + break;//积分商品 + } + $data['max_commission'] = sprintf("%.2f" , $goods['commission']); + //商品参与分销 + if($type == 8){ + $goods['isdistri'] = $goods['isdistri'] ? 0:1; + } + if($goods['isdistri'] != 1 && $data['max_commission'] > 0){ + $data['is_show'] = 1; + } + //判断用户 + if($disflag == 0){ + if($disSet['dishelp'] > 0){ + $data['tipflag'] = 1; + } + $data['is_show'] = 0; + } + //定制 + if(Customized::init('pocket140') > 0){ + $data['korea'] = 1; + }else{ + $data['korea'] = 0; + } + } + + return $data; + } + /** + * Comment: 获取应该的分销佣金 + * Author: wlf + * Date: 2020/11/25 18:48 + */ + public static function getDismoney($disarray,$lv_id,$isdistristatus,$price,$rate){ + global $_W; + if($disarray[$lv_id]['onedismoney'] > 0){ + if($isdistristatus > 0){ + $dismoney = $disarray[$lv_id]['onedismoney']; + }else{ + $dismoney = sprintf("%.2f" , $price * $disarray[$lv_id]['onedismoney'] /100); + } + }else{ + $dismoney = sprintf("%.2f" , $price * $rate); + } + return $dismoney; + } + /** + * Comment: 记录用户浏览信息 + * Author: zzw + * Date: 2019/11/14 14:34 + * @param $type int 商品类型:1=抢购 2=团购 3=拼团 4=大礼包 5=优惠券 6=折扣卡 7=砍价商品 8=积分商品 + * @param $id int 商品id + */ + public static function browseRecord($type, $id){ + global $_W; + #商品类型:1=抢购 2=团购 3=拼团 4=大礼包 5=优惠券 6=折扣卡 7=砍价商品 8=积分商品 + if($_W['mid']){ + $data = [ + 'type' => $type , + 'mid' => $_W['mid'] , + 'goods_id' => $id , + 'uniacid' => $_W['uniacid'] + ]; + #1、判断用户是否已经浏览当前商品 + $isBrowse = pdo_get(PDO_NAME."browse_record",$data); + if($isBrowse){ + //已经浏览 修改最近浏览时间 + pdo_update(PDO_NAME."browse_record",['updade_time'=>time()],$data); + }else{ + $data['create_time'] = time(); + $data['updade_time'] = time(); + pdo_insert(PDO_NAME."browse_record",$data); + } + } + } + /** + * Comment: 获取某个商品的浏览记录 + * Author: zzw + * Date: 2019/11/14 14:50 + * @param int $type 商品类型:1=抢购 2=团购 3=拼团 4=大礼包 5=优惠券 6=折扣卡 7=砍价商品 8=积分商品 + * @param int $id 商品id + * @param int $limit 查询的最大数量 + * @return array + */ + public static function getBrowseRecord($type, $id,$limit = 5){ + global $_W; + #1、条件生成 + //$where = " a.type = {$type} AND a.goods_id = {$id} AND a.uniacid = {$_W['uniacid']} "; + // if($_W['mid']) $where .= " AND mid != {$_W['mid']} "; + #1、获取当前商品的浏览记录 +// $sql = "SELECT a.id,b.avatar,b.nickname FROM ".tablename(PDO_NAME."browse_record") +// . " as a RIGHT JOIN ".tablename(PDO_NAME."member") +// ." as b ON a.mid = b.id WHERE {$where} ORDER BY a.updade_time DESC LIMIT {$limit}"; +// $list = pdo_fetchall($sql); + if(empty($_W['mid'])) $_W['mid'] = 0; + $list = pdo_fetchall("SELECT distinct mid FROM ".tablename(PDO_NAME."browse_record")."WHERE uniacid = {$_W['uniacid']} AND mid != {$_W['mid']} AND type = {$type} AND goods_id = {$id} ORDER BY updade_time DESC LIMIT {$limit}"); + if($list){ + foreach ($list as &$li){ + $member = pdo_get(PDO_NAME."member",array('id' => $li['mid']),array('avatar','nickname')); + $li['nickname'] = $member['nickname']; + $li['avatar'] = tomedia($member['avatar']); + } + } + return is_array($list) ? $list : []; + } + /** + * Comment: 获取某个商品或规格的销量 + * Author: wlf + * Date: 2020/06/28 18:30 + * @param int $plugin 商品类型:1=抢购 2=团购 3=拼团 4=卡券 5=砍价 6=活动 + * @param int $id 商品id + * @param int $specid 规格id + * @param int $type 类型: 1=已下单 2=已支付 3=已完成 + * @param int $mid 买家ID + * @param int $starttime 起始时间 + * @param int $endtime 结束时间 + * @param int $endtime 三方商品id + * @return array + */ + public static function getSalesNum($plugin,$id,$specid = 0,$type = 1,$mid = 0,$starttime = 0,$endtime = 0,$threeid = 0){ + global $_W; + if($threeid > 0){ + $salesnum = Pftapimod::getThreeSalesNum($plugin,$id,$type,$mid,$starttime,$endtime); + }else{ + if($plugin == 1){ + $orderwhere = " activityid = {$id}"; + $smallorderwhere = " gid = {$id} AND plugin = 'rush'"; + if($specid > 0){ + $orderwhere .= " AND optionid = {$specid}"; + $smallorderwhere .= " AND specid = {$specid}"; + } + if($mid > 0){ + $orderwhere .= " AND mid = {$mid}"; + $smallorderwhere .= " AND mid = {$mid}"; + } + if($starttime > 0){ + $orderwhere .= " AND createtime > {$starttime}"; + $smallorderwhere .= " AND createtime > {$starttime}"; + } + if($endtime > 0){ + $orderwhere .= " AND createtime < {$endtime}"; + $smallorderwhere .= " AND createtime < {$endtime}"; + } + if($type == 1){ + //未支付的 + $nopayorderwhere = $orderwhere." AND status = 0"; + $nopaynum = implode(pdo_fetch("SELECT sum(num) FROM " . tablename(PDO_NAME . "rush_order") . " WHERE {$nopayorderwhere}")); + //快递的 + $expresswhere = $orderwhere." AND expressid > 0 AND status IN (2,3,6,4,8,9)"; + $expressnum = implode(pdo_fetch("SELECT sum(num) FROM " . tablename(PDO_NAME . "rush_order") . " WHERE {$expresswhere}")); + //核销的 + $smallorderwhere .= " AND status != 3"; + $hexiaonum = pdo_fetchcolumn('SELECT count(id) FROM '.tablename('wlmerchant_smallorder')." WHERE {$smallorderwhere}"); + $salesnum = $nopaynum + $expressnum + $hexiaonum; + }else if($type == 2){ + //快递的 + $expresswhere = $orderwhere." AND expressid > 0 AND status IN (2,3,6,4,8,9)"; + $expressnum = implode(pdo_fetch("SELECT sum(num) FROM " . tablename(PDO_NAME . "rush_order") . " WHERE {$expresswhere}")); + //核销的 + $smallorderwhere .= " AND status != 3"; + $hexiaonum = pdo_fetchcolumn('SELECT count(id) FROM '.tablename('wlmerchant_smallorder')." WHERE {$smallorderwhere}"); + $salesnum = $expressnum + $hexiaonum; + }else if($type == 3){ + //快递的 + $expresswhere = $orderwhere." AND expressid > 0 AND status IN (2,3)"; + $expressnum = implode(pdo_fetch("SELECT sum(num) FROM " . tablename(PDO_NAME . "rush_order") . " WHERE {$expresswhere}")); + //核销的 + $smallorderwhere .= " AND status = 2"; + $hexiaonum = pdo_fetchcolumn('SELECT count(id) FROM '.tablename('wlmerchant_smallorder')." WHERE {$smallorderwhere}"); + $salesnum = $expressnum + $hexiaonum; + } + } + else{ + $orderwhere = " fkid = {$id}"; + $smallorderwhere = " gid = {$id}"; + switch($plugin){ + case 2: + $orderwhere .= " AND plugin = 'groupon'"; + $smallorderwhere .= " AND plugin = 'groupon'"; + break; + case 3: + $orderwhere .= " AND plugin = 'wlfightgroup'"; + $smallorderwhere .= " AND plugin = 'wlfightgroup'"; + break; + case 4: + $orderwhere .= " AND plugin = 'coupon'"; + $smallorderwhere .= " AND plugin = 'coupon'"; + break; + case 5: + $orderwhere .= " AND plugin = 'bargain'"; + $smallorderwhere .= " AND plugin = 'bargain'"; + break; + case 6: + $orderwhere .= " AND plugin = 'activity'"; + $smallorderwhere .= " AND plugin = 'activity'"; + break; + } + if($specid > 0){ + $orderwhere .= " AND specid = {$specid}"; + $smallorderwhere .= " AND specid = {$specid}"; + } + if($mid > 0){ + $orderwhere .= " AND mid = {$mid}"; + $smallorderwhere .= " AND mid = {$mid}"; + } + if($starttime > 0){ + $orderwhere .= " AND createtime > {$starttime}"; + $smallorderwhere .= " AND createtime > {$starttime}"; + } + if($endtime > 0){ + $orderwhere .= " AND createtime < {$endtime}"; + $smallorderwhere .= " AND createtime < {$endtime}"; + } + if($type == 1){ + //未支付的 + $nopayorderwhere = $orderwhere." AND status = 0"; + $nopaynum = implode(pdo_fetch("SELECT sum(num) FROM " . tablename(PDO_NAME . "order") . " WHERE {$nopayorderwhere}")); + $nopaynum = $nopaynum ? : 0; + //快递的 + $expresswhere = $orderwhere." AND expressid > 0 AND status IN (2,3,6,4,8,9)"; + $expressnum = implode(pdo_fetch("SELECT sum(num) FROM " . tablename(PDO_NAME."order") . " WHERE {$expresswhere}")); + $expressnum = $expressnum ? : 0; + //核销的 + $smallorderwhere .= " AND status != 3"; + $hexiaonum = pdo_fetchcolumn('SELECT count(id) FROM '.tablename('wlmerchant_smallorder')." WHERE {$smallorderwhere}"); + $hexiaonum = $hexiaonum ? : 0; + $salesnum = $nopaynum + $expressnum + $hexiaonum; + //拼团的特殊处理(拼团中的订单) + if($plugin == 3){ + $fightorderwhere = " a.fkid = {$id} AND a.fightstatus = 1 AND a.status = 1 AND b.status = 1"; + if($mid > 0){ + $fightorderwhere .= " AND a.mid = {$mid}"; + } + if($specid > 0){ + $fightorderwhere .= " AND a.specid = {$specid}"; + } + $fightnum = implode(pdo_fetch("SELECT sum(a.num) FROM " . tablename(PDO_NAME . "order"). " as a LEFT JOIN ".tablename(PDO_NAME . "fightgroup_group") . " as b ON a.fightgroupid = b.id WHERE {$fightorderwhere}")); + $salesnum = $salesnum + $fightnum; + } + }else if($type == 2){ + //快递的 + $expresswhere = $orderwhere." AND expressid > 0 AND status IN (2,3,6,4,8,9)"; + $expressnum = implode(pdo_fetch("SELECT sum(num) FROM " . tablename(PDO_NAME."order") . " WHERE {$expresswhere}")); + //核销的 + $smallorderwhere .= " AND status != 3"; + $hexiaonum = pdo_fetchcolumn('SELECT count(id) FROM '.tablename('wlmerchant_smallorder')." WHERE {$smallorderwhere}"); + $salesnum = $expressnum + $hexiaonum; + //拼团的特殊处理(拼团中的订单) + if($plugin == 3){ + $fightorderwhere = " a.fkid = {$id} AND a.fightstatus = 1 AND a.status = 1 AND b.status = 1"; + if($mid > 0){ + $fightorderwhere .= " AND a.mid = {$mid}"; + } + if($specid > 0){ + $fightorderwhere .= " AND a.specid = {$specid}"; + } + $fightnum = implode(pdo_fetch("SELECT sum(a.num) FROM " . tablename(PDO_NAME . "order"). " as a LEFT JOIN ".tablename(PDO_NAME . "fightgroup_group") . " as b ON a.fightgroupid = b.id WHERE {$fightorderwhere}")); + $salesnum = $salesnum + $fightnum; + } + }else if($type == 3){ + //快递的 + $expresswhere = $orderwhere." AND expressid > 0 AND status IN (2,3)"; + $expressnum = implode(pdo_fetch("SELECT sum(num) FROM " . tablename(PDO_NAME."order") . " WHERE {$expresswhere}")); + //核销的 + $smallorderwhere .= " AND status = 2"; + $hexiaonum = pdo_fetchcolumn('SELECT count(id) FROM '.tablename('wlmerchant_smallorder')." WHERE {$smallorderwhere}"); + $salesnum = $expressnum + $hexiaonum; + } + } + } + return $salesnum; + } + /** + * Comment: 检查商品当天是否可以购买 + * Author: wlf + * Date: 2020/09/21 17:48 + */ + public static function checkUseDateStatus($status = 0,$week = '',$day = ''){ + global $_W; + $time = time();//时间筛选 + $toWeek = date("w", $time);//当前时间的星期 + if ($toWeek == 0) $toWeek = 7;//星期天时值的转换 + $toDay = date("j", $time);//当前时间的日期 + if($status == 1){ + $week = unserialize($week); + if(in_array($toWeek,$week)){ + return 1; + } + }else if($status == 2){ + $day = unserialize($day); + if(in_array($toDay,$day)){ + return 1; + } + } + return 0; + } + /** + * Comment: 获取当前会员等级的会员价 + * Author: wlf + * Date: 2020/11/12 16:46 + */ + public static function getVipDiscount($viparray,$levelid = 0){ + global $_W; + $viparray = unserialize($viparray); + if($levelid == -1){ + $prices = array_column($viparray,'vipprice'); + $discount = max($prices); + }else{ + $discount = $viparray[$levelid]['vipprice']; + } + return $discount ? : 0; + } + /** + * Comment: 合并规格和商品会员减免数组 + * Author: wlf + * Date: 2020/11/20 14:13 + */ + public static function mergeVipArray($optionviparray,$goodsviparray){ + global $_W; + $optionviparray = unserialize($optionviparray); + $goodsviparray = unserialize($goodsviparray); + foreach($optionviparray as $optk => &$opvip){ + if($opvip['vipprice'] < 0.01){ + $opvip['vipprice'] = $goodsviparray[$optk]['vipprice']; + } + if($opvip['storeset'] < 0.01){ + $opvip['storeset'] = $goodsviparray[$optk]['storeset']; + } + } + $viparray = serialize($optionviparray); + return $viparray ? : 0; + } + /** + * Comment: 合并规格和商品会员分销数组 + * Author: wlf + * Date: 2020/11/25 11:48 + */ + public static function mergeDisArray($optiondisarray,$goodsdisarray){ + global $_W; + $optiondisarray = unserialize($optiondisarray); + $goodsdisarray = unserialize($goodsdisarray); + foreach($optiondisarray as $optk => &$opvip){ + if($opvip['onedismoney'] < 0.01){ + $opvip['onedismoney'] = $goodsdisarray[$optk]['onedismoney']; + } + if($opvip['twodismoney'] < 0.01){ + $opvip['twodismoney'] = $goodsdisarray[$optk]['twodismoney']; + } + } + $disarray = serialize($optiondisarray); + return $disarray ? : 0; + } + +} + + + diff --git a/addons/weliam_smartcity/core/class/util_csv.class.php b/addons/weliam_smartcity/core/class/util_csv.class.php new file mode 100644 index 0000000..9d22ed8 --- /dev/null +++ b/addons/weliam_smartcity/core/class/util_csv.class.php @@ -0,0 +1,137 @@ + $value) { + $output = array(); + $output[] = $value['id']; + $output[] = $value['name']; + echo iconv('utf-8', 'gbk//TRANSLIT', '"' . implode('","', $output) . "\"\n"); + } + } + + /** + * 导出CSV文件 + * @param array $data 数据 + * @param array $header_data 首行数据 + * @param string $file_name 文件名称 + * @return string + */ + static function export_csv_2($data = array(), $header_data = array(), $file_name = '') { + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment;filename=' . $file_name); + header('Cache-Control: max-age=0'); + $fp = fopen('php://output', 'a'); + if (!empty($header_data)) { + foreach ($header_data as $key => $value) { + $header_data[$key] = iconv('utf-8', 'gbk', $value); + } + fputcsv($fp, $header_data); + } + $num = 0; + //每隔$limit行,刷新一下输出buffer,不要太大,也不要太小 + $limit = 100000; + //逐行取出数据,不浪费内存 + $count = count($data); + if ($count > 0) { + for ($i = 0; $i < $count; $i++) { + $num++; + //刷新一下输出buffer,防止由于数据过多造成问题 + if ($limit == $num) { + ob_flush(); + flush(); + $num = 0; + } + $row = $data[$i]; + foreach ($row as $key => $value) { + $row[$key] = iconv('utf-8', 'gbk', $value); + } + fputcsv($fp, $row); + } + } + fclose($fp); + } + + /** + * 保存CSV文件 + * @param array $data 数据 + * @param array $header_data 首行数据 + * @param string $file_name 文件名称 + * @return string + */ + static function save_csv($data = array(), $header_data = array(), $file_name = '') { + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment;filename=' . $file_name); + header('Cache-Control: max-age=0'); + $csv_filename = PATH_ATTACHMENT . "public_file/" . MODULE_NAME . "/".$file_name; + $fp = fopen($csv_filename, "w"); + if (!empty($header_data)) { + foreach ($header_data as $key => $value) { + $header_data[$key] = iconv('utf-8', 'gbk', $value); + } + fputcsv($fp, $header_data); + } + $num = 0; + //每隔$limit行,刷新一下输出buffer,不要太大,也不要太小 + $limit = 100000; + //逐行取出数据,不浪费内存 + $count = count($data); + if ($count > 0) { + for ($i = 0; $i < $count; $i++) { + $num++; + //刷新一下输出buffer,防止由于数据过多造成问题 + if ($limit == $num) { + ob_flush(); + flush(); + $num = 0; + } + $row = $data[$i]; + foreach ($row as $key => $value) { + $row[$key] = iconv('utf-8', 'gbk', $value); + } + fputcsv($fp, $row); + } + } + fclose($fp); + } + +} diff --git a/addons/weliam_smartcity/core/class/wlPay.class.php b/addons/weliam_smartcity/core/class/wlPay.class.php new file mode 100644 index 0000000..62c6c85 --- /dev/null +++ b/addons/weliam_smartcity/core/class/wlPay.class.php @@ -0,0 +1,168 @@ +finance($openid, $money, $desc, $realname, $trade_no); + return $arr; + } + /** + * Comment: 退款操作 + * Author: zzw + * Date: 2019/9/29 10:55 + * @param $id int 订单ID + * @param $money float 退款金额 + * @param $remark string 退款原因 + * @param $plugin string 模块信息 + * @param int $type int 1微信端2web端3计划任务退款 + * @param $blendcredit float 退款到余额 + * @return mixed + * @throws \Yansongda\Pay\Exceptions\GatewayException + * @throws \Yansongda\Pay\Exceptions\InvalidArgumentException + * @throws \Yansongda\Pay\Exceptions\InvalidConfigException + * @throws \Yansongda\Pay\Exceptions\InvalidSignException + */ + static function refundMoney ($id , $money , $remark , $plugin , $type = 3,$blendcredit = 0){ + global $_W; + #1、初始申明 + $refund = false;//默认退款失败 + #2、基本订单信息获取 + switch ($plugin) { + case 'rush' : + $order = pdo_get(PDO_NAME.'rush_order' ,[ 'id' => $id] ,['paytype','orderno','aid','sid']); + break; + case 'attestation' : + $order = pdo_get(PDO_NAME.'attestation_money' ,[ 'id' => $id] ,['paytype','orderno']); + break; + case 'mobilerecharge' : + $order = pdo_get(PDO_NAME.'mrecharge_order' ,[ 'id' => $id] ,['paytype','orderno']); + break; + default : + $order = pdo_get(PDO_NAME.'order' , [ 'id' => $id] ,['paytype','orderno','aid','sid','paylogid']); + break; + } + #3、获取支付信息 + if(empty($order['orderno'])){ + $res['status'] = false; + $res['message'] = '订单不存在'; + } + if($plugin == 'citydelivery'){ + $payInfo = pdo_get(PDO_NAME."paylogvfour",['tid'=>$order['orderno']] ,['tid','transaction_id','fee','blendcredit','mid','module','uniacid','type']); + if(empty($payInfo)){ + $payInfo = pdo_get(PDO_NAME."paylogvfour",['plid'=>$order['paylogid']] ,['tid','transaction_id','fee','blendcredit','mid','module','uniacid','type']); + } + $order['orderno'] = $payInfo['tid']; + }else{ + $payInfo = pdo_get(PDO_NAME."paylogvfour",['tid'=>$order['orderno']] ,['transaction_id','fee','mid','blendcredit','module','uniacid','type']); + if(empty($payInfo)){ + $payInfo = pdo_get(PDO_NAME."paylog",['tid'=>$order['orderno']] ,['transaction_id','fee','mid','module','uniacid','type']); + } + } + if(empty($payInfo)){ + $payInfo = ['fee' => 0]; + } + $orderInfo = array_merge($order,$payInfo);//合并两个数组的信息 + #4、退款金额判断 + if ($money > $orderInfo['fee']) { + $errMsg = '退款金额大于实际支付金额,无法退款'; + } else if ($money > 0) { + $orderInfo['refund_money'] = $money;//记录退款金额 + } else if ($blendcredit < 0.01){ + $money = $orderInfo['fee'];//退款金额为支付金额(全额退款) + if($orderInfo['blendcredit'] > 0){ + $money = sprintf("%.2f",$money - $orderInfo['blendcredit']); + $blendcredit = $orderInfo['blendcredit']; + } + } + //支付返现判断 + if(p('cashback')){ + //判断当前订单是否存在返现订单 + $cashOrderInfo = pdo_get(PDO_NAME."cashback",['order_id'=>$id,'plugin'=>$plugin,'status'=>1]); + if($cashOrderInfo){ + //退款比例计算 + $proportion = sprintf("%.2f",$money / $orderInfo['fee']);//比例 + $cashRefund = sprintf("%.2f",$cashOrderInfo['money'] * $proportion);//取消的返现金额 + //数据判断 余额是否大于当前取消返现金额 + $member = Member::wl_member_get($cashOrderInfo['mid'],['id','uid','cash_back_money']);//用户当前余额获取 + if($member['credit2'] < $cashRefund) return ['status'=>false,'message'=>'退款失败;余额不足,不能取消返现金额!']; + } + } + #5、插入退款记录信息 + $refundRecord = [ + 'sid' => $orderInfo['sid'] , + 'orderno' => $orderInfo['orderno'] , + 'mid' => $orderInfo['mid'] , + 'aid' => $orderInfo['aid'] , + 'paytype' => $orderInfo['type'] , + 'transid' => $orderInfo['transaction_id'] , + 'type' => $type , + 'orderid' => $id , + 'payfee' => $orderInfo['fee'] , + 'refundfee' => sprintf("%.2f",$money + $blendcredit), + 'uniacid' => $orderInfo['uniacid'] , + 'remark' => $remark , + 'plugin' => $plugin + ]; + $refundid = pdo_getcolumn(PDO_NAME.'refund_record',$refundRecord,'id'); + if(empty($refundid)){ + $refundRecord['createtime'] = TIMESTAMP; + $refundRecord['status'] = 0; + pdo_insert(PDO_NAME . 'refund_record' , $refundRecord); + $refundid = pdo_insertid(); + } + #6、判断退款成功失败信息 + $pluginArray = [ 'rush','housekeep' , 'vip' ,'mobilerecharge', 'citydelivery','yellowpage','coupon' ,'attestation','merchant' , 'wlfightgroup' , 'activity' , 'groupon' , 'bargain' ]; + if (!in_array($plugin , $pluginArray)) { + pdo_update(PDO_NAME . 'refund_record' , [ 'errmsg' => '退款订单插件' . $plugin . '错误' ] , [ 'id' => $refundid]); + $errMsg = '退款订单插件' . $plugin . '错误'; + } + if ($money <= 0 && $blendcredit <= 0 && $orderInfo['paytype'] != 6 ) { + pdo_update(PDO_NAME . 'refund_record' , ['errmsg' => '退款金额小于0'] , ['id' => $refundid]); + $errMsg = '退款金额小于0'; + } + if (empty($orderInfo['transaction_id']) && $orderInfo['type'] == 'wechat') { + pdo_update(PDO_NAME . 'refund_record' ,['errmsg' => '无微信订单号'] , ['id' => $refundid]); + $errMsg = '微信订单无微信订单号'; + } + if($orderInfo['module'] == 'weliam_merchant'){ + $errMsg = '此订单为旧版系统支付订单,无法在V4版本进行退款,请前往旧版系统退款'; + pdo_update(PDO_NAME . 'refund_record' ,['errmsg' => $errMsg] , ['id' => $refundid]); + } + #7、符合退款要求,开始退款操作 + if (empty($errMsg)){ + if($orderInfo['paytype'] == 6){ + $result = ['error' => 1]; + }else{ + $result = Refund::refundInit($orderInfo['orderno'],$money,$blendcredit); //调用方法进行退款操作 + } + } + #8、返回退款结果 + if ($result['error']) { + pdo_update(PDO_NAME . 'refund_record' , [ 'status' => 1 ] , [ 'id' => $refundid ]); + $res['status'] = true; + $res['message'] = '退款成功'; + //支付返现退款操作 + if(p('cashback') && $cashOrderInfo){ + //修改用户返现金额 + pdo_update(PDO_NAME."member",['cash_back_money'=>sprintf("%.2f",$member['cash_back_money'] - $cashRefund)],['id'=>$cashOrderInfo['mid']]); + //修改用户余额信息 + Member::credit_update_credit2($cashOrderInfo['mid'],-$cashRefund,'订单['.$order['orderno'].']退款取消返现金额'); + //修改返现记录信息 + pdo_update(PDO_NAME."cashback",['refund_money'=>sprintf("%.2f",$cashOrderInfo['refund_money'] + $cashRefund)],['id'=>$cashOrderInfo['id']]); + } + } else { + $errMsg = $result['msg'] ? : $errMsg; + if (empty($errMsg)) $errMsg = '未知错误,请联系管理员'; + pdo_update(PDO_NAME . 'refund_record' ,['errmsg' => $errMsg] , ['id' => $refundid]); + $res['status'] = false; + $res['message'] = $errMsg; + } + return $res; + } + + + +} diff --git a/addons/weliam_smartcity/core/common/Im.php b/addons/weliam_smartcity/core/common/Im.php new file mode 100644 index 0000000..f15e850 --- /dev/null +++ b/addons/weliam_smartcity/core/common/Im.php @@ -0,0 +1,292 @@ +model('attachment'); +//获取基本设置信息 +$set = pdo_get(PDO_NAME.'setting',['key' => 'im_set'],['value']); +if (is_array($set)) $set = iunserializer($set['value']); +$port = $set['port']; +$cert = $set['pem_path']; +$key = $set['key_path']; +//$cert = 'D:/Software/phpstudy_pro/Extensions/Nginx1.15.11/conf/ssl/www.locatiom.smartcity.com.pem'; +//$key = 'D:/Software/phpstudy_pro/Extensions/Nginx1.15.11/conf/ssl/www.locatiom.smartcity.com.key'; + +//开始进行通讯处理 +use Workerman\Worker; +require_once PATH_VENDOR.'workerman/workerman/Autoloader.php'; +//创建一个Worker监听端口,使用websocket协议通讯 +$context = [ + // 更多ssl选项请参考手册 http://php.net/manual/zh/context.ssl.php + 'ssl' => [ + 'local_cert' => $cert, + 'local_pk' => $key, + 'verify_peer' => false, + // 'allow_self_signed' => true, //如果是自签名证书需要开启此选项 + ] +]; +$socket = new Worker("websocket://0.0.0.0:{$port}",$context); +$socket->transport = 'ssl'; +//$socket->count = 4;//启动x个进程对外提供服务 +$socket->onWorkerStart = function($worker) { + // 将db实例存储在全局变量中(也可以存储在某类的静态成员中) + global $db; + require '../../../../data/config.php'; + $master = $config['db']['master']; + $db = new \Workerman\MySQL\Connection($master['host'],$master['port'], $master['username'], $master['password'],$master['database']); +}; +//接收数据并且进行对应的处理 +$socket->onMessage = function ($connection,$data) { + //处理信息 + (new handle($data,$connection))->handleData(); +}; +//当某个链接断开时触发 +$socket->onClose = function ($connection) { + + +}; +//方法类 +class handle{ + private $data,//当前接收的消息 + $sendId,//发送方唯一id + $receiveId,//接收方唯一id + $idsFile = PATH_CORE."common/im_ids.php"; + + public function __construct($data,$connection){ + global $_W; + //data信息处理 + $data = json_decode($data,true); + $_W['uniacid'] = $data['i'] ? : $data['uniacid'];//公众号id + $_W['aid'] = $data['aid'];//代理商id + $_W['source'] = $data['source'];//渠道 + //通讯信息获取 + $data['send_id'] = intval($data['send_id']) ? : $_W['mid'];//当前发送信息的用户的id(商户id) + $data['receive_id'] = intval($data['receive_id']);//接受消息的用户id(商户id) + $data['page'] = intval($data['page']) ? : 1;//页码 + $data['page_index'] = intval($data['page_index']) ? : 10;//每页的数量 + $this->sendId = $data['send_id'].'_'.$data['receive_id']; + $this->receiveId = $data['receive_id'].'_'.$data['send_id']; + $this->data = $data; + //通讯节点处理 + $this->setIds($this->sendId,$connection->id); + } + /** + * Comment: 处理接收的data信息 + * Author: zzw + * Date: 2021/3/8 11:44 + * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + */ + public function handleData(){ + global $_W,$db; + //接受信息 + $data = $this->data; + //判断是否给自己发送消息 + if($data['send_id'] == $data['receive_id'] && $data['send_type'] == $data['receive_type']) $this->socketSend($this->sendId,"不能给自己发送信息哦",5); + //判断通讯类型,进行对应的操作。信息类型:1=系统信息,2=通信信息,3=断开链接,4=通讯记录,5=错误抛出 + if($data['im_type'] == 2){ + //记录信息到表 + $newData['uniacid'] = $_W['uniacid']; + $newData['send_id'] = $data['send_id'];//发送方id + $newData['send_type'] = $data['send_type'];//发送方类型(1=用户;2=商户) + $newData['receive_id'] = $data['receive_id'];//接收人id + $newData['receive_type'] = $data['receive_type'];//接收人类型(1=用户;2=商户) + $newData['create_time'] = time();//发送时间(建立时间) + $newData['type'] = $data['type'];//内容类型:0=文本内容(可带表情),1=图片信息(不可带表情),2=视频信息(不可带表情),3=名片信息(不可带表情),4=简历信息(不可带表情),5=其他信息(不可带表情) + $newData['content'] = base64_encode($data['content']);//发送内容 + $newData['plugin'] = $data['plugin'];//发送内容 + $table = trim(tablename(PDO_NAME."im"),'`'); + $db->insert($table)->cols($newData)->query(); + //判断接收方是否在线 在线进行推送 + $memberInfo = $db->select('nickname,avatar') + ->from(trim(tablename(PDO_NAME."member"),'`')) + ->where("id={$newData['send_id']}") + ->row(); + $sendInfo = [ + 'avatar' => tomedia($memberInfo['avatar']), + 'content' => $data['content'], + 'create_time' => $newData['create_time'], + 'date_time' => date('Y-m-d H:i:s',$newData['create_time']), + 'is_my' => 1,//0=自己发送的消息,1=对方发送的消息 + 'nickname' => $memberInfo['nickname'], + 'receive_id' => $newData['receive_id'], + 'send_id' => $newData['send_id'], + 'type' => $newData['type'] + ]; + + $this->socketSend($this->receiveId,'即时通讯信息',2,$data['type'],['list'=>[$sendInfo]]); + }else if ($data['im_type'] == 3){ + //断开链接 + //$this->log(['断开',$data]); + $this->deleteIds($this->sendId); + }else if($data['im_type'] == 4){ + //获取通讯记录信息 + $sendInfo['send_id'] = $data['send_id'] ;//发送方id + $sendInfo['send_type'] = $data['send_type'] ;//发送方类型(1=用户;2=商户) + $sendInfo['receive_id'] = $data['receive_id'] ;//接收人id + $sendInfo['receive_type'] = $data['receive_type'] ;//接收人类型(1=用户;2=商户) + //$list = Im::imRecord($data['page'],$data['page_index'],$sendInfo); + $pageStart = $data['page'] * $data['page_index'] - $data['page_index']; + //条件生成 + $where = " as a WHERE a.uniacid = {$_W['uniacid']} AND + ( + (a.send_id = {$sendInfo['send_id']} AND a.send_type = {$sendInfo['send_type']} AND a.receive_id = {$sendInfo['receive_id']} AND a.receive_type = {$sendInfo['receive_type']}) + OR + (a.send_id = {$sendInfo['receive_id']} AND a.send_type = {$sendInfo['receive_type']} AND a.receive_id = {$sendInfo['send_id']} AND a.receive_type = {$sendInfo['send_type']}) + )"; + if($data['plugin']) $where .= " AND a.plugin = {$data['plugin']} "; + else $where .= " AND (a.plugin = '' OR a.plugin IS NULL)"; + //要查询的字段生成 + $field = " a.id,a.send_id,a.`receive_id`,a.content,a.create_time,a.type,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%S') as date_time, + CASE {$sendInfo['receive_id']} WHEN a.send_id THEN 1 + ELSE 0 + END as is_my, + CASE a.`send_type` + WHEN 1 THEN (SELECT `nickname` FROM ".tablename(PDO_NAME."member")." WHERE `id` = a.`send_id`) + ELSE (SELECT storename FROM ".tablename(PDO_NAME."merchantdata")." WHERE `id` = a.`send_id` ) + END as nickname, + CASE a.`send_type` + WHEN 1 THEN (SELECT `avatar` FROM ".tablename(PDO_NAME."member")." WHERE `id` = a.`send_id`) + ELSE (SELECT logo FROM ".tablename(PDO_NAME."merchantdata")." WHERE `id` = a.`send_id` ) + END as avatar"; + #4、获取总页数 + $totalSql = "SELECT COUNT(*) as total FROM ".tablename(PDO_NAME."im").$where; + $total = $db->single($totalSql); + $list['total'] = ceil($total / $data['page_index']); + #5、获取当前页列表信息 + $listSql = "SELECT {$field} FROM ".tablename(PDO_NAME."im").$where + ." ORDER BY a.create_time DESC LIMIT {$pageStart},{$data['page_index']} "; + $list['list'] = $db->query($listSql); + foreach($list['list'] as $key => &$val) { + $val['avatar'] = tomedia($val['avatar']); + if(is_base64($val['content'])) $val['content'] = base64_decode($val['content'],true); + } + //修改信息为已读 + /*if(is_array($list['list']) && count($list['list']) > 0) { + //条件生成 + $ids = array_column($list['list'],'id'); + if(!empty($sendInfo['send_id'])) $where = " receive_id = {$sendInfo['send_id']} "; + else $where = " receive_id = {$_W['mid']} "; + if(count($ids) > 1){ + $idStr = implode(',',$ids); + $where .= " AND id IN ({$idStr}) "; + }else{ + $where .= " AND id = {$ids[0]} "; + } + #2、修改内容 + $updateSql = "UPDATE ".tablename(PDO_NAME."im")." SET is_read = 1 WHERE ".$where; + $db->query($updateSql); + }*/ + $where = " send_id = {$sendInfo['receive_id']} AND send_type = {$sendInfo['receive_type']} AND receive_id = {$sendInfo['send_id']} AND receive_type = {$sendInfo['send_type']} AND is_read = 0 "; + $sql = " UPDATE ".tablename(PDO_NAME."im")." SET is_read = 1 WHERE {$where} "; + $db->query($sql); + //信息排序 + $sortArr = array_column($list['list'], 'create_time'); + array_multisort($sortArr, SORT_ASC, $list['list']); + //获取聊天对象的昵称 1=用户;2=商户 + if($sendInfo['receive_type'] == 1) { + $nicknameSql = "SELECT nickname FROM ".tablename(PDO_NAME."member")." WHERE id = {$sendInfo['receive_id']} "; + $list['receive_name'] = $db->single($nicknameSql); + } else { + $nicknameSql = "SELECT storename FROM ".tablename(PDO_NAME."merchantdata")." WHERE id = {$sendInfo['receive_id']} "; + $list['receive_name'] = $db->single($nicknameSql); + } + $this->socketSend($this->sendId,'通讯记录',4,5,$list); + } + } + /** + * Comment: 发送数据给移动端 + * Author: zzw + * Date: 2021/3/8 11:44 + * @param $id + * @param $content + * @param int $imType + * @param int $type + * @param array $other + */ + public function socketSend($id,$content,$imType = 2,$type = 0,$other = []){ + global $socket; + //生成需要发送的信息 + $data = [ + 'im_type' => $imType,//信息类型:1=系统信息,2=通信信息,3=断开链接,4=通讯记录,5=错误抛出 + //具体通讯信息 + 'type' => $type,//内容类型:0=文本内容(可带表情),1=图片信息(不可带表情),2=视频信息(不可带表情),3=名片信息(不可带表情),4=简历信息(不可带表情),5=其他信息(数组) + 'content' => $content,//文本内容 + 'other' => $other,//其他信息(名片信息|简历信息) + ]; + //发送信息 + $connectionId = $this->getIds($id); + if($connectionId > 0){ + $connection = $socket->connections[$connectionId]; + + if(is_object($connection)) $connection->send(json_encode($data,JSON_UNESCAPED_UNICODE)); + } + } + /** + * Comment: 日志记录 + * Author: zzw + * Date: 2021/3/8 11:44 + * @param $content + * @param string $title + */ + public function log($content,$title = '日志'){ + Util::wl_log('socket',PATH_MODULE . "log/",$content,$title,false); + } + /** + * Comment: 获取ids数组信息 + * Author: zzw + * Date: 2021/3/12 10:21 + * @param int $key 发送者id + * @return array|bool|Memcache|mixed|Redis|string + */ + public function getIds($id = 0){ + //获取文件读写权限 + if(!is_readable($this->idsFile)) chmod($this->idsFile,0755); + //获取文件内容 + $data = file_get_contents($this->idsFile); + $data = json_decode($data,true); + if($id > 0) return $data[$id]; + else return $data; + } + /** + * Comment: 设置id缓存 + * Author: zzw + * Date: 2021/3/12 10:21 + * @param int $key 发送者id + * @param int $val 通讯节点id + */ + public function setIds($key,$val){ + header('Content-Type:text/html;charset=utf-8'); + //数组转字符串 + $data = $this->getIds(); + $data[$key] = $val; + $idStr = json_encode($data,JSON_UNESCAPED_UNICODE); + file_put_contents($this->idsFile, print_r($idStr, true)); + } + /** + * Comment: 删除id缓存 + * Author: zzw + * Date: 2021/3/18 11:13 + * @param $id + */ + public function deleteIds($id){ + header('Content-Type:text/html;charset=utf-8'); + //数组转字符串 + $data = $this->getIds(); + unset($data[$id]); + $idStr = json_encode($data,JSON_UNESCAPED_UNICODE); + file_put_contents($this->idsFile, print_r($idStr, true)); + } + + + + +} +//运行 +Worker::runAll(); diff --git a/addons/weliam_smartcity/core/common/api.php b/addons/weliam_smartcity/core/common/api.php new file mode 100644 index 0000000..86e900d --- /dev/null +++ b/addons/weliam_smartcity/core/common/api.php @@ -0,0 +1,16 @@ +model('attachment'); + +//判断公众号相关 +$_W['siteroot'] = str_replace(array('/addons/'.MODULE_NAME.'/core/common','/addons/weliam_smartcity/core/common'), '', $_W['siteroot']); +$_W['method'] = $method = !empty($_GPC['do']) ? $_GPC['do'] : 'index'; +$_W['aid'] = intval($_GPC['aid']); +$_W['uniacid'] = intval($_GPC['i']); +$_W['apitoken'] = trim($_GPC['token']); +if(empty($_W['uniacid'])) { + $_W['uniacid'] = intval($_GPC['weid']); +} +$_W['uniaccount'] = $_W['account'] = uni_fetch($_W['uniacid']); +if(empty($_W['uniaccount'])) { + header('HTTP/1.1 404 Not Found'); + header("status: 404 Not Found"); + exit; +} +if (!empty($_W['uniaccount']['endtime']) && TIMESTAMP > $_W['uniaccount']['endtime']) { + exit('抱歉,您的公众号服务已过期,请及时联系管理员'); +} +$_W['acid'] = $_W['uniaccount']['acid']; +$isdel_account = pdo_get('account', array('isdeleted' => 1, 'acid' => $_W['acid'])); +if (!empty($isdel_account)) { + exit('指定公众号已被删除'); +} +$_W['attachurl'] = attachment_set_attach_url(); + +//寻找对应方法 +require IA_ROOT . "/addons/'.MODULE_NAME.'/plugin/openapi/openapi.php"; +$instance = new Weliam_smartcityModuleOpenapi(); +if (!method_exists($instance, $method)) { + $method = 'doPage' . ucfirst($method); +} +$instance -> $method(); + + +class Openapi { + + public function __construct(){ + global $_W; + $settings = Setting::wlsetting_read('apiset'); + if ($_W['apitoken'] != $settings['token']) { + $this->result(-1, '无效Token'); + } + } + + public function result($errno, $message, $data = '') { + exit(json_encode(array( + 'errno' => $errno, + 'message' => $message, + 'data' => $data, + ))); + } + +} diff --git a/addons/weliam_smartcity/core/common/task.php b/addons/weliam_smartcity/core/common/task.php new file mode 100644 index 0000000..e2233a4 --- /dev/null +++ b/addons/weliam_smartcity/core/common/task.php @@ -0,0 +1,23 @@ + queueMain($on); \ No newline at end of file diff --git a/addons/weliam_smartcity/core/common/uniapp.php b/addons/weliam_smartcity/core/common/uniapp.php new file mode 100644 index 0000000..ea5a1de --- /dev/null +++ b/addons/weliam_smartcity/core/common/uniapp.php @@ -0,0 +1 @@ +model('attachment'); //判断公众号相关 $_W['siteroot'] = str_replace(array('/addons/'.MODULE_NAME.'/core/common','/addons/weliam_smartcity/core/common','/addons/weliam_smartcity','/addons/'.MODULE_NAME), '', $_W['siteroot']); $_W['method'] = $method = !empty($_GPC['do']) ? $_GPC['do'] : 'index'; $_W['uniacid'] = intval($_GPC['i']); if (empty($_W['uniacid'])) { $_W['uniacid'] = intval($_GPC['weid']); } $_W['uniaccount'] = $_W['account'] = uni_fetch($_W['uniacid']); if (empty($_W['uniaccount'])) { header('HTTP/1.1 404 Not Found'); header("status: 404 Not Found"); exit; } $_W['acid'] = $_W['uniaccount']['acid']; $_W['attachurl'] = attachment_set_attach_url(); $_W['wlsetting'] = Setting::wlsetting_load(); $_W['source'] = $_GPC['source'] ? intval($_GPC['source']) : 1;//1=公众号(默认);2=h5;3=小程序 $_W['aid'] = intval($_GPC['aid'])?intval($_GPC['aid']):0;//代理id //寻找对应方法 $plugin = trim($_GPC['p']); if (empty($plugin)) { require IA_ROOT . "/addons/".MODULE_NAME."/uniapp.php"; $instance = new Weliam_smartcityModuleUniapp(); if (!method_exists($instance, $method)) { $instance->securityVerification($method);//调用方法进行安全验证 } } else { $uniapp = new Uniapp(); //判断文件是否存在 $filePath = IA_ROOT . "/addons/".MODULE_NAME."/plugin/" . $plugin . "/uniapp.php"; if (!file_exists($filePath)) $filePath = IA_ROOT . "/addons/".MODULE_NAME."/api/" . ucfirst($plugin) . ".php"; if (!file_exists($filePath)) $uniapp->renderError('错误的请求 - file does not exist! '); require $filePath; //判断类是否存在 $className = ucfirst($plugin) . 'ModuleUniapp'; if (class_exists($className)) { $instance = new $className(); if (method_exists($instance, $method)) $instance->$method(); else $uniapp->renderError('错误的请求 - '.$instance.':'.$method.'Method does not exist! '); } else { $uniapp->renderError('错误的请求 - '.$className.'Non-existent classes! '); } } class Uniapp { public $disSetting;//分销设置信息 #0=操作成功;1=操作失败;2=需要登录;3=未开通地区;4=隐藏信息,仅开发者查看使用;5=小程序端必须登录才能访问的接口 public function __construct() { global $_W, $_GPC; //判断平台状态 $accinfo = Util::object_array($_W['account']); if($accinfo['endtime'] > 0 && $accinfo['endtime'] < time() ){ $this->renderError('平台已过期,无法访问。'); } //获取用户信息 $token = trim($_GPC['token']); if (strlen($token) == 32) { $res = Login::generateToken($token); if($res['errno'] == '401' && $_W['source'] == 1){ file_put_contents(PATH_DATA . "login_error222.log", var_export($token, true) . PHP_EOL, FILE_APPEND); $this->reLogin(); }else if($res['errno'] == '205'){ wl_setcookie('user_token',$res['code'],86400); $res = Login::generateToken($res['message']); $token = $res['message']; }else{ $token = $res['message']; } if(!empty($token)){ $user = Member::wl_member_get(['tokey' => $token]); if(!empty($user['encodename'])){ $user['nickname'] = base64_decode($user['encodename']); } if($user['blackflag']>0){ $tips = $_W['wlsetting']['userset']['black_desc'] ? $_W['wlsetting']['userset']['black_desc'] : '您被禁止访问,如有疑问请联系客服'; $this->renderError($tips); } if (is_array($user) && !empty($user)) { $_W['wlmember'] = $user; $_W['mid'] = $user['id']; } } } //目前默认 公共接口为不需要进行登录判断 仅判断各个模块下面的私有接口 if (!empty($_GPC['p'])) { $api = $_GPC['p'] . '/' . $_GPC['do'];//将要请求的接口名称 $list = $this->noLoginApiList($_W['source']);//获取不需要登录的接口名称列表 #1、获取当前访问的接口信息 if (!in_array($api, $list) ) { if(empty($_W['mid'])){ $this->reLogin(); } } } if(empty($_W['mid']) && $_GPC['do'] == 'Poster'){ $this->reLogin(); } //获取基本信息 $this->disSetting = $_W['wlsetting']['distribution']; //分销商关系绑定 // $head_id = intval($_GPC['head_id']); // if ($head_id > 0 && $_W['mid'] > 0 && p('distribution') && $_W['mid'] != $head_id) { // Distribution::addJunior($head_id, $_W['mid']); // } } /** * Comment: 操作成功输出方法 * Author: zzw * Date: 2019/7/16 9:35 * @param string $message * @param array $data */ public function renderSuccess($message = '操作成功', $data = [],$nodo = 0) { global $_W,$_GPC; //JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK,JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT $content = json_encode(['errno' => 0, 'message' => $message, 'data' => $data]); //if($_GPC['do'] != 'getGoodsExtensionInfo' && $_GPC['do'] != 'transferDetail'){ if(empty($nodo)){ //开启链接处理功能一 目前主要兼容未在#号前添加问号(?)的链接 //$content = str_replace('weliam_smartcity\/h5\/#\/', 'weliam_smartcity\/h5\/?#\/', $content); $prefixPaths = explode('#/', h5_url('pages/mainPages/index/diypage'))[0] . '#/'; //处理富文本超链接一 带有href跳转的链接转换为指定字符串 $temporaryUrl = 'this_is_temporary_url_info'; $hrefPath = json_encode('href="'.$prefixPaths); $content = str_replace(trim($hrefPath, '"'), $temporaryUrl, $content); //开启链接处理功能二 目前主要兼容删除?#/前面的链接 只保留page路径信息及参数信息 $prefixPaths = explode('#/', h5_url('pages/mainPages/index/diypage'))[0] . '#/'; $jsonPath = json_encode($prefixPaths); $content = str_replace(trim($jsonPath, '"'), '', $content); //处理富文本超链接二 将字段字符串转为超链接前缀 $temporaryUrl = 'this_is_temporary_url_info'; $content = str_replace($temporaryUrl, trim($hrefPath, '"'), $content); } exit($content); } /** * Comment: 操作失败返回内容 * Author: zzw * Date: 2019/7/16 9:36 * @param string $message * @param array $data */ public function renderError($message = '操作失败', $data = []) { global $_W; //JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK,JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT $content = json_encode(['errno' => 1, 'message' => $message, 'data' => $data]); //是否开启链接处理功能一 目前主要兼容未在#号前添加问号(?)的链接 $state1 = $_REQUEST['debug'] ? true : true; // if ($state1) { // $content = str_replace('weliam_smartcity\/h5\/#\/', 'weliam_smartcity\/h5\/?#\/', $content); // } //是否开启链接处理功能二 目前主要兼容删除?#/前面的链接 只保留page路径信息及参数信息 $state2 = $_REQUEST['debug'] ? true : true; if ($state2) { $prefixPaths = explode('#/', h5_url('pages/mainPages/index/diypage'))[0] . '#/'; $jsonPath = json_encode($prefixPaths); $content = str_replace(trim($jsonPath, '"'), '', $content); } exit($content); } /** * Comment: 登录错误,重新登录 * Author: zzw * Date: 2019/7/29 16:40 * @param string $message */ public function reLogin() { global $_W; $errno = ($_W['source'] == 3) ? 5 : 2; exit(json_encode(array( 'errno' => $errno,//2 'message' => '请先登录', 'data' => [ 'weChat_login' => $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=entry&m=' . MODULE_NAME . '&do=wechatsign', ], ))); } /** * Comment: 隐藏信息,仅开发者查看使用 * Author: zzw * Date: 2019/11/1 10:07 * @param string $message * @param array $data */ public function debugging($message = '维护中....', $data = []) { exit(json_encode(array( 'errno' => 4, 'message' => $message, 'data' => $data, ))); } /** * Comment: 不需要登录验证的接口列表 * Author: zzw * Date: 2019/7/29 16:24 * @return array */ protected function noLoginApiList($source) { $list = ['member/login', 'headline/HeadlineList','headline/HeadlineInfo','headline/getComment', 'distribution/getSetting', 'store/homeList', 'rush/homeList', 'rush/specialInfo', 'wlcoupon/homeList' , 'halfcard/homeList', 'wlfightgroup/homeList', 'pocket/homeList', 'groupon/homeList', 'bargain/homeList', 'consumption/homeList', 'halfcard/packageList', 'member/getRegisterSet', 'member/register', 'member/userLogin', 'member/resetPassword','citycard/homeList','citycard/cardHome','citycard/cardInfo', 'redpack/newRedPackInfo','pocket/commentList','redpack/festivalRedPackDesc','citydelivery/finishOrder','goods/getGoodsCateList','recruit/homeList', 'dating/homeList','im/infoList','Im/getSetInfo','dating/homeList','dating/dynamicList','vehicle/homeList','recruit/enterpriseList']; if($source == 3 || $source == 2){ //小程序不需要登录的接口 $newList = [ 'store/chargeList','store/detail','store/getStoreGoods','store/getStoreComment','store/getStoreDynamic', 'store/cateList','goods/getGoodsDetail', 'member/memberInfo','helper/helpInfo','helper/helpInfo','helper/problemList', 'helper/detail', 'distribution/applyCondition', 'citycard/cardShare','halfcard/memberCardHome','halfcard/cardList', 'consumption/homeInfo', 'consumption/detail', 'pocket/homeInfo','pocket/classList','pocket/receivingRecords','pocket/getPocketStore','store/userShopList', 'pocket/infoList','pocket/detail','pocket/shareNum','pocket/getDisclaimer','wxapp/liveList','bargain/detail','housekeep/getStorelist', 'housekeep/getServicelist','housekeep/getArtificerlist','housekeep/getDemandlist','housekeep/getNewStorelist','recruit/recruitDesc','wlfightgroup/groupDetail','yellowpage/homeInfo','yellowpage/homeList', 'yellowpage/cateList','luckydraw/drawPageInfo','luckydraw/getShareCode' ]; $list = array_merge($newList,$list); } return $list; } } \ No newline at end of file diff --git a/addons/weliam_smartcity/core/common/yunAsyNotify.php b/addons/weliam_smartcity/core/common/yunAsyNotify.php new file mode 100644 index 0000000..063837f --- /dev/null +++ b/addons/weliam_smartcity/core/common/yunAsyNotify.php @@ -0,0 +1,31 @@ + $transaction_id] , ['status','tid','uniacid','plugin' ,'plid','fee','payfor']); +$_W['uniacid'] = $paylog['uniacid']; +$tid = $paylog['tid']; +if($paylog['status'] == 0){ + $successInfo = [ + 'type' => 2 ,//支付方式 + 'tid' => $paylog['tid'],//订单号 + 'transaction_id' => $transaction_id, + 'time' => $yunorderinfo['paidTime'], + ]; + PayResult::main($successInfo);//调用方法处理订单 + exit('SUCCESS'); +}else{ + exit('SUCCESS'); +} diff --git a/addons/weliam_smartcity/core/common/yunnotify.php b/addons/weliam_smartcity/core/common/yunnotify.php new file mode 100644 index 0000000..bbbc258 --- /dev/null +++ b/addons/weliam_smartcity/core/common/yunnotify.php @@ -0,0 +1,113 @@ + $transaction_id] , ['status','tid','uniacid','plugin' ,'plid','fee','payfor']); +$_W['uniacid'] = $paylog['uniacid']; +$tid = $paylog['tid']; +//订单信息查询 +$type = strtolower($paylog['plugin']); +$payfor = strtolower($paylog['payfor']); +$data = []; +$data['plugin'] = $type; +if ($type == 'rush') { + $order = pdo_get('wlmerchant_rush_order' , ['orderno' => $tid] , ['id' ,'aid', 'num' , 'activityid' , 'actualprice']); + $data['price'] = $order['actualprice']; + $data['goodsname'] = pdo_getcolumn(PDO_NAME.'rush_activity',array('id'=>$order['activityid']),'name'); + $detail_url = h5_url('pages/subPages/orderList/orderDetails/orderDetails',['orderid'=>$order['id'],'plugin'=>'rush']); +} +else if ($type == 'merchant' && $payfor == 'halfcard') { + $order = pdo_get('wlmerchant_halfcard_record' , ['orderno' => $tid] , ['id','aid', 'num' , 'price']); + $data['price'] = $order['price']; + $data['goodsname'] = '会员开通/续费'; +} +else if ($type == 'attestation') { + $order = pdo_get('wlmerchant_attestation_money' , ['orderno' => $tid] , ['id' , 'num' , 'money' , 'type']); + $data['price'] = $order['money']; + $data['type'] = $order['type']; + $data['goodsname'] = '认证保证金缴纳'; +}else { + $order = pdo_get('wlmerchant_order' , ['orderno' => $tid] , ['id','aid' , 'recordid' , 'num' , 'fkid' , 'plugin' , 'fightstatus' , 'paidprid' , 'price' , 'vip_card_id' , 'expressid']); + $data['price'] = $order['price']; + if ($order['plugin'] == 'wlfightgroup') { + $data['goodsname'] = pdo_getcolumn(PDO_NAME.'fightgroup_goods',array('id'=>$order['fkid']),'name'); + $detail_url = h5_url('pages/subPages/orderList/orderDetails/orderDetails',['orderid'=>$order['id'],'plugin'=>'wlfightgroup']); + }else if ($order['plugin'] == 'coupon') { + $data['goodsname'] = pdo_getcolumn(PDO_NAME.'couponlist',array('id'=>$order['fkid']),'title'); + $detail_url = h5_url('pages/subPages/orderList/orderDetails/orderDetails',['orderid'=>$order['id'],'plugin'=>'coupon']); + }else if($data['plugin'] == 'citydelivery'){ + $data['price'] = $paylog['fee']; + $order = pdo_get('wlmerchant_order' , ['paylogid' => $paylog['plid']] , ['id' , 'recordid' , 'num' , 'fkid' , 'plugin' , 'fightstatus' , 'paidprid' , 'price' , 'vip_card_id' , 'expressid']); + $detail_url = h5_url('pages/subPages/orderList/orderDetails/orderDetails',['orderid'=>$order['id'],'plugin'=>'citydelivery']); + $data['goodsname'] = '同城配送商品'; + }else if ($order['plugin'] == 'groupon') { + $data['goodsname'] = pdo_getcolumn(PDO_NAME.'groupon_activity',array('id'=>$order['fkid']),'name'); + $detail_url = h5_url('pages/subPages/orderList/orderDetails/orderDetails',['orderid'=>$order['id'],'plugin'=>'groupon']); + }else if ($order['plugin'] == 'bargain') { + $data['goodsname'] = pdo_getcolumn(PDO_NAME.'bargain_activity',array('id'=>$order['fkid']),'name'); + $detail_url = h5_url('pages/subPages/orderList/orderDetails/orderDetails',['orderid'=>$order['id'],'plugin'=>'bargain']); + }else if ($order['plugin'] == 'pocket') { + $data['goodsname'] = '掌上信息付费'; + }else if ($order['plugin'] == 'store') { + $data['goodsname'] = '商户入驻'; + }else if ($order['plugin'] == 'distribution') { + $data['goodsname'] = '分销商申请'; + }else if ($order['plugin'] == 'consumption') { + $data['goodsname'] = pdo_getcolumn(PDO_NAME.'consumption_goods',array('id'=>$order['fkid']),'title'); + }else if ($order['plugin'] == 'member') { + $data['goodsname'] = '余额充值'; + }else if ($order['plugin'] == 'halfcard') { + $data['goodsname'] = '在线买单'; + }else if ($order['plugin'] == 'halfcard') { + $data['goodsname'] = '在线买单'; + }else if ($order['plugin'] == 'citycard') { + $data['goodsname'] = '同城名片付费'; + }else if ($order['plugin'] == 'yellowpage') { + $data['goodsname'] = '黄页114付费'; + }else if ($order['plugin'] == 'recruit') { + $data['goodsname'] = '招聘求职付费'; + }else if ($order['plugin'] == 'dating') { + $data['goodsname'] = '相亲交友付费'; + }else if ($order['plugin'] == 'vehicle') { + $data['goodsname'] = '顺风车付费'; + }else if ($order['plugin'] == 'housekeep') { + $data['goodsname'] = '家政服务付费'; + } +} +$data['num'] = $order['num'] ? : 1; +if(empty($data['goodsname'])){ + $data['goodsname'] = '其他付费项目'; +} +$_W['aid'] = $order['aid'] ? : 0; +//系统信息查询 +$_W['attachurl_remote'] = attachment_set_attach_url(); +$base = Setting::wlsetting_read('base'); +$base['logo'] = tomedia($base['logo']); +$home_url = h5_url('pages/mainPages/index/index'); +if(empty($detail_url)){ + $detail_url = h5_url('pages/subPages/orderList/orderList',['type'=>10]); +} +//处理订单回调 +if($paylog['status'] == 0){ + $successInfo = [ + 'type' => 2 ,//支付方式 + 'tid' => $paylog['tid'],//订单号 + 'transaction_id' => $transaction_id, + 'time' => $_GPC['t'], + ]; + PayResult::main($successInfo);//调用方法处理订单 +} + + +include wl_template('utility/ahrcu'); \ No newline at end of file diff --git a/addons/weliam_smartcity/core/function/global.func.php b/addons/weliam_smartcity/core/function/global.func.php new file mode 100644 index 0000000..298fbef --- /dev/null +++ b/addons/weliam_smartcity/core/function/global.func.php @@ -0,0 +1,1346 @@ + MODULE_NAME), 'mid'); + $moduleid = empty($moduleid) ? '000000' : sprintf("%06d", $moduleid); + $uniontid = date('YmdHis') . $moduleid . random(8, 1); + //生成商户订单号 + return $uniontid; +} + +/** + * model类实例函数 + * + * @access public + * @name m + * @param $filename 文件夹/文件名 + * @return 对象 + */ +function m($filename = '') { + static $_modules = array(); + if (strpos($filename, '/') > -1) { + [$file, $name] = explode('/', $filename); + } else { + die('文件结构不正确,正确结构(文件夹名/文件名)'); + } + if (isset($_modules[$file][$name])) + return $_modules[$file][$name]; + $model = PATH_CORE . "library/" . $file . "/" . $name . '.lib.php'; + if (!is_file($model)) { + die('Library Class ' . $filename . ' Not Found!'); + } + require $model; + $class_name = ucfirst($name); + //调用该类 + $_modules[$file][$name] = new $class_name(); + return $_modules[$file][$name]; +} +/** + * Comment: 判断 当前模块权限 + * Author: zzw + * Date: 2020/11/16 11:24 + * @param string $name + * @return bool + */ +function p($name = '') { + global $_W; + //默认拥有当前模块权限 + $status = true; + //判断文件是否存在 不存在则无权限 + $model = PATH_PLUGIN . strtolower($name) . '/config.xml'; + if (!is_file($model)) $status = false; + + + return $status; +} + +/** + * Comment: 判断 当前公众号是否有此权限 + * Author: wlf + * Date: 2021/09/26 14:36 + * @param string $name + * @return bool + */ +function uniacid_p($name = '') { + global $_W; + $status = 1; + $pp = p($name); + if($pp){ + $plugin = pdo_getcolumn(PDO_NAME.'perm_account',array('uniacid'=>$_W['uniacid']),'plugins'); + $plugin = unserialize($plugin); + if(!empty($plugin)){ + if(!in_array($name,$plugin)){ + $status = 0; + } + } + }else{ + $status = 0; + } + return $status; +} + +/** + * Comment: 判断 当前代理是否有此权限 + * Author: wlf + * Date: 2021/09/26 15:06 + * @param string $name + * @return bool + */ +function agent_p($name = ''){ + global $_W; + $status = 1; + $up = uniacid_p($name); + if($up > 0){ + //获取代理分组权限信息 + if($_W['aid'] > 0){ + $groupid = pdo_getcolumn(PDO_NAME.'agentusers',array('id'=>$_W['aid']),'groupid'); + if($groupid > 0){ + $plugin = pdo_getcolumn(PDO_NAME.'agentusers_group',array('id'=>$groupid),'package'); + $plugin = unserialize($plugin); + if(!empty($plugin)){ + if(!in_array($name,$plugin)){ + $status = 0; + } + } + } + } + }else{ + $status = 0; + } + return $status; +} + +/** + * Comment: 判断 当前商户是否有此权限 + * Author: wlf + * Date: 2021/09/26 15:19 + * @param string $name + * @return bool + */ +function store_p($name = '',$sid){ + global $_W; + $status = 1; + $ap = agent_p($name); + if($ap > 0){ + $groupid = pdo_getcolumn(PDO_NAME.'merchantdata',array('id'=>$sid),'groupid'); + if($groupid > 0){ + $plugin = pdo_getcolumn(PDO_NAME.'chargelist',array('id'=>$groupid),'authority'); + $plugin = unserialize($plugin); + if(!empty($plugin)){ + if(!in_array($name,$plugin)){ + $status = 0; + } + } + } + }else{ + $status = 0; + } + return $status; +} + + +/** + * Comment: 判断当前模块是否存在权限 + * Author: zzw + * Date: 2020/11/16 19:45 + * @param $name + * @return bool + */ +function j($name){ + //TODO 当前权限判断功能需要优化 请求内容和判断内容过多 导致加载缓慢 当时为了方便直接使用的其他方法的返回结果在重新判断 可以重写判断不适用其他方法返回结果进行重新判断 + //默认拥有当前模块权限 + $status = true; + //判断是否存在权限 + if(is_agent()) $wholePlugin = App::get_apps(0, 'agent');//全部插件 + else if(is_store()) $wholePlugin = App::get_apps(0, 'store');//全部插件 + else $wholePlugin = App::get_apps(0, 'account');//全部插件 + $wholeIdents = array_column($wholePlugin,'ident');//插件昵称 + $plugins = App::get_cate_plugins('agent');//当前代理商户拥有权限的插件 + $channel = array_column($plugins['channel']['plugins'],'ident'); + $market = array_column($plugins['market']['plugins'],'ident'); + $interact = array_column($plugins['interact']['plugins'],'ident'); + $expand = array_column($plugins['expand']['plugins'],'ident'); + $help = array_column($plugins['help']['plugins'],'ident'); + $idents = array_merge((array)$channel, (array)$market, (array)$interact, (array)$expand, (array)$help); + //当前插件存在权限处理 当前代理无当前权限 + if(is_agent() || is_store()) { + if(!in_array($name,$wholeIdents) || !in_array($name,$idents)) $status = false; + }else{ + if(!in_array($name,$wholeIdents)) $status = false; + } + + return $status; +} +/** + * 权限检测函数 + * + * @access public + * @name checkLimit + * @param $roleid 角色id + * @param $arr 检测位置 + * @return false|true + */ +function checkLimit($roleid, $arr = array()) { + $allPerms = Perms::allParms(); + if (empty($allPerms[$arr['p']][$arr['ac']][$arr['do']])) + return true; + $limits = Perms::getRolePerms($roleid); + if (empty($limits) || empty($arr)) + return false; + if (empty($limits[$arr['p']][$arr['ac']][$arr['do']])) + return false; + return true; +} + +if ((!function_exists('url') && defined('IN_UNIAPP')) || !function_exists('url') && defined('IS_INDEPENDENT')) { + function url($segment, $params = array(), $noredirect = false) { + return murl($segment, $params, $noredirect); + } +} + + +/** + * web地址生成 + * + * @access public + * @name getUrlByWeb + * @param $segment do/ac/op + * @param $params 参数 + * @return string + */ +function web_url($segment, $params = array()) { + global $_W; + [$p, $ac, $do] = explode('/', $segment); + if (is_store()) { + $url = $_W['siteroot'] . 'web/citystore.php?'; + } else if (is_agent()) { + $url = $_W['siteroot'] . 'web/cityagent.php?'; + } else if (is_staff()) { + $url = $_W['siteroot'] . 'web/citysys.php?'; + } else { + $url = $_W['siteroot'] . 'web/index.php?c=site&a=entry&m=' . MODULE_NAME . '&'; + } + if (!empty($p)) { + $url .= "p={$p}&"; + } + if (!empty($ac)) { + $url .= "ac={$ac}&"; + } + $do = !empty($do) ? $do : 'index'; + if (!empty($do)) { + $url .= "do={$do}&"; + } + if (!empty($params)) { + $queryString = http_build_query($params, '', '&'); + $url .= $queryString; + } + return $url; +} + +/** + * APP地址生成 + * + * @access public + * @name app_url + * @param $segment do/ac/op + * @param $params 参数 + * @return string + */ +function app_url($segment, $params = array(), $addhost = TRUE) { + global $_W; + [$p, $ac, $do] = explode('/', $segment); + + if ($addhost == TRUE) { + $_W['siteroot'] = str_replace(array('/addons/' . MODULE_NAME,'/addons/weliam_smartcity','/core/common', '/addons/bm_payms'), '', $_W['siteroot']); + $url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=entry&m=' . MODULE_NAME . '&'; + } else { + $url = './index.php?i=' . $_W['uniacid'] . '&c=entry&m=' . MODULE_NAME . '&'; + } + + if (!empty($p)) { + $url .= "p={$p}&"; + } + if (!empty($ac)) { + $url .= "ac={$ac}&"; + } + $do = !empty($do) ? $do : 'index'; + if (!empty($do)) { + $url .= "do={$do}&"; + } + if (!empty($params)) { + $queryString = http_build_query($params, '', '&'); + $url .= $queryString; + } + if (substr($url, -1) == '&') { + $url = substr($url, 0, strlen($url) - 1); + } + + return $url; +} + +/** + * Comment: H5链接地址生成 强制生成为https链接 + * Author: zzw + * Date: 2019/7/2 16:37 + * @param string $page + * @param array $params + * @param $addhost + * @return bool|string + */ +function h5_url($page, $params = array(), $catalog = 'h5',$aid=0) { + global $_W; + $_W['siteroot'] = str_replace(array('/addons/' . MODULE_NAME,'/addons/weliam_smartcity','/plugin/pftapimod','/core/common', '/addons/bm_payms','/addons/weliam_smartcity/payment','/addons/'.MODULE_NAME.'/payment','/payment'), '', $_W['siteroot']); + $_W['siteroot'] = str_replace(':19080','',$_W['siteroot']); + $is_have = strpos($page, '?'); + if ($is_have) { + $info = explode('?', $page); + $page = $info[0]; + $paramStr = $info[1]; + //判断参数是否存在i 存在则删除 + foreach (explode('&', $paramStr) as $key => $value) { + if ($value{0} == 'i' && $value{1} == '=') { + $paramStr = str_replace($value . '&', '', $paramStr); + break; + } + } + } + if(empty($aid)){ + $aid = $_W['aid']; + } + if(empty($catalog)){ + $catalog = 'h5'; + } + $url = $_W['siteroot'] . 'addons/' . MODULE_NAME . '/' . $catalog . '/#/' . $page . "?i=" . $_W['uniacid'] . '&aid=' .$aid. '&' . $paramStr; + $url = trim($url, "&"); + if (!empty($params)) { + $queryString = http_build_query($params, '', '&'); + $url .= '&' . trim($queryString, "&"); + } + + $domain = Cloud::wl_syssetting_read('jumpadmin'); + if(!empty($domain['targetDmain'])){ + foreach($domain['targetDmain'] as $tar){ + $url = str_replace($tar,$domain['endDmain'],$url); + } + } + + return $url; +} + +function is_store() { + if (defined('IN_STORE')) { + return true; + } + return false; +} +function is_agent() { + if (defined('IN_WEB')) { + return true; + } + return false; +} +function is_staff() { + if (defined('IN_STAFF')) { + return true; + } + return false; +} +if (!function_exists('is_wxapp')) { + function is_wxapp() { + global $_W; + if (!empty($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'miniProgram')) { + return true; + } + + return false; + } + +} + +if (!function_exists('is_weixin')) { + function is_weixin() { + global $_W; + + if (empty($_SERVER['HTTP_USER_AGENT']) || ((strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows Phone') === false))) { + return false; + } + + return true; + } + +} + +if (!function_exists('is_h5app')) { + function is_h5app() { + if (!empty($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'CK 2.0')) { + return true; + } + + return false; + } + +} + +if (!function_exists('is_ios')) { + function is_ios() { + if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')) { + return true; + } + + return false; + } + +} + +if (!function_exists('is_mobile')) { + function is_mobile() { + $useragent = $_SERVER['HTTP_USER_AGENT']; + if (preg_match('/(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i', substr($useragent, 0, 4))) { + return true; + } + + return false; + } + +} + +function ifilter_url($params) { + return wl_filter_url($params); +} + +function wl_setcookie($key, $value, $expire = 0, $httponly = false) { + global $_W; + $expire = $expire != 0 ? (TIMESTAMP + $expire) : 0; + $secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0; + $value = is_array($value) ? base64_encode(json_encode($value)) : $value; + return setcookie('weliam_' . $key, $value, $expire, $_W['config']['cookie']['path'], $_W['config']['cookie']['domain'], $secure, $httponly); +} + +function wl_getcookie($key) { + $sting = $_COOKIE['weliam_' . $key]; + $data = json_decode(base64_decode($sting), true); + return is_array($data) ? $data : $sting; +} + +//2019.9.4 默认:1=失败,0=成功 +function wl_json($errno = 0, $message = '', $data = '') { + exit(json_encode(array('errno' => $errno, 'message' => $message, 'data' => $data))); +} + +function wl_new_method($plugin, $controller, $method, $catalog = 'app') { + global $_W; + $dir = IA_ROOT . '/addons/' . MODULE_NAME . '/'; + $file = $dir . $catalog . '/controller/' . $plugin . '/' . $controller . '.ctrl.php'; + if (!is_file($file)) { + $file = $dir . 'plugin/' . $plugin . '/' . $catalog . '/controller/' . $controller . '.ctrl.php'; + } + if (($catalog == 'web' || $catalog == 'sys') && !is_file($file)) { + $_W['catalog'] = $catalog = ($catalog == 'web') ? 'sys' : 'web'; + $file = $dir . $catalog . '/controller/' . $plugin . '/' . $controller . '.ctrl.php'; + if (!is_file($file)) { + $file = $dir . 'plugin/' . $plugin . '/' . $catalog . '/controller/' . $controller . '.ctrl.php'; + } + } + if (is_file($file)) { + require_once $file; + } else { + trigger_error("访问的模块 {$plugin} 不存在.", E_USER_WARNING); + } + $class = ucfirst($controller) . '_WeliamController'; + if (class_exists($class, false)) { + $instance = new $class(); + } else { + $instance = new $controller(); + } + if ($catalog == 'app') { + $instance->inMobile = TRUE; + } + if (!method_exists($instance, $method)) { + trigger_error('控制器 ' . $controller . ' 方法 ' . $method . ' 未找到!'); + } + + $instance->$method(); + exit(); +} + +/** + * html文件引入,生成缓存 + * + * @access public + * @name wl_template + * @param $filename 文件 + * @return string + */ +function wl_template($filename, $flag = '') { + global $_W; + $name = MODULE_NAME; + $catalog = strstr($filename, 'common/') ? 'web' : $_W['catalog'] ? : 'web'; + $source = IA_ROOT . "/addons/{$name}/{$catalog}/view/default/{$filename}.html"; + $compile = IA_ROOT . "/data/tpl/{$catalog}/{$name}/{$_W['plugin']}/{$catalog}/view/default/{$filename}.tpl.php"; + if (!is_file($source)) $source = IA_ROOT . "/addons/{$name}/plugin/{$_W['plugin']}/{$catalog}/view/default/{$filename}.html"; + if (!is_file($source)) exit("Error: template source '{$filename}' is not exist!!!"); + if (!is_file($compile) || filemtime($source) > filemtime($compile)) Template::wl_template_compile($source, $compile, true); + if ($flag == TEMPLATE_FETCH) { + extract($GLOBALS, EXTR_SKIP); + ob_end_flush(); + ob_clean(); + ob_start(); + include $compile; + $contents = ob_get_contents(); + ob_clean(); + return $contents; + } else if ($flag == 'template') { + extract($GLOBALS, EXTR_SKIP); + return $compile; + } else { + return $compile; + } + +/* $name = MODULE_NAME; + if (defined('IN_SYS') || defined('IN_WEB')) { + $catalog = strstr($filename, 'common/') ? 'web' : $_W['catalog']; + $source = IA_ROOT . "/addons/{$name}/{$catalog}/view/default/{$filename}.html"; + $compile = IA_ROOT . "/data/tpl/{$catalog}/{$name}/{$catalog}/view/default/{$filename}.tpl.php"; + if (!is_file($source)) { + $source = IA_ROOT . "/addons/{$name}/plugin/{$_W['plugin']}/{$catalog}/view/default/{$filename}.html"; + } + } + + if (defined('IN_APP')) { + $template = "default"; + if (!empty($_W['wlsetting']['templat']['appview'])) { + $template = $_W['wlsetting']['templat']['appview']; + } + $source = IA_ROOT . "/addons/{$name}/app/view/{$template}/{$filename}.html"; + $compile = IA_ROOT . "/data/tpl/app/{$name}/app/view/{$template}/{$filename}.tpl.php"; + if (!is_file($source)) { + $source = IA_ROOT . "/addons/{$name}/app/view/default/{$filename}.html"; + } + if (!is_file($source)) { + $source = IA_ROOT . "/addons/{$name}/plugin/{$_W['plugin']}/app/view/{$template}/{$filename}.html"; + } + if (!is_file($source)) { + $source = IA_ROOT . "/addons/{$name}/plugin/{$_W['plugin']}/app/view/default/{$filename}.html"; + } + if (!is_file($source)) { + $filenames = explode("/", $filename); + $source = IA_ROOT . "/addons/{$name}/plugin/{$filenames[0]}/app/view/default/{$filename}.html"; + } + if (!empty($_W['wlsetting']['trade']['credittext']) || !empty($_W['wlsetting']['trade']['moneytext'])) { + $compile = IA_ROOT . "/data/tpl/app/{$name}/{$_W['uniacid']}/app/view/{$template}/{$filename}.tpl.php"; + } + if (!empty($_W['wlsetting']['halfcard']['text']['halfcardtext']) || !empty($_W['wlsetting']['halfcard']['text']['privilege'])) { + $compile = IA_ROOT . "/data/tpl/app/{$name}/{$_W['uniacid']}/app/view/{$template}/{$filename}.tpl.php"; + } + } + if (!is_file($source)) { + exit("Error: template source '{$filename}' is not exist!!!"); + } + if (!is_file($compile) || filemtime($source) > filemtime($compile)) { + Template::wl_template_compile($source, $compile, true); + } + if ($flag == TEMPLATE_FETCH) { + extract($GLOBALS, EXTR_SKIP); + ob_end_flush(); + ob_clean(); + ob_start(); + include $compile; + $contents = ob_get_contents(); + ob_clean(); + return $contents; + } else if ($flag == 'template') { + extract($GLOBALS, EXTR_SKIP); + return $compile; + } else { + return $compile; + }*/ +} + +function wl_message($msg, $redirect = '', $type = '') { + global $_W, $_GPC; + if ($redirect == 'refresh') { + $redirect = $_W['script_name'] . '?' . $_SERVER['QUERY_STRING']; + } + if ($redirect == 'referer') { + $redirect = referer(); + } + if ($redirect == 'close') { + $redirect = 'wx.closeWindow()'; + $close = 1; + } + if ($redirect == '') { + $type = in_array($type, array('success', 'error', 'info', 'warning', 'ajax', 'sql', 'fixed')) ? $type : 'info'; + } else { + $type = in_array($type, array('success', 'error', 'info', 'warning', 'ajax', 'sql', 'fixed')) ? $type : 'success'; + } + if (IN_WXAPP == 'wxapp') { + die(json_encode(array('errno' => $type == 'success' ? 0 : 1, 'message' => $msg, 'data' => $redirect))); + } + if ($_W['isajax'] || !empty($_GET['isajax']) || $type == 'ajax') { + if ($type != 'ajax' && !empty($_GPC['target'])) { + exit(" +"); + } else { + //ajaxsubmit兼容方案 + if ($_W['isajax'] && !empty($_GPC['token'])) { + $ret = array('status' => $type == 'success' ? 1 : 0, 'result' => $type == 'success' ? array('url' => $redirect ? $redirect : referer()) : array()); + $ret['result']['message'] = $msg; + exit(json_encode($ret)); + } else { + $vars = array(); + if (is_array($msg)) { + $vars['errno'] = $msg['errno']; + $vars['message'] = $msg['message']; + die(json_encode($vars)); + } else { + $vars['message'] = $msg; + } + $vars['redirect'] = $redirect; + $vars['type'] = $type; + die(json_encode($vars)); + } + } + } elseif (is_array($msg)) { + $msg = $msg['message']; + } + if (empty($msg) && !empty($redirect)) { + header('location: ' . $redirect); + } + $label = $type; + if ($type == 'error') { + $label = 'danger'; + } + if ($type == 'ajax' || $type == 'sql') { + $label = 'warning'; + } + + include wl_template('common/message', TEMPLATE_INCLUDEPATH); + exit(); +} + +/** + * debug打印 + * + * @access public + * @name wl_debug + * @param $value 需要打印的参数 + */ +function wl_debug($value) { + echo "
";
+    print_r($value);
+    echo "
"; + exit; +} + +/** + * Comment: 自有的debug模式 只有指定人员访问才会debug,其他人员访问不debug。 + * Author: zzw + * Date: 2019/11/12 9:27 + * @param array | string | int $value debug的内容 + * @param int $mid 用户id + * @param bool $status 是否强制打印 + */ +function private_debug($value,$mid = 0,$status = false){ + global $_W; + if($status || ($_W['mid'] == $mid || $_REQUEST['debug'])){ + echo "
";
+        print_r($value);
+        echo "
"; + exit; + } +} + + +/** + * 日志文件打印 + * + * @access public + * @name wl_log + * @param $filename 文件名 + * @param $title 打印标题 + * @param $data 需要打印内容 + * @return array + */ +function wl_log($filename, $title, $data) { + global $_W; + if ($uniacid != '') { + $_W['uniacid'] = $uniacid; + } + $url_log = PATH_DATA . "log/" . date('Y-m-d', time()) . "/" . $filename . ".log"; + $url_dir = PATH_DATA . "log/" . date('Y-m-d', time()); + Util::mkDirs($url_dir); + file_put_contents($url_log, var_export('/=======' . date('Y-m-d H:i:s', time()) . '【' . $title . '】=======/', true) . PHP_EOL, FILE_APPEND); + file_put_contents($url_log, var_export($data, true) . PHP_EOL, FILE_APPEND); +} + +function wl_filter_url($params) { + global $_W; + if (empty($params)) { + return ''; + } + $query_arr = array(); + $parse = parse_url($_W['siteurl']); + if (!empty($parse['query'])) { + $query = $parse['query']; + parse_str($query, $query_arr); + } + $params = explode(',', $params); + foreach ($params as $val) { + if (!empty($val)) { + $data = explode(':', $val); + $query_arr[$data[0]] = trim($data[1]); + } + } + $query_arr['page'] = 1; + $query = http_build_query($query_arr); + if(defined('IN_WEB')){ + return './cityagent.php?' . $query; + }else if(defined('IN_STORE')){ + return './citystore.php?' . $query; + }else if(defined('IN_STAFF')){ + return './citysys.php?' . $query; + }else{ + return './index.php?' . $query; + } +} + +function wl_get_module_name(){ + return MODULE_NAME; +} + +function wl_tpl_form_field_member($value = array()) { + $s = ''; + $s = ' + '; + $s .= ' +
+ +
+ +
+ +
+ +
+
+ +
+
+ '; + return $s; +} + +/** + * qr二维码生成 + * + * @access public + * @name qr + * @param $url 需要生成二维码的链接 + */ +function qr($url) { + global $_W; + if (empty($url)) + return false; + m('qrcode/QRcode')->png($url, false, QR_ECLEVEL_H, 4); +} + +/** + * puv浏览量统计 + * + * @access public + * @name puv + * @param + */ +function puv() { + global $_W; + if ($_W['uniacid'] <= 0 || empty($_W['areaid'])) { + return; + } + $puv = pdo_getcolumn(PDO_NAME . 'puv', array('uniacid' => $_W['uniacid'], 'date' => date('Ymd'), 'areaid' => $_W['areaid']), 'id'); + if (empty($puv)) { + pdo_insert(PDO_NAME . 'puv', array('areaid' => $_W['areaid'], 'uniacid' => $_W['uniacid'], 'pv' => 0, 'uv' => 0, 'date' => date('Ymd'))); + $puv = pdo_insertid(); + } + pdo_query('UPDATE ' . tablename(PDO_NAME . 'puv') . " SET `pv` = `pv` + 1 WHERE id = {$puv}"); + if ($_W['mid']) { + $myp = pdo_getcolumn(PDO_NAME . 'puvrecord', array('uniacid' => $_W['uniacid'], 'date' => date('Ymd'), 'mid' => $_W['mid'], 'areaid' => $_W['areaid']), 'id'); + if (empty($myp)) { + pdo_query('UPDATE ' . tablename(PDO_NAME . 'puv') . " SET `uv` = `uv` + 1 WHERE id = {$puv}"); + pdo_insert(PDO_NAME . 'puvrecord', array('areaid' => $_W['areaid'], 'uniacid' => $_W['uniacid'], 'pv' => 0, 'mid' => $_W['mid'], 'date' => date('Ymd'))); + $myp = pdo_insertid(); + } + pdo_query('UPDATE ' . tablename(PDO_NAME . 'puvrecord') . " SET `pv` = `pv` + 1 WHERE id = {$myp}"); + } +} + +if (!function_exists('show_json')) { + function show_json($status = 1, $return = NULL) { + $ret = array('status' => $status, 'result' => $status == 1 ? array('url' => referer()) : array()); + + if (!is_array($return)) { + if ($return) { + $ret['result']['message'] = $return; + } + + exit(json_encode($ret)); + } else { + $ret['result'] = $return; + } + + if (isset($return['url'])) { + $ret['result']['url'] = $return['url']; + } else { + if ($status == 1) { + $ret['result']['url'] = referer(); + } + } + + exit(json_encode($ret)); + } + +} + +function checkshare() {//禁止分享 + global $_W; + if ($_W['controller'] == 'supervise') {//商户管理 + return 1; + } else if ($_W['method'] == 'orderlist') {//订单列表详情 + return 1; + } else if ($_W['controller'] == 'home' && $_W['method'] == 'paySuccess') {//抢购订单详情 + return 1; + } else if ($_W['controller'] == 'coupon_app' && $_W['method'] == 'couponDetail') {//卡券订单详情 + return 1; + } else if ($_W['controller'] == 'fightapp' && $_W['method'] == 'expressorder') {//拼团订单详情 + return 1; + } else { + return 0; + } +} + +if (!function_exists('array_column')) { + function array_column($input, $column_key, $index_key = NULL) { + $arr = array(); + foreach ($input as $d) { + if (!isset($d[$column_key])) { + return NULL; + } + if ($index_key !== NULL) { + return array($d[$index_key] => $d[$column_key]); + } + $arr[] = $d[$column_key]; + } + + if ($index_key !== NULL) { + $tmp = array(); + foreach ($arr as $ar) { + $tmp[key($ar)] = current($ar); + } + $arr = $tmp; + } + return $arr; + } +} + +/** + * $time 需要格式化的时间戳 + * return 格式化时间 + */ +function time_tran($time) { + $text = ''; + if (!$time) { + return $text; + } + $current = time(); + $t = $current - $time; + $retArr = array('刚刚', '秒前', '分钟前', '小时前', '天前', '月前', '年前'); + switch ($t) { + case $t < 0://时间大于当前时间,返回格式化时间 + $text = date('Y-m-d', $time); + break; + case $t == 0://刚刚 + $text = $retArr[0]; + break; + case $t < 60:// 几秒前 + $text = $t . $retArr[1]; + break; + case $t < 3600://几分钟前 + $text = floor($t / 60) . $retArr[2]; + break; + case $t < 86400://几小时前 + $text = floor($t / 3600) . $retArr[3]; + break; + case $t < 2592000: //几天前 + $text = floor($t / 86400) . $retArr[4]; + break; + case $t < 31536000: //几个月前 + $text = floor($t / 2592000) . $retArr[5]; + break; + default : //几年前 + $text = floor($t / 31536000) . $retArr[6]; + + } + return $text; +} + +/** + * Comment: http请求(post) + * Author: zzw + * Date: 2019/10/8 14:29 + * @param $url + * @param $postData + * @param $header + * @return mixed + */ +function curlPostRequest($url, $postData, $header = '') { + $curl = curl_init();//初始化 + curl_setopt($curl, CURLOPT_URL, $url);//设置抓取的url + if ($header) curl_setopt($curl, CURLOPT_HTTPHEADER, $header);//设置header信息 + curl_setopt($curl, CURLOPT_HEADER, 1);//设置头文件的信息作为数据流输出 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//设置获取的信息以文件流的形式返回,而不是直接输出。 + curl_setopt($curl, CURLOPT_POST, 1);//设置post方式提交 + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); + $data = curl_exec($curl); //执行命令 +// if (curl_errno($curl)) { +// $error = 'Error:' . curl_error($curl); +// wl_debug($error); +// } + $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);// 获得响应结果里的:header头大小 + $info = substr($data, $headerSize);//通过截取 获取body信息 + curl_close($curl);//关闭URL请求 + return json_decode($info, true);//返回获取的信息数据 +} +/** + * Comment: Comment: http请求(get) + * Author: zzw + * Date: 2020/7/22 17:15 + * @param string $url 请求地址 + * @param string $header + * @return mixed + */ +function curlGetRequest($url, $header = '') { + $curl = curl_init();//初始化 + curl_setopt($curl, CURLOPT_URL, $url);//设置抓取的url + if ($header) curl_setopt($curl, CURLOPT_HTTPHEADER, $header);//设置header信息 + curl_setopt($curl, CURLOPT_HEADER, 1);//设置头文件的信息作为数据流输出 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//设置获取的信息以文件流的形式返回,而不是直接输出。 + $data = curl_exec($curl); //执行命令 + $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);// 获得响应结果里的:header头大小 + $info = substr($data, $headerSize);//通过截取 获取body信息 + curl_close($curl);//关闭URL请求 + return json_decode($info, true);//返回获取的信息数据 +} +/** + * Comment: 查看本地是否存在某张图片,不存在则下载到本地 + * Author: zzw + * Date: 2019/11/18 18:37 + * @param $imgPath + * @param $imgLink + */ +function wl_uploadImages($imgPath,$imgLink){ + #1、判断是否已经存在本地 + if(!file_exists($imgPath)){ + $imgName = explode('/',$imgPath); + $dir = str_replace($imgName[count($imgName) - 1],'',$imgPath); + mkdir($dir,0777,true); + $img = $imgLink; + ob_clean(); + ob_start(); + readfile($img);//读取图片 + $img = ob_get_contents();//得到缓冲区中保存的图片 + ob_end_clean();//清空缓冲区 + $fp = fopen($imgPath,'w'); //写入图片 + if(fwrite($fp,$img)) { + fclose($fp); + } + } +} +/** + * Comment: 判断某个远程文件是否存在 + * Author: zzw + * Date: 2020/1/17 11:17 + * @param $url + * @return int + */ +function remoteFileExists($url){ + if(file_get_contents($url,0,null,0,1)) return 1; + else return 0; +} +/** + * Comment: 汉字首字母 拼音获取 + * Author: zzw + * Date: 2020/4/26 14:26 + * @param $s0 + * @return string|null + */ +function getFirstChar($s0){ + $fchar = ord($s0{0}); + if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{0}); + $s1 = iconv("UTF-8","gb2312", $s0); + $s2 = iconv("gb2312","UTF-8", $s1); + if($s2 == $s0){$s = $s1;}else{$s = $s0;} + $asc = ord($s{0}) * 256 + ord($s{1}) - 65536; + if($asc >= -20319 and $asc <= -20284) return "A"; + if($asc >= -20283 and $asc <= -19776) return "B"; + if($asc >= -19775 and $asc <= -19219) return "C"; + if($asc >= -19218 and $asc <= -18711) return "D"; + if($asc >= -18710 and $asc <= -18527) return "E"; + if($asc >= -18526 and $asc <= -18240) return "F"; + if($asc >= -18239 and $asc <= -17923) return "G"; + if($asc >= -17922 and $asc <= -17418) return "H"; + if($asc >= -17922 and $asc <= -17418) return "I"; + if($asc >= -17417 and $asc <= -16475) return "J"; + if($asc >= -16474 and $asc <= -16213) return "K"; + if($asc >= -16212 and $asc <= -15641) return "L"; + if($asc >= -15640 and $asc <= -15166) return "M"; + if($asc >= -15165 and $asc <= -14923) return "N"; + if($asc >= -14922 and $asc <= -14915) return "O"; + if($asc >= -14914 and $asc <= -14631) return "P"; + if($asc >= -14630 and $asc <= -14150) return "Q"; + if($asc >= -14149 and $asc <= -14091) return "R"; + if($asc >= -14090 and $asc <= -13319) return "S"; + if($asc >= -13318 and $asc <= -12839) return "T"; + if($asc >= -12838 and $asc <= -12557) return "W"; + if($asc >= -12556 and $asc <= -11848) return "X"; + if($asc >= -11847 and $asc <= -11056) return "Y"; + if($asc >= -11055 and $asc <= -10247) return "Z"; + return NULL; + //return $s0; +} +/** + * Comment: 腾讯云远程附件 丢失方法 + * 由于自动加载路径问题,当前方法在微擎腾讯云远程附件中报错,所以在这里添加一个方法,强制成功 + * Author: zzw + * Date: 2020/9/7 11:49 + * @param $uri + * @param int $options + * @return mixed + */ +function _idn_uri_convert($uri, $options = 0) +{ + if ($uri->getHost()) { + $idnaVariant = defined('INTL_IDNA_VARIANT_UTS46') ? INTL_IDNA_VARIANT_UTS46 : 0; + $asciiHost = $idnaVariant === 0 + ? idn_to_ascii($uri->getHost(), $options) + : idn_to_ascii($uri->getHost(), $options, $idnaVariant, $info); + if ($asciiHost === false) { + $errorBitSet = isset($info['errors']) ? $info['errors'] : 0; + + $errorConstants = array_filter(array_keys(get_defined_constants()), function ($name) { + return substr($name, 0, 11) === 'IDNA_ERROR_'; + }); + + $errors = []; + foreach ($errorConstants as $errorConstant) { + if ($errorBitSet & constant($errorConstant)) { + $errors[] = $errorConstant; + } + } + + $errorMessage = 'IDN conversion failed'; + if ($errors) { + $errorMessage .= ' (errors: ' . implode(', ', $errors) . ')'; + } + + throw new InvalidArgumentException($errorMessage); + } else { + if ($uri->getHost() !== $asciiHost) { + // Replace URI only if the ASCII version is different + $uri = $uri->withHost($asciiHost); + } + } + } + + return $uri; +} +/** +* Comment: 分页方法 + * Author: zzw + * Date: 2020/12/29 9:49 + * @param $total + * @param $pageIndex + * @param int $pageSize + * @param string $url + * @param array $context + * @return string + */ +function wl_pagination($total, $pageIndex, $pageSize = 15, $url = '', $context = array('before' => 5, 'after' => 4, 'ajaxcallback' => '', 'callbackfuncname' => '')) { + global $_W; + $pdata = array( + 'tcount' => 0, + 'tpage' => 0, + 'cindex' => 0, + 'findex' => 0, + 'pindex' => 0, + 'nindex' => 0, + 'lindex' => 0, + 'options' => '', + ); + if (empty($context['before'])) { + $context['before'] = 5; + } + if (empty($context['after'])) { + $context['after'] = 4; + } + + if ($context['ajaxcallback']) { + $context['isajax'] = true; + } + + if ($context['callbackfuncname']) { + $callbackfunc = $context['callbackfuncname']; + } + + $pdata['tcount'] = $total; + $pdata['tpage'] = (empty($pageSize) || $pageSize < 0) ? 1 : ceil($total / $pageSize); + if ($pdata['tpage'] <= 1) { + return ''; + } + $cindex = $pageIndex; + $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 ($context['isajax']) { + if (empty($url)) { + $url = $_W['script_name'] . '?' . http_build_query($_GET); + } + $pdata['faa'] = 'href="javascript:;" page="' . $pdata['findex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['findex'] . '\', this);"' : ''); + $pdata['paa'] = 'href="javascript:;" page="' . $pdata['pindex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['pindex'] . '\', this);"' : ''); + $pdata['naa'] = 'href="javascript:;" page="' . $pdata['nindex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['nindex'] . '\', this);"' : ''); + $pdata['laa'] = 'href="javascript:;" page="' . $pdata['lindex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['lindex'] . '\', this);"' : ''); + } else { + if ($url) { + $pdata['faa'] = 'href="?' . str_replace('*', $pdata['findex'], $url) . '"'; + $pdata['paa'] = 'href="?' . str_replace('*', $pdata['pindex'], $url) . '"'; + $pdata['naa'] = 'href="?' . str_replace('*', $pdata['nindex'], $url) . '"'; + $pdata['laa'] = 'href="?' . str_replace('*', $pdata['lindex'], $url) . '"'; + } else { + $_GET['page'] = $pdata['findex']; + $pdata['faa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"'; + $_GET['page'] = $pdata['pindex']; + $pdata['paa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"'; + $_GET['page'] = $pdata['nindex']; + $pdata['naa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"'; + $_GET['page'] = $pdata['lindex']; + $pdata['laa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"'; + } + } + $html = '
'; + + return $html; +} +/** + * Comment: 判断当前数组是否存在指定表中不存在的字段,存在则删除该字段 + * Author: zzw + * Date: 2021/3/10 10:26 + * @param array $data + * @param string $table + * @return mixed + */ +function fieldJudge($data,$table){ + $sql = "SHOW COLUMNS FROM ".tablename(PDO_NAME.$table); + $fieldList = pdo_fetchall($sql); + $fields = array_column($fieldList,'Field'); + foreach($data as $fieldName => $fieldVal){ + //判断 数据库不存在该字段 删除信息 + if(!in_array($fieldName, $fields)) unset($data[$fieldName]); + } + + return $data; +} +/** + * Comment: 判断当前字符串是否包含html内容 + * Author: zzw + * Date: 2021/4/27 9:47 + * @param $str + * @return bool + */ +function isHtml($str){ + if($str != strip_tags($str)) return true; + else return false; +} +/** + * Comment: 生成距离计算sql语句 + * Author: zzw + * Date: 2021/5/6 11:30 + * @param float|int $lat 纬度 + * @param float|int $lng 经度 + * @param string $latField 纬度在表中的字段 + * @param string $lngField 经度在表中的字段 + * @return string + */ +function getDistancesSql($lat,$lng,string $latField,string $lngField):string +{ + return "ROUND(CASE + WHEN {$lat} > 0 AND {$lng} > 0 THEN ROUND(6378.138 * 2 * ASIN( + SQRT( + POW(SIN(({$lat} * PI() / 180 - $latField * PI() / 180) / 2),2) + + COS({$lat} * PI() / 180) * COS($latField * PI() / 180) * + POW(SIN(({$lng} * PI() / 180 - $lngField * PI() / 180) / 2),2) + ) + ) * 1000 + ) + ELSE 0 +END)"; +} + + +function beautifyImgInfo($imgs) +{ + global $_W; + $imgs = unserialize($imgs); + if (empty($imgs)) { + $imgs = []; + } else { + foreach ($imgs as &$th) { + $th = tomedia($th); + } + } + return $imgs; +} + +function add_aid($url){ + global $_W; + if(strstr($url,'?')){ + $url = $url.'&aid='.$_W['aid']; + }else{ + $url = $url.'?aid='.$_W['aid']; + } + return $url; +} + +/** + * 汉字截取 + * @param $str + * @param $offset + * @param $length + * @return string + */ +function truncate_chinese_string($str,$offset = 0, $length = 10) { + global $_W; + $strlen = strlen('汉'); + return substr($str,$offset,$strlen * $length); +} + + + + + diff --git a/addons/weliam_smartcity/core/function/tpl.func.php b/addons/weliam_smartcity/core/function/tpl.func.php new file mode 100644 index 0000000..22f9a84 --- /dev/null +++ b/addons/weliam_smartcity/core/function/tpl.func.php @@ -0,0 +1,1004 @@ + $scene, + ); + $option = json_encode($option); + $s = ' + '; + define('TPL_INIT_TINY_FANS', true); + } + + $s .= ' +
+ + + + + + + +
+
+ +
'; + return $s; +} + +function itpl_form_field_daterange($name, $value = array(), $time = false) { + global $_GPC; + $placeholder = ((isset($value['placeholder']) ? $value['placeholder'] : '')); + $s = ''; + + if (empty($time) && !defined('TPL_INIT_TINY_DATERANGE_DATE')) { + $s = ' +'; + define('TPL_INIT_TINY_DATERANGE_DATE', true); + } + + if (!empty($time) && !defined('TPL_INIT_TINY_DATERANGE_TIME')) { + $s = ' +'; + define('TPL_INIT_TINY_DATERANGE_TIME', true); + } + + $str = $placeholder; + $value['starttime'] = ((isset($value['starttime']) ? $value['starttime'] : (($_GPC[$name]['start'] ? $_GPC[$name]['start'] : '')))); + $value['endtime'] = ((isset($value['endtime']) ? $value['endtime'] : (($_GPC[$name]['end'] ? $_GPC[$name]['end'] : '')))); + if ($value['starttime'] && $value['endtime']) { + if (empty($time)) { + $str = date('Y-m-d', strtotime($value['starttime'])) . '至 ' . date('Y-m-d', strtotime($value['endtime'])); + } else { + $str = date('Y-m-d H:i', strtotime($value['starttime'])) . ' 至 ' . date('Y-m-d H:i', strtotime($value['endtime'])); + } + } + + $s .= ' +
+ + +
+
+ + +
'; + return $s; +} + +function tpl_form_field_tiny_link($name, $value = '', $options = array()) { + global $_GPC; + $s = ''; + if (!defined('TPL_INIT_TINY_LINK')) { + $s = ' + '; + define('TPL_INIT_TINY_LINK', true); + } + $s .= ' +
+ + + + +
+ '; + return $s; +} + +function tpl_form_field_tiny_wxapp_link($name, $value = '', $options = array()) { + global $_GPC; + $s = ''; + if (!defined('TPL_INIT_TINY_WXAPP_LINK')) { + $s = ' + '; + define('TPL_INIT_TINY_WXAPP_LINK', true); + } + $s .= ' +
+ + + + +
+ '; + return $s; +} + +function tpl_form_field_tiny_coordinate($field, $value = array(), $required = false) { + global $_W; + $s = ''; + if (!defined('TPL_INIT_TINY_COORDINATE')) { + $s .= ''; + define('TPL_INIT_TINY_COORDINATE', true); + } + $s .= ' +
+
+ +
+
+ +
+
+ +
+
'; + return $s; +} + +function tpl_select2($name, $data, $value = 0, $filter = array('id', 'title'), $default = '请选择') { + $element_id = "select2-{$name}"; + $json_data = array(); + foreach ($data as $da) { + $json_data[] = array( + 'id' => $da[$filter[0]], + 'text' => $da[$filter[1]], + ); + } + $json_data = json_encode($json_data); + $html = ''; + $html .= ''; + return $html; +} + +function tpl_form_field_tiny_image($name, $value = '') { + global $_W; + $default = ''; + $val = $default; + if (!empty($value)) { + $val = tomedia($value); + } + if (!empty($options['global'])) { + $options['global'] = true; + } else { + $options['global'] = false; + } + if (empty($options['class_extra'])) { + $options['class_extra'] = ''; + } + if (isset($options['dest_dir']) && !empty($options['dest_dir'])) { + if (!preg_match('/^\w+([\/]\w+)?$/i', $options['dest_dir'])) { + exit('图片上传目录错误,只能指定最多两级目录,如: "we7_store","we7_store/d1"'); + } + } + $options['direct'] = true; + $options['multiple'] = false; + if (isset($options['thumb'])) { + $options['thumb'] = !empty($options['thumb']); + } + $s = ''; + if (!defined('TPL_INIT_TINY_IMAGE')) { + $s = ' + '; + define('TPL_INIT_TINY_IMAGE', true); + } + + $s .= ' +
+
+ +
+ + + + +
'; + return $s; +} + +function tpl_form_field_store($name, $value = '', $option = array('mutil' => 0)) { + global $_W; + if (empty($default)) { + $default = './resource/images/nopic.jpg'; + } + if (!is_array($value)) { + $value = intval($value); + $value = array($value); + } + $value_ids = implode(',', $value); + $stores_temp = pdo_fetchall('select id, title, logo from ' . tablename('tiny_wmall_store') . " where uniacid = :uniacid and id in ({$value_ids})", array(':uniacid' => $_W['uniacid'])); + $stores = array(); + if (!empty($stores_temp)) { + foreach ($stores_temp as $row) { + $row['logo'] = tomedia($row['logo']); + $stores[] = $row; + } + } + + $definevar = 'TPL_INIT_TINY_STORE'; + $function = 'showStoreDialog'; + if (!empty($option['mutil'])) { + $definevar = 'TPL_INIT_TINY_MUTIL_STORE'; + $function = 'showMutilStoreDialog'; + } + $s = ''; + if (!defined($definevar)) { + $option_json = json_encode($option); + $s = ' + '; + define($definevar, true); + } + + $s .= ' +
+ + + + +
'; + if (empty($option['mutil'])) { + $s .= ' +
+ + + '; + if (empty($stores[0]['title'])) { + $s .= ''; + } else { + $s .= '' . $stores[0]['title'] . ''; + } + $s .= '
'; + } else { + $s .= '
'; + foreach ($stores as $store) { + $s .= ' +
+ + + × + ' . $store['title'] . ' +
'; + } + $s .= '
'; + } + return $s; +} + +function tpl_form_field_mutil_store($name, $value = '') { + return tpl_form_field_store($name, $value, $option = array('mutil' => 1)); +} + +function tpl_form_field_goods($name, $value = '', $option = array('mutil' => 0, 'sid' => 0, 'ignore' => array())) { + global $_W; + if (!isset($option['mutil'])) { + $option['mutil'] = 0; + } + if (empty($default)) { + $default = './resource/images/nopic.jpg'; + } + if (!is_array($value)) { + $value = intval($value); + $value = array($value); + } + $condition = ' where uniacid = :uniacid'; + $params = array(':uniacid' => $_W['uniacid']); + $value_ids = implode(',', $value); + $condition .= " and id in ({$value_ids})"; + $goods_temp = pdo_fetchall('select id, title, thumb from ' . tablename('tiny_wmall_goods') . "{$condition}", $params); + $goods = array(); + if (!empty($goods_temp)) { + foreach ($goods_temp as $row) { + $row['thumb'] = tomedia($row['thumb']); + $goods[] = $row; + } + } + + $definevar = 'TPL_INIT_TINY_GOODS'; + $function = 'showGoodsDialog'; + if (!empty($option['mutil'])) { + $definevar = 'TPL_INIT_TINY_MUTIL_GOODS'; + $function = 'showMutilGoodsDialog'; + } + $s = ''; + if (!defined($definevar)) { + $option_json = json_encode($option); + $s = ' + '; + define($definevar, true); + } + + $s .= ' +
+ + + + +
'; + if (empty($option['mutil'])) { + $s .= ' +
+ + + '; + if (empty($goods[0]['title'])) { + $s .= ''; + } else { + $s .= '' . $goods[0]['title'] . ''; + } + $s .= '
'; + } else { + $s .= '
'; + foreach ($goods as $good) { + $s .= ' +
+ + + × + ' . $good['title'] . ' +
'; + } + $s .= '
'; + } + return $s; +} + +function tpl_form_field_mutil_goods($name, $value = '', $option = array('sid' => 0, 'ignore' => array())) { + if (!isset($option['mutil'])) { + $option['mutil'] = 1; + } + return tpl_form_field_goods($name, $value, $option); +} + +function tpl_form_filter_hidden($ctrls) { + global $_W; + if (is_agent()) { + $html = ''; + } else { + $html = ' + + + + '; + } + + [$p, $ac, $do] = explode('/', $ctrls); + if (!empty($p)) { + $html .= ''; + if (!empty($ac)) { + $html .= ''; + if (!empty($do)) { + $html .= ''; + } + } + } + return $html; +} + +function tpl_form_field_tiny_category_2level($name, $parents, $children, $parentid, $childid) { + $html = ' + '; + if (!defined('TPL_INIT_TINY_CATEGORY')) { + $html .= ' + + '; + define('TPL_INIT_TINY_CATEGORY', true); + } + + $html .= + '
+
+ +
+
+ +
+
+ '; + return $html; +} + +function tpl_form_field_editor($params = array(), $callback = NULL) { + $html = ''; + $html .= ''; + $html .= '' . $params['value'] . ''; + $html .= '修改'; + $html .= ''; + $html .= ''; + $html .= ' + + + + + + + + '; + + $html .= ''; + return $html; + +} +/** + * Comment: 状态改变控制器 + * Author: zzw + * Date: 2019/9/18 14:30 + * @param string $url 状态改变后提交的地址 + * @param string $val 当前的值 + * @param int $open 开启的值 + * @param int $close 关闭的值 + * @return string + */ +function tpl_change_status($url, $val, $open = 1, $close = 0) { + $url = web_url($url); + #1、生成基础内容 + if ($val == $open) $html = ''; + else $html = ''; + return $html; +} +/** + * Comment: 用户选择器 + * Author: zzw + * Date: 2019/11/29 18:17 + * @param string|int $mid 用户id名称 + * @param string|int $midVal 用户id值 + * @return string + */ +function tpl_select_user($mid, $midVal,$title = '选择用户') { + $default = './resource/images/nopic.jpg'; + if(!empty($midVal)) $member = Member::wl_member_get($midVal); + $html = '
+ + + '.$title.' +
+
+ +
'; + return $html; +} +/** + * Comment: 时间选择器 tpl_form_field_daterange的重构版本 + * Author: zzw + * Date: 2020/4/9 11:53 + * @param $name + * @param array $value + * @param bool $time + * @return string + */ +function tpl_select_time_info($name, $value = array(), $time = false) { + $s = ' + + '; + define('TPL_INIT_DATERANGE_DATE' , true); + if ($value['starttime'] !== false && $value['start'] !== false) { + if($value['start']) { + $value['starttime'] = empty($time) ? date('Y-m-d',strtotime($value['start'])) : date('Y-m-d H:i',strtotime($value['start'])); + } + $value['starttime'] = empty($value['starttime']) ? (empty($time) ? date('Y-m-d') : date('Y-m-d H:i') ): $value['starttime']; + } else { + $value['starttime'] = '请选择'; + } + + if ($value['endtime'] !== false && $value['end'] !== false) { + if($value['end']) { + $value['endtime'] = empty($time) ? date('Y-m-d',strtotime($value['end'])) : date('Y-m-d H:i',strtotime($value['end'])); + } + $value['endtime'] = empty($value['endtime']) ? $value['starttime'] : $value['endtime']; + } else { + $value['endtime'] = '请选择'; + } + + + $s .= ' + + + + '; + return $s; +} +/** + * Comment: 图片选择模型 —— 单选 + * Author: zzw + * Date: 2020/8/31 18:50 + * @param $name + * @param string $default_img + * @return string + */ +function attachment_select($name,$default_img = '',$ordernum = 0){ + //名称处理 + $idName = str_replace(['[',']'],'_',$name); + $http_url = $default_img; + if($http_url) $http_url = tomedia($http_url); + //生成html信息 + $html = '
+ + + + +
+
+ + × +
'; + + return $html; +} + +function attachment_select2W($name,$default_img = '',$ordernum = 0){ + //名称处理 + $idName = str_replace(['[',']'],'_',$name); + $http_url = $default_img; + if($http_url) $http_url = tomedia($http_url); + //生成html信息 + $html = '
+ + + + +
+
+ + × +
'; + + return $html; +} + +/** + * Comment: 图片选择模型 —— 多选 + * Author: zzw + * Date: 2020/8/31 19:35 + * @param $name + * @param string $default_img + * @return string + */ +function attachment_select_multi($name,$default_img = ''){ + //名称处理 + $idName = str_replace(['[',']'],'_',$name); + //默认图片信息处理 + $html = ''; + if(is_array($default_img) && count($default_img) > 0){ + foreach($default_img as $attKey => $attVal){ + //图片信息处理 + $httpUrl = tomedia($attVal); + //生成html信息 + $html .= '
+ + + × +
'; + } + } + //生成html信息 + $html = '
+ + + + +
+
'.$html.'
'; + + + return $html; +} +/** + * Comment: 生成百度富文本编辑器 + * Author: zzw + * Date: 2020/9/3 14:38 + * @param $name + * @param string $value + * @return string + */ +function tpl_diy_editor_create($name,$value = ''){ + $html = ''; + + return $html; +} +/** + * Comment: 地图定位 + * Author: zzw + * Date: 2020/9/8 16:02 + * @param $addressName + * @param $lngName + * @param $latName + * @param $address + * @param $lng + * @param $lat + * @return string + */ +function tpl_select_address($addressName,$lngName,$latName,$address,$lng,$lat){ + //名称处理 + $idAddressName = str_replace(['[',']'],'_',$addressName); + $idLngName = str_replace(['[',']'],'_',$lngName); + $idLatName = str_replace(['[',']'],'_',$latName); + //生成html信息 + $html = '
+ + + + 地图定位 +
'; + + return $html; +} +/** + * Comment: 红包选择器 + * Author: zzw + * Date: 2020/9/14 15:22 + * @param string $name + * @param string $id + * @return string + */ +function tpl_select_redPack($name = '',$id = ''){ + $html = '
+ + + + + +
'; + return $html; +} +/** + * Comment: 音频选择器 + * Author: zzw + * Date: 2021/2/1 10:12 + * @param $name + * @param string $defaultUrl + * @return string + */ +function attachment_select_audio($name,$defaultUrl = ''){ + //名称处理 + $idName = str_replace(['[',']'],'_',$name); + //生成html信息 + $html = '
+ + + + +
'; + return $html; +} +/** + * Comment: 视频选择器 + * Author: zzw + * Date: 2021/2/26 17:39 + * @param $name + * @param string $defaultUrl + * @return string + */ +function attachment_select_video($name,$defaultUrl = ''){ + //名称处理 + $idName = str_replace(['[',']'],'_',$name); + $http_url = $defaultUrl; + if($http_url) $http_url = tomedia($http_url); + //生成html信息 + $html = '
+ + + + +
+
+ + × +
'; + + return $html; +} + + diff --git a/addons/weliam_smartcity/core/table/agentarea.table.php b/addons/weliam_smartcity/core/table/agentarea.table.php new file mode 100644 index 0000000..8e098d9 --- /dev/null +++ b/addons/weliam_smartcity/core/table/agentarea.table.php @@ -0,0 +1,38 @@ +classs('table'); + +class AgentareaTable extends We7Table { + + protected $tableName = 'wlmerchant_oparea'; + + public function getAreaList() { + return $this->query->from($this->tableName)->orderby('sort', 'DESC')->getall(); + } + + public function selectFields($select) { + $this->query->select($select); + return $this; + } + + public function searchWithLevel($level) { + $this->query->where('level', $level); + return $this; + } + + public function searchWithHot() { + $this->query->where('ishot', 1); + return $this; + } + + public function searchWithOpen() { + $this->query->where('status', 1); + return $this; + } + + public function searchWithUniacid($uniacid) { + $this->query->where('uniacid', $uniacid); + return $this; + } + +} \ No newline at end of file diff --git a/addons/weliam_smartcity/core/table/area.table.php b/addons/weliam_smartcity/core/table/area.table.php new file mode 100644 index 0000000..039351a --- /dev/null +++ b/addons/weliam_smartcity/core/table/area.table.php @@ -0,0 +1,45 @@ +classs('table'); + +class AreaTable extends We7Table { + + protected $area_table = 'wlmerchant_area'; + protected $oparea_table = 'wlmerchant_oparea'; + + public function getAreaList() { + return $this->query->from($this->area_table)->getall(); + } + + public function getAreaById($id) { + return $this->query->from($this->area_table)->where('id', $id)->get(); + } + + public function selectFields($select) { + $this->query->select($select); + return $this; + } + + public function searchWithLevel($level) { + $this->query->where('level', $level); + return $this; + } + + public function searchWithOpen() { + $this->query->where('visible', 2); + return $this; + } + + public function searchWithUniacid($uniacid) { + $value = !empty($uniacid) ? [0, $uniacid] : 0; + $this->query->where('displayorder', $value); + return $this; + } + + public function searchWithKeyword($keyword) { + if (!empty($keyword)) { + $this->query->where('name LIKE', "%{$keyword}%")->whereor('pinyin LIKE', "%{$keyword}%"); + return $this; + } + } +} \ No newline at end of file diff --git a/addons/weliam_smartcity/core/table/distribution.table.php b/addons/weliam_smartcity/core/table/distribution.table.php new file mode 100644 index 0000000..8523699 --- /dev/null +++ b/addons/weliam_smartcity/core/table/distribution.table.php @@ -0,0 +1,17 @@ +classs('table'); + +class DistributionTable extends We7Table { + + protected $distributor_table = 'wlmerchant_distributor'; + + public function getDisNumById($id, $level = 1) { + if ($level == 1) { + + } + $onenum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_distributor') . " WHERE leadid = {$_W['wlmember']['id']}"); + $twonum = pdo_fetchcolumn('SELECT count(id) FROM ' . tablename('wlmerchant_distributor') . " WHERE leadid in (select mid from " . tablename('wlmerchant_distributor') . " where `leadid` = {$_W['wlmember']['id']})"); + return $this->query->from($this->area_table)->where('id', $id)->get(); + } +} \ No newline at end of file