|
|
@@ -108,29 +108,49 @@ class ProductController extends BaseController
|
|
|
$id = $post['id'] ?? 0;
|
|
|
$info = ProductClass::getById($id, true);
|
|
|
ProductClass::check($info, $this->mainId);
|
|
|
- $str = $post['date'] ?? '';
|
|
|
- $presell = $post['presell'] ?? 0;
|
|
|
- $newStr = '';
|
|
|
- if ($presell == 1) {
|
|
|
- if (empty($str)) {
|
|
|
- util::fail('请填写预售日期');
|
|
|
- }
|
|
|
- $arr = json_decode($str, true);
|
|
|
- if (empty($arr)) {
|
|
|
- util::fail('请填写预售日期');
|
|
|
+
|
|
|
+ try{
|
|
|
+ $str = $post['date'] ?? '';
|
|
|
+ $presell = $post['presell'] ?? 0;
|
|
|
+ $newStr = '';
|
|
|
+ if ($presell == 1) {
|
|
|
+ if (empty($str)) {
|
|
|
+ util::fail('请填写预售日期');
|
|
|
+ }
|
|
|
+ $arr = json_decode($str, true);
|
|
|
+ if (empty($arr)) {
|
|
|
+ util::fail('请填写预售日期');
|
|
|
+ }
|
|
|
+ $new = [];
|
|
|
+ foreach ($arr as $date) {
|
|
|
+ $new[] = strtotime($date);
|
|
|
+ }
|
|
|
+ $new = array_unique(array_filter($new));
|
|
|
+ sort($new);
|
|
|
+ $newStr = implode(',', $new);
|
|
|
+
|
|
|
+ //使用redis缓存来保存某用户设置了某花材的预售
|
|
|
+ $redis = Yii::$app->redis;
|
|
|
+ $redis->set('product_presell:'.$id, $new[0]);
|
|
|
+ } else {
|
|
|
+ $redis = Yii::$app->redis;
|
|
|
+ if ($redis->exists('product_presell:'.$id)) {
|
|
|
+ $redis->del('product_presell:'.$id);
|
|
|
+ }
|
|
|
}
|
|
|
- $new = [];
|
|
|
- foreach ($arr as $date) {
|
|
|
- $new[] = strtotime($date);
|
|
|
+ $info->presell = $presell;
|
|
|
+ $info->presellDate = $newStr;
|
|
|
+ $info->discountPrice = 0;
|
|
|
+ $info->save();
|
|
|
+ }catch(\Exception $e){
|
|
|
+ // 失败情况,要把缓存删除
|
|
|
+ if ($presell == 1) {
|
|
|
+ $redis = Yii::$app->redis;
|
|
|
+ if ($redis->exists('product_presell:'.$id)) {
|
|
|
+ $redis->del('product_presell:'.$id);
|
|
|
+ }
|
|
|
}
|
|
|
- $new = array_unique(array_filter($new));
|
|
|
- asort($new);
|
|
|
- $newStr = implode(',', $new);
|
|
|
}
|
|
|
- $info->presell = $presell;
|
|
|
- $info->presellDate = $newStr;
|
|
|
- $info->discountPrice = 0;
|
|
|
- $info->save();
|
|
|
util::complete();
|
|
|
}
|
|
|
|