alias('t'); $model = $model->join('store_product s', 's.id=t.product_id'); $model = $model->field('t.*,s.stock,s.price'); $model = $model->order('t.sort desc,t.id desc'); $model = $model->where('t.is_show', 1); $model = $model->where('t.is_del', 0); // $model = $model->where('t.is_finish', 0); // $model = $model->where('t.start_time', '<', $time); // $model = $model->where('t.stop_time', '>', $time); if ($page) $model = $model->page($page, $limit); return $model->select()->each(function ($item) { $item['image'] = set_file_url($item['image']); }); } /** * 获取一条试用商品数据 * @param $id * @return mixed */ public static function getTryOne($id) { $model = new self(); $model = $model->alias('t'); $model = $model->join('store_product s', 's.id=t.product_id'); // $model = $model->field('a.*,s.price as product_price,SUM(s.sales+s.ficti) as total'); $model = $model->field('t.*,s.slider_image,s.stock,s.unit_name,s.price'); $model = $model->where('t.is_show', 1); $model = $model->where('t.is_del', 0); // $model = $model->where('t.is_finish', 0); $model = $model->where('t.id', $id); // $model = $model->where('a.start_time','<',time()); // $model = $model->where('a.stop_time','>',time()-86400); return $model->find(); } /** * 修改销量和库存 * @param $num * @param $CombinationId * @return bool */ public static function decCombinationStock($num, $product_id, $unique) { if ($unique) { $res = false !== StoreProductAttrValue::decProductAttrStock($product_id, $unique, $num, 0); // $res = $res && self::where('id', $CombinationId)->dec('stock', $num)->inc('sales', $num)->update(); $sku = StoreProductAttrValue::where('product_id', $product_id)->where('unique', $unique)->where('type', 0)->value('suk'); $res = $res && StoreProductAttrValue::where('product_id', $product_id)->where('suk', $sku)->where('type', 0)->dec('stock', $num)->inc('sales', $num)->update(); } else { $res = $res && StoreProduct::where('id', $product_id)->dec('stock', $num)->inc('sales', $num)->update(); } return $res; } }