where('store_id', getAdmStoId())->where('type', 5)->find(); if ($rs) { if ($rs['end_time'] < time()) $this->redirect(U('Admin/weapp/not_xcx')); $this->assign('end_time', $rs['end_time']); } else { $this->redirect(U('Admin/weapp/not_xcx')); } } } //settings public function settings() { $getstoid = getAdmStoId(); $weres = M('weapp')->where(' store_id=' . $getstoid)->find(); $this->assign('getstoid', $getstoid); if ($weres) { $this->redirect($_SERVER['HTTP_HOST'] . '/Admin/Weapp/call?appid=' . $weres['appid'], 302); } else { return $this->fetch('', getAdmStoId()); } //查询是否已授权,如果已授权直接到定向到小程序详情页 } //小程序授权 public function call($appid) { $m_end=M("store_module_endtime")->where("type",5)->where("store_id",getAdmStoId())->find(); $this->assign("m_end",$m_end); $getadmstoid = getAdmStoId(); //小程序二维码生成 $resl = M('weapp')->where('appid', $appid)->find(); $default_pageValue = "pages/index/index/index"; $weapp_auditinfo = M('weapp_audit')->where(array('store_id' => $getadmstoid, 'status' => 0))->order('id desc')->find(); if ($weapp_auditinfo) { $weapp_qrcode = M('weapp_qrcode')->where(array('store_id' => $getadmstoid, 'pageValue' => $default_pageValue))->find(); if (empty($weapp_qrcode)) { $wepp_api = WEAPPAPIURL . "api/wx/open/app/user/createQrcode/" . $getadmstoid . "?pageValue=pages/index/index/index"; $wepp_info = httpRequest($wepp_api); if ($wepp_info) { $wepp_info = json_decode($wepp_info, true); if ($wepp_info['code'] == 0) { $weapp_qrcode['qrcodeurl'] = $wepp_info['data']; //新增data $qrcode_adddata['sceneValue'] = ""; $qrcode_adddata['store_id'] = $getadmstoid; $qrcode_adddata['date'] = time(); $qrcode_adddata['pageValue'] = $default_pageValue; $qrcode_adddata['qrcodeurl'] = $wepp_info['data']; M('weapp_qrcode')->save($qrcode_adddata); } } } else { if ($weapp_qrcode['date'] < $weapp_auditinfo['succtime']) { $wepp_api = WEAPPAPIURL . "api/wx/open/app/user/createQrcode/" . $getadmstoid . "?pageValue=pages/index/index/index"; $wepp_info = httpRequest($wepp_api); if ($wepp_info) { $wepp_info = json_decode($wepp_info, true); if ($wepp_info['code'] == 0) { $weapp_qrcode['qrcodeurl'] = $wepp_info['data']; //新增data $qrcode_adddata['sceneValue'] = ""; $qrcode_adddata['store_id'] = $getadmstoid; $qrcode_adddata['date'] = time(); $qrcode_adddata['pageValue'] = $default_pageValue; $qrcode_adddata['qrcodeurl'] = $wepp_info['data']; M('weapp_qrcode')->where(array('id' => $weapp_qrcode['id']))->save($qrcode_adddata); } } } } $this->assign('weapp_qrcode', $weapp_qrcode); } $wxuser = M('wx_user')->where(' store_id=' . $getadmstoid)->find(); switch ($resl['service_type_info']) { case 2: $type = "服务号"; break; default: $type = "订阅号"; break; } //处理订阅号和服务号 switch ($resl['verify_type_info']) { case -1: $verify_type_info = "未认证"; break; default: $verify_type_info = "已认证"; break; } $sq_func_info = $resl[sq_func_info]; $func_info = explode(',', $sq_func_info); for ($i = 0; $i < (count($func_info) - 1); $i++) { switch ($func_info[$i]) { case 1: $func_info[$i] = "消息管理权限"; break; case 2: $func_info[$i] = "用户管理权限"; break; case 3: $func_info[$i] = "帐号服务权限"; break; case 4: $func_info[$i] = "网页服务权限"; break; case 5: $func_info[$i] = "微信小店权限"; break; case 6: $func_info[$i] = "微信多客服权限"; break; case 7: $func_info[$i] = "群发与通知权限"; break; case 8: $func_info[$i] = "微信卡券权限"; break; case 9: $func_info[$i] = "微信扫一扫权限"; break; case 10: $func_info[$i] = "微信连WIFI权限"; break; case 11: $func_info[$i] = "素材管理权限"; break; case 12: $func_info[$i] = "微信摇周边权限"; break; case 13: $func_info[$i] = "微信门店权限"; break; case 14: $func_info[$i] = "微信支付权限"; break; case 15: $func_info[$i] = "自定义菜单权限"; break; case 16: $func_info[$i] = ""; break; case 17: $func_info[$i] = "帐号管理权限"; break; case 18: $func_info[$i] = "开发管理权限"; break; case 19: $func_info[$i] = "客服消息管理权限"; break; default: $func_info[$i] = ""; break; } } $this->assign('func_info', $func_info); $this->assign('verify_type_info', $verify_type_info); $this->assign('type', $type); $this->assign('res', $resl); $this->assign('appid', $appid); $this->assign('wxuser', $wxuser); $storeid = getAdmStoId(); $this->assign('getstoid', $storeid); return $this->fetch('call'); } //支付配置 public function payset() { $id = getAdmStoId(); $dir = ROOT_PATH . '/public/cert/' . $id . '/weapp/apiclient_cert.pem'; $isup = 0; //创建目录失败 if (file_exists($dir)) { $this->assign('isup', 1); $isup = 1; } $weapp = M('weapp')->where(array('store_id' => $id))->find(); if (!$weapp) { $this->error('请先进行授权', U('Admin/Weapp/settings')); exit; } if (IS_POST) { $post_data = input('post.'); foreach ($post_data as $k => $v) { $post_data[$k] = trim($v); } $row = M('weapp')->where(array('store_id' => $id))->update($post_data); if ($row !== false) { //有上传证书要校验一遍 if ($isup) { $getcheck_json = $this->check_zip(1); if ($getcheck_json['code'] != 1) { $this->error($getcheck_json['msg']); exit(); } } $this->success("修改成功"); } else { $this->error("修改失败"); } } $this->assign('weapp', $weapp); return $this->fetch('', getAdmStoId()); } public function check_zip($ind = 0) { include_once "plugins/payment/weixin/weixin.class.php"; $wx = new \weixin(); $stoid = getAdmStoId(); $ordno = $total_fee = $refund_fee = 1; $path = BASE_PATH . 'public/cert/' . $stoid . '/weapp/'; $json = null; $json['time'] = time(); try { $rs = $wx->refund2($ordno, $total_fee, $refund_fee, $path, $stoid,"weapp",1); if ($rs['return_code'] == 'FAIL') { $json['code'] = -1; $json['msg'] = $rs['return_msg']; $str = urldecode(urldecode($rs['return_msg'])); if (strpos($str, 'certificate not match') !== false) { $json['msg'] = "证书已失效,请到微信商户平台更新证书,重新下载后上传"; } if (strpos($str, 'mch_id') !== false) { $json['msg'] = "微信支付商户号错误,请重新编辑"; } if (strpos($str, '签名错误') !== false) { $json['msg'] = "微信支付KEY错误,请重新编辑"; } if (strpos($str, '订单不存在') !== false) { $json['code'] = 1; $json['msg'] = '校验成功'; } } else { $json['code'] = 1; $json['msg'] = '校验成功'; } }catch (\Exception $e) { $json['code'] = 1; $json['msg'] = '校验成功'; mlog($e->getMessage(), "check_zipwepp/" . getAdmStoId()); $str = $e->getMessage(); if (strpos($str, '52') !== false) { $json['code'] = -1; $json['msg'] = '证书路径错误,请重新上传'; } if (strpos($str, '58') !== false) { $json['code'] = -1; $json['msg'] = '证书未上传或者证书路径错误,请重新上传'; } } M('weapp')->where('store_id', $stoid) ->save(['check_json' => json_encode($json)]); if ($ind == 1) return $json; return json($json); } //提交代码 1 public function sumbitcode() { $getadmstoid = getAdmStoId(); $weapp = M('weapp')->where(array('store_id' => $getadmstoid))->find(); if (!$weapp) { $this->error('请先进行授权', U('Admin/Weapp/settings')); exit; } $man_res = M('manager_config')->find(); if (IS_POST) { $post_data = input('post.'); // $res = httpRequest("https://api.weixin.qq.com/wxa/gettemplatedraftlist?access_token=".getcomponent_access_token()); // var_dump($res);die; $getweptoken = weapp_get_access_token($weapp, $getadmstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { $this->error('请重新授权', U('Admin/Weapp/settings')); exit; } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $PostData_str = '{"user_version":"' . $post_data["user_version"] . '","user_desc":"' . $post_data['user_desc'] . '","ext_json":"{\"extAppid\":\"'.WEAPPID.'\",'; $PostData_str .= '\"ext\":{\"extAppid\":\"'.WEAPPID.'\",\"appCode\":\"UNION_PAY\",\"appNickName\":\"万信达商城\",\"shopId\":\"'.WEAPPSTOREID.'\",\"preDomain\":\"'.WEAPPAPIURL.'\"},'; $PostData_str .= '\"extPages\":{},\"pages\":' . $man_res["weapp_ext_json"] . ','; $PostData_str .= ' \"window\":{},\"networkTimeout\":{},\"tabBar\":{\"color\":\"#7f8389\",\"selectedColor\":\"#ff9a0f\",\"borderStyle\":\"white\",'; $PostData_str .= '\"list\":[{\"pagePath\":\"pages/index/index/index\",\"text\":\"首页\",\"iconPath\":\"images/bar/index.png\",\"selectedIconPath\":\"images/bar/index_on.png\"},{\"pagePath\":\"pages/goods/categoryList/categoryList\",\"text\":\"分类\",\"iconPath\":\"images/bar/fl.png\",\"selectedIconPath\":\"images/bar/fl_on.png\"},{\"pagePath\":\"pages/cart/cart/cart\",\"text\":\"购物车\",\"iconPath\":\"images/bar/car.png\",\"selectedIconPath\":\"images/bar/car_on.png\"},{\"pagePath\":\"pages/user/index/index\",\"text\":\"我的\",\"iconPath\":\"images/bar/user.png\",\"selectedIconPath\":\"images/bar/user_on.png\"}]}}"}'; //如下是正确格式 // $PostData_str='{\"extAppid\":\"wx2ea7cdd3ef52cdff\",\"ext\":{\"extAppid\":\"wx2ea7cdd3ef52cdff\",\"appCode\":\"UNION_PAY\",\"appNickName\":\"万信达商城\",\"shopId\":\"1\",\"preDomain\":\"https://test.yolipai.net/\"},\"extPages\":{},\"pages\":[\"pages/index/index/index\",\"pages/goods/categoryList/categoryList\",\"pages/activity/group_list/group_list\",\"pages/activity/coupon_list/coupon_list\",\"pages/cart/cart/cart\",\"pages/cart/cart2/cart2\",\"pages/cart/cart4/cart4\",\"pages/goods/integralMall/integralMall\",\"pages/goods/brandstreet/brandstreet\",\"pages/goods/goodsInfo/goodsInfo\",\"pages/goods/goodsList/goodsList\",\"pages/goods/search/search\",\"pages/order/refund_order/refund_order\",\"pages/payment/payment/payment\",\"pages/user/index/index\",\"pages/user/order_list/order_list\",\"pages/user/order_detail/order_detail\",\"pages/user/visit_log/visit_log\",\"pages/user/address_list/address_list\",\"pages/user/userinfo/userinfo\",\"pages/user/account/account\",\"pages/user/comment/comment\",\"pages/user/return_goods_list/return_goods_list\",\"pages/user/userinfo_edit/userinfo_edit\",\"pages/user/collect_list/collect_list\",\"pages/user/coupon/coupon\",\"pages/user/checkcoupon/checkcoupon\",\"pages/user/add_address/add_address\",\"pages/user/account_list/account_list\",\"pages/user/points_list/points_list\",\"pages/user/recharge_list/recharge_list\",\"pages/user/withdrawals_list/withdrawals_list\",\"pages/user/add_comment/add_comment\",\"pages/user/return_goods_info/return_goods_info\",\"pages/user/return_goods/return_goods\",\"pages/user/withdrawals/withdrawals\",\"pages/user/recharge/recharge\",\"pages/user/message_notice/message_notice\",\"pages/user/express/express\",\"pages/user/binding_info/binding_info\",\"pages/user/get_user_info/get_user_info\",\"pages/virtual/buy_step/buy_step\",\"pages/virtual/virtual_list/virtual_list\",\"pages/distribut/index/index\",\"pages/distribut/distribut_list/distribut_list\",\"pages/distribut/good_list/good_list\",\"pages/distribut/order_list/order_list\",\"pages/distribut/my_store/my_store\",\"pages/distribut/set_store/set_store\",\"pages/distribut/team/team\",\"pages/index/webview/webview\",\"pages/cart/integral/integral\",\"pages/team/index/index\",\"pages/team/team_info/team_info\",\"pages/team/team_detail/team_detail\",\"pages/team/team_confirm/team_confirm\",\"pages/team/team_coupon/team_coupon\",\"pages/team/team_order/team_order\",\"pages/activity/seckill_list/seckill_list\"],\"window\":{\"backgroundTextStyle\":\"light\",\"navigationBarTextStyle\":\"black\",\"navigationBarTitleText\":\"加载中...\",\"navigationBarBackgroundColor\":\"#ffffff\",\"backgroundColor\":\"#eeeeee\",\"enablePullDownRefresh\":true},\"networkTimeout\":{},\"tabBar\":{\"color\":\"#7f8389\",\"selectedColor\":\"#ff9a0f\",\"borderStyle\":\"white\",\"list\":[{\"pagePath\":\"pages/index/index/index\",\"text\":\"首页\",\"iconPath\":\"images/bar/index.png\",\"selectedIconPath\":\"images/bar/index_on.png\"},{\"pagePath\":\"pages/goods/categoryList/categoryList\",\"text\":\"分类\",\"iconPath\":\"images/bar/fl.png\",\"selectedIconPath\":\"images/bar/fl_on.png\"},{\"pagePath\":\"pages/cart/cart/cart\",\"text\":\"购物车\",\"iconPath\":\"images/bar/car.png\",\"selectedIconPath\":\"images/bar/car_on.png\"},{\"pagePath\":\"pages/user/index/index\",\"text\":\"我的\",\"iconPath\":\"images/bar/user.png\",\"selectedIconPath\":\"images/bar/user_on.png\"}]}}'; $res = httpRequest("https://api.weixin.qq.com/wxa/commit?access_token=" . $getauthorizer_access_token, "POST", $PostData_str); return $res; } $this->assign('weapp', $weapp); return $this->fetch('', getAdmStoId()); } //获取体验小程序的体验二维码 2 public function get_qrcode() { $getstoid = I('stoid/d', 0); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => '该商家取消授权,请重新授权')); } if ($weapp['qrcode_urlimg']) { return json(array('errcode' => 0, 'qrcode_urlimg' => QCLOUD_IMGURL . $weapp['qrcode_urlimg'], 'errmsg' => 'ok')); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/wxa/get_qrcode?access_token=" . $getauthorizer_access_token, 'get'); $localpath = "/public/upload/weappqrcode/" . $getstoid . "/"; $picname = time() . ".jpg"; if (!file_exists(ROOT_PATH . $localpath)) { mkdir(ROOT_PATH . $localpath, 0777, true); } $ret = file_put_contents(ROOT_PATH . $localpath . $picname, $res, true); vendor('qcloudcos.myqcloudcos'); $resfolder = Myqcloudcos::statFolder('wxd', $localpath); if ($resfolder && $resfolder['code'] != 0)//不存在创建 { Myqcloudcos::createFolder('wxd', $localpath); } //上传到腾讯云 $res = Myqcloudcos::upload('wxd', ROOT_PATH . $localpath . $picname, $localpath . $picname); if ($res && $res['code'] == 0)// { // $savedata['qrcode_urlimg'] = $localpath . $picname; M('weapp')->where(array('store_id' => $getstoid))->save($savedata); mdelFile($localpath); return json(array('errcode' => 0, 'qrcode_urlimg' => QCLOUD_IMGURL . $localpath . $picname, 'errmsg' => 'ok')); } else { return json(array('errcode' => -1, 'errmsg' => '生成失败')); } } //获取小程序的第三方提交代码的页面配置(仅供第三方开发者代小程序调用)3 public function get_page() { $getstoid = I('stoid/d', 0); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => '该商家取消授权,请重新授权')); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/wxa/get_page?access_token=" . $getauthorizer_access_token, 'get'); return $res; } //获取草稿箱内的所有临时代码草稿 4 public function gettemplatedraftlist() { $res = httpRequest("https://api.weixin.qq.com/wxa/gettemplatedraftlist?access_token=" . getcomponent_access_token(), 'get'); return $res; } //获取代码模版库中的所有小程序代码模版 5 public function gettemplatelist() { $res = httpRequest("https://api.weixin.qq.com/wxa/gettemplatelist?access_token=" . getcomponent_access_token(), 'get'); return $res; } //将草稿箱的草稿选为小程序代码模版 6 public function addtotemplate() { $draft_id = I('draft_id'); if ($draft_id == "") { return json(array('errcode' => -1, 'errmsg' => '请选择草稿模板')); } $postdata['draft_id'] = $draft_id; $res = httpRequest("https://api.weixin.qq.com/wxa/addtotemplate?access_token=" . getcomponent_access_token(), 'POST', json_encode($postdata)); return $res; } //将草稿箱的草稿选为小程序代码模版 7 public function deletetemplate() { $template_id = I('template_id'); if ($template_id == "") { return json(array('code' => -1, 'msg' => '请选择要删除的模版ID')); } $postdata['template_id'] = $template_id; $res = httpRequest("https://api.weixin.qq.com/wxa/deletetemplate?access_token=" . getcomponent_access_token(), 'POST', json_encode($postdata)); return $res; } //设置小程序业务域名(仅供第三方代小程序调用) 8 public function setwebviewdomain() { $getstoid = I('stoid/d', 0); $getaction = I('action', 'get'); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $getpostr = "POST"; //add添加, delete删除, set覆盖, get获取 switch ($getaction) { case "add": $postdata['webviewdomain'] = "[\"https://test-weshop.yolipai.net\"]"; break; case "delete": $postdata['webviewdomain'] = "[\"https://test-weshop.yolipai.net\"]"; break; case "set": $postdata['webviewdomain'] = "[\"https://test-weshop.yolipai.net\"]"; break; case "get": break; default: break; } $postdata['action'] = $getaction; $postdatastr = json_encode($postdata); $res = httpRequest("https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=" . $getauthorizer_access_token, $getpostr, $postdatastr); return $res; } //设置小程序服务器域名 9 public function modify_domain() { $getstoid = I('stoid/d', 0); $getaction = I('action', 'get'); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $getpostr = "POST"; //add添加, delete删除, set覆盖, get获取 $postdata['action'] = $getaction; switch ($getaction) { case "add": $postdata['requestdomain'] = "[\"https://test-weshop.yolipai.net\"]"; $postdata['wsrequestdomain'] = "[\"https://test-weshop.yolipai.net\"]"; $postdata['uploaddomain'] = "[\"https://test-weshop.yolipai.net\"]"; $postdata['downloaddomain'] = "[\"https://test-weshop.yolipai.net\"]"; break; case "delete": $postdata['requestdomain'] = "[\"https://test-weshop.yolipai.net\"]"; $postdata['wsrequestdomain'] = "[\"https://test-weshop.yolipai.net\"]"; $postdata['uploaddomain'] = "[\"https://test-weshop.yolipai.net\"]"; $postdata['downloaddomain'] = "[\"https://test-weshop.yolipai.net\"]"; break; case "set": $postdata['requestdomain'] = "[\"https://test-weshop.yolipai.net\"]"; $postdata['wsrequestdomain'] = "[\"https://test-weshop.yolipai.net\"]"; $postdata['uploaddomain'] = "[\"https://test-weshop.yolipai.net\"]"; $postdata['downloaddomain'] = "[\"https://test-weshop.yolipai.net\"]"; break; case "get": break; default: break; } $postdatastr = json_encode($postdata); $res = httpRequest("https://api.weixin.qq.com/wxa/modify_domain?access_token=" . $getauthorizer_access_token, $getpostr, $postdatastr); return $res; } // //获取授权小程序帐号的可选类目10 public function get_category() { $getstoid = I('stoid/d', 0); $getaction = I('action', 'get'); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/wxa/get_category?access_token=" . $getauthorizer_access_token, "GET"); return $res; } //将第三方提交的代码包提交审核11 public function submit_audit() { $getstoid = I('stoid/d', 0); $getaction = I('action', 'get'); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $tag = I('tag'); $first_class = I('first_class'); $second_class = I('second_class'); $third_class = I('third_class'); $title = I('title'); if ($tag && $first_class && $second_class && $third_class && $title) { $postdata['item_list']['tag'] = $first_class; $postdata['item_list']['first_class'] = $second_class; $postdata['item_list']['second_class'] = $third_class; $postdata['item_list']['third_class'] = $third_class; $postdata['item_list']['title'] = $title; $res = httpRequest("https://api.weixin.qq.com/wxa/submit_audit?access_token=" . $getauthorizer_access_token, "POST"); return $res; } else { return json(array('errcode' => -1, 'errmsg' => '参数有误')); } } //设置小程序隐私设置(是否可被搜索)12 public function changewxasearchstatus() { $getstoid = I('stoid/d', 0); // "status":0, //1表示不可搜索,0表示可搜索 $getstatus = I('status/d', 0); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $postdata['status'] = $getstatus; $postdatastr = json_encode($postdata); $res = httpRequest("https://api.weixin.qq.com/wxa/changewxasearchstatus?access_token=" . $getauthorizer_access_token, "POST", $postdatastr); return $res; } //查询小程序当前隐私设置(是否可被搜索)13 public function getwxasearchstatus() { $getstoid = I('stoid/d', 0); // "status":0, //1表示不可搜索,0表示可搜索 $getstatus = I('status/d', 0); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/wxa/getwxasearchstatus?access_token=" . $getauthorizer_access_token, "get"); return $res; } //获取小程序模板库标题列表14 public function template_library_list() { $getstoid = I('stoid/d', 0); // "status":0, //1表示不可搜索,0表示可搜索 $getp = I('p/d', 1); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getcount = 20; $getoffset = 0; if ($getp > 1) { $getoffset = $getp * $getcount; } $postdata['offset'] = $getoffset; $postdata['count'] = $getcount; $postdatastr = json_encode($postdata); $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list?access_token=" . $getauthorizer_access_token, "POST", $postdatastr); return $res; } //获取模板库某个模板标题下关键词库15 public function template_library_get() { $getstoid = I('stoid/d', 0); $getid = I('id'); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } if (empty($getid)) { return json(array('errcode' => -1, 'errmsg' => '请输入模板标题')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $postdata['id'] = $getid; $postdatastr = json_encode($postdata); $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get?access_token=" . $getauthorizer_access_token, "POST", $postdatastr); return $res; } //组合模板并添加至帐号下的个人模板库16 public function template_add() { $getstoid = I('stoid/d', 0); $getid = I('id'); $keyword_id_list = I('keyword_id_list'); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } if (empty($getid)) { return json(array('errcode' => -1, 'errmsg' => '请输入模板标题')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $postdata['id'] = $getid; $postdata['keyword_id_list'] = $keyword_id_list; $postdatastr = json_encode($postdata); $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=" . $getauthorizer_access_token, "POST", $postdatastr); return $res; } //获取帐号下已存在的模板列表17 public function template_list() { $getstoid = I('stoid/d', 0); $getp = I('p/d', 1); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getcount = 20; $getoffset = 0; if ($getp > 1) { $getoffset = $getp * $getcount; } $postdata['offset'] = $getoffset; $postdata['count'] = $getcount; $postdatastr = json_encode($postdata); $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=" . $getauthorizer_access_token, "POST", $postdatastr); return $res; } //组合模板并添加至帐号下的个人模板库18 public function template_del() { $getstoid = I('stoid/d', 0); $template_id = I('template_id'); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } if (empty($template_id)) { return json(array('errcode' => -1, 'errmsg' => '请选择删除模板ID')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $postdata['template_id'] = $template_id; $postdatastr = json_encode($postdata); $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token=" . $getauthorizer_access_token, "POST", $postdatastr); return $res; } //查询某个指定版本的审核状态19 public function get_auditstatus() { $getstoid = I('stoid/d', 0); $auditid = I('auditid'); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } if (empty($auditid)) { return json(array('errcode' => -1, 'errmsg' => '请选择提交审核时获得的审核id')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $postdata['auditid'] = $auditid; $postdatastr = json_encode($postdata); $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/wxa/get_auditstatus?access_token=" . $getauthorizer_access_token, "POST", $postdatastr); return $res; } //查询最新一次提交的审核状态20 public function get_latest_auditstatus() { $getstoid = I('stoid/d', 0); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=" . $getauthorizer_access_token, "get"); return $res; } //发布已通过审核的小程序21 public function release() { $getstoid = I('stoid/d', 0); if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $postdatastr = "{}"; $res = httpRequest("https://api.weixin.qq.com/wxa/release?access_token=" . $getauthorizer_access_token, "POST", $postdatastr); return $res; } //修改小程序线上代码的可见状态(仅供第三方代小程序调用)22 public function change_visitstatus() { $getstoid = I('stoid/d', 0); $getaction = I('action');//close为不可见,open为可见 if (empty($getstoid)) { return json(array('errcode' => -1, 'errmsg' => '请选择商家')); } if (empty($getaction)) { return json(array('errcode' => -1, 'errmsg' => '请输入可访问状态')); } $weapp = M('weapp')->where(array('store_id' => $getstoid))->find(); if (empty($weapp)) { return json(array('errcode' => -1, 'errmsg' => '该商家未授权')); } $getweptoken = weapp_get_access_token($weapp, $getstoid); $getweptoken = json_decode($getweptoken, true); if ($getweptoken['errcode'] != 0) { return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg'])); } $postdata['action'] = $getaction; $postdatastr = json_encode($postdata); $getauthorizer_access_token = $getweptoken["authorizer_access_token"]; $res = httpRequest("https://api.weixin.qq.com/wxa/change_visitstatus?access_token=" . $getauthorizer_access_token, "POST", $postdatastr); return $res; } //没有支付小程序 public function not_xcx() { $yy = M("storage_recharge")->where("store_id", getAdmStoId())->where('recharge_state', 1) ->where("wxapp_price_id>0")->field('dj_price_id')->select(); $aarr = M("wxapp_price")->where(array('id'=>array('neq',1)))->order('type desc,money desc')->select(); $barr = null; if ($yy) { foreach ($aarr as $k => $v) { if ( $v['type'] == 0) { if ($v['money'] <= 0) break; else { } $barr[] = $v; } else { if ($v['type'] == 1) $barr[] = $v; else break; } } } else { $barr = $aarr; } if ($barr) { $this->assign('price_arr', $barr); } //先判断缴费记录是否有该商家的记录 $rss = M('store_module_endtime')->where('store_id=' . getAdmStoId())->where('type', 5) ->where('is_sy', 0)->find(); if ($rss) { $end_time = strtotime('+1 year', $rss['end_time']); $end_time = date("Y-m-d H:i:s", $end_time); $this->assign('t_end_time', $end_time); } else { $end_time = strtotime('+1 year', time()); $end_time = date("Y-m-d H:i:s", $end_time); $this->assign('t_end_time', $end_time); } return $this->fetch('', getAdmStoId()); } /*** * 自定义模板有关 */ /***小程序模板列表***/ public function miniTemplateList() { $pagenum = I('pagenum/d', 10); $key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索 $cur_page = I('p/d', 0);//当前页数 $this->assign('key_word', $key_word); $this->assign('pagenum', $pagenum); $this->assign('cur_page', $cur_page); return $this->fetch('', getAdmStoId()); } /***小程序模板列表的加载更多***/ public function ajaxMiniTemplateList() { $key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索 $cur_page = I('p/d', 0);//当前页数 if ($cur_page <= 0) { $cur_page = 1; } $pagenum = I('pagenum/d', 10); $where = " a.type=4 and a.store_id=" . getAdmStoId(); $this->assign('stoid', getAdmStoId()); if ($key_word) { $where .= " and (a.page_title like '%$key_word%' or c.page_title like '%$key_word%' or a.template_sn like '%$key_word%')"; } $model = M('store_module'); $count = $model->alias('a') ->join('store_module c', 'a.from_id=c.id', 'left') ->where($where)->count(); $Page = new AjaxPage($count, $pagenum); $show = $Page->show(); $List = $model->alias('a') ->join('store_module c', 'a.from_id=c.id', 'left') ->where($where) ->field('a.*,c.page_title as page_title_type') ->order("a.billdate desc") ->limit($Page->firstRow . ',' . $Page->listRows)->select(); $oldurl = U('admin/template/templatelist', array( "key_word" => $key_word, "pagenum" => $pagenum, "p" => $cur_page, )); $this->assign('oldurl', urlencode($oldurl)); $this->assign('key_word', $key_word); $this->assign('pagenum', $pagenum); $this->assign('cur_page', $cur_page); $this->assign('temList', $List); $this->assign('page', $show);// 赋值分页输出 $this->assign('pager', $Page); // upload_ylp_log('模块列表'); return $this->fetch("", getAdmStoId()); } //小程序搜索选择模板 public function templatesearch_mini() { $p = I('p/d', 1); $type = I('type'); $type_id = I('type_id/d'); $kw = I('keywords'); $this->assign('keywords', $kw); $sto_id = getAdmStoId(); $where = " (type=0 or type=3)"; if ($type_id) { $where .= " and type_id=" . $type_id; } else { $type_id = 0; } $this->assign('gettypeid', $type_id); if (!empty($kw)) { $where .= " and (page_title like '%" . $kw . "%' )"; } $count = M('store_module')->where($where)->where("(store_id=" . $sto_id . " or store_id is null)")->count(); $Page = new Page($count, 10); $mList = M('store_module')->where($where) ->where("(store_id=" . $sto_id . " or store_id is null)") ->order('type desc,billdate DESC') ->limit($Page->firstRow . ',' . $Page->listRows)->select(); /*--数组顶部插入--*/ $show = $Page->show();//分页显示输出 foreach ($mList as $k => $v) { $check = M('store_renew_module')->where(['module_id' => $v['id'], 'store_id' => $sto_id])->where('end_time>' . time() . ' or end_time=0')->field('id')->find(); if ($check) { $mList[$k]['money'] = 0; $mList[$k]['isshow'] = 1; } } $this->assign('page', $show);//赋值分页输出 $this->assign('mList', $mList); $this->assign('pager', $Page);//赋值分页输出 return $this->fetch("", $sto_id); } //小程序模板处理 public function templatehandle_mini() { /*--获取id--*/ $id = I('id'); $new = I("new"); $this->assign("new", $new); $this->assign('is_mini', 1);//是小程序的页面 $this->initEditor(); $stoid = getAdmStoId(); /*-------模块读取-------*/ $rs = M("module")->order('sort')->where('is_use', 1)->select(); //元素 {"content":citem,"ename":data.data.eng_name,"name":"","icon":"",type:"1"}; type:1表示自定义模块 foreach ($rs as $k => $v) { //小程序的不需要富文本 if ($v['eng_name'] == "richText") continue; if ($v['eng_name'] == "groupbuy") continue; $str = file_get_contents(ROOT_PATH . $v['controljson']); $jdata = json_decode($str, true); $data[] = [ "content" => $jdata['content'], "ename" => $v['eng_name'], "name" => $v['name'], "icon" => getimg($v['module_icon'], NOIMG), "type" => 0 ]; } /*---------如果有自定义模块-------*/ $rrs = M('custommodule_list')->where('store_id', $stoid)->select(); if ($rrs) { $data[] = [ "content" => ['ename' => "", 'name' => ""], "ename" => "custom", "name" => "自定义", "icon" => "/public/static/images/model/custom_img.png", "type" => 1 ]; $this->assign("customlist", $rrs); } if (empty($data)) $data = -1; $this->assign("module", json_encode($data)); if (!empty($id)) { /*--模板读取--*/ $temdata = M("store_module")->where('id', $id)->find(); /*--3是空模板--*/ if ($temdata['type'] <> 3) { /*--要读取content--*/ if ($temdata['type'] == 0 || $temdata['type'] == 4) $p = ROOT_PATH . "/public/template/feature/" . $stoid . '/' . $temdata['template_sn'] . ".json"; else $p = ROOT_PATH . "/public/template/feature/" . $temdata['template_sn'] . ".json"; if (file_exists($p)) { $str = file_get_contents($p); if ($temdata['type'] != 0 && $new == 1) { $str = str_replace('stoid/1.html', "stoid/" . $stoid . "html", $str); $str = str_replace('stoid\/1.html', "stoid\/" . $stoid . ".html", $str); $str = str_replace('stoid\/1\/', "stoid\/" . $stoid . "\/", $str); $str = str_replace('stoid/1/', "stoid/" . $stoid . "/", $str); } $jjdata = json_decode($str, true); if ($temdata['type'] != 0 && $temdata['type'] != 4) { foreach ($jjdata as $kh => $vh) { $content = $vh['content']; if ($content['moudletype'] == 3 || $content['moudletype'] == 2 || $content['classstyle'] == 2) { $content['data'] = []; } $jjdata[$kh]['content'] = $content; } } } else { $this->assign("temdata", -1); $this->assign("config", -1); $this->assign("err", "未找到模板文件"); return $this->fetch(); } $this->assign("temdata", json_encode($jjdata)); /*--config--{"title":"","descr":"","istop":0,"isright":0,"money":0};*/ $data = [ "title" => $temdata['page_title'], "descr" => $temdata['page_describe'], "istop" => $temdata['istop'], "isright" => $temdata['isright'], "money" => $temdata['money'], "bkcolor" => $temdata['bkcolor'], ]; $this->assign("config", json_encode($data)); //商家要对from_id进行映射,如果是收费模板,要进行记录 if ($temdata['type'] == 2 || $temdata['type'] == 1) { $this->assign("from_id", $id); } else if ($temdata['type'] == 0) { $this->assign("from_id", $temdata['from_id']); } } else { $this->assign("temdata", -1); $this->assign("config", -1); } } else { $this->assign("temdata", -1); $this->assign("config", -1); } return $this->fetch("", getAdmStoId()); } /*-------小程序模板的保存------------*/ public function temlatesave_mini() { /*--清除缓存--*/ ClearALLCache(); delFile(TEMP_PATH . "/" . getAdmStoId()); $data = I("post."); $id = I('id'); $from_id = I('from_id/d', 0); $stoid = getAdmStoId(); /*---创建模板存放目录---*/ if (!is_dir(ROOT_PATH . '/public/template/feature/' . $stoid . '/')) mkdir(ROOT_PATH . '/public/template/feature/' . $stoid . '/'); /*----页面基础配置----*/ $conf = $data[1]; /*----json文件保存----*/ $str = json_encode($data[0]); mlog("文字:" . $str, "temlatesave/" . $stoid); if (!empty($id)) { $r10 = $rs = M('store_module')->where('id', $id)->find(); } /*----------------新增,或者是空模板,或者是从商家商城模板那里选择的-----------------*/ if (empty($id) || $r10['type'] == 3 || $r10['type'] == 0) { $mr = get_total_millisecond(); $sn = date('YmdHis') . $mr . rand(1000, 9999); /*--json文件操作--*/ $filename = '/public/template/feature/' . $stoid . '/' . $sn . '.json'; if (file_exists(ROOT_PATH . $filename) && $filename) { mdelFile(ROOT_PATH . $filename); } file_put_contents(ROOT_PATH . $filename, $str); /*---调用风格表存储手机端显示文件---*/ $filename2 = '/public/template/feature/' . $stoid . '/' . $sn . '.html'; if (file_exists(ROOT_PATH . $filename2) && $filename2) { mdelFile(ROOT_PATH . $filename2); } /*---手机前端要显示保存的内容---*/ mlog("文字122:" . json_encode($data[0]), "temlatesave/" . $stoid); $htm = ""; foreach ($data[0] as $k => $v) { if ($v['type'] == 1) { $htmlfile = '/public/template/custom/' . getAdmStoId() . '/' . $v['content']['ename'] . '.html'; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); $htm .= $cstr; } else { return json(['code' => -1, 'msg' => '未找自定义模板的文件']); } } else { /*--风格类型--*/ $type = $v['content']['style']; $r0 = M("module")->where('eng_name', $v['ename'])->find(); $r1 = M("module_list")->where('parent_id', $r0['id'])->where('type', $type)->find(); /*--获取手机前端要显示html--*/ $htmlfile = "/public/template/html/" . $r0['eng_name'] . "/mobliehtm" . $r1['class_eng_name'] . ".html"; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); } else { return json(['code' => -1, 'msg' => '未找到手机端展示文件']); } /*--根据字段替换--*/ $fields = explode(",", $r1['fields']); foreach ($fields as $kk => $vv) { $val = $v['content'][$vv]; if ($vv == 'no') { $val = uniqid(); } if ($vv == 'scoll_length') { $val = $v['content']['length']; if (count($v['content']['data']) < $val) { $val = count($v['content']['data']); } } if (gettype($val) == 'boolean') { $val = (int)$val; } $replacestr = "{{" . $vv . "}}"; $cstr = str_replace($replacestr, $val . "", $cstr); } /*--如果有循环体--*/ if (!empty($v['content']['data'])) { $rhtm = ""; $width = 100 / count($v['content']['data']); /*--截取循环里面的循环体--*/ $start1 = strpos($cstr, '', 0); if ($start1) { $end1 = strpos($cstr, '', 0); /* $str = "{{name}}"; */ $repeat = substr($cstr, $start1 + 9, $end1 - $start1 - 9); $cstr = str_replace('', "", $cstr); $cstr = str_replace('', "", $cstr); $cstr = str_replace($repeat, "{{the_repeat}}", $cstr); foreach ($v['content']['data'] as $kk => $vv) { $vv['width'] = $width; $rp = $repeat; foreach ($vv as $mk => $mv) { $replacestr = "{{" . $mk . "}}"; $rp = str_replace($replacestr, $mv . "", $rp); } $rhtm .= $rp; } $cstr = str_replace("{{the_repeat}}", $rhtm, $cstr); } else { /*--如果有按数组替换的--*/ if (strpos($cstr, '{{data[0]', 0)) { /*--根据字段替换--*/ foreach ($v['content']['data'] as $kk => $vv) { foreach ($vv as $km => $vm) { $replacestr = "{{data[" . $kk . "]." . $km . "}}"; $cstr = str_replace($replacestr, $vm . "", $cstr); } } } else { /*---如果是商品分组的手动选择商品---*/ if ( $v['content']['classstyle'] == 1 || $v['content']['moudletype'] == 2 || $v['content']['moudletype'] == 3 || $v['content']['moudletype'] == 4 ) { $idlist = ""; foreach ($v['content']['data'] as $kk => $vv) { $idlist .= $vv['goodsid'] . ","; } $idlist = substr($idlist, 0, strlen($idlist) - 1); $replacestr = "{{idlist}}"; $cstr = str_replace($replacestr, $idlist . "", $cstr); } } } } $htm .= $cstr; } } mlog("文字2:" . $htm, "temlatesave/" . $stoid); /*---写入文件---*/ file_put_contents(ROOT_PATH . $filename2, $htm); /*--存储数据--*/ $sdata = [ "type" => 4,//设置成了小程序模板 "page_title" => $conf['title'], "page_describe" => $conf['descr'], "bkcolor" => $conf['bkcolor'], "istop" => $conf['istop'], "isright" => $conf['isright'], "money" => $conf['money'], "template_sn" => $sn, "billdate" => time(), "store_id" => getAdmStoId(), "from_id" => $from_id, "json_str" => $str ]; $u = M('store_module')->save($sdata); if ($u) { upload_ylp_log('D01模板添加/确认提交'); return json(['code' => 1]); } else return json(['code' => -1, 'msg' => '保存失败']); } /*----------------编辑-----------------*/ else { $rs = M('store_module')->where('id', $id)->where('store_id', getAdmStoId())->find(); if (!$rs) { return json(['code' => -1, 'msg' => '未找到模板']); } $sn = $rs['template_sn']; /*--json文件操作--*/ $filename = '/public/template/feature/' . $stoid . '/' . $sn . '.json'; if (file_exists(ROOT_PATH . $filename) && $filename) { mdelFile(ROOT_PATH . $filename); } file_put_contents(ROOT_PATH . $filename, $str); /*---调用风格表存储手机端显示文件---*/ $filename2 = '/public/template/feature/' . $stoid . '/' . $sn . '.html'; if (file_exists(ROOT_PATH . $filename2) && $filename2) { mdelFile(ROOT_PATH . $filename2); } /*---手机前端要显示保存的内容---*/ $htm = ""; mlog("文字12:" . json_encode($data[0]), "temlatesave/" . $stoid); foreach ($data[0] as $k => $v) { if ($v['type'] == 1) { $htmlfile = '/public/template/custom/' . getAdmStoId() . '/' . $v['content']['ename'] . '.html'; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); $htm .= $cstr; } else { return json(['code' => -1, 'msg' => '未找自定义模板的文件']); } } else { /*--风格类型--*/ $type = $v['content']['style']; $r0 = M("module")->where('eng_name', $v['ename'])->find(); $r1 = M("module_list")->where('parent_id', $r0['id'])->where('type', $type)->find(); /*--获取手机前端要显示html--*/ $htmlfile = "/public/template/html/" . $r0['eng_name'] . "/mobliehtm" . $r1['class_eng_name'] . ".html"; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); } else { return json(['code' => -1, 'msg' => '未找到手机端展示文件']); } /*--根据字段替换--*/ $fields = explode(",", $r1['fields']); foreach ($fields as $kk => $vv) { $val = $v['content'][$vv]; if ($vv == 'no') { $val = uniqid(); } if ($vv == 'scoll_length') { $val = $v['content']['length']; if (count($v['content']['data']) < $val) { $val = count($v['content']['data']); } } if (gettype($val) == 'boolean') { $val = (int)$val; } $replacestr = "{{" . $vv . "}}"; $cstr = str_replace($replacestr, $val . "", $cstr); } /*--如果有循环体--*/ if (!empty($v['content']['data'])) { $rhtm = ""; $width = 100 / count($v['content']['data']); /*--截取循环里面的循环体--*/ $start1 = strpos($cstr, '', 0); if ($start1) { $end1 = strpos($cstr, '', 0); /* $str = "{{name}}"; */ $repeat = substr($cstr, $start1 + 9, $end1 - $start1 - 9); $cstr = str_replace('', "", $cstr); $cstr = str_replace('', "", $cstr); $cstr = str_replace($repeat, "{{the_repeat}}", $cstr); foreach ($v['content']['data'] as $kk => $vv) { $vv['width'] = $width; $rp = $repeat; foreach ($vv as $mk => $mv) { $replacestr = "{{" . $mk . "}}"; $rp = str_replace($replacestr, $mv . "", $rp); } $rhtm .= $rp; } $cstr = str_replace("{{the_repeat}}", $rhtm, $cstr); } else { /*--如果有按数组替换的--*/ if (strpos($cstr, '{{data[0]', 0)) { /*--根据字段替换--*/ foreach ($v['content']['data'] as $kk => $vv) { foreach ($vv as $km => $vm) { $replacestr = "{{data[" . $kk . "]." . $km . "}}"; $cstr = str_replace($replacestr, $vm . "", $cstr); } } } else { /*---如果是商品分组的手动选择商品---*/ if ( $v['content']['classstyle'] == 1 || $v['content']['classstyle'] == 2 || $v['content']['classstyle'] == 3 || $v['content']['moudletype'] == 2 || $v['content']['moudletype'] == 3 || $v['content']['moudletype'] == 4 ) { $idlist = ""; foreach ($v['content']['data'] as $kk => $vv) { $idlist .= $vv['goodsid'] . ","; } $idlist = substr($idlist, 0, strlen($idlist) - 1); $replacestr = "{{idlist}}"; $cstr = str_replace($replacestr, $idlist . "", $cstr); } } } } $htm .= $cstr; } } mlog("文字2:" . $htm, "temlatesave/" . $stoid); /*---写入文件---*/ file_put_contents(ROOT_PATH . $filename2, $htm); $mid = session('admin_id'); $rr = M("admin")->where("admin_id", $mid)->find(); /*--存储数据--*/ $sdata = [ "type" => 4,//设置成了小程序模板 "page_title" => $conf['title'], "page_describe" => $conf['descr'], "bkcolor" => $conf['bkcolor'], "istop" => $conf['istop'], "isright" => $conf['isright'], "money" => $conf['money'], "editdate" => time(), "editip" => getIP(), "editman" => $rr['ERPName'], "store_id" => getAdmStoId(), "from_id" => $from_id, "json_str" => $str ]; $u = M('store_module')->where('id', $id)->save($sdata); if ($u) { return json(['code' => 1]); } else return json(['code' => -1]); } } /*---小程序模板设置为首页---*/ public function sethomepage_mini() { /*--清除缓存--*/ ClearALLCache(); delFile(TEMP_PATH . "/" . getAdmStoId()); $id = I('id'); $stoid = getAdmStoId(); /*--查找模板--*/ $r0 = M('store_module')->where(['id' => $id, 'type' => 4, 'store_id' => $stoid])->find(); if ($r0) { M('store_module')->where(['type' => 4, 'store_id' => $stoid])->save(['isdefault' => 0]); M('store_module')->where(['id' => $id, 'type' => 4, 'store_id' => $stoid])->save(['isdefault' => 1]); return json(['code' => 1]); } else { return json(['code' => -1, 'msg' => '未找到该模板']); } } /*--小程序模板取消首页--*/ public function canclehomepage_mini() { /*--清除缓存--*/ ClearALLCache(); delFile(TEMP_PATH . "/" . getAdmStoId()); $id = I('id'); $stoid = getAdmStoId(); /*--查找模板--*/ $r0 = M('store_module')->where(['id' => $id, 'type' => 4, 'store_id' => $stoid])->find(); if ($r0) { M('store_module')->where(['id' => $id, 'type' => 4, 'store_id' => $stoid])->save(['isdefault' => 0]); return json(['code' => 1]); } else { return json(['code' => -1, 'msg' => '未找到该模板']); } } /** * 初始化编辑器链接 * 本编辑器参考 地址 http://fex.baidu.com/ueditor/ */ private function initEditor() { $this->assign("URL_upload", U('admin/Ueditor/imageUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片上传目录 $this->assign("URL_imageUp", U('admin/Ueditor/imageUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 不知道啥图片 $this->assign("URL_fileUp", U('admin/Ueditor/fileUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 文件上传s $this->assign("URL_scrawlUp", U('admin/Ueditor/scrawlUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片流 $this->assign("URL_getRemoteImage", U('admin/Ueditor/getRemoteImage', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 远程图片管理 $this->assign("URL_imageManager", U('admin/Ueditor/imageManager', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片管理 $this->assign("URL_getMovie", U('admin/Ueditor/getMovie', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 视频上传 $this->assign("URL_Home", ""); } //获取续费的信息 public function getxufeimoney() { $id = I("id"); $rs = M('store_module')->alias('a')->join('store_module b', 'a.from_id=b.id', 'left') ->field('a.from_id,b.money,b.days')->where('a.id', $id)->find(); if ($rs) { return json(['code' => 1, 'id' => $rs['from_id'], 'money' => $rs['money'], 'days' => $rs['days']]); } else { return json(['code' => 0]); } } //微信触发消息 public function wxsendlist() { $pagenum = 10;//每页显示多少条 if ((int)I('pagenum/s') > 0) { $pagenum = I('pagenum/s'); } $key_word = I('key_word') ? trim(I('key_word')) : ''; if ($key_word) { $where['b.typename|a.typeid'] = array('like', '%' . $key_word . '%'); } $where['store_id'] = getAdmStoId(); $model = M('weapp_sendlist'); $count = $model->alias('a')->join('weapp_sendtype b', ' a.typeid=b.typeid')->where($where)->count(); $Page = new Page($count, $pagenum); $list = $model->alias('a')->join('weapp_sendtype b', ' a.typeid=b.typeid')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('a.typeid asc')->select(); $show = $Page->show();//分页显示输出 $this->assign('page', $show);//赋值分页输出 $this->assign('list', $list); $this->assign('pager', $Page);//赋值分页输出 $this->assign('pagenum', $pagenum); $this->assign('oldurl', urlencode(curPageURL())); // $oldurl = urldecode(urldecode($oldurl)); // upload_ylp_log('微信消息设置'); return $this->fetch('', getAdmStoId()); } //添加推送消息 public function addwxsend() { $typwhere = "1=1"; $erpid = getERPId(); $oldurl = I('oldurl/s'); if ($oldurl) { $oldurl = urldecode(urldecode($oldurl)); } $getstoid = getAdmStoId(); $id = I('sendid'); //修改 if ($id) { $wxsend = M('weapp_sendlist')->alias('a') ->join('weapp_sendtype b', 'a.typeid=b.typeid', 'left') ->where(array('a.store_id' => $getstoid, 'a.sendid' => $id)) ->field('a.*,b.remark as type_remark,b.typestate') ->find(); if ($wxsend) { if (empty($wxsend['typestate'])) { $this->error('该模板微信官网已失效无法修改', U('Weapp/wxsendlist')); exit; } if ($wxsend['store_remark']) { $store_remark = json_decode($wxsend['store_remark'], true); $wxsend['first'] = $store_remark['first']; $wxsend['remark'] = $store_remark['remark']; } } // // } else { $wxsend['state'] = 1; $typwhere .= " and typeid not in(select typeid from wxd_weapp_sendlist where store_id=" . $getstoid . ") and typestate=1 "; } $typelist = M('weapp_sendtype')->where($typwhere)->order('typeid asc')->select(); if (IS_POST) { $data = input('post.'); $typeid = I('post.typeid'); $data['store_id'] = $getstoid; unset($data['wx_first']); unset($data['wx_remark']); $data['template_id'] = trim(I('template_id')); $data['htmlurl'] = trim(I('htmlurl')); if (I('post.wx_first') && I('post.wx_remark')) { $store_remark['first'] = I('post.wx_first'); $store_remark['remark'] = I('post.wx_remark'); $data['store_remark'] = json_encode($store_remark); } else { $data['store_remark'] = ""; } if ($id) { $data['sendid'] = $id; M("weapp_sendlist")->update($data); } else { $data['add_time'] = time(); $sendlist = M('weapp_sendlist')->where(array('store_id' => $getstoid, 'typeid' => $typeid))->find(); if ($sendlist) { $this->error('该模板已存在!', U('Admin/Weapp/addwxsend')); exit(); } else { M("weapp_sendlist")->insert($data); } } if ($oldurl) { $this->success("操作成功!!!", $oldurl); } else { $this->success("操作成功!!!", U('Admin/Weapp/wxsendlist')); } exit; } $this->assign('wxsend', $wxsend); $this->assign('typelist', $typelist); return $this->fetch('', getAdmStoId()); } //获取模板类型的格式 public function getwxremark(){ $model = M("weapp_sendtype"); $res= $model->where(array('typeid' => $_GET['typeid']))->find(); if ($model) { $return_arr = array('status' => 1, 'msg' => '操作成功', 'remark' =>$res['remark']); } else{ $return_arr = array('status' => -1, 'msg' => '获取失败', 'data' => ''); } $this->ajaxReturn($return_arr); } //消息模板测试 public function sendtest() { $getstoid = getAdmStoId(); $gid = I('post.sendid'); if (!empty($gid)) { $wxsend = M('weapp_sendlist')->where(array('store_id' => $getstoid, 'sendid' => $gid))->find(); } $this->assign('wxsend', $wxsend); return $this->fetch('', getAdmStoId()); } public function sumbitsendtest() { $getstoid = getAdmStoId(); $gid = I('post.sendid'); $mobile = I('post.mobile'); $userinfo = M('users')->alias('a') ->join('weapp b', 'a.store_id=b.store_id') ->field("a.*,b.appid") ->where(array('a.store_id' => $getstoid, 'a.mobile' => $mobile))->find(); if (empty($userinfo)) { $return_arr = array('code' => -1, 'msg' => '会员手机号不存在', 'data' => ''); $this->ajaxReturn($return_arr); } if (empty($userinfo['weapp_openid'])) { $return_arr = array('code' => -1, 'msg' => '该手机号未绑定线上会员', 'data' => ''); $this->ajaxReturn($return_arr); } $wxsend = M('weapp_sendlist')->alias('a')->where(array('a.store_id' => $getstoid, 'a.sendid' => $gid))->find(); $wxsendtype = M('weapp_sendtype')->where('typeid', $wxsend['typeid'])->find(); if (empty($wxsend)) { $return_arr = array('code' => -1, 'msg' => '未设置该模板', 'data' => ''); $this->ajaxReturn($return_arr); } $colorlist = urlencode("#FF0000|#173177|#173177|#173177|#173177|#173177|#FF0000|#ca003a"); $pd['colorlist'] = $colorlist; $pd['title'] = "测试标题"; $pd['key1'] = "关键字1"; $pd['key2'] = "关键字2"; $pd['key3'] = "关键字3";; $pd['key4'] = "关键字4"; $pd['key5'] = "关键字5"; $pd['remark'] = "备注"; $mdataarr = explode(",", $wxsendtype["myfieldlist"]); $postdata = null; /*--双数组,确定推送内容--*/ foreach ($mdataarr as $ku => $vu) { $postdata[] = $pd[$vu]; } $postdata[] = $colorlist; $backurl = ""; $return_arr = array('code' => 0, 'msg' => '发送成功', 'data' => '',); $this->ajaxReturn($return_arr); } //删除推送消息 public function delsendlist() { $model = M("weapp_sendlist"); $model->where(array('sendid' => $_GET['id'], 'store_id' => getAdmStoId()))->delete(); $return_arr = array('status' => 1, 'msg' => '操作成功', 'data' => '',); $this->ajaxReturn($return_arr); } }