初始上传

This commit is contained in:
2026-04-04 17:27:12 +08:00
parent 4d80d28eb4
commit b7e11774ee
11191 changed files with 1588469 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\model\system\Address as AddressModel;
use app\storeapi\controller\BaseStoreApi;
/**
* 地址控制器
*/
class Address extends BaseStoreApi
{
/**
* 通过ajax得到运费模板的地区数据
*/
public function areaList()
{
$address_model = new AddressModel();
$pid = $this->params['pid'] ?? 0;
$condition = [
'pid' => $pid
];
$list = $address_model->getAreaList($condition, 'id, pid, name, level', 'id asc');
return $this->response($list);
}
/**
* 获取地理位置id
*/
public function getGeographicId()
{
$address_model = new AddressModel();
$address = $this->params['address'] ?? ',,';
$address_array = explode(',', $address);
$province = $address_array[0];
$city = $address_array[1];
$district = $address_array[2];
$subdistrict = $address_array[3];
$province_list = $address_model->getAreaList(['name' => $province, 'level' => 1], 'id', '');
$province_id = !empty($province_list['data']) ? $province_list['data'][0]['id'] : 0;
$city_list = ($province_id > 0) && !empty($city) ? $address_model->getAreaList(['name' => $city, 'level' => 2, 'pid' => $province_id], 'id', '') : [];
$city_id = !empty($city_list['data']) ? $city_list['data'][0]['id'] : 0;
$district_list = !empty($district) && $city_id > 0 && $province_id > 0 ? $address_model->getAreaList(['name' => $district, 'level' => 3, 'pid' => $city_id], 'id', '') : [];
$district_id = !empty($district_list['data']) ? $district_list['data'][0]['id'] : 0;
$subdistrict_list = !empty($subdistrict) && $city_id > 0 && $province_id > 0 && $district_id > 0 ? $address_model->getAreaList(['name' => $subdistrict, 'level' => 4, 'pid' => $district_id], 'id', '') : [];
$subdistrict_id = !empty($subdistrict_list['data']) ? $subdistrict_list['data'][0]['id'] : 0;
$data = [];
$data['province_id'] = $province_id;
$data['city_id'] = $city_id;
$data['district_id'] = $district_id;
$data['subdistrict_id'] = $subdistrict_id;
return $this->response($this->success($data));
}
/**
* 转化省市区地址形式为实际的省市区id
*/
public function tranAddressInfo()
{
$latlng = $this->params['latlng'] ?? '';
$address_model = new AddressModel();
$address_result = $address_model->getAddressByLatlng(['latlng' => $latlng]);
if ($address_result['code'] < 0)
return $this->response($address_result);
$address_data = $address_result['data'];
$province = $address_data['province'] ?? '';
$city = $address_data['city'] ?? '';
$district = $address_data['district'] ?? '';
$province_id = $address_model->getAreasInfo([['name', 'like', '%' . $province . '%'], ['level', '=', 1]], 'id')['data']['id'] ?? 0;
if ($province_id > 0)
$city_id = $address_model->getAreasInfo([['name', 'like', '%' . $city . '%'], ['level', '=', 2], ['pid', '=', $province_id]], 'id')['data']['id'] ?? 0;
if (isset($city_id) && $city_id > 0 && $province_id > 0)
$district_id = $address_model->getAreasInfo([['name', 'like', '%' . $district . '%'], ['level', '=', 3], ['pid', '=', $city_id]], 'id')['data']['id'] ?? 0;
$data = [
'province_id' => $province_id ?? 0,
'city_id' => $city_id ?? 0,
'district_id' => $district_id ?? 0,
'province' => $province,
'city' => $city,
'district' => $district,
'address' => $address_data['full_address'] ?? ''
];
return $this->response($this->success($data));
}
public function getAddressByName()
{
$address = $this->params['address'] ?? '';
$address_model = new AddressModel();
$address_result = $address_model->getAddressByName($address);
if ($address_result['code'] < 0)
return $this->response($address_result);
return $this->response($address_result);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\model\system\AppVersionManage;
use app\storeapi\controller\BaseStoreApi;
/**
* Class AppVersion
* @package addon\cashier\storeapi\controller
*/
class AppVersion extends BaseStoreApi
{
/**
* 检测更新
* @return false|string
*/
public function checkUpdate()
{
$condition = [
[ 'app_key', '=', $this->params[ 'app_key' ] ],
[ 'platform', '=', $this->params[ 'platform' ] ],
[ 'version_no', '>', $this->params[ 'version_no' ] ],
];
$data = ( new AppVersionManage() )->getVersionFirstInfo($condition, '*', 'version_no desc');
return $this->response($data);
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\dict\goods\GoodsDict;
use app\model\goods\Goods as GoodsModel;
use app\storeapi\controller\BaseStoreApi;
use think\facade\Db;
/**
* 卡项控制器
* Class Activity
* @package addon\shop\storeapi\controller
*/
class Card extends BaseStoreApi
{
public function page()
{
$page_index = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$goods_category = $this->params[ 'category' ] ?? 'all';
$search_text = $this->params[ 'search_text' ] ?? '';
$goods_class = $this->params[ 'goods_class' ] ?? 'all';
$card_type = $this->params[ 'card_type' ] ?? 'all';
$model = new GoodsModel();
$condition = [
[ 'g.site_id', '=', $this->site_id ],
[ 'g.is_delete', '=', 0 ],
[ 'g.goods_state', '=', 1 ],
[ 'g.sale_store', 'like', ['%all%', '%,'.$this->store_id.',%'], 'or' ],
[ '', 'exp', Db::raw("(g.sale_channel = 'all' OR g.sale_channel = 'offline')") ]
];
if ($goods_class !== 'all') {
$condition[] = [ 'g.goods_class', '=', $goods_class ];
}else{
$condition[] = [ 'g.goods_class', 'in', [GoodsDict::real, GoodsDict::service, GoodsDict::card, GoodsDict::weigh] ];
}
if ($card_type !== 'all') {
$condition[] = [ 'gc.card_type', '=', $card_type ];
}
if ($goods_category != 'all') $condition[] = [ 'g.category_id', 'like', "%,{$goods_category},%" ];
if ($search_text != '') $condition[] = [ 'g.goods_name', 'like', "%{$search_text}%" ];
if(addon_is_exit('store')){
$status = $this->params[ 'status' ] ?? 1;
if($status !== 'all'){
$condition[] = [ 'sg.status', '=', $status ];
}
$field = 'g.goods_id,g.goods_name,g.introduction,g.goods_image,g.goods_state,g.sku_id,g.price,gs.discount_price,g.goods_spec_format,g.is_unify_price,
IFNULL(IF(g.is_unify_price = 1,g.price,sg.price), g.price) as price, IFNULL(IF(g.is_unify_price = 1,gs.discount_price,sg.price), gs.discount_price) as discount_price,
sg.price as store_price,gc.card_type,gc.card_type_name,gc.renew_price,gc.recharge_money,gc.common_num,gc.discount_goods_type,gc.discount,gc.validity_type,gc.validity_day,gc.validity_time';
$join = [
['goods_sku gs', 'gs.sku_id = g.sku_id', 'left'],
['store_goods sg', 'g.goods_id=sg.goods_id and sg.store_id='.$this->store_id, 'left'],
['goods_card gc', 'gc.goods_id = g.goods_id', 'left'],
];
$stock_store_id = (new \app\model\store\Store())->getStoreStockTypeStoreId(['store_id' => $this->store_id])['data'] ?? 0;
if($stock_store_id == $this->store_id){
$field .= ', IFNULL(sg.stock, 0) as stock';
}else{
$join[] = ['store_goods sg2', 'g.goods_id = sg2.goods_id and sg2.store_id='.$stock_store_id, 'left'];
$field .= ', IFNULL(sg2.stock, 0) as stock';
}
}else{
$field = 'g.goods_id,g.goods_name,g.introduction,g.goods_image,g.goods_state,g.sku_id,g.price,gs.discount_price,g.goods_spec_format,g.is_unify_price,gs.stock,
gc.card_type,gc.card_type_name,gc.renew_price,gc.recharge_money,gc.common_num,gc.discount_goods_type,gc.discount,gc.validity_type,gc.validity_day,gc.validity_time';
$join = [
['goods_sku gs', 'gs.sku_id = g.sku_id', 'left'],
['goods_card gc', 'gc.goods_id = g.goods_id', 'left'],
];
}
$data = $model->getGoodsPageList($condition, $page_index, $page_size, 'g.sort asc,g.create_time desc', $field, 'g', $join);
return $this->response($data);
}
/**
* 商品详情
* @return false|string
*/
public function detail()
{
$goods_id = $this->params[ 'goods_id' ] ?? 0;
$goods_model = new GoodsModel();
$field = 'g.goods_id, g.goods_name, g.introduction, g.goods_class_name, g.goods_image, g.goods_state, g.sku_id, g.price, g.unit, g.cost_price, g.category_id, g.brand_name,g.is_unify_price,
sg.stock as store_stock, sg.price as store_price, sg.cost_price as store_cost_price, sg.status as store_status,
gc.card_type,gc.card_type_name,gc.renew_price,gc.recharge_money,gc.common_num,gc.discount_goods_type,gc.discount,gc.validity_type,gc.validity_day,gc.validity_time';
$join = [
['store_goods sg', 'g.goods_id=sg.goods_id and sg.store_id=' . $this->store_id, 'left'],
['goods_card gc', 'gc.goods_id = g.goods_id', 'left'],
];
$goods_info = $goods_model->getGoodsInfo([ [ 'g.goods_id', '=', $goods_id ], [ 'g.site_id', '=', $this->site_id ] ], $field, 'g', $join)[ 'data' ];
if (empty($goods_info)) return $this->response($goods_model->error(null, '商品信息缺失'));
//查询商品规格
$sku_filed = 'sku.sku_id,sku.sku_name,sku.sku_no,sku.price,sku.discount_price,sku.cost_price,sku.sku_image,sku.sku_images,sku.spec_name,
sgs.price as store_price, sgs.cost_price as store_cost_price, sgs.status as store_status';
$join = [
['store_goods_sku sgs', 'sku.sku_id=sgs.sku_id and sgs.store_id='.$this->store_id, 'left']
];
$goods_info[ 'sku_list' ] = $goods_model->getGoodsSkuList([ [ 'sku.goods_id', '=', $goods_id ], [ 'sku.site_id', '=', $this->site_id ] ], $sku_filed, 'sku.sku_id asc', 0, 'sku', $join)[ 'data' ];
return $this->response($goods_model->success($goods_info));
}
}

View File

@@ -0,0 +1,300 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\printer\model\PrinterOrder;
use app\model\system\Export as ExportModel;
use app\model\web\Config as ConfigModel;
use app\storeapi\controller\BaseStoreApi;
use addon\cashier\model\Cashier as CashierModel;
use app\model\order\OrderCommon;
class Cashier extends BaseStoreApi
{
/**
* 交接班
*/
public function changeShifts()
{
$res = (new CashierModel())->changeShifts($this->user_info, $this->site_id, $this->store_id);
return $this->response($res);
}
/**
* 班次数据
*/
public function shiftsData()
{
$data = [
'shifts_data' => (new CashierModel())->getShiftsData($this->site_id, $this->store_id),
'userinfo' => [
'username' => $this->user_info[ 'username' ]
]
];
return $this->response($this->success($data));
}
/**
* 交接班记录
*/
public function changeShiftsRecord()
{
$page = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$uid = $this->params[ 'uid' ] ?? 0;
$start_time = $this->params[ 'start_time' ] ?? '';
$end_time = $this->params[ 'end_time' ] ?? '';
if (!empty($start_time)) $start_time = strtotime($start_time);
if (!empty($end_time)) $end_time = strtotime($end_time);
$condition = [
['csr.site_id', '=', $this->site_id],
['csr.store_id', '=', $this->store_id],
];
if ($uid != 0) $condition[] = ['csr.uid', '=', $uid];
if ($start_time && $end_time) {
$condition[] = ['csr.end_time', 'between', [$start_time, $end_time]];
} elseif (!$start_time && $end_time) {
$condition[] = ['csr.end_time', '<=', $end_time];
} elseif ($start_time && !$end_time) {
$condition[] = ['csr.end_time', '>=', $start_time];
}
$join = [['user u', 'u.uid = csr.uid', 'left']];
$cashier_model = new CashierModel();
$res = $cashier_model->getchangeShiftsPageList($condition, 'csr.*,u.username', 'csr.id desc', $page, $page_size, 'csr', $join);
foreach($res['data']['list'] as &$val){
$val['sale_goods_count'] = $cashier_model->getSaleGoodsCount([
['o.store_id', '=', $val['store_id']],
['o.pay_time', '>', $val['start_time']],
['o.pay_time', '<=', $val['end_time']],
])['data'];
}
return $this->response($res);
}
/**
* 交接班销售记录
*/
public function changeShiftsSaleGoodsList()
{
$record_id = $this->params['record_id'] ?? 0;
$page = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$sale_channel = $this->params['sale_channel'] ?? '';
$sku_name = $this->params['sku_name'] ?? '';
//交接班信息
$cashier_model = new CashierModel();
$record_info = $cashier_model->getChangeShiftsRecordInfo([['id', '=', $record_id]], '*')['data'];
$alias = 'og';
$join = [
['order o', 'og.order_id = o.order_id', 'inner'],
];
$condition = [
['o.store_id', '=', $record_info['store_id']],
['o.pay_time', '>', $record_info['start_time']],
['o.pay_time', '<=', $record_info['end_time']],
];
if($sale_channel !== '' && $sale_channel !== 'all'){
if($sale_channel == 'offline'){
$condition[] = ['o.order_from', '=', 'cashier'];
}else{
$condition[] = ['o.order_from', '<>', 'cashier'];
}
}
if($sku_name !== ''){
$condition[] = ['og.sku_name', 'like', '%'.$sku_name.'%'];
}
$order = 'og.sku_id desc';
$field = "og.sku_id,og.goods_name,og.sku_name,og.sku_image,og.goods_id,sum(og.num) as num,sum(og.goods_money) as goods_money,sum(IF(o.order_from = 'cashier', og.num, 0)) as offline_num, sum(IF(o.order_from <> 'cashier', og.num, 0)) as online_num,og.goods_class,og.goods_class_name";
$group = 'og.sku_id';
$order_model = new OrderCommon();
$res = $order_model->getOrderGoodsPageList($condition, $page, $page_size, $order, $field, $alias, $join, $group);
foreach($res['data']['list'] as &$val){
$val['online_num'] = numberFormat($val['online_num']);
$val['offline_num'] = numberFormat($val['offline_num']);
$val['price'] = sprintf("%.2f",$val['goods_money'] / $val['num']);
$val['spec_name'] = mb_substr($val['sku_name'], mb_strlen($val['goods_name']) + 1);
}
return $this->response($res);
}
/**
* 交接班销售导出
*/
public function changeShiftsSaleGoodsExport()
{
$record_id = $this->params['record_id'] ?? 0;
$sale_channel = $this->params['sale_channel'] ?? '';
$sku_name = $this->params['sku_name'] ?? '';
//交接班信息
$cashier_model = new CashierModel();
$record_info = $cashier_model->getChangeShiftsRecordInfo([['id', '=', $record_id]], '*')['data'];
$condition = [
['o.store_id', '=', $record_info['store_id']],
['o.pay_time', '>', $record_info['start_time']],
['o.pay_time', '<=', $record_info['end_time']],
];
$condition_desc = [];
if($sale_channel !== '' && $sale_channel !== 'all'){
if($sale_channel == 'offline'){
$condition[] = ['o.order_from', '=', 'cashier'];
$sale_channel_name = '线下';
}else{
$condition[] = ['o.order_from', '<>', 'cashier'];
$sale_channel_name = '线上';
}
$condition_desc[] = ['name' => '销售渠道', 'value' => $sale_channel_name];
}
if($sku_name !== ''){
$condition[] = ['og.sku_name', 'like', '%'.$sku_name.'%'];
$condition_desc[] = ['name' => '商品名称', 'value' => $sku_name];
}
$field = "og.sku_id,og.goods_name,og.sku_name,og.sku_image,og.goods_id,sum(og.num) as num,sum(og.goods_money) as goods_money,sum(IF(o.order_from = 'cashier', og.num, 0)) as offline_num, sum(IF(o.order_from <> 'cashier', og.num, 0)) as online_num";
$param = [
'site_id' => $this->site_id,
'store_id' => $this->store_id,
'from_type' => 'change_shifts_sale_goods',
'from_type_name' => '交接班商品销售',
'condition_desc' => $condition_desc,
'query' => [
'table' => 'order_goods',
'alias' => 'og',
'join' => [
['order o', 'og.order_id = o.order_id', 'inner'],
],
'group' => 'og.sku_id',
'condition' => $condition,
'field' => $field,
'chunk_field' => 'og.sku_id',
'chunk_order' => 'desc',
],
'export_field' => [
['field' => 'goods_name', 'name' => '商品名称'],
['field' => 'spec_name', 'name' => '商品规格'],
['field' => 'num', 'name' => '总数量'],
['field' => 'price', 'name' => '平均销售价'],
['field' => 'goods_money', 'name' => '销售总额'],
['field' => 'offline_num', 'name' => '线下销售'],
['field' => 'online_num', 'name' => '线上销售'],
],
'handle' => function($item_list){
foreach($item_list as &$val){
$val['num'] = numberFormat($val['num']);
$val['online_num'] = numberFormat($val['online_num']);
$val['offline_num'] = numberFormat($val['offline_num']);
$val['price'] = sprintf("%.2f",$val['goods_money'] / $val['num']);
$val['spec_name'] = mb_substr($val['sku_name'], mb_strlen($val['goods_name']) + 1);
}
return $item_list;
},
];
$export_model = new ExportModel();
$res = $export_model->export($param);
return $this->response($res);
}
/**
* 交班打印
* @return false|string
*/
public function printTicket()
{
$record_id = $this->params[ 'record_id' ] ?? 0;
$printer_ids = $this->params['printer_ids'] ?? 'all';
$printer_order_model = new PrinterOrder();
$res = $printer_order_model->printer([
'type' => 'change_shifts',
'site_id' => $this->site_id,
'store_id' => $this->store_id,
'userinfo' => $this->user_info,
'record_id' => $record_id,
'printer_ids' => $printer_ids,
]);
return $this->response($res);
}
/**
* 获取收银台收款设置
* @return false|string
*/
public function getCashierCollectMoneyConfig()
{
$res = (new CashierModel())->getCashierCollectMoneyConfig($this->site_id, $this->store_id);
return $this->response($res);
}
/**
* 收银台收款设置
* @return false|string
*/
public function setCashierCollectMoneyConfig()
{
$data = [
'reduction' => $this->params[ 'reduction' ] ?? 1,
'point' => $this->params[ 'point' ] ?? 1,
'balance' => $this->params[ 'balance' ] ?? 1,
'balance_safe' => $this->params[ 'balance_safe' ] ?? 0,
'sms_verify' => $this->params[ 'sms_verify' ] ?? 0,
'pay_type' => json_decode($this->params[ 'pay_type' ] ?? '[]', true),
];
$res = (new CashierModel())->setCashierCollectMoneyConfig($this->site_id, $this->store_id, $data);
return $this->response($res);
}
/**
* 详情信息
*/
public function defaultimg()
{
$upload_config_model = new ConfigModel();
$res = $upload_config_model->getDefaultImg($this->site_id, 'shop');
if (!empty($res[ 'data' ][ 'value' ])) {
return $this->response($this->success($res[ 'data' ][ 'value' ]));
} else {
return $this->response($this->error());
}
}
/**
* 设置收银台主题风格配置
* @return false|string
*/
public function setThemeConfig()
{
$data = [
'title' => $this->params[ 'title' ] ?? '',
'name' => $this->params[ 'name' ] ?? '',
'color' => $this->params[ 'color' ] ?? ''
];
$res = (new CashierModel())->setThemeConfig($data, $this->site_id);
return $this->response($res);
}
/**
* 获取收银台主题风格列表
* @return false|string
*/
public function getThemeList()
{
$res = (new CashierModel())->getThemeList();
return $this->response($res);
}
}

View File

@@ -0,0 +1,254 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cashier\model\order\CashierOrder as CashierOrderModel;
use addon\memberrecharge\model\MemberrechargeOrder;
use addon\printer\model\PrinterOrder;
use app\model\order\OrderCommon;
use app\storeapi\controller\BaseStoreApi;
use think\facade\Db;
use app\dict\order_refund\OrderRefundDict;
class Cashierorder extends BaseStoreApi
{
/**
* 收银订单列表
*/
public function lists()
{
$page_index = $this->params['page'] ?? 1;
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$store_id = $this->store_id;
$start_time = $this->params['start_time'] ?? '';
$end_time = $this->params['end_time'] ?? '';
$pay_type = $this->params['pay_type'] ?? '';
$search_text = $this->params['search_text'] ?? '';
$cashier_order_type = $this->params['cashier_order_type'] ?? '';
$order_id = $this->params['order_id'] ?? 0;
$order_type = $this->params[ 'order_type' ] ?? '';//订单类型
$order_from = $this->params[ 'order_from' ] ?? '';//订单来源
$order_status = $this->params[ 'order_status' ] ?? 'all';//订单状态
$order_model = new OrderCommon();
$condition = [
['site_id', '=', $this->site_id],
];
$condition[] = ['store_id', '=', $store_id];
if (!empty($start_time) && empty($end_time)) {
$condition[] = ['create_time', '>=', date_to_time($start_time)];
} elseif (empty($start_time) && !empty($end_time)) {
$condition[] = ['create_time', '<=', date_to_time($end_time)];
} elseif (!empty($start_time) && !empty($end_time)) {
$condition[] = ['create_time', 'between', [date_to_time($start_time), date_to_time($end_time)]];
}
//订单状态
if ($order_status !== 'all' && $order_status !== '') {
if ($order_status == 'refunding') {
$order_goods_list = $order_model->getOrderGoodsList([ [ 'refund_status', 'not in', [ OrderRefundDict::REFUND_NOT_APPLY, OrderRefundDict::REFUND_COMPLETE,OrderRefundDict::PARTIAL_REFUND ] ] ], 'order_id')[ 'data' ];
$order_id_arr = array_unique(array_column($order_goods_list, 'order_id'));
$condition[] = [ 'order_id', 'in', $order_id_arr ];
}elseif ($order_status == 'refunded') {
$order_goods_list = $order_model->getOrderGoodsList([ [ 'refund_status', 'in', [ OrderRefundDict::REFUND_COMPLETE,OrderRefundDict::PARTIAL_REFUND ] ] ], 'order_id')[ 'data' ];
$order_id_arr = array_unique(array_column($order_goods_list, 'order_id'));
$condition[] = [ 'order_id', 'in', $order_id_arr ];
}else{
$condition[] = [ 'order_status', '=', $order_status ];
}
}
$order_scene = $this->params['order_scene'] ?? '';
if ($order_scene !== 'all' && $order_scene !== '') {
$condition[] = ['order_scene', '=', $order_scene];
}
//收货方式
if ($order_type !== 'all' && $order_type !== '') {
if($order_scene == 'online'){
$condition[] = [ 'order_type', '=', $order_type ];
}else{
$condition[] = [ 'cashier_order_type', '=', $order_type ];
}
}
if (!empty($cashier_order_type)) {
$condition[] = ['cashier_order_type', '=', $cashier_order_type];
}
//订单来源
if ($order_from !== 'all' && $order_from !== '') {
$condition[] = [ 'order_from', '=', $order_from ];
}
//支付方式
if ($pay_type !== 'all' && $pay_type !== '') {
$condition[] = ['pay_type', '=', $pay_type];
}
if (!empty($search_text)) {
$condition[] = ['order_no|order_name|mobile|name|buyer_message|remark', 'like', '%' . $search_text . '%'];
}
if ($order_id) {
$condition[] = ['order_id', '=', $order_id];
}
$cashier_order = new CashierOrderModel();
$cashier_order_type_list = $cashier_order->getCashierOrderType();
$data = $order_model->getOrderPageList($condition, $page_index, $page_size, 'create_time desc')['data'];
if (!empty($data['list'])) {
foreach ($data['list'] as $k => $item) {
$data['list'][$k]['cashier_order_type_name'] = $cashier_order_type_list[$item['cashier_order_type']] ?? '';
}
}
return $this->response($this->success($data));
}
/**
* 收银订单详情
*/
public function detail()
{
$order_id = $this->params['order_id'] ?? '';
$order_model = new OrderCommon();
$detail = $order_model->getOrderDetail($order_id);
if (empty($detail['data'])) return $this->response($this->error(null, '未获取到订单信息'));
if ($detail['data']['site_id'] != $this->site_id) return $this->response($this->error(null, '未获取到订单信息'));
if ($detail['data']['store_id'] != $this->store_id) return $this->response($this->error(null, '未获取到订单信息'));
return $this->response($detail);
}
/**
* 获取支付方式
* @return false|string
*/
public function getOrderPayType()
{
$order_model = new CashierOrderModel();
$pay_type_list = $order_model->getPayType();
return $this->response($this->success($pay_type_list));
}
/**
* 删除订单
* @return array|false|string
*/
public function deleteOrder()
{
//订单关闭并删除
$order_id = $this->params['order_id'] ?? 0;
$order_common_model = new OrderCommon();
//关闭检测
$check_res = $order_common_model->activeOrderCloseCheck($order_id);
if($check_res['code'] < 0) return $this->response($check_res);
$close_result = $order_common_model->orderClose($order_id);
if ($close_result['code'] < 0) {
return $this->response($close_result);
}
$order_model = new CashierOrderModel();
$condition = [
['site_id', '=', $this->site_id],
['store_id', '=', $this->store_id],
['order_id', '=', $this->params['order_id'] ?? 0],
// [ 'order_status', '=', 0 ]
];
$res = $order_model->deleteOrder($condition);
return $this->response($res);
}
/**
* 订单备注
* @return false|string
*/
public function orderRemark()
{
$order_id = $this->params['order_id'] ?? 0;
$remark = $this->params['remark'] ?? '';
$order_model = new CashierOrderModel();
$res = $order_model->orderUpdate(['remark' => $remark], [
['site_id', '=', $this->site_id],
['store_id', '=', $this->store_id],
['order_id', '=', $order_id]
]);
return $this->response($res);
}
/**
* 打印订单小票
*/
public function printTicket()
{
$order_id = $this->params['order_id'] ?? 0;
$printer_type = $this->params['printer_type'] ?? 'order_pay'; // order_pay 支付 manual 手动
$printer_ids = $this->params['printer_ids'] ?? 'all';
$order_info = (new OrderCommon())->getOrderInfo([['order_id', '=', $order_id], ['store_id', '=', $this->store_id]], 'cashier_order_type')['data'];
if (empty($order_info)) return $this->response($this->error('', '未获取到订单信息'));
$printer_order_model = new PrinterOrder();
// 如果是充值订单
if ($order_info['cashier_order_type'] == 'recharge') {
$recharge_order = (new MemberrechargeOrder())->getMemberRechargeOrderInfo([['relate_type', '=', 'order'], ['relate_id', '=', $order_id]], 'order_id')['data'];
if (empty($recharge_order)) return $this->response($this->error('', '未获取到充值订单信息'));
$res = $printer_order_model->printer([
'order_id' => $recharge_order['order_id'],
'type' => 'recharge',
'printer_ids' => $printer_ids,
]);
} else {
$res = $printer_order_model->printer([
'order_id' => $order_id,
'type' => 'goodsorder',
'printer_type' => $printer_type,
'printer_ids' => $printer_ids,
]);
}
return $this->response($res);
}
/**
* 获取订单信息
*/
public function getOrderInfo()
{
$order_model = new OrderCommon();
$condition = [
['site_id', '=', $this->site_id],
['store_id', '=', $this->store_id],
['order_id', '=', $this->params['order_id'] ?? 0]
];
$res = $order_model->getOrderInfo($condition);
return $this->response($res);
}
/**
* 订单调价
* @return mixed
*/
public function adjustPrice()
{
$order_id = $this->params['order_id'] ?? 0;
$adjust_money = $this->params['adjust_money'] ?? 0;
$delivery_money = $this->params['delivery_money'] ?? 0;
$order_common_model = new OrderCommon();
$result = $order_common_model->orderAdjustMoney($order_id, $adjust_money, $delivery_money);
return $this->response($result);
}
}

View File

@@ -0,0 +1,191 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cashier\model\order\CashierOrderCreate as CashierOrderCreateModel;
use app\storeapi\controller\BaseStoreApi;
class Cashierordercreate extends BaseStoreApi
{
/**
* 商品计算
* @return false|string
*/
public function calculate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id,
'mobile' => $this->params[ 'mobile' ] ?? '',
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'goods',
'source' => $this->params[ 'source' ] ?? '',// is_buy 普通购买 cart 购物车 参与活动,
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
];
$res = $order_create_model->setParam($data)->calculate();
return $this->response($this->success($res));
}
/**
* 创建 收银单据
*/
public function create()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_id = $this->params[ 'order_id' ] ?? 0;
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'order_key' => $this->params['order_key'] ?? '',
'order_id' => $order_id,
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id ?? 0,
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'goods',
'source' => $this->params[ 'source' ] ?? '',// is_buy 普通购买 cart 购物车 参与活动,
'remark' => $this->params[ 'remark' ] ?? '',
'operator' => $this->user_info,//操作人员,
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
];
$res = $order_create_model->setParam($data)->create();
return $this->response($res);
}
/**
* 会员卡订单
* @return false|string
*/
// public function levelCreate()
// {
// $token = $this->checkToken();
// if ($token[ 'code' ] < 0) return $this->response($token);
// $order_create_model = new CashierOrderCreateModel();
// $data = [
// 'site_id' => $this->site_id,//站点id
// 'order_key' => $this->params['order_key'] ?? '',
// 'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
//
// 'store_id' => $this->store_id ?? 0,
//
// 'remark' => $this->params[ 'remark' ] ?? '',
// 'order_from' => $this->params[ 'app_type' ],
// 'order_from_name' => $this->params[ 'app_type_name' ],
// 'type' => 'level',
//
// 'cashier_type' => 'cashier',
// 'operator' => $this->user_info,//操作人员,
// ];
// if (empty($data[ 'sku_array' ])) {
// return $this->response($this->error('', '缺少必填参数商品数据'));
// }
// $res = $order_create_model->create($data);
// return $this->response($res);
// }
/**
* 充值订单
* @return false|string
*/
public function rechargeCreate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],//[{'recharge_id':10}, {'money':20}]
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id ?? 0,
'remark' => $this->params[ 'remark' ] ?? '',
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'recharge',
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
'operator' => $this->user_info, // 操作人员
];
$res = $order_create_model->setParam($data)->calculate();
$data['order_key'] = $res['order_key'];
$res = $order_create_model->setParam($data)->create();
return $this->response($res);
}
/**
* 卡项订单
* @return false|string
*/
public function cardCreate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'order_key' => $this->params['order_key'] ?? '',
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id ?? 0,
'remark' => $this->params[ 'remark' ] ?? '',
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'card',
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
'operator' => $this->user_info,//操作人员,
];
$res = $order_create_model->setParam($data)->create();
return $this->response($res);
}
/**
* 卡项订单计算
* @return false|string
*/
public function cardCalculate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->params[ 'store_id' ] ?? 0,
'mobile' => $this->params[ 'mobile' ] ?? '',
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'card',
'cashier_type' => 'cashier',
];
$res = $order_create_model->setParam($data)->calculate();
return $this->response($this->success($res));
}
}

