lszyh
zengyyh 7 months ago
parent bcfab48a6f
commit 11f1c6f958
  1. 34
      app/common/model/MerchantGoodsCate.php
  2. 31
      app/store/controller/Merchant.php

@ -40,4 +40,38 @@ class MerchantGoodsCate extends BaseModel
];
return static::get($where, []);
}
/**
* 更新记录
* @param array $data
* @return bool
*/
public function edit(array $data): bool
{
return $this->save($data) !== false;
}
/**
* 新增记录
* @param array $data
* @return bool
*/
public function add(array $data): bool
{
return $this->save($this->createData($data));
}
/**
* 创建数据
* @param array $data
* @return array
*/
private function createData(array $data): array
{
$data['store_id'] = self::$storeId;
return $data;
}
}

@ -180,29 +180,36 @@ class Merchant extends Controller
}
public function setMerchantGoodsCate(): Json{
$model = new MerchantGoodsCate;
$merchantId = $this->merchantId;
$detail = MerchantGoodsCate::detail($merchantId);
$data = $this->postForm();
$data['merchant_id'] = $merchantId;
if (empty($detail)) {
if ($model->add($data)) {
return $this->renderSuccess('操作成功');
}
} else {
$data['merchant_id'] = $detail['merchant_id'];
if ($detail->edit($data)) {
return $this->renderSuccess('操作成功');
}
}
return $this->renderError($model->getError() ?: '操作失败');
}
public function getMerchantGoodsCate(): Json{
$merchantId = $this->merchantId;
$merchant = MerchantGoodsCate::detail($merchantId);
$data = $this->postForm();
//var_dump($merchant);
return $this->renderSuccess(compact("merchant"));
}
public function addMerchant(): Json
{
$data = $this->postForm();
$data = json_decode($data);
$Merchant = MerchantGoodsCate::where($this->storeId)->find()->toArray();
return $this->renderSuccess($Merchant);
}

Loading…
Cancel
Save