public function actionAdd($id)
{
Yii::$app->response->format = Response::FORMAT_JSON;
if (!Goods::find()->where(['id' => $id, 'store_id' => Yii::$app->user->identity->store_id, 'status' => [Goods::STATUS_NORMAL, Goods::STATUS_OFF_SHELVES]])->exists() || Purchase::hasGoods($id)) {
throw new BadRequestHttpException('拒绝操作。');
}
$model = new Purchase();
$model->goods_id = $id;
$model->store_id = Yii::$app->user->identity->store_id;
$model->count = 1;
if ($model->save(false)) {
return ['status' => 'success', 'data' => []];
} else {
return ['status' => 'fail', 'data' => ['message' => '加入失败。']];
}
}