文件
mashangyoujiu/Application/CashierApi/Controller/OrderController.class.php

2191 行
100 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace CashierApi\Controller;
use Addons\Api\GlobalFunction;
use Addons\Api\ResultCodeManager;
use Common\Business\Sell;
use Common\Business\SerialNumberGoods;
use Common\Business\SkuAttribute;
use Common\Business\StockRecord;
use Common\Model\RetailBillAdvanceModel;
use Common\Model\RetailBillDiscountModel;
use Common\Model\RetailBillOnlineModel;
use Common\Model\RetailBillOrderModel;
use Common\Model\RetailCashierModel;
use Common\Model\RetailDaOrderModel;
use Common\Model\RetailGoodsModel;
use Common\Model\RetailGuideModel;
use Common\Model\RetailPayOrderModel;
use Common\Model\RetailSellModel;
use Common\Model\RetailStoreModel;
use Common\Model\RetailUuOrderModel;
use Common\Model\RetailVipModel;
use Common\Model\SellSerialModel;
use Common\Model\StoreConfigModel;
use LittleGift\Business\Order;
use Make\Business\Make;
use Make\Model\MakeOrderModel;
use PayApi\Controller\PrinterController;
use PayApi\Controller\SellDataController;
use Blessing\Business\Index;
use Common\Business\Plug;
//[1.9.20]
/**
* 订单列表及订单操作
* Class OrderController
* @package CashierApi\Controller
*/
class OrderController extends BaseController
{
/**
* 获取订单列表
*/
public function orderInfo()
{
$type = I('post.type'); // 日期查询条件
$line = I('post.line'); // 判断小程序订单 、 所有订单 1:流水 2:商城
$order_num = I('post.order_number'); // 搜索查询条件
$judge = I('post.judge'); // 订单号 提货码
$page = I('post.page'); // 分页
$num = I('post.num'); // 分页数量
$vipCode = I('post.vip_code'); //会员订单
$cashier_id = self::$cashier_id; // 收银员id
$store_id = self::$store_id;; // 门店id
$BillModel = D("RetailBillOrder");
$BillOnlineModel = D("RetailBillOnline");
$BillDiscountModel = D("RetailBillDiscount");
// 门店
$where[$BillModel::STORE_ID] = $store_id;
$map[$BillModel::STORE_ID] = $store_id;
$refund_map[$BillModel::STORE_ID] = $store_id;
// 已支付
$where[$BillModel::PAY_STATE] = 1;
$map[$BillModel::PAY_STATE] = 1;
$refund_map[$BillModel::PAY_STATE] = 1;
// 时间 查询条件
if ($type == 1) { //今天
$start_time = strtotime(date('Y-m-d 0:0:0', time()));
$end_time = strtotime(date('Y-m-d 0:0:0', time())) + 86400;
$time_str = $start_time . ',' . $end_time;
$where[$BillModel::ADD_TIME] = array('between', $time_str);
$map[$BillModel::ADD_TIME] = array('between', $time_str);
$refund_map[$BillModel::ADD_TIME] = array('between', $time_str);
} else if ($type == 2) { //昨天
$start_time = strtotime(date('Y-m-d 0:0:0', strtotime("-1day")));
$end_time = strtotime(date('Y-m-d 0:0:0', strtotime("-1day"))) + 86400;
$time_str = $start_time . ',' . $end_time;
$where[$BillModel::ADD_TIME] = array('between', $time_str);
$map[$BillModel::ADD_TIME] = array('between', $time_str);
$refund_map[$BillModel::ADD_TIME] = array('between', $time_str);
}else if($type == 6){
$start_time = strtotime(I('post.start_time'));
$end_time = strtotime(I('post.end_time'));
$time_str = $start_time . ',' . $end_time;
$where[$BillModel::ADD_TIME] = array('between', $time_str);
$map[$BillModel::ADD_TIME] = array('between', $time_str);
$refund_map[$BillModel::ADD_TIME] = array('between', $time_str);
} else if ($type == 3) { //本周
$start_time = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)));
$end_time = strtotime(date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))) + 86399;
$time_str = $start_time . ',' . $end_time;
$where[$BillModel::ADD_TIME] = array('between', $time_str);
$map[$BillModel::ADD_TIME] = array('between', $time_str);
$refund_map[$BillModel::ADD_TIME] = array('between', $time_str);
} else if ($type == 4) { //其他
$start_time = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)));
$where[$BillModel::ADD_TIME] = array('lt', $start_time);
$map[$BillModel::ADD_TIME] = array('lt', $start_time);
$refund_map[$BillModel::ADD_TIME] = array('lt', $start_time);
} else { // 默认 今日
$start_time = strtotime(date('Y-m-d 0:0:0', time()));
$end_time = strtotime(date('Y-m-d 0:0:0', time())) + 86400;
$time_str = $start_time . ',' . $end_time;
$where[$BillModel::ADD_TIME] = array('between', $time_str);
$map[$BillModel::ADD_TIME] = array('between', $time_str);
}
// 订单号搜索
if ($order_num) {
if ($judge == 1) {
$where[$BillModel::ORDER_NO] = array('like', '%' . $order_num);
$map[$BillModel::ORDER_NO] = array('like', '%' . $order_num);
$refund_map[$BillModel::ORDER_NO] = array('like', '%' . $order_num);
} else {
$where['o.' . $BillOnlineModel::PICK_CODE] = $order_num;
$map['o.' . $BillOnlineModel::PICK_CODE] = $order_num;
$refund_map['o.' . $BillOnlineModel::PICK_CODE] = $order_num;
}
unset($where[$BillModel::ADD_TIME]);
unset($map[$BillModel::ADD_TIME]);
unset($refund_map[$BillModel::ADD_TIME]);
}
if ($vipCode) {
$StoreModel = new RetailStoreModel();
$VipModel = new RetailVipModel();
$merchant_id = $StoreModel->getFindField(array($StoreModel::ID => $store_id), $StoreModel::MERCHANT_ID);
$vip = $VipModel->getFind(array($VipModel::MOBILE_PHONE . '|' . $VipModel::CARD_NUM . '|' . $VipModel::CARD_KEY => array('like', '%' . $vipCode . '%'), $VipModel::MERCHANT_ID => $merchant_id, $VipModel::STATUS => 1));
if (!$vip) {
$res['status'] = 1;
$res['order'] = array();
$res['msg'] = '会员不存在或已被冻结、挂失';
$res['count'] = 0;
$this->ajaxReturn($res);
} else {
$map[$BillModel::VID] = $vip[$VipModel::ID];
$where[$BillModel::VID] = $vip[$VipModel::ID];
}
}
$CashierModel = new RetailCashierModel();
if ($line == 2) { //线上 小程序订单
$status = I('post.status'); // 类型查询条件
$order_genre = I('post.order_genre'); //1.商城订单 2.拼团订单 3.秒杀订单
$BillGroupModel = D('RetailBillGroup');
$BillSpikeModel = D('RetailBillSpike');
if ($order_genre == 2) {
//拼团
$where['g.' . $BillGroupModel::STATE] = array('in', array(2, 3));
$map['g.' . $BillGroupModel::STATE] = array('in', array(2, 3));
$refund_map['g.' . $BillGroupModel::STATE] = 3;
} else if ($order_genre == 3) {
//秒杀
$where['s.' . $BillSpikeModel::STATE] = array('in', array(0, 1));
$map['s.' . $BillSpikeModel::STATE] = array('in', array(0, 1));
$refund_map['s.' . $BillSpikeModel::STATE] = 0;
}
// 订单类型 普通订单 拼团订单 秒杀订单
$where['o.' . $BillOnlineModel::ORDER_GENRE] = $order_genre;
$map['o.' . $BillOnlineModel::ORDER_GENRE] = $order_genre;
$refund_map['o.' . $BillOnlineModel::ORDER_GENRE] = $order_genre;
$where[$BillModel::TYPE] = 1;
//线上类型查询条件
switch ($status) {
case 0: // 全部订单
$where[$BillModel::ORDER_TYPE] = array('in', array('1', '2'));
$map[$BillModel::ORDER_TYPE] = 1;
$refund_map[$BillModel::ORDER_TYPE] = array('in', array('2', '3'));
$refund_map[$BillModel::TYPE] = 2;
break;
case 1: // 待自提订单
$where['o.' . $BillOnlineModel::PICKUP_TYPE] = 1;
$where[$BillModel::ORDER_TYPE] = 1;
$where['o.' . $BillOnlineModel::STATUS] = 1;
$where[$BillModel::REFUND_STATUS] = 0;
$map['o.' . $BillOnlineModel::PICKUP_TYPE] = 1;
$map[$BillModel::ORDER_TYPE] = 1;
$map['o.' . $BillOnlineModel::STATUS] = 1;
$map[$BillModel::REFUND_STATUS] = 0;
unset($refund_map);
break;
case 2: // 已自提订单
$where['o.' . $BillOnlineModel::PICKUP_TYPE] = 1;
$where[$BillModel::ORDER_TYPE] = 1;
$where['o.' . $BillOnlineModel::STATUS] = 3;
$where[$BillModel::REFUND_STATUS] = 0;
$map['o.' . $BillOnlineModel::PICKUP_TYPE] = 1;
$map[$BillModel::ORDER_TYPE] = 1;
$map['o.' . $BillOnlineModel::STATUS] = 3;
$map[$BillModel::REFUND_STATUS] = 0;
unset($refund_map);
break;
case 3: // 待发货
$where['o.' . $BillOnlineModel::PICKUP_TYPE] = 2;
$where[$BillModel::ORDER_TYPE] = 1;
$where['o.' . $BillOnlineModel::STATUS] = 1;
$where[$BillModel::REFUND_STATUS] = 0;
$map['o.' . $BillOnlineModel::PICKUP_TYPE] = 2;
$map[$BillModel::ORDER_TYPE] = 1;
$map['o.' . $BillOnlineModel::STATUS] = 1;
$map[$BillModel::REFUND_STATUS] = 0;
unset($refund_map);
break;
case 4: // 配送中
$where['o.' . $BillOnlineModel::PICKUP_TYPE] = 2;
$where[$BillModel::ORDER_TYPE] = 1;
$where['o.' . $BillOnlineModel::STATUS] = 2;
$where[$BillModel::REFUND_STATUS] = 0;
$map['o.' . $BillOnlineModel::PICKUP_TYPE] = 2;
$map[$BillModel::ORDER_TYPE] = 1;
$map['o.' . $BillOnlineModel::STATUS] = 2;
$map[$BillModel::REFUND_STATUS] = 0;
unset($refund_map);
break;
case 5: // 已收货
$where['o.' . $BillOnlineModel::PICKUP_TYPE] = 2;
$where[$BillModel::ORDER_TYPE] = 1;
$where['o.' . $BillOnlineModel::STATUS] = 3;
$where[$BillModel::REFUND_STATUS] = 0;
$map['o.' . $BillOnlineModel::PICKUP_TYPE] = 2;
$map[$BillModel::ORDER_TYPE] = 1;
$map['o.' . $BillOnlineModel::STATUS] = 3;
$map[$BillModel::REFUND_STATUS] = 0;
unset($refund_map);
break;
case 6: // 正常购买
$where[$BillModel::ORDER_TYPE] = 1;
$where[$BillModel::REFUND_STATUS] = 0;
$map[$BillModel::ORDER_TYPE] = 1;
$map[$BillModel::REFUND_STATUS] = 0;
unset($refund_map);
break;
case 7: // 待退款
$where[$BillModel::ORDER_TYPE] = 2;
$where[$BillModel::REFUND_STATUS] = 1;
$refund_map[$BillModel::ORDER_TYPE] = 2;
$refund_map[$BillModel::REFUND_STATUS] = 1;
unset($map);
break;
case 8: // 已退款
$where[$BillModel::ORDER_TYPE] = 1;
$where[$BillModel::REFUND_STATUS] = array('in', array('2', '3'));
$refund_map[$BillModel::ORDER_TYPE] = 1;
$refund_map[$BillModel::REFUND_STATUS] = array('in', array('2', '3'));
unset($map);
break;
case 9: // 购买订单
$where[$BillModel::ORDER_TYPE] = 1;
$map[$BillModel::ORDER_TYPE] = 1;
$refund_map[$BillModel::ORDER_TYPE] = 1;
$refund_map[$BillModel::REFUND_STATUS] = array('in', array('1', '2', '3'));
break;
case 10: // 退款订单
$where[$BillModel::ORDER_TYPE] = 2;
$refund_map[$BillModel::ORDER_TYPE] = 2;
unset($map);
break;
default:
$where[$BillModel::ORDER_TYPE] = array('in', array('1', '2'));
$map[$BillModel::ORDER_TYPE] = 1;
$refund_map[$BillModel::ORDER_TYPE] = array('in', array('2', '3'));
}
if (!empty($map)) {
$map[$BillModel::TYPE] = 1;
if ($order_genre == 1) {
//商城
$resBack = $BillModel->getOnlineAllData($map); //获取总条数和总金额
} else if ($order_genre == 2) {
//拼团
$resBack = $BillModel->getOnlineGroupAllData($map); //获取总条数和总金额
} else if ($order_genre == 3) {
//秒杀
$resBack = $BillModel->getOnlineSkillAllData($map); //获取总条数和总金额
}
$order_count = $resBack['num'];
$order_money = $resBack['money'];
} else {
$order_count = 0;
$order_money = 0;
}
if (!empty($refund_map)) {
$refund_map[$BillModel::TYPE] = 1;
if ($order_genre == 1) {
//商城
$resBack = $BillModel->getOnlineAllData($refund_map); //获取总条数和总金额
} else if ($order_genre == 2) {
//拼团
$resBack = $BillModel->getOnlineGroupAllData($refund_map); //获取总条数和总金额
} else if ($order_genre == 3) {
//秒杀
$resBack = $BillModel->getOnlineSkillAllData($refund_map); //获取总条数和总金额
}
$refund_order_count = $resBack['num'];
$refund_order_money = $resBack['money'];
} else {
$refund_order_count = 0;
$refund_order_money = 0;
}
$all_money = $order_money - $refund_order_money;
$res['order_count'] = $order_count;
$res['order_money'] = $order_money;
$res['refund_order_count'] = $refund_order_count;
$res['refund_order_money'] = $refund_order_money;
$res['all_money'] = $all_money > 0 ? round($all_money, 2) : '0';
if ($order_genre == 1) {
//商城
$modelRes = $BillModel->getOnlineOrder($where, $page, $num);
} else if ($order_genre == 2) {
//拼团
$modelRes = $BillModel->getOnlineGroupOrder($where, $page, $num);
} else if ($order_genre == 3) {
//秒杀
$modelRes = $BillModel->getOnlineSkillOrder($where, $page, $num);
}
} else {
/* 收银员是否可以查看所有订单 */
$cashier_show_other_sell = $CashierModel->getFindField(array($CashierModel::ID => $cashier_id), $CashierModel::SHOW_SELL_STATE);
$cashier_show_other_sell = $cashier_show_other_sell ? $cashier_show_other_sell : 2;
if ($cashier_show_other_sell == 2) { // 收银员查看自己订单
$map[$BillModel::CASHIER_ID] = $cashier_id;
$where[$BillModel::CASHIER_ID] = $cashier_id;
$refund_map[$BillModel::CASHIER_ID] = $cashier_id;
}
//现金支付
$map[$BillModel::TYPE] = 2;
$combination = A('PayApi/SellData')->combinationPayment($map, 1);
$map[$BillModel::PAY_TYPE] = 1;
$map[$BillModel::ORDER_TYPE] = 1;
$x_money = $BillModel->getSum($map, $BillModel::ALL_MONEY);
$x_money = round($x_money + $combination['combination_xj'], 2);
// 微信支付
$map[$BillModel::PAY_TYPE] = array('in', '3,6');
$w_money = $BillModel->getSum($map, $BillModel::ALL_MONEY);
$w_money = round($w_money + $combination['combination_wxpay'], 2);
//支付宝支付
$map[$BillModel::PAY_TYPE] = 4;
$z_money = $BillModel->getSum($map, $BillModel::ALL_MONEY);
$z_money = round($z_money + $combination['combination_zfb'], 2);
//会员卡余额
$map[$BillModel::PAY_TYPE] = 5;
$h_money = $BillModel->getSum($map, $BillModel::ALL_MONEY);
$h_money = round($h_money + $combination['combination_membermoney'], 2);
//其他支付
$map[$BillModel::PAY_TYPE] = 7;
$other_money = $BillModel->getSum($map, $BillModel::ALL_MONEY);
$other_money = round($other_money + $combination['combination_other_pay'], 2);
//退款金额
$refund_map[$BillModel::ORDER_TYPE] = 2;
$refund_money = $BillModel->getSum($refund_map, $BillModel::ALL_MONEY);
$refund_money = $refund_money ? round($refund_money, 2) : 0;
$res['x_money'] = $x_money;
$res['w_money'] = $w_money;
$res['z_money'] = $z_money;
$res['h_money'] = $h_money;
$res['o_money'] = $other_money;
$res['r_money'] = $refund_money;
$where['type'] = 2;
$modelRes = $BillModel->getOutlineOrder($where, $page, $num);
}
$order = $modelRes['data'];
$order_count = $modelRes['count'];
$SellModel = D('RetailSell');
if (!empty($order)) {
foreach ($order as $key => &$val) {
if ($val[$BillDiscountModel::COUPON_MONEY] == null) {
$val[$BillDiscountModel::COUPON_MONEY] = '0.00';
}
if ($val[$BillDiscountModel::CASHIER_DIS_MONEY] == null) {
$val[$BillDiscountModel::CASHIER_DIS_MONEY] = '0.00';
}
if ($val[$BillDiscountModel::SMALL_CHANGES_MONEY] == null) {
$val[$BillDiscountModel::SMALL_CHANGES_MONEY] = '0.00';
}
if ($val[$BillDiscountModel::INTEGRAL_DIS_MONEY] == null) {
$val[$BillDiscountModel::INTEGRAL_DIS_MONEY] = '0.00';
}
if ($val[$BillDiscountModel::VIP_DIS_MONEY] == null) {
$val[$BillDiscountModel::VIP_DIS_MONEY] = '0.00';
}
$val['user_select_time'] = $val['user_select_time'] ? date('m-d H:i', $val['user_select_time']) : '';
//商城订单返回数据
if ($line == 2) {
//判断是否达达配送
if ($val[$BillOnlineModel::DELIVERY_TYPE] == 2) {
$DaOrderModel = D('RetailDaOrder');
$clerkinfo = $DaOrderModel->getOrderFind(array($DaOrderModel::ORDER_NO => strval($val[$BillModel::ORDER_NO]), $DaOrderModel::ID => $val[$BillOnlineModel::DELIVERY_RECORD_ID]), '*', 'id desc');
$val['order_status'] = $clerkinfo[$DaOrderModel::ORDER_STATUS];
} else if ($val[$BillOnlineModel::DELIVERY_TYPE] == 1) {
//门店配送
if ($val[$BillOnlineModel::STATUS] == 1 && $val[$BillOnlineModel::PICKUP_TYPE] = 2) {
$val['order_status'] = 0;
}
} else if ($val[$BillOnlineModel::DELIVERY_TYPE] == 3) {
//Uu配送转成达达订单状态显示
$uuOrderModel = D('RetailUuOrder');
$state_uu = $uuOrderModel->getOrderFindField(array($uuOrderModel::ORIGIN_ID => $val[$BillModel::ID], $uuOrderModel::ID => $val[$BillOnlineModel::DELIVERY_RECORD_ID]), $uuOrderModel::STATE, 'id desc');
if ($state_uu == 1) {
$val['order_status'] = 1;
} else if ($state_uu == 3 || $state_uu == 4) {
$val['order_status'] = 2;
} else if ($state_uu == 5 || $state_uu == 6) {
$val['order_status'] = 3;
} else {
$val['order_status'] = 4;
}
$val['delivery'] = 2;
}
if ($val[$BillModel::TYPE] == 1) {
//商城
if ($val[$BillOnlineModel::PICKUP_TYPE] == 2) {
if ($val[$BillOnlineModel::USER_ADDRESS]) {
$val['address_name'] = $val[$BillOnlineModel::USER_NAME];
$val['address_phone'] = $val[$BillOnlineModel::USER_PHONE];
$val['address_address'] = $val[$BillOnlineModel::USER_ADDRESS];
}
} else {
$val['address_name'] = $val[$BillOnlineModel::USER_NAME];
$val['address_phone'] = $val[$BillOnlineModel::USER_PHONE];
}
}
}
$val[$CashierModel::JOB_NUM] = $CashierModel->getFindField(array($CashierModel::ID => $val[$BillModel::CASHIER_ID]), $CashierModel::JOB_NUM);
$val['key'] = $key + 1;
//判断支付人员类型
if (!empty($val[$BillModel::VID])) {
$val['vip_class'] = '会员';
} else {
$val['vip_class'] = '散客';
}
$val['payList'] = getPayTypeList($val[$BillModel::PAY_TYPE], $val[$BillModel::ALL_MONEY], $val[$BillModel::ID]);
$fields = array(
$SellModel::VIP_DISCOUNT,
$SellModel::GOODS_ID,
$SellModel::GOODS_NAME,
$SellModel::NUM,
$SellModel::REFUND_NUM,
$SellModel::VIP_PRICE,
$SellModel::PRICE,
$SellModel::ORIGINAL_PRICE,
$SellModel::PLUS_VIP_PRICE,
$SellModel::ORIGINAL_PRICE,
$SellModel::ALL_MONEY,
$SellModel::GOODS_TYPE,
$SellModel::ATTRIBUTE_STATE,
$SellModel::SKU_JSON_INFO,
$SellModel::PRICING_METHOD,
);
$sellList = $SellModel->getSelect(array($SellModel::BILL_ID => $val[$BillModel::ID]), $fields);
$beforeAllMoney = 0;
$v_discount = 1;
foreach ($sellList as $key => &$v) {
$v['index'] = $key + 1;
if (($v[$SellModel::GOODS_TYPE] == 2 || $v[$SellModel::GOODS_ID] == 0) && empty($v[$SellModel::GOODS_NAME])) {
$v[$SellModel::GOODS_NAME] = '无码商品';
}
if (!empty($v[$SellModel::SKU_JSON_INFO])) {
$sku = json_decode($v[$SellModel::SKU_JSON_INFO], true);
$v['sku_name'] = $sku['name'];
$v['sku_id'] = $sku['id'];
} else {
$v['sku_name'] = '';
$v['sku_id'] = 0;
}
$v[$SellModel::NUM] = round($v[$SellModel::NUM], 3);
if (floatval($v[$SellModel::VIP_DISCOUNT]) < 1 && floatval($v[$SellModel::VIP_DISCOUNT]) > 0) {
$v_discount = floatval($v[$SellModel::VIP_DISCOUNT]);
}
$v[$SellModel::PRICE] = floatval($v[$SellModel::PRICE]);
$v[$SellModel::ORIGINAL_PRICE] = floatval($v[$SellModel::ORIGINAL_PRICE]);
$v[$SellModel::PLUS_VIP_PRICE] = floatval($v[$SellModel::PLUS_VIP_PRICE]);
$v[$SellModel::VIP_PRICE] = floatval($v[$SellModel::VIP_PRICE]);
$v['before_all_money'] = round($v[$SellModel::PRICE] * $v[$SellModel::NUM], 2);
$beforeAllMoney += $v['before_all_money'];
}
$val['v_discount'] = $v_discount;
$val['beforeAllMoney'] = $beforeAllMoney;
$val['goods_info'] = $sellList;
// $val['coupon'] = $val[$BillDiscountModel::VIP_DIS_MONEY];
//配送
$val[$BillModel::ADD_TIME] = date('Y-m-d H:i:s', $val[$BillModel::ADD_TIME]);
$val[$BillDiscountModel::CASHIER_DIS_MONEY] = !empty($val[$BillDiscountModel::CASHIER_DIS_MONEY]) ? $val[$BillDiscountModel::CASHIER_DIS_MONEY] : 0;
//优惠金额
$val['discount_amount'] = round($val[$BillDiscountModel::COUPON_MONEY] + $val[$BillDiscountModel::VIP_DIS_MONEY] + $val[$BillDiscountModel::CASHIER_DIS_MONEY] + $val[$BillDiscountModel::SMALL_CHANGES_MONEY], 2);
$guide_name = '';
if (!empty($val[$BillModel::GUIDE_ID])) {
$GuideModel = D('RetailGuide');
$guide_name = $GuideModel->getFindField(array($GuideModel::ID => $val[$BillModel::GUIDE_ID]), $GuideModel::NAME);
}
$val['guide_name'] = $guide_name;
unset($val[$BillModel::PAY_TYPE]);
unset($val[$BillModel::VID]);
unset($val[$BillModel::STORE_ID]);
unset($val[$BillModel::MERCHANT_ID]);
unset($val[$BillModel::CASHIER_ID]);
}
} else {
$order = array();
}
$res['status'] = 1;
$res['order'] = $order;
$res['count'] = $order_count;
$this->ajaxReturn($res);
}
/**
* 获取订单列表2020-3-4
* $type 日期查询条件
* $line 判断小程序订单 、 所有订单 1:流水 2:商城
* $order_num 搜索查询条件
* $page 分页
* $num 分页数量
* $vipCode 会员订单
* $cashier_id 收银员id
* $store_id 门店id
* judge 搜索类型 1订单号 2自提码 3串号
*/
public function orderInfo_v1()
{
$type = I('post.type');
$line = I('post.line');
$order_num = I('post.order_number');
$judge = I('post.judge');
$page = I('post.page');
$num = I('post.num');
$vipCode = I('post.vip_code');
$bill_type = I('post.bill_type'); //订单类型 1普通订单 2赊账订单
$credit_type = I('post.credit_type'); //选择赊账状态 1未还清 2已还清
$pay_type = I('post.pay_type'); //支付方式 1微信 2支付宝 3现金 4余额
$cashier_id = self::$cashier_id;
$store_id = self::$store_id;
$BillModel = new RetailBillOrderModel();
$SellSerialModel = new SellSerialModel();
$SerialClass = new SerialNumberGoods();
// 门店
$where['b.store_id'] = $store_id;
$map['store_id'] = $store_id;
$refund_map['store_id'] = $store_id;
// 已支付
$where['b.pay_state'] = 1;
$map['pay_state'] = 1;
$refund_map['pay_state'] = 1;
// 时间 查询条件
switch ($type) {
case 1:
//今天
$start_time = strtotime(date('Y-m-d 0:0:0', time()));
$end_time = strtotime(date('Y-m-d 0:0:0', time())) + 86400;
$time_str = $start_time . ',' . $end_time;
$where['b.add_time'] = ['between', $time_str];
$map['add_time'] = ['between', $time_str];
$refund_map['add_time'] = ['between', $time_str];
$credit_map['ca.add_time'] = ['between', $time_str];
break;
case 2:
//昨天
$start_time = strtotime(date('Y-m-d 0:0:0', strtotime("-1day")));
$end_time = strtotime(date('Y-m-d 0:0:0', strtotime("-1day"))) + 86400;
$time_str = $start_time . ',' . $end_time;
$where['b.add_time'] = ['between', $time_str];
$map['add_time'] = ['between', $time_str];
$refund_map['add_time'] = ['between', $time_str];
$credit_map['ca.add_time'] = ['between', $time_str];
break;
case 3:
//本周
$start_time = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)));
$end_time = strtotime(date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))) + 86399;
$time_str = $start_time . ',' . $end_time;
$where['b.add_time'] = ['between', $time_str];
$map['add_time'] = ['between', $time_str];
$refund_map['add_time'] = ['between', $time_str];
$credit_map['ca.add_time'] = ['between', $time_str];
break;
case 4:
//其他
$start_time = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)));
$where['b.add_time'] = ['lt', $start_time];
$map['add_time'] = ['lt', $start_time];
$refund_map['add_time'] = ['lt', $start_time];
$credit_map['ca.add_time'] = ['lt', $start_time];
break;
case 6:
$start_time = strtotime(I('post.start_time'));
$end_time = strtotime(I('post.end_time'));
$time_str = $start_time . ',' . $end_time;
$where[$BillModel::ADD_TIME] = array('between', $time_str);
$map[$BillModel::ADD_TIME] = array('between', $time_str);
$refund_map[$BillModel::ADD_TIME] = array('between', $time_str);
break;
default:
// 默认 今日
$start_time = strtotime(date('Y-m-d 0:0:0', time()));
$end_time = strtotime(date('Y-m-d 0:0:0', time())) + 86400;
$time_str = $start_time . ',' . $end_time;
$where['b.add_time'] = ['between', $time_str];
$map['add_time'] = ['between', $time_str];
$credit_map['ca.add_time'] = ['between', $start_time];
break;
}
// 订单号搜索
if (!empty($order_num)) {
switch ($judge) {
case 1:
$where['b.order_no'] = ['like', '%' . $order_num];
$map['order_no'] = ['like', '%' . $order_num];
$refund_map['order_no'] = ['like', '%' . $order_num];
$credit_map['rbo.order_no'] = ['like', '%' . $order_num];
break;
case 2:
$where['o.pick_code'] = $order_num;
$map['o.pick_code'] = $order_num;
$refund_map['o.pick_code'] = $order_num;
break;
case 3:
$order_id_arr = $SellSerialModel->basisSerialOrderId($order_num, 1);
if (!empty($order_id_arr)) {
$where['b.id'] = ['in', $order_id_arr];
$map['id'] = ['in', $order_id_arr];
$refund_map['id'] = ['in', $order_id_arr];
$credit_map['ca.id'] = ['in', $order_id_arr];
} else {
$res['status'] = 1;
$res['order'] = [];
$res['msg'] = '串号不存在';
$res['count'] = 0;
$this->ajaxReturn($res);
}
break;
}
unset($where['b.add_time']);
unset($map['add_time']);
unset($refund_map['add_time']);
unset($credit_map['ca.add_time']);
}
$VipModel = new RetailVipModel();
if ($vipCode) {
$StoreModel = new RetailStoreModel();
$merchant_id = $StoreModel->getFindField(['id' => $store_id], 'merchantid');
$vip = $VipModel->getFind(['mobile_phone|cardnum|card_key' => ['like', '%' . $vipCode . '%'], 'merchantid' => $merchant_id, 'status' => 1]);
if (!$vip) {
$res['status'] = 1;
$res['order'] = [];
$res['msg'] = '会员不存在或已被冻结、挂失';
$res['count'] = 0;
$this->ajaxReturn($res);
} else {
$map['vid'] = $vip['id'];
$where['b.vid'] = $vip['id'];
$credit_map['rc.vid'] = $vip['id'];
}
}
$CashierModel = new RetailCashierModel();
if ($line == 2) { //线上 小程序订单
$where['pay_state'] = ['in', '1,2'];
$map['pay_state'] = ['in', '1,2'];
$status = I('post.status'); // 类型查询条件
$order_genre = I('post.order_genre'); //1.商城订单 2.拼团订单 3.秒杀订单 4预售订单
$where['o.order_genre'] = $order_genre;
$map['o.order_genre'] = $order_genre;
$where['type'] = 1;
$where['b.order_type'] = 1;
$map['b.order_type'] = 1;
switch ($order_genre) {
case 2:
//拼团
$where['g.state'] = ['in', '2,3'];
$map['g.state'] = ['in', '2,3'];
break;
case 3:
//秒杀
$where['s.state'] = ['in', '0,1'];
$map['s.state'] = ['in', '0,1'];
break;
case 4:
$where['a.state'] = ['in', '1,2'];
$map['a.state'] = ['in', '1,2'];
break;
}
switch ($status) {
case 0: // 全部订单
$where['order_type'] = 1;
$map['order_type'] = 1;
break;
case 1: // 待自提订单
$where['o.pickup_type'] = 1;
$where['order_type'] = 1;
$where['o.status'] = 1;
$where['refund_status'] = 0;
$map['o.pickup_type'] = 1;
$map['order_type'] = 1;
$map['o.status'] = 1;
$map['refund_status'] = 0;
break;
case 2: // 已自提订单
$where['o.pickup_type'] = 1;
$where['order_type'] = 1;
$where['o.status'] = 3;
$where['refund_status'] = 0;
$map['o.pickup_type'] = 1;
$map['order_type'] = 1;
$map['o.status'] = 3;
$map['refund_status'] = 0;
break;
case 3: // 待发货
$where['o.pickup_type'] = 2;
$where['order_type'] = 1;
$where['o.status'] = 1;
$where['refund_status'] = 0;
$map['o.pickup_type'] = 2;
$map['order_type'] = 1;
$map['o.status'] = 1;
$map['refund_status'] = 0;
break;
case 4: // 配送中
$where['o.pickup_type'] = 2;
$where['order_type'] = 1;
$where['o.status'] = 2;
$where['refund_status'] = 0;
$map['o.pickup_type'] = 2;
$map['order_type'] = 1;
$map['o.status'] = 2;
$map['refund_status'] = 0;
break;
case 5: // 已收货
$where['o.pickup_type'] = 2;
$where['order_type'] = 1;
$where['o.status'] = 3;
$where['refund_status'] = 0;
$map['o.pickup_type'] = 2;
$map['order_type'] = 1;
$map['o.status'] = 3;
$map['refund_status'] = 0;
break;
case 6: // 正常购买
$where['order_type'] = 1;
$where['refund_status'] = 0;
$map['order_type'] = 1;
$map['refund_status'] = 0;
break;
case 9: // 购买订单
$where['order_type'] = 1;
$map['order_type'] = 1;
break;
case 10:
//待付尾款已过期
$where['a.state'] = 1;
$where['a.tail_end_time'] = ['lt', time()];
$where['a.advance_type'] = 2;
$map['a.state'] = 1;
$map['a.tail_end_time'] = ['lt', time()];
$map['a.advance_type'] = 2;
break;
case 11:
//待付尾款未过期
$where['a.state'] = 1;
$where['a.tail_end_time'] = ['gt', time()];
$where['a.advance_type'] = 2;
$map['a.state'] = 1;
$map['a.tail_end_time'] = ['gt', time()];
$map['a.advance_type'] = 2;
break;
case 12:
//已付款
$where['a.state'] = 2;
$map['a.state'] = 2;
break;
default:
$where['order_type'] = 1;
$map['order_type'] = 1;
}
if (!empty($map)) {
$map['type'] = 1;
switch ($order_genre) {
case 1:
//商城
$resBack = $BillModel->getOnlineAllData($map); //获取总条数和总金额
break;
case 2:
//拼团
$resBack = $BillModel->getOnlineGroupAllData($map); //获取总条数和总金额
break;
case 3:
//秒杀
$resBack = $BillModel->getOnlineSkillAllData($map); //获取总条数和总金额
break;
case 4:
//预售
$resBack = $BillModel->getAdvanceData($map); //获取总条数和总金额
break;
}
$order_count = $resBack['num'];
$order_money = $resBack['money'];
} else {
$order_count = 0;
$order_money = 0;
}
if (!empty($refund_map)) {
$refund_map['type'] = 1;
$refund_map['order_type'] = 2;
if ($order_genre == 1) {
//商城
$resBack = $BillModel->getOnlineAllData($refund_map); //获取总条数和总金额
} else if ($order_genre == 2) {
//拼团
$resBack = $BillModel->getOnlineGroupAllData($refund_map); //获取总条数和总金额
} else if ($order_genre == 3) {
//秒杀
$resBack = $BillModel->getOnlineSkillAllData($refund_map); //获取总条数和总金额
}
$refund_order_count = $resBack['num'];
$refund_order_money = $resBack['money'] ? $resBack['money'] : 0;
} else {
$refund_order_count = 0;
$refund_order_money = 0;
}
$all_money = $order_money - $refund_order_money;
$res['order_count'] = $order_count;
$res['order_money'] = $order_money;
$res['refund_order_count'] = $refund_order_count;
$res['refund_order_money'] = $refund_order_money;
$res['all_money'] = $all_money > 0 ? round($all_money, 2) : '0';
switch ($order_genre) {
case 1:
//商城
$modelRes = $BillModel->getOnlineOrder($where, $page, $num);
break;
case 2:
//拼团
$modelRes = $BillModel->getOnlineGroupOrder($where, $page, $num);
break;
case 3:
//秒杀
$modelRes = $BillModel->getOnlineSkillOrder($where, $page, $num);
break;
case 4:
//预售
$modelRes = $BillModel->getAdvanceOrder($where, $page, $num);
break;
}
} else {
/* 收银员是否可以查看所有订单 */
$cashier_show_other_sell = $CashierModel->getFindField(['id' => $cashier_id], 'cashier_show_other_sell');
$cashier_show_other_sell = $cashier_show_other_sell ? $cashier_show_other_sell : 2;
if ($cashier_show_other_sell == 2) { // 收银员查看自己订单
$map['cashier_id'] = $cashier_id;
$where['b.cashier_id'] = $cashier_id;
$refund_map['cashier_id'] = $cashier_id;
$credit_map['ca.cashier_id'] = $cashier_id;
}
//订单类型 1普通订单 2赊账订单
if ($bill_type && in_array('Credit', C('MODULE_ALLOW_LIST'))) {
$where['settlement_type'] = $bill_type;
$map['settlement_type'] = $bill_type;
$refund_map['settlement_type'] = $bill_type;
}
//选择赊账状态 1未还清 2已还清
if ($credit_type) {
if ($credit_type == 1) {
$where['ca.state'] = 2;
} else if ($credit_type == 2) {
$where['ca.state'] = 1;
}
}
//支付方式 1微信 2支付宝 3现金 4余额
if ($pay_type) {
switch ($pay_type) {
case 1:
$where['pay_type'] = 3;
$map['pay_type'] = 3;
$refund_map['pay_type'] = 3;
break;
case 2:
$where['pay_type'] = 4;
$map['pay_type'] = 4;
$refund_map['pay_type'] = 4;
break;
case 3:
$where['pay_type'] = 1;
$map['pay_type'] = 1;
$refund_map['pay_type'] = 1;
break;
case 4:
$where['pay_type'] = 5;
$map['pay_type'] = 5;
$refund_map['pay_type'] = 5;
break;
case 5:
$where['pay_type'] = 8;
$map['pay_type'] = 8;
$refund_map['pay_type'] = 8;
break;
}
}
//现金支付
$map['type'] = 2;
$SellDataApi = new SellDataController();
$combination = $SellDataApi->combinationPayment($map, 1);
$map['pay_type'] = 1;
$map['order_type'] = 1;
$x_money = $BillModel->getSum($map, 'all_money');
$x_money = round($x_money + $combination['combination_xj'], 2);
// 微信支付
$map['pay_type'] = ['in', '3,6'];
$w_money = $BillModel->getSum($map, 'all_money');
$w_money = round($w_money + $combination['combination_wxpay'], 2);
//支付宝支付
$map['pay_type'] = 4;
$z_money = $BillModel->getSum($map, 'all_money');
$z_money = round($z_money + $combination['combination_zfb'], 2);
//会员卡余额
$map['pay_type'] = 5;
$h_money = $BillModel->getSum($map, 'all_money');
$h_money = round($h_money + $combination['combination_membermoney'], 2);
//其他支付
$map['pay_type'] = 7;
$other_money = $BillModel->getSum($map, 'all_money');
$other_money = round($other_money + $combination['combination_other_pay'], 2);
//赊账
if (in_array('Credit', C('MODULE_ALLOW_LIST'))) {
$ArrearageModel = new \Credit\Model\CreditArrearageModel();
$credit_map['ca.store_id'] = $store_id;
$credit_map['ca.status'] = 1;
if ($cashier_show_other_sell == 2) {
$credit_map['cashier_id'] = $cashier_id;
}
$res['c_money'] = $ArrearageModel->getPcCreditMoney($credit_map);
}
//退款金额
$refund_map['order_type'] = 2;
$refund_money = $BillModel->getSum($refund_map, 'all_money');
$refund_money = $refund_money ? round($refund_money, 2) : 0;
$res['x_money'] = $x_money;
$res['w_money'] = $w_money;
$res['z_money'] = $z_money;
$res['h_money'] = $h_money;
$res['o_money'] = $other_money;
$res['r_money'] = $refund_money;
$where['type'] = 2;
$modelRes = $BillModel->getOutlineOrder($where, $page, $num);
}
$order = $modelRes['data'];
$order_count = $modelRes['count'];
$payTypeName = [
'1' => '现金',
'2' => '银行卡',
'3' => '微信',
'4' => '支付宝',
'5' => '会员余额',
'6' => '小程序微信',
'7' => '其他',
'8' => '组合',
];
$SellModel = new RetailSellModel();
$PayOrderModel = new RetailPayOrderModel();
$DaOrderModel = new RetailDaOrderModel();
$uuOrderModel = new RetailUuOrderModel();
$GuideModel = new RetailGuideModel();
$BillAdvanceModel = new RetailBillAdvanceModel();
$SkuAttribute = new SkuAttribute();
$plugClass = new Plug();
//订单获取祝福码,判断该门店是否,有,并且开启
$storePlugStatusPost = [
'store_id' => $store_id,
'identification_arr' => ['blessing'],
];
$storePlugStatus = $plugClass->plugStoreStatus($storePlugStatusPost);//获取状态
if (!empty($order)) {
foreach ($order as $key => &$val) {
if (!$val['ca_id']) {
unset($val['ca_id']);
}
if ($val['coupon_money'] == null) {
$val['coupon_money'] = '0.00';
}
if ($val['cashier_dis_money'] == null) {
$val['cashier_dis_money'] = '0.00';
}
if ($val['small_changes_money'] == null) {
$val['small_changes_money'] = '0.00';
}
if ($val['integral_dis_money'] == null) {
$val['integral_dis_money'] = '0.00';
}
if ($val['vip_dis_money'] == null) {
$val['vip_dis_money'] = '0.00';
}
if ($val['cashier_manual_money'] == null) {
$val['cashier_manual_money'] = '0.00';
}
if ((int)$val['pay_type'] != 0) {
$val['pay_type_name'] = $payTypeName[$val['pay_type']] ? $payTypeName[$val['pay_type']] : '未知类型';
} else {
if (in_array('Credit', C('MODULE_ALLOW_LIST'))) {
$CreditRecord = new \Credit\Business\CreditRecord();
$val['pay_type_name'] = $CreditRecord->getPayTypeName($val['id']);
} else {
$val['pay_type_name'] = '未知类型';
}
}
$val['user_select_time'] = $val['user_select_time'] ? date('m-d H:i', $val['user_select_time']) : '';
if (!empty($val['vid'])) {
$val['vipInfo'] = $VipModel->getFind(["id" => $val['vid']], "nickname,name,balance,mobile_phone,integral");
}
//商城订单返回数据
if ($line == 2) {
if ($val['order_genre'] == 4) {
if ($val['advance_type'] == 2) {
//定金
$val['earnest_pay_time'] = date('Y-m-d H:i:s', $val['earnest_pay_time']);
$val['all_earnest_price'] = round($val['all_earnest_price'], 2);
$val['all_arrive_price'] = $val['all_arrive_price'] ? round($val['all_arrive_price']) : '';
$val['tail_pay_money'] = round($val['all_money'] - $val['all_earnest_price'], 2); //尾款
$val['advance_type_name'] = "定金 + 尾款";
} else {
//全额
$val['tail_pay_money'] = round($val['all_money'], 2);
$val['finish_time'] = date('Y-m-d H:i:s', $val['finish_time']);
$val['advance_type_name'] = "全额";
}
if ($val['state'] == 2) {
$tail_time = $PayOrderModel->getFindField(['id' => $val['tail_pay_order_id']], "trade_date");
$val['trade_date'] = date('Y-m-d H:i:s', $tail_time);
}
}
switch ($val['delivery_type']) {
case 1:
//门店配送
if ($val['status'] == 1 && $val['pickup_type'] == 2) {
$val['order_status'] = 0;
}
break;
case 2:
//达达配送
$clerkInfo = $DaOrderModel->getOrderFind(['order_no' => strval($val['order_no']), 'id' => $val['delivery_record_id']], '*', 'id desc');
$val['order_status'] = $clerkInfo['order_status'];
break;
case 3:
//Uu配送转成达达订单状态显示
$state_uu = $uuOrderModel->getOrderFindField(['origin_id' => $val['id'], 'id' => $val['delivery_record_id']], 'state', 'id desc');
if ($state_uu == 1) {
$val['order_status'] = 1;
} else if ($state_uu == 3 || $state_uu == 4) {
$val['order_status'] = 2;
} else if ($state_uu == 5 || $state_uu == 6) {
$val['order_status'] = 3;
} else if ($state_uu == -1) {
$val['order_status'] = 5;
} else {
$val['order_status'] = 4;
}
$val['delivery'] = 2;
break;
case 5:
//码科配送
$MakeOrderModel = new MakeOrderModel();
$status = $MakeOrderModel->getOrderFindField(['bill_id' => $val['id']], "status", "id desc");
switch ($status) {
case 'payed':
//待接单
$val['order_status'] = 1;
break;
case 'accepted':
//'待取件
$val['order_status'] = 2;
break;
case 'geted':
//待收件
$val['order_status'] = 3;
break;
case 'gotoed':
//待评价
$val['order_status'] = 4;
break;
case 'completed':
//订单已完成
$val['order_status'] = 4;
break;
case 'cancel':
//已取消
$val['order_status'] = 5;
break;
}
break;
}
if ($val['type'] == 1) {
//商城
if ($val['pickup_type'] == 2) {
if ($val['user_address']) {
$val['address_name'] = $val['user_name'];
$val['address_phone'] = $val['user_phone'];
$val['address_address'] = $val['user_address'];
}
} else {
$val['address_name'] = $val['user_name'];
$val['address_phone'] = $val['user_phone'];
}
}
switch ($val['status']) {
case 0:
if ($val['order_genre'] == 4 && $val['pay_state'] == 2) {
if ($val['cancel_time'] > 0) {
$val['state_name'] = '已申请售后';
} else if ($val['tail_end_time'] < time()) {
$val['state_name'] = '超出尾款支付时间';
} else if ($val['tail_start_time'] > time()) {
$val['state_name'] = '未到尾款支付时间';
} else {
$val['state_name'] = '待付尾款';
}
}
break;
case 1:
if ($val['refund_status'] == 0) {
$val['state_name'] = '待发货';
if ($val["pickup_type"] == 1) {
$val['state_name'] = '待自取';
}
} else if ($val["refund_status"] == 1) {
$val['state_name'] = '已申请售后';
}
break;
case 2:
$val['state_name'] = '待收货';
break;
case 3:
$val['state_name'] = '交易完成';
if ($val["refund_status"] == 1) {
$val['state_name'] = '已申请售后';
}
break;
}
}
if (!empty($val['cashier_id'])) {
$cashier_info = $CashierModel->getFind(['id' => $val['cashier_id']], "name,jobnum");
$val['jobnum'] = $cashier_info['jobnum'];
$val['cashier_name'] = $cashier_info['name'];
}
$val['key'] = $key + 1;
//判断支付人员类型
if (!empty($val['vid'])) {
$val['vip_class'] = '会员';
} else {
$val['vip_class'] = '散客';
}
if ($val['order_genre'] == 4) {
$val['payList'] = $BillAdvanceModel->payMode($val);
} else {
$val['payList'] = getPayTypeList($val['pay_type'], $val['all_money'], $val['id']);
}
if ((int)$val['pay_type'] == 7 && isset($val['payList'][0]['name'])) {
$val['pay_type_name'] = $val['payList'][0]['name'];//其他支付名称
}
$fields = array(
'vip_discount',
'goods_id',
'goods_name',
'num',
'refund_num',
'vip_price',
'price',
'plus_vip_price',
'original_price',
'all_money',
'goods_type',
'attribute_state',
'sku_json_info',
'pricing_method',
'integral_marketing',
'mem_integral',
'use_integral',
'cashier_manual_discount',
'cashier_manual_discount_money',
"company",
"goods_gifts_id",
"goods_gifts_type",
'serial_number_state',
'id',
'code_price_state',
);
$sellList = $SellModel->getSelect(['bill_id' => $val['id']], $fields);
$beforeAllMoney = 0;
$v_discount = 1;
$cashier_manual_discount = 1;
$GoodsModel = new RetailGoodsModel();
foreach ($sellList as &$v) {
if (($v['goods_type'] == 2 || $v['goods_id'] == 0) && empty($v['goods_name'])) {
$v['goods_name'] = '无码商品';
}
$v['goods_code'] = '';
if ($v['goods_type'] == 1) {
$v['goods_code'] = $GoodsModel->getFindField(['id' => $v['goods_id']], 'goods_code');
}
if (!empty($v['sku_json_info'])) {
$sku = json_decode($v['sku_json_info'], true);
$v['sku_name'] = $sku['name'];
if (!$v['sku_name']) {
$sku_name = $SkuAttribute->basisSkuIdListSkuNameArr($sku['sku_id_list']);
$v['sku_name'] = implode(',', $sku_name);
}
$v['sku_id'] = $sku['id'];
}
$v['num'] = round($v['num'], 3);
if (floatval($v['vip_discount']) < 1 && floatval($v['vip_discount']) > 0) {
$v_discount = floatval($v['vip_discount']);
}
if (floatval($v['cashier_manual_discount']) < 1 && floatval($v['cashier_manual_discount_money']) > 0) {
$cashier_manual_discount = floatval($v['cashier_manual_discount']);
}
$v['mem_integral'] = intval($v['mem_integral']);
$v['price'] = floatval($v['price']);
$v['original_price'] = floatval($v['original_price']);
$v['plus_vip_price'] = floatval($v['plus_vip_price']);
$v['vip_price'] = floatval($v['vip_price']);
$v['before_all_money'] = round($v['price'] * $v['num'], 2);
$beforeAllMoney += $v['before_all_money'];
//串号信息
if ($v['serial_number_state'] == 1) {
$serialResult = $SerialClass->sellSerialList([
'id' => $v['id']
]);
$v['serial_list'] = $serialResult['data']['list'];
}
}
$val['v_discount'] = $v_discount;
$val['cashier_manual_discount'] = $cashier_manual_discount;
$val['beforeAllMoney'] = $beforeAllMoney;
$val['goods_info'] = $sellList;
//配送
$val['add_time'] = date('m-d H:i:s', $val['add_time']);
$val['cashier_dis_money'] = !empty($val['cashier_dis_money']) ? $val['cashier_dis_money'] : 0;
//优惠金额
$val['discount_amount'] = round($val['coupon_money'] + $val['vip_dis_money'] + $val['cashier_dis_money'] + $val['small_changes_money'] + $val['cashier_manual_money'], 2);
$val['pay_coupon_fee'] = $val['pay_coupon_fee'] > 0 ? floatval($val['pay_coupon_fee']) : 0;
$guide_name = '';
if (!empty($val['guide_id'])) {
$guide_name = $GuideModel->getFindField(['id' => $val['guide_id']], 'guidename');
}
$val['guide_name'] = $guide_name;
unset($val['vid']);
unset($val['store_id']);
unset($val['merchant_id']);
unset($val['cashier_id']);
if ($storePlugStatus === true) {
//门店有权限,并开启插件,查询订单是否有祝福码
$extractionCode = new Index();
$val['extraction_code'] = $extractionCode->obtainExtractionCode($val['id']);//祝福码
} else {
//门店无权限,或没开启
$val['extraction_code'] = null;
}
}
} else {
$order = [];
}
$res['status'] = 1;
$res['order'] = $order;
$res['count'] = $order_count;
$this->ajaxReturn($res);
}
/**
* 获取商城流水合计 2020-10-14
* param [
* order_number 订单号搜索
* vip_code 会员订单搜索
* judge 线上用 1订单号 2提货码
* start_time 起始时间
* end_time 结束时间
* line 1线下订单 2线上订单
* status 类型查询条件
* order_genre 线上订单类型 1商城 2拼团 3秒杀 4预售
* pay_type 支付方式 1微信 2支付宝 3现金 4余额
* bill_type 订单类型 1普通订单 2赊账订单
* credit_type 选择赊账状态 1未还清 2已还清
* ]
*/
public function orderOfWaterTotal()
{
$OrderWater = new \CashierApi\Business\OrderWater();
$param['order_num'] = I('post.order_number');
$param['vipCode'] = I('post.vip_code');
$param['judge'] = I('post.judge') ? I('post.judge') : 1;
$param['start_time'] = I('post.start_time');
$param['end_time'] = I('post.end_time');
$param['line'] = I('post.line');
$param['status'] = I('post.status');
$param['pay_type'] = I('post.pay_type');
$param['cashier_id'] = self::$cashier_id;
$param['store_id'] = self::$store_id;
$param['order_genre'] = I('post.order_genre');
$param['bill_type'] = I('post.bill_type'); //订单类型 1普通订单 2赊账订单
$param['credit_type'] = I('post.credit_type'); //选择赊账状态 1未还清 2已还清
$res = $OrderWater->orderOfWaterTotal($param);
$this->ajaxReturn($res);
}
/**
* 获取商城流水列表 2020-10-14
* param [
* page 页码
* num 页长
* order_number 订单号搜索
* vip_code 会员订单搜索
* judge 线上用 1订单号 2提货码
* start_time 起始时间
* end_time 结束时间
* line 1线下订单 2线上订单
* status 类型查询条件
* order_genre 线上订单类型 1商城 2拼团 3秒杀 4预售
* pay_type 支付方式 1微信 2支付宝 3现金 4余额
* bill_type 订单类型 1普通订单 2赊账订单
* credit_type 选择赊账状态 1未还清 2已还清
* ]
*/
public function orderOfWaterList()
{
$OrderWater = new \CashierApi\Business\OrderWater();
$param['num'] = I('post.num');
$param['line'] = I('post.line');
$param['page'] = I('post.page');
$param['start_time'] = I('post.start_time');
$param['end_time'] = I('post.end_time');
$param['judge'] = I('post.judge') ? I('post.judge') : 1;
$param['status'] = I('post.status');
$param['vipCode'] = I('post.vip_code');
$param['pay_type'] = I('post.pay_type');
$param['store_id'] = self::$store_id;
$param['merchant_id'] = self::$merchant_id;
$param['order_num'] = I('post.order_number');
$param['cashier_id'] = self::$cashier_id;
$param['order_genre'] = I('post.order_genre');
$param['bill_type'] = I('post.bill_type'); //订单类型 1普通订单 2赊账订单
$param['credit_type'] = I('post.credit_type'); //选择赊账状态 1未还清 2已还清
$res = $OrderWater->orderOfWaterList($param);
$this->ajaxReturn($res);
}
/**
* 2019-6-22 打印订单接口
*/
public function printOrder_v1()
{
$order_no = I('post.order_no'); //支付完成返回的order_id
if (empty($order_no)) {
$result['status'] = 0;
$result['msg'] = '缺少必要参数order_no';
$this->ajaxReturn($result);
}
$merchant_id = self::$merchant_id; //商户id
$store_id = self::$store_id; //门店id
$BillModel = new RetailBillOrderModel();
$map = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'order_no' => strval($order_no),
);
$billOrder = $BillModel->getFind($map);
if ($billOrder) {
//根据售卖表查询订单信息
$SellModel = new RetailSellModel();
$map = array(
'bill_id' => $billOrder['id']
);
$fields = array(
'original_price', //原单价
'price', //购买身份价格
'vip_price', //会员价
'plus_vip_price', //plus会员价
'vip_discount', //会员折扣值
'num', //购买数量
'vid', //会员id0
'all_money', //总价
'goods_name', //商品名称
'pricing_method', //计价类型
'goods_type', //商品类型
'sku_json_info', //规格详情
'mem_integral', //购买单个商品所需的积分
'integral_marketing', //积分营销 1基于订单 2基于商品
'integral_dis_money', //积分抵扣的金额或者抵扣积分的金额
'use_integral', //会员卡买单消费积分
'cashier_manual_discount', // 收银员手动折扣: 1为不打折
'cashier_manual_discount_money', // 收银员单品打折优惠金额
'company',
'goods_gifts_id',
// 'business_remark',
'goods_gifts_type',
'code_price_state',
);
$sellOrder = $SellModel->getSelect($map, $fields);
$beforeAllMoney = 0;
$v_discount = 1;
//查询会员信息
if ($billOrder['vid']) {
$VipModel = new RetailVipModel();
$map = array(
'id' => $billOrder['vid']
);
$fields = array(
'mobile_phone', //手机号
'balance', //余额
'card_key', //实体卡号
'integral', //积分
'name', //姓名
'nickname', //昵称
'plus_type' //会员类型
);
$vipInfo = $VipModel->getFind($map, $fields);
$name = $vipInfo['name'] ? $vipInfo['name'] : $vipInfo['nickname'];
$phone = $vipInfo['mobile_phone'] ? $vipInfo['mobile_phone'] : $vipInfo['card_key'];
// 获取打印配置--store_config--mobile_set
$StoreConfigModel = new StoreConfigModel();
$mobile_set = $StoreConfigModel->getFindField(['store_id' => $store_id], 'mobile_set');
if ($mobile_set['mobile_set'] == 1) { // 需要隐藏手机号
$phone = substr($phone, 0, 3) . "****" . substr($phone, -(strlen($phone) - 7));
}
if (!$name) {
$name = '未设置名称';
}
$vip = array(
'phone' => $phone,
'mobile_phone' => $phone,
'name' => $name,
'balance' => $vipInfo['balance'],
'integral' => $vipInfo['integral'] ? $vipInfo['integral'] : '0',
'plus_type' => $vipInfo['plus_type']
);
} else if ($billOrder['third_vip_code']) {
$response['mec_vip'] = [
'name' => $billOrder['third_vip_name'],
'code' => $billOrder['third_vip_code'],
];
} else {
$vip = array(
'phone' => '',
'mobile_phone' => '',
'name' => '',
'balance' => '',
'integral' => '0',
'plus_type' => ''
);
}
$guide_name = '';
if (!empty($billOrder['guide_id'])) {
$GuideModel = new RetailGuideModel();
$guide_name = $GuideModel->getFindField(array('id' => $billOrder['guide_id']), $GuideModel::NAME);
}
$BillDiscountModel = new RetailBillDiscountModel();
$billDiscount = $BillDiscountModel->getFind(array('bill_id' => $billOrder['id']));
$CashierModel = new RetailCashierModel();
$StoreModel = new RetailStoreModel();
$response['job_num'] = self::$cashier[$CashierModel::JOB_NUM]; //收银员工号
$response['store_name'] = self::$store[$StoreModel::STORE_NAME]; //门店名称
$response['all_money'] = floatval($billOrder['all_money']); //订单最终价格
$response['coupon_money'] = floatval($billDiscount['coupon_money']); //优惠券金额
$response['vip_dis_money'] = floatval($billDiscount['vip_dis_money']); //会员打折金额
$response['small_changes_money'] = floatval($billDiscount['small_changes_money']); //抹零金额
$response['discount'] = floatval($billDiscount['discount']); //收银员折扣值
$response['cashier_dis_money'] = floatval($billDiscount['cashier_dis_money']); //收银员打折金额
$response['integral_dis_money'] = floatval($billDiscount['integral_dis_money']); //积分抵扣金额
$response['use_integral'] = floatval($billDiscount['use_integral']); //积分抵扣的总积分
$response['vip_less_money'] = floatval($billDiscount['vip_less_money']); //会员价优惠的金额
$response['integral_marketing'] = $billDiscount['integral_marketing']; //1基于订单 2基于商品
$response['money_dis_integral'] = $billDiscount['money_dis_integral']; //金额抵扣积分数
$response['cashier_manual_money'] = $billDiscount['cashier_manual_money']; // 单品打折优惠金额
$response['pay_coupon_fee'] = floatval($billDiscount['pay_coupon_fee']); //代金券金额 // 单品打折优惠金额
$response['amount_received'] = floatval($billOrder['amount_received']); //实收金额
$response['give_change'] = floatval($billOrder['give_change']); //找零金额
$response['zero_storage'] = floatval($billOrder['zero_storage']); //存零金额
$response['add_time'] = date('Y/m/d H:i:s', $billOrder['add_time']); //下单时间
$response['finish_time'] = $billOrder['finish_time'] ? date('Y/m/d H:i:s', $billOrder['finish_time']) : ''; //支付完成时间
$response['order_type'] = $billOrder['type'] == 2 ? '店内订单' : '商城订单';
$response['print_time'] = date('Y/m/d H:i:s', time()); //打印时间
$response['print_number'] = (int)$billOrder['print_number']; // 订单编号--2020/08/12 新增
$response['order_no'] = $order_no; //订单编号
$response['guide_name'] = $guide_name; //导购员姓名
$response['type'] = $billOrder['type']; //1线上 2线下
$response['business_remark'] = $billOrder['business_remark']; //备注
$response['pay_type'] = $billOrder['pay_type']; // 支付类型 1现金 2银行卡 3微信 4支付宝 5会员余额 6小程序微信 7其他 8组合
$BillAdvanceModel = new RetailBillAdvanceModel();
if ($billOrder['type'] == 1) {
$OnlineModel = new RetailBillOnlineModel();
$fields = array(
'user_name',
'user_phone',
'user_address',
'pickup_type', //1自提 2配送 3快递发货
'delivery_fee', //自提或者配送时用户选择的时间
'user_select_time', //自提或者配送时用户选择的时间
'order_genre',
'remark'
);
$online = $OnlineModel->getFind(array('bill_id' => $billOrder['id']), $fields);
if ($online['order_genre'] == 4) {
$advance_order = $BillAdvanceModel->getFind(array('bill_id' => $billOrder['id']));
if ($advance_order['advance_type'] == 2) {
//定金
$response['earnest_pay_time'] = date('Y-m-d H:i:s', $advance_order['earnest_pay_time']);
$response['all_earnest_price'] = round($advance_order['all_earnest_price'], 2);
if ($advance_order['state'] == 1) {
$response['tail_pay_money'] = '——';
}
$response['all_arrive_price'] = $advance_order['all_arrive_price'] ? round($advance_order['all_arrive_price']) : '';
$response['tail_pay_money'] = round($billOrder['all_money'] - $advance_order['all_earnest_price'], 2); //尾款
$response['advance_type_name'] = "定金 + 尾款";
} else {
//全额
$response['tail_pay_money'] = round($billOrder['all_money'], 2);
$response['advance_type_name'] = "全额";
}
if ($advance_order['state'] == 2) {
$tail_time = D("RetailPayOrder")->getFindField(array('id' => $advance_order['tail_pay_order_id']), "trade_date");
$response['trade_date'] = date('Y-m-d H:i:s', $tail_time);
}
$response['advance_type'] = $advance_order['advance_type'];
$response['state'] = $advance_order['state'];
}
switch ($online['pickup_type']) {
case 1:
$response['pickup_name'] = "自提";
break;
case 2:
$response['pickup_name'] = "商家配送";
break;
case 3:
$response['pickup_name'] = "快递发货";
break;
}
$response['pickup_type'] = $online['pickup_type'];
$response['remark'] = $online['remark'] ? $online['remark'] : '';
$response['order_genre'] = $online['order_genre'];
$response['user_name'] = $online['user_name'];
$response['user_phone'] = $online['user_phone'];
$response['user_address'] = $online['user_address'] ? $online['user_address'] : '自提';
$response['delivery_fee'] = floatval($online['delivery_fee']);
$response['user_select_time'] = $online['user_select_time'] ? date('m-d H:i', $online['user_select_time']) : '';
}
foreach ($sellOrder as &$val) {
if ($val['goods_type'] == 2 && empty($val['goods_name'])) {
$val['goods_name'] = '无码商品';
}
if (!empty($val['sku_json_info'])) {
$val['sku_name'] = json_decode($val['sku_json_info'], true)['name'];
} else {
$val['sku_name'] = '';
}
if (floatval($val['vip_discount']) < 1 && floatval($val['vip_discount']) > 0) {
$v_discount = floatval($val['vip_discount']);
}
unset($val['sku_json_info']);
$val['vip_discount'] = floatval($val['vip_discount']);
$val['num'] = floatval($val['num']);
$val['price'] = floatval($val['price']);
$val['plus_vip_price'] = floatval($val['plus_vip_price']);
$val['vip_price'] = floatval($val['vip_price']);
if ($val['code_price_state'] == 0) {
$val['before_all_money'] = round($val['price'] * $val['num'], 2); //优惠之前的总价
} else {
//总价+会员折扣优惠的金额+收银员单品打折的金额+收银员整单折扣的金额+优惠券优惠的金额+抹零的金额+积分抵扣的金额
$val['before_all_money'] = round($val['all_money'] + $val['vip_dis_money'] + $val['cashier_manual_discount_money'] + $val['cashier_dis_money'] + $val['coupon_money'] + $val['small_changes_money'] + ($val['integral_marketing'] == 1 ? $val['integral_dis_money'] : 0), 2);
}
$beforeAllMoney += $val['before_all_money'];
}
$vip['discount'] = $v_discount;
$response['vipInfo'] = $vip; //会员详情
$response['v_discount'] = $v_discount;
$response['goods'] = $sellOrder; //商品详情
$response['goods_info'] = $sellOrder; //商品详情
$response['beforeAllMoney'] = $beforeAllMoney; //优惠打折之前的总价
if ($billOrder['type'] == 1 && $online['order_genre'] == 4) {
$payList = $BillAdvanceModel->payMode($advance_order);
} else {
$payList = getPayTypeList($billOrder['pay_type'], $billOrder['all_money'], $billOrder['id']);
}
if (!empty($billOrder["cashier_id"])) {
$cashier_info = $CashierModel->getFind(array($CashierModel::ID => $val[$BillModel::CASHIER_ID]), "name,jobnum");
$response['cashier_name'] = $cashier_info['name'];
}
$response['payList'] = $payList; //支付类型
$res['status'] = 1;
$res['msg'] = "查询成功";
$res['data'] = $response;
} else {
$res['status'] = 0;
$res['msg'] = "没有订单信息";
}
$this->ajaxReturn($res);
}
/**
* wifi打印订单
*/
public function wifiPrint_v1()
{
$bill_id = I('post.id');
if (empty($bill_id)) {
$res['status'] = 0;
$res['msg'] = "缺少参数id";
$this->ajaxReturn($res);
}
$PrinterApi = new PrinterController();
$PrinterApi->linePrinting_v1(self::$store_id, $bill_id, true);
}
/**
* 2019-7-15
* 商城订单自提
*/
public function selfMention_v1()
{
$order_no = I('post.order_no'); //订单编号
$pick_code = I('post.pick_code'); //订单手机号(提货验证)
if (empty($order_no) || empty($pick_code)) {
$res['status'] = 0;
$res['msg'] = "缺少参数";
$this->ajaxReturn($res);
}
$cashier_id = self::$cashier_id;
$store_id = self::$store_id;
//查询该订单
$BillModel = D('RetailBillOrder');
$bMap = array(
$BillModel::ORDER_NO => strval($order_no),
$BillModel::STORE_ID => $store_id,
$BillModel::PAY_STATE => 1, //支付成功
$BillModel::TYPE => 1, //商城订单
$BillModel::ORDER_TYPE => 1, //购买订单
);
$billOrder = $BillModel->getFind($bMap); //主订单
if (empty($billOrder)) {
$result['status'] = 0;
$result['msg'] = '暂未查询到该订单';
$this->ajaxReturn($result);
}
$OnlineModel = D('RetailBillOnline');
$oMap = array(
$OnlineModel::BILL_ID => $billOrder[$BillModel::ID]
);
$onlineOrder = $OnlineModel->getFind($oMap); //线上订单
if (empty($onlineOrder)) {
$result['status'] = 0;
$result['msg'] = '数据库操作有误';
$this->ajaxReturn($result);
}
if ($onlineOrder[$OnlineModel::ORDER_GENRE] == 2) {
//拼团订单
$BillGroupModel = D('RetailBillGroup');
$state = $BillGroupModel->getFindField(array($BillGroupModel::BILL_ID => $billOrder[$BillModel::ID]), $BillGroupModel::STATE);
if ($state != 2) {
$result['status'] = 0;
$result['msg'] = '该订单未拼团成功,不能进行配送';
$this->ajaxReturn($result);
}
}
if ($onlineOrder[$OnlineModel::STATUS] != 1) {
$result['status'] = 0;
$result['msg'] = '订单已提货,请勿重复操作';
$this->ajaxReturn($result);
}
if ($billOrder[$BillModel::REFUND_STATUS] == 1) {
$result['status'] = 0;
$result['msg'] = '该订单存在退款申请,请先处理';
$this->ajaxReturn($result);
}
if ($pick_code != $onlineOrder[$OnlineModel::PICK_CODE]) {
$result['status'] = 0;
$result['msg'] = '提货码不正确';
$this->ajaxReturn($result);
}
//商品信息验证
$SellClass = new Sell();
$goodsVerify = $SellClass->distributionGoodsVerify([
'merchant_id' => self::$merchant_id,
'store_id' => $store_id,
'order_id' => $billOrder['id'],
'type' => 1
]);
if ($goodsVerify['status'] != 1) {
$goodsVerify['msg'] = $goodsVerify['message'];
$this->ajaxReturn($goodsVerify);
}
$goods_serial_list = $goodsVerify['data'];
//第三方平台
if (self::$merchant['platform_type'] == 2 && $billOrder['order_type'] == 1) {
$ThirdClass = new Order();
$thirdResult = $ThirdClass->orderExecute([
'merchant_id' => self::$merchant_id,
'third_order' => $billOrder['third_order']
]);
if ($thirdResult['status'] == 0) {
$result['status'] = 0;
$result['msg'] = '第三方发货失败' . $thirdResult['message'];
$this->ajaxReturn($result);
}
}
//出库
if (!empty($goods_serial_list)) {
$SerialClass = new SerialNumberGoods();
$SerialClass->basisNumberOperation([
'store_id' => $store_id,
'goods_list' => $goods_serial_list,
'type' => 2
]);
//出库记录新增
$sell_id_arr = array_column($goods_serial_list, 'id');
if (!empty($sell_id_arr)) {
$StockRecordClass = new StockRecord();
$outsideResult = $StockRecordClass->basisSellStockRecord([
'store_id' => $store_id,
'sell_id' => $sell_id_arr
]);
$outside_id_arr = $outsideResult['data'];
if (!empty($outside_id_arr)) {
$new_outside_id_arr = array_column($outside_id_arr, null, 'stock_out_id');
$order_genre = $OnlineModel->getFindField([
"bill_id" => $billOrder['id'],
], 'order_genre');
switch ($order_genre) {
case 1:
$stock_type = 8;
break;
case 2:
$stock_type = 4;
break;
case 3:
$stock_type = 5;
break;
case 4:
$stock_type = 11;
break;
}
foreach ($goods_serial_list as $val) {
if ($val['serial_number_state'] == 1 && !empty($val['serial_list'])) {
$SerialClass->stockSerial([
'user_type' => 4,
'merchant_id' => self::$merchant_id,
'store_id' => $store_id,
'outside_id' => $new_outside_id_arr[$val['id']]['id'],
'type' => $stock_type,
'goods_id' => $val['goods_id'],
'sku_id' => $val['sku_id'] ? $val['sku_id'] : 0,
'serial_list' => $val['serial_list']
]);
}
}
}
}
}
//通过订单编号修改订单状态及自提状态
$time = time();
$bSave = array(
$BillModel::FINISH_TIME => $time,
$BillModel::CASHIER_ID => $cashier_id
);
$bUpdate = $BillModel->updateOrder($bMap, $bSave);
$plugClass = new Plug();
//订单信息,判断该门店是否,有,并且开启,祝福语插件
$storePlugStatusPost = [
'store_id' => $billOrder[$BillModel::STORE_ID],
'identification_arr' => ['blessing'],
];
$storePlugStatus = $plugClass->plugStoreStatus($storePlugStatusPost);//获取状态
if ($bUpdate) {
$oSave = array(
$OnlineModel::STATUS => 3,
$OnlineModel::PICK_CODE => '',
$OnlineModel::RECEIVING_TIME => $time,
);
$oUpdate = $OnlineModel->updateOrder($oMap, $oSave);
if ($oUpdate) {
if ($storePlugStatus === true) {
//有权限,可以修改有效期
$index = new Index();
$index->validityTimeSave($billOrder[$BillModel::ID], 2);//修改有效期:$type == 1:首次扫码(id = 门店id),2:确认订单(id = 订单id)
}
$result['status'] = 1;
$result['msg'] = '提货成功';
} else {
$BillModel->updateOrder($bMap, array($BillModel::FINISH_TIME => '', $BillModel::CASHIER_ID => null));
$result['status'] = 0;
$result['msg'] = '提货失败,请重试';
}
} else {
$result['status'] = 0;
$result['msg'] = '提货失败,请重试1';
}
$this->ajaxReturn($result);
}
//获取码科跑腿配送费
public function getMakeDeliveryPrice()
{
$data = array(
'order_no' => I("post.order_no"),
'merchant_id' => self::$merchant_id,
'store_id' => self::$store_id
);
$MakeClass = new Make();
$result = $MakeClass->getDeliveryPrice($data);
$this->ajaxReturn($result);
}
/**
* 获取UU配送费和距离
*/
public function getUuDeliveryPrice()
{
$data = array(
'order_no' => I("post.order_no"),
'merchant_id' => self::$merchant_id,
'store_id' => self::$store_id,
'store' => self::$store
);
$res = A("Api/Delivery")->getUuDeliveryPrice($data);
$this->ajaxReturn($res);
}
/**
* 配送 2020/3/18
* type 配送类型 1商家配送 2达达配送 3UU配送
* order_no 订单号
* option_type 1收银端 2后台操作
* uu_phone 收银员手机号或者门店手机号
* special_type 特殊处理类型,是否需要保温箱 1需要 0不需要
* note 备注
*/
public function deliveryOrder_v1()
{
$uu_phone = I('post.uu_phone');
$special_type = I('post.special_type') ? I('post.special_type') : 0;
$note = I('post.note');
if (empty($uu_phone)) {
$CashierModel = D('RetailCashier');
$uu_phone = self::$cashier[$CashierModel::MOBILE];
}
$data = array(
'option_type' => 1,
'merchant_id' => self::$merchant_id,
'store_id' => self::$store_id,
'cashier_id' => self::$cashier_id,
'cashier' => self::$cashier,
'store' => self::$store,
'order_no' => I('post.order_no'),
'type' => I('post.type'),
'uu_phone' => $uu_phone,
'special_type' => $special_type,
'note' => $note,
'platform_type' => self::$merchant['platform_type'] ? self::$merchant['platform_type'] : 1
);
if (C("IS_SET_REDIS")) {
$ApiRedis = new \Addons\Api\RedisController();
$redis_key = "customer_" . $data['order_no'];
if ($ApiRedis::$redis->exists($redis_key)) {
$res['status'] = 0;
$res['msg'] = "正在操作该订单,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($redis_key, 10, $data['order_no']);
}
$res = A("Api/Delivery")->deliveryOrder($data);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($redis_key);
}
$this->ajaxReturn($res);
}
//串号商品查询
public function searchSerial()
{
$data = I('post.');
$data['user_type'] = 4;
$data['merchant_id'] = self::$merchant_id;
$data['store_id'] = self::$store_id;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->searchWarehouseSerial($data);
$this->ajaxReturn($result);
}
//配送前确认商品信息confirmDistributionGoods
public function confirmDistributionGoods()
{
$data = I('post.');
$data['merchant_id'] = self::$merchant_id;
$data['store_id'] = self::$store_id;
$data['type'] = 1;
$SellClass = new Sell();
$result = $SellClass->confirmSellGoods($data);
$this->ajaxReturn($result);
}
/**
* 配送 2020/3/18
* type 配送类型 1商家配送 2达达配送 3UU配送 5码科配送
* order_no 订单号
* option_type 1收银端 2后台操作
* uu_phone 收银员手机号或者门店手机号
* special_type 特殊处理类型,是否需要保温箱 1需要 0不需要
* note 备注
* total_price 配送价格
* distance 距离
*/
public function deliveryOrder_v2()
{
$data = I('post.');
$data['platform_type'] = self::$merchant['platform_type'] ? self::$merchant['platform_type'] : 1;
$data['option_type'] = 1;
$data['merchant_id'] = self::$merchant_id;
$data['store_id'] = self::$store_id;
$data['cashier_id'] = self::$cashier_id;
$data['cashier'] = self::$cashier;
$data['store'] = self::$store;
$data['special_type'] = $data['special_type'] ? $data['special_type'] : 0;
$data['total_price'] = $data['total_price'] ? $data['total_price'] : 0;
$data['distance'] = $data['distance'] ? $data['distance'] : '';
if (C("IS_SET_REDIS")) {
$ApiRedis = new \Addons\Api\RedisController();
$redis_key = "customer_" . $data['order_no'];
if ($ApiRedis::$redis->exists($redis_key)) {
$res['status'] = 0;
$res['msg'] = "正在操作该订单,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($redis_key, 10, $data['order_no']);
}
$res = A("Api/Delivery")->deliveryOrder($data);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($redis_key);
}
$this->ajaxReturn($res);
}
/**
* 取消配送2020/3/18
* order_no 订单号
* reason //UU取消配送原因
* reason_id //达达取消配送原因id
*/
public function cancelDelivery_v1()
{
$data = array(
"order_no" => I('post.order_no'),
"reason" => I('post.reason'),
"reason_id" => I('post.reason_id'),
"merchant_id" => self::$merchant_id,
"store_id" => self::$store_id,
);
if (C("IS_SET_REDIS")) {
$ApiRedis = new \Addons\Api\RedisController();
$redis_key = "customer_" . $data['order_no'];
if ($ApiRedis::$redis->exists($redis_key)) {
$res['status'] = 0;
$res['msg'] = "正在操作该订单,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($redis_key, 10, $data['order_no']);
}
$res = A("Api/Delivery")->cancelDelivery($data);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($redis_key);
}
$this->ajaxReturn($res);
}
//串号修改
public function serialModify()
{
$data = I('post.');
$data['user_type'] = 6;
$data['operator_type'] = 2;
$data['merchant_id'] = self::$merchant_id;
$data['store_id'] = self::$store_id;
$data['cashier_id'] = self::$cashier_id;
$data['operator_id'] = self::$cashier_id;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->serialModify($data);
$this->ajaxReturn($result);
}
//串号修改记录
public function serialModifyRecord()
{
$data = I('post.');
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->serialModifyRecord($data);
$this->ajaxReturn($result);
}
/**
* 取消配送2020/3/18
* order_no 订单号
* reason //UU取消配送原因
* reason_id //达达取消配送原因id
*/
public function cancelDelivery_v2()
{
$data = array(
"order_no" => I('post.order_no'),
"reason" => I('post.reason'),
"reason_id" => I('post.reason_id'),
"merchant_id" => self::$merchant_id,
"store_id" => self::$store_id,
);
if (C("IS_SET_REDIS")) {
$ApiRedis = new \Addons\Api\RedisController();
$redis_key = "customer_" . $data['order_no'];
if ($ApiRedis::$redis->exists($redis_key)) {
$res['status'] = 0;
$res['msg'] = "正在操作该订单,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($redis_key, 10, $data['order_no']);
}
$res = A("Api/Delivery")->cancelDelivery($data);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($redis_key);
}
$this->ajaxReturn($res);
}
/**
* 获取达达配送取消订单原因
*/
public function getCancelDeliveryReason_v1()
{
$reason = M('retail_da_reason')->select();
if ($reason) {
$res['status'] = 1;
$res['msg'] = '获取成功';
$res['reason'] = $reason;
} else {
$res['status'] = 0;
$res['msg'] = '暂无数据';
$res['reason'] = array();
}
$this->ajaxReturn($res);
}
/**
* 获取骑手信息
*/
public function getRiderInfo_v1()
{
$order_no = I('post.order_no'); //订单编号
if (empty($order_no)) {
$result['status'] = 0;
$result['msg'] = "缺少参数";
$this->ajaxReturn($result);
}
$result = A('PayApi/Order')->getRider($order_no);
$this->ajaxReturn($result);
}
/**
* 获取门店配置的默认配送方式
*/
public function getDefaultDelivery_v1()
{
$store = self::$store;
$StoreModel = D('RetailStore');
$default_delivery = $store[$StoreModel::DEFAULT_DELIVERY];
$res['status'] = 1;
$res['msg'] = '获取成功';
$res['default_delivery'] = $default_delivery['default_delivery'];
$this->ajaxReturn($res);
}
//收银机核销自提奖品
public function turntableSelfPrizeCode()
{
$post = I('post.'); //接收前端传参 array
$validParams = [
// 'store_id',// 门店ID,
'code', // 核销码
'phone', // 手机号
]; //定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) { //值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']); //返回缺失字段
}
//查询中奖记录
$map = [
'store_id' => self::$store_id,
'phone' => $post['phone'],
'receive_code' => $post['code'],
'status' => 2,
'delivery_status' => 1,
];
$prize_record = D('TurntableUse')->getOrderFind($map);
if (!$prize_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::NO_WIN_PRIZE_RECORD, ResultCodeManager::$messages[ResultCodeManager::NO_WIN_PRIZE_RECORD]));
}
//核销中奖记录
$save_data = [
'delivery_status' => 2
];
D('TurntableUse')->updateOrder(['id' => $prize_record['id']], $save_data);
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS]));
}
//收银机查询自提记录
public function turntableWinRecord()
{
$post = I('post.'); //接收前端传参 array
$validParams = [
// 'store_id',// 门店ID,
'code', // 核销码
'phone', // 手机号
]; //定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) { //值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']); //返回缺失字段
}
//查询中奖记录
$map = [
'store_id' => self::$store_id,
// 'store_id'=>1,
'phone' => $post['phone'],
'receive_code' => $post['code'],
'status' => 2,
'delivery_status' => 1,
];
$prize_record = D('TurntableUse')->getOrderFind($map, 'id,user_id,add_time,receive_time,turntable_prize_id,turntable_id,order_num,username,phone');
if (!$prize_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::NO_WIN_PRIZE_RECORD, ResultCodeManager::$messages[ResultCodeManager::NO_WIN_PRIZE_RECORD]));
}
//查询奖品信息
$prize = D('TurntablePrize')->getOrderFind(['id' => $prize_record['turntable_prize_id']], 'id,prize_name,prize_img,type');
$prize_record['prize_info'] = $prize;
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $prize_record));
}
}