select(array('status' => 1)); } # 为商户生成appkey public function createAppKey($data) { $info = Dever::db('info', 'seller')->find($data['id']); if (!$info['appkey']) { $update['appkey'] = 'app' . Str::rand(15, 0); $update['appsecret'] = strtoupper(Str::rand(32)); $check = Dever::db('info', 'seller')->find(array('appkey' => $update['appkey'])); if ($check) { return $this->createAppKey($data); } Dever::db('info', 'seller')->update($data['id'], $update); } # 写到redis中 $info = Dever::db('info', 'seller')->find($data['id']); Dever::cache('seller_' . $info['appkey'], $info); } # 订单手动充值 public function createOrder($data) { if (!$data['seller_id']) { Dever::error('未选择商户'); } if (!$data['data']) { Dever::error('未输入充值数据'); } $goods = explode(',', $data['goods']); $goods_id = end($goods); $sku_id = $data['sku_id']; $seller_id = $data['seller_id']; $seller = Dever::db('info', 'seller')->find($seller_id); if (!$seller) { Dever::error('商户不存在'); } if ($seller && $seller['status'] == 2) { Dever::error('商户已封禁'); } if (!$goods_id) { Dever::error('未选择商品'); } if (!$sku_id) { Dever::error('未选择规格'); } $goods = Dever::db('info', 'goods')->find($goods_id); $sku = Dever::db('info_sku', 'goods')->find($sku_id); if (!$goods) { Dever::error('商品不存在'); } if (!$sku) { Dever::error('规格不存在'); } if ($sku['info_id'] != $goods['id']) { Dever::error('商品['.$goods['name'].']下无此规格'); } $param = explode("\r\n", $data['data']); $class = Dever::load('order', 'seller'); foreach ($param as $k => $v) { $order = Str::order('PAY') . '_' . $k; $class->add($seller, $goods, $sku, $v, $order); } return $data; } # 修改订单状态 public function editOrder($id, $data) { if ($data['status'] <= 10) { Dever::error('请选择订单状态'); } $newid = array(); $id = explode(',', $id); foreach ($id as $k => $v) { $info = Dever::db('order', 'seller')->find($v); if ($info['status'] < 10) { $newid[] = $v; if (!$info['order_num']) { $update['order_num'] = Dever::load('order', 'seller')->createOrder(); Dever::db('order', 'seller')->update($v, $update); } } } if (!$newid) { Dever::error('请选择未完成订单'); } $newid = implode(',', $newid); $data['finish'] = 1; $data['finish_date'] = time(); return array($newid, $data); } # 将订单插入到订单日志中 public function addOrderLog($id, $data) { $id = explode(',', $id); foreach ($id as $k => $v) { $info = Dever::db('order', 'seller')->find($v); if ($info['status'] >= 10) { if ($info['status'] == 11) { # 失败,余额加回来 Dever::load('info', 'seller')->inc($info['seller_id'], $info['price']); Dever::load('info', 'seller')->log($info['seller_id'], $info['id'], $info['price'], 4); } Dever::db('order_log', 'seller')->insert($info); } } } # 后台充值、提现 public function operCash($data) { if ($data['type'] == 1) { Dever::load('info', 'seller')->inc($data['seller_id'], $data['cash']); Dever::db('info', 'seller')->update($id, array('p_cash' => array('+', $cash))); } elseif ($data['type'] == 2) { Dever::load('info', 'seller')->dec($data['seller_id'], $data['cash']); $data['cash'] = -1*$data['cash']; } return $data; } # 展示订单信息 public function showOrder($order_id) { $result = ''; if ($order_id) { $order = Dever::db('order', 'seller')->find($order_id); if ($order) { $result = $order['order_num']; } } return $result; } # 展示订单金额 public function showOrderCash($cate_id, $goods_id, $sku_id, $cash, $price) { $goods = Dever::db('info', 'goods')->find($goods_id); $result = $goods['name'] . ' / ' . $cash . ' / ' . $price; return $result; } # 展示订单状态 public function showOrderStatus($status) { $value = Dever::db('order', 'seller')->config['struct']['status']['value'][$status]; if ($status < 10) { return $value; } elseif ($status == 10) { return ''.$value.''; } elseif ($status == 11) { return ''.$value.''; } } # 展示订单统计信息 public function showOrderStat($where) { $db = Dever::db('order', 'seller'); $total = $db->count($where); $zongjine = $db->find($where, array('col' => 'sum(cash) as cash')); $where['status'] = 10; $yes = $db->count($where); if ($total <= 0) { $lv = '0%'; } else { $lv = round($yes/$total*100, 2) . '%'; } $czongjine = $db->find($where, array('col' => 'sum(cash) as cash')); $szongjine = $db->find($where, array('col' => 'sum(price) as cash')); $where['status'] = array('<', 10); $chu = $db->count($where); $where['status'] = 11; $shibai = $db->count($where); return array ( array ( # 一共24 'span' => '3', 'name' => '总订单数', 'value' => $total, ), array ( 'span' => '3', 'name' => '成功订单数', 'value' => $yes, ), array ( 'span' => '3', 'name' => '成功率', 'value' => $lv, ), array ( 'span' => '3', 'name' => '处理中订单数', 'value' => $chu, ), array ( 'span' => '3', 'name' => '失败订单数', 'value' => $shibai, ), array ( 'span' => '3', 'name' => '总金额', 'value' => $zongjine['cash'] ?? 0, ), array ( 'span' => '3', 'name' => '成功金额', 'value' => $czongjine['cash'] ?? 0, ), array ( 'span' => '3', 'name' => '实际成功金额', 'value' => $szongjine['cash'] ?? 0, ), ); } # 展示订单扩展信息 public function showOrderExpand($data) { $seller = Dever::db('info', 'seller')->find($data['seller_id']); $channel = array(); if ($data['channel_id']) { $channel = Dever::db('info', 'channel')->find($data['channel_id']); } $value = $this->showOrderStatus($data['status']); $goods = $this->showOrderCash($data['cate_id'], $data['goods_id'], $data['sku_id'], $data['cash'], $data['price']); $result['type'] = 'desc'; $result['content'][] = array ( 'title' => '商户发起请求', 'border' => true, 'direction' => 'horizontal', 'size' => 'small', 'column' => 1, 'content' => array ( array('商户名称', $seller['name']), array('商户订单号', $data['seller_order_num']), array('商品', $goods), array('商户请求参数', $data['seller_request']), array('请求时间', date('Y-m-d H:i', $data['cdate'])), ), ); $result['content'][] = array ( 'title' => '系统下单', 'border' => true, 'direction' => 'horizontal',//'vertical' | 'horizontal' 'size' => 'small',//'' | 'large' | 'default' | 'small' 'column' => 1, 'content' => array ( array('系统订单ID', $data['id']), array('系统订单号', $data['order_num']), array('订单状态', $value), array('系统发起请求', $data['channel_request']), array('请求时间', $data['channel_order_date'] ? date('Y-m-d H:i', $data['channel_order_date']) : '-'), ), ); if ($channel) { $result['content'][] = array ( 'title' => '渠道响应信息', 'border' => true, 'direction' => 'horizontal', 'size' => 'small', 'column' => 1, 'content' => array ( array('渠道名称', $channel['name']), array('渠道订单号', $data['channel_order_num']), array('渠道响应信息', $data['channel_response']), ), ); } if ($data['channel_callback']) { $result['content'][] = array ( 'title' => '渠道回调信息', 'border' => true, 'direction' => 'horizontal', 'size' => 'small', 'column' => 1, 'content' => array ( array('渠道回调信息', $data['channel_callback']), array('回调时间', date('Y-m-d H:i', $data['channel_callback_date'])), array('官方流水号', $data['official_order_num']), array('官方充值结果', $data['official_msg']), ), ); } $result['content'][] = array ( 'title' => '系统向商户发起回调', 'border' => true, 'direction' => 'horizontal', 'size' => 'small', 'column' => 1, 'content' => array ( array('商户响应信息', $data['seller_callback']), array('响应时间', $data['seller_callback_date'] ? date('Y-m-d H:i', $data['seller_callback_date']) : '-'), array('响应次数', $data['seller_callback_num']), ), ); return $result; } }