View File

@@ -0,0 +1,233 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\dict\order_refund\OrderRefundDict;
use app\storeapi\controller\BaseStoreApi;
use app\model\order\OrderRefund as OrderRefundModel;
use addon\cashier\model\order\CashierOrderRefund as CashierOrderRefundModel;
class Cashierorderrefund extends BaseStoreApi
{
/**
* 商品计算
* @return false|string
*/
public function getRefundApplyData()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_refund_model = new CashierOrderRefundModel();
$params = [
'site_id' => $this->site_id,
'store_id' => $this->store_id,
'order_id' => $this->params[ 'order_id' ] ?? 0,
'refund_array' => $this->params[ 'refund_array' ] ?? '{}',// ['order_goods_id1','order_goods_id2','order_goods_id2']
];
$res = $order_refund_model->getRefundApplyData($params);
return $this->response($res);
}
public function refund()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_refund_model = new CashierOrderRefundModel();
$data = [
'site_id' => $this->site_id,
'store_id' => $this->store_id,
'order_id' => $this->params[ 'order_id' ] ?? 0,
'refund_transfer_type' => $this->params[ 'refund_transfer_type' ] ?? '',
'refund_array' => empty($this->params[ 'refund_array' ]) ? [] : json_decode($this->params[ 'refund_array' ], true),// {'order_goods_id1':{'refund_money':10}},
'refund_reason' => $this->params[ 'refund_reason' ] ?? '',
'refund_remark' => $this->params[ 'refund_remark' ] ?? '',
'operator' => $this->user_info,
];
$res = $order_refund_model->refund($data);
return $this->response($res);
}
/**
* 为维权列表
* @return false|string
*/
public function lists()
{
$page_index = $this->params[ 'page' ] ?? 1;
$search = $this->params[ 'search' ] ?? '';
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$order_refund_model = new OrderRefundModel();
$condition = [
[ 'nop.site_id', '=', $this->site_id ],
[ 'no.store_id', '=', $this->store_id ],
[ 'nop.refund_status', '<>', OrderRefundDict::REFUND_NOT_APPLY ],
];
//商品名称
if (!empty($search)) {
$condition[] = [ 'nop.sku_name|no.order_no', 'like', '%' . $search . '%' ];
}
$list = $order_refund_model->getRefundOrderGoodsPageList($condition, $page_index, $page_size, 'nop.refund_action_time desc');
return $this->response($list);
}
/**
* 详情
* @return false|string
*/
public function detail()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_goods_id = $this->params[ 'order_goods_id' ] ?? 0;
$order_refund_model = new OrderRefundModel();
$detail = $order_refund_model->getRefundDetail($order_goods_id, $this->site_id, $this->store_id);
return $this->response($detail);
}
/**
* 同意维权
* @return false|string
*/
public function agree()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_goods_id = $this->params[ 'order_goods_id' ] ?? 0;
$order_refund_model = new OrderRefundModel();
$data = [
'order_goods_id' => $order_goods_id
];
$res = $order_refund_model->orderRefundConfirm($data, $this->user_info);
return $this->response($res);
}
/**
* 拒绝维权
* @return false|string
*/
public function refuse()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_goods_id = $this->params[ 'order_goods_id' ] ?? 0;
$refund_refuse_reason = $this->params[ 'refund_refuse_reason' ] ?? '';
$order_refund_model = new OrderRefundModel();
$data = [
'order_goods_id' => $order_goods_id,
'refund_refuse_reason' => $refund_refuse_reason
];
$log_data = [
'uid' => $this->user_info[ 'uid' ],
'nick_name' => $this->user_info[ 'username' ],
'action' => '商家拒绝了维权',
'action_way' => 2
];
$res = $order_refund_model->orderRefundRefuse($data, $this->user_info, $refund_refuse_reason, $log_data);
return $this->response($res);
}
/**
* 关闭维权
* @return false|string
*/
public function close()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_goods_id = $this->params[ 'order_goods_id' ] ?? 0;
$order_refund_model = new OrderRefundModel();
$res = $order_refund_model->orderRefundClose($order_goods_id, $this->site_id, $this->user_info);
return $this->response($res);
}
/**
* 获取订单项退款信息
* @return false|string
*/
public function refundInfo()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_goods_id = $this->params[ 'order_goods_id' ] ?? 0;
$order_refund_model = new OrderRefundModel();
$res = $order_refund_model->getOrderGoodsRefundInfo($order_goods_id, $this->site_id);
return $this->response($res);
}
/**
* 维权通过
* @return false|string
*/
public function complete()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_goods_id = $this->params[ 'order_goods_id' ] ?? 0;
$refund_money_type = $this->params[ 'refund_money_type' ] ?? '';
$shop_refund_remark = $this->params[ 'shop_refund_remark' ] ?? '';
$refund_real_money = $this->params[ 'refund_real_money' ] ?? 0;
$is_deposit_back = $this->params[ 'is_deposit_back' ] ?? 1;
$order_refund_model = new OrderRefundModel();
$data = [
'order_goods_id' => $order_goods_id,
'refund_money_type' => $refund_money_type,
'shop_refund_remark' => $shop_refund_remark,
'refund_real_money' => $refund_real_money,
'is_deposit_back' => $is_deposit_back
];
$log_data = [
'uid' => $this->user_info[ 'uid' ],
'nick_name' => $this->user_info[ 'username' ],
'action' => '商家对维权进行了转账,维权结束',
'action_way' => 2
];
$res = $order_refund_model->orderRefundFinish($data, $this->user_info, $log_data);
return $this->response($res);
}
/**
* 维权收货
* @return false|string
*/
public function receive()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_goods_id = $this->params[ 'order_goods_id' ] ?? 0;
$is_refund_stock = $this->params[ 'is_refund_stock' ] ?? 0; // 是否入库
$order_refund_model = new OrderRefundModel();
$data = [
'order_goods_id' => $order_goods_id,
'is_refund_stock' => $is_refund_stock
];
$res = $order_refund_model->orderRefundTakeDelivery($data, $this->user_info);
return $this->response($res);
}
}

