diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..5b8b1c1 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,54 @@ +--- +kind: pipeline +type: ssh +name: "自动部署" + +server: + host: 175.178.113.105 + user: root + ssh_key: + from_secret: SSH_KEY + +clone: + disable: true + +steps: + - name: "设置远端Git" + environment: + GIT_NAME: + from_secret: GIT_NAME + GIT_PASSWD: + from_secret: GIT_PASSWD + commands: + - echo "Git 设置" + - cd /www/wwwroot/we.cnp5.cn/addons/ewei_shopv2 + - git remote rm origin + - git remote add origin ssh://git@home.des8.com:8022/heibai2006/wpfw_ewei_shopv2.git + + - name: "git更新代码" + commands: + - echo "git更新代码" + - cd /www/wwwroot/we.cnp5.cn/addons/ewei_shopv2 + - pwd && ls -l + - git pull origin main + + - name: "复制api文件" + commands: + - echo "复制api文件到app目录" + - printenv + - pwd + - /bin/cp -f /www/wwwroot/we.cnp5.cn/addons/ewei_shopv2/ewei_shopv2_api.php /www/wwwroot/we.cnp5.cn/ewei_shopv2_api.php + - /bin/cp -f /www/wwwroot/we.cnp5.cn/addons/ewei_shopv2/api.php /www/wwwroot/we.cnp5.cn/api.php + + - name: "更改文件权限" + commands: + - echo "更改文件权限" + - cd /www/wwwroot/we.cnp5.cn/addons/ewei_shopv2 + - chown -R www:www ./ + - pwd && ls -l +trigger: + branch: + - main + event: + - push + - pull_request \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3af0ccb..d4ebf9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /data +__MACOSX diff --git a/plugin/app/core/mobile/__MACOSX/._changce b/plugin/app/core/mobile/__MACOSX/._changce deleted file mode 100644 index 5dfae40..0000000 Binary files a/plugin/app/core/mobile/__MACOSX/._changce and /dev/null differ diff --git a/plugin/app/core/mobile/__MACOSX/changce/._article.php b/plugin/app/core/mobile/__MACOSX/changce/._article.php deleted file mode 100644 index 5dfae40..0000000 Binary files a/plugin/app/core/mobile/__MACOSX/changce/._article.php and /dev/null differ diff --git a/plugin/app/core/mobile/__MACOSX/changce/._commission.php b/plugin/app/core/mobile/__MACOSX/changce/._commission.php deleted file mode 100644 index 5dfae40..0000000 Binary files a/plugin/app/core/mobile/__MACOSX/changce/._commission.php and /dev/null differ diff --git a/plugin/app/core/mobile/__MACOSX/changce/._lottery.php b/plugin/app/core/mobile/__MACOSX/changce/._lottery.php deleted file mode 100644 index 5dfae40..0000000 Binary files a/plugin/app/core/mobile/__MACOSX/changce/._lottery.php and /dev/null differ diff --git a/plugin/app/core/mobile/__MACOSX/changce/._merch.php b/plugin/app/core/mobile/__MACOSX/changce/._merch.php deleted file mode 100644 index 5dfae40..0000000 Binary files a/plugin/app/core/mobile/__MACOSX/changce/._merch.php and /dev/null differ diff --git a/plugin/app/core/mobile/__MACOSX/changce/._sign.php b/plugin/app/core/mobile/__MACOSX/changce/._sign.php deleted file mode 100644 index 5dfae40..0000000 Binary files a/plugin/app/core/mobile/__MACOSX/changce/._sign.php and /dev/null differ diff --git a/plugin/app/core/mobile/order/index.php b/plugin/app/core/mobile/order/index.php index b81ec93..a65e16f 100644 --- a/plugin/app/core/mobile/order/index.php +++ b/plugin/app/core/mobile/order/index.php @@ -199,7 +199,7 @@ class Index_EweiShopV2Page extends AppMobilePage -// print_r($row['goods']);exit; + //print_r($row['goods']);exit; $statuscss = "text-cancel"; $nextstatus=''; diff --git a/plugin/open_api/core/mobile/order/detail.php b/plugin/open_api/core/mobile/order/detail.php index eac080b..82cec9d 100644 --- a/plugin/open_api/core/mobile/order/detail.php +++ b/plugin/open_api/core/mobile/order/detail.php @@ -407,34 +407,42 @@ class Detail_EweiShopV2Page extends OpenApiMobilePage ); } - function get_list() + public function get_list() { global $_W, $_GPC; $uniacid = $this->uniacid; $openid = $_GPC['openid']; $member_id = $_GPC['member_id']; - - if(empty($openid) && empty($member_id)){ - return $this->error("参数错误 openid或member_id不能为空", 552000); - } - if(empty($openid)){ + // if(empty($openid) && empty($member_id)){ + // return $this->error("参数错误 openid或member_id不能为空", 552000); + // } + if(!empty($member_id)){ $member = pdo_fetch("SELECT openid FROM " . tablename("ewei_shop_member") . " WHERE id=:id AND uniacid=:uniacid", array(":id" => $member_id, ":uniacid" => $this->uniacid)); $openid = $member['openid']; } if(empty($openid)){ - return $this->error("参数错误,没找到openid", 552000); + $condition = " and ismr=0 and deleted=0 and uniacid=:uniacid "; + $params = array( + ':uniacid' => $uniacid + ); + //return $this->error("参数错误,没找到openid", 552000); + }else{ + $condition = " and openid=:openid and ismr=0 and deleted=0 and uniacid=:uniacid "; + $params = array( + ':uniacid' => $uniacid, + ':openid' => $openid + ); } - // $pindex = max(1, intval($_GPC['page'])); - // $psize = 10; + $pindex = max(1, (int) $_GPC["page"]); $psize = max(10, (int) $_GPC["page_size"]); $show_status = $_GPC['status']; $r_type = array('0' => '退款', '1' => '退货退款', '2' => '换货'); - $condition = " and openid=:openid and ismr=0 and deleted=0 and uniacid=:uniacid "; - $params = array( - ':uniacid' => $uniacid, - ':openid' => $openid - ); + // $condition = " and openid=:openid and ismr=0 and deleted=0 and uniacid=:uniacid "; + // $params = array( + // ':uniacid' => $uniacid, + // ':openid' => $openid + // ); //多商户 $merchdata = $this->merchData(); @@ -746,20 +754,28 @@ class Detail_EweiShopV2Page extends OpenApiMobilePage //return app_json(array( 'list' => $list, 'pagesize' => $psize, 'total' => $total ,'page'=>$pindex,'can_sync_goodscircle'=>$can_sync_goodscircle)); } - function detail() + public function detail() { global $_W, $_GPC; - $openid = $_W['openid']; - $uniacid = $_W['uniacid']; - $orderid = intval($_GPC['id']); - $ispeerpay = m('order')->checkpeerpay($orderid);//检查是否是代付订单 - if (empty($orderid) || empty($openid)) { - return app_error(AppError::$ParamsError); - } + $ordersn = $_GPC['order_sn']; + $uniacid = $this->uniacid; + $orderid = intval($_GPC['order_id']); - $order = pdo_fetch("select * from " . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1' - , array(':id' => $orderid, ':uniacid' => $uniacid, ':openid' => $openid)); + if (empty($orderid) && empty($ordersn)) { + return $this->error("参数错误,订单号或ID为空!", 552000); + } + if(!empty($orderid)){ + $order = pdo_fetch("select * from " . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $orderid, ':uniacid' => $uniacid)); + }else{ + $order = pdo_fetch("select * from " . tablename('ewei_shop_order') . ' where ordersn=:ordersn and uniacid=:uniacid limit 1', array(':ordersn' => $ordersn, ':uniacid' => $uniacid)); + } + //pdo_debug(); + if(empty($order)){ + return $this->error("没找到订单!", 552000); + } + $ispeerpay = m('order')->checkpeerpay($order['id']);//检查是否是代付订单 + $orderid = $order['id']; if ($order['paytype'] == 3 || !empty($order['storeid'])) { $trade = m('common')->getSysset('trade'); if (empty($trade['freightText'])){ @@ -783,13 +799,13 @@ class Detail_EweiShopV2Page extends OpenApiMobilePage $isonlyverifygoods = m('order')->checkisonlyverifygoods($order['id']);; if (empty($order)) { - return app_error(AppError::$OrderNotFound); + return $this->error("参数错误,订单号或ID为空!", 552000); } if ($order['merchshow'] == 1) { - return app_error(AppError::$OrderNotFound); + return $this->error("参数错误,订单号或ID为空!", 552000); } if ($order['userdeleted'] == 2) { - return app_error(AppError::$OrderNotFound); + return $this->error("参数错误,订单号或ID为空!", 552000); } //多商户 $merchdata = $this->merchData(); @@ -1473,838 +1489,302 @@ class Detail_EweiShopV2Page extends OpenApiMobilePage } $result['use_membercard'] = $use_membercard; $result['membercard_info'] = $membercard_info; - - return app_json($result); + return $this->result($result); } + public function delete() { - function express() - { global $_W, $_GPC; - $openid = $_W['openid']; - $uniacid = $_W['uniacid']; - $orderid = intval($_GPC['id']); - $sendtype = intval($_GPC['sendtype']); - $bundle = chr(trim($_GPC['bundle'])); - $cycelid = intval($_GPC['cycelid']); - if (empty($orderid) ) { - return app_error(AppError::$OrderNotFound); + $ordersn = $_GPC['order_sn']; + $uniacid = $this->uniacid; + $orderid = intval($_GPC['order_id']); + + if (empty($orderid) && empty($ordersn)) { + return $this->error("参数错误,订单号或ID为空!", 552000); } - - if(!empty($cycelid)){ - $order = pdo_fetch("select expresscom,expresssn,addressid,status,express,address from ".tablename('ewei_shop_cycelbuy_periods') ." where id=:id and uniacid=:uniacid",array(':id'=>$cycelid,':uniacid'=>$uniacid)); - - }else{ - $order = pdo_fetch("select expresscom,expresssn,addressid,status,express,sendtype,address,carrier from " . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1' - , array(':id' => $orderid, ':uniacid' => $uniacid, ':openid' => $openid)); - if (empty($order)) { - return app_error(AppError::$OrderNotFound); - } - if (empty($order['addressid'])) { - return app_error(AppError::$OrderNoExpress); - } - if ($order['status'] < 2 && $order['sendtype'] == 0) { - return app_error(AppError::$OrderNoExpress); - } - } - - $bundlelist = array(); - if(!empty($order['sendtype']) && $sendtype == 0){ - for($i=1;$i<=intval($order['sendtype']);$i++){ - $bundlelist[$i]['code']=chr($i+64); - $bundlelist[$i]['sendtype'] = $i; - $bundlelist[$i]['orderid'] = $orderid; - $goods_arr=pdo_fetchall("select g.title,g.thumb,og.total,og.optionname as optiontitle,og.expresssn,og.express, - og.sendtype,og.expresscom,og.sendtime from " . tablename('ewei_shop_order_goods') . " og " - . " left join " . tablename('ewei_shop_goods') . " g on g.id=og.goodsid " - . " where og.orderid=:orderid and og.sendtype = ".$i." and og.uniacid=:uniacid ", array(':uniacid' => $uniacid, ':orderid' => $orderid)); - foreach ($goods_arr as &$goods){ - $goods['thumb']=tomedia($goods['thumb']); - } - - unset($goods); - $bundlelist[$i]['goods'] =$goods_arr; - if(empty($bundlelist[$i]['goods'])){ - unset($bundlelist[$i]); - } - } - $bundlelist = array_values($bundlelist); - } - $condition = ''; - //商品信息 - if($sendtype>0){ - $condition = ' and og.sendtype = '.$sendtype; - } - - //商品信息 - $goods = pdo_fetchall("select og.goodsid,og.price,g.title,g.thumb,og.total,g.credit,og.optionid,og.optionname as optiontitle,g.isverify,og.expresssn,og.express, - og.sendtype,og.expresscom,og.sendtime,g.storeids from " . tablename('ewei_shop_order_goods') . " og " - . " left join " . tablename('ewei_shop_goods') . " g on g.id=og.goodsid " - . " where og.orderid=:orderid and og.single_refundtime=0 ".$condition." and og.uniacid=:uniacid ", array(':uniacid' => $uniacid, ':orderid' => $orderid)); - if($sendtype>0){ - $order['express'] = $goods[0]['express']; - $order['expresssn'] = $goods[0]['expresssn']; - $order['expresscom'] = $goods[0]['expresscom']; - } - $user['mobile'] = ''; - if ($order['express'] == 'shunfeng') { - if (empty($order['addressid'])) { - $user = unserialize($order['carrier']); - } else { - $user = iunserializer($order['address']); - if (!is_array($user)) { - $user = pdo_fetch("SELECT * FROM " . tablename('ewei_shop_member_address') . " WHERE id = :id and uniacid=:uniacid", array(':id' => $item['addressid'], ':uniacid' => $_W['uniacid'])); - } - } - } - - $expresslist = m('util')->getExpressList($order['express'], $order['expresssn'], $user['mobile']); - $status = ''; - if (!empty($expresslist)) { - if (strexists($expresslist[0]['step'], '已签收')) { - $status = '已签收'; - } else if (count($expresslist) <= 2) { - $status = '已发货'; - } else { - $status = '配送中'; - } - } - else - { - switch (intval($order['status'])){ - case 1:{ - $status = '已支付'; - break; - } - case 3:{ - $status = '已完成'; - break; - } - case -1:{ - $status = '订单关闭'; - break; - } - default :{ - $status = '已发货'; - break; - } - } - } - - - - - return app_json(array( - 'com' => $order['expresscom'], - 'sn' => $order['expresssn'], - 'status' => $status, - 'count' => count($goods), - 'thumb' => tomedia($goods[0]['thumb']), - 'expresslist' => $expresslist, - 'bundlelist'=>$bundlelist - )); - - } - - //周期购详情 - function cycelbuy_list(){ - global $_GPC,$_W; - - $orderid = intval($_GPC['id']); - if (empty($orderid)) { - return app_error(AppError::$OrderNotFound); - } - - $cycelbuy_set = m('common') -> getSysset('cycelbuy'); - - $sql = 'SELECT id,cycelbuy_periodic,refundstate FROM ' .tablename('ewei_shop_order'). ' WHERE id=:orderid AND uniacid =:uniacid '; - $orderData = pdo_fetch($sql,array(':uniacid'=>$_W['uniacid'],':orderid'=>$orderid)); - - $cycelSql = 'SELECT * FROM '.tablename('ewei_shop_cycelbuy_periods').' WHERE orderid=:orderid AND uniacid=:uniacid'; - $cycelParams = array( - ':orderid' => $orderid, - ':uniacid' => $_W['uniacid'], - ); - $cycelData = pdo_fetchall($cycelSql,$cycelParams); - $cycelUnderway = pdo_fetch('SELECT count(*) as count FROM '.tablename('ewei_shop_cycelbuy_periods').' WHERE orderid='.$orderid.' AND status<=1 AND uniacid='.$_W['uniacid']); - - $notStart = false; //未开始 - - $status0=0;//未开始数 - $status2=0;//已完成数 - $period_index=1;//当前第几期,默认取1 - $receipttime=$cycelData[0]['receipttime'];//当期收货时间,默认取第一期 - - $weekArr = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六'); - - if(!empty($cycelData)){ - $notArray= array(); - $start = false; - foreach($cycelData as $ck => $cv){ - $cycelData[$ck]['week'] = $weekArr[date('w',$cv['receipttime'])]; - $cycelData[$ck]['receipttime'] = date('Y-m-d',$cv['receipttime']); - $address = unserialize($cv['address']); - $cycelData[$ck]['addressInfo'] = $address['province'].$address['city'].$address['area'].$address['address']; - - if($cv['status']==0){ - $status0+=1; - $notArray[] = $ck; -// $period_index=$ck; - }elseif ($cv['status']==1){ - $start = true; - $period_index=$ck; - $receipttime=$cv['receipttime']; - }elseif ($cv['status']==2){ - $status2+=1; - } - } - if(empty($start) && !empty($notArray)){ - $period_index = min($notArray); - } - if($status0 == count($cycelData)){ - $notStart = true; - } - - //是否有修改地址申请 - $existApply = ''; - $existApply = pdo_get( 'ewei_shop_address_applyfor' , array('orderid' => $orderid , 'uniacid' => $_W['uniacid'], 'isdelete' => 0) ); - if(!empty($existApply)){ - $applyid = $existApply['id']; - } - } - $applyfor = pdo_get( 'ewei_shop_address_applyfor' , array('orderid' => $orderid , 'uniacid'=>$_W['uniacid']) ); - - $result = array( - 'list' => $cycelData, - 'cycelUnderway' => $cycelUnderway['count'], - 'cycelbuy_periodic' => $orderData['cycelbuy_periodic'], - 'maxday' => $cycelbuy_set['max_day'], - 'notStart' => $notStart, - 'period_index' => $period_index, - 'orderid' => $orderData['id'], - 'applyid' => $applyid, - 'refundstate' =>$orderData['refundstate'], - 'applyforid' =>$applyfor['id'], - ); - - return app_json($result); - } - - //获取周期购时间 - function getCycelbuyDate(){ - global $_W,$_GPC; - - $cycelid = intval($_GPC['cycelid']); - if (empty($cycelid)) { - return app_error(AppError::$OrderNotFound); - } - - $cycelSql = 'SELECT * FROM '.tablename('ewei_shop_cycelbuy_periods').' WHERE id=:cycelid AND uniacid=:uniacid'; - $cycelParams = array( - ':cycelid' => $cycelid, - ':uniacid' => $_W['uniacid'], - ); - - $cycelData = pdo_fetch($cycelSql,$cycelParams); - - $result = array( - 'receipttime' => date('Ymd',$cycelData['receipttime']), - ); - - return app_json($result); - } - - //顺延时间 - public function do_deferred() - { - global $_W,$_GPC; - $openid = $_W['openid']; - $time = intval($_GPC['time']); - $day = 86400; - $order_id = $_GPC['orderid']; - $is_all = intval($_GPC['is_all']); - - if( empty($order_id) ){ - show_json( 0 , '缺少订单ID' ); - } - - if( empty( $_GPC['time'] ) ){ - show_json( 0 , '缺少顺延时间' ); - } - - //获取订单信息 - $order = pdo_get( 'ewei_shop_order' , array('id' => $order_id)); - if( empty( $order ) ){ - show_json( 0 , '没有查到该订单' ); - } - //截取订单时间间隔 - if( !empty( $order['cycelbuy_periodic'] ) ){ - $arr = explode( ',' , $order['cycelbuy_periodic'] ); - }else{ - show_json( 0 , '无法获取周期' ); - } - - - if( $arr[1] == 0 ){ - //间隔多少天 - $interval = $arr['0']*$day; - }elseif( $arr[1] == 1 ){ - $interval = $arr['0']*($day * 7); - }else{ - $interval = $arr['0']*($day * 30); - } - - //查询还没有发的期数商品 - $condition = "orderid = :order_id and uniacid = :uniacid and status = 0 order by receipttime asc "; - - if( empty($is_all) ) { - $condition .= 'limit 1'; - } - $param = array( - 'order_id' => $order_id, - 'uniacid' => $_W['uniacid'], - ); - $data = pdo_fetchall( 'select * from '.tablename('ewei_shop_cycelbuy_periods').' where '.$condition , $param); - -// $data['receipttime'] = $time; - - foreach ( $data as $k => $v ){ - //计算相应的日期 - $receipttime = $time+$interval*$k; - pdo_update( 'ewei_shop_cycelbuy_periods',array('receipttime' => $receipttime),array('id' => $v['id']) ); - } - - $this -> model -> sendMessage(null,$data,'TM_CYCELBUY_SELLER_DATE'); - $this -> model -> sendMessage($openid,$data,'TM_CYCELBUY_BUYER_DATE'); - - $result = array( - 'show' => 1, - 'showText' => '修改成功', - ); - return app_json($result); - - } - - public function address() - { - global $_W, $_GPC; - - $area_set = m('util')->get_area_config_set(); - $new_area = intval($area_set['new_area']); - $address_street = intval($area_set['address_street']); - $show_data = 1; - - $applyforid = intval($_GPC['applyid']); - $orderid = intval($_GPC['id']); - $cycelid = intval($_GPC['cycelid']); - $sql = 'SELECT id,cycelbuy_periodic FROM ' .tablename('ewei_shop_order'). ' WHERE id=:orderid AND uniacid =:uniacid '; - $orderData = pdo_fetch($sql,array(':uniacid'=>$_W['uniacid'],':orderid'=>$orderid)); - $ordersn = $orderData['ordersn']; - if(!empty($orderid)){ - $address= pdo_fetch( 'select * from '.tablename( 'ewei_shop_cycelbuy_periods' ).' where id=:id and orderid=:orderid and status = 0' , array(':orderid' => $orderid,':id'=>$cycelid) ); - $address = iunserializer( $address['address'] ); + pdo_update('ewei_shop_order', array('deleted' => 1), array('id' => $orderid, 'uniacid' => $uniacid)); + }else{ + pdo_update('ewei_shop_order', array('deleted' => 1), array('ordersn' => $ordersn, 'uniacid' => $uniacid)); } - if( !empty($applyforid) ){ - //查询当期修改地址信息 lgt - $new_address = pdo_fetch('select * from '.tablename('ewei_shop_address_applyfor').' where cycleid = :cycleid and isdelete = 0 order by createtime desc limit 1' , array(':cycleid' => $cycelid) ); - if(!empty($new_address)){ - $data = iunserializer( $new_address['data'] ); - $address = array_merge( $new_address , $data ); - } - - } - if((!empty($new_area) && empty($address['datavalue'])) || (empty($new_area) && !empty($address['datavalue']))) { - $show_data = 0; - } - - $result = array( - 'detail' => $address, - ); - if(!empty($applyforid)){ - $result['isdispose'] = $address['isdispose']; - } - - return app_json($result); - + plog('order.op.delete', "接口订单删除 ID: {$orderid} 订单号:{$ordersn}"); + return $this->result(array('msg'=>'订单已删除','order_id'=>$orderid,'order_sn'=>$ordersn)); } - function addressSubmit() { + protected function opData() { + global $_W, $_GPC; - $applyid = intval($_GPC['applyid']); - $orderid = intval($_GPC['orderid']); -// if( $_GPC['ordersn'] ){ -// $new_data['ordersn'] = $_GPC['ordersn']; -// } - $data = array(); - - $data['realname'] = trim($_GPC['realname']); - $data['mobile'] = trim($_GPC['mobile']); - $data['province'] = $_GPC['province']; - $data['city'] = $_GPC['city']; - $data['area'] = $_GPC['area']; - $data['address'] = $_GPC['address']; - $data['street'] = trim($_GPC['street']); - $data['datavalue'] = trim($_GPC['datavalue']); - $data['streetdatavalue'] = trim($_GPC['streetdatavalue']); - $new_data['data'] = iserializer( $data ); - $new_data['orderid'] = $orderid; - $new_data['uniacid'] = $_W['uniacid']; - $new_data['openid'] = $_W['openid']; - $new_data['createtime'] = time(); - if(!empty($_GPC['isall'])){ - $new_data['isall'] = 1; + $ordersn = $_GPC['order_sn']; + $uniacid = $this->uniacid; + $id = intval($_GPC['order_id']); + if (empty($orderid) && empty($ordersn)) { + return $this->error("参数错误,订单号或ID为空!", 552000); + } + if(!empty($orderid)){ + $item = pdo_fetch("SELECT * FROM " . tablename('ewei_shop_order') . " WHERE id = :id and uniacid=:uniacid", array(':id' => $id, ':uniacid' => $_W['uniacid'])); }else{ - $new_data['cycleid'] = $_GPC['cycelid']; //每期id - $new_data['isall'] = 0; + $item = pdo_fetch("SELECT * FROM " . tablename('ewei_shop_order') . " WHERE ordersn = :ordersn and uniacid=:uniacid", array(':ordersn' => $ordersn, ':uniacid' => $_W['uniacid'])); + } + $id = $item['id']; + if (empty($item)) { + return $this->error("未找到订单", 552000); } + $order_goods = pdo_fetchall('select single_refundstate from ' . tablename('ewei_shop_order_goods'). ' where orderid=:orderid and uniacid=:uniacid', array(':uniacid' => $_W['uniacid'], ':orderid' => $item['id'])); - if( !empty( $applyid) ){ - $res = pdo_update( 'ewei_shop_address_applyfor' , $new_data , array('id' => $applyid)); - }else{ - $is_submit = pdo_get( 'ewei_shop_address_applyfor' , array('orderid' => $orderid,'isdelete' => 0 ,'isdispose' => 0) ); - if( $is_submit ){ - return app_json( 1 , '请勿重复提交' ); + $is_singlerefund=false;//是否正在维权 + foreach ($order_goods as $og){ + if(!$is_singlerefund && ($og['single_refundstate']==1 ||$og['single_refundstate']==2)){ + $is_singlerefund=true;//存在维权申请,需要处理后再进行后续操作 + break; } - - //查询老地址 - $address= pdo_fetch( 'select * from '.tablename( 'ewei_shop_cycelbuy_periods' ).' where orderid=:orderid and (status = 0 or status = 1) order by receipttime asc limit 1' , array(':orderid' => $orderid) ); - $new_data['old_address'] = $address['address']; - - $res = pdo_insert( 'ewei_shop_address_applyfor' , $new_data ); } - if( $res != false ){ - return app_json(0); - }else{ - return app_json(1); - } + return array('id' => $id, 'item' => $item,'is_singlerefund'=>$is_singlerefund); } + //接口支付 + public function pay() { - //确认收货 - function confirm_receipt(){ global $_W, $_GPC; + $opdata = $this->opData(); + extract($opdata); - $p = p('commission'); - $pcoupon = com('coupon'); - - $id = $_GPC['id']; - $orderid = $_GPC['orderid']; - - if(empty($id)){ - return app_json(0,array('message'=>'参数错误')); + if ($item['status'] > 1) { + return $this->error("订单已付款,不需重复付款!", 552000); } - if(empty($orderid)){ - return app_json(0,array('message'=>'参数错误')); - } - - $order= pdo_fetch("select * from " . tablename('ewei_shop_order') . ' where uniacid=:uniacid and id=:id limit 1', array(':uniacid' => $_W['uniacid'], ':id' => $orderid)); - $last_periods= pdo_fetch("select * from " . tablename('ewei_shop_cycelbuy_periods') . ' where uniacid=:uniacid and orderid=:orderid order by id desc limit 1', array(':uniacid' => $_W['uniacid'], ':orderid' => $orderid)); - if(!empty($last_periods)){ - if($last_periods['id']==$id){ - pdo_update('ewei_shop_order', array('status' => 3,'finishtime'=>time()), array('id' =>$orderid,'status'=>2)); - $result = pdo_update('ewei_shop_cycelbuy_periods', array( 'status' => 2,'finishtime'=>time()), array('orderid' => $orderid, 'uniacid' => $_W['uniacid'])); - - //会员升级 - m('member')->upgradeLevel($order['openid'], $orderid); - //余额赠送 - m('order')->setGiveBalance($orderid, 1); - //模板消息 - m('notice')->sendOrderMessage($orderid); - //商品全返 - m('order')->fullback($orderid); - //处理积分 - m('order')->setStocksAndCredits($orderid, 3); - //优惠券返利 - if ($pcoupon) { - //发送赠送优惠券 - com('coupon')->sendcouponsbytask($orderid); //订单支付 - - if (!empty($order['couponid'])) { - $pcoupon->backConsumeCoupon($orderid); //自动收货 - } - } - //分销检测 - if ($p) { - $p->checkOrderFinish($orderid); - } - }else{ - $result = pdo_update('ewei_shop_cycelbuy_periods', array( 'status' => 2,'finishtime'=>time()), array('id' => $id, 'uniacid' => $_W['uniacid'])); - } - - - if(!empty($result)){ - return app_json(1,array('message'=>'收货成功')); - }else{ - return app_json(0,array('message'=>'操作失败')); - } - } - - } - - //周期购订单 - function cycel_orderList(){ - global $_W, $_GPC; - $uniacid = $_W['uniacid']; - $openid = $_W['openid']; - if(empty($openid)){ - return app_error(AppError::$ParamsError); - } - - $pindex = max(1, intval($_GPC['page'])); - $psize = 10; - $show_status = $_GPC['status']; - $r_type = array('0' => '退款', '1' => '退货退款', '2' => '换货'); - $condition = " and openid=:openid and ismr=0 and deleted=0 and uniacid=:uniacid and iscycelbuy = 1"; - $params = array( - ':uniacid' => $uniacid, - ':openid' => $openid - ); - - //多商户 - $merchdata = $this->merchData(); - extract($merchdata); - - $condition .= " and merchshow=0 "; - - if ($show_status != '') { - $show_status = intval($show_status); - - switch ($show_status) { - case 0: - $condition .= ' and status=0 and paytype!=3'; - break; - case 2: - $condition .= ' and (status=2 or status=0 and paytype=3)'; - break; - case 4: - $condition .= ' and refundstate>0'; - break; - case 5: - $condition .= " and userdeleted=1 "; - break; - default: - $condition .= ' and status=' . intval($show_status); - } - - if ($show_status != 5) { - $condition .= " and userdeleted=0 "; - } + if (!empty($item['virtual']) && com('virtual')) { + //虚拟物品自动发货 + com('virtual')->pay($item); } else { - $condition .= " and userdeleted=0 "; + $time = time(); + $updateorder = array( + 'status' => 1, + 'paytype' => 11, + 'paytime' => $time + ); + $isonlyverifygoods = m('order')->checkisonlyverifygoods($item['id']); + if($isonlyverifygoods){ + $updateorder['status']=2; + $updateorder['sendtime']= $time; + } + //确认付款先改状态,再设置库存 + pdo_update('ewei_shop_order', $updateorder, array('id' => $item['id'], 'uniacid' => $_W['uniacid'])); + + //设置库存,增加积分 + m('order')->setStocksAndCredits($item['id'], 1); + + //模板消息 + m('notice')->sendOrderMessage($item['id']); + + //打印机打印 + com_run('printer::sendOrderMessage',$item['id']); + + //发送赠送优惠券 + if (com('coupon')) { + com('coupon')->sendcouponsbytask($item['id']); //订单支付 + } + + //优惠券返利 + if (com('coupon') && !empty($item['couponid'])) { + com('coupon')->backConsumeCoupon($item['id']); //后台确认付款 + } + + //分销检测 + if (p('commission')) { + p('commission')->checkOrderPay($item['id']); + } + + //抵消优惠券 + $plugincoupon = com('coupon'); + if ($plugincoupon) { + $oid = $item['id']; + $plugincoupon->useConsumeCoupon($oid); + } } - $com_verify = com('verify'); + //创建记次时商品记录 + m('verifygoods')->createverifygoods($item['id']); - $list = pdo_fetchall("select id,ordersn,price,userdeleted,isparent,refundstate,paytype,status,addressid,refundid,isverify,dispatchtype,verifytype,verifyinfo,verifycode,iscomment from " . tablename('ewei_shop_order') . " where 1 {$condition} order by createtime desc LIMIT " . ($pindex - 1) * $psize . ',' . $psize, $params); - $total = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_order') . " where 1 {$condition}", $params); + plog('order.op.pay', "订单接口确认付款 ID: {$item['id']} 订单号: {$item['ordersn']}"); + return $this->success("订单接口确认付款 ID: {$item['id']} 订单号: {$item['ordersn']}"); + } + //关闭订单 + public function close() + { + global $_W, $_GPC; + $opdata = $this->opData(); + extract($opdata); - $refunddays = intval($_W['shopset']['trade']['refunddays']); - if ($is_openmerch == 1) { - $merch_user = $merch_plugin->getListUser($list, 'merch_user'); + if ($is_singlerefund) { + return $this->error("订单商品存在维权,无法关闭订单!", 552000); } - foreach ($list as &$row) { + if ($item['status'] == -1) { + return $this->error('订单已关闭,无需重复关闭!', 550000); + } else if ($item['status'] >= 1) { + return $this->error('订单已付款,不能关闭!', 556000); + } + if (!empty($item['transid'])) { + //changeWechatSend($item['ordersn'], 0, $_GPC['reson']); + } + $time = time(); + if ($item['refundstate'] > 0 && !empty($item['refundid'])) { - $param = array(); + $change_refund = array(); + $change_refund['status'] = -1; + $change_refund['refundtime'] = $time; + pdo_update('ewei_shop_order_refund', $change_refund, array('id' => $item['refundid'], 'uniacid' => $_W['uniacid'])); + } - if ($row['isparent'] == 1) { - $scondition = " og.parentorderid=:parentorderid"; - $param[':parentorderid'] = $row['id']; - } else { - $scondition = " og.orderid=:orderid"; - $param[':orderid'] = $row['id']; - } + //返还抵扣积分 + if ($item['deductcredit'] > 0) { + m('member')->setCredit($item['openid'], 'credit1', $item['deductcredit'], array('0', $_W['shopset']['shop']['name'] . "购物返还抵扣积分 积分: {$item['deductcredit']} 抵扣金额: {$item['deductprice']} 订单号: {$item['ordersn']}")); + } - //所有商品 - $sql = "SELECT og.id,og.goodsid,og.total,g.title,g.thumb,og.price,og.optionname as optiontitle,og.optionid,op.specs,g.merchid,g.status,og.single_refundid,og.single_refundstate FROM " . tablename('ewei_shop_order_goods') . " og " - . " left join " . tablename('ewei_shop_goods') . " g on og.goodsid = g.id " - . " left join " . tablename('ewei_shop_goods_option') . " op on og.optionid = op.id " - . " where $scondition order by og.id asc"; + //返还抵扣余额 + m('order')->setDeductCredit2($item); - $goods = pdo_fetchall($sql, $param); - $goods = set_medias($goods,array('thumb')); + //退还优惠券 + if (com('coupon') && !empty($item['couponid'])) { + com('coupon')->returnConsumeCoupon($item['id']); //后台关闭订单 + } - $ismerch = 0; - $merch_array = array(); - $g = 0; - $nog = 0; + m('order')->setStocksAndCredits($item['id'], 2); - foreach($goods as &$r){ - $merchid = $r['merchid']; - $merch_array[$merchid]= $merchid; - //读取规格的图片 - if (!empty($r['specs'])) { - $thumb = m('goods')->getSpecThumb($r['specs']); - if (!empty($thumb)) { - $r['thumb'] = tomedia($thumb); - } - } - if($r['status']==2){ - $row['gift'][$g] = $r; - $g++; - }else{ - $row['nogift'][$nog] = $r; - $nog++; + pdo_update('ewei_shop_order', array('status' => -1, 'refundstate' => 0, 'canceltime' => $time, 'remarkclose' => $_GPC['remark']), array('id' => $item['id'], 'uniacid' => $_W['uniacid'])); + + if (!empty($item['virtual']) && $item['virtual'] != 0) { + + $goodsid = pdo_fetch('SELECT goodsid FROM ' . tablename('ewei_shop_order_goods') . ' WHERE uniacid = ' . $_W['uniacid'] . ' AND orderid = ' . $item['id']); + + $typeid = $item['virtual']; + $vkdata = ltrim($item['virtual_info'], '['); + $vkdata = rtrim($vkdata, ']'); + $arr = explode('}', $vkdata); + foreach ($arr as $k => $v) { + if (!$v) { + unset($arr[$k]); } } - unset($r); + $vkeynum = count($arr); - if (!empty($merch_array)) { - if (count($merch_array) > 1) { - $ismerch = 1; - } + //未付款卡密变为未使用 + pdo_query("update " . tablename('ewei_shop_virtual_data') . ' set openid="",usetime=0,orderid=0,ordersn="",price=0,merchid=' . $item['merchid'] . ' where typeid=' . intval($typeid) . ' and orderid = ' . $item["id"]); + + //模板减少使用数据 + pdo_query("update " . tablename('ewei_shop_virtual_type') . " set usedata=usedata-" . $vkeynum . " where id=" . intval($typeid)); + } + + //加入好物圈收藏 + // $goodscircle = p('goodscircle'); + // if ($goodscircle) { + // $goodscircle->updateOrder($item['openid'], $item['id']); + // } + + plog('order.op.close', "订单关闭 ID: {$item['id']} 订单号: {$item['ordersn']}"); + return $this->success("订单关闭 ID: {$item['id']} 订单号: {$item['ordersn']}"); + } + //取消付款 + public function paycancel() + { + global $_W, $_GPC; + $opdata = $this->opData(); + extract($opdata); + if ($is_singlerefund) { + return $this->error("订单商品存在维权,无法取消付款!", 552000); + } + if ($item['status'] != 1) { + return $this->error("订单未付款,不需取消!", 552000); + } + //先设置库存,再更改状态, + m('order')->setStocksAndCredits($item['id'], 2); + + pdo_update('ewei_shop_order', array( + 'status' => 0, + 'cancelpaytime' => time() + ), array('id' => $item['id'], 'uniacid' => $_W['uniacid'])); + + plog('order.op.paycancel', "订单取消付款 ID: {$item['id']} 订单号: {$item['ordersn']}"); + return $this->success("订单取消付款 ID: {$item['id']} 订单号: {$item['ordersn']}"); + } + public function send() { + + global $_W, $_GPC; + $opdata = $this->opData(); + extract($opdata); + + if($is_singlerefund){ + return $this->error("订单商品存在维权,无法取消付款!", 552000); + } + + if ($item['paytype'] != 3) { + if ($item['status'] != 1) { + return $this->error("订单未付款,无法发货!", 552000); } - if(empty($goods)){ - $goods = array(); - } - foreach($goods as &$r){ - $r['thumb'].="?t=".random(50); - } - unset($r); - - $goods_list = array(); - $i = 0; - if ($ismerch) { - $getListUser = $merch_plugin->getListUser($goods); - $merch_user = $getListUser['merch_user']; - - foreach ($getListUser['merch'] as $k => $v) { - if (empty($merch_user[$k]['merchname'])) { - $goods_list[$i]['shopname'] = $_W['shopset']['shop']['name']; - }else{ - $goods_list[$i]['shopname'] = $merch_user[$k]['merchname']; - } - $goods_list[$i]['goods'] = $v; - $i++; - } - } else { - if ($merchid == 0) { - $goods_list[$i]['shopname'] = $_W['shopset']['shop']['name']; - } else { - $merch_data = $merch_plugin->getListUserOne($merchid); - $goods_list[$i]['shopname'] = $merch_data['merchname']; - } - $goods_list[$i]['goods'] = $goods; - } - - $row['goods'] = $goods_list; - - -// print_r($row['goods']);exit; - - $statuscss = "text-cancel"; - - switch ($row['status']) { - case "-1": - $status = "已取消"; - break; - case "0": - if ($row['paytype'] == 3) { - - $status = "待发货"; - } else { - $status = "待付款"; - } - $statuscss = "text-cancel"; - break; - case "1": - if ($row['isverify'] == 1) { - $status = "使用中"; - } else if (empty($row['addressid'])) { - $status = "待取货"; - } else { - $status = "待发货"; - } - $statuscss = "text-warning"; - break; - case "2": - $status = "待收货"; - $statuscss = "text-danger"; - break; - case "3": - if (empty($row['iscomment'])) { - if ($show_status == 5) { - $status = "已完成"; - } else { - $status = empty($_W['shopset']['trade']['closecomment']) ? "待评价" : "已完成"; - - } - } else { - $status = "交易完成"; - } - $statuscss = "text-success"; - break; - } - $row['statusstr'] = $status; - $row['statuscss'] = $statuscss; - if ($row['refundstate'] > 0 && !empty($row['refundid'])) { - - $refund = pdo_fetch("select * from " . tablename('ewei_shop_order_refund') . ' where id=:id and uniacid=:uniacid and orderid=:orderid limit 1' - , array(':id' => $row['refundid'], ':uniacid' => $uniacid, ':orderid' => $row['id'])); + } + if ($_W['ispost']) { + //取消退款状态 + if (!empty($item['refundid'])) { + $refund = pdo_fetch('select * from ' . tablename('ewei_shop_order_refund') . ' where id=:id limit 1', array(':id' => $item['refundid'])); if (!empty($refund)) { - $row['statusstr'] = '待' . $r_type[$refund['rtype']]; + pdo_update('ewei_shop_order_refund', array('status' => -1, 'endtime' => $time), array('id' => $item['refundid'])); + pdo_update('ewei_shop_order', array('refundstate' => 0), array('id' => $item['id'])); } } - //是否可以核销 - $row['canverify'] = false; + if ($item['paytype'] == 3) { + //处理订单库存 + m('order')->setStocksAndCredits($item['id'], 1); + } - $canverify = false; + //加入好物圈收藏 + // $goodscircle = p('goodscircle'); + // if($goodscircle){ + // $goodscircle->updateOrder($item['openid'],$item['id']); + // } - if ($com_verify) { - $showverify = $row['dispatchtype'] || $row['isverify']; - if ($row['isverify']) { - - if ($row['verifytype'] == 0 || $row['verifytype'] == 1) { - $vs = iunserializer($row['verifyinfo']); - $verifyinfo = array( - array( - 'verifycode' => $row['verifycode'], - 'verified' => $row['verifytype'] == 0 ? $row['verified'] : count($vs) >= $row['goods'][0]['total'] - ) - ); - if ($row['verifytype'] == 0) { - $canverify = empty($row['verified']) && $showverify; - } else if ($row['verifytype'] == 1) { - $canverify = count($vs) < $row['goods'][0]['total'] && $showverify; + //模板消息 + m('notice')->sendOrderMessage($item['id']); + + // 判断是否发送小程序订阅消息 + if(!empty($item['wxapp_allow_subscribe'])) { + $template = explode(',', $item['wxapp_allow_subscribe']); + if (in_array('send', $template)) { + $msgdata = array(); + $msgdata['ordersn'] = $item['ordersn']; + $goods = pdo_fetchall("select og.goodsid,og.price,g.title,g.thumb,og.total,g.credit,og.optionid,og.optionname as optiontitle,g.isverify,g.storeids, og.realprice from " . tablename('ewei_shop_order_goods') . " og " + . " left join " . tablename('ewei_shop_goods') . " g on g.id=og.goodsid " + . " where og.orderid=:orderid ", array(':orderid' => $item['id'])); + $title = ''; + foreach ($goods as $og) { + if (!empty($title)) { + $title .= "\n"; } - - } else { - - $verifyinfo = iunserializer($row['verifyinfo']); - - $last = 0; - foreach ($verifyinfo as $v) { - if (!$v['verified']) { - $last++; - } + $title .= $og['title']; + if (!empty($og['optiontitle'])) { + $title .= "(" . $og['optiontitle'].')'; } - $canverify = $last > 0 && $showverify; + $title .= ' 数量:' . $og['total'] . ' 总价: ' . $og['realprice']; + } + $msgdata['title'] = $title; + $msgdata['express'] = $_GPC['expresscom'] ? : '其他快递'; + $msgdata['expresssn'] = trim($_GPC['expresssn']); + $msgdata['time'] = date('Y年m月d日 H:i:s'); + $msgdata['page'] = '/pages/order/detail/index?id='.$item['id']; + if (p('app')) { + if (strexists('sns_wa', $item['openid'])) { + $openid = $item['openid']; + } else { + $openid = pdo_fetchcolumn("select openid_wa from ".tablename('ewei_shop_member')." where openid='{$item['openid']}'"); + } + p('app')->sendSubscribeMessage($openid, $msgdata, 'send'); } - - } else if (!empty($row['dispatchtype'])) { - $canverify = $row['status'] == 1 && $showverify; } } - - $row['canverify'] = $canverify; - if ($is_openmerch == 1) { - $row['merchname'] = $merch_user[$row['merchid']]['merchname'] ? $merch_user[$row['merchid']]['merchname'] : $_W['shopset']['shop']['name']; - } - - $row['cancancel'] = !$row['userdeleted'] && !$row['status']; - $row['canpay'] = $row['paytype'] != 3 && !$row['userdeleted'] && $row['status'] == 0; - $row['canverify'] = $row['canverify'] && $row['status'] != -1 && $row['status'] != 0; - $row['candelete'] = $row['status'] == 3 || $row['status'] == -1; - $row['cancomment'] = $row['status'] == 3 && $row['iscomment'] == 0 && empty($_W['shopset']['trade']['closecomment']); - $row['cancomment2'] = $row['status'] == 3 && $row['iscomment'] == 1 && empty($_W['shopset']['trade']['closecomment']); - $row['cancomplete'] = $row['status'] == 2; - $row['cancancelrefund'] = $row['refundstate'] > 0 && isset($refund) && $refund['status'] != 5; - - $row['candelete2'] = $row['userdeleted'] == 1; - $row['canrestore'] = $row['userdeleted'] == 1; - $row['hasexpress'] = $row['status']>1 && $row['addressid']>0; - + + plog('order.op.send', "订单发货 ID: {$item['id']} 订单号: {$item['ordersn']}"); + return $this->success("订单发货 ID: {$item['id']} 订单号: {$item['ordersn']}"); } - unset($row); - - - return app_json(array( 'list' => $list, 'pagesize' => $psize, 'total' => $total ,'page'=>$pindex)); - - } - - function express_number(){ - global $_W, $_GPC; - $refundid = intval($_GPC['refundid']); - $uniacid = intval($_W['uniacid']); - if($_GPC['submit']){ - if(empty($refundid)){ - return app_error(AppError::$ParamsError); - } - - $refund = array( - 'status'=>4, - 'express'=>trim($_GPC['express']), - 'expresscom'=>trim($_GPC['expresscom']), - 'expresssn'=>trim($_GPC['express_number']), - 'sendtime'=>time() - ); - $res = pdo_update('ewei_shop_order_refund', $refund, array('id' => $refundid, 'uniacid' => $uniacid)); - if($res){ - return app_json(); - } - } - - $sql = 'SELECT * FROM '.tablename('ewei_shop_order_refund').' WHERE id = :id AND uniacid = :uniacid'; - $params = array( - ':id' => $refundid, - ':uniacid' => $uniacid, - ); - $refund = pdo_fetch($sql,$params); - $express_list = m('express')->getExpressList(); - $index = ''; - if(!empty($refund['express'])){ - foreach($express_list as $k => $v){ - if($v['express'] == $refund['express']){ - $index = $k; - } - } - } - return app_json(array( - 'express' => $refund['express'], - 'expresscom' => $refund['expresscom'], - 'express_number' => $refund['expresssn'], - 'express_list' => $express_list, - 'index' => $index, - )); - } - - function single_express_number(){ - global $_W, $_GPC; - $refundid = intval($_GPC['refundid']); - $uniacid = intval($_W['uniacid']); - if($_GPC['submit']){ - if(empty($refundid)){ - return app_error(AppError::$ParamsError); - } - - $refund = array( - 'status'=>4, - 'express'=>trim($_GPC['express']), - 'expresscom'=>trim($_GPC['expresscom']), - 'expresssn'=>trim($_GPC['express_number']), - 'sendtime'=>time() - ); - $res = pdo_update('ewei_shop_order_single_refund', $refund, array('id' => $refundid, 'uniacid' => $uniacid)); - if($res){ - return app_json(); - } - } - - $sql = 'SELECT * FROM '.tablename('ewei_shop_order_single_refund').' WHERE id = :id AND uniacid = :uniacid'; - $params = array( - ':id' => $refundid, - ':uniacid' => $uniacid, - ); - $refund = pdo_fetch($sql,$params); - $express_list = m('express')->getExpressList(); - $index = ''; - if(!empty($refund['express'])){ - foreach($express_list as $k => $v){ - if($v['express'] == $refund['express']){ - $index = $k; - } - } - } - return app_json(array( - 'express' => $refund['express'], - 'expresscom' => $refund['expresscom'], - 'express_number' => $refund['expresssn'], - 'express_list' => $express_list, - 'index' => $index, - )); } }