From c9ab982e686779c51c968ccee30da6b7295f9bd1 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Thu, 30 Jul 2020 16:01:19 +0800 Subject: [PATCH 01/66] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 28 +++++++++++++++++++++++ config/routes.php | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/Controller/CouponRebateController.php diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php new file mode 100644 index 0000000..7ed921d --- /dev/null +++ b/app/Controller/CouponRebateController.php @@ -0,0 +1,28 @@ +success('创建成功'); + } +} diff --git a/config/routes.php b/config/routes.php index 10aa6e4..ef01848 100644 --- a/config/routes.php +++ b/config/routes.php @@ -19,5 +19,5 @@ Router::addGroup('/v1/',function (){ Router::post('CouponUserReceive/getUserReceiveCouponList', 'App\Controller\CouponController@getUserReceiveCouponList'); Router::post('CouponUserReceive/userReceiveCoupon', 'App\Controller\CouponController@userReceiveCoupon'); Router::post('CouponUserReceive/getUserAvailableCoupons', 'App\Controller\CouponController@getUserAvailableCoupons'); - + Router::post('CoupontRebate/isCoupontRebate', 'App\Controller\CouponRebateController@isCouponRebate'); }); \ No newline at end of file From 82cdae3c0241e9033a44f2253c5ec16003254ea9 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 26 Jul 2020 12:53:19 +0800 Subject: [PATCH 02/66] =?UTF-8?q?=E5=97=AF=EF=BC=8Cparamstoken=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Envoy.blade.php | 6 + app/Controller/ParamsTokenController.php | 28 + app/Controller/TestController.php | 52 ++ app/Libs/SimpleSSDB.php | 622 ++++++++++++++++++++ app/Service/ParamsTokenServiceInterface.php | 11 + app/Service/ParamsTokenSsdbService.php | 17 + app/TaskWorker/SSDBTask.php | 39 ++ composer.json | 6 +- config/autoload/dependencies.php | 1 + config/autoload/server.php | 4 + config/autoload/translation.php | 16 + config/routes.php | 7 +- storage/languages/en/validation.php | 177 ++++++ storage/languages/zh_CN/validation.php | 177 ++++++ 14 files changed, 1161 insertions(+), 2 deletions(-) create mode 100644 app/Controller/ParamsTokenController.php create mode 100644 app/Controller/TestController.php create mode 100644 app/Libs/SimpleSSDB.php create mode 100644 app/Service/ParamsTokenServiceInterface.php create mode 100644 app/Service/ParamsTokenSsdbService.php create mode 100644 app/TaskWorker/SSDBTask.php create mode 100644 config/autoload/translation.php create mode 100644 storage/languages/en/validation.php create mode 100644 storage/languages/zh_CN/validation.php diff --git a/Envoy.blade.php b/Envoy.blade.php index db21e39..39d6cc9 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -11,11 +11,17 @@ @task('git_dev') cd /lanzu_api git pull origin develop + @if($composer == true) + composer update --lock + @endif supervisorctl restart lanzu_api @endtask @task('git_prod') cd /lanzu_api git pull origin master + @if($composer == true) + composer update --no-dev --lock + @endif supervisorctl restart lanzu_api @endtask diff --git a/app/Controller/ParamsTokenController.php b/app/Controller/ParamsTokenController.php new file mode 100644 index 0000000..0120c41 --- /dev/null +++ b/app/Controller/ParamsTokenController.php @@ -0,0 +1,28 @@ +paramsTokenService->generate($this->request->all()); + return $this->success($res); + } + + public function analyze() + { + $res = $this->paramsTokenService->analyze($this->request->input('token')); + return $this->success($res); + } +} \ No newline at end of file diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php new file mode 100644 index 0000000..bc034d0 --- /dev/null +++ b/app/Controller/TestController.php @@ -0,0 +1,52 @@ +get(TaskExecutor::class); + // $result = $exec->execute(new Task([MethodTask::class, 'handle'], [Coroutine::id()])); + + $client = ApplicationContext::getContainer()->get(SSDBTask::class); + $result = $client->exec("set","bar","1234"); + $result = $client->exec("get","bar"); + + // $client = ApplicationContext::getContainer()->get(MethodTask::class); + // $result = $client->handle("set"); + + $this->name = 'index1 action '. $result; + return $this->name; + } + + public function index2(RequestInterface $request) + { + $this->name = 'index2 action'; + return $this->name; + } + + public function index3(RequestInterface $request) + { + return $this->name; + } +} \ No newline at end of file diff --git a/app/Libs/SimpleSSDB.php b/app/Libs/SimpleSSDB.php new file mode 100644 index 0000000..b6920b2 --- /dev/null +++ b/app/Libs/SimpleSSDB.php @@ -0,0 +1,622 @@ +easy(); + } +} + +class SSDB_Response +{ + public $cmd; + public $code; + public $data = null; + public $message; + + function __construct($code='ok', $data_or_message=null){ + $this->code = $code; + if($code == 'ok'){ + $this->data = $data_or_message; + }else{ + $this->message = $data_or_message; + } + } + + function __toString(){ + if($this->code == 'ok'){ + $s = $this->data === null? '' : json_encode($this->data); + }else{ + $s = $this->message; + } + return sprintf('%-13s %12s %s', $this->cmd, $this->code, $s); + } + + function ok(){ + return $this->code == 'ok'; + } + + function not_found(){ + return $this->code == 'not_found'; + } +} + +// Depricated, use SimpleSSDB instead! +class SSDB +{ + private $debug = false; + public $sock = null; + private $_closed = false; + private $recv_buf = ''; + private $_easy = false; + public $last_resp = null; + + function __construct($host, $port, $timeout_ms=2000){ + $timeout_f = (float)$timeout_ms/1000; + $this->sock = @stream_socket_client("[$host]:$port", $errno, $errstr, $timeout_f); + if(!$this->sock){ + throw new SSDBException("$errno: $errstr"); + } + $timeout_sec = intval($timeout_ms/1000); + $timeout_usec = ($timeout_ms - $timeout_sec * 1000) * 1000; + @stream_set_timeout($this->sock, $timeout_sec, $timeout_usec); + if(function_exists('stream_set_chunk_size')){ + @stream_set_chunk_size($this->sock, 1024 * 1024); + } + } + + function set_timeout($timeout_ms){ + $timeout_sec = intval($timeout_ms/1000); + $timeout_usec = ($timeout_ms - $timeout_sec * 1000) * 1000; + @stream_set_timeout($this->sock, $timeout_sec, $timeout_usec); + } + + /** + * After this method invoked with yesno=true, all requesting methods + * will not return a SSDB_Response object. + * And some certain methods like get/zget will return false + * when response is not ok(not_found, etc) + */ + function easy(){ + $this->_easy = true; + } + + function close(){ + if(!$this->_closed){ + @fclose($this->sock); + $this->_closed = true; + $this->sock = null; + } + } + + function closed(){ + return $this->_closed; + } + + private $batch_mode = false; + private $batch_cmds = array(); + + function batch(){ + $this->batch_mode = true; + $this->batch_cmds = array(); + return $this; + } + + function multi(){ + return $this->batch(); + } + + function exec(){ + $ret = array(); + foreach($this->batch_cmds as $op){ + list($cmd, $params) = $op; + $this->send_req($cmd, $params); + } + foreach($this->batch_cmds as $op){ + list($cmd, $params) = $op; + $resp = $this->recv_resp($cmd, $params); + $resp = $this->check_easy_resp($cmd, $resp); + $ret[] = $resp; + } + $this->batch_mode = false; + $this->batch_cmds = array(); + return $ret; + } + + function request(){ + $args = func_get_args(); + $cmd = array_shift($args); + return $this->__call($cmd, $args); + } + + private $async_auth_password = null; + + function auth($password){ + $this->async_auth_password = $password; + return null; + } + + function __call($cmd, $params=array()){ + $cmd = strtolower($cmd); + if($this->async_auth_password !== null){ + $pass = $this->async_auth_password; + $this->async_auth_password = null; + $auth = $this->__call('auth', array($pass)); + if($auth !== true){ + throw new Exception("Authentication failed"); + } + } + + if($this->batch_mode){ + $this->batch_cmds[] = array($cmd, $params); + return $this; + } + + try{ + if($this->send_req($cmd, $params) === false){ + $resp = new SSDB_Response('error', 'send error'); + }else{ + $resp = $this->recv_resp($cmd, $params); + } + }catch(SSDBException $e){ + if($this->_easy){ + throw $e; + }else{ + $resp = new SSDB_Response('error', $e->getMessage()); + } + } + + if($resp->code == 'noauth'){ + $msg = $resp->message; + throw new Exception($msg); + } + + $resp = $this->check_easy_resp($cmd, $resp); + return $resp; + } + + private function check_easy_resp($cmd, $resp){ + $this->last_resp = $resp; + if($this->_easy){ + if($resp->not_found()){ + return NULL; + }else if(!$resp->ok() && !is_array($resp->data)){ + return false; + }else{ + return $resp->data; + } + }else{ + $resp->cmd = $cmd; + return $resp; + } + } + + function multi_set($kvs=array()){ + $args = array(); + foreach($kvs as $k=>$v){ + $args[] = $k; + $args[] = $v; + } + return $this->__call(__FUNCTION__, $args); + } + + function multi_hset($name, $kvs=array()){ + $args = array($name); + foreach($kvs as $k=>$v){ + $args[] = $k; + $args[] = $v; + } + return $this->__call(__FUNCTION__, $args); + } + + function multi_zset($name, $kvs=array()){ + $args = array($name); + foreach($kvs as $k=>$v){ + $args[] = $k; + $args[] = $v; + } + return $this->__call(__FUNCTION__, $args); + } + + function incr($key, $val=1){ + $args = func_get_args(); + return $this->__call(__FUNCTION__, $args); + } + + function decr($key, $val=1){ + $args = func_get_args(); + return $this->__call(__FUNCTION__, $args); + } + + function zincr($name, $key, $score=1){ + $args = func_get_args(); + return $this->__call(__FUNCTION__, $args); + } + + function zdecr($name, $key, $score=1){ + $args = func_get_args(); + return $this->__call(__FUNCTION__, $args); + } + + function zadd($key, $score, $value){ + $args = array($key, $value, $score); + return $this->__call('zset', $args); + } + + function zRevRank($name, $key){ + $args = func_get_args(); + return $this->__call("zrrank", $args); + } + + function zRevRange($name, $offset, $limit){ + $args = func_get_args(); + return $this->__call("zrrange", $args); + } + + function hincr($name, $key, $val=1){ + $args = func_get_args(); + return $this->__call(__FUNCTION__, $args); + } + + function hdecr($name, $key, $val=1){ + $args = func_get_args(); + return $this->__call(__FUNCTION__, $args); + } + + private function send_req($cmd, $params){ + $req = array($cmd); + foreach($params as $p){ + if(is_array($p)){ + $req = array_merge($req, $p); + }else{ + $req[] = $p; + } + } + return $this->send($req); + } + + private function recv_resp($cmd, $params){ + $resp = $this->recv(); + if($resp === false){ + return new SSDB_Response('error', 'Unknown error'); + }else if(!$resp){ + return new SSDB_Response('disconnected', 'Connection closed'); + } + if($resp[0] == 'noauth'){ + $errmsg = isset($resp[1])? $resp[1] : ''; + return new SSDB_Response($resp[0], $errmsg); + } + switch($cmd){ + case 'dbsize': + case 'ping': + case 'qset': + case 'getbit': + case 'setbit': + case 'countbit': + case 'strlen': + case 'set': + case 'setx': + case 'setnx': + case 'zset': + case 'hset': + case 'qpush': + case 'qpush_front': + case 'qpush_back': + case 'qtrim_front': + case 'qtrim_back': + case 'del': + case 'zdel': + case 'hdel': + case 'hsize': + case 'zsize': + case 'qsize': + case 'hclear': + case 'zclear': + case 'qclear': + case 'multi_set': + case 'multi_del': + case 'multi_hset': + case 'multi_hdel': + case 'multi_zset': + case 'multi_zdel': + case 'incr': + case 'decr': + case 'zincr': + case 'zdecr': + case 'hincr': + case 'hdecr': + case 'zget': + case 'zrank': + case 'zrrank': + case 'zcount': + case 'zsum': + case 'zremrangebyrank': + case 'zremrangebyscore': + case 'ttl': + case 'expire': + if($resp[0] == 'ok'){ + $val = isset($resp[1])? intval($resp[1]) : 0; + return new SSDB_Response($resp[0], $val); + }else{ + $errmsg = isset($resp[1])? $resp[1] : ''; + return new SSDB_Response($resp[0], $errmsg); + } + case 'zavg': + if($resp[0] == 'ok'){ + $val = isset($resp[1])? floatval($resp[1]) : (float)0; + return new SSDB_Response($resp[0], $val); + }else{ + $errmsg = isset($resp[1])? $resp[1] : ''; + return new SSDB_Response($resp[0], $errmsg); + } + case 'get': + case 'substr': + case 'getset': + case 'hget': + case 'qget': + case 'qfront': + case 'qback': + if($resp[0] == 'ok'){ + if(count($resp) == 2){ + return new SSDB_Response('ok', $resp[1]); + }else{ + return new SSDB_Response('server_error', 'Invalid response'); + } + }else{ + $errmsg = isset($resp[1])? $resp[1] : ''; + return new SSDB_Response($resp[0], $errmsg); + } + break; + case 'qpop': + case 'qpop_front': + case 'qpop_back': + if($resp[0] == 'ok'){ + $size = 1; + if(isset($params[1])){ + $size = intval($params[1]); + } + if($size <= 1){ + if(count($resp) == 2){ + return new SSDB_Response('ok', $resp[1]); + }else{ + return new SSDB_Response('server_error', 'Invalid response'); + } + }else{ + $data = array_slice($resp, 1); + return new SSDB_Response('ok', $data); + } + }else{ + $errmsg = isset($resp[1])? $resp[1] : ''; + return new SSDB_Response($resp[0], $errmsg); + } + break; + case 'keys': + case 'zkeys': + case 'hkeys': + case 'hlist': + case 'zlist': + case 'qslice': + if($resp[0] == 'ok'){ + $data = array(); + if($resp[0] == 'ok'){ + $data = array_slice($resp, 1); + } + return new SSDB_Response($resp[0], $data); + }else{ + $errmsg = isset($resp[1])? $resp[1] : ''; + return new SSDB_Response($resp[0], $errmsg); + } + case 'auth': + case 'exists': + case 'hexists': + case 'zexists': + if($resp[0] == 'ok'){ + if(count($resp) == 2){ + return new SSDB_Response('ok', (bool)$resp[1]); + }else{ + return new SSDB_Response('server_error', 'Invalid response'); + } + }else{ + $errmsg = isset($resp[1])? $resp[1] : ''; + return new SSDB_Response($resp[0], $errmsg); + } + break; + case 'multi_exists': + case 'multi_hexists': + case 'multi_zexists': + if($resp[0] == 'ok'){ + if(count($resp) % 2 == 1){ + $data = array(); + for($i=1; $idebug){ + echo '> ' . str_replace(array("\r", "\n"), array('\r', '\n'), $s) . "\n"; + } + try{ + while(true){ + $ret = @fwrite($this->sock, $s); + if($ret === false || $ret === 0){ + $this->close(); + throw new SSDBException('Connection lost'); + } + $s = substr($s, $ret); + if(strlen($s) == 0){ + break; + } + @fflush($this->sock); + } + }catch(Exception $e){ + $this->close(); + throw new SSDBException($e->getMessage()); + } + return $ret; + } + + function recv(){ + $this->step = self::STEP_SIZE; + while(true){ + $ret = $this->parse(); + if($ret === null){ + try{ + $data = @fread($this->sock, 1024 * 1024); + if($this->debug){ + echo '< ' . str_replace(array("\r", "\n"), array('\r', '\n'), $data) . "\n"; + } + }catch(Exception $e){ + $data = ''; + } + if($data === false || $data === ''){ + if(feof($this->sock)){ + $this->close(); + throw new SSDBException('Connection lost'); + }else{ + throw new SSDBTimeoutException('Connection timeout'); + } + } + $this->recv_buf .= $data; +# echo "read " . strlen($data) . " total: " . strlen($this->recv_buf) . "\n"; + }else{ + return $ret; + } + } + } + + const STEP_SIZE = 0; + const STEP_DATA = 1; + public $resp = array(); + public $step; + public $block_size; + + private function parse(){ + $spos = 0; + $epos = 0; + $buf_size = strlen($this->recv_buf); + // performance issue for large reponse + //$this->recv_buf = ltrim($this->recv_buf); + while(true){ + $spos = $epos; + if($this->step === self::STEP_SIZE){ + $epos = strpos($this->recv_buf, "\n", $spos); + if($epos === false){ + break; + } + $epos += 1; + $line = substr($this->recv_buf, $spos, $epos - $spos); + $spos = $epos; + + $line = trim($line); + if(strlen($line) == 0){ // head end + $this->recv_buf = substr($this->recv_buf, $spos); + $ret = $this->resp; + $this->resp = array(); + return $ret; + } + $this->block_size = intval($line); + $this->step = self::STEP_DATA; + } + if($this->step === self::STEP_DATA){ + $epos = $spos + $this->block_size; + if($epos <= $buf_size){ + $n = strpos($this->recv_buf, "\n", $epos); + if($n !== false){ + $data = substr($this->recv_buf, $spos, $epos - $spos); + $this->resp[] = $data; + $epos = $n + 1; + $this->step = self::STEP_SIZE; + continue; + } + } + break; + } + } + + // packet not ready + if($spos > 0){ + $this->recv_buf = substr($this->recv_buf, $spos); + } + return null; + } +} \ No newline at end of file diff --git a/app/Service/ParamsTokenServiceInterface.php b/app/Service/ParamsTokenServiceInterface.php new file mode 100644 index 0000000..440665f --- /dev/null +++ b/app/Service/ParamsTokenServiceInterface.php @@ -0,0 +1,11 @@ + 'zh_cjdianc/pages/couponrebate/index', 'previous_id' => 211, 'is_expired' => 2]; + } +} \ No newline at end of file diff --git a/app/TaskWorker/SSDBTask.php b/app/TaskWorker/SSDBTask.php new file mode 100644 index 0000000..9c6ef29 --- /dev/null +++ b/app/TaskWorker/SSDBTask.php @@ -0,0 +1,39 @@ +client()->__call($method,$args); + + return $result; + } + + protected function client(){ + if ($this->ss instanceof SimpleSSDB) { + return $this->ss; + } + + $this->ss = new SimpleSSDB(env('SSDB_HOST'), env('SSDB_PORT')); + $this->ss->auth(env('SSDB_AUTH')); + + return $this->ss; + + } +} + diff --git a/composer.json b/composer.json index 5d55e6c..3b9ff4f 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,11 @@ "hyperf/process": "~2.0.0", "hyperf/redis": "~2.0.0", "hyperf/constants": "~2.0.0", - "hyperf/model-cache": "~2.0.0" + "hyperf/model-cache": "~2.0.0", + "hyperf/filesystem": "^2.0", + "xxtime/flysystem-aliyun-oss": "^1.5", + "hyperf/validation": "^2.0", + "hyperf/task": "^2.0" }, "require-dev": { "swoole/ide-helper": "^4.5", diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 55b80d5..9096061 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -10,4 +10,5 @@ declare(strict_types=1); * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ return [ + \App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class ]; diff --git a/config/autoload/server.php b/config/autoload/server.php index d6211cc..f44b083 100644 --- a/config/autoload/server.php +++ b/config/autoload/server.php @@ -36,10 +36,14 @@ return [ 'max_request' => 100000, 'socket_buffer_size' => 2 * 1024 * 1024, 'buffer_output_size' => 2 * 1024 * 1024, + 'task_worker_num' => 8, + 'task_enable_coroutine' => false, ], 'callbacks' => [ SwooleEvent::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'], SwooleEvent::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'], SwooleEvent::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'], + SwooleEvent::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'], + SwooleEvent::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'], ], ]; diff --git a/config/autoload/translation.php b/config/autoload/translation.php new file mode 100644 index 0000000..35b9f06 --- /dev/null +++ b/config/autoload/translation.php @@ -0,0 +1,16 @@ + 'zh_CN', + 'fallback_locale' => 'en', + 'path' => BASE_PATH . '/storage/languages', +]; diff --git a/config/routes.php b/config/routes.php index ef01848..6e62af4 100644 --- a/config/routes.php +++ b/config/routes.php @@ -19,5 +19,10 @@ Router::addGroup('/v1/',function (){ Router::post('CouponUserReceive/getUserReceiveCouponList', 'App\Controller\CouponController@getUserReceiveCouponList'); Router::post('CouponUserReceive/userReceiveCoupon', 'App\Controller\CouponController@userReceiveCoupon'); Router::post('CouponUserReceive/getUserAvailableCoupons', 'App\Controller\CouponController@getUserAvailableCoupons'); - Router::post('CoupontRebate/isCoupontRebate', 'App\Controller\CouponRebateController@isCouponRebate'); + Router::post('ServiceEvaluate/evaluate', 'App\Controller\ServiceEvaluateController@evaluate'); + Router::post('ServiceEvaluate/getPersonnelInfo', 'App\Controller\ServiceEvaluateController@getPersonnelInfo'); + Router::post('ServiceEvaluate/getEvaluateList', 'App\Controller\ServiceEvaluateController@getEvaluateList'); + Router::get('test/index1', 'App\Controller\TestController@index1'); + Router::POST('ParamsToken/generate', 'App\Controller\ParamsTokenController@generate'); + Router::POST('ParamsToken/analyze', 'App\Controller\ParamsTokenController@analyze'); }); \ No newline at end of file diff --git a/storage/languages/en/validation.php b/storage/languages/en/validation.php new file mode 100644 index 0000000..5e128a6 --- /dev/null +++ b/storage/languages/en/validation.php @@ -0,0 +1,177 @@ + 'The :attribute must be accepted.', + 'active_url' => 'The :attribute is not a valid URL.', + 'after' => 'The :attribute must be a date after :date.', + 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', + 'alpha' => 'The :attribute may only contain letters.', + 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', + 'alpha_num' => 'The :attribute may only contain letters and numbers.', + 'array' => 'The :attribute must be an array.', + 'before' => 'The :attribute must be a date before :date.', + 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', + 'between' => [ + 'numeric' => 'The :attribute must be between :min and :max.', + 'file' => 'The :attribute must be between :min and :max kilobytes.', + 'string' => 'The :attribute must be between :min and :max characters.', + 'array' => 'The :attribute must have between :min and :max items.', + ], + 'boolean' => 'The :attribute field must be true or false.', + 'confirmed' => 'The :attribute confirmation does not match.', + 'date' => 'The :attribute is not a valid date.', + 'date_format' => 'The :attribute does not match the format :format.', + 'different' => 'The :attribute and :other must be different.', + 'digits' => 'The :attribute must be :digits digits.', + 'digits_between' => 'The :attribute must be between :min and :max digits.', + 'dimensions' => 'The :attribute has invalid image dimensions.', + 'distinct' => 'The :attribute field has a duplicate value.', + 'email' => 'The :attribute must be a valid email address.', + 'exists' => 'The selected :attribute is invalid.', + 'file' => 'The :attribute must be a file.', + 'filled' => 'The :attribute field is required.', + 'gt' => [ + 'numeric' => 'The :attribute must be greater than :value', + 'file' => 'The :attribute must be greater than :value kb', + 'string' => 'The :attribute must be greater than :value characters', + 'array' => 'The :attribute must be greater than :value items', + ], + 'gte' => [ + 'numeric' => 'The :attribute must be great than or equal to :value', + 'file' => 'The :attribute must be great than or equal to :value kb', + 'string' => 'The :attribute must be great than or equal to :value characters', + 'array' => 'The :attribute must be great than or equal to :value items', + ], + 'image' => 'The :attribute must be an image.', + 'in' => 'The selected :attribute is invalid.', + 'in_array' => 'The :attribute field does not exist in :other.', + 'integer' => 'The :attribute must be an integer.', + 'ip' => 'The :attribute must be a valid IP address.', + 'ipv4' => 'The :attribute must be a valid IPv4 address.', + 'ipv6' => 'The :attribute must be a valid IPv6 address.', + 'json' => 'The :attribute must be a valid JSON string.', + 'lt' => [ + 'numeric' => 'The :attribute must be less than :value', + 'file' => 'The :attribute must be less than :value kb', + 'string' => 'The :attribute must be less than :value characters', + 'array' => 'The :attribute must be less than :value items', + ], + 'lte' => [ + 'numeric' => 'The :attribute must be less than or equal to :value', + 'file' => 'The :attribute must be less than or equal to :value kb', + 'string' => 'The :attribute must be less than or equal to :value characters', + 'array' => 'The :attribute must be less than or equal to :value items', + ], + 'max' => [ + 'numeric' => 'The :attribute may not be greater than :max.', + 'file' => 'The :attribute may not be greater than :max kilobytes.', + 'string' => 'The :attribute may not be greater than :max characters.', + 'array' => 'The :attribute may not have more than :max items.', + ], + 'mimes' => 'The :attribute must be a file of type: :values.', + 'mimetypes' => 'The :attribute must be a file of type: :values.', + 'min' => [ + 'numeric' => 'The :attribute must be at least :min.', + 'file' => 'The :attribute must be at least :min kilobytes.', + 'string' => 'The :attribute must be at least :min characters.', + 'array' => 'The :attribute must have at least :min items.', + ], + 'not_in' => 'The selected :attribute is invalid.', + 'not_regex' => 'The :attribute cannot match a given regular rule.', + 'numeric' => 'The :attribute must be a number.', + 'present' => 'The :attribute field must be present.', + 'regex' => 'The :attribute format is invalid.', + 'required' => 'The :attribute field is required.', + 'required_if' => 'The :attribute field is required when :other is :value.', + 'required_unless' => 'The :attribute field is required unless :other is in :values.', + 'required_with' => 'The :attribute field is required when :values is present.', + 'required_with_all' => 'The :attribute field is required when :values is present.', + 'required_without' => 'The :attribute field is required when :values is not present.', + 'required_without_all' => 'The :attribute field is required when none of :values are present.', + 'same' => 'The :attribute and :other must match.', + 'size' => [ + 'numeric' => 'The :attribute must be :size.', + 'file' => 'The :attribute must be :size kilobytes.', + 'string' => 'The :attribute must be :size characters.', + 'array' => 'The :attribute must contain :size items.', + ], + 'starts_with' => 'The :attribute must be start with :values ', + 'string' => 'The :attribute must be a string.', + 'timezone' => 'The :attribute must be a valid zone.', + 'unique' => 'The :attribute has already been taken.', + 'uploaded' => 'The :attribute failed to upload.', + 'url' => 'The :attribute format is invalid.', + 'uuid' => 'The :attribute is invalid UUID.', + 'max_if' => [ + 'numeric' => 'The :attribute may not be greater than :max when :other is :value.', + 'file' => 'The :attribute may not be greater than :max kilobytes when :other is :value.', + 'string' => 'The :attribute may not be greater than :max characters when :other is :value.', + 'array' => 'The :attribute may not have more than :max items when :other is :value.', + ], + 'min_if' => [ + 'numeric' => 'The :attribute must be at least :min when :other is :value.', + 'file' => 'The :attribute must be at least :min kilobytes when :other is :value.', + 'string' => 'The :attribute must be at least :min characters when :other is :value.', + 'array' => 'The :attribute must have at least :min items when :other is :value.', + ], + 'between_if' => [ + 'numeric' => 'The :attribute must be between :min and :max when :other is :value.', + 'file' => 'The :attribute must be between :min and :max kilobytes when :other is :value.', + 'string' => 'The :attribute must be between :min and :max characters when :other is :value.', + 'array' => 'The :attribute must have between :min and :max items when :other is :value.', + ], + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ + + 'custom' => [ + 'attribute-name' => [ + 'rule-name' => 'custom-message', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | The following language lines are used to swap attribute place-holders + | with something more reader friendly such as E-Mail Address instead + | of "email". This simply helps us make messages a little cleaner. + | + */ + + 'attributes' => [], + 'phone_number' => 'The :attribute must be a valid phone number', + 'telephone_number' => 'The :attribute must be a valid telephone number', + + 'chinese_word' => 'The :attribute must contain valid characters(chinese/english character, number, underscore)', + 'sequential_array' => 'The :attribute must be sequential array', +]; diff --git a/storage/languages/zh_CN/validation.php b/storage/languages/zh_CN/validation.php new file mode 100644 index 0000000..8093224 --- /dev/null +++ b/storage/languages/zh_CN/validation.php @@ -0,0 +1,177 @@ + ':attribute 必须接受', + 'active_url' => ':attribute 必须是一个合法的 URL', + 'after' => ':attribute 必须是 :date 之后的一个日期', + 'after_or_equal' => ':attribute 必须是 :date 之后或相同的一个日期', + 'alpha' => ':attribute 只能包含字母', + 'alpha_dash' => ':attribute 只能包含字母、数字、中划线或下划线', + 'alpha_num' => ':attribute 只能包含字母和数字', + 'array' => ':attribute 必须是一个数组', + 'before' => ':attribute 必须是 :date 之前的一个日期', + 'before_or_equal' => ':attribute 必须是 :date 之前或相同的一个日期', + 'between' => [ + 'numeric' => ':attribute 必须在 :min 到 :max 之间', + 'file' => ':attribute 必须在 :min 到 :max kb 之间', + 'string' => ':attribute 必须在 :min 到 :max 个字符之间', + 'array' => ':attribute 必须在 :min 到 :max 项之间', + ], + 'boolean' => ':attribute 字符必须是 true 或 false, 1 或 0', + 'confirmed' => ':attribute 二次确认不匹配', + 'date' => ':attribute 必须是一个合法的日期', + 'date_format' => ':attribute 与给定的格式 :format 不符合', + 'different' => ':attribute 必须不同于 :other', + 'digits' => ':attribute 必须是 :digits 位', + 'digits_between' => ':attribute 必须在 :min 和 :max 位之间', + 'dimensions' => ':attribute 具有无效的图片尺寸', + 'distinct' => ':attribute 字段具有重复值', + 'email' => ':attribute 必须是一个合法的电子邮件地址', + 'exists' => '选定的 :attribute 是无效的', + 'file' => ':attribute 必须是一个文件', + 'filled' => ':attribute 的字段是必填的', + 'gt' => [ + 'numeric' => ':attribute 必须大于 :value', + 'file' => ':attribute 必须大于 :value kb', + 'string' => ':attribute 必须大于 :value 个字符', + 'array' => ':attribute 必须大于 :value 项', + ], + 'gte' => [ + 'numeric' => ':attribute 必须大于等于 :value', + 'file' => ':attribute 必须大于等于 :value kb', + 'string' => ':attribute 必须大于等于 :value 个字符', + 'array' => ':attribute 必须大于等于 :value 项', + ], + 'image' => ':attribute 必须是 jpg, jpeg, png, bmp 或者 gif 格式的图片', + 'in' => '选定的 :attribute 是无效的', + 'in_array' => ':attribute 字段不存在于 :other', + 'integer' => ':attribute 必须是个整数', + 'ip' => ':attribute 必须是一个合法的 IP 地址', + 'ipv4' => ':attribute 必须是一个合法的 IPv4 地址', + 'ipv6' => ':attribute 必须是一个合法的 IPv6 地址', + 'json' => ':attribute 必须是一个合法的 JSON 字符串', + 'lt' => [ + 'numeric' => ':attribute 必须小于 :value', + 'file' => ':attribute 必须小于 :value kb', + 'string' => ':attribute 必须小于 :value 个字符', + 'array' => ':attribute 必须小于 :value 项', + ], + 'lte' => [ + 'numeric' => ':attribute 必须小于等于 :value', + 'file' => ':attribute 必须小于等于 :value kb', + 'string' => ':attribute 必须小于等于 :value 个字符', + 'array' => ':attribute 必须小于等于 :value 项', + ], + 'max' => [ + 'numeric' => ':attribute 的最大值为 :max', + 'file' => ':attribute 的最大为 :max kb', + 'string' => ':attribute 的最大长度为 :max 字符', + 'array' => ':attribute 至多有 :max 项', + ], + 'mimes' => ':attribute 的文件类型必须是 :values', + 'mimetypes' => ':attribute 的文件MIME必须是 :values', + 'min' => [ + 'numeric' => ':attribute 的最小值为 :min', + 'file' => ':attribute 大小至少为 :min kb', + 'string' => ':attribute 的最小长度为 :min 字符', + 'array' => ':attribute 至少有 :min 项', + ], + 'not_in' => '选定的 :attribute 是无效的', + 'not_regex' => ':attribute 不能匹配给定的正则', + 'numeric' => ':attribute 必须是数字', + 'present' => ':attribute 字段必须存在', + 'regex' => ':attribute 格式是无效的', + 'required' => ':attribute 字段是必须的', + 'required_if' => ':attribute 字段是必须的当 :other 是 :value', + 'required_unless' => ':attribute 字段是必须的,除非 :other 是在 :values 中', + 'required_with' => ':attribute 字段是必须的当 :values 是存在的', + 'required_with_all' => ':attribute 字段是必须的当 :values 是存在的', + 'required_without' => ':attribute 字段是必须的当 :values 是不存在的', + 'required_without_all' => ':attribute 字段是必须的当 没有一个 :values 是存在的', + 'same' => ':attribute 和 :other 必须匹配', + 'size' => [ + 'numeric' => ':attribute 必须是 :size', + 'file' => ':attribute 必须是 :size kb', + 'string' => ':attribute 必须是 :size 个字符', + 'array' => ':attribute 必须包括 :size 项', + ], + 'starts_with' => ':attribute 必须以 :values 为开头', + 'string' => ':attribute 必须是一个字符串', + 'timezone' => ':attribute 必须是个有效的时区', + 'unique' => ':attribute 已存在', + 'uploaded' => ':attribute 上传失败', + 'url' => ':attribute 无效的格式', + 'uuid' => ':attribute 无效的UUID格式', + 'max_if' => [ + 'numeric' => '当 :other 为 :value 时 :attribute 不能大于 :max', + 'file' => '当 :other 为 :value 时 :attribute 不能大于 :max kb', + 'string' => '当 :other 为 :value 时 :attribute 不能大于 :max 个字符', + 'array' => '当 :other 为 :value 时 :attribute 最多只有 :max 个单元', + ], + 'min_if' => [ + 'numeric' => '当 :other 为 :value 时 :attribute 必须大于等于 :min', + 'file' => '当 :other 为 :value 时 :attribute 大小不能小于 :min kb', + 'string' => '当 :other 为 :value 时 :attribute 至少为 :min 个字符', + 'array' => '当 :other 为 :value 时 :attribute 至少有 :min 个单元', + ], + 'between_if' => [ + 'numeric' => '当 :other 为 :value 时 :attribute 必须介于 :min - :max 之间', + 'file' => '当 :other 为 :value 时 :attribute 必须介于 :min - :max kb 之间', + 'string' => '当 :other 为 :value 时 :attribute 必须介于 :min - :max 个字符之间', + 'array' => '当 :other 为 :value 时 :attribute 必须只有 :min - :max 个单元', + ], + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ + + 'custom' => [ + 'attribute-name' => [ + 'rule-name' => 'custom-message', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | The following language lines are used to swap attribute place-holders + | with something more reader friendly such as E-Mail Address instead + | of "email". This simply helps us make messages a little cleaner. + | + */ + + 'attributes' => [], + 'phone_number' => ':attribute 必须为一个有效的电话号码', + 'telephone_number' => ':attribute 必须为一个有效的手机号码', + + 'chinese_word' => ':attribute 必须包含以下有效字符 (中文/英文,数字, 下划线)', + 'sequential_array' => ':attribute 必须是一个有序数组', +]; From 1b5a51e1ad9cc63c336a1657db71df979ad501a3 Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 30 Jul 2020 18:42:28 +0800 Subject: [PATCH 03/66] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=B7=A8=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Middleware/CorsMiddleware.php | 34 +++++++++++++++++++++++++++++++ config/autoload/middlewares.php | 3 ++- config/routes.php | 4 ++-- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 app/Middleware/CorsMiddleware.php diff --git a/app/Middleware/CorsMiddleware.php b/app/Middleware/CorsMiddleware.php new file mode 100644 index 0000000..7fb6495 --- /dev/null +++ b/app/Middleware/CorsMiddleware.php @@ -0,0 +1,34 @@ +withHeader('Access-Control-Allow-Origin', '*') + ->withHeader('Access-Control-Allow-Credentials', 'true') + // Headers 可以根据实际情况进行改写。 + ->withHeader('Access-Control-Allow-Headers', 'DNT,Keep-Alive,User-Agent,Cache-Control,Content-Type,Authorization'); + + Context::set(ResponseInterface::class, $response); + + if ($request->getMethod() == 'OPTIONS') { + return $response; + } + + return $handler->handle($request); + } +} \ No newline at end of file diff --git a/config/autoload/middlewares.php b/config/autoload/middlewares.php index 8a27adf..292a74a 100644 --- a/config/autoload/middlewares.php +++ b/config/autoload/middlewares.php @@ -11,6 +11,7 @@ declare(strict_types=1); */ return [ 'http' => [ - \App\Middleware\Auth\ApiMiddleware::class + \App\Middleware\Auth\ApiMiddleware::class, + \App\Middleware\CorsMiddleware::class, ], ]; diff --git a/config/routes.php b/config/routes.php index 6e62af4..88b8a99 100644 --- a/config/routes.php +++ b/config/routes.php @@ -23,6 +23,6 @@ Router::addGroup('/v1/',function (){ Router::post('ServiceEvaluate/getPersonnelInfo', 'App\Controller\ServiceEvaluateController@getPersonnelInfo'); Router::post('ServiceEvaluate/getEvaluateList', 'App\Controller\ServiceEvaluateController@getEvaluateList'); Router::get('test/index1', 'App\Controller\TestController@index1'); - Router::POST('ParamsToken/generate', 'App\Controller\ParamsTokenController@generate'); - Router::POST('ParamsToken/analyze', 'App\Controller\ParamsTokenController@analyze'); + Router::post('ParamsToken/generate', 'App\Controller\ParamsTokenController@generate'); + Router::post('ParamsToken/analyze', 'App\Controller\ParamsTokenController@analyze'); }); \ No newline at end of file From 169e37abdd15ca7ae3a73b56869da846ce8f1b72 Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 3 Aug 2020 09:09:50 +0800 Subject: [PATCH 04/66] token --- app/Constants/ErrorCode.php | 5 +++ app/Controller/ParamsTokenController.php | 2 +- .../Handler/SsdbExceptionHandler.php | 37 +++++++++++++++++++ app/Exception/SsdbException.php | 18 +++++++++ app/Service/ParamsTokenSsdbService.php | 36 +++++++++++++++++- config/autoload/exceptions.php | 1 + 6 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 app/Exception/Handler/SsdbExceptionHandler.php create mode 100644 app/Exception/SsdbException.php diff --git a/app/Constants/ErrorCode.php b/app/Constants/ErrorCode.php index 0651e85..229e25e 100644 --- a/app/Constants/ErrorCode.php +++ b/app/Constants/ErrorCode.php @@ -23,4 +23,9 @@ class ErrorCode extends AbstractConstants * @Message("Server Error!") */ const SERVER_ERROR = 500; + + /** + * @Message("Ssdb Error!") + */ + const SSDB_ERROR = 600; } diff --git a/app/Controller/ParamsTokenController.php b/app/Controller/ParamsTokenController.php index 0120c41..8182bbd 100644 --- a/app/Controller/ParamsTokenController.php +++ b/app/Controller/ParamsTokenController.php @@ -17,7 +17,7 @@ class ParamsTokenController extends BaseController public function generate() { $res = $this->paramsTokenService->generate($this->request->all()); - return $this->success($res); + return $this->success(['token' => $res]); } public function analyze() diff --git a/app/Exception/Handler/SsdbExceptionHandler.php b/app/Exception/Handler/SsdbExceptionHandler.php new file mode 100644 index 0000000..8eeaa0e --- /dev/null +++ b/app/Exception/Handler/SsdbExceptionHandler.php @@ -0,0 +1,37 @@ +stopPropagation(); + + $content = json_encode( + [ + "status" => 'error', + "code" => ErrorCode::SSDB_ERROR, + "result" => [], + "message" => $throwable->getMessage() ?: ErrorCode::getMessage(ErrorCode::SSDB_ERROR) + ] + ); + + return $response->withHeader('Content-Type', 'application/json') + ->withStatus($throwable->status) + ->withBody(new SwooleStream($content)); + } + + public function isValid(Throwable $throwable): bool + { + return $throwable instanceof SsdbException; + } +} \ No newline at end of file diff --git a/app/Exception/SsdbException.php b/app/Exception/SsdbException.php new file mode 100644 index 0000000..c005c38 --- /dev/null +++ b/app/Exception/SsdbException.php @@ -0,0 +1,18 @@ +get(SSDBTask::class); + + $kvs = []; + foreach ($params as $key => $value) { + $kvs[] = $key; + $kvs[] = $value; + } + + if(false === $ssdb->exec('multi_hset', self::HASH_PREFIX.$token, $kvs)) { + throw new SsdbException(ErrorCode::SSDB_ERROR, 'token生成失败'); + } + + return $token; } public function analyze($token) { - return ['page' => 'zh_cjdianc/pages/couponrebate/index', 'previous_id' => 211, 'is_expired' => 2]; + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $params = $ssdb->exec('hgetall', self::HASH_PREFIX.$token); + + if (false === $params) { + throw new SsdbException(ErrorCode::SSDB_ERROR, 'token解析失败'); + } + + if (empty($params)) { + throw new SsdbException(ErrorCode::SSDB_ERROR, 'token不存在'); + } + + return $params; } + } \ No newline at end of file diff --git a/config/autoload/exceptions.php b/config/autoload/exceptions.php index 895bda9..6417a73 100644 --- a/config/autoload/exceptions.php +++ b/config/autoload/exceptions.php @@ -14,6 +14,7 @@ return [ 'http' => [ Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class, App\Exception\Handler\AppExceptionHandler::class, + App\Exception\Handler\SsdbExceptionHandler::class, ], ], ]; From 5a9ebaa2f68beccd2cb0e6add5b2090af188fd0f Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 3 Aug 2020 10:32:30 +0800 Subject: [PATCH 05/66] =?UTF-8?q?=E5=90=88=E5=B9=B6=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=B1=BB=E5=88=B0=E5=BD=93=E5=89=8D=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Commons/Log.php | 88 +++++++++++++++++++++++++++ app/Controller/AbstractController.php | 8 +++ app/Controller/TestController.php | 16 +++-- composer.json | 2 +- config/autoload/dependencies.php | 4 ++ 5 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 app/Commons/Log.php diff --git a/app/Commons/Log.php b/app/Commons/Log.php new file mode 100644 index 0000000..bf5fb24 --- /dev/null +++ b/app/Commons/Log.php @@ -0,0 +1,88 @@ +clientFactory = $clientFactory; + } + + public function getClient() + { + // $options 等同于 GuzzleHttp\Client 构造函数的 $config 参数 + $options = [ + 'timeout' => 2.0, + ]; + // $client 为协程化的 GuzzleHttp\Client 对象 + $client = $this->clientFactory->create($options); + + return $client; + } + + public function event($labels=null,$datas){ + + co(function () use ($labels,$datas){ + + $client = $this->getClient(); + $kv = []; + foreach ($datas as $key => $value) { + $kv[] = $key."=".$value; + } + $pushLabels = []; + + $event_name = 'event_'.env('APP_ENV'); + if(!empty($labels)) $pushLabels[$event_name] = $labels; + + /* + * data format: + curl -v -H "Content-Type: application/json" -XPOST -s "http://39.96.12.39:3100/loki/api/v1/push" --data-raw \ + '{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1596274538882028800", "fizzbuzz" ] ] }]}' + */ + $ts = $this->getMsecTime() . '000000'; + $datas = implode("&",$kv); + $values = [[$ts,$datas]]; + $app_name = env('APP_NAME').'_'.env('APP_ENV'); + + $pushLabels['app']= $app_name; + $pushDatas = [ + 'streams'=>[ + [ + 'stream'=>$pushLabels, + 'values'=>$values, + ] + ] + ]; + $client->post( + 'http://39.96.12.39:3100/loki/api/v1/push', + [ + 'headers'=>[ + 'Content-Type'=>'application/json' + ], + 'body' => json_encode($pushDatas) + ] + ); + //var_dump(json_encode($pushDatas) ); + }); + } + + + public function push($datas){ + $this->event(null,$datas); + } + + public function getMsecTime() + { + list($msec, $sec) = explode(' ', microtime()); + $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); + return $msectime; + } + +} diff --git a/app/Controller/AbstractController.php b/app/Controller/AbstractController.php index be3a537..b7429ea 100644 --- a/app/Controller/AbstractController.php +++ b/app/Controller/AbstractController.php @@ -15,9 +15,17 @@ use Hyperf\Di\Annotation\Inject; use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\HttpServer\Contract\ResponseInterface; use Psr\Container\ContainerInterface; +use App\Commons\Log; abstract class AbstractController { + + /** + * @Inject + * @var Log + */ + protected $log; + /** * @Inject * @var ContainerInterface diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php index bc034d0..f69cea8 100644 --- a/app/Controller/TestController.php +++ b/app/Controller/TestController.php @@ -11,6 +11,7 @@ use Hyperf\Utils\ApplicationContext; use Hyperf\Task\TaskExecutor; use Hyperf\Task\Task; use App\TaskWorker\SSDBTask; +use App\Commons\Log; /** * @AutoController() @@ -28,14 +29,21 @@ class TestController extends AbstractController // $exec = $container->get(TaskExecutor::class); // $result = $exec->execute(new Task([MethodTask::class, 'handle'], [Coroutine::id()])); - $client = ApplicationContext::getContainer()->get(SSDBTask::class); - $result = $client->exec("set","bar","1234"); - $result = $client->exec("get","bar"); + // $client = ApplicationContext::getContainer()->get(SSDBTask::class); + // $result = $client->exec("set","bar","1234"); + // $result = $client->exec("get","bar"); // $client = ApplicationContext::getContainer()->get(MethodTask::class); // $result = $client->handle("set"); - $this->name = 'index1 action '. $result; + + //$log = ApplicationContext::getContainer()->get(Log::class); + $log = $this->log; + + $log->push(['test'=>1,'user_id'=>290,'msg'=>'order']); + $log->event('t1',['test'=>1,'user_id'=>290,'msg'=>'order']); + + //$this->name = 'index1 action '. $result; return $this->name; } diff --git a/composer.json b/composer.json index 3b9ff4f..3d44a8c 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "hyperf/config": "~2.0.0", "hyperf/db-connection": "~2.0.0", "hyperf/framework": "~2.0.0", - "hyperf/guzzle": "~2.0.0", + "hyperf/guzzle": "^2.0", "hyperf/http-server": "~2.0.0", "hyperf/logger": "~2.0.0", "hyperf/memory": "~2.0.0", diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 9096061..547a711 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -10,5 +10,9 @@ declare(strict_types=1); * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ return [ + \App\Service\ServiceEvaluateServiceInterface::class => \App\Service\ServiceEvaluateService::class, + \App\Service\AttachmentServiceInterface::class => \App\Service\AttachmentService::class, + \App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class, \App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class + \App\Commons\Log::class => \App\Commons\Log::class, ]; From 1555fe2a07fd64f84f7fd498b0e55518d2306c9d Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 3 Aug 2020 10:48:41 +0800 Subject: [PATCH 06/66] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/autoload/dependencies.php | 1 - 1 file changed, 1 deletion(-) diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 547a711..80f707b 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -13,6 +13,5 @@ return [ \App\Service\ServiceEvaluateServiceInterface::class => \App\Service\ServiceEvaluateService::class, \App\Service\AttachmentServiceInterface::class => \App\Service\AttachmentService::class, \App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class, - \App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class \App\Commons\Log::class => \App\Commons\Log::class, ]; From 6ab5eff503ebe101a9901737eddc65e6278185a0 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Mon, 3 Aug 2020 17:00:37 +0800 Subject: [PATCH 07/66] =?UTF-8?q?=E8=BF=94=E5=88=B8=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 16 ++++++++++------ app/CouponRebate/CouponRebate.php | 19 +++++++++++++++++++ app/CouponRebate/CouponRebateInterface.php | 10 ++++++++++ config/autoload/dependencies.php | 1 + config/routes.php | 1 + 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 app/CouponRebate/CouponRebate.php create mode 100644 app/CouponRebate/CouponRebateInterface.php diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 7ed921d..3d344cb 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -11,18 +11,22 @@ declare(strict_types=1); */ namespace App\Controller; - -use App\Model\CouponUserRecType; -use App\Model\Coupon; -use App\Model\CouponRec; use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; use Hyperf\Utils\ApplicationContext; - +use App\CouponRebate\CouponRebateInterface; +use http\Client\Curl\User; +use Hyperf\Di\Annotation\Inject; class CouponRebateController extends BaseController { + /** + * @Inject + * @var CouponRebateInterface + */ + protected $CouponRebate; public function isCouponRebate() { - return $this->success('创建成功'); + $res = $this->CouponRebate->isCouponRebate('测试数据'); + return $this->success($res); } } diff --git a/app/CouponRebate/CouponRebate.php b/app/CouponRebate/CouponRebate.php new file mode 100644 index 0000000..d006177 --- /dev/null +++ b/app/CouponRebate/CouponRebate.php @@ -0,0 +1,19 @@ + \App\Service\AttachmentService::class, \App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class, \App\Commons\Log::class => \App\Commons\Log::class, + \App\CouponRebate\CouponRebateInterface::class => \App\CouponRebate\CouponRebate::class, ]; diff --git a/config/routes.php b/config/routes.php index 88b8a99..7305ea3 100644 --- a/config/routes.php +++ b/config/routes.php @@ -25,4 +25,5 @@ Router::addGroup('/v1/',function (){ Router::get('test/index1', 'App\Controller\TestController@index1'); Router::post('ParamsToken/generate', 'App\Controller\ParamsTokenController@generate'); Router::post('ParamsToken/analyze', 'App\Controller\ParamsTokenController@analyze'); + Router::post('CouponRebate/isCouponRebate', 'App\Controller\CouponRebateController@isCouponRebate'); }); \ No newline at end of file From 96cc3ef11a5408d1c36ff4be83268e33c7a07e19 Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 3 Aug 2020 17:31:16 +0800 Subject: [PATCH 08/66] =?UTF-8?q?=E5=88=86=E4=BA=AB=E9=A1=B5token=E3=80=81?= =?UTF-8?q?=E9=A6=96=E9=A1=B5banner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/ErrorCode.php | 5 + app/Constants/LogLabel.php | 19 +++ app/Constants/SsdbKeysPrefix.php | 19 +++ app/Controller/AdController.php | 27 +++++ app/Controller/ParamsTokenController.php | 22 +++- .../Handler/SsdbExceptionHandler.php | 14 +-- .../Handler/ValidationExceptionHandler.php | 35 ++++++ .../ValidatorFactoryResolvedListener.php | 113 ++++++++++++++++++ app/Model/Ad.php | 70 +++++++++++ app/Service/AdService.php | 20 ++++ app/Service/AdServiceInterface.php | 11 ++ app/Service/ParamsTokenServiceInterface.php | 13 +- app/Service/ParamsTokenSsdbService.php | 41 ++++++- config/autoload/dependencies.php | 1 + config/autoload/exceptions.php | 1 + config/autoload/listeners.php | 1 + config/autoload/middlewares.php | 1 + config/routes.php | 1 + 18 files changed, 395 insertions(+), 19 deletions(-) create mode 100644 app/Constants/LogLabel.php create mode 100644 app/Constants/SsdbKeysPrefix.php create mode 100644 app/Controller/AdController.php create mode 100644 app/Exception/Handler/ValidationExceptionHandler.php create mode 100644 app/Listener/ValidatorFactoryResolvedListener.php create mode 100644 app/Model/Ad.php create mode 100644 app/Service/AdService.php create mode 100644 app/Service/AdServiceInterface.php diff --git a/app/Constants/ErrorCode.php b/app/Constants/ErrorCode.php index 229e25e..506e36c 100644 --- a/app/Constants/ErrorCode.php +++ b/app/Constants/ErrorCode.php @@ -24,6 +24,11 @@ class ErrorCode extends AbstractConstants */ const SERVER_ERROR = 500; + /** + * @Message("Params Invalid!") + */ + const PARAMS_INVALID = 900; + /** * @Message("Ssdb Error!") */ diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php new file mode 100644 index 0000000..2265cf4 --- /dev/null +++ b/app/Constants/LogLabel.php @@ -0,0 +1,19 @@ +success($this->adService->banners()); + } +} diff --git a/app/Controller/ParamsTokenController.php b/app/Controller/ParamsTokenController.php index 8182bbd..db1cdca 100644 --- a/app/Controller/ParamsTokenController.php +++ b/app/Controller/ParamsTokenController.php @@ -1,11 +1,15 @@ paramsTokenService->generate($this->request->all()); - return $this->success(['token' => $res]); + $token = $this->paramsTokenService->generate($this->request->all()); + return $this->success(['token' => $token]); } + /** + * 解析token获取对应参数数据 + * @return \Psr\Http\Message\ResponseInterface + */ public function analyze() { - $res = $this->paramsTokenService->analyze($this->request->input('token')); - return $this->success($res); + $params = $this->paramsTokenService->analyze($this->request->input('token')); + return $this->success($params); } } \ No newline at end of file diff --git a/app/Exception/Handler/SsdbExceptionHandler.php b/app/Exception/Handler/SsdbExceptionHandler.php index 8eeaa0e..118d5ef 100644 --- a/app/Exception/Handler/SsdbExceptionHandler.php +++ b/app/Exception/Handler/SsdbExceptionHandler.php @@ -16,18 +16,14 @@ class SsdbExceptionHandler extends ExceptionHandler { $this->stopPropagation(); - $content = json_encode( - [ + $content = json_encode([ "status" => 'error', - "code" => ErrorCode::SSDB_ERROR, + "code" => $throwable->getCode(), "result" => [], - "message" => $throwable->getMessage() ?: ErrorCode::getMessage(ErrorCode::SSDB_ERROR) - ] - ); + "message" => $throwable->getMessage() + ]); - return $response->withHeader('Content-Type', 'application/json') - ->withStatus($throwable->status) - ->withBody(new SwooleStream($content)); + return $response->withHeader('Content-Type', 'application/json')->withBody(new SwooleStream($content)); } public function isValid(Throwable $throwable): bool diff --git a/app/Exception/Handler/ValidationExceptionHandler.php b/app/Exception/Handler/ValidationExceptionHandler.php new file mode 100644 index 0000000..cc2384c --- /dev/null +++ b/app/Exception/Handler/ValidationExceptionHandler.php @@ -0,0 +1,35 @@ +stopPropagation(); + + $content = json_encode([ + "status" => 'error', + "code" => ErrorCode::PARAMS_INVALID, + "result" => [], + "message" => $throwable->validator->errors()->first() + ]); + + return $response->withHeader('Content-Type', 'application/json') + ->withStatus($throwable->status) + ->withBody(new SwooleStream($content)); + } + + public function isValid(Throwable $throwable): bool + { + return $throwable instanceof ValidationException; + } +} \ No newline at end of file diff --git a/app/Listener/ValidatorFactoryResolvedListener.php b/app/Listener/ValidatorFactoryResolvedListener.php new file mode 100644 index 0000000..75b3a36 --- /dev/null +++ b/app/Listener/ValidatorFactoryResolvedListener.php @@ -0,0 +1,113 @@ +validatorFactory; + + // 注册了 nonempty 验证器规则 + $validatorFactory->extend('nonempty', function ($attribute, $value, $parameters, $validator) { + + return isset($value) + && $value + && !empty($value) + && !is_null($value) + && $value != 'undefined' + && $value != 'unknown' + && $value != 'null' + && $value != 'false'; + + }); + + // 注册了 strlen 验证器规则,参数是min,max,最小长度和最大长度 + $validatorFactory->extend('strlen', function ($attribute, $value, $parameters, $validator) { + return mb_strlen($value)>=$parameters[0] && mb_strlen($value)<=$parameters[1]; + }); + $validatorFactory->replacer('strlen', function ($message, $attribute, $rule, $parameters) { + $message = str_replace(':min', $parameters[0], $message); + $message = str_replace(':max', $parameters[1], $message); + return $message; + }); + + // 注册了 base64 验证器规则 + $validatorFactory->extend('base64', function ($attribute, $value, $parameters, $validator) { + + preg_match('/^(data:\s*image\/(\w+);base64,)/', $value, $result); + + if (empty($result)) { + return false; + } + + if ( + in_array('image', $parameters) + && !in_array($result[2], ['jpg','jpeg','png','gif','svg','bmp']) + ) { + return false; + } + + return true; + + }); + + // 注册了 ext_not_in 验证器规则 + $validatorFactory->extend('ext_not_in', function ($attribute, $value, $parameters, $validator) { + + if (empty($parameters)) { + $parameters = ['', 'php', 'exe', 'sql', 'sh', 'bat', 'py', 'go', 'c', 'cpp']; + } + return !in_array($value->getExtension(), $parameters); + + }); + + // 注册了 exists_enable 验证器规则,参数是table,field,where1,where2... + $validatorFactory->extend('exists_enable', function ($attribute, $value, $parameters, $validator) { + + // 查询 + $builder = Db::table($parameters[0])->where($parameters[1], '=', $value); + + $whereArr = array_slice($parameters,2); + if (!empty($whereArr)) { + foreach ($whereArr as $key => $where) { + $builder->whereRaw($where); + } + } + + return $builder->exists(); + }); + + // 注册了 not_equal 验证器规则,参数是anotherfield,table,primary_field,foreign_field + // 要排除对比的字段请求参数名、表名、本参数对应表id、比较字段 + $validatorFactory->extend('not_equal', function ($attribute, $value, $parameters, $validator) { + + // 获取比较字段参数值 + $foreignValue = $validator->getData()[$parameters[0]]; + + // 查询 + $builder = Db::table($parameters[1]) + ->where($parameters[2], '=', $value) + ->where($parameters[3], '!=', $foreignValue) + ; + + return $builder->exists(); + }); + } +} \ No newline at end of file diff --git a/app/Model/Ad.php b/app/Model/Ad.php new file mode 100644 index 0000000..71cdbf9 --- /dev/null +++ b/app/Model/Ad.php @@ -0,0 +1,70 @@ + 'page', + 2 => 'webview', + 3 => 'applet', + ]; + + /** + * 类型 1 = 首页banners + */ + const TYPE_BANNER = 1; + + /** + * 启用状态 + */ + const STATUS_YES = 1; + const STATUS_NO = 2; + + /** + * The table associated with the model. + * + * @var string + */ + protected $table = 'ims_cjdc_ad'; + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = []; + /** + * The attributes that should be cast to native types. + * + * @var array + */ + protected $casts = []; + + protected $appends = [ + 'item_text', + 'redirect_url' + ]; + + /** + * 获取跳转说明 + */ + public function getItemTextAttribute() + { + return self::ITEM[$this->item]; + } + + /** + * 获取跳转连接 + */ + public function getRedirectUrlAttribute() + { + return $this->src ?: $this->src2; + } +} \ No newline at end of file diff --git a/app/Service/AdService.php b/app/Service/AdService.php new file mode 100644 index 0000000..77170ac --- /dev/null +++ b/app/Service/AdService.php @@ -0,0 +1,20 @@ +select(['id','title','logo','item','src','src2']) + ->where([ + 'type' => Ad::TYPE_BANNER, + 'status' => Ad::STATUS_YES + ])->get(); + } +} \ No newline at end of file diff --git a/app/Service/AdServiceInterface.php b/app/Service/AdServiceInterface.php new file mode 100644 index 0000000..f488422 --- /dev/null +++ b/app/Service/AdServiceInterface.php @@ -0,0 +1,11 @@ +exec('multi_hset', self::HASH_PREFIX.$token, $kvs)) { + if(false === $ssdb->exec('multi_hset', SsdbKeysPrefix::PARAMS_TOKEN.$token, $kvs)) { + + $this->log->event( + LogLabel::SSDB_LOG, + ['method' => 'multi_hset', 'key' => SsdbKeysPrefix::PARAMS_TOKEN.$token, 'kvs' => $kvs] + ); + throw new SsdbException(ErrorCode::SSDB_ERROR, 'token生成失败'); } return $token; } + /** + * 解析token获取对应数据参数 + * @param $token + */ public function analyze($token) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $params = $ssdb->exec('hgetall', self::HASH_PREFIX.$token); + $params = $ssdb->exec('hgetall', SsdbKeysPrefix::PARAMS_TOKEN.$token); if (false === $params) { + + $this->log->event( + LogLabel::SSDB_LOG, + ['method' => 'hgetall', 'key' => SsdbKeysPrefix::PARAMS_TOKEN.$token, 'params' => $params] + ); + throw new SsdbException(ErrorCode::SSDB_ERROR, 'token解析失败'); } if (empty($params)) { + + $this->log->event( + LogLabel::SSDB_LOG, + ['method' => 'hgetall', 'key' => SsdbKeysPrefix::PARAMS_TOKEN.$token, 'params' => $params] + ); + throw new SsdbException(ErrorCode::SSDB_ERROR, 'token不存在'); } diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 80f707b..74f9420 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -13,5 +13,6 @@ return [ \App\Service\ServiceEvaluateServiceInterface::class => \App\Service\ServiceEvaluateService::class, \App\Service\AttachmentServiceInterface::class => \App\Service\AttachmentService::class, \App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class, + \App\Service\AdServiceInterface::class => \App\Service\AdService::class, \App\Commons\Log::class => \App\Commons\Log::class, ]; diff --git a/config/autoload/exceptions.php b/config/autoload/exceptions.php index 6417a73..0aa0812 100644 --- a/config/autoload/exceptions.php +++ b/config/autoload/exceptions.php @@ -14,6 +14,7 @@ return [ 'http' => [ Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class, App\Exception\Handler\AppExceptionHandler::class, + App\Exception\Handler\ValidationExceptionHandler::class, App\Exception\Handler\SsdbExceptionHandler::class, ], ], diff --git a/config/autoload/listeners.php b/config/autoload/listeners.php index 55b80d5..2741751 100644 --- a/config/autoload/listeners.php +++ b/config/autoload/listeners.php @@ -10,4 +10,5 @@ declare(strict_types=1); * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ return [ + \App\Listener\ValidatorFactoryResolvedListener::class, ]; diff --git a/config/autoload/middlewares.php b/config/autoload/middlewares.php index 292a74a..5eb19a5 100644 --- a/config/autoload/middlewares.php +++ b/config/autoload/middlewares.php @@ -12,6 +12,7 @@ declare(strict_types=1); return [ 'http' => [ \App\Middleware\Auth\ApiMiddleware::class, + \Hyperf\Validation\Middleware\ValidationMiddleware::class, \App\Middleware\CorsMiddleware::class, ], ]; diff --git a/config/routes.php b/config/routes.php index 88b8a99..97cea66 100644 --- a/config/routes.php +++ b/config/routes.php @@ -25,4 +25,5 @@ Router::addGroup('/v1/',function (){ Router::get('test/index1', 'App\Controller\TestController@index1'); Router::post('ParamsToken/generate', 'App\Controller\ParamsTokenController@generate'); Router::post('ParamsToken/analyze', 'App\Controller\ParamsTokenController@analyze'); + Router::post('Ad/banners', 'App\Controller\AdController@banners'); }); \ No newline at end of file From dbe2c06e9764f96ed845c4962723ce19b1d0aca8 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Mon, 3 Aug 2020 17:48:06 +0800 Subject: [PATCH 09/66] =?UTF-8?q?=E5=88=A4=E6=96=AD=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E9=A2=86=E8=BF=87=E5=88=86=E4=BA=AB=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BC=98=E6=83=A0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 3 ++- app/CouponRebate/CouponRebate.php | 13 ++++++++++--- app/CouponRebate/CouponRebateInterface.php | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 3d344cb..3f90802 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -26,7 +26,8 @@ class CouponRebateController extends BaseController protected $CouponRebate; public function isCouponRebate() { - $res = $this->CouponRebate->isCouponRebate('测试数据'); + $user_id = $this->request->input('user_id', 0); + $res = $this->CouponRebate->isCouponRebate($user_id); return $this->success($res); } } diff --git a/app/CouponRebate/CouponRebate.php b/app/CouponRebate/CouponRebate.php index d006177..88f8d7f 100644 --- a/app/CouponRebate/CouponRebate.php +++ b/app/CouponRebate/CouponRebate.php @@ -10,10 +10,17 @@ use Hyperf\Paginator\Paginator; class CouponRebate implements CouponRebateInterface { - public function isCouponRebate($data) + public function isCouponRebate($user_id) { - // 当前用户是否今日新注册并第一次提交评论 - return $data; + $res = Db::table('ims_system_coupon_user as u') + ->join('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') + ->where([ + ['r.user_id','=',$user_id], + ['u.active_type','=',2] + ]) + ->select('r.id') + ->first(); + return $res; } } \ No newline at end of file diff --git a/app/CouponRebate/CouponRebateInterface.php b/app/CouponRebate/CouponRebateInterface.php index 8f18adb..8c63313 100644 --- a/app/CouponRebate/CouponRebateInterface.php +++ b/app/CouponRebate/CouponRebateInterface.php @@ -5,6 +5,6 @@ namespace App\CouponRebate; interface CouponRebateInterface { - public function isCouponRebate($data); + public function isCouponRebate($user_id); } \ No newline at end of file From f6eb266a86d1c0e1eb9bd20047386624b9ba9f5f Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 4 Aug 2020 11:56:57 +0800 Subject: [PATCH 10/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E6=B7=BB=E5=8A=A0=E9=A2=86=E5=8F=96=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 1 + app/Controller/CouponRebateController.php | 91 ++++++++++++++++++++++ app/Request/couponRebateReceiveRequest.php | 48 ++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 app/Request/couponRebateReceiveRequest.php diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index 409c2cf..5152e63 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -67,6 +67,7 @@ class CouponController extends BaseController ['u.end_time','>',$nowTime], ['u.start_time','<=',$nowTime], ['u.status','=',1], + ['u.active_type','=',1], ]; if (env('SUB_CHANNEL') == 1) { diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 3f90802..12696a6 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -17,6 +17,10 @@ use Hyperf\Utils\ApplicationContext; use App\CouponRebate\CouponRebateInterface; use http\Client\Curl\User; use Hyperf\Di\Annotation\Inject; +use App\Model\Coupon; +use App\Model\CouponUserRecType; +use App\Model\CouponRec; +use App\Request\CouponRebateReceiveRequest; class CouponRebateController extends BaseController { /** @@ -30,4 +34,91 @@ class CouponRebateController extends BaseController $res = $this->CouponRebate->isCouponRebate($user_id); return $this->success($res); } + + /** + * 用户领取优惠券 + */ + public function userReceiveCouponA(couponRebateReceiveRequest $validator) + { + $userId = $this->request->input("user_id", 0); + $receiveType = $this->request->input("receive_type", 0); + $ids = $this->request->input("ids", ''); + $sendUserId = $this->request->input("send_user_id", 0); + $phone = $this->request->input("phone", ''); + $ids = explode(',', $ids); + $now = time(); + + // moke 数据 给前端用 + $test = $this->request->input("test", 0); + if($test){ + $cps = Coupon::whereIn('id', $ids)->lockForUpdate()->first(); + return $this->success([ + 'success' => [$cps], + 'fail' => [], + ]); + } + + $success = []; + $fail = []; + + Db::transaction( function () use ($ids,$receiveType,$userId,$sendUserId,$phone,&$success,&$fail,$now) { + //读写锁,完全控制,性能低 + $cps = Coupon::whereIn('id', $ids)->lockForUpdate() + ->select('id','title','status','inventory','inventory_use','start_time','end_time') + ->get(); + + foreach ($cps as $key => $cp) { + + $where = [ + 'system_coupon_user_id' => $cp->id, + ]; + + if (env('SUB_CHANNEL') == 1) { + $where['receive_type'] = $receiveType; + } + + $crt = CouponUserRecType::where($where)->first(); + + $cr = new CouponRec; + $cr->user_id = $userId; + $cr->system_coupon_user_id = $cp->id; + $cr->order_main_id = 0; + $cr->receive_time = $now; + $cr->number = $crt->one_receive_number; + $cr->number_remain = $crt->one_receive_number; + $cr->status = 0; + $cr->update_time = $now; + $cr->receive_type = $receiveType; + $cr->send_user_id = $sendUserId; + $cr->phone = $phone; + //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 + if ( + $cp->status != 1 + || + $cp->inventory <= $cp->inventory_use + || + $cp->inventory < ($cp->inventory_use+$cr->number) + || + $cp->start_time < $now + || + $cp->end_time > $now + ) + { + $fail[] = $cp; + }else{ + $cp->inventory_use += $cr->number;//记录已领取的数量 + if ( $cr->save() && $cp->save() ) { + $success[] = $cp; + } else { + $fail[] = $cp; + } + } + } + }); + + return $this->success([ + 'success' => $success, + 'fail' => $fail, + ]); + } } diff --git a/app/Request/couponRebateReceiveRequest.php b/app/Request/couponRebateReceiveRequest.php new file mode 100644 index 0000000..4c4beed --- /dev/null +++ b/app/Request/couponRebateReceiveRequest.php @@ -0,0 +1,48 @@ + 'required|nonempty|integer|exists_enable:ims_cjdc_user,id', + 'receive_type' => 'required|nonempty|integer', + 'ids' => 'required|nonempty', + ]; + } + + public function messages(): array + { + return [ + 'user_id.*' => ':attribute信息不正确', + 'receive_type.*' => ':attribute必须', + 'ids.*' => ':attribute必须', + ]; + } + + public function attributes(): array + { + return [ + 'user_id' => '领取用户ID', + 'receive_type' => '领取方式', + 'ids' => '优惠券', + ]; + } +} From ccfac7644e9dbe1c3308b11404dcae56eff141a4 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 4 Aug 2020 15:30:26 +0800 Subject: [PATCH 11/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E7=BB=99=E5=89=8D=E7=AB=AFmock=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 6 ++++-- config/routes.php | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 12696a6..150e7fa 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -48,10 +48,12 @@ class CouponRebateController extends BaseController $ids = explode(',', $ids); $now = time(); - // moke 数据 给前端用 + // mock 数据 给前端用 $test = $this->request->input("test", 0); if($test){ - $cps = Coupon::whereIn('id', $ids)->lockForUpdate()->first(); + $cps = Coupon::whereIn('id', $ids)->lockForUpdate() + ->select('id','title','status','inventory','inventory_use','start_time','end_time') + ->first(); return $this->success([ 'success' => [$cps], 'fail' => [], diff --git a/config/routes.php b/config/routes.php index 83a8e13..0b238a6 100644 --- a/config/routes.php +++ b/config/routes.php @@ -26,5 +26,6 @@ Router::addGroup('/v1/',function (){ Router::post('ParamsToken/generate', 'App\Controller\ParamsTokenController@generate'); Router::post('ParamsToken/analyze', 'App\Controller\ParamsTokenController@analyze'); Router::post('Ad/banners', 'App\Controller\AdController@banners'); - Router::post('CouponRebate/isCouponRebate', 'App\Controller\CouponRebateController@isCouponRebate'); + Router::post('CouponRebate/isCouponRebate', 'App\Controller\CouponRebateController@isCouponRebate'); + Router::post('CouponRebate/userReceiveCoupon', 'App\Controller\CouponRebateController@userReceiveCouponA'); }); \ No newline at end of file From 425a2d810e538d1e7f0a5dffbba554000e7d6790 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 4 Aug 2020 16:35:33 +0800 Subject: [PATCH 12/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E4=BF=AE=E6=94=B9=E9=AA=8C=E8=AF=81=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 2 +- app/Request/couponRebateReceiveRequest.php | 48 ---------------------- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 app/Request/couponRebateReceiveRequest.php diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 150e7fa..89e1cd3 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -38,7 +38,7 @@ class CouponRebateController extends BaseController /** * 用户领取优惠券 */ - public function userReceiveCouponA(couponRebateReceiveRequest $validator) + public function userReceiveCouponA(CouponRebateReceiveRequest $validator) { $userId = $this->request->input("user_id", 0); $receiveType = $this->request->input("receive_type", 0); diff --git a/app/Request/couponRebateReceiveRequest.php b/app/Request/couponRebateReceiveRequest.php deleted file mode 100644 index 4c4beed..0000000 --- a/app/Request/couponRebateReceiveRequest.php +++ /dev/null @@ -1,48 +0,0 @@ - 'required|nonempty|integer|exists_enable:ims_cjdc_user,id', - 'receive_type' => 'required|nonempty|integer', - 'ids' => 'required|nonempty', - ]; - } - - public function messages(): array - { - return [ - 'user_id.*' => ':attribute信息不正确', - 'receive_type.*' => ':attribute必须', - 'ids.*' => ':attribute必须', - ]; - } - - public function attributes(): array - { - return [ - 'user_id' => '领取用户ID', - 'receive_type' => '领取方式', - 'ids' => '优惠券', - ]; - } -} From 0c6f0dbd52f261814001cb6deedf4665423511f4 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 4 Aug 2020 16:49:27 +0800 Subject: [PATCH 13/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E9=A2=86=E5=8F=96=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8A=A0=E9=AA=8C=E8=AF=81=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Request/CouponRebateReceiveRequest.php | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 app/Request/CouponRebateReceiveRequest.php diff --git a/app/Request/CouponRebateReceiveRequest.php b/app/Request/CouponRebateReceiveRequest.php new file mode 100644 index 0000000..4c4beed --- /dev/null +++ b/app/Request/CouponRebateReceiveRequest.php @@ -0,0 +1,48 @@ + 'required|nonempty|integer|exists_enable:ims_cjdc_user,id', + 'receive_type' => 'required|nonempty|integer', + 'ids' => 'required|nonempty', + ]; + } + + public function messages(): array + { + return [ + 'user_id.*' => ':attribute信息不正确', + 'receive_type.*' => ':attribute必须', + 'ids.*' => ':attribute必须', + ]; + } + + public function attributes(): array + { + return [ + 'user_id' => '领取用户ID', + 'receive_type' => '领取方式', + 'ids' => '优惠券', + ]; + } +} From ebedccb17282486666b4b05ec9f0485bd7dca3d9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Tue, 4 Aug 2020 16:52:30 +0800 Subject: [PATCH 14/66] =?UTF-8?q?=E9=A2=86=E5=88=B8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/CouponRebate/CouponRebate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/CouponRebate/CouponRebate.php b/app/CouponRebate/CouponRebate.php index 88f8d7f..f687113 100644 --- a/app/CouponRebate/CouponRebate.php +++ b/app/CouponRebate/CouponRebate.php @@ -13,7 +13,7 @@ class CouponRebate implements CouponRebateInterface public function isCouponRebate($user_id) { $res = Db::table('ims_system_coupon_user as u') - ->join('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') + ->leftjoin('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') ->where([ ['r.user_id','=',$user_id], ['u.active_type','=',2] From 33ce9d99e136b4104daf32ec889512ef6ef66679 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Tue, 4 Aug 2020 17:14:35 +0800 Subject: [PATCH 15/66] =?UTF-8?q?=E9=A2=86=E5=88=B8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/CouponRebate/CouponRebate.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/CouponRebate/CouponRebate.php b/app/CouponRebate/CouponRebate.php index f687113..85cf4e5 100644 --- a/app/CouponRebate/CouponRebate.php +++ b/app/CouponRebate/CouponRebate.php @@ -16,7 +16,8 @@ class CouponRebate implements CouponRebateInterface ->leftjoin('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') ->where([ ['r.user_id','=',$user_id], - ['u.active_type','=',2] + ['u.active_type','=',2], + ['u.receive_type','=',4] ]) ->select('r.id') ->first(); From 2ddda3a71dd08a0ffeaf75473a1210556dc1591b Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Tue, 4 Aug 2020 17:16:45 +0800 Subject: [PATCH 16/66] =?UTF-8?q?=E9=A2=86=E5=88=B8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/CouponRebate/CouponRebate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/CouponRebate/CouponRebate.php b/app/CouponRebate/CouponRebate.php index 85cf4e5..60438a1 100644 --- a/app/CouponRebate/CouponRebate.php +++ b/app/CouponRebate/CouponRebate.php @@ -16,8 +16,8 @@ class CouponRebate implements CouponRebateInterface ->leftjoin('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') ->where([ ['r.user_id','=',$user_id], + ['r.receive_type','=',4], ['u.active_type','=',2], - ['u.receive_type','=',4] ]) ->select('r.id') ->first(); From 2c7c43fdc8a042c67dfb677a40059af2e094cba1 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 4 Aug 2020 17:44:12 +0800 Subject: [PATCH 17/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E9=A2=86=E5=8F=96=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 2 +- config/routes.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 89e1cd3..119ac36 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -38,7 +38,7 @@ class CouponRebateController extends BaseController /** * 用户领取优惠券 */ - public function userReceiveCouponA(CouponRebateReceiveRequest $validator) + public function userReceiveCoupon(CouponRebateReceiveRequest $validator) { $userId = $this->request->input("user_id", 0); $receiveType = $this->request->input("receive_type", 0); diff --git a/config/routes.php b/config/routes.php index 0b238a6..547837f 100644 --- a/config/routes.php +++ b/config/routes.php @@ -27,5 +27,5 @@ Router::addGroup('/v1/',function (){ Router::post('ParamsToken/analyze', 'App\Controller\ParamsTokenController@analyze'); Router::post('Ad/banners', 'App\Controller\AdController@banners'); Router::post('CouponRebate/isCouponRebate', 'App\Controller\CouponRebateController@isCouponRebate'); - Router::post('CouponRebate/userReceiveCoupon', 'App\Controller\CouponRebateController@userReceiveCouponA'); + Router::post('CouponRebate/userReceiveCoupon', 'App\Controller\CouponRebateController@userReceiveCoupon'); }); \ No newline at end of file From fd64e9a5ab5141301a810838cc2461787409b799 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Tue, 4 Aug 2020 18:00:19 +0800 Subject: [PATCH 18/66] =?UTF-8?q?=E8=BF=94=E5=88=B8=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E8=AF=A6=E7=BB=86=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 12 ++++++++++++ app/CouponRebate/CouponRebate.php | 10 ++++++++++ app/CouponRebate/CouponRebateInterface.php | 2 ++ config/routes.php | 1 + 4 files changed, 25 insertions(+) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 89e1cd3..3c1ee3d 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -28,6 +28,9 @@ class CouponRebateController extends BaseController * @var CouponRebateInterface */ protected $CouponRebate; + /** + * 用户是否领取过领取优惠券 + */ public function isCouponRebate() { $user_id = $this->request->input('user_id', 0); @@ -35,6 +38,15 @@ class CouponRebateController extends BaseController return $this->success($res); } + /** + * 返回活动信息 + */ + public function getActiveInfo() + { + $res = $this->CouponRebate->getActiveInfo(); + return $this->success($res); + } + /** * 用户领取优惠券 */ diff --git a/app/CouponRebate/CouponRebate.php b/app/CouponRebate/CouponRebate.php index 60438a1..d61e2d8 100644 --- a/app/CouponRebate/CouponRebate.php +++ b/app/CouponRebate/CouponRebate.php @@ -24,4 +24,14 @@ class CouponRebate implements CouponRebateInterface return $res; } + public function getActiveInfo() + { + $res = Db::table('ims_system_coupon_user') + ->where([ + ['active_type','=',2], + ]) + ->get(); + return $res; + } + } \ No newline at end of file diff --git a/app/CouponRebate/CouponRebateInterface.php b/app/CouponRebate/CouponRebateInterface.php index 8c63313..385f1a7 100644 --- a/app/CouponRebate/CouponRebateInterface.php +++ b/app/CouponRebate/CouponRebateInterface.php @@ -7,4 +7,6 @@ interface CouponRebateInterface public function isCouponRebate($user_id); + public function getActiveInfo(); + } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 0b238a6..86c239d 100644 --- a/config/routes.php +++ b/config/routes.php @@ -28,4 +28,5 @@ Router::addGroup('/v1/',function (){ Router::post('Ad/banners', 'App\Controller\AdController@banners'); Router::post('CouponRebate/isCouponRebate', 'App\Controller\CouponRebateController@isCouponRebate'); Router::post('CouponRebate/userReceiveCoupon', 'App\Controller\CouponRebateController@userReceiveCouponA'); + Router::post('CouponRebate/getActiveInfo', 'App\Controller\CouponRebateController@getActiveInfo'); }); \ No newline at end of file From e74b37a25650598349c96ed10add87fd9cf3f78b Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 4 Aug 2020 18:48:53 +0800 Subject: [PATCH 19/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E4=BF=AE=E6=94=B9=E9=A2=86=E5=88=B8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 126 +++++++++++---------- app/Request/CouponRebateReceiveRequest.php | 6 +- 2 files changed, 67 insertions(+), 65 deletions(-) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 119ac36..9c78b87 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -36,91 +36,93 @@ class CouponRebateController extends BaseController } /** - * 用户领取优惠券 + * 用户领取优惠券 2020.08.04 只领一张 */ public function userReceiveCoupon(CouponRebateReceiveRequest $validator) { $userId = $this->request->input("user_id", 0); $receiveType = $this->request->input("receive_type", 0); - $ids = $this->request->input("ids", ''); + $id = $this->request->input("id", 0); $sendUserId = $this->request->input("send_user_id", 0); $phone = $this->request->input("phone", ''); - $ids = explode(',', $ids); $now = time(); + // status : 0 领取成功 >0 领取失败 + $return = [ + 'status' => 1, + 'data' => [], + 'coupon_text' => '继续努力~' + ]; // mock 数据 给前端用 $test = $this->request->input("test", 0); if($test){ - $cps = Coupon::whereIn('id', $ids)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time') + $cps = Coupon::where('id', $id)->lockForUpdate() + ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') ->first(); - return $this->success([ - 'success' => [$cps], - 'fail' => [], - ]); + $return['status'] = 0; + $return['data'] = $cps; + $return['coupon_text'] = $cps['discounts'].'元红包'; + return $this->success($return); } - $success = []; - $fail = []; - - Db::transaction( function () use ($ids,$receiveType,$userId,$sendUserId,$phone,&$success,&$fail,$now) { + Db::transaction( function () use ($id,$receiveType,$userId,$sendUserId,$phone,&$success,&$fail,$now) { //读写锁,完全控制,性能低 - $cps = Coupon::whereIn('id', $ids)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time') - ->get(); - - foreach ($cps as $key => $cp) { + $cp = Coupon::where('id', $id)->lockForUpdate() + ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') + ->first(); - $where = [ - 'system_coupon_user_id' => $cp->id, - ]; + $where = [ + 'system_coupon_user_id' => $cp->id, + ]; - if (env('SUB_CHANNEL') == 1) { - $where['receive_type'] = $receiveType; - } + if (env('SUB_CHANNEL') == 1) { + $where['receive_type'] = $receiveType; + } + // 查询领取类型一次能领取的数量 + $crt = CouponUserRecType::where($where)->first(); - $crt = CouponUserRecType::where($where)->first(); + $cr = new CouponRec; + $cr->user_id = $userId; + $cr->system_coupon_user_id = $cp->id; + $cr->order_main_id = 0; + $cr->receive_time = $now; + $cr->number = $crt->one_receive_number; + $cr->number_remain = $crt->one_receive_number; + $cr->status = 0; + $cr->update_time = $now; + $cr->receive_type = $receiveType; + $cr->send_user_id = $sendUserId; + $cr->phone = $phone; - $cr = new CouponRec; - $cr->user_id = $userId; - $cr->system_coupon_user_id = $cp->id; - $cr->order_main_id = 0; - $cr->receive_time = $now; - $cr->number = $crt->one_receive_number; - $cr->number_remain = $crt->one_receive_number; - $cr->status = 0; - $cr->update_time = $now; - $cr->receive_type = $receiveType; - $cr->send_user_id = $sendUserId; - $cr->phone = $phone; - //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 - if ( - $cp->status != 1 - || - $cp->inventory <= $cp->inventory_use - || - $cp->inventory < ($cp->inventory_use+$cr->number) - || - $cp->start_time < $now - || - $cp->end_time > $now - ) - { - $fail[] = $cp; - }else{ - $cp->inventory_use += $cr->number;//记录已领取的数量 - if ( $cr->save() && $cp->save() ) { - $success[] = $cp; - } else { - $fail[] = $cp; - } + //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 + if ( + $cp->status != 1 + || + $cp->inventory <= $cp->inventory_use + || + $cp->inventory < ($cp->inventory_use+$cr->number) + || + $cp->start_time < $now + || + $cp->end_time > $now + ) + { + $return['status'] = 2; + $return['coupon_text'] = '红包已经领完~'; + }else{ + $cp->inventory_use += $cr->number;//记录已领取的数量 + if ( $cr->save() && $cp->save() ) { + $return['status'] = 0; + $return['data'] = $cps; + $return['coupon_text'] = $cps['discounts'].'元红包'; + } else { + $return['status'] = 3; + $return['coupon_text'] = '下次继续努力~'; } } + }); - return $this->success([ - 'success' => $success, - 'fail' => $fail, - ]); + return $this->success($return); } } diff --git a/app/Request/CouponRebateReceiveRequest.php b/app/Request/CouponRebateReceiveRequest.php index 4c4beed..3169c3e 100644 --- a/app/Request/CouponRebateReceiveRequest.php +++ b/app/Request/CouponRebateReceiveRequest.php @@ -24,7 +24,7 @@ class CouponRebateReceiveRequest extends FormRequest return [ 'user_id' => 'required|nonempty|integer|exists_enable:ims_cjdc_user,id', 'receive_type' => 'required|nonempty|integer', - 'ids' => 'required|nonempty', + 'id' => 'required|nonempty', ]; } @@ -33,7 +33,7 @@ class CouponRebateReceiveRequest extends FormRequest return [ 'user_id.*' => ':attribute信息不正确', 'receive_type.*' => ':attribute必须', - 'ids.*' => ':attribute必须', + 'id.*' => ':attribute必须', ]; } @@ -42,7 +42,7 @@ class CouponRebateReceiveRequest extends FormRequest return [ 'user_id' => '领取用户ID', 'receive_type' => '领取方式', - 'ids' => '优惠券', + 'id' => '优惠券', ]; } } From 22fe7c27aab85a8e94595f8732bda4ef50d5cd90 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 4 Aug 2020 20:04:57 +0800 Subject: [PATCH 20/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E5=88=A0=E9=99=A4mock=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 202a0a3..39fbb14 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -67,17 +67,6 @@ class CouponRebateController extends BaseController 'data' => [], 'coupon_text' => '继续努力~' ]; - // mock 数据 给前端用 - $test = $this->request->input("test", 0); - if($test){ - $cps = Coupon::where('id', $id)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') - ->first(); - $return['status'] = 0; - $return['data'] = $cps; - $return['coupon_text'] = $cps['discounts'].'元红包'; - return $this->success($return); - } Db::transaction( function () use ($id,$receiveType,$userId,$sendUserId,$phone,&$return,$now) { //读写锁,完全控制,性能低 From cd72658a2f2a0e55a57c3081c23edfe80eda35f6 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 4 Aug 2020 20:32:52 +0800 Subject: [PATCH 21/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E9=A2=86=E5=8F=96=E6=8E=A5=E5=8F=A3-=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 39fbb14..1c856f3 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -50,7 +50,7 @@ class CouponRebateController extends BaseController /** * 用户领取优惠券 - * 用户领取优惠券 2020.08.04 只领一张 + * 2020.08.04 只领一张优惠券 */ public function userReceiveCoupon(CouponRebateReceiveRequest $validator) { @@ -73,7 +73,7 @@ class CouponRebateController extends BaseController $cp = Coupon::where('id', $id)->lockForUpdate() ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') ->first(); - + $where = [ 'system_coupon_user_id' => $cp->id, ]; @@ -83,7 +83,7 @@ class CouponRebateController extends BaseController } // 查询领取类型一次能领取的数量 $crt = CouponUserRecType::where($where)->first(); - + $cr = new CouponRec; $cr->user_id = $userId; $cr->system_coupon_user_id = $cp->id; @@ -96,7 +96,7 @@ class CouponRebateController extends BaseController $cr->receive_type = $receiveType; $cr->send_user_id = $sendUserId; $cr->phone = $phone; - + //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 if ( $cp->status != 1 @@ -105,9 +105,9 @@ class CouponRebateController extends BaseController || $cp->inventory < ($cp->inventory_use+$cr->number) || - $cp->start_time < $now + $cp->start_time > $now || - $cp->end_time > $now + $cp->end_time < $now ) { $return['status'] = 2; @@ -116,11 +116,8 @@ class CouponRebateController extends BaseController $cp->inventory_use += $cr->number;//记录已领取的数量 if ( $cr->save() && $cp->save() ) { $return['status'] = 0; - $return['data'] = $cps; - $return['coupon_text'] = $cps['discounts'].'元红包'; - } else { - $return['status'] = 3; - $return['coupon_text'] = '下次继续努力~'; + $return['data'] = $cp; + $return['coupon_text'] = $cp['discounts'].'元红包'; } } From 901c91ae49b935dbe3248fcf00782bc773597486 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Tue, 4 Aug 2020 20:52:09 +0800 Subject: [PATCH 22/66] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/CouponRebate/CouponRebate.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/CouponRebate/CouponRebate.php b/app/CouponRebate/CouponRebate.php index d61e2d8..510e99b 100644 --- a/app/CouponRebate/CouponRebate.php +++ b/app/CouponRebate/CouponRebate.php @@ -26,10 +26,15 @@ class CouponRebate implements CouponRebateInterface public function getActiveInfo() { + $time = time(); $res = Db::table('ims_system_coupon_user') ->where([ + ['status','=',1], ['active_type','=',2], + ['start_time','<=',$time], + ['end_time','>',$time], ]) + ->whereRaw('inventory > inventory_use') ->get(); return $res; } From 58c1f57d699c81af6cdc652c0ca606295c30e11a Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Wed, 5 Aug 2020 09:38:52 +0800 Subject: [PATCH 23/66] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 2 +- app/{CouponRebate => Service}/CouponRebate.php | 2 +- app/{CouponRebate => Service}/CouponRebateInterface.php | 2 +- config/autoload/dependencies.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename app/{CouponRebate => Service}/CouponRebate.php (97%) rename app/{CouponRebate => Service}/CouponRebateInterface.php (81%) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 1c856f3..8cdfd9a 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -14,7 +14,7 @@ namespace App\Controller; use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; use Hyperf\Utils\ApplicationContext; -use App\CouponRebate\CouponRebateInterface; +use App\Service\CouponRebateInterface; use http\Client\Curl\User; use Hyperf\Di\Annotation\Inject; use App\Model\Coupon; diff --git a/app/CouponRebate/CouponRebate.php b/app/Service/CouponRebate.php similarity index 97% rename from app/CouponRebate/CouponRebate.php rename to app/Service/CouponRebate.php index 510e99b..a171bb8 100644 --- a/app/CouponRebate/CouponRebate.php +++ b/app/Service/CouponRebate.php @@ -1,6 +1,6 @@ \App\Service\ParamsTokenSsdbService::class, \App\Service\AdServiceInterface::class => \App\Service\AdService::class, \App\Commons\Log::class => \App\Commons\Log::class, - \App\CouponRebate\CouponRebateInterface::class => \App\CouponRebate\CouponRebate::class, + \App\Service\CouponRebateInterface::class => \App\Service\CouponRebate::class, ]; From 96655993183d2bd3f02d42567cd0dfb17a503e78 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Wed, 5 Aug 2020 11:39:37 +0800 Subject: [PATCH 24/66] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebate.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Service/CouponRebate.php b/app/Service/CouponRebate.php index a171bb8..9f05999 100644 --- a/app/Service/CouponRebate.php +++ b/app/Service/CouponRebate.php @@ -35,6 +35,7 @@ class CouponRebate implements CouponRebateInterface ['end_time','>',$time], ]) ->whereRaw('inventory > inventory_use') + ->orderBy('addtime','desc') ->get(); return $res; } From 0c9b3f76453a1cf5f97d3116f854f16cdb707827 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 5 Aug 2020 14:20:24 +0800 Subject: [PATCH 25/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E5=B0=81=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E7=89=88=EF=BC=88=E9=A2=86=E5=8F=96=E5=8F=AA=E9=A2=86=E4=B8=80?= =?UTF-8?q?=E5=BC=A0=E5=88=B8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/LogLabel.php | 2 + app/Controller/CouponRebateController.php | 79 ++--------- app/Service/CouponRebateService.php | 135 +++++++++++++++++++ app/Service/CouponRebateServiceInterface.php | 11 ++ 4 files changed, 157 insertions(+), 70 deletions(-) create mode 100644 app/Service/CouponRebateService.php create mode 100644 app/Service/CouponRebateServiceInterface.php diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php index 2265cf4..c09c8df 100644 --- a/app/Constants/LogLabel.php +++ b/app/Constants/LogLabel.php @@ -16,4 +16,6 @@ class LogLabel extends AbstractConstants * @Message("Ssdb Log Label") */ const SSDB_LOG = 'ssdb_log'; + + const COUPON_LOG = 'coupon_log'; } diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 1c856f3..51f8b78 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -21,6 +21,7 @@ use App\Model\Coupon; use App\Model\CouponUserRecType; use App\Model\CouponRec; use App\Request\CouponRebateReceiveRequest; +use App\Service\CouponRebateService; class CouponRebateController extends BaseController { /** @@ -28,6 +29,13 @@ class CouponRebateController extends BaseController * @var CouponRebateInterface */ protected $CouponRebate; + + /** + * @Inject + * @var CouponRebateService + */ + protected $CouponRebateService; + /** * 用户是否领取过领取优惠券 */ @@ -54,75 +62,6 @@ class CouponRebateController extends BaseController */ public function userReceiveCoupon(CouponRebateReceiveRequest $validator) { - $userId = $this->request->input("user_id", 0); - $receiveType = $this->request->input("receive_type", 0); - $id = $this->request->input("id", 0); - $sendUserId = $this->request->input("send_user_id", 0); - $phone = $this->request->input("phone", ''); - $now = time(); - - // status : 0 领取成功 >0 领取失败 - $return = [ - 'status' => 1, - 'data' => [], - 'coupon_text' => '继续努力~' - ]; - - Db::transaction( function () use ($id,$receiveType,$userId,$sendUserId,$phone,&$return,$now) { - //读写锁,完全控制,性能低 - $cp = Coupon::where('id', $id)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') - ->first(); - - $where = [ - 'system_coupon_user_id' => $cp->id, - ]; - - if (env('SUB_CHANNEL') == 1) { - $where['receive_type'] = $receiveType; - } - // 查询领取类型一次能领取的数量 - $crt = CouponUserRecType::where($where)->first(); - - $cr = new CouponRec; - $cr->user_id = $userId; - $cr->system_coupon_user_id = $cp->id; - $cr->order_main_id = 0; - $cr->receive_time = $now; - $cr->number = $crt->one_receive_number; - $cr->number_remain = $crt->one_receive_number; - $cr->status = 0; - $cr->update_time = $now; - $cr->receive_type = $receiveType; - $cr->send_user_id = $sendUserId; - $cr->phone = $phone; - - //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 - if ( - $cp->status != 1 - || - $cp->inventory <= $cp->inventory_use - || - $cp->inventory < ($cp->inventory_use+$cr->number) - || - $cp->start_time > $now - || - $cp->end_time < $now - ) - { - $return['status'] = 2; - $return['coupon_text'] = '红包已经领完~'; - }else{ - $cp->inventory_use += $cr->number;//记录已领取的数量 - if ( $cr->save() && $cp->save() ) { - $return['status'] = 0; - $return['data'] = $cp; - $return['coupon_text'] = $cp['discounts'].'元红包'; - } - } - - }); - - return $this->success($return); + return $this->success($this->CouponRebateService->userReceiveCoupon($this->request->all())); } } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php new file mode 100644 index 0000000..cdd384c --- /dev/null +++ b/app/Service/CouponRebateService.php @@ -0,0 +1,135 @@ +0 领取失败 + $result = [ + 'status' => 1, + 'data' => [], + 'coupon_text' => '继续努力~' + ]; + + // 错误日志记录 + $errorData = [ + 'coupon_id' =>$id, + 'user_id' =>$userId, + 'receiveType' =>$receiveType, + 'sendUserId' =>$sendUserId, + 'phone' =>$phone + ]; + + Db::transaction( function() use ($id,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData) { + + try{ + //读写锁,完全控制,性能低 + $cp = Coupon::where('id', $id)->lockForUpdate() + ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') + ->first(); + + $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$cp->id)->select('one_receive_number'); + + if (env('SUB_CHANNEL') == 1) { + $couponReceiveType->where('receive_type',$receiveType); + } + // 查询一次能领取的数量 + $crt = $couponReceiveType->first(); + + $cr = new CouponRec; + $cr->user_id = $userId; + $cr->system_coupon_user_id = $cp->id; + $cr->order_main_id = 0; + $cr->receive_time = $now; + $cr->number = $crt->one_receive_number; + $cr->number_remain = $crt->one_receive_number; + $cr->status = 0; + $cr->update_time = $now; + $cr->receive_type = $receiveType; + $cr->send_user_id = $sendUserId; + $cr->phone = $phone; + + //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 + if ( + $cp->status != 1 + || + $cp->inventory <= $cp->inventory_use + || + $cp->inventory < ($cp->inventory_use+$cr->number) + || + $cp->start_time > $now + || + $cp->end_time < $now + ) + { + $result['status'] = 2; + $result['coupon_text'] = '红包已经领完~'; + + $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + }else{ + // 判断是否领取过 存在记录则领取过 + $isReceive = CouponRec::select('id') + ->where('system_coupon_user_id',$id) + ->where('user_id',$userId) + ->exists(); + + if(!$isReceive){ + + $cp->inventory_use += $cr->number;//记录已领取的数量 + + if ( $cr->save() && $cp->save() ) { + $result['status'] = 0; + // $result['data'] = $cp; + $result['coupon_text'] = $cp['discounts'].'元红包'; + } + }else{ + $errorData['msg'] = '用户已经领取了此优惠券'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } + } + } catch (Exception $e){ + $errorData['msg'] = $e->getMessage(); + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } + }); + + return $result; + } +} \ No newline at end of file diff --git a/app/Service/CouponRebateServiceInterface.php b/app/Service/CouponRebateServiceInterface.php new file mode 100644 index 0000000..1ba93d0 --- /dev/null +++ b/app/Service/CouponRebateServiceInterface.php @@ -0,0 +1,11 @@ + Date: Wed, 5 Aug 2020 15:34:32 +0800 Subject: [PATCH 26/66] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E8=BF=94=E5=88=B8=E6=B6=88=E6=81=AF=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/couponRebateConsumer.php | 28 ++++++++++++++++++ config/autoload/amqp.php | 33 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 app/Amqp/Consumer/couponRebateConsumer.php create mode 100644 config/autoload/amqp.php diff --git a/app/Amqp/Consumer/couponRebateConsumer.php b/app/Amqp/Consumer/couponRebateConsumer.php new file mode 100644 index 0000000..7b04668 --- /dev/null +++ b/app/Amqp/Consumer/couponRebateConsumer.php @@ -0,0 +1,28 @@ +getBody()); + return Result::ACK; + } + + public function isEnable(): bool + { + return parent::isEnable(); + } +} diff --git a/config/autoload/amqp.php b/config/autoload/amqp.php new file mode 100644 index 0000000..e14780a --- /dev/null +++ b/config/autoload/amqp.php @@ -0,0 +1,33 @@ + [ + 'host' => env('RQM_HOST', 'localhost'), + 'port' => 5672, + 'user' => env('RQM_USER','guest'), + 'password' => env('RQM_PASSWORD','guest'), + 'vhost' => '/', + 'concurrent' => [ + 'limit' => 1, + ], + 'pool' => [ + 'min_connections' => 1, + 'max_connections' => 10, + 'connect_timeout' => 10.0, + 'wait_timeout' => 3.0, + 'heartbeat' => -1, + ], + 'params' => [ + 'insist' => false, + 'login_method' => 'AMQPLAIN', + 'login_response' => null, + 'locale' => 'en_US', + 'connection_timeout' => 3.0, + 'read_write_timeout' => 6.0, + 'context' => null, + 'keepalive' => false, + 'heartbeat' => 3, + 'close_on_destruct' => false, + ], + ] +]; From 765dbccf8fa6465380e48a6ff2428b246a73f7f5 Mon Sep 17 00:00:00 2001 From: weigang Date: Wed, 5 Aug 2020 15:41:08 +0800 Subject: [PATCH 27/66] =?UTF-8?q?=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/couponRebateConsumer.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Amqp/Consumer/couponRebateConsumer.php b/app/Amqp/Consumer/couponRebateConsumer.php index 7b04668..a4f7e27 100644 --- a/app/Amqp/Consumer/couponRebateConsumer.php +++ b/app/Amqp/Consumer/couponRebateConsumer.php @@ -18,6 +18,9 @@ class couponRebateConsumer extends ConsumerMessage { var_dump($data); var_dump($message->getBody()); + if (false) { + return Result::REQUEUE; + } return Result::ACK; } From 3481ead47977cfa9986d5126ae8d957978111c4a Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Wed, 5 Aug 2020 17:18:53 +0800 Subject: [PATCH 28/66] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 11 ++----- app/Service/CouponRebate.php | 28 ------------------ app/Service/CouponRebateService.php | 31 ++++++++++++++++++++ app/Service/CouponRebateServiceInterface.php | 5 ++++ config/autoload/dependencies.php | 2 +- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 43a73e9..c1b2b93 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -14,7 +14,7 @@ namespace App\Controller; use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; use Hyperf\Utils\ApplicationContext; -use App\Service\CouponRebateInterface; +use App\Service\CouponRebateServiceInterface; use http\Client\Curl\User; use Hyperf\Di\Annotation\Inject; use App\Model\Coupon; @@ -24,11 +24,6 @@ use App\Request\CouponRebateReceiveRequest; use App\Service\CouponRebateService; class CouponRebateController extends BaseController { - /** - * @Inject - * @var CouponRebateInterface - */ - protected $CouponRebate; /** * @Inject @@ -42,7 +37,7 @@ class CouponRebateController extends BaseController public function isCouponRebate() { $user_id = $this->request->input('user_id', 0); - $res = $this->CouponRebate->isCouponRebate($user_id); + $res = $this->CouponRebateService->isCouponRebate($user_id); return $this->success($res); } @@ -51,7 +46,7 @@ class CouponRebateController extends BaseController */ public function getActiveInfo() { - $res = $this->CouponRebate->getActiveInfo(); + $res = $this->CouponRebateService->getActiveInfo(); return $this->success($res); } diff --git a/app/Service/CouponRebate.php b/app/Service/CouponRebate.php index 9f05999..1afe901 100644 --- a/app/Service/CouponRebate.php +++ b/app/Service/CouponRebate.php @@ -10,34 +10,6 @@ use Hyperf\Paginator\Paginator; class CouponRebate implements CouponRebateInterface { - public function isCouponRebate($user_id) - { - $res = Db::table('ims_system_coupon_user as u') - ->leftjoin('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') - ->where([ - ['r.user_id','=',$user_id], - ['r.receive_type','=',4], - ['u.active_type','=',2], - ]) - ->select('r.id') - ->first(); - return $res; - } - public function getActiveInfo() - { - $time = time(); - $res = Db::table('ims_system_coupon_user') - ->where([ - ['status','=',1], - ['active_type','=',2], - ['start_time','<=',$time], - ['end_time','>',$time], - ]) - ->whereRaw('inventory > inventory_use') - ->orderBy('addtime','desc') - ->get(); - return $res; - } } \ No newline at end of file diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index cdd384c..9db3bc9 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -132,4 +132,35 @@ class CouponRebateService implements CouponRebateServiceInterface return $result; } + + public function isCouponRebate($user_id) + { + $res = Db::table('ims_system_coupon_user as u') + ->leftjoin('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') + ->where([ + ['r.user_id','=',$user_id], + ['r.receive_type','=',4], + ['u.active_type','=',2], + ]) + ->select('r.id') + ->first(); + return $res; + } + + public function getActiveInfo() + { + $time = time(); + $res = Db::table('ims_system_coupon_user') + ->where([ + ['status','=',1], + ['active_type','=',2], + ['start_time','<=',$time], + ['end_time','>',$time], + ]) + ->whereRaw('inventory > inventory_use') + ->orderBy('addtime','desc') + ->get(); + return $res; + } + } \ No newline at end of file diff --git a/app/Service/CouponRebateServiceInterface.php b/app/Service/CouponRebateServiceInterface.php index 1ba93d0..cc8c0ef 100644 --- a/app/Service/CouponRebateServiceInterface.php +++ b/app/Service/CouponRebateServiceInterface.php @@ -8,4 +8,9 @@ interface CouponRebateServiceInterface * 领取优惠券 */ public function userReceiveCoupon($params); + + public function isCouponRebate($user_id); + + public function getActiveInfo(); + } \ No newline at end of file diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 9089d7f..12dd53c 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -15,5 +15,5 @@ return [ \App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class, \App\Service\AdServiceInterface::class => \App\Service\AdService::class, \App\Commons\Log::class => \App\Commons\Log::class, - \App\Service\CouponRebateInterface::class => \App\Service\CouponRebate::class, + \App\Service\CouponRebateServiceInterface::class => \App\Service\CouponRebateService::class, ]; From 8406b27bca10533077335fa65d190e0f56925bdc Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Wed, 5 Aug 2020 17:22:25 +0800 Subject: [PATCH 29/66] =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=90=8E=20=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=A4=9A=E4=BD=99=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebate.php | 15 --------------- app/Service/CouponRebateInterface.php | 12 ------------ 2 files changed, 27 deletions(-) delete mode 100644 app/Service/CouponRebate.php delete mode 100644 app/Service/CouponRebateInterface.php diff --git a/app/Service/CouponRebate.php b/app/Service/CouponRebate.php deleted file mode 100644 index 1afe901..0000000 --- a/app/Service/CouponRebate.php +++ /dev/null @@ -1,15 +0,0 @@ - Date: Wed, 5 Aug 2020 17:23:59 +0800 Subject: [PATCH 30/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E9=A2=86=E5=8F=96=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E4=B8=80=E6=AC=A1=E5=8F=AF=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E5=A4=9A=E5=BC=A0=E4=BC=98=E6=83=A0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Request/CouponRebateReceiveRequest.php | 6 +- app/Service/CouponRebateService.php | 171 +++++++++++---------- 2 files changed, 97 insertions(+), 80 deletions(-) diff --git a/app/Request/CouponRebateReceiveRequest.php b/app/Request/CouponRebateReceiveRequest.php index 3169c3e..4c4beed 100644 --- a/app/Request/CouponRebateReceiveRequest.php +++ b/app/Request/CouponRebateReceiveRequest.php @@ -24,7 +24,7 @@ class CouponRebateReceiveRequest extends FormRequest return [ 'user_id' => 'required|nonempty|integer|exists_enable:ims_cjdc_user,id', 'receive_type' => 'required|nonempty|integer', - 'id' => 'required|nonempty', + 'ids' => 'required|nonempty', ]; } @@ -33,7 +33,7 @@ class CouponRebateReceiveRequest extends FormRequest return [ 'user_id.*' => ':attribute信息不正确', 'receive_type.*' => ':attribute必须', - 'id.*' => ':attribute必须', + 'ids.*' => ':attribute必须', ]; } @@ -42,7 +42,7 @@ class CouponRebateReceiveRequest extends FormRequest return [ 'user_id' => '领取用户ID', 'receive_type' => '领取方式', - 'id' => '优惠券', + 'ids' => '优惠券', ]; } } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index cdd384c..e0f9007 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -21,113 +21,130 @@ class CouponRebateService implements CouponRebateServiceInterface /** * 领取优惠券 + * 返券活动领取 + * 一次可领取多张优惠券 + * 一个用户不可重复领取 */ public function userReceiveCoupon($params) { $userId = $params["user_id"]; $receiveType = $params["receive_type"]; - $id = $params["id"]; + $ids = $params["ids"]; $sendUserId = $params["send_user_id"]; $phone = $params["phone"]; $now = time(); + $ids = is_array($ids) ? implode(',',$ids) : $ids; - // status : 0 领取成功 >0 领取失败 + // status: 0领取成功 >0领取失败 $result = [ 'status' => 1, - 'data' => [], 'coupon_text' => '继续努力~' ]; // 错误日志记录 $errorData = [ - 'coupon_id' =>$id, + 'coupon_ids' =>$ids, 'user_id' =>$userId, 'receiveType' =>$receiveType, 'sendUserId' =>$sendUserId, 'phone' =>$phone ]; - Db::transaction( function() use ($id,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData) { + Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData) { - try{ - //读写锁,完全控制,性能低 - $cp = Coupon::where('id', $id)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') - ->first(); - - $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$cp->id)->select('one_receive_number'); + try{ + //读写锁,完全控制,性能低 + $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() + ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') + ->get(); - if (env('SUB_CHANNEL') == 1) { - $couponReceiveType->where('receive_type',$receiveType); - } - // 查询一次能领取的数量 - $crt = $couponReceiveType->first(); - - $cr = new CouponRec; - $cr->user_id = $userId; - $cr->system_coupon_user_id = $cp->id; - $cr->order_main_id = 0; - $cr->receive_time = $now; - $cr->number = $crt->one_receive_number; - $cr->number_remain = $crt->one_receive_number; - $cr->status = 0; - $cr->update_time = $now; - $cr->receive_type = $receiveType; - $cr->send_user_id = $sendUserId; - $cr->phone = $phone; - - //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 - if ( - $cp->status != 1 - || - $cp->inventory <= $cp->inventory_use - || - $cp->inventory < ($cp->inventory_use+$cr->number) - || - $cp->start_time > $now - || - $cp->end_time < $now - ) - { - $result['status'] = 2; - $result['coupon_text'] = '红包已经领完~'; + foreach($coupons as $coupon){ + $errorData['coupon_id'] = $coupon->id; - $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); - }else{ - // 判断是否领取过 存在记录则领取过 - $isReceive = CouponRec::select('id') - ->where('system_coupon_user_id',$id) - ->where('user_id',$userId) - ->exists(); + //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内可领取, 否则返回领取失败的优惠券 + if ( + $coupon->status == 1 + && + $coupon->inventory > $coupon->inventory_use + && + $coupon->start_time <= $now + && + $coupon->end_time >= $now + ) + { - if(!$isReceive){ + // 查询一次能领取的数量 + $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$coupon->id)->select('one_receive_number'); + if (env('SUB_CHANNEL') == 1) { + $couponReceiveType->where('receive_type',$receiveType); + } + $couponReceiveType = $couponReceiveType->first(); + + // 优惠券可领取数量 >= 本次领取数量 + if($coupon->inventory - $coupon->inventory_use >= $couponReceiveType->one_receive_number){ - $cp->inventory_use += $cr->number;//记录已领取的数量 - - if ( $cr->save() && $cp->save() ) { - $result['status'] = 0; - // $result['data'] = $cp; - $result['coupon_text'] = $cp['discounts'].'元红包'; + // 判断是否领取过 存在记录则领取过 + $isReceive = CouponRec::select('id') + ->where('system_coupon_user_id',$ids) + ->where('user_id',$userId) + ->exists(); + + if(!$isReceive){ + //记录已领取的数量 + $coupon->inventory_use += $couponReceiveType->number; + + $couponReceive = new CouponRec; + $couponReceive->user_id = $userId; + $couponReceive->system_coupon_user_id = $coupon->id; + $couponReceive->order_main_id = 0; + $couponReceive->receive_time = $now; + $couponReceive->number = $couponReceiveType->one_receive_number; + $couponReceive->number_remain = $couponReceiveType->one_receive_number; + $couponReceive->status = 0; + $couponReceive->update_time = $now; + $couponReceive->receive_type = $receiveType; + $couponReceive->send_user_id = $sendUserId; + $couponReceive->phone = $phone; + + if ( $couponReceive->save() && $coupon->save() ) { + $result['status'] = 0; + $result['coupon_text'] = '恭喜您领取成功!'; + } + }else{ + $result['status'] = 2; + $result['coupon_text'] = '您已领取!赶快去下单吧~'; + + $errorData['msg'] = '用户已经领取了优惠券'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } + }else{ + $errorData['remain_receive_number'] = $coupon->inventory - $coupon->inventory_use; + $errorData['one_receive_number'] = $couponReceiveType->one_receive_number; + $errorData['msg'] = '优惠券剩余数量不足'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } + }else{ + $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); } - }else{ - $errorData['msg'] = '用户已经领取了此优惠券'; - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); } + + } catch (Exception $e){ + $errorData['msg'] = $e->getMessage(); + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); } - } catch (Exception $e){ - $errorData['msg'] = $e->getMessage(); - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); - } }); return $result; From 8e004f23c774b1fabc087dfd116812532e3a416f Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 5 Aug 2020 21:04:52 +0800 Subject: [PATCH 31/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8-=E9=A2=86=E5=8F=96=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E8=AE=B0=E5=BD=95=E5=88=B0ssdb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/SsdbKeysPrefix.php | 5 +++ app/Service/CouponRebateService.php | 57 ++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/app/Constants/SsdbKeysPrefix.php b/app/Constants/SsdbKeysPrefix.php index 158fefe..2cac620 100644 --- a/app/Constants/SsdbKeysPrefix.php +++ b/app/Constants/SsdbKeysPrefix.php @@ -16,4 +16,9 @@ class SsdbKeysPrefix extends AbstractConstants * @Message("Params Token Key Prefix") */ const PARAMS_TOKEN = 'params_token_'; + + /** + * @Message("Coupon rebate Key Prefix") + */ + const COUPON_REBATE_RECEIVE = 'coupon_rebate_receive_'; } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 19d077f..7c06421 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -9,6 +9,9 @@ use App\Model\CouponUserRecType; use App\Model\CouponRec; use App\Constants\LogLabel; use App\Commons\Log; +use Hyperf\Utils\ApplicationContext; +use App\TaskWorker\SSDBTask; +use App\Constants\SsdbKeysPrefix; use Exception; class CouponRebateService implements CouponRebateServiceInterface @@ -40,7 +43,7 @@ class CouponRebateService implements CouponRebateServiceInterface 'status' => 1, 'coupon_text' => '继续努力~' ]; - + // 错误日志记录 $errorData = [ 'coupon_ids' =>$ids, @@ -50,12 +53,17 @@ class CouponRebateService implements CouponRebateServiceInterface 'phone' =>$phone ]; - Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData) { + $receiveSsdb = []; + + try{ + Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData,&$receiveSsdb) { - try{ + $success = []; + $fail = []; + //读写锁,完全控制,性能低 $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') + ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts','active_type') ->get(); foreach($coupons as $coupon){ @@ -70,6 +78,8 @@ class CouponRebateService implements CouponRebateServiceInterface $coupon->start_time <= $now && $coupon->end_time >= $now + && + $coupon->active_type == 2 ) { @@ -107,10 +117,12 @@ class CouponRebateService implements CouponRebateServiceInterface $couponReceive->phone = $phone; if ( $couponReceive->save() && $coupon->save() ) { - $result['status'] = 0; - $result['coupon_text'] = '恭喜您领取成功!'; + $success[] = $coupon; + $receiveSsdb[] = $coupon->id;; } }else{ + $fail[] = $coupon; + $receiveSsdb[] = $coupon->id; $result['status'] = 2; $result['coupon_text'] = '您已领取!赶快去下单吧~'; @@ -121,6 +133,7 @@ class CouponRebateService implements CouponRebateServiceInterface ); } }else{ + $fail[] = $coupon; $errorData['remain_receive_number'] = $coupon->inventory - $coupon->inventory_use; $errorData['one_receive_number'] = $couponReceiveType->one_receive_number; $errorData['msg'] = '优惠券剩余数量不足'; @@ -130,6 +143,7 @@ class CouponRebateService implements CouponRebateServiceInterface ); } }else{ + $fail[] = $coupon; $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; $this->log->event( LogLabel::COUPON_LOG, @@ -137,16 +151,33 @@ class CouponRebateService implements CouponRebateServiceInterface ); } } - - } catch (Exception $e){ - $errorData['msg'] = $e->getMessage(); + $result['data'] = [ + 'success' => $success, + 'fail' => $fail + ]; + if(count($success) > 0){ + $result['status'] = 0; + $result['coupon_text'] = '恭喜您领取成功!'; + } + }); + } catch (Exception $e){ + $errorData['msg'] = $e->getMessage(); + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } + if(count($receiveSsdb) > 0){ + // 记录到ssdb + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + if(false === $ssdb->exec('hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$receiveSsdb)){ + $errorData['msg'] = '记录领取优惠券到ssdb失败'; $this->log->event( LogLabel::COUPON_LOG, $errorData - ); - } - }); - + ); + }; + } return $result; } From 1ddf72a15fdbf0b36f2624c114dba1421877cb0d Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 5 Aug 2020 21:28:48 +0800 Subject: [PATCH 32/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E9=A2=86?= =?UTF-8?q?=E5=8F=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 7c06421..6d488c1 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -36,7 +36,7 @@ class CouponRebateService implements CouponRebateServiceInterface $sendUserId = $params["send_user_id"]; $phone = $params["phone"]; $now = time(); - $ids = is_array($ids) ? implode(',',$ids) : $ids; + $ids = is_array($ids) ? $ids : explode(',',$ids); // status: 0领取成功 >0领取失败 $result = [ @@ -60,9 +60,10 @@ class CouponRebateService implements CouponRebateServiceInterface $success = []; $fail = []; + $isr = []; //读写锁,完全控制,性能低 - $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() + $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts','active_type') ->get(); @@ -95,7 +96,7 @@ class CouponRebateService implements CouponRebateServiceInterface // 判断是否领取过 存在记录则领取过 $isReceive = CouponRec::select('id') - ->where('system_coupon_user_id',$ids) + ->where('system_coupon_user_id',$coupon->id) ->where('user_id',$userId) ->exists(); @@ -116,10 +117,10 @@ class CouponRebateService implements CouponRebateServiceInterface $couponReceive->send_user_id = $sendUserId; $couponReceive->phone = $phone; - if ( $couponReceive->save() && $coupon->save() ) { - $success[] = $coupon; - $receiveSsdb[] = $coupon->id;; - } + // if ( $couponReceive->save() && $coupon->save() ) { + // $success[] = $coupon; + // $receiveSsdb[] = $coupon->id;; + // } }else{ $fail[] = $coupon; $receiveSsdb[] = $coupon->id; @@ -168,9 +169,14 @@ class CouponRebateService implements CouponRebateServiceInterface ); } if(count($receiveSsdb) > 0){ + $saveSsdb = []; + foreach($receiveSsdb as $kssdb => $vssdb){ + $saveSsdb[] = $kssdb; + $saveSsdb[] = $vssdb; + } // 记录到ssdb $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - if(false === $ssdb->exec('hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$receiveSsdb)){ + if(false === $ssdb->exec('hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$saveSsdb)){ $errorData['msg'] = '记录领取优惠券到ssdb失败'; $this->log->event( LogLabel::COUPON_LOG, From 4d79a99ad0b56eed1359bae1c37cfb75d063d4c3 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Thu, 6 Aug 2020 10:24:02 +0800 Subject: [PATCH 33/66] =?UTF-8?q?=E8=BF=94=E5=88=B8=E6=B4=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/couponRebateConsumer.php | 11 + app/Controller/CouponRebateController.php | 16 +- app/Service/CouponRebateService.php | 248 +++++++++++++------ app/Service/CouponRebateServiceInterface.php | 2 + config/routes.php | 1 + 5 files changed, 196 insertions(+), 82 deletions(-) diff --git a/app/Amqp/Consumer/couponRebateConsumer.php b/app/Amqp/Consumer/couponRebateConsumer.php index a4f7e27..475c7b9 100644 --- a/app/Amqp/Consumer/couponRebateConsumer.php +++ b/app/Amqp/Consumer/couponRebateConsumer.php @@ -8,16 +8,27 @@ use Hyperf\Amqp\Result; use Hyperf\Amqp\Annotation\Consumer; use Hyperf\Amqp\Message\ConsumerMessage; use PhpAmqpLib\Message\AMQPMessage; +use App\Service\CouponRebateService; +use App\Service\CouponRebateServiceInterface; +use Hyperf\Di\Annotation\Inject; /** * @Consumer(exchange="couponRebate", routingKey="couponRebate", queue="couponRebate", name ="couponRebateConsumer", nums=1) */ class couponRebateConsumer extends ConsumerMessage { + /** + * @Inject + * @var CouponRebateService + */ + protected $CouponRebateService; + public function consumeMessage($data, AMQPMessage $message): string { var_dump($data); var_dump($message->getBody()); + $res = $this->CouponRebateService->couponRebate($data); + var_dump($res); if (false) { return Result::REQUEUE; } diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index c1b2b93..30cc5bb 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -25,11 +25,11 @@ use App\Service\CouponRebateService; class CouponRebateController extends BaseController { - /** + /** * @Inject * @var CouponRebateService */ - protected $CouponRebateService; + protected $CouponRebateService; /** * 用户是否领取过领取优惠券 @@ -50,13 +50,21 @@ class CouponRebateController extends BaseController return $this->success($res); } - + /** * 用户领取优惠券 * 2020.08.04 只领一张优惠券 - */ + */ public function userReceiveCoupon(CouponRebateReceiveRequest $validator) { return $this->success($this->CouponRebateService->userReceiveCoupon($this->request->all())); } + + public function couponRebate() + { + $order_id = $this->request->input('order_id', 0); + $res = $this->CouponRebateService->couponRebate($order_id); + return $this->success($res); + } + } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 9db3bc9..48d8596 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -13,7 +13,7 @@ use Exception; class CouponRebateService implements CouponRebateServiceInterface { - /** + /** * @Inject * @var Log */ @@ -30,7 +30,7 @@ class CouponRebateService implements CouponRebateServiceInterface $sendUserId = $params["send_user_id"]; $phone = $params["phone"]; $now = time(); - + // status : 0 领取成功 >0 领取失败 $result = [ 'status' => 1, @@ -49,113 +49,119 @@ class CouponRebateService implements CouponRebateServiceInterface Db::transaction( function() use ($id,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData) { - try{ - //读写锁,完全控制,性能低 - $cp = Coupon::where('id', $id)->lockForUpdate() + try{ + //读写锁,完全控制,性能低 + $cp = Coupon::where('id', $id)->lockForUpdate() ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') ->first(); - - $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$cp->id)->select('one_receive_number'); - if (env('SUB_CHANNEL') == 1) { - $couponReceiveType->where('receive_type',$receiveType); - } - // 查询一次能领取的数量 - $crt = $couponReceiveType->first(); - - $cr = new CouponRec; - $cr->user_id = $userId; - $cr->system_coupon_user_id = $cp->id; - $cr->order_main_id = 0; - $cr->receive_time = $now; - $cr->number = $crt->one_receive_number; - $cr->number_remain = $crt->one_receive_number; - $cr->status = 0; - $cr->update_time = $now; - $cr->receive_type = $receiveType; - $cr->send_user_id = $sendUserId; - $cr->phone = $phone; - - //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 - if ( - $cp->status != 1 - || - $cp->inventory <= $cp->inventory_use - || - $cp->inventory < ($cp->inventory_use+$cr->number) - || - $cp->start_time > $now - || - $cp->end_time < $now + $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$cp->id)->select('one_receive_number'); + + if (env('SUB_CHANNEL') == 1) { + $couponReceiveType->where('receive_type',$receiveType); + } + // 查询一次能领取的数量 + $crt = $couponReceiveType->first(); + + $cr = new CouponRec; + $cr->user_id = $userId; + $cr->system_coupon_user_id = $cp->id; + $cr->order_main_id = 0; + $cr->receive_time = $now; + $cr->number = $crt->one_receive_number; + $cr->number_remain = $crt->one_receive_number; + $cr->status = 0; + $cr->update_time = $now; + $cr->receive_type = $receiveType; + $cr->send_user_id = $sendUserId; + $cr->phone = $phone; + + //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 + if ( + $cp->status != 1 + || + $cp->inventory <= $cp->inventory_use + || + $cp->inventory < ($cp->inventory_use+$cr->number) + || + $cp->start_time > $now + || + $cp->end_time < $now ) - { - $result['status'] = 2; - $result['coupon_text'] = '红包已经领完~'; + { + $result['status'] = 2; + $result['coupon_text'] = '红包已经领完~'; - $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); - }else{ - // 判断是否领取过 存在记录则领取过 - $isReceive = CouponRec::select('id') - ->where('system_coupon_user_id',$id) - ->where('user_id',$userId) - ->exists(); - - if(!$isReceive){ - - $cp->inventory_use += $cr->number;//记录已领取的数量 - - if ( $cr->save() && $cp->save() ) { - $result['status'] = 0; - // $result['data'] = $cp; - $result['coupon_text'] = $cp['discounts'].'元红包'; - } - }else{ - $errorData['msg'] = '用户已经领取了此优惠券'; + $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; $this->log->event( LogLabel::COUPON_LOG, $errorData - ); + ); + }else{ + // 判断是否领取过 存在记录则领取过 + $isReceive = CouponRec::select('id') + ->where('system_coupon_user_id',$id) + ->where('user_id',$userId) + ->exists(); + + if(!$isReceive){ + + $cp->inventory_use += $cr->number;//记录已领取的数量 + + if ( $cr->save() && $cp->save() ) { + $result['status'] = 0; + // $result['data'] = $cp; + $result['coupon_text'] = $cp['discounts'].'元红包'; + } + }else{ + $errorData['msg'] = '用户已经领取了此优惠券'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } } + } catch (Exception $e){ + $errorData['msg'] = $e->getMessage(); + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); } - } catch (Exception $e){ - $errorData['msg'] = $e->getMessage(); - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); - } }); return $result; } + /* + * 判断用户是否已领取过优惠券 + * */ public function isCouponRebate($user_id) { $res = Db::table('ims_system_coupon_user as u') ->leftjoin('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') ->where([ - ['r.user_id','=',$user_id], - ['r.receive_type','=',4], - ['u.active_type','=',2], + ['r.user_id' ,'=', $user_id], + ['r.receive_type','=', 4], + ['u.active_type' ,'=', 2], ]) ->select('r.id') ->first(); return $res; } + /* + *获取活动信息 + */ public function getActiveInfo() { $time = time(); $res = Db::table('ims_system_coupon_user') ->where([ - ['status','=',1], - ['active_type','=',2], - ['start_time','<=',$time], - ['end_time','>',$time], + ['status' ,'=', 1], + ['active_type' ,'=', 2], + ['start_time' ,'<=', $time], + ['end_time' ,'>', $time], ]) ->whereRaw('inventory > inventory_use') ->orderBy('addtime','desc') @@ -163,4 +169,90 @@ class CouponRebateService implements CouponRebateServiceInterface return $res; } + /* + * 支付成功 返券 + */ + public function couponRebate($order_id) + { + + /* 判断优惠券类型是否为转发活动优惠券 */ + $coupon = Db::table('ims_system_coupon_user_receive as r') + ->leftjoin('ims_system_coupon_user_use as u', 'u.user_receive_id', '=', 'r.id') + ->where([ + ['u.order_main_id', '=', $order_id], + ['r.send_user_id', '>', 0], + ['r.rebate_type', '=', 1], + ['r.receive_type', '=', 4], + ['u.status', '=', 1], + ]) + ->select('r.id', 'r.send_user_id', 'u.system_coupon_id') + ->first(); + /* 如果使用的优惠券为转发活动优惠券 则给赠送者返一张优惠券*/ + if (isset($coupon->send_user_id) && ($coupon->send_user_id) > 0) { + //判断该优惠券是否有库存 +// $inventory = Db::table('system_coupon_user_receive as r'); +// if($inventory['inventory'] <= 0){ +// return '库存不足'; +// } + //判断用户是否已有该类型优惠券 + $exist_coupon = Db::table('ims_system_coupon_user_receive') + ->where([ + ['system_coupon_user_id', '=', $coupon->system_coupon_id], + ['user_id', '=', $coupon->send_user_id], + ['receive_type', '=', 5], + ['status', '=', 0], + ]) + ->select('id') + ->first(); + //return $exist_coupon; + //开启事务 + try { + /* + * 如果已有该优惠券 则领取数量 和 可用数量 自增1 + * 否则新增一条返券记录 + */ + $nowTime = time(); + $res = Db::table('ims_system_coupon_user_receive')->updateOrInsert( + [ + 'system_coupon_user_id' => $coupon->system_coupon_id, + 'user_id' => $coupon->send_user_id, + 'receive_type' => 5, + 'status' => 0, + ], + [ + 'order_main_id' => $order_id, + 'receive_time' => $nowTime, + 'number' => 1, + 'number_remain' => 1, + 'update_time' => $nowTime, + 'created_at' => $nowTime, + 'updated_at' => $nowTime, + ] + ); +// if ($res) { +// //首次返券更新rebate_type字段 防止重复返券 +// Db::table('system_coupon_user_receive')->where('id', $coupon->id)->update(['rebate_type' => 2]); +// //更新库存操作 +// Db::table('system_coupon_user') +// ->where('id', $coupon->id) +// ->increment('inventory_use'); +// } else { +// Db::rollBack(); +// return '事务失败'; +// } + // 提交 + Db::commit(); + } catch (\Exception $e) { + // 回滚 + Db::rollBack(); + return '返券失败'; + } + } else { +// $str1 = 'order_main_id:'.$this->order_id . ',未查询到用户领取优惠券信息['.$coupon.']'; +// $this->couponErrorLog($str1); + } + + + return $exist_coupon->id; + } } \ No newline at end of file diff --git a/app/Service/CouponRebateServiceInterface.php b/app/Service/CouponRebateServiceInterface.php index cc8c0ef..f7bc3a0 100644 --- a/app/Service/CouponRebateServiceInterface.php +++ b/app/Service/CouponRebateServiceInterface.php @@ -13,4 +13,6 @@ interface CouponRebateServiceInterface public function getActiveInfo(); + public function couponRebate($order_id); + } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 0db0115..0f3633c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -29,4 +29,5 @@ Router::addGroup('/v1/',function (){ Router::post('CouponRebate/isCouponRebate', 'App\Controller\CouponRebateController@isCouponRebate'); Router::post('CouponRebate/userReceiveCoupon', 'App\Controller\CouponRebateController@userReceiveCoupon'); Router::post('CouponRebate/getActiveInfo', 'App\Controller\CouponRebateController@getActiveInfo'); + Router::post('CouponRebate/couponRebate', 'App\Controller\CouponRebateController@couponRebate'); }); \ No newline at end of file From 240f58c43ef79907cd7696efe83d9f20fe4fe782 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Thu, 6 Aug 2020 11:35:42 +0800 Subject: [PATCH 34/66] =?UTF-8?q?=E8=87=AA=E5=A2=9E=E6=88=96=E6=8F=92?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 48d8596..78213ae 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -174,7 +174,6 @@ class CouponRebateService implements CouponRebateServiceInterface */ public function couponRebate($order_id) { - /* 判断优惠券类型是否为转发活动优惠券 */ $coupon = Db::table('ims_system_coupon_user_receive as r') ->leftjoin('ims_system_coupon_user_use as u', 'u.user_receive_id', '=', 'r.id') @@ -212,7 +211,7 @@ class CouponRebateService implements CouponRebateServiceInterface * 否则新增一条返券记录 */ $nowTime = time(); - $res = Db::table('ims_system_coupon_user_receive')->updateOrInsert( + $res = Db::table('ims_system_coupon_user_receive')->updateOrIncrement( [ 'system_coupon_user_id' => $coupon->system_coupon_id, 'user_id' => $coupon->send_user_id, @@ -222,11 +221,13 @@ class CouponRebateService implements CouponRebateServiceInterface [ 'order_main_id' => $order_id, 'receive_time' => $nowTime, - 'number' => 1, - 'number_remain' => 1, 'update_time' => $nowTime, 'created_at' => $nowTime, 'updated_at' => $nowTime, + ], + [ + 'number' => 1, + 'number_remain' => 1, ] ); // if ($res) { From c715d1e81fc02cf99a408b9bed84a0c5bb28ba4b Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Thu, 6 Aug 2020 15:06:58 +0800 Subject: [PATCH 35/66] =?UTF-8?q?=E6=89=B9=E9=87=8F=E8=87=AA=E5=A2=9Eor?= =?UTF-8?q?=E6=8F=92=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 78213ae..af734c0 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -193,16 +193,6 @@ class CouponRebateService implements CouponRebateServiceInterface // if($inventory['inventory'] <= 0){ // return '库存不足'; // } - //判断用户是否已有该类型优惠券 - $exist_coupon = Db::table('ims_system_coupon_user_receive') - ->where([ - ['system_coupon_user_id', '=', $coupon->system_coupon_id], - ['user_id', '=', $coupon->send_user_id], - ['receive_type', '=', 5], - ['status', '=', 0], - ]) - ->select('id') - ->first(); //return $exist_coupon; //开启事务 try { @@ -211,7 +201,7 @@ class CouponRebateService implements CouponRebateServiceInterface * 否则新增一条返券记录 */ $nowTime = time(); - $res = Db::table('ims_system_coupon_user_receive')->updateOrIncrement( + $res = Db::table('ims_system_coupon_user_receive')->moreIncrementOrInsert( [ 'system_coupon_user_id' => $coupon->system_coupon_id, 'user_id' => $coupon->send_user_id, @@ -254,6 +244,6 @@ class CouponRebateService implements CouponRebateServiceInterface } - return $exist_coupon->id; + return '返券成功'; } } \ No newline at end of file From e0ed0eca9657d3529ca8728301fc191bd568a26a Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Thu, 6 Aug 2020 15:07:47 +0800 Subject: [PATCH 36/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E5=8F=AF?= =?UTF-8?q?=E9=A2=86=E5=8F=96=E4=BC=98=E6=83=A0=E5=88=B8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?getSystemCouponUserList=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=BB=91=E5=AE=9A=E4=BC=98=E6=83=A0=E5=88=B8=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/SsdbKeysPrefix.php | 10 ++ app/Controller/CouponController.php | 79 ++--------- app/Controller/CouponRebateController.php | 15 +- app/Request/CouponGetListRequest.php | 45 ++++++ app/Request/CouponRebateTieRequest.php | 48 +++++++ app/Service/CouponRebateService.php | 54 ++++++- app/Service/CouponRebateServiceInterface.php | 2 + app/Service/CouponService.php | 141 +++++++++++++++++++ app/Service/CouponServiceInterface.php | 18 +++ config/routes.php | 1 + 10 files changed, 345 insertions(+), 68 deletions(-) create mode 100644 app/Request/CouponGetListRequest.php create mode 100644 app/Request/CouponRebateTieRequest.php create mode 100644 app/Service/CouponService.php create mode 100644 app/Service/CouponServiceInterface.php diff --git a/app/Constants/SsdbKeysPrefix.php b/app/Constants/SsdbKeysPrefix.php index 2cac620..2550f84 100644 --- a/app/Constants/SsdbKeysPrefix.php +++ b/app/Constants/SsdbKeysPrefix.php @@ -21,4 +21,14 @@ class SsdbKeysPrefix extends AbstractConstants * @Message("Coupon rebate Key Prefix") */ const COUPON_REBATE_RECEIVE = 'coupon_rebate_receive_'; + + /** + * @Message("Coupon rebate Key Prefix") + */ + const COUPON_REBATE_FORWARD = 'coupon_rebate_forward_'; + + /** + * @Message("Coupon rebate Key Prefix") + */ + const COUPON_REBATE_REPAY = 'coupon_rebate_REPAY_'; } diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index 5152e63..6212782 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -12,86 +12,33 @@ declare(strict_types=1); namespace App\Controller; +use Hyperf\Di\Annotation\Inject; use App\Model\CouponUserRecType; use App\Model\Coupon; use App\Model\CouponRec; use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; use Hyperf\Utils\ApplicationContext; +use App\Request\CouponGetListRequest; +use App\Service\CouponService; class CouponController extends BaseController { + /** + * @Inject + * @var CouponService + */ + protected $couponService; /** * 获取用户可领取优惠卷接口 */ - public function getSystemCouponUserList() + public function getSystemCouponUserList(CouponGetListRequest $validator) { - $user_id = $this->request->input('user_id', 0); - $receive_type = $this->request->input('receive_type', 0); - - if ($this->empty($user_id) || $this->empty($receive_type)) { - return $this->success(['not_reveive' => []]); - } - - $c_ids = []; - // 渠道开启,查询该渠道可以领取的优惠券ID - // 渠道未开启,查询所有优惠券 - if (env('SUB_CHANNEL') == 1) { - $c_ids = CouponUserRecType::where('receive_type', $receive_type)->pluck('system_coupon_user_id'); - } else { - $c_ids = Coupon::pluck('id'); - } - - $nowTime = time(); - - $where = [ - ['user_id',"=",$user_id] - ]; - - // 渠道开启,查询该用户在此渠道领过的优惠券ID - if (env('SUB_CHANNEL') == 1) { - array_push($where, ['receive_type', "=", $receive_type]); - } - - $cr_ids = CouponRec::where($where)->pluck('system_coupon_user_id'); - - //领过券的ID - $c_ids = $c_ids->toArray(); - $cr_ids = $cr_ids->toArray(); - - // 当前用户可领的优惠券ID - $couponIds = array_diff($c_ids, $cr_ids); - - $whereC = [ - ['u.end_time','>',$nowTime], - ['u.start_time','<=',$nowTime], - ['u.status','=',1], - ['u.active_type','=',1], - ]; - - if (env('SUB_CHANNEL') == 1) { - array_push($whereC, ['type.receive_type','=',$receive_type]); - } - - $c = Db::table('ims_system_coupon_user as u') - ->where($whereC) - ->join('ims_system_coupon_user_receivetype as type', 'u.id', '=', 'type.system_coupon_user_id') - ->whereRaw('u.inventory_use <= u.inventory and u.inventory-u.inventory_use > type.one_receive_number') - // ->whereIn('u.id',$c_ids) - // ->whereNotIn('u.id',$cr_ids) - ->whereIn('u.id', $couponIds) - ->select('u.*','type.one_receive_number') - ->orderBy('u.weigh','desc') - // ->orderByRaw('FIELD(u.id, '.implode(", " , $ids).')') - ->limit(4) - ->get(); - foreach ($c as $k => &$v){ - if($v->discount_type == 2){ - $v->discounts = floatval($v->discounts); - } - } - return $this->success(['not_reveive'=>$c]); + $userId = $this->request->input('user_id', 0); + $receiveType = $this->request->input('receive_type', 0); + $res = $this->couponService->getSystemCouponUserList($userId,$receiveType); + return $this->success($res); } //统计用户 diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index c1b2b93..41b8fdb 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -22,6 +22,7 @@ use App\Model\CouponUserRecType; use App\Model\CouponRec; use App\Request\CouponRebateReceiveRequest; use App\Service\CouponRebateService; +use App\Request\CouponRebateTieRequest; class CouponRebateController extends BaseController { @@ -53,10 +54,22 @@ class CouponRebateController extends BaseController /** * 用户领取优惠券 - * 2020.08.04 只领一张优惠券 */ public function userReceiveCoupon(CouponRebateReceiveRequest $validator) { return $this->success($this->CouponRebateService->userReceiveCoupon($this->request->all())); } + + /** + * 将优惠券绑定活动 + */ + public function tieCouponActive(CouponRebateTieRequest $validator) + { + $couponForward = $this->request->input('coupon_forward_ids',[]); + $couponForward = is_array($couponForward) ? $couponForward : explode(',',$couponForward) ; + $couponRepay = $this->request->input('coupon_repay_id',0); + $couponActivity = $this->request->input('coupon_activity',0); + $res = $this->CouponRebateService->tieCouponActive($couponActivity,$couponForward,$couponRepay); + return $this->success($res); + } } diff --git a/app/Request/CouponGetListRequest.php b/app/Request/CouponGetListRequest.php new file mode 100644 index 0000000..252a45c --- /dev/null +++ b/app/Request/CouponGetListRequest.php @@ -0,0 +1,45 @@ + 'required|nonempty|integer|exists_enable:ims_cjdc_user,id', + 'receive_type' => 'required|nonempty|integer' + ]; + } + + public function messages(): array + { + return [ + 'user_id.*' => ':attribute信息不正确', + 'receive_type.*' => ':attribute必须' + ]; + } + + public function attributes(): array + { + return [ + 'user_id' => '用户ID', + 'receive_type' => '领取方式' + ]; + } +} diff --git a/app/Request/CouponRebateTieRequest.php b/app/Request/CouponRebateTieRequest.php new file mode 100644 index 0000000..39a5863 --- /dev/null +++ b/app/Request/CouponRebateTieRequest.php @@ -0,0 +1,48 @@ + 'required|nonempty', + 'coupon_forward_ids' => 'required|nonempty', + 'coupon_repay_id' => 'required|nonempty', + ]; + } + + public function messages(): array + { + return [ + 'coupon_activity.*' => ':attribute必须', + 'coupon_forward_ids.*' => ':attribute必须', + 'coupon_repay_id.*' => ':attribute必须', + ]; + } + + public function attributes(): array + { + return [ + 'coupon_activity' => '优惠券活动', + 'coupon_forward_ids' => '领取类型优惠券', + 'coupon_repay_id' => '返还类型优惠券', + ]; + } +} diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 6d488c1..c7dad5b 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -176,7 +176,7 @@ class CouponRebateService implements CouponRebateServiceInterface } // 记录到ssdb $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - if(false === $ssdb->exec('hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$saveSsdb)){ + if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$saveSsdb)){ $errorData['msg'] = '记录领取优惠券到ssdb失败'; $this->log->event( LogLabel::COUPON_LOG, @@ -216,5 +216,57 @@ class CouponRebateService implements CouponRebateServiceInterface ->get(); return $res; } + + /** + * 将优惠券绑定活动 + * 领取优惠券 COUPON_REBATE_FORWARD 可多张 + * 返还优惠券 COUPON_REBATE_REPAY 只一张 + */ + public function tieCouponActive($couponActivity,$couponForward,$couponRepay) + { + $result = [ + 'forward' => true, + 'repay' => true, + ]; + + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $rrss1 = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$couponActivity); + $rrss2 = $ssdb->exec('get',SsdbKeysPrefix::COUPON_REBATE_REPAY.$couponActivity); + return [$rrss1,$rrss2]; + // 记录领取类型优惠券 + $forwardData = []; + foreach($couponForward as $kForward => $vForward){ + $forwardData[] = $kForward; + $forwardData[] = $vForward; + } + + if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$couponActivity,$forwardData)){ + + $this->log->event( + LogLabel::COUPON_LOG, + [ + 'coupon_activity' => $couponActivity, + 'coupon_forward' => $forwardData, + 'msg' => '绑定-领取-优惠券到ssdb失败' + ] + ); + $result['forward'] = false; + }; + + // 记录返还类型优惠券 + if(false === $ssdb->exec('set',SsdbKeysPrefix::COUPON_REBATE_REPAY.$couponActivity,$couponRepay)){ + + $this->log->event( + LogLabel::COUPON_LOG, + [ + 'coupon_activity' => $couponActivity, + 'coupon_Repay' => $couponRepay, + 'msg' => '绑定-返还-优惠券到ssdb失败' + ] + ); + $result['repay'] = false; + }; + return $result; + } } \ No newline at end of file diff --git a/app/Service/CouponRebateServiceInterface.php b/app/Service/CouponRebateServiceInterface.php index cc8c0ef..cc8fd86 100644 --- a/app/Service/CouponRebateServiceInterface.php +++ b/app/Service/CouponRebateServiceInterface.php @@ -13,4 +13,6 @@ interface CouponRebateServiceInterface public function getActiveInfo(); + public function tieCouponActive($couponActivity,$couponForward,$couponRepay); + } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php new file mode 100644 index 0000000..d980954 --- /dev/null +++ b/app/Service/CouponService.php @@ -0,0 +1,141 @@ + 1, + 'not_receive' => [], + 'jump_data' => [ + 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, + 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, + 'coupons' => [] + ] + ]; + $nowTime = time(); + $c_ids = []; +$result['active_type'] = 1; + // 渠道开启,查询该渠道可以领取的优惠券ID + // 渠道未开启,查询所有优惠券 + if (env('SUB_CHANNEL') == 1) { + $c_ids = CouponUserRecType::where('receive_type', $receiveType)->pluck('system_coupon_user_id'); + } else { + $c_ids = Coupon::pluck('id'); + } + + $couponReceive = CouponRec::where('user_id',$userId); + + // 渠道开启,查询该用户在此渠道领过的优惠券ID + if (env('SUB_CHANNEL') == 1) { + $couponReceive->where('receive_type', $receiveType); + } + $cr_ids = $couponReceive->pluck('system_coupon_user_id'); + + // 可领取的券ID + $c_ids = $c_ids->toArray(); + // 已经领取的券ID + $cr_ids = $cr_ids->toArray(); + + // 当前用户可领的优惠券ID + $couponIds = array_diff($c_ids, $cr_ids); + + // 获取领取型优惠券 + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $couponRebateIds = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$activityType); + // $result['active_type'] = $couponRebateIds; + // return $result; + $couponIds = ($couponRebateIds === false || empty($couponRebateIds)) ? $couponIds : array_merge($couponIds,$couponRebateIds) ; + + $whereC = [ + ['u.end_time','>',$nowTime], + ['u.start_time','<=',$nowTime], + ['u.status','=',1] + ]; + + if (env('SUB_CHANNEL') == 1) { + array_push($whereC, ['type.receive_type','=', $receiveType]); + } + + $coupons = Db::table('ims_system_coupon_user as u') + ->join('ims_system_coupon_user_receivetype as type', 'u.id', '=', 'type.system_coupon_user_id') + ->whereIn('u.id', $couponIds) + ->where($whereC) + ->whereRaw('u.inventory_use < u.inventory and u.inventory-u.inventory_use >= type.one_receive_number') + ->select('u.*','type.one_receive_number') + ->orderBy('u.weigh','desc') + ->limit(4) + ->get(); + + foreach ($coupons as $k => &$v){ + if($v['active_type'] == 1){ + $result['not_receive'] = $v; + }else if($v['active_type'] == 2){ + $result['jump_data']['coupons'][] = $v; + } + if($v->discount_type == 2){ + $v->discounts = floatval($v->discounts); + } + } + + $result['active_type'] = count($result['jump_data']['coupons']) > 0 ? 2 : $result['active_type'] ; + + return $result; + } + + //统计用户 + public function userCouponAccount() + { + + } + + /** + * 用户领取优惠卷 + */ + public function userReceiveCoupon() + { + + } + + /** + * 获取用户已经领取的优惠卷列表 + */ + public function getUserReceiveCouponList() + { + + } + + /** + * 获取用户当前订单可用的优惠券列表 + * 按分类(1订单 等优惠)分组返回 + */ + public function getUserAvailableCoupons() + { + + } + +} \ No newline at end of file diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php new file mode 100644 index 0000000..b096ecd --- /dev/null +++ b/app/Service/CouponServiceInterface.php @@ -0,0 +1,18 @@ + Date: Thu, 6 Aug 2020 15:26:19 +0800 Subject: [PATCH 37/66] =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 84 ++++++++++++++++------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index dec3b75..da4b6da 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -37,13 +37,13 @@ class CouponRebateService implements CouponRebateServiceInterface $phone = $params["phone"]; $now = time(); $ids = is_array($ids) ? $ids : explode(',',$ids); - + // status: 0领取成功 >0领取失败 $result = [ 'status' => 1, 'coupon_text' => '继续努力~' ]; - + // 错误日志记录 $errorData = [ 'coupon_ids' =>$ids, @@ -54,24 +54,24 @@ class CouponRebateService implements CouponRebateServiceInterface ]; $receiveSsdb = []; - + try{ Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData,&$receiveSsdb) { $success = []; $fail = []; $isr = []; - + //读写锁,完全控制,性能低 $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts','active_type') - ->get(); + ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts','active_type') + ->get(); foreach($coupons as $coupon){ $errorData['coupon_id'] = $coupon->id; //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内可领取, 否则返回领取失败的优惠券 - if ( + if ( $coupon->status == 1 && $coupon->inventory > $coupon->inventory_use @@ -81,7 +81,7 @@ class CouponRebateService implements CouponRebateServiceInterface $coupon->end_time >= $now && $coupon->active_type == 2 - ) + ) { // 查询一次能领取的数量 @@ -90,15 +90,15 @@ class CouponRebateService implements CouponRebateServiceInterface $couponReceiveType->where('receive_type',$receiveType); } $couponReceiveType = $couponReceiveType->first(); - + // 优惠券可领取数量 >= 本次领取数量 if($coupon->inventory - $coupon->inventory_use >= $couponReceiveType->one_receive_number){ // 判断是否领取过 存在记录则领取过 $isReceive = CouponRec::select('id') - ->where('system_coupon_user_id',$coupon->id) - ->where('user_id',$userId) - ->exists(); + ->where('system_coupon_user_id',$coupon->id) + ->where('user_id',$userId) + ->exists(); if(!$isReceive){ //记录已领取的数量 @@ -116,7 +116,7 @@ class CouponRebateService implements CouponRebateServiceInterface $couponReceive->receive_type = $receiveType; $couponReceive->send_user_id = $sendUserId; $couponReceive->phone = $phone; - + // if ( $couponReceive->save() && $coupon->save() ) { // $success[] = $coupon; // $receiveSsdb[] = $coupon->id;; @@ -126,12 +126,12 @@ class CouponRebateService implements CouponRebateServiceInterface $receiveSsdb[] = $coupon->id; $result['status'] = 2; $result['coupon_text'] = '您已领取!赶快去下单吧~'; - + $errorData['msg'] = '用户已经领取了优惠券'; $this->log->event( LogLabel::COUPON_LOG, $errorData - ); + ); } }else{ $fail[] = $coupon; @@ -161,6 +161,13 @@ class CouponRebateService implements CouponRebateServiceInterface $result['coupon_text'] = '恭喜您领取成功!'; } }); + } catch (Exception $e){ + $errorData['msg'] = $e->getMessage(); + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } if(count($receiveSsdb) > 0){ $saveSsdb = []; foreach($receiveSsdb as $kssdb => $vssdb){ @@ -186,11 +193,11 @@ class CouponRebateService implements CouponRebateServiceInterface public function isCouponRebate($user_id) { $res = Db::table('ims_system_coupon_user as u') - ->leftjoin('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') + ->leftjoin('ims_system_coupon_user_receive as r', 'u.id', '=', 'r.system_coupon_user_id') ->where([ - ['r.user_id' ,'=', $user_id], - ['r.receive_type','=', 4], - ['u.active_type' ,'=', 2], + ['r.user_id', '=', $user_id], + ['r.receive_type', '=', 4], + ['u.active_type', '=', 2], ]) ->select('r.id') ->first(); @@ -205,13 +212,13 @@ class CouponRebateService implements CouponRebateServiceInterface $time = time(); $res = Db::table('ims_system_coupon_user') ->where([ - ['status' ,'=', 1], - ['active_type' ,'=', 2], - ['start_time' ,'<=', $time], - ['end_time' ,'>', $time], + ['status', '=', 1], + ['active_type', '=', 2], + ['start_time', '<=', $time], + ['end_time', '>', $time], ]) ->whereRaw('inventory > inventory_use') - ->orderBy('addtime','desc') + ->orderBy('addtime', 'desc') ->get(); return $res; } @@ -220,47 +227,47 @@ class CouponRebateService implements CouponRebateServiceInterface * 将优惠券绑定活动 * 领取优惠券 COUPON_REBATE_FORWARD 可多张 * 返还优惠券 COUPON_REBATE_REPAY 只一张 - */ - public function tieCouponActive($couponActivity,$couponForward,$couponRepay) + */ + public function tieCouponActive($couponActivity, $couponForward, $couponRepay) { $result = [ 'forward' => true, - 'repay' => true, + 'repay' => true, ]; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $rrss1 = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$couponActivity); - $rrss2 = $ssdb->exec('get',SsdbKeysPrefix::COUPON_REBATE_REPAY.$couponActivity); - return [$rrss1,$rrss2]; + $rrss1 = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity); + $rrss2 = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity); + return [$rrss1, $rrss2]; // 记录领取类型优惠券 $forwardData = []; - foreach($couponForward as $kForward => $vForward){ + foreach ($couponForward as $kForward => $vForward) { $forwardData[] = $kForward; $forwardData[] = $vForward; } - if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$couponActivity,$forwardData)){ + if (false === $ssdb->exec('multi_hset', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity, $forwardData)) { $this->log->event( LogLabel::COUPON_LOG, [ 'coupon_activity' => $couponActivity, - 'coupon_forward' => $forwardData, - 'msg' => '绑定-领取-优惠券到ssdb失败' + 'coupon_forward' => $forwardData, + 'msg' => '绑定-领取-优惠券到ssdb失败' ] ); $result['forward'] = false; }; // 记录返还类型优惠券 - if(false === $ssdb->exec('set',SsdbKeysPrefix::COUPON_REBATE_REPAY.$couponActivity,$couponRepay)){ + if (false === $ssdb->exec('set', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity, $couponRepay)) { $this->log->event( LogLabel::COUPON_LOG, [ 'coupon_activity' => $couponActivity, - 'coupon_Repay' => $couponRepay, - 'msg' => '绑定-返还-优惠券到ssdb失败' + 'coupon_Repay' => $couponRepay, + 'msg' => '绑定-返还-优惠券到ssdb失败' ] ); $result['repay'] = false; @@ -344,4 +351,5 @@ class CouponRebateService implements CouponRebateServiceInterface return '返券成功'; - }} \ No newline at end of file + } +} \ No newline at end of file From a529ccc46a9737c057dc6b6b61cee6e852f0393f Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Thu, 6 Aug 2020 15:27:47 +0800 Subject: [PATCH 38/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E5=8E=BB=E6=8E=89=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/SsdbKeysPrefix.php | 2 +- app/Service/CouponService.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Constants/SsdbKeysPrefix.php b/app/Constants/SsdbKeysPrefix.php index 2550f84..d747600 100644 --- a/app/Constants/SsdbKeysPrefix.php +++ b/app/Constants/SsdbKeysPrefix.php @@ -30,5 +30,5 @@ class SsdbKeysPrefix extends AbstractConstants /** * @Message("Coupon rebate Key Prefix") */ - const COUPON_REBATE_REPAY = 'coupon_rebate_REPAY_'; + const COUPON_REBATE_REPAY = 'coupon_rebate_repay_'; } diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index d980954..39c91c8 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -39,7 +39,7 @@ class CouponService implements CouponServiceInterface ]; $nowTime = time(); $c_ids = []; -$result['active_type'] = 1; + // 渠道开启,查询该渠道可以领取的优惠券ID // 渠道未开启,查询所有优惠券 if (env('SUB_CHANNEL') == 1) { From 3d764144c2161174cc0b95ac30b2553a2f9619a3 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Thu, 6 Aug 2020 15:49:18 +0800 Subject: [PATCH 39/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=BC=98=E6=83=A0=E5=88=B8=E6=8E=A5=E5=8F=A3getSystem?= =?UTF-8?q?CouponUserList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 6 +++--- app/Service/CouponService.php | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index da4b6da..8bce00e 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -236,9 +236,9 @@ class CouponRebateService implements CouponRebateServiceInterface ]; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $rrss1 = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity); - $rrss2 = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity); - return [$rrss1, $rrss2]; + // $rrss1 = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity); + // $rrss2 = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity); + // return [$rrss2]; // 记录领取类型优惠券 $forwardData = []; foreach ($couponForward as $kForward => $vForward) { diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 39c91c8..67f9e56 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -33,7 +33,7 @@ class CouponService implements CouponServiceInterface 'not_receive' => [], 'jump_data' => [ 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, + 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'coupons' => [] ] ]; @@ -67,8 +67,7 @@ class CouponService implements CouponServiceInterface // 获取领取型优惠券 $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $couponRebateIds = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$activityType); - // $result['active_type'] = $couponRebateIds; - // return $result; + $couponIds = ($couponRebateIds === false || empty($couponRebateIds)) ? $couponIds : array_merge($couponIds,$couponRebateIds) ; $whereC = [ @@ -92,11 +91,13 @@ class CouponService implements CouponServiceInterface ->get(); foreach ($coupons as $k => &$v){ - if($v['active_type'] == 1){ + + if($v->active_type == 1){ $result['not_receive'] = $v; - }else if($v['active_type'] == 2){ - $result['jump_data']['coupons'][] = $v; + }else if($v->active_type == 2){ + $result['jump_data']['coupons'][] = $v->id; } + if($v->discount_type == 2){ $v->discounts = floatval($v->discounts); } From 7fdba93322e0c4e9cc54042889d70a8112cd32e3 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Thu, 6 Aug 2020 16:50:07 +0800 Subject: [PATCH 40/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E8=AE=B0=E5=BD=95=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E6=B4=BB=E5=8A=A8=E6=A0=87=E8=AF=86=E5=80=BCactivity?= =?UTF-8?q?=5Ftype=E5=88=B0ssdb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/SsdbKeysPrefix.php | 5 +++++ app/Service/CouponRebateService.php | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Constants/SsdbKeysPrefix.php b/app/Constants/SsdbKeysPrefix.php index d747600..1e721c2 100644 --- a/app/Constants/SsdbKeysPrefix.php +++ b/app/Constants/SsdbKeysPrefix.php @@ -31,4 +31,9 @@ class SsdbKeysPrefix extends AbstractConstants * @Message("Coupon rebate Key Prefix") */ const COUPON_REBATE_REPAY = 'coupon_rebate_repay_'; + + /** + * @Message("Coupon rebate Key Prefix") + */ + const COUPON_REBATE_ACTIVITY = 'coupon_rebate_activity'; } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 8bce00e..f46e973 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -233,12 +233,28 @@ class CouponRebateService implements CouponRebateServiceInterface $result = [ 'forward' => true, 'repay' => true, + 'activity' => true, ]; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); // $rrss1 = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity); // $rrss2 = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity); - // return [$rrss2]; + // $rrss3 = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); + // return [$rrss3]; + + // 记录活动本次 activity_type 活动标志值 + if (false === $ssdb->exec('set', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY, $couponActivity)) { + + $this->log->event( + LogLabel::COUPON_LOG, + [ + 'coupon_activity' => $couponActivity, + 'msg' => '记录活动标志值(activity_type)到ssdb失败' + ] + ); + $result['activity'] = false; + }; + // 记录领取类型优惠券 $forwardData = []; foreach ($couponForward as $kForward => $vForward) { @@ -272,6 +288,7 @@ class CouponRebateService implements CouponRebateServiceInterface ); $result['repay'] = false; }; + return $result; } From d583c82bcd78487fb4403b6e4341b477441cae44 Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 6 Aug 2020 17:25:10 +0800 Subject: [PATCH 41/66] =?UTF-8?q?app=5Fenv=E8=AE=BE=E7=BD=AE=E4=B8=BAlocal?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E8=BF=9B=E8=A1=8Capi=20auth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 371ecf76c89ec444796d8831b8594100272196ab) --- app/Middleware/Auth/ApiMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Middleware/Auth/ApiMiddleware.php b/app/Middleware/Auth/ApiMiddleware.php index ce06bff..44cf3fc 100644 --- a/app/Middleware/Auth/ApiMiddleware.php +++ b/app/Middleware/Auth/ApiMiddleware.php @@ -39,7 +39,7 @@ class ApiMiddleware implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - if (env('APP_ENV') == 'dev') { + if (env('APP_ENV') == 'dev' || env('APP_ENV') == 'local') { return $handler->handle($request); } From 343a4be0b9be137c1a46af2dcccf79e86c83a11f Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Thu, 6 Aug 2020 17:51:17 +0800 Subject: [PATCH 42/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BC=98=E5=8C=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=A2=86=E5=8F=96=E4=BC=98=E6=83=A0=E5=88=B8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 240 +++++++++++++++------------- 1 file changed, 128 insertions(+), 112 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index f46e973..a3bff6e 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -36,7 +36,7 @@ class CouponRebateService implements CouponRebateServiceInterface $sendUserId = $params["send_user_id"]; $phone = $params["phone"]; $now = time(); - $ids = is_array($ids) ? $ids : explode(',',$ids); + $idsData = is_array($ids) ? $ids : explode(',',$ids); // status: 0领取成功 >0领取失败 $result = [ @@ -53,81 +53,102 @@ class CouponRebateService implements CouponRebateServiceInterface 'phone' =>$phone ]; + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $receiveSsdb = []; - try{ - Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData,&$receiveSsdb) { - - $success = []; - $fail = []; - $isr = []; - - //读写锁,完全控制,性能低 - $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts','active_type') - ->get(); - - foreach($coupons as $coupon){ - $errorData['coupon_id'] = $coupon->id; - - //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内可领取, 否则返回领取失败的优惠券 - if ( - $coupon->status == 1 - && - $coupon->inventory > $coupon->inventory_use - && - $coupon->start_time <= $now - && - $coupon->end_time >= $now - && - $coupon->active_type == 2 - ) - { - - // 查询一次能领取的数量 - $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$coupon->id)->select('one_receive_number'); - if (env('SUB_CHANNEL') == 1) { - $couponReceiveType->where('receive_type',$receiveType); - } - $couponReceiveType = $couponReceiveType->first(); - - // 优惠券可领取数量 >= 本次领取数量 - if($coupon->inventory - $coupon->inventory_use >= $couponReceiveType->one_receive_number){ - - // 判断是否领取过 存在记录则领取过 - $isReceive = CouponRec::select('id') - ->where('system_coupon_user_id',$coupon->id) - ->where('user_id',$userId) - ->exists(); - - if(!$isReceive){ - //记录已领取的数量 - $coupon->inventory_use += $couponReceiveType->number; - - $couponReceive = new CouponRec; - $couponReceive->user_id = $userId; - $couponReceive->system_coupon_user_id = $coupon->id; - $couponReceive->order_main_id = 0; - $couponReceive->receive_time = $now; - $couponReceive->number = $couponReceiveType->one_receive_number; - $couponReceive->number_remain = $couponReceiveType->one_receive_number; - $couponReceive->status = 0; - $couponReceive->update_time = $now; - $couponReceive->receive_type = $receiveType; - $couponReceive->send_user_id = $sendUserId; - $couponReceive->phone = $phone; - - // if ( $couponReceive->save() && $coupon->save() ) { - // $success[] = $coupon; - // $receiveSsdb[] = $coupon->id;; - // } + // 判断是否已全部领取 + $couponActivity = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); + $userReceiveCouponIds = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity); + if($userReceiveCouponIds !== false){ + $ids = array_diff($idsData, $userReceiveCouponIds); + }else{ + $ids = $idsData; + } + + if(count($ids) > 0){ + try{ + Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData,&$receiveSsdb) { + + $success = []; + $fail = []; + $isr = []; + + //读写锁,完全控制,性能低 + $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() + ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts','active_type') + ->get(); + + foreach($coupons as $coupon){ + $errorData['coupon_id'] = $coupon->id; + + //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内可领取, 否则返回领取失败的优惠券 + if ( + $coupon->status == 1 + && + $coupon->inventory > $coupon->inventory_use + && + $coupon->start_time <= $now + && + $coupon->end_time >= $now + && + $coupon->active_type == 2 + ) + { + + // 查询一次能领取的数量 + $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$coupon->id)->select('one_receive_number'); + if (env('SUB_CHANNEL') == 1) { + $couponReceiveType->where('receive_type',$receiveType); + } + $couponReceiveType = $couponReceiveType->first(); + + // 优惠券可领取数量 >= 本次领取数量 + if($coupon->inventory - $coupon->inventory_use >= $couponReceiveType->one_receive_number){ + + // 判断是否领取过 存在记录则领取过 + $isReceive = CouponRec::select('id') + ->where('system_coupon_user_id',$coupon->id) + ->where('user_id',$userId) + ->exists(); + + if(!$isReceive){ + //记录已领取的数量 + $coupon->inventory_use += $couponReceiveType->number; + + $couponReceive = new CouponRec; + $couponReceive->user_id = $userId; + $couponReceive->system_coupon_user_id = $coupon->id; + $couponReceive->order_main_id = 0; + $couponReceive->receive_time = $now; + $couponReceive->number = $couponReceiveType->one_receive_number; + $couponReceive->number_remain = $couponReceiveType->one_receive_number; + $couponReceive->status = 0; + $couponReceive->update_time = $now; + $couponReceive->receive_type = $receiveType; + $couponReceive->send_user_id = $sendUserId; + $couponReceive->phone = $phone; + + // if ( $couponReceive->save() && $coupon->save() ) { + // $success[] = $coupon; + // $receiveSsdb[] = $coupon->id;; + // } + }else{ + $fail[] = $coupon; + $receiveSsdb[] = $coupon->id; + $result['status'] = 2; + $result['coupon_text'] = '您已领取!赶快去下单吧~'; + + $errorData['msg'] = '用户已经领取了优惠券'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } }else{ $fail[] = $coupon; - $receiveSsdb[] = $coupon->id; - $result['status'] = 2; - $result['coupon_text'] = '您已领取!赶快去下单吧~'; - - $errorData['msg'] = '用户已经领取了优惠券'; + $errorData['remain_receive_number'] = $coupon->inventory - $coupon->inventory_use; + $errorData['one_receive_number'] = $couponReceiveType->one_receive_number; + $errorData['msg'] = '优惠券剩余数量不足'; $this->log->event( LogLabel::COUPON_LOG, $errorData @@ -135,55 +156,50 @@ class CouponRebateService implements CouponRebateServiceInterface } }else{ $fail[] = $coupon; - $errorData['remain_receive_number'] = $coupon->inventory - $coupon->inventory_use; - $errorData['one_receive_number'] = $couponReceiveType->one_receive_number; - $errorData['msg'] = '优惠券剩余数量不足'; + $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; $this->log->event( LogLabel::COUPON_LOG, $errorData ); } - }else{ - $fail[] = $coupon; - $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); } - } - $result['data'] = [ - 'success' => $success, - 'fail' => $fail - ]; - if(count($success) > 0){ - $result['status'] = 0; - $result['coupon_text'] = '恭喜您领取成功!'; - } - }); - } catch (Exception $e){ - $errorData['msg'] = $e->getMessage(); - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); - } - if(count($receiveSsdb) > 0){ - $saveSsdb = []; - foreach($receiveSsdb as $kssdb => $vssdb){ - $saveSsdb[] = $kssdb; - $saveSsdb[] = $vssdb; - } - // 记录到ssdb - $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$saveSsdb)){ - $errorData['msg'] = '记录领取优惠券到ssdb失败'; + $result['data'] = [ + 'success' => $success, + 'fail' => $fail + ]; + if(count($success) > 0){ + $result['status'] = 0; + $result['coupon_text'] = '恭喜您领取成功!'; + } + }); + } catch (Exception $e){ + $errorData['msg'] = $e->getMessage(); $this->log->event( LogLabel::COUPON_LOG, $errorData ); - }; + } + + if(count($receiveSsdb) > 0){ + $saveSsdb = []; + foreach($receiveSsdb as $kssdb => $vssdb){ + $saveSsdb[] = $kssdb; + $saveSsdb[] = $vssdb; + } + // 记录到ssdb + if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$saveSsdb)){ + $errorData['msg'] = '记录领取优惠券到ssdb失败'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + }; + } + }else{ + $result['status'] = 2; + $result['coupon_text'] = '您已领取!赶快去下单吧~'; } + return $result; } @@ -242,8 +258,8 @@ class CouponRebateService implements CouponRebateServiceInterface // $rrss3 = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); // return [$rrss3]; - // 记录活动本次 activity_type 活动标志值 - if (false === $ssdb->exec('set', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY, $couponActivity)) { + // 记录活动本次 activity_type 活动标志值 + if (false === $ssdb->exec('set', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY, $couponActivity)) { $this->log->event( LogLabel::COUPON_LOG, From 1a177615b96428daee09e84c1ef7b2fb58581fae Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 7 Aug 2020 10:08:11 +0800 Subject: [PATCH 43/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=B4=BB=E5=8A=A8=E6=A0=87=E5=BF=97acrtivity=5Ftype?= =?UTF-8?q?=E4=B8=BA=E9=80=9A=E8=BF=87ssdb=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 18 +++++++++--------- app/Service/CouponService.php | 12 +++++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index a3bff6e..c31cf19 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -36,7 +36,7 @@ class CouponRebateService implements CouponRebateServiceInterface $sendUserId = $params["send_user_id"]; $phone = $params["phone"]; $now = time(); - $idsData = is_array($ids) ? $ids : explode(',',$ids); + $idsData = is_array($ids) ? $ids : explode(',',$ids); // status: 0领取成功 >0领取失败 $result = [ @@ -57,8 +57,8 @@ class CouponRebateService implements CouponRebateServiceInterface $receiveSsdb = []; // 判断是否已全部领取 - $couponActivity = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); - $userReceiveCouponIds = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity); + $couponActivity = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY,0); + $userReceiveCouponIds = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $couponActivity . $userId); if($userReceiveCouponIds !== false){ $ids = array_diff($idsData, $userReceiveCouponIds); }else{ @@ -187,7 +187,7 @@ class CouponRebateService implements CouponRebateServiceInterface $saveSsdb[] = $vssdb; } // 记录到ssdb - if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$saveSsdb)){ + if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $couponActivity . $userId, $saveSsdb)){ $errorData['msg'] = '记录领取优惠券到ssdb失败'; $this->log->event( LogLabel::COUPON_LOG, @@ -254,12 +254,12 @@ class CouponRebateService implements CouponRebateServiceInterface $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); // $rrss1 = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity); - // $rrss2 = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity); - // $rrss3 = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); - // return [$rrss3]; + // $rrss2 = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity,0); + // $rrss3 = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY,0); + // return [$rrss1,$rrss2,$rrss3]; // 记录活动本次 activity_type 活动标志值 - if (false === $ssdb->exec('set', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY, $couponActivity)) { + if (false === $ssdb->exec('hset', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY, [0,$couponActivity])) { $this->log->event( LogLabel::COUPON_LOG, @@ -292,7 +292,7 @@ class CouponRebateService implements CouponRebateServiceInterface }; // 记录返还类型优惠券 - if (false === $ssdb->exec('set', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity, $couponRepay)) { + if (false === $ssdb->exec('hset', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity, [0,$couponRepay])) { $this->log->event( LogLabel::COUPON_LOG, diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 67f9e56..c0ff451 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -27,13 +27,16 @@ class CouponService implements CouponServiceInterface */ public function getSystemCouponUserList($userId,$receiveType) { - $activityType = 2;/* 优惠券活动标志 2 */ + /* 优惠券活动标志 2 */ + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $couponActivity = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY,0); + $result = [ 'active_type' => 1, 'not_receive' => [], 'jump_data' => [ - 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, + 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$couponActivity, + 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$couponActivity, 'coupons' => [] ] ]; @@ -65,8 +68,7 @@ class CouponService implements CouponServiceInterface $couponIds = array_diff($c_ids, $cr_ids); // 获取领取型优惠券 - $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $couponRebateIds = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$activityType); + $couponRebateIds = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$couponActivity); $couponIds = ($couponRebateIds === false || empty($couponRebateIds)) ? $couponIds : array_merge($couponIds,$couponRebateIds) ; From 5961de7d49adab31d000458076e7e3502eab7dfc Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 7 Aug 2020 10:25:26 +0800 Subject: [PATCH 44/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E7=BA=A2=E5=8C=85--=E9=A2=86=E5=8F=96=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E5=B0=86=E4=BF=9D=E5=AD=98=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E8=B0=83=E8=AF=95=EF=BC=8C=E7=8E=B0=E5=9C=A8?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index c31cf19..be0225a 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -64,14 +64,13 @@ class CouponRebateService implements CouponRebateServiceInterface }else{ $ids = $idsData; } - + if(count($ids) > 0){ try{ Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData,&$receiveSsdb) { $success = []; $fail = []; - $isr = []; //读写锁,完全控制,性能低 $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() @@ -128,14 +127,14 @@ class CouponRebateService implements CouponRebateServiceInterface $couponReceive->send_user_id = $sendUserId; $couponReceive->phone = $phone; - // if ( $couponReceive->save() && $coupon->save() ) { - // $success[] = $coupon; - // $receiveSsdb[] = $coupon->id;; - // } + if ( $couponReceive->save() && $coupon->save() ) { + $success[] = $coupon; + $receiveSsdb[] = $coupon->id;; + } }else{ $fail[] = $coupon; $receiveSsdb[] = $coupon->id; - $result['status'] = 2; + $result['status'] = 3; $result['coupon_text'] = '您已领取!赶快去下单吧~'; $errorData['msg'] = '用户已经领取了优惠券'; From 8d1582cfd590fc03747420ad7a655b002870c425 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 7 Aug 2020 10:53:20 +0800 Subject: [PATCH 45/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E4=BF=AE=E6=94=B9=E9=A2=86=E5=8F=96=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3-ssdb=E8=AE=B0=E5=BD=95=E5=85=A8=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E6=83=A0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index be0225a..660e433 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -61,6 +61,7 @@ class CouponRebateService implements CouponRebateServiceInterface $userReceiveCouponIds = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $couponActivity . $userId); if($userReceiveCouponIds !== false){ $ids = array_diff($idsData, $userReceiveCouponIds); + $receiveSsdb = $userReceiveCouponIds; }else{ $ids = $idsData; } @@ -129,7 +130,7 @@ class CouponRebateService implements CouponRebateServiceInterface if ( $couponReceive->save() && $coupon->save() ) { $success[] = $coupon; - $receiveSsdb[] = $coupon->id;; + $receiveSsdb[] = $coupon->id; } }else{ $fail[] = $coupon; From e3b323d2a71c432b7a3cf29613e7f7346274af1f Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 7 Aug 2020 12:06:12 +0800 Subject: [PATCH 46/66] =?UTF-8?q?SSDB=20Task=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit e5ead242086db660d887f340c169a222d7c1a94d) --- app/Libs/SimpleSSDB.php | 2 +- app/TaskWorker/SSDBTask.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Libs/SimpleSSDB.php b/app/Libs/SimpleSSDB.php index b6920b2..c829bda 100644 --- a/app/Libs/SimpleSSDB.php +++ b/app/Libs/SimpleSSDB.php @@ -78,7 +78,7 @@ class SSDB function __construct($host, $port, $timeout_ms=2000){ $timeout_f = (float)$timeout_ms/1000; - $this->sock = @stream_socket_client("[$host]:$port", $errno, $errstr, $timeout_f); + $this->sock = @stream_socket_client("$host:$port", $errno, $errstr, $timeout_f); if(!$this->sock){ throw new SSDBException("$errno: $errstr"); } diff --git a/app/TaskWorker/SSDBTask.php b/app/TaskWorker/SSDBTask.php index 9c6ef29..fd4d451 100644 --- a/app/TaskWorker/SSDBTask.php +++ b/app/TaskWorker/SSDBTask.php @@ -24,6 +24,13 @@ class SSDBTask return $result; } + public function execWithoutTask($method,...$args) + { + $result = $this->client()->__call($method,$args); + + return $result; + } + protected function client(){ if ($this->ss instanceof SimpleSSDB) { return $this->ss; From 7d989e3d6f4349ce6c977202d9b6f7889ca8837d Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Fri, 7 Aug 2020 12:07:40 +0800 Subject: [PATCH 47/66] =?UTF-8?q?=E8=BF=94=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 115 ++++++++++++++++++---------- 1 file changed, 73 insertions(+), 42 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index be0225a..6641015 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -312,6 +312,18 @@ class CouponRebateService implements CouponRebateServiceInterface */ public function couponRebate($order_id) { + //$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + // $active_id = $ssdb->exec('get',SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); + // $rebate_id = $ssdb->exec('get',SsdbKeysPrefix::COUPON_REBATE_REPAY.$active_id); + $rebate_id = 56; + //判断该优惠券是否有库存 + $inventory = Db::table('ims_system_coupon_user') + ->where('id',$rebate_id) + ->whereRaw('inventory > inventory_use') + ->exists(); + if(!$inventory){ + return '库存不足'; + } /* 判断优惠券类型是否为转发活动优惠券 */ $coupon = Db::table('ims_system_coupon_user_receive as r') ->leftjoin('ims_system_coupon_user_use as u', 'u.user_receive_id', '=', 'r.id') @@ -322,63 +334,82 @@ class CouponRebateService implements CouponRebateServiceInterface ['r.receive_type', '=', 4], ['u.status', '=', 1], ]) - ->select('r.id', 'r.send_user_id', 'u.system_coupon_id') + ->select('r.id', 'r.user_id', 'r.send_user_id', 'u.system_coupon_id') ->first(); /* 如果使用的优惠券为转发活动优惠券 则给赠送者返一张优惠券*/ if (isset($coupon->send_user_id) && ($coupon->send_user_id) > 0) { - //判断该优惠券是否有库存 -// $inventory = Db::table('system_coupon_user_receive as r'); -// if($inventory['inventory'] <= 0){ -// return '库存不足'; -// } - //return $exist_coupon; + //是否已返过券 + $exists_coupon_rebate = Db::table('ims_system_coupon_user_receive') + ->where([ + ['system_coupon_user_id' ,'=', $rebate_id], + ['user_id' ,'=', $coupon->send_user_id], + ['receive_type' ,'=', 5], + ['status' ,'=', 0], + ]) + ->exists(); //开启事务 + Db::beginTransaction(); try { /* * 如果已有该优惠券 则领取数量 和 可用数量 自增1 * 否则新增一条返券记录 */ - $nowTime = time(); - $res = Db::table('ims_system_coupon_user_receive')->moreIncrementOrInsert( - [ - 'system_coupon_user_id' => $coupon->system_coupon_id, - 'user_id' => $coupon->send_user_id, - 'receive_type' => 5, - 'status' => 0, - ], - [ - 'order_main_id' => $order_id, - 'receive_time' => $nowTime, - 'update_time' => $nowTime, - 'created_at' => $nowTime, - 'updated_at' => $nowTime, - ], - [ - 'number' => 1, - 'number_remain' => 1, - ] - ); -// if ($res) { -// //首次返券更新rebate_type字段 防止重复返券 -// Db::table('system_coupon_user_receive')->where('id', $coupon->id)->update(['rebate_type' => 2]); -// //更新库存操作 -// Db::table('system_coupon_user') -// ->where('id', $coupon->id) -// ->increment('inventory_use'); -// } else { -// Db::rollBack(); -// return '事务失败'; -// } + if($exists_coupon_rebate){ + var_dump(222); + Db::table('ims_system_coupon_user_receive') + ->where([ + ['user_id' ,'=', $coupon->send_user_id], + ['receive_type' ,'=', 5], + ]) + ->increment('number'); + Db::table('ims_system_coupon_user_receive') + ->where([ + ['user_id' ,'=', $coupon->send_user_id], + ['receive_type' ,'=', 5], + ]) + ->increment('number_remain'); + }else { + var_dump(111111222); + $nowTime = time(); + Db::table('ims_system_coupon_user_receive')->insert([ + [ + 'user_id' => $coupon->send_user_id, + 'system_coupon_user_id' => $rebate_id, + 'receive_type' => 5, + 'status' => 0, + 'number' => 1, + 'number_remain' => 1, + 'order_main_id' => $order_id, + 'receive_time' => $nowTime, + 'update_time' => $nowTime, + 'created_at' => $nowTime, + 'updated_at' => $nowTime, + ] + ]); + } + //首次返券更新rebate_type字段 防止重复返券 + Db::table('ims_system_coupon_user_receive') + ->where([ + ['user_id','=',$coupon->user_id], + ['receive_type','=',4], + ]) + ->update(['rebate_type' => 2]); + //更新库存操作 + Db::table('ims_system_coupon_user') + ->where('id', $rebate_id) + ->increment('inventory_use'); // 提交 Db::commit(); } catch (\Exception $e) { // 回滚 Db::rollBack(); - return '返券失败'; + $errorData['order_main_id'] = $order_id; + $errorData['msg'] = '返券失败'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); } - } else { -// $str1 = 'order_main_id:'.$this->order_id . ',未查询到用户领取优惠券信息['.$coupon.']'; -// $this->couponErrorLog($str1); } From b0e417ff34b3849d7305277d8bbd79bb0752af05 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 7 Aug 2020 16:33:56 +0800 Subject: [PATCH 48/66] =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=96=B0=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/OrderMain.php | 10 +++++++++ app/Service/UserService.php | 31 ++++++++++++++++++++++++++++ app/Service/UserServiceInterface.php | 15 ++++++++++++++ config/autoload/dependencies.php | 1 + config/autoload/middlewares.php | 2 +- 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 app/Model/OrderMain.php create mode 100644 app/Service/UserService.php create mode 100644 app/Service/UserServiceInterface.php diff --git a/app/Model/OrderMain.php b/app/Model/OrderMain.php new file mode 100644 index 0000000..7c7eb3d --- /dev/null +++ b/app/Model/OrderMain.php @@ -0,0 +1,10 @@ +where(['user_id' => $user_id]) + ->where(function ($query){ + $query->where('state', 'in', [4,5,10]) + ->orWhere('dm_state', 'in', [2,3]); + }) + ->exists(); + + return !$exist; + } +} \ No newline at end of file diff --git a/app/Service/UserServiceInterface.php b/app/Service/UserServiceInterface.php new file mode 100644 index 0000000..c5bf647 --- /dev/null +++ b/app/Service/UserServiceInterface.php @@ -0,0 +1,15 @@ + \App\Service\AdService::class, \App\Commons\Log::class => \App\Commons\Log::class, \App\Service\CouponRebateServiceInterface::class => \App\Service\CouponRebateService::class, + \App\Service\UserServiceInterface::class => \App\Service\UserService::class, ]; diff --git a/config/autoload/middlewares.php b/config/autoload/middlewares.php index 5eb19a5..2befbcd 100644 --- a/config/autoload/middlewares.php +++ b/config/autoload/middlewares.php @@ -11,8 +11,8 @@ declare(strict_types=1); */ return [ 'http' => [ + \App\Middleware\CorsMiddleware::class, \App\Middleware\Auth\ApiMiddleware::class, \Hyperf\Validation\Middleware\ValidationMiddleware::class, - \App\Middleware\CorsMiddleware::class, ], ]; From e695f5553d593d05b8de188dedc64bea23819945 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 7 Aug 2020 17:43:21 +0800 Subject: [PATCH 49/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8--=E6=B7=BB=E5=8A=A0=E6=B8=85=E9=99=A4=E9=A2=86?= =?UTF-8?q?=E5=8F=96=E8=AE=B0=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 12 +- app/Service/CouponRebateService.php | 234 +++++++------------ app/Service/CouponRebateServiceInterface.php | 4 +- app/Service/CouponService.php | 13 +- config/routes.php | 4 +- 5 files changed, 110 insertions(+), 157 deletions(-) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 84ef098..dd9ed65 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -73,10 +73,20 @@ class CouponRebateController extends BaseController public function tieCouponActive(CouponRebateTieRequest $validator) { $couponForward = $this->request->input('coupon_forward_ids',[]); - $couponForward = is_array($couponForward) ? $couponForward : explode(',',$couponForward) ; + $couponForward = is_array($couponForward) ? implode(',',$couponForward) : $couponForward ; $couponRepay = $this->request->input('coupon_repay_id',0); $couponActivity = $this->request->input('coupon_activity',0); $res = $this->CouponRebateService->tieCouponActive($couponActivity,$couponForward,$couponRepay); return $this->success($res); } + + /** + * 清优惠券领取记录(SSDB) + */ + public function clearSsdbCouponReceiveByName(){ + $activity = $this->request->input('activity_type',0); + $userId = $this->request->input('user_id',0); + $get = $this->request->input('get',0); + return $this->success($this->CouponRebateService->clearSsdbCouponReceiveByName($activity,$userId, $get)); + } } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 660e433..ecc0c6a 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -14,6 +14,8 @@ use App\TaskWorker\SSDBTask; use App\Constants\SsdbKeysPrefix; use Exception; +use function AlibabaCloud\Client\json; + class CouponRebateService implements CouponRebateServiceInterface { /** @@ -35,7 +37,6 @@ class CouponRebateService implements CouponRebateServiceInterface $ids = $params["ids"]; $sendUserId = $params["send_user_id"]; $phone = $params["phone"]; - $now = time(); $idsData = is_array($ids) ? $ids : explode(',',$ids); // status: 0领取成功 >0领取失败 @@ -54,119 +55,85 @@ class CouponRebateService implements CouponRebateServiceInterface ]; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $activity = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY ,'activity'); $receiveSsdb = []; - // 判断是否已全部领取 - $couponActivity = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY,0); - $userReceiveCouponIds = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $couponActivity . $userId); - if($userReceiveCouponIds !== false){ + // 判断是否已全部领取过 + $userReceive = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId); + if($userReceive === false){ + $ids = $idsData; + }else{ + $userReceiveCouponIds = empty($userReceive) ? [] : $userReceive ; $ids = array_diff($idsData, $userReceiveCouponIds); $receiveSsdb = $userReceiveCouponIds; - }else{ - $ids = $idsData; } if(count($ids) > 0){ try{ - Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData,&$receiveSsdb) { - + Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,&$result,&$errorData,&$receiveSsdb) { + + $now = time(); $success = []; - $fail = []; - //读写锁,完全控制,性能低 + //获取优惠券信息 (读写锁,完全控制,性能低) $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts','active_type') + ->where('active_type',2) + ->where('status',1) + ->where('start_time', '<=', $now) + ->where('end_time', '>=', $now) + ->whereRaw('inventory > inventory_use') + ->select('id','title','inventory','inventory_use','full_amount','discounts','active_type') ->get(); foreach($coupons as $coupon){ $errorData['coupon_id'] = $coupon->id; - - //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内可领取, 否则返回领取失败的优惠券 - if ( - $coupon->status == 1 - && - $coupon->inventory > $coupon->inventory_use - && - $coupon->start_time <= $now - && - $coupon->end_time >= $now - && - $coupon->active_type == 2 - ) - { - - // 查询一次能领取的数量 - $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$coupon->id)->select('one_receive_number'); - if (env('SUB_CHANNEL') == 1) { - $couponReceiveType->where('receive_type',$receiveType); - } - $couponReceiveType = $couponReceiveType->first(); - - // 优惠券可领取数量 >= 本次领取数量 - if($coupon->inventory - $coupon->inventory_use >= $couponReceiveType->one_receive_number){ - - // 判断是否领取过 存在记录则领取过 - $isReceive = CouponRec::select('id') - ->where('system_coupon_user_id',$coupon->id) - ->where('user_id',$userId) - ->exists(); - - if(!$isReceive){ - //记录已领取的数量 - $coupon->inventory_use += $couponReceiveType->number; - - $couponReceive = new CouponRec; - $couponReceive->user_id = $userId; - $couponReceive->system_coupon_user_id = $coupon->id; - $couponReceive->order_main_id = 0; - $couponReceive->receive_time = $now; - $couponReceive->number = $couponReceiveType->one_receive_number; - $couponReceive->number_remain = $couponReceiveType->one_receive_number; - $couponReceive->status = 0; - $couponReceive->update_time = $now; - $couponReceive->receive_type = $receiveType; - $couponReceive->send_user_id = $sendUserId; - $couponReceive->phone = $phone; - - if ( $couponReceive->save() && $coupon->save() ) { - $success[] = $coupon; - $receiveSsdb[] = $coupon->id; - } + + // 查询一次能领取的数量 + $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$coupon->id)->select('one_receive_number'); + if (env('SUB_CHANNEL') == 1) { + $couponReceiveType->where('receive_type',$receiveType); + } + $couponReceiveType = $couponReceiveType->first(); + + // 优惠券可领取数量 >= 本次领取数量 + if($coupon->inventory - $coupon->inventory_use >= $couponReceiveType->one_receive_number){ + + // 判断是否领取过 存在记录则领取过 + $isReceive = CouponRec::select('id') + ->where('system_coupon_user_id',$coupon->id) + ->where('user_id',$userId) + ->exists(); + + if(!$isReceive){ + //记录已领取的数量 + $coupon->inventory_use += $couponReceiveType->number; + + $couponReceive = new CouponRec; + $couponReceive->user_id = $userId; + $couponReceive->system_coupon_user_id = $coupon->id; + $couponReceive->order_main_id = 0; + $couponReceive->receive_time = $now; + $couponReceive->number = $couponReceiveType->one_receive_number; + $couponReceive->number_remain = $couponReceiveType->one_receive_number; + $couponReceive->status = 0; + $couponReceive->update_time = $now; + $couponReceive->receive_type = $receiveType; + $couponReceive->send_user_id = $sendUserId; + $couponReceive->phone = $phone; + + if ( $couponReceive->save() && $coupon->save() ) { + $success[] = $coupon; + $receiveSsdb[] = $coupon->id; }else{ - $fail[] = $coupon; - $receiveSsdb[] = $coupon->id; - $result['status'] = 3; - $result['coupon_text'] = '您已领取!赶快去下单吧~'; - - $errorData['msg'] = '用户已经领取了优惠券'; + $errorData['msg'] = '添加优惠券到用户领取表或者记录已领取数量失败'; $this->log->event( LogLabel::COUPON_LOG, $errorData ); } - }else{ - $fail[] = $coupon; - $errorData['remain_receive_number'] = $coupon->inventory - $coupon->inventory_use; - $errorData['one_receive_number'] = $couponReceiveType->one_receive_number; - $errorData['msg'] = '优惠券剩余数量不足'; - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); } - }else{ - $fail[] = $coupon; - $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); } } - $result['data'] = [ - 'success' => $success, - 'fail' => $fail - ]; if(count($success) > 0){ $result['status'] = 0; $result['coupon_text'] = '恭喜您领取成功!'; @@ -187,8 +154,8 @@ class CouponRebateService implements CouponRebateServiceInterface $saveSsdb[] = $vssdb; } // 记录到ssdb - if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $couponActivity . $userId, $saveSsdb)){ - $errorData['msg'] = '记录领取优惠券到ssdb失败'; + if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId, $saveSsdb)){ + $errorData['msg'] = '记录领取优惠券到ssdb失败'; $this->log->event( LogLabel::COUPON_LOG, $errorData @@ -246,64 +213,19 @@ class CouponRebateService implements CouponRebateServiceInterface */ public function tieCouponActive($couponActivity, $couponForward, $couponRepay) { - $result = [ - 'forward' => true, - 'repay' => true, - 'activity' => true, - ]; - + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - // $rrss1 = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity); - // $rrss2 = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity,0); - // $rrss3 = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY,0); - // return [$rrss1,$rrss2,$rrss3]; - - // 记录活动本次 activity_type 活动标志值 - if (false === $ssdb->exec('hset', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY, [0,$couponActivity])) { - - $this->log->event( - LogLabel::COUPON_LOG, - [ - 'coupon_activity' => $couponActivity, - 'msg' => '记录活动标志值(activity_type)到ssdb失败' - ] - ); - $result['activity'] = false; - }; - // 记录领取类型优惠券 - $forwardData = []; - foreach ($couponForward as $kForward => $vForward) { - $forwardData[] = $kForward; - $forwardData[] = $vForward; - } - - if (false === $ssdb->exec('multi_hset', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity, $forwardData)) { - - $this->log->event( - LogLabel::COUPON_LOG, - [ - 'coupon_activity' => $couponActivity, - 'coupon_forward' => $forwardData, - 'msg' => '绑定-领取-优惠券到ssdb失败' - ] - ); - $result['forward'] = false; - }; - - // 记录返还类型优惠券 - if (false === $ssdb->exec('hset', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity, [0,$couponRepay])) { + $data = [ + 'activity', $couponActivity, + 'forward' , $couponForward, + 'repay' , $couponRepay + ]; - $this->log->event( - LogLabel::COUPON_LOG, - [ - 'coupon_activity' => $couponActivity, - 'coupon_Repay' => $couponRepay, - 'msg' => '绑定-返还-优惠券到ssdb失败' - ] - ); - $result['repay'] = false; - }; + $result = [ + 'result' => ($ssdb->exec('multi_hset', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY, $data) === false) ? false : true , + 'data' => $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY) + ]; return $result; } @@ -385,4 +307,22 @@ class CouponRebateService implements CouponRebateServiceInterface return '返券成功'; } + + /** + * 清优惠券领取记录(SSDB) + */ + public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0){ + + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + + if($get > 0){ + return [ + $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ), + $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $userId ), + SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId + ]; + } + + return ( $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ) === false) ? false : true; + } } \ No newline at end of file diff --git a/app/Service/CouponRebateServiceInterface.php b/app/Service/CouponRebateServiceInterface.php index 0e97dca..6b6edf9 100644 --- a/app/Service/CouponRebateServiceInterface.php +++ b/app/Service/CouponRebateServiceInterface.php @@ -15,6 +15,8 @@ interface CouponRebateServiceInterface public function tieCouponActive($couponActivity,$couponForward,$couponRepay); - public function couponRebate($order_id); + public function couponRebate($order_id); + + public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0); } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index c0ff451..915dc6e 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -29,14 +29,15 @@ class CouponService implements CouponServiceInterface { /* 优惠券活动标志 2 */ $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $couponActivity = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY,0); + $couponActivity = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); + $activityType = $couponActivity === false ? 0 : $couponActivity['activity']; $result = [ 'active_type' => 1, 'not_receive' => [], 'jump_data' => [ - 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$couponActivity, - 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$couponActivity, + 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, + 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'coupons' => [] ] ]; @@ -67,10 +68,8 @@ class CouponService implements CouponServiceInterface // 当前用户可领的优惠券ID $couponIds = array_diff($c_ids, $cr_ids); - // 获取领取型优惠券 - $couponRebateIds = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$couponActivity); - - $couponIds = ($couponRebateIds === false || empty($couponRebateIds)) ? $couponIds : array_merge($couponIds,$couponRebateIds) ; + // 获取领取型优惠券 + $couponIds = $couponActivity['forward'] === false ? $couponIds : array_merge($couponIds,explode(',',$couponActivity['forward'])); $whereC = [ ['u.end_time','>',$nowTime], diff --git a/config/routes.php b/config/routes.php index f2a579b..174546f 100644 --- a/config/routes.php +++ b/config/routes.php @@ -31,5 +31,7 @@ Router::addGroup('/v1/',function (){ Router::post('CouponRebate/getActiveInfo', 'App\Controller\CouponRebateController@getActiveInfo'); Router::post('CouponRebate/tieCouponActive', 'App\Controller\CouponRebateController@tieCouponActive'); - Router::post('CouponRebate/couponRebate', 'App\Controller\CouponRebateController@couponRebate'); + Router::post('CouponRebate/couponRebate', 'App\Controller\CouponRebateController@couponRebate'); + Router::post('CouponRebate/clearSsdbReceive', 'App\Controller\CouponRebateController@clearSsdbCouponReceiveByName'); + }); \ No newline at end of file From 0dbf1b1b17da7f1f4380d6938115d10045ca7566 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Fri, 7 Aug 2020 18:19:56 +0800 Subject: [PATCH 50/66] =?UTF-8?q?=E8=BF=94=E5=88=B8=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/couponRebateConsumer.php | 12 ++- app/Service/CouponRebateService.php | 89 ++++++++++++++-------- 2 files changed, 67 insertions(+), 34 deletions(-) diff --git a/app/Amqp/Consumer/couponRebateConsumer.php b/app/Amqp/Consumer/couponRebateConsumer.php index 475c7b9..e04615e 100644 --- a/app/Amqp/Consumer/couponRebateConsumer.php +++ b/app/Amqp/Consumer/couponRebateConsumer.php @@ -4,16 +4,19 @@ declare(strict_types=1); namespace App\Amqp\Consumer; +use App\Constants\SsdbKeysPrefix; use Hyperf\Amqp\Result; use Hyperf\Amqp\Annotation\Consumer; use Hyperf\Amqp\Message\ConsumerMessage; +use Hyperf\Utils\ApplicationContext; use PhpAmqpLib\Message\AMQPMessage; use App\Service\CouponRebateService; use App\Service\CouponRebateServiceInterface; use Hyperf\Di\Annotation\Inject; + /** - * @Consumer(exchange="couponRebate", routingKey="couponRebate", queue="couponRebate", name ="couponRebateConsumer", nums=1) + * @Consumer(exchange="couponRebate1", routingKey="couponRebate1", queue="couponRebate1", name ="couponRebateConsumer", nums=1) */ class couponRebateConsumer extends ConsumerMessage { @@ -25,10 +28,11 @@ class couponRebateConsumer extends ConsumerMessage public function consumeMessage($data, AMQPMessage $message): string { - var_dump($data); - var_dump($message->getBody()); + //var_dump($data); + //ar_dump($rebate_id); + //var_dump($message->getBody()); $res = $this->CouponRebateService->couponRebate($data); - var_dump($res); + //var_dump($res); if (false) { return Result::REQUEUE; } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index d3474ff..b3db743 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -208,8 +208,13 @@ class CouponRebateService implements CouponRebateServiceInterface * */ public function isCouponRebate($user_id) { + //获取SSDB上的活动信息 + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $active = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); + $coupon_ids = explode(',',$active['forward']); $res = Db::table('ims_system_coupon_user as u') ->leftjoin('ims_system_coupon_user_receive as r', 'u.id', '=', 'r.system_coupon_user_id') + ->whereIn('r.system_coupon_user_id',$coupon_ids) ->where([ ['r.user_id', '=', $user_id], ['r.receive_type', '=', 4], @@ -225,8 +230,13 @@ class CouponRebateService implements CouponRebateServiceInterface */ public function getActiveInfo() { + //获取SSDB上的活动信息 + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $active = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); + $coupon_ids = explode(',',$active['forward']); $time = time(); $res = Db::table('ims_system_coupon_user') + ->whereIn('id',$coupon_ids) ->where([ ['status', '=', 1], ['active_type', '=', 2], @@ -234,6 +244,7 @@ class CouponRebateService implements CouponRebateServiceInterface ['end_time', '>', $time], ]) ->whereRaw('inventory > inventory_use') + ->orderBy('weigh', 'desc') ->orderBy('addtime', 'desc') ->get(); return $res; @@ -313,19 +324,22 @@ class CouponRebateService implements CouponRebateServiceInterface */ public function couponRebate($order_id) { - //$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - // $active_id = $ssdb->exec('get',SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); - // $rebate_id = $ssdb->exec('get',SsdbKeysPrefix::COUPON_REBATE_REPAY.$active_id); - $rebate_id = 56; - //判断该优惠券是否有库存 + //获取SSDB上的活动信息 + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $active = $ssdb->execWithoutTask('hgetall',SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); + //判断返券优惠券是否有库存 $inventory = Db::table('ims_system_coupon_user') - ->where('id',$rebate_id) + ->where('id',$active['repay']) ->whereRaw('inventory > inventory_use') ->exists(); if(!$inventory){ return '库存不足'; } - /* 判断优惠券类型是否为转发活动优惠券 */ + + //获取活动发放优惠券id + $coupon_ids = explode(',',$active['forward']); + + /* 判断被使用的优惠券类型是否为转发活动优惠券 */ $coupon = Db::table('ims_system_coupon_user_receive as r') ->leftjoin('ims_system_coupon_user_use as u', 'u.user_receive_id', '=', 'r.id') ->where([ @@ -333,49 +347,52 @@ class CouponRebateService implements CouponRebateServiceInterface ['r.send_user_id', '>', 0], ['r.rebate_type', '=', 1], ['r.receive_type', '=', 4], - ['u.status', '=', 1], ]) - ->select('r.id', 'r.user_id', 'r.send_user_id', 'u.system_coupon_id') + ->whereIn('r.system_coupon_user_id',$coupon_ids) + ->select('r.user_id', 'r.send_user_id') ->first(); /* 如果使用的优惠券为转发活动优惠券 则给赠送者返一张优惠券*/ if (isset($coupon->send_user_id) && ($coupon->send_user_id) > 0) { //是否已返过券 $exists_coupon_rebate = Db::table('ims_system_coupon_user_receive') ->where([ - ['system_coupon_user_id' ,'=', $rebate_id], + ['system_coupon_user_id' ,'=', $active['repay']], ['user_id' ,'=', $coupon->send_user_id], ['receive_type' ,'=', 5], - ['status' ,'=', 0], ]) - ->exists(); + ->select('id','status') + ->first(); //开启事务 Db::beginTransaction(); try { - /* - * 如果已有该优惠券 则领取数量 和 可用数量 自增1 - * 否则新增一条返券记录 - */ - if($exists_coupon_rebate){ - var_dump(222); + //返券 + if($exists_coupon_rebate->id){ + //如果已有该优惠券 则领取数量 和 可用数量 自增1 Db::table('ims_system_coupon_user_receive') ->where([ - ['user_id' ,'=', $coupon->send_user_id], - ['receive_type' ,'=', 5], + ['id' ,'=', $exists_coupon_rebate->id], ]) ->increment('number'); Db::table('ims_system_coupon_user_receive') ->where([ - ['user_id' ,'=', $coupon->send_user_id], - ['receive_type' ,'=', 5], + ['id' ,'=', $exists_coupon_rebate->id], ]) ->increment('number_remain'); + //如果该用户在领取表中 status为已用完状态 2 则改为已用部分 1 + if($exists_coupon_rebate->status == 2){ + Db::table('ims_system_coupon_user_receive') + ->where([ + ['id' ,'=', $exists_coupon_rebate->id], + ]) + ->update(['status' => 1]);; + } }else { - var_dump(111111222); + //否则新增一条返券记录 $nowTime = time(); Db::table('ims_system_coupon_user_receive')->insert([ [ 'user_id' => $coupon->send_user_id, - 'system_coupon_user_id' => $rebate_id, + 'system_coupon_user_id' => $active['repay'], 'receive_type' => 5, 'status' => 0, 'number' => 1, @@ -394,26 +411,38 @@ class CouponRebateService implements CouponRebateServiceInterface ['user_id','=',$coupon->user_id], ['receive_type','=',4], ]) + ->whereIn('system_coupon_user_id',$coupon_ids) ->update(['rebate_type' => 2]); //更新库存操作 Db::table('ims_system_coupon_user') - ->where('id', $rebate_id) + ->where('id', $active['repay']['repay']) ->increment('inventory_use'); + // 提交 Db::commit(); } catch (\Exception $e) { // 回滚 Db::rollBack(); - $errorData['order_main_id'] = $order_id; - $errorData['msg'] = '返券失败'; + $log_Data = array(); + $log_Data['name'] = '返券'; + $log_Data['order_main_id'] = $order_id; + $log_Data['msg'] = '返券失败'; $this->log->event( LogLabel::COUPON_LOG, - $errorData + $log_Data ); } } - - + $log_Data = array(); + $log_Data['name'] = '返券'; + $log_Data['user_id'] = $order_id; + $log_Data['send_user_id'] = $coupon->send_user_id; + $log_Data['order_main_id'] = $order_id; + $log_Data['msg'] = '返券成功'; + $this->log->event( + LogLabel::COUPON_LOG, + $log_Data + ); return '返券成功'; } } \ No newline at end of file From 6eb8019119d686760a4a32c8242c752183eeaec6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Fri, 7 Aug 2020 18:24:54 +0800 Subject: [PATCH 51/66] =?UTF-8?q?=E8=BF=94=E5=88=B8=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/couponRebateConsumer.php | 2 +- app/Service/CouponRebateService.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Amqp/Consumer/couponRebateConsumer.php b/app/Amqp/Consumer/couponRebateConsumer.php index e04615e..239aee7 100644 --- a/app/Amqp/Consumer/couponRebateConsumer.php +++ b/app/Amqp/Consumer/couponRebateConsumer.php @@ -33,7 +33,7 @@ class couponRebateConsumer extends ConsumerMessage //var_dump($message->getBody()); $res = $this->CouponRebateService->couponRebate($data); //var_dump($res); - if (false) { + if (!$res) { return Result::REQUEUE; } return Result::ACK; diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index cc65a8e..233a4ae 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -255,7 +255,8 @@ class CouponRebateService implements CouponRebateServiceInterface ->whereRaw('inventory > inventory_use') ->exists(); if(!$inventory){ - return '库存不足'; + //库存不足 + return false; } //获取活动发放优惠券id @@ -365,7 +366,7 @@ class CouponRebateService implements CouponRebateServiceInterface LogLabel::COUPON_LOG, $log_Data ); - return '返券成功'; + return true; } /** From e043558427c6c2b26ecbd251f2b7ec0fadb01343 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Mon, 10 Aug 2020 16:30:00 +0800 Subject: [PATCH 52/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E5=87=8F=E5=BA=93=E5=AD=98?= =?UTF-8?q?=EF=BC=88=E5=8A=A0=E9=A2=86=E5=8F=96=E9=87=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 233a4ae..138b7a9 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -106,7 +106,7 @@ class CouponRebateService implements CouponRebateServiceInterface if(!$isReceive){ //记录已领取的数量 - $coupon->inventory_use += $couponReceiveType->number; + $coupon->inventory_use += $couponReceiveType->one_receive_number; $couponReceive = new CouponRec; $couponReceive->user_id = $userId; @@ -378,9 +378,7 @@ class CouponRebateService implements CouponRebateServiceInterface if($get > 0){ return [ - $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ), - $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $userId ), - SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId + $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ) ]; } From 1272da173d2a1dcb33a2e08ffc7b68dee92ed0f6 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Mon, 10 Aug 2020 19:35:05 +0800 Subject: [PATCH 53/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=88getSystemCouponUserList=EF=BC=89?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=94=E5=9B=9E=E8=83=8C=E6=99=AF=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 915dc6e..f43af83 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -36,9 +36,11 @@ class CouponService implements CouponServiceInterface 'active_type' => 1, 'not_receive' => [], 'jump_data' => [ - 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, + 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'coupons' => [] + 'share_bg' => "https://img.lanzulive.com/attachment/images/background/dangmian_dialog_background.png", + 'receive_bg' => "https://img.lanzulive.com/attachment/images/background/dangmian_dialog_background.png", + 'coupons' => [] ] ]; $nowTime = time(); From 7a8803643b81e4e0569b793a3327b1eb47613819 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Mon, 10 Aug 2020 20:38:57 +0800 Subject: [PATCH 54/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=BC=98=E6=83=A0=E5=88=B8=E5=88=86=E4=BA=AB=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E5=9B=BE=E7=89=87=E6=97=B6=E7=9A=84=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index f43af83..8b50689 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -38,8 +38,8 @@ class CouponService implements CouponServiceInterface 'jump_data' => [ 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'share_bg' => "https://img.lanzulive.com/attachment/images/background/dangmian_dialog_background.png", - 'receive_bg' => "https://img.lanzulive.com/attachment/images/background/dangmian_dialog_background.png", + 'share_bg' => env('OSS_IMG_HOST')."/attachment/images/background/dangmian_dialog_background.png", + 'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/background/dangmian_dialog_background.png", 'coupons' => [] ] ]; From 5febaa87c28accd3252539352886139533f780e6 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Mon, 10 Aug 2020 21:15:08 +0800 Subject: [PATCH 55/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E8=83=8C=E6=99=AF=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 8b50689..7c365f0 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -38,7 +38,7 @@ class CouponService implements CouponServiceInterface 'jump_data' => [ 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'share_bg' => env('OSS_IMG_HOST')."/attachment/images/background/dangmian_dialog_background.png", + 'share_bg' => env('OSS_IMG_HOST')."/attachment/images/png/2020/08/10/23245eea88db680670df67e77e0d8d7e.png", 'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/background/dangmian_dialog_background.png", 'coupons' => [] ] From b1156b71a3ff43979bdcf5ff8a4b39f10b691e30 Mon Sep 17 00:00:00 2001 From: weigang Date: Tue, 11 Aug 2020 12:57:08 +0800 Subject: [PATCH 56/66] =?UTF-8?q?Token=20name=E8=87=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/ParamsTokenSsdbService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/ParamsTokenSsdbService.php b/app/Service/ParamsTokenSsdbService.php index 65bd113..8aa60e2 100644 --- a/app/Service/ParamsTokenSsdbService.php +++ b/app/Service/ParamsTokenSsdbService.php @@ -26,7 +26,7 @@ class ParamsTokenSsdbService implements ParamsTokenServiceInterface */ public function generate($params) { - $token = md5(json_encode($params)); + $token = $params['token_name'] ?? md5(json_encode($params)); $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); From 7e51571ec36f24140d7b4056b3e4bdbb98d0064d Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 11 Aug 2020 15:31:54 +0800 Subject: [PATCH 57/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E9=A2=86?= =?UTF-8?q?=E5=8F=96=E4=BC=98=E6=83=A0=E5=88=B8=E5=AD=98ssdb=E7=9A=84?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponRebateController.php | 3 +- app/Service/CouponRebateService.php | 43 ++++++++++++-------- app/Service/CouponRebateServiceInterface.php | 2 +- app/Service/CouponService.php | 2 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index dd9ed65..3f4064b 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -87,6 +87,7 @@ class CouponRebateController extends BaseController $activity = $this->request->input('activity_type',0); $userId = $this->request->input('user_id',0); $get = $this->request->input('get',0); - return $this->success($this->CouponRebateService->clearSsdbCouponReceiveByName($activity,$userId, $get)); + $isAll = $this->request->input('is_all',0);; + return $this->success($this->CouponRebateService->clearSsdbCouponReceiveByName($activity,$userId, $get, $isAll)); } } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 138b7a9..8d27c16 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -56,14 +56,16 @@ class CouponRebateService implements CouponRebateServiceInterface $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $activity = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY ,'activity'); + // ssdb 键值 + $ssdbKey = 'activity_'.$activity.'_user_'.$userId; $receiveSsdb = []; // 判断是否已全部领取过 - $userReceive = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId); + $userReceive = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_RECEIVE,$ssdbKey); if($userReceive === false){ $ids = $idsData; }else{ - $userReceiveCouponIds = empty($userReceive) ? [] : $userReceive ; + $userReceiveCouponIds = empty($userReceive) ? [] : explode(',',$userReceive) ; $ids = array_diff($idsData, $userReceiveCouponIds); $receiveSsdb = $userReceiveCouponIds; } @@ -148,13 +150,12 @@ class CouponRebateService implements CouponRebateServiceInterface } if(count($receiveSsdb) > 0){ - $saveSsdb = []; - foreach($receiveSsdb as $kssdb => $vssdb){ - $saveSsdb[] = $kssdb; - $saveSsdb[] = $vssdb; - } - // 记录到ssdb - if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId, $saveSsdb)){ +; + $saveSsdb = [ + $ssdbKey, + implode(',',$receiveSsdb) + ]; + if(false === $ssdb->exec('hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE, $saveSsdb)){ $errorData['msg'] = '记录领取优惠券到ssdb失败'; $this->log->event( LogLabel::COUPON_LOG, @@ -372,16 +373,24 @@ class CouponRebateService implements CouponRebateServiceInterface /** * 清优惠券领取记录(SSDB) */ - public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0){ - + public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0, $isAll = 0){ + $key = 'activity_'.$activity.'_user_'.$userId; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - if($get > 0){ - return [ - $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ) - ]; + if($isAll > 0){ + if($get > 0){ + return $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE); + }else{ + return ( $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE) === false) ? false : true ; + } + }else { + $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ); + + if($get > 0){ + return $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_RECEIVE, $key); + }else{ + return ( $ssdb->exec('hdel', SsdbKeysPrefix::COUPON_REBATE_RECEIVE, $key) === false) ? false : true ; + } } - - return ( $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ) === false) ? false : true; } } \ No newline at end of file diff --git a/app/Service/CouponRebateServiceInterface.php b/app/Service/CouponRebateServiceInterface.php index 6b6edf9..df8fc5d 100644 --- a/app/Service/CouponRebateServiceInterface.php +++ b/app/Service/CouponRebateServiceInterface.php @@ -17,6 +17,6 @@ interface CouponRebateServiceInterface public function couponRebate($order_id); - public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0); + public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0, $isAll = 0); } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 7c365f0..8ee46a2 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -38,7 +38,7 @@ class CouponService implements CouponServiceInterface 'jump_data' => [ 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'share_bg' => env('OSS_IMG_HOST')."/attachment/images/png/2020/08/10/23245eea88db680670df67e77e0d8d7e.png", + 'share_bg' => env('OSS_IMG_HOST').'/attachment/images/png/2020/08/11/23245eea88db680670df67e77e0d8d7e.png', 'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/background/dangmian_dialog_background.png", 'coupons' => [] ] From 6d4c4d32402365886a17cd117b3ce788560ca8e4 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 11 Aug 2020 15:54:23 +0800 Subject: [PATCH 58/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 8ee46a2..afcb702 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -38,7 +38,7 @@ class CouponService implements CouponServiceInterface 'jump_data' => [ 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'share_bg' => env('OSS_IMG_HOST').'/attachment/images/png/2020/08/11/23245eea88db680670df67e77e0d8d7e.png', + 'share_bg' => env('OSS_IMG_HOST').'/attachment/images/png/2020/08/11/d697d43b91913f861f931649f0898815.png', 'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/background/dangmian_dialog_background.png", 'coupons' => [] ] From 33ad505c93bc4fdb2b14a895c172963868dd787f Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 11 Aug 2020 17:31:57 +0800 Subject: [PATCH 59/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index afcb702..2d76319 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -39,7 +39,7 @@ class CouponService implements CouponServiceInterface 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'share_bg' => env('OSS_IMG_HOST').'/attachment/images/png/2020/08/11/d697d43b91913f861f931649f0898815.png', - 'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/background/dangmian_dialog_background.png", + 'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/png/2020/08/11/9c7d7c95b5de29539fad4bc9a2fcb98d.png", 'coupons' => [] ] ]; From dbb96dad6b884b82b22e8069bc925bf15f270ade Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 11 Aug 2020 18:18:55 +0800 Subject: [PATCH 60/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 2d76319..b0aa716 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -96,7 +96,7 @@ class CouponService implements CouponServiceInterface foreach ($coupons as $k => &$v){ if($v->active_type == 1){ - $result['not_receive'] = $v; + $result['not_receive'][] = $v; }else if($v->active_type == 2){ $result['jump_data']['coupons'][] = $v->id; } From c0ac902090e7e93af78b3f18ef7ad9af07696c1e Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 12 Aug 2020 09:49:34 +0800 Subject: [PATCH 61/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E6=B7=BB=E5=8A=A0=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E8=BF=87=E6=9C=9F=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 8d27c16..c907186 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -42,7 +42,7 @@ class CouponRebateService implements CouponRebateServiceInterface // status: 0领取成功 >0领取失败 $result = [ 'status' => 1, - 'coupon_text' => '继续努力~' + 'coupon_text' => '活动已过期~' ]; // 错误日志记录 From 1ad034cc2c785017349547215decec25a2770981 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 12 Aug 2020 11:33:13 +0800 Subject: [PATCH 62/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E8=AF=B7=E6=B1=82=E5=8F=82?= =?UTF-8?q?=E6=95=B0ids=E4=B8=BA=E7=A9=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Request/CouponRebateReceiveRequest.php | 3 --- app/Service/CommonService.php | 25 ++++++++++++++++++++++ app/Service/CouponRebateService.php | 19 +++++++++++++--- 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 app/Service/CommonService.php diff --git a/app/Request/CouponRebateReceiveRequest.php b/app/Request/CouponRebateReceiveRequest.php index 4c4beed..7abce7d 100644 --- a/app/Request/CouponRebateReceiveRequest.php +++ b/app/Request/CouponRebateReceiveRequest.php @@ -24,7 +24,6 @@ class CouponRebateReceiveRequest extends FormRequest return [ 'user_id' => 'required|nonempty|integer|exists_enable:ims_cjdc_user,id', 'receive_type' => 'required|nonempty|integer', - 'ids' => 'required|nonempty', ]; } @@ -33,7 +32,6 @@ class CouponRebateReceiveRequest extends FormRequest return [ 'user_id.*' => ':attribute信息不正确', 'receive_type.*' => ':attribute必须', - 'ids.*' => ':attribute必须', ]; } @@ -42,7 +40,6 @@ class CouponRebateReceiveRequest extends FormRequest return [ 'user_id' => '领取用户ID', 'receive_type' => '领取方式', - 'ids' => '优惠券', ]; } } diff --git a/app/Service/CommonService.php b/app/Service/CommonService.php new file mode 100644 index 0000000..9ffb169 --- /dev/null +++ b/app/Service/CommonService.php @@ -0,0 +1,25 @@ +0领取失败 $result = [ 'status' => 1, 'coupon_text' => '活动已过期~' ]; + /* 如果请求的优惠券ids为空,则返回过期提示 */ + if($this->commonService->empty($params["ids"])){ + return $result; + } + + $ids = $params["ids"]; + $idsData = is_array($ids) ? $ids : explode(',',$ids); // 错误日志记录 $errorData = [ @@ -150,7 +163,7 @@ class CouponRebateService implements CouponRebateServiceInterface } if(count($receiveSsdb) > 0){ -; + $saveSsdb = [ $ssdbKey, implode(',',$receiveSsdb) From d13bd3253888e62feae0f2bd73e96d2fd4480b88 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 12 Aug 2020 12:04:32 +0800 Subject: [PATCH 63/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E5=8F=AA=E6=9C=89=E5=8A=A0?= =?UTF-8?q?=E8=BF=9B=E6=B4=BB=E5=8A=A8=E7=9A=84=E5=88=B8=E6=89=8D=E8=BF=94?= =?UTF-8?q?=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index b0aa716..994b899 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -70,8 +70,8 @@ class CouponService implements CouponServiceInterface // 当前用户可领的优惠券ID $couponIds = array_diff($c_ids, $cr_ids); - // 获取领取型优惠券 - $couponIds = $couponActivity['forward'] === false ? $couponIds : array_merge($couponIds,explode(',',$couponActivity['forward'])); + // 转发型优惠券 + $couponReceiveIds = $couponActivity === false ? [] : explode(',',$couponActivity['forward']); $whereC = [ ['u.end_time','>',$nowTime], @@ -97,7 +97,7 @@ class CouponService implements CouponServiceInterface if($v->active_type == 1){ $result['not_receive'][] = $v; - }else if($v->active_type == 2){ + }else if($v->active_type == 2 && in_array($v->id,$couponReceiveIds)){ $result['jump_data']['coupons'][] = $v->id; } From 0a6fdc159f583c7df7aa219ae8b4ac8a7db98671 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 12 Aug 2020 14:35:25 +0800 Subject: [PATCH 64/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E6=B8=85?= =?UTF-8?q?=E9=99=A4=E9=A2=86=E5=8F=96=E7=BC=93=E5=AD=98=EF=BC=88ssdb?= =?UTF-8?q?=EF=BC=89=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 539a404..56e9da7 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -397,8 +397,6 @@ class CouponRebateService implements CouponRebateServiceInterface return ( $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE) === false) ? false : true ; } }else { - $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ); - if($get > 0){ return $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_RECEIVE, $key); }else{ From 232b3c48830136cfa8e8a1d9d43cfe54af2aae0e Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Thu, 13 Aug 2020 17:04:08 +0800 Subject: [PATCH 65/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=8E=A5=E5=8F=A3-=E6=9F=A5=E8=AF=A2=E6=9D=A1?= =?UTF-8?q?=E6=95=B0=E4=B8=8D=E9=99=90=E5=88=B6=E5=92=8C=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app/Controller/CouponController.php | 4 ++-- app/Controller/CouponRebateController.php | 11 ++------- app/Service/CouponService.php | 27 ++++++++++++++++++----- config/autoload/dependencies.php | 1 + 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 9091e68..9454e2b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ vendor/ *.lock .phpunit* /watch +.vscode/ diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index 6212782..648039a 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -20,13 +20,13 @@ use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; use Hyperf\Utils\ApplicationContext; use App\Request\CouponGetListRequest; -use App\Service\CouponService; +use App\Service\CouponServiceInterface; class CouponController extends BaseController { /** * @Inject - * @var CouponService + * @var CouponServiceInterface */ protected $couponService; diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 3f4064b..7765de3 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -11,24 +11,17 @@ declare(strict_types=1); */ namespace App\Controller; -use Hyperf\DbConnection\Db; -use Hyperf\Redis\Redis; -use Hyperf\Utils\ApplicationContext; + use App\Service\CouponRebateServiceInterface; -use http\Client\Curl\User; use Hyperf\Di\Annotation\Inject; -use App\Model\Coupon; -use App\Model\CouponUserRecType; -use App\Model\CouponRec; use App\Request\CouponRebateReceiveRequest; -use App\Service\CouponRebateService; use App\Request\CouponRebateTieRequest; class CouponRebateController extends BaseController { /** * @Inject - * @var CouponRebateService + * @var CouponRebateServiceInterface */ protected $CouponRebateService; diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 994b899..9fc4f97 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -13,6 +13,7 @@ use App\Constants\SsdbKeysPrefix; use App\Constants\LogLabel; use App\Commons\Log; use Exception; +use App\Service\CommonService; class CouponService implements CouponServiceInterface { @@ -21,6 +22,12 @@ class CouponService implements CouponServiceInterface * @var Log */ protected $log; + + /** + * @Inject + * @var CommonService + */ + protected $commonService; /** * 获取用户可领取优惠卷接口 @@ -45,13 +52,17 @@ class CouponService implements CouponServiceInterface ]; $nowTime = time(); $c_ids = []; - + $whereC = [ + ['end_time','>',$nowTime], + ['start_time','<=',$nowTime], + ['status','=',1] + ]; // 渠道开启,查询该渠道可以领取的优惠券ID // 渠道未开启,查询所有优惠券 if (env('SUB_CHANNEL') == 1) { - $c_ids = CouponUserRecType::where('receive_type', $receiveType)->pluck('system_coupon_user_id'); + $c_ids = CouponUserRecType::where('receive_type', $receiveType)->where($whereC)->pluck('system_coupon_user_id'); } else { - $c_ids = Coupon::pluck('id'); + $c_ids = Coupon::where($whereC)->pluck('id'); } $couponReceive = CouponRec::where('user_id',$userId); @@ -71,13 +82,17 @@ class CouponService implements CouponServiceInterface $couponIds = array_diff($c_ids, $cr_ids); // 转发型优惠券 - $couponReceiveIds = $couponActivity === false ? [] : explode(',',$couponActivity['forward']); + $couponReceiveIds = ($couponActivity === false || $this->commonService->empty($couponActivity['forward']) )? [] : explode(',',$couponActivity['forward']); + // 所有优惠券 + $couponIds = array_merge($couponIds,$couponReceiveIds); $whereC = [ ['u.end_time','>',$nowTime], ['u.start_time','<=',$nowTime], ['u.status','=',1] ]; + // 查询领取型1 和 转发型2 + $whereActiveType = [1,2]; if (env('SUB_CHANNEL') == 1) { array_push($whereC, ['type.receive_type','=', $receiveType]); @@ -86,16 +101,16 @@ class CouponService implements CouponServiceInterface $coupons = Db::table('ims_system_coupon_user as u') ->join('ims_system_coupon_user_receivetype as type', 'u.id', '=', 'type.system_coupon_user_id') ->whereIn('u.id', $couponIds) + ->whereIn('u.active_type', $whereActiveType) ->where($whereC) ->whereRaw('u.inventory_use < u.inventory and u.inventory-u.inventory_use >= type.one_receive_number') ->select('u.*','type.one_receive_number') ->orderBy('u.weigh','desc') - ->limit(4) ->get(); foreach ($coupons as $k => &$v){ - if($v->active_type == 1){ + if($v->active_type == 1 && count($result['not_receive']) < 4){ $result['not_receive'][] = $v; }else if($v->active_type == 2 && in_array($v->id,$couponReceiveIds)){ $result['jump_data']['coupons'][] = $v->id; diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 2b8b2ad..28a2970 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -17,4 +17,5 @@ return [ \App\Commons\Log::class => \App\Commons\Log::class, \App\Service\CouponRebateServiceInterface::class => \App\Service\CouponRebateService::class, \App\Service\UserServiceInterface::class => \App\Service\UserService::class, + \App\Service\CouponServiceInterface::class => \App\Service\CouponService::class, ]; From 4da66fe1f9892112f5e520813125ae2ff64f71e7 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 14 Aug 2020 14:51:32 +0800 Subject: [PATCH 66/66] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=BA=E6=AD=A3=E5=BC=8Foos=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 9fc4f97..6708822 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -45,8 +45,8 @@ class CouponService implements CouponServiceInterface 'jump_data' => [ 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'share_bg' => env('OSS_IMG_HOST').'/attachment/images/png/2020/08/11/d697d43b91913f861f931649f0898815.png', - 'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/png/2020/08/11/9c7d7c95b5de29539fad4bc9a2fcb98d.png", + 'share_bg' => env('OSS_IMG_HOST').'/static/img/coupon_bg.png', + 'receive_bg' => env('OSS_IMG_HOST').'/static/img/coupon_share.png', 'coupons' => [] ] ];