670 行
24 KiB
PHP
可执行文件
670 行
24 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Common\Model;
|
||
|
||
use Think\Model;
|
||
|
||
//[1.8.72]
|
||
|
||
/**
|
||
* 订单主表 ZaiYuLi 2019-6-15
|
||
* Class RetailBillModel
|
||
* @package Common\Model
|
||
*/
|
||
class RetailBillOrderModel extends BaseModel
|
||
{
|
||
protected $tableName = 'retail_bill_order';
|
||
const ID = 'id'; //int(11) DEFAULT NULL COMMENT 'id',
|
||
const ALL_MONEY = 'all_money'; //decimal(10,2) DEFAULT NULL COMMENT '总价',
|
||
const PAY_STATE = 'pay_state'; //tinyint(1) DEFAULT '0' COMMENT '0未支付 1已支付 2待支付(确认订单)',
|
||
const PAY_TYPE = 'pay_type'; //tinyint(1) DEFAULT '0' COMMENT '支付类型 1现金 2银行卡 3微信支付 4支付宝支付 5会员卡余额支付 6小程序商城微信支付 7其他支付方式 8组合支付',
|
||
const REFUND_STATUS = 'refund_status'; //tinyint(1) DEFAULT '0' COMMENT '主要判断商品退款 0正常买单1申请退款或换货2退款或换货成功3换货中、待用户发货 4用户已发货、待商家收货 5商家已收货、待商家发货或待商家退款 6驳回退款或换货 7取消退款换货
|
||
const TYPE = 'type'; //tinyint(1) DEFAULT NULL COMMENT '应用类型 1商城 2店内',
|
||
const ORDER_TYPE = 'order_type'; //tinyint(1) DEFAULT '1' COMMENT '订单类型 默认为1:购买订单 2:退款订单 3:换货订单',
|
||
const ADD_TIME = 'add_time'; //varchar(20) DEFAULT NULL COMMENT '添加时间',
|
||
const VID = 'vid'; //int(11) DEFAULT NULL COMMENT '会员id',
|
||
const STORE_ID = 'store_id'; //int(11) DEFAULT NULL COMMENT '门店id',
|
||
const MERCHANT_ID = 'merchant_id'; //int(11) DEFAULT NULL COMMENT '商户id',
|
||
const CASHIER_ID = 'cashier_id'; //int(11) DEFAULT NULL COMMENT '收银员id',
|
||
const GUIDE_ID = 'guide_id'; //int(11) DEFAULT NULL COMMENT '导购员id',
|
||
const ORDER_NO = 'order_no'; //int(11) DEFAULT NULL COMMENT '订单号',
|
||
const UID = 'uid'; //int(11) DEFAULT NULL COMMENT '小程序用户id',
|
||
const REFUND_NO = 'refund_no'; //varchar(32) DEFAULT '0' COMMENT '(属于退款订单) 保存被退款的订单编号',
|
||
const REFUND_MONEY = 'refund_money'; //decimal(11,2) DEFAULT '0.00' COMMENT '退款金额',
|
||
const FINISH_TIME = 'finish_time'; //varchar(20) DEFAULT NULL COMMENT '订单完成时间',
|
||
const AMOUNT_RECEIVED = 'amount_received'; //decimal(11,2) DEFAULT '0.00' COMMENT '实收金额',
|
||
const GIVE_CHANGE = 'give_change'; //decimal(11,2) DEFAULT '0.00' COMMENT '找零金额',
|
||
const ZERO_STORAGE = 'zero_storage'; //decimal(11,2) DEFAULT '0.00' COMMENT '存零金额',
|
||
const PAY_MONEY = 'pay_money'; //decimal(11,2) DEFAULT '0.00' COMMENT '已经支付的金额',
|
||
const UPGRADE_STATE = 'upgrade_state'; //tinyint(1) DEFAULT '0' COMMENT '是否升级为plus会员 0否 1是',
|
||
const DELIVER_STATE = 'deliver_state'; //用户退款换货订单是否需要客户发货 0不需要 1需要
|
||
const EXPRESS_ID = 'express_id'; //快递express_order的id
|
||
const OPERATION_ID = 'operation_id'; //后台操作人id
|
||
const BUSINESS_REMARK = 'business_remark'; //商家订单备注
|
||
const SETTLEMENT_TYPE = 'settlement_type'; //结算方式 1直接结账 2赊账 3部分赊账
|
||
|
||
/**
|
||
* 获取总条数和总金额
|
||
* @param $map
|
||
* @return array
|
||
*/
|
||
public function getOnlineAllData($map)
|
||
{
|
||
$num = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->where($map)
|
||
->count();
|
||
$money = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->where($map)
|
||
->sum($this::ALL_MONEY);
|
||
$res = array(
|
||
'num' => $num,
|
||
'money' => $money
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 获取总条数和总金额 拼团
|
||
* @param $map
|
||
* @return array
|
||
*/
|
||
public function getOnlineGroupAllData($map)
|
||
{
|
||
$num = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_group as g on b.' . $this::ID . '=g.bill_id')
|
||
->where($map)
|
||
->count();
|
||
$money = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_group as g on b.' . $this::ID . '=g.bill_id')
|
||
->where($map)
|
||
->sum($this::ALL_MONEY);
|
||
$res = array(
|
||
'num' => $num,
|
||
'money' => $money
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 获取总条数和总金额 秒杀
|
||
* @param $map
|
||
* @return array
|
||
*/
|
||
public function getOnlineSkillAllData($map)
|
||
{
|
||
$num = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_spike as s on b.' . $this::ID . '=s.bill_id')
|
||
->where($map)
|
||
->count();
|
||
$money = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_spike as s on b.' . $this::ID . '=s.bill_id')
|
||
->where($map)
|
||
->sum($this::ALL_MONEY);
|
||
$res = array(
|
||
'num' => $num,
|
||
'money' => $money
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* @param $where
|
||
* @param $page
|
||
* @param $num
|
||
* @return array
|
||
*/
|
||
public function getAdvanceData($map)
|
||
{
|
||
$num = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_advance as a on b.' . $this::ID . '=a.bill_id')
|
||
->where($map)
|
||
->count();
|
||
$map['state'] = 2; //全部付款
|
||
$money = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_advance as a on b.' . $this::ID . '=a.bill_id')
|
||
->where($map)
|
||
->sum($this::ALL_MONEY);
|
||
$money = $money ? $money : 0;
|
||
$map['state'] = 1; //支付定金
|
||
$all_earnest_price = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_advance as a on b.' . $this::ID . '=a.bill_id')
|
||
->where($map)
|
||
->sum("a.all_earnest_price");
|
||
$all_earnest_price = $all_earnest_price ? $all_earnest_price : 0;
|
||
$money = round($money + $all_earnest_price, 2);
|
||
$res = array(
|
||
'num' => $num,
|
||
'money' => $money
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
//获取收银端线上订单
|
||
public function getOnlineOrder($where, $page, $num)
|
||
{
|
||
$data = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id', 'LEFT')
|
||
->where($where)
|
||
->order($this::ADD_TIME . " desc")
|
||
->page($page . ',' . $num)
|
||
->select();
|
||
$count = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id', 'LEFT')
|
||
->where($where)
|
||
->count();
|
||
$res = array(
|
||
'count' => $count,
|
||
'data' => $data
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
//获取收银端线上订单 拼团
|
||
public function getOnlineGroupOrder($where, $page, $num)
|
||
{
|
||
$data = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_group as g on b.' . $this::ID . '=g.bill_id')
|
||
->where($where)
|
||
->order($this::ADD_TIME . " desc")
|
||
->page($page . ',' . $num)
|
||
->select();
|
||
$count = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_group as g on b.' . $this::ID . '=g.bill_id')
|
||
->where($where)
|
||
->count();
|
||
$res = array(
|
||
'count' => $count,
|
||
'data' => $data
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
//获取收银端线上订单 秒杀
|
||
public function getOnlineSkillOrder($where, $page, $num)
|
||
{
|
||
$data = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_spike as s on b.' . $this::ID . '=s.bill_id')
|
||
->where($where)
|
||
->order($this::ADD_TIME . " desc")
|
||
->page($page . ',' . $num)
|
||
->select();
|
||
$count = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_spike as s on b.' . $this::ID . '=s.bill_id')
|
||
->where($where)
|
||
->count();
|
||
$res = array(
|
||
'count' => $count,
|
||
'data' => $data
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
//获取收银端线上订单 预售
|
||
public function getAdvanceOrder($where, $page, $num)
|
||
{
|
||
$data = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_advance as a on b.' . $this::ID . '=a.bill_id')
|
||
->where($where)
|
||
->order($this::ADD_TIME . " desc")
|
||
->page($page . ',' . $num)
|
||
->select();
|
||
$count = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id', 'LEFT')
|
||
->join('ls_retail_bill_advance as a on b.' . $this::ID . '=a.bill_id')
|
||
->where($where)
|
||
->count();
|
||
$res = array(
|
||
'count' => $count,
|
||
'data' => $data
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
//获取收银端流水订单
|
||
public function getOutlineOrder($where, $page, $num)
|
||
{
|
||
$data = $this->alias('b')
|
||
->where($where)
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id', 'LEFT')
|
||
->order($this::ADD_TIME . " desc")
|
||
->page($page . ',' . $num)
|
||
->select();
|
||
$count = $this->alias('b')
|
||
->where($where)
|
||
->count();
|
||
$res = array(
|
||
'count' => $count,
|
||
'data' => $data
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
//获取收银端流水订单(赊账)
|
||
public function getCreditOutlineOrder($where, $page, $num)
|
||
{
|
||
$data = $this->alias('b')
|
||
->where($where)
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id', 'LEFT')
|
||
->join('ls_retail_credit_arrearage as ca on ca.bill_id = b.id', 'LEFT')
|
||
->field('b.*,d.*')
|
||
->order('b.' . $this::ADD_TIME . " desc")
|
||
->page($page . ',' . $num)
|
||
->select();
|
||
$count = $this->alias('b')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id', 'LEFT')
|
||
->join('ls_retail_credit_arrearage as ca on ca.bill_id = b.id', 'LEFT')
|
||
->where($where)
|
||
->count();
|
||
$res = array(
|
||
'count' => $count,
|
||
'data' => $data
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
//要添加的数据
|
||
public function addBillOrder($item)
|
||
{
|
||
$id = $this->addOrder($item);
|
||
if ($id) {
|
||
$order_no = createOrderTradeNo($id);
|
||
$save = $this->updateOrder(array($this::ID => $id), array($this::ORDER_NO => $order_no));
|
||
if ($save) {
|
||
$item[$this::ID] = $id;
|
||
$item[$this::ORDER_NO] = $order_no;
|
||
return $item;
|
||
} else {
|
||
return false;
|
||
}
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
//获取三表字段sum
|
||
public function getDiscountSum($where = array(), $key)
|
||
{
|
||
$money = $this->alias('b')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->where($where)
|
||
->sum($key);
|
||
return $money;
|
||
}
|
||
|
||
//获取三表count
|
||
public function getBillCount($where = array())
|
||
{
|
||
$count = $this->alias('b')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->where($where)
|
||
->count();
|
||
return $count;
|
||
}
|
||
|
||
//连vip表查询内容 count select
|
||
public function getVipData($where, $page = '', $limit = '')
|
||
{
|
||
if ($page == '') {
|
||
$list = $this->alias('b')
|
||
->join('ls_retail_vip as v on b.' . $this::VID . '=v.id', 'LEFT')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->field('b.*,v.mobile_phone')
|
||
->where($where)
|
||
->order('b.' . $this::ADD_TIME . ' desc')
|
||
->select();
|
||
return $list;
|
||
}
|
||
$count = $this->alias('b')
|
||
->join('ls_retail_vip as v on b.' . $this::VID . '=v.id', 'LEFT')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->where($where)
|
||
->count();
|
||
|
||
$list = $this->alias('b')
|
||
->join('ls_retail_vip as v on b.' . $this::VID . '=v.id', 'LEFT')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->page((int)$page, (int)$limit)
|
||
->field('b.*,o.*,d.*,v.mobile_phone as vip_phone')
|
||
->where($where)
|
||
->order('b.' . $this::ADD_TIME . ' desc')
|
||
->select();
|
||
$res = array(
|
||
'count' => $count,
|
||
'list' => $list
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
//order,online,discount 三表查find
|
||
public function getBillFind($where, $field = array(), $order = '', $page = '')
|
||
{
|
||
if ($page) {
|
||
$res = $this->alias('b')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->field($field)
|
||
->order($order)
|
||
->page($page)
|
||
->where($where)
|
||
->select();
|
||
} else {
|
||
$res = $this->alias('b')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id','LEFT')
|
||
->field($field)
|
||
->order($order)
|
||
->where($where)
|
||
->find();
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 拼团订单联查(find)
|
||
* @param array $map 条件
|
||
* @param array $field 字段 default '*'
|
||
* @return array $find
|
||
*/
|
||
public function getFindGroup($map, $field = '*')
|
||
{
|
||
$find = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_group as g on b.' . $this::ID . '=g.bill_id')
|
||
->field($field)
|
||
->where($map)
|
||
->find();
|
||
return $find;
|
||
}
|
||
|
||
/**
|
||
* 拼团订单联查(select)
|
||
* @param array $map 条件
|
||
* @param array $field 字段 default '*'
|
||
* @param array $order 排序
|
||
* @return array $select
|
||
*/
|
||
public function getSelectGroup($map, $field = '*', $order = 'id asc')
|
||
{
|
||
$select = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_group as g on b.' . $this::ID . '=g.bill_id')
|
||
->field($field)
|
||
->where($map)
|
||
->order($order)
|
||
->select();
|
||
return $select;
|
||
}
|
||
|
||
/**
|
||
* 拼团订单联查,与用户联查(select)
|
||
* @param array $map 条件
|
||
* @param array $field 字段 default '*'
|
||
* @param array $order 排序
|
||
* @return array $select
|
||
*/
|
||
public function getUserSelectGroup($map, $field = '*', $order = 'id asc', $group = '')
|
||
{
|
||
if ($group) {
|
||
$select = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_group as g on b.' . $this::ID . '=g.bill_id')
|
||
->join('ls_retail_xcxvip as x on b.' . $this::UID . '=x.id')
|
||
->field($field)
|
||
->where($map)
|
||
->group($group)
|
||
->order($order)
|
||
->select();
|
||
} else {
|
||
$select = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_group as g on b.' . $this::ID . '=g.bill_id')
|
||
->join('ls_retail_xcxvip as x on b.' . $this::UID . '=x.id')
|
||
->field($field)
|
||
->where($map)
|
||
->order($order)
|
||
->select();
|
||
}
|
||
return $select;
|
||
}
|
||
|
||
/**
|
||
* 统计拼团成员数
|
||
* @param array $map 条件
|
||
* @return int $count
|
||
*/
|
||
public function countGroupUser($map)
|
||
{
|
||
$count = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_group as g on b.' . $this::ID . '=g.bill_id')
|
||
->join('ls_retail_xcxvip as x on b.' . $this::UID . '=x.id')
|
||
->where($map)
|
||
->count();
|
||
return $count;
|
||
}
|
||
|
||
/**
|
||
* 秒杀订单联查(find)
|
||
* @param array $map 条件
|
||
* @param array $field 字段 default '*'
|
||
* @return array $find
|
||
*/
|
||
public function getFindSpike($map, $field = '*')
|
||
{
|
||
$find = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_spike as s on b.' . $this::ID . '=s.bill_id')
|
||
->field($field)
|
||
->where($map)
|
||
->find();
|
||
return $find;
|
||
}
|
||
|
||
/**
|
||
* 秒杀订单联查(select)
|
||
* @param array $map 条件
|
||
* @param array $field 字段 default '*'
|
||
* @param array $order 排序
|
||
* @return array $select
|
||
*/
|
||
public function getSelectSpike($map, $field = '*', $order = 'id asc')
|
||
{
|
||
$select = $this->alias('b')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->join('ls_retail_bill_spike as s on b.' . $this::ID . '=s.bill_id')
|
||
->field($field)
|
||
->where($map)
|
||
->order($order)
|
||
->select();
|
||
return $select;
|
||
}
|
||
|
||
/**
|
||
* 获取bill_order、bill_discount、bill_online三表联查数据
|
||
* @param $map
|
||
* @param $field
|
||
* @param string $order
|
||
* @param null $page
|
||
* @return mixed
|
||
*/
|
||
public function getOrderLinkSelect($map, $field, $order = 'b.id desc', $page = null)
|
||
{
|
||
if (!empty($page)) {
|
||
$list = $this->alias('b')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->field($field)
|
||
->where($map)
|
||
->order($order)
|
||
->page($page)
|
||
->select();
|
||
} else {
|
||
$list = $this->alias('b')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id')
|
||
->field($field)
|
||
->where($map)
|
||
->order($order)
|
||
->select();
|
||
}
|
||
return $list;
|
||
}
|
||
|
||
/**
|
||
* 获取bill_order、bill_discount、bill_online三表联查数据
|
||
* @param $map
|
||
* @param $field
|
||
* @return mixed
|
||
*/
|
||
public function getOrderLinkFind($map, $field = '*')
|
||
{
|
||
$list = $this->alias('b')
|
||
->join('ls_retail_bill_discount as d on b.' . $this::ID . '=d.bill_id')
|
||
->join('ls_retail_bill_online as o on b.' . $this::ID . '=o.bill_id', 'LEFT')
|
||
->field($field)
|
||
->where($map)
|
||
->find();
|
||
return $list;
|
||
}
|
||
|
||
/**
|
||
* 用于配送验证购买或换货订单是否存在
|
||
*/
|
||
public function order_existence_verify($parameter)
|
||
{
|
||
if (is_array($parameter)) {
|
||
if (empty($parameter['order_no']) || empty($parameter['store_id'])) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
return $res;
|
||
}
|
||
$where = array(
|
||
$this::ORDER_NO => strval($parameter['order_no']),
|
||
$this::STORE_ID => $parameter['store_id'],
|
||
$this::PAY_STATE => 1, //支付成功
|
||
$this::TYPE => 1, //商城订单
|
||
$this::ORDER_TYPE => array('in', '1,3'),
|
||
);
|
||
$billOrder = $this->getFind($where);
|
||
if (empty($billOrder)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂未查询到该订单';
|
||
return $res;
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = '验证成功';
|
||
$res['bill_order'] = $billOrder;
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = "验证失败";
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
|
||
/**
|
||
* 生成排序单号
|
||
* @param $id
|
||
* @param $type
|
||
* @param $store_id
|
||
*/
|
||
public function create_print_number($id, $type, $store_id)
|
||
{
|
||
// 1.写入redis
|
||
$endToday = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'));
|
||
|
||
$redis_key = 'retail_print_number_' . $type . '_' . $store_id;
|
||
$ApiRedis = new \Addons\Api\RedisController();
|
||
|
||
// 检查是否已存在,防止重复push导致重复打印
|
||
$wait_print_content = $ApiRedis::$redis->lRange($redis_key, 0, -1);
|
||
if (in_array($id, $wait_print_content)) {
|
||
return;
|
||
}
|
||
|
||
$needTime = $endToday - time();
|
||
$ApiRedis->rPush($redis_key, $id, $needTime);
|
||
|
||
$wait_print_content = $ApiRedis::$redis->lRange($redis_key, 0, -1);
|
||
|
||
$print_number = array_search($id, $wait_print_content);
|
||
$savePrint = array(
|
||
'print_number' => $print_number + 1
|
||
);
|
||
// $ApiRedis::$redis->delete($redis_key);
|
||
$this->updateOrder(array('id' => $id), $savePrint);
|
||
}
|
||
|
||
/**
|
||
* 后台--商城各销售额合计
|
||
* @param $where 条件
|
||
* @param $field 合计字段
|
||
*/
|
||
public function backMoneySum($where, $field)
|
||
{
|
||
$result = M('retail_bill_order as b')
|
||
->join('ls_retail_bill_online as o on b.id=o.bill_id')
|
||
->join('ls_retail_bill_discount as d on b.id=d.bill_id')
|
||
->where($where)
|
||
->sum($field);
|
||
|
||
return $result ? round($result, 2) : '0';
|
||
}
|
||
|
||
/**
|
||
* 后台--商城各订单待发货数量合计
|
||
* @param $where 条件
|
||
* @return bool
|
||
*/
|
||
public function backMoneyCount($where)
|
||
{
|
||
$result = M('retail_bill_order as b')
|
||
->join('ls_retail_bill_online as o on b.id=o.bill_id')
|
||
->join('ls_retail_bill_discount as d on b.id=d.bill_id')
|
||
->where($where)
|
||
->count();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 获取收银端bill_order、bill_discount两表查询
|
||
* @param $where
|
||
* @param $field
|
||
* @return mixed
|
||
*/
|
||
public function getCashierOrder($where, $field = '*')
|
||
{
|
||
$info = $this->alias('b')
|
||
->join('ls_retail_bill_discount as d on b.id=d.bill_id')
|
||
->field($field)
|
||
->where($where)
|
||
->find();
|
||
return $info;
|
||
}
|
||
}
|