147 行
5.3 KiB
PHP
可执行文件
147 行
5.3 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace CashierApi\Controller;
|
|
|
|
use Think\Controller;
|
|
|
|
//[1.2.41]
|
|
|
|
class BaseController extends Controller
|
|
{
|
|
static $merchant_id; //商户id
|
|
static $store_id; //门店id
|
|
static $cashier_id; //收银员id
|
|
static $cashier; //收银员信息
|
|
static $store; //门店信息
|
|
static $merchant; //商户信息
|
|
static $record; //上班记录信息
|
|
protected $REQUEST_URL; //当前地址
|
|
protected $EMPTY_GOODS_IMG;//默认图片
|
|
|
|
public function _initialize()
|
|
{
|
|
$store_id = I('post.store_id'); //门店id
|
|
$cashier_id = I('post.cashier_id'); //收银员id
|
|
$merchant_id = I('post.merchant_id'); //商户id
|
|
$sign = I('post.sign');
|
|
if (empty($store_id)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '缺少必要参数store_id';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
if (empty($cashier_id)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '缺少必要参数cashier_id';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
if (empty($merchant_id)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '缺少必要参数merchant_id';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
if (empty($sign)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '缺少必要参数sign';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$RetailMerchantModel = D('RetailMerchant');
|
|
$merchantData = $RetailMerchantModel->getFindNormalMerchant($merchant_id);
|
|
if ($merchantData['status'] == 0) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = $merchantData['msg'];
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$merchant = $merchantData['data'];
|
|
$agentState = D('RetailAgent')->getFindNormalAgent($merchant[$RetailMerchantModel::AGENT_ID]);
|
|
if ($agentState['status'] != 1) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = $agentState['msg'];
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$CashierModel = D('RetailCashier');
|
|
$map = array(
|
|
$CashierModel::ID => $cashier_id,
|
|
$CashierModel::STORE_ID => $store_id,
|
|
$CashierModel::MERCHANT_ID => $merchant_id
|
|
);
|
|
$cashier = $CashierModel->getFind($map);
|
|
if (empty($cashier)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '收银员账号有误';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
$RetailStoreModel = D('RetailStore');
|
|
$map = array(
|
|
$RetailStoreModel::ID => $store_id,
|
|
$RetailStoreModel::STORE_STATUS => 0,
|
|
$RetailStoreModel::MERCHANT_ID => $merchant_id
|
|
);
|
|
$store = $RetailStoreModel->getFind($map); //判断门店是否正常使用中
|
|
if (empty($store)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '门店被禁用';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
$keyItem = S('cashier_key_item_' . $cashier[$CashierModel::ID]);//登录存储的数据
|
|
if (empty($keyItem)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '登录超时,请重新登录1';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$keyItem = json_decode($keyItem, true);
|
|
$post = I('post.');
|
|
// file_put_contents('face.txt', date('Y-m-d H:i:s') . ' check: ' . checkSign($post, $keyItem['key']) . "\r\n", FILE_APPEND);
|
|
if (!checkSign($post, $keyItem['key'])) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '登录超时,请重新登录';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
$WorkRecordModel = D('WorkRecord');
|
|
$map = array(
|
|
$WorkRecordModel::STORE_ID => $store_id,
|
|
$WorkRecordModel::CASHIER_ID => $cashier_id
|
|
);
|
|
$record = $WorkRecordModel->getOrderFind($map, '*', $WorkRecordModel::START_TIME . ' desc');
|
|
if (empty($record) || !empty($record[$WorkRecordModel::END_TIME])) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '收银员未在上班';
|
|
S('cashier_key_item_' . $cashier[$CashierModel::ID], null);//清除登录存储的数据
|
|
$this->ajaxReturn($result);
|
|
}
|
|
self::$record = $record;
|
|
self::$merchant_id = $merchant_id;
|
|
self::$store_id = $store_id;
|
|
self::$cashier_id = $cashier_id;
|
|
self::$merchant = $merchant;
|
|
self::$store = $store;
|
|
self::$cashier = $cashier;
|
|
$title = 'http';
|
|
if ($_SERVER['HTTPS'] == 'on') {
|
|
$title .= 's';
|
|
}
|
|
$this->REQUEST_URL = $title . '://' . $_SERVER['HTTP_HOST'];
|
|
$this->EMPTY_GOODS_IMG = D('GoodsDefaultImg')->getDefaultImg($store_id);
|
|
}
|
|
|
|
protected function getGoodsImage($img_id, $img_url = '')
|
|
{
|
|
$ImageGalleryModel = D('ImageGallery');
|
|
if (!empty($img_id)) {
|
|
$img_url = $ImageGalleryModel->getFieldPath(array('id' => $img_id));
|
|
if (!$img_url) {
|
|
$img_url = $this->EMPTY_GOODS_IMG;
|
|
}
|
|
} else {
|
|
if (!empty($imgUrl) && $img_url != '/Uploads') { // 处理图片
|
|
$img_url = $this->REQUEST_URL . $img_url;
|
|
} else {
|
|
$img_url = $this->EMPTY_GOODS_IMG;
|
|
}
|
|
}
|
|
return $img_url;
|
|
}
|
|
}
|