cxfoot/models/common/CommonCartActionForm.php
2023-10-27 14:25:12 +08:00

85 lines
2.1 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2021年6月15日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\models\common;
use app\models\Cart;
use app\models\Model;
class CommonCartActionForm extends Model
{
public $cart_ids;
public $plugin_sign;
public $cx_mch_id;
public $user_id;
public function rules()
{
return [
[['cx_mch_id', 'user_id',], 'integer'],
[['cx_mch_id', 'user_id', 'plugin_sign'], 'required'],
[['cart_ids', ], 'required', 'on' => 'delete']
];
}
public function delete()
{
if(!$this->validate()){
return $this->getModelError();
}
try {
Cart::cacheStatusSet(true);
$this->cart_ids = json_decode($this->cart_ids, true);
Cart::updateAll(['is_delete' => 1, 'deleted_at' => time()], [
'id' => $this->cart_ids,
'is_delete' => 0,
'cx_mch_id' => $this->cx_mch_id,
'user_id' => $this->user_id,
'plugin_sign' => $this->plugin_sign,
]);
return $this->apiReturnSuccess("操作成功");
} catch (\Exception $e) {
return $this->apiReturnError($e->getMessage());
}
}
public function clear()
{
if(!$this->validate()){
return $this->getModelError();
}
try {
Cart::cacheStatusSet(true);
$this->cart_ids = json_decode($this->cart_ids, true);
Cart::updateAll(['is_delete' => 1, 'deleted_at' => time()], [
'is_delete' => 0,
'cx_mch_id' => $this->cx_mch_id,
'user_id' => $this->user_id,
'plugin_sign' => $this->plugin_sign,
]);
return $this->apiReturnSuccess("操作成功");
} catch (\Exception $e) {
return $this->apiReturnError($e->getMessage());
}
}
public function __destruct()
{
Cart::cacheStatusSet(false);
}
}