0] : $map = []; if ($status) { $map['status'] = 1; } $query = $this->app->db->name('MerchantList'); return $query->where($map)->order('id desc')->column('id,name,status,is_deleted', 'id'); } /** * 获取订单商品数据 * @return array */ public function getProductList($where = false, $status = true) { $where ? $map = ['is_deleted' => 0] : $map = []; if ($status) { $map['status'] = 1; } $query = $this->app->db->name('ChannelProduct'); return $query->where($map)->order('id desc')->column('key,id,name,cid,status,is_deleted', 'id'); } /** * 获取订单商品数据 * @return array */ public function getServiceList() { $query = $this->app->db->name('service_info'); return $query->order('id desc')->column('key,id,name', 'key'); } /** * 获取订单商品数据 * @return array */ public function getProductKeyList($where = false) { $where ? $map = ['is_deleted' => 0] : $map = []; $map['status'] = 1; $query = $this->app->db->name('ChannelProduct'); return $query->where($map)->order('id desc')->group('key')->column('key,id,name,cid,status,is_deleted', 'id'); } /** * 获取订单关联数据 * @return array */ public function getOrderInfo($mid,$pid) { $data = []; $field = 'id,name,status,is_deleted'; // $data['c'] = $this->app->db->name('ChannelList')->where('id',$cid)->field($field)->find(); $data['m'] = $this->app->db->name('MerchantList')->where('id',$mid)->field($field)->find(); $data['p'] = $this->app->db->name('ChannelProduct')->where('id',$pid)->field($field)->find(); return $data; } public function total() { $data_type = input('data_type', 1); if ($data_type == 2) { $this->table = 'merchant_order_history_kami91'; } $where = array(); $mid = input('mid'); if ($mid) { $where['mid'] = $mid; } $pid = input('pid'); if ($pid) { $where['pid'] = $pid; } $cash = input('cash'); if ($cash) { $where['cash'] = $cash; } $status = input('status'); if ($status) { $where['status'] = $status; } $product_key = input('product_key'); if ($product_key) { $where['product_key'] = $product_key; } $create_at = input('create_at'); $col = 'create_at'; $callback_at = input('callback_at'); if ($callback_at) { $create_at = $callback_at; $col = 'callback_at'; } if ($create_at) { $temp = explode(' - ', $create_at); $begin = $temp[0] . ' 00:00:00'; $after = $temp[1] . ' 23:59:59'; $time = [$begin, $after]; } else { $time = false; } //$result['num'] = $this->getDb($where, $time); unset($where['status']); $result['order_num'] = $result['order_dong_num'] = $result['order_no_num'] = $result['order_yes_num'] = $result['order_ys_num'] = 0; if ($data_type == 2) { $result['order_dong_num'] = 0; } else { $where['status'] = 4; $result['order_dong_num'] = $this->getDb($where, $time, '*'); } $where['status'] = 2; $result['order_yes_num'] = $this->getDb($where, $time, '*'); $where['status'] = 3; $result['order_no_num'] = $this->getDb($where, $time, '*'); $where['status'] = 5; $result['order_yc_num'] = $this->getDb($where, $time, '*'); $where['status'] = 1; $result['order_xd_num'] = $this->getDb($where, $time, '*'); $where['status'] = 6; $result['order_dfxx_num'] = $this->getDb($where, $time, '*'); $where['status'] = 7; $result['order_dcl_num'] = $this->getDb($where, $time, '*'); $result['order_num'] = $result['order_dong_num'] + $result['order_yes_num'] + $result['order_no_num'] + $result['order_yc_num'] + $result['order_xd_num'] + $result['order_dcl_num'] + $result['order_dfxx_num']; $result['order_yes_lv'] = $result['order_num'] > 0 ? round(($result['order_yes_num']/$result['order_num']) * 100, 2) . '%' : '0%'; return $result; } private function getDb($where, $time, $col = 'cash', $status = false) { $db = $this->db()->where($where); if ($status) { $db->whereRaw(' status in('.$status.')'); } if ($time) { $callback_at = input('callback_at'); if ($callback_at) { $time_col = 'callback_at'; } else { $time_col = 'create_at'; } $db = $db->whereBetween($time_col, $time); } $order_id = input('order_id'); if ($order_id) { $db = $db->whereLike('order_id', "%{$order_id}%"); } $merchant_order_id = input('merchant_order_id'); if ($merchant_order_id) { $db = $db->whereLike('merchant_order_id', "%{$merchant_order_id}%"); } if ($col == '*') { return round($db->count($col), 2); } return round($db->sum($col), 2); } public function getOrder($data_type, $order_id) { $where = array(); if (str_contains($order_id, ',')) { $where[] = array('id', 'in', $order_id); } elseif (is_numeric($order_id)) { $where['id'] = $order_id; } else { $where['order_id'] = $order_id; } if ($data_type == 2) { $this->table = 'merchant_order_history_kami91'; } return $this->db()->where($where)->find(); } public function upkami($orderid,$cardlist) { $where['order_id'] = $orderid; $info = $this->db()->where($where)->find(); if(isset($info['cardno'])){ return 'ok'; } $update['cardno'] = $cardlist['cardno']; $update['cardpwd'] = $cardlist['cardpwd']; $update['expire_time'] = $cardlist['expired']; $this->db()->where(array('order_id' => $orderid))->update($update); return 'ok'; } public function up($where, $data = []) { // $data = array(); // $data['name'] = $name; $info = $this->db()->where($where)->find(); // $data['status'] = 1; if (!$info) { return $this->db()->insertGetId($data); } else { $this->db()->where(array('id' => $info['id']))->update($data); return $info['id']; } } public function upStatus($orderid,$status,$callback_msg ='') { $where['order_id'] = $orderid; $info = $this->db()->where($where)->find(); if(isset($info['callback_at'])){ return 'ok'; } if(isset($callback_msg) && $callback_msg ){ $update['callback_msg'] = $callback_msg; } $update['status'] = $status; $update['callback_at'] = date('Y-m-d H:i:s'); $this->db()->where(array('order_id' => $orderid))->update($update); return 'ok'; } # 获取所有完成的订单 public function getFinishData($day, $page = 1) { if (!$day) { $start = date('Y-m-d', strtotime('-360 day')); $day = date('Y-m-d', strtotime('-1 day')); } else { $start = $day; } $begin = $start . ' 00:00:00'; $after = $day . ' 23:59:59'; $time = [$begin, $after]; $db = $this->db()->whereRaw('status in(2,3) '); $db = $db->whereBetween('create_at', $time)->order('id asc'); if ($page) { $limit = 10000; $page = $page - 1; $page = $page*$limit; $db->limit($page, $limit); } return $db->select()->toArray(); } # 删除订单 public function del($id) { $where['id'] = $id; return $this->db()->where($where)->delete(); } // public function up($type, $value, $desc = '') // { // $where['type'] = $type; // $where['value'] = $value; // $info = $this->db()->where($where)->find(); // // $update['type'] = $type; // $update['value'] = $value; // $update['desc'] = $desc; // if (!$info) { // $update['status'] = 1; // $this->db()->insert($update); // } else { // $this->db()->where(array('id' => $info['id']))->update($update); // } // // return true; // } }