View File

@@ -0,0 +1,167 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cashier\model\order\CashierOrderCalculate;
use addon\cashier\model\order\CashierOrderPay;
use app\model\system\Pay as PayModel;
use app\storeapi\controller\BaseStoreApi;
/**
* 收银支付
* Class Pay
* @package app\shop\controller
*/
class Cashierpay extends BaseStoreApi
{
/**
* 计算
* @return false|string
*/
public function payCalculate()
{
$out_trade_no = $this->params[ 'out_trade_no' ] ?? '';
$promotion = !empty($this->params[ 'promotion' ]) ? json_decode($this->params[ 'promotion' ], true) : [];
$data = [
'pay_type' => $this->params[ 'pay_type' ] ?? '',
'site_id' => $this->site_id,
'out_trade_no' => $out_trade_no,
'store_id' => $this->store_id ?? 0,
'promotion' => $promotion,
'member_id' => $this->params[ 'member_id' ],
'cash' => $this->params[ 'cash' ] ?? 0
];
$cashier_order_calculate_model = new CashierOrderCalculate();
$result = $cashier_order_calculate_model->calculate($data);
//记录缓存(操作记录保存)
$cashier_order_pay_model = new CashierOrderPay();
$cashier_order_pay_model->setCache($out_trade_no, [ 'promotion' => $promotion, 'member_id' => $this->params[ 'member_id' ] ?? 0 ]);
return $this->response($result);
}
/**
* 订单支付
*/
public function confirm()
{
$out_trade_no = $this->params[ 'out_trade_no' ] ?? '';
$promotion = !empty($this->params[ 'promotion' ]) ? json_decode($this->params[ 'promotion' ], true) : [];
$cashier_order_pay_model = new CashierOrderPay();
$data = [
'pay_type' => $this->params[ 'pay_type' ] ?? '',
'site_id' => $this->site_id,//站点id
'out_trade_no' => $out_trade_no,
'store_id' => $this->store_id ?? 0,
'promotion' => $promotion,
'member_id' => $this->params[ 'member_id' ],
'cash' => $this->params[ 'cash' ] ?? 0
];
$result = $cashier_order_pay_model->confirm($data);
return $this->response($result);
}
/**
* 支付信息
* @return false|string
*/
public function info()
{
$out_trade_no = $this->params[ 'out_trade_no' ];
$pay = new PayModel();
$info = $pay->getPayInfo($out_trade_no);
if (!empty($info[ 'data' ])) {
$res = event('PayOrderQuery', [ 'relate_id' => $info[ 'data' ][ 'id' ] ]);
$info['data']['event_res'] = $res;
}
return $this->response($info);
}
/**
* 生成支付二维码
*/
public function payQrcode()
{
$out_trade_no = $this->params[ 'out_trade_no' ];
$cashier_order_pay_model = new CashierOrderPay();
$data = [
'site_id' => $this->site_id,//站点id
'out_trade_no' => $this->params[ 'out_trade_no' ] ?? '',
'store_id' => $this->store_id ?? 0,
];
$result = $cashier_order_pay_model->createPay($data);
if ($result[ 'code' ] < 0) {
return $this->response($result);
}
if (!empty($result[ 'data' ])) $out_trade_no = $result[ 'data' ];
$data = [];
$pay = new PayModel();
foreach (event('PayType', []) as $item) {
$result = $pay->pay($item[ 'pay_type' ], $out_trade_no, 'cashier', 0);
if ($result && $result[ 'code' ] >= 0 && !empty($result['data']['qrcode'])) {
$data[] = [
'pay_type' => $item['pay_type'],
'pay_type_name' => $item['pay_type_name'],
'qrcode' => $result['data']['qrcode'],
'logo' => img($item['logo']),
'out_trade_no' => $out_trade_no
];
}
}
return $this->response($this->success($data));
}
/**
* 创建支付单据
* @return false|string
*/
public function createPay()
{
$cashier_order_pay_model = new CashierOrderPay();
$data = [
'site_id' => $this->site_id,//站点id
'out_trade_no' => $this->params[ 'out_trade_no' ] ?? '',
'store_id' => $this->store_id ?? 0,
];
$result = $cashier_order_pay_model->createPay($data);
return $this->response($result);
}
/**
* 会员付款码支付 (已废弃)
*/
public function paymentCodePay()
{
$out_trade_no = $this->params[ 'out_trade_no' ];
$auth_code = $this->params[ 'auth_code' ];
return $this->response($this->error());
}
/**
* 支付类型
*/
public function payType()
{
$pay = new PayModel();
$info = $pay->getPayType($this->params);
$temp = empty($info) ? [] : $info;
$type = [];
foreach ($temp[ 'data' ] as $k => $v) {
$type[] = $v['pay_type'];
}
return $this->response($this->success($type));
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cashier\model\Cashier as CashierModel;
use app\storeapi\controller\BaseStoreApi;
use app\model\order\Config as OrderConfigModel;
/**
* Class Config
* @package addon\cashier\storeapi\controller
*/
class Config extends BaseStoreApi
{
public function __construct()
{
$this->site_id = request()->siteid();
$this->params = input();
}
/**
* 获取收银台主题风格配置
* @return false|string
*/
public function getThemeConfig()
{
$res = (new CashierModel())->getThemeConfig($this->site_id)[ 'data' ][ 'value' ];
return $this->response($this->success($res));
}
/**
* 设置收银台会员搜索方式配置
* @return false|string
*/
public function setMemberSearchWayConfig()
{
$data = [
'way' => $this->params[ 'way' ] ?? 'exact'
];
$res = (new CashierModel())->setMemberSearchWayConfig($data, $this->store_id, $this->site_id);
return $this->response($this->success($res));
}
/**
* 获取收银台会员搜索方式配置
* @return false|string
*/
public function getMemberSearchWayConfig()
{
$res = (new CashierModel())->getMemberSearchWayConfig($this->store_id, $this->site_id)[ 'data' ][ 'value' ];
return $this->response($this->success($res));
}
/**
* 插件是否存在
*/
public function addonIsExist()
{
$addon = new \app\model\system\Addon();
$addon_is_exist = $addon->addonIsExist();
return $this->response($this->success($addon_is_exist));
}
/**
* 订单提醒
*/
public function orderRemind()
{
$config_model = new OrderConfigModel();
$config_info = $config_model->getOrderRemindConfig($this->site_id)['data']['value'];
return $this->response($this->success($config_info));
}
}

View File

@@ -0,0 +1,616 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\supply\model\Supplier as SupplierModel;
use app\dict\goods\GoodsDict;
use app\model\goods\Goods as GoodsModel;
use app\model\goods\GoodsBrand as GoodsBrandModel;
use app\model\goods\GoodsCategory;
use app\model\storegoods\StoreGoods as StoreGoodsModel;
use app\model\system\Export as ExportModel;
use app\model\web\Config as ConfigModel;
use app\storeapi\controller\BaseStoreApi;
use think\facade\Db;
/**
* Class Goods
* @package addon\cashier\storeapi\controller
*/
class Goods extends BaseStoreApi
{
/**
* 获取商品分类的组织
* @return false|string
*/
public function category()
{
$level = $this->params['level'] ?? 1;
$category_ids = $this->params['category_ids'] ?? '';
$category_model = new GoodsCategory();
$condition = [
['is_show', '=', 0],
['level', '<=', $level],
['site_id', '=', $this->site_id]
];
if ($category_ids) {
$condition[] = ['category_id', 'in', $category_ids];
}
$list = $category_model->getCategoryList($condition, 'pid,category_id,category_name,image,level', 'sort asc,category_id desc')['data'];
$tree = list_to_tree($list, 'category_id', 'pid', 'child_list', 0);
$tree = keyArrToIndexArr($tree, 'child_list');
return $this->response($category_model->success($tree));
}
public function page()
{
$page_index = $this->params['page'] ?? 1;
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$goods_category = $this->params['category'] ?? 'all';
$search_text = $this->params['search_text'] ?? '';
$goods_class = $this->params['goods_class'] ?? 'all';
$status = $this->params['status'] ?? 1;
$start_price = $this->params['start_price'] ?? 0;
$end_price = $this->params['end_price'] ?? 0;
$goods_state = $this->params['goods_state'] ?? 'all';
$sku_no = $this->params['sku_no'] ?? '';
$scene = $this->params['scene'] ?? 'common';//普通common 开单billing
$model = new GoodsModel();
$condition = [
['g.site_id', '=', $this->site_id],
['g.is_delete', '=', 0],
['g.sale_store', 'like', ['%all', '%,' . $this->store_id . ',%'], 'or'],
// ['', 'exp', Db::raw("(g.sale_channel = 'all' OR g.sale_channel = 'offline')")]
];
if ($goods_class !== 'all') {
$condition[] = ['g.goods_class', 'in', $goods_class];
} else {
$condition[] = ['g.goods_class', 'in', '1,4,5,6'];
}
if ($goods_category != 'all') $condition[] = ['g.category_id', 'like', "%,{$goods_category},%"];
if (!empty($search_text)) {
$goods_sku_list = $model->getGoodsSkuList([['', 'exp', Db::raw("FIND_IN_SET('{$search_text}', sku_no)")]], 'goods_id')['data'];
$goods_id_arr = array_unique(array_column($goods_sku_list, 'goods_id'));
if (!empty($goods_id_arr)) {
$condition[] = ['g.goods_id', 'in', $goods_id_arr];
} else {
$condition[] = ['g.goods_name', 'like', "%{$search_text}%"];
}
}
if ($status !== 'all') {
if ($status == '0') {
$condition[] = ['', 'exp', Db::raw('sg1.status is null or sg1.status = 0')];
} else {
$condition[] = ['sg1.status', '=', $status];
}
}
if ($goods_state !== 'all') {
$condition[] = ['g.goods_state', '=', $goods_state];
}
if (!empty($start_price)) {
$condition[] = ['g.price', '>=', $start_price];
}
if (!empty($end_price)) {
$condition[] = ['g.price', '<=', $end_price];
}
if ($sku_no) {
$sku_list = $model->getGoodsSkuList([['sku_no', 'like', '%' . $sku_no . '%']], 'goods_id')['data'];
$goods_ids = array_column($sku_list, 'goods_id');
$goods_ids = array_unique($goods_ids);
$condition[] = ['g.goods_id', 'in', $goods_ids];
}
$field = 'g.goods_id,g.goods_name,g.goods_class,g.goods_class_name,g.introduction,g.goods_image,g.goods_state,g.sku_id,g.price,gs.discount_price,g.goods_spec_format,g.is_unify_price,g.pricing_type,
IFNULL(IF(g.is_unify_price = 1,g.price,sg1.price), g.price) as price, IFNULL(IF(g.is_unify_price = 1,gs.discount_price,sg1.price), gs.discount_price) as discount_price,g.unit,
IFNULL(sg1.price, 0) as store_price,IFNULL(sg1.status, 0) as store_status';
$join = [
['goods_sku gs', 'gs.sku_id = g.sku_id', 'left'],
['store_goods sg1', 'g.goods_id=sg1.goods_id and (sg1.store_id is null or sg1.store_id=' . $this->store_id . ')', 'left'],
];
//todo 这部分可以封装
$stock_store_id = (new \app\model\store\Store())->getStoreStockTypeStoreId(['store_id' => $this->store_id])['data'] ?? 0;
if ($stock_store_id == $this->store_id) {
$field .= ', IFNULL(sg1.stock, 0) as stock';
} else {
$join[] = ['store_goods sg2', 'g.goods_id = sg2.goods_id and sg2.store_id=' . $stock_store_id, 'left'];
$field .= ', IFNULL(sg2.stock, 0) as stock';
}
$res = $model->getGoodsPageList($condition, $page_index, $page_size, 'g.sort asc,g.create_time desc', $field, 'g', $join);
//开单页面库存转换处理
if(addon_is_exit('stock')){
if($scene == 'billing'){
$goods_ids = array_column($res['data']['list'], 'goods_id');
$field = 'gs.goods_id,gs.sku_id';
$alias = 'gs';
$join = [
['goods g', 'g.goods_id = gs.goods_id', 'inner'],
[
'store_goods_sku sgs',
'sgs.sku_id = gs.sku_id and sgs.store_id = ' . $this->store_id,
'left'
]
];
//判断是统一库存还是独立库存
$store_model = new \app\model\store\Store();
$store_info = $store_model->getStoreInfo([['store_id', '=', $this->store_id]])['data'];
if ($store_info[ 'stock_type' ] == 'store') {
$field .= ',IFNULL(sgs.stock, 0) as stock';
}else{
$field .= ',gs.stock';
}
$condition = [
['gs.is_delete', '=', 0],
['sgs.status', '=', 1],
['gs.goods_id', 'in', $goods_ids],
['gs.site_id', '=', $this->site_id]
];
$sku_list = $model->getGoodsSkuList($condition, $field, '', null, $alias, $join)['data'];
$sku_list = $model->goodsStockTransform($sku_list, $this->store_id, 'store');
$goods_stocks = [];
foreach ($goods_ids as $goods_id){
$goods_stocks[$goods_id] = 0;
}
foreach($sku_list as $sku_info){
$goods_id = $sku_info['goods_id'];
$goods_stocks[$goods_id] += $sku_info['stock'];
}
foreach($res['data']['list'] as &$goods_info){
$goods_info['stock'] = $goods_stocks[$goods_info['goods_id']];
}
}
}
return $this->response($res);
}
/**
* 商品详情
* @return false|string
*/
public function detail()
{
$goods_id = $this->params['goods_id'] ?? 0;
$goods_model = new GoodsModel();
$field = 'g.goods_id, g.goods_name, g.introduction,g.goods_class,g.is_virtual, g.goods_class_name, g.goods_image, g.goods_state, g.sku_id, g.price, g.unit, g.cost_price, g.category_id, g.brand_name,g.is_unify_price,g.pricing_type,
sg1.price as store_price, sg1.cost_price as store_cost_price, sg1.status as store_status';
$join = [
['store_goods sg1', 'g.goods_id=sg1.goods_id and sg1.store_id=' . $this->store_id, 'left'],
];
//todo 这部分可以封装
$stock_store_id = (new \app\model\store\Store())->getStoreStockTypeStoreId(['store_id' => $this->store_id])['data'] ?? 0;
if ($stock_store_id == $this->store_id) {
$field .= ',sg1.stock';
} else {
$join[] = ['store_goods sg2', 'g.goods_id = sg2.goods_id and sg2.store_id=' . $stock_store_id, 'left'];
$field .= ', sg2.stock';
}
$condition = [
['g.site_id', '=', $this->site_id],
['g.is_delete', '=', 0],
['g.goods_id', '=', $goods_id],
['g.sale_store', 'like', ['%all%', '%,' . $this->store_id . ',%'], 'or'],
// ['', 'exp', Db::raw("(g.sale_channel = 'all' OR g.sale_channel = 'offline')")]
];
$goods_info = $goods_model->getGoodsInfo($condition, $field, 'g', $join)['data'];
if (empty($goods_info)) return $this->response($goods_model->error(null, '商品信息缺失'));
//查询商品规格
$sku_filed = 'IFNULL(sgs1.is_delivery_restrictions, 1) as is_delivery_restrictions ,sku.sku_id,sku.sku_name,sku.sku_no,sku.price,sku.discount_price,sku.cost_price,sku.sku_image,sku.sku_images,sku.spec_name,sku.unit,
IF(sku.is_unify_price = 1,sku.discount_price,sgs1.price) as store_price, sgs1.cost_price as store_cost_price, sgs1.status as store_status';
$join = [
['store_goods_sku sgs1', 'sku.sku_id=sgs1.sku_id and sgs1.store_id=' . $this->store_id, 'left'],
];
if ($stock_store_id == $this->store_id) {
$sku_filed .= ', sgs1.stock, IFNULL(sgs1.real_stock, 0) as real_stock';
} else {
$join[] = ['store_goods_sku sgs2', 'sku.sku_id = sgs2.sku_id and sgs2.store_id=' . $stock_store_id, 'left'];
$sku_filed .= ', sgs2.stock, IFNULL(sgs2.real_stock, 0) as real_stock';
}
$goods_info['sku_list'] = $goods_model->getGoodsSkuList([['sku.goods_id', '=', $goods_id], ['sku.site_id', '=', $this->site_id]], $sku_filed, 'sku.sku_id asc', 0, 'sku', $join)['data'];
return $this->response($goods_model->success($goods_info));
}
/**
* 上下架
*/
public function setStatus()
{
$goods_id = $this->params['goods_id'] ?? 0;
$status = $this->params['status'] ?? 0;
$model = new StoreGoodsModel();
$res = $model->modifyGoodsState($goods_id, $status, $this->site_id, $this->store_id);
return $this->response($res);
}
/**
* 商品编辑
*/
public function editGoods()
{
$goods_sku_array = isset($this->params['goods_sku_list']) ? json_decode($this->params['goods_sku_list'], true) : [];
$model = new StoreGoodsModel();
$res = $model->editStoreGoods($goods_sku_array, $this->site_id, $this->store_id, $this->uid);
return $this->response($res);
}
/**
* 获取商品规格
*/
public function skuList()
{
$goods_id = $this->params['goods_id'] ?? 0;
$sku_filed = 'sku.goods_id,sku.sku_id,sku.sku_name,sku.goods_name,sku.sku_no,sku.sku_image,sku.sku_images,sku.spec_name,sku.goods_spec_format,sku.unit,IFNULL(IF(g.is_unify_price = 1,sku.price,sgs.price), sku.price) as price,g.goods_class,sku.pricing_type';
$join = [
['goods g', 'sku.goods_id=g.goods_id', 'inner'],
['store_goods_sku sgs', 'sku.sku_id=sgs.sku_id and sgs.store_id=' . $this->store_id, 'left'],
];
$stock_store_id = (new \app\model\store\Store())->getStoreStockTypeStoreId(['store_id' => $this->store_id])['data'] ?? 0;
if ($stock_store_id == $this->store_id) {
$sku_filed .= ', IFNULL(sgs.stock, 0) as stock';
} else {
$join[] = ['store_goods_sku sgs2', 'sku.sku_id = sgs2.sku_id and sgs2.store_id=' . $stock_store_id, 'left'];
$sku_filed .= ', IFNULL(sgs2.stock, 0) as stock';
}
$goods_model = new GoodsModel();
$sku_list = $goods_model->getGoodsSkuList([['sku.goods_id', '=', $goods_id], ['sku.site_id', '=', $this->site_id]], $sku_filed, 'sku.sku_id asc', 0, 'sku', $join)['data'];
//库存转换
$sku_list = $goods_model->goodsStockTransform($sku_list, $this->store_id, 'store');
return $this->response($this->success($sku_list));
}
/**
* 查询sku信息
* @return false|string
*/
public function skuInfo()
{
$sku_id = $this->params['sku_id'] ?? 0;
$sku_no = $this->params['sku_no'] ?? '';
$condition = [
['sku.site_id', '=', $this->site_id],
['sku.is_delete', '=', 0],
];
if ($sku_id) $condition[] = ['sku.sku_id', '=', $sku_id];
// 检测是否存在称重商品插件
if (!empty($sku_no)) {
$condition[] = ['', 'exp', Db::raw("FIND_IN_SET('{$sku_no}', sku.sku_no)")];
}
$sku_filed = 'g.goods_class,sku.goods_id,sku.sku_id,sku.sku_name,sku.goods_name,sku.sku_no,sku.sku_image,sku.sku_images,sku.spec_name,sku.goods_spec_format,sku.unit,IFNULL(IF(g.is_unify_price = 1,sku.price,sgs.price), sku.price) as price,sku.cost_price,sku.pricing_type,sku.goods_state';
$join = [
['goods g', 'sku.goods_id=g.goods_id', 'inner'],
['store_goods_sku sgs', 'sku.sku_id=sgs.sku_id and sgs.store_id=' . $this->store_id, 'inner'],
];
$stock_store_id = (new \app\model\store\Store())->getStoreStockTypeStoreId(['store_id' => $this->store_id])['data'] ?? 0;
if ($stock_store_id == $this->store_id) {
$sku_filed .= ', IFNULL(sgs.stock, 0) as stock, IFNULL(sgs.real_stock, 0) as real_stock';
} else {
$join[] = ['store_goods_sku sgs2', 'sku.sku_id = sgs2.sku_id and sgs2.store_id=' . $stock_store_id, 'left'];
$sku_filed .= ', IFNULL(sgs2.stock, 0) as stock, IFNULL(sgs2.real_stock, 0) as real_stock';
}
$goods_model = new GoodsModel();
$sku_info = $goods_model->getGoodsSkuInfo($condition, $sku_filed, 'sku', $join);
if (empty($sku_info['data']) && (strlen($sku_no) == 13 || strlen($sku_no) == 18)) {
$plu = intval(substr($sku_no, 2, 5));
array_pop($condition);
$condition[] = ['sku.plu', '=', $plu];
$sku_info = $goods_model->getGoodsSkuInfo($condition, $sku_filed, 'sku', $join);
if (!empty($sku_info['data'])) {
// 如果格式为 两位店号 + 五位plu码 + 五位重量 + 一位校验码
if (strlen($sku_no) == 13 || strlen($sku_no) == 18) {
$weigh = intval(substr($sku_no, 7, 5));
$sku_info['data']['weigh'] = $sku_info['data']['pricing_type'] == 'weight' ? round($weigh / 1000, 3) : $weigh;
}
// 如果格式为 两位店号 + 五位plu码 + 五位重量 + 五位金额 + 一位校验码
if (strlen($sku_no) == 18) {
$adjust_price = round(intval(substr($sku_no, 12, 5)) / 100, 2);
$sku_info['data']['goods_money'] = $adjust_price;
}
}
}
return $this->response($sku_info);
}
/**
* 用于商品选择的商品
*/
public function getGoodsListBySelect()
{
$page = $this->params['page'] ?? 1;
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$search_text = $this->params['search_text'] ?? '';
$goods_ids = $this->params['goods_ids'] ?? '';
$is_virtual = $this->params['is_virtual'] ?? '';// 是否虚拟类商品0实物1.虚拟)
$min_price = $this->params['min_price'] ?? '';
$max_price = $this->params['max_price'] ?? '';
$category_id = $this->params['category_id'] ?? '';// 商品分类id
$promotion_type = $this->params['promotion_type'] ?? '';
$label_id = $this->params['label_id'] ?? '';
$select_type = $this->params['select_type'] ?? '';
$sale_channel = $this->params['sale_channel'] ?? ''; // 销售渠道 all 线上线下销售 online 线上销售 offline线下销售
$goods_class_all = $this->params['goods_class_all'] ?? '';
$goods_class = $this->params['goods_class'] ?? '';
$brand_id = $this->params['brand_id'] ?? '';
$supplier_id = $this->params['supplier_id'] ?? '';
$goods_model = new GoodsModel();
$condition = [
['is_delete', '=', 0],
['goods_state', '=', 1],
['goods_stock', '>', 0],
['site_id', '=', $this->site_id]
];
if(!empty($goods_class_all)){
$goods_class_all = explode(',', $goods_class_all);
}else{
$goods_class_all = [ GoodsDict::real, GoodsDict::weigh, GoodsDict::service, GoodsDict::card ];
}
$condition[] = [ 'goods_class', 'in', $goods_class_all ];
if (!empty($search_text)) {
$search_text = paramFilter($search_text);
$goods_sku_list = $goods_model->getGoodsSkuList([['sku_no', 'like', '%' . $search_text . '%']], 'goods_id')['data'];
$goods_id_arr = array_unique(array_column($goods_sku_list, 'goods_id'));
if (!empty($goods_id_arr)) {
$goods_ids = join(',', $goods_id_arr);
$condition[] = ['', 'exp', \think\facade\Db::raw("goods_name like '%{$search_text}%' or goods_id in ({$goods_ids})")];
} else {
$condition[] = ['goods_name', 'like', "%{$search_text}%"];
}
}
if ($is_virtual !== '') {
$condition[] = ['is_virtual', '=', $is_virtual];
}
if ($select_type == 'selected') {
$condition[] = ['goods_id', 'in', $goods_ids];
}
if (!empty($category_id)) {
if (!empty($goods_class) && $goods_class == GoodsDict::service) {
$condition[] = ['service_category', 'like', '%,' . $category_id . ',%'];
} else {
$condition[] = ['category_id', 'like', '%,' . $category_id . ',%'];
}
}
if (!empty($sale_channel)) {
$condition[] = ['sale_channel', 'in', $sale_channel];
}
if (!empty($promotion_type)) {
$condition[] = ['promotion_addon', 'like', "%{$promotion_type}%"];
}
if (!empty($label_id)) {
$condition[] = ['label_id', '=', $label_id];
}
if ($min_price != '' && $max_price != '') {
$condition[] = ['price', 'between', [$min_price, $max_price]];
} elseif ($min_price != '') {
$condition[] = ['price', '<=', $min_price];
} elseif ($max_price != '') {
$condition[] = ['price', '>=', $max_price];
}
if(!empty($goods_class)){
$condition[] = ['goods_class', '=', $goods_class];
}
if(!empty($brand_id)){
$condition[] = ['brand_id', '=', $brand_id];
}
if(!empty($supplier_id)){
$condition[] = ['supplier_id', '=', $supplier_id];
}
$config_model = new ConfigModel();
$sort_config = $config_model->getGoodsSort($this->site_id)['data']['value'];
$order = 'sort ' . $sort_config['type'] . ',create_time desc';
$field = 'goods_id,goods_name,goods_class_name,goods_image,price,goods_stock,is_virtual';
$goods_list = $goods_model->getGoodsPageList($condition, $page, $page_size, $order, $field)['data'] ?? [];
if (!empty($goods_list['list'])) {
$temp_sku_list = $goods_model->getGoodsSkuList([['goods_id', 'in', array_column($goods_list['list'], 'goods_id')], ['site_id', '=', $this->site_id]], 'sku_id,sku_name,price,stock,sku_image,goods_id,goods_class_name', 'price asc')['data'] ?? [];
$sku_column = [];
if (!empty($temp_sku_list)) {
foreach ($temp_sku_list as $item) {
$sku_column[$item['goods_id']][] = $item;
}
}
foreach ($goods_list['list'] as &$v) {
$v['sku_list'] = $sku_column[$v['goods_id']] ?? [];
}
}
return $this->response($this->success($goods_list));
}
/**
* 用于规格选择的
*/
public function getSkuListBySelect()
{
$page = $this->params['page'] ?? 1;
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$goods_id = $this->params['goods_id'] ?? 0;
$search = $this->params['search_text'] ?? '';
$category_id = $this->params['category_id'] ?? '';
$temp_store_id = $this->params[ 'temp_store_id' ] ?? 0;
$store_id = $temp_store_id > 0 ? $temp_store_id : $this->store_id;
$goods_class_all = $this->params['goods_class_all'] ?? '';
$goods_class = $this->params['goods_class'] ?? '';
$brand_id = $this->params['brand_id'] ?? '';
$supplier_id = $this->params['supplier_id'] ?? '';
$selected_sku_ids = $this->params['selected_sku_ids'] ?? '';
$unselected_sku_ids = $this->params['unselected_sku_ids'] ?? '';
$goods_model = new GoodsModel();
$alias = 'gs';
$join = [
['goods g', 'g.goods_id = gs.goods_id', 'left'],
['store_goods_sku sgs', 'sgs.sku_id = gs.sku_id and (sgs.store_id is null or sgs.store_id = ' . $store_id . ')', 'left'],
['supplier s', 'g.supplier_id = s.supplier_id', 'left'],
];
$condition = [
[ 'g.is_delete', '=', 0 ],
[ 'g.goods_state', '=', 1 ],
[ 'gs.site_id', '=', $this->site_id ],
[ 'g.is_virtual', '=', 0]
];
if(!$goods_class_all){
$goods_class_all = explode(',', $goods_class_all);
}else{
$goods_class_all = [ GoodsDict::real, GoodsDict::weigh, GoodsDict::service, GoodsDict::card ];
}
$condition[] = [ 'g.goods_class', 'in', $goods_class_all ];
if (!empty($search)) {
$condition[] = [ 'gs.sku_name|gs.spec_name|g.goods_name|gs.sku_no', 'like', '%' . $search . '%' ];
}
if (!empty($goods_id)) {
$condition[] = [ 'g.goods_id', '=', $goods_id ];
}
if(!empty($selected_sku_ids)){
$condition[] = ['gs.sku_id', 'in', $selected_sku_ids];
}
if(!empty($unselected_sku_ids)){
$condition[] = ['gs.sku_id', 'not in', $unselected_sku_ids];
}
if ($store_id > 0) {
//查询商品支持门店(支持当前门店或全部)
$condition[] = [ 'g.sale_store', 'like', [ '%,' . $store_id . ',%', '%all%'], 'or' ];
}
if (!empty($category_id)) {
$condition[] = [ 'g.category_id', 'like', '%,' . $category_id . ',%' ];
}
if(!empty($goods_class)){
$condition[] = ['g.goods_class', '=', $goods_class];
}
if(!empty($brand_id)){
$condition[] = ['g.brand_id', '=', $brand_id];
}
if(!empty($supplier_id)){
$condition[] = ['g.supplier_id', '=', $supplier_id];
}
$field = 'gs.sku_id, gs.goods_id, gs.sku_name, gs.sku_no, gs.market_price,gs.weight,gs.goods_class, gs.goods_name, gs.spec_name, gs.sku_image,gs.unit, sgs.stock,sgs.real_stock,sgs.store_id, sgs.price,sgs.cost_price,g.category_id,g.category_json,g.brand_id,g.brand_name,g.label_id,g.label_name';
$field .= ',IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as price';
$field .= ',IFNULL(s.title,"") as supplier_name';
$res = $goods_model->getGoodsSkuPageList($condition, $page, $page_size, 'gs.goods_id desc, gs.create_time desc, gs.sku_id desc', $field, $alias, $join);
$res['data']['list'] = $goods_model->getCategoryNames($res['data']['list']);
return $this->response($res);
}
/**
* 设置不同门店 sku 同城配送模式 非起送 商品业务
*/
public function setGoodsLocalRestrictions()
{
$goods_sku_array = isset($this->params['goods_sku_list']) ? json_decode($this->params['goods_sku_list'], true) : [];
$model = new \app\model\goods\GoodsLocalRestrictions();
$res = $model->setRestrictions($goods_sku_array, $this->site_id, $this->store_id);
return $this->response($res);
}
/**
* 搜索条件
*/
public function screen()
{
$requires = $this->params['requires'] ?? 'all';
if($requires == 'all') $requires = 'supplier,brand';
$requires = explode(',', $requires);
$res = [];
foreach($requires as $require){
switch($require){
case 'supplier':
$res['is_install_supply'] = addon_is_exit('supply');;
if($res['is_install_supply']){
$supplier_model = new SupplierModel();
$res['supplier_list'] = $supplier_model->getSupplyList([['supplier_site_id', '=', $this->site_id]], 'supplier_id,title', 'supplier_id desc')['data'];
}
break;
case 'brand':
$goods_brand_model = new GoodsBrandModel();
$res['brand_list'] = $goods_brand_model->getBrandList([['site_id', '=', $this->site_id]], 'brand_id,brand_name', 'sort asc')['data'];
break;
}
}
return $this->response($this->success($res));
}
/**
* 导出打印价格标签数据
*/
public function exportPrintPriceTagData()
{
$json = $this->params['data'] ?? '';
$data = json_decode($json, true);
$param = [
'site_id' => $this->site_id,
'store_id' => $this->store_id,
'from_type' => 'print_price_tag',
'from_type_name' => '打印价格标签',
'condition_desc' => [],
'export_field' => [
/*['field' => 'print_num', 'name' => '打印份数'],*/
['field' => 'goods_name', 'name' => '商品名称'],
['field' => 'spec_name', 'name' => '商品规格'],
['field' => 'sku_no', 'name' => '商品条码'],
['field' => 'market_price', 'name' => '划线价'],
['field' => 'price', 'name' => '零售价'],
['field' => 'unit', 'name' => '单位'],
['field' => 'weight', 'name' => '重量'],
['field' => 'category_names', 'name' => '商品分类'],
['field' => 'brand_name', 'name' => '品牌'],
['field' => 'supplier_name', 'name' => '供应商'],
['field' => 'label_name', 'name' => '标签'],
],
'data' => $data,
];
$export_model = new ExportModel();
$res = $export_model->export($param);
return $this->response($res);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\model\system\User as UserModel;
use app\storeapi\controller\Captcha;
use app\storeapi\controller\BaseStoreApi;
/**
* 门店登录控制器
*/
class Login extends BaseStoreApi
{
public function __construct()
{
$this->params = input();
$this->getApiConfig();
}
public function login()
{
if (empty($this->params['username'])) return $this->response($this->error([], '账号不能为空!'));
if (empty($this->params['password'])) return $this->response($this->error([], '密码不可为空!'));
$captcha = new Captcha();
$check_res = $captcha->checkCaptcha();
if ($check_res[ 'code' ] < 0) return $this->response($check_res);
// 登录
$login = new UserModel();
$res = $login->uniAppLogin($this->params[ 'username' ], $this->params['password'], 'store');
//生成access_token
if ($res[ 'code' ] >= 0) {
if (empty($res[ 'data' ][ 'user_group_list' ])) return $this->response($this->error('', '没有可管理的门店'));
$token = $this->createToken($res[ 'data' ]);
return $this->response($this->success([
'token' => $token,
'site_id' => $res[ 'data' ][ 'site_id' ],
'store_id' => $res[ 'data' ][ 'user_group_list' ][ 0 ][ 'store_id' ]
]));
}
return $this->response($res);
}
}

View File

@@ -0,0 +1,459 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cardservice\model\MemberCard;
use addon\coupon\model\Coupon as CouponModel;
use addon\coupon\model\CouponType;
use addon\coupon\model\MemberCoupon;
use addon\store\model\StoreMember;
use app\dict\member_account\AccountDict;
use app\model\member\Member as MemberModel;
use app\model\member\MemberAccount as MemberAccountModel;
use app\model\member\MemberLabel as MemberLabelModel;
use app\model\member\MemberLevel as MemberLevelModel;
use app\model\message\Message;
use app\model\order\OrderCommon;
use app\model\system\PayBalance;
use app\storeapi\controller\BaseStoreApi;
use Exception;
use think\facade\Cache;
/**
* 会员管理 控制器
*/
class Member extends BaseStoreApi
{
public function lists()
{
$page_index = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$search_text = $this->params[ 'search_text' ] ?? '';
$condition = [
[ 'site_id', '=', $this->site_id ],
];
if (!empty($search_text)) $condition[] = [ 'username|nickname|mobile|member_code', 'like', '%' . $search_text . '%' ];
$member = new MemberModel();
$field = 'member_id,mobile,nickname,headimg,email,status,headimg,member_level,member_level_name,member_label,member_label_name,last_login_time,sex,point,balance,growth,balance_money,is_member,order_money,order_complete_money,order_num,order_complete_num';
$list = $member->getMemberPageList($condition, $page_index, $page_size, 'member_id desc', $field);
return $this->response($list);
}
/*
* 会员信息
*/
public function info($mid = 0)
{
$member_id = $this->params[ 'member_id' ] ?? 0;
if (!empty($mid)) {
$member_id = $mid;
}
if (empty($member_id)) return $this->response($this->error());
$condition = [
[ 'member_id', '=', $member_id ]
];
$member = new MemberModel();
$field = 'member_id, username, nickname, mobile, status, headimg, member_level, member_level_name, member_label, member_label_name, last_login_time, last_visit_time, realname, sex, location, birthday, reg_time, point, balance, growth, balance_money, account5, is_auth, is_member, member_time, order_money, order_complete_money, order_num, order_complete_num, balance_withdraw_apply, balance_withdraw, member_code';
$data = $member->getMemberInfo($condition, $field);
$coupon_model = new MemberCoupon();
$coupon_num = $coupon_model->getMemberCouponNum($member_id, 1, $this->site_id)[ 'data' ];
$data[ 'data' ][ 'coupon_num' ] = $coupon_num;
$data[ 'data' ][ 'card_num' ] = ( new MemberCard() )->getCardCount([ [ 'mgc.member_id', '=', $member_id ], [ 'mgc.status', '=', 1 ], [ 'g.is_delete', '=', 0 ] ], 'card_id', 'mgc', [
[ 'goods g', 'g.goods_id = mgc.goods_id', 'inner' ]
])[ 'data' ];
return $this->response($data);
}
public function searchMember()
{
$search_text = $this->params[ 'search_text' ] ?? '';
$search_type = $this->params[ 'search_type' ] ?? '';
if ($search_type == 'mobile' || $search_type == 'nickname' || $search_type == 'member_code') {
} else {
$search_type = 'username|mobile|member_code';
}
$condition = [
[ $search_type, '=', $search_text ],
[ 'is_delete', '=', 0 ]
];
$member = new MemberModel();
$data = $member->getMemberInfo($condition);
return $this->response($data);
}
/**
* 根据手机号查询会员,支持模糊
* @return false|string
*/
public function searchMemberByMobile()
{
$mobile = $this->params[ 'mobile' ] ?? '';
if (empty($mobile)) {
return $this->response($this->error('', '缺少参数 mobile'));
}
$condition = [
[ 'mobile', 'like', '%' . $mobile . '%' ],
[ 'is_delete', '=', 0 ]
];
$member = new MemberModel();
$field = 'member_id, username, nickname, mobile, status, headimg, member_level, member_level_name, member_label, member_label_name, last_login_time, last_visit_time, realname, sex, location, birthday, reg_time, point, balance, growth, balance_money, account5, is_auth, is_member, member_time, order_money, order_complete_money, order_num, order_complete_num, balance_withdraw_apply, balance_withdraw, member_code';
$res = $member->getMemberPageList($condition, 1, PAGE_LIST_ROWS, 'member_id desc', $field)[ 'data' ];
if ($res[ 'count' ] == 1) {
return $this->response($this->success($res[ 'list' ][ 0 ]));
} elseif ($res[ 'count' ] > 1) {
return $this->response($this->error($res[ 'count' ], '该账户存在多个,请输入完整的手机号进行查询'));
} elseif ($res[ 'count' ] == 0) {
return $this->response($this->error($res[ 'count' ], '会员不存在'));
}
}
public function addMember()
{
$data = [
'site_id' => $this->site_id,
'username' => '',
'mobile' => $this->params[ 'mobile' ] ?? '',
'email' => '',
'status' => 1,
'headimg' => '',
'member_level' => $this->params[ 'member_level' ] ?? 0,
'member_level_name' => $this->params[ 'member_level_name' ] ?? '',
'nickname' => $this->params[ 'nickname' ],
'sex' => $this->params[ 'sex' ] ?? 0,
'birthday' => $this->params[ 'birthday' ] ? strtotime($this->params[ 'birthday' ]) : 0,
'realname' => $this->params[ 'realname' ] ?? '',
'reg_time' => time(),
];
if (empty($data[ 'mobile' ])) return $this->response($this->error('', '手机号不能为空'));
if (empty($data[ 'nickname' ])) $data[ 'nickname' ] = $data[ 'mobile' ];
$member_model = new MemberModel();
$add_res = $member_model->addMember($data);
if ($add_res[ 'code' ] != 0) return $this->response($add_res);
$res = ( new StoreMember() )->addStoreMember($this->store_id, $add_res[ 'data' ]);
$this->addLog('添加会员' . $data[ 'username' ] . $data[ 'mobile' ]);
return $this->response($add_res);
}
/**
* 会员优惠券
* @return false|string
*/
public function coupon()
{
$member_id = $this->params[ 'member_id' ] ?? 0;
$page = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$state = $this->params[ 'state' ] ?? 1;
$condition = [
[ 'npc.member_id', '=', $member_id ],
[ 'npc.state', '=', $state ]
];
$coupon_model = new CouponModel();
$list = $coupon_model->getMemberCouponPageList($condition, $page, $page_size);
$coupon_type_model = new CouponType();
foreach($list['data']['list'] as &$val){
$val = $coupon_type_model->getCouponSubData($val);
}
return $this->response($list);
}
/**
* 会员编辑
*/
public function editMember()
{
$data = [];
if (isset($this->params[ 'headimg' ])) $data[ 'headimg' ] = $this->params[ 'headimg' ];
if (isset($this->params[ 'nickname' ])) $data[ 'nickname' ] = $this->params[ 'nickname' ];
if (isset($this->params[ 'mobile' ])) $data[ 'mobile' ] = $this->params[ 'mobile' ];
if (isset($this->params[ 'level_id' ]) && !empty($this->params[ 'level_id' ])) $data[ 'member_level' ] = $this->params[ 'level_id' ];
if (isset($this->params[ 'level_id' ]) && !empty($this->params[ 'level_id' ])) {
$member_level_model = new MemberLevelModel();
$condition = [
[ 'site_id', '=', $this->site_id ],
[ 'level_id', '=', $this->params[ 'level_id' ] ],
[ 'status', '=', 1 ]
];
$member_level = $member_level_model->getFirstMemberLevel($condition);
if(empty($member_level[ 'data' ])){
return $this->response($this->error(null, '会员等级不存在'));
}
$data[ 'member_level_name' ] = $member_level[ 'data' ][ 'level_name' ];
}
if (isset($this->params[ 'label_id' ]) && !empty($this->params[ 'label_id' ])) $data[ 'member_label' ] = $this->params[ 'label_id' ];
if (isset($this->params[ 'label_id' ]) && !empty($this->params[ 'label_id' ])) {
$member_label_model = new MemberLabelModel();
$member_label = $member_label_model->getMemberLabelInfo([ [ 'label_id', '=', $this->params[ 'label_id' ] ] ]);
$data[ 'member_label_name' ] = $member_label[ 'data' ][ 'label_name' ];
}
if (isset($this->params[ 'sex' ])) $data[ 'sex' ] = $this->params[ 'sex' ];
if (isset($this->params[ 'birthday' ])) $data[ 'birthday' ] = $this->params[ 'birthday' ] ? strtotime($this->params[ 'birthday' ]) : 0;
$member_id = $this->params[ 'member_id' ];
$member_model = new MemberModel();
$this->addLog('编辑会员:id' . $member_id, $data);
$info = $member_model->editMember($data, [ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $this->site_id ] ]);
return $this->response($info);
}
/**
* 账户流水
* @return false|string
*/
public function memberAccountList()
{
$member_id = $this->params[ 'member_id' ] ?? 0;
$page_index = isset($this->params[ 'page' ]) && !empty($this->params[ 'page_size' ]) ? $this->params[ 'page' ] : 1;
$page_size = isset($this->params[ 'page_size' ]) && !empty($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
$account_type = $this->params[ 'account_type' ] ?? '';
if (!empty($account_type)) {
if (!in_array($account_type, [ 'point', 'growth', 'balance', 'balance_money' ])) {
return $this->response($this->error('', 'INVALID_PARAMETER'));
}
}
$memberAcc = new MemberAccountModel();
$condition = [
[ 'member_id', '=', $member_id ],
[ 'site_id', '=', $this->site_id ]
];
if (!empty($account_type)) {
$condition[] = [ 'account_type', '=', $account_type ];
}
$field = 'id,member_id,account_type,account_data,from_type,type_name,type_tag,remark,create_time,username,mobile,email';
$data = $memberAcc->getMemberAccountPageList($condition, $page_index, $page_size, 'create_time desc', $field);
if (!empty($data[ 'data' ][ 'list' ])) {
$account_type = $memberAcc->getAccountType();
$data[ 'data' ][ 'list' ] = array_map(function($item) use ($account_type) {
$item[ 'account_type_name' ] = $account_type[ $item[ 'account_type' ] ];
return $item;
}, $data[ 'data' ][ 'list' ]);
}
return $this->response($data);
}
/**
* 加入移除黑名单
* @return false|string
*/
public function joinBlacklist()
{
$member_id = input('member_id', 0);
$status = input('status', 0);
$condition = [
[ 'member_id', '=', $member_id ],
[ 'site_id', '=', $this->site_id ]
];
$member_model = new MemberModel();
$info = $member_model->modifyMemberStatus($status, $condition);
return $this->response($info);
}
/**
* 获取会员订单列表
*/
public function orderList()
{
$search_text = $this->params[ 'search_text' ] ?? '';
$member_id = $this->params[ 'member_id' ] ?? 0;
$page_index = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
if (!empty($search_text)) {
$condition[] = [ 'order_no', 'like', '%' . $search_text . '%' ];
}
$condition[] = [ 'member_id', '=', $member_id ];
$condition[] = [ 'site_id', '=', $this->site_id ];
$field = 'order_id,order_no,order_name,order_type,order_money,pay_money,balance_money,order_type_name,order_status_name,delivery_status_name,create_time';
$order = new OrderCommon();
$list = $order->getMemberOrderPageList($condition, $page_index, $page_size, 'order_id desc', $field);
return $this->response($list);
}
/**
* 重置密码
*/
public function modifyMemberPassword()
{
$password = $this->params[ 'password' ] ?? '123456';
$member_id = $this->params[ 'member_id' ] ?? 0;
$member_model = new MemberModel();
$info = $member_model->resetMemberPassword($password, [ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $this->site_id ] ]);
return $this->response($info);
}
/**
* 调整余额
*/
public function modifyBalance()
{
$member_id = $this->params[ 'member_id' ] ?? 0;
$adjust_num = $this->params[ 'adjust_num' ] ?? 0;
$remark = $this->params[ 'remark' ] ?? '商家调整';
$this->addLog('会员余额调整id:' . $member_id . '金额' . $adjust_num);
$member_account_model = new MemberAccountModel();
$info = $member_account_model->addMemberAccount($this->site_id, $member_id, AccountDict::balance, $adjust_num, 'adjust', 0, $remark);
return $this->response($info);
}
/**
* 余额调整(可提现)
*/
public function modifyBalanceMoney()
{
return $this->response($this->error());
$member_id = $this->params[ 'member_id' ] ?? 0;
$adjust_num = $this->params[ 'adjust_num' ] ?? 0;
$remark = $this->params[ 'remark' ] ?? '商家调整';
$this->addLog('会员余额调整id:' . $member_id . '金额' . $adjust_num);
$member_account_model = new MemberAccountModel();
$info = $member_account_model->addMemberAccount($this->site_id, $member_id, 'balance_money', $adjust_num, 'adjust', 0, $remark);
return $this->response($info);
}
/**
* 积分调整
*/
public function modifyPoint()
{
$member_id = $this->params[ 'member_id' ] ?? 0;
$adjust_num = $this->params[ 'adjust_num' ] ?? 0;
$remark = $this->params[ 'remark' ] ?? '商家调整';
$this->addLog('会员积分调整id:' . $member_id . '数量' . $adjust_num);
$member_account_model = new MemberAccountModel();
$info = $member_account_model->addMemberAccount($this->site_id, $member_id, 'point', $adjust_num, 'adjust', 0, $remark);
return $this->response($info);
}
/**
* 成长值调整
*/
public function modifyGrowth()
{
$member_id = $this->params[ 'member_id' ] ?? 0;
$adjust_num = $this->params[ 'adjust_num' ] ?? 0;
$remark = $this->params[ 'remark' ] ?? '商家调整';
$this->addLog('会员成长值调整id:' . $member_id . '数量' . $adjust_num);
$member_account_model = new MemberAccountModel();
$info = $member_account_model->addMemberAccount($this->site_id, $member_id, 'growth', $adjust_num, 'adjust', 0, $remark);
return $this->response($info);
}
/**
* 发放优惠券
* @return false|string
*/
public function sendCoupon()
{
$member_id = $this->params[ 'member_id' ] ?? 0;
$coupon_data = json_decode(input('coupon_data', '[]'), true); // [{coupon_type_id: **, num: **}]
if (empty($coupon_data)) {
return $this->response($this->error('', '要发放的优惠券不能为空'));
}
$res = ( new CouponModel() )->giveCoupon($coupon_data, $this->site_id, $member_id, CouponModel::GET_TYPE_MERCHANT_GIVE);
return $this->response($res);
}
/**
* 办理会员
* @return false|string
*/
public function handleMember()
{
$member_id = $this->params[ 'member_id' ] ?? 0;
$level_id = $this->params[ 'level_id' ] ?? 0;
$member_code = $this->params[ 'member_code' ] ?? '';
$member_model = new MemberModel();
$res = $member_model->handleMember([
'member_id' => $member_id,
'level_id' => $level_id,
'member_code' => $member_code,
'site_id' => $this->site_id
]);
return $this->response($res);
}
/**
* 会员验证 验证码
* @return false|string
* @throws Exception
*/
public function memberVerifyCode()
{
$member_id = $this->params[ 'member_id' ] ?? 0;
$member_model = new MemberModel();
$member_info = $member_model->getMemberInfo([ [ 'site_id', '=', $this->site_id ], [ 'member_id', '=', $member_id ] ], 'mobile')[ 'data' ];
if (empty($member_info)) return $this->response($this->error('', '未获取到会员信息'));
if (empty($member_info[ 'mobile' ])) return $this->response($this->error('', '会员未绑定手机号'));
$code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);// 生成4位随机数左侧补0
$message_model = new Message();
$res = $message_model->sendMessage([ 'type' => 'code', 'mobile' => $member_info[ 'mobile' ], 'site_id' => $this->site_id, 'code' => $code, 'support_type' => [ 'sms' ], 'keywords' => 'CASHIER_MEMBER_VERIFY_CODE' ]);
if ($res[ 'code' ] >= 0) {
//将验证码存入缓存
$key = 'cashier_member_verify' . md5(uniqid(null, true));
Cache::tag('bind_mobile_code')->set($key, [ 'code' => $code ], 600);
return $this->response($this->success([ 'key' => $key ]));
} else {
return $this->response($res);
}
}
/**
* 验证短信验证码
* @return false|string
*/
public function checkSmsCode()
{
$key = $this->params[ 'key' ] ?? '';
$code = $this->params[ 'code' ] ?? '';
$verify_data = Cache::get($key);
if (!empty($verify_data) && $verify_data[ 'code' ] == $this->params[ 'code' ]) {
return $this->response($this->success());
} else {
return $this->response($this->error('', '验证码不正确'));
}
}
/**
* 验证付款码
*/
public function checkPaymentCode()
{
$code = $this->params[ 'code' ] ?? '';
$member_id = $this->params[ 'member_id' ] ?? 0;
$res = ( new PayBalance() )->checkPaymentCode($code, $member_id);
if ($res[ 'code' ] >= 0 && !empty($res[ 'data' ][ 'member_id' ])) {
$res[ 'data' ][ 'member_info' ] = $this->info($res[ 'data' ][ 'member_id' ])->getData()[ 'data' ] ?? [];
}
return $this->response($res);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\model\member\MemberLevel as MemberLevelModel;
use app\storeapi\controller\BaseStoreApi;
/**
* 会员等级
* @package app\shop\controller
*/
class Memberlevel extends BaseStoreApi
{
/**
* 会员等级列表
*/
public function lists()
{
$condition = [
['site_id', '=', $this->site_id],
['level_type', '=', 0]
];
$list = (new MemberLevelModel())->getMemberLevelList($condition, 'level_id, level_name', 'growth asc');
return $this->response($list);
}
}

View File

@@ -0,0 +1,343 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\model\express\ExpressCompany;
use app\model\express\ExpressDeliver;
use app\model\order\LocalOrder as LocalOrderModel;
use app\model\order\Order as OrderModel;
use app\model\order\OrderCommon;
use app\model\order\OrderLog;
use app\model\verify\Verify;
use app\storeapi\controller\BaseStoreApi;
use think\facade\Config;
/**
* 订单控制器
* Class Order
* @package addon\cashier\storeapi\controller
*/
class Order extends BaseStoreApi
{
/**
* 订单筛选条件
*/
public function condition()
{
$data = [];
//商城订单筛选数据
$order_common_model = new OrderCommon();
//订单类型
$order_type_list = $order_common_model->getOrderTypeStatusList();
$temp_order_type_list = [];
foreach(['all', 1,2,3] as $type){
$temp_order_type_list[] = $order_type_list[$type];
}
$order_type_list = $temp_order_type_list;
unset($temp_order_type_list);
$data[ 'order_type_list' ] = $order_type_list;
//订单来源
$order_from = Config::get("app_type");
$data[ 'order_from_list' ] = $order_from;
//支付方式
$pay_type = $order_common_model->getPayType();
$data[ 'pay_type_list' ] = $pay_type;
//收银订单筛选数据
$cashier_order_model = new \addon\cashier\model\order\CashierOrder();
//收银台订单类型
$data[ 'cashier_order_type_list' ] = $cashier_order_model->cashier_order_type;
//收银台支付方式
$data[ 'cashier_pay_type_list' ] = $cashier_order_model->pay_type;
//收银台订单状态
$data[ 'cashier_order_status_list' ] = $cashier_order_model->order_status;
$data[ 'cashier_order_status_list' ]['refunded'] = ['status' => 'refunding', 'name' => '已退款'];
return $this->response($this->success($data));
}
/**
* 列表
* @return false|string
*/
public function lists()
{
$order_common_model = new OrderModel();
$page = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$search_text = $this->params[ 'search_text' ] ?? '';//关键词
$order_status = $this->params[ 'order_status' ] ?? 'all';//订单状态
$start_time = $this->params[ 'start_time' ] ?? '';//开始时间
$end_time = $this->params[ 'end_time' ] ?? '';//结束时间
$trade_type = $this->params[ 'trade_type' ] ?? '';//订单类型
$order_from = $this->params[ 'order_from' ] ?? '';//订单来源
$pay_type = $this->params[ 'pay_type' ] ?? '';//支付方式
$condition = [
[ 'site_id', '=', $this->site_id ],
[ 'store_id', '=', $this->store_id ],
[ 'is_delete', '=', 0 ],
[ 'order_type', '=', 'o2o' ],
];
//订单状态
if ($order_status != 'all' && !empty($order_status)) {
$condition[] = [ 'order_status', '=', $order_status ];
}
//订单时间
if (!empty($start_time) && empty($end_time)) {
$condition[] = [ 'create_time', '>=', date_to_time($start_time) ];
} elseif (empty($start_time) && !empty($end_time)) {
$condition[] = [ 'create_time', '<=', date_to_time($end_time) ];
} elseif (!empty($start_time) && !empty($end_time)) {
$condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
}
//订单内容
if ($search_text != '') {
$condition[] = [ 'order_no|out_trade_no|order_name|nickname', 'like', '%' . $search_text . '%' ];
}
//收货方式
if ($trade_type != '') {
$condition[] = [ 'trade_type', '=', $trade_type ];
}
//订单来源
if ($order_from != '') {
$condition[] = [ 'order_from', '=', $order_from ];
}
//订单支付
if ($pay_type != '') {
$condition[] = [ 'pay_type', '=', $pay_type ];
}
$order = 'create_time desc';
$field = '*';
$list = $order_common_model->getOrderPageList($condition, $page, $page_size, $order, $field);
$list['c'] = $condition;
return $this->response($list);
}
/**
* 获取支付方式
*/
public function getOrderPayType()
{
$order_common_model = new OrderModel();
$pay_type_list = $order_common_model->getPayType();
return $this->response($this->success($pay_type_list));
}
/**
* 获取订单来源
*/
public function getOrderFromType()
{
$order_common_model = new OrderModel();
$list = $order_common_model->getOrderFromList([ 'order_scene' => 'cashier' ]);
return $this->response($this->success($list));
}
/**
* 获取订单信息
*/
public function info()
{
$order_id = $this->params[ 'order_id' ] ?? 0;
//订单信息
$order_common_model = new OrderModel();
$condition = [
[ 'order_id', '=', $order_id ],
[ 'site_id', '=', $this->site_id ],
[ 'store_id', '=', $this->store_id ],
];
$res = $order_common_model->getOrderInfo($condition);
return $this->response($res);
}
/**
* 订单详情
*/
public function detail()
{
$order_id = $this->params[ 'order_id' ] ?? 0;
//订单详情
$order_common_model = new OrderModel();
$order_detail = $order_common_model->getOrderDetail($order_id)[ 'data' ];
if (empty($order_detail)) return $this->response($this->error(null, '无法获取订单数据'));
//查询订单日志
$order_log_model = new OrderLog();
$log_condition = [
[ 'order_id', '=', $order_id ],
];
$order_detail[ 'order_log_list' ] = OrderLog::getOrderLogList($log_condition, '*', 'action_time desc,id desc', $order_log_model)[ 'data' ];
return $this->response($this->success($order_detail));
}
/**
* 订单调价
* @return false|string
*/
public function adjustPrice()
{
$order_id = $this->params[ 'order_id' ] ?? 0;
$adjust_money = $this->params[ 'adjust_money' ] ?? 0;
$shipping_money = $this->params[ 'shipping_money' ] ?? 0;
$order_common_model = new OrderModel();
$result = $order_common_model->orderAdjustMoney($order_id, $adjust_money, $shipping_money);
return $this->response($result);
}
/**
* 订单关闭
* @return false|string
*/
public function close()
{
$order_id = $this->params[ 'order_id' ] ?? 0;
$order_common_model = new OrderModel();
//关闭检测
$check_res = $order_common_model->activeOrderCloseCheck($order_id);
if($check_res['code'] < 0) return $this->response($check_res);
$log_data = [
'uid' => $this->user_info[ 'uid' ],
'nick_name' => $this->user_info[ 'username' ],
'action_way' => 2
];
$result = $order_common_model->orderClose($order_id, $log_data, '商家关闭了订单');
return $this->response($result);
}
/**
* 订单删除
*/
public function delete()
{
$order_id = $this->params[ 'order_id' ] ?? 0;
$order_common_model = new OrderModel();
$result = $order_common_model->orderDelete($order_id, $this->site_id);
return $this->response($result);
}
/**
* 同城配送发货
* @return false|string
*/
public function localDelivery()
{
$order_id = $this->params[ 'order_id' ] ?? 0;
$deliverer = $this->params[ 'deliverer' ] ?? '';
$deliverer_mobile = $this->params[ 'deliverer_mobile' ] ?? '';
$local_order_model = new LocalOrderModel();
$data = [
'order_id' => $order_id,
'deliverer' => $deliverer,
'deliverer_mobile' => $deliverer_mobile,
'site_id' => $this->site_id,
'store_id' => $this->store_id
];
$result = $local_order_model->orderGoodsDelivery($data);
return $this->response($result);
}
/**
* 门店提货
* @return false|string
*/
public function storeDelivery()
{
$order_id = $this->params[ 'order_id' ] ?? 0;
$order_common_model = new OrderCommon();
$condition = [
[ 'site_id', '=', $this->site_id ],
[ 'store_id', '=', $this->store_id ],
[ 'order_id', '=', $order_id ]
];
$order_info = $order_common_model->getOrderInfo($condition, 'delivery_code')[ 'data' ] ?? [];
if (empty($order_info)) return $this->response($this->error('', '订单不存在'));
$verify_code = $order_info[ 'delivery_code' ];
$info = [
'verifier_id' => $this->uid,
'verifier_name' => $this->user_info[ 'username' ],
'verify_from' => 'shop',
'store_id' => $this->store_id
];
$verify_model = new Verify();
$result = $verify_model->verify($info, $verify_code);
return $this->response($result);
}
/**
* 快递发货
* @return false|string
*/
public function expressDelivery()
{
$order_model = new OrderModel();
$data = [
'type' => 'manual',//发货方式(手动发货、电子面单)
'order_goods_ids' => $this->params[ 'order_goods_ids' ] ?? '',//商品id
'express_company_id' => $this->params[ 'express_company_id' ] ?? 0,//物流公司
'delivery_no' => $this->params[ 'delivery_no' ] ?? '',//快递单号
'order_id' => $this->params[ 'order_id' ] ?? 0,//订单id
'delivery_type' => $this->params[ 'delivery_type' ] ?? 0,//是否需要物流
'site_id' => $this->site_id,
'store_id' => $this->store_id,
'template_id' => 0,//电子面单模板id
'user_info' => $this->user_info
];
$log_data = [
'uid' => $this->user_info[ 'uid' ],
'nick_name' => $this->user_info[ 'username' ],
'action' => '商家对订单进行了发货',
'action_way' => 2,
];
$result = $order_model->orderGoodsDelivery($data, 1, $log_data);
return $this->response($result);
}
/**
* 获取门店配送员
*/
public function deliverList()
{
$deliver_model = new ExpressDeliver();
$list = $deliver_model->getDeliverLists([ [ 'site_id', '=', $this->site_id ], [ 'store_id', '=', $this->store_id ] ], 'deliver_id,deliver_name,deliver_mobile');
return $this->response($list);
}
/**
* 获取物流公司
* @return false|string
*/
public function expressCompany()
{
$express_company_model = new ExpressCompany();
//店铺物流公司
$result = $express_company_model->getExpressCompanyList([ ['site_id', '=', $this->site_id ] ]);
return $this->response($result);
}
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cashier\model\order\PendOrder as PendOrderModel;
use app\storeapi\controller\BaseStoreApi;
class Pendorder extends BaseStoreApi
{
public function add()
{
$goods = $this->params[ 'goods' ] ?? '[]';
$discount = $this->params[ 'discount' ] ?? '{}';
$data = [
'site_id' => $this->site_id,
'member_id' => $this->params[ 'member_id' ] ?? 0,
'store_id' => $this->store_id,
'goods' => json_decode($goods, true),
'discount_money' => $this->params[ 'discount_money' ] ?? 0,
'discount' => $discount,
'remark' => $this->params[ 'remark' ] ?? ''
];
$res = ( new PendOrderModel() )->add($data);
return $this->response($res);
}
public function edit()
{
$goods = $this->params[ 'goods' ] ?? '[]';
$discount = $this->params[ 'discount' ] ?? '{}';
$data = [
'site_id' => $this->site_id,
'order_id' => $this->params[ 'order_id' ],
'member_id' => $this->params[ 'member_id' ] ?? 0,
'store_id' => $this->store_id,
'goods' => json_decode($goods, true),
'discount_money' => $this->params[ 'discount_money' ] ?? 0,
'discount' => $discount,
'remark' => $this->params[ 'remark' ] ?? ''
];
$res = ( new PendOrderModel() )->edit($data);
return $this->response($res);
}
public function page()
{
$page_index = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$condition = [
[ 'o.site_id', '=', $this->site_id ],
[ 'o.store_id', '=', $this->store_id ]
];
$model = new PendOrderModel();
$data = $model->getOrderPageList($condition, 'o.*,m.nickname', 'o.create_time desc', $page_index, $page_size, 'o', [ [ 'member m', 'm.member_id = o.member_id', 'left' ] ]);
if (!empty($data[ 'data' ][ 'list' ])) {
$order_id_array = [];
foreach ($data[ 'data' ][ 'list' ] as $k => $v) {
$order_id_array[] = $v[ 'order_id' ];
}
$order_ids = implode(',', $order_id_array);
$field = 'og.*, g.goods_name, gs.spec_name, g.goods_image';
$list = $model->getOrderGoodsList([ [ 'og.order_id', 'in', $order_ids ] ], $field, '', 'og', [
[ 'goods g', 'g.goods_id = og.goods_id', 'left' ],
[ 'goods_sku gs', 'gs.sku_id = og.sku_id', 'left' ]
])[ 'data' ];
foreach ($data[ 'data' ][ 'list' ] as $k => $v) {
foreach ($list as $k_order_goods => $v_order_goods) {
if ($v[ 'order_id' ] == $v_order_goods[ 'order_id' ]) {
$data[ 'data' ][ 'list' ][ $k ][ 'order_goods' ][] = $v_order_goods;
}
}
}
}
return $this->response($data);
}
public function delete()
{
$order_id = $this->params[ 'order_id' ];
$res = ( new PendOrderModel() )->delete([
'site_id' => $this->site_id,
'store_id' => $this->store_id,
'order_id' => $order_id
]);
return $this->response($res);
}
public function updateRemark()
{
$order_id = $this->params[ 'order_id' ];
$remark = $this->params[ 'remark' ];
$res = ( new PendOrderModel() )->update([ 'remark' => $remark ], [
[ 'site_id', '=', $this->site_id ],
[ 'store_id', '=', $this->store_id ],
[ 'order_id', '=', $order_id ]
]);
return $this->response($res);
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cashier\model\Group;
use app\model\system\User as UserModel;
use app\model\system\UserGroup;
use app\storeapi\controller\BaseStoreApi;
/**
* 用户控制器
* Class User
* @package addon\shop\siteapi\controller
*/
class Promotion extends BaseStoreApi
{
public function getPromotionQrcode()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$promotion_model = new \app\model\system\Promotion();
$option_json = $this->params['option'] ?? '';
$option = $option_json ? json_decode($option_json, true) : [];
$res = $promotion_model->getPromotionQrcode([
'page_name' => $this->params['page_name'] ?? '',
'option' => $option,
'app_type' => $this->params['app_type'] ?? 'h5',
'site_id' => $this->site_id,
]);
return $this->response($res);
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\storeapi\controller\BaseStoreApi;
use GatewayClient\Gateway;
/**
* 消息推送
*/
class Push extends BaseStoreApi
{
//初始化
protected function initGateway()
{
$config_info = require root_path().'/config/gateway.php';
Gateway::$registerAddress = $config_info['gateway']['register_address'];
}
//uid
protected function getUid($store_id)
{
return 'store_'.$store_id;
}
//捕获错误
protected function pushError(\Exception $e)
{
return $this->response($this->error([$e->getFile(),$e->getLine(),$e->getMessage()], '推送服务未开启,请联系管理员'));
}
/**
* 绑定
*/
public function bind()
{
$client_id = $this->params['client_id'] ?? '';
if(empty($client_id)){
return $this->response($this->error(null, '客户端id不能为空'));
}
try{
$this->initGateway();
Gateway::bindUid($client_id, $this->getUid($this->store_id));
return $this->response($this->success());
}catch(\Exception $e){
return $this->pushError($e);
}
}
/**
* 改变绑定
*/
public function changeBind()
{
$client_id = $this->params['client_id'] ?? '';
$old_store_id = $this->params['old_store_id'] ?? '';
if(empty($client_id)){
return $this->response($this->error(null, '客户端id不能为空'));
}
try{
$this->initGateway();
Gateway::unbindUid($client_id, $this->getUid($old_store_id));
Gateway::bindUid($client_id, $this->getUid($this->store_id));
return $this->response($this->success());
}catch(\Exception $e){
return $this->pushError($e);
}
}
/**
* 下线
*/
public function offline()
{
$client_id = $this->params['client_id'] ?? '';
if(empty($client_id)){
return $this->response($this->error(null, '客户端id不能为空'));
}
try{
$this->initGateway();
Gateway::closeClient($client_id);
return $this->response($this->success());
}catch(\Exception $e){
return $this->pushError($e);
}
}
/**
* 服务状态
*/
public function status()
{
try{
$this->initGateway();
Gateway::isUidOnline($this->getUid($this->store_id));
return $this->response($this->success());
}catch(\Exception $e){
return $this->pushError($e);
}
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\memberrecharge\model\Memberrecharge;
use addon\memberrecharge\model\MemberrechargeOrder;
use app\storeapi\controller\BaseStoreApi;
class Recharge extends BaseStoreApi
{
/**
* 会员充值活动
* @return false|string
*/
public function activity()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$member_recharge_model = new Memberrecharge();
$list = $member_recharge_model->getMemberRechargeList([['site_id', '=', $this->site_id]]);
return $this->response($list);
}
/**
* 充值记录
* @return false|string
*/
public function orderPage()
{
$page = $this->params['page'] ?? 1;
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$search_text = $this->params['search_text'] ?? '';
$search_mode = $this->params['search_mode'] ?? 'pay_time';
$start_time = $this->params['start_time'] ?? '';
$end_time = $this->params['end_time'] ?? '';
$condition = [
['site_id', '=', $this->site_id],
['store_id', '=', $this->store_id],
['status', '=', 2],
];
if (!empty($search_text)) {
$condition[] = ['order_no|out_trade_no|nickname', 'like', '%' . $search_text . '%'];
}
if (!empty($search_mode)) {
if (!empty($start_time) && empty($end_time)) {
$condition[] = [$search_mode, '>=', date_to_time($start_time)];
} elseif (empty($start_time) && !empty($end_time)) {
$condition[] = [$search_mode, '<=', date_to_time($end_time)];
} elseif (!empty($start_time) && !empty($end_time)) {
$condition[] = [$search_mode, 'between', [date_to_time($start_time), date_to_time($end_time)]];
}
}
$recharge_model = new MemberrechargeOrder();
$list = $recharge_model->getMemberRechargeOrderPageList($condition, $page, $page_size, 'create_time desc');
return $this->response($list);
}
/**
* 充值详情
* @return false|string
*/
public function orderDetail()
{
$order_id = $this->params['order_id'] ?? 0;
$recharge_model = new MemberrechargeOrder();
$condition = [
['site_id', '=', $this->site_id],
['store_id', '=', $this->store_id],
['order_id', '=', $order_id],
];
$detail = $recharge_model->getMemberRechargeOrderInfo($condition);
return $this->response($detail);
}
}

View File

@@ -0,0 +1,157 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\dict\goods\GoodsDict;
use app\model\goods\ServiceCategory;
use app\model\goods\Goods as GoodsModel;
use app\model\storegoods\StoreGoods as StoreGoodsModel;
use app\storeapi\controller\BaseStoreApi;
use think\facade\Db;
/**
* Class Service
* @package addon\cashier\storeapi\controller
*/
class Service extends BaseStoreApi
{
/**
* 获取商品分类的组织
* @return false|string
*/
public function category()
{
$level = $this->params[ 'level' ] ?? 1;
$service_category_model = new ServiceCategory();
$condition = [
[ 'is_show', '=', 0 ],
[ 'level', '<=', $level ],
[ 'site_id', '=', $this->site_id ]
];
$list = $service_category_model->getCategoryTree($condition, 'category_id,category_name,image,level', 'sort asc,category_id desc');
return $this->response($list);
}
public function page()
{
$page_index = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$goods_category = $this->params[ 'category' ] ?? 'all';
$search_text = $this->params[ 'search_text' ] ?? '';
$goods_state = $this->params[ 'goods_state' ] ?? 'all';
$is_virtual = $this->params[ 'is_virtual' ] ?? 0;
$model = new GoodsModel();
$condition = [
[ 'g.site_id', '=', $this->site_id ],
[ 'g.is_delete', '=', 0 ],
[ 'g.goods_class', '=', GoodsDict::service ],
[ 'g.sale_store', 'like', [ '%all%', '%,' . $this->store_id . ',%' ], 'or' ],
[ '', 'exp', Db::raw("(g.sale_channel = 'all' OR g.sale_channel = 'offline')") ]
];
if ($goods_state !== 'all') {
$condition[] = [ 'g.goods_state', '=', $goods_state ];
}
if ($goods_category != 'all') $condition[] = [ 'g.service_category', 'like', "%,{$goods_category},%" ];
if ($search_text != '') {
$goods_sku_list = $model->getGoodsSkuList([ [ 'sku_no', 'like', '%' . $search_text . '%' ] ], 'goods_id')[ 'data' ];
$goods_id_arr = array_unique(array_column($goods_sku_list, 'goods_id'));
if (!empty($goods_id_arr)) {
$condition[] = [ 'g.goods_id', 'in', $goods_id_arr ];
} else {
$condition[] = [ 'g.goods_name', 'like', "%{$search_text}%" ];
}
}
$status = $this->params[ 'status' ] ?? 1;
if ($status !== 'all') {
$condition[] = [ 'sg.status', '=', $status ];
}
$field = 'g.goods_id,g.goods_name,g.goods_class,g.introduction,g.goods_image,g.goods_state,g.sku_id,g.price,gs.discount_price,g.goods_spec_format,gs.service_length,
IFNULL(IF(g.is_unify_price = 1,g.price,sg.price), g.price) as price, IFNULL(IF(g.is_unify_price = 1,gs.discount_price,sg.price), gs.discount_price) as discount_price,
sg.price as store_price';
$join = [
[ 'goods_sku gs', 'gs.sku_id = g.sku_id', 'left' ],
[ 'store_goods sg', 'g.goods_id=sg.goods_id and sg.store_id=' . $this->store_id, 'left' ],
[ 'store s', 's.store_id = sg.store_id', 'left' ]
];
$stock_store_id = ( new \app\model\store\Store() )->getStoreStockTypeStoreId([ 'store_id' => $this->store_id ])[ 'data' ] ?? 0;
if ($stock_store_id == $this->store_id) {
$field .= ', IFNULL(sg.stock, 0) as stock';
} else {
$join[] = [ 'store_goods sg2', 'g.goods_id=sg2.goods_id and sg2.store_id=' . $stock_store_id, 'left' ];
$field .= ', IFNULL(sg2.stock, 0) as stock';
}
$data = $model->getGoodsPageList($condition, $page_index, $page_size, 'g.sort asc,g.create_time desc', $field, 'g', $join);
return $this->response($data);
}
/**
* 商品详情
* @return false|string
*/
public function detail()
{
$goods_id = $this->params[ 'goods_id' ] ?? 0;
$goods_model = new GoodsModel();
$field = 'g.goods_id, g.goods_name, g.introduction, g.goods_class_name, g.goods_image, g.goods_state, g.sku_id, g.price, g.unit, g.cost_price, g.category_id, g.brand_name,g.is_unify_price,
sg.price as store_price, sg.cost_price as store_cost_price, sg.status as store_status';
$goods_info = $goods_model->getGoodsInfo([ [ 'g.goods_id', '=', $goods_id ], [ 'g.site_id', '=', $this->site_id ] ], $field, 'g', [
[ 'store_goods sg', 'g.goods_id=sg.goods_id and sg.store_id=' . $this->store_id, 'left' ]
])[ 'data' ];
if (empty($goods_info)) return $this->response($goods_model->error(null, '商品信息缺失'));
//查询商品规格
$sku_filed = 'sku.sku_id,sku.sku_name,sku.sku_no,sku.price,sku.discount_price,sku.cost_price,sku.sku_image,sku.sku_images,sku.spec_name,
sgs.price as store_stock, sgs.cost_price as store_cost_price, sgs.status as store_status';
$join = [
[ 'store_goods_sku sgs', 'sku.sku_id=sgs.sku_id and sgs.store_id=' . $this->store_id, 'left' ]
];
$goods_info[ 'sku_list' ] = $goods_model->getGoodsSkuList([ [ 'sku.goods_id', '=', $goods_id ], [ 'sku.site_id', '=', $this->site_id ] ], $sku_filed, 'sku.sku_id asc', 0, 'sku', $join)[ 'data' ];
return $this->response($goods_model->success($goods_info));
}
/**
* 上下架
*/
public function setStatus()
{
$goods_id = $this->params[ 'goods_id' ] ?? 0;
$status = $this->params[ 'status' ] ?? 0;
$model = new StoreGoodsModel();
$res = $model->modifyGoodsState($goods_id, $status, $this->site_id, $this->store_id);
return $this->response($res);
}
/**
* 商品编辑
*/
public function editGoods()
{
$goods_sku_array = isset($this->params[ 'goods_id' ]) ? json_decode($this->params[ 'goods_id' ]) : [];
$model = new StoreGoodsModel();
$res = $model->editStoreGoods($goods_sku_array, $this->site_id, $this->store_id, $this->uid);
return $this->response($res);
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\model\store\Stat as StatModel;
use app\storeapi\controller\BaseStoreApi;
use Carbon\Carbon;
/**
* 数据统计
* Class Stat
* @package addon\shop\siteapi\controller
*/
class Stat extends BaseStoreApi
{
/**
* 统计数据总和
*/
public function statTotal()
{
$start_time = $this->params['start_time'] ?? strtotime(date('Y-m-d', time()));
$end_time = $this->params['end_time'] ?? time();
if ($start_time > $end_time) {
$start_time = $this->params['end_time'];
$end_time = $this->params['start_time'];
}
$stat_model = new StatModel();
$data = $stat_model->getShopStatSum($this->site_id, $start_time, $end_time, $this->store_id);
return $this->response($data);
}
/**
* 获取天统计趋势数据
*/
public function dayStatData()
{
$start_time = $this->params['start_time'] ?? strtotime(date('Y-m-d', strtotime('-6 day')));
$end_time = $this->params['end_time'] ?? time();
if ($start_time > $end_time) {
$start_time = $this->params['end_time'];
$end_time = $this->params['start_time'];
}
$stat_model = new StatModel();
$fields = $stat_model->getStatField();
$fields[] = 'expected_earnings_total_money';
$stat_list = $stat_model->getShopStatList($this->site_id, $start_time, $end_time, $this->store_id)['data'];
$stat_list = array_map(function ($item) {
$item['day_time'] = date('Y-m-d', $item['day_time']);
return $item;
}, $stat_list);
$stat_list = array_column($stat_list, null, 'day_time');
$day = ceil(($end_time - $start_time) / 86400);
foreach ($fields as $field) {
$value = [];
$time = [];
for ($i = 0; $i < $day; $i++) {
$date = date('Y-m-d', $start_time + $i * 86400);
$time[] = $date;
$value[] = isset($stat_list[$date]) ? $stat_list[$date][$field] : 0;
}
$data[$field] = $value;
$data['time'] = $time;
}
return $this->response($this->success($data));
}
/**
* 获取小时统计趋势数据
*/
public function hourStatData()
{
$time = $this->params['start_time'] ?? time();
$carbon = Carbon::createFromTimestamp($time);
$stat_model = new StatModel();
$fields = $stat_model->getStatHourField();
$fields[] = 'expected_earnings_total_money';
$stat_list = $stat_model->getShopStatHourList($this->site_id, $carbon->year, $carbon->month, $carbon->day, $this->store_id)['data'];
$data = [];
$empty = array_map(function () {
return 0;
}, range(0, 23, 1));
if (!empty($stat_list)) {
$stat_list = array_column($stat_list, null, 'hour');
foreach ($fields as $field) {
$value = [];
for ($i = 0; $i < 24; $i++) {
$value[$i] = isset($stat_list[$i]) ? $stat_list[$i][$field] : 0;
}
$data[$field] = $value;
}
} else {
foreach ($fields as $field) {
$data[$field] = $empty;
}
}
$data['time'] = array_map(function ($value) {
return $value . '时';
}, range(0, 23, 1));
return $this->response($this->success($data));
}
}

View File

@@ -0,0 +1,216 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cashier\model\Menu;
use addon\stock\model\stock\Stock as StockModel;
use app\model\express\ExpressDeliver;
use app\model\store\Store as StoreModel;
use app\storeapi\controller\BaseStoreApi;
/**
* 门店控制器
*/
class Store extends BaseStoreApi
{
public function checkPageAuth()
{
$page = $this->params[ 'page' ] ?? '';
if ($this->user_info[ 'is_admin' ]) return $this->response($this->success());
$name = ( new Menu() )->getMenuValue([ [ 'url', '=', substr($page, 1) ], [ 'type', '=', 'page' ] ], 'name')[ 'data' ];
if (empty($name)) return $this->response($this->success());
$menu_array = $this->store_list[ $this->store_id ][ 'menu_array' ] ?? '';
if (empty($menu_array)) return $this->response($this->success());
if (!in_array($name, explode(',', $menu_array))) return $this->response($this->error([], 'NO_PERMISSION'));
return $this->response($this->success());
}
/**
* 获取可管理的门店列表
* @return false|string
*/
public function lists()
{
$store_ids = array_keys($this->store_list);
$store_model = new StoreModel();
$store_info = $store_model->getStoreList([ [ 'store_id', 'in', $store_ids ] ], 'store_id,store_image,store_name,full_address,address,open_date', 'is_default desc,store_id desc');
return $this->response($store_info);
}
/**
* 编辑门店
* @return false|string
*/
public function editStore()
{
$store_id = $this->store_id;
$condition = [
[ 'site_id', '=', $this->site_id ],
[ 'store_id', '=', $store_id ]
];
$store_model = new StoreModel();
$data = [
'store_name' => $this->params[ 'store_name' ] ?? '',
'telphone' => $this->params[ 'telphone' ] ?? '',
'store_image' => $this->params[ 'store_image' ] ?? '',
'province_id' => $this->params[ 'province_id' ] ?? 0,
'city_id' => $this->params[ 'city_id' ] ?? 0,
'district_id' => $this->params[ 'district_id' ] ?? 0,
'community_id' => $this->params[ 'community_id' ] ?? 0,
'address' => $this->params[ 'address' ] ?? '',
'full_address' => $this->params[ 'full_address' ] ?? '',
'longitude' => $this->params[ 'longitude' ] ?? '',
'latitude' => $this->params[ 'latitude' ] ?? '',
'store_type' => $this->params[ 'store_type' ] ?? '',
];
$result = $store_model->editStore($data, $condition, [], 1, 1);
return $this->response($result);
}
/**
* 编辑门店运营设置
* @return false|string
*/
public function editStoreOperate()
{
$store_id = $this->store_id;
$condition = [
[ 'site_id', '=', $this->site_id ],
[ 'store_id', '=', $store_id ]
];
$store_model = new StoreModel();
$data = [
'store_image' => $this->params[ 'store_image' ] ?? '',
'start_time' => $this->params[ 'start_time' ] ?? '',
'end_time' => $this->params[ 'end_time' ] ?? '',
'time_type' => $this->params[ 'time_type' ] ?? '',
'time_week' => $this->params[ 'time_week' ] ?? '',
'stock_type' => $this->params[ 'stock_type' ] ?? '',
'is_pickup' => $this->params[ 'is_pickup' ] ?? '',
'is_o2o' => $this->params[ 'is_o2o' ] ?? '',
'open_date' => $this->params[ 'open_date' ] ?? '',
'status' => $this->params[ 'status' ] ?? 0,
];
$result = $store_model->editStore($data, $condition, [], 1, 1);
return $this->response($result);
}
/**
* 配送员列表
*/
public function deliverLists()
{
$deliver_model = new ExpressDeliver();
$page = $this->params[ 'page' ] ?? '';
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$search_text = $this->params[ 'search_text' ] ?? '';
$condition = [
[
'site_id', '=', $this->site_id,
],
[
'store_id', '=', $this->store_id,
]
];
if (!empty($search_text)) {
$condition[] = [ 'deliver_name', 'like', '%' . $search_text . '%' ];
}
$deliver_lists = $deliver_model->getDeliverPageLists($condition, '*', 'create_time desc', $page, $page_size);
return $this->response($deliver_lists);
}
/**
* 添加配送员
*/
public function deliverinfo()
{
$deliver_id = $this->params[ 'deliver_id' ] ?? 0;
$deliver_model = new ExpressDeliver();
$result = $deliver_model->getDeliverInfo($deliver_id, $this->site_id, $this->store_id);
return $this->response($result);
}
/**
* 添加配送员
*/
public function addDeliver()
{
$deliver_model = new ExpressDeliver();
$data = [
'deliver_name' => $this->params[ 'deliver_name' ] ?? '',
'deliver_mobile' => $this->params[ 'deliver_mobile' ] ?? '',
'store_id' => $this->store_id,
'site_id' => $this->site_id,
];
$result = $deliver_model->addDeliver($data);
return $this->response($result);
}
/**
* 编辑配送员
*/
public function editDeliver()
{
$deliver_id = $this->params[ 'deliver_id' ] ?? 0;
$deliver_model = new ExpressDeliver();
$data = [
'deliver_name' => $this->params[ 'deliver_name' ] ?? '',
'deliver_mobile' => $this->params[ 'deliver_mobile' ] ?? '',
'site_id' => $this->site_id,
'store_id' => $this->store_id
];
$result = $deliver_model->editDeliver($data, $deliver_id);
return $this->response($result);
}
/**
* 删除配送员
*/
public function deleteDeliver()
{
$deliver_model = new ExpressDeliver();
$deliver_id = $this->params[ 'deliver_id' ] ?? 0;
$site_id = $this->site_id;
$result = $deliver_model->deleteDeliver($deliver_id, $site_id, $this->store_id);
return $this->response($result);
}
/**
* 获取门店信息
*/
public function info()
{
$store_model = new StoreModel();
$store_info = $store_model->getStoreDetail([ [ 'store_id', '=', $this->store_id ] ]);
$stock_config = [];
if (addon_is_exit('stock')) {
$stock_model = new StockModel();
$stock_config = $stock_model->getStockConfig($this->site_id)[ 'data' ][ 'value' ];
}
$store_info[ 'data' ][ 'stock_config' ] = $stock_config;
return $this->response($store_info);
}
}

View File

@@ -0,0 +1,182 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\model\upload\Upload as UploadModel;
use app\storeapi\controller\BaseStoreApi;
/**
* Class Upload
* @package addon\shop\siteapi\controller
*/
class Upload extends BaseStoreApi
{
/**
* 上传(不存入相册)
* @return false|string
*/
public function image()
{
$site_id = $this->site_id;
$upload_model = new UploadModel($site_id, $this->app_module);
$thumb_type = $this->params['thumb'] ?? '';
$name = $this->params['name'] ?? '';
$watermark = $this->params['watermark'] ?? 0;// 是否需生成水印
$cloud = $this->params['cloud'] ?? 1;// 是否需上传到云存储
$width = $this->params['width'] ?? 0;// 限制宽度
$height = $this->params['height'] ?? 0;// 限制高度
$from = $this->params['from'] ?? '';// 位置
$param = [
'thumb_type' => '',
'name' => 'file',
'watermark' => $watermark,
'cloud' => $cloud,
'width' => $width,
'height' => $height,
'from' => $from
];
$result = $upload_model->setPath('common/images/' . date('Ymd') . '/')->image($param);
return $this->response($result);
}
/**
* 上传 存入相册
* @return false|string
*/
public function album()
{
$upload_model = new UploadModel($this->site_id);
$album_id = $this->params['album_id'] ?? 0;
$name = $this->params['name'] ?? '';
$param = [
'thumb_type' => ['BIG', 'MID', 'SMALL'],
'name' => 'file',
'album_id' => $album_id
];
$result = $upload_model->setPath('common/images/' . date('Ymd') . '/')->imageToAlbum($param);
return $this->response($result);
}
/**
* 视频上传
* @return false|string
*/
public function video()
{
$upload_model = new UploadModel($this->site_id);
$name = $this->params['name'] ?? '';
$param = [
'name' => 'file'
];
$result = $upload_model->setPath('common/video/' . date('Ymd') . '/')->video($param);
return $this->response($this->success($result));
}
/**
* 上传(不存入相册)
* @return false|string
*/
public function upload()
{
$upload_model = new UploadModel();
$name = $this->params['name'] ?? '';
$thumb_type = $this->params['thumb'] ?? '';
$param = [
'thumb_type' => '',
'name' => 'file'
];
$result = $upload_model->setPath('common/images/' . date('Ymd') . '/')->image($param);
return $this->response($this->success($result));
}
/**
* 校验文件
*/
public function checkfile()
{
$upload_model = new UploadModel();
$result = $upload_model->domainCheckFile([ 'name' => 'file']);
return $this->response($result);
}
/**
* 上传文件
*/
public function file()
{
$upload_model = new UploadModel($this->site_id);
$param = [
'name' => 'file',
'extend_type' => [ 'xlsx', 'pdf' ]
];
$result = $upload_model->setPath('common/file/' . date('Ymd') . '/')->file($param);
return $this->response($this->success($result));
}
/**
* 删除文件
*/
public function deleteFile()
{
if (request()->isJson()) {
$path = $this->params['path'] ?? '';
$res = false;
if (!empty($path)) {
$res = delFile($path);
}
return $this->response($this->success($res));
}
}
/**
* 上传微信支付证书
*/
public function uploadWechatCert()
{
$upload_model = new UploadModel();
$site_id = $this->site_id;
$name = $this->params['name'] ?? '';
$extend_type = [ 'pem' ];
$param = [
'name' => 'file',
'extend_type' => $extend_type
];
$site_id = max($site_id, 0);
$result = $upload_model->setPath('common/wechat/cert/' . $site_id . '/')->file($param);
return $this->response($this->success($result));
}
/**
* 退款退货凭证上传
*/
public function refundMessageImg()
{
$upload_model = new UploadModel($this->site_id);
$param = [
'thumb_type' => '',
'name' => 'file',
'watermark' => 0,
'cloud' => 1
];
$result = $upload_model->setPath('refund/refund_message/' . date('Ymd') . '/')->image($param);
return $this->response($result);
}
}

View File

@@ -0,0 +1,247 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cashier\model\Group;
use app\model\system\User as UserModel;
use app\model\system\UserGroup;
use app\storeapi\controller\BaseStoreApi;
/**
* 用户控制器
* Class User
* @package addon\shop\siteapi\controller
*/
class User extends BaseStoreApi
{
/**
* 用户列表
* @return false|string
*/
public function lists()
{
$page = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$status = $this->params[ 'status' ] ?? '';
$username = $this->params[ 'username' ] ?? '';
$condition = [
[ 'ug.site_id', '=', $this->site_id ],
[ 'ug.store_id', '=', $this->store_id ],
[ 'ug.app_module', '=', 'store' ]
];
$curr_user_info = $this->getUserInfo();
if($curr_user_info['create_uid'] > 0){
$condition[] = ['u.create_user_data', 'like', '%"'.$this->uid.'"%'];
}
if (!empty($username)) {
$condition[] = [ 'u.username', 'like', '%' . $username . '%' ];
}
if ($status != '') {
$condition[ 'u.status' ] = [ 'status', '=', $status ];
}
$join = [
[ 'user u', 'u.uid = ug.uid', 'inner' ],
[ 'cashier_auth_group cag', 'cag.group_id = ug.group_id', 'inner' ]
];
$field = 'u.uid,u.username,u.is_admin,u.status,u.create_time,cag.group_id,cag.group_name,u.login_time,u.create_uid,u.create_user_data';
$user_model = new UserGroup();
$list = $user_model->getUserPageList($condition, $page, $page_size, 'u.is_admin desc,u.create_time desc', $field, 'ug', $join);
return $this->response($list);
}
/**
* 添加用户
* @return false|string
*/
public function addUser()
{
$username = $this->params[ 'username' ] ?? '';
$password = $this->params[ 'password' ] ?? '';
$group_id = $this->params[ 'group_id' ] ?? '';
$user_model = new UserModel();
$data = [
'username' => $username,
'password' => $password,
'group_id' => $group_id,
'app_module' => 'shop',
'site_id' => $this->site_id,
'store' => [
[ 'store_id' => $this->store_id, 'group_id' => $group_id ]
],
'create_uid' => $this->uid,
];
$result = $user_model->addUser($data, $this->store_id, 'add');
return $this->response($result);
}
/**
* 用户详情
*/
public function userInfo()
{
$uid = $this->params[ 'uid' ] ?? 0;
if (!$uid) {
$user_info = $this->success($this->user_info);
}else{
$condition = [
[ 'ug.site_id', '=', $this->site_id ],
[ 'ug.store_id', '=', $this->store_id ],
[ 'ug.uid', '=', $uid ],
[ 'ug.app_module', '=', 'store' ]
];
$join = [
[ 'user u', 'u.uid = ug.uid', 'inner' ],
[ 'group g', 'g.group_id = u.group_id', 'left' ],
[ 'cashier_auth_group cag', 'cag.group_id = ug.group_id', 'inner' ]
];
$field = 'u.uid,u.username,u.is_admin,u.status,u.create_time,u.login_time,u.login_ip,cag.group_id,cag.group_name,g.is_system,u.create_uid,u.create_user_data';
$user_model = new UserGroup();
$user_info = $user_model->getUserInfo($condition, $field, 'ug', $join);
}
if(!empty($user_info['data']['uid'])){
$user_model = new UserModel();
$user_info['data']['user_group_list'] = $user_model->getUserInfo([['uid', '=', $user_info['data']['uid']]], 'uid')['data']['user_group_list'] ?? [];
}
if(!empty($user_info['data']['create_uid'])){
$user_model = new UserModel();
$user_info['data']['create_user_info'] = $user_model->getUserInfo([['uid', '=', $user_info['data']['create_uid']]], '*')['data'];
}
return $this->response($user_info);
}
/**
* 删除用户
*/
public function deleteUser()
{
$uid = $this->params[ 'uid' ] ?? 0;
if ($uid == $this->user_info[ 'uid' ]) return $this->response($this->error('', '自己不能删除自己'));
$user_model = new UserGroup();
$condition = [
[ 'uid', '=', $uid ],
[ 'site_id', '=', $this->site_id ],
[ 'store_id', '=', $this->store_id ],
];
$result = $user_model->deleteUser($condition);
return $this->response($result);
}
/**
* 管理组列表
* @return false|string
*/
public function group()
{
$condition = [
[ 'site_id', '=', $this->site_id ],
[ 'store_id', 'in', [0,$this->store_id]],
];
$group_model = new Group();
$list = $group_model->getGroupList($condition, 'group_id,group_name,create_uid,create_user_data,store_id,store_name');
return $this->response($list);
}
/**
* 用户日志
*/
public function userLog()
{
$user_model = new UserModel();
$page = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$uid = $this->params[ 'uid' ] ?? 0;
$search_keys = $this->params[ 'search_keys' ] ?? '';
$condition = [];
$condition[] = [ 'site_id', '=', $this->site_id ];
if (!empty($search_keys)) {
$condition[] = [ 'action_name', 'like', '%' . $search_keys . '%' ];
}
if ($uid > 0) {
$condition[] = [ 'uid', '=', $uid ];
}
$list = $user_model->getUserLogPageList($condition, $page, $page_size, 'create_time desc');
return $this->response($list);
}
/**
* 编辑用户
* @return false|string
*/
public function editUser()
{
$user_model = new UserModel();
$group_id = $this->params[ 'group_id' ] ?? '';
$status = $this->params[ 'status' ] ?? '';
$uid = $this->params[ 'uid' ] ?? 0;
$condition = [
[ 'uid', '=', $uid ],
[ 'site_id', '=', $this->site_id ],
[ 'app_module', '=', $this->app_module ],
];
$data = [
'group_id' => $group_id,
'status' => $status,
'store' => [
[ 'store_id' => $this->store_id, 'group_id' => $group_id ]
]
];
$this->addLog('编辑用户:' . $uid);
$result = $user_model->editUser($data, $condition);
return $this->response($result);
}
/**
* 修改密码
* */
public function modifyPassword()
{
$site_id = $this->site_id;
$user_model = new UserModel();
$uid = $this->uid;
$old_pass = $this->params[ 'old_pass' ] ?? '';
$new_pass = $this->params[ 'new_pass' ] ?? '123456';
$condition = [
[ 'uid', '=', $uid ],
[ 'password', '=', data_md5($old_pass) ],
[ 'site_id', '=', $site_id ]
];
$res = $user_model->modifyAdminUserPassword($condition, $new_pass);
return $this->response($res);
}
/**
* 获取门店用户权限
*/
public function userGroupAuth()
{
$data = [
'is_admin' => $this->user_info[ 'is_admin' ],
'menu_array' => $this->store_list[ $this->store_id ][ 'menu_array' ] ?? ''
];
return $this->response($this->success($data));
}
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use app\model\verify\Verify as VerifyModel;
use app\model\verify\VerifyRecord;
use app\storeapi\controller\BaseStoreApi;
/**
* 订单核销控制器
* Class Verify
* @package addon\shop\siteapi\controller
*/
class Verify extends BaseStoreApi
{
/**
* 获取核销码信息
* @return false|string
*/
public function info()
{
$code = $this->params[ 'code' ] ?? '';
$verify_model = new VerifyModel();
$condition = [
[ 'verify_code', '=', $code ],
[ 'site_id', '=', $this->site_id ],
[ 'store_id', 'in', [0, $this->store_id] ]
];
$info = $verify_model->getVerifyInfo($condition);
if(!empty($info['data'])){
$check_store_res = $verify_model->checkStore($info['data'], $this->store_id);
if($check_store_res['code'] < 0){
return $this->response($check_store_res);
}
}
return $this->response($info);
}
/**
* 核销类型
*/
public function verifyType()
{
$verify_model = new VerifyModel();
$verify_type = $verify_model->getVerifyType();
return $this->response($this->success($verify_type));
}
/**
* 核销
*/
public function verify()
{
$verify_code = $this->params[ 'verify_code' ] ?? '';
$info = [
'verifier_id' => $this->uid,
'verifier_name' => $this->user_info[ 'username' ],
'verify_from' => 'shop',
'store_id' => $this->store_id
];
$verify_model = new VerifyModel();
$res = $verify_model->verify($info, $verify_code);
return $this->response($res);
}
/**
* 核销记录
* @return false|string
*/
public function recordLists()
{
$verify_model = new VerifyRecord();
$page = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$verify_type = $this->params[ 'verify_type' ] ?? '';//验证类型
$search_text = $this->params[ 'search_text' ] ?? '';
$start_time = $this->params[ 'start_time' ] ?? '';
$end_time = $this->params[ 'end_time' ] ?? '';
$condition = [
[ 'store_id', '=', $this->store_id ],
];
if (!empty($search_text)) {
$condition[] = [ 'verify_code|verifier_name', 'like', '%' . $search_text . '%' ];
}
if (!empty($start_time) && empty($end_time)) {
$condition[] = [ 'verify_time', '>=', date_to_time($start_time) ];
} elseif (empty($start_time) && !empty($end_time)) {
$condition[] = [ 'verify_time', '<=', date_to_time($end_time) ];
} elseif (!empty($start_time) && !empty($end_time)) {
$condition[] = [ 'verify_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
}
$list = $verify_model->getVerifyRecordsPageList($condition, $page, $page_size, '*', 'verify_time desc');
return $this->response($list);
}
/**
* 核销记录详情
* @return false|string
*/
public function recordsDetail()
{
$id = $this->params[ 'id' ] ?? 0;
$verify_model = new VerifyRecord();
$condition = [
[ 'vr.id', '=', $id ],
[ 'vr.store_id', '=', $this->store_id ]
];
$field = 'vr.*,v.verify_type_name,v.expire_time,v.verify_total_count,v.verify_use_num,v.verify_content_json,v.member_id, m.nickname,m.headimg,m.mobile';
$join = [
[ 'verify v', 'v.verify_code = vr.verify_code', 'left' ],
[ 'member m', 'v.member_id = m.member_id', 'left' ],
];
$verify_detail = $verify_model->getVerifyRecordsInfo($condition, $field, 'vr', $join)[ 'data' ] ?? [];
if (!empty($verify_detail)) {
$verify_detail['verify_content_json'] = json_decode($verify_detail['verify_content_json'], true);
}
return $this->response($this->success($verify_detail));
}
}