123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <?php namespace Pinterface\Api;
- use Dever;
- use Pinterface\Lib\Core;
- class Sales extends Core
- {
- protected $login = true;
- protected $entry = true;
- protected $info;
- protected $data = [];
- public function init()
- {
- $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(\Psales\Lib\Info::class)->get($this->data['sales_type'], $this->data['sales_id']);
- if ($this->info['uid'] != $this->place->uid) {
- Dever::error('您没有权限', -3);
- }
- $this->info['mobile'] = \Dever\Helper\Str::hide($this->info['mobile']);
- if (!$this->info['info']) {
- $this->info['info'] = $this->place->info['info'];
- }
- }
- # 销售渠道信息
- public function info()
- {
- $data['user'] = $this->place->user;
- $data['info'] = $this->info;
- $data['desc'] = $this->info['info'];
- # 获取权益
- $data['benefit'] = '';
- $benefit = Dever::db('pbenefit/sales')->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('puser/info')->count($this->data);
- # 身份数
- $data['role'] = [];
- # 身份列表
- $role = Dever::db('prole/info')->select(['status' => 1]);
- if ($role) {
- $roleWhere = $this->data;
- foreach ($role as $k => $v) {
- $level = Dever::db('prole/level')->find(['info_id' => $v['id'], 'status' => 1]);
- if ($level) {
- $roleWhere['info_id'] = $v['id'];
- $roleWhere['status'] = 1;
- $num = Dever::db('prole/user')->count($roleWhere);
- $data['role'][] = ['id' => $v['id'], 'name' => $v['name'], 'num' => $num];
- }
- }
- }
- # 订单数
- unset($where['status']);
- $data['order'] = Dever::db('porder/source')->count($where);
- $money = $this->place->money();
-
- # 收益
- $data['profit'] = Dever::db('psales/profit')->sum($where, 'money') . $money['unit'];
- # 流水
- $where['status'] = ['in', '2,3,4,5,6'];
- $data['cash'] = Dever::db('porder/source')->sum($where, 'money_cash') . $money['unit'];
- # 获取待付款
- $where['status'] = 1;
- $data['order_1'] = Dever::db('porder/source')->count($where);
- # 待发货
- $where['status'] = 2;
- $data['order_2'] = Dever::db('porder/source')->count($where);
- # 待收货
- $where['status'] = ['in', '3,4'];
- $data['order_3'] = Dever::db('porder/source')->count($where);
- # 已完成
- $where['status'] = ['in', '5,6'];
- $data['order_4'] = Dever::db('porder/source')->count($where);
- # 有退款
- unset($where['status']);
- $where['refund_status'] = 1;
- $data['order_5'] = Dever::db('porder/source')->count($where);
- return $data;
- }
- # 店铺用户列表
- public function getUser()
- {
- $this->data['status'] = 1;
- $data['list'] = Dever::db('puser/info')->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('prole/info')->find(['id' => $id, 'status' => 1], ['col' => 'id,name,info,score_id']);
- $user = Dever::db('prole/user')->select($this->data, ['num' => 10, 'col' => '*']);
- $data['list'] = [];
- if ($user) {
- foreach ($user as $k => $v) {
- $data['list'][$k] = Dever::db('puser/info')->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(\Porder\Lib\Source\Order::class)->getList($this->place->uid, $status, $this->data['sales_type'], $this->data['sales_id']);
- return ['list' => $data];
- }
- # 店铺订单详情
- public function getOrderView()
- {
- $info = $this->getOrderInfo();
- $info = Dever::load(\Porder\Lib\Source\Order::class)->getInfo($info, true);
- $data = ['info' => $info, 'refund_desc_type' => Dever::db('porder/source_refund')->value('desc_type'), 'refund_type' => Dever::db('porder/source_refund')->value('type')];
- $data['express'] = [Dever::call("Sector/Lib/Delivery.getList", 1)];
- $data['virtual'] = [Dever::call("Sector/Lib/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('porder/source')->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(\Porder\Lib\Source\Order::class)->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(\Porder\Lib\Source\Delivery::class)->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(\Porder\Lib\Source\Refund::class)->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(\Porder\Lib\Source\Refund::class)->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'] = $this->place->money();
- $data['cash'] = Dever::db('psales/profit')->sum($where, 'money') . $data['money']['unit'];
- $data['list'] = Dever::db('psales/profit')->select($where, ['num' => 10]);
- if ($data['list']) {
- foreach ($data['list'] as &$v) {
- $log = Dever::db('pscore/user_log')->find($v['user_log_id']);
- $v['desc'] = $log['desc'];
- $v['cdate'] = date('Y-m-d H:i:s', $v['cdate']);
- $info = Dever::db('pscore/action')->find($v['action_id']);
- $v['action_name'] = $info['name'];
- $v['amount'] = Dever::load(\Pscore\Lib\Info::class)->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(\Area\Lib\Data::class)->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(\Psales\Lib\Info::class)->getType($this->data['sales_type'])['table'];
- Dever::load(\Place\Lib\Info::class)->update($this->place['id']);
- Dever::db('psales/' . $table)->update($this->data['sales_id'], $update);
- }
- return $this->getInfo();
- }
- }
|