作者 王晓刚
1 个管道 的构建 通过 耗费 33 秒

tb

... ... @@ -80,7 +80,7 @@ if (!function_exists('cdnurl')) {
* @param boolean $domain 是否显示域名 或者直接传入域名
* @return string
*/
function cdnurl($url, $domain = false)
function cdnurl($url, $domain = true)
{
$regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i";
$url = preg_match($regex, $url) ? $url : \think\Config::get('upload.cdnurl') . $url;
... ...
... ... @@ -108,7 +108,11 @@ class HomeBase extends Controller
*/
public function getUserId(){
if (empty($this->userId)) {
$this->redirect("user/login_view");
if($this->request->isAjax()){
$this->error('用户未登录~',url("user/login_view"));
}else{
$this->redirect("user/login_view");
}
}
$user = Db::name('user')->where(['id'=>$this->userId])->find();
if($user['status'] != 'normal'){
... ...
... ... @@ -58,10 +58,10 @@ if (!function_exists('distance')) {
*/
function distance($work, $user)
{
$lng1 = $user['longitude'];//经度1
$lat1 = $user['latitude'];//纬度1
$lng2 = $work['longitude'];//经度2
$lat2 = $work['latitude'];//纬度2
$lng1 = $user['lng'];//经度1
$lat1 = $user['lat'];//纬度1
$lng2 = $work['lng'];//经度2
$lat2 = $work['lat'];//纬度2
$EARTH_RADIUS = 6378137; //地球半径
$RAD = pi() / 180.0;
... ... @@ -73,7 +73,7 @@ if (!function_exists('distance')) {
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
$s = $s * $EARTH_RADIUS;
$result = round($s * 10000) / 10000;
return $result/1000;
return round($result/1000,2);
}
}
if (!function_exists('getAge')) {
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/13
* Time: 16:14
*/
namespace app\index\controller;
use app\common\controller\HomeBase;
class Address extends HomeBase
{
public function add(){
$user_id = $this->getUserId();
$param = $this->request->param();
$validate = new \think\Validate([
'name' => 'require',
'province_id' => 'require',
'city_id' => 'require',
'county_id' => 'require',
'phone' => 'require',
'address' => 'require',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$addressModel = new \app\index\model\Address();
$param['user_id'] = $user_id;
$param['createtime'] = time();
$param['updatetime'] = time();
$param['is_default'] = "2";
$result = $addressModel->insertData($param);
if(empty($result)){
$this->error('sql执行失败');
}
$this->success('SUCCESS','',['address_id'=>$result]);
}
public function edit(){
$user_id = $this->getUserId();
$param = $this->request->param();
$validate = new \think\Validate([
'address_id' => 'require',
'name' => 'require',
'province_id' => 'require',
'city_id' => 'require',
'county_id' => 'require',
'phone' => 'require',
'address' => 'require',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$addressModel = new \app\index\model\Address();
$param['updatetime'] = time();
$result = $addressModel->updateData(['id'=>$param['address_id'],'user_id'=>$user_id],$param);
if(empty($result)){
$this->error('sql执行失败');
}
$this->success('SUCCESS','',['address_id'=>$param['address_id']]);
}
public function update(){
$user_id = $this->getUserId();
$param = $this->request->param();
$validate = new \think\Validate([
'name' => 'require',
'province_id' => 'require',
'city_id' => 'require',
'county_id' => 'require',
'phone' => 'require',
'address' => 'require',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$param['updatetime'] = time();
$addressModel = new \app\index\model\Address();
if(!empty($param['address_id'])){
$address_id = $param['address_id'];
unset($param['address_id']);
$result = $addressModel->updateData(['id'=>$address_id,'user_id'=>$user_id],$param);
}else{
unset($param['address_id']);
$param['user_id'] = $user_id;
$param['createtime'] = time();
$param['is_default'] = "2";
$result = $addressModel->insertData($param);
$address_id = $result;
}
if(empty($result)){
$this->error('sql执行失败');
}
$data = $addressModel->findData(['id'=>$address_id]);
$this->success('SUCCESS','',$data);
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/11
* Time: 11:41
*/
namespace app\index\controller;
use app\common\controller\HomeBase;
use app\index\model\Store;
class Car extends HomeBase
{
/**
* 购物车页面
* @return mixed
*/
public function index(){
$user_id = $this->getUserId();
$carModel = new \app\index\model\Car();
$car1 = $carModel->where(['user_id'=>$user_id])->group('store_id')->select();
$store_ids = [];
foreach($car1 as $key => $c1){
$store_ids[] = $c1['store_id'];
}
$goodsModel = new \app\index\model\Goods();
$storeModel = new Store();
$store = $storeModel->selectData(['id'=>['in',$store_ids]]);
$store = collection($store)->toArray();
foreach($store as $key1 => $s){
$car = $carModel->selectData(['store_id'=>$s['id']]);
foreach($car as $key2 => $c){
$goods = $goodsModel->findData(['g.id'=>$c['goods_id']]);
$car[$key2]['goods'] = $goods;
}
$store[$key1]['car'] = collection($car)->toArray();
}
$this->assign('data',$store);
$this->assign('title','购物车');
return $this->fetch();
}
/**
* 更新购物车
*/
public function add(){
$user_id = $this->getUserId();
$goods_id = $this->request->param('goods_id',0,'intval');
$number = $this->request->param('number',1,'intval');
$type = $this->request->param('type',0,'intval');//1增,2减
$province_id = $this->request->param('province_id',0,'intval');
if(empty($goods_id) || empty($number) || empty($type) || empty($province_id)){
$this->error("缺少必要参数");
}
$goodsModel = new \app\index\model\Goods();
$data = $goodsModel->findData(['g.id'=>$goods_id]);
if(empty($data)){
$this->error('查询为空');
}
if($data['status'] != '1'){
$this->error('该商品已下架');
}
$storeModel = new Store();
$store = $storeModel->findData(['id'=>$data['store_id']]);
//判断该区域是否为会员
if($store['is_svip'] != '1'){
if($store['is_vip'] != '1'){
$this->error('该商品不可以进行该操作~');
}else{
if(!in_array($province_id,$store['province_ids'])){
$this->error('该商品不可以进行该操作~');
}
}
}
$carModel = new \app\index\model\Car();
$arr['user_id'] = $user_id;
$arr['goods_id'] = $goods_id;
$arr['store_id'] = $data['store_id'];
$arr['number'] = $number;
$car = $carModel->findData(['user_id'=>$user_id,'goods_id'=>$goods_id]);
if(empty($car)){
//新增
//判断库存是否充足
if($data['inventory'] < 1){
$this->error("商品 【$data[goodsname]】 库存不足~");
}
$arr['createtime'] = time();
$result = $carModel->insertData($arr);
}else{
//更新
$arr['updatetime'] = time();
if($type == 1){
//增加数量
//判断库存是否充足
if($data['inventory'] < 1){
$this->error("商品 【$data[goodsname]】 库存不足~");
}
$result = $carModel->where(['id'=>$car['id']])->setInc('number',$number);
}else{
//减少数量
if($car['number'] <= 1){
$this->error('不能再减了~');
}
$result = $carModel->where(['id'=>$car['id']])->setDec('number',$number);
}
}
if(empty($result)){
$this->error('sql执行失败');
}
$car = $carModel->findData(['user_id'=>$user_id,'goods_id'=>$goods_id]);
$this->success('SUCCESS','',['number'=>$car['number']]);
}
/**
* 删除购物车
*/
public function del(){
$car_ids = $this->request->param('car_ids');
$car_ids = explode(',',$car_ids);
if(empty($car_ids)){
$this->error('缺少必要参数');
}
$carModel = new \app\index\model\Car();
$result = $carModel->where(['id'=>['in',$car_ids]])->delete();
$this->success('SUCCESS');
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/11
* Time: 15:20
*/
namespace app\index\controller;
use app\common\controller\HomeBase;
use app\index\model\Goodscollect;
class Collect extends HomeBase
{
public function index(){
$user_id = $this->getUserId();
$goods_id = $this->request->param('goods_id',0,'intval');
if(empty($goods_id)){
$this->error('缺少必要参数');
}
$where['user_id'] = ['eq',$user_id];
$where['goods_id'] = ['eq',$goods_id];
$collectModel = new Goodscollect();
$data = $collectModel->findData($where);
$arr['user_id'] = $user_id;
$arr['goods_id'] = $goods_id;
$arr['createtime'] = time();
if(empty($data)){
$result = $collectModel->insertData($arr);
}else{
$result = $collectModel->deleteData($where);
}
if(empty($result)){
$this->error('sql执行失败');
}
$this->success('SUCCESS',$result);
}
}
\ No newline at end of file
... ...
... ... @@ -11,6 +11,7 @@ namespace app\index\controller;
use app\common\controller\HomeBase;
use app\index\model\Evaluate;
use app\index\model\Goodscollect;
use app\index\model\Goodstype;
use app\index\model\Pic;
use app\index\model\Province;
... ... @@ -46,6 +47,7 @@ class Goods extends HomeBase
* @return mixed
*/
public function detail(){
$user_id = $this->userId;
$goods_id = $this->request->param('goods_id',0,'intval');
if(empty($goods_id)){
$this->error('缺少必要参数');
... ... @@ -58,6 +60,16 @@ class Goods extends HomeBase
if($data['status'] != '1'){
$this->error('该商品已下架');
}
//收藏
$is_collect = "2";
if(!empty($user_id)){
$collectModel = new Goodscollect();
$collect = $collectModel->findData(['user_id'=>$user_id,'goods_id'=>$goods_id]);
if(!empty($collect)){
$is_collect = "1";
}
}
$data['is_collect'] = $is_collect;
//获取评论
$evaluateModel = new Evaluate();
$comments_count1 = $evaluateModel->countData(['goods_id'=>$goods_id]);//全部评论数量
... ... @@ -125,10 +137,19 @@ class Goods extends HomeBase
$where['g.status'] = ['eq','1'];
if(!empty($param['province_id'])){
$storeModel = new Store();
$store = $storeModel->selectData(['province_ids'=>['like',"%,$param[province_id],%"]]);
$store = $storeModel->selectData([]);
$store_ids = [];
foreach($store as $key => $s){
$store_ids[] = $s['id'];
/*//判断该区域是否为会员
if($s['is_svip'] == '1'){
$store_ids[] = $s['id'];
continue;
}
if($s['is_vip'] == '1' && in_array($param['province_id'],$s['province_ids'])){
$store_ids[] = $s['id'];
continue;
}*/
}
$where['g.store_id'] = ['in',$store_ids];
}
... ... @@ -170,9 +191,28 @@ class Goods extends HomeBase
}
}
$goodsModel = new \app\index\model\Goods();
$ids = [];
if(!empty($param['lng']) && !empty($param['lat'])){
$data = $goodsModel
->alias('g')
->field('g.*,t.name as goodstype_name,s.lng,s.lat,s.name as store_name,s.address as store_address,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
->join('sto_goodstype t','t.id = g.goodstype_id')
->join('sto_store s','s.id = g.store_id')
->where($where)
->order($order)
->select();
foreach($data as $key => $vo){
//计算距离
$distance = distance($param,$vo);
if($distance <= 50){
$ids[] = $vo['id'];
}
}
$where['g.id'] = ['in',$ids];
}
$data = $goodsModel
->alias('g')
->field('g.*,t.name as goodstype_name,s.name as store_name,s.address as store_address,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
->field('g.*,t.name as goodstype_name,s.lng,s.lat,s.name as store_name,s.address as store_address,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
->join('sto_goodstype t','t.id = g.goodstype_id')
->join('sto_store s','s.id = g.store_id')
->where($where)
... ... @@ -185,19 +225,27 @@ class Goods extends HomeBase
$storeModel = new Store();
$evaluateModel = new Evaluate();
foreach($data as $key => $vo){
//判断店铺在该区域是否为会员
$insurance = '2';
$store = $storeModel->findData(['id'=>$vo['store_id']]);
if($store['is_vip'] == '1' && $store['is_svip'] == '1'){
if($store['is_svip'] == '1' || ($store['is_vip'] == '1' && in_array($param['province_id'],$store['province_ids']))){
$insurance = '1';
}
$data[$key]['store_is_vip'] = $store['is_vip'];
$data[$key]['store_ids_svip'] = $store['is_svip'];
$data[$key]['insurance'] = $insurance;
//计算平均分
$score_count = $evaluateModel->where(['goods_id'=>$vo['id']])->count();
$score_sum = $evaluateModel->where(['goods_id'=>$vo['id']])->sum('level');
$average_score = !empty($score_sum) ? round($score_sum/$score_count,2) : 0;
$data[$key]['average_score'] = $average_score;
//计算距离
$distance = 0;
if(!empty($param['lng']) && !empty($param['lat'])){
$distance = distance($param,$vo);
if($distance <= 50){
$ids[] = $vo['id'];
}
}
$data[$key]['distance'] = $distance;
}
if(!empty($param['sort'])){
if($param['sort'] == 2){
... ... @@ -207,4 +255,25 @@ class Goods extends HomeBase
}
$this->success('SUCCESS','',$data);
}
public function get_one(){
$param = $this->request->param();
if(empty($param['goods_id']) || empty($param['province_id'])){
$this->error('缺少必要参数');
}
$goodsModel = new \app\index\model\Goods();
$data = $goodsModel->findData(['g.id'=>$param['goods_id']]);
if(empty($data)){
$this->error('查询为空','',['result'=>2]);
}
$storeModel = new Store();
$store = $storeModel->findData(['id'=>$data['store_id']]);
if(empty($store)){
$this->error('查询为空','',['result'=>2]);
}
$result = 2;
if($store['is_svip'] == '1' || ($store['is_vip'] == '1' && in_array($param['province_id'],$store['province_ids']))){
$result = 1;
}
$this->success('SUCCESS','',['result'=>$result]);
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/12
* Time: 18:19
*/
namespace app\index\controller;
use app\common\controller\HomeBase;
use app\index\model\Address;
use app\index\model\Area;
use app\index\model\Store;
class Order extends HomeBase
{
public function confirm(){
$user_id = $this->getUserId();
// $car_ids = $this->request->param('car_ids');
$data = $this->request->param('data');
$province_id = $this->request->param('province_id',0,'intval');
if(empty($data) || empty($province_id)){
$this->error('缺少必要参数');
}
$data = json_decode($data,true);
/*if(!empty($car_ids)){
$car_ids = explode(',',$car_ids);
$carModel = new \app\index\model\Car();
$result = $carModel->where(['id'=>$car_ids])->delete();
if(empty($result)){
$this->error('sql执行失败');
}
}*/
$goodsModel = new \app\index\model\Goods();
$goods_price = [];
$store_ids = [];
foreach($data as $key1 => $vo){
//获取店铺id
$goods = $goodsModel->findData(['g.id'=>$vo['goods_id']]);
$data[$key1]['store_id'] = $goods['store_id'];
$store_ids[] = $goods['store_id'];
}
$storeModel = new Store();
$store = $storeModel->selectData(['id'=>['in',$store_ids]]);
foreach($store as $key2 => $s){
if($s['is_svip'] != '1'){
if($s['is_vip'] != '1' && !in_array($province_id,$s['province_ids'])){
$this->error("店铺 【$s[name]】 不可以进行购买~");
}
}
$goods_ids = [];
$number = [];
foreach($data as $key3 => $vo){
if($vo['store_id'] == $s['id']){
$goods_ids[] = $vo['goods_id'];
$number[] = $vo['number'];
}
}
$store[$key2]['goods_ids'] = $goods_ids;
$goods_arr = [];
foreach($goods_ids as $key4 => $goods_id){
$goods = $goodsModel->findData(['g.id'=>$goods_id]);
if($goods['inventory'] < $number[$key4]){
$this->error("商品 【$goods[goodsname]】 库存不足~");
}
$goods['number'] = $number[$key4];
$goods_price[] = $goods['price']*$number[$key4];
$goods_arr[] = $goods;
}
//商品总价格
$store[$key2]['sum_goods_price'] = array_sum($goods_price);
//商品实际支付价格
$goods_total = $store[$key2]['sum_goods_price'];
$store[$key2]['goods_total'] = $goods_total;
//配送价格
$postage_price = 0;
if($goods_total < $s['money']){
$postage_price = $store['freight'];
}
$store[$key2]['postage_price'] = $postage_price;
$store[$key2]['goods'] = $goods_arr;
}
//总合计
$goods_total1 = 0;
$postage_price1 = 0;
foreach($store as $key => $vo3){
$goods_total1 = $goods_total1 + $vo3['goods_total'];
$postage_price1 = $postage_price1 + $vo3['postage_price'];
}
$total = $goods_total1 + $postage_price1;
//收货地址
$addressModel = new Address();
$address = $addressModel->selectData(['user_id'=>$user_id]);
//省市区三级联动
$areaModel = new Area();
$province = $areaModel->selectData(['pid'=>0,'level'=>1]);
$province_id = !empty($province[0]['id']) ? $province[0]['id'] : 0;
$city = $areaModel->selectData(['pid'=>$province_id,'level'=>2]);
$city_id = !empty($city[0]['id']) ? $city[0]['id'] : 0;
$county = $areaModel->selectData(['pid'=>$city_id,'level'=>3]);
$this->assign('province',$province);
$this->assign('city',$city);
$this->assign('county',$county);
$this->assign('store',$store);
$this->assign('total',$total);
$this->assign('address',$address);
$this->assign('title','确认订单');
return $this->fetch();
}
}
\ No newline at end of file
... ...
... ... @@ -10,6 +10,7 @@ namespace app\index\controller;
use app\common\controller\HomeBase;
use app\index\model\Area;
use app\index\model\Province;
use fast\Http;
... ... @@ -51,4 +52,20 @@ class Sundry extends HomeBase
$province_id = $provinceModel->where(['name'=>$province_name])->value('id');
$this->success('SUCCESS','',['province_id'=>$province_id]);
}
/**
* 省市区三级联动
*/
public function get_area(){
$pid = $this->request->param('pid',0,'intval');
$level = $this->request->param('level',0,'intval');
if(empty($level)){
$this->error('缺少必要参数');
}
$where['pid'] = ['eq',$pid];
$where['level'] = ['eq',$level];
$areaModel = new Area();
$data = $areaModel->selectData($where);
$this->success('SUCCESS','',$data);
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/13
* Time: 10:57
*/
namespace app\index\model;
use think\Model;
class Address extends Model
{
public function selectData($where){
$data = $this->where($where)->order('createtime desc')->select();
$areaModel = new Area();
foreach ($data as $key => $vo){
$province_name = $areaModel->where(['id'=>$vo['province_id']])->value('name');
$city_name = $areaModel->where(['id'=>$vo['city_id']])->value('name');
$county_name = $areaModel->where(['id'=>$vo['county_id']])->value('name');
$data[$key]['province_name'] = $province_name;
$data[$key]['city_name'] = $city_name;
$data[$key]['county_name'] = $county_name;
}
return $data;
}
public function findData($where){
$data = $this->where($where)->find();
$areaModel = new Area();
$province_name = $areaModel->where(['id'=>$data['province_id']])->value('name');
$city_name = $areaModel->where(['id'=>$data['city_id']])->value('name');
$county_name = $areaModel->where(['id'=>$data['county_id']])->value('name');
$data['province_name'] = $province_name;
$data['city_name'] = $city_name;
$data['county_name'] = $county_name;
return $data;
}
public function insertData($data){
$result = $this->insertGetId($data);
return $result;
}
public function updateData($where,$data){
$result = $this->where($where)->update($data);
return $result;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/13
* Time: 13:34
*/
namespace app\index\model;
use think\Model;
class Area extends Model
{
public function selectData($where){
$data = $this->where($where)->order('id asc')->select();
return $data;
}
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/11
* Time: 11:58
*/
namespace app\index\model;
use think\Model;
class Car extends Model
{
public function insertData($data){
$result = $this->insertGetId($data);
return $result;
}
public function updateData($where,$data){
$result = $this->where($where)->update($data);
return $result;
}
public function selectData($where){
$data = $this->where($where)->order('createtime desc')->select();
return $data;
}
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
}
\ No newline at end of file
... ...
... ... @@ -20,6 +20,9 @@ class Goods extends Model
}
return $data;
}
public function getThumbnailAttr($value){
return cdnurl($value);
}
public function selectData($where){
$where['g.status'] = ['eq','1'];
$data = $this
... ... @@ -32,14 +35,9 @@ class Goods extends Model
->select();
$storeModel = new Store();
foreach($data as $key => $vo){
$insurance = '2';
$store = $storeModel->findData(['id'=>$vo['store_id']]);
if($store['is_vip'] == '1' && $store['is_svip'] == '1'){
$insurance = '1';
}
$data[$key]['store_is_vip'] = $store['is_vip'];
$data[$key]['store_ids_svip'] = $store['is_svip'];
$data[$key]['insurance'] = $insurance;
$data[$key]['store_is_svip'] = $store['is_svip'];
}
return $data;
}
... ... @@ -55,34 +53,24 @@ class Goods extends Model
->paginate($pageNum);
$storeModel = new Store();
foreach($data as $key => $vo){
$insurance = '2';//保险logo
$store = $storeModel->findData(['id'=>$vo['store_id']]);
if($store['is_vip'] == '1' && $store['is_svip'] == '1'){
$insurance = '1';
}
$data[$key]['store_is_vip'] = $store['is_vip'];
$data[$key]['store_ids_svip'] = $store['is_svip'];
$data[$key]['insurance'] = $insurance;
$data[$key]['store_is_svip'] = $store['is_svip'];
}
return $data;
}
public function findData($where){
$data = $this
->alias('g')
->field('g.*,t.name as goodstype_name,s.name as store_name,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
->field('g.*,t.name as goodstype_name,s.lng,s.lat,s.name as store_name,s.address as store_address,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
->join('sto_goodstype t','t.id = g.goodstype_id')
->join('sto_store s','s.id = g.store_id')
->where($where)
->find();
$storeModel = new Store();
$insurance = '2';//保险logo
$store = $storeModel->findData(['id'=>$data['store_id']]);
if($store['is_vip'] == '1' && $store['is_svip'] == '1'){
$insurance = '1';
}
$data['store_is_vip'] = $store['is_vip'];
$data['store_ids_svip'] = $store['is_svip'];
$data['insurance'] = $insurance;
$data['store_is_svip'] = $store['is_svip'];
return $data;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/11
* Time: 14:33
*/
namespace app\index\model;
use think\Model;
class Goodscollect extends Model
{
public function insertData($data){
$result = $this->insert($data);
return $result;
}
public function updateData($where,$data){
$result = $this->where($where)->update($data);
return $result;
}
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
public function deleteData($where){
$result = $this->where($where)->delete();
return $result;
}
}
\ No newline at end of file
... ...
... ... @@ -13,13 +13,24 @@ use think\Model;
class Store extends Model
{
public function getProvinceIdsAttr($value){
$province_ids = [];
if(!empty($value)){
$province_ids = explode(',',trim($value,','));
}
return $province_ids;
}
public function getThumbnailAttr($value){
return cdnurl($value);
}
public function selectData($where){
$data = $this->where($where)->select();
$areaModel = new Area();
foreach($data as $key => $vo){
//判断是否为会员
//判断会员是否过期
$is_vip = '2';
if(!empty($vo['vip_pasttime'])){
if($vo['vip_pasttime'] > time()){
if(!empty($vo['vip_passtime'])){
if($vo['vip_passtime'] > time()){
$is_vip = "1";
}
}
... ... @@ -31,15 +42,22 @@ class Store extends Model
}
$data[$key]['is_vip'] = $is_vip;
$data[$key]['is_svip'] = $is_svip;
//获取省市区
$province_name = $areaModel->where(['id'=>$vo['province_id']])->value('name');
$city_name = $areaModel->where(['id'=>$vo['city_id']])->value('name');
$county_name = $areaModel->where(['id'=>$vo['county_id']])->value('name');
$data[$key]['province_name'] = $province_name;
$data[$key]['city_name'] = $city_name;
$data[$key]['county_name'] = $county_name;
}
return $data;
}
public function findData($where){
$data = $this->where($where)->find();
//判断是否为会员
//判断会员是否过期
$is_vip = '2';
if(!empty($data['vip_pasttime'])){
if($data['vip_pasttime'] > time()){
if(!empty($data['vip_passtime'])){
if($data['vip_passtime'] > time()){
$is_vip = "1";
}
}
... ... @@ -51,6 +69,14 @@ class Store extends Model
}
$data['is_vip'] = $is_vip;
$data['is_svip'] = $is_svip;
//获取省市区
$areaModel = new Area();
$province_name = $areaModel->where(['id'=>$data['province_id']])->value('name');
$city_name = $areaModel->where(['id'=>$data['city_id']])->value('name');
$county_name = $areaModel->where(['id'=>$data['county_id']])->value('name');
$data['province_name'] = $province_name;
$data['city_name'] = $city_name;
$data['county_name'] = $county_name;
return $data;
}
}
\ No newline at end of file
... ...
... ... @@ -15,8 +15,8 @@ class User extends Model
$data = $this->where($where)->find();
//判断是否为会员
$is_vip = '2';
if(!empty($data['vip_pasttime'])){
if($data['vip_pasttime'] > time()){
if(!empty($data['vip_passtime'])){
if($data['vip_passtime'] > time()){
$is_vip = "1";
}
}
... ...
<!DOCTYPE html>
<html lang="zh">
{include file="public/head"/}
<!--swiper引入-->
<link rel="stylesheet" href="__CDN__/assets/store/js/Swiper-3.4.2/css/swiper.min.css">
<script type="text/javascript" src="__CDN__/assets/store/js/Swiper-3.4.2/js/swiper.min.js"></script>
<style>
body{
background: rgba(249,249,249,1);
}
.content{
width: 100%;
font-size: 0;
background: rgba(249,249,249,1);
}
/*购物车样式*/
.content .shoppingCartBox{
width: 100%;
background: rgba(249,249,249,1);
}
/*购物车标题部分样式*/
.content .shoppingCartBox .shoppingCartTitleBox{
width: 1200px;
background: rgba(255,255,255,1);
margin: 0 auto 12px auto;
font-size: 16px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(61,68,77,1);
border-radius:8px;
}
.content .shoppingCartBox .shoppingCartTitleBox .titleBox{
width: 1200px;
height: 62px;
line-height: 62px;
}
.content .shoppingCartBox .shoppingCartTitleBox .titleBox span:first-child{
display: inline-block;
float: left;
width: 6px;
height: 20px;
margin-top: 21px;
background: rgba(0,159,142,1);
border-radius: 2px;
}
.content .shoppingCartBox .shoppingCartTitleBox .titleBox span:nth-child(2){
height: 22px;
line-height: 22px;
float: left;
margin-top: 20px;
padding-left: 12px;
font-size: 16px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(0,159,142,1);
}
.content .shoppingCartBox .shoppingCartTitleBox .shoppingCartTitle{
width: 100%;
height: 70px;
padding: 0 30px;
line-height: 70px;
font-size: 16px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(61,68,77,1);
}
.content .shoppingCartBox .shoppingCartTitleBox .shoppingCartTitle table{
width: 100%;
height: 100%;
}
/*购物车商品部分样式*/
.content .shopListBox{
width: 1200px;
margin: 0 auto;
}
.content .shopListBox .shopBox{
margin-bottom: 12px;
}
.content .shopListBox .shopBox .title{
width: 100%;
height: 39px;
padding: 0 30px;
font-size: 14px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(61,68,77,1);
border-bottom: 1px solid rgba(238,238,238,1);
background: rgba(255,255,255,1);
border-radius: 8px 8px 0 0;
}
.content .shopListBox .shopBox .title p{
display: inline-block;
height: 39px;
line-height: 39px;
font-size: 14px;
font-family: PingFang SC;
font-weight:500;
color: rgba(61,68,77,1);
}
.content .shopListBox .shopBox .title p:first-child{
width: 276px;
}
.content .shopListBox .shopBox .title p:nth-child(2){
width: 130px;
}
.content .shopListBox .shopBox .title p:nth-child(3){
color:rgba(234,50,43,1);
}
.content .shopListBox .shopBox .title p:nth-child(3) img{
margin-top: -5px;
}
.content .shopListBox .shopBox .title p:nth-child(3) span{
/*vertical-align: middle;*/
}
.content .shopListBox .shopBox ul{
width: 100%;
background: rgba(255,255,255,1);
border-radius: 0 0 8px 8px;
}
.content .shopListBox .shopBox ul li{
list-style-type: none;
width: 100%;
height: 120px;
padding: 0 30px;
}
.content .shopListBox .shopBox ul li div{
display: inline-block;
}
.content .shopListBox .shopBox ul li .radioBox{
width: 40px;
height: 100%;
line-height: 120px;
border-bottom: transparent;
}
.content .shopListBox .shopBox ul li .imgBox{
width: 110px;
height: 100%;
line-height: 120px;
display: inline-block;
}
.content .shopListBox .shopBox ul li .imgBox img{
width: 72px;
height: 72px;
}
.content .shopListBox .shopBox ul li .borderBox{
width: 1100px;
height: 100%;
float: right;
border-bottom:1px solid rgba(238,238,238,1);
font-size: 14px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(91,94,99,1);
}
.content .shopListBox .shopBox ul li .commodityNameBox{
width: 416px;
height: 100%;
}
.content .shopListBox .shopBox ul li .commodityNameBox p{
margin: 0;
}
.content .shopListBox .shopBox ul li .unitPriceBox{
width: 109px;
height: 100%;
text-align: center;
}
.content .shopListBox .shopBox ul li .numberBox{
width: 183px;
height: 100%;
text-align: center;
}
.content .shopListBox .shopBox ul li .numberBox .input-group-btn{
width: 30px;
height: 30px;
}
.content .shopListBox .shopBox ul li .numberBox .input-group-btn button{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border:1px solid rgba(238,238,238,1);
color: #5B5E63;
}
.content .shopListBox .shopBox ul li .numberBox .input-group-btn:first-child{
float: left;
}
.content .shopListBox .shopBox ul li .numberBox .contInput{
width: 56px;
height: 30px;
text-align: center;
color: #5B5E63;
}
.content .shopListBox .shopBox ul li .subtotalBox{
width: 150px;
height: 100%;
text-align: center;
}
.content .shopListBox .shopBox ul li .operationBox{
width: 110px;
height: 100%;
text-align: right;
}
.content .shopListBox .shopBox ul li .operationBox .btnSpan{
cursor: pointer;
}
.content .shopListBox .shopBox ul li .operationBox .btnSpan span{
vertical-align: middle;
}
/*结算订单部分样式*/
.content .submitBox {
width: 1200px;
height: 52px;
background: rgba(255, 255, 255, 1);
border-radius: 8px;
margin: 60px auto 50px auto;
padding-left: 30px;
}
.content .submitBox .myCheckBox{
display: inline-block;
width: 66px;
height: 52px;
line-height: 52px;
margin: 0;
font-size:12px;
font-family:PingFang SC;
font-weight:500;
color:rgba(140,145,152,1);
}
.content .submitBox .myCheckBox #checkAll_bottom{
vertical-align: middle;
margin: -2px 6px 0 0;
}
.content .submitBox .myCheckBox span{
/*vertical-align: middle;*/
}
.content .submitBox p {
display: inline-block;
width: 100px;
height: 52px;
line-height: 52px;
font-size: 14px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(140, 145, 152, 1);
margin: 0;
}
.content .submitBox .btnP{
cursor: pointer;
}
.content .submitBox .totalPrice {
width: 730px;
text-align: right;
padding-right: 21px;
}
.content .submitBox .totalPrice span {
font-size: 16px;
color: rgba(234, 50, 43, 1);
}
.content .submitBox .totalPrice #totalCount{
font-size: 12px;
color: rgba(61,68,77,1);
}
.content .submitBox .btn {
width: 170px;
height: 52px;
background: rgba(0, 159, 142, 1);
border: 0;
font-size: 16px;
font-family: PingFang SC;
font-weight: 500;
line-height: 22px;
color: rgba(255, 255, 255, 1);
border-radius: 0;
margin-top: -12px;
}
</style>
<body>
{include file="public/header"/}
<!--主要内容-->
<div class="content">
<div class="navBarBox">
<ul>
<li><a href="{:url('index/index')}">首页</a></li>
<li><a href="{:url('goods/index')}">采购中心</a></li>
<li><a href="">帮买服务</a></li>
<li><a href="">产品维修</a></li>
<li><a href="">关于我们</a></li>
</ul>
</div>
<div class="shoppingCartBox">
<!--购物车头部部分-->
<div class="shoppingCartTitleBox">
<div class="titleBox">
<span></span>
<span>我的购物车</span>
</div>
<div class="shoppingCartTitle">
<table>
<tr>
<td style="width: 155px">
<div style="display:inline-block;height: 70px;line-height: 70px">
<input id="checkAll_top" type="checkbox" style="margin: 0 10px 0 0;vertical-align: middle">
</div>
<span style="vertical-align: middle">全选</span>
</td>
<td style="width: 415px">商品</td>
<td style="width: 117px;text-align: center">单价</td>
<td style="width: 186px;text-align: center">数量</td>
<td style="width: 152px;text-align: center">小计</td>
<td style="text-align: right">操作</td>
</tr>
</table>
</div>
</div>
<!--购物车商品部分-->
<div class="shopListBox">
{foreach name="$data" item="vo"}
<div class="shopBox" data-free_freight="{$vo.money}" data-freight="{$vo.freight}">
<div class="title">
<p>{$vo.name}</p>
<p>运费:{eq name="$vo.freight" value="0"}免运费{else /}¥{$vo.freight}{/eq}</p>
{neq name="$vo.freight" value="0"}
<p>
<img src="__CDN__/assets/store/images/discountImg.png" alt="img">
<span>满{$vo.money}元免运费</span>
</p>
{/neq}
</div>
<ul>
{foreach name="$vo.car" item="c"}
<li>
<div class="radioBox"><input class="commodityCheck" type="checkbox" data-goods_id="{$c.goods_id}" data-number="{$c.number}" value="{$c.id}"></div>
<div class="borderBox">
<div class="imgBox">
<img src="{$c.goods.thumbnail}" alt="img">
</div>
<div class="commodityNameBox">
<p style="width: 196px">{$c.goods.goodsname}</p>
</div>
<div class="unitPriceBox">
¥{$c.goods.price}
</div>
<div class="numberBox">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default car-decrease" data-goods_id="{$c.goods_id}" data-type="2">-</button>
</div>
<input type="text" class="form-control contInput" value="{$c.number}">
<div class="input-group-btn">
<button type="button" class="btn btn-default car-add" data-goods_id="{$c.goods_id}" data-type="1">+</button>
</div>
</div>
</div>
<div class="subtotalBox">
¥{$c.goods.price*$c.number}
</div>
<div class="operationBox">
<span class="btnSpan" onclick="del(this,{$c.id})">
<img src="__CDN__/assets/store/images/icon_del.png" alt="">
<span>删除</span>
</span>
</div>
</div>
</li>
{/foreach}
</ul>
</div>
{/foreach}
</div>
<!--结算订单部分-->
<div class="submitBox">
<div class="myCheckBox">
<input id="checkAll_bottom" type="checkbox">
<span>全选</span>
</div>
<p class="btnP" onclick="delSelect()">删除选中商品</p>
<p class="btnP" onclick="clearFun()">清空购物车</p>
<p class="totalPrice">已选择&nbsp;<span id="totalCount">0</span>&nbsp;件商品&nbsp;&nbsp;&nbsp;总价:<span style="color: #EA322B">¥</span><span id="totalPrice">0.00</span></p>
<button type="button" class="btn" onclick="settlement()">去结算</button>
</div>
</div>
</div>
{include file="public/footer"/}
{include file="public/js"/}
<script>
$(function () {
initLocation();
});
//定位当前位置
function initLocation(){
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
$('#locationText').html(r.address.province + "" + r.address.city);
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
//省份名称转换为id
$.ajax({
url:"{:url('index/sundry/get_province_id')}",
type:"POST",
data:{"province_name":r.address.province},
async:false,
success:function(res){
if(res.code == 1){
province_id = res.data.province_id;
lng = r.point.lng;
lat = r.point.lat;
}else{
toast(res.msg);
}
},
error:function(res){
toast('与服务器断开连接');
}
});
} else {
toast('failed'+this.getStatus());
}
},{enableHighAccuracy: true})
}
//去结算
function settlement() {
if($("input[class='commodityCheck']:checked").length == 0){
toast('请选择要结算的商品');
return false;
}
var data = [];
for(var i=0;i<$("input[class='commodityCheck']:checked").length;i++){
var obj = {};
var goods_id = $("input[class='commodityCheck']:checked").eq(i).attr('data-goods_id');
var number = $("input[class='commodityCheck']:checked").eq(i).attr('data-number');
obj.goods_id = goods_id;
obj.number = number;
data.push(obj);
}
data = JSON.stringify(data);
var str = "{:url('index/order/confirm',array('data'=>'DATA','province_id'=>'PROVINCE_ID'))}";
window.location.href = str.replace("DATA",data).replace("PROVINCE_ID",province_id);
}
//单个删除按钮
function del(_this,car_id) {
$.ajax({
url:"{:url('index/car/del')}",
type:"POST",
data:{'car_ids':car_id},
success:function(res){
if(res.code == 1){
$(_this).closest('li').remove();
for(var i=$('.shopBox').length;i>-1;i--){
console.log($($('.shopBox')[i]).find('li').length);
if($($('.shopBox')[i]).find('li').length == 0){
$($('.shopBox')[i]).remove();
}
}
contTotalPrice();
toast('操作成功');
}
},
error:function(res){
toast('与服务器断开连接');
}
});
}
//删除选中商品
function delSelect() {
var commodityCheck = $("input[class='commodityCheck']:checked");
var car_ids = [];
$(commodityCheck).each(function (key, vo) {
car_ids.push(commodityCheck.eq(key).val());
});
if(car_ids.length < 1){
toast('请至少选择一个商品删除~');
return false;
}
car_ids = car_ids.toString();
$.ajax({
url:"{:url('index/car/del')}",
type:"POST",
data:{"car_ids":car_ids},
success:function(res){
if(res.code == 1){
$("input[class='commodityCheck']:checked").closest('li').remove();
for(var i=$('.shopBox').length;i>-1;i--){
console.log($($('.shopBox')[i]).find('li').length);
if($($('.shopBox')[i]).find('li').length == 0){
$($('.shopBox')[i]).remove();
}
}
contTotalPrice();
toast('操作成功');
}else{
toast(res.msg);
}
},
error:function(res){
toast('与服务器断开连接');
}
});
}
//清空购物车
function clearFun() {
var commodityCheck = $("input[class='commodityCheck']");
var car_ids = [];
$(commodityCheck).each(function (key, vo) {
car_ids.push(commodityCheck.eq(key).val());
});
car_ids = car_ids.toString();
$.ajax({
url:"{:url('index/car/del')}",
type:"POST",
data:{"car_ids":car_ids},
success:function(res){
if(res.code == 1){
$('.shopBox').remove();
contTotalPrice();
toast('操作成功');
}else{
toast(res.msg);
}
},
error:function(res){
toast('与服务器断开连接');
}
});
}
//头部全选按钮
$('#checkAll_top').on('change', function() {
if(this.checked) {
$('#checkAll_bottom').prop('checked', true)
} else {
$('#checkAll_bottom').prop('checked', false)
}
checkedAll(this)
});
//尾部全选按钮
$('#checkAll_bottom').on('change', function() {
if(this.checked) {
$('#checkAll_top').prop('checked', true)
} else {
$('#checkAll_top').prop('checked', false)
}
checkedAll(this)
});
//全选、反选
function checkedAll(_this) {
if(_this.checked) {
$('.shopBox').find('.commodityCheck').prop('checked', true);
} else {
$('.shopBox').find('.commodityCheck').prop('checked', false);
}
contTotalPrice();
}
//单个商品选择按钮
$('.commodityCheck').on('change', function() {
if($('.shopBox ul li').length == $("input[class='commodityCheck']:checked").length){
$('#checkAll_top').prop('checked', true);
$('#checkAll_bottom').prop('checked', true);
}else{
$('#checkAll_top').prop('checked', false);
$('#checkAll_bottom').prop('checked', false);
}
contTotalPrice();
});
//数量减
$('.car-decrease').on('click', function() {
var self = $(this);
var goods_id = self.attr('data-goods_id');
var type = self.attr('data-type');
$.ajax({
url:"{:url('index/car/add')}",
type:"POST",
data:{'goods_id':goods_id,'type':type,'province_id':province_id},
success:function(res){
if(res.code == 1){
var val = parseInt(self.closest('li').find('.contInput').val());
(val===1)?1:(val--);
$(self.closest('li').find('.contInput')[0]).val(val);
contPrice(self, val);
toast('操作成功');
}else{
toast(res.msg);
}
},
error:function(res){
toast('与服务器断开连接');
}
});
});
//数量加
$('.car-add').on('click', function() {
var self = $(this);
var goods_id = self.attr('data-goods_id');
var type = self.attr('data-type');
$.ajax({
url:"{:url('index/car/add')}",
type:"POST",
data:{'goods_id':goods_id,'type':type,'province_id':province_id},
success:function(res){
if(res.code == 1){
var val = parseInt(self.closest('li').find('.contInput').val());
val++;
$(self.closest('li').find('.contInput')[0]).val(val);
contPrice(self, val);
toast('操作成功');
}else{
toast(res.msg);
}
},
error:function(res){
toast('与服务器断开连接');
}
});
});
//计算小计
function contPrice(_this, val){
var unitPrice = parseInt($($(_this).closest('li').find('.unitPriceBox')[0]).html().split('¥')[1]);
$($(_this).closest('li').find('.subtotalBox')[0]).html('¥' + (unitPrice * val).toFixed(2));
contTotalPrice();
}
//计算总数、总价
function contTotalPrice() {
var totalCount = 0;
var totalPrice = 0;
var totalFreight = 0;
/*for(var i=0;i<$('.shopBox ul li').length;i++){
if($($('.shopBox ul li')[i]).find('.commodityCheck')[0].checked==true){
var subtotalNum = parseInt($($('.shopBox ul li')[i]).find('.contInput').val());
totalCount += subtotalNum;
var subtotal = parseInt($($('.shopBox ul li')[i]).find('.subtotalBox').html().split('¥')[1]);
var freight = parseInt($($('.shopBox')[i]).attr('data-freight'));//运费
var free_freight = parseInt($($('.shopBox')[i]).attr('data-free_freight'));//满免运费
if(subtotal < free_freight){
subtotal += freight;
}
console.log(subtotal);
console.log(free_freight);
console.log(freight);
totalPrice += subtotal;
}
}*/
for(var i1=0;i1<$('.shopBox').length;i1++){
var freight = parseInt($($('.shopBox')[i1]).attr('data-freight'));//运费
var free_freight = parseInt($($('.shopBox')[i1]).attr('data-free_freight'));//满免运费
for(var i2=0;i2<$('.shopBox').eq(i1).find('ul li').length;i2++){
if($('.shopBox').eq(i1).find('ul li').eq(i2).find('.commodityCheck')[0].checked==true) {
var subtotalNum = parseInt($('.shopBox').eq(i1).find('ul li').eq(i2).find('.contInput').val());
totalCount += subtotalNum;
var subtotal = parseInt($('.shopBox').eq(i1).find('ul li').eq(i2).find('.subtotalBox').html().split('¥')[1]);
totalPrice += subtotal;
}
}
if (totalPrice < free_freight) {
totalFreight += freight;
totalPrice += totalFreight;
}
if($("input[class='commodityCheck']:checked").length == 0){
totalPrice -= totalFreight;
}
}
$('#totalCount').html(totalCount.toFixed(0));
$('#totalPrice').html(totalPrice.toFixed(2));
}
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -255,7 +255,7 @@
}
.content .commodityInfoBox .commodityInfoMain .brandBox{
width: 100%;
height: 80px;
/*height: 80px;*/
padding-left: 20px;
font-size: 16px;
font-family: PingFang SC;
... ... @@ -584,10 +584,10 @@
<p>库存数量:<span id="inventory">{$data.inventory}</span></p>
</div>
<div class="brandBox">
<div class="nsuranceBox">
<!--<div class="nsuranceBox">
<img src="__CDN__/assets/store/images/insurance_icon.png" alt="img">
<span>中国人民保险公司承保</span>
</div>
</div>-->
<p>品牌:<span id="brand">{$data.brand}</span></p>
</div>
<div class="unitBox">
... ... @@ -607,15 +607,20 @@
<p>合计:<span id="totalPrice">¥{$data.price}</span></p>
</div>
<div class="bottobBox">
<button class="btn buy" onclick="buy()">
<!--<button class="btn buy" onclick="buy()">
立即购买
</button>
<button class="btn addToCart" onclick="addToCart()">
<button class="btn addToCart" onclick="addToCart({$data.id})">
加入购物车
</button>
<button id="collectionBtn" class="btn collection" onclick="collection()">
</button>-->
<button id="collectionBtn" class="btn collection {if condition='$data.is_collect eq 1'}collected{/if}" onclick="collection({$data.id})">
{if condition="$data.is_collect eq 2"}
<img src="__CDN__/assets/store/images/collection_dark.png" alt="user">
<span style="font-family: 黑体;vertical-align: middle;">收藏</span>
<span style="font-family: 黑体;vertical-align: middle;color: rgba(91,94,99,1);">收藏</span>
{else /}
<img src="__CDN__/assets/store/images/collection_light.png" alt="user">
<span style="font-family: 黑体;vertical-align: middle;color: #FF9417;">收藏</span>
{/if}
</button>
</div>
</div>
... ... @@ -870,11 +875,101 @@
{include file="public/footer"/}
{include file="public/js"/}
<script>
var goods_id = "{$data.id}";
var html1 = "<button class=\"btn buy\" onclick=\"buy("+goods_id+")\">\n" +
" 立即购买\n" +
" </button>\n" +
" <button class=\"btn addToCart\" onclick=\"addToCart("+goods_id+")\">\n" +
" 加入购物车\n" +
" </button>";
var html2 = "<button class=\"btn buy\" onclick=\"buy()\">\n" +
" 购买咨询\n" +
" </button>";
var insurance1 = "<div class=\"nsuranceBox\">\n" +
" <img src=\"__CDN__/assets/store/images/insurance_icon.png\" alt=\"img\">\n" +
" <span>中国人民保险公司承保</span>\n" +
" </div>";
var insurance2 = "";
$(function () {
initPinnerClick();
evaluateVal({$probability1}, {$probability1}, {$probability2}, {$probability3});//调用此方法显示好评度
initLocation();
});
//定位当前位置
function initLocation(){
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
$('#locationText').html(r.address.province + "" + r.address.city);
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
//省份名称转换为id
$.ajax({
url:"{:url('index/sundry/get_province_id')}",
type:"POST",
data:{"province_name":r.address.province},
async:false,
success:function(res){
if(res.code == 1){
province_id = res.data.province_id;
lng = r.point.lng;
lat = r.point.lat;
getGoods();
}else{
$('.bottobBox').prepend(html2);
$('.brandBox').prepend(insurance2);
toast(res.msg);
}
},
error:function(res){
$('.bottobBox').prepend(html2);
$('.brandBox').prepend(insurance2);
toast('与服务器断开连接');
}
});
} else {
$('.bottobBox').prepend(html2);
$('.brandBox').prepend(insurance2);
toast('failed'+this.getStatus());
}
},{enableHighAccuracy: true})
}
//获取商品信息
function getGoods(){
$.ajax({
url:"{:url('index/goods/get_one')}",
type:"POST",
data:{"goods_id":goods_id,'province_id':province_id},
success:function(res){
if(res.code == 1){
if(res.data.result == '1'){
$('.bottobBox').prepend(html1);
$('.brandBox').prepend(insurance1);
}else{
$('.bottobBox').prepend(html2);
$('.brandBox').prepend(insurance2);
}
}else{
$('.bottobBox').prepend(html2);
$('.brandBox').prepend(insurance2);
toast(res.msg);
}
},
error:function(res){
$('.bottobBox').prepend(html2);
$('.brandBox').prepend(insurance2);
toast("与服务器断开连接");
}
});
}
//初始化数字框点击事件
function initPinnerClick() {
$('.spinner .btn:first-of-type').on('click', function() {
... ... @@ -922,33 +1017,50 @@
}
//加入购物车
function addToCart() {
//setCookie('user_name','', -1);
var userName = getCookie('user_name');
if(userName == null || userName == ''){
window.location.href = 'login.html?page=commodityDetail';
}else{
$.message({
message:'已加入购物车',
type:'success'
});
}
function addToCart(goods_id) {
$.ajax({
url:"{:url('index/car/add')}",
type:"POST",
data:{"goods_id":goods_id,"type":1,'province_id':province_id},
success:function(res){
if(res.code == 1){
toast('操作成功');
}else{
toast(res.msg);
}
},
error:function(res){
toast("与服务器断开连接");
}
});
}
//收藏、取消收藏
function collection() {
var userName = getCookie('user_name');
if(userName == null || userName == ''){
window.location.href = 'login.html?page=commodityDetail';
}else{
if($('#collectionBtn').hasClass('collected')){
$('#collectionBtn img').attr('src','__CDN__/assets/store/images/collection_dark.png');
$('#collectionBtn').removeClass('collected');
}else{
$('#collectionBtn img').attr('src','__CDN__/assets/store/images/collection_light.png');
$('#collectionBtn').addClass('collected');
function collection(goods_id) {
$.ajax({
url:"{:url('index/collect/index')}",
type:"POST",
data:{"goods_id":goods_id},
success:function(res){
if(res.code == 1){
if($('#collectionBtn').hasClass('collected')){
$('#collectionBtn img').attr('src','__CDN__/assets/store/images/collection_dark.png');
$('#collectionBtn span').css('color','rgba(91,94,99,1)');
$('#collectionBtn').removeClass('collected');
}else{
$('#collectionBtn img').attr('src','__CDN__/assets/store/images/collection_light.png');
$('#collectionBtn span').css('color','#FF9417');
$('#collectionBtn').addClass('collected');
}
toast('操作成功');
}else{
toast(res.msg);
}
},
error:function(res){
toast("与服务器断开连接");
}
}
})
}
//评价数据:好评度,好评,中评,差评
... ...
... ... @@ -476,9 +476,9 @@
$(vo.property).each(function (key2, p) {
property += "<span>"+p+"</span>";
});
var insurance = "<img class=\"insurance_icon\" src=\"__CDN__/assets/store/images/insurance_icon.png\" alt=\"img\">";
var insurance = "";
if(vo.insurance == '1'){
insurance = "";
insurance = "<img class=\"insurance_icon\" src=\"__CDN__/assets/store/images/insurance_icon.png\" alt=\"img\">";
}
var str = "<div class=\"commodityBox\">\n" +
" <a href=\"{:url('index/goods/detail',array('goods_id'=>'GOODS_ID'))}\">\n" +
... ...
... ... @@ -569,9 +569,9 @@
$(vo.property).each(function (key2, p) {
property += "<span>"+p+"</span>";
});
var insurance = "<img class=\"insurance_icon\" src=\"__CDN__/assets/store/images/insurance_icon.png\" alt=\"img\">";
var insurance = "";
if(vo.insurance == '1'){
insurance = ""
insurance = "<img class=\"insurance_icon\" src=\"__CDN__/assets/store/images/insurance_icon.png\" alt=\"img\">"
}
var str = "<div class=\"commodityBox\">\n" +
" <a href=\"{:url('index/goods/detail',array('goods_id'=>'GOODS_ID'))}\">\n" +
... ...
... ... @@ -669,9 +669,9 @@
var locationLat = 39.11365;
$(function () {
// showTableData();
initMap();
// initMap();
tableClick();
initPaging();
// initPaging();
initLocation();//获取定位信息
});
... ... @@ -752,7 +752,7 @@
" <td>"+vo.store_name+property+"\n" +
" <td>"+vo.brand+"</td>\n" +
" <td>单价:¥"+vo.price+"</td>\n" +
" <td>"+vo.store_address+"(10km)</td>\n" +
" <td>"+vo.store_address+"("+vo.distance+"km)</td>\n" +
" </tr>";
goods_html += str.replace("GOODS_ID",vo.id);
});
... ... @@ -909,7 +909,7 @@
function initMap() {
var point = new BMap.Point(locationLng, locationLat);
mapObj = new BMap.Map("mapDiv");
mapObj.centerAndZoom(point, 15);
mapObj.centerAndZoom(point, 12);
mapObj.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
mapObj.setDefaultCursor('pointer');
addMarker(point, 999);
... ... @@ -963,11 +963,10 @@
//添加标注点
function addMarker(point, index){ // 创建图标对象
var myIcon = new BMap.Icon("__CDN__/assets/store/images/mapPoint_icon.png", new BMap.Size(45, 45), {});
var myIcon = new BMap.Icon("__CDN__/assets/store/images/mapPoint_icon.png", new BMap.Size(50, 50), {});
// 创建标注对象并添加到地图
var marker = new BMap.Marker(point, {icon: myIcon});
mapObj.addOverlay(marker);
console.log(marker);
}
//查询50KM范围内在售商品
... ...
<!DOCTYPE html>
<html lang="zh">
{include file="public/head"/}
<!--swiper引入-->
<link rel="stylesheet" href="__CDN__/assets/store/js/Swiper-3.4.2/css/swiper.min.css">
<script type="text/javascript" src="__CDN__/assets/store/js/Swiper-3.4.2/js/swiper.min.js"></script>
<style>
/*新增、修改收货人信息模态窗*/
.modal-dialog {
width: 423px;
height: 485px;
}
.modal-header {
height: 80px;
border: 0;
}
.modal-body {
padding: 10px 24px 20px 24px;
max-height: none;
}
.modal-title {
height: 50px;
line-height: 50px;
text-align: center;
font-size: 20px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(6, 18, 30, 1);
}
form {
font-size: 14px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(61, 68, 77, 1);
}
form .form-group {
width: 100%;
height: 54px;
margin: 0 0 20px 0;
position: relative;
}
form .form-group .tipsInfo {
position: absolute;
width: 100%;
height: 20px;
font-size: 10px;
color: red;
top: 55px;
left: 0;
}
form .form-group .form-control {
width: 100%;
height: 100%;
box-shadow: none;
}
form .form-group:nth-child(3), form .form-group:nth-child(5) {
position: relative;
}
form .form-group:nth-child(3) span {
display: inline-block;
position: absolute;
top: 15px;
right: 20px;
font-size: 16px;
font-family: PingFang SC;
font-weight: 400;
color: rgba(140, 145, 152, 1);
}
form .form-group:nth-child(5) span {
display: inline-block;
position: absolute;
top: 35px;
left: 12px;
font-size: 16px;
font-family: PingFang SC;
font-weight: 400;
line-height: 22px;
color: rgba(140, 145, 152, 1);
}
form p {
height: 22px;
padding-left: 9px;
font-size: 16px;
font-family: PingFang SC;
font-weight: 500;
line-height: 22px;
color: rgba(6, 18, 30, 1);
}
form button {
width: 100%;
height: 51px;
border: 0 !important;
background: rgba(0, 159, 142, 1) !important;
border-radius: 2px !important;
font-size: 18px !important;
font-family: PingFang SC;
font-weight: 400 !important;
color: rgba(255, 255, 255, 1) !important;
}
form .imgBox {
margin-bottom: 20px;
}
</style>
<style>
body {
background: rgba(249, 249, 249, 1);
}
.content {
width: 100%;
font-size: 0;
}
/*订单信息部分样式*/
.content .orderInfoBox {
width: 100%;
/*height: 905px;*/
background: rgba(249, 249, 249, 1);
}
.content .orderInfoBox .titleBox {
width: 1200px;
height: 60px;
line-height: 60px;
background: rgba(255, 255, 255, 1);
border-radius: 8px;
margin: 12px auto;
}
.content .orderInfoBox .titleBox span:first-child {
display: inline-block;
float: left;
width: 6px;
height: 20px;
margin-top: 21px;
background: rgba(0, 159, 142, 1);
border-radius: 2px;
}
.content .orderInfoBox .titleBox span:nth-child(2) {
height: 22px;
line-height: 22px;
float: left;
margin-top: 20px;
padding-left: 12px;
font-size: 16px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(0, 159, 142, 1);
}
/*物流方式部分样式*/
.content .orderInfoBox .sendModeBox {
width: 1200px;
height: 108px;
background: rgba(255, 255, 255, 1);
border-radius: 8px;
margin: 0 auto 12px auto;
}
.content .orderInfoBox .title {
width: 100%;
height: 40px;
padding: 0 30px;
font-size: 14px;
font-family: PingFang SC;
font-weight: 500;
line-height: 40px;
color: rgba(61, 68, 77, 1);
border-bottom: 1px solid rgba(238, 238, 238, 1);
margin: 0;
}
.content .orderInfoBox .sendModeBox ul {
width: 100%;
height: 68px;
padding: 0 30px;
}
.content .orderInfoBox .sendModeBox ul li {
list-style-type: none;
float: left;
width: 95px;
height: 65px;
line-height: 65px;
margin-right: 30px;
font-size: 14px;
font-family: PingFang SC;
font-weight: 400;
color: rgba(6, 18, 30, 1);
cursor: pointer;
}
.content .orderInfoBox .sendModeBox ul li img {
width: 16px;
height: 16px;
margin-right: 12px;
}
/*快递_收货人信息部分样式*/
.content .orderInfoBox .consigneeBox {
width: 1200px;
background: rgba(255, 255, 255, 1);
border-radius: 8px;
margin: 0 auto 12px auto;
}
.content .orderInfoBox .title {
display: inline-block;
}
.content .orderInfoBox .title span {
display: inline-block;
float: right;
width: 84px;
height: 40px;
font-size: 14px;
font-family: PingFang SC;
font-weight: 500;
line-height: 40px;
color: rgba(0, 159, 142, 1);
cursor: pointer;
}
.content .orderInfoBox .consigneeBox ul {
width: 100%;
padding: 0;
}
.content .orderInfoBox .consigneeBox ul li {
list-style-type: none;
width: 100%;
height: 112px;
cursor: pointer;
}
.content .orderInfoBox .consigneeBox ul li .imgBox {
float: left;
width: 76px;
height: 100%;
text-align: center;
line-height: 112px;
}
.content .orderInfoBox .consigneeBox ul li .contentBox {
width: 1090px;
height: 100%;
margin-left: 77px;
overflow: hidden;
border-bottom: 1px solid rgba(238, 238, 238, 1);
}
.content .orderInfoBox .consigneeBox ul li .contentBox .box {
width: 100%;
height: 20px;
}
.content .orderInfoBox .consigneeBox ul li .contentBox .box:first-child {
margin: 30px 0 12px 0;
}
.content .orderInfoBox .consigneeBox ul li .contentBox .box {
margin: 0;
font-size: 14px;
font-family: PingFang SC;
font-weight: 500;
line-height: 20px;
color: rgba(91, 94, 99, 1);
}
.content .orderInfoBox .consigneeBox ul li .contentBox .box p {
margin: 0;
display: inline-block;
}
.content .orderInfoBox .consigneeBox ul li .contentBox .box p .phone {
display: inline-block;
margin-left: 10px;
font-size: 12px;
}
.content .orderInfoBox .consigneeBox ul li .contentBox .box .btnSpan {
display: inline-block;
width: 60px;
height: 17px;
float: right;
text-align: right;
}
.content .orderInfoBox .consigneeBox ul li .contentBox .box .btnSpan span {
display: inline-block;
vertical-align: middle;
}
.content .orderInfoBox .consigneeBox ul li .contentBox .box .btnSpan img{
margin-right: 6px;
}
/*跑腿_收货人信息*/
.content .orderInfoBox .errandsBox {
display: none;
width: 1200px;
background: rgba(255, 255, 255, 1);
border-radius: 8px;
margin: 0 auto 12px auto;
}
.content .orderInfoBox .errandsBox ul {
width: 100%;
/*padding: 0 30px;*/
}
.content .orderInfoBox .errandsBox ul li {
list-style-type: none;
width: 100%;
height: 116px;
cursor: pointer;
}
.content .orderInfoBox .errandsBox ul li .imgBox {
float: left;
width: 76px;
height: 100%;
text-align: center;
line-height: 112px;
}
.content .orderInfoBox .errandsBox ul li .contentBox {
width: 1064px;
height: 100%;
margin-left: 77px;
overflow: hidden;
border-bottom: 1px solid rgba(238, 238, 238, 1);
padding-top: 20px;
}
.content .orderInfoBox .errandsBox ul li .contentBox p {
font-size: 14px;
font-family: PingFang SC;
font-weight: 500;
line-height: 20px;
color: rgba(91, 94, 99, 1);
margin-bottom: 8px;
}
/*支付方式部分样式*/
.content .orderInfoBox .payModeBox {
width: 1200px;
height: 264px;
background: rgba(255, 255, 255, 1);
border-radius: 8px;
margin: 0 auto 12px auto;
}
.content .orderInfoBox .payModeBox ul {
width: 100%;
padding: 0 30px;
}
.content .orderInfoBox .payModeBox ul li {
list-style-type: none;
width: 100%;
height: 68px;
cursor: pointer;
}
.content .orderInfoBox .payModeBox ul li .imgBox {
float: left;
width: 76px;
height: 100%;
text-align: center;
line-height: 68px;
}
.content .orderInfoBox .payModeBox ul li .contentBox {
width: 1064px;
height: 100%;
margin-left: 77px;
overflow: hidden;
border-bottom: 1px solid rgba(238, 238, 238, 1);
padding-top: 20px;
font-size: 14px;
font-family: PingFang SC;
font-weight: 400;
line-height: 20px;
color: rgba(6, 18, 30, 1);
}
/*二维码部分样式*/
.content .orderInfoBox .downloadBox {
display: none;
width: 1200px;
height: 132px;
border-radius: 8px;
margin: 8px auto 0 auto;
padding: 0 30px;
}
.content .orderInfoBox .downloadBox div {
display: inline-block;
width: 100px;
}
.content .orderInfoBox .downloadBox div img {
width: 100px;
height: 100px;
margin-bottom: 12px;
}
.content .orderInfoBox .downloadBox div p {
margin: 0;
width: 100px;
height: 20px;
text-align: center;
font-size: 14px;
font-family: PingFang SC;
font-weight: 400;
line-height: 20px;
color: rgba(6, 18, 30, 1);
}
/*提交订单部分样式*/
.content .orderInfoBox .submitBox {
width: 1200px;
height: 52px;
background: rgba(255, 255, 255, 1);
border-radius: 8px;
margin: 60px auto 50px auto;
padding-left: 30px;
}
.content .orderInfoBox .submitBox p {
display: inline-block;
width: 160px;
height: 52px;
line-height: 52px;
font-size: 14px;
font-family: PingFang SC;
font-weight: 500;
color: rgba(140, 145, 152, 1);
margin: 0;
}
.content .orderInfoBox .submitBox p:nth-child(3) {
width: 680px;
text-align: right;
padding-right: 21px;
}
.content .orderInfoBox .submitBox p:nth-child(3) span {
font-size: 16px;
color: rgba(234, 50, 43, 1);
}
.content .orderInfoBox .submitBox .btn {
width: 170px;
height: 52px;
background: rgba(0, 159, 142, 1);
border: 0;
font-size: 16px;
font-family: PingFang SC;
font-weight: 500;
line-height: 22px;
color: rgba(255, 255, 255, 1);
border-radius: 0;
margin-top: -12px;
}
</style>
<body>
{include file="public/header"/}
<!--主要内容-->
<div class="content">
<div class="navBarBox">
<ul>
<li><a href="{:url('index/index')}">首页</a></li>
<li><a href="{:url('goods/index')}">采购中心</a></li>
<li><a href="">帮买服务</a></li>
<li><a href="">产品维修</a></li>
<li><a href="">关于我们</a></li>
</ul>
</div>
<!--订单信息部分-->
<div class="orderInfoBox">
<!--标题部分-->
<div class="titleBox">
<span></span>
<span id="orderTitle">订单确认</span>
</div>
<!--物流方式-->
<div class="sendModeBox">
<p class="title">物流方式</p>
<ul>
<li onclick="changeSendMode('express')"><img id="expressImg" src="__CDN__/assets/store/images/checkbox_orange.png" alt="img">快递运输
</li>
<li onclick="changeSendMode('dada')"><img id="dadaImg" src="__CDN__/assets/store/images/radioUnSelect.png" alt="img">达达快递
</li>
<li onclick="changeSendMode('meiTuan')"><img id="meiTuanImg" src="__CDN__/assets/store/images/radioUnSelect.png" alt="img">美团跑腿
</li>
</ul>
</div>
<!--快递_收货人信息-->
<div class="consigneeBox">
<p class="title">
收货人信息
<span onclick="addConsignee()">新增收货地址</span>
</p>
<ul class="address_box">
{foreach name="$address" item="a"}
<li onclick="changeConsignee(this)" data-address_id="{$a.id}">
<div class="imgBox">
<img class="checkImg" src="{if condition='$a.is_default eq 1'}__CDN__/assets/store/images/checkbox_orange.png{else /}__CDN__/assets/store/images/radioUnSelect.png{/if}" alt="img">
</div>
<div class="contentBox address-{$a.id}">
<div class="box">
<p>
<span class="name">{$a.name}</span>
<span class="phone">{$a.phone}</span>
</p>
<span class="btnSpan" onclick="edit(this)">
<img src="__CDN__/assets/store/images/icon_bianji.png" alt="img">
<span></span>编辑
</span>
</div>
<div class="box">
<p class="address">
<span data-province_id="{$a.province_id}">{$a.province_name}</span>
<span data-city_id="{$a.city_id}">{$a.city_name}</span>
<span data-county_id="{$a.county_id}">{$a.county_name}</span>
<span>{$a.address}</span>
</p>
<span class="btnSpan" onclick="del(this)"><img src="__CDN__/assets/store/images/icon_del.png" alt="">
<span>删除</span>
</span>
</div>
</div>
</li>
{/foreach}
</ul>
</div>
<!--跑腿_收货人信息-->
<div class="errandsBox">
<p class="title">
店铺信息
</p>
<ul>
{foreach name="$store" item="s"}
<li onclick="changeErrands(this)">
<div class="imgBox">
<img class="checkImg" src="__CDN__/assets/store/images/checkbox_orange.png" alt="img">
</div>
<div class="contentBox">
<p>联系人(店铺名称):<span class="shopName">{$s.name}</span></p>
<p>电话:<span class="phone">{$s.phone}</span></p>
<p>店铺地址:
<span class="address">
<span data-province_id="{$s.province_id}">{$s.province_name}</span>
<span data-city_id="{$s.city_id}">{$s.city_name}</span>
<span data-county_id="{$s.county_id}">{$s.county_name}</span>
<span>{$s.address}</span>
</span>
</p>
</div>
</li>
{/foreach}
</ul>
</div>
<!--支付方式-->
<div class="payModeBox">
<p class="title">支付方式</p>
<ul>
<li onclick="changePayMode(this,'weChat')">
<div class="imgBox">
<img class="checkImg" src="__CDN__/assets/store/images/checkbox_orange.png" alt="img">
</div>
<div class="contentBox">
<img src="__CDN__/assets/store/images/weixin.png" alt="img">
微信支付
</div>
</li>
<li onclick="changePayMode(this,'aliPay')">
<div class="imgBox">
<img class="checkImg" src="__CDN__/assets/store/images/radioUnSelect.png" alt="img">
</div>
<div class="contentBox">
<img src="__CDN__/assets/store/images/zhufubao.png" alt="img">
支付宝
</div>
</li>
<li onclick="changePayMode(this,'yunPay')">
<div class="imgBox">
<img class="checkImg" src="__CDN__/assets/store/images/radioUnSelect.png" alt="img">
</div>
<div class="contentBox">
<img src="__CDN__/assets/store/images/yunshanfu.png" alt="img">
云闪付
</div>
</li>
</ul>
</div>
<!--二维码部分-->
<div class="downloadBox">
<div>
<img src="__CDN__/assets/store/images/dadaCode.png" alt="img">
<p>下载达达</p>
</div>
<div>
<img src="__CDN__/assets/store/images/meiTuanCode.png" alt="img">
<p>下载美团</p>
</div>
</div>
<!--提交订单部分-->
<div class="submitBox">
<p>商品金额:<span>¥150.00</span></p>
<p>物流费用:<span>¥0.00</span></p>
<p>应付总额:<span>¥198.00</span></p>
<button id="submitBtn" type="button" class="btn" onclick="submitOrder()">提交订单</button>
</div>
</div>
</div>
<!--新增、修改收货人信息模态窗-->
<div class="modal fade" id="changeInfoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<img src="__CDN__/assets/store/images/close_icon.png" alt="close">
</button>
<h4 class="modal-title" id="myModalLabel">
新增/修改收货人信息
</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<input type="text" class="form-control" id="userName" placeholder="姓名">
<span id="userNameTips" class="tipsInfo"></span>
</div>
<div class="form-group">
<input type="text" class="form-control" id="phoneNum" placeholder="手机号">
<span id="phoneNumTips" class="tipsInfo"></span>
</div>
<div style="display: flex;">
<div class="form-group">
<select id="province" class="form-control" placeholder="请选择省份">
<option value="">请选择</option>
{foreach name="$province" item="p"}
<option value="{$p.id}">{$p.name}</option>
{/foreach}
</select>
</div>
<div class="form-group">
<select id="city" class="form-control" placeholder="请选择城市">
<option value="">请选择</option>
<!--{foreach name="$city" item="c"}
<option value="{$c.id}">{$c.name}</option>
{/foreach}-->
</select>
</div>
<div class="form-group">
<select id="county" class="form-control" placeholder="请选择省份">
<option value="">请选择</option>
<!--{foreach name="$county" item="c"}
<option value="{$c.id}">{$c.name}</option>
{/foreach}-->
</select>
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" id="addressDetail" placeholder="详细地址">
<span id="addressDetailTips" class="tipsInfo"></span>
</div>
<input type="hidden" id="address_id" value=""/>
<button type="button" class="btn btn-submit" onclick="sendInfo()">确定</button>
</form>
</div>
</div>
</div>
</div>
{include file="public/footer"/}
{include file="public/js"/}
<script>
var sendMode = 'express';
var payMode = 'weChat';
$(function () {
var source = window.location.href.split('source=')[1];
if (source){
$('#orderTitle').html('订单详情');
$('#submitBtn').hide();
}
});
//更换运输方式
function changeSendMode(type) {
$('.sendModeBox ul li img').attr('src', '__CDN__/assets/store/images/radioUnSelect.png');
sendMode = type;
if (type == 'express') {
//快递
$('.errandsBox,.downloadBox').hide();
$('.consigneeBox').show();
$('#expressImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
} else if (type == 'dada') {
//达达
$('.consigneeBox').hide();
$('.errandsBox,.downloadBox').show();
$('#dadaImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
} else {
//美团
$('.consigneeBox').hide();
$('.errandsBox,.downloadBox').show();
$('#meiTuanImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
}
}
//新增收货信息
function addConsignee() {
$('#userName').val('');
$('#phoneNum').val('');
$('#addressDetail').val('');
$('#address_id').val('');
getProvince();
getCity();
getCounty();
$('#changeInfoModal').modal();
}
//发送收货人信息
function sendInfo() {
var name = $('#userName').val();
var phone = $('#phoneNum').val();
var reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
var province_id = $('#province').val();
var city_id = $('#city').val();
var county_id = $('#county').val();
var address = $('#addressDetail').val();
var address_id = $('#address_id').val();
if(name == ''){
toast('请输入姓名');
return false;
}else if(phone == ''){
toast('请输入电话');
return false;
}else if(!reg.test(phone)){
toast('请输入正确的手机号');
return false;
}else if(province_id == ''){
toast('请选择省份');
return false;
}else if(city_id == ''){
toast('请选择城市');
return false;
}else if(county_id == ''){
toast('请选择区/县');
return false;
}else if(address == ''){
toast('请输入详细地址');
return false;
}
$.ajax({
url:"{:url('index/address/update')}",
type:"POST",
data:{'name':name,'phone':phone,'province_id':province_id,'city_id':city_id,'county_id':county_id,'address':address,'address_id':address_id},
success:function (res) {
if(res.code == 1){
var data = res.data;
if(address_id != ''){
//编辑
var html = "<div class=\"box\">\n" +
" <p>\n" +
" <span class=\"name\">"+data.name+"</span>\n" +
" <span class=\"phone\">"+data.phone+"</span>\n" +
" </p>\n" +
" <span class=\"btnSpan\" onclick=\"edit(this)\">\n" +
" <img src=\"__CDN__/assets/store/images/icon_bianji.png\" alt=\"img\">\n" +
" <span></span>编辑\n" +
" </span>\n" +
" </div>\n" +
" <div class=\"box\">\n" +
" <p class=\"address\">\n" +
" <span data-province_id=\""+data.province_id+"\">"+data.province_name+"</span>\n" +
" <span data-city_id=\""+data.city_id+"\">"+data.city_name+"</span>\n" +
" <span data-county_id=\""+data.county_id+"\">"+data.county_name+"</span>\n" +
" <span>"+data.address+"</span>\n" +
" </p>\n" +
" <span class=\"btnSpan\" onclick=\"del(this)\"><img src=\"__CDN__/assets/store/images/icon_del.png\" alt=\"\">\n" +
" <span>删除</span>\n" +
" </span>\n" +
" </div>";
$(".address-"+data.id+"").html(html);
}else{
//新增
var html = "<li onclick=\"changeConsignee(this)\" data-address_id=\""+data.id+"\">\n" +
" <div class=\"imgBox\">\n" +
" <img class=\"checkImg\" src=\"__CDN__/assets/store/images/checkbox_orange.png\" alt=\"img\">\n" +
" </div>\n" +
" <div class=\"contentBox address-"+data.id+"\">\n" +
" <div class=\"box\">\n" +
" <p>\n" +
" <span class=\"name\">"+data.name+"</span>\n" +
" <span class=\"phone\">"+data.phone+"</span>\n" +
" </p>\n" +
" <span class=\"btnSpan\" onclick=\"edit(this)\">\n" +
" <img src=\"__CDN__/assets/store/images/icon_bianji.png\" alt=\"img\">\n" +
" <span></span>编辑\n" +
" </span>\n" +
" </div>\n" +
" <div class=\"box\">\n" +
" <p class=\"address\">\n" +
" <span data-province_id=\""+data.province_id+"\">"+data.province_name+"</span>\n" +
" <span data-city_id=\""+data.city_id+"\">"+data.city_name+"</span>\n" +
" <span data-county_id=\""+data.county_id+"\">"+data.county_name+"</span>\n" +
" <span>"+data.address+"</span>\n" +
" </p>\n" +
" <span class=\"btnSpan\" onclick=\"del(this)\"><img src=\"__CDN__/assets/store/images/icon_del.png\" alt=\"\">\n" +
" <span>删除</span>\n" +
" </span>\n" +
" </div>\n" +
" </div>\n" +
" </li>";
//将所有收货地址变为未选中状态
$('.imgBox').find('img').attr('src',"__CDN__/assets/store/images/radioUnSelect.png");
$('.address_box').prepend(html);
}
$('#changeInfoModal').modal('hide');
toast('操作成功');
}
},
error:function (res) {
toast('与服务器断开连接');
}
});
}
//更改收货人
function changeConsignee(obj) {
$('.content .orderInfoBox .consigneeBox ul li .checkImg').attr('src', '__CDN__/assets/store/images/radioUnSelect.png');
$(obj).find('.checkImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
var name = $(obj).find('.name').html();
var phone = $(obj).find('.phone').html();
var address = $(obj).find('.address').html();
}
//更改跑腿收货人
function changeErrands(obj) {
$('.content .orderInfoBox .errandsBox ul li .checkImg').attr('src', '__CDN__/assets/store/images/radioUnSelect.png');
$(obj).find('.checkImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
var name = $(obj).find('.shopName').html().split('<span')[0];
var phone = $(obj).find('.phone').html();
var address = $(obj).find('.address').html();
}
//修改收件信息
function edit(obj) {
/*console.log($(obj).parent().next('.address').html());
var name = $(obj).parent().find('.name').html().split('<span')[0];
var phone = $(obj).parent().find('.phone').html();
$('#userName').val(name);
$('#phoneNum').val(phone);
var province_id2 = $(obj).parents().find('.address').find('span').eq(0).attr('data-province_id');
console.log(province_id2);
getProvince(0,province_id2);
var city_id2 = $(obj).parents().find('.address').find('span').eq(1).attr('data-city_id');
console.log(city_id2);
getCity(province_id2,city_id2);
var county_id2 = $(obj).parents().find('.address').find('span').eq(2).attr('data-county_id');
console.log(county_id2);
getCounty(city_id2,county_id2);
$('#addressDetail').val();
$('#changeInfoModal').modal();*/
var address_id = $(obj).parent().parent().parent().attr('data-address_id');
var name = $(obj).prev().find('span').eq(0).html();
var phone = $(obj).prev().find('span').eq(1).html();
var province_id2 = $(obj).parent().next().find('.address span').eq(0).attr('data-province_id');
var city_id2 = $(obj).parent().next().find('.address span').eq(1).attr('data-city_id');
var county_id2 = $(obj).parent().next().find('.address span').eq(2).attr('data-county_id');
var address = $(obj).parent().next().find('.address span').eq(3).html();
$('#userName').val(name);
$('#phoneNum').val(phone);
getProvince(0,province_id2);
getCity(province_id2,city_id2);
getCounty(city_id2,county_id2);
$('#addressDetail').val(address);
$('#address_id').val(address_id);
$('#changeInfoModal').modal();
}
//删除收件信息
function del(obj) {
$(obj).parent().parent().parent('li').remove();
}
//修改支付方式
function changePayMode(obj, type) {
$('.content .orderInfoBox .payModeBox ul li .checkImg').attr('src', '__CDN__/assets/store/images/radioUnSelect.png');
$(obj).find('.checkImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
if (type == 'weChat') {
//微信支付
payMode = 'weChat';
} else if (type == 'aliPay') {
//支付宝支付
payMode = 'aliPay';
} else {
//云闪付
payMode = 'yunPay';
}
}
//提交订单
function submitOrder() {
}
//更换省份
$("#province").on("change",function(){
var province_id2 = $(this).val();
getCity(province_id2);
getCounty();
});
//更换城市
$("#city").on("change",function(){
var city_id2 = $(this).val();
getCounty(city_id2);
});
//获取省份
function getProvince(pid = 0,select_id = 0){
$.ajax({
url:"{:url('index/sundry/get_area')}",
type:"POST",
data:{"pid":pid,'level':1},
success:function (res) {
console.log(res);
var html = "<option value=\"\">请选择</option>";
if(res.code == 1){
$(res.data).each(function (key1, vo) {
var is_select = "";
if(select_id == vo.id){
is_select = "selected";
}
html += "<option value=\""+vo.id+"\" "+is_select+">"+vo.name+"</option>";
});
}
console.log(html);
$('#province').html(html);
},
error:function (res) {
toast('与服务器断开连接')
}
})
}
//获取城市
function getCity(province_id2, select_id = 0){
$.ajax({
url:"{:url('index/sundry/get_area')}",
type:"POST",
data:{"pid":province_id2,'level':2},
success:function (res) {
console.log(res);
var html = "<option value=\"\">请选择</option>";
if(res.code == 1){
$(res.data).each(function (key1, vo) {
var is_select = "";
if(select_id == vo.id){
is_select = "selected";
}
html += "<option value=\""+vo.id+"\" "+is_select+">"+vo.name+"</option>";
});
}
console.log(html);
$('#city').html(html);
},
error:function (res) {
toast('与服务器断开连接')
}
})
}
//获取区/县
function getCounty(city_id2, select_id = 0){
$.ajax({
url:"{:url('index/sundry/get_area')}",
type:"POST",
data:{"pid":city_id2,'level':3},
success:function (res) {
console.log(res);
var html = "<option value=\"\">请选择</option>";
if(res.code == 1){
$(res.data).each(function (key1, vo) {
var is_select = "";
if(select_id == vo.id){
is_select = "selected";
}
html += "<option value=\""+vo.id+"\" "+is_select+">"+vo.name+"</option>";
});
}
$('#county').html(html);
},
error:function (res) {
toast('与服务器断开连接')
}
})
}
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -12,13 +12,13 @@
</a>
{/empty}
{notempty name="$token"}
<a href="personalCenter.html" class="btn btn-warning">
<a href="{:url('index/member/index')}" class="btn btn-warning">
<img src="__CDN__/assets/store/images/user.png" alt="shop">
个人中心
</a>
{/notempty}
{notempty name="$token"}
<a href="shoppingCart.html" class="btn">
<a href="{:url('index/car/index')}" class="btn">
<img src="__CDN__/assets/store/images/icon_gouwu.png" alt="shop">
购物车
</a>
... ...
.toast{
position: fixed;
z-index: 999;
z-index: 9999;
background: rgba(0,0,0,0.5);
color: #ffffff;
padding: 12px 25px;
... ... @@ -13,10 +13,13 @@
display: none;
}
.bg{
z-index: 999;
z-index: 9999;
width: 100%;
height: 100%;
display: none;
position: fixed;
top: 0;
}
::-webkit-scrollbar{
display:none;
}
\ No newline at end of file
... ...