diff --git a/app/api/logic/LocalStoreGoodsLogic.php b/app/api/logic/LocalStoreGoodsLogic.php index 222e16c1..48d43334 100644 --- a/app/api/logic/LocalStoreGoodsLogic.php +++ b/app/api/logic/LocalStoreGoodsLogic.php @@ -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();