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; } }