|
@@ -0,0 +1,337 @@
|
|
|
+<?php namespace Place_interface\Api;
|
|
|
+use Dever;
|
|
|
+use Place;
|
|
|
+use Place_interface\Lib\Core;
|
|
|
+class Sales extends Core
|
|
|
+{
|
|
|
+ protected $login = true;
|
|
|
+ protected $entry = true;
|
|
|
+ protected $info;
|
|
|
+ protected $data = [];
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ parent::__construct();
|
|
|
+ $this->data['sales_type'] = Dever::input('sales_type', 'is_numeric', '销售渠道类型');
|
|
|
+ $this->data['sales_id'] = Dever::input('sales_id', 'is_numeric', '销售渠道ID');
|
|
|
+ $this->info = Dever::load('info', 'place_channel_sales')->get($this->data['sales_type'], $this->data['sales_id']);
|
|
|
+ if ($this->info['uid'] != Place::$uid) {
|
|
|
+ Dever::error('您没有权限', -3);
|
|
|
+ }
|
|
|
+ $this->info['mobile'] = \Dever\Helper\Str::hide($this->info['mobile']);
|
|
|
+ if (!$this->info['info']) {
|
|
|
+ $this->info['info'] = Place::$info['info'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 销售渠道信息
|
|
|
+ public function info()
|
|
|
+ {
|
|
|
+ $data['user'] = Place::$user;
|
|
|
+ $data['info'] = $this->info;
|
|
|
+ $data['desc'] = $this->info['info'];
|
|
|
+
|
|
|
+ # 获取权益
|
|
|
+ $data['benefit'] = '';
|
|
|
+ $benefit = Dever::db('sales', 'place_benefit')->find(['sales_cate_id' => $this->info['cate_id'], 'status' => 1]);
|
|
|
+ if ($benefit && $benefit['desc']) {
|
|
|
+ $data['benefit'] = htmlspecialchars_decode($benefit['desc']);
|
|
|
+ }
|
|
|
+
|
|
|
+ # 用户数
|
|
|
+ $where = $this->data;
|
|
|
+ $where['status'] = 1;
|
|
|
+ $data['member'] = Dever::db('info', 'place_user')->count($this->data);
|
|
|
+
|
|
|
+ # 角色数
|
|
|
+ $data['role'] = [];
|
|
|
+ # 角色列表
|
|
|
+ $role = Dever::db('info', 'place_role')->select(['status' => 1]);
|
|
|
+ if ($role) {
|
|
|
+ $roleWhere = $this->data;
|
|
|
+ foreach ($role as $k => $v) {
|
|
|
+ $level = Dever::db('level', 'place_role')->find(['info_id' => $v['id'], 'status' => 1]);
|
|
|
+ if ($level) {
|
|
|
+ $roleWhere['info_id'] = $v['id'];
|
|
|
+ $roleWhere['status'] = 1;
|
|
|
+ $num = Dever::db('user', 'place_role')->count($roleWhere);
|
|
|
+ $data['role'][] = ['id' => $v['id'], 'name' => $v['name'], 'num' => $num];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 订单数
|
|
|
+ unset($where['status']);
|
|
|
+ $data['order'] = Dever::db('source', 'place_order')->count($where);
|
|
|
+
|
|
|
+ $money = Place::money();
|
|
|
+
|
|
|
+ # 收益
|
|
|
+ $data['profit'] = Dever::db('profit', 'place_channel_sales')->sum($where, 'money') . $money['unit'];
|
|
|
+
|
|
|
+ # 流水
|
|
|
+ $where['status'] = ['in', '2,3,4,5,6'];
|
|
|
+ $data['cash'] = Dever::db('source', 'place_order')->sum($where, 'money_cash') . $money['unit'];
|
|
|
+
|
|
|
+
|
|
|
+ # 获取待付款
|
|
|
+ $where['status'] = 1;
|
|
|
+ $data['order_1'] = Dever::db('source', 'place_order')->count($where);
|
|
|
+ # 待发货
|
|
|
+ $where['status'] = 2;
|
|
|
+ $data['order_2'] = Dever::db('source', 'place_order')->count($where);
|
|
|
+ # 待收货
|
|
|
+ $where['status'] = ['in', '3,4'];
|
|
|
+ $data['order_3'] = Dever::db('source', 'place_order')->count($where);
|
|
|
+ # 已完成
|
|
|
+ $where['status'] = ['in', '5,6'];
|
|
|
+ $data['order_4'] = Dever::db('source', 'place_order')->count($where);
|
|
|
+
|
|
|
+ # 有退款
|
|
|
+ unset($where['status']);
|
|
|
+ $where['refund_status'] = 1;
|
|
|
+ $data['order_5'] = Dever::db('source', 'place_order')->count($where);
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 店铺用户列表
|
|
|
+ public function getUser()
|
|
|
+ {
|
|
|
+ $this->data['status'] = 1;
|
|
|
+ $data['list'] = Dever::db('info', 'place_user')->select($this->data, ['num' => 10, 'col' => 'id,name,avatar,num_order,cdate']);
|
|
|
+ if ($data['list']) {
|
|
|
+ foreach ($data['list'] as &$v) {
|
|
|
+ $v['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
|
|
|
+ $v['order'] = $v['num_order'] . '单';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data['page'] = Dever::page('total');
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 店铺角色用户列表
|
|
|
+ public function getRoleUser()
|
|
|
+ {
|
|
|
+ $id = Dever::input('id', 'is_numeric', '角色');
|
|
|
+ $this->data['info_id'] = $id;
|
|
|
+ $this->data['status'] = 1;
|
|
|
+ $data['info'] = $info = Dever::db('info', 'place_role')->find(['id' => $id, 'status' => 1], ['col' => 'id,name,info,score_id']);
|
|
|
+ $user = Dever::db('user', 'place_role')->select($this->data, ['num' => 10, 'col' => '*']);
|
|
|
+ $data['list'] = [];
|
|
|
+ if ($user) {
|
|
|
+ foreach ($user as $k => $v) {
|
|
|
+ $data['list'][$k] = Dever::db('info', 'place_user')->find($v['uid'], ['col' => 'id,name,avatar,num_order']);
|
|
|
+ if ($data['list'][$k]) {
|
|
|
+ $data['list'][$k]['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
|
|
|
+ # 获取订单数
|
|
|
+ $data['list'][$k]['order'] = $data['list'][$k]['num_order'] . '单';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data['page'] = Dever::page('total');
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 店铺订单列表
|
|
|
+ public function getOrder()
|
|
|
+ {
|
|
|
+ $status = Dever::input('status');
|
|
|
+ $data = Dever::load('source/order', 'place_order')->getList(Place::$uid, $status, $this->data['sales_type'], $this->data['sales_id']);
|
|
|
+ return ['list' => $data];
|
|
|
+ }
|
|
|
+
|
|
|
+ # 店铺订单详情
|
|
|
+ public function getOrderView()
|
|
|
+ {
|
|
|
+ $info = $this->getOrderInfo();
|
|
|
+ $info = Dever::load('source/order', 'place_order')->getInfo($info, true);
|
|
|
+ $data = ['info' => $info, 'refund_desc_type' => Dever::db('source_refund', 'place_order')->value('desc_type'), 'refund_type' => Dever::db('source_refund', 'place_order')->value('type')];
|
|
|
+ $data['express'] = [Dever::call("sector/delivery.getList", 1)];
|
|
|
+ $data['virtual'] = [Dever::call("sector/delivery.getList", 2)];
|
|
|
+
|
|
|
+ # 获取退货地址
|
|
|
+ if ($data['info']['refund_status'] == 1 && isset($data['info']['refund']) && $data['info']['refund'] && $data['info']['refund']['status'] == 1 && $data['info']['refund']['type'] == 1 && $data['info']['method'] > 1) {
|
|
|
+ //$data['address'] = Dever::load('address', 'place')->getList();
|
|
|
+ $name = $this->info['name'];
|
|
|
+ $data['address'][] = ['id' => 'sales_' . $this->data['sales_type'] . '_' . $this->data['sales_id'], 'name' => $name];
|
|
|
+ $data['address'] = [$data['address']];
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取订单信息
|
|
|
+ private function getOrderInfo()
|
|
|
+ {
|
|
|
+ $id = Dever::input('order_id');
|
|
|
+ if (!$id) {
|
|
|
+ Dever::error('订单信息错误');
|
|
|
+ }
|
|
|
+ $info = Dever::db('source', 'place_order')->find(['id' => $id, 'sales_type' => $this->data['sales_type'], 'sales_id' => $this->data['sales_id']]);
|
|
|
+ if (!$info) {
|
|
|
+ Dever::error('订单信息有误');
|
|
|
+ }
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 确认自提
|
|
|
+ public function setPickup()
|
|
|
+ {
|
|
|
+ $info = $this->getOrderInfo();
|
|
|
+ $code = Dever::input('code', 'is_numeric', '自提码');
|
|
|
+ $info['code'] = substr($info['cdate'], -4);
|
|
|
+ if ($info['code'] != $code) {
|
|
|
+ Dever::error('自提码错误');
|
|
|
+ }
|
|
|
+ Dever::load('source/order', 'place_order')->finish($this->data['sales_type'], $info, true, $this->data['sales_id']);
|
|
|
+ return 'ok';
|
|
|
+ }
|
|
|
+
|
|
|
+ # 发货
|
|
|
+ public function setDelivery()
|
|
|
+ {
|
|
|
+ $info = $this->getOrderInfo();
|
|
|
+ $detail_id = Dever::input('detail_id', 'is_numeric', '订单信息');
|
|
|
+ $delivery_id = Dever::input('delivery_id', 'is_numeric', '发货信息');
|
|
|
+ $content = Dever::input('content', 'is_string', '发货信息');
|
|
|
+ Dever::load('source/delivery', 'place_order')->up($info['id'], $detail_id, $delivery_id, $content, $this->data['sales_type']+10, $this->data['sales_id']);
|
|
|
+ return 'ok';
|
|
|
+ }
|
|
|
+
|
|
|
+ # 审核退款
|
|
|
+ public function setRefund()
|
|
|
+ {
|
|
|
+ $data = $this->getOrderView();
|
|
|
+ if ($data['info']['refund_status'] == 1 && isset($data['info']['refund']) && $data['info']['refund']) {
|
|
|
+ $type = Dever::input('type', 'is_numeric', '审核类型');
|
|
|
+ $desc = Dever::input('desc');
|
|
|
+ $address_id = Dever::input('address_id');
|
|
|
+ if ($type == 2 && !$desc) {
|
|
|
+ Dever::error('审核备注不能为空');
|
|
|
+ }
|
|
|
+ if ($type == 1 && isset($data['address']) && $data['address']) {
|
|
|
+ if (!$address_id) {
|
|
|
+ Dever::error('请选择退货地址');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Dever::load('source/refund', 'place_order')->audit($data['info']['refund']['id'], $type, $desc, $address_id, $this->data['sales_type']+10, $this->data['sales_id']);
|
|
|
+ return 'ok';
|
|
|
+ } else {
|
|
|
+ Dever::error('审核失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 审核退货
|
|
|
+ public function setRefundDelivery()
|
|
|
+ {
|
|
|
+ $data = $this->getOrderView();
|
|
|
+ if ($data['info']['refund_status'] == 1 && isset($data['info']['refund']) && $data['info']['refund']) {
|
|
|
+ $type = Dever::input('type', 'is_numeric', '审核类型');
|
|
|
+ $desc = Dever::input('desc');
|
|
|
+ if ($type == 2 && !$desc) {
|
|
|
+ Dever::error('审核备注不能为空');
|
|
|
+ }
|
|
|
+ Dever::load('source/refund', 'place_order')->auditDelivery($data['info']['refund']['id'], $type, $desc, $this->data['sales_type']+10, $this->data['sales_id']);
|
|
|
+ return 'ok';
|
|
|
+ } else {
|
|
|
+ Dever::error('审核失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 店铺订单发货、退款、代完成等
|
|
|
+
|
|
|
+ # 店铺流水列表
|
|
|
+ public function getOrderCash()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ # 店铺收益列表
|
|
|
+ public function getProfit()
|
|
|
+ {
|
|
|
+ $where = $this->data;
|
|
|
+ $data['money'] = Place::money();
|
|
|
+ $data['cash'] = Dever::db('profit', 'place_channel_sales')->sum($where, 'money') . $data['money']['unit'];
|
|
|
+ $data['list'] = Dever::db('profit', 'place_channel_sales')->select($where, ['num' => 10]);
|
|
|
+ if ($data['list']) {
|
|
|
+ foreach ($data['list'] as &$v) {
|
|
|
+ $log = Dever::db('user_log', 'place_score')->find($v['user_log_id']);
|
|
|
+ $v['desc'] = $log['desc'];
|
|
|
+ $v['cdate'] = date('Y-m-d H:i:s', $v['cdate']);
|
|
|
+ $info = Dever::db('action', 'place_score')->find($v['action_id']);
|
|
|
+ $v['action_name'] = $info['name'];
|
|
|
+ $v['amount'] = Dever::load('info', 'place_score')->getText($v['amount'], $v['score_id']);
|
|
|
+ $v['money'] .= $data['money']['unit'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 店铺权益列表 暂时不做
|
|
|
+ public function getBenefit()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取店铺信息
|
|
|
+ public function getInfo()
|
|
|
+ {
|
|
|
+ $this->info['content'] = htmlspecialchars_decode($this->info['content']);
|
|
|
+ if (isset($this->info['area'])) {
|
|
|
+ $this->info['area_string'] = Dever::load('data', 'area')->string($this->info['area'], '-');
|
|
|
+ $this->info['area'] = explode(',', 'CN,' . $this->info['area']);
|
|
|
+ }
|
|
|
+ return $this->info;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 更新信息
|
|
|
+ public function update()
|
|
|
+ {
|
|
|
+ $update = [];
|
|
|
+ $name = Dever::input('name', 'is_string', '名称');
|
|
|
+ $truename = Dever::input('truename', 'is_string', '联系人');
|
|
|
+ $this->info['name'] = $update['name'] = $name;
|
|
|
+ $this->info['truename'] = $update['truename'] = $truename;
|
|
|
+ $logo = Dever::input('logo');
|
|
|
+ if ($logo) {
|
|
|
+ $this->info['logo'] = $update['logo'] = $logo;
|
|
|
+ }
|
|
|
+ $info = Dever::input('info');
|
|
|
+ if ($info) {
|
|
|
+ $this->info['info'] = $update['info'] = $info;
|
|
|
+ }
|
|
|
+ $content = Dever::input('content');
|
|
|
+ if ($content) {
|
|
|
+ $this->info['content'] = $update['content'] = $content;
|
|
|
+ }
|
|
|
+ $open = Dever::input('open');
|
|
|
+ if ($open) {
|
|
|
+ $this->info['open'] = $update['open'] = $open;
|
|
|
+ }
|
|
|
+ $worktime = Dever::input('worktime');
|
|
|
+ if ($worktime) {
|
|
|
+ $this->info['worktime'] = $update['worktime'] = $worktime;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($this->info['area'])) {
|
|
|
+ $province = Dever::input('province_id', 'is_numeric', '省份');
|
|
|
+ $city = Dever::input('city_id', 'is_numeric', '城市');
|
|
|
+ $county = Dever::input('county_id', 'is_numeric', '区县');
|
|
|
+ $town = Dever::input('town_id', 'is_numeric', '街镇');
|
|
|
+ $address = Dever::input('address', 'is_string', '地址');
|
|
|
+ $this->info['province_id'] = $update['province_id'] = $province;
|
|
|
+ $this->info['city_id'] = $update['city_id'] = $city;
|
|
|
+ $this->info['county_id'] = $update['county_id'] = $county;
|
|
|
+ $this->info['town_id'] = $update['town_id'] = $town;
|
|
|
+ if ($province && $city && $county && $town) {
|
|
|
+ $update['area'] = $province . ',' . $city . ',' . $county . ',' . $town;
|
|
|
+ }
|
|
|
+ $this->info['address'] = $update['address'] = $address;
|
|
|
+ }
|
|
|
+ if ($update) {
|
|
|
+ $table = Dever::load('info', 'place_channel_sales')->getTypeName($this->data['sales_type']);
|
|
|
+ Dever::load('info', 'place')->update(Place::$info['id']);
|
|
|
+ Dever::db($table, 'place_channel_sales')->update($this->data['sales_id'], $update);
|
|
|
+ }
|
|
|
+ return $this->getInfo();
|
|
|
+ }
|
|
|
+}
|