123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- /**
- * 暂存Controller
- * Created by PhpStorm.
- * User: 小威
- * Date: 2020/03/30
- * Time: 16:30
- */
- namespace JinDouYun\Controller\Common;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Cache\PauseSave as CachePauseSave;
- class PauseSave extends BaseController
- {
- private $objCachePauseSave;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objCachePauseSave = new CachePauseSave($this->onlineEnterpriseId,$this->onlineUserId);
- }
- /**
- * 暂存添加
- */
- public function addPauseSave()
- {
- //获取数据
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('数据为空', ErrorCode::$paramError);
- }
- $key = isset($params['key']) ? $params['key'] : '';
- if(empty($key)){
- parent::sendOutput('参数错误', ErrorCode::$paramError);
- }
- $data = isset($params['data']) ? $params['data'] : [];
- if(empty($data)){
- parent::sendOutput('暂存数据为空', ErrorCode::$paramError);
- }
- //查询是否已有暂存
- //不用覆盖的原因是覆盖返回值是0
- $cacheResult = $this->objCachePauseSave->getCacheHash($key);
- if($cacheResult){
- //如果已有暂存 删除之前的暂存数据
- $delResult = $this->objCachePauseSave->delCacheHash($key);
- if(!$delResult){
- parent::sendOutput('删除缓存失败', ErrorCode::$paramError);
- }
- }
- //保存新的暂存
- $saveResult = $this->objCachePauseSave->addCacheHash($key, $data);
- if(!$saveResult){
- parent::sendOutput('缓存失败', ErrorCode::$paramError);
- }
- parent::sendOutput($saveResult);
- }
- /**
- * 暂存获取
- */
- public function getPauseSave()
- {
- $params = $this->request->getRawJson();
- $key = isset($params['key']) ? $params['key'] : '';
- if(empty($key)){
- parent::sendOutput('参数错误', ErrorCode::$paramError);
- }
- $cacheResult = $this->objCachePauseSave->getCacheHash($key);
- parent::sendOutput($cacheResult);
- }
- /**
- * 暂存删除
- */
- public function delPauseSave()
- {
- $params = $this->request->getRawJson();
- $key = isset($params['key']) ? $params['key'] : '';
- if(empty($key)){
- parent::sendOutput('参数错误', ErrorCode::$paramError);
- }
- $cacheResult = $this->objCachePauseSave->delCacheHash($key);
- parent::sendOutput($cacheResult);
- }
- /**************************************************** 价格暂存 ******************************************************/
- /**
- * 暂存添加
- * @throws Exception
- */
- public function addMoneyPauseSave()
- {
- //获取数据
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('数据为空', ErrorCode::$paramError);
- }
- $data = isset($params['data']) ? $params['data'] : [];
- if(empty($data)){
- parent::sendOutput('暂存数据为空', ErrorCode::$paramError);
- }
- $cacheData = [];
- foreach($data as $value){
- $cacheData[$value['skuId']] = sprintf("%.2f",substr(sprintf("%.3f", $value['money']), 0, -2));
- }
- //保存新的暂存
- $saveResult = $this->objCachePauseSave->addMoneyCache($cacheData);
- if(!$saveResult){
- parent::sendOutput('缓存失败', ErrorCode::$paramError);
- }
- parent::sendOutput($saveResult);
- }
- /**
- * 暂存获取
- */
- public function getMoneyPauseSave()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $array = isset($params['skuIds']) ? $params['skuIds'] : [];
- if(empty($array)){
- parent::sendOutput('参数错误', ErrorCode::$paramError);
- }
- $returnData = [];
- foreach($array as $skuId){
- $cacheResult = $this->objCachePauseSave->getMoneyCache($skuId);
- if($cacheResult){
- $returnData[$skuId] = sprintf("%.2f",substr(sprintf("%.3f", $cacheResult), 0, -2));
- }else{
- $returnData[$skuId] = 0.00;
- }
- }
- parent::sendOutput($returnData);
- }
- }
|