修改商品添加和修改方式

This commit is contained in:
wangxiaowei 2024-08-23 10:33:31 +08:00
parent 919eb89a3a
commit e4e4dfb2c9

@ -10,6 +10,8 @@ use think\facade\Config;
class LocalStoreGoodsLogic extends Logic
{
private static $SHELVES = 1;
// 获取商品列表
public static function lists($get)
{
@ -54,24 +56,37 @@ class LocalStoreGoodsLogic extends Logic
public static function saveGoods($form, $user_id)
{
try {
$form['user_id'] = $user_id;
$form['create_time'] = time();
$form['state'] = 1;
$len = strlen(Config::get('aliyunoss.domain'));
$pic = $form['url'];
unset($form['url']);
// $id = LocalStoreGoods::insertGetId($form);
if ($form['type'] === 'add') {
$id = LocalStoreGoods::insertGetId([
'user_id' => $user_id,
'lstore_id' => $form['lstore_id'],
'title' => $form['title'],
'price' => $form['price'],
'desc' => $form['desc'],
'details' => $form['details'],
'state' => self::$SHELVES,
'create_time' => time(),
]);
} else if ($form['type'] === 'edit') {
LocalStoreGoods::where(['id' => $form['id']])->update([
'title' => $form['title'],
'price' => $form['price'],
'desc' => $form['desc'],
'details' => $form['details'],
'update_time' => time(),
]);
LocalStoreGoodsPic::where(['id' => $form['id']])->delete();
$id = $form['id'];
}
$data = [];
$len = strlen(Config::get('aliyunoss.domain'));
foreach ($pic as $k => &$v) {
dump(substr($v, $len, strlen($v)));
// $data[$k]['lsg_id'] = $id;
// $data[$k]['url'] = basename($v);
foreach ($form['url'] as $k => &$v) {
$data[$k]['lsg_id'] = $id;
$data[$k]['url'] = substr($v, $len, strlen($v));
}
die;
LocalStoreGoodsPic::insertAll($data);
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();