field('id, lstore_id, title, price') ->where($where) ->where($m_where) ->order('id', 'desc') ->page($get['page_no'], $get['page_size']) ->select() ->toArray(); $count = LocalStoreGoods::where($where)->where($m_where)->count(); foreach ($list as &$v) { foreach ($v['pic'] as &$v1) { $v1['url'] = Config::get('aliyunoss.domain') . $v1['url']; } } // 统计待审核的商品数量 $stay_goods_count = LocalStoreGoods::where($m_where)->where(['audit_status' => LocalStoreGoodsEnum::AUDIT_STATUS_STAY])->count(); // 统计审核失败的商品数量 $fail_goods_count = LocalStoreGoods::where($m_where)->where(['audit_status' => LocalStoreGoodsEnum::AUDIT_STATUS_REFUSE])->count(); $result = [ 'stay_goods_count' => $stay_goods_count, 'fail_goods_count' => $fail_goods_count, 'count' => $count, 'lists' => $list, 'more' => is_more($count, $get['page_no'], $get['page_size']), 'page_no' => $get['page_no'], 'page_size' => $get['page_size'] ]; return $result; } // 添加商品 public static function saveGoods($form, $user_id) { try { $len = strlen(Config::get('aliyunoss.domain')); 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'] ?? '', 'is_multiple_spec' => !empty($form['sku']) ? 1 : 0, 'create_time' => time(), ]); $item = array(); if (!empty($form['spec'])) { // foreach ($form['sku'] as &$v) { // foreach ($v['spec'] as &$v2) { // $spec_id = LocalStoreGoodsSpec::insertGetId([ // 'goods_id' => $id, // 'name' => $v['name'] // ]); // // foreach ($v2['item'] as &$v3) { // $spec_value_id[] = LocalStoreGoodsSpecValue::insertGetId([ // 'goods_id' => $id, // 'spec_id' => $spec_id, // 'value' => $v3 // ]); // } // } // } $spec = []; foreach ($form['spec'] as &$v) { $spec[] = [ 'user_id' => $user_id, 'lstore_id' => $form['lstore_id'], 'goods_id' => $id, 'name' => $v['name'] ]; } LocalStoreGoodsSpec::insertAll($spec); $spec_name_id = LocalStoreGoodsSpec::where(['goods_id' => $id])->column('id', 'name'); $spec_value = []; foreach ($form['spec'] as &$v) { foreach ($v['item'] as $k => &$v2) { $spec_value[] = [ 'goods_id' => $id, 'spec_id' => $spec_name_id[$v['name']], 'value' => $v2 ]; } } // LocalStoreGoodsSpecValue::insertAll($spec_value); // $spec_value_id = LocalStoreGoodsSpecValue::where(['goods_id' => $id])->column('id', 'value'); dump($spec_value); die; } } else if ($form['type'] === 'edit') { LocalStoreGoods::where(['id' => $form['id'], 'user_id' => $user_id])->update([ 'title' => $form['title'], 'price' => $form['price'], 'desc' => $form['desc'] ?? '', 'details' => $form['details'] ?? '', 'audit_status' => LocalStoreGoodsEnum::AUDIT_STATUS_STAY, 'update_time' => time(), ]); LocalStoreGoodsPic::where(['lsg_id' => $form['id']])->delete(); $id = $form['id']; } // 处理图片 $data = []; foreach ($form['url'] as $k => &$v) { $data[$k]['lsg_id'] = $id; $data[$k]['url'] = substr($v, $len, strlen($v)); } LocalStoreGoodsPic::insertAll($data); return true; } catch (\Exception $e) { self::$error = $e->getMessage(); return false; } } public static function editPrice($form, $user_id) { LocalStoreGoods::where(['id' => $form['id'], 'user_id' => $user_id])->update([ 'price' => $form['price'], 'update_time' => time(), ]); return true; } public static function editGoods($form, $user_id) { try { $form['user_id'] = $user_id; $form['update'] = time(); $form['state'] = 1; $pic = $form['url']; unset($form['url']); $id = LocalStoreGoods::update([ 'title' => $form['title'], 'price' => $form['price'], 'desc' => $form['desc'], 'details' => $form['details'], ]); $data = []; foreach ($pic as $k => &$v) { $data[$k]['lsg_id'] = $id; $data[$k]['url'] = basename($v); } LocalStoreGoodsPic::insertAll($data); return true; } catch (\Exception $e) { self::$error = $e->getMessage(); return false; } } // 获取商家自身的商品详情 public static function shop_details($get) { $data = LocalStoreGoods::with('pic') ->where([ 'id' => $get['id'], 'lstore_id' => $get['lstore_id'], 'delete_time' => 0, 'audit_status' => $get['audit_status'] ])->find()->toArray(); if ($data) { foreach ($data['pic'] as &$v) { $v['url'] = Config::get('aliyunoss.domain') . $v['url']; } return $data; } return false; } // 获取商品详情 public static function details($get) { $data = LocalStoreGoods::with('pic') ->where([ 'id' => $get['id'], 'lstore_id' => $get['lstore_id'], 'delete_time' => 0, 'state' => LocalStoreGoodsEnum::SHELVES, 'audit_status' => LocalStoreGoodsEnum::AUDIT_STATUS_OK, ])->find()->toArray(); if ($data) { foreach ($data['pic'] as &$v) { $v['url'] = Config::get('aliyunoss.domain') . $v['url']; } return $data; } return false; } // 设置状态 public static function setState($form, $user_id) { if ($form['type'] == LocalStoreGoodsEnum::SHELVES || $form['type'] == LocalStoreGoodsEnum::STATUS_SOLD_OUT) { $result = LocalStoreGoods::where(['id' => $form['id'], 'user_id' => $user_id, 'lstore_id' => $form['lstore_id']])->update([ 'state' => $form['type'], 'update_time' => time() ]); if ($result) { return $result; } return false; } return false; } }