文件
mashangyoujiu/Application/Terminalapi/Controller/BaseController.class.php

8073 行
340 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Terminalapi\Controller;
use Common\Business\Goods;
use Common\Business\InventoryOperation;
use Common\Business\InventoryRecord;
use Common\Business\InventorySet;
use Common\Business\OutboundOrder;
use Common\Business\PaymentRefund;
use Common\Business\Plug;
use Common\Business\PurchaseGoodsInfo;
use Common\Business\RefuseWarehousing;
use Common\Business\SaleGoods;
use Common\Business\Sell;
use Common\Business\SerialNumberGoods;
use Common\Business\ShoppingMall;
use Common\Business\StockRecord;
use Common\Business\Store;
use Common\Business\VipEdit;
use Common\Business\WarehousingRecord;
use Common\Model\MemberAnalyzeModel;
use Common\Model\RechargeOrderModel;
use Common\Model\RetailBillOrderModel;
use Common\Model\RetailCashierModel;
use Common\Model\RetailDaOrderModel;
use Common\Model\RetailMerchantConfigModel;
use Common\Model\RetailMerchantModel;
use Common\Model\RetailPayOrderModel;
use Common\Model\RetailStoreModel;
use Common\Model\RetailUuOrderModel;
use Common\Model\SPurchaseOrderModel;
use Common\Model\SStockGoodsSerialModel;
use Common\Model\SStockOutGoodsModel;
use Common\Model\StockGoodsSerialModel;
use Common\Model\StockOutGoodsModel;
use Common\Model\SWarehousingGoodsModel;
use Common\Model\VipConfigModel;
use Common\Order\BillOrder;
use Common\Order\PayOrder;
use LittleGift\Business\Vip;
use Make\Model\MakeOrderModel;
use Pay\Controller\CloudPayController;
use Terminalapi\Business\Statistics;
use Think\Controller;
use Blessing\Business\Index;
//[1.9.20]
/**
* Class BaseController
* @package Terminalapi\Controller
*/
class BaseController extends Controller
{
/**
* @param parameter 日志公共参数
* type 1合伙人端 2代理商端 3商户端 4门店端
* desc 描述
*/
protected function system_parameter($parameter)
{
$log_data = array(
'source' => 1,
'type' => $parameter['type'],
'desc' => $parameter['desc'],
'request_data' => json_encode($_POST),
'operator_id' => $_POST['operator_id'],
'mer_id' => $_POST['merchantid']
);
action_log_v2($log_data);
}
//登录接口
protected function login()
{
if (IS_POST) {
$userName = I("post.username");
$pwd = I("post.password");
$type = I("post.type");
$merchant = M('retail_merchant'); // 商户
$manager = M('retail_manager'); // 店长getLogo
$map['mobile'] = $userName;
$map['status'] = 1; //店长表:1:正常 2:被删除 商户表:1:正常 2:被禁用 3:被删除 只取1
$JMap['login_name'] = $userName;
$JMap['state'] = 1;
$JMap['status'] = 1;
$JMap['first_pid'] = 0;
//实例化插件类
$PlugApi = new Plug();
if ($type == 3) {
//商户登录
$User = $merchant->where($map)->find();
$JMap['user_type'] = 3;
$JMap['system_user_id'] = $User['id'];
$JurUser = M('jurisdiction_user')->where($JMap)->find();
if (empty($User) || empty($JurUser)) {
$res['status'] = 0;
$res['msg'] = '账号不存在或已被禁用';
} else {
//商户有使用失效限制,需要判断账号是否可用
$now = time();
if ($now > $User['begin_time'] && $now < $User['end_time']) {
//账号可用
$CryptrModel = new \Addons\Api\Crypto();
$orignPwd = $CryptrModel->encrypt($pwd, date('YmdHis', $JurUser['add_time']));
if ($orignPwd == $JurUser['password']) {
$time = time();
if ($User['begin_time'] < $time && $time < $User['end_time']) {
$storelist = M('retail_store')
->where(array('merchantid' => $User['id'], 'state' => 0, 'store_status' => 0))
->field('id as storeid,storetag as name')
->order('store_type asc,addtime asc')
->select();
$res['status'] = 1;
$User2['usertype'] = 1;
if (count($storelist) > 0) {
$User2['storetag'] = $storelist[0]['name'];
} else {
$User2['storetag'] = "暂无门店";
$res['status'] = 0;
$res['msg'] = '对不起,商户下无可用门店,无法登录';
$this->ajaxReturn($res);
}
$User2['storelist'] = $storelist;
$User2['merchantid'] = $User['id'];
$User2['uid'] = $User['id'];
$User2['operator_id'] = $JurUser['id'];
//获取付费插件列表及状态
$plug_result = $PlugApi->PlugPermissions(array(
'merchant_id' => $User2['merchantid'],
'identification_arr' => ['credit']
));
//商户是否存在赊账插件
$User2['is_credit'] = $plug_result['data']['plug']['credit'] && $plug_result['data']['plug']['credit'] > 0 ? true : false;
$res['msg'] = '登录成功';
$res['userinfo'] = $User2;
} else {
$res['msg'] = '账号已到期,请联系商家';
}
} else {
$res['msg'] = '密码错误';
}
} elseif ($now < $User['begin_time']) {
//账号正常 但未到启用时间
$res['status'] = 0;
$res['msg'] = '对不起,该账号还未到使用时间范围,无法登录';
} elseif ($now > $User['end_time']) {
//账号过期
$res['status'] = 0;
$res['msg'] = '对不起,该账号已过期,无法登录';
}
}
} elseif ($type == 4) {
//店长登录
$cashier = $manager->where($map)->find();
$JMap['user_type'] = 4;
$JMap['system_user_id'] = $cashier['id'];
$JurUser = M('jurisdiction_user')->where($JMap)->find();
if (empty($cashier) || empty($JurUser)) {
//查询不到
$res['status'] = 0;
$res['msg'] = '账号不存在';
} else {
$User = $merchant->where(array('id' => $cashier['merchantid']))->find();
$store = M("retail_store")->where(array('id' => $cashier['storeid']))->find();
//商户有使用失效限制,需要判断账号是否可用
//还需判断商户账号是否可用
if ($User['status'] == 1) {
$now = time();
if ($now > $User['begin_time'] && $now < $User['end_time']) {
//账号可用
//需要判断门店状态
if (empty($store)) {
$res['status'] = 0;
$res['msg'] = '不存在该门店,无法登录';
} elseif ($store['state'] == '1') {
//被删除状态
$res['status'] = 0;
$res['msg'] = '门店状态异常,无法登录';
} elseif ($store['state'] == '0' && $store['store_status'] == '0') {
$CryptrModel = new \Addons\Api\Crypto();
$orignPwd = $CryptrModel->encrypt($pwd, date('YmdHis', $JurUser['add_time']));
if ($orignPwd == $JurUser['password']) {
$inventorySet = new InventorySet();
$inventory_set = $inventorySet->getInfo([
'user_type' => 4,
'merchant_id' => $cashier['merchantid'],
'store_id' => $cashier['storeid']
]);
$res['status'] = 1;
$cashier['account_type'] = 2;
$res['msg'] = '登录成功';
$userinfo['usertype'] = 2;
$userinfo['storeid'] = $cashier['storeid'];
$userinfo['merchantid'] = $cashier['merchantid'];
$userinfo['uid'] = $cashier['id'];
$userinfo['storetag'] = $store['storetag'];
$userinfo['supplier_type'] = $store['supplier_type'];
$userinfo['manager_id'] = $cashier['id'];
$userinfo['operator_id'] = $JurUser['id'];
$userinfo['modify_price_state'] = $inventory_set['modify_price_state']; //是否可以编辑零售价
//获取付费插件列表及状态
$plug_result = $PlugApi->PlugPermissions(array(
'merchant_id' => $userinfo['merchantid'],
'identification_arr' => ['credit']
));
//商户是否存在赊账插件
$userinfo['is_credit'] = $plug_result['data']['plug']['credit'] && $plug_result['data']['plug']['credit'] > 0 ? true : false;
$res['userinfo'] = $userinfo;
} else {
$res['msg'] = '密码错误';
}
} elseif ($store['state'] == '0' && $store['store_status'] == '1') {
$res['status'] = 0;
$res['msg'] = '门店状态异常,无法登录,请联系商家管理员';
}
} elseif ($now < $User['begin_time']) {
//账号正常 但未到启用时间
$res['status'] = 0;
$res['msg'] = '对不起,该商户账号还未到使用时间范围,无法登录';
} elseif ($now > $User['end_time']) {
//账号过期
$res['status'] = 0;
$res['msg'] = '对不起,该商户账号已过期,无法登录';
}
} else {
//商户账号不可用
$res['status'] = 0;
$res['msg'] = '商户账号不可用,无法登录';
}
}
} else if ($type == 5) {
//收银员登录
A('CashierApi/Login')->doLogin_v1();
}
$this->ajaxReturn($res);
} else {
$res['status'] = 0;
$res['msg'] = '错误的请求方式,必须是post方式';
$this->ajaxReturn($res);
}
}
/**
* 2020-05-30
* 登录接口
*/
protected function login_v1()
{
if (IS_POST) {
$userName = I("post.username");
$pwd = I("post.password");
$type = I("post.type");
$merchant = M('retail_merchant'); // 商户
$manager = M('retail_manager'); // 店长getLogo
$map['mobile'] = $userName;
$map['status'] = 1; //店长表:1:正常 2:被删除 商户表:1:正常 2:被禁用 3:被删除 只取1
$JMap['login_name'] = $userName;
$JMap['state'] = 1;
$JMap['status'] = 1;
$JMap['first_pid'] = 0;
$PlugApi = new Plug();
if ($type == 3) {
//商户登录
$User = $merchant->where($map)->find();
$JMap['user_type'] = 3;
$JMap['system_user_id'] = $User['id'];
$JurUser = M('jurisdiction_user')->where($JMap)->find();
if (empty($User) || empty($JurUser)) {
$res['status'] = 0;
$res['msg'] = '账号不存在或已被禁用';
} else {
//商户有使用失效限制,需要判断账号是否可用
$now = time();
if ($now > $User['begin_time'] && $now < $User['end_time']) {
//账号可用
$CryptrModel = new \Addons\Api\Crypto();
$orignPwd = $CryptrModel->encrypt($pwd, date('YmdHis', $JurUser['add_time']));
if ($orignPwd == $JurUser['password']) {
$time = time();
if ($User['begin_time'] < $time && $time < $User['end_time']) {
$storelist = M('retail_store')
->where(array('merchantid' => $User['id'], 'state' => 0, 'store_status' => 0))
->field('id as storeid,storetag as name')
->order('store_type asc,addtime asc')
->select();
$res['status'] = 1;
$User2['usertype'] = 1;
if (count($storelist) > 0) {
$User2['storetag'] = $storelist[0]['name'];
} else {
$User2['storetag'] = "暂无门店";
$res['status'] = 0;
$res['msg'] = '对不起,商户下无可用门店,无法登录';
$this->ajaxReturn($res);
}
$User2['storelist'] = $storelist;
$User2['merchantid'] = $User['id'];
$User2['uid'] = $User['id'];
$User2['operator_id'] = $JurUser['id'];
//获取付费插件列表及状态
$plug_result = $PlugApi->merPlugState([
'merchant_id' => $User2['merchantid'],
'identification_arr' => ['credit', 'moraleducationcoin']
]);
$User2['is_credit'] = $plug_result['credit'];
$User2['moralEducationCoin'] = $plug_result['moraleducationcoin'];
$RetailMerchantConfigModel = new RetailMerchantConfigModel();
$VipConfigModel = new VipConfigModel();
$User2['goods_integral_state'] = $VipConfigModel->getFindField(['merchantid' => $User['id']], 'goods_integral_state'); //1开启 2关闭
$User2['is_check_show_invenum'] = $RetailMerchantConfigModel->getFindField(['merchant_id' => $User['id']], 'is_check_show_invenum');
$User2['platform_type'] = $User['platform_type'] ? $User['platform_type'] : 1;
if ($plug_result['moraleducationcoin']) {
//商户德育币插件设置是否禁用非德育币支付方式
$MerModel = new \MoralEducationCoin\Model\MoralEducationCoinMerModel();
$conf = $MerModel->getFind(['merchant_id' => $User['id']], 'only_pay');
$User2['show_normal_pay'] = $conf['only_pay'] == 1 ? 0 : 1;
} else {
$User2['show_normal_pay'] = 1;
}
$res['msg'] = '登录成功';
$res['userinfo'] = $User2;
} else {
$res['msg'] = '账号已到期,请联系商家';
}
} else {
$res['msg'] = '密码错误';
}
} elseif ($now < $User['begin_time']) {
//账号正常 但未到启用时间
$res['status'] = 0;
$res['msg'] = '对不起,该账号还未到使用时间范围,无法登录';
} elseif ($now > $User['end_time']) {
//账号过期
$res['status'] = 0;
$res['msg'] = '对不起,该账号已过期,无法登录';
}
}
} elseif ($type == 4) {
//店长登录
$cashier = $manager->where($map)->find();
$JMap['user_type'] = 4;
$JMap['system_user_id'] = $cashier['id'];
$JurUser = M('jurisdiction_user')->where($JMap)->find();
if (empty($cashier) || empty($JurUser)) {
//查询不到
$res['status'] = 0;
$res['msg'] = '账号不存在';
} else {
$User = $merchant->where(array('id' => $cashier['merchantid']))->find();
$store = M("retail_store")->where(array('id' => $cashier['storeid']))->find();
//商户有使用失效限制,需要判断账号是否可用
//还需判断商户账号是否可用
if ($User['status'] == 1) {
$now = time();
if ($now > $User['begin_time'] && $now < $User['end_time']) {
//账号可用
//需要判断门店状态
if (empty($store)) {
$res['status'] = 0;
$res['msg'] = '不存在该门店,无法登录';
} elseif ($store['state'] == '1') {
//被删除状态
$res['status'] = 0;
$res['msg'] = '门店状态异常,无法登录';
} elseif ($store['state'] == '0' && $store['store_status'] == '0') {
$CryptrModel = new \Addons\Api\Crypto();
$orignPwd = $CryptrModel->encrypt($pwd, date('YmdHis', $JurUser['add_time']));
if ($orignPwd == $JurUser['password']) {
$res['status'] = 1;
$cashier['account_type'] = 2;
$res['msg'] = '登录成功';
$userinfo['usertype'] = 2;
$userinfo['storeid'] = $cashier['storeid'];
$userinfo['merchantid'] = $cashier['merchantid'];
$userinfo['uid'] = $cashier['id'];
$userinfo['storetag'] = $store['storetag'];
$userinfo['supplier_type'] = $store['supplier_type'];
$userinfo['manager_id'] = $cashier['id'];
$userinfo['operator_id'] = $JurUser['id'];
$VipConfigModel = new VipConfigModel();
$userinfo['goods_integral_state'] = $VipConfigModel->getFindField(['merchantid' => $cashier['merchantid']], 'goods_integral_state'); //1开启 2关闭
$StoreConfigModel = new \Common\Model\StoreConfigModel();
$userinfo['is_check_show_invenum'] = $StoreConfigModel->getFindField(['store_id' => $store['id']], 'is_check_show_invenum');
//获取付费插件列表及状态
$plug_result = $PlugApi->merPlugState([
'merchant_id' => $userinfo['merchantid'],
'identification_arr' => ['credit', 'moraleducationcoin']
]);
$userinfo['is_credit'] = $plug_result['credit'];
$userinfo['moralEducationCoin'] = $plug_result['moraleducationcoin'];
$userinfo['platform_type'] = $User['platform_type'] ? $User['platform_type'] : 1;
if ($plug_result['moraleducationcoin']) {
//商户德育币插件设置是否禁用非德育币支付方式
$MerModel = new \MoralEducationCoin\Model\MoralEducationCoinMerModel();
$conf = $MerModel->getFind(['merchant_id' => $userinfo['merchantid']], 'only_pay');
$userinfo['show_normal_pay'] = $conf['only_pay'] == 1 ? 0 : 1;
} else {
$userinfo['show_normal_pay'] = 1;
}
$res['userinfo'] = $userinfo;
} else {
$res['msg'] = '密码错误';
}
} elseif ($store['state'] == '0' && $store['store_status'] == '1') {
$res['status'] = 0;
$res['msg'] = '门店状态异常,无法登录,请联系商家管理员';
}
} elseif ($now < $User['begin_time']) {
//账号正常 但未到启用时间
$res['status'] = 0;
$res['msg'] = '对不起,该商户账号还未到使用时间范围,无法登录';
} elseif ($now > $User['end_time']) {
//账号过期
$res['status'] = 0;
$res['msg'] = '对不起,该商户账号已过期,无法登录';
}
} else {
//商户账号不可用
$res['status'] = 0;
$res['msg'] = '商户账号不可用,无法登录';
}
}
} else if ($type == 5) {
//收银员登录
A('CashierApi/Login')->doLogin_v1();
}
$this->ajaxReturn($res);
} else {
$res['status'] = 0;
$res['msg'] = '错误的请求方式,必须是post方式';
$this->ajaxReturn($res);
}
}
/**
* 助手数据汇总
* 2021年1月12日16:02:30
* @param storeid 门店id
* @param user_type 用户类型
* @param operator_id 操作人员id
* @author GuYunQinFeng
*/
protected function sellcount()
{
$storeid = I('post.storeid');
if (!$storeid) {
$this->ajaxReturn(['status' => 0, 'msg' => '参数错误']);
}
$user_type = I('post.user_type');
if ($user_type == 3) {
//收银员
$RetailCashierModel = new RetailCashierModel();
$cashier_id = I('post.operator_id');
if ($cashier_id) {
$cashier_show_other_sell = $RetailCashierModel->getFindField(['id' => $cashier_id], 'cashier_show_other_sell');
if ($cashier_show_other_sell == 2) {
$where['cashier_id'] = $cashier_id;
}
}
}
$BillOrderModel = new RetailBillOrderModel();
$PayOrderModel = new RetailPayOrderModel();
$start = strtotime(date('Y-m-d 00:00:00'));
$end = $start + 86399;
$where['add_time'] = ['between', [$start, $end]];
$where['pay_state'] = 1;
$where['store_id'] = $storeid;
$where['order_type'] = 1;
$billAllMoney = $BillOrderModel->getSum($where, 'all_money');
$billALlCount = $BillOrderModel->getCount($where);
$where['order_type'] = 2;
$billRefundMoney = $BillOrderModel->getSum($where, 'all_money');
//快捷收银
$map = [
'store_id' => $storeid,
'order_type' => 6,
'trade_date' => ['between', [$start, $end]],
'order_state' => 'SUCCESS',
];
if ($cashier_id && $cashier_show_other_sell == 2) {
$map['cashier_id'] = $cashier_id;
}
$quickTotalMoney = $PayOrderModel->getSum($map, 'trade_amount');
$quickTotalCount = $PayOrderModel->getCount($map);
$map['order_state'] = 'REFUND';
$quickRefundMoney = $PayOrderModel->getSum($map, 'trade_amount');
$repaymentMoney = 0;
//实例化插件类
$PlugApi = new Plug();
//获取付费插件列表及状态
$plug_result = $PlugApi->PlugPermissions(array(
'merchant_id' => I('post.merchant_id'),
'identification_arr' => ['credit']
));
//商户是否存在赊账插件
if ($plug_result['data']['plug']['credit'] > 0) {
$CreditRepaymentModel = new \Credit\Model\CreditRepaymentModel(); // 还款
$repayment_map = [
'operate_type' => 1, //确保是收银员
'store_id' => $storeid,
'add_time' => ['between', [$start, $end]],
];
if ($cashier_id && $cashier_show_other_sell == 2) {
$repayment_map['operate_id'] = $cashier_id;
}
$repaymentMoney = $CreditRepaymentModel->getSum($repayment_map, 'money');
}
$all_money = round($repaymentMoney + $billAllMoney - $billRefundMoney + $quickTotalMoney - $quickRefundMoney, 2); //总的交易金额
$count = bcadd($billALlCount, $quickTotalCount, 0); //总的交易笔数(减去退款笔数)
// 次卡销售金额统计
$subCardMap = [
'store_id' => $storeid,
'scene_type' => 1, //付款订单
'order_type' => 7, //购买次卡
'trade_date' => ['between', [$start, $end]],
];
$sub_card_money = $PayOrderModel->getSum($subCardMap, 'trade_amount'); //次卡没有退款
$info = [
'allmoney' => bcadd($all_money, $sub_card_money, 2),
'count' => $count
];
$store = M('retail_store_jurisdiction')->where(['storeid' => $storeid])->find();
$result = [
'status' => 1,
'msg' => '搜索成功',
'info' => $info,
'jurisdiction' => $store ? $store : (object)array(),
];
$this->ajaxReturn($result);
}
// 收银员列表
protected function cashierlist()
{
if (IS_POST) {
$this->newCashierList_v1();
}
}
//------------------------------------------------------------------收银员收款---------------------------------------------------------
protected function newcashierlist()
{
if (IS_POST) {
$storeid = I('post.storeid');
if (!$storeid) {
$rt['status'] = 0;
$rt['msg'] = '参数错误';
$this->ajaxReturn($rt);
exit();
}
$needsellinfo = I('post.needsellinfo');
$list = M('retail_cashier')
->where(array('status' => 1, 'storeid' => $storeid))
->field('id,name')
->select();
if ($list) {
if ($needsellinfo) {
$list = $list ? $list : array();
// $list = array_merge(array(array('id'=>0,'name'=>'商城订单收银统计')),$list);
$endtime = I('post.endtime'); // 2018-10-11;
$starttime = I('post.starttime'); // 2018-10-11;
$start = strtotime($starttime . ' 00:00:00');
$end = strtotime($endtime . ' 23:59:59');
foreach ($list as $k => $v) {
$count = 0;
if ($v['id']) {
$where['admin_id'] = $v['id'];
} else {
$where['admin_id'] = array(array('eq', 0), array('EXP', 'IS NULL'), 'OR');
}
//----------------------------------------------------------------------------------------------//
if (!$endtime && !$starttime) {
$start = strtotime(date('Y-m-d 00:00:00', time()));
$end = $start + 86399;
}
$where['addtime'] = array('between', array($start, $end));
$where['pay_state'] = 1;
$where['storeid'] = $storeid;
$where['order_type'] = 1;
// 现金付款
$where['paytype'] = 1;
$xj = M('retail_bill')->where($where)->sum('allmoney');
$xj_1 = M('retail_bill')->where($where)->sum('refund_money');
$xj_1 = $xj_1 ? round($xj_1, 2) : 0;
$xj = $xj ? round($xj - $xj_1, 2) : 0;
$count += M('retail_bill')->where($where)->count();
//微信支付
$where['paytype'] = 3;
$wxpay = M('retail_bill')->where($where)->sum('allmoney');
$wxpay_1 = M('retail_bill')->where($where)->sum('refund_money');
$wxpay_1 = $wxpay_1 ? round($wxpay_1, 2) : 0;
$wxpay = $wxpay ? round($wxpay - $wxpay_1, 2) : 0;
$count += M('retail_bill')->where($where)->count();
//支付宝支付
$where['paytype'] = 4;
$zfb = M('retail_bill')->where($where)->sum('allmoney');
$zfb_1 = M('retail_bill')->where($where)->sum('refund_money');
$zfb_1 = $zfb_1 ? round($zfb_1, 2) : 0;
$zfb = $zfb ? round($zfb - $zfb_1, 2) : 0;
$count += M('retail_bill')->where($where)->count();
//小程序微信支付
$where['paytype'] = 6;
$xcxwx = M('retail_bill')->where($where)->sum('allmoney');
$xcxwx_1 = M('retail_bill')->where($where)->sum('refund_money');
$xcxwx = $xcxwx ? round($xcxwx - $xcxwx_1, 2) : 0;
$xcxwx_1 = $xcxwx_1 ? round($xcxwx_1, 2) : 0;
$count += M('retail_bill')->where($where)->count();
if ($v['id'] == 0) {
// 拼团支付(今日)
$g_map['paystatus'] = 2;
$g_map['refundtype'] = 1;
$g_map['paytime'] = array('between', array($start, $end));
$xcx_group = M('retail_group_order')->where($g_map)->sum('paymoney');
$count += M('retail_group_order')->where($g_map)->count();
// 拼团退款(今日)
$g_map_1['paystatus'] = 2;
$g_map_1['refundtype'] = 2;
$g_map_1['refundtime'] = array('between', array($start, $end));
$xcx_group_1 = M('retail_group_order')->where($g_map_1)->sum('paymoney');
$xcx_group = $xcx_group ? round($xcx_group, 2) : 0;
$xcx_group_1 = $xcx_group_1 ? round($xcx_group_1, 2) : 0;
$count += M('retail_group_order')->where($g_map_1)->count();
// 小程序秒杀
$s_map['paystatus'] = 2;
$s_map['status'] = 1;
$s_map['paytime'] = array('between', array($start, $end));
$xcx_seckill = M('retail_seckill_order')->where($s_map)->sum('paymoney');
$xcx_seckill = $xcx_seckill ? round($xcx_seckill, 2) : 0;
$count += M('retail_seckill_order')->where($s_map)->count();
}
// 计算(整型)
$xcx_sum_old = ($xcxwx * 100) + ($xcx_group * 100) + ($xcx_seckill * 100);
$xcx_sum_old_1 = ($xcxwx_1 * 100) + ($xcx_group_1 * 100);
// 转换成实际价钱
$xcx_sum = $xcx_sum_old / 100;
$xcx_sum_1 = $xcx_sum_old_1 / 100;
// 其他支付。
$where['paytype'] = 7;
$other_pay = M('retail_bill')->where($where)->sum('allmoney');
$other_pay_1 = M('retail_bill')->where($where)->sum('refund_money');
$other_pay_1 = $other_pay_1 ? round($other_pay_1, 2) : 0;
$other_pay = $other_pay ? round($other_pay - $other_pay_1, 2) : 0;
$count += M('retail_bill')->where($where)->count();
//会员卡支付
$where['paytype'] = 5;
$membermoney = M('retail_bill')->where($where)->sum('allmoney');
$membermoney_1 = M('retail_bill')->where($where)->sum('refund_money');
$membermoney_1 = $membermoney_1 ? round($membermoney_1, 2) : 0;
$membermoney = $membermoney ? round($membermoney - $membermoney_1, 2) : 0;
$count += M('retail_bill')->where($where)->count();
//统计今日退款金额
$refund = round($xj_1 + $wxpay_1 + $zfb_1 + $xcx_sum_1 + $other_pay_1 + $membermoney_1, 2);
//今日总金额
$allmoney = round($xj + $wxpay + $zfb + $xcx_sum + $membermoney + $other_pay, 2);
//-----------------------------------------------------------------------------------------------//
// $where['addtime'] = array('between', array($start, $end));
// $where['pay_state'] = 1;
// $where['storeid'] = $storeid;
// $where['order_type'] = 1;
// // 现金付款
// $where['paytype'] = 1;
// $xj = M('retail_bill')->where($where)->sum('allmoney');
// $xj_1 = M('retail_bill')->where($where)->sum('refund_money');
// $count += M('retail_bill')->where($where)->count();
// $xj_1 = $xj_1 ? round($xj_1, 2) : 0;
// $xj = $xj ? round($xj - $xj_1, 2) : 0;
//
// //微信支付
// $where['paytype'] = 3;
// $wxpay = M('retail_bill')->where($where)->sum('allmoney');
// $wxpay_1 = M('retail_bill')->where($where)->sum('refund_money');
// $count += M('retail_bill')->where($where)->count();
// $wxpay_1 = $wxpay_1 ? round($wxpay_1, 2) : 0;
// $wxpay = $wxpay ? round($wxpay - $wxpay_1, 2) : 0;
//
// //支付宝支付
// $where['paytype'] = 4;
// $zfb = M('retail_bill')->where($where)->sum('allmoney');
// $zfb_1 = M('retail_bill')->where($where)->sum('refund_money');
// $count += M('retail_bill')->where($where)->count();
// $zfb_1 = $zfb_1 ? round($zfb_1, 2) : 0;
// $zfb = $zfb ? round($zfb - $zfb_1, 2) : 0;
//
// //小程序微信支付
// $where['paytype'] = 6;
// $xcxwx = M('retail_bill')->where($where)->sum('allmoney');
// $xcxwx_1 = M('retail_bill')->where($where)->sum('refund_money');
// $count += M('retail_bill')->where($where)->count();
// $xcxwx = $xcxwx ? round($xcxwx - $xcxwx_1, 2) : 0;
// $xcxwx_1 = $xcxwx_1 ? round($xcxwx_1, 2) : 0;
// if($v['id']==0) {
// // 拼团支付(今日)
// $g_map['paystatus'] = 2;
// $g_map['refundtype'] = 1;
// $g_map['paytime'] = array('between', array($start, $end));
// $xcx_group = M('retail_group_order')->where($g_map)->sum('paymoney');
// $count += M('retail_group_order')->where($g_map)->count();
// // 拼团退款(今日)
// $g_map_1['paystatus'] = 2;
// $g_map_1['refundtype'] = 2;
// $g_map_1['refundtime'] = array('between', array($start, $end));
// $xcx_group_1 = M('retail_group_order')->where($g_map_1)->sum('paymoney');
// $count += M('retail_group_order')->where($g_map_1)->count();
// $xcx_group = $xcx_group ? round($xcx_group, 2) : 0;
// $xcx_group_1 = $xcx_group_1 ? round($xcx_group_1, 2) : 0;
// // 小程序秒杀
// $s_map['paystatus'] = 2;
// $s_map['status'] = 1;
// $s_map['paytime'] = array('between', array($start, $end));
// $xcx_seckill = M('retail_seckill_order')->where($s_map)->sum('paymoney');
// $count += M('retail_seckill_order')->where($s_map)->count();
// $xcx_seckill = $xcx_seckill ? round($xcx_seckill, 2) : 0;
//
// // 计算(整型)
// $xcx_sum_old = ($xcxwx * 100) + ($xcx_group * 100) + ($xcx_seckill * 100);
// $xcx_sum_old_1 = ($xcxwx_1 * 100) + ($xcx_group_1 * 100);
// }else{
// // 计算(整型)
// $xcx_sum_old = ($xcxwx * 100) ;
// $xcx_sum_old_1 = ($xcxwx_1 * 100);
// }
// // 转换成实际价钱
// $xcx_sum = $xcx_sum_old / 100;
// $xcx_sum_1 = $xcx_sum_old_1 / 100;
//
// // 其他支付。
// $where['paytype'] = 7;
// $other_pay = M('retail_bill')->where($where)->sum('allmoney');
// $other_pay_1 = M('retail_bill')->where($where)->sum('refund_money');
// $count += M('retail_bill')->where($where)->count();
// $other_pay_1 = $other_pay_1 ? round($other_pay_1, 2) : 0;
// $other_pay = $other_pay ? round($other_pay - $other_pay_1, 2) : 0;
//
// //会员卡支付
// $where['paytype'] = 5;
// $membermoney = M('retail_bill')->where($where)->sum('allmoney');
// $membermoney_1 = M('retail_bill')->where($where)->sum('refund_money');
// $count += M('retail_bill')->where($where)->count();
// $membermoney_1 = $membermoney_1 ? round($membermoney_1, 2) : 0;
// $membermoney = $membermoney ? round($membermoney - $membermoney_1, 2) : 0;
// //统计今日退款金额
// $refund = round($xj_1 + $wxpay_1 + $zfb_1 + $xcx_sum_1 + $other_pay_1 + $membermoney_1, 2);
//会员卡
$ww2['storeid'] = $storeid;
$ww2['type'] = 1; // 会员充值
$ww2['addtime'] = array('between', array($start, $end));
if ($v['id']) {
$ww2['usertype'] = 3;
$ww2['adminid'] = $v['id'];
} else {
$ww2['adminid'] = array(array('eq', 0), array('EXP', 'IS NULL'), 'OR');
}
$ww2['status'] = 1;
$vipcard = M('recharge_order')->where($ww2)->sum('money');
$vipcard = $vipcard ? round($vipcard, 2) : 0;
//
// //今日总金额
// $allmoney = round($xj + $wxpay + $zfb + $xcx_sum + $membermoney + $other_pay, 2);
$info = array(
'xj' => $xj,
'wx' => $wxpay,
'zfb' => $zfb,
'xcx' => $xcx_sum,
'refund' => $refund,
'vipcard' => $membermoney,
'vipaddmoney' => $vipcard,
'allmoney' => $allmoney,
'other_pay' => $other_pay,
'count' => $count
);
$list[$k]['sellinfo'] = $info;
}
$rt['status'] = 1;
$rt['msg'] = '查询成功';
$rt['list'] = $list;
$rt['starttime'] = date('Y-m-d', $start);
$rt['endtime'] = date('Y-m-d', $end);
} else {
$rt['status'] = 1;
$rt['msg'] = '查询成功';
$rt['list'] = $list;
$rt['starttime'] = date('Y-m-d', time());
$rt['endtime'] = date('Y-m-d', time());
}
} else {
$rt['status'] = 0;
$rt['msg'] = '暂无收银员';
$rt['starttime'] = date('Y-m-d', time());
$rt['endtime'] = date('Y-m-d', time());
}
$this->ajaxReturn($rt);
}
}
// 商品分类数据
protected function goodscate()
{
if (IS_POST) {
$merchantid = I('post.merchantid');
$keyword = I('post.keyword');
$classindextype = I('post.classtypeindex');
$classindextype = $classindextype ? $classindextype : 0;
$type = I('post.type');
$user_type = I('post.user_type'); //user_type 1商户 2门店
$store_id = I('post.store_id');
$w = array('merchantid' => $merchantid, 'status' => 0);
$w1 = array('merchantid' => $merchantid, 'status' => 0);
$w2 = array('merchantid' => $merchantid, 'status' => 0);
if ($user_type == 2 && !empty($store_id)) {
//门店的行业对分类获取进行限制
$StoreModel = new RetailStoreModel();
$industry_id = $StoreModel->getFindField([
'id' => $store_id
], 'industry_id');
if (!empty($industry_id)) {
$w['industry_id'] = ['in', [0, $industry_id]];
$w1['industry_id'] = ['in', [0, $industry_id]];
$w2['industry_id'] = ['in', [0, $industry_id]];
}
}
if ($classindextype == 0) {
if ($keyword) {
$w['class_name'] = array('like', '%' . $keyword . '%');
}
$w['type'] = 1; // 一级分类
$one = M('retail_goods_class')
->where($w)
->order('code asc')
->field('id,class_name')
->select();
if ($one) {
foreach ($one as $k1 => $v1) {
$w1['type'] = 2;
$w1['pid'] = $v1['id'];
$two = M('retail_goods_class')
->where($w1)
->order('code asc')
->field('id,class_name')
->select();
if ($two) {
foreach ($two as $k2 => $v2) {
$w2['type'] = 3;
$w2['pid'] = $v2['id'];
$three = M('retail_goods_class')
->where($w2)
->order('code asc')
->field('id,class_name')
->select();
if ($three) {
if ($type) {
$two[$k2]['childtwo'] = $three;
} else {
$two[$k2]['child'] = $three;
}
$two[$k2]['haschild'] = 1;
$two[$k2]['show'] = false;
} else {
if ($type) {
$two[$k2]['childtwo'] = array();
} else {
$two[$k2]['child'] = array();
}
$two[$k2]['haschild'] = 0;
}
}
if ($type) {
$one[$k1]['childone'] = $two;
} else {
$one[$k1]['child'] = $two;
}
$one[$k1]['haschild'] = 1;
$one[$k1]['show'] = false;
} else {
if ($type) {
$one[$k1]['childone'] = array();
} else {
$one[$k1]['child'] = array();
}
$one[$k1]['haschild'] = 0;
}
}
}
} else if ($classindextype == 1) {
$w1['type'] = 2;
if ($keyword) {
$w1['class_name'] = array('like', '%' . $keyword . '%');
}
$one = M('retail_goods_class')
->where($w1)
->order('code asc')
->field('id,class_name')
->select();
if ($one) {
foreach ($one as $k2 => $v2) {
$w2['type'] = 3;
$w2['pid'] = $v2['id'];
$three = M('retail_goods_class')
->where($w2)
->order('code asc')
->field('id,class_name')
->select();
if ($three) {
if ($type) {
$one[$k2]['childone'] = $three;
} else {
$one[$k2]['child'] = $three;
}
$one[$k2]['haschild'] = 1;
$one[$k2]['show'] = false;
} else {
if ($type) {
$one[$k2]['childone'] = array();
} else {
$one[$k2]['child'] = array();
}
$two[$k2]['haschild'] = 0;
}
}
}
} else if ($classindextype == 2) {
if ($keyword) {
$w['class_name'] = array('like', '%' . $keyword . '%');
}
$w['type'] = 3; // 三级分类
$one = M('retail_goods_class')
->where($w)
->order('code asc')
->field('id,class_name')
->select();
}
$goodsclass = $one;
if ($goodsclass) {
$rt['status'] = 1;
$rt['msg'] = '搜索成功';
$rt['goodscate'] = $goodsclass;
} else {
$rt['status'] = 0;
$rt['msg'] = '搜索失败';
}
$this->ajaxReturn($rt);
}
}
//获取规格信息
protected function skuInfo()
{
$merchant_id = I('post.merchantid');
$skuList = A('Api/Inventory')->getSkuAttr($merchant_id);
$this->ajaxReturn($skuList);
}
/*
* 添加规格属性
*/
protected function addSkuAttr()
{
$user_type = I('post.user_type'); //1商户2门店3收银员
$user_type = $user_type ? $user_type : 0;
$store_id = I('post.storeid');
$merchant_id = I('post.merchantid');
$name = I('post.name');
$success = A('Api/Inventory')->addSkuAttr_forAddMGoods($name, $user_type, $merchant_id, $store_id);
$this->ajaxReturn($success);
}
//添加规格
protected function addSkuList()
{
$user_type = I('post.user_type');
$user_type = $user_type ? $user_type : 0;
$store_id = I('post.storeid');
$merchant_id = I('post.merchantid');
$attr_id = I('post.attr_id');
$name = I('post.name');
$success = A('Api/Inventory')->addSkuList_forAddMGoods($attr_id, $name, $user_type, $merchant_id, $store_id);
$this->ajaxReturn($success);
}
/**
* 自动获取获取货号
*/
public function auto_number()
{
$data = I("post.");
$store_id = $data['storeid'];
$merchant_id = $data['merchantid'];
$user_type = $data['user_type']; //1商家 2门店 3员工
$i = 0;
switch ($user_type) {
case 1:
$MGoods = D("RetailMgoods");
while (1) {
$num = rand(1000, 99999);
$map = array(
$MGoods::MERCHANT_ID => $merchant_id,
$MGoods::GOODS_NUMBER => $num,
$MGoods::STATUS => array('in', '0,1')
);
$info = $MGoods->getFindField($map, "id");
if (empty($info)) {
$res['status'] = 1;
$res['goods_number'] = $num;
$res['msg'] = '获取成功';
$this->ajaxReturn($res);
break;
}
$i++;
if ($i > 30) {
$res['status'] = 0;
$res['msg'] = '获取失败,请重试';
$this->ajaxReturn($res);
break;
}
}
break;
case 2:
case 3;
$Goods = D("RetailGoods");
while (1) {
$num = rand(1000, 99999);
$map = array(
$Goods::STORE_ID => $store_id,
$Goods::GOODS_NUMBER => $num,
$Goods::STATUS => array('in', '0,1')
);
$info = $Goods->getFindField($map, "id");
if (empty($info)) {
$res['status'] = 1;
$res['goods_number'] = $num;
$res['msg'] = '获取成功';
$this->ajaxReturn($res);
break;
}
$i++;
if ($i > 30) {
$res['status'] = 0;
$res['msg'] = '获取失败,请重试';
$this->ajaxReturn($res);
break;
}
}
}
}
// 新增商品
protected function addgoods()
{
if (IS_POST) {
$postInfo = I("post.");
$usertype = $postInfo["user_type"] ? $postInfo["user_type"] : 3; //1商户 2门店 3收银员
$cashier_id = $postInfo['cashier_id']; //收银员id
$store_id = $postInfo['storeid'];
$merchant_id = $postInfo["merchantid"];
$supplier_type = D("RetailStore")->getFindField(array('id' => $store_id), "supplier_type");
if ($usertype == 1) {
//商户
$warehouse_id = D('SaleWarehouse')->getFindField(array('merchant_id' => $merchant_id, 'status' => 1), "id");
} else {
$addGoodsPower = M("retail_store_jurisdiction")->where(array('storeid' => $store_id))->getField("addgoods");
if ($addGoodsPower == 2) {
$res['status'] = 0;
$res['msg'] = "暂无添加商品权限";
$this->ajaxReturn($res);
}
if ($usertype == 3) {
$cashierInfo = D("RetailCashier")->getFind(array('id' => $cashier_id), "cashier_add_goods");
if ($cashierInfo['cashier_add_goods'] == 2) {
$res['status'] = 0;
$res['msg'] = "暂无添加商品权限";
$this->ajaxReturn($res);
}
}
$warehouse_id = D('SSaleWarehouse')->getFindField(array('store_id' => $store_id, 'status' => 1), "id");
}
if (!$warehouse_id) {
$res['status'] = 0;
$res['msg'] = '请先创建仓库';
$this->ajaxReturn($res);
}
$data = array();
$data['goods_name'] = $postInfo["goods_name"]; //商品名称
$purchase_price = $postInfo["purch_price"];
$goods_number = $postInfo["goods_number"];
$goods_img_id = $postInfo["goodimage"];
$is_change_weight = $postInfo["is_change_weight"] ? $postInfo["is_change_weight"] : 1;
$attribute_state = $postInfo["attribute_state"] ? $postInfo["attribute_state"] : 1;
$goods_num = $postInfo["goods_num"] ? $postInfo["goods_num"] : 0; //商品库存
$data['status'] = 0; //商品状态
$data['more_num'] = $postInfo["more_num"]; //商品超量值
$data['less_num'] = $postInfo["less_num"]; //商品预警值
$data['goods_code'] = $postInfo["goods_code"]; //商品条码
$data['goods_class_id'] = $postInfo["goods_class_id"]; //商品分类
$data['retail_price'] = $postInfo["retail_price"]; //商品零售价
$data['company'] = $postInfo['company'] ? $postInfo['company'] : '';
if ($is_change_weight == 2 && $data['company'] == '') {
$res['status'] = 0;
$res['msg'] = '请输入单位';
$this->ajaxReturn($res);
}
if ($usertype == 1) {
$data['merchantid'] = $merchant_id; //商户ID
$data['storeid'] = $store_id; //门店ID
$data['addtime'] = time();
$data['purch_price'] = $purchase_price; //商品进价
$data['good_number'] = $goods_number; //商品货号
$data['can_exchange_weigh'] = $is_change_weight;
$data['attribute'] = $attribute_state;
$data['goods_image_id'] = $goods_img_id; // 商户商品图片
} else {
$data['merchant_id'] = $merchant_id; //商户ID
$data['store_id'] = $store_id; //门店ID
$data['add_time'] = time();
$data['purchase_price'] = $purchase_price; //商品进价
$data['goods_number'] = $goods_number; //商品货号
$data['pricing_method'] = $is_change_weight;
$data['attribute_state'] = $attribute_state;
$data['goods_img_id'] = $goods_img_id; // 商品图片
}
$skuList = $_POST["skuList"];
$skuList = json_decode($skuList, true);
if ($is_change_weight == 2 && $attribute_state == 2) {
$res['status'] = 0;
$res['msg'] = '规格与称重不能同时开启';
$this->ajaxReturn($res);
}
if ($attribute_state == 2 && empty($skuList)) {
$res['status'] = 0;
$res['msg'] = '规格信息有误';
$this->ajaxReturn($res);
}
if (empty($goods_number)) {
$res['status'] = 0;
$res['msg'] = '货号不能为空';
$this->ajaxReturn($res);
}
if ($goods_num > 0 && $purchase_price * 1 <= 0 || $purchase_price < 0) {
$res['status'] = 0;
$res['msg'] = '进价不得小于0';
$this->ajaxReturn($res);
}
if (!empty($data['goods_code']) && strlen($data['goods_code']) > 17) {
$res['status'] = 0;
$res['msg'] = '商品条码长度不得大于17';
$this->ajaxReturn($res);
}
if ($supplier_type != 2 && $goods_num * 1 < 0) {
$res['status'] = 0;
$res['msg'] = '库存不得小于0';
$this->ajaxReturn($res);
}
if ($data['more_num'] * 1 < 0) {
$res['status'] = 0;
$res['msg'] = '超量值不得小于0';
$this->ajaxReturn($res);
}
if ($data['less_num'] * 1 < 0) {
$res['status'] = 0;
$res['msg'] = '预警值不得小于0';
$this->ajaxReturn($res);
}
$map = array();
$map['status'] = array('neq', 2);
if ($usertype == 1) {
$map['merchantid'] = $merchant_id;
$map['good_number'] = $goods_number; //商品货号
$one = M('retail_mgoods')->where($map)->find();
} else {
$map['store_id'] = $store_id;
$map['merchant_id'] = $merchant_id;
$map['goods_number'] = $goods_number; //商品货号
$one = M('retail_goods')->where($map)->find();
}
if ($one) {
$res['status'] = 0;
$res['msg'] = '商品货号重复';
$this->ajaxReturn($res);
}
if (!empty($data['goods_code'])) {
$map = array();
$map['status'] = array('neq', 2);
$map['goods_code'] = $data['goods_code']; //商品条码
if ($usertype == 1) {
$map['merchantid'] = $merchant_id;
$one = M('retail_mgoods')->where($map)->find();
} else {
$map['store_id'] = $store_id;
$map['merchant_id'] = $merchant_id;
$one = M('retail_goods')->where($map)->find();
}
if ($one) {
$res['status'] = 0;
$res['msg'] = '商品条码重复';
$this->ajaxReturn($res);
}
}
if ($attribute_state == 2 && is_array($skuList) && !empty($skuList)) {
$sku_attr_length = count($skuList[0]['id']);
if ($sku_attr_length > 4) {
$res['status'] = 0;
$res['msg'] = '最多只能添加四种规格';
$this->ajaxReturn($res);
}
$sku_goods_num = 0;
$codeArr = array();
$numberArr = array();
if (!empty($data['goods_code'])) {
$codeArr[] = $data['goods_code'];
}
if (!empty($goods_number)) {
$numberArr[] = $goods_number;
}
$all_sku_list_id = '';
foreach ($skuList as $key => $val) {
if (!$val['sku_goods_number']) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格正确的货号';
$this->ajaxReturn($res);
}
if (in_array($val['sku_goods_number'], $numberArr)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格货号已存在';
$this->ajaxReturn($res);
} else {
$numberArr[] = $val['sku_goods_number'];
}
$sku_map = array();
$sku_map['sku_goods_number'] = $val['sku_goods_number'];
$sku_map['state'] = 0;
if ($usertype == 1) { //商户
$sku_map['merchantid'] = $merchant_id;
$skuInfo = M('retail_sku_mgoods')->where($sku_map)->find();
} else {
$sku_map['store_id'] = $store_id;
$skuInfo = M('retail_sku_goods')->where($sku_map)->find();
}
if ($skuInfo) {
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格货号已存在';
$this->ajaxReturn($res);
}
if ($usertype == 1) {
$map = array(
'good_number' => $val['sku_goods_number'],
'merchantid' => $merchant_id,
'status' => array('in', '0,1')
);
$goodsInfo = M('retail_mgoods')->where($map)->find();
} else {
$map = array(
'store_id' => $store_id,
'goods_number' => $val['sku_goods_number'],
'merchant_id' => $merchant_id,
'status' => array('in', '0,1')
);
$goodsInfo = M('retail_goods')->where($map)->find();
}
if ($goodsInfo) {
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格货号已存在';
$this->ajaxReturn($res);
}
if (!is_numeric($val['purchase_price']) || $val['purchase_price'] < 0) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格正确的进价';
$this->ajaxReturn($res);
}
if ($val['goods_num'] > 0) {
if (!$val['purchase_price'] || $val['purchase_price'] < 0.01 || $val['purchase_price'] != round($val['purchase_price'], 2)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格正确的进价';
$this->ajaxReturn($res);
}
}
if (!$val['retail_price'] || !is_numeric($val['retail_price']) || $val['retail_price'] < 0.01 || $val['retail_price'] != round($val['retail_price'], 2)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格正确的零售价';
$this->ajaxReturn($res);
}
if (!empty($val['sku_code'])) {
if (strlen($val['sku_code']) > 17) {
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格条码不能大于18位';
$this->ajaxReturn($res);
}
if (in_array($val['sku_code'], $codeArr)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格商品条码重复';
$this->ajaxReturn($res);
} else {
$codeArr[] = $val['sku_code'];
}
if ($usertype == 1) {
$map = array(
'merchantid' => $merchant_id,
'sku_code' => $val['sku_code'],
'state' => 0
);
$old = M('retail_sku_mgoods')->where($map)->find();
} else {
$map = array(
'store_id' => $store_id,
'sku_code' => $val['sku_code'],
'state' => 0
);
$old = M('retail_sku_goods')->where($map)->find();
}
if ($usertype == 1) {
$map = array(
'goods_code' => $val['sku_code'],
'merchantid' => $merchant_id,
'status' => array('in', '0,1')
);
$old1 = M('retail_mgoods')->where($map)->find();
} else {
$map = array(
'store_id' => $store_id,
'goods_code' => $val['sku_code'],
'merchant_id' => $merchant_id,
'status' => array('in', '0,1')
);
$old1 = M('retail_goods')->where($map)->find();
}
if (!empty($old) || !empty($old1)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格商品条码已存在';
$this->ajaxReturn($res);
}
}
$sku_id_list = '';
$sku_name = '';
for ($i = 0; $i < $sku_attr_length; $i++) {
if (!empty($val['id'][$i])) {
$sku_id_list .= ',' . $val['id'][$i];
$sku_name .= ',' . $val['name'][$i];
} else {
$res['val'] = $key . '-' . $i;
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '条规格数据的规格信息有误';
}
$all_sku_list_id .= ',' . $sku_id_list;
}
$temp['sku_num'] = 1;
$temp['name'] = ltrim($sku_name, ',');
$temp['sku_id_list'] = ltrim($sku_id_list, ',');
$temp['retail_price'] = $val['retail_price'];
$temp['purchase_price'] = $val['purchase_price'] ? $val['purchase_price'] : 0;
$temp['goods_num'] = is_numeric($val['goods_num']) ? $val['goods_num'] : 0;
if (!empty($val['goods_num']) && (!is_numeric($val['goods_num']) || $val['goods_num'] != round($val['goods_num']))) {
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格的库存有误';
$this->ajaxReturn($res);
}
$temp['add_time'] = time();
$temp['status'] = 1;
$temp['state'] = 0;
$temp['sku_goods_number'] = $val['sku_goods_number'];
$temp['sku_code'] = $val['sku_code'];
if ($usertype == 1) {
$temp['merchantid'] = $merchant_id;
} else {
$temp['store_id'] = $store_id;
$temp['merchant_id'] = $merchant_id;
}
$skuArrData[] = $temp;
unset($temp);
}
$all_sku_list_id = ltrim($all_sku_list_id, ',');
$attr = M('retail_sku_attr as a')
->join('ls_retail_sku_list as l on l.attr_id=a.id')
->field('a.*')
->where(array('a.merchantid' => $merchant_id, 'a.state' => 0, 'l.id' => array('in', $all_sku_list_id)))
->group('l.attr_id')
->select();
if (count($attr) != $sku_attr_length) {
$res['status'] = 0;
$res['msg'] = '您添加的规格信息属性重复';
$this->ajaxReturn($res);
}
}
$content = array();
$content = $data;
if ($usertype == 1) {
$create = M('retail_mgoods')->add($data);
$content['merchant_id'] = $merchant_id;
$content['goods_number'] = $goods_number;
$content['pricing_method'] = $is_change_weight;
$content['attribute_state'] = $attribute_state;
} else {
$create = M('retail_goods')->add($data);
}
$content['warehouse_id'] = $warehouse_id;
$content['goods_id'] = $create;
if ($create) {
unset($content['retail_price']);
if ($attribute_state == 1) {
$content['goods_num'] = $goods_num;
if ($usertype == 1) {
$content['purchase_price'] = $purchase_price;
//商户添加
A('Api/Inventory')->merAddSaleGoods($content, 1);
} else {
A('Api/Inventory')->addSaleGoods($content, 1);
}
} else if ($attribute_state == 2) {
foreach ($skuArrData as $k => &$v) {
$content['sku_name'] = $v['name'];
$content['sku_id_list'] = $v['sku_id_list'];
$content['sku_goods_number'] = $v['sku_goods_number'];
$content['sku_code'] = $v['sku_code'];
$content['goods_num'] = $v['goods_num'];
$content['purchase_price'] = $v['purchase_price'];
$content['add_time'] = $v['add_time'];
$content['sku_num'] = 1;
unset($content['more_num']);
unset($content['less_num']);
if ($usertype == 1) {
$v['mgoods_id'] = $create;
$v['addtime'] = $v['add_time'];
$v['purch_price'] = $v['purchase_price'];
unset($v['add_time']);
unset($v['purchase_price']);
} else {
$v['goods_id'] = $create;
}
unset($v['id']);
unset($v['goods_num']);
if ($usertype == 1) {
$add = M("retail_sku_mgoods")->add($v);
$content['sku_id'] = $add;
A('Api/Inventory')->merAddSaleGoods($content, 1);
} else {
$add = M("retail_sku_goods")->add($v);
$content['sku_id'] = $add;
A('Api/Inventory')->addSaleGoods($content, 1);
} //添加规格
}
}
if ($usertype == 1 || $usertype == 2) {
$parameter['desc'] = '商品档案-新增';
switch ($usertype) {
case 1:
$parameter['type'] = 3;
break;
case 2:
$parameter['type'] = 4;
break;
}
$this->system_parameter($parameter);
}
$res['status'] = 1;
$res['msg'] = '录入成功';
} else {
$res['status'] = 0;
$res['msg'] = '录入失败';
}
$this->ajaxReturn($res);
}
}
// 新增商品2020-6-5
protected function addgoods_v1()
{
if (IS_POST) {
$postInfo = I("post.");
$usertype = $postInfo["user_type"] ? $postInfo["user_type"] : 3; //1商户 2门店 3收银员
$cashier_id = $postInfo['cashier_id']; //收银员id
$store_id = $postInfo['storeid'];
$merchant_id = $postInfo["merchantid"];
$supplier_type = D("RetailStore")->getFindField(array('id' => $store_id), "supplier_type");
if ($usertype == 1) {
//商户
$warehouse_id = D('SaleWarehouse')->getFindField(array('merchant_id' => $merchant_id, 'status' => 1), "id");
} else {
$addGoodsPower = M("retail_store_jurisdiction")->where(array('storeid' => $store_id))->getField("addgoods");
if ($addGoodsPower == 2) {
$res['status'] = 0;
$res['msg'] = "暂无添加商品权限";
$this->ajaxReturn($res);
}
if ($usertype == 3) {
$cashierInfo = D("RetailCashier")->getFind(array('id' => $cashier_id), "cashier_add_goods");
if ($cashierInfo['cashier_add_goods'] == 2) {
$res['status'] = 0;
$res['msg'] = "暂无添加商品权限";
$this->ajaxReturn($res);
}
}
$warehouse_id = D('SSaleWarehouse')->getFindField(array('store_id' => $store_id, 'status' => 1), "id");
}
if (!$warehouse_id) {
$res['status'] = 0;
$res['msg'] = '请先创建仓库';
$this->ajaxReturn($res);
}
$data = array();
$data['status'] = $postInfo['status'] ? $postInfo['status'] : 0; //0,正常,1,下架,2,删除
$data['goods_name'] = $postInfo["goods_name"]; //商品名称
$data['more_num'] = $postInfo["more_num"]; //商品超量值
$data['less_num'] = $postInfo["less_num"]; //商品预警值
$data['goods_code'] = $postInfo["goods_code"]; //商品条码
$data['goods_class_id'] = $postInfo["goods_class_id"]; //商品分类
$data['retail_price'] = $postInfo["retail_price"]; //商品零售价
$data['company'] = $postInfo['company'] ? $postInfo['company'] : ''; //单位
$data['weight_value'] = $postInfo['weight_value'] ? $postInfo['weight_value'] : null; //重量
$data['online_price'] = $postInfo['online_price'] ? $postInfo['online_price'] : null; //商城价
$purchase_price = $postInfo["purch_price"];
$goods_number = $postInfo["goods_number"];
$goods_img_id = $postInfo["goodimage"];
$goods_image = $postInfo["goods_image"]; //商品云库图片
$item = array(
'add_time' => time(),
'from_type_id' => 19,
'localUrl' => 'Merchant/Goods',
'user_type' => 3,
'merchant_id' => $merchant_id,
);
if ($usertype == 2) {
$item['store_id'] = $store_id;
$item['user_type'] = 4;
$item['localUrl'] = 'Store/Goods';
$item['from_type_id'] = 28;
}
$uploads = uploadFiles($item); //本次请求的所有图片上传
if (!empty($uploads['image_file'])) {
$data['goods_img_id'] = $uploads['image_file']['id']; //商品封面图
}
if (!$data['goods_img_id'] && $goods_image) {
$item['path'] = $goods_image;
$goodsApi = new \Common\Business\Goods(); //商品类
$codeImage = $goodsApi->basisCodeAddImageGallery($item); //阿里云条码查询的商品图片存入库图片库
$goods_img_id = $codeImage['goods_image']['id'];
}
$is_change_weight = $postInfo["is_change_weight"] ? $postInfo["is_change_weight"] : 1;
$attribute_state = $postInfo["attribute_state"] ? $postInfo["attribute_state"] : 1;
$goods_num = $postInfo["goods_num"] ? $postInfo["goods_num"] : 0; //商品库存
$online_state = $postInfo['online_state'] ? $postInfo['online_state'] : 0; //0,不在,1,在商城出售。
if ($is_change_weight == 2) {
if (empty($data['company'])) {
$res['status'] = 0;
$res['msg'] = '请输入单位';
$this->ajaxReturn($res);
}
switch ($data['company']) {
case 'g':
case 'G':
case '克':
$data['weight_value'] = 0.001;
break;
case '斤':
case '市斤':
$data['weight_value'] = 0.5;
break;
default:
$data['weight_value'] = 1;
break;
}
}
if ($is_change_weight != 2 && !empty($data['weight_value']) && !preg_match("/^[+-]?\d*\.?\d{0,3}$/", $data['weight_value'])) {
$res['status'] = 0;
$res['msg'] = '请输入正确重量';
$this->ajaxReturn($res);
}
if (!empty($data['online_price']) && !preg_match("/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d{0,2})$/", $data['online_price'])) {
$res['status'] = 0;
$res['msg'] = '商城价有误';
$this->ajaxReturn($res);
}
if ($usertype == 1) {
$data['merchantid'] = $merchant_id; //商户ID
$data['storeid'] = $store_id; //门店ID
$data['addtime'] = time();
$data['purch_price'] = $purchase_price; //商品进价
$data['good_number'] = $goods_number; //商品货号
$data['can_exchange_weigh'] = $is_change_weight;
$data['attribute'] = $attribute_state;
$data['goods_image_id'] = $goods_img_id; // 商户商品图片
$data['issellonline'] = $online_state;
} else {
$data['merchant_id'] = $merchant_id; //商户ID
$data['store_id'] = $store_id; //门店ID
$data['add_time'] = time();
$data['purchase_price'] = $purchase_price; //商品进价
$data['goods_number'] = $goods_number; //商品货号
$data['pricing_method'] = $is_change_weight;
$data['attribute_state'] = $attribute_state;
$data['goods_img_id'] = $goods_img_id; // 商品图片
$data['online_state'] = $online_state;
}
$skuList = $_POST["skuList"];
$skuList = json_decode($skuList, true);
if ($is_change_weight == 2 && $attribute_state == 2) {
$res['status'] = 0;
$res['msg'] = '规格与称重不能同时开启';
$this->ajaxReturn($res);
}
if ($attribute_state == 2 && empty($skuList)) {
$res['status'] = 0;
$res['msg'] = '规格信息有误';
$this->ajaxReturn($res);
}
if (empty($goods_number)) {
$res['status'] = 0;
$res['msg'] = '货号不能为空';
$this->ajaxReturn($res);
}
if ($goods_num > 0 && $purchase_price * 1 <= 0 || $purchase_price < 0) {
$res['status'] = 0;
$res['msg'] = '进价不得小于0';
$this->ajaxReturn($res);
}
if (!empty($data['goods_code']) && strlen($data['goods_code']) > 17) {
$res['status'] = 0;
$res['msg'] = '商品条码长度不得大于17';
$this->ajaxReturn($res);
}
if ($supplier_type != 2 && $goods_num * 1 < 0) {
$res['status'] = 0;
$res['msg'] = '库存不得小于0';
$this->ajaxReturn($res);
}
if ($data['more_num'] * 1 < 0) {
$res['status'] = 0;
$res['msg'] = '超量值不得小于0';
$this->ajaxReturn($res);
}
if ($data['less_num'] * 1 < 0) {
$res['status'] = 0;
$res['msg'] = '预警值不得小于0';
$this->ajaxReturn($res);
}
$map = array();
$map['status'] = array('neq', 2);
if ($usertype == 1) {
$map['merchantid'] = $merchant_id;
$map['good_number'] = $goods_number; //商品货号
$one = M('retail_mgoods')->where($map)->find();
} else {
$map['store_id'] = $store_id;
$map['merchant_id'] = $merchant_id;
$map['goods_number'] = $goods_number; //商品货号
$one = M('retail_goods')->where($map)->find();
}
if ($one) {
$res['status'] = 0;
$res['msg'] = '商品货号重复';
$this->ajaxReturn($res);
}
if (!empty($data['goods_code'])) {
$map = array();
$map['status'] = array('neq', 2);
$map['goods_code'] = $data['goods_code']; //商品条码
if ($usertype == 1) {
$map['merchantid'] = $merchant_id;
$one = M('retail_mgoods')->where($map)->find();
} else {
$map['store_id'] = $store_id;
$map['merchant_id'] = $merchant_id;
$one = M('retail_goods')->where($map)->find();
}
if ($one) {
$res['status'] = 0;
$res['msg'] = '商品条码重复';
$this->ajaxReturn($res);
}
}
if ($attribute_state == 2 && is_array($skuList) && !empty($skuList)) {
$sku_attr_length = count($skuList[0]['id']);
if ($sku_attr_length > 4) {
$res['status'] = 0;
$res['msg'] = '最多只能添加四种规格';
$this->ajaxReturn($res);
}
$sku_goods_num = 0;
$codeArr = array();
$numberArr = array();
if (!empty($data['goods_code'])) {
$codeArr[] = $data['goods_code'];
}
if (!empty($goods_number)) {
$numberArr[] = $goods_number;
}
$all_sku_list_id = '';
foreach ($skuList as $key => $val) {
if (!$val['sku_goods_number']) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格正确的货号';
$this->ajaxReturn($res);
}
if (in_array($val['sku_goods_number'], $numberArr)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格货号已存在';
$this->ajaxReturn($res);
} else {
$numberArr[] = $val['sku_goods_number'];
}
if (!empty($val['weight_value']) && !preg_match("/^[+-]?\d*\.?\d{0,3}$/", $val['weight_value'])) {
$res['status'] = 0;
$res['msg'] = '请填写正确第' . ($key + 1) . '个规格重量';
$this->ajaxReturn($res);
}
$sku_map = array();
$sku_map['sku_goods_number'] = $val['sku_goods_number'];
$sku_map['state'] = 0;
if ($usertype == 1) { //商户
$sku_map['merchantid'] = $merchant_id;
$skuInfo = M('retail_sku_mgoods')->where($sku_map)->find();
} else {
$sku_map['store_id'] = $store_id;
$skuInfo = M('retail_sku_goods')->where($sku_map)->find();
}
if ($skuInfo) {
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格货号已存在';
$this->ajaxReturn($res);
}
if ($usertype == 1) {
$map = array(
'good_number' => $val['sku_goods_number'],
'merchantid' => $merchant_id,
'status' => array('in', '0,1')
);
$goodsInfo = M('retail_mgoods')->where($map)->find();
} else {
$map = array(
'store_id' => $store_id,
'goods_number' => $val['sku_goods_number'],
'merchant_id' => $merchant_id,
'status' => array('in', '0,1')
);
$goodsInfo = M('retail_goods')->where($map)->find();
}
if ($goodsInfo) {
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格货号已存在';
$this->ajaxReturn($res);
}
if (!is_numeric($val['purchase_price']) || $val['purchase_price'] < 0) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格正确的进价';
$this->ajaxReturn($res);
}
if ($val['goods_num'] > 0) {
if (!$val['purchase_price'] || $val['purchase_price'] < 0.01 || $val['purchase_price'] != round($val['purchase_price'], 2)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格正确的进价';
$this->ajaxReturn($res);
}
}
if ($online_state == 1 && !preg_match("/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d{0,2})$/", $val['online_price'])) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格正确的商城价';
$this->ajaxReturn($res);
}
if (!$val['retail_price'] || !is_numeric($val['retail_price']) || $val['retail_price'] < 0.01 || $val['retail_price'] != round($val['retail_price'], 2)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '请填写第' . ($key + 1) . '个规格正确的零售价';
$this->ajaxReturn($res);
}
if (!empty($val['sku_code'])) {
if (strlen($val['sku_code']) > 17) {
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格条码不能大于18位';
$this->ajaxReturn($res);
}
if (in_array($val['sku_code'], $codeArr)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格商品条码重复';
$this->ajaxReturn($res);
} else {
$codeArr[] = $val['sku_code'];
}
if ($usertype == 1) {
$map = array(
'merchantid' => $merchant_id,
'sku_code' => $val['sku_code'],
'state' => 0
);
$old = M('retail_sku_mgoods')->where($map)->find();
} else {
$map = array(
'store_id' => $store_id,
'sku_code' => $val['sku_code'],
'state' => 0
);
$old = M('retail_sku_goods')->where($map)->find();
}
if ($usertype == 1) {
$map = array(
'goods_code' => $val['sku_code'],
'merchantid' => $merchant_id,
'status' => array('in', '0,1')
);
$old1 = M('retail_mgoods')->where($map)->find();
} else {
$map = array(
'store_id' => $store_id,
'goods_code' => $val['sku_code'],
'merchant_id' => $merchant_id,
'status' => array('in', '0,1')
);
$old1 = M('retail_goods')->where($map)->find();
}
if (!empty($old) || !empty($old1)) {
$res['val'] = $key;
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格商品条码已存在';
$this->ajaxReturn($res);
}
}
$sku_id_list = '';
$sku_name = '';
for ($i = 0; $i < $sku_attr_length; $i++) {
if (!empty($val['id'][$i])) {
$sku_id_list .= ',' . $val['id'][$i];
$sku_name .= ',' . $val['name'][$i];
} else {
$res['val'] = $key . '-' . $i;
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '条规格数据的规格信息有误';
}
$all_sku_list_id .= ',' . $sku_id_list;
}
$temp['sku_num'] = 1;
$temp['name'] = ltrim($sku_name, ',');
$temp['sku_id_list'] = ltrim($sku_id_list, ',');
$temp['retail_price'] = $val['retail_price'];
$temp['purchase_price'] = $val['purchase_price'] ? $val['purchase_price'] : 0;
$temp['goods_num'] = is_numeric($val['goods_num']) ? $val['goods_num'] : 0;
if (!empty($val['goods_num']) && (!is_numeric($val['goods_num']) || $val['goods_num'] != round($val['goods_num']))) {
$res['status'] = 0;
$res['msg'] = '第' . ($key + 1) . '个规格的库存有误';
$this->ajaxReturn($res);
}
$temp['add_time'] = time();
$temp['status'] = 1;
$temp['state'] = 0;
$temp['sku_goods_number'] = $val['sku_goods_number'];
$temp['sku_code'] = $val['sku_code'];
if ($usertype == 1) {
$temp['merchantid'] = $merchant_id;
} else {
$temp['store_id'] = $store_id;
$temp['merchant_id'] = $merchant_id;
}
$skuArrData[] = $temp;
unset($temp);
}
$all_sku_list_id = ltrim($all_sku_list_id, ',');
$attr = M('retail_sku_attr as a')
->join('ls_retail_sku_list as l on l.attr_id=a.id')
->field('a.*')
->where(array('a.merchantid' => $merchant_id, 'a.state' => 0, 'l.id' => array('in', $all_sku_list_id)))
->group('l.attr_id')
->select();
if (count($attr) != $sku_attr_length) {
$res['status'] = 0;
$res['msg'] = '您添加的规格信息属性重复';
$this->ajaxReturn($res);
}
}
$content = array();
$content = $data;
if ($usertype == 1) {
$create = M('retail_mgoods')->add($data);
$content['merchant_id'] = $merchant_id;
$content['goods_number'] = $goods_number;
$content['pricing_method'] = $is_change_weight;
$content['attribute_state'] = $attribute_state;
} else {
$create = M('retail_goods')->add($data);
if (!empty($create)) {
//存入商品变更记录表
$GoodsClass = new Goods();
$GoodsClass->goodsEditRecord([
'store_id' => $store_id,
'merchant_id' => $merchant_id,
'goods_id' => $create
]);
}
}
$content['warehouse_id'] = $warehouse_id;
$content['goods_id'] = $create;
if ($create) {
unset($content['retail_price']);
if ($attribute_state == 1) {
$content['goods_num'] = $goods_num;
if ($usertype == 1) {
$content['purchase_price'] = $purchase_price;
//商户添加
A('Api/Inventory')->merAddSaleGoods($content, 1);
} else {
A('Api/Inventory')->addSaleGoods($content, 1);
}
} else if ($attribute_state == 2) {
foreach ($skuArrData as $k => &$v) {
$content['sku_name'] = $v['name'];
$content['sku_id_list'] = $v['sku_id_list'];
$content['sku_goods_number'] = $v['sku_goods_number'];
$content['sku_code'] = $v['sku_code'];
$content['goods_num'] = $v['goods_num'];
$content['purchase_price'] = $v['purchase_price'];
$content['add_time'] = $v['add_time'];
$content['sku_num'] = 1;
unset($content['more_num']);
unset($content['less_num']);
if ($usertype == 1) {
$v['mgoods_id'] = $create;
$v['addtime'] = $v['add_time'];
$v['purch_price'] = $v['purchase_price'];
unset($v['add_time']);
unset($v['purchase_price']);
} else {
$v['goods_id'] = $create;
}
unset($v['id']);
unset($v['goods_num']);
if ($usertype == 1) {
$add = M("retail_sku_mgoods")->add($v);
$content['sku_id'] = $add;
A('Api/Inventory')->merAddSaleGoods($content, 1);
} else {
$add = M("retail_sku_goods")->add($v);
$content['sku_id'] = $add;
A('Api/Inventory')->addSaleGoods($content, 1);
} //添加规格
}
}
if ($usertype == 1 || $usertype == 2) {
$parameter['desc'] = '商品档案-新增';
switch ($usertype) {
case 1:
$parameter['type'] = 3;
break;
case 2:
$parameter['type'] = 4;
break;
}
$this->system_parameter($parameter);
}
$res['status'] = 1;
$res['msg'] = '录入成功';
} else {
$res['status'] = 0;
$res['msg'] = '录入失败';
}
$this->ajaxReturn($res);
}
}
// 库存查询
protected function searchgoods()
{
if (IS_POST) {
$storeid = I('post.storeid');
$keyword = I('post.keyword');
if (!$keyword) {
$res['status'] = 0;
$res['msg'] = '请输入查询内容';
} else {
if ($keyword) {
$w['store_id'] = $storeid;
$w['goods_code|goods_number|goods_name'] = array('like', "%" . $keyword . "%");
$w['status'] = array('in', array(0, 1));
$field = "goods_name,goods_number,goods_code,cost_price as purchase_price,pricing_method,goods_num,sku_name,attribute_state,sku_code,sku_goods_number";
$goodslist = D('SSaleMGoods')->getSelect($w, $page = '', $limit = '', $field);
if ($goodslist) {
} else {
$w = array();
$w['store_id'] = $storeid;
$w['goods_name'] = array('like', '%' . $keyword . '%');
$w['status'] = array('in', array(0, 1));
$goodslist = D('SSaleMGoods')->getSelect($w, $page = '', $limit = '', $field);
}
}
if ($goodslist) {
foreach ($goodslist as $key => &$val) {
$val['purchase_price'] = round($val['purchase_price'], 2);
$val['goods_num'] = round($val['goods_num'], 3);
if ($val['attribute_state'] == 2) {
$val['goods_name'] = trim($val['goods_name'] . '-' . $val['sku_name'], ',');
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
}
$goodslist[0]['givenum'] = 0;
$goodslist[0]['num'] = "";
$res['sql'] = M()->_sql();
$res['status'] = 1;
$res['msg'] = '查询成功';
$res['goodslist'] = $goodslist;
} else {
$res['status'] = 0;
$res['msg'] = '暂无数据';
}
}
$this->ajaxReturn($res);
}
}
//2019-11-29 库存查询
protected function StockQuery()
{
$data = I("post.");
$storeid = $data['storeid'];
$keyword = $data['keyword'];
$page = $data['page'];
$limit = $data['limit'];
if (!$keyword) {
$res['status'] = 0;
$res['msg'] = '请输入查询内容';
$this->ajaxReturn($res);
}
if ($keyword) {
$where['goods_code | goods_number | goods_name | sku_code | sku_goods_number | sku_name'] = array('like', "%" . $keyword . "%");
}
$where['store_id'] = $storeid;
$where['status'] = array('in', '0,1');
$fields = "goods_number,sku_goods_number,goods_code,sku_code,attribute_state,goods_name,sku_name,cost_price,goods_num";
$list = D('SSaleMGoods')->getSelect($where, $page, $limit, $fields);
if ($list) {
foreach ($list as &$val) {
if ($val['attribute_state'] == 2) {
$val['goods_name'] = $val['goods_name'] . '-' . $val['sku_name'];
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
$val['cost_price'] = round($val['cost_price'], 2);
$val['goods_num'] = round($val['goods_num'], 3);
}
$res['msg'] = '查询成功';
} else {
$res['msg'] = '暂无数据';
}
$res['status'] = 1;
$res['list'] = $list;
$this->ajaxReturn($res);
}
//2019-11-26
protected function searchgoods_v1()
{
$data = I("post.");
$storeid = $data['storeid'];
$keyword = $data['keyword'];
$person1 = $data['person1'];
$person2 = $data['person2'];
$person3 = $data['person3'];
$page = $data['page'];
$limit = $data['limit'];
if ($keyword) {
$where['s.goods_code | s.goods_number | s.goods_name | s.sku_code | s.sku_goods_number | s.sku_name'] = array('like', "%" . $keyword . "%");
}
$flag = 0;
if (!empty($person3)) {
$where['s.goods_class_id'] = $person3;
} else if (!empty($person2)) {
$class = M('retail_goods_class as c2')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid')
->where(array('c2.id' => $person2, 'c3.status' => 0))
->field('c3.id')->select();
$flag = 1;
} else if (!empty($person1)) {
$class = M('retail_goods_class as c1')
->join('ls_retail_goods_class as c2 on c1.id=c2.pid')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid AND c3.status=0', 'LEFT')
->where(array('c1.id' => $person1, 'c2.status' => 0))
->field('c2.id,c3.id as c3_id')->select();
$flag = 1;
}
if (!empty($class)) {
$arr = array();
foreach ($class as &$val) {
if (!in_array($val['id'], $arr)) {
$arr[] = $val['id'];
}
if (!empty($val['c3_id'])) {
if (!in_array($val['c3_id'], $arr)) {
$arr[] = $val['c3_id'];
}
}
}
$str = implode(',', $arr);
$where['s.goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
} else if ($flag == 1) {
$where['s.goods_class_id'] = $person2 ? $person2 : $person1;
}
$where['s.store_id'] = $storeid;
$where['s.status'] = array('in', '0,1');
$fields = "s.goods_id,s.goods_code,s.goods_number,s.sku_goods_number,s.goods_class_id,s.goods_name,s.attribute_state,s.goods_num,s.sku_code,s.sku_id,s.sku_name,s.cost_price,g.retail_price,g.online_state,g.online_price,g.store_mem_status,g.store_mem_price,g.shop_mem_status,g.shop_mem_price,g.plus_mem_status,g.plus_price";
$goodslist = M("retail_store_sale_goods as s")
->join("ls_retail_goods as g on s.goods_id=g.id", "LEFT")
->where($where)
->field($fields)
->page($page, $limit)
->order("s.id desc")
->select();
if ($goodslist) {
$count = M("retail_store_sale_goods as s")
->join("ls_retail_goods as g on s.goods_id=g.id", "LEFT")
->count();
foreach ($goodslist as $key => &$val) {
if ($val['attribute_state'] == 2) { //规格商品
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
$sku_info = D('RetailSkuGoods')->getFind(array('id' => $val['sku_id'], 'goods_id' => $val['goods_id']), "retail_price,online_price,shop_mem_price,store_mem_price,plus_price");
$val['retail_price'] = round($sku_info['retail_price'] ? $sku_info['retail_price'] : '', 2); //店内价
$val['online_price'] = round($sku_info['online_price'] ? $sku_info['online_price'] : '', 2); //小程序商城价格
$val['shop_mem_price'] = round($sku_info['shop_mem_price'] ? $sku_info['shop_mem_price'] : '', 2); //商城会员价格
$val['store_mem_price'] = round($sku_info['store_mem_price'] ? $sku_info['store_mem_price'] : '', 2); //店内会员价
$val['plus_price'] = round($sku_info['plus_price'] ? $sku_info['plus_price'] : '', 2); //小程序商城Plus价格
} else {
$val['shop_mem_price'] = round($val['shop_mem_price'], 2); //商城会员价格
$val['store_mem_price'] = round($val['store_mem_price'], 2); //店内会员价
$val['online_price'] = round($val['online_price'], 2); //小程序商城价格
$val['plus_price'] = round($val['plus_price'], 2); //小程序商城Plus价格
$val['retail_price'] = round($val['retail_price'], 2); //零售价
}
$val['goods_num'] = round($val['goods_num'], 3);
$val['cost_price'] = round($val['cost_price'], 2);
}
}
$res['status'] = 1;
$res['msg'] = '查询成功';
$res['goodsList'] = $goodslist;
$res['page'] = $page;
$res['count'] = $count ? $count : 0;
$this->ajaxReturn($res);
}
//旧版保存价格
protected function submitchangegoodsprice()
{
$storeid = I('post.storeid');
$newprice = I('post.newprice');
if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $newprice)) {
$res['status'] = 0;
$res['msg'] = '价格有误,请重新提交';
$this->ajaxReturn($res);
}
$goodsInfo = I('post.goodsInfo');
if ($goodsInfo) {
switch ($goodsInfo['attribute_state']) {
case 1:
$save = D('RetailGoods')->updateOrder(array('id' => $goodsInfo['goods_id']), array('retail_price' => $newprice));
break;
case 2:
$save = D('RetailSkuGoods')->updateOrder(array('id' => $goodsInfo['sku_id'], 'goods_id' => $goodsInfo['goods_id']), array('retail_price' => $newprice));
}
if ($save) {
$res['status'] = 1;
$res['msg'] = '操作成功';
} else {
$res['status'] = 1;
$res['msg'] = '暂无修改';
}
} else {
$res['status'] = 0;
$res['msg'] = '数据接受失败,请重新提交';
}
$this->ajaxReturn($res);
}
//改价2019-11-26
protected function PriceModify()
{
$data = I("post.");
$store_id = $data['storeid'];
$new_retail_price = $data["new_retail_price"];
$new_online_price = $data["new_online_price"];
$new_store_mem_price = $data["new_store_mem_price"];
$new_shop_mem_price = $data["new_shop_mem_price"];
$new_plus_price = $data["new_plus_price"];
if ($data['type'] == 'Android') {
$goods_info = json_decode($data['goodsInfo'], true);
} else {
$goods_info = $data['goodsInfo'];
}
$store_mem_status = $goods_info["store_mem_status"];
$shop_mem_status = $goods_info["shop_mem_status"];
$plus_mem_status = $goods_info["plus_mem_status"];
$online_state = $goods_info["online_state"];
if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $new_retail_price) && !empty($new_retail_price)) {
$res['status'] = 0;
$res['msg'] = '售价有误,请重新提交';
$this->ajaxReturn($res);
}
if ($online_state == 1 && !empty($new_online_price) && !preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $new_online_price)) {
$res['status'] = 0;
$res['msg'] = '商城价有误,请重新提交';
$this->ajaxReturn($res);
}
if ($store_mem_status == 1 && !empty($new_store_mem_price)) {
if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $new_store_mem_price)) {
$res['status'] = 0;
$res['msg'] = '店内会员价,请重新提交';
$this->ajaxReturn($res);
}
if ((floatval($new_store_mem_price) > floatval($new_retail_price)) && !empty($new_retail_price)) {
$res['status'] = 0;
$res['msg'] = '店内会员价不能大于零售价';
$this->ajaxReturn($res);
}
}
if ($shop_mem_status == 1 && !empty($new_shop_mem_price)) {
if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $new_shop_mem_price)) {
$res['status'] = 0;
$res['msg'] = '商城会员价有误,请重新提交';
$this->ajaxReturn($res);
}
if ((floatval($new_shop_mem_price) > floatval($new_online_price)) && !empty($new_online_price)) {
$res['status'] = 0;
$res['msg'] = '商城会员价不能大于商城价';
$this->ajaxReturn($res);
}
}
if (!empty($new_plus_price) && $plus_mem_status == 1) {
if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $new_plus_price)) {
$res['status'] = 0;
$res['msg'] = 'plus价有误,请重新提交';
$this->ajaxReturn($res);
}
}
if ($goods_info) {
switch ($goods_info['attribute_state']) {
case 1:
if (!empty($new_retail_price)) {
$content['retail_price'] = $new_retail_price;
}
if (!empty($new_online_price) && $online_state == 1) {
$content['online_price'] = $new_online_price;
}
if (!empty($new_store_mem_price) && $store_mem_status == 1) {
$content['store_mem_price'] = $new_store_mem_price;
}
if ($shop_mem_status == 1 && !empty($new_shop_mem_price)) {
$content['shop_mem_price'] = $new_shop_mem_price;
}
if (!empty($new_plus_price) && $plus_mem_status == 1) {
$content['plus_price'] = $new_plus_price;
}
if (!empty($content)) {
$save = D('RetailGoods')->updateOrder(array('id' => $goods_info['goods_id']), $content);
} else {
$save = false;
}
break;
case 2:
if (!empty($new_retail_price)) {
$content['retail_price'] = $new_retail_price;
}
if (!empty($new_online_price) && $online_state == 1) {
$content['online_price'] = $new_online_price;
}
if (!empty($new_store_mem_price) && $store_mem_status == 1) {
$content['store_mem_price'] = $new_store_mem_price;
}
if ($shop_mem_status == 1 && !empty($new_shop_mem_price)) {
$content['shop_mem_price'] = $new_shop_mem_price;
}
if (!empty($new_plus_price) && $plus_mem_status == 1) {
$content['plus_price'] = $new_plus_price;
}
if (!empty($content)) {
$save = D('RetailSkuGoods')->updateOrder(array('id' => $goods_info['sku_id'], 'goods_id' => $goods_info['goods_id']), $content);
} else {
$save = false;
}
break;
}
if ($save) {
$parameter = array(
'type' => 4,
'desc' => '商品改价'
);
$this->system_parameter($parameter);
$res['status'] = 1;
$res['msg'] = '操作成功';
} else {
$res['status'] = 1;
$res['msg'] = '暂无修改';
}
} else {
$res['status'] = 0;
$res['msg'] = '数据接受失败,请重新提交';
}
$this->ajaxReturn($res);
}
// 商品列表
protected function goodsShow()
{
$skuvel = C('sku');
$skuvel = $skuvel ? $skuvel : 2;
if ($skuvel == 2) {
if (IS_POST) {
$storeid = I('post.storeid');
$merchantid = I('post.merchantid');
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
if (empty($storeid) || empty($merchantid)) {
$res['status'] = 0;
$res['msg'] = '参数错误,请重新登录';
} else {
//由于分类属于商户管理范围,所以直接获取商户商品分类
$m_map['status'] = 0;
$m_map['merchantid'] = $merchantid;
$m_map['type'] = 2;
$cate = M("retail_goods_class")
->where($m_map)
->select();
if (!empty($cate)) {
$cates = $cate;
foreach ($cates as $key => $value) {
$son = M("retail_goods_class")
->where(array('pid' => $value['id'], 'merchantid' => $merchantid, 'type' => 3, 'status' => 0))
->select();
$temp = array();
if (!empty($son)) {
foreach ($son as $k => $val) {
$goods = M("retail_goods")
->field("id,good_image,goods_num,goods_code,purch_price,good_number,goods_class_id,goods_name,retail_price,vip_retail_state,agoods_count,can_exchange_weigh")
->where(array('goods_class_id' => $val['id'], 'storeid' => $storeid, 'status' => 0))->select();
if (!empty($goods)) {
foreach ($goods as $ks => $vals) {
$vals['agoods_count'] = 0;
if ($vals['good_image']) {
$vals['good_image'] = $http_type . $_SERVER['HTTP_HOST'] . $vals['good_image'];
} else {
$vals['good_image'] = "";
}
$temp[] = $vals;
}
}
}
}
$cates[$key]['goods'] = $temp;
}
$newcates = array();
foreach ($cates as $k => $v) {
if (count($v['goods']) == 0) {
unset($cates[$k]);
} else {
$newcates[] = $v;
}
}
$res['status'] = 1;
$res['msg'] = '获取成功';
$res['data'] = $newcates;
} else {
$res['status'] = 0;
$res['msg'] = '获取失败';
}
}
$this->ajaxReturn($res);
}
} else {
/*
* 启用规格 11-01
* */
if (IS_POST) {
$storeid = I('post.storeid');
$merchantid = I('post.merchantid');
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
if (!$storeid || !$merchantid) {
$res['status'] = 0;
$res['msg'] = '参数错误,请重新登录';
} else {
//直接获取商户下面的分类
$m_map['status'] = 0;
$m_map['merchantid'] = $merchantid;
$m_map['type'] = 2;
$cate = M("retail_goods_class")->field("id,class_name,pid,type")->where($m_map)->select();
$m_map['type'] = 3;
$sonCate = M("retail_goods_class")->field("id,class_name,pid,type")->where($m_map)->select();
$goods = M("retail_goods")
->field("id,good_image,goods_num,goods_code,purch_price,good_number,goods_class_id,goods_name,retail_price,vip_retail_state,agoods_count,can_exchange_weigh,attribute,attributeid")
->where(array('merchantid' => $merchantid, 'storeid' => $storeid, 'status' => 0))->select();
$newgoods = array();
foreach ($goods as $key => $value) {
foreach ($sonCate as $k => $v) {
if ($value['goods_class_id'] == $v['id']) {
$goods[$key]['pid'] = $v['pid'];
}
}
$goods[$key]['agoods_count'] = 0;
if ($value['good_image']) {
$goods[$key]['good_image'] = $http_type . $_SERVER['HTTP_HOST'] . $value['good_image'];
} else {
$goods[$key]['good_image'] = "";
}
//多规格商品
if ($value['attribute'] == 2) {
//启用多规格,但存在没有添加规格商品的可能
if (isset($value['attributeid'])) {
//添加了多规格商品
$skuitems = M('retail_goodsku')->where(array('goods_id' => $value['id'], "status" => 2))->select();
if (!$skuitems) {
$goods[$key]['attribute'] = 1;
$newgoods[] = $goods[$key];
$goods[$key]['skujson'] = array();
} else {
$skujson = array();
foreach ($skuitems as $k => $v) {
$skujson[$k]['id'] = $v['id'];
$skujson[$k]['goods_id'] = $v['goods_id'];
$skujson[$k]['sku'] = $v['sku'];
$skujson[$k]['sku_res'] = $v['sku_res'];
$skujson[$k]['retail_price'] = $v['goods_price'];
$skujson[$k]['num'] = $v['num'];
$sku = $skujson[$k];
$goods[$key]['sku'][] = $sku;
$newgoods[] = $goods[$key];
}
}
} else {
$goods[$key]['attribute'] = 1;
$newgoods[] = $goods[$key];
}
} else {
$newgoods[] = $goods[$key];
}
}
$goods = $newgoods;
foreach ($cate as $key => $value) {
foreach ($goods as $k => $v) {
if ($value['id'] == $v['pid']) {
$cate[$key]['goods'][] = $v;
} else {
continue;
}
}
}
$newcates = array();
foreach ($cate as $k => $v) {
if (count($v['goods']) == 0) {
unset($cate[$k]);
} else {
$newcates[] = $v;
}
}
if ($newcates) {
$res['status'] = 1;
$res['data'] = $newcates;
} else {
$res['status'] = 0;
$res['data'] = array();
}
}
}
$this->ajaxReturn($res);
}
}
// 销售收银-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//现金支付
protected function cashPay()
{
// A('Sellapi/PayRefund')->cashPay();
A('Sellapi/Pay')->cashPay();
}
// 会员支付
protected function cardpay()
{
A('Sellapi/Pay')->cardpay();
}
// 获取会员信息
protected function getvipinfo()
{
if (IS_POST) {
$vip_num = I('post.card_num'); //会员卡号;
$merchantid = I('post.merchantid'); //商户id;
$total_money = I('post.allMoney'); //用户消费金额(用来查询可用优惠券);
if (strlen($vip_num) == 11) {
$map['mobile_phone'] = $vip_num;
} else {
$map['card_key'] = $vip_num;
}
//先根据商户id查询出主店id 用来获取会员信息
$map['merchantid'] = $merchantid;
$vip = M('retail_vip')
->where($map)
->field('id,nickname,name,balance,mobile_phone as cardnum,card_key,integral,grade_integral,status')
->find();
if (!empty($vip)) {
//用来判断会员等级
$grade = M('retail_vip_integral')
->where(array('min_integral' => array('ELT', $vip['grade_integral']), 'merchantid' => $merchantid))
->order('min_integral desc')
->find();
if (empty($grade)) {
$vip['grade'] = 'vip';
$vip['cardname'] = '普通会员';
$vip['discount'] = 1;
} else {
$vip['grade'] = $grade['cardname'];
$vip['cardname'] = $grade['cardname'];
$vip['discount'] = $grade['discount'];
}
if ($vip['nickname'] == null || $vip['nickname'] == '') {
$vip['nickname'] = $vip['name'];
}
if ($vip['name'] == null || $vip['name'] == '') {
$vip['name'] = $vip['nickname'];
}
if ($vip['status'] == 1) {
$storeid = I('post.storeid');
//查询优惠券条件(个人)
$c_map['v.isuse'] = 1; //未使用优惠券
$c_map['v.vid'] = $vip['id']; //会员id
$c_map['v.starttime'] = array("LT", time()); //优惠券使用期在今天范围内
$c_map['v.endtime'] = array("GT", time()); //优惠券使用期在今天范围内
$myCoupons = M("retail_vipmcoupon as v")
->join('ls_retail_mcoupon as m on m.id=v.mcouponid')
->field("m.coupon_name,v.id,v.vid,v.starttime,v.endtime,v.needmoney,v.reducemoney,v.canusestoreids,v.merchantid")
->where($c_map)
->select();
$cc = array();
if (!empty($myCoupons)) {
foreach ($myCoupons as &$value) {
$value['starttime'] = date("Y/m/d", $value['starttime']);
$value['endtime'] = date("Y/m/d", $value['endtime']);
if ($value['canusestoreids'] != 0) {
$canUseStore = explode(",", trim($value['canusestoreids'], ','));
if (in_array($storeid, $canUseStore)) {
$cc[] = $value;
}
} else {
$cc[] = $value;
}
}
}
$vip['coupons'] = $cc;
$res['status'] = 1;
$res['msg'] = '查询成功';
$res['info'] = $vip;
} else if ($vip['status'] == 3) {
$res['status'] = 0;
$res['msg'] = '会员卡已被冻结';
// $res['info'] = $vip;
} else if ($vip['status'] == 4) {
$res['status'] = 0;
$res['msg'] = '会员卡已挂失';
// $res['info'] = $vip;
} else {
// $res['one'] = $one;
$res['status'] = 1;
$res['msg'] = '查询成功';
$res['info'] = $vip;
}
} else {
$res['status'] = 0;
$res['msg'] = '暂未查询到该会员';
}
$this->ajaxReturn($res);
}
}
// 会员信息
protected function vipIndex()
{
$storeid = I('post.storeid'); //门店id
$merchantid = M('retail_store')->where(array('id' => $storeid))->getField("merchantid");
if ($storeid == null && $storeid == '') {
$static['status'] = 0;
$static['msg'] = '查询失败';
} else {
$start = strtotime(date("Y-m-d 0:0:0", strtotime("-1day"))); //开始
$end = $start + 86400;
//会员总数
$jurisdiction = M('retail_store_jurisdiction')->field("store_show_vip_info")->where(array('storeid' => $storeid))->find();
if (!empty($jurisdiction) && $jurisdiction['store_show_vip_info'] == 2) {
$mem['v.storeid|p.storeid'] = $storeid;
}
$mem['v.merchantid'] = $merchantid;
$mem['v.status'] = 1;
$time = time();
$memcount = M('retail_vip as v')
->join('ls_retail_plus_vip as p on p.vip_id=v.id and p.start_time<' . $time . ' and p.end_time>' . $time, 'LEFT')
->where($mem)
->count();
//昨日新会员
$mem['v.addtime'] = array('between', array($start, $end));
$daycount = M('retail_vip as v')
->join('ls_retail_plus_vip as p on p.vip_id=v.id and p.start_time<' . $time . ' and p.end_time>' . $time, 'LEFT')
->where($mem)
->count();
$static['memcount'] = $memcount ? $memcount : '0'; //会员总数
$static['daycount'] = $daycount ? $daycount : '0'; //昨日会员
$static['status'] = 1;
$static['msg'] = '成功';
}
$this->ajaxReturn($static);
}
//会员详细信息
protected function queryMember()
{
if (IS_POST) {
//门店id
$storeid = I("post.storeid");
$merchantid = M("retail_store")->where(array("id" => $storeid))->getField("merchantid");
//查询会员条件
//列表
$keyword = I('post.keyword');
if (!empty($keyword)) {
$map2['mobile_phone|name|nickname|card_key'] = array('like', "%{$keyword}%");
}
$type = I('post.type');
if ($type == 1) {
$start = strtotime(date("Y-m-d 0:0:0", strtotime("-1day"))); //开始
$end = $start + 86400;
$map2['v.addtime'] = array('between', array($start, $end));
}
$page = I('post.page');
$limit = 200;
$jurisdiction = M('retail_store_jurisdiction')->field("store_show_vip_info")->where(array('storeid' => $storeid))->find();
if (!empty($jurisdiction) && $jurisdiction['store_show_vip_info'] == 2) {
$map2['v.storeid|p.storeid'] = $storeid;
}
$map2['v.status'] = 1;
$time = time();
$map2['v.merchantid'] = $merchantid;
$list = M('retail_vip as v')
->join('ls_retail_plus_vip as p on p.vip_id=v.id and p.start_time<' . $time . ' and p.end_time>' . $time, 'LEFT')
->field('v.id,v.mobile_phone,v.integral,v.nickname,v.name,v.addtime,v.balance,v.grade_integral,v.card_key,v.headimgurl,v.plus_type')
->where($map2)
->page($page, $limit)
->order('v.grade_integral desc')
->select();
if (!empty($list)) {
foreach ($list as $k => &$v) {
$arr = $this->getgrade($merchantid, $v['grade_integral']);
unset($list[$k]['grade_integral']);
$list[$k]['grade'] = $arr['grade'];
$list[$k]['cardname'] = $arr['cardname'];
$list[$k]['addtime'] = date('Y-m-d', $v['addtime']);
if ($v['headimgurl']) {
$v['hasimg'] = "1";
} else {
$v['hasimg'] = "2";
$list[$k]['headimgurl'] = "/images/defaultimg.png";
}
if ($v['name'] == null || $v['name'] == '') {
$v['zname'] = $v['nickname'] ? $v['nickname'] : "昵称";
} else {
$v['zname'] = $v['name'] ? $v['name'] : "会员名称";
}
unset($v['name']);
unset($v['nickname']);
}
$count = M('retail_vip as v')
->join('ls_retail_plus_vip as p on p.vip_id=v.id', 'LEFT')
->where($map2)
->count();
$rt['status'] = 1;
$rt['msg'] = '刷新成功';
$rt['count'] = $count;
$rt['viplist'] = $list;
} else {
$rt['status'] = 0;
$rt['msg'] = '暂无会员';
}
$this->ajaxReturn($rt);
}
}
public function getgrade($merchantid, $integral)
{
$wgrade['min_integral'] = array("elt", $integral);
$wgrade['merchantid'] = $merchantid;
$integrallist = M('retail_vip_integral')
->where($wgrade)
->order("min_integral desc")
->limit(1)
->select();
if ($integrallist) {
$cardname = $integrallist[0]['cardname'];
$grade = $integrallist[0]['cardname'];
$grade_id = $integrallist[0]['id'];
} else {
$grade = "0";
$cardname = "普通会员";
}
return array('grade' => $grade, 'cardname' => $cardname, 'grade_id' => $grade_id);
}
// 会员信息
protected function vipInfo()
{
if (IS_POST) {
$vid = I('post.vid');
$merchantid = I('post.merchantid');
$user_type = I("post.user_type"); //1商户 2门店 3收银员
$cashier_id = I("post.cashier_id");
if ($user_type == 3) {
$modifymem = D("RetailCashier")->getFindField(array('id' => $cashier_id), "modifymem");
}
$modifymem = $modifymem ? $modifymem : '';
$map['id'] = $vid;
$map['status'] = array('neq', 2);
$vip = M("retail_vip")->where($map)
->field('id,mobile_phone,integral,nickname,name,addtime,balance,grade_integral,card_key,cardnum,plus_type')
->find();
if (!empty($vip)) {
//所有等级
$VipIntegraModel = D("RetailVipIntegral");
$fields = "cardname,id,min_integral";
$order = "min_integral asc";
$gradeData = $VipIntegraModel->getSelect(array($VipIntegraModel::MERCHANT_ID => $merchantid), $fields, $order);
if (!empty($gradeData) && $gradeData[0]['min_integral'] != 0) {
array_unshift($gradeData, array('id' => 0, 'cardname' => '无等级'));
}
$arr = $this->getgrade($merchantid, $vip['grade_integral']);
unset($vip['grade_integral']);
$vip['grade_id'] = $arr['grade_id'];
$vip['cardname'] = $arr['cardname'];
$vip['mobile_phone'] = $vip['mobile_phone'] ? $vip['mobile_phone'] : '';
$vip['addtime'] = date('Y-m-d', $vip['addtime']);
if ($vip['name'] == null || $vip['name'] == '') {
$vip['zname'] = $vip['nickname'];
} else {
$vip['zname'] = $vip['name'];
}
$w['vid'] = $vid;
$w['type'] = 1;
$w['status'] = 1;
$summoney = M('recharge_order')->where($w)->sum('all_money');
$vip['summoney'] = $summoney ? $summoney : 0;
unset($vip['name']);
unset($vip['nickname']);
$rt['status'] = 1;
$rt['msg'] = '搜索成功';
$rt['vip'] = $vip;
$recharge = M('vip_recharge')->where(array('merchantid' => $merchantid))->select(); //充值优惠信息
$rt['recharge'] = $recharge ? $recharge : array();
$rt['gradeData'] = $gradeData;
$rt['modifymem'] = $modifymem;
} else {
$rt['status'] = 0;
$rt['msg'] = '暂未查询到该会员';
}
$this->ajaxReturn($rt);
}
}
protected function getVipEsteatment()
{
if (IS_POST) {
$id = I("post.vid");
$w['vid'] = $id;
$w['status'] = 1;
$e = strtotime(date("Y-m-d 23:59:59")); //开始
$s = $e - 86400 * 30;
$w['add_time'] = array('between', array($s, $e));
$recharge_order = M('recharge_order')
->field('id,state,user_type,vid,cashier_id,', true)
->where($w)
->order('add_time desc')
->select();
if ($recharge_order) { // storename storeid
foreach ($recharge_order as $k => $v) {
$recharge_order[$k]['timedetail'] = date('Y-m-d H:i:s', $v['add_time']);
if ($v['type'] == 2) {
if ($v['store_id']) {
$recharge_order[$k]['storename'] = M('retail_store')
->where(array('id' => $v['store_id']))
->getField('storetag');
} else {
$recharge_order[$k]['storename'] = "其他消费(非门店内消费)";
}
} else if ($v['type'] == 1) {
if ($v['store_id']) {
$recharge_order[$k]['storename'] = M('retail_store')
->where(array('id' => $v['store_id']))
->getField('storetag');
} else {
$recharge_order[$k]['storename'] = "其他充值(非门店内充值)";
}
}
}
$rt['status'] = 1;
$rt['msg'] = "查询成功";
$rt['paylist'] = $recharge_order;
} else {
$rt['status'] = 0;
$rt['msg'] = "查询失败";
}
$this->ajaxReturn($rt);
}
}
// 今日会员充值与消费记录统计
protected function todayvipcardinfo()
{
if (IS_POST) {
$keyword = I('post.keyword');
$merchantid = I('post.merchantid');
$page = I('post.page');
$limit = 20;
if ($keyword) {
$map['merchantid'] = $merchantid;
$map['mobile_phone|nickname|name'] = $keyword;
$vid = M('retail_vip')
->where($map)
->getField('id');
if (!$vid) {
$rt['status'] = 0;
$rt['msg'] = '未找到符合条件的会员';
$this->ajaxReturn($rt);
}
$w['vid'] = $vid;
}
$e = strtotime(date("Y-m-d 23:59:59")); //开始
$s = $e - 86400;
$w['add_time'] = array('between', array($s, $e));
$w['status'] = 1;
$w['merchant_id'] = $merchantid;
$w['type'] = 1;
$ccount = M('recharge_order')->where($w)->page($page, $limit)->count();
$cgetmoney = M('recharge_order')->where($w)->page($page, $limit)->sum('all_money');
$cpaymoney = M('recharge_order')->where($w)->page($page, $limit)->sum('money');
$resummoney = $cgetmoney - $cpaymoney;
$w['type'] = array('in', array(2, 6));
$allpaycount = M('recharge_order')->where($w)->page($page, $limit)->count();
$allpay = M('recharge_order')->where($w)->page($page, $limit)->sum('all_money');
$w['type'] = 5;
$refund = M('recharge_order')->where($w)->page($page, $limit)->sum('money');
$w['type'] = 8;
$hdadd = M('recharge_order')->where($w)->page($page, $limit)->sum('all_money');
$rt['status'] = 1;
$rt['msg'] = '查询成功';
$rt['summoney'] = $cpaymoney ? round($cpaymoney, 2) : 0; // 总充值支付
$rt['allmoney'] = $cgetmoney ? round($cgetmoney, 2) : 0; // 总充值获得
$rt['resummoney'] = $resummoney ? round($resummoney, 2) : 0; // 总充值赠送
$rt['ccount'] = $ccount ? round($ccount, 2) : 0; // 充值笔数。
$rt['pay'] = $allpay ? round($allpay, 2) : 0;
$rt['paynum'] = $allpaycount ? round($allpaycount, 2) : 0;
$rt['refund'] = $refund ? round($refund, 2) : 0;
$rt['hdadd'] = $hdadd ? round($hdadd, 2) : 0;
if ($allpaycount > 0) {
$rt['ave'] = round($allpay / $allpaycount, 2);
} else {
$rt['ave'] = 0;
}
$this->ajaxReturn($rt);
}
}
// 今日会员充值与消费记录列表
protected function todayVipCardList()
{
if (IS_POST) {
$keyword = I('post.keyword');
$merchantid = I('post.merchantid');
$page = I('post.page');
$limit = 20;
if ($keyword) {
$map['merchantid'] = $merchantid;
$map['mobile_phone|nickname|name'] = $keyword;
$vid = M('retail_vip')
->where($map)
->getField('id');
if (!$vid) {
$rt['status'] = 0;
$rt['msg'] = '未找到符合条件的会员';
$this->ajaxReturn($rt);
}
$w['vid'] = $vid;
}
$e = strtotime(date("Y-m-d 23:59:59")); //开始
$s = $e - 86400;
$w['add_time'] = array('between', array($s, $e));
$w['status'] = 1;
$w['merchant_id'] = $merchantid;
$list = M('recharge_order')
->where($w)
->page($page, $limit)
->select();
if ($list) {
foreach ($list as $k => $v) {
$list[$k]['addtime'] = date('Y-m-d H:i', $v['add_time']);
if ($v['type'] == 1) {
$list[$k]['typename'] = '充值';
} else if ($v['type'] == 2) {
$list[$k]['typename'] = '消费';
} else if ($v['type'] == 5) {
$list[$k]['typename'] = '余额退款';
} else if ($v['type'] == 6) {
$list[$k]['typename'] = '红包充值';
} else if ($v['type'] == 8) {
$list[$k]['typename'] = '礼品卡充值';
}
if ($v['storeid']) {
$list[$k]['storetag'] = M('retail_store')
->where(array('id' => $v['storeid']))
->getField('storetag');
}
}
}
$rt['status'] = 1;
if ($keyword && $vid) {
$rt['msg'] = '该会员今日无交易记录';
} else {
$rt['msg'] = '查询成功';
}
$rt['data'] = $list ? $list : array();
$rt['count'] = $limit;
$this->ajaxReturn($rt);
}
}
/**
* 会员充值记录
*/
public function vipRechargeRecord()
{
A('Terminalapi/Vip')->vipRechargeRecord();
}
// 线上订单
protected function onlineorderInfo()
{
$storeid = I('post.storeid');
$data['storeid'] = $storeid;
$order_num = I('post.order_number');
$page = I('post.page');
$num = 20;
if ($storeid == '') {
$res['status'] = 0;
$this->ajaxReturn($res);
exit;
} else {
$where['b.store_id'] = $storeid;
//线上
$where['b.type'] = 1;
if (!empty($order_num)) {
$where['b.order_no|o.pick_code'] = $order_num;
} else {
$where['b.pay_state'] = 1; // 已付款
}
$where['b.order_type'] = 1; // 购买订单
$where['o.status'] = array('neq', 0); //0未支付(不会用该值判断) 1未发货 2已发货 3已收货
$where['b.pay_state'] = 1;
$order = M('retail_bill_order as b')
->join('ls_retail_bill_online as o on o.bill_id=b.id')
->join('ls_retail_bill_discount as d on d.bill_id=b.id')
->join('ls_retail_bill_group as g on g.bill_id=b.id and g.state=1', 'LEFT')
->join('ls_retail_bill_spike as s on s.bill_id=b.id and s.state=1', 'LEFT')
->where($where)
->order('b.id desc')
->page($page, $num)
->select();
$SerialClass = new SerialNumberGoods();
$plugClass = new Plug();
//订单获取祝福码,判断该门店是否,有,并且开启
$storePlugStatusPost = [
'store_id' => $storeid,
'identification_arr' => ['blessing'],
];
$storePlugStatus = $plugClass->plugStoreStatus($storePlugStatusPost);//获取状态
foreach ($order as $key => &$val) {
// 1未发货 2已发货 3已收货 4已评价 5下单成功未支付 6订单有被退款
$val['statusnum'] = $val['status'];
if ($val['refund_status'] == 0) {
switch ($val['status']) {
case 1:
$val['status'] = '未发货';
break;
case 2:
$val['status'] = '已发货';
break;
case 3:
$val['status'] = '已收货';
break;
default:
$val['status'] = '正常订单';
break;
}
} else if ($val['refund_status'] == 1) {
$val['status'] = '申请售后';
}
//支付方式 1现金 3微信支付 4支付宝支付 5会员卡余额支付 7其他支付方式 8组合支付
switch ($val['pay_type']) {
case 1:
$val['payname'] = '现金';
break;
case 2:
$val['payname'] = '银行卡';
break;
case 3:
$val['payname'] = '微信支付';
break;
case 4:
$val['payname'] = '支付宝支付';
break;
case 5:
$val['payname'] = '会员卡余额支付';
break;
case 6:
$val['payname'] = '微信小程序支付';
break;
case 7:
$val['payname'] = '其他支付';
break;
case 8:
$val['payname'] = '组合支付';
break;
}
switch ($val['order_genre']) {
case 1:
$val['order_genre'] = "普通订单";
break;
case 2:
$val['order_genre'] = "拼团订单";
break;
case 3:
$val['order_genre'] = "秒杀订单";
break;
case 4:
$val['order_genre'] = "预售订单";
break;
default:
break;
}
$sell_ids = M('retail_sell')->where(array('bill_id' => $val['id']))->getField('id', true);
foreach ($sell_ids as $ke => &$va) {
$sell_info = M('retail_sell')->where(array('id' => $va))->find();
if (empty($sell_info)) {
$val['good_info'][$ke]['name'] = '详情数据被清除';
$val['good_info'][$ke]['yuan_price'] = '0';
$val['good_info'][$ke]['goods_allmoney'] = '0';
$val['good_info'][$ke]['discount'] = '0';
} else {
$val['good_info'][$ke]['goods_id'] = $sell_info['goods_id'];
if ($sell_info['attribute_state'] == 2) {
$skuinfo = json_decode($sell_info['sku_json_info'], true);
$val['good_info'][$ke]['skuinfo'] = $skuinfo;
$val['good_info'][$ke]['name'] = $sell_info['goods_name'] . '(' . $skuinfo['name'] . ')';
$val['good_info'][$ke]['sku_id'] = $sell_info['sku_id'];
} else {
$val['good_info'][$ke]['name'] = $sell_info['goods_name'];
}
$val['good_info'][$ke]['num'] = $sell_info['num'];
$val['good_info'][$ke]['company'] = $sell_info['company'];
$val['good_info'][$ke]['yuan_price'] = $sell_info['original_price'];
$val['good_info'][$ke]['goods_allmoney'] = $sell_info['all_money'];
$val['good_info'][$ke]['discount'] = $sell_info['vip_discount'];
//串号信息
$val['good_info'][$ke]['serial_number_state'] = $sell_info['serial_number_state'];
if ($sell_info['serial_number_state'] == 1) {
$serialResult = $SerialClass->sellSerialList([
'id' => $sell_info['id']
]);
$val['good_info'][$ke]['serial_list'] = $serialResult['data']['list'];
}
}
}
if (empty($val['vip_dis_money'])) {
$val['coupon'] = 0;
} else {
$val['coupon'] = $val['vip_dis_money'];
}
$val['add_time'] = date('m-d H:i:s', $val['add_time']);
if (!empty($val['delivery_time'])) {
$val['delivery_time'] = date('Y-m-d H:i:s', $val['delivery_time']);
}
if ($val['pickup_type'] == 1) {
//自提
$val['address_name'] = $val['user_name'];
$val['address_phone'] = $val['user_phone'];
$val['address_address'] = '自提暂无地址';
$val['user_select_time'] = date('Y-m-d H:i:s', $val['user_select_time']);
} else if ($val['pickup_type'] == 2) {
//配送
$val['address_name'] = $val['user_name'];
$val['address_phone'] = $val['user_phone'];
$val['address_address'] = $val['user_address'];
$val['user_select_time'] = date('Y-m-d H:i:s', $val['user_select_time']);
} else if ($val['pickup_type'] == 3) {
//配送
$val['address_name'] = $val['user_name'];
$val['address_phone'] = $val['user_phone'];
$val['address_address'] = $val['user_address'];
}
unset($val['sellid']);
unset($val['paytype']);
unset($val['vipid']);
unset($val['storeid']);
unset($val['merchantid']);
unset($val['admin_id']);
unset($val['people_class']);
unset($val['vip_card']);
if ($storePlugStatus === true) {
//有权限
$extractionCode = new Index();
$val['extraction_code'] = $extractionCode->obtainExtractionCode($val['id']);//祝福码
} else {
//无权限
$val['extraction_code'] = null;
}
}
$res['count'] = 20;
$res['status'] = 1;
$res['order'] = $order ? $order : array();
}
$this->ajaxReturn($res);
}
// 自提货操作
protected function distribution_zt()
{
$res = A('CashierApi/Order')->selfMention_v1();
return $res;
}
// 配送操作
protected function distribution_ps()
{
$res = A('CashierApi/Order')->deliveryOrder_v2();
return $res;
}
//查询商品库信息30
protected function checkgoodscode()
{
$data = I('post.');
if (empty($data['code'])) {
$this->ajaxReturn(['status' => 0, 'msg' => '请输入条码']);
}
$merchantModel = new RetailMerchantModel();
$partner_id = $merchantModel->getFindField(['id' => $data['merchant_id']], "partnerid");
$goods = new Goods();
$result = $goods->basisCodeGetGoodsInfo($data['code'], $partner_id);
if ($result['status'] == 1) {
$res = [
'status' => 1,
'msg' => '查询成功',
'data' => $result['data']['goods']
];
} else {
$res = [
'status' => 0,
'msg' => '未找到该商品'
];
}
$this->ajaxReturn($res);
}
// 添加商品检测货号
protected function checkgoodsnum()
{
if (IS_POST) {
$code = I('post.code');
$storeid = I('post.storeid');
$info = M('retail_goods')->where(array('goods_number' => $code, 'store_id' => $storeid, ""))->field('id')->find();
if ($info) {
$rt['status'] = 0;
$rt['msg'] = '重复,货号不可用';
} else {
$rt['status'] = 1;
$rt['msg'] = '货号可用';
}
$this->ajaxReturn($rt);
}
}
//查询线上订单未读的数量
public function unreadshow()
{
$storeid = I('post.storeid');
$starttime = strtotime("-30 day");
$endtime = time();
$where['addtime'] = array('between', array($starttime, $endtime));
$where['storeid'] = $storeid;
$where['paytype'] = array('neq', 0);
$where['type'] = 1;
$where['unread'] = 1;
$count = M('retail_bill')->where($where)->count();
if ($count) {
$res['status'] = 1;
$res['count'] = $count;
} else {
$res['status'] = 0;
$res['count'] = 0;
}
$this->ajaxReturn($res);
}
//修改订单未读状态
public function modifyUnread()
{
$storeid = I('post.storeid');
$startime = strtotime("-30 day");
$endtime = time();
$where['patype'] = array('neq', 0);
$where['type'] = 1;
$where['storeid'] = $storeid;
$where['addtime'] = array('between', array($startime, $endtime));
$save = M('retail_bill')->where($where)->save(array('unread' => 2));
if ($save) {
$res['status'] = 1;
} else {
$res['statuus'] = 0;
}
$this->ajaxReturn($res);
}
protected function newGoodsList_v1()
{
A('Sellapi/GoodShow')->newGoodsList_V1();
}
protected function newGoodsList_v3()
{
if (IS_POST) {
$storeid = I('post.storeid');
$merchantid = I('post.merchantid');
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
if (!$storeid || !$merchantid) {
$res['status'] = 0;
$res['msg'] = '参数错误,请重新登录';
} else {
//直接获取商户下面的分类
$m_map['c.status'] = 0;
$m_map['c.merchantid'] = $merchantid;
$m_map['g.store_id'] = $storeid;
$m_map['g.status'] = 0;
$commonUse = array();
$tempClass = array();
$tempIndexArr = array();
$field = "c.id as c_id,c.class_name,g.usual_state,g.id,g.goods_img_id,
g.goods_code,g.purchase_price,g.goods_number,g.goods_name,g.retail_price,
g.vip_retail_state,g.pricing_method,g.attribute_state,
g.store_mem_status,g.store_mem_price";
$goods = M("retail_goods as g")
->join('ls_retail_goods_class as c on g.goods_class_id=c.id')
->where($m_map)
->field($field)
->select();
$skufield = 'id,sku_id_list,retail_price,goods_img,sku_code,store_mem_price';
foreach ($goods as &$value) {
if (!empty($value['goods_img_id'])) {
$img = D('ImageGallery')->getFieldPath(array('id' => $value['goods_img_id']));
} else {
$defaultimg = M('retail_goods_defaultimg')
->where(array('storeid' => $storeid))
->cache(true, 300)// 缓存300s
->field('default_goods_img,default_goods_img_id')->find();
if (!empty($defaultimg['default_goods_img_id'])) {
$img = D('ImageGallery')->getFieldPath(array('id' => $defaultimg['default_goods_img_id']));
if (!$img) {
$img = $http_type . $_SERVER['HTTP_HOST'] . "/Public/images/empty-goods-images.png";
}
} else {
if (!$defaultimg['default_goods_img'] || $defaultimg['default_goods_img'] == '/Uploads') {
$img = $http_type . $_SERVER['HTTP_HOST'] . "/Public/images/empty-goods-images.png";
} else {
$img = $http_type . $_SERVER['HTTP_HOST'] . $defaultimg['default_goods_img'];
}
}
}
$value['good_image'] = $img;
if ($value['pricing_method'] == 2) {
$value['attribute'] = 1;
}
$value['goods_type'] = 1;
//多规格商品
$value['skuAttr'] = array();
$value['skuList'] = array();
if ($value['attribute_state'] == 2) {
//启用多规格,但存在没有添加规格商品的可能
$str = '';
$goodsSku = M('retail_sku_goods')
->where(array('goods_id' => $value['id'], 'state' => 0))
->order('retail_price asc')
->field($skufield)
->select();
if (empty($goodsSku)) {
$value['attribute_state'] = 1;
} else {
foreach ($goodsSku as &$val) {
$str .= ',' . $val['sku_id_list'];
if (empty($val['goods_img'])) {
$val['goods_img'] = $value['good_image'];
} else {
$val['goods_img'] = $http_type . $_SERVER['HTTP_HOST'] . $val['goods_img'];
}
$name = M('retail_sku_list')->where(array('id' => array('in', $val['sku_id_list'])))->getField('name', true);
$val['name'] = implode(',', $name);
$val['store_mem_status'] = $value['store_mem_status'];
}
$str = ltrim($str, ',');
$sku_id_list = explode(',', $goodsSku[0]['sku_id_list']);
$attr = array();
foreach ($sku_id_list as $v) {
$tempAttr = M('retail_sku_list as l')
->join('ls_retail_sku_attr as a on l.attr_id=a.id')
->where(array('l.id' => $v))
->field('a.id,a.name')
->find();
$tempAttr['list'] = M('retail_sku_list')
->where(array('id' => array('in', $str), 'attr_id' => $tempAttr['id'], 'state' => 0))
->field('id,name')
->select();
$attr[] = $tempAttr;
}
$value['skuAttr'] = $attr;
$value['skuList'] = $goodsSku;
}
}
if ($value['usual_state'] == 2) {
$commonUse[] = $value;
}
$class_name = $value['class_name'];
$key = array_search($class_name, $tempIndexArr);
if ($key !== false) {
unset($value['c_id']);
unset($value['class_name']);
$tempClass[$key]['goods'][] = $value;
} else {
$tempIndexArr[] = $class_name;
$tempArr['id'] = $value['c_id'];
$tempArr['class_name'] = $class_name;
unset($value['c_id']);
unset($value['class_name']);
$tempArr['goods'][] = $value;
$tempClass[] = $tempArr;
unset($tempArr);
}
}
if (!empty($commonUse)) {
$newCate = array(
'class_name' => '常用商品',
'goods' => $commonUse,
'id' => 0
);
array_unshift($tempClass, $newCate);
}
if ($tempClass) {
$res['status'] = 1;
$res['data'] = $tempClass;
} else {
$res['status'] = 0;
$res['data'] = array();
}
}
}
$this->ajaxReturn($res);
}
protected function getGoodsList_v1()
{
$res = A('CashierApi/GoodsShow')->goodsList_v1();
return $res;
}
protected function dadadelivery()
{
A('Sellapi/Order')->dadadelivery();
}
/*
* 2019-1-26收银员收款统计
* */
protected function newCashierList_v1()
{
if (IS_POST) {
$storeid = I('post.storeid');
$cashier_id = I('post.operator_id');
if (!$storeid) {
$rt['status'] = 0;
$rt['msg'] = '参数错误';
$this->ajaxReturn($rt);
exit();
}
$PayOrderModel = D("RetailPayOrder"); //支付流水模型
$needsellinfo = I('post.needsellinfo');
$cashier_show_other_sell = M('retail_cashier')->where(array('id' => $cashier_id))->getField("cashier_show_other_sell");
$where_cashier = array(
'status' => 1,
'storeid' => $storeid,
);
if ($cashier_show_other_sell == 2) {
$where_cashier['id'] = $cashier_id;
}
$list = M('retail_cashier')
->where($where_cashier)
->field('id,name')
->select();
if ($list || $needsellinfo) {
if ($needsellinfo) {
$list = $list ? $list : array();
$endtime = I('post.endtime');
$starttime = I('post.starttime');
$start = strtotime($starttime . ' 00:00:00');
$end = strtotime($endtime . ' 23:59:59');
if (!$endtime && !$starttime) {
$start = strtotime(date('Y-m-d 00:00:00', time()));
$end = $start + 86399;
}
$PlugApi = new Plug();
//获取付费插件列表及状态
$plug_result = $PlugApi->PlugPermissions(array(
'merchant_id' => I('post.merchantid'),
'identification_arr' => ['credit']
));
//商户是否存在赊账插件
$isCredit = $plug_result['data']['plug']['credit'] && $plug_result['data']['plug']['credit'] > 0 ? true : false;
if ($isCredit) {
$CreditArrearageModel = new \Credit\Model\CreditArrearageModel(); // 赊账
$CreditRepaymentModel = new \Credit\Model\CreditRepaymentModel(); // 还款
}
foreach ($list as $k => $v) {
$where = array();
$where['cashier_id'] = $v['id'];
$where['add_time'] = array('between', array($start, $end));
$where['pay_state'] = 1;
$where['store_id'] = $storeid;
$where['order_type'] = 1;
$where['type'] = 2;
$where['pay_type'] = array('neq', '0');
$count = M('retail_bill_order')->where($where)->count();
$allmoney = M('retail_bill_order')->where($where)->sum('all_money'); //今日总金额
$allmoney = $allmoney ? $allmoney : 0;
$where['order_type'] = 2;
$refund_store = M('retail_bill_order')->where($where)->sum('refund_money'); //统计今日门店退款金额
$refund_store = $refund_store ? $refund_store : 0;
//赊账数据统计
if ($isCredit) {
$arrearage_map = [
'cashier_id' => $v['id'],
'add_time' => ['between', [$start, $end]],
'store_id' => $storeid,
];
$arrearageMoney = $CreditArrearageModel->getSum($arrearage_map, 'total_money');
$repayment_map = [
'operate_type' => 1, //确保是收银员
'operate_id' => $v['id'],
'store_id' => $storeid,
'add_time' => ['between', [$start, $end]],
];
$repaymentMoney = $CreditRepaymentModel->getSum($repayment_map, 'money');
}
//快捷收银
$map = array();
$map[$PayOrderModel::CASHIER_ID] = $v['id'];
$map[$PayOrderModel::ORDER_TYPE] = 6;
$map[$PayOrderModel::ORDER_STATE] = 'SUCCESS';
$map[$PayOrderModel::TRADE_DATE] = array('between', array($start, $end));
$q_all_money = $PayOrderModel->getSum($map, $PayOrderModel::TRADE_AMOUNT); //快捷下单总金额
$q_all_money = $q_all_money ? $q_all_money : 0;
$allmoney = round($allmoney + $q_all_money, 2);
$map[$PayOrderModel::ORDER_STATE] = 'REFUND';
$q_refund_money = $PayOrderModel->getSum($map, $PayOrderModel::TRADE_AMOUNT); //快捷下单退款金额
$q_refund_money = $q_refund_money ? $q_refund_money : 0;
$refund_store = round($refund_store + $q_refund_money, 2);
//会员卡
$ww2['store_id'] = $storeid;
$ww2['type'] = 1; // 会员充值
$ww['scene_type'] = 1;
$ww2['add_time'] = array('between', array($start, $end));
$ww2['cashier_id'] = $v['id'];
$ww2['status'] = 1;
$vipcard = M('recharge_order')->where($ww2)->sum('money');
$vipcard = $vipcard ? round($vipcard, 2) : 0;
$payList = A('PayApi/SellData')->getPayData_v1($start, $end, $storeid, $v['id']); //支付方式总额统计数据
$info = array(
'xj' => $payList['cash_amount'],
'wx' => $payList['weChat_amount'],
'zfb' => $payList['ali_amount'],
'xcx' => 0,
'refund' => $refund_store,
'vipcard' => $payList['vip_amount'],
'vipaddmoney' => $vipcard,
'allmoney' => $allmoney,
'other_pay' => $payList['other_amount'],
'count' => $count,
'arrearageMoney' => $arrearageMoney ? $arrearageMoney : 0,
'repaymentMoney' => $repaymentMoney ? $repaymentMoney : 0,
);
$list[$k]['sellinfo'] = $info;
}
$parameter = array(
'store_id' => $storeid,
'start_time' => $start,
'end_time' => $end
);
$shoppingMall = new ShoppingMall();
$shoppingMallInfo = $shoppingMall->getShopAmountTotal($parameter);
$count = $shoppingMallInfo['place_count'];
$allmoney = $shoppingMallInfo['xcx_amount_total'];
$wxpay = $shoppingMallInfo['xcx_wx_actual_received'];
$membermoney = $shoppingMallInfo['xcx_member_actual_received'];
$refund_shop = $shoppingMallInfo['xcx_amount_refund_total'];
$ww['store_id'] = $storeid;
$ww['type'] = 1; // 会员充值
$ww['scene_type'] = 4;
$ww['add_time'] = array('between', array($start, $end));
$ww['status'] = 1;
$vipcard = M('recharge_order')->where($ww)->sum('money');
$vipcard = $vipcard ? round($vipcard, 2) : 0;
$sellinfo = array(
'sellinfo' => array(
'xj' => 0,
'wx' => 0,
'zfb' => 0,
'xcx' => $wxpay,
'refund' => $refund_shop,
'vipcard' => $membermoney,
'vipaddmoney' => $vipcard,
'allmoney' => $allmoney,
'other_pay' => 0,
'count' => $count
),
'id' => 0,
'name' => '商城订单收银统计'
);
array_unshift($list, $sellinfo);
$rt['status'] = 1;
$rt['msg'] = '查询成功';
$rt['list'] = $list;
$rt['starttime'] = date('Y-m-d', $start);
$rt['endtime'] = date('Y-m-d', $end);
} else {
$rt['status'] = 1;
$rt['msg'] = '查询成功';
$rt['list'] = $list;
$rt['starttime'] = date('Y-m-d', time());
$rt['endtime'] = date('Y-m-d', time());
}
} else {
$rt['status'] = 0;
$rt['msg'] = '暂无收银员';
$rt['starttime'] = date('Y-m-d', time());
$rt['endtime'] = date('Y-m-d', time());
}
$this->ajaxReturn($rt);
}
}
/**
* 2020-10-29 商城收款统计
*/
public function shoppingStoreList()
{
if (IS_POST) {
$storeid = I('post.storeid') ? I('post.storeid') : I('post.store_id'); //小程序小助手store_id 安卓小助手storeid
if (!$storeid) {
$rt['status'] = 0;
$rt['msg'] = '参数错误';
$this->ajaxReturn($rt);
exit();
}
$needsellinfo = I('post.needsellinfo');
if ($needsellinfo) {
$endtime = I('post.endtime');
$starttime = I('post.starttime');
$start = strtotime($starttime . ' 00:00:00');
$end = strtotime($endtime . ' 23:59:59');
if (!$endtime && !$starttime) {
$start = strtotime(date('Y-m-d 00:00:00', time()));
$end = $start + 86399;
}
$parameter = array(
'store_id' => $storeid,
'start_time' => $start,
'end_time' => $end
);
$shoppingMall = new ShoppingMall();
$shoppingMallInfo = $shoppingMall->getShopAmountTotal($parameter);
$count = $shoppingMallInfo['place_count'];
$allmoney = $shoppingMallInfo['xcx_amount_actual_received_total'];
$wxpay = $shoppingMallInfo['xcx_wx_actual_received'];
$membermoney = $shoppingMallInfo['xcx_member_actual_received'];
$refund_shop = $shoppingMallInfo['xcx_amount_refund_total'];
$ww['store_id'] = $storeid;
$ww['type'] = 1; // 会员充值
$ww['scene_type'] = 4;
$ww['add_time'] = array('between', array($start, $end));
$ww['status'] = 1;
$vipcard = M('recharge_order')->where($ww)->sum('money');
$vipcard = $vipcard ? round($vipcard, 2) : 0;
$list[] = array(
'sellinfo' => array(
'xj' => 0,
'wx' => 0,
'zfb' => 0,
'xcx' => $wxpay,
'refund' => $refund_shop,
'vipcard' => $membermoney,
'vipaddmoney' => $vipcard,
'allmoney' => $allmoney,
'other_pay' => 0,
'count' => $count
),
'id' => 0,
'name' => '商城订单收银统计'
);
$rt['status'] = 1;
$rt['msg'] = '查询成功';
$rt['list'] = $list;
$rt['starttime'] = date('Y-m-d', $start);
$rt['endtime'] = date('Y-m-d', $end);
} else {
$rt['status'] = 0;
$rt['msg'] = '查询失败';
$rt['starttime'] = date('Y-m-d', time());
$rt['endtime'] = date('Y-m-d', time());
}
$this->ajaxReturn($rt);
}
}
/**
* 2020-10-29 收银员收款统计
*/
public function newCashierCollecting()
{
if (IS_POST) {
$storeid = I('post.storeid') ? I('post.storeid') : I('post.store_id'); //小程序小助手store_id 安卓小助手storeid
$cashier_id = I('post.operator_id');
$user_type = I('post.user_type');
if (!$storeid) {
$this->ajaxReturn(['status' => 0, 'msg' => '参数错误']);
}
$PayOrderModel = new RetailPayOrderModel(); //支付流水模型
$RetailCashierModel = new RetailCashierModel();
$needsellinfo = I('post.needsellinfo');
if ($user_type == 3) {
$cashier_show_other_sell = $RetailCashierModel->getFindField(['id' => $cashier_id], 'cashier_show_other_sell');
}
$where_cashier = [
'status' => 1,
'storeid' => $storeid,
];
if ($cashier_show_other_sell == 2) {
$where_cashier['id'] = $cashier_id;
}
$list = $RetailCashierModel->getSelect($where_cashier, 'id,name');
if ($list || $needsellinfo) {
if ($needsellinfo) {
$list = $list ? $list : [];
$endtime = I('post.endtime');
$starttime = I('post.starttime');
$start = strtotime($starttime . ' 00:00:00');
$end = strtotime($endtime . ' 23:59:59');
if (!$endtime && !$starttime) {
$start = strtotime(date('Y-m-d 00:00:00'));
$end = $start + 86399;
}
$PlugApi = new Plug();
//获取付费插件列表及状态
$plug_result = $PlugApi->PlugPermissions(array(
'merchant_id' => I('post.merchantid'),
'identification_arr' => ['credit']
));
//商户是否存在赊账插件
$isCredit = $plug_result['data']['plug']['credit'] && $plug_result['data']['plug']['credit'] > 0 ? true : false;
if ($isCredit) {
$CreditArrearageModel = new \Credit\Model\CreditArrearageModel(); // 赊账
$CreditRepaymentModel = new \Credit\Model\CreditRepaymentModel(); // 还款
}
$RetailBillOrderModel = new RetailBillOrderModel();
$RechargeOrderModel = new RechargeOrderModel();
$SellDataController = new \PayApi\Controller\SellDataController();
foreach ($list as &$v) {
$where = [];
$where['cashier_id'] = $v['id'];
$where['add_time'] = ['between', [$start, $end]];
$where['pay_state'] = 1;
$where['store_id'] = $storeid;
$where['order_type'] = 1;
$where['type'] = 2;
$where['pay_type'] = ['neq', '0'];
$count = $RetailBillOrderModel->getCount($where);
$allmoney = $RetailBillOrderModel->getSum($where, 'all_money'); //今日总金额
$allmoney = $allmoney ? $allmoney : 0;
$where['order_type'] = 2;
$refund_store = $RetailBillOrderModel->getSum($where, 'refund_money'); //统计今日门店退款金额
$refund_store = $refund_store ? $refund_store : 0;
//赊账数据统计
if ($isCredit) {
$arrearage_map = [
'cashier_id' => $v['id'],
'add_time' => ['between', [$start, $end]],
'store_id' => $storeid,
];
$arrearageMoney = $CreditArrearageModel->getSum($arrearage_map, 'total_money');
$repayment_map = [
'operate_type' => 1, //确保是收银员
'operate_id' => $v['id'],
'store_id' => $storeid,
'add_time' => ['between', [$start, $end]],
];
$repaymentMoney = $CreditRepaymentModel->getSum($repayment_map, 'money');
}
//快捷收银
$map = [];
$map['cashier_id'] = $v['id'];
$map['order_type'] = 6;
$map['order_state'] = 'SUCCESS';
$map['trade_date'] = ['between', [$start, $end]];
$q_all_money = $PayOrderModel->getSum($map, 'trade_amount'); //快捷下单总金额
$q_all_money = $q_all_money ? $q_all_money : 0;
$allmoney = round($allmoney + $q_all_money, 2);
$map['order_state'] = 'REFUND';
$q_refund_money = $PayOrderModel->getSum($map, 'trade_amount'); //快捷下单退款金额
$q_refund_money = $q_refund_money ? $q_refund_money : 0;
$refund_store = round($refund_store + $q_refund_money, 2);
//会员卡
$ww2['store_id'] = $storeid;
$ww2['type'] = 1; // 会员充值
$ww2['add_time'] = ['between', [$start, $end]];
$ww2['cashier_id'] = $v['id'];
$ww2['status'] = 1;
$vipcard = $RechargeOrderModel->getSum($ww2, 'money');
$vipcard = $vipcard ? round($vipcard, 2) : 0;
$payList = $SellDataController->getPayData_v1($start, $end, $storeid, $v['id']); //支付方式总额统计数据
$info = [
'xj' => $payList['cash_amount'],
'wx' => $payList['weChat_amount'],
'zfb' => $payList['ali_amount'],
'xcx' => 0,
'refund' => $refund_store,
'vipcard' => $payList['vip_amount'],
'vipaddmoney' => $vipcard,
'allmoney' => $allmoney,
'other_pay' => $payList['other_amount'],
'count' => $count,
'arrearageMoney' => $arrearageMoney ? $arrearageMoney : 0,
'repaymentMoney' => $repaymentMoney ? $repaymentMoney : 0,
];
$v['sellinfo'] = $info;
}
$result = [
'status' => 1,
'msg' => '查询成功',
'list' => $list,
'starttime' => date('Y-m-d', $start),
'endtime' => date('Y-m-d', $end),
];
} else {
$result = [
'status' => 1,
'msg' => '查询成功',
'list' => $list,
'starttime' => date('Y-m-d'),
'endtime' => date('Y-m-d'),
];
}
} else {
$result = [
'status' => 0,
'msg' => '暂无收银员',
'starttime' => date('Y-m-d'),
'endtime' => date('Y-m-d'),
];
}
$this->ajaxReturn($result);
}
}
public function refund()
{
$res = array(
'status' => 1,
'msg' => '开发中,请到收银端或后台操作'
);
$this->ajaxReturn($res);
/* $res = A('CashierApi/Refund')->onlineOrderRefund_v1();
return $res;*/
}
public function verifyCode()
{
A('Sellapi/Checkpassword')->refundcode();
exit;
}
public function getLogo()
{
if (IS_POST) {
$logoinfo = M('retail_logo')->find();
if (!empty($logoinfo) && !empty($logoinfo['aide_logo'])) {
if (!empty($logoinfo['aide_logo_id'])) {
$img = D('ImageGallery')->getFieldPath(array('id' => $logoinfo['aide_logo_id']));
if (!$img) {
$res['status'] = 0;
$res['msg'] = '未设置';
} else {
$res['img'] = $img;
$res['status'] = 1;
$res['msg'] = '查询成功';
}
} else {
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$res['img'] = $http_type . $_SERVER['HTTP_HOST'] . $logoinfo['aide_logo'];
$res['status'] = 1;
$res['msg'] = '查询成功';
}
} else {
$res['status'] = 0;
$res['msg'] = '未设置';
}
$this->ajaxReturn($res);
}
}
public function newPlaceOrderPay_v3()
{
$res = A("CashierApi/Pay")->placeOrderPay_v1();
return $res;
}
public function vipLogin_v1()
{
if (IS_POST) {
$code = I('post.vipCode'); //会员卡号;
$merchantid = I('post.merchantid'); //商户id;
$storeid = I("post.storeid"); //门店id 查询门店优惠券
if (empty($code) || empty($merchantid) || empty($storeid)) {
$res['status'] = 0;
$res['msg'] = '缺少参数';
$this->ajaxReturn($res);
}
$temp = (int)substr($code, 0, 2);
if (is_numeric($code) && strlen($code) == 18 && $temp >= 86 && $temp <= 89) {
$map = array(
'code' => $code,
'status' => 0,
'state' => 0,
'merchantid' => $merchantid
);
$old = M('vip_dynamic_code')->where($map)->find();
if (empty($old) || $old['failure_time'] <= time()) {
$res['status'] = 0;
$res['msg'] = '请会员刷新动态码';
$this->ajaxReturn($res);
} else {
M('vip_dynamic_code')->where($map)->save(array('status' => 1, 'use_storeid' => $storeid));
}
$vip = M('retail_vip')->where(array('id' => $old['vid'], 'status' => array('neq', 2)))
->field('id,nickname,name,balance,mobile_phone as cardnum,card_key,integral,grade_integral,status')
->find();
$vip['login_type'] = 1;
$vip['payCode'] = $code;
} else {
if (is_numeric($code) && strlen($code) == 11) {
$map['mobile_phone'] = $code;
} else if (is_numeric($code) && strlen($code) == 4) {
$map['mobile_phone'] = array('like', '%' . $code);
} else if (is_numeric($code)) {
$map['card_key|cardnum'] = $code;
} else {
$map['card_key'] = $code;
}
$map['merchantid'] = $merchantid;
$map['status'] = array('neq', 2);
$vip = M('retail_vip')
->where($map)
->field('id,nickname,name,balance,mobile_phone as cardnum,card_key,integral,grade_integral,status')
->find();
if (empty($vip)) {
$res['status'] = 0;
$res['msg'] = '未查询到会员';
$this->ajaxReturn($res);
}
$vip['payCode'] = $vip['cardnum'] ? $vip['cardnum'] : $vip['card_key'];
$vip['login_type'] = 2;
}
//用来判断会员等级
$grade = M('retail_vip_integral')
->where(array('min_integral' => array('ELT', $vip['grade_integral']), 'merchantid' => $merchantid))
->order('min_integral desc')
->find();
if (empty($grade)) {
$vip['grade'] = 'vip';
$vip['cardname'] = '普通会员';
$vip['discount'] = 1;
} else {
$vip['grade'] = $grade['grade'];
$vip['cardname'] = $grade['cardname'];
$vip['discount'] = $grade['discount'];
}
if (empty($vip['nickname'])) {
$vip['nickname'] = $vip['name'];
}
if (empty($vip['name'])) {
$vip['name'] = $vip['nickname'];
}
if ($vip['status'] == 1) {
$c_map['v.isuse'] = 1; //未使用优惠券
$c_map['v.vid'] = $vip['id']; //会员id
$c_map['v.starttime'] = array("LT", time()); //优惠券使用期在今天范围内
$c_map['v.endtime'] = array("GT", time()); //优惠券使用期在今天范围内
$Coupons = M("retail_vipmcoupon as v")
->join('ls_retail_mcoupon as m on m.id=v.mcouponid')
->field("m.coupon_name,v.id,v.vid,v.starttime,v.endtime,v.needmoney,v.reducemoney,v.canusestoreids,v.merchantid")
->where($c_map)
->select();
$tempCoupon = array();
if (!empty($Coupons)) {
foreach ($Coupons as &$value) {
$value['starttime'] = date("Y/m/d", $value['starttime']);
$value['endtime'] = date("Y/m/d", $value['endtime']);
if ($value['canusestoreids'] != 0) {
$canUseStore = explode(",", trim($value['canusestoreids'], ','));
if (in_array($storeid, $canUseStore)) {
$tempCoupon[] = $value;
}
} else {
$tempCoupon[] = $value;
}
}
}
$vip['coupons'] = $tempCoupon;
$res['status'] = 1;
$res['msg'] = '查询成功';
$res['info'] = $vip;
} else if ($vip['status'] == 3) {
$res['status'] = 0;
$res['msg'] = '会员卡已被冻结';
} else if ($vip['status'] == 4) {
$res['status'] = 0;
$res['msg'] = '会员卡已挂失';
} else if ($vip['status'] == 2) {
$res['status'] = 0;
$res['msg'] = '会员卡已删除';
}
$this->ajaxReturn($res);
}
}
public function vipLogin_v2()
{
$res = A("CashierApi/GetVipInfo")->vipLogin();
return $res;
}
public function newPlaceOrderPay_v4()
{
$res = A("CashierApi/Pay")->orderPay_v1();
return $res;
}
/*
* 2019-9-30收银支付接口
*/
public function orderPay_v2()
{
$res = A("CashierApi/Pay")->OrderPay_v3();
return $res;
}
/**
* 获取导购
* @param int $store_id 门店id
* @param int $merchant_id 商户id
* @return array $res
*/
public function getGuideList()
{
// 接收参数
$store_id = I('post.store_id');
$merchant_id = I('post.merchant_id');
// 判断门店id
if (!$store_id) {
$res = array('status' => 0, 'msg' => '缺少必要的store_id');
$this->ajaxReturn($res);
}
// 判断商户id
if (!$merchant_id) {
$res = array('status' => 0, 'msg' => '缺少必要的merchant_id');
$this->ajaxReturn($res);
}
// 实例化模型
$GuideModel = D('RetailGuide');
$map = array(
$GuideModel::MERCHANT_ID => $merchant_id,
$GuideModel::STORE_ID => $store_id,
$GuideModel::STATUS => 1,
);
$field = array($GuideModel::ID, $GuideModel::NAME);
$guide_list = $GuideModel->getSelect($map, $field);
if ($guide_list) {
$res = array('status' => 1, 'guide_list' => $guide_list);
} else {
$res = array('status' => 0, 'msg' => '暂无导购');
}
$this->ajaxReturn($res);
}
/**
* @param int|string $user_type 操作人员类型 1.商户 2.店长 3.收银员
* @param int $use_id 操作人员id
* @param int $store_id 门店id
* @param int $merchant_id 商户id
* @param int $vip_info 表单提交
* @return array $res
*/
public function addVipInfo()
{
// 接收参数
$user_type = I('post.user_type');
$use_id = I('post.use_id');
$store_id = I('post.store_id');
$merchant_id = I('post.merchant_id');
$platform_type = I('post.platform_type');
$vip_info = json_decode($_POST['vip_info'], true);
// 判断操作人员
if (!$use_id) {
$res = array('status' => 0, 'msg' => '缺少必要的操作人员参数');
$this->ajaxReturn($res);
}
// 判断门店id
if (!$store_id) {
$res = array('status' => 0, 'msg' => '缺少必要的store_id');
$this->ajaxReturn($res);
}
// 判断商户id
if (!$merchant_id) {
$res = array('status' => 0, 'msg' => '缺少必要的merchant_id');
$this->ajaxReturn($res);
}
// 判断人员类型
switch ($user_type) {
case 1:
// 查询商户
$RMerchantModel = D('RetailMerchant');
$result = $RMerchantModel->getFindNormalMerchant($use_id);
if ($result['status'] == 0) {
$this->ajaxReturn($result);
}
break;
case 2:
// 查询店长
$RManagerModel = D('RetailManager');
$manager = $RManagerModel->getFind(array($RManagerModel::MERCHANT_ID => $merchant_id, $RManagerModel::STORE_ID => $store_id, $RManagerModel::STATUS => 1, $RManagerModel::ID => $use_id));
if (empty($manager)) {
$res = array('status' => 0, 'msg' => '未知的店长人员');
$this->ajaxReturn($res);
}
break;
case 3:
// 查询收银员
$CashierModel = D('RetailCashier');
$cashier = $CashierModel->getFind(array($CashierModel::ID => $use_id, $CashierModel::STORE_ID => $store_id, $CashierModel::MERCHANT_ID => $merchant_id));
if (empty($cashier)) {
$res = array('status' => 0, 'msg' => '未知的收银人员');
$this->ajaxReturn($res);
}
break;
default:
$res = array('status' => 0, 'msg' => '未知的操作人员');
$this->ajaxReturn($res);
break;
}
// 判断表单提交
if (!$vip_info['card_key']) { // 未绑定实体卡
if (!$vip_info['name'] || !$vip_info['mobile_phone'] || strlen($vip_info['mobile_phone']) != 11) {
$res = array('status' => 0, 'msg' => '请检查表单提交信息是否正确');
$this->ajaxReturn($res);
}
if (!$vip_info['password']) {
$password = substr($vip_info['mobile_phone'], -6);
} else {
if (strlen($vip_info['password']) != 6) {
$res = array('status' => 0, 'msg' => '密码格式错误');
$this->ajaxReturn($res);
}
$password = $vip_info['password'];
}
} else { // 绑定实体卡
if (!$vip_info['password'] || strlen($vip_info['password']) != 6) {
$res = array('status' => 0, 'msg' => '密码格式错误');
$this->ajaxReturn($res);
}
$password = $vip_info['password'];
}
// 添加会员
$VipModel = D('RetailVip');
$time = time();
$cr[$VipModel::NAME] = $vip_info[$VipModel::NAME];
// 手机号
if ($vip_info[$VipModel::MOBILE_PHONE]) {
// 验证手机号
$test_phone = "/^1[3456789]\d{9}$/";
if (!preg_match($test_phone, $vip_info[$VipModel::MOBILE_PHONE])) {
$res = array('status' => 0, 'msg' => '手机号格式有误');
$this->ajaxReturn($res);
}
// 判断手机号是否被使用
$vMap = array(
$VipModel::MOBILE_PHONE => $vip_info[$VipModel::MOBILE_PHONE],
$VipModel::STATUS => array('neq', 2),
$VipModel::MERCHANT_ID => $merchant_id,
);
$used_phone = $VipModel->getSelect($vMap);
if ($used_phone) {
$res = array('status' => 0, 'msg' => '该手机号已被注册');
$this->ajaxReturn($res);
}
$cr[$VipModel::MOBILE_PHONE] = $vip_info[$VipModel::MOBILE_PHONE];
}
// 密码
$cryptoModel = new \Addons\Api\Crypto();
$cr[$VipModel::PASSWORD] = $cryptoModel->encrypt($password, date('YmdHis', $time));
// 生日
if ($vip_info['birthday']) {
$cr[$VipModel::BIRTHDAY] = $vip_info['birthday'];
}
// 实体卡
if ($vip_info['card_key']) {
// 判断实体卡是否被使用
$vMap = array(
$VipModel::CARD_KEY => $vip_info['card_key'],
$VipModel::STATUS => array('neq', 2),
$VipModel::MERCHANT_ID => $merchant_id,
);
$used_card_key = $VipModel->getSelect($vMap);
if ($used_card_key) {
$res = array('status' => 0, 'msg' => '该实体卡已被绑定');
$this->ajaxReturn($res);
}
$cr[$VipModel::CARD_KEY] = $vip_info['card_key'];
}
// 导购员
if ($vip_info['guide_id']) {
// 判断导购是否存在
$GuideModel = D('RetailGuide');
$gMap = array(
$GuideModel::ID => $vip_info['guide_id'],
$GuideModel::MERCHANT_ID => $merchant_id,
$GuideModel::STORE_ID => $store_id,
$GuideModel::STATUS => 1,
);
$guide_info = $GuideModel->getFind($gMap);
if (!$guide_info) {
$res = array('status' => 0, 'msg' => '未查询到导购信息');
$this->ajaxReturn($res);
}
$cr[$VipModel::GUIDE_ID] = $vip_info['guide_id'];
}
// 二次判断
if (!$cr) {
$res = array('status' => 0, 'msg' => '请填写表单提交信息');
$this->ajaxReturn($res);
}
$cr[$VipModel::MERCHANT_ID] = $merchant_id;
$cr[$VipModel::STORE_ID] = $store_id;
$cr[$VipModel::ADD_TIME] = $time;
if ($platform_type == 2) {
//第三方平台
if (empty($cr[$VipModel::MOBILE_PHONE])) {
$res = array('status' => 0, 'msg' => '请输入手机号');
$this->ajaxReturn($res);
}
$ThirdVipClass = new Vip();
$ThirdGoodsClass = new \LittleGift\Business\Goods();
$storeResult = $ThirdGoodsClass->storeCode($store_id);
if (empty($storeResult['data'])) {
$res = array('status' => 0, 'msg' => '第三方平台门店编码有误');
$this->ajaxReturn($res);
}
$thirdData = [
'merchant_id' => $merchant_id,
'vip_info' => [
'Code' => $cr[$VipModel::MOBILE_PHONE],
'Source' => '收银端添加',
'Customer_Code' => $storeResult['data'],
'Name' => $cr[$VipModel::NAME]
]
];
if (!empty($vip_info['birthday'])) {
$thirdData['vip_info']['DateOfBirth'] = "/Date(" . (newStrToTime($vip_info['birthday']) * 1000) . "+0800)/";
}
$thirdData['vip_info'] = json_encode($thirdData['vip_info']);
$thirdResult = $ThirdVipClass->vipInsert($thirdData);
if ($thirdResult['status'] == 0) {
$res = array('status' => 0, 'msg' => '第三方平台添加失败' . $thirdResult['message']);
$this->ajaxReturn($res);
}
if (!empty($thirdResult['data']) && !empty($thirdResult['data']['Code'])) {
//Q3已存在更新Q3的会员信息
$third_vip = $thirdResult['data'];
if (!empty($third_vip['Source'])) {
$cr['source_channel'] = $third_vip['Source'];
}
if (!empty($third_vip['Name'])) {
$cr['name'] = $third_vip['Name'];
}
if (!empty($third_vip['DateOfBirth'])) {
$cr['birthday'] = date('Y-m-d', substr($third_vip['DateOfBirth'], 6, 10));
}
if ($storeResult['data'] != $third_vip['Customer_Code']) {
$StoreModel = new RetailStoreModel();
$new_store_id = $StoreModel->getFindField([
'third_code' => $third_vip['Customer_Code'],
'merchantid' => $merchant_id,
'state' => 0
], 'id');
if (!empty($new_store_id)) {
$cr['storeid'] = $new_store_id;
}
}
}
}
$add_result = $VipModel->addOrder($cr);
if (!$add_result) {
$res = array('status' => 0, 'msg' => '添加失败');
$this->ajaxReturn($res);
}
// 新会员注册福利
A('PayApi/Vip')->newVipWelfare($add_result, $merchant_id, 1, $vip_info['vip_type']);
$res = array('status' => 1, 'msg' => '添加成功');
$this->ajaxReturn($res);
}
/*
* *************************************会员编辑资料*****************************
*/
/*
* 编辑提交
* @param $user_type 1商户 2门店 3收银员
* @param $operator_id 操作员id
* @param $vid 会员id
* @param $vip_type 3常规会员 2plus会员
* @param $grade_id 等级id
*@param $modify_vip_code 收银员权限码
*/
public function VipEdit()
{
$PlusVipModel = D("RetailPlusVip");
$VipModel = D("RetailVip");
$StoreAuthModel = D('RetailStoreAuth');
$retailCashierModel = D('RetailCashier');
$content = I("post.");
$merchant_id = $content['merchantid'];
$store_id = $content["storeid"];
$user_type = $content["user_type"];
$operator_id = $content['operator_identity_id'];
$modify_vip_code = $content["modify_vip_code"];
$vip_type = $content["vip_type"];
$vid = $content['vid'];
$grade_id = $content["grade_id"];
$phoneNew = $content["mobile_phone"];
$balance = $content["balance"];
$name = $content["name"];
$time = time();
if (!$vip_type) {
$res = array(
"status" => 0,
"msg" => "请选择会员类型"
);
$this->ajaxReturn($res);
}
if (!is_numeric($balance) || $balance < 0) {
$res = array(
"status" => 0,
"msg" => "余额不能小于0"
);
$this->ajaxReturn($res);
}
if ($vip_type == 3) {
if (!isset($grade_id)) {
$res = array(
"status" => 0,
"msg" => "请选择会员等级"
);
$this->ajaxReturn($res);
}
}
switch ($user_type) {
case 1:
if (!$merchant_id || !$vid) {
$res = array(
'status' => 0,
'msg' => "参数缺失"
);
$this->ajaxReturn($res);
}
break;
case 2:
if (!$merchant_id || !$store_id || !$vid) {
$res = array(
'status' => 0,
'msg' => "参数缺失"
);
$this->ajaxReturn($res);
}
// 判断门店权限
$edit_vip = $StoreAuthModel->getFindField(array($StoreAuthModel::STORE_ID => $store_id), $StoreAuthModel::EDIT_VIP);
if ($edit_vip && $edit_vip == 2) {
$res = array(
'status' => 0,
'msg' => '门店暂无编辑权限'
);
$this->ajaxReturn($res);
}
break;
case 3:
if (!$merchant_id || !$store_id || !$vid) {
$res = array(
"status" => 0,
"msg" => "参数缺失"
);
$this->ajaxReturn($res);
}
//判断门店权限
$edit_vip = $StoreAuthModel->getFindField(array($StoreAuthModel::STORE_ID => $store_id), $StoreAuthModel::EDIT_VIP);
if ($edit_vip && $edit_vip == 2) {
$res = array(
'status' => 0,
'msg' => '门店暂无编辑权限'
);
$this->ajaxReturn($res);
}
if (!$modify_vip_code) {
$res = array(
'status' => 0,
'msg' => '请输入权限码'
);
$this->ajaxReturn($res);
}
$map = array(
$retailCashierModel::ID => $operator_id,
$retailCashierModel::STATUS => 1
);
$cashier = $retailCashierModel->getFind($map);
if (!$cashier) {
$res = array(
"status" => 0,
"msg" => "未找到该收银员,请重新登录"
);
$this->ajaxReturn($res);
}
// 判断收银员
if (!$cashier[$retailCashierModel::MODIFY_VIP_STATE] || $cashier[$retailCashierModel::MODIFY_VIP_STATE] == 1) {
$res = array(
"status" => 0,
"msg" => "暂无权限编辑会员资料"
);
$this->ajaxReturn($res);
}
if ($modify_vip_code != $cashier[$retailCashierModel::MODIFY_VIP_CODE]) {
$res = array(
'status' => 0,
'msg' => '权限码错误'
);
$this->ajaxReturn($res);
}
break;
}
$map['id'] = $vid;
$map['merchantid'] = $merchant_id;
$map['status'] = array('neq', 2);
$vip = D("RetailVip")->getFind($map);
if (empty($vip)) {
$res = array(
"status" => 0,
"msg" => "未找到该会员"
);
$this->ajaxReturn($res);
}
if ($user_type == 3 && ($balance > $vip["balance"])) {
$res = array(
"status" => 0,
"msg" => "增加会员余额,请从充值入口进行充值"
);
$this->ajaxReturn($res);
}
if (!empty($name)) {
$data['name'] = $name;
}
if ($vip['mobile_phone'] != $phoneNew) {
$test_phone = "/^1[3456789]\d{9}$/";
if (!preg_match($test_phone, $phoneNew)) {
$res = array(
'status' => 0,
'msg' => '手机号格式有误'
);
$this->ajaxReturn($res);
}
//使用新的手机号
if (!empty($phoneNew)) {
$map['id'] = array('neq', $vid);
$map['mobile_phone'] = $phoneNew;
$map['status'] = array('neq', 2);
$oldVip = D("RetailVip")->getFind($map);;
if (!empty($oldVip)) {
$res = array(
"status" => 0,
"msg" => "该手机号已被占用"
);
$this->ajaxReturn($res);
}
$data['mobile_phone'] = $phoneNew;
$data['cardnum'] = $phoneNew;
} else {
if (!empty($vip['mobile_phone'])) {
$res = array(
"status" => 0,
"msg" => "不能将原有手机号删除"
);
$this->ajaxReturn($res);
}
}
}
if ($balance != $vip['balance']) {
$data['balance'] = $balance;
}
if ($vip_type == 3) { //常规会员
$gradeVip = M('retail_vip_integral')
->where(array('min_integral' => array('ELT', $vip['grade_integral']), 'merchantid' => $merchant_id))
->order('min_integral desc')
->find();
if ($gradeVip['id'] != $grade_id) {
$gradeInfo = M('retail_vip_integral')->where(array('id' => $grade_id))->find();
if (empty($gradeInfo)) {
if ($grade_id == 0) {
$data['grade_integral'] = 0;
} else {
$res = array(
"status" => 0,
"msg" => "会员等级有误"
);
$this->ajaxReturn($res);
}
} else {
$data['grade_integral'] = $gradeInfo['min_integral'];
}
}
} else if ($vip_type == 2 && $vip['plus_type'] != 2) { //plus会员
$start_time = $time;
$end_time = strtotime("+1 year");
$plus_vip_info = $PlusVipModel->getFind(array('vip_id' => $vip['id'], 'merchantid' => $merchant_id));
if ($plus_vip_info) {
$PlusVipModel->updateOrder(array('vip_id' => $vip['id'], 'merchantid' => $merchant_id), array('state' => 1, 'start_time' => $start_time, 'end_time' => $end_time));
$plus_add = $plus_vip_info['id'];
} else {
$plus_data = array(
"vip_id" => $vid,
"merchantid" => $merchant_id,
"addtime" => $time,
"start_time" => $start_time,
"end_time" => $end_time,
"state" => 1,
"storeid" => $vip['storeid']
);
$plus_add = $PlusVipModel->addOrder($plus_data);
}
if ($plus_add) {
$xcx_info = M('retail_xcxvip')->where(array('merchantid' => $merchant_id, 'vip_id' => $vip['id']))->find();
if ($xcx_info) {
M('retail_xcxvip')->where(array('id' => $xcx_info['id']))->save(array('plus_vip_id' => $plus_add, 'type' => 2));
$PlusVipModel->updateOrder(array('id' => $plus_add), array('xcx_vip_id' => $xcx_info['id']));
}
$data['plus_id'] = $plus_add;
$data['plus_type'] = 2;
$data['plus_state'] = 1;
}
}
if (!empty($data)) {
$save = $VipModel->updateOrder(array('id' => $vid), $data);
if ($save) {
if ($balance != $vip['balance']) {
if ($balance < $vip['balance']) {
$money = round($vip['balance'] - $balance, 2);
$add['type'] = 4;
$add['money'] = $money;
$str = '扣除';
} else {
$money = round($balance - $vip['balance'], 2);
$add['type'] = 3;
$add['money'] = 0;
$str = '增加';
}
switch ($user_type) {
case 1:
$add['remark'] = '小助手商户修改余额' . $str . $money . '元';
break;
case 2:
$add['remark'] = '小助手店长修改余额' . $str . $money . '元';
break;
case 3:
$add['remark'] = '小助手收银员修改余额' . $str . $money . '元';
break;
}
$add['vid'] = $vid;
$add['status'] = 1;
$add['all_money'] = $money;
$add['state'] = 1;
$add['add_time'] = $time;
$add['merchant_id'] = $merchant_id;
$add['user_type'] = $user_type;
if ($user_type == 2 || $user_type == 3) {
$add['store_id'] = $store_id;
}
$add['scene_type'] = 6;
D("RetailRechargeOrder")->add($add);
}
$record = array();
$record['operator'] = $user_type;
$record['operator_id'] = $operator_id;
$record['merchant_id'] = $merchant_id;
if ($user_type == 2 || $user_type == 3) {
$record['store_id'] = $store_id;
}
if ($vip['mobile_phone'] != $phoneNew) {
$record['before_phone'] = $vip['mobile_phone'] ? $vip['mobile_phone'] : '';
$record['after_phone'] = $phoneNew ? $phoneNew : '';
}
if ($vip_type == 3) {
if ($gradeVip['id'] != $grade_id) {
$record['before_grade'] = $gradeVip['cardname'] ? $gradeVip['cardname'] : '无等级';
$record['after_grade'] = $gradeInfo['cardname'] ? $gradeInfo['cardname'] : '无等级';
}
} else if ($vip_type == 2 && $vip['plus_type'] != 2) {
$gradeVip = M('retail_vip_integral')
->where(array('min_integral' => array('ELT', $vip['grade_integral']), 'merchantid' => $merchant_id))
->order('min_integral desc')
->find();
$record['before_grade'] = $gradeVip['cardname'] ? $gradeVip['cardname'] : '无等级';
$record['after_grade'] = "Plus会员";
}
if ($balance != $vip['balance']) {
$record['before_balance'] = $vip['balance'] ? $vip['balance'] : 0;
$record['after_balance'] = $balance ? $balance : 0;
}
$record['add_time'] = $time;
$record['vip_id'] = $vid;
$addRecord = D('RetailVipChange')->add($record);
if ($addRecord) {
$saves = 1;
} else {
$saves = 2;
}
} else {
$saves = 0;
}
} else {
$saves = 1;
}
switch ($saves) {
case 1:
$res = array(
"status" => 1,
"msg" => "操作成功"
);
break;
case 2:
$res = array(
"status" => 1,
"msg" => "操作成功,记录存入失败"
);
break;
case 3:
$res = array(
"status" => 0,
"msg" => "操作失败"
);
break;
default:
$res = array(
"status" => 0,
"msg" => "暂无修改"
);
break;
}
if (($saves == 1 || $saves == 2) && ($user_type == 1 || $user_type == 2)) {
$parameter['desc'] = '会员编辑';
switch ($user_type) {
case 1:
$parameter['type'] = 3;
break;
case 2:
$parameter['type'] = 4;
break;
}
$this->system_parameter($parameter);
}
$this->ajaxReturn($res);
}
public function VipEdit_v1()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['operator_id'] = $data['operator_identity_id'];
$data['merchant_id'] = $data['merchantid'];
$data['store_id'] = $data['storeid'];
$data['cashier_id'] = $data['operator_identity_id'];
switch ($data['user_type']) {
case 1:
$data['user_type'] = 3;
break;
case 2:
$data['user_type'] = 4;
break;
case 3:
$data['user_type'] = 6;
break;
}
$VipEditClass = new VipEdit();
$result = $VipEditClass->editInfo($data);
$this->ajaxReturn($result);
}
/*
* 会员充值
*/
public function VipRecharge()
{
A('CashierApi/Recharge')->VipRecharge();
}
/*
* 充值获取会员信息
*/
public function getRechargeActivity()
{
A('CashierApi/Vip')->getRechargeActivity();
}
/*
* *****************************************销售记录列表*********************************
*/
/*
* 收银员列表
*/
public function cashierInfo()
{
$CashierModel = D("RetailCashier");
$data = I("post.");
$map = array(
$CashierModel::STORE_ID => $data['storeid'],
$CashierModel::STATUS => 1
);
$fields = $CashierModel::ID . ',' . $CashierModel::NAME;
$cashierList = $CashierModel->getSelect($map, $fields);
$cashierList = $cashierList ? $cashierList : array();
$res = array(
'status' => 1,
'data' => $cashierList
);
$this->ajaxReturn($res);
}
//订单商品信息
public function sell_list()
{
$data = I('post.');
$SellClass = new Sell();
$result = $SellClass->sellList($data);
$this->ajaxReturn($result);
}
//销售明细的串号列表
public function sellSerialList()
{
$data = I('post.');
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->sellSerialList($data);
$this->ajaxReturn($result);
}
/*
* 商品销售记录
*/
public function getSellList()
{
$data = I("post.");
$store_id = $data['storeid'];
$merchant_id = $data['merchantid'];
$start_time = $data['start_time'];
$end_time = $data['end_time'];
$keyword = $data['keyword'];
$page = $data['page'];
$limit = $data['limit'];
if (!$store_id) {
$res = array('status' => 0, 'msg' => '登录超时,请重新登录');
$this->ajaxReturn($res);
}
/* 查看进价权限 */
$show_purch_price = M("retail_store_jurisdiction")->where(array('storeid' => $store_id))->getField("showpurch_price");
// 时间搜索
if (!empty($start_time) && !empty($end_time)) {
$start_time = strtotime($start_time . "00:00:00");
$end_time = strtotime($end_time . "23:59:59");
$map['s.add_time'] = array('between', array($start_time, $end_time));
} else if (!empty($start_time)) {
$start_time = strtotime($start_time . "00:00:00");
$map['s.add_time'] = array('gt', $start_time);
} else if (!empty($end_time)) {
$end_time = strtotime($end_time . "23:59:59");
$map['s.add_time'] = array('lt', $end_time);
}
// 货号、条码
if (!empty($keyword)) {
$map['g.goods_number|g.goods_name'] = array('like', '%' . $keyword . "%");
}
$map['s.pay_type'] = array('neq', 0);
$map['s.pay_state'] = 1;
$map['s.merchant_id'] = $merchant_id;
$map['s.store_id'] = $store_id;
$fields = 's.id,s.serial_number_state,s.goods_id,s.company,s.price,s.num,s.all_money,s.add_time,s.purchase_price,s.sell_type,g.goods_name,g.goods_number';
$sell_list = M('retail_sell as s')
->join('ls_retail_goods as g on s.goods_id=g.id', 'LEFT')
->field($fields)
->where($map)
->page($page, $limit)
->order('s.add_time desc')
->select();
if ($sell_list) {
foreach ($sell_list as $key => &$val) {
$val['index'] = $key + 1;
$val['goods_name'] = $val['goods_name'] ? $val['goods_name'] : '无码商品';
$val['goods_number'] = $val['goods_number'] ? $val['goods_number'] : '无';
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
$val['price'] = round($val['price'], 2);
$val['num'] = round($val['num'], 3);
$val['subtotal'] = floatval(round($val['price'] * $val['num'], 2)); // 小计
if ($show_purch_price == 2) {
$val['purchase_price'] = '***';
}
if ($val['sell_type'] == 1) {
$val['sell_mold'] = '售';
} else if ($val['sell_type'] == 2) {
$val['sell_mold'] = '退';
} else {
$val['sell_mold'] = '未知';
}
}
}
$sell_list = $sell_list ? $sell_list : array();
$res = array(
'status' => 1,
'sell_list' => $sell_list
);
$this->ajaxReturn($res);
}
/*
* 店内经营订单
* @param storeid 门店id
* @param add_time 时间搜索
* @param order_no 订单号
* @param cashier_id 收银员id
* @param pay_type 支付方式
* @param order_type 订单类型 1:购买订单 2:退款订单
* @param type 1商城2店内
*/
public function StoreOrderList()
{
$data = I("post.");
$store_id = $data['storeid'];
$start_time = $data['start_time'];
$end_time = $data['end_time'];
$order_no = $data['order_no'];
$admin_id = $data['cashier_id'];
$pay_type = $data['pay_type'];
$order_type = $data['order_type'];
$type = $data['type'];
$page = $data["page"];
$limit = $data["limit"];
if (!empty($start_time) && !empty($end_time)) {
$start_time = strtotime($start_time . "00:00:00");
$end_time = strtotime($end_time . "23:59:59");
$map['b.add_time'] = array('between', array($start_time, $end_time));
} else if (!empty($start_time)) {
$start_time = strtotime($start_time . "00:00:00");
$map['b.add_time'] = array('gt', $start_time);
} else if (!empty($end_time)) {
$end_time = strtotime($end_time . "23:59:59");
$map['b.add_time'] = array('lt', $end_time);
}
if (!empty($order_no)) {
$map['b.order_no'] = $order_no;
}
if (!empty($admin_id)) {
$map['b.cashier_id'] = $admin_id;
}
if (!empty($pay_type)) {
$map['b.pay_type'] = $pay_type;
}
if (!empty($order_type)) {
$map['b.order_type'] = $order_type;
}
if (!empty($type)) {
$map['b.type'] = $type;
}
$map['b.pay_state'] = 1;
$map['b.store_id'] = $store_id;
$sell_list = M('retail_bill_order as b')
->join('ls_retail_cashier as c on c.id=b.cashier_id', 'LEFT')
->join('ls_retail_vip as v on v.id=b.vid', 'LEFT')
->join('ls_retail_bill_discount as d on d.bill_id=b.id', 'LEFT')
->field('b.*,v.name as vip_name,v.nickname,v.mobile_phone as vip_mobile,v.card_key,c.name as adminname,d.coupon_money,d.vip_dis_money,d.cashier_dis_money,d.discount,d.small_changes_money')
->where($map)
->order("b.id desc")
->page($page, $limit)
->select();
if ($sell_list) {
$BillOrder = new BillOrder();
$Plug = new Plug();
$plug_result = $Plug->merPlugState([
'merchant_id' => $data['merchant_id'],
'identification_arr' => ['moraleducationcoin']
]);
$StoreModel = new RetailStoreModel();
$villageId = $StoreModel->getFindField(['id'=>$store_id],'third_code');
foreach ($sell_list as $key => &$val) {
$val['index'] = $key + 1;
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
$total_discount = round($val['coupon_money'] + $val['cashier_dis_money'] + $val['vip_dis_money'] + $val[' small_changes_money'], 2); // 总减少金额
$val['type_name'] = $val['type'] == 1 ? '商城' : '店内';
$val['all_money'] = floatval($val['all_money']) . '(元)'; // 消费金额
$val['discount'] = $val['discount'] >= 1 ? '无折扣' : floatval($val['discount']) . ' 折'; // 手动折扣
$val['coupon_money'] = $val['coupon_money'] && $val['coupon_money'] > 0 ? floatval($val['coupon_money']) . '(元)' : '无优惠'; // 优惠券金额
$val['cashier_dis_money'] = $val['cashier_dis_money'] && $val['cashier_dis_money'] > 0 ? floatval($val['cashier_dis_money']) . '(元)' : '无优惠'; // 手动折扣金额
$val['vip_dis_money'] = $val['vip_dis_money'] && $val['vip_dis_money'] > 0 ? floatval($val['vip_dis_money']) . '(元)' : '无优惠';
$val['small_changes_money'] = $val['small_changes_money'] && $val['small_changes_money'] > 0 ? floatval($val['small_changes_money']) . '(元)' : '未抹零'; // 手动折扣金额
$val['total_discount'] = $total_discount ? $total_discount . '(元)' : '无优惠';
if ($val['vid']) { // 会员信息
$val['vip_name'] = $val['vip_name'] ? $val['vip_name'] : ($val['nickname'] ? $val['nickname'] : '会员');
$val['vip_mobile'] = $val['vip_mobile'] ? $val['vip_mobile'] : '未设置';
$val['card_key'] = $val['card_keycard_key'] ? $val['card_key'] : '未绑定';
} else if ($plug_result['moraleducationcoin']) {
$val['vip_name'] = $val['third_vip_name'];
$val['villageId'] = $villageId;
$val['vip_mobile'] = '';
$val['card_key'] = '';
} else {
$val['vip_name'] = '散客';
$val['vip_mobile'] = '未设置';
$val['card_key'] = '未绑定';
}
$val['pay_name'] = $BillOrder->getPayType($val['pay_type'], $val['id']);
/* 订单类型 */
if ($val['order_type'] == 2) {
$val['status_name'] = '退款订单';
} else {
if ($val['refund_status'] == 3) {
$val['status_name'] = '有退款';
} else {
$val['status_name'] = '购买订单';
}
}
/* 导购员 */
if ($val['guideid']) {
$guide_name = M('retail_guide')->where(array('id' => $val['guideid']))->getField('guidename');
$val['guide_name'] = $guide_name ? $guide_name : '自购';
} else {
$val['guide_name'] = '自购';
}
}
}
$sell_list = $sell_list ? $sell_list : array();
$res['status'] = 1;
$res['data'] = $sell_list;
$this->ajaxReturn($res);
}
/*
* 组合支付详情
* @param id 订单id
*/
public function payTypeShow()
{
$id = I('post.id');
$PayOrder = new PayOrder();
$info = $PayOrder->getFindPayList('', '', $id);
$res['data'] = $info ? $info : array();
$this->ajaxReturn($res);
}
//收银员交班交班统计数据
public function record()
{
A('CashierApi/Record')->record();
}
public function submitWork()
{
A('CashierApi/Record')->submitWork();
}
public function printerRecordData_v1()
{
A('CashierApi/Record')->printerRecordData_v1();
}
/*
* ***********************************************盘点模块******************************
*/
//盘点信息列表
public function InventoryList()
{
$data = I("post.");
$user_type = $data["user_type"]; // 1商户 2店长 3收银员
$merchant_id = $data['merchantid'];
$store_id = $data['storeid'];
$page = $data['page'];
$limit = $data['limit'];
$order_number = $data['order_number'];
$start_time = $data['start_time'];
$end_time = $data['end_time'];
if (!empty($order_number)) {
$where['order_number'] = array('like', $order_number . '%');
}
if (!empty($start_time) && !empty($end_time)) {
$start_time = strtotime($start_time . "00:00:00");
$end_time = strtotime($end_time . "23:59:59");
$where['add_time'] = array('between', array($start_time, $end_time));
} else if (!empty($start_time)) {
$start_time = strtotime($start_time . "00:00:00");
$where['add_time'] = array('gt', $start_time);
} else if (!empty($end_time)) {
$end_time = strtotime($end_time . "23:59:59");
$where['add_time'] = array('lt', $end_time);
}
$where['merchant_id'] = $merchant_id;
$where['status'] = array('in', '1,2');
switch ($user_type) {
case 1:
$info = D('InventoryOrder')->getSelect($where, $page, $limit, $field = "*", $order = "id desc");
if ($info) {
foreach ($info as $key => &$val) {
$val['index'] = $key + 1;
$val['operator'] = A('Api/Inventory')->OperatorName($val['operator_id']);
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
$val['amount'] = round($val['amount'], 2);
$val['quantity'] = round($val['quantity'], 3);
switch ($val['status']) {
case 1:
$val['status_name'] = '完成';
break;
case 2:
$val['status_name'] = '进行中';
break;
default:
$val['status_name'] = '失败';
break;
}
}
}
break;
case 2:
case 3:
//门店与收银员盘点列表
$where['store_id'] = $store_id;
$info = D('SInventoryOrder')->getSelect($where, $page, $limit, $field = "*", $order = "id desc");
if ($info) {
$showpurch_price = M("retail_store_jurisdiction")->where(array('storeid' => $store_id))->getField("showpurch_price");
foreach ($info as $key => &$val) {
$val['index'] = $key + 1;
if ($val['operator_type'] == 1) { //收银员
$val['operator'] = D('Cashier')->getFindField(array('id' => $val['operator_id']), "name");
} else {
$val['operator'] = A('Api/Inventory')->OperatorName($val['operator_id']);
}
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
$val['quantity'] = round($val['quantity'], 3);
if ($showpurch_price == 2) {
$val['amount'] = '***';
} else {
$val['amount'] = strval(round($val['amount'], 2));
}
switch ($val['status']) {
case 1:
$val['status_name'] = '完成';
break;
case 2:
$val['status_name'] = '进行中';
break;
default:
$val['status_name'] = '失败';
break;
}
}
}
break;
}
$res['status'] = 1;
$res['data'] = $info ? $info : array();
$res['msg'] = '查询成功';
$this->ajaxReturn($res);
}
//盘点详情的串号列表
public function inventorySerial()
{
$data = I('post.');
$data['serial_type'] = 4;
switch ($data['user_type']) {
case 1:
$data['user_type'] = 3;
break;
case 2:
case 3:
$data['user_type'] = 4;
break;
}
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
//盘点单详情
public function InventoryInfo()
{
$data = I("post.");
$user_type = $data["user_type"]; //1商户 2门店 3收银员
$id = $data["id"];
$where['inventory_order_id'] = $id;
switch ($user_type) {
case 1:
$detailsList = D('InventoryGoods')->getSelect($where, $page = '', $limit = '');
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
$val['inventory_num'] = round($val['inventory_num'], 3);
$val['cost_price'] = round($val['cost_price'], 2);
$val['subtotal'] = round($val['subtotal'], 2);
$val['sku_num'] = round($val['sku_num'], 3);
$val['goods_num'] = round($val['goods_num'], 3);
$val['num'] = round($val['num'], 3);
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
}
}
break;
case 2:
case 3:
$purchase_model = new SPurchaseOrderModel();
$supplier_type = D('RetailStore')->getFindField(array('id' => $data['storeid']), "supplier_type");
$detailsList = D('SInventoryGoods')->getSelect($where, $page = '', $limit = '');
if ($detailsList) {
$showpurch_price = M("retail_store_jurisdiction")->where(array('storeid' => $data['storeid']))->getField("showpurch_price");
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
$val['inventory_num'] = round($val['inventory_num'], 3);
$val['sku_num'] = round($val['sku_num'], 3);
$val['goods_num'] = round($val['goods_num'], 3);
$val['num'] = round($val['num'], 3);
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
if ($showpurch_price == 2) {
$val['cost_price'] = '***';
$val['subtotal'] = '***';
} else {
$val['cost_price'] = strval(round($val['cost_price'], 2));
$val['subtotal'] = strval(round($val['subtotal'], 2));
}
if ($supplier_type == 2 && !empty($val['purchase_order_id'])) {
$val['purchase_order_number'] = $purchase_model->getFindField(array('id' => $val['purchase_order_id']), "order_number");
}
}
}
break;
}
$res['data'] = $detailsList ? $detailsList : array();
$res['status'] = 1;
$this->ajaxReturn($res);
}
//盘点的商品信息接口
public function GoodsListShow()
{
$content = I("post.");
$user_type = $content['user_type'] ? $content['user_type'] : 2; //1商户 2门店 3收银员
$merchant_id = $content['merchantid'];
$store_id = $content['storeid'];
$page = $content['page'];
$limit = $content['limit'];
$searchText = $content['searchText'];
$notInIds = $content['notInIds'];
$person1 = $content['person1'];
$person2 = $content['person2'];
$person3 = $content['person3'];
$supplier_type = D("RetailStore")->getFindField(array('id' => $store_id), "supplier_type");
if (!empty($searchText)) {
$where['goods_name|sku_name|goods_code|sku_code|goods_number|sku_goods_number'] = array('like', '%' . $searchText . '%');
}
$flag = 0;
if (!empty($person3)) {
$where['goods_class_id'] = $person3;
} else if (!empty($person2)) {
$class = M('retail_goods_class as c2')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid')
->where(array('c2.id' => $person2, 'c3.status' => 0))
->field('c3.id')->select();
$flag = 1;
} else if (!empty($person1)) {
$class = M('retail_goods_class as c1')
->join('ls_retail_goods_class as c2 on c1.id=c2.pid')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid AND c3.status=0', 'LEFT')
->where(array('c1.id' => $person1, 'c2.status' => 0))
->field('c2.id,c3.id as c3_id')->select();
$flag = 1;
}
if (!empty($class)) {
$arr = array();
foreach ($class as &$val) {
if (!in_array($val['id'], $arr)) {
$arr[] = $val['id'];
}
if (!empty($val['c3_id'])) {
if (!in_array($val['c3_id'], $arr)) {
$arr[] = $val['c3_id'];
}
}
}
$str = implode(',', $arr);
$where['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
} else if ($flag == 1) {
$where['goods_class_id'] = $person2 ? $person2 : $person1;
}
if (!empty($notInIds)) {
$where['id'] = array('not in', $notInIds);
}
$where['merchant_id'] = $merchant_id;
$where['status'] = array('in', '0,1');
$where['cost_price'] = array('gt', 0);
switch ($user_type) {
case 1:
$info = D('SaleMGoods')->getSelect($where, $page, $limit, $field = '', $order = "id desc");
if ($info) {
foreach ($info as $key => &$value) {
$value['index'] = $key + 1;
$value['inventory_num'] = "";
$value['goods_num'] = round($value['goods_num'], 3);
$value['cost_price'] = round($value['cost_price'], 2);
$value['checked'] = false;
}
}
break;
case 2:
case 3:
//商品列表
$where['store_id'] = $store_id;
$info = D('SSaleMGoods')->getSelect($where, $page, $limit, $field = '', $order = "id desc");
if ($info) {
foreach ($info as $key => &$value) {
$value['index'] = $key + 1;
$value['inventory_num'] = "";
$value['goods_num'] = round($value['goods_num'], 3);
$value['cost_price'] = round($value['cost_price'], 2);
$value['checked'] = false;
if ($supplier_type == 2) {
$parameter = array(
'goods_id' => $value['goods_id'],
'sku_id' => $value['sku_id'],
'store_id' => $store_id,
);
$value['pur_id'] = D('SSaleMGoods')->getPurchaseId($parameter);
$value['purchase_order_id'] = '';
}
}
}
break;
}
$res['status'] = 1;
$res['msg'] = '查询成功';
$res['data'] = $info ? $info : array();
$this->ajaxReturn($res);
}
//盘点商品查询2020-11-5
public function GoodsListShow_v1()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['merchant_id'] = $data['merchantid'];
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
case 3:
//门店
$data['store_id'] = $data['storeid'];
$data['user_type'] = 4;
break;
}
$data['search_info'] = isset($data['search_info']) ? $data['search_info'] : $data['searchText'];
$data['exists_id_arr'] = isset($data['exists_id_arr']) ? $data['exists_id_arr'] : $data['notInIds'];
$SaleGoodsClass = new SaleGoods();
$result = $SaleGoodsClass->InventorySearchGoods($data);
$this->ajaxReturn($result);
}
//盘点扫码查询商品2020-11-5
public function InventoryScanCodeGoods()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['merchant_id'] = $data['merchantid'];
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
case 3:
//门店
$data['store_id'] = $data['storeid'];
$data['user_type'] = 4;
$StoreClass = new Store();
$data['supplier_type'] = $StoreClass->getSupplierType($data['storeid']);
break;
}
$SaleGoodsClass = new SaleGoods();
$result = $SaleGoodsClass->InventoryScanCodeGoods($data);
$this->ajaxReturn($result);
}
//盘点串号验证
public function inventorySerialVerify()
{
$data = I('post.');
switch ($data['user_type']) {
case 1:
$data['user_type'] = 3;
break;
case 2:
$data['user_type'] = 4;
break;
case 3:
$data['user_type'] = 6;
break;
}
$data['operator_type'] = 3;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->inventorySerialVerify($data);
$this->ajaxReturn($result);
}
/*
* 继续盘点的原盘点订单的商品明细
* @param inventory_order_id 盘点订单id
* @param user_type 1商家 2门店 3收银员
*/
public function InventoryConduct()
{
$inventory_order_id = I("post.inventory_order_id");
$user_type = I('post.user_type');
$store_id = I("storeid");
switch ($user_type) {
case 1:
$user_type = 3;
break;
case 2:
$user_type = 4;
break;
case 3:
$user_type = 6;
break;
}
$RetailStoreModel = new RetailStoreModel();
$supplier_type = $RetailStoreModel->getFindField(array('id' => $store_id), "supplier_type");
$InventoryRecordClass = new InventoryRecord();
$result = $InventoryRecordClass->keepInventory([
'user_type' => $user_type,
'store_id' => $store_id ? $store_id : 0,
'inventory_order_id' => $inventory_order_id,
'supplier_type' => $supplier_type
]);
$goodsList = $result['data'];
$res = array(
'status' => 1,
'inventory_order_id' => $inventory_order_id,
'goodsList' => $goodsList
);
$this->ajaxReturn($res);
}
/*@param merchantid 商户id
* @param storeid 门店id
* @param remarks 备注
* @param goodsList 盘点商品信息
* @param user_type 盘点人身份
* @param operator_id 操作人id
* @param status 1盘点 2保存草稿箱
* @param inventory_order_id 盘点单id
*/
public function InventorySbu()
{
if (IS_POST) {
$data = I("post.");
$merchant_id = $data['merchantid'];
$store_id = $data['storeid'];
$remarks = $data['remarks'] ? $data['remarks'] : "";
$status = I("post.status");
$inventory_order_id = I("post.inventory_order_id");
$goodsList = $data['goodsList'];
$goodsList = json_decode(htmlspecialchars_decode($goodsList), true);
$user_type = $data['user_type'] ? $data['user_type'] : 2; //1商户 2店长 3收银员
$operator_id = $data['operator_id'];
if (!$operator_id || !$user_type) {
$res['status'] = 0;
$res['msg'] = "缺少参数,请重新登录";
$this->ajaxReturn($res);
}
if (!$goodsList || count($goodsList) == 0) {
$res['status'] = 0;
$res['msg'] = "请添加盘点的商品";
$this->ajaxReturn($res);
}
if (count($goodsList) > 500) {
$res['status'] = 0;
$res['msg'] = "单次盘点上限为500种商品";
$this->ajaxReturn($res);
}
switch ($user_type) {
case 1:
$parameter = array(
'merchant_id' => $merchant_id,
'operator_id' => $operator_id,
'remarks' => $remarks,
'goodsList' => $goodsList,
'status' => $status,
'inventory_order_id' => $inventory_order_id
);
$res = A('Api/Inventory')->MerInventorying_V1($parameter);
break;
case 2:
case 3:
$supplier_type = D('RetailStore')->getFindField(array('id' => $store_id), "supplier_type");
$parameter = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'operator_id' => $operator_id,
'user_type' => $user_type,
'remarks' => $remarks,
'goodsList' => $goodsList,
'status' => $status,
'inventory_order_id' => $inventory_order_id,
'supplier_type' => $supplier_type
);
$res = A('Api/Inventory')->Inventorying_V1($parameter);
break;
}
} else {
$res['status'] = 0;
$res['msg'] = "网络错误";
}
$this->ajaxReturn($res);
}
//删除盘点商品记录
public function deleteGoodsRecord()
{
$data = I('post.');
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
//门店
$data['user_type'] = 4;
break;
case 3:
//收银员
$data['user_type'] = 6;
break;
}
$InventoryClass = new InventoryOperation();
$result = $InventoryClass->deleteGoodsRecord($data);
$this->ajaxReturn($result);
}
//新版盘点
public function InventorySbu_v1()
{
$data = I('post.');
$data['merchant_id'] = $data['merchantid'];
$data['store_id'] = $data['storeid'] ? $data['storeid'] : 0;
$data['operator_type'] = 3;
$data['goodsList'] = json_decode(htmlspecialchars_decode($data['goodsList']), true);
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
//门店
$data['user_type'] = 4;
break;
case 3:
//收银员
$data['user_type'] = 6;
break;
}
if ($data['user_type'] == 4 || $data['user_type'] == 6) {
$StoreClass = new Store();
$data['supplier_type'] = $StoreClass->getSupplierType($data['store_id']);
}
unset($data['merchantid']);
unset($data['storeid']);
$InventoryClass = new InventoryOperation();
$result = $InventoryClass->storeReal($data);
$this->ajaxReturn($result);
}
//采购已经入库的串号列表
public function purchaseWarehouseSerial()
{
$data = I('post.');
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
//门店
$data['user_type'] = 4;
break;
case 3:
//收银员
$data['user_type'] = 6;
break;
}
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->purchaseWarehouseSerial($data);
$this->ajaxReturn($result);
}
//采购已经退货的串号列表
public function purchaseRetreatSerial()
{
$data = I('post.');
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
//门店
$data['user_type'] = 4;
break;
case 3:
//收银员
$data['user_type'] = 6;
break;
}
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->purchaseRetreatSerial($data);
$this->ajaxReturn($result);
}
/*
* *************************************快捷收银***************************************************
*/
/*
* 快捷收银会员登录
*/
public function VipSign()
{
$data = I("post.");
$code = $data["vipCode"]; //会员卡号;
if (empty($code)) {
$res['status'] = 0;
$res['msg'] = '缺少参数';
$this->ajaxReturn($res);
}
$merchant_id = $data["merchantid"]; //商户id;
$store_id = $data["storeid"]; //门店id
$user_type = $data["user_type"]; // 1商户 2店长 3收银员
$cashier_id = $data["cashier_id"];
$VipDynamicCodeModel = D('RetailVipDynamicCode');
$VipModel = D('RetailVip');
$temp = (int)substr($code, 0, 2);
$field = array(
$VipModel::ID,
$VipModel::NICK_NAME,
$VipModel::NAME,
$VipModel::BALANCE,
$VipModel::MOBILE_PHONE . ' as cardnum',
$VipModel::CARD_KEY,
$VipModel::INTEGRAL,
$VipModel::GRADE_INTEGRAL,
$VipModel::STATUS,
$VipModel::PLUS_TYPE,
$VipModel::DENSITY_FREE
);
if (is_numeric($code) && strlen($code) == 18 && $temp >= 86 && $temp <= 89) {
$map = array(
$VipDynamicCodeModel::CODE => $code,
$VipDynamicCodeModel::STATUS => 0,
$VipDynamicCodeModel::STATE => 0,
$VipDynamicCodeModel::MERCHANT_ID => $merchant_id
);
$old = $VipDynamicCodeModel->getFind($map);
if (empty($old) || $old[$VipDynamicCodeModel::FAILURE_TIME] <= time()) {
$res['status'] = 0;
$res['msg'] = '请会员刷新动态码';
$this->ajaxReturn($res);
} else {
$save = array(
$VipDynamicCodeModel::STATUS => 1,
$VipDynamicCodeModel::USE_STORE_ID => $store_id,
);
if ($user_type == 3) {
$save[$VipDynamicCodeModel::USE_CASHIER_ID] = $cashier_id;
}
$VipDynamicCodeModel->updateOrder($map, $save);
}
$where[$VipModel::ID] = $old[$VipDynamicCodeModel::VID];
$where[$VipModel::STATUS] = array('neq', 2);
$vip = $VipModel->getSelect($where, $field);
$login_type = 1;
$payCode = $code;
$vipList = $vip;
} else {
$map[$VipModel::MERCHANT_ID] = $merchant_id;
$map[$VipModel::STATUS] = array('neq', 2);
if (is_numeric($code) && strlen($code) == 11) {
$map[$VipModel::MOBILE_PHONE] = $code;
} else if (is_numeric($code) && strlen($code) == 4) {
$map[$VipModel::MOBILE_PHONE] = array('like', '%' . $code);
} else if (is_numeric($code)) {
$map[$VipModel::CARD_KEY . '|' . $VipModel::CARD_NUM] = $code;
} else {
$map[$VipModel::CARD_KEY] = $code;
}
$vipList = $VipModel->getSelect($map, $field);
$login_type = 2;
}
if (!empty($vipList)) {
foreach ($vipList as &$value) {
$value['login_type'] = $login_type;
$value['payCode'] = !empty($payCode) ? $payCode : ($value[$VipModel::CARD_NUM] ? $value[$VipModel::CARD_NUM] : $value[$VipModel::CARD_KEY]);
if (empty($value[$VipModel::NICK_NAME])) {
$value['nickname'] = $value[$VipModel::NAME];
}
if (empty($value[$VipModel::NAME])) {
$value['name'] = $value[$VipModel::NICK_NAME];
}
}
$StoreModel = D('RetailStore');
$store = D('RetailStore')->getOrderFind(array($StoreModel::ID => $store_id), $StoreModel::DENSITY_FREE_STATE);
$res['density_free_state'] = $store[$StoreModel::DENSITY_FREE_STATE];
$res['info'] = $vipList;
$res['status'] = 1;
$res['msg'] = '查询成功';
} else {
$res['status'] = 0;
$res['msg'] = '查询失败';
}
$this->ajaxReturn($res);
}
/*
*快捷收银下单2019-9-30
*/
public function QuickCashier_v1()
{
$data = I("post.");
$store_id = $data["storeid"];
$merchant_id = $data["merchantid"];
$user_type = $data["user_type"]; // 1商户 2店长 3收银员
$operator_id = $data['operator_identity_id']; //操作人员id
$pay_type = $data["pay_type"]; //支付类型 1微信 2支付宝 3现金 5其他 6会员余额
$pay_money = $data['pay_money']; //支付金额
$code = $data["code"]; //支付宝、微信付款码
$vip_login_type = $data["vip_login_type"]; //会员登录方式1动态码 2账号登录
$vid = $data["vid"]; //会员id
$password = $data["password"]; //会员支付密码
$card_code = $data["card_code"]; //会员动态码
if (!$merchant_id || !$store_id || !$operator_id || !$pay_type) {
$res['status'] = 0;
$res['msg'] = "参数缺失,请重新登录";
$this->ajaxReturn($res);
}
if (round($pay_money, 2) > 100000) {
$res = array(
"status" => 0,
"msg" => "金额不能超过10万元"
);
$this->ajaxReturn($res);
}
if (!in_array($user_type, array('2', '3'))) {
$res['status'] = 0;
$res['msg'] = "登录超时,请重新登录";
$this->ajaxReturn($res);
}
if (!in_array($pay_type, array('1', '2', '3', '6'))) {
$res['status'] = 0;
$res['msg'] = "支付类型有误";
$this->ajaxReturn($res);
}
//验证支付金额
if (!verifyPrice($pay_money)) {
$result['status'] = 0;
$result['msg'] = '支付金额有误,请输入大于0的支付金额';
$this->ajaxReturn($result);
}
$Order = array();
$PayOrderModel = D("RetailPayOrder");
switch ($pay_type) {
case '1':
case '2':
//微信支付
if (!empty($code)) {
//刷卡支付、付款码支付
$map = array(
$PayOrderModel::STORE_ID => $store_id,
$PayOrderModel::CODE => $code
);
$historyOrder = $PayOrderModel->getFind($map);
if (!empty($historyOrder)) {
$result['status'] = 0;
$result['msg'] = '请用户刷新付款码';
$this->ajaxReturn($result);
}
$text = substr($code, 0, 2);
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
$pay_type = 2;
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
$pay_type = 1;
} else {
$result['status'] = 0;
$result['msg'] = "请扫描正确的付款码";
$this->ajaxReturn($result);
}
$Order[$PayOrderModel::CODE] = $code;
} else {
$result['status'] = 0;
$result['msg'] = '缺少支付参数code';
$this->ajaxReturn($result);
}
$PaySetModel = D('RetailPaySet');
$paySet = $PaySetModel->getFindMerchantConfig($merchant_id, $pay_type);
if ($paySet['status'] != 1) {
$result['status'] = 0;
$result['msg'] = $paySet['msg'];
$this->ajaxReturn($result);
}
$config = $paySet['config'];
$Order[$PayOrderModel::M_PAY_TYPE] = $paySet['m_pay_type'];
break;
case '6':
if (empty($vid) || empty($vip_login_type)) {
$result['status'] = 0;
$result['msg'] = '缺少会员参数';
$this->ajaxReturn($result);
}
$Order[$PayOrderModel::VID] = $vid;
break;
}
$Order[$PayOrderModel::PAY_TYPE] = $pay_type;
$Order[$PayOrderModel::STORE_ID] = $store_id;
$Order[$PayOrderModel::MERCHANT_ID] = $merchant_id;
if ($user_type == 2) { //店长
$Order[$PayOrderModel::SHOPOWNER_ID] = $operator_id;
} else if ($user_type == 3) { //收银员
$Order[$PayOrderModel::CASHIER_ID] = $operator_id;
}
$Order[$PayOrderModel::TRADE_AMOUNT] = round($pay_money, 2);
$Order[$PayOrderModel::ORDER_TYPE] = 6;
$Order[$PayOrderModel::ORDER_STATE] = 'WAIT_BUYER_PAY';
$Order[$PayOrderModel::ADD_TIME] = time();
$pay_order = $PayOrderModel->addPayOrder($Order);
if (!$pay_order) {
$result['status'] = 0;
$result['msg'] = '创建订单失败,请重试';
$this->ajaxReturn($result);
}
$Order[$PayOrderModel::ID] = $pay_order[$PayOrderModel::ID];
$Order[$PayOrderModel::OUT_TRADE_NO] = $pay_order[$PayOrderModel::OUT_TRADE_NO];
switch ($pay_type) {
case '1':
case '2':
//微信
//支付宝
if ($Order[$PayOrderModel::M_PAY_TYPE] == 3) {
//新大陆支付
$res = A('Pay/PayContinent')->toContinentPay_v3($Order, "小助手快捷收银");
} else if ($Order[$PayOrderModel::M_PAY_TYPE] == 4) {
//云闪付
$payObj = new CloudPayController();
$res = $payObj->soltCard($Order, $config, $pay_type);
} else if ($Order[$PayOrderModel::M_PAY_TYPE] == 7) {
//钱客云
$res = $this->paymentQuery($Order, $config, $pay_type);
} else {
if ($pay_type == 1) {
//微信
$res = A('Pay/NewWxPay')->toWxPay_v2($Order, $config);
} else {
//支付宝
$res = A('Pay/NewAliPay')->toAliPay_v2($Order, $config);
}
}
if ($res['status'] == 1) {
$result['status'] = 1;
$result['msg'] = '付款成功';
} else {
$result = $res;
}
break;
case '3':
//现金
$save = array(
$PayOrderModel::ORDER_STATE => 'SUCCESS',
$PayOrderModel::TRADE_DATE => time(),
);
$up = $PayOrderModel->updateOrder(array($PayOrderModel::ID => $pay_order[$PayOrderModel::ID]), $save);
if (!$up) {
$result['status'] = 0;
$result['msg'] = '数据库发成故障,支付流水表更新失败,请重新支付';
} else {
$result['status'] = 1;
$result['msg'] = '付款成功';
}
break;
case '6':
//会员余额
$res = $this->toVipPay_v1($Order, $password, $vip_login_type, $card_code);
if ($res['status'] == 1) {
$result['status'] = 1;
$result['msg'] = "";
} else {
$result = $res;
}
break;
}
if ($user_type == 2 && $result['status'] == 1) {
$parameter = array(
'type' => 4,
'desc' => '快速收款'
);
$this->system_parameter($parameter);
}
$result['out_trade_no'] = $Order[$PayOrderModel::OUT_TRADE_NO];
$this->ajaxReturn($result);
}
//钱客云,快速收款,支付,查询
public function paymentQuery($Order, $config, $pay_type)
{
$moneyGuest = new \MoneyGuestPay\Business\MoneyGuest();
$param['pay_order_info'] = $Order;
$param['config'] = $config;
$param['pay_type'] = $pay_type;
//支付
$res = $moneyGuest->moneyGuestPay($param);
if ($res['status'] == 1) {
//发起支付成功,查询订单,是否支付
$result = $this->searchAndUpdateOrder_v3($param);
$res = $result;
}
$res['pay_channel'] = 7;
return $res;
}
/**
* 用户等待支付
* @param $param
* @return mixed
*/
public function searchAndUpdateOrder_v3($param)
{
$Order = $param['pay_order_info'];
$canReturn = false;
$PayOrderModel = D('RetailPayOrder');
while (!$canReturn) {
$moneyGuest = new \MoneyGuestPay\Business\MoneyGuest();
$data = $moneyGuest->moneyGuestQueryOrder([
'pay_order' => $Order,
'config' => $param['config']
]);//查询订单状态
$res = $data['payInfo'];
if ($res['code'] == 200) {
if ($res['obj']['status'] == 1) {
//支付中
$time = get_runtime();
if ($time >= 60) {
//超时,撤销订单
$result['status'] = 0;
$result['msg'] = '用户取消支付';
$canReturn = true;
}
} else if ($res['obj']['status'] == 2) {
//支付成功
$save[$PayOrderModel::TRADE_NO] = $res['obj']['orderNumber'];
$save[$PayOrderModel::ORDER_STATE] = 'SUCCESS';
$save[$PayOrderModel::TRADE_DATE] = time();
$save[$PayOrderModel::EXTEND_CONTENT] = json_encode($res);
$up = $PayOrderModel->updateOrder(array($PayOrderModel::ID => $Order[$PayOrderModel::ID]), $save);
//支付成功,走分润
A('Pay/Base')->doAddRate($res['obj']['orderNumber'], $Order, 7);//分润(云闪付)
if ($up) {
$result['status'] = 1;
$result['msg'] = '支付成功';
} else {
$result['status'] = 0;
$result['msg'] = '支付成功但订单更新失败2,请联系管理员';
}
$canReturn = true;
} else {
$result['status'] = 0;
$result['msg'] = '用户取消支付2';
$canReturn = true;
}
} else {
$result['status'] = 0;
$result['res'] = $res;
$result['msg'] = '用户取消支付3';
$canReturn = true;
}
}
return $result;
}
/**
* 会员卡支付 2019-9-11 快捷支付
* @param $Order pay_order
* @param $password 会员支付密码
* @param $vipLoginType 会员登录方式 1动态码 2手机号或实体卡号
* @param $cardCode 会员动态码或手机号实体卡号
* @return mixed
*/
public function toVipPay_v1($Order, $password, $vipLoginType, $cardCode)
{
$VipModel = D('RetailVip');
$PayOrderModel = D('RetailPayOrder');
$vipMap = array(
$VipModel::ID => $Order[$PayOrderModel::VID]
);
$vipInfo = $VipModel->getFind($vipMap);
if ($vipLoginType == 1) {
$DynamicModel = D('RetailVipDynamicCode');
$map = array(
$DynamicModel::CODE => $cardCode,
$DynamicModel::STATUS => 1,
$DynamicModel::STATE => 0,
$DynamicModel::MERCHANT_ID => $Order[$PayOrderModel::MERCHANT_ID],
$DynamicModel::USE_STORE_ID => $Order[$PayOrderModel::STORE_ID],
);
if (!empty($Order[$PayOrderModel::CASHIER_ID])) {
$map[$DynamicModel::USE_CASHIER_ID] = $Order[$PayOrderModel::CASHIER_ID];
}
$old = $DynamicModel->getFind($map);
if (empty($old) || $old[$DynamicModel::FAILURE_TIME] <= time()) {
$result['status'] = 0;
$result['msg'] = '请会员刷新动态码';
return $result;
} else {
$DynamicModel->updateOrder($map, array($DynamicModel::STATUS => 2));
}
} else {
$StoreModel = D('RetailStore');
$store = D('RetailStore')->getOrderFind(array($StoreModel::ID => $Order[$PayOrderModel::STORE_ID]), $StoreModel::DENSITY_FREE_STATE);
if ($vipInfo[$VipModel::DENSITY_FREE] != 1 && !$store[$StoreModel::DENSITY_FREE_STATE]) {
//非免密
if (empty($password)) {
$result['status'] = 3;
$result['msg'] = '请输入会员支付密码';
return $result;
}
} else {
$password = null;
}
}
$result = $this->pay(6, 2, $password, $Order[$PayOrderModel::ID]);
return $result;
}
/**
* @param $bill_id
* @param $scene_type 场景 1收银机 2商户后台 3门店后台 4小程序 5公众号 6小助手快捷收银
* @param $type 类型 1充值 2消费 3编辑增加 4编辑减少 5退款增加 6红包充值 7大转盘充值 8礼品卡充值
* @param null $password
* @param null $pay_order_id
* @return mixed
*/
public function pay($scene_type, $type, $password = null, $pay_order_id = null)
{
$PayOrderModel = D('RetailPayOrder');
if (!empty($pay_order_id)) {
$payMap[$PayOrderModel::ID] = $pay_order_id;
}
$payOrder = $PayOrderModel->getFind($payMap);
if (empty($payOrder)) {
$res['status'] = 0;
$res['msg'] = '订单不存在';
return $res;
}
if ($payOrder[$PayOrderModel::PAY_TYPE] = !6 || empty($payOrder[$PayOrderModel::VID])) {
$res['status'] = 0;
$res['msg'] = '您的请求有误';
return $res;
}
$VipModel = D('RetailVip');
$vipMap = array(
$VipModel::ID => $payOrder[$PayOrderModel::VID],
);
$vipInfo = $VipModel->getFind($vipMap);
if (empty($vipInfo)) {
$res['status'] = 0;
$res['msg'] = '数据库发生错误';
return $res;
}
if (!empty($password) && !checkPassword($vipInfo[$VipModel::PASSWORD], $password, $vipInfo[$VipModel::ADD_TIME])) {
$res['status'] = 0;
$res['msg'] = '支付密码错误';
return $res;
}
$payMoney = $payOrder[$PayOrderModel::TRADE_AMOUNT];
if (round($vipInfo[$VipModel::BALANCE] - $payMoney, 2) < 0) {
$res['status'] = 0;
$res['msg'] = '会员卡余额不足,无法支付';
return $res;
}
$pay = $VipModel->toSetDec($vipMap, $VipModel::BALANCE, $payMoney);
if ($pay) {
$RechargeOrderModel = D('RetailRechargeOrder');
$remark = '';
switch ($scene_type) {
case 6:
$remark = '小助手快捷收银' . $payMoney . '元';
break;
}
$item = array(
$RechargeOrderModel::STORE_ID => $payOrder[$PayOrderModel::STORE_ID],
$RechargeOrderModel::MERCHANT_ID => $payOrder[$PayOrderModel::MERCHANT_ID],
$RechargeOrderModel::PAY_ORDER_ID => $payOrder[$PayOrderModel::ID],
$RechargeOrderModel::MONEY => $payMoney,
$RechargeOrderModel::ALL_MONEY => $payMoney,
$RechargeOrderModel::STATE => 1,
$RechargeOrderModel::SCENE_TYPE => $scene_type, //1收银机 2商户后台 3门店后台 4小程序 5公众号 6小助手
$RechargeOrderModel::TYPE => $type, //1充值 2消费 3编辑增加 4编辑减少 5退款增加 6红包充值 7大转盘充值 8礼品卡充值
$RechargeOrderModel::ADD_TIME => time(),
$RechargeOrderModel::VID => $vipInfo[$VipModel::ID],
$RechargeOrderModel::REMARK => $remark,
);
if (!empty($payOrder[$PayOrderModel::CASHIER_ID])) {
$item[$RechargeOrderModel::CASHIER_ID] = $payOrder[$PayOrderModel::CASHIER_ID];
}
$add = $RechargeOrderModel->addOrder($item);
if ($add) {
$res['status'] = 1;
$res['msg'] = '支付成功';
$save = array(
$PayOrderModel::ORDER_STATE => 'SUCCESS',
$PayOrderModel::TRADE_DATE => time()
);
$PayOrderModel->updateOrder($payMap, $save);
} else {
$res['status'] = 0;
$res['msg'] = '支付成功,添加记录失败,请联系系统管理员';
}
} else {
$res['status'] = 0;
$res['msg'] = '会员卡支付失败,请刷新动态码重试';
}
return $res;
}
//快捷收银退款2019-9-30
public function QuickRefund_v1()
{
$data = I("post.");
$merchant_id = $data['merchantid'];
$store_id = $data['storeid'];
$out_trade_no = $data["out_trade_no"]; //订单编号
$user_type = $data["user_type"]; // 1商户 2店长 3收银员
$operator_id = $data['operator_identity_id']; //操作人员id
$username = $data["username"]; //店长账号
$refund_code = $data["refund_code"]; //退款密码
if (!$out_trade_no || !$user_type || !$operator_id || !$merchant_id) {
$res['status'] = 0;
$res['msg'] = "参数缺失";
$this->ajaxReturn($res);
}
if ($user_type == 3 && (empty($refund_code) && empty($username))) {
$res['status'] = 0;
$res['msg'] = "请输入退款码";
$this->ajaxReturn($res);
}
if ($user_type == 3) {
$verify_type = $user_type == 3 ? 1 : $user_type;
$res = A("CashierApi/Refund")->verifyRefund($verify_type, $refund_code, $username);
if ($res['status'] != 1) {
$this->ajaxReturn($res);
}
}
$PayOrderModel = D("RetailPayOrder");
$wap['trade_no'] = $out_trade_no;
$wap['out_trade_no'] = $out_trade_no;
$wap['_logic'] = 'or';
$where['_complex'] = $wap;
$where['store_id'] = $store_id;
$where['order_type'] = 6;
$payOrder = $PayOrderModel->getOrderFind($where);
if (!$payOrder) {
$res['status'] = 0;
$res['msg'] = "未找到快捷收银支付成功订单";
$this->ajaxReturn($res);
}
if ($payOrder[$PayOrderModel::ORDER_STATE] != "SUCCESS") {
$res['status'] = 0;
$res['msg'] = "该订单未支付成功,无法退款";
$this->ajaxReturn($res);
}
$where = array(
$PayOrderModel::PAY_ORDER_ID => $payOrder[$PayOrderModel::ID],
$PayOrderModel::ORDER_STATE => "REFUND"
);
$refundOrder = $PayOrderModel->getOrderFind($where);
if ($refundOrder) {
$res['status'] = 0;
$res['msg'] = "该订单已退款";
$this->ajaxReturn($res);
}
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key = "quick_refund_" . $out_trade_no;
if ($ApiRedis::$redis->exists($key)) {
$res['status'] = 0;
$res['msg'] = "正在退款,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key, 10, $out_trade_no);
}
$paySet = D('RetailPaySet')->getFindMerchantPaySet($merchant_id);
$config = $paySet['config'];
$item = array(
$PayOrderModel::PAY_ORDER_ID => $payOrder[$PayOrderModel::ID], //'退款原订单id',
$PayOrderModel::ORDER_TYPE => 6, //'6快捷收银',
$PayOrderModel::SCENE_TYPE => 2, //'1付款 2退款',
$PayOrderModel::PAY_TYPE => $payOrder[$PayOrderModel::PAY_TYPE], //'1微信 2支付宝 3现金 4小程序微信 5其他支付方式 6会员余额',
$PayOrderModel::TRADE_AMOUNT => $payOrder[$PayOrderModel::TRADE_AMOUNT], //'订单金额',
$PayOrderModel::STORE_ID => $payOrder[$PayOrderModel::STORE_ID], //'门店id',
$PayOrderModel::MERCHANT_ID => $payOrder[$PayOrderModel::MERCHANT_ID], //'商户id',
$PayOrderModel::VID => $payOrder[$PayOrderModel::VID], //'会员id',
$PayOrderModel::TRADE_NO => $payOrder[$PayOrderModel::TRADE_NO], //'订单微信支付宝流水号',
$PayOrderModel::ADD_TIME => time(), //'订单创建时间',
$PayOrderModel::M_PAY_TYPE => $payOrder[$PayOrderModel::M_PAY_TYPE], //'订单支付类型 1普通商户模式 2服务商模式 3新大陆模式',
);
if ($user_type == 2) { //店长
$item[$PayOrderModel::SHOPOWNER_ID] = $operator_id;
} else if ($user_type == 3) {
$item[$PayOrderModel::CASHIER_ID] = $operator_id; //'收银员id',
}
$new_pay_order = $PayOrderModel->addPayOrder($item);
if ($new_pay_order) {
switch ($item[$PayOrderModel::PAY_TYPE]) {
case '1':
case '2':
//微信
//支付宝
$new_pay_order['before_amount'] = $payOrder[$PayOrderModel::TRADE_AMOUNT];
$new_pay_order['before_trade_no'] = $payOrder[$PayOrderModel::OUT_TRADE_NO];
if ($new_pay_order[$PayOrderModel::M_PAY_TYPE] == 3) {
//新大陆
$res = A('Pay/PayContinent')->toOrderRefund_v3($new_pay_order);
} else if ($new_pay_order[$PayOrderModel::M_PAY_TYPE] == 4) {
//云闪付
$payObj = new CloudPayController();
$res = $payObj->cloudRefund($new_pay_order, $config, $new_pay_order[$PayOrderModel::PAY_TYPE]);
} else if ($new_pay_order[$PayOrderModel::M_PAY_TYPE] == 7) {
//钱客云
$moneyGuest = new \MoneyGuestPay\Business\MoneyGuest();
$res = $moneyGuest->moneyGuestRefund($new_pay_order, $config);
if ($res['status'] == 1) {
//退款成功之后,走退款分润
A('Pay/Base')->doRefundRate($new_pay_order['trade_no'], $new_pay_order['trade_amount'], 6);//钱客云分润
}
} else if ($new_pay_order[$PayOrderModel::PAY_TYPE] == 1) {
//微信
if (!empty($payOrder['pay_coupon_id_str']) && $payOrder['pay_coupon_fee'] > 0) {
$new_pay_order['trade_amount'] = bcadd($new_pay_order['trade_amount'], $payOrder['pay_coupon_fee'], 2);
$new_pay_order['before_amount'] = $new_pay_order['trade_amount'];
}
$res = A('Pay/NewWxPay')->toWxRefund_v2($new_pay_order, $config);
} else {
//支付宝
$res = A('Pay/NewAliPay')->toAliRefund_v2($new_pay_order, $config);
}
break;
case '3':
//现金
$res = array(
'status' => 1
);
break;
case '6':
//会员余额
$res = A('PayApi/VipPay')->refundForVip_v1($item, 6, 5);
break;
default:
$res = array(
'status' => 0,
'msg' => '数据库发生错误'
);
}
if ($res['status'] == 1) {
$save = array(
$PayOrderModel::ORDER_STATE => 'REFUND',
$PayOrderModel::EXTEND_CONTENT => $res['data'] ? json_encode($res['data']) : '',
$PayOrderModel::TRADE_DATE => time()
);
if ($new_pay_order[$PayOrderModel::PAY_TYPE] == 1 && $res['response']['coupon_refund_count'] > 0) {
//代金券退款
$PaymentRefundClass = new PaymentRefund();
$couponResult = $PaymentRefundClass->paymentRefund(json_encode([
'refund_info' => $res['response'],
'merchant_id' => $payOrder['merchant_id'],
'type' => 2,
'old_pay_order_id' => $item['pay_order_id']
]));
if ($couponResult['status'] == 1) {
$save['pay_coupon_id_str'] = $couponResult['data']['pay_coupon_id_str'];
$save['pay_coupon_fee'] = $payOrder['pay_coupon_fee'];
$save['refund_coupon_fee'] = $couponResult['data']['pay_coupon_fee'];
$PayOrderModel->toSetInc([
'id' => $item['pay_order_id']
], 'refund_coupon_fee', $couponResult['data']['pay_coupon_fee']);
}
}
$PayOrderModel->updateOrder(array($PayOrderModel::ID => $new_pay_order[$PayOrderModel::ID]), $save); //更新新的pay_order数据
$PayOrderModel->toSetInc(array($PayOrderModel::ID => $item[$PayOrderModel::PAY_ORDER_ID]), $PayOrderModel::REFUND_MONEY, $payOrder[$PayOrderModel::TRADE_AMOUNT]); //增加原pay_order的退款金额
if ($user_type == 2) {
$parameter = array(
'type' => 4,
'desc' => '快速收款-退款'
);
$this->system_parameter($parameter);
}
$result['status'] = 1;
$result['msg'] = '退款成功';
} else {
$result['res'] = $res;
$result['status'] = 0;
$result['msg'] = $res['msg'];
}
} else {
$result['status'] = 0;
$result['msg'] = '退款订单创建失败';
}
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key);
}
$this->ajaxReturn($result);
}
//快捷收银列表
public function QuickList()
{
$PayOrderModel = D("RetailPayOrder");
$data = I("post.");
$user_type = $data["user_type"]; //1商户 2门店 3收银员
$merchant_id = $data['merchant_id'];
$store_id = $data['store_id'];
$cashier_id = $data['cashier_id']; //收银员id
$out_trade_no = $data['out_trade_no']; //内部流水号
$page = $data['page'] ? $data['page'] : 1;
$limit = $data['limit'] ? $data['limit'] : 1;
$start_time = $data['start_time'];
$end_time = $data['end_time'];
if (!$store_id || !$merchant_id || !$user_type) {
$res = array(
"status" => 0,
"msg" => "参数缺失"
);
$this->ajaxReturn($res);
}
if ($user_type == 3) {
$cashierInfo = D('RetailCashier')->getFind(array('id' => $cashier_id), "cashier_show_other_sell");
if ($cashierInfo['cashier_show_other_sell'] == 2) {
$where[$PayOrderModel::CASHIER_ID] = $cashier_id;
}
}
if (!empty($start_time) && !empty($end_time)) {
$start_time = strtotime($start_time . "00:00:00");
$end_time = strtotime($end_time . "23:59:59");
$where[$PayOrderModel::ADD_TIME] = array('between', array($start_time, $end_time));
} else if (!empty($start_time)) {
$start_time = strtotime($start_time . "00:00:00");
$where[$PayOrderModel::ADD_TIME] = array('gt', $start_time);
} else if (!empty($end_time)) {
$end_time = strtotime($end_time . "23:59:59");
$where[$PayOrderModel::ADD_TIME] = array('lt', $end_time);
}
switch ($user_type) {
case 1:
$where[$PayOrderModel::MERCHANT_ID] = $merchant_id;
break;
case 2:
case 3:
$where[$PayOrderModel::MERCHANT_ID] = $merchant_id;
$where[$PayOrderModel::STORE_ID] = $store_id;
break;
}
if (!empty($out_trade_no)) {
$where[$PayOrderModel::OUT_TRADE_NO] = array('like', '%' . $out_trade_no . '%');
}
$where[$PayOrderModel::ORDER_TYPE] = 6;
$where[$PayOrderModel::ORDER_STATE] = array('in', "SUCCESS,REFUND");
$order = "id desc";
$page = $page . ',' . $limit;
$list = $PayOrderModel->getSelect($where, "pay_type,order_state,trade_date,shopowner_id,cashier_id,out_trade_no,trade_amount", $order, $page);
if ($list) {
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
switch ($val['pay_type']) {
case 1:
$val['pay_name'] = "微信";
break;
case 2:
$val['pay_name'] = "支付宝";
break;
case 3:
$val['pay_name'] = "现金";
break;
case 6:
$val['pay_name'] = "会员";
break;
}
switch ($val['order_state']) {
case "SUCCESS":
$val["order_name"] = "支付订单";
if ($val['refund_money'] == 0) {
$val['type'] = 1; //可退款
} else if ($val['refund_money'] == $val['trade_amount']) {
$val['type'] = 2; //已退款
}
break;
case "REFUND":
$val['type'] = 3; //退款订单
$val["order_name"] = "退款订单";
break;
}
$val['trade_date'] = date("Y-m-d H:i:s", $val['trade_date']); //支付时间
if (!empty($val['shopowner_id'])) {
$val['operator_name'] = M("retail_manager")->where(array('id' => $val['shopowner_id']))->getField("name");
} else if (!empty($val['cashier_id'])) {
$cashierInfo = D("RetailCashier")->getFind(array('id' => $val['cashier_id']), "name");
$val['operator_name'] = $cashierInfo['name'];
}
}
}
$res['status'] = 1;
$res["data"] = $list ? $list : array();
$this->ajaxReturn($res);
}
//生成二维码
public function GetCode()
{
$data = I("post.");
$store_id = $data["storeid"];
$merchant_id = $data["merchantid"];
$user_type = $data["user_type"]; // 1商户 2店长 3收银员
$operator_id = $data['operator_id']; //操作人员id
$pay_type = $data["pay_type"]; //支付类型 1微信 2支付宝 3现金 5其他 6会员余额
$pay_money = $data['pay_money']; //支付金额
if (!$merchant_id || !$store_id || !$operator_id || !$pay_type) {
$res['status'] = 0;
$res['msg'] = "参数缺失,请重新登录";
$this->ajaxReturn($res);
}
if (round($pay_money, 2) > 100000) {
$res = array(
"status" => 0,
"msg" => "金额不能超过10万元"
);
$this->ajaxReturn($res);
}
if (!in_array($user_type, array('2', '3'))) {
$res['status'] = 0;
$res['msg'] = "登录超时,请重新登录";
$this->ajaxReturn($res);
}
if (!in_array($pay_type, array('1', '2'))) {
$res['status'] = 0;
$res['msg'] = "支付类型有误";
$this->ajaxReturn($res);
}
//验证支付金额
if (!verifyPrice($pay_money)) {
$result['status'] = 0;
$result['msg'] = '支付金额有误,请输入大于0的支付金额';
$this->ajaxReturn($result);
}
$Order = array();
$PayOrderModel = D("RetailPayOrder");
$PaySetModel = D('RetailPaySet');
$paySet = $PaySetModel->getFindMerchantConfig($merchant_id, $pay_type);
if ($paySet['status'] != 1) {
$result['status'] = 0;
$result['msg'] = $paySet['msg'];
$this->ajaxReturn($result);
}
$config = $paySet['config'];
$Order[$PayOrderModel::M_PAY_TYPE] = $paySet['m_pay_type'];
$Order[$PayOrderModel::PAY_TYPE] = $pay_type;
$Order[$PayOrderModel::STORE_ID] = $store_id;
$Order[$PayOrderModel::MERCHANT_ID] = $merchant_id;
if ($user_type == 2) { //店长
$Order[$PayOrderModel::SHOPOWNER_ID] = $operator_id;
} else if ($user_type == 3) { //收银员
$Order[$PayOrderModel::CASHIER_ID] = $operator_id;
}
$Order[$PayOrderModel::TRADE_AMOUNT] = round($pay_money, 2);
$Order[$PayOrderModel::ORDER_TYPE] = 6;
$Order[$PayOrderModel::ORDER_STATE] = 'WAIT_BUYER_PAY';
$Order[$PayOrderModel::ADD_TIME] = time();
$pay_order = $PayOrderModel->addPayOrder($Order);
if (!$pay_order) {
$result['status'] = 0;
$result['msg'] = '创建订单失败,请重试';
$this->ajaxReturn($result);
}
$Order[$PayOrderModel::ID] = $pay_order[$PayOrderModel::ID];
$Order[$PayOrderModel::OUT_TRADE_NO] = $pay_order[$PayOrderModel::OUT_TRADE_NO];
$storeInfo = D("RetailStore")->getFind(array('id' => $store_id), "storetag");
$store_name = $storeInfo['storetag'];
if ($pay_order[$PayOrderModel::M_PAY_TYPE] == 3) { //新大陆
$res = A('Pay/PayContinent')->sweepCodePay($pay_order);
if ($res['status'] == 0) {
$this->ajaxReturn($res);
}
$res['status'] = 1;
} else if ($pay_order[$PayOrderModel::M_PAY_TYPE] == 4) { //云闪付
$payObj = new CloudPayController();
$res = $payObj->cloudPaybarCodeAll($Order, $config, $pay_type, $store_name);
if ($res['status'] == 0) {
$this->ajaxReturn($res);
}
$res['status'] = 1;
} else if ($pay_type == 1) { // 微信
$result = A("Api/PaymentCodes")->createWxPayOrder($Order, $config, $store_name, 2);
if ($result['status'] == 1) {
$res['qr_code'] = $result['data']['code_url'];
$res['status'] = 1;
} else {
$res = $result;
}
} else if ($pay_type == 2) { // 支付宝
$result = A("Api/PaymentCodes")->createAliPayOrder($Order, $config, $store_name, 2);
if ($result['status'] == 1) {
$res['qr_code'] = $result['qr_code'];
$res['status'] = 1;
} else {
$res = $result;
}
} else {
$res = array(
'status' => 0,
'msg' => "支付方式有误"
);
}
$res['out_trade_no'] = $pay_order[$PayOrderModel::OUT_TRADE_NO];
$this->ajaxReturn($res);
}
/**
* 快捷收单查询扫码支付订单状态
* @param string $out_trade_no pay_order订单号
* @return array $res
*/
public function searchOrderPayState()
{
// 接受数据
$out_trade_no = I('post.out_trade_no');
// 判断订单号
if (!$out_trade_no) {
$res = array(
'status' => 0,
'msg' => '请求错误'
);
$this->ajaxReturn($res);
}
// 查询订单
$RPOModel = D('RetailPayOrder');
$pay_order = $RPOModel->getFind(array($RPOModel::OUT_TRADE_NO => strval($out_trade_no)));
// 判断订单
if (empty($pay_order)) {
$res = array(
'status' => 0,
'msg' => '订单异常'
);
$this->ajaxReturn($res);
}
// 判断支付
if ($pay_order[$RPOModel::ORDER_STATE] == 'REVOKED') {
$res = array(
'status' => 0,
'msg' => '订单已撤销成功'
);
} else if ($pay_order[$RPOModel::ORDER_STATE] == 'SUCCESS') {
$res = array(
'status' => 1,
'msg' => '支付成功'
);
} else {
$res = array(
'status' => 2,
'msg' => '等待支付'
);
}
$this->ajaxReturn($res);
}
/*
* *************************************商户模块***********************************
*/
/**
* 门店之间调拨列表
*/
public function StoreAllocatList()
{
$data = I("post.");
$merchant_id = $data['merchantid'];
$page = $data['page'];
$limit = $data['limit'];
$order_number = $data['order_number'];
$add_time = $data['add_time'];
$store_id = $data['store_id'];
$examine_status = $data['examine_status'];
if (!empty($order_number)) {
$where['order_number'] = $order_number;
}
if (!empty($add_time)) {
$start_time = strtotime($add_time[0] . "00:00:00");
$end_time = strtotime($add_time[1] . "23:59:59");
$where['add_time'] = array('between', array($start_time, $end_time));
}
if (!empty($store_id)) {
$where['store_id'] = $store_id;
}
if ($examine_status != '') {
$where['examine_status'] = $examine_status;
}
$where['merchant_id'] = $merchant_id;
$where['type'] = 3;
$where['status'] = 1;
$orderList = D('SStockOutOrder')->getSelect($where, $page, $limit);
if ($orderList) {
foreach ($orderList as $key => &$val) {
$val['index'] = $key + 1;
$val['store_name'] = D('Store')->getStoreName(array('id' => $val['store_id']));
$val['transfer_name'] = D('Store')->getStoreName(array('id' => $val['transfer_to_store_id']));
$val['money_total'] = round($val['money_total'], 2);
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
$val['warehouse_time'] = date('Y-m-d H:i:s', $val['warehouse_time']);
switch ($val['examine_status']) {
case 0:
$val['examine_name'] = '未审核';
break;
case 1:
if (!$val['warehousing_status']) {
$val['examine_name'] = '未入库';
} else {
$val['examine_name'] = '已入库';
$val['real_money_total'] = round($val['real_money_total'], 2);
}
break;
case 2:
$val['examine_name'] = '审核失败';
break;
}
}
}
$res['status'] = 1;
$res['msg'] = '';
$res['data'] = $orderList;
$this->ajaxReturn($res);
}
/**
*审核通过
*/
public function Examine()
{
$id = I("post.id");
$type = I("post.type");
$data = array();
$data['examine_status'] = $type;
$success = D('SStockOutOrder')->updateData(array('id' => $id), $data);
if ($success['status'] == 0) {
$res['status'] = 0;
$res['msg'] = '操作失败';
$this->ajaxReturn($res);
}
$success = D('SWarehousingRecord')->updateData(array('stock_out_id' => $id, 'type' => 5), $data);
if ($success['status'] == 0) {
$res['status'] = 0;
$res['msg'] = '操作失败';
$this->ajaxReturn($res);
}
$res['status'] = 1;
$res['msg'] = '操作成功';
$this->ajaxReturn($res);
}
/**
* 门店列表
*/
public function storeInfo()
{
$user_type = I("post.user_type"); //1商户 2门店 3收银员
$merchant_id = I("post.merchantid");
if ($user_type == 2) {
$store_id = I("post.storeid");
} else {
$store_id = '';
}
$res = A('Api/Inventory')->storeList($merchant_id, $store_id);
$this->ajaxReturn($res);
}
//商户出库商品列表
public function AllocateGoodsList()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['user_type'] = 3;
$data['merchant_id'] = $data['merchantid'];
$data['exists_id_arr'] = isset($data['exists_id_arr']) ? $data['exists_id_arr'] : $data['notInIds'];
$data['search_info'] = isset($data['search_info']) ? $data['search_info'] : $data['searchText'];
$SaleGoodsClass = new SaleGoods();
$result = $SaleGoodsClass->warehouseSearchGoods($data);
$result['msg'] = $result['message'];
$result['data'] = $result['data']['list'];
$this->ajaxReturn($result);
}
/*
* 入库商品信息
*/
public function warehousingGoodsList()
{
$id = I("post.id");
$StockOutGoodsModel = new StockOutGoodsModel();
$StockSerialModel = new StockGoodsSerialModel();
$goodsList = $StockOutGoodsModel->getSelect(array('stock_out_id' => $id));
if (!empty($goodsList)) {
$where = [
'merchant_id' => $this->merchant_id,
'num' => ['gt', 0]
];
$fields = 'id,main_serial_number,auxiliary_serial_number_one,auxiliary_serial_number_two';
foreach ($goodsList as $key => &$val) {
$val['stock_num'] = round($val['stock_num'], 3);
$val['warehouse_num'] = $val['stock_num'];
$val['warehouse_price'] = $val['stock_price'];
$val['build_date'] = '';
$val['quality_guarantee_period'] = '';
if ($val['serial_number_state'] == 1) {
$where['outside_id'] = $val['id'];
$val['serial_list'] = $StockSerialModel->getSelect($where, '', '', $fields);
}
}
}
$res['status'] = 1;
$res['data'] = $goodsList;
$this->ajaxReturn($res);
}
//商户出库扫码查询商品
public function AllocateScanCodeGoods()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['user_type'] = 3;
$data['merchant_id'] = $data['merchantid'];
$SaleGoodsClass = new SaleGoods();
$result = $SaleGoodsClass->warehouseScanCodeGoods($data);
$this->ajaxReturn($result);
}
/**
* 商户确认出库操作
* @parame type 出库类型 0其他出库 1调拨出库 2盘亏出库 3门店申请调拨出库 4退货出库
* @param store_id 目标门店
*/
public function AllocateConfirm()
{
A("Terminalapi/Stock")->AllocateConfirm();
}
/**
* 商户出库单
* @param order_number 订单号
* @param add_time 时间
* @param type 1调拨出库 2盘亏出库 3门店申请调拨出库
*/
public function AllocateOrder()
{
A("Terminalapi/Stock")->AllocateOrder();
}
/**
* 商户调拨单列表
* @param order_number 订单号
* @param add_time 时间
* @param status 1申请 2已出库 3已入库
*/
public function AllocateOrderList()
{
A("Terminalapi/Stock")->AllocateOrderList();
}
public function AllocateApply() {
A("Terminalapi/Stock")->AllocateApply();
}
//商户出库单详情
public function AllocateInfo()
{
$data = I('post.');
$data['user_type'] = 3;
$OutboundOrderClass = new OutboundOrder();
$result = $OutboundOrderClass->detailList($data);
$this->ajaxReturn($result);
}
/**
*商户端调拨单的门店入库单详情
*/
public function WarehousingList()
{
$id = I("post.id");
$SWarehousingGoodsModel = new SWarehousingGoodsModel();
$list = $SWarehousingGoodsModel->getSelect(array('warehouse_record_id' => $id));
if (!empty($list)) {
foreach ($list as $key => &$val) {
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
if (!empty($val['build_date'])) {
$val['build_date'] = date('Y-m-d', $val['build_date']);
}
$val['index'] = $key + 1;
$val['sku_num'] = round($val['sku_num'], 3);
$val['warehouse_num'] = round($val['warehouse_num'], 3);
$val['warehouse_price'] = round($val['warehouse_price'], 2);
$val['subtotal'] = round($val['subtotal'], 2);
}
}
$res['status'] = 1;
$res['data'] = $list;
$this->ajaxReturn($res);
}
/*
* 出库详情列表
*/
public function WarehousingOutList()
{
$id = I("post.id");
$AllocationGoodsModel = new \Common\Model\AllocationGoodsModel();
$SaleMGoodsModel = new \Common\Model\SaleMGoodsModel();
$list = $AllocationGoodsModel->getSelect(array('allocation_id' => $id), $page = '', $limit = '', $fields = '', 'id asc');
foreach ($list as $key => &$val) {
$where = [
'goods_id' => $val['goods_id']
];
if ($val['attribute_state'] == 2) {
$where['sku_id'] = $val['sku_id'];
}
$goods = $SaleMGoodsModel->getFind($where);
$val['apply_num'] = round($val['apply_num'], 3);
if ($val['serial_number_state'] == 1) {
$val['stock_num'] = 0;
} else {
$val['stock_num'] = $val['apply_num'];
}
$val['sku_num'] = round($val['sku_num'], 3);
$val['goods_num'] = round($goods['goods_num'], 3);
$val['cost_price'] = round($goods['cost_price'], 2);
$stockInfo = D('StockOutGoods')->getFind($where, "id desc");
if ($stockInfo) {
$val['stock_price'] = $stockInfo['stock_price'];
} else {
$val['stock_price'] = $goods['cost_price'];
}
$val['stock_price'] = round($val['stock_price'], 2);
$val['subtotal'] = round($val['stock_price'] * $val['stock_num'], 2);
}
$res['status'] = 1;
$res['data'] = $list;
$this->ajaxReturn($res);
}
/**
*商户采购单列表
*/
public function MerPurchaseOrder()
{
A("Terminalapi/PurchaseOrder")->PurchaseOrder();
}
/**
*商户采购仓与供货商
*/
public function MerWarehouseInfo()
{
A("Terminalapi/PurchaseOrder")->WarehouseInfo();
}
/**
*商户采购选择的商品
*/
public function MerPurGoods()
{
A("Terminalapi/PurchaseOrder")->GoodsInfo();
}
//采购串号验证
public function MerPurGoodsSerialVerify()
{
A("Terminalapi/PurchaseOrder")->serialVerify();
}
/**
*商户采购选择的商品 2020-11-4
*/
public function MerPurGoods_v1()
{
A("Terminalapi/PurchaseOrder")->GoodsInfo_v1();
}
/**
*商户采购扫码查询的商品 2020-11-4
*/
public function MerPurScanCodeGoods()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['user_type'] = 3;
$data['merchant_id'] = $data['merchantid'];
$PurchaseGoodsClass = new SaleGoods();
$result = $PurchaseGoodsClass->purchaseScanCodeGoods($data);
$this->ajaxReturn($result);
}
/**
*商户采购提交操作
*/
public function MerPurchaseOperation()
{
A("Terminalapi/PurchaseOrder")->PurchaseOperation();
}
//采购详情串号列表
public function merPurDetailSerialList()
{
A("Terminalapi/PurchaseOrder")->detailSerialList();
}
/**
*商户采购详情
*/
public function MerPurDetails()
{
A("Terminalapi/PurchaseOrder")->DetailsList();
}
/**
*商户采购编辑提交
*/
public function MerPurOrderEdit()
{
A("Terminalapi/PurchaseOrder")->PurchaseOrderEdit();
}
/**
*商户采购入库
*/
public function MerWarehouseOperation()
{
A("Terminalapi/PurchaseOrder")->WarehousingOperation();
}
//采购基础数据
public function addPurchaseOrderBasics()
{
$data = I('post.');
$data['merchant_id'] = $data['merchantid'];
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
case 3:
//门店
$data['user_type'] = 4;
$data['store_id'] = $data['storeid'];
break;
}
//采购修改售价权限
$InventorySetClass = new InventorySet();
$info = $InventorySetClass->getInfo($data);
$this->ajaxReturn([
'status' => 1,
'message' => '查询成功',
'data' => [
'modify_price_state' => $info['modify_price_state']
]
]);
}
//商户退货列表
public function MerRetreatOrder()
{
A("Terminalapi/PurchaseOrder")->RetreatOrder();
}
//采购退货详情的串号列表
public function merRetreatDetailSerial()
{
A("Terminalapi/PurchaseOrder")->retreatDetailSerialList();
}
/**
*商户退货详情
*/
public function MerRetreatDetails()
{
A("Terminalapi/PurchaseOrder")->RetreatDetails();
}
//采购退货可退的串号
public function MerRetreatGoodsSerial()
{
A("Terminalapi/PurchaseOrder")->serialList();
}
/**
*商户采购退货选择的商品
*/
public function MerRetreatGoods()
{
A("Terminalapi/PurchaseOrder")->RetreatGoods();
}
/**
*商户采购退货选择的商品 2020-11-4
*/
public function MerRetreatScanCodeGoods()
{
A("Terminalapi/PurchaseOrder")->returnableScanCodeGoods();
}
/**
*商户采购退货操作
*/
public function MerRetreatAction()
{
A("Terminalapi/PurchaseOrder")->RetreatAction();
}
/**
* 商户的门店间调拨列表
*/
public function AllocationTube()
{
A("Terminalapi/AllocationTube")->OrderList();
}
/**
* 商户的门店间调拨审核操作
*/
public function ExamineAction()
{
A("Terminalapi/AllocationTube")->ExamineAction();
}
/**
* 商户的门店间调拨的出库详情
*/
public function AllocationDetails()
{
A("Terminalapi/AllocationTube")->AllocationDetails();
}
/**
* 商户的门店间调拨入库详情
*/
public function WarehousingDetails()
{
A("Terminalapi/AllocationTube")->WarehousingDetails();
}
//商户报损列表
public function LossReportList()
{
A("Terminalapi/LossReport")->LossReportList();
}
/**
* 商户报损商品查询
*/
public function LossGoodsList()
{
A("Terminalapi/LossReport")->LossGoodsList();
}
//报损选择商品的串号列表
public function LossGoodsSerial()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['merchant_id'] = $data['merchantid'];
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
case 3:
//门店
$data['user_type'] = 4;
$data['store_id'] = $data['storeid'];
break;
}
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->warehouseSerialList($data);
$this->ajaxReturn($result);
}
//商户报损商品查询2020-11-5
public function LossGoodsList_v1()
{
$data = I('post.');
$data['merchant_id'] = $data['merchantid'];
$data['operator_type'] = 3;
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
case 3:
//门店
$data['user_type'] = 4;
$data['store_id'] = $data['storeid'];
break;
}
$data['exists_id_arr'] = isset($data['exists_id_arr']) ? $data['exists_id_arr'] : $data['notInIds'];
$data['search_info'] = isset($data['search_info']) ? $data['search_info'] : $data['searchText'];
$SaleGoodsClass = new SaleGoods();
$result = $SaleGoodsClass->lossSearchGoods($data);
$this->ajaxReturn($result);
}
//报损扫码查询2020-11-5
public function lossScanCodeGoods()
{
$data = I('post.');
$data['merchant_id'] = $data['merchantid'];
$data['operator_type'] = 3;
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
case 3:
//门店
$data['user_type'] = 4;
$data['store_id'] = $data['storeid'];
break;
}
$SaleGoodsClass = new SaleGoods();
$result = $SaleGoodsClass->lossScanCodeGoods($data);
$this->ajaxReturn($result);
}
/**
* 商户报损提交操作
*/
public function LossOperation()
{
A("Terminalapi/LossReport")->LossOperation();
}
//商户报损单详情的串号列表
public function lossInfoSerial()
{
A("Terminalapi/LossReport")->lossInfoSerial();
}
//商户报损单详情
public function LossInfo()
{
A("Terminalapi/LossReport")->LossInfo();
}
/*
* *************************************************门店模块*******************************
*/
/**
* 门店入库详情可编辑
* @param
*[
* id 入库单id
* type 4商户调拨 5门店调拨
* }
*/
public function SEnterInfo()
{
$id = I("post.id");
$type = I("post.type");
$fields = 'id,main_serial_number,auxiliary_serial_number_one,auxiliary_serial_number_two';
$map = [
'num' => ['gt', 0]
];
switch ($type) {
case 4:
//商户调拨
$where = array();
$where['warehouse_record_id'] = $id;
$where['type'] = 1;
$StockOutGoodsModel = new StockOutGoodsModel();
$StockSerialModel = new StockGoodsSerialModel();
$goodsList = $StockOutGoodsModel->getSelect($where);
if ($goodsList) {
foreach ($goodsList as $key => &$val) {
$val['stock_num'] = round($val['stock_num'], 3);
$val['warehouse_num'] = round($val['stock_num'], 3);
$val['warehouse_price'] = round($val['stock_price'], 2);
if ($val['serial_number_state'] == 1) {
$map['outside_id'] = $val['id'];
$val['serial_list'] = $StockSerialModel->getSelect($map, '', '', $fields);
}
}
}
break;
case 5:
//门店调拨
$where = array();
$where['warehouse_record_id'] = $id;
$where['type'] = 3;
$SStockOutGoodsModel = new SStockOutGoodsModel();
$SStockSerialModel = new SStockGoodsSerialModel();
$goodsList = $SStockOutGoodsModel->getSelect($where);
if ($goodsList) {
foreach ($goodsList as $key => &$val) {
$val['stock_num'] = round($val['stock_num'], 3);
$val['warehouse_num'] = round($val['stock_num'], 3);
$val['warehouse_price'] = round($val['stock_price'], 2);
if ($val['serial_number_state'] == 1) {
$map['outside_id'] = $val['id'];
$val['serial_list'] = $SStockSerialModel->getSelect($map, '', '', $fields);
}
}
}
}
$res['status'] = 1;
$res['data'] = $goodsList;
$this->ajaxReturn($res);
}
/**
* 门店确认调拨入库判断商品信息
*/
public function goodsVerification()
{
$data = I("post.");
$store_id = $data["storeid"];
$merchant_id = $data['merchantid'];
$goodsList = $data["goodsList"];
$id = $data['post.id'];
$goodsList = json_decode(htmlspecialchars_decode($goodsList), true);
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_id . "_warehousing_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 60, $id);
}
$success = A('Api/Inventory')->goodsVerify($merchant_id, $store_id, $goodsList);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($success);
}
//出库操作
public function stockOperation()
{
$merchant_id = I("post.merchantid");
$operator_id = I("post.operator_id");
$goodsList = I("post.goodsList");
$goodsList = json_decode(htmlspecialchars_decode($goodsList), true);
$id = I("post.id");
$remarks = I("post.remarks");
if (!$id || !$goodsList) {
$res['status'] = 0;
$res['msg'] = "参数错误";
$this->ajaxReturn($res);
}
$AllocationOrderModel = new \Common\Model\AllocationOrderModel();
$info = $AllocationOrderModel->getFind(array('id' => $id));
if (!$info) {
$res['status'] = 0;
$res['msg'] = '未找到该订单';
$this->ajaxReturn($res);
}
if ($info['status'] == 2) {
$res['status'] = 0;
$res['msg'] = '已出库,请勿重复操作';
$this->ajaxReturn($res);
}
$store_id = $info['store_id'];
$SaleWarehouseModel = new \Common\Model\SaleWarehouseModel();
$warehouse_id = $SaleWarehouseModel->getFindField(array('merchant_id' => $merchant_id, 'status' => 1), "id");
$type = 3;//门店申请调拨出库
$order_number = $info['order_number'];
foreach ($goodsList as $key => &$val) {
$val['output_num'] = round($val['stock_num'], 3);
if ($val['serial_number_state'] == 1 && $val['output_num'] != count($val['serial_list'])) {
$res = ['status' => 0, 'msg' => '串号信息与数量不符'];
$this->ajaxReturn($res);
}
unset($val['stock_num']);
}
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_id . "_allocation_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 60, $id);
}
$parameter = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'operator_id' => $operator_id,
'warehouse_id' => $warehouse_id,
'type' => $type,
'goodsList' => $goodsList,
'remarks' => $remarks,
'order_number' => $order_number
);
$res = A("Api/Inventory")->MerStockOut($parameter);
if ($res['status'] == 1) {
//出库成功
$saveData = array();
$saveData['stock_order_id'] = $res['stockOrderId'];
$saveData['warehouse_order_id'] = $res['warehouseOrderId'];
$saveData['goods_species'] = $res['goods_species'];
$saveData['money_total'] = $res['money_total'];
$saveData['status'] = 2;
$saveData['stock_time'] = time();
$saveData['m_operator_id'] = session("jurisdiction_user")['id'];
$res = D('AllocationOrder')->updateData(array('id' => $id), $saveData);
if ($res['status'] == 1) {
$log_data = [
'source' => 1,
'type' => 4,
'desc' => '调拨单-申请出库',
'request_data' => json_encode($_POST),
'operator_id' => $operator_id,
'mer_id' => $merchant_id
];
action_log_v2($log_data);
}
} else {
$res['status'] = 0;
}
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($res);
}
/**
* 将门店未有的商品信息同步到门店
* @param
* [
* goodsIds array 未有的商品id
* type 4商户调拨过来 5其他门店调拨过来
* ]
*/
public function batchSync()
{
$data = I("post.");
$merchant_id = $data['merchantid'];
$store_id = $data["storeid"];
$goodsIds = $data["goodsIds"];
$type = $data["type"];
$id = $data['id'];
if (!$store_id || !$goodsIds || !$type) {
$res['status'] = 0;
$res['msg'] = '登录超时,请重新登录';
$this->ajaxReturn($res);
}
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_id . "_warehousing_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 60, $id);
}
$success = A('Api/Inventory')->batchSync([
'operate_id' => $data['operator_id'],
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'goodsIds' => $goodsIds,
'type' => $type
]);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($success);
}
/**
* 门店入库操作
* [
* id 入库单id
* order_number 入库订单号
* goodsList 入库商品
* refuseList 拒收的商品
* warehouse_id 仓库id
* textarea 备注
* type 入库类型 0其他入库 1采购入库 2补货入库 3盘盈入库 4商户调拨入库 5其他门店调拨入库 6该门店申请调拨入库 7初始化商品档案入库 8拼团退货入库 9秒杀退货入库 10拆分入库 11收银退货入库 12商城退货入库
* ]
*/
public function SEnterOperation()
{
$data = I("post.");
$id = $data["id"];
$store_id = $data["storeid"];
$merchant_id = $data['merchantid'];
$goodsList = $data["goodsList"]; //入库商品
$refuseList = $data['refuseList']; //拒收商品
$goodsList = json_decode(htmlspecialchars_decode($goodsList), true);
if (!empty($refuseList)) {
$refuseList = json_decode(htmlspecialchars_decode($refuseList), true);
}
$warehouse_id = D("SSaleWarehouse")->getFindField(array("merchant_id" => $merchant_id, "store_id" => $store_id, "status" => 1), "id");
$remarks = $data['remarks'] ? $data['remarks'] : '';
if (!$warehouse_id) {
$res['status'] = 0;
$res['msg'] = "请先创建供给仓";
$this->ajaxReturn($res);
}
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_id . "_warehousing_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 120, $id);
}
$res = A("Api/Inventory")->goodsVerify($merchant_id, $store_id, $goodsList); //参数验证
if ($res['status'] == 1) {
$parameter = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'id' => $id, //入库单id
'type' => $data["type"],
'order_number' => $data["order_number"],
'goodsList' => $goodsList, //入库商品
'refuseList' => $refuseList, //拒收商品
'warehouse_id' => $warehouse_id, //仓库id
'remarks' => $remarks, //备注
'operator_id' => $data['operator_id'], //操作人id
);
$success = A("Api/Inventory")->allocationWarehousing($parameter); //入库操作
if ($success) {
$res['status'] = 1;
$res['msg'] = '操作成功';
} else {
$res['status'] = 0;
$res['msg'] = '操作失败';
}
}
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($res);
}
/*
* 门店申请调拨入库操作
*/
public function warehousingOperation()
{
$merchant_id = I("post.merchantid");
$store_id = I("post.storeid");
$id = I("post.id");
$goodsList = json_decode(htmlspecialchars_decode(I("post.goodsList")), true);
$refuseList = json_decode(htmlspecialchars_decode(I("post.refuse_list")), true);
$remarks = I("post.remarks");
if (!$id || !$goodsList) {
$res['status'] = 0;
$res['msg'] = '参数错误';
$this->ajaxReturn($res);
}
$info = D('AllocationOrder')->getFind(array('id' => $id));
if (!$info) {
$res['status'] = 0;
$res['msg'] = '未找到该订单';
$this->ajaxReturn($res);
}
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_id . "_allocation_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 60, $id);
}
$warehouse_id = D('SSaleWarehouse')->getFindField(array('store_id' => $store_id, 'merchant_id' => $merchant_id, 'status' => 1), "id");
$parameter = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'id' => $info['warehouse_order_id'],
'type' => 6, //申请调拨入库,
'order_number' => $info['order_number'],
'goodsList' => $goodsList,
'warehouse_id' => $warehouse_id,
'remarks' => $remarks,
'operator_id' => I("post.operator_id"),
'refuseList' => $refuseList,
);
$res = A('Api/Inventory')->allocationWarehousing($parameter);
if ($res['status'] == 1) {
$saveData = array(
'accept_goods_species' => $res['accept_goods_species'],
'accept_money_total' => $res['accept_money_total'],
'accept_total_cost_money' => $res['accept_total_cost_money'],
'status' => 3,
'storage_time' => time(),
);
if ($res['refuse_status'] == 2) {
//有拒收
$saveData['refuse_status'] = 2;
$saveData['refuse_total_cost_money'] = $res['refuse_total_cost_money'];
$saveData['refuse_total_stock_money'] = $res['refuse_total_stock_money'];
$saveData['refuse_goods_species'] = $res['refuse_goods_species'];
}
$res = D('AllocationOrder')->updateData(array('id' => $id), $saveData);
if ($res['status'] == 1) {
$log_data = [
'source' => 1,
'type' => 4,
'desc' => '调拨单-入库',
'request_data' => json_encode($_POST),
'operator_id' => I("post.operator_id"),
'mer_id' => $merchant_id
];
action_log_v2($log_data);
}
} else {
$res['status'] = 0;
$res['msg'] = '操作失败';
}
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($res);
}
/**
* 门店入库单ID获取单个入库详情信息
* @param
* [
* id 门店入库单id
* ]
*/
public function getStoreWarehousingInfo()
{
$id = I('post.id');
$warehousing = new WarehousingRecord();
$result = $warehousing->getStoreWarehousingOrderInfo($id);
$this->ajaxReturn($result);
}
/**
* 门店入库单拒绝入库操作
*/
public function storeRefuseWarehousing()
{
A('Terminalapi/RefuseWarehousing')->storeRefuseWarehousing();
}
public function refuse() {
A('Terminalapi/RefuseWarehousing')->refuse();
}
//拒收详情的串号列表
public function refuseSerial()
{
$data = I('post.');
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->refuseSerialList($data);
$this->ajaxReturn($result);
}
/**
* 门店拒收详情
* @param id 出库单id
* @param $type
*/
public function storeRefuseInfo()
{
$data = I("post.");
$id = $data['stock_out_id'];
$type = $data['type'];
switch ($type) {
case 4:
case 6:
$refuse_type = 1; //拒收商户调拨商品
break;
case 5:
$refuse_type = 2; //拒收门店调拨商品
break;
default:
$user_type = $data['user_type'];
switch ($user_type) {
case 1:
//商户调拨
$refuse_type = 1; //默认拒收商户调拨商品
break;
case 2:
//门店调拨
$refuse_type = 2; //默认拒收门店调拨商品
break;
}
break;
}
$RefuseWarehousing = new RefuseWarehousing();
$list = $RefuseWarehousing->refuseOrderList($id, $refuse_type);
$res = ['status' => 1, 'message' => '查询成功', 'data' => ['list' => $list]];
$this->ajaxReturn($res);
}
/**
* 门店入库单列表
* [
* merchant_id 商户id
* store_id 门店id
* order_number 入库订单号
* supplier_id 供货商id
* type 0其他入库 1采购入库 2补货入库 3盘盈入库 4商户调拨入库 5其他门店调拨入库 6门店申请调拨入库
* status 0入库出错 1入库成功
* start_time 入库开始时间 移动端
* end_time 入库结束时间 移动端
* operator_type 1后台 2收银 3助手
* ]
*/
public function SEnterOrderList()
{
$content = I("post.");
$content['merchant_id'] = $content['merchantid'];
$content['store_id'] = $content['storeid'];
$content['operator_type'] = 3;
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->storeWarehousingOrderList($content); //获取入库单列表
$res['status'] = 1;
$res['data'] = $result['data']['list'];
$res['msg'] = $result['message'];
$this->ajaxReturn($res);
}
/**
* 门店的调拨详情
* @parameter
* [
* id 门店的入库单id
* type 0其他入库 1采购入库 2补货入库 3盘盈入库 4商户调拨入库 5其他门店调拨入库 6门店申请调拨入库
* ]
*/
public function SAllocateDetails()
{
$data = I("post.");
$data['show_type'] = 2;
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->getStoreAllocationGoodsList($data); //获取调拨商品列表
$this->ajaxReturn($result);
}
//入库详情串号列表
public function storeDetailsSerial()
{
$data = I('post.');
$data['user_type'] = 4;
$data['serial_type'] = 2;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
/**
* 门店入库详情
*/
public function SEnterDetails()
{
$id = I("post.id"); //入库单id
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->getStoreWarehousingGoodsList(array('id' => $id)); //获取入库商品列表
$this->ajaxReturn($result);
}
/**
* 门店重新调拨获取出库单信息
*/
public function SStockInfo()
{
A('Terminalapi/SStock')->addStockOut();
}
/*
* 门店出库时仓库商品状态明细
*/
public function SStockGoods()
{
A('Terminalapi/SStock')->StockGoods();
}
//门店出库扫码查询
public function SStockScanCodeGoods_v1()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['user_type'] = 4;
$data['merchant_id'] = $data['merchantid'];
$data['store_id'] = $data['storeid'];
$SaleGoodsClass = new SaleGoods();
$result = $SaleGoodsClass->warehouseScanCodeGoods($data);
$this->ajaxReturn($result);
}
//门店出库提交页面数据初始化
public function addStockOutInitial()
{
$data = I('post.');
$StockRecordClass = new StockRecord();
$result = $StockRecordClass->addStockOutInitial($data);
$this->ajaxReturn($result);
}
/**
* 门店出库操作
*/
public function SStockOperation()
{
A('Terminalapi/SStock')->StockOperation();
}
/**
* 门店出库单列表
*/
public function SStockOrderList()
{
A('Terminalapi/SStock')->StockOrderList();
}
/**
* 门店出库详情列表
*/
public function SStockDetails()
{
A('Terminalapi/SStock')->StockDetails();
}
//商户门店出库单的详情的串号列表
public function stockGoodsInfoSerial()
{
$data = I('post.');
$data['serial_type'] = 3;
switch ($data['user_type']) {
case 1:
//商户
$data['user_type'] = 3;
break;
case 2:
case 3:
//门店
$data['user_type'] = 4;
break;
}
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
/**
* 门店出库单的入库详情列表
*/
public function SStockEnterDetails()
{
A('Terminalapi/SStock')->StockEnterDetails();
}
/**
* 门店采购单列表
*/
public function StorePurchaseOrder()
{
A('Terminalapi/StorePurchaseOrder')->PurchaseOrder();
}
/**
* 采购仓与供货商信息
*/
public function StoreWarehouseInfo()
{
A('Terminalapi/StorePurchaseOrder')->WarehouseInfo();
}
/**
* 门店采购选择商品列表
*/
public function StorePurGoods()
{
A('Terminalapi/StorePurchaseOrder')->GoodsInfo();
}
//采购串号验证
public function StorePurGoodsSerialVerify()
{
A('Terminalapi/StorePurchaseOrder')->serialVerify();
}
/**
* 门店采购选择商品列表2020-11-5
*/
public function StorePurGoods_v1()
{
A('Terminalapi/StorePurchaseOrder')->goodsList();
}
//门店采购选择商品列表2020-1-5
public function StorePurScanCodeGoods()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['user_type'] = 4;
$data['merchant_id'] = $data['merchantid'];
$data['store_id'] = $data['storeid'];
$SaleGoodsClass = new SaleGoods();
$result = $SaleGoodsClass->purchaseScanCodeGoods($data);
$this->ajaxReturn($result);
}
/**
* 门店采购提交操作
*/
public function StorePurchaseOperation()
{
A('Terminalapi/StorePurchaseOrder')->PurchaseOperation();
}
//门店采购详情串号列表
public function storePurDetailSerialList()
{
A('Terminalapi/StorePurchaseOrder')->detailSerialList();
}
/**
* 门店采购单详情
*/
public function StorePurDetails()
{
A('Terminalapi/StorePurchaseOrder')->PurchaseDetails();
}
/**
* 门店编辑采购单提交
*/
public function StorePurEdit()
{
A('Terminalapi/StorePurchaseOrder')->PurchaseOrderEdit();
}
/**
* 门店采购单入库到供给仓操作
*/
public function StoreWarehouseOperation()
{
A('Terminalapi/StorePurchaseOrder')->WarehousingOperation();
}
/**
*门店退货列表
*/
public function StoreRetreatOrder()
{
A('Terminalapi/StorePurchaseOrder')->RetreatOrder();
}
//采购退货详情的串号列表
public function storeRetreatDetailSerial()
{
A('Terminalapi/StorePurchaseOrder')->retreatDetailSerialList();
}
//门店采购退货详情
public function StoreRetreatDetails()
{
A('Terminalapi/StorePurchaseOrder')->RetreatDetails();
}
//门店采购退货串号列表
public function StoreRetreatGoodsSerial()
{
A('Terminalapi/StorePurchaseOrder')->serialList();
}
/**
* 门店采购退货选择的商品
*
*/
public function StoreRetreatGoods()
{
A('Terminalapi/StorePurchaseOrder')->RetreatGoods();
}
//采购退货扫码查询商品2020-11-5
public function StoreRetreatScanCodeGoods()
{
$data = I('post.');
$data['operator_type'] = 3;
$data['user_type'] = 4;
$data['merchant_id'] = $data['merchantid'];
$data['store_id'] = $data['storeid'];
$PurchaseGoodsClass = new PurchaseGoodsInfo();
$result = $PurchaseGoodsClass->returnablePurchaseScanCodeGoods($data);
$this->ajaxReturn($result);
}
/**
* 门店采购退货操作
*
*/
public function StoreRetreatAction()
{
A('Terminalapi/StorePurchaseOrder')->RetreatAction();
}
/**
* 门店报损列表
*/
public function StoreLossReportList()
{
A('Terminalapi/LossReport')->StoreLossReportList();
}
/**
* 门店报损商品列表
*/
public function StoreLossGoodsList()
{
A('Terminalapi/LossReport')->StoreLossGoodsList();
}
/**
* 门店提交报损操作
*/
public function StoreLossOperation()
{
A('Terminalapi/LossReport')->StoreLossOperation();
}
//门店报损详情
public function StoreLossInfo()
{
A('Terminalapi/LossReport')->StoreLossInfo();
}
public function storeLossInfoSerial()
{
A('Terminalapi/LossReport')->storeLossInfoSerial();
}
/**
* 会员分析-活跃会员
*/
public function MemberAnalyzeActive()
{
$type = I('post.type');
$store_id = I('post.store_id');
$merchant_id = I('post.merchant_id');
$MemberAnalyzeModel = new MemberAnalyzeModel();
$result = $MemberAnalyzeModel->getActiveUserBread($type, $store_id, $merchant_id);
$this->ajaxReturn($result);
}
/*
* 会员分析-根据月份获取用户数据
*/
public function MemberAnalyzeActiveList()
{
$timestamp = I('post.timestamp'); // 查询月份
$page = I('post.page') ? I('post.page') : 0;
$pageSize = I('post.pageSize') ? I('post.pageSize') : 10;
$type = I('post.type'); // 沉睡会员/活跃会员
$store_id = I('post.store_id');
$merchant_id = I('post.merchant_id');
$MemberAnalyzeModel = new MemberAnalyzeModel();
$result = $MemberAnalyzeModel->getActiveUserByMonth($timestamp, $type, $page, $pageSize, $store_id, $merchant_id);
$this->ajaxReturn($result);
}
/*
* 会员分析-会员生日统计
*/
public function MemberAnalyzeBirth()
{
$store_id = I('post.store_id');
$merchant_id = I('post.merchant_id');
$MemberAnalyzeModel = new MemberAnalyzeModel();
$result = $MemberAnalyzeModel->getBirthUserBread($merchant_id);
$this->ajaxReturn($result);
}
/*
* 会员分析-根据月份获取用户数据
*/
public function MemberAnalyzeBirthList()
{
$type = I('post.type');
$page = I('post.page') ? I('post.page') : 0;
$pageSize = I('post.pageSize') ? I('post.pageSize') : 10;
$store_id = I('post.store_id');
$merchant_id = I('post.merchant_id');
$MemberAnalyzeModel = new MemberAnalyzeModel();
$result = $MemberAnalyzeModel->getActiveUserByBirth($type, $page, $pageSize, $merchant_id);
$this->ajaxReturn($result);
}
/**
* 2021年1月9日11:25:19
* 助手商城收款统计
*/
public function getTerminalShopTotal()
{
$Statistics = new Statistics();
$result = $Statistics->getTerminalShopTotal([
'store_id' => I('post.store_id'),
'start_time' => I('post.start_time'),
'end_time' => I('post.end_time'),
]);
$this->ajaxReturn($result);
}
/**
* 2021年1月11日09:43:24
* 助手收银员收款统计
*/
public function getTerminalCashierTotal()
{
$Statistics = new Statistics();
$result = $Statistics->getTerminalCashierTotal([
'store_id' => I('post.store_id'),
'merchant_id' => I('post.merchant_id'),
'cashier_id' => I('post.cashier_id'),
'user_type' => I('post.user_type'),
'start_time' => I('post.start_time'),
'end_time' => I('post.end_time'),
]);
$this->ajaxReturn($result);
}
//串号修改
public function serialModify()
{
$data = I('post.');
$data['user_type'] = 6;
$data['operator_type'] = 3;
$data['cashier_id'] = $data['operator_id'];
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->serialModify($data);
$this->ajaxReturn($result);
}
//仓库的串号列表
public function SaleSerialList()
{
$data = I('post.');
switch ($data['user_type']) {
case 1:
$data['user_type'] = 3;
break;
case 2:
case 3:
$data['user_type'] = 4;
break;
}
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->warehouseSerialList($data);
$this->ajaxReturn($result);
}
// 获取流水
public function lineOrderTotal()
{
echo "10000";
}